1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AppSwapWindow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_APPSWAPWINDOW_HXX
34 #include "AppSwapWindow.hxx"
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
39 #ifndef _DBA_DBACCESS_HELPID_HRC_
40 #include "dbaccess_helpid.hrc"
43 #include "dbu_app.hrc"
45 #ifndef DBAUI_APPVIEW_HXX
46 #include "AppView.hxx"
49 #include <vcl/svapp.hxx>
51 #ifndef _SV_SYSWIN_HXX
52 #include <vcl/syswin.hxx>
55 #include <vcl/menu.hxx>
57 #ifndef _SV_MNEMONIC_HXX
58 #include <vcl/mnemonic.hxx>
60 #include "IApplicationController.hxx"
64 using namespace ::dbaui
;
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::sdbc
;
67 using namespace ::com::sun::star::lang
;
68 using namespace ::com::sun::star::container
;
70 //==================================================================
71 // class OApplicationSwapWindow
72 DBG_NAME(OApplicationSwapWindow
)
73 //==================================================================
74 OApplicationSwapWindow::OApplicationSwapWindow( Window
* _pParent
, OAppBorderWindow
& _rBorderWindow
)
75 :Window(_pParent
,WB_DIALOGCONTROL
)
78 ,m_rBorderWin( _rBorderWindow
)
80 DBG_CTOR(OApplicationSwapWindow
,NULL
);
81 // SetCompoundControl( TRUE );
83 ImplInitSettings( sal_True
, sal_True
, sal_True
);
85 m_aIconControl
.SetClickHdl(LINK(this, OApplicationSwapWindow
, OnContainerSelectHdl
));
86 m_aIconControl
.setControlActionListener( &m_rBorderWin
.getView()->getAppController() );
87 m_aIconControl
.SetHelpId(HID_APP_SWAP_ICONCONTROL
);
88 m_aIconControl
.Show();
89 //m_aIconControl.Enable(TRUE);
91 // -----------------------------------------------------------------------------
92 OApplicationSwapWindow::~OApplicationSwapWindow()
95 DBG_DTOR(OApplicationSwapWindow
,NULL
);
97 // -----------------------------------------------------------------------------
98 void OApplicationSwapWindow::Resize()
100 Size aFLSize
= LogicToPixel( Size( 8, 0 ), MAP_APPFONT
);
102 if ( m_aIconControl
.GetEntryCount() != 0 )
103 nX
= m_aIconControl
.GetBoundingBox( m_aIconControl
.GetEntry(0) ).GetWidth() + aFLSize
.Width();
105 Size aOutputSize
= GetOutputSize();
107 m_aIconControl
.SetPosSizePixel( Point(static_cast<long>((aOutputSize
.Width() - nX
)*0.5), 0) ,Size(nX
,aOutputSize
.Height()));
108 m_aIconControl
.ArrangeIcons();
110 // -----------------------------------------------------------------------------
111 void OApplicationSwapWindow::ImplInitSettings( sal_Bool bFont
, sal_Bool bForeground
, sal_Bool bBackground
)
113 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
117 aFont
= rStyleSettings
.GetFieldFont();
118 aFont
.SetColor( rStyleSettings
.GetWindowTextColor() );
119 SetPointFont( aFont
);
122 if( bForeground
|| bFont
)
124 SetTextColor( rStyleSettings
.GetFieldTextColor() );
129 SetBackground( rStyleSettings
.GetFieldColor() );
131 // -----------------------------------------------------------------------
132 void OApplicationSwapWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
134 Window::DataChanged( rDCEvt
);
135 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
136 (rDCEvt
.GetType() == DATACHANGED_DISPLAY
) ||
137 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
138 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
139 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
141 ImplInitSettings( sal_True
, sal_True
, sal_True
);
145 // -----------------------------------------------------------------------------
146 void OApplicationSwapWindow::clearSelection()
148 m_aIconControl
.SetNoSelection();
150 SvxIconChoiceCtrlEntry
* pEntry
= m_aIconControl
.GetSelectedEntry(nPos
);
152 m_aIconControl
.InvalidateEntry(pEntry
);
153 m_aIconControl
.GetClickHdl().Call(&m_aIconControl
);
156 // -----------------------------------------------------------------------------
157 void OApplicationSwapWindow::createIconAutoMnemonics( MnemonicGenerator
& _rMnemonics
)
159 m_aIconControl
.CreateAutoMnemonics( _rMnemonics
);
162 // -----------------------------------------------------------------------------
163 bool OApplicationSwapWindow::interceptKeyInput( const KeyEvent
& _rEvent
)
165 const KeyCode
& rKeyCode
= _rEvent
.GetKeyCode();
166 if ( rKeyCode
.GetModifier() == KEY_MOD2
)
167 return m_aIconControl
.DoKeyInput( _rEvent
);
173 // -----------------------------------------------------------------------------
174 ElementType
OApplicationSwapWindow::getElementType() const
177 SvxIconChoiceCtrlEntry
* pEntry
= m_aIconControl
.GetSelectedEntry(nPos
);
178 return ( pEntry
) ? *static_cast<ElementType
*>(pEntry
->GetUserData()) : E_NONE
;
181 // -----------------------------------------------------------------------------
182 bool OApplicationSwapWindow::onContainerSelected( ElementType _eType
)
184 if ( m_eLastType
== _eType
)
187 if ( m_rBorderWin
.getView()->getAppController().onContainerSelect( _eType
) )
189 if ( _eType
!= E_NONE
)
190 m_eLastType
= _eType
;
192 } // if ( m_rBorderWin.getView()->getAppController().onContainerSelect( _eType ) )
194 PostUserEvent( LINK( this, OApplicationSwapWindow
, ChangeToLastSelected
) );
198 // -----------------------------------------------------------------------------
199 IMPL_LINK(OApplicationSwapWindow
, OnContainerSelectHdl
, SvtIconChoiceCtrl
*, _pControl
)
202 SvxIconChoiceCtrlEntry
* pEntry
= _pControl
->GetSelectedEntry( nPos
);
203 ElementType eType
= E_NONE
;
206 eType
= *static_cast<ElementType
*>(pEntry
->GetUserData());
207 onContainerSelected( eType
); // i87582
212 //------------------------------------------------------------------------------
213 IMPL_LINK(OApplicationSwapWindow
, ChangeToLastSelected
, void*, EMPTYARG
)
215 selectContainer(m_eLastType
);
218 // -----------------------------------------------------------------------------
219 void OApplicationSwapWindow::selectContainer(ElementType _eType
)
221 ULONG nCount
= m_aIconControl
.GetEntryCount();
222 SvxIconChoiceCtrlEntry
* pEntry
= NULL
;
223 for (ULONG i
=0; i
< nCount
; ++i
)
225 pEntry
= m_aIconControl
.GetEntry(i
);
226 if ( pEntry
&& *static_cast<ElementType
*>(pEntry
->GetUserData()) == _eType
)
232 m_aIconControl
.SetCursor(pEntry
); // this call also initiates a onContainerSelected call
234 onContainerSelected( _eType
);