1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBAUI_APPSWAPWINDOW_HXX
27 #include "AppSwapWindow.hxx"
28 #endif
29 #ifndef _TOOLS_DEBUG_HXX
30 #include <tools/debug.hxx>
31 #endif
32 #ifndef _DBA_DBACCESS_HELPID_HRC_
33 #include "dbaccess_helpid.hrc"
34 #endif
35 #ifndef _DBU_APP_HRC_
36 #include "dbu_app.hrc"
37 #endif
38 #ifndef DBAUI_APPVIEW_HXX
39 #include "AppView.hxx"
40 #endif
41 #ifndef _SV_SVAPP_HXX
42 #include <vcl/svapp.hxx>
43 #endif
44 #ifndef _SV_SYSWIN_HXX
45 #include <vcl/syswin.hxx>
46 #endif
47 #ifndef _SV_MENU_HXX
48 #include <vcl/menu.hxx>
49 #endif
50 #ifndef _SV_MNEMONIC_HXX
51 #include <vcl/mnemonic.hxx>
52 #endif
53 #include "IApplicationController.hxx"
54 
55 #include <memory>
56 
57 using namespace ::dbaui;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::sdbc;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::container;
62 
63 //==================================================================
64 // class OApplicationSwapWindow
65 DBG_NAME(OApplicationSwapWindow)
66 //==================================================================
67 OApplicationSwapWindow::OApplicationSwapWindow( Window* _pParent, OAppBorderWindow& _rBorderWindow )
68     :Window(_pParent,WB_DIALOGCONTROL )
69 	,m_aIconControl(this)
70 	,m_eLastType(E_NONE)
71 	,m_rBorderWin( _rBorderWindow )
72 {
73     DBG_CTOR(OApplicationSwapWindow,NULL);
74 //	SetCompoundControl( sal_True );
75 
76 	ImplInitSettings( sal_True, sal_True, sal_True );
77 
78 	m_aIconControl.SetClickHdl(LINK(this, OApplicationSwapWindow, OnContainerSelectHdl));
79 	m_aIconControl.setControlActionListener( &m_rBorderWin.getView()->getAppController() );
80 	m_aIconControl.SetHelpId(HID_APP_SWAP_ICONCONTROL);
81 	m_aIconControl.Show();
82 	//m_aIconControl.Enable(sal_True);
83 }
84 // -----------------------------------------------------------------------------
85 OApplicationSwapWindow::~OApplicationSwapWindow()
86 {
87 
88     DBG_DTOR(OApplicationSwapWindow,NULL);
89 }
90 // -----------------------------------------------------------------------------
91 void OApplicationSwapWindow::Resize()
92 {
93     Size aFLSize = LogicToPixel( Size( 8, 0 ), MAP_APPFONT );
94     long nX = 0;
95     if ( m_aIconControl.GetEntryCount() != 0 )
96         nX = m_aIconControl.GetBoundingBox( m_aIconControl.GetEntry(0) ).GetWidth() + aFLSize.Width();
97 
98     Size aOutputSize = GetOutputSize();
99 
100     m_aIconControl.SetPosSizePixel(	Point(static_cast<long>((aOutputSize.Width() - nX)*0.5), 0)  ,Size(nX,aOutputSize.Height()));
101 	m_aIconControl.ArrangeIcons();
102 }
103 // -----------------------------------------------------------------------------
104 void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
105 {
106 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
107 	if( bFont )
108 	{
109 		Font aFont;
110 		aFont = rStyleSettings.GetFieldFont();
111 		aFont.SetColor( rStyleSettings.GetWindowTextColor() );
112 		SetPointFont( aFont );
113 	}
114 
115 	if( bForeground || bFont )
116 	{
117 		SetTextColor( rStyleSettings.GetFieldTextColor() );
118 		SetTextFillColor();
119 	}
120 
121 	if( bBackground )
122 		SetBackground( rStyleSettings.GetFieldColor() );
123 }
124 // -----------------------------------------------------------------------
125 void OApplicationSwapWindow::DataChanged( const DataChangedEvent& rDCEvt )
126 {
127 	Window::DataChanged( rDCEvt );
128 	if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
129 		(rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
130 		(rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
131 		((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
132 		(rDCEvt.GetFlags() & SETTINGS_STYLE)) )
133 	{
134 		ImplInitSettings( sal_True, sal_True, sal_True );
135 		Invalidate();
136 	}
137 }
138 // -----------------------------------------------------------------------------
139 void OApplicationSwapWindow::clearSelection()
140 {
141 	m_aIconControl.SetNoSelection();
142 	sal_uLong nPos = 0;
143 	SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
144 	if ( pEntry )
145 		m_aIconControl.InvalidateEntry(pEntry);
146 	m_aIconControl.GetClickHdl().Call(&m_aIconControl);
147 }
148 
149 // -----------------------------------------------------------------------------
150 void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
151 {
152     m_aIconControl.CreateAutoMnemonics( _rMnemonics );
153 }
154 
155 // -----------------------------------------------------------------------------
156 bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent& _rEvent )
157 {
158     const KeyCode& rKeyCode = _rEvent.GetKeyCode();
159     if ( rKeyCode.GetModifier() == KEY_MOD2 )
160         return m_aIconControl.DoKeyInput( _rEvent );
161 
162     // not handled
163     return false;
164 }
165 
166 // -----------------------------------------------------------------------------
167 ElementType OApplicationSwapWindow::getElementType() const
168 {
169 	sal_uLong nPos = 0;
170 	SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
171 	return ( pEntry ) ? *static_cast<ElementType*>(pEntry->GetUserData()) : E_NONE;
172 }
173 
174 // -----------------------------------------------------------------------------
175 bool OApplicationSwapWindow::onContainerSelected( ElementType _eType )
176 {
177 	if ( m_eLastType == _eType )
178         return true;
179 
180     if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
181     {
182 		if ( _eType != E_NONE )
183 			m_eLastType = _eType;
184         return true;
185     } // if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
186 
187 	PostUserEvent( LINK( this, OApplicationSwapWindow, ChangeToLastSelected ) );
188     return false;
189 }
190 
191 // -----------------------------------------------------------------------------
192 IMPL_LINK(OApplicationSwapWindow, OnContainerSelectHdl, SvtIconChoiceCtrl*, _pControl)
193 {
194 	sal_uLong nPos = 0;
195 	SvxIconChoiceCtrlEntry*	pEntry = _pControl->GetSelectedEntry( nPos );
196 	ElementType eType = E_NONE;
197 	if ( pEntry )
198     {
199 		eType = *static_cast<ElementType*>(pEntry->GetUserData());
200 	    onContainerSelected( eType ); // i87582
201 	}
202 
203 	return 1L;
204 }
205 //------------------------------------------------------------------------------
206 IMPL_LINK(OApplicationSwapWindow, ChangeToLastSelected, void*, EMPTYARG)
207 {
208 	selectContainer(m_eLastType);
209 	return 0L;
210 }
211 // -----------------------------------------------------------------------------
212 void OApplicationSwapWindow::selectContainer(ElementType _eType)
213 {
214 	sal_uLong nCount = m_aIconControl.GetEntryCount();
215 	SvxIconChoiceCtrlEntry*	pEntry = NULL;
216 	for (sal_uLong i=0; i < nCount; ++i)
217 	{
218 		pEntry = m_aIconControl.GetEntry(i);
219 		if ( pEntry && *static_cast<ElementType*>(pEntry->GetUserData()) == _eType )
220 			break;
221 		pEntry = NULL;
222 	}
223 
224     if ( pEntry )
225 		m_aIconControl.SetCursor(pEntry); // this call also initiates a onContainerSelected call
226     else
227 	    onContainerSelected( _eType );
228 }
229