Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : // autogen include statement, do not remove
30 : :
31 : : #include <classes/fwktabwindow.hxx>
32 : : #include "framework.hrc"
33 : : #include <classes/fwkresid.hxx>
34 : :
35 : : #include <com/sun/star/awt/PosSize.hpp>
36 : : #include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
37 : : #include <com/sun/star/awt/XContainerWindowProvider.hpp>
38 : : #include <com/sun/star/awt/XWindow.hpp>
39 : : #include <com/sun/star/awt/XWindowPeer.hpp>
40 : : #include <com/sun/star/awt/XControl.hpp>
41 : : #include <com/sun/star/beans/NamedValue.hpp>
42 : : #include <com/sun/star/graphic/XGraphic.hpp>
43 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 : :
45 : : #include <comphelper/processfactory.hxx>
46 : : #include <toolkit/helper/vclunohelper.hxx>
47 : : #include <tools/stream.hxx>
48 : : #include <tools/diagnose_ex.h>
49 : : #include <vcl/bitmap.hxx>
50 : : #include <vcl/image.hxx>
51 : : #include <vcl/msgbox.hxx>
52 : :
53 : : const char SERVICENAME_WINPROVIDER[] = "com.sun.star.awt.ContainerWindowProvider";
54 : : const char EXTERNAL_EVENT[] = "external_event";
55 : : const char INITIALIZE_METHOD[] = "initialize";
56 : :
57 : : using namespace ::com::sun::star;
58 : :
59 : : namespace framework
60 : : {
61 : :
62 : : // class FwkTabControl ---------------------------------------------------
63 : 0 : FwkTabControl::FwkTabControl( Window* pParent, const ResId& rResId ) :
64 : :
65 : 0 : TabControl( pParent, rResId )
66 : : {
67 : 0 : }
68 : :
69 : : // -----------------------------------------------------------------------
70 : :
71 : 0 : void FwkTabControl::BroadcastEvent( sal_uLong nEvent )
72 : : {
73 [ # # ][ # # ]: 0 : if ( VCLEVENT_TABPAGE_ACTIVATE == nEvent || VCLEVENT_TABPAGE_DEACTIVATE == nEvent )
74 : 0 : ImplCallEventListeners( nEvent, (void*)(sal_uIntPtr)GetCurPageId() );
75 : : else
76 : : {
77 : : SAL_WARN( "framework", "FwkTabControl::BroadcastEvent(): illegal event" );
78 : : }
79 : 0 : }
80 : :
81 : : // class FwkTabPage ------------------------------------------------
82 : :
83 : 0 : FwkTabPage::FwkTabPage(
84 : : Window* pParent, const rtl::OUString& rPageURL,
85 : : const css::uno::Reference< css::awt::XContainerWindowEventHandler >& rEventHdl,
86 : : const css::uno::Reference< css::awt::XContainerWindowProvider >& rProvider ) :
87 : :
88 : : TabPage( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_CHILDDLGCTRL ),
89 : :
90 : : m_sPageURL ( rPageURL ),
91 : : m_xEventHdl ( rEventHdl ),
92 : 0 : m_xWinProvider ( rProvider )
93 : :
94 : : {
95 : 0 : }
96 : :
97 : : // -----------------------------------------------------------------------
98 : :
99 : 0 : FwkTabPage::~FwkTabPage()
100 : : {
101 [ # # ]: 0 : Hide();
102 [ # # ]: 0 : DeactivatePage();
103 [ # # ]: 0 : }
104 : :
105 : : // -----------------------------------------------------------------------
106 : :
107 : 0 : void FwkTabPage::CreateDialog()
108 : : {
109 : : try
110 : : {
111 : 0 : uno::Reference< uno::XInterface > xHandler;
112 [ # # ]: 0 : if ( m_xEventHdl.is() )
113 [ # # ]: 0 : xHandler = m_xEventHdl;
114 : :
115 [ # # ][ # # ]: 0 : uno::Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), uno::UNO_QUERY );
116 : : m_xPage = uno::Reference < awt::XWindow >(
117 [ # # ]: 0 : m_xWinProvider->createContainerWindow(
118 [ # # ][ # # ]: 0 : m_sPageURL, rtl::OUString(), xParent, xHandler ), uno::UNO_QUERY );
[ # # ]
119 : :
120 [ # # ]: 0 : uno::Reference< awt::XControl > xPageControl( m_xPage, uno::UNO_QUERY );
121 [ # # ]: 0 : if ( xPageControl.is() )
122 : : {
123 [ # # ][ # # ]: 0 : uno::Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
124 [ # # ]: 0 : if ( xWinPeer.is() )
125 : : {
126 [ # # ]: 0 : Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
127 [ # # ]: 0 : if ( pWindow )
128 [ # # ][ # # ]: 0 : pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
129 : 0 : }
130 : : }
131 : :
132 [ # # ]: 0 : CallMethod( rtl::OUString(INITIALIZE_METHOD) );
[ # # # ]
133 : : }
134 : 0 : catch ( const lang::IllegalArgumentException& )
135 : : {
136 : : SAL_WARN( "framework", "FwkTabPage::CreateDialog(): illegal argument" );
137 : : }
138 : 0 : catch ( const uno::Exception& )
139 : : {
140 : : SAL_WARN( "framework", "FwkTabPage::CreateDialog(): exception of XDialogProvider2::createContainerWindow()" );
141 : : }
142 : 0 : }
143 : :
144 : : // -----------------------------------------------------------------------
145 : :
146 : 0 : sal_Bool FwkTabPage::CallMethod( const rtl::OUString& rMethod )
147 : : {
148 : 0 : sal_Bool bRet = sal_False;
149 [ # # ]: 0 : if ( m_xEventHdl.is() )
150 : : {
151 : : try
152 : : {
153 [ # # ][ # # ]: 0 : bRet = m_xEventHdl->callHandlerMethod( m_xPage, uno::makeAny( rMethod ), rtl::OUString(EXTERNAL_EVENT) );
[ # # ][ # # ]
154 : : }
155 : 0 : catch ( const uno::Exception& )
156 : : {
157 : : DBG_UNHANDLED_EXCEPTION();
158 : : }
159 : : }
160 : 0 : return bRet;
161 : : }
162 : :
163 : : // -----------------------------------------------------------------------
164 : :
165 : 0 : void FwkTabPage::ActivatePage()
166 : : {
167 : 0 : TabPage::ActivatePage();
168 : :
169 [ # # ]: 0 : if ( !m_xPage.is() )
170 : 0 : CreateDialog();
171 : :
172 [ # # ]: 0 : if ( m_xPage.is() )
173 : : {
174 : 0 : Resize ();
175 : 0 : m_xPage->setVisible( sal_True );
176 : : }
177 : 0 : }
178 : :
179 : : // -----------------------------------------------------------------------
180 : :
181 : 0 : void FwkTabPage::DeactivatePage()
182 : : {
183 : 0 : TabPage::DeactivatePage();
184 : :
185 [ # # ]: 0 : if ( m_xPage.is() )
186 : 0 : m_xPage->setVisible( sal_False );
187 : 0 : }
188 : :
189 : : // -----------------------------------------------------------------------
190 : :
191 : 0 : void FwkTabPage::Resize()
192 : : {
193 [ # # ]: 0 : if ( m_xPage.is () )
194 : : {
195 [ # # ]: 0 : Size aSize = GetSizePixel();
196 : :
197 [ # # ][ # # ]: 0 : m_xPage->setPosSize( 0, 0, aSize.Width()-1 , aSize.Height()-1, awt::PosSize::POSSIZE );
198 : : }
199 : 0 : }
200 : :
201 : : // class FwkTabWindow ---------------------------------------------
202 : :
203 : 0 : FwkTabWindow::FwkTabWindow( Window* pParent ) :
204 : :
205 : : Window( pParent, FwkResId( WIN_TABWINDOW ) ),
206 : :
207 [ # # ][ # # ]: 0 : m_aTabCtrl ( this, FwkResId( TC_TABCONTROL ) )
[ # # ][ # # ]
208 : : {
209 [ # # ]: 0 : uno::Reference < lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
210 : : m_xWinProvider = uno::Reference < awt::XContainerWindowProvider >(
211 [ # # ][ # # ]: 0 : xFactory->createInstance( rtl::OUString(SERVICENAME_WINPROVIDER) ), uno::UNO_QUERY );
[ # # ][ # # ]
212 : :
213 [ # # ]: 0 : SetPaintTransparent(true);
214 : :
215 [ # # ]: 0 : m_aTabCtrl.SetActivatePageHdl( LINK( this, FwkTabWindow, ActivatePageHdl ) );
216 [ # # ]: 0 : m_aTabCtrl.SetDeactivatePageHdl( LINK( this, FwkTabWindow, DeactivatePageHdl ) );
217 [ # # ]: 0 : m_aTabCtrl.Show();
218 : 0 : }
219 : :
220 : : // -----------------------------------------------------------------------
221 : :
222 [ # # ]: 0 : FwkTabWindow::~FwkTabWindow()
223 : : {
224 [ # # ]: 0 : ClearEntryList();
225 [ # # ]: 0 : }
226 : :
227 : : // -----------------------------------------------------------------------
228 : :
229 : 0 : void FwkTabWindow::ClearEntryList()
230 : : {
231 : 0 : TabEntryList::const_iterator pIt;
232 [ # # ][ # # ]: 0 : for ( pIt = m_TabList.begin();
[ # # ]
233 : 0 : pIt != m_TabList.end();
234 : : ++pIt )
235 : : {
236 [ # # ][ # # ]: 0 : delete *pIt;
237 : : }
238 : :
239 : 0 : m_TabList.clear();
240 : 0 : }
241 : :
242 : : // -----------------------------------------------------------------------
243 : :
244 : 0 : bool FwkTabWindow::RemoveEntry( sal_Int32 nIndex )
245 : : {
246 : 0 : TabEntryList::iterator pIt;
247 [ # # ][ # # ]: 0 : for ( pIt = m_TabList.begin();
248 : 0 : pIt != m_TabList.end();
249 : : ++pIt )
250 : : {
251 [ # # ]: 0 : if ( (*pIt)->m_nIndex == nIndex )
252 : 0 : break;
253 : : }
254 : :
255 : : // remove entry from vector
256 [ # # ][ # # ]: 0 : if ( pIt != m_TabList.end())
257 : : {
258 [ # # ]: 0 : m_TabList.erase(pIt);
259 : 0 : return true;
260 : : }
261 : : else
262 : 0 : return false;
263 : : }
264 : :
265 : : // -----------------------------------------------------------------------
266 : 0 : TabEntry* FwkTabWindow::FindEntry( sal_Int32 nIndex ) const
267 : : {
268 : 0 : TabEntry* pEntry = NULL;
269 : :
270 : 0 : TabEntryList::const_iterator pIt;
271 [ # # ][ # # ]: 0 : for ( pIt = m_TabList.begin();
272 : 0 : pIt != m_TabList.end();
273 : : ++pIt )
274 : : {
275 [ # # ]: 0 : if ( (*pIt)->m_nIndex == nIndex )
276 : : {
277 : 0 : pEntry = *pIt;
278 : 0 : break;
279 : : }
280 : : }
281 : :
282 : 0 : return pEntry;
283 : : }
284 : :
285 : : // -----------------------------------------------------------------------
286 : :
287 : 0 : IMPL_LINK_NOARG(FwkTabWindow, ActivatePageHdl)
288 : : {
289 : 0 : const sal_uInt16 nId = m_aTabCtrl.GetCurPageId();
290 : 0 : FwkTabPage* pTabPage = static_cast< FwkTabPage* >( m_aTabCtrl.GetTabPage( nId ) );
291 [ # # ]: 0 : if ( !pTabPage )
292 : : {
293 : 0 : TabEntry* pEntry = FindEntry( nId );
294 [ # # ]: 0 : if ( pEntry )
295 : : {
296 [ # # ]: 0 : pTabPage = new FwkTabPage( &m_aTabCtrl, pEntry->m_sPageURL, pEntry->m_xEventHdl, m_xWinProvider );
297 : 0 : pEntry->m_pPage = pTabPage;
298 : 0 : m_aTabCtrl.SetTabPage( nId, pTabPage );
299 : 0 : pTabPage->Show();
300 : 0 : pTabPage->ActivatePage();
301 : : }
302 : : } else {
303 : 0 : pTabPage->ActivatePage();
304 : : }
305 : 0 : m_aTabCtrl.BroadcastEvent( VCLEVENT_TABPAGE_ACTIVATE );
306 : 0 : return 1;
307 : : }
308 : :
309 : : // -----------------------------------------------------------------------
310 : :
311 : 0 : IMPL_LINK_NOARG(FwkTabWindow, DeactivatePageHdl)
312 : : {
313 : 0 : m_aTabCtrl.BroadcastEvent( VCLEVENT_TABPAGE_DEACTIVATE );
314 : 0 : return 1;
315 : : }
316 : :
317 : : // -----------------------------------------------------------------------
318 : :
319 : 0 : void FwkTabWindow::AddEventListener( const Link& rEventListener )
320 : : {
321 : 0 : m_aTabCtrl.AddEventListener( rEventListener );
322 : 0 : }
323 : :
324 : 0 : void FwkTabWindow::RemoveEventListener( const Link& rEventListener )
325 : : {
326 : 0 : m_aTabCtrl.RemoveEventListener( rEventListener );
327 : 0 : }
328 : :
329 : : // -----------------------------------------------------------------------
330 : :
331 : 0 : FwkTabPage* FwkTabWindow::AddTabPage( sal_Int32 nIndex, const uno::Sequence< beans::NamedValue >& rProperties )
332 : : {
333 : 0 : ::rtl::OUString sTitle, sToolTip, sPageURL;
334 : 0 : uno::Reference< css::awt::XContainerWindowEventHandler > xEventHdl;
335 : 0 : uno::Reference< graphic::XGraphic > xImage;
336 : 0 : bool bDisabled = false;
337 : :
338 : 0 : sal_Int32 i = 0, nLen = rProperties.getLength();
339 [ # # ]: 0 : for ( i = 0; i < nLen; ++i )
340 : : {
341 : 0 : beans::NamedValue aValue = rProperties[i];
342 : 0 : ::rtl::OUString sName = aValue.Name;
343 : :
344 [ # # ]: 0 : if ( sName == "Title" )
345 : 0 : aValue.Value >>= sTitle;
346 [ # # ]: 0 : else if ( sName == "ToolTip" )
347 : 0 : aValue.Value >>= sToolTip;
348 [ # # ]: 0 : else if ( sName == "PageURL" )
349 : 0 : aValue.Value >>= sPageURL;
350 [ # # ]: 0 : else if ( sName == "EventHdl" )
351 [ # # ]: 0 : aValue.Value >>= xEventHdl;
352 [ # # ]: 0 : else if ( sName == "Image" )
353 [ # # ]: 0 : aValue.Value >>= xImage;
354 [ # # ]: 0 : else if ( sName == "Disabled" )
355 : 0 : aValue.Value >>= bDisabled;
356 : 0 : }
357 : :
358 [ # # ][ # # ]: 0 : TabEntry* pEntry = new TabEntry( nIndex, sPageURL, xEventHdl );
359 [ # # ]: 0 : m_TabList.push_back( pEntry );
360 : 0 : sal_uInt16 nIdx = static_cast< sal_uInt16 >( nIndex );
361 [ # # ][ # # ]: 0 : m_aTabCtrl.InsertPage( nIdx, sTitle );
[ # # ]
362 [ # # ]: 0 : if ( !sToolTip.isEmpty() )
363 [ # # ][ # # ]: 0 : m_aTabCtrl.SetHelpText( nIdx, sToolTip );
[ # # ]
364 [ # # ]: 0 : if ( xImage.is() )
365 [ # # ][ # # ]: 0 : m_aTabCtrl.SetPageImage( nIdx, Image( xImage ) );
[ # # ]
366 [ # # ]: 0 : if ( bDisabled )
367 [ # # ]: 0 : m_aTabCtrl.EnablePage( nIdx, false );
368 : :
369 : 0 : return pEntry->m_pPage;
370 : : }
371 : :
372 : : // -----------------------------------------------------------------------
373 : :
374 : 0 : void FwkTabWindow::ActivatePage( sal_Int32 nIndex )
375 : : {
376 : 0 : m_aTabCtrl.SetCurPageId( static_cast< sal_uInt16 >( nIndex ) );
377 : 0 : ActivatePageHdl( &m_aTabCtrl );
378 : 0 : }
379 : :
380 : : // -----------------------------------------------------------------------
381 : :
382 : 0 : void FwkTabWindow::RemovePage( sal_Int32 nIndex )
383 : : {
384 : 0 : TabEntry* pEntry = FindEntry(nIndex);
385 [ # # ]: 0 : if ( pEntry )
386 : : {
387 : 0 : m_aTabCtrl.RemovePage( static_cast< sal_uInt16 >( nIndex ) );
388 [ # # ]: 0 : if (RemoveEntry(nIndex))
389 [ # # ]: 0 : delete pEntry;
390 : : }
391 : 0 : }
392 : :
393 : : // -----------------------------------------------------------------------
394 : 0 : void FwkTabWindow::Resize()
395 : : {
396 [ # # ]: 0 : Size aPageSize = GetSizePixel();
397 [ # # ]: 0 : m_aTabCtrl.SetTabPageSizePixel( aPageSize );
398 : 0 : }
399 : :
400 : : } // namespace framework
401 : :
402 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|