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