Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / app / AppSwapWindow.cxx
blob9d8ab1a517087889ea97ca95f31c85821788974b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "AppSwapWindow.hxx"
30 #include <tools/debug.hxx>
31 #include "dbaccess_helpid.hrc"
32 #include "dbu_app.hrc"
33 #include "AppView.hxx"
34 #include <vcl/svapp.hxx>
35 #include <vcl/syswin.hxx>
36 #include <vcl/menu.hxx>
37 #include <vcl/mnemonic.hxx>
38 #include "IApplicationController.hxx"
40 #include <memory>
42 using namespace ::dbaui;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::container;
48 //==================================================================
49 // class OApplicationSwapWindow
50 DBG_NAME(OApplicationSwapWindow)
51 //==================================================================
52 OApplicationSwapWindow::OApplicationSwapWindow( Window* _pParent, OAppBorderWindow& _rBorderWindow )
53 :Window(_pParent,WB_DIALOGCONTROL )
54 ,m_aIconControl(this)
55 ,m_eLastType(E_NONE)
56 ,m_rBorderWin( _rBorderWindow )
58 DBG_CTOR(OApplicationSwapWindow,NULL);
60 ImplInitSettings( sal_True, sal_True, sal_True );
62 m_aIconControl.SetClickHdl(LINK(this, OApplicationSwapWindow, OnContainerSelectHdl));
63 m_aIconControl.setControlActionListener( &m_rBorderWin.getView()->getAppController() );
64 m_aIconControl.SetHelpId(HID_APP_SWAP_ICONCONTROL);
65 m_aIconControl.Show();
67 // -----------------------------------------------------------------------------
68 OApplicationSwapWindow::~OApplicationSwapWindow()
71 DBG_DTOR(OApplicationSwapWindow,NULL);
73 // -----------------------------------------------------------------------------
74 void OApplicationSwapWindow::Resize()
76 Size aFLSize = LogicToPixel( Size( 8, 0 ), MAP_APPFONT );
77 long nX = 0;
78 if ( m_aIconControl.GetEntryCount() != 0 )
79 nX = m_aIconControl.GetBoundingBox( m_aIconControl.GetEntry(0) ).GetWidth() + aFLSize.Width();
81 Size aOutputSize = GetOutputSize();
83 m_aIconControl.SetPosSizePixel( Point(static_cast<long>((aOutputSize.Width() - nX)*0.5), 0) ,Size(nX,aOutputSize.Height()));
84 m_aIconControl.ArrangeIcons();
86 // -----------------------------------------------------------------------------
87 void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
89 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
90 if( bFont )
92 Font aFont;
93 aFont = rStyleSettings.GetFieldFont();
94 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
95 SetPointFont( aFont );
98 if( bForeground || bFont )
100 SetTextColor( rStyleSettings.GetFieldTextColor() );
101 SetTextFillColor();
104 if( bBackground )
105 SetBackground( rStyleSettings.GetFieldColor() );
107 // -----------------------------------------------------------------------
108 void OApplicationSwapWindow::DataChanged( const DataChangedEvent& rDCEvt )
110 Window::DataChanged( rDCEvt );
111 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
112 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
113 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
114 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
115 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
117 ImplInitSettings( sal_True, sal_True, sal_True );
118 Invalidate();
121 // -----------------------------------------------------------------------------
122 void OApplicationSwapWindow::clearSelection()
124 m_aIconControl.SetNoSelection();
125 sal_uLong nPos = 0;
126 SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
127 if ( pEntry )
128 m_aIconControl.InvalidateEntry(pEntry);
129 m_aIconControl.GetClickHdl().Call(&m_aIconControl);
132 // -----------------------------------------------------------------------------
133 void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
135 m_aIconControl.CreateAutoMnemonics( _rMnemonics );
138 // -----------------------------------------------------------------------------
139 bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent& _rEvent )
141 const KeyCode& rKeyCode = _rEvent.GetKeyCode();
142 if ( rKeyCode.GetModifier() == KEY_MOD2 )
143 return m_aIconControl.DoKeyInput( _rEvent );
145 // not handled
146 return false;
149 // -----------------------------------------------------------------------------
150 ElementType OApplicationSwapWindow::getElementType() const
152 sal_uLong nPos = 0;
153 SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
154 return ( pEntry ) ? *static_cast<ElementType*>(pEntry->GetUserData()) : E_NONE;
157 // -----------------------------------------------------------------------------
158 bool OApplicationSwapWindow::onContainerSelected( ElementType _eType )
160 if ( m_eLastType == _eType )
161 return true;
163 if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
165 if ( _eType != E_NONE )
166 m_eLastType = _eType;
167 return true;
170 PostUserEvent( LINK( this, OApplicationSwapWindow, ChangeToLastSelected ) );
171 return false;
174 // -----------------------------------------------------------------------------
175 IMPL_LINK(OApplicationSwapWindow, OnContainerSelectHdl, SvtIconChoiceCtrl*, _pControl)
177 sal_uLong nPos = 0;
178 SvxIconChoiceCtrlEntry* pEntry = _pControl->GetSelectedEntry( nPos );
179 ElementType eType = E_NONE;
180 if ( pEntry )
182 eType = *static_cast<ElementType*>(pEntry->GetUserData());
183 onContainerSelected( eType ); // i87582
186 return 1L;
188 //------------------------------------------------------------------------------
189 IMPL_LINK_NOARG(OApplicationSwapWindow, ChangeToLastSelected)
191 selectContainer(m_eLastType);
192 return 0L;
194 // -----------------------------------------------------------------------------
195 void OApplicationSwapWindow::selectContainer(ElementType _eType)
197 sal_uLong nCount = m_aIconControl.GetEntryCount();
198 SvxIconChoiceCtrlEntry* pEntry = NULL;
199 for (sal_uLong i=0; i < nCount; ++i)
201 pEntry = m_aIconControl.GetEntry(i);
202 if ( pEntry && *static_cast<ElementType*>(pEntry->GetUserData()) == _eType )
203 break;
204 pEntry = NULL;
207 if ( pEntry )
208 m_aIconControl.SetCursor(pEntry); // this call also initiates a onContainerSelected call
209 else
210 onContainerSelected( _eType );
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */