bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / app / AppSwapWindow.cxx
blob2eba13004c3be6a773c2d7a32ff60db8275f8401
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "AppSwapWindow.hxx"
21 #include <tools/debug.hxx>
22 #include "dbaccess_helpid.hrc"
23 #include "dbu_app.hrc"
24 #include "AppView.hxx"
25 #include <vcl/svapp.hxx>
26 #include <vcl/syswin.hxx>
27 #include <vcl/menu.hxx>
28 #include <vcl/mnemonic.hxx>
29 #include "IApplicationController.hxx"
31 #include <memory>
33 using namespace ::dbaui;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::container;
39 //==================================================================
40 // class OApplicationSwapWindow
41 DBG_NAME(OApplicationSwapWindow)
42 //==================================================================
43 OApplicationSwapWindow::OApplicationSwapWindow( Window* _pParent, OAppBorderWindow& _rBorderWindow )
44 :Window(_pParent,WB_DIALOGCONTROL )
45 ,m_aIconControl(this)
46 ,m_eLastType(E_NONE)
47 ,m_rBorderWin( _rBorderWindow )
49 DBG_CTOR(OApplicationSwapWindow,NULL);
51 ImplInitSettings( sal_True, sal_True, sal_True );
53 m_aIconControl.SetClickHdl(LINK(this, OApplicationSwapWindow, OnContainerSelectHdl));
54 m_aIconControl.setControlActionListener( &m_rBorderWin.getView()->getAppController() );
55 m_aIconControl.SetHelpId(HID_APP_SWAP_ICONCONTROL);
56 m_aIconControl.Show();
58 // -----------------------------------------------------------------------------
59 OApplicationSwapWindow::~OApplicationSwapWindow()
62 DBG_DTOR(OApplicationSwapWindow,NULL);
64 // -----------------------------------------------------------------------------
65 void OApplicationSwapWindow::Resize()
67 Size aFLSize = LogicToPixel( Size( 8, 0 ), MAP_APPFONT );
68 long nX = 0;
69 if ( m_aIconControl.GetEntryCount() != 0 )
70 nX = m_aIconControl.GetBoundingBox( m_aIconControl.GetEntry(0) ).GetWidth() + aFLSize.Width();
72 Size aOutputSize = GetOutputSize();
74 m_aIconControl.SetPosSizePixel( Point(static_cast<long>((aOutputSize.Width() - nX)*0.5), 0) ,Size(nX,aOutputSize.Height()));
75 m_aIconControl.ArrangeIcons();
77 // -----------------------------------------------------------------------------
78 void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
80 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
81 if( bFont )
83 Font aFont;
84 aFont = rStyleSettings.GetFieldFont();
85 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
86 SetPointFont( aFont );
89 if( bForeground || bFont )
91 SetTextColor( rStyleSettings.GetFieldTextColor() );
92 SetTextFillColor();
95 if( bBackground )
96 SetBackground( rStyleSettings.GetFieldColor() );
98 // -----------------------------------------------------------------------
99 void OApplicationSwapWindow::DataChanged( const DataChangedEvent& rDCEvt )
101 Window::DataChanged( rDCEvt );
102 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
103 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
104 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
105 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
106 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
108 ImplInitSettings( sal_True, sal_True, sal_True );
109 Invalidate();
112 // -----------------------------------------------------------------------------
113 void OApplicationSwapWindow::clearSelection()
115 m_aIconControl.SetNoSelection();
116 sal_uLong nPos = 0;
117 SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
118 if ( pEntry )
119 m_aIconControl.InvalidateEntry(pEntry);
120 m_aIconControl.GetClickHdl().Call(&m_aIconControl);
123 // -----------------------------------------------------------------------------
124 void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
126 m_aIconControl.CreateAutoMnemonics( _rMnemonics );
129 // -----------------------------------------------------------------------------
130 bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent& _rEvent )
132 const KeyCode& rKeyCode = _rEvent.GetKeyCode();
133 if ( rKeyCode.GetModifier() == KEY_MOD2 )
134 return m_aIconControl.DoKeyInput( _rEvent );
136 // not handled
137 return false;
140 // -----------------------------------------------------------------------------
141 ElementType OApplicationSwapWindow::getElementType() const
143 sal_uLong nPos = 0;
144 SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
145 return ( pEntry ) ? *static_cast<ElementType*>(pEntry->GetUserData()) : E_NONE;
148 // -----------------------------------------------------------------------------
149 bool OApplicationSwapWindow::onContainerSelected( ElementType _eType )
151 if ( m_eLastType == _eType )
152 return true;
154 if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
156 if ( _eType != E_NONE )
157 m_eLastType = _eType;
158 return true;
161 PostUserEvent( LINK( this, OApplicationSwapWindow, ChangeToLastSelected ) );
162 return false;
165 // -----------------------------------------------------------------------------
166 IMPL_LINK(OApplicationSwapWindow, OnContainerSelectHdl, SvtIconChoiceCtrl*, _pControl)
168 sal_uLong nPos = 0;
169 SvxIconChoiceCtrlEntry* pEntry = _pControl->GetSelectedEntry( nPos );
170 ElementType eType = E_NONE;
171 if ( pEntry )
173 eType = *static_cast<ElementType*>(pEntry->GetUserData());
174 onContainerSelected( eType ); // i87582
177 return 1L;
179 //------------------------------------------------------------------------------
180 IMPL_LINK_NOARG(OApplicationSwapWindow, ChangeToLastSelected)
182 selectContainer(m_eLastType);
183 return 0L;
185 // -----------------------------------------------------------------------------
186 void OApplicationSwapWindow::selectContainer(ElementType _eType)
188 sal_uLong nCount = m_aIconControl.GetEntryCount();
189 SvxIconChoiceCtrlEntry* pEntry = NULL;
190 for (sal_uLong i=0; i < nCount; ++i)
192 pEntry = m_aIconControl.GetEntry(i);
193 if ( pEntry && *static_cast<ElementType*>(pEntry->GetUserData()) == _eType )
194 break;
195 pEntry = NULL;
198 if ( pEntry )
199 m_aIconControl.SetCursor(pEntry); // this call also initiates a onContainerSelected call
200 else
201 onContainerSelected( _eType );
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */