xref: /trunk/main/dbaccess/source/ui/app/AppSwapWindow.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef DBAUI_APPSWAPWINDOW_HXX
31*cdf0e10cSrcweir #include "AppSwapWindow.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
37*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef _DBU_APP_HRC_
40*cdf0e10cSrcweir #include "dbu_app.hrc"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef DBAUI_APPVIEW_HXX
43*cdf0e10cSrcweir #include "AppView.hxx"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
46*cdf0e10cSrcweir #include <vcl/svapp.hxx>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef _SV_SYSWIN_HXX
49*cdf0e10cSrcweir #include <vcl/syswin.hxx>
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef _SV_MENU_HXX
52*cdf0e10cSrcweir #include <vcl/menu.hxx>
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #ifndef _SV_MNEMONIC_HXX
55*cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #include "IApplicationController.hxx"
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <memory>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir using namespace ::dbaui;
62*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
63*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
64*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
65*cdf0e10cSrcweir using namespace ::com::sun::star::container;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //==================================================================
68*cdf0e10cSrcweir // class OApplicationSwapWindow
69*cdf0e10cSrcweir DBG_NAME(OApplicationSwapWindow)
70*cdf0e10cSrcweir //==================================================================
71*cdf0e10cSrcweir OApplicationSwapWindow::OApplicationSwapWindow( Window* _pParent, OAppBorderWindow& _rBorderWindow )
72*cdf0e10cSrcweir     :Window(_pParent,WB_DIALOGCONTROL )
73*cdf0e10cSrcweir     ,m_aIconControl(this)
74*cdf0e10cSrcweir     ,m_eLastType(E_NONE)
75*cdf0e10cSrcweir     ,m_rBorderWin( _rBorderWindow )
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     DBG_CTOR(OApplicationSwapWindow,NULL);
78*cdf0e10cSrcweir //  SetCompoundControl( sal_True );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     ImplInitSettings( sal_True, sal_True, sal_True );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     m_aIconControl.SetClickHdl(LINK(this, OApplicationSwapWindow, OnContainerSelectHdl));
83*cdf0e10cSrcweir     m_aIconControl.setControlActionListener( &m_rBorderWin.getView()->getAppController() );
84*cdf0e10cSrcweir     m_aIconControl.SetHelpId(HID_APP_SWAP_ICONCONTROL);
85*cdf0e10cSrcweir     m_aIconControl.Show();
86*cdf0e10cSrcweir     //m_aIconControl.Enable(sal_True);
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir // -----------------------------------------------------------------------------
89*cdf0e10cSrcweir OApplicationSwapWindow::~OApplicationSwapWindow()
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     DBG_DTOR(OApplicationSwapWindow,NULL);
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir // -----------------------------------------------------------------------------
95*cdf0e10cSrcweir void OApplicationSwapWindow::Resize()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     Size aFLSize = LogicToPixel( Size( 8, 0 ), MAP_APPFONT );
98*cdf0e10cSrcweir     long nX = 0;
99*cdf0e10cSrcweir     if ( m_aIconControl.GetEntryCount() != 0 )
100*cdf0e10cSrcweir         nX = m_aIconControl.GetBoundingBox( m_aIconControl.GetEntry(0) ).GetWidth() + aFLSize.Width();
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     Size aOutputSize = GetOutputSize();
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     m_aIconControl.SetPosSizePixel( Point(static_cast<long>((aOutputSize.Width() - nX)*0.5), 0)  ,Size(nX,aOutputSize.Height()));
105*cdf0e10cSrcweir     m_aIconControl.ArrangeIcons();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir // -----------------------------------------------------------------------------
108*cdf0e10cSrcweir void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
111*cdf0e10cSrcweir     if( bFont )
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir         Font aFont;
114*cdf0e10cSrcweir         aFont = rStyleSettings.GetFieldFont();
115*cdf0e10cSrcweir         aFont.SetColor( rStyleSettings.GetWindowTextColor() );
116*cdf0e10cSrcweir         SetPointFont( aFont );
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     if( bForeground || bFont )
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         SetTextColor( rStyleSettings.GetFieldTextColor() );
122*cdf0e10cSrcweir         SetTextFillColor();
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     if( bBackground )
126*cdf0e10cSrcweir         SetBackground( rStyleSettings.GetFieldColor() );
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir // -----------------------------------------------------------------------
129*cdf0e10cSrcweir void OApplicationSwapWindow::DataChanged( const DataChangedEvent& rDCEvt )
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
132*cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
133*cdf0e10cSrcweir         (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
134*cdf0e10cSrcweir         (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
135*cdf0e10cSrcweir         ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
136*cdf0e10cSrcweir         (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
137*cdf0e10cSrcweir     {
138*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
139*cdf0e10cSrcweir         Invalidate();
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir // -----------------------------------------------------------------------------
143*cdf0e10cSrcweir void OApplicationSwapWindow::clearSelection()
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     m_aIconControl.SetNoSelection();
146*cdf0e10cSrcweir     sal_uLong nPos = 0;
147*cdf0e10cSrcweir     SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
148*cdf0e10cSrcweir     if ( pEntry )
149*cdf0e10cSrcweir         m_aIconControl.InvalidateEntry(pEntry);
150*cdf0e10cSrcweir     m_aIconControl.GetClickHdl().Call(&m_aIconControl);
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir // -----------------------------------------------------------------------------
154*cdf0e10cSrcweir void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     m_aIconControl.CreateAutoMnemonics( _rMnemonics );
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir // -----------------------------------------------------------------------------
160*cdf0e10cSrcweir bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent& _rEvent )
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     const KeyCode& rKeyCode = _rEvent.GetKeyCode();
163*cdf0e10cSrcweir     if ( rKeyCode.GetModifier() == KEY_MOD2 )
164*cdf0e10cSrcweir         return m_aIconControl.DoKeyInput( _rEvent );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     // not handled
167*cdf0e10cSrcweir     return false;
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir // -----------------------------------------------------------------------------
171*cdf0e10cSrcweir ElementType OApplicationSwapWindow::getElementType() const
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     sal_uLong nPos = 0;
174*cdf0e10cSrcweir     SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
175*cdf0e10cSrcweir     return ( pEntry ) ? *static_cast<ElementType*>(pEntry->GetUserData()) : E_NONE;
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir // -----------------------------------------------------------------------------
179*cdf0e10cSrcweir bool OApplicationSwapWindow::onContainerSelected( ElementType _eType )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     if ( m_eLastType == _eType )
182*cdf0e10cSrcweir         return true;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
185*cdf0e10cSrcweir     {
186*cdf0e10cSrcweir         if ( _eType != E_NONE )
187*cdf0e10cSrcweir             m_eLastType = _eType;
188*cdf0e10cSrcweir         return true;
189*cdf0e10cSrcweir     } // if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     PostUserEvent( LINK( this, OApplicationSwapWindow, ChangeToLastSelected ) );
192*cdf0e10cSrcweir     return false;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // -----------------------------------------------------------------------------
196*cdf0e10cSrcweir IMPL_LINK(OApplicationSwapWindow, OnContainerSelectHdl, SvtIconChoiceCtrl*, _pControl)
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     sal_uLong nPos = 0;
199*cdf0e10cSrcweir     SvxIconChoiceCtrlEntry* pEntry = _pControl->GetSelectedEntry( nPos );
200*cdf0e10cSrcweir     ElementType eType = E_NONE;
201*cdf0e10cSrcweir     if ( pEntry )
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir         eType = *static_cast<ElementType*>(pEntry->GetUserData());
204*cdf0e10cSrcweir         onContainerSelected( eType ); // i87582
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     return 1L;
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir //------------------------------------------------------------------------------
210*cdf0e10cSrcweir IMPL_LINK(OApplicationSwapWindow, ChangeToLastSelected, void*, EMPTYARG)
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir     selectContainer(m_eLastType);
213*cdf0e10cSrcweir     return 0L;
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir // -----------------------------------------------------------------------------
216*cdf0e10cSrcweir void OApplicationSwapWindow::selectContainer(ElementType _eType)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     sal_uLong nCount = m_aIconControl.GetEntryCount();
219*cdf0e10cSrcweir     SvxIconChoiceCtrlEntry* pEntry = NULL;
220*cdf0e10cSrcweir     for (sal_uLong i=0; i < nCount; ++i)
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         pEntry = m_aIconControl.GetEntry(i);
223*cdf0e10cSrcweir         if ( pEntry && *static_cast<ElementType*>(pEntry->GetUserData()) == _eType )
224*cdf0e10cSrcweir             break;
225*cdf0e10cSrcweir         pEntry = NULL;
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     if ( pEntry )
229*cdf0e10cSrcweir         m_aIconControl.SetCursor(pEntry); // this call also initiates a onContainerSelected call
230*cdf0e10cSrcweir     else
231*cdf0e10cSrcweir         onContainerSelected( _eType );
232*cdf0e10cSrcweir }
233