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