Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
30 :
31 : #include <memory>
32 :
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;
38 :
39 : //==================================================================
40 : // class OApplicationSwapWindow
41 : DBG_NAME(OApplicationSwapWindow)
42 : //==================================================================
43 0 : OApplicationSwapWindow::OApplicationSwapWindow( Window* _pParent, OAppBorderWindow& _rBorderWindow )
44 : :Window(_pParent,WB_DIALOGCONTROL )
45 : ,m_aIconControl(this)
46 : ,m_eLastType(E_NONE)
47 0 : ,m_rBorderWin( _rBorderWindow )
48 : {
49 : DBG_CTOR(OApplicationSwapWindow,NULL);
50 :
51 0 : ImplInitSettings( sal_True, sal_True, sal_True );
52 :
53 0 : m_aIconControl.SetClickHdl(LINK(this, OApplicationSwapWindow, OnContainerSelectHdl));
54 0 : m_aIconControl.setControlActionListener( &m_rBorderWin.getView()->getAppController() );
55 0 : m_aIconControl.SetHelpId(HID_APP_SWAP_ICONCONTROL);
56 0 : m_aIconControl.Show();
57 0 : }
58 : // -----------------------------------------------------------------------------
59 0 : OApplicationSwapWindow::~OApplicationSwapWindow()
60 : {
61 :
62 : DBG_DTOR(OApplicationSwapWindow,NULL);
63 0 : }
64 : // -----------------------------------------------------------------------------
65 0 : void OApplicationSwapWindow::Resize()
66 : {
67 0 : Size aFLSize = LogicToPixel( Size( 8, 0 ), MAP_APPFONT );
68 0 : long nX = 0;
69 0 : if ( m_aIconControl.GetEntryCount() != 0 )
70 0 : nX = m_aIconControl.GetBoundingBox( m_aIconControl.GetEntry(0) ).GetWidth() + aFLSize.Width();
71 :
72 0 : Size aOutputSize = GetOutputSize();
73 :
74 0 : m_aIconControl.SetPosSizePixel( Point(static_cast<long>((aOutputSize.Width() - nX)*0.5), 0) ,Size(nX,aOutputSize.Height()));
75 0 : m_aIconControl.ArrangeIcons();
76 0 : }
77 : // -----------------------------------------------------------------------------
78 0 : void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
79 : {
80 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
81 0 : if( bFont )
82 : {
83 0 : Font aFont;
84 0 : aFont = rStyleSettings.GetFieldFont();
85 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
86 0 : SetPointFont( aFont );
87 : }
88 :
89 0 : if( bForeground || bFont )
90 : {
91 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
92 0 : SetTextFillColor();
93 : }
94 :
95 0 : if( bBackground )
96 0 : SetBackground( rStyleSettings.GetFieldColor() );
97 0 : }
98 : // -----------------------------------------------------------------------
99 0 : void OApplicationSwapWindow::DataChanged( const DataChangedEvent& rDCEvt )
100 : {
101 0 : Window::DataChanged( rDCEvt );
102 0 : if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
103 0 : (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
104 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
105 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
106 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
107 : {
108 0 : ImplInitSettings( sal_True, sal_True, sal_True );
109 0 : Invalidate();
110 : }
111 0 : }
112 : // -----------------------------------------------------------------------------
113 0 : void OApplicationSwapWindow::clearSelection()
114 : {
115 0 : m_aIconControl.SetNoSelection();
116 0 : sal_uLong nPos = 0;
117 0 : SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
118 0 : if ( pEntry )
119 0 : m_aIconControl.InvalidateEntry(pEntry);
120 0 : m_aIconControl.GetClickHdl().Call(&m_aIconControl);
121 0 : }
122 :
123 : // -----------------------------------------------------------------------------
124 0 : void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator& _rMnemonics )
125 : {
126 0 : m_aIconControl.CreateAutoMnemonics( _rMnemonics );
127 0 : }
128 :
129 : // -----------------------------------------------------------------------------
130 0 : bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent& _rEvent )
131 : {
132 0 : const KeyCode& rKeyCode = _rEvent.GetKeyCode();
133 0 : if ( rKeyCode.GetModifier() == KEY_MOD2 )
134 0 : return m_aIconControl.DoKeyInput( _rEvent );
135 :
136 : // not handled
137 0 : return false;
138 : }
139 :
140 : // -----------------------------------------------------------------------------
141 0 : ElementType OApplicationSwapWindow::getElementType() const
142 : {
143 0 : sal_uLong nPos = 0;
144 0 : SvxIconChoiceCtrlEntry* pEntry = m_aIconControl.GetSelectedEntry(nPos);
145 0 : return ( pEntry ) ? *static_cast<ElementType*>(pEntry->GetUserData()) : E_NONE;
146 : }
147 :
148 : // -----------------------------------------------------------------------------
149 0 : bool OApplicationSwapWindow::onContainerSelected( ElementType _eType )
150 : {
151 0 : if ( m_eLastType == _eType )
152 0 : return true;
153 :
154 0 : if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
155 : {
156 0 : if ( _eType != E_NONE )
157 0 : m_eLastType = _eType;
158 0 : return true;
159 : }
160 :
161 0 : PostUserEvent( LINK( this, OApplicationSwapWindow, ChangeToLastSelected ) );
162 0 : return false;
163 : }
164 :
165 : // -----------------------------------------------------------------------------
166 0 : IMPL_LINK(OApplicationSwapWindow, OnContainerSelectHdl, SvtIconChoiceCtrl*, _pControl)
167 : {
168 0 : sal_uLong nPos = 0;
169 0 : SvxIconChoiceCtrlEntry* pEntry = _pControl->GetSelectedEntry( nPos );
170 0 : ElementType eType = E_NONE;
171 0 : if ( pEntry )
172 : {
173 0 : eType = *static_cast<ElementType*>(pEntry->GetUserData());
174 0 : onContainerSelected( eType ); // i87582
175 : }
176 :
177 0 : return 1L;
178 : }
179 : //------------------------------------------------------------------------------
180 0 : IMPL_LINK_NOARG(OApplicationSwapWindow, ChangeToLastSelected)
181 : {
182 0 : selectContainer(m_eLastType);
183 0 : return 0L;
184 : }
185 : // -----------------------------------------------------------------------------
186 0 : void OApplicationSwapWindow::selectContainer(ElementType _eType)
187 : {
188 0 : sal_uLong nCount = m_aIconControl.GetEntryCount();
189 0 : SvxIconChoiceCtrlEntry* pEntry = NULL;
190 0 : for (sal_uLong i=0; i < nCount; ++i)
191 : {
192 0 : pEntry = m_aIconControl.GetEntry(i);
193 0 : if ( pEntry && *static_cast<ElementType*>(pEntry->GetUserData()) == _eType )
194 0 : break;
195 0 : pEntry = NULL;
196 : }
197 :
198 0 : if ( pEntry )
199 0 : m_aIconControl.SetCursor(pEntry); // this call also initiates a onContainerSelected call
200 : else
201 0 : onContainerSelected( _eType );
202 0 : }
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|