1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <tools/rc.h>
25 //#define RESOURCE_PUBLISH_PROTECTED 1
26 #if RESOURCE_PUBLISH_PROTECTED
27 // ugh, override non-helpful proctection
28 #define protected public
29 #endif /* RESOURCE_PUBLISH_PROTECTED */
30 #include <tools/rc.hxx>
31 #undef protected
32 
33 
34 #include "wrapper.hxx"
35 
36 #include <awt/vclxplugin.hxx>
37 #include <awt/vclxtabcontrol.hxx>
38 #include <com/sun/star/awt/PosSize.hpp>
39 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
40 #include <com/sun/star/awt/WindowAttribute.hpp>
41 #include <com/sun/star/awt/XDialog2.hpp>
42 #include <com/sun/star/awt/XProgressBar.hpp>
43 #include <com/sun/star/awt/XSimpleTabController.hpp>
44 #include <com/sun/star/awt/XTabListener.hpp>
45 #include <com/sun/star/graphic/XGraphic.hpp>
46 #include <comphelper/processfactory.hxx>
47 #include <layout/core/factory.hxx>
48 #include <layout/core/localized-string.hxx>
49 #include <layout/core/root.hxx>
50 #include <toolkit/awt/vclxwindow.hxx>
51 #include <vcl/ctrl.hxx>
52 #include <vcl/dialog.hxx>
53 #include <vcl/image.hxx>
54 #include <vcl/tabctrl.hxx>
55 #include <vcl/tabpage.hxx>
56 #include <vcl/window.hxx>
57 
58 using namespace ::com::sun::star;
59 using rtl::OUString;
60 
61 namespace layout
62 {
63 
64 // Context bits ...
65 class ContextImpl
66 {
67     uno::Reference< awt::XLayoutRoot > mxRoot;
68     uno::Reference< container::XNameAccess > mxNameAccess;
69     PeerHandle mxTopLevel;
70 
71 public:
ContextImpl(char const * pPath)72     ContextImpl( char const *pPath )
73     {
74         uno::Sequence< uno::Any > aParams( 1 );
75         aParams[0] <<= OUString( pPath, strlen( pPath ), RTL_TEXTENCODING_UTF8 );
76 
77         uno::Reference< lang::XSingleServiceFactory > xFactory(
78             comphelper::createProcessComponent(
79                 OUString::createFromAscii( "com.sun.star.awt.Layout" ) ),
80             uno::UNO_QUERY );
81         if ( !xFactory.is() )
82         {
83             throw uno::RuntimeException(
84                 OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ),
85                 uno::Reference< uno::XInterface >() );
86         }
87         mxRoot = uno::Reference< awt::XLayoutRoot >(
88             xFactory->createInstanceWithArguments( aParams ),
89             uno::UNO_QUERY );
90 
91         mxNameAccess = uno::Reference< container::XNameAccess >( mxRoot, uno::UNO_QUERY );
92     }
93 
~ContextImpl()94     ~ContextImpl()
95     {
96     }
97 
getByName(const OUString & rName)98     PeerHandle getByName( const OUString &rName )
99     {
100         uno::Any val = mxNameAccess->getByName( rName );
101         PeerHandle xRet;
102         val >>= xRet;
103         return xRet;
104     }
getTopLevel()105     PeerHandle getTopLevel()
106     {
107         return mxTopLevel;
108     }
setTopLevel(PeerHandle xToplevel)109     void setTopLevel( PeerHandle xToplevel )
110     {
111         mxTopLevel = xToplevel;
112     }
getRoot()113     PeerHandle getRoot()
114     {
115         return mxRoot;
116     }
117 };
118 
Context(const char * pPath)119 Context::Context( const char *pPath )
120     : pImpl( new ContextImpl( pPath ) )
121 {
122 }
~Context()123 Context::~Context()
124 {
125     delete pImpl;
126     pImpl = NULL;
127 }
128 
setToplevel(PeerHandle xToplevel)129 void Context::setToplevel( PeerHandle xToplevel )
130 {
131     pImpl->setTopLevel( xToplevel );
132 }
133 
getToplevel()134 PeerHandle Context::getToplevel()
135 {
136     return pImpl->getTopLevel();
137 }
getRoot()138 PeerHandle Context::getRoot()
139 {
140     return pImpl->getRoot();
141 }
142 
GetPeerHandle(const char * id,sal_uInt32 nId) const143 PeerHandle Context::GetPeerHandle( const char *id, sal_uInt32 nId ) const
144 {
145     PeerHandle xHandle;
146     xHandle = pImpl->getByName( OUString( id, strlen( id ), RTL_TEXTENCODING_UTF8 ) );
147     if ( !xHandle.is() )
148     {
149         DBG_ERROR1( "Failed to fetch widget '%s'", id );
150     }
151 
152     if ( nId != 0 )
153     {
154         rtl::OString aStr = rtl::OString::valueOf( (sal_Int32) nId );
155         xHandle = GetPeerHandle( aStr.getStr(), 0 );
156     }
157     return xHandle;
158 }
159 
WindowImpl(Context * context,const PeerHandle & peer,Window * window)160 WindowImpl::WindowImpl (Context *context, const PeerHandle &peer, Window *window)
161     : mpWindow (window)
162     , mpCtx (context)
163     , mxWindow (peer, uno::UNO_QUERY)
164     , mxVclPeer (peer, uno::UNO_QUERY)
165     , mvclWindow (0)
166     , bFirstTimeVisible (true)
167 {
168 }
169 
~WindowImpl()170 WindowImpl::~WindowImpl ()
171 {
172     if (mpWindow)
173         mpWindow->mpImpl = 0;
174     if (mvclWindow)
175     {
176         VCLXWindow *v = mvclWindow->GetWindowPeer ();
177         v->SetWindow (0);
178         mvclWindow->SetComponentInterface (uno::Reference <awt::XWindowPeer> ());
179         mvclWindow->SetWindowPeer (uno::Reference <awt::XWindowPeer> (), 0);
180         delete mvclWindow;
181         mvclWindow = 0;
182     }
183 }
184 
wrapperGone()185 void WindowImpl::wrapperGone ()
186 {
187     mvclWindow = 0;
188     mpWindow->mpImpl = 0;
189     mpWindow = 0;
190     mpCtx = 0;
191     if ( mxWindow.is() )
192     {
193         uno::Reference< lang::XComponent > xComp( mxWindow, uno::UNO_QUERY );
194         mxWindow.clear ();
195         if ( xComp.is() )
196             xComp->dispose();
197     }
198 }
199 
disposing(lang::EventObject const &)200 void SAL_CALL WindowImpl::disposing (lang::EventObject const&)
201     throw (uno::RuntimeException)
202 {
203     if (mxWindow.is ())
204         mxWindow.clear ();
205 }
206 
getProperty(char const * name)207 uno::Any WindowImpl::getProperty (char const* name)
208 {
209     if ( !this || !mxVclPeer.is() )
210         return css::uno::Any();
211     return mxVclPeer->getProperty
212         ( rtl::OUString( name, strlen( name ), RTL_TEXTENCODING_ASCII_US ) );
213 }
214 
setProperty(char const * name,uno::Any any)215 void WindowImpl::setProperty (char const *name, uno::Any any)
216 {
217     if ( !this || !mxVclPeer.is() )
218         return;
219     mxVclPeer->setProperty
220         ( rtl::OUString( name, strlen( name ), RTL_TEXTENCODING_ASCII_US ), any );
221 }
222 
redraw(bool resize)223 void WindowImpl::redraw (bool resize)
224 {
225     uno::Reference <awt::XWindow> ref (mxWindow, uno::UNO_QUERY);
226     ::Window* window = VCLXWindow::GetImplementation (ref)->GetWindow ();
227     ::Window* parent = window->GetParent();
228     ::Rectangle r = Rectangle (parent->GetPosPixel (),
229                                parent->GetSizePixel ());
230     parent->Invalidate (r, INVALIDATE_CHILDREN | INVALIDATE_NOCHILDREN );
231     if (resize)
232         parent->SetPosSizePixel (0, 0, 1, 1, awt::PosSize::SIZE);
233     else
234         parent->SetPosSizePixel (0, 0, r.nRight - r.nLeft, r.nBottom - r.nTop,
235                                  awt::PosSize::SIZE);
236 }
237 
Window(WindowImpl * pImpl)238 Window::Window( WindowImpl *pImpl )
239     : mpImpl( pImpl )
240 {
241     mpImpl->mvclWindow = GetVCLXWindow () ? GetWindow () : 0;
242 }
243 
~Window()244 Window::~Window()
245 {
246     /* likely to be an UNO object - with floating references */
247     if (mpImpl)
248         mpImpl->wrapperGone ();
249     mpImpl = 0;
250 }
251 
252 ///IMPL_GET_IMPL( Control );
253 
254 static ControlImpl* null_control_impl = 0;
255 
getImpl() const256 ControlImpl &Control::getImpl () const
257 {
258     if (ControlImpl* c = static_cast<ControlImpl *>(mpImpl))
259         return *c;
260     return *null_control_impl;
261 }
262 
~Control()263 Control::~Control ()
264 {
265     SetGetFocusHdl (Link ());
266     SetLoseFocusHdl (Link ());
267 }
268 
setRes(ResId const & res)269 void Window::setRes (ResId const& res)
270 {
271 #if RESOURCE_PUBLISH_PROTECTED
272     // Resources are shut-off from use.  Is that really necessary?
273     Resource &r = *GetWindow ();
274     r.GetRes (res);
275 #else /* !RESOURCE_PUBLISH_PROTECTED */
276     //We *must* derive.  Is this also really necessary?
277     //Resource r (res);
278 
279     // ugh, I wonder which solution is cleaner...
280     class Resource_open_up : public Resource
281     {
282     public:
283         Resource_open_up (ResId const& r)
284             : Resource (r)
285         {
286         }
287         static sal_Int32 GetLongRes (void *p)
288         {
289             return Resource::GetLongRes (p);
290         }
291         void* GetClassRes ()
292         {
293             return Resource::GetClassRes ();
294         }
295         sal_Int32 ReadLongRes ()
296         {
297             return Resource::ReadLongRes ();
298         }
299         UniString ReadStringRes ()
300         {
301             return Resource::ReadStringRes ();
302         }
303         rtl::OString ReadByteStringRes()
304         {
305             return Resource::ReadByteStringRes();
306         }
307     };
308 
309     Resource_open_up r (res);
310 #endif /* !RESOURCE_PUBLISH_PROTECTED */
311     sal_uInt32 mask = r.ReadLongRes ();
312     if (mask & WINDOW_HELPID)
313         SetHelpId (r.ReadByteStringRes());
314     if ( mask & WINDOW_TEXT )
315         SetText( r.ReadStringRes ());
316 }
317 
SetParent(::Window * parent)318 void Window::SetParent( ::Window *parent )
319 {
320     uno::Reference <awt::XWindow> ref( GetPeer(), uno::UNO_QUERY );
321     if (VCLXWindow *vcl = VCLXWindow::GetImplementation( ref ))
322         if (::Window *window = vcl->GetWindow())
323             window->SetParent( parent );
324 }
325 
SetParent(Window * parent)326 void Window::SetParent( Window *parent )
327 {
328     /* Let's hear it for C++: poor man's dynamic binding.  */
329     parent->ParentSet (this);
330 }
331 
ParentSet(Window * window)332 void Window::ParentSet (Window *window)
333 {
334     window->SetParent (GetWindow ());
335 }
336 
getContext()337 Context *Window::getContext()
338 {
339     return this && mpImpl ? mpImpl->mpCtx : NULL;
340 }
341 
GetPeer() const342 PeerHandle Window::GetPeer() const
343 {
344     if ( !mpImpl )
345         return PeerHandle();
346     return mpImpl->mxWindow;
347 }
348 
GetRef() const349 uno::Reference<awt::XWindow> Window::GetRef() const
350 {
351     return uno::Reference <awt::XWindow> ( GetPeer(), uno::UNO_QUERY );
352 }
353 
GetVCLXWindow() const354 VCLXWindow* Window::GetVCLXWindow() const
355 {
356     return VCLXWindow::GetImplementation( GetRef() );
357 }
358 
GetWindow() const359 ::Window* Window::GetWindow() const
360 {
361     return GetVCLXWindow()->GetWindow();
362 }
363 
GetParent() const364 ::Window* Window::GetParent() const
365 {
366     return GetWindow()->GetParent();
367 }
368 
SetHelpId(const rtl::OString & id)369 void Window::SetHelpId( const rtl::OString& id )
370 {
371     GetWindow()->SetHelpId( id );
372 }
373 
GetHelpId() const374 const rtl::OString& Window::GetHelpId() const
375 {
376     return GetWindow()->GetHelpId();
377 }
378 
EnterWait()379 void Window::EnterWait ()
380 {
381     GetWindow()->EnterWait ();
382 }
LeaveWait()383 void Window::LeaveWait ()
384 {
385     GetWindow()->LeaveWait ();
386 }
IsWait() const387 bool Window::IsWait () const
388 {
389     return GetWindow()->IsWait ();
390 }
391 
IsVisible() const392 bool Window::IsVisible () const
393 {
394     if (GetWindow ())
395         return GetWindow()->IsVisible ();
396     return false;
397 }
398 
HasChildPathFocus(bool systemWindow) const399 bool Window::HasChildPathFocus (bool systemWindow) const
400 {
401     return GetWindow()->HasChildPathFocus (systemWindow);
402 }
403 
SetPosPixel(Point const &)404 void Window::SetPosPixel (Point const&)
405 {
406 }
407 
GetPosPixel() const408 Point Window::GetPosPixel () const
409 {
410     return Point ();
411 }
412 
SetSizePixel(Size const &)413 void Window::SetSizePixel (Size const&)
414 {
415 }
416 
SetPosSizePixel(Point const &,Size const &)417 void Window::SetPosSizePixel (Point const&, Size const&)
418 {
419 }
420 
GetSizePixel() const421 Size Window::GetSizePixel () const
422 {
423     return Size ();
424 }
425 
426 // void Window::Enable (bool enable, bool child);
427 // {
428 //     GetWindow ()->Enable (enable, child);
429 // }
430 
431 // void Window::Disable (bool child)
432 // {
433 //     GetWindow ()->Disable (child);
434 // }
435 
IsEnabled() const436 bool Window::IsEnabled () const
437 {
438     return GetWindow ()->IsEnabled ();
439 //     if (getImpl().mxWindow.is ())
440 //         return getImpl ().mxWindow->isEnabled ();
441 //     return false;
442 }
443 
EnableInput(bool enable,bool child)444 void Window::EnableInput (bool enable, bool child)
445 {
446     GetWindow ()->EnableInput (enable, child);
447 }
448 
IsInputEnabled() const449 bool Window::IsInputEnabled () const
450 {
451     return GetWindow ()->IsInputEnabled ();
452 }
453 
HasFocus() const454 bool Window::HasFocus () const
455 {
456     return GetWindow ()->HasFocus ();
457 }
458 
GetFont() const459 Font& Window::GetFont () const
460 {
461     return const_cast <Font&> (GetWindow ()->GetFont ());
462 }
463 
SetFont(Font const & font)464 void Window::SetFont (Font const& font)
465 {
466     GetWindow ()->SetFont (font);
467 }
468 
Invalidate(sal_uInt8 flags)469 void Window::Invalidate (sal_uInt8 flags)
470 {
471     GetWindow ()->Invalidate (flags);
472 }
473 
474 struct ToolkitVclPropsMap
475 {
476     WinBits vclStyle;
477     long initAttr;
478     const char *propName;
479 
480     // the value to give the prop to enable/disable it -- not the most brilliant
481     // type declaration and storage, but does the work... properties are
482     // either a boolean or a short since they are either a directly wrappers for
483     // a WinBit, or aggregates related (like Align for WB_LEFT, _RIGHT and _CENTER).
484     bool isBoolean;
485     short enableProp, disableProp;
486 };
487 
488 #define TYPE_BOOL  true
489 #define TYPE_SHORT false
490 #define NOTYPE     0
491 static const ToolkitVclPropsMap toolkitVclPropsMap[] =
492 {
493     { WB_BORDER,    awt::WindowAttribute::BORDER,    "Border", TYPE_SHORT, 1, 0 },
494     { WB_NOBORDER,    awt::VclWindowPeerAttribute::NOBORDER,    "Border", TYPE_SHORT, 0, 1 },
495     { WB_SIZEABLE,    awt::WindowAttribute::SIZEABLE,    NULL, NOTYPE, 0, 0 },
496     { WB_MOVEABLE,    awt::WindowAttribute::MOVEABLE,    NULL, NOTYPE, 0, 0 },
497     { WB_CLOSEABLE,    awt::WindowAttribute::CLOSEABLE,    NULL, NOTYPE, 0, 0 },
498 
499     { WB_HSCROLL,    awt::VclWindowPeerAttribute::HSCROLL,    NULL, NOTYPE, 0, 0 },
500     { WB_VSCROLL,    awt::VclWindowPeerAttribute::VSCROLL,    NULL, NOTYPE, 0, 0 },
501     { WB_LEFT,    awt::VclWindowPeerAttribute::LEFT,    "Align", TYPE_SHORT, 0, 0 },
502     { WB_CENTER,    awt::VclWindowPeerAttribute::CENTER,    "Align", TYPE_SHORT, 1, 0 },
503     { WB_RIGHT,    awt::VclWindowPeerAttribute::RIGHT,    "Align", TYPE_SHORT, 2, 0 },
504     { WB_SPIN,    awt::VclWindowPeerAttribute::SPIN,    NULL, NOTYPE, 0, 0 },
505     { WB_SORT,    awt::VclWindowPeerAttribute::SORT,    NULL, NOTYPE, 0, 0 },
506     { WB_DROPDOWN,    awt::VclWindowPeerAttribute::DROPDOWN,    "Dropdown",    TYPE_BOOL, 1, 0 },
507     { WB_DEFBUTTON,    awt::VclWindowPeerAttribute::DEFBUTTON,    "DefaultButton", TYPE_BOOL, 1, 0 },
508     { WB_READONLY,    awt::VclWindowPeerAttribute::READONLY,    NULL, NOTYPE, 0, 0 },
509     { WB_CLIPCHILDREN,    awt::VclWindowPeerAttribute::CLIPCHILDREN,    NULL, NOTYPE, 0, 0 },
510     { WB_GROUP,    awt::VclWindowPeerAttribute::GROUP,    NULL, NOTYPE, 0, 0 },
511 
512     { WB_OK,    awt::VclWindowPeerAttribute::OK,    NULL, NOTYPE, 0, 0 },
513     { WB_OK_CANCEL,    awt::VclWindowPeerAttribute::OK_CANCEL,    NULL, NOTYPE, 0, 0 },
514     { WB_YES_NO,    awt::VclWindowPeerAttribute::YES_NO,    NULL, NOTYPE, 0, 0 },
515     { WB_YES_NO_CANCEL,    awt::VclWindowPeerAttribute::YES_NO_CANCEL,    NULL, NOTYPE, 1, 0 },
516     { WB_RETRY_CANCEL,    awt::VclWindowPeerAttribute::RETRY_CANCEL,    NULL, NOTYPE, 1, 0 },
517     { WB_DEF_OK,    awt::VclWindowPeerAttribute::DEF_OK,    NULL, NOTYPE, 0, 0 },
518     { WB_DEF_CANCEL,    awt::VclWindowPeerAttribute::DEF_CANCEL,    NULL, NOTYPE, 1, 0 },
519     { WB_DEF_RETRY,    awt::VclWindowPeerAttribute::DEF_RETRY,    NULL, NOTYPE, 0, 0 },
520     { WB_DEF_YES,    awt::VclWindowPeerAttribute::DEF_YES,    NULL, NOTYPE, 0, 0 },
521     { WB_DEF_NO,    awt::VclWindowPeerAttribute::DEF_NO,    NULL, NOTYPE, 0, 0 },
522 
523     { WB_AUTOHSCROLL, awt::VclWindowPeerAttribute::AUTOHSCROLL, "AutoHScroll", TYPE_BOOL, 1, 0 },
524     { WB_AUTOVSCROLL, awt::VclWindowPeerAttribute::AUTOVSCROLL, "AutoVScroll",    TYPE_BOOL, 1, 0 },
525 
526     { WB_WORDBREAK,    0,    "MultiLine", TYPE_BOOL, 1, 0 },
527     { WB_NOPOINTERFOCUS,    0,    "FocusOnClick", TYPE_BOOL, 1, 0 },
528     { WB_TOGGLE,    0,    "Toggle", TYPE_BOOL, 1, 0 },
529     { WB_REPEAT,    0,    "Repeat", TYPE_BOOL, 1, 0 },
530     { WB_NOHIDESELECTION,    0,    "HideInactiveSelection", TYPE_BOOL, 1, 0 },
531 };
532 #undef TYPE_BOOL
533 #undef TYPE_SHORT
534 #undef NOTYPE
535 
536 static const int toolkitVclPropsMapLen =
537     sizeof( toolkitVclPropsMap ) / sizeof( ToolkitVclPropsMap );
538 
SetStyle(WinBits nStyle)539 void Window::SetStyle( WinBits nStyle )
540 {
541     uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer;
542     for (int i = 0; i < toolkitVclPropsMapLen; i++)
543     {
544         if ( toolkitVclPropsMap[ i ].propName )
545         {
546             short nValue;
547             if ( nStyle & toolkitVclPropsMap[ i ].vclStyle )
548                 nValue = toolkitVclPropsMap[ i ].enableProp;
549             else
550                 nValue = toolkitVclPropsMap[ i ].disableProp;
551             uno::Any aValue;
552             if ( toolkitVclPropsMap[ i ].isBoolean )
553                 aValue = uno::makeAny( (bool) nValue );
554             else
555                 aValue = uno::makeAny( (short) nValue );
556             mpImpl->setProperty( toolkitVclPropsMap[ i ].propName, aValue );
557         }
558     }
559 }
560 
GetStyle()561 WinBits Window::GetStyle()
562 {
563     uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer;
564     WinBits ret = 0;
565     for (int i = 0; i < toolkitVclPropsMapLen; i++)
566     {
567         if ( toolkitVclPropsMap[ i ].propName )
568         {
569             short nValue = 0;
570             if ( toolkitVclPropsMap[ i ].isBoolean )
571             {
572                 bool bValue = false;
573                 mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= bValue;
574                 nValue = bValue ? 1 : 0;
575             }
576             else
577                 mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= nValue;
578             if ( nValue == toolkitVclPropsMap[ i ].enableProp )
579                 ret |= toolkitVclPropsMap[i].vclStyle;
580         }
581     }
582     return ret;
583 }
584 
585 /* Unpleasant way to get an xToolkit pointer ... */
getToolkit()586 uno::Reference< awt::XToolkit > getToolkit()
587 {
588     static uno::Reference< awt::XToolkit > xToolkit;
589     if (!xToolkit.is())
590     {
591         // Urgh ...
592         xToolkit = uno::Reference< awt::XToolkit >(
593             ::comphelper::getProcessServiceFactory()->createInstance(
594                 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ),
595             uno::UNO_QUERY );
596         if ( !xToolkit.is() )
597             throw uno::RuntimeException(
598                 OUString( RTL_CONSTASCII_USTRINGPARAM( "failed to create toolkit!") ),
599                 uno::Reference< uno::XInterface >() );
600     }
601     return xToolkit;
602 }
603 
CreatePeer(Window * parent,WinBits nStyle,const char * pName)604 PeerHandle Window::CreatePeer( Window *parent, WinBits nStyle, const char *pName)
605 {
606     long nWinAttrbs = 0;
607     for (int i = 0; i < toolkitVclPropsMapLen; i++)
608         if ( nStyle & toolkitVclPropsMap[ i ].vclStyle )
609             nWinAttrbs |= toolkitVclPropsMap[ i ].initAttr;
610 
611     return layoutimpl::WidgetFactory::createWidget (getToolkit(), parent->GetPeer(), OUString::createFromAscii( pName ), nWinAttrbs);
612 }
613 
Enable(bool bEnable)614 void Window::Enable( bool bEnable )
615 {
616     if ( !getImpl().mxWindow.is() )
617         return;
618     getImpl().mxWindow->setEnable( bEnable );
619 }
620 
Show(bool bVisible)621 void Window::Show( bool bVisible )
622 {
623     if ( !getImpl().mxWindow.is() )
624         return;
625     getImpl().mxWindow->setVisible( bVisible );
626     if (!bVisible)
627         getImpl ().bFirstTimeVisible = true;
628     else if (GetParent() && getImpl().bFirstTimeVisible)
629     {
630         getImpl().redraw ();
631         getImpl().bFirstTimeVisible = false;
632     }
633 }
634 
GrabFocus()635 void Window::GrabFocus()
636 {
637     if ( !getImpl().mxWindow.is() )
638         return;
639     getImpl().mxWindow->setFocus();
640 }
641 
SetUpdateMode(bool mode)642 void Window::SetUpdateMode(bool mode)
643 {
644     GetWindow()->SetUpdateMode( mode );
645 }
646 
SetPointer(Pointer const & pointer)647 void Window::SetPointer( Pointer const& pointer )
648 {
649     GetWindow()->SetPointer( pointer );
650 }
651 
GetPointer() const652 Pointer const& Window::GetPointer() const
653 {
654     return GetWindow()->GetPointer();
655 }
656 
SetText(OUString const & str)657 void Window::SetText( OUString const& str )
658 {
659     GetWindow()->SetText( str );
660 }
661 
GetText() const662 String Window::GetText() const
663 {
664     return GetWindow()->GetText();
665 }
666 
GetCtrlTextWidth(OUString const &) const667 sal_Int32 Window::GetCtrlTextWidth (OUString const&) const
668 {
669     return 0;
670 }
671 
GetTextHeight() const672 sal_Int32 Window::GetTextHeight () const
673 {
674     return 0;
675 }
676 
LogicToPixel(Size const & size,MapMode const &) const677 Size Window::LogicToPixel( Size const& size, MapMode const&) const
678 {
679     return size;
680 }
681 
ControlImpl(Context * context,const PeerHandle & peer,Window * window)682 ControlImpl::ControlImpl (Context *context, const PeerHandle &peer, Window *window)
683     : WindowImpl( context, peer, window )
684 {
685 }
686 
~ControlImpl()687 ControlImpl::~ControlImpl ()
688 {
689     if ((!!mGetFocusHdl || !!mLoseFocusHdl) && mxWindow.is ())
690         /* Disposing will be done @ VCLXWindow::dispose () maFocusListeners.disposeAndClear()
691            don't do it twice */
692         mxWindow.clear ();
693 }
694 
SetGetFocusHdl(Link const & link)695 void ControlImpl::SetGetFocusHdl (Link const& link)
696 {
697     if (!mLoseFocusHdl || !link)
698         UpdateListening (link);
699     mGetFocusHdl = link;
700 }
701 
GetGetFocusHdl()702 Link& ControlImpl::GetGetFocusHdl ()
703 {
704     return mGetFocusHdl;
705 }
706 
SetLoseFocusHdl(Link const & link)707 void ControlImpl::SetLoseFocusHdl (Link const& link)
708 {
709     if (!mGetFocusHdl || !link)
710         UpdateListening (link);
711     mLoseFocusHdl = link;
712 }
713 
GetLoseFocusHdl()714 Link& ControlImpl::GetLoseFocusHdl ()
715 {
716     return mGetFocusHdl;
717 }
718 
UpdateListening(Link const & link)719 void ControlImpl::UpdateListening (Link const& link)
720 {
721     if (!link && (!!mGetFocusHdl || !!mLoseFocusHdl)
722         && (!mGetFocusHdl || !mLoseFocusHdl))
723         mxWindow->removeFocusListener (this);
724     else if (!!link && !mGetFocusHdl && !mLoseFocusHdl)
725         mxWindow->addFocusListener (this);
726 }
727 
disposing(lang::EventObject const &)728 void SAL_CALL ControlImpl::disposing (lang::EventObject const&)
729     throw (uno::RuntimeException)
730 {
731 ///    mxWindow.clear ();
732 }
733 
focusGained(awt::FocusEvent const &)734 void SAL_CALL ControlImpl::focusGained (awt::FocusEvent const&)
735     throw (uno::RuntimeException)
736 {
737     mGetFocusHdl.Call (mpWindow);
738 }
739 
focusLost(awt::FocusEvent const &)740 void SAL_CALL ControlImpl::focusLost (awt::FocusEvent const&)
741     throw (uno::RuntimeException)
742 {
743     mLoseFocusHdl.Call (mpWindow);
744 }
745 
GetGetFocusHdl()746 Link& Control::GetGetFocusHdl ()
747 {
748     return getImpl ().GetGetFocusHdl ();
749 }
750 
SetGetFocusHdl(Link const & link)751 void Control::SetGetFocusHdl (Link const& link)
752 {
753     if (&getImpl () && getImpl().mxWindow.is ())
754         getImpl ().SetGetFocusHdl (link);
755 }
756 
GetLoseFocusHdl()757 Link& Control::GetLoseFocusHdl ()
758 {
759     return getImpl ().GetLoseFocusHdl ();
760 }
761 
SetLoseFocusHdl(Link const & link)762 void Control::SetLoseFocusHdl (Link const& link)
763 {
764     if (&getImpl () && getImpl().mxWindow.is ())
765         getImpl ().SetLoseFocusHdl (link);
766 }
767 
768 class DialogImpl : public WindowImpl
769 {
770 public:
771     uno::Reference< awt::XDialog2 > mxDialog;
772     DialogImpl( Context *context, PeerHandle const &peer, Window *window );
773 };
774 
DialogImpl(Context * context,const PeerHandle & peer,Window * window)775 DialogImpl::DialogImpl( Context *context, const PeerHandle &peer, Window *window )
776     : WindowImpl( context, peer, window )
777     , mxDialog( peer, uno::UNO_QUERY )
778 {
779 }
780 
Dialog(Window * parent,const char * xml_file,const char * id,sal_uInt32 nId)781 Dialog::Dialog( Window *parent, const char *xml_file, const char *id, sal_uInt32 nId )
782     : Context( xml_file )
783     , Window( new DialogImpl( this, Context::GetPeerHandle( id, nId ), this ) )
784     , bConstruct (true)
785 {
786     if ( parent )
787         SetParent( parent );
788 }
789 
Dialog(::Window * parent,const char * xml_file,const char * id,sal_uInt32 nId)790 Dialog::Dialog( ::Window *parent, const char *xml_file, const char *id, sal_uInt32 nId )
791     : Context( xml_file )
792     , Window( new DialogImpl( this, Context::GetPeerHandle( id, nId ), this ) )
793 {
794     if ( parent )
795         SetParent( parent );
796 }
797 
~Dialog()798 Dialog::~Dialog ()
799 {
800 }
801 
802 IMPL_GET_WINDOW (Dialog);
803 IMPL_GET_IMPL (Dialog);
804 
805 #define MX_DIALOG if (getImpl ().mxDialog.is ()) getImpl ().mxDialog
806 #define RETURN_MX_DIALOG if (getImpl ().mxDialog.is ()) return getImpl ().mxDialog
807 
Execute()808 short Dialog::Execute()
809 {
810     RETURN_MX_DIALOG->execute ();
811     return -1;
812 }
813 
EndDialog(long result)814 void Dialog::EndDialog( long result )
815 {
816     MX_DIALOG->endDialog (result);
817 }
818 
SetText(OUString const & str)819 void Dialog::SetText( OUString const& str )
820 {
821     SetTitle (str);
822 }
823 
SetTitle(OUString const & str)824 void Dialog::SetTitle( OUString const& str )
825 {
826     MX_DIALOG->setTitle (str);
827 }
828 
Close()829 bool Dialog::Close ()
830 {
831     EndDialog (false);
832     return true;
833 }
834 
Notify(NotifyEvent & event)835 long Dialog::Notify (NotifyEvent& event)
836 {
837     return GetDialog ()->Notify (event);
838 }
839 
Initialize(SfxChildWinInfo *)840 void Dialog::Initialize (SfxChildWinInfo*)
841 {
842 }
843 
844 #define MESSAGE_BOX_MEMBER_INIT\
845     Dialog (parent, xml_file, id)\
846         , imageError (this, "FI_ERROR")\
847         , imageInfo (this, "FI_INFO")\
848         , imageQuery (this, "FI_QUERY")\
849         , imageWarning (this, "FI_WARNING")\
850         , messageText (this, "FT_MESSAGE")\
851         , cancelButton (this, "BTN_CANCEL")\
852         , helpButton (this, "BTN_HELP")\
853         , ignoreButton (this, "BTN_IGNORE")\
854         , noButton (this, "BTN_NO")\
855         , retryButton (this, "BTN_RETRY")\
856         , yesButton (this, "BTN_YES")
857 
MessageBox(::Window * parent,char const * message,char const * yes,char const * no,const rtl::OString & help_id,char const * xml_file,char const * id)858 MessageBox::MessageBox (::Window *parent, char const* message,
859                         char const* yes, char const* no, const rtl::OString& help_id,
860                         char const* xml_file, char const* id)
861     : MESSAGE_BOX_MEMBER_INIT
862 {
863     ignoreButton.Hide ();
864     retryButton.Hide ();
865     init (message, yes, no, help_id);
866 }
867 
868 MessageBox::MessageBox (::Window *parent, OUString const& message,
869                         OUString yes, OUString no, const rtl::OString& help_id,
870                         char const* xml_file, char const* id)
871     : MESSAGE_BOX_MEMBER_INIT
872 {
873     ignoreButton.Hide ();
874     retryButton.Hide ();
875     init (message, yes, no, help_id);
876 }
877 
878 #if !defined (__GNUC__)
879 #define __PRETTY_FUNCTION__ __FUNCTION__
880 #endif /* !__GNUC__ */
881 
882 MessageBox::MessageBox (::Window *parent, WinBits bits, char const* message,
883                         char const* yes, char const* no, const rtl::OString& help_id,
884                         char const* xml_file, char const* id)
885     : MESSAGE_BOX_MEMBER_INIT
886 {
887     // HIG suggests using verbs instead of yes/no/retry etc.
888     // This constructor provides client-code compatibility: Client code should be fixed.
889 #ifndef __SUNPRO_CC
890     OSL_TRACE ("%s: warning, deprecated vcl/Messbox compatibility", __PRETTY_FUNCTION__);
891 #endif
892     bits_init (bits, OUString::createFromAscii (message), OUString::createFromAscii (yes), OUString::createFromAscii (no), help_id);
893 }
894 
895 MessageBox::MessageBox (::Window *parent, WinBits bits, OUString const& message,
896                         OUString yes, OUString no, const rtl::OString& help_id,
897                         char const* xml_file, char const* id)
898     : MESSAGE_BOX_MEMBER_INIT
899 {
900     // HIG suggests using verbs instead of yes/no/retry etc.
901     // This constructor provides client-code compatibility: Client code should be fixed.
902 #ifndef __SUNPRO_CC
903     OSL_TRACE ("%s: warning, deprecated vcl/Messbox compatibility", __PRETTY_FUNCTION__);
904 #endif
905     bits_init (bits, message, yes, no, help_id);
906 }
907 
908 void MessageBox::bits_init (WinBits bits, OUString const& message,
909                             OUString yes, OUString no, const rtl::OString& help_id)
910 {
911 	if ( bits & ( WB_OK_CANCEL | WB_OK ))
912         yes = Button::GetStandardText ( BUTTON_OK );
913 	if ( bits & (WB_YES_NO | WB_YES_NO_CANCEL ))
914 	{
915         yes = Button::GetStandardText ( BUTTON_YES );
916         no =  Button::GetStandardText ( BUTTON_NO );
917 	}
918     if (! (bits & (WB_RETRY_CANCEL | WB_YES_NO_CANCEL | WB_ABORT_RETRY_IGNORE )))
919         cancelButton.Hide ();
920     if (! (bits & (WB_RETRY_CANCEL | WB_ABORT_RETRY_IGNORE)))
921         retryButton.Hide ();
922     if ( bits & WB_ABORT_RETRY_IGNORE )
923         cancelButton.SetText ( Button::GetStandardText (BUTTON_ABORT));
924     else
925         ignoreButton.Hide ();
926 	if ( !(bits & ( WB_OK | WB_OK_CANCEL | WB_YES_NO | WB_YES_NO_CANCEL)))
927         yesButton.Hide ();
928 	if ( !(bits & ( WB_YES_NO | WB_YES_NO_CANCEL)))
929         noButton.Hide ();
930 
931     init (message, yes, no, help_id);
932 }
933 
init(char const * message,char const * yes,char const * no,const rtl::OString & help_id)934 void MessageBox::init (char const* message, char const* yes, char const* no, const rtl::OString& help_id)
935 {
936     init ( OUString::createFromAscii (message), OUString::createFromAscii (yes), OUString::createFromAscii (no), help_id);
937 }
938 
init(OUString const & message,OUString const & yes,OUString const & no,const rtl::OString & help_id)939 void MessageBox::init (OUString const& message, OUString const& yes, OUString const& no, const rtl::OString& help_id)
940 {
941     imageError.Hide ();
942     imageInfo.Hide ();
943     imageQuery.Hide ();
944     imageWarning.Hide ();
945     if (message.getLength ())
946         messageText.SetText (message);
947     if (yes.getLength ())
948     {
949         yesButton.SetText (yes);
950         if (yes != OUString (Button::GetStandardText (BUTTON_OK))
951             && yes != OUString (Button::GetStandardText (BUTTON_YES)))
952             SetTitle (yes);
953         if (no.getLength ())
954             noButton.SetText (no);
955         else
956             noButton.Hide ();
957     }
958     if( !help_id.isEmpty())
959         SetHelpId (help_id);
960     else
961         helpButton.Hide ();
962 }
963 
964 #undef MESSAGE_BOX_IMPL
965 #define MESSAGE_BOX_IMPL(Name)\
966     Name##Box::Name##Box (::Window *parent, char const* message,\
967                           char const* yes, char const* no, const rtl::OString& help_id,\
968                           char const* xml_file, char const* id)\
969     : MessageBox (parent, message, yes, no, help_id, xml_file, id)\
970     {\
971         image##Name.Show ();\
972     }\
973     Name##Box::Name##Box (::Window *parent, OUString const& message,\
974                           OUString yes, OUString no, const rtl::OString& help_id,\
975                           char const* xml_file, char const* id)\
976     : MessageBox (parent, message, yes, no, help_id, xml_file, id)\
977     {\
978         image##Name.Show ();\
979     }\
980     Name##Box::Name##Box (::Window *parent, WinBits bits, char const* message,\
981                           char const* yes, char const* no, const rtl::OString& help_id,\
982                           char const* xml_file, char const* id)\
983     : MessageBox (parent, bits, message, yes, no, help_id, xml_file, id)\
984     {\
985         image##Name.Show ();\
986     }\
987     Name##Box::Name##Box (::Window *parent, WinBits bits, OUString const& message,\
988                           OUString yes, OUString no, const rtl::OString& help_id,\
989                           char const* xml_file, char const* id)\
990     : MessageBox (parent, bits, message, yes, no, help_id, xml_file, id)\
991     {\
992         image##Name.Show ();\
993     }
994 
995 MESSAGE_BOX_IMPL (Error);
996 MESSAGE_BOX_IMPL (Info);
997 MESSAGE_BOX_IMPL (Query);
998 MESSAGE_BOX_IMPL (Warning);
999 
1000 class TabControlImpl
1001     : public ControlImpl
1002     , public ::cppu::WeakImplHelper1 <awt::XTabListener>
1003 {
1004     Link mActivatePageHdl;
1005     Link mDeactivatePageHdl;
1006 
1007 public:
1008     uno::Reference <awt::XSimpleTabController> mxTabControl;
TabControlImpl(Context * context,const PeerHandle & peer,Window * window)1009     TabControlImpl (Context *context, const PeerHandle &peer, Window *window)
1010         : ControlImpl (context, peer, window)
1011         ,  mxTabControl (peer, uno::UNO_QUERY)
1012     {
1013     }
1014 
disposing(lang::EventObject const & e)1015     virtual void SAL_CALL disposing (lang::EventObject const& e)
1016         throw (uno::RuntimeException)
1017     {
1018         ControlImpl::disposing (e);
1019         mxTabControl.clear ();
1020     }
1021 
GetActivatePageHdl()1022     Link& GetActivatePageHdl ()
1023     {
1024         return mActivatePageHdl;
1025     }
1026 
SetActivatePageHdl(Link const & link)1027     void SetActivatePageHdl (Link const& link)
1028     {
1029         if (!mDeactivatePageHdl || !link)
1030             UpdateListening (link);
1031         mActivatePageHdl = link;
1032     }
1033 
GetDeactivatePageHdl()1034     Link& GetDeactivatePageHdl ()
1035     {
1036         return mDeactivatePageHdl;
1037     }
1038 
SetDeactivatePageHdl(Link const & link)1039     void SetDeactivatePageHdl (Link const& link)
1040     {
1041         if (!mActivatePageHdl || !link)
1042             UpdateListening (link);
1043         mDeactivatePageHdl = link;
1044     }
1045 
UpdateListening(Link const & link)1046     void UpdateListening (Link const& link)
1047     {
1048         if (!link && (!!mActivatePageHdl || !!mDeactivatePageHdl))
1049             mxTabControl->removeTabListener (this);
1050         else if (!!link && !mActivatePageHdl && !mDeactivatePageHdl)
1051             mxTabControl->addTabListener (this);
1052     }
1053 
activated(sal_Int32)1054     void SAL_CALL activated (sal_Int32)
1055         throw (uno::RuntimeException)
1056     {
1057         mActivatePageHdl.Call (mpWindow);
1058     }
1059 
deactivated(sal_Int32)1060     void SAL_CALL deactivated (sal_Int32)
1061         throw (uno::RuntimeException)
1062     {
1063         mDeactivatePageHdl.Call (mpWindow);
1064     }
1065 
inserted(sal_Int32)1066     void SAL_CALL inserted (sal_Int32)
1067         throw (uno::RuntimeException)
1068     {
1069     }
1070 
removed(sal_Int32)1071     void SAL_CALL removed (sal_Int32)
1072         throw (uno::RuntimeException)
1073     {
1074     }
1075 
changed(sal_Int32,uno::Sequence<beans::NamedValue> const &)1076     void SAL_CALL changed (sal_Int32, uno::Sequence <beans::NamedValue> const&)
1077         throw (uno::RuntimeException)
1078     {
1079     }
1080 };
1081 
1082 IMPL_GET_WINDOW (TabControl);
1083 IMPL_GET_LAYOUT_VCLXWINDOW (TabControl);
1084 
1085 #define MX_TABCONTROL if (getImpl ().mxTabControl.is ()) getImpl ().mxTabControl
1086 #define RETURN_MX_TABCONTROL if (getImpl ().mxTabControl.is ()) return getImpl ().mxTabControl
1087 
~TabControl()1088 TabControl::~TabControl ()
1089 {
1090     SetActivatePageHdl (Link ());
1091     SetDeactivatePageHdl (Link ());
1092 }
1093 
InsertPage(sal_uInt16 id,OUString const & title,sal_uInt16 pos)1094 void TabControl::InsertPage (sal_uInt16 id, OUString const& title, sal_uInt16 pos)
1095 {
1096     (void) pos;
1097 //    GetTabControl ()->InsertPage (id, title, pos);
1098 //    GetTabControl ()->SetTabPage (id, new ::TabPage (GetTabControl ()));
1099 
1100     MX_TABCONTROL->insertTab ();
1101     SetCurPageId (id);
1102 
1103 #if 1 // colour me loc productive -- NOT
1104 #define ADD_PROP( seq, i, name, val )\
1105     { \
1106         beans::NamedValue value; \
1107         value.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( name ) ); \
1108         value.Value = uno::makeAny( val ); \
1109         seq[i] = value; \
1110     }
1111 
1112     uno::Sequence< beans::NamedValue > seq (1);
1113     ADD_PROP ( seq, 0, "Title", OUString (title) );
1114     MX_TABCONTROL->setTabProps (id, seq);
1115 #else
1116     GetTabPage (id)->SetText (title);
1117 #endif
1118 
1119 #if 0
1120     /// This so seems the right solution, but it makes the buttons of the
1121     /// tabdialog move up
1122 
1123     ::TabPage *page = GetTabPage (id);
1124     if (Window *w = dynamic_cast <Window*> (page))
1125     {
1126         w->SetParent (this);
1127         //GetVCLXTabControl ()->Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY));
1128         //GetVCLXTabControl ()->Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY));
1129         //GetVCLXTabControl ()->AddChild (w);
1130         //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY));
1131         //uno::Reference <uno::XInterface> x (page->GetWindowPeer());
1132         //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->::Window::GetWindowPeer (), uno::UNO_QUERY));
1133         //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetComponentInterface (), uno::UNO_QUERY));
1134     }
1135     getImpl ().redraw ();
1136 #endif
1137 }
RemovePage(sal_uInt16 id)1138 void TabControl::RemovePage (sal_uInt16 id)
1139 {
1140     GetTabControl ()->RemovePage (id);
1141 }
GetPageCount() const1142 sal_uInt16 TabControl::GetPageCount () const
1143 {
1144     return GetTabControl ()->GetPageCount ();
1145 }
GetPageId(sal_uInt16 pos) const1146 sal_uInt16 TabControl::GetPageId (sal_uInt16 pos) const
1147 {
1148     return GetTabControl ()->GetPageId (pos);
1149 }
GetPagePos(sal_uInt16 id) const1150 sal_uInt16 TabControl::GetPagePos (sal_uInt16 id) const
1151 {
1152     getImpl ().redraw ();
1153     return GetTabControl ()->GetPagePos (id);
1154 }
SetCurPageId(sal_uInt16 id)1155 void TabControl::SetCurPageId (sal_uInt16 id)
1156 {
1157     getImpl ().redraw ();
1158     GetTabControl ()->SetCurPageId (id);
1159 }
GetCurPageId() const1160 sal_uInt16 TabControl::GetCurPageId () const
1161 {
1162     return GetTabControl ()->GetCurPageId ();
1163 }
SetTabPage(sal_uInt16 id,::TabPage * page)1164 void TabControl::SetTabPage (sal_uInt16 id, ::TabPage* page)
1165 {
1166     GetTabControl ()->SetTabPage (id, page);
1167 
1168 #if 0
1169     /// This so seems the right solution, but it makes the buttons of the
1170     /// tabdialog move up
1171     if (Window *w = dynamic_cast <Window*> (page))
1172     {
1173         w->SetParent (this);
1174         //GetVCLXTabControl ()->Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY));
1175         //GetVCLXTabControl ()->Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY));
1176         //GetVCLXTabControl ()->AddChild (w);
1177         //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY));
1178         //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetWindowPeer (), uno::UNO_QUERY));
1179         //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetComponentInterface (), uno::UNO_QUERY));
1180     }
1181 #endif
1182     getImpl ().redraw ();
1183 }
GetTabPage(sal_uInt16 id) const1184 ::TabPage* TabControl::GetTabPage (sal_uInt16 id) const
1185 {
1186     return GetTabControl ()->GetTabPage (id);
1187 }
SetActivatePageHdl(Link const & link)1188 void TabControl::SetActivatePageHdl (Link const& link)
1189 {
1190     if (&getImpl () && getImpl().mxTabControl.is ())
1191         getImpl ().SetActivatePageHdl (link);
1192 }
GetActivatePageHdl() const1193 Link& TabControl::GetActivatePageHdl () const
1194 {
1195     return getImpl ().GetActivatePageHdl ();
1196 }
SetDeactivatePageHdl(Link const & link)1197 void TabControl::SetDeactivatePageHdl (Link const& link)
1198 {
1199     if (&getImpl () && getImpl().mxTabControl.is ())
1200         getImpl ().SetDeactivatePageHdl (link);
1201 }
GetDeactivatePageHdl() const1202 Link& TabControl::GetDeactivatePageHdl () const
1203 {
1204     return getImpl ().GetDeactivatePageHdl ();
1205 }
SetTabPageSizePixel(Size const & size)1206 void TabControl::SetTabPageSizePixel (Size const& size)
1207 {
1208     GetTabControl ()->SetTabPageSizePixel (size);
1209 //    GetParent()->SetSizePixel (size);
1210 //    GetWindow()->SetSizePixel (size);
1211     //GetVCLXTabControl->SetTabSize (size);
1212 }
GetTabPageSizePixel() const1213 Size TabControl::GetTabPageSizePixel () const
1214 {
1215 #if 0
1216     //return GetTabControl ()->GetTabPageSizePixel ();
1217     static size_t const tab_page_first_index = 1;
1218     for (size_t i = 0; i < GetPageCount (); i++)
1219     {
1220         ::TabPage *p = GetTabPage (i + tab_page_first_index);
1221         //if (dynamic_cast<Windowt*> (p))
1222         if (i) // URG
1223             return p->GetOptimalSize (WINDOWSIZE_MINIMUM);
1224     }
1225 #endif
1226     return GetTabControl ()->GetTabPageSizePixel ();
1227 }
1228 
1229 IMPL_CONSTRUCTORS (TabControl, Control, "tabcontrol");
1230 IMPL_GET_IMPL (TabControl);
1231 
1232 class TabPageImpl : public WindowImpl
1233 {
1234 public:
1235     uno::Reference< awt::XWindow > mxTabPage;
TabPageImpl(Context * context,const PeerHandle & peer,Window * window)1236     TabPageImpl( Context *context, const PeerHandle &peer, Window *window )
1237         : WindowImpl( context, peer, window )
1238         , mxTabPage( peer, uno::UNO_QUERY )
1239     {
1240     }
1241 };
1242 
1243 ::Window* TabPage::global_parent = 0;
1244 TabControl* TabPage::global_tabcontrol = 0;
1245 
1246 IMPL_GET_IMPL( TabPage );
1247 
TabPage(Window * parent,const char * xml_file,const char * id,sal_uInt32 nId)1248 TabPage::TabPage( Window *parent, const char *xml_file, const char *id, sal_uInt32 nId)
1249     : Context( xml_file )
1250     , Window( new TabPageImpl( this, Context::GetPeerHandle( id, nId ), this ) )
1251 {
1252     if ( parent )
1253         SetParent( parent );
1254 }
1255 
TabPage(::Window * parent,const char * xml_file,const char * id,sal_uInt32 nId)1256 TabPage::TabPage( ::Window *parent, const char *xml_file, const char *id, sal_uInt32 nId)
1257     : Context( xml_file )
1258     , Window( new TabPageImpl( this, Context::GetPeerHandle( id, nId ), this ) )
1259 {
1260     if ( parent )
1261         SetParent( parent );
1262 }
1263 
~TabPage()1264 TabPage::~TabPage()
1265 {
1266     delete GetTabPage();
1267 }
1268 
1269 IMPL_GET_WINDOW( TabPage );
1270 
ActivatePage()1271 void TabPage::ActivatePage()
1272 {
1273 }
1274 
DeactivatePage()1275 void TabPage::DeactivatePage()
1276 {
1277 }
1278 
1279 class FixedLineImpl : public ControlImpl
1280 {
1281 public:
FixedLineImpl(Context * context,const PeerHandle & peer,Window * window)1282     FixedLineImpl( Context *context, const PeerHandle &peer, Window *window )
1283         : ControlImpl( context, peer, window )
1284     {
1285     }
1286 };
1287 
1288 IMPL_CONSTRUCTORS( FixedLine, Control, "hfixedline" );
1289 IMPL_GET_IMPL( FixedLine );
1290 
IsEnabled() const1291 bool FixedLine::IsEnabled() const
1292 {
1293     //FIXME
1294     return true;
1295 }
1296 
1297 class FixedTextImpl : public ControlImpl
1298 {
1299 public:
1300     uno::Reference< awt::XFixedText > mxFixedText;
FixedTextImpl(Context * context,const PeerHandle & peer,Window * window)1301     FixedTextImpl( Context *context, const PeerHandle &peer, Window *window )
1302         : ControlImpl( context, peer, window )
1303         , mxFixedText( peer, uno::UNO_QUERY )
1304     {
1305     }
1306 
1307     ~FixedTextImpl ();
1308 
1309     virtual void SAL_CALL disposing( lang::EventObject const& e )
1310         throw (uno::RuntimeException);
1311 };
1312 
~FixedTextImpl()1313 FixedTextImpl::~FixedTextImpl ()
1314 {
1315 }
1316 
disposing(lang::EventObject const & e)1317 void SAL_CALL FixedTextImpl::disposing( lang::EventObject const& e )
1318     throw (uno::RuntimeException)
1319 {
1320     ControlImpl::disposing (e);
1321     mxFixedText.clear ();
1322 }
1323 
~FixedText()1324 FixedText::~FixedText ()
1325 {
1326 }
1327 
1328 IMPL_CONSTRUCTORS( FixedText, Control, "fixedtext" );
1329 IMPL_GET_IMPL( FixedText );
1330 
SetText(OUString const & rStr)1331 void FixedText::SetText( OUString const& rStr )
1332 {
1333     if ( !getImpl().mxFixedText.is() )
1334         return;
1335     getImpl().mxFixedText->setText( rStr );
1336 }
1337 
1338 class FixedInfoImpl : public FixedTextImpl
1339 {
1340 public:
FixedInfoImpl(Context * context,const PeerHandle & peer,Window * window)1341     FixedInfoImpl( Context *context, const PeerHandle &peer, Window *window )
1342         : FixedTextImpl( context, peer, window )
1343     {
1344     }
1345 };
1346 
1347 IMPL_CONSTRUCTORS( FixedInfo, FixedText, "fixedinfo" );
1348 IMPL_GET_IMPL( FixedInfo );
1349 
1350 class ProgressBarImpl : public ControlImpl
1351 {
1352 public:
1353     uno::Reference< awt::XProgressBar > mxProgressBar;
ProgressBarImpl(Context * context,const PeerHandle & peer,Window * window)1354     ProgressBarImpl( Context *context, const PeerHandle &peer, Window *window )
1355         : ControlImpl( context, peer, window )
1356         , mxProgressBar( peer, uno::UNO_QUERY )
1357     {
1358     }
1359 
disposing(lang::EventObject const & e)1360     virtual void SAL_CALL disposing( lang::EventObject const& e )
1361         throw (uno::RuntimeException)
1362     {
1363         ControlImpl::disposing (e);
1364         mxProgressBar.clear ();
1365     }
1366 };
1367 
1368 
1369 class FixedImageImpl: public ControlImpl
1370 {
1371 public:
1372     uno::Reference< graphic::XGraphic > mxGraphic;
FixedImageImpl(Context * context,const PeerHandle & peer,Window * window)1373     FixedImageImpl( Context *context, const PeerHandle &peer, Window *window)
1374 //                    const char *pName )
1375         : ControlImpl( context, peer, window )
1376           //, mxGraphic( layoutimpl::loadGraphic( pName ) )
1377         , mxGraphic( peer, uno::UNO_QUERY )
1378     {
1379         if ( !mxGraphic.is() )
1380         {
1381             DBG_ERROR( "ERROR: failed to load image: `%s'" /*, pName*/ );
1382         }
1383 #if 0
1384         else
1385             getImpl().mxGraphic->...();
1386 #endif
1387     }
1388 };
1389 
1390 IMPL_CONSTRUCTORS( FixedImage, Control, "fixedimage" );
IMPL_GET_IMPL(FixedImage)1391 IMPL_GET_IMPL( FixedImage )
1392 
1393 void FixedImage::setImage( ::Image const& i )
1394 {
1395     (void) i;
1396     if ( !getImpl().mxGraphic.is() )
1397         return;
1398     //FIXME: hack moved to proplist
1399     //getImpl().mxGraphic =
1400 }
1401 
1402 #if 0
1403 
1404 FixedImage::FixedImage( const char *pName )
1405     : pImpl( new FixedImageImpl( pName ) )
1406 {
1407 }
1408 
1409 FixedImage::~FixedImage()
1410 {
1411     delete pImpl;
1412 }
1413 
1414 #endif
1415 
1416 
1417 IMPL_CONSTRUCTORS( ProgressBar, Control, "ProgressBar" );
1418 IMPL_GET_IMPL( ProgressBar );
1419 
SetForegroundColor(util::Color color)1420 void ProgressBar::SetForegroundColor( util::Color color )
1421 {
1422     if ( !getImpl().mxProgressBar.is() )
1423         return;
1424     getImpl().mxProgressBar->setForegroundColor( color );
1425 }
1426 
SetBackgroundColor(util::Color color)1427 void ProgressBar::SetBackgroundColor( util::Color color )
1428 {
1429     if ( !getImpl().mxProgressBar.is() )
1430         return;
1431     getImpl().mxProgressBar->setBackgroundColor( color );
1432 }
1433 
SetValue(sal_Int32 i)1434 void ProgressBar::SetValue( sal_Int32 i )
1435 {
1436     if ( !getImpl().mxProgressBar.is() )
1437         return;
1438     getImpl().mxProgressBar->setValue( i );
1439 }
1440 
SetRange(sal_Int32 min,sal_Int32 max)1441 void ProgressBar::SetRange( sal_Int32 min, sal_Int32 max )
1442 {
1443     if ( !getImpl().mxProgressBar.is() )
1444         return;
1445     getImpl().mxProgressBar->setRange( min, max );
1446 }
1447 
GetValue()1448 sal_Int32 ProgressBar::GetValue()
1449 {
1450     if ( !getImpl().mxProgressBar.is() )
1451         return 0;
1452     return getImpl().mxProgressBar->getValue();
1453 }
1454 
1455 class PluginImpl: public ControlImpl
1456 {
1457 public:
1458     ::Control *mpPlugin;
1459 
PluginImpl(Context * context,const PeerHandle & peer,Window * window,::Control * plugin)1460     PluginImpl( Context *context, const PeerHandle &peer, Window *window, :: Control *plugin )
1461         : ControlImpl( context, peer, window )
1462         , mpPlugin( plugin )
1463     {
1464         uno::Reference <awt::XWindow> ref( mxWindow, uno::UNO_QUERY );
1465         layoutimpl::VCLXPlugin *vcl
1466             = static_cast<layoutimpl::VCLXPlugin*>( VCLXWindow::GetImplementation( ref ) );
1467         ::Window *parent = vcl->mpWindow->GetParent();
1468         vcl->SetWindow( plugin );
1469         vcl->SetPlugin( mpPlugin );
1470         plugin->SetParent( parent );
1471         plugin->SetStyle( vcl->mStyle );
1472         plugin->SetCreatedWithToolkit( true );
1473         plugin->SetComponentInterface( vcl );
1474         plugin->Show();
1475     }
1476 };
1477 
Plugin(Context * context,char const * id,::Control * plugin)1478 Plugin::Plugin( Context *context, char const *id, ::Control *plugin )
1479     : Control( new PluginImpl( context, context->GetPeerHandle( id, 0 ), this, plugin ) )
1480     , mpPlugin( plugin )
1481 {
1482 }
1483 
1484 IMPL_GET_IMPL( Plugin );
1485 
1486 class LocalizedStringImpl : public WindowImpl
1487 {
1488 public:
1489     layoutimpl::LocalizedString *mpString;
1490     OUString maString;
LocalizedStringImpl(Context * context,const PeerHandle & peer,Window * window)1491     LocalizedStringImpl( Context *context, const PeerHandle &peer, Window *window )
1492         : WindowImpl( context, peer, window )
1493         , mpString( static_cast<layoutimpl::LocalizedString*>( VCLXWindow::GetImplementation( uno::Reference <awt::XWindow> ( mxWindow, uno::UNO_QUERY ) ) ) )
1494         , maString ()
1495     {
1496     }
getText()1497     OUString getText()
1498     {
1499         if (mpString)
1500             maString = mpString->getText ();
1501         return maString;
1502     }
setText(OUString const & s)1503     void setText( OUString const& s )
1504     {
1505         if (mpString)
1506             mpString->setText( s );
1507     }
1508 };
1509 
1510 IMPL_GET_IMPL( LocalizedString );
1511 
LocalizedString(Context * context,char const * id)1512 LocalizedString::LocalizedString( Context *context, char const* id )
1513     : Window( new LocalizedStringImpl( context, context->GetPeerHandle( id, 0 ), this ) )
1514 {
1515 }
1516 
getString()1517 String LocalizedString::getString ()
1518 {
1519     return getImpl ().getText ();
1520 }
1521 
getOUString()1522 OUString LocalizedString::getOUString ()
1523 {
1524     return getImpl ().getText ();
1525 }
1526 
operator OUString()1527 LocalizedString::operator OUString ()
1528 {
1529     return getOUString ();
1530 }
1531 
1532 LocalizedString::operator OUString const& ()
1533 {
1534     getOUString ();
1535     return getImpl ().maString;
1536 }
1537 
operator String()1538 LocalizedString::operator String()
1539 {
1540     getOUString ();
1541     return getImpl ().maString;
1542 }
1543 
GetToken(sal_uInt16 i,sal_Char c)1544 String LocalizedString::GetToken (sal_uInt16 i, sal_Char c)
1545 {
1546     return getString ().GetToken (i, c);
1547 }
1548 
operator =(OUString const & s)1549 OUString LocalizedString::operator= (OUString const& s)
1550 {
1551     getImpl().setText( s );
1552     return getImpl().getText();
1553 }
1554 
operator +=(OUString const & b)1555 OUString LocalizedString::operator+= (OUString const& b)
1556 {
1557     OUString a = getImpl ().getText ();
1558     a += b;
1559     getImpl ().setText (a);
1560     return getImpl ().getText ();
1561 }
1562 
operator +=(sal_Unicode const b)1563 OUString LocalizedString::operator+= (sal_Unicode const b)
1564 {
1565     String a = getImpl ().getText ();
1566     a += b;
1567     getImpl ().setText (a);
1568     return getImpl ().getText ();
1569 }
1570 
1571 class InPlugImpl : public WindowImpl
1572 {
1573 public:
InPlugImpl(Context * context,const PeerHandle & peer,Window * window)1574     InPlugImpl (Context *context, const PeerHandle &peer, Window *window)
1575         : WindowImpl (context, peer, window)
1576     {
1577     }
1578 };
1579 
1580 IMPL_GET_IMPL (InPlug);
1581 
FIXME_set_parent(::Window * parent,char const * xml_file)1582 static char const *FIXME_set_parent (::Window *parent, char const *xml_file)
1583 {
1584     layout::TabPage::global_parent = parent;
1585     return xml_file;
1586 }
1587 
InPlug(Window * parent,char const * xml_file,char const * id,sal_uInt32 nId)1588 InPlug::InPlug (Window *parent, char const* xml_file, char const* id, sal_uInt32 nId)
1589     : Context (FIXME_set_parent (parent ? parent->GetWindow () : 0, xml_file))
1590     , layout::Window (new InPlugImpl (this, Context::GetPeerHandle (id, nId), this))
1591 {
1592     if (parent)
1593         SetParent (parent);
1594     if (::Window *w = dynamic_cast< ::Window* > (this))
1595         w->SetComponentInterface (GetVCLXWindow ());
1596 }
1597 
InPlug(::Window * parent,char const * xml_file,char const * id,sal_uInt32 nId)1598 InPlug::InPlug (::Window *parent, char const* xml_file, char const* id, sal_uInt32 nId)
1599     : Context (FIXME_set_parent (parent, xml_file))
1600     , layout::Window (new InPlugImpl (this, Context::GetPeerHandle (id, nId), this))
1601 {
1602     if (parent)
1603         layout::Window::SetParent (parent);
1604     if (::Window *w = dynamic_cast< ::Window* > (this))
1605         w->SetComponentInterface (GetVCLXWindow ());
1606 }
1607 
ParentSet(Window * window)1608 void InPlug::ParentSet (Window *window)
1609 {
1610     window->SetParent (dynamic_cast< ::Window* > (this));
1611 
1612     /// FIXME: for standalone run of layout::SfxTabDialog
1613     SetParent (window->GetParent ());
1614 }
1615 
1616 } // namespace layout
1617