Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "AppSwapWindow.hxx"
21 : #include <tools/debug.hxx>
22 : #include "dbaccess_helpid.hrc"
23 : #include "dbu_app.hrc"
24 : #include "AppView.hxx"
25 : #include <vcl/svapp.hxx>
26 : #include <vcl/syswin.hxx>
27 : #include <vcl/menu.hxx>
28 : #include <vcl/mnemonic.hxx>
29 : #include <vcl/settings.hxx>
30 : #include "IApplicationController.hxx"
31 :
32 : using namespace ::dbaui;
33 : using namespace ::com::sun::star::uno;
34 : using namespace ::com::sun::star::sdbc;
35 : using namespace ::com::sun::star::lang;
36 : using namespace ::com::sun::star::container;
37 :
38 : // class OApplicationSwapWindow
39 0 : OApplicationSwapWindow::OApplicationSwapWindow( Window* _pParent, OAppBorderWindow& _rBorderWindow )
40 : :Window(_pParent,WB_DIALOGCONTROL )
41 : ,m_aIconControl(this)
42 : ,m_eLastType(E_NONE)
43 0 : ,m_rBorderWin( _rBorderWindow )
44 : {
45 :
46 0 : ImplInitSettings( sal_True, sal_True, sal_True );
47 :
48 0 : m_aIconControl.SetClickHdl(LINK(this, OApplicationSwapWindow, OnContainerSelectHdl));
49 0 : m_aIconControl.setControlActionListener( &m_rBorderWin.getView()->getAppController() );
50 0 : m_aIconControl.SetHelpId(HID_APP_SWAP_ICONCONTROL);
51 0 : m_aIconControl.Show();
52 0 : }
53 :
54 0 : OApplicationSwapWindow::~OApplicationSwapWindow()
55 : {
56 :
57 0 : }
58 :
59 0 : void OApplicationSwapWindow::Resize()
60 : {
61 0 : Size aFLSize = LogicToPixel( Size( 8, 0 ), MAP_APPFONT );
62 0 : long nX = 0;
63 0 : if ( m_aIconControl.GetEntryCount() != 0 )
64 0 : nX = m_aIconControl.GetBoundingBox( m_aIconControl.GetEntry(0) ).GetWidth() + aFLSize.Width();
65 :
66 0 : Size aOutputSize = GetOutputSize();
67 :
68 0 : m_aIconControl.SetPosSizePixel( Point(static_cast<long>((aOutputSize.Width() - nX)*0.5), 0) ,Size(nX,aOutputSize.Height()));
69 0 : m_aIconControl.ArrangeIcons();
70 0 : }
71 :
72 0 : void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
73 : {
74 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
75 0 : if( bFont )
76 : {
77 0 : Font aFont;
78 0 : aFont = rStyleSettings.GetFieldFont();
79 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
80 0 : SetPointFont( aFont );
81 : }
82 :
83 0 : if( bForeground || bFont )
84 : {
85 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
86 0 : SetTextFillColor();
87 : }
88 :
89 0 : if( bBackground )
90 0 : SetBackground( rStyleSettings.GetFieldColor() );
91 0 : }
92 :
93 0 : void OApplicationSwapWindow::DataChanged( const DataChangedEvent& rDCEvt )
94 : {
95 0 : Window::DataChanged( rDCEvt );
96 0 : if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
97 0 : (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
98 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
99 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
100 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
101 : {
102 0 : ImplInitSettings( sal_True, sal_True, sal_True );
103 0 : Invalidate();
104 : }
105 0 : }
106 :
107 0 : void OApplicationSwapWindow::clearSelection()
108 : {
109 0 : m_aIconControl.SetNoSelection();
110 0 : sal_uLong nPos = 0;
111 0 : SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
112 0 : if ( pEntry )
113 0 : m_aIconControl.InvalidateEntry(pEntry);
114 0 : m_aIconControl.GetClickHdl().Call(&m_aIconControl);
115 0 : }
116 :
117 0 : void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
118 : {
119 0 : m_aIconControl.CreateAutoMnemonics( _rMnemonics );
120 0 : }
121 :
122 0 : bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent& _rEvent )
123 : {
124 0 : const KeyCode& rKeyCode = _rEvent.GetKeyCode();
125 0 : if ( rKeyCode.GetModifier() == KEY_MOD2 )
126 0 : return m_aIconControl.DoKeyInput( _rEvent );
127 :
128 : // not handled
129 0 : return false;
130 : }
131 :
132 0 : ElementType OApplicationSwapWindow::getElementType() const
133 : {
134 0 : sal_uLong nPos = 0;
135 0 : SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
136 0 : return ( pEntry ) ? *static_cast<ElementType*>(pEntry->GetUserData()) : E_NONE;
137 : }
138 :
139 0 : bool OApplicationSwapWindow::onContainerSelected( ElementType _eType )
140 : {
141 0 : if ( m_eLastType == _eType )
142 0 : return true;
143 :
144 0 : if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
145 : {
146 0 : if ( _eType != E_NONE )
147 0 : m_eLastType = _eType;
148 0 : return true;
149 : }
150 :
151 0 : PostUserEvent( LINK( this, OApplicationSwapWindow, ChangeToLastSelected ) );
152 0 : return false;
153 : }
154 :
155 0 : IMPL_LINK(OApplicationSwapWindow, OnContainerSelectHdl, SvtIconChoiceCtrl*, _pControl)
156 : {
157 0 : sal_uLong nPos = 0;
158 0 : SvxIconChoiceCtrlEntry* pEntry = _pControl->GetSelectedEntry( nPos );
159 0 : ElementType eType = E_NONE;
160 0 : if ( pEntry )
161 : {
162 0 : eType = *static_cast<ElementType*>(pEntry->GetUserData());
163 0 : onContainerSelected( eType ); // i87582
164 : }
165 :
166 0 : return 1L;
167 : }
168 :
169 0 : IMPL_LINK_NOARG(OApplicationSwapWindow, ChangeToLastSelected)
170 : {
171 0 : selectContainer(m_eLastType);
172 0 : return 0L;
173 : }
174 :
175 0 : void OApplicationSwapWindow::selectContainer(ElementType _eType)
176 : {
177 0 : sal_uLong nCount = m_aIconControl.GetEntryCount();
178 0 : SvxIconChoiceCtrlEntry* pEntry = NULL;
179 0 : for (sal_uLong i=0; i < nCount; ++i)
180 : {
181 0 : pEntry = m_aIconControl.GetEntry(i);
182 0 : if ( pEntry && *static_cast<ElementType*>(pEntry->GetUserData()) == _eType )
183 0 : break;
184 0 : pEntry = NULL;
185 : }
186 :
187 0 : if ( pEntry )
188 0 : m_aIconControl.SetCursor(pEntry); // this call also initiates a onContainerSelected call
189 : else
190 0 : onContainerSelected( _eType );
191 0 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|