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