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