1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
)
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
);
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();
84 aFont
= rStyleSettings
.GetFieldFont();
85 aFont
.SetColor( rStyleSettings
.GetWindowTextColor() );
86 SetPointFont( aFont
);
89 if( bForeground
|| bFont
)
91 SetTextColor( rStyleSettings
.GetFieldTextColor() );
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
);
112 // -----------------------------------------------------------------------------
113 void OApplicationSwapWindow::clearSelection()
115 m_aIconControl
.SetNoSelection();
117 SvxIconChoiceCtrlEntry
* pEntry
= m_aIconControl
.GetSelectedEntry(nPos
);
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
);
140 // -----------------------------------------------------------------------------
141 ElementType
OApplicationSwapWindow::getElementType() const
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
)
154 if ( m_rBorderWin
.getView()->getAppController().onContainerSelect( _eType
) )
156 if ( _eType
!= E_NONE
)
157 m_eLastType
= _eType
;
161 PostUserEvent( LINK( this, OApplicationSwapWindow
, ChangeToLastSelected
) );
165 // -----------------------------------------------------------------------------
166 IMPL_LINK(OApplicationSwapWindow
, OnContainerSelectHdl
, SvtIconChoiceCtrl
*, _pControl
)
169 SvxIconChoiceCtrlEntry
* pEntry
= _pControl
->GetSelectedEntry( nPos
);
170 ElementType eType
= E_NONE
;
173 eType
= *static_cast<ElementType
*>(pEntry
->GetUserData());
174 onContainerSelected( eType
); // i87582
179 //------------------------------------------------------------------------------
180 IMPL_LINK_NOARG(OApplicationSwapWindow
, ChangeToLastSelected
)
182 selectContainer(m_eLastType
);
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
)
199 m_aIconControl
.SetCursor(pEntry
); // this call also initiates a onContainerSelected call
201 onContainerSelected( _eType
);
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */