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