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