diff options
Diffstat (limited to 'toolkit/source/layout/vcl')
-rw-r--r-- | toolkit/source/layout/vcl/makefile.mk | 56 | ||||
-rw-r--r-- | toolkit/source/layout/vcl/wbutton.cxx | 685 | ||||
-rw-r--r-- | toolkit/source/layout/vcl/wcontainer.cxx | 270 | ||||
-rw-r--r-- | toolkit/source/layout/vcl/wfield.cxx | 796 | ||||
-rw-r--r-- | toolkit/source/layout/vcl/wrapper.cxx | 1630 | ||||
-rw-r--r-- | toolkit/source/layout/vcl/wrapper.hxx | 153 |
6 files changed, 3590 insertions, 0 deletions
diff --git a/toolkit/source/layout/vcl/makefile.mk b/toolkit/source/layout/vcl/makefile.mk new file mode 100644 index 000000000000..a6cc754efa1b --- /dev/null +++ b/toolkit/source/layout/vcl/makefile.mk @@ -0,0 +1,56 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile$ +# +# $Revision$ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=../../.. +PRJNAME=toolkit +TARGET=layout-vcl +ENABLE_EXCEPTIONS=true + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +.IF "$(COMNAME)" == "gcc3" +CFLAGS+=-Wall -fno-default-inline +.ENDIF + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/wrapper.obj \ + $(SLO)$/wbutton.obj \ + $(SLO)$/wcontainer.obj \ + $(SLO)$/wfield.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/toolkit/source/layout/vcl/wbutton.cxx b/toolkit/source/layout/vcl/wbutton.cxx new file mode 100644 index 000000000000..0b8b41299315 --- /dev/null +++ b/toolkit/source/layout/vcl/wbutton.cxx @@ -0,0 +1,685 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile$ + * + * $Revision$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wrapper.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XActionListener.hpp> +#include <com/sun/star/awt/XButton.hpp> +#include <com/sun/star/awt/XCheckBox.hpp> +#include <com/sun/star/awt/XRadioButton.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <cppuhelper/implbase1.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/awt/vclxwindows.hxx> +#include <toolkit/helper/convert.hxx> +#include <vcl/button.hxx> +#include <vcl/event.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> + +#include <list> + +#include <layout/core/helper.hxx> + +using namespace ::com::sun::star; + +using rtl::OUString; + +namespace layout +{ + +class ImageImpl +{ + public: + uno::Reference< graphic::XGraphic > mxGraphic; + ImageImpl( const char *pName ) + : mxGraphic( layoutimpl::loadGraphic( pName ) ) + { + if ( !mxGraphic.is() ) + { + DBG_ERROR1( "ERROR: failed to load image: `%s'\n", pName ); + } + } +}; + +Image::Image( const char *pName ) + : pImpl( new ImageImpl( pName ) ) +{ +} + +Image::~Image() +{ + delete pImpl; +} + +class ButtonImpl : public ControlImpl + , public ::cppu::WeakImplHelper1< awt::XActionListener > +{ + Link maClickHdl; + +public: + uno::Reference< awt::XButton > mxButton; + ButtonImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxButton( peer, uno::UNO_QUERY ) + { + /* We have default action when clicked, always listen. */ + mxButton->addActionListener( this ); + } + + ~ButtonImpl() + { + } + + virtual void Click() { /* make me pure virtual? */ }; + + Link& GetClickHdl () + { + return maClickHdl; + } + + virtual void SetClickHdl( Link const& link ) + { + maClickHdl = link; + } + + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + mxButton->removeActionListener( this ); + ControlImpl::disposing (e); + mxButton.clear (); + } + + virtual void SAL_CALL actionPerformed( const awt::ActionEvent& ) + throw (uno::RuntimeException) + { + if ( !maClickHdl ) + Click(); + else + maClickHdl.Call( static_cast<Window *>( mpWindow ) ); + } + + bool SetModeImage( uno::Reference< graphic::XGraphic > xGraph ) + { + setProperty( "Graphic", uno::Any( xGraph ) ); + return true; + } +}; + +Button::~Button () +{ +} + +String Button::GetStandardText (sal_uInt16 button_type) +{ + return ::Button::GetStandardText (button_type); +} + +void Button::SetText( OUString const& rStr ) +{ + if ( !getImpl().mxButton.is() ) + return; + getImpl().mxButton->setLabel( rStr ); +} + +void Button::SetClickHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxButton.is ()) + getImpl().SetClickHdl( link ); +} + +Link& Button::GetClickHdl () +{ + return getImpl().GetClickHdl (); +} + +bool Button::SetModeImage (Image const& image) +{ + return getImpl().SetModeImage (image.getImpl().mxGraphic); +} + +bool Button::SetModeImage (::Image const& image, BmpColorMode mode) +{ + return GetButton ()->SetModeImage (image, mode); +} + +void Button::SetImageAlign( ImageAlign eAlign ) +{ + getImpl().setProperty( "ImageAlign", uno::Any( (sal_Int16) eAlign ) ); +} + +void Button::Click() +{ +} + +IMPL_GET_IMPL( Button ); +IMPL_CONSTRUCTORS( Button, Control, "button" ); +IMPL_GET_WINDOW (Button); + +class PushButtonImpl : public ButtonImpl + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ + Link maToggleHdl; +public: + PushButtonImpl( Context *context, const PeerHandle &peer, Window *window ) + : ButtonImpl( context, peer, window ) + { + } + + void SetToggleHdl( const Link& link ) + { + // XButton doesn't have an explicit event for Toggle. Anyway, it is a + // superset of the clicks: all clicks, and explicit toggles + if (!link && !!maToggleHdl) + mxButton->removeActionListener( this ); + else if (!!link && !maToggleHdl) + mxButton->addActionListener( this ); + maToggleHdl = link; + } + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::disposing (e); + } + virtual void SAL_CALL actionPerformed( awt::ActionEvent const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::actionPerformed( e ); + fireToggle(); + } + virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& ) + throw (uno::RuntimeException) + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } + void fireToggle() + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } + +}; + +PushButton::~PushButton () +{ + SetToggleHdl (Link ()); +} + +void PushButton::Check( bool bCheck ) +{ + getImpl().setProperty( "State", uno::Any( (sal_Int16) !!bCheck ) ); + // XButton doesn't have explicit toggle event + getImpl().fireToggle(); +} + +bool PushButton::IsChecked() const +{ + return !!( getImpl().getProperty( "State" ).get< sal_Int16 >() ); +} + +void PushButton::Toggle() +{ + Check( true ); +} + +void PushButton::SetToggleHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxButton.is ()) + getImpl().SetToggleHdl( link ); +} + +IMPL_GET_IMPL( PushButton ); +IMPL_CONSTRUCTORS( PushButton, Button, "pushbutton" ); +IMPL_GET_WINDOW (PushButton); + +class RadioButtonImpl : public ButtonImpl + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ + Link maToggleHdl; +public: + uno::Reference< awt::XRadioButton > mxRadioButton; + RadioButtonImpl( Context *context, const PeerHandle &peer, Window *window ) + : ButtonImpl( context, peer, window ) + , mxRadioButton( peer, uno::UNO_QUERY ) + { + } + + void Check( bool bCheck ) + { + if ( !mxRadioButton.is() ) + return; + +#if 1 + // Have setState fire item event for + // RadioGroups::RadioGroup::itemStateChanged () + ::RadioButton *r = static_cast<RadioButton*>(mpWindow)->GetRadioButton (); + bool state = r->IsRadioCheckEnabled (); + r->EnableRadioCheck(); + mxRadioButton->setState( !!bCheck ); + r->EnableRadioCheck (state); +#else + mxRadioButton->setState( !!bCheck ); +#endif + fireToggle(); + } + + bool IsChecked() + { + if ( !mxRadioButton.is() ) + return false; + return mxRadioButton->getState(); + } + + void SetToggleHdl( const Link& link ) + { + if (!link && !!maToggleHdl) + mxRadioButton->removeItemListener( this ); + else if (!!link && !maToggleHdl) + mxRadioButton->addItemListener( this ); + maToggleHdl = link; + } + + inline void fireToggle() + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } + + virtual void SetClickHdl( const Link& link ) + { + // Keep RadioGroups::RadioGroup's actionListener at HEAD + // of list. This way, it can handle RadioGroup's button + // states before all other callbacks and make sure the + // client code has the right state. + + // IWBN to add an XRadioButton2 and layout::VCLXRadioButton + // with {get,set}RadioGroup() (and a "radiogroup" property + // even) and handle the grouping here in RadioButtonImpl. + uno::Reference< uno::XInterface > x = static_cast<VCLXRadioButton*> (mpWindow->GetVCLXWindow ())->getFirstActionListener (); + uno::Reference< awt::XActionListener > a = uno::Reference< awt::XActionListener> (x ,uno::UNO_QUERY ); + mxButton->removeActionListener (a); + ButtonImpl::SetClickHdl (link); + mxButton->addActionListener (a); + } + + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::disposing (e); + } + + virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& ) + throw (uno::RuntimeException) + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } +}; + +RadioButton::~RadioButton () +{ + SetToggleHdl (Link ()); +} + +void RadioButton::Check( bool bCheck ) +{ + getImpl().Check( bCheck ); +} + +bool RadioButton::IsChecked() const +{ + return getImpl().IsChecked(); +} + +void RadioButton::SetToggleHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxRadioButton.is ()) + getImpl().SetToggleHdl( link ); +} + +IMPL_GET_IMPL( RadioButton ); +IMPL_GET_WINDOW( RadioButton ); +IMPL_GET_VCLXWINDOW( RadioButton ); +IMPL_CONSTRUCTORS( RadioButton, Button, "radiobutton" ); + +class CheckBoxImpl : public ButtonImpl + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ + Link maToggleHdl; + public: + uno::Reference< awt::XCheckBox > mxCheckBox; + CheckBoxImpl( Context *context, const PeerHandle &peer, Window *window ) + : ButtonImpl( context, peer, window ) + , mxCheckBox( peer, uno::UNO_QUERY ) + { + } + + void SetToggleHdl( const Link& link ) + { + if (!link && !!maToggleHdl) + mxCheckBox->removeItemListener( this ); + else if (!!link && !maToggleHdl) + mxCheckBox->addItemListener( this ); + maToggleHdl = link; + } + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::disposing (e); + } + virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& ) + throw (uno::RuntimeException) + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } +}; + +CheckBox::~CheckBox () +{ + SetToggleHdl (Link ()); +} + +void CheckBox::Check( bool bCheck ) +{ + if ( !getImpl().mxCheckBox.is() ) + return; + getImpl().mxCheckBox->setState( !!bCheck ); +} + +bool CheckBox::IsChecked() const +{ + if ( !getImpl().mxCheckBox.is() ) + return false; + return getImpl().mxCheckBox->getState() != 0; +} + +void CheckBox::SetToggleHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxCheckBox.is ()) + getImpl().SetToggleHdl( link ); +} + +IMPL_GET_IMPL( CheckBox ); +IMPL_CONSTRUCTORS( CheckBox, Button, "checkbox" ); + +#define BUTTON_IMPL(t, parent, response) \ + class t##Impl : public parent##Impl \ + { \ + public: \ + t##Impl( Context *context, PeerHandle const& peer, Window *window ) \ + : parent##Impl( context, peer, window ) \ + { \ + } \ + void Click() \ + { \ + if (Dialog *d = static_cast<Dialog *> (mpCtx)) \ + d->EndDialog( response ); \ + } \ + } + +/* Common button types currently unavailable in OOo: */ +/* mpReset */ +/* mpApply */ +/* mpAction */ +#define RET_RESET 6 +#define RET_APPLY 7 +#define BUTTONID_RESET RET_RESET +#define BUTTONID_APPLY RET_APPLY + +BUTTON_IMPL( OKButton, PushButton, BUTTONID_OK ); +BUTTON_IMPL( CancelButton, PushButton, BUTTONID_CANCEL ); +BUTTON_IMPL( YesButton, PushButton, BUTTONID_YES ); +BUTTON_IMPL( NoButton, PushButton, BUTTONID_NO ); +BUTTON_IMPL( RetryButton, PushButton, BUTTONID_RETRY ); +BUTTON_IMPL( IgnoreButton, PushButton, BUTTONID_IGNORE ); +BUTTON_IMPL( ResetButton, PushButton, BUTTONID_RESET ); +BUTTON_IMPL( ApplyButton, PushButton, BUTTONID_APPLY ); /* Deprecated? */ +BUTTON_IMPL( HelpButton, PushButton, BUTTONID_HELP ); + +IMPL_CONSTRUCTORS( OKButton, PushButton, "okbutton" ); +IMPL_CONSTRUCTORS( CancelButton, PushButton, "cancelbutton" ); +IMPL_CONSTRUCTORS( YesButton, PushButton, "yesbutton" ); +IMPL_CONSTRUCTORS( NoButton, PushButton, "nobutton" ); +IMPL_CONSTRUCTORS( RetryButton, PushButton, "retrybutton" ); +IMPL_CONSTRUCTORS( IgnoreButton, PushButton, "ignorebutton" ); +IMPL_CONSTRUCTORS( ResetButton, PushButton, "resetbutton" ); +IMPL_CONSTRUCTORS( ApplyButton, PushButton, "applybutton" ); /* Deprecated? */ +IMPL_CONSTRUCTORS( HelpButton, PushButton, "helpbutton" ); + +IMPL_IMPL (ImageButton, PushButton) + + +IMPL_CONSTRUCTORS( ImageButton, PushButton, "imagebutton" ); + +class AdvancedButtonImpl : public PushButtonImpl +{ +protected: + bool bAdvancedMode; + std::list< Window*> maAdvanced; + std::list< Window*> maSimple; + +public: + rtl::OUString mAdvancedLabel; + rtl::OUString mSimpleLabel; + +protected: + Window* Remove( std::list< Window*> lst, Window* w ) + { + for ( std::list< Window*>::iterator it = maAdvanced.begin(); + it != maAdvanced.end(); it++ ) + if ( *it == w ) + { + lst.erase( it ); + return *it; + } + return 0; + } + +public: + AdvancedButtonImpl( Context *context, PeerHandle const& peer, Window *window ) + : PushButtonImpl( context, peer, window ) + , bAdvancedMode( false ) + // TODO: i18n + // Button::GetStandardText( BUTTON_ADVANCED ); + // Button::GetStandardText( BUTTON_SIMPLE ); + , mAdvancedLabel( rtl::OUString::createFromAscii( "Advanced..." ) ) + , mSimpleLabel( rtl::OUString::createFromAscii( "Simple..." ) ) + { + } + void Click() + { + bAdvancedMode = !bAdvancedMode; + if ( bAdvancedMode ) + advancedMode(); + else + simpleMode(); + } + void setAlign () + { + ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton (); + b->SetSymbolAlign (SYMBOLALIGN_RIGHT); + b->SetSmallSymbol (); + //mpWindow->SetStyle (mpWindow->GetStyle() | WB_CENTER); + } + void advancedMode() + { + ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton (); + b->SetSymbol (SYMBOL_PAGEUP); + setAlign (); + if (mSimpleLabel.getLength ()) + b->SetText (mSimpleLabel); + for ( std::list< Window*>::iterator it = maAdvanced.begin(); + it != maAdvanced.end(); it++ ) + ( *it )->Show(); + for ( std::list< Window*>::iterator it = maSimple.begin(); + it != maSimple.end(); it++ ) + ( *it )->Hide(); + + redraw (); + } + void simpleMode() + { + //mxButton->setLabel( mSimpleLabel ); + ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton (); + b->SetSymbol (SYMBOL_PAGEDOWN); + if (mAdvancedLabel.getLength ()) + b->SetText (mAdvancedLabel); + setAlign (); + for ( std::list< Window*>::iterator it = maAdvanced.begin(); + it != maAdvanced.end(); it++ ) + ( *it )->Hide(); + for ( std::list< Window*>::iterator it = maSimple.begin(); + it != maSimple.end(); it++ ) + ( *it )->Show(); + + redraw (true); + } + void AddAdvanced( Window* w ) + { + maAdvanced.push_back( w ); + if ( !bAdvancedMode ) + w->Hide(); + } + void AddSimple( Window* w ) + { + maSimple.push_back( w ); + if ( bAdvancedMode ) + w->Hide(); + } + void RemoveAdvanced( Window* w ) + { + Remove( maAdvanced, w ); + } + void RemoveSimple( Window* w ) + { + Remove( maSimple, w ); + } +}; + +void AdvancedButton::AddAdvanced( Window* w ) +{ + getImpl().AddAdvanced( w ); +} + +void AdvancedButton::AddSimple( Window* w ) +{ + getImpl().AddSimple( w ); +} + +void AdvancedButton::RemoveAdvanced( Window* w ) +{ + getImpl().RemoveAdvanced( w ); +} + +void AdvancedButton::RemoveSimple( Window* w ) +{ + getImpl().RemoveSimple( w ); +} + +void AdvancedButton::SetAdvancedText (rtl::OUString const& text) +{ + if (text.getLength ()) + getImpl ().mAdvancedLabel = text; +} + +void AdvancedButton::SetSimpleText (rtl::OUString const& text) +{ + if (text.getLength ()) + getImpl ().mSimpleLabel = text; +} + +rtl::OUString AdvancedButton::GetAdvancedText () const +{ + return getImpl ().mAdvancedLabel; +} + +rtl::OUString AdvancedButton::GetSimpleText () const +{ + return getImpl ().mSimpleLabel; +} + +void AdvancedButton::SetDelta (int) +{ +} + +IMPL_CONSTRUCTORS_BODY( AdvancedButton, PushButton, "advancedbutton", getImpl().simpleMode () ); +IMPL_GET_IMPL( AdvancedButton ); + + +class MoreButtonImpl : public AdvancedButtonImpl +{ +public: + MoreButtonImpl( Context *context, PeerHandle const& peer, Window *window ) + : AdvancedButtonImpl( context, peer, window) + { + mSimpleLabel = Button::GetStandardText( BUTTON_MORE ); + mAdvancedLabel = Button::GetStandardText( BUTTON_LESS ); + } + void AddWindow( Window* w ) { AddAdvanced( w ); } + void RemoveWindow( Window* w ) { RemoveAdvanced( w ); } +}; + +// TODO +//BUTTON_IMPL( MoreButton, PushButton, 0 ); +IMPL_CONSTRUCTORS_BODY( MoreButton, AdvancedButton, "morebutton", getImpl().simpleMode () ); +IMPL_GET_IMPL( MoreButton ); + +void MoreButton::AddWindow( Window* w ) +{ + getImpl().AddWindow( w ); +} + +void MoreButton::RemoveWindow( Window* w ) +{ + getImpl().RemoveWindow( w ); +} + +void MoreButton::SetMoreText (rtl::OUString const& text) +{ + SetAdvancedText (text); +} + +void MoreButton::SetLessText (rtl::OUString const& text) +{ + SetSimpleText (text); +} + +rtl::OUString MoreButton::GetMoreText () const +{ + return GetAdvancedText (); +} + +rtl::OUString MoreButton::GetLessText () const +{ + return GetSimpleText (); +} + +} // namespace layout diff --git a/toolkit/source/layout/vcl/wcontainer.cxx b/toolkit/source/layout/vcl/wcontainer.cxx new file mode 100644 index 000000000000..e4f5a92f69e0 --- /dev/null +++ b/toolkit/source/layout/vcl/wcontainer.cxx @@ -0,0 +1,270 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile$ + * + * $Revision$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wrapper.hxx" + +#include <com/sun/star/awt/XLayoutRoot.hpp> +#include <com/sun/star/awt/XLayoutContainer.hpp> +#include <comphelper/processfactory.hxx> +#include <layout/core/helper.hxx> +#include <tools/debug.hxx> + +using namespace ::com::sun::star; + +namespace layout +{ + +Container::Container( Context const* context, char const* pId ) + : mxContainer( context->GetPeerHandle( pId ), uno::UNO_QUERY ) +{ + if ( !mxContainer.is() ) + { + DBG_ERROR1( "Error: failed to associate container with '%s'", pId ); + } +} + +Container::Container( rtl::OUString const& rName, sal_Int32 nBorder ) +{ + mxContainer = layoutimpl::WidgetFactory::createContainer( rName ); + + uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Border" ) ), + uno::Any( nBorder ) ); +} + +void Container::Add( Window *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + } +} + +void Container::Add( Container *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + } +} + +void Container::Remove( Window *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY ); + mxContainer->removeChild( xChild ); + } +} + +void Container::Remove( Container *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY ); + mxContainer->removeChild( xChild ); + } +} + +void Container::Clear() +{ + css::uno::Sequence< css::uno::Reference < css::awt::XLayoutConstrains > > children; + children = mxContainer->getChildren(); + for (int i = 0; i < children.getLength(); i++) + mxContainer->removeChild( children[i] ); +} + +void Container::ShowAll( bool bShow ) +{ + struct inner + { + static void setChildrenVisible( uno::Reference < awt::XLayoutContainer > xCont, + bool bVisible ) /* auxiliary */ + { + if ( xCont.is() ) + { + uno::Sequence< uno::Reference < awt::XLayoutConstrains > > aChildren; + aChildren = xCont->getChildren(); + for (int i = 0; i < aChildren.getLength(); i++) + { + uno::Reference < awt::XLayoutConstrains > xChild( aChildren[ i ] ); + + uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY); + if ( xWin.is() ) + xWin->setVisible( bVisible ); + + uno::Reference < awt::XLayoutContainer > xChildCont( + xChild, uno::UNO_QUERY ); + setChildrenVisible( xChildCont, bVisible ); + } + } + } + }; + + inner::setChildrenVisible( mxContainer, bShow ); +} + +void Container::Show() +{ + ShowAll( true ); +} + +void Container::Hide() +{ + ShowAll( false ); +} + +Table::Table( sal_Int32 nBorder, sal_Int32 nColumns ) + : Container( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) ), nBorder ) +{ + uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" ) ), + uno::Any( nColumns ) ); +} + +void Table::Add( Window *window, bool bXExpand, bool bYExpand, + sal_Int32 nXSpan, sal_Int32 nYSpan ) +{ + if ( !window ) + return; + WindowImpl &rImpl = window->getImpl(); + uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow, + uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan ); +} + +void Table::Add( Container *pContainer, bool bXExpand, bool bYExpand, + sal_Int32 nXSpan, sal_Int32 nYSpan ) +{ + if ( !pContainer ) + return; + uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(), + uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan ); +} + +void Table::setProps( uno::Reference< awt::XLayoutConstrains > xChild, + bool bXExpand, bool bYExpand, sal_Int32 nXSpan, sal_Int32 nYSpan ) +{ + uno::Reference< beans::XPropertySet > xProps + ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "XExpand" ) ), + uno::Any( bXExpand ) ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "YExpand" ) ), + uno::Any( bYExpand ) ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "ColSpan" ) ), + uno::Any( nXSpan ) ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "RowSpan" ) ), + uno::Any( nYSpan ) ); +} + +Box::Box( rtl::OUString const& rName, sal_Int32 nBorder, bool bHomogeneous ) + : Container( rName, nBorder ) +{ + uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ) ), + uno::Any( bHomogeneous ) ); +} + +void Box::Add( Window *window, bool bExpand, bool bFill, sal_Int32 nPadding) +{ + if ( !window ) + return; + WindowImpl &rImpl = window->getImpl(); + uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow, + uno::UNO_QUERY ); + + mxContainer->addChild( xChild ); + setProps( xChild, bExpand, bFill, nPadding ); +} + +void Box::Add( Container *pContainer, bool bExpand, bool bFill, sal_Int32 nPadding) +{ + if ( !pContainer ) + return; + + uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(), + uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + setProps( xChild, bExpand, bFill, nPadding ); +} + +void Box::setProps( uno::Reference< awt::XLayoutConstrains > xChild, + bool bExpand, bool bFill, sal_Int32 nPadding ) +{ + uno::Reference< beans::XPropertySet > xProps + ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW ); + + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Expand" ) ), + uno::Any( bExpand ) ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Fill" ) ), + uno::Any( bFill ) ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Padding" ) ), + uno::Any( nPadding ) ); +} + +Table::Table( Context const* context, char const* pId ) + : Container( context, pId ) +{ +} + +Box::Box( Context const* context, char const* pId ) + : Container( context, pId ) +{ +} + +HBox::HBox( sal_Int32 nBorder, bool bHomogeneous ) + : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hbox" ) ), + nBorder, bHomogeneous ) +{ +} + +HBox::HBox( Context const* context, char const* pId ) + : Box( context, pId ) +{ +} + +VBox::VBox( sal_Int32 nBorder, bool bHomogeneous ) + : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vbox" ) ), + nBorder, bHomogeneous ) +{ +} + +VBox::VBox( Context const* context, char const* pId ) + : Box( context, pId ) +{ +} + +} // namespace layout diff --git a/toolkit/source/layout/vcl/wfield.cxx b/toolkit/source/layout/vcl/wfield.cxx new file mode 100644 index 000000000000..281d909530b0 --- /dev/null +++ b/toolkit/source/layout/vcl/wfield.cxx @@ -0,0 +1,796 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile$ + * + * $Revision$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wrapper.hxx" + +#include <comphelper/processfactory.hxx> +#include <com/sun/star/awt/XMetricField.hpp> +#include <com/sun/star/awt/XNumericField.hpp> +#include <com/sun/star/awt/XTextComponent.hpp> +#include <com/sun/star/awt/XListBox.hpp> +#include <com/sun/star/awt/XComboBox.hpp> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/awt/XActionListener.hpp> +#include <com/sun/star/awt/XItemListener.hpp> +#include <com/sun/star/awt/XMouseListener.hpp> +#include <vcl/combobox.hxx> +#include <vcl/lstbox.hxx> + +#include <toolkit/awt/vclxwindows.hxx> + +using namespace ::com::sun::star; +using rtl::OUString; + +#define LAYOUT_API_CALLS_HANDLER 0 + +namespace layout +{ + +class EditImpl : public ControlImpl + , public ::cppu::WeakImplHelper1< awt::XTextListener > +{ +public: + Link maModifyHdl; + + uno::Reference< awt::XTextComponent > mxEdit; + EditImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxEdit( peer, uno::UNO_QUERY ) + { + } + + ~EditImpl (); + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException); + + virtual void SetModifyHdl( Link const& link ); + + void SAL_CALL textChanged( const awt::TextEvent& /* rEvent */ ) + throw (uno::RuntimeException) + { + maModifyHdl.Call( mpWindow ); + } +}; + +EditImpl::~EditImpl () +{ +} + +void SAL_CALL EditImpl::disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) +{ + ControlImpl::disposing (e); + mxEdit.clear (); +} + +void EditImpl::SetModifyHdl( Link const& link ) +{ + if (!link && !!maModifyHdl) + mxEdit->removeTextListener( this ); + else if (!!link && !maModifyHdl) + mxEdit->addTextListener( this ); + maModifyHdl = link; +} + +Edit::~Edit () +{ + SetModifyHdl (Link ()); +} + +void Edit::SetSelection( Selection const& rSelection ) +{ +#if LAYOUT_API_CALLS_HANDLER + if ( !getImpl().mxEdit.is() ) + getImpl().mxEdit->setSelection( awt::Selection( rSelection.Min(), rSelection.Max() ) ); +#else /* !LAYOUT_API_CALLS_HANDLER */ + GetEdit ()->SetSelection (rSelection); +#endif /* !LAYOUT_API_CALLS_HANDLER */ +} + +void Edit::SetText( OUString const& rStr ) +{ +#if LAYOUT_API_CALLS_HANDLER + if ( getImpl().mxEdit.is() ) + /// this calls handlers; endless loop in numfmt.cxx + getImpl().mxEdit->setText( rStr ); +#else /* !LAYOUT_API_CALLS_HANDLER */ + GetEdit ()->SetText (rStr); +#endif /* !LAYOUT_API_CALLS_HANDLER */ +} + +String Edit::GetText() const +{ + if ( !getImpl().mxEdit.is() ) + return getImpl().mxEdit->getText(); + return OUString(); +} + +void Edit::SetModifyHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxEdit.is ()) + getImpl().SetModifyHdl( link ); +} + +IMPL_CONSTRUCTORS( Edit, Control, "edit" ); +IMPL_GET_IMPL( Edit ); +IMPL_GET_WINDOW (Edit); + +class MultiLineEditImpl : public EditImpl +{ +public: + MultiLineEditImpl( Context *context, const PeerHandle &peer, Window *window ) + : EditImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( MultiLineEdit, Edit, "multilineedit" ); +IMPL_GET_IMPL( MultiLineEdit ); + +class SpinFieldImpl : public EditImpl +{ + public: + SpinFieldImpl( Context *context, const PeerHandle &peer, Window *window ) + : EditImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( SpinField, Edit, "spinfield" ); + +class NumericFieldImpl : public SpinFieldImpl +{ + public: + NumericFieldImpl( Context *context, const PeerHandle &peer, Window *window ) + : SpinFieldImpl( context, peer, window ) + { + } +}; + +class MetricFieldImpl : public SpinFieldImpl +{ + public: + MetricFieldImpl( Context *context, const PeerHandle &peer, Window *window ) + : SpinFieldImpl( context, peer, window ) + { + } +}; + +IMPL_GET_IMPL( SpinField ); +IMPL_GET_IMPL( NumericField ); +IMPL_GET_IMPL( MetricField ); + +class FormatterBaseImpl +{ + protected: + PeerHandle mpeer; + public: + explicit FormatterBaseImpl( const PeerHandle &peer ) + : mpeer( peer ) + { + }; +}; + +FormatterBase::FormatterBase( FormatterBaseImpl *pFormatImpl ) + : mpFormatImpl( pFormatImpl ) +{ +} + +class NumericFormatterImpl : public FormatterBaseImpl +{ + public: + uno::Reference< awt::XNumericField > mxField; + explicit NumericFormatterImpl( const PeerHandle &peer ) + : FormatterBaseImpl( peer ) + , mxField( peer, uno::UNO_QUERY ) + { + } + + // FIXME: burn that CPU ! cut/paste from vclxwindows.cxx + double valueToDouble( sal_Int64 nValue ) + { + sal_Int16 nDigits = mxField->getDecimalDigits(); + double n = (double)nValue; + for ( sal_uInt16 d = 0; d < nDigits; d++ ) + n /= 10; + return n; + } // FIXME: burn that CPU ! cut/paste from vclxwindows.cxx + sal_Int64 doubleToValue( double nValue ) + { + sal_Int16 nDigits = mxField->getDecimalDigits(); + double n = nValue; + for ( sal_uInt16 d = 0; d < nDigits; d++ ) + n *= 10; + return (sal_Int64) n; + } +}; + +class MetricFormatterImpl : public FormatterBaseImpl +{ + public: + uno::Reference< awt::XMetricField > mxField; + explicit MetricFormatterImpl( const PeerHandle &peer ) + : FormatterBaseImpl( peer ) + , mxField( peer, uno::UNO_QUERY ) + { + } +}; + +NumericFormatter::NumericFormatter( FormatterBaseImpl *pImpl ) + : FormatterBase( pImpl ) +{ +} + +NumericFormatterImpl& NumericFormatter::getFormatImpl() const +{ + return *( static_cast<NumericFormatterImpl *>( mpFormatImpl ) ); +} + +#define SET_IMPL(vclmethod, idlmethod) \ + void NumericFormatter::vclmethod( sal_Int64 nValue ) \ + { \ + if ( !getFormatImpl().mxField.is() ) \ + return; \ + getFormatImpl().mxField->idlmethod( getFormatImpl().valueToDouble( nValue ) ); \ + } + +SET_IMPL( SetMin, setMin ) +SET_IMPL( SetMax, setMax ) +SET_IMPL( SetLast, setLast ) +SET_IMPL( SetFirst, setFirst ) +SET_IMPL( SetValue, setValue ) +SET_IMPL( SetSpinSize, setSpinSize ) + +sal_Int64 NumericFormatter::GetValue() const +{ + if ( !getFormatImpl().mxField.is() ) + return 0; + return getFormatImpl().doubleToValue( getFormatImpl().mxField->getValue() ); +} + +#undef SET_IMPL + +IMPL_CONSTRUCTORS_2( NumericField, SpinField, NumericFormatter, "numericfield" ); + +MetricFormatter::MetricFormatter( FormatterBaseImpl *pImpl ) + : FormatterBase( pImpl ) +{ +} +MetricFormatterImpl& MetricFormatter::getFormatImpl() const +{ return *( static_cast<MetricFormatterImpl *>( mpFormatImpl ) ); } + +#define MetricUnitVclToUno(a) ((sal_uInt16)(a)) + +#define SET_IMPL(vclmethod, idlmethod) \ + void MetricFormatter::vclmethod( sal_Int64 nValue, FieldUnit nUnit ) \ + { \ + if ( !getFormatImpl().mxField.is() ) \ + return; \ + getFormatImpl().mxField->idlmethod( nValue, MetricUnitVclToUno( nUnit ) ); \ + } + +SET_IMPL( SetMin, setMin ) +SET_IMPL( SetMax, setMax ) +SET_IMPL( SetLast, setLast ) +SET_IMPL( SetFirst, setFirst ) +SET_IMPL( SetValue, setValue ) + +#undef SET_IMPL + +void MetricFormatter::SetSpinSize( sal_Int64 nValue ) +{ + if ( !getFormatImpl().mxField.is() ) + return; + getFormatImpl().mxField->setSpinSize( nValue ); +} + +sal_Int64 MetricFormatter::GetValue( FieldUnit nUnit ) const +{ + if ( !getFormatImpl().mxField.is() ) + return 0; + return getFormatImpl().mxField->getValue( MetricUnitVclToUno( nUnit ) ); +} + +IMPL_CONSTRUCTORS_2( MetricField, SpinField, MetricFormatter, "metricfield" ); + +class ComboBoxImpl : public EditImpl + , public ::cppu::WeakImplHelper1< awt::XActionListener > + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ +public: + uno::Reference< awt::XComboBox > mxComboBox; + + Link maClickHdl; + Link maSelectHdl; + + Window *parent; + + ComboBoxImpl( Context *context, const PeerHandle &peer, Window *window ) + : EditImpl( context, peer, window ) + , mxComboBox( peer, uno::UNO_QUERY ) + { + } + + ~ComboBoxImpl (); + + sal_uInt16 InsertEntry( OUString const& rStr, sal_uInt16 nPos ) + { + if ( nPos == COMBOBOX_APPEND ) + nPos = GetEntryCount(); + mxComboBox->addItem( rtl::OUString( rStr ), nPos ); + return nPos; + } + + void RemoveEntry( sal_uInt16 nPos ) + { + mxComboBox->removeItems( nPos, 1 ); + } + + sal_uInt16 GetEntryPos( String const& rStr ) const + { + uno::Sequence< rtl::OUString> aItems( mxComboBox->getItems() ); + rtl::OUString rKey( rStr ); + sal_uInt16 n = sal::static_int_cast< sal_uInt16 >(aItems.getLength()); + for (sal_uInt16 i = 0; i < n; i++) + { + if ( aItems[ i ] == rKey ) + return i; + } + return COMBOBOX_ENTRY_NOTFOUND; + } + + OUString GetEntry( sal_uInt16 nPos ) const + { + return OUString( mxComboBox->getItem( nPos ) ); + } + + sal_uInt16 GetEntryCount() const + { + return mxComboBox->getItemCount(); + } + + void SetClickHdl( Link const& link ) + { + if (!link && !!maClickHdl) + mxComboBox->removeActionListener( this ); + else if (!!link && !maClickHdl) + mxComboBox->addActionListener( this ); + maClickHdl = link; + } + + void SetSelectHdl( Link const& link ) + { + if (!link && !!maSelectHdl) + mxComboBox->removeItemListener( this ); + else if (!!link && !maSelectHdl) + mxComboBox->addItemListener( this ); + maSelectHdl = link; + } + + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException); + + void SAL_CALL actionPerformed (const awt::ActionEvent&) + throw (uno::RuntimeException) + { + ComboBox* pComboBox = static_cast<ComboBox*>( mpWindow ); + if ( !pComboBox ) + return; + maClickHdl.Call( pComboBox ); + } + + void SAL_CALL itemStateChanged( awt::ItemEvent const&) + throw (uno::RuntimeException) + { + ComboBox* pComboBox = static_cast<ComboBox*>( mpWindow ); + if ( !pComboBox ) + return; + maSelectHdl.Call( pComboBox ); + } +}; + +ComboBox::~ComboBox () +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: deleting ComboBox for window: %p", __FUNCTION__, GetWindow ()); +#endif +} + +ComboBoxImpl::~ComboBoxImpl () +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: deleting ComboBoxImpl for window: %p", __FUNCTION__, mpWindow ? mpWindow->GetWindow () : 0); + OSL_TRACE ("%s: deleting ComboBoxImpl for listener: %p", __FUNCTION__, static_cast<XFocusListener*> (this)); +#endif +} + +void ComboBoxImpl::disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) +{ + EditImpl::disposing (e); + mxComboBox.clear (); +} + +sal_uInt16 ComboBox::InsertEntry( String const& rStr, sal_uInt16 nPos ) +{ + return getImpl().InsertEntry( rStr, nPos ); +} + +void ComboBox::RemoveEntry( String const& rStr ) +{ + getImpl().RemoveEntry( GetEntryPos( rStr ) ); +} + +void ComboBox::RemoveEntry( sal_uInt16 nPos ) +{ + getImpl().RemoveEntry( nPos ); +} + +void ComboBox::Clear() +{ + uno::Sequence< rtl::OUString> aNoItems; + getImpl().setProperty( "StringItemList", uno::Any( aNoItems ) ); +} + +sal_uInt16 ComboBox::GetEntryPos( String const& rStr ) const +{ + return getImpl().GetEntryPos( rStr ); +} + +String ComboBox::GetEntry( sal_uInt16 nPos ) const +{ + rtl::OUString rItem = getImpl().mxComboBox->getItem( nPos ); + return OUString( rItem ); +} + +sal_uInt16 ComboBox::GetEntryCount() const +{ + return getImpl().GetEntryCount(); +} + +void ComboBox::SetClickHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxComboBox.is ()) + getImpl().SetClickHdl( link ); +} + +void ComboBox::SetSelectHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxComboBox.is ()) + getImpl().SetSelectHdl( link ); +} + +void ComboBox::EnableAutocomplete (bool enable, bool matchCase) +{ + GetComboBox ()->EnableAutocomplete (enable, matchCase); +} + +IMPL_CONSTRUCTORS_BODY( ComboBox, Edit, "combobox", getImpl().parent = parent; ); +IMPL_GET_WINDOW (ComboBox); +/// IMPL_GET_IMPL( ComboBox ); + +static ComboBoxImpl* null_combobox_impl = 0; + +ComboBoxImpl &ComboBox::getImpl () const +{ + if (ComboBoxImpl* c = static_cast<ComboBoxImpl *>(mpImpl)) + return *c; + return *null_combobox_impl; +} + +class ListBoxImpl : public ControlImpl + , public ::cppu::WeakImplHelper1< awt::XActionListener > + , public ::cppu::WeakImplHelper1< awt::XItemListener > + , public ::cppu::WeakImplHelper1< awt::XMouseListener > +{ + Link maClickHdl; + Link maSelectHdl; + Link maDoubleClickHdl; + +public: + uno::Reference< awt::XListBox > mxListBox; + ListBoxImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxListBox( peer, uno::UNO_QUERY ) + { + SelectEntryPos (0, true); + } + + sal_uInt16 InsertEntry (String const& rStr, sal_uInt16 nPos) + { + if ( nPos == LISTBOX_APPEND ) + nPos = mxListBox->getItemCount(); + mxListBox->addItem( rtl::OUString( rStr ), nPos ); + return nPos; + } + + void RemoveEntry( sal_uInt16 nPos ) + { + mxListBox->removeItems( nPos, 1 ); + } + + sal_uInt16 RemoveEntry( String const& rStr, sal_uInt16 nPos) + { + if ( nPos == LISTBOX_APPEND ) + nPos = mxListBox->getItemCount(); + mxListBox->addItem( rtl::OUString( rStr ), nPos ); + return nPos; + } + + sal_uInt16 GetEntryPos( String const& rStr ) const + { + uno::Sequence< rtl::OUString> aItems( mxListBox->getItems() ); + rtl::OUString rKey( rStr ); + sal_uInt16 n = sal::static_int_cast< sal_uInt16 >(aItems.getLength()); + for (sal_uInt16 i = 0; i < n; i++) + { + if ( aItems[ i ] == rKey ) + return i; + } + return LISTBOX_ENTRY_NOTFOUND; + } + + OUString GetEntry( sal_uInt16 nPos ) const + { + return mxListBox->getItem( nPos ); + } + + sal_uInt16 GetEntryCount() const + { + return mxListBox->getItemCount(); + } + + void SelectEntryPos( sal_uInt16 nPos, bool bSelect ) + { + mxListBox->selectItemPos( nPos, bSelect ); + } + + sal_uInt16 GetSelectEntryCount() const + { + return sal::static_int_cast< sal_uInt16 >( mxListBox->getSelectedItems().getLength() ); + } + + sal_uInt16 GetSelectEntryPos( sal_uInt16 nSelIndex ) const + { + sal_uInt16 nSelected = 0; + if ( mxListBox->isMutipleMode() ) + { + uno::Sequence< short > aItems( mxListBox->getSelectedItemsPos() ); + if ( nSelIndex < aItems.getLength() ) + nSelected = aItems[ nSelIndex ]; + } + else + nSelected = mxListBox->getSelectedItemPos(); + return nSelected; + } + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ControlImpl::disposing (e); + mxListBox.clear (); + } + + Link& GetClickHdl () + { + return maClickHdl; + } + + void SetClickHdl( Link const& link ) + { + if (!link && !!maClickHdl) + mxListBox->removeActionListener( this ); + else if (!!link && !maClickHdl) + mxListBox->addActionListener( this ); + maClickHdl = link; + } + + void SAL_CALL actionPerformed( const awt::ActionEvent& /* rEvent */ ) + throw (uno::RuntimeException) + { + maClickHdl.Call( mpWindow ); + } + + Link& GetSelectHdl () + { + return maSelectHdl; + } + + void SetSelectHdl( Link const& link ) + { + if (!link && !!maSelectHdl) + mxListBox->removeItemListener( this ); + else if (!!link && !maSelectHdl) + mxListBox->addItemListener( this ); + maSelectHdl = link; + } + + void SAL_CALL itemStateChanged (awt::ItemEvent const&) + throw (uno::RuntimeException) + { + maSelectHdl.Call (static_cast <ListBox*> (mpWindow)); + } + + Link& GetDoubleClickHdl () + { + return maDoubleClickHdl; + } + + void SetDoubleClickHdl (Link const& link) + { + if (!link && !!maDoubleClickHdl) + mxWindow->removeMouseListener (this); + else if (!!link && !maSelectHdl) + mxWindow->addMouseListener (this); + maDoubleClickHdl = link; + } + + void SAL_CALL mousePressed (awt::MouseEvent const&) throw (uno::RuntimeException) + { + } + void SAL_CALL mouseReleased (awt::MouseEvent const& e) throw (uno::RuntimeException) + { + if (e.ClickCount == 2) + maDoubleClickHdl.Call (mpWindow); + } + void SAL_CALL mouseEntered (awt::MouseEvent const&) throw (uno::RuntimeException) + { + } + void SAL_CALL mouseExited (awt::MouseEvent const&) throw (uno::RuntimeException) + { + } +}; + +ListBox::~ListBox () +{ +} + +sal_uInt16 ListBox::InsertEntry (String const& rStr, sal_uInt16 nPos) +{ + return getImpl().InsertEntry(rStr, nPos); +} + +void ListBox::RemoveEntry( sal_uInt16 nPos ) +{ + return getImpl().RemoveEntry( nPos ); +} + +void ListBox::RemoveEntry( String const& rStr ) +{ + return getImpl().RemoveEntry( GetEntryPos( rStr ) ); +} + +void ListBox::Clear() +{ + uno::Sequence< rtl::OUString> aNoItems; + getImpl().setProperty( "StringItemList", uno::Any( aNoItems ) ); +} + +sal_uInt16 ListBox::GetEntryPos( String const& rStr ) const +{ + return getImpl().GetEntryPos( rStr ); +} + +String ListBox::GetEntry( sal_uInt16 nPos ) const +{ + return getImpl().GetEntry( nPos ); +} + +sal_uInt16 ListBox::GetEntryCount() const +{ + return getImpl().GetEntryCount(); +} + +void ListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect ) +{ +#if LAYOUT_API_CALLS_HANDLER + getImpl().SelectEntryPos( nPos, bSelect ); +#else /* !LAYOUT_API_CALLS_HANDLER */ + GetListBox ()->SelectEntryPos (nPos, bSelect); +#endif /* !LAYOUT_API_CALLS_HANDLER */ +} + +void ListBox::SelectEntry( String const& rStr, bool bSelect ) +{ + SelectEntryPos( GetEntryPos( rStr ), bSelect ); +} + +sal_uInt16 ListBox::GetSelectEntryCount() const +{ + return getImpl().GetSelectEntryCount(); +} + +sal_uInt16 ListBox::GetSelectEntryPos( sal_uInt16 nSelIndex ) const +{ + return getImpl().GetSelectEntryPos( nSelIndex ); +} + +String ListBox::GetSelectEntry( sal_uInt16 nSelIndex ) const +{ + return GetEntry( GetSelectEntryPos( nSelIndex ) ); +} + +Link& ListBox::GetSelectHdl () +{ + return getImpl ().GetSelectHdl (); +} + +void ListBox::SetSelectHdl( Link const& link ) +{ + getImpl().SetSelectHdl( link ); +} + +Link& ListBox::GetClickHdl () +{ + return getImpl ().GetSelectHdl (); +} + +void ListBox::SetClickHdl( Link const& link ) +{ + if (&getImpl () && getImpl().mxListBox.is ()) + getImpl().SetClickHdl( link ); +} + +Link& ListBox::GetDoubleClickHdl () +{ + return getImpl ().GetSelectHdl (); +} + +void ListBox::SetDoubleClickHdl( Link const& link ) +{ + getImpl().SetDoubleClickHdl( link ); +} + +void ListBox::SetEntryData( sal_uInt16 pos, void* data) +{ + GetListBox ()->SetEntryData (pos, data); +} + +void* ListBox::GetEntryData( sal_uInt16 pos) const +{ + return GetListBox ()->GetEntryData (pos); +} + +void ListBox::SetNoSelection () +{ + GetListBox ()->SetNoSelection (); +} + +IMPL_CONSTRUCTORS (ListBox, Control, "listbox"); +IMPL_GET_IMPL (ListBox); +IMPL_GET_WINDOW (ListBox); + +IMPL_IMPL (MultiListBox, ListBox) +IMPL_CONSTRUCTORS_BODY( MultiListBox, ListBox, "multilistbox", GetMultiListBox()->EnableMultiSelection( true ); ); +IMPL_GET_IMPL( MultiListBox ); +IMPL_GET_WINDOW( MultiListBox ); +} // namespace layout diff --git a/toolkit/source/layout/vcl/wrapper.cxx b/toolkit/source/layout/vcl/wrapper.cxx new file mode 100644 index 000000000000..0e2eec91773e --- /dev/null +++ b/toolkit/source/layout/vcl/wrapper.cxx @@ -0,0 +1,1630 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile$ + * + * $Revision$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/rc.h> +//#define RESOURCE_PUBLISH_PROTECTED 1 +#if RESOURCE_PUBLISH_PROTECTED +// ugh, override non-helpful proctection +#define protected public +#endif /* RESOURCE_PUBLISH_PROTECTED */ +#include <tools/rc.hxx> +#undef protected + + +#include "wrapper.hxx" + +#include <awt/vclxplugin.hxx> +#include <awt/vclxtabcontrol.hxx> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/XDialog2.hpp> +#include <com/sun/star/awt/XProgressBar.hpp> +#include <com/sun/star/awt/XSimpleTabController.hpp> +#include <com/sun/star/awt/XTabListener.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <comphelper/processfactory.hxx> +#include <layout/core/factory.hxx> +#include <layout/core/localized-string.hxx> +#include <layout/core/root.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <vcl/ctrl.hxx> +#include <vcl/dialog.hxx> +#include <vcl/image.hxx> +#include <vcl/tabctrl.hxx> +#include <vcl/tabpage.hxx> +#include <vcl/window.hxx> + +using namespace ::com::sun::star; +using rtl::OUString; + +namespace layout +{ + +// Context bits ... +class ContextImpl +{ + uno::Reference< awt::XLayoutRoot > mxRoot; + uno::Reference< container::XNameAccess > mxNameAccess; + PeerHandle mxTopLevel; + +public: + ContextImpl( char const *pPath ) + { + uno::Sequence< uno::Any > aParams( 1 ); + aParams[0] <<= OUString( pPath, strlen( pPath ), RTL_TEXTENCODING_UTF8 ); + + uno::Reference< lang::XSingleServiceFactory > xFactory( + comphelper::createProcessComponent( + OUString::createFromAscii( "com.sun.star.awt.Layout" ) ), + uno::UNO_QUERY ); + if ( !xFactory.is() ) + { + throw uno::RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ), + uno::Reference< uno::XInterface >() ); + } + mxRoot = uno::Reference< awt::XLayoutRoot >( + xFactory->createInstanceWithArguments( aParams ), + uno::UNO_QUERY ); + + mxNameAccess = uno::Reference< container::XNameAccess >( mxRoot, uno::UNO_QUERY ); + } + + ~ContextImpl() + { + } + + PeerHandle getByName( const OUString &rName ) + { + uno::Any val = mxNameAccess->getByName( rName ); + PeerHandle xRet; + val >>= xRet; + return xRet; + } + PeerHandle getTopLevel() + { + return mxTopLevel; + } + void setTopLevel( PeerHandle xToplevel ) + { + mxTopLevel = xToplevel; + } + PeerHandle getRoot() + { + return mxRoot; + } +}; + +Context::Context( const char *pPath ) + : pImpl( new ContextImpl( pPath ) ) +{ +} +Context::~Context() +{ + delete pImpl; + pImpl = NULL; +} + +void Context::setToplevel( PeerHandle xToplevel ) +{ + pImpl->setTopLevel( xToplevel ); +} + +PeerHandle Context::getToplevel() +{ + return pImpl->getTopLevel(); +} +PeerHandle Context::getRoot() +{ + return pImpl->getRoot(); +} + +PeerHandle Context::GetPeerHandle( const char *id, sal_uInt32 nId ) const +{ + PeerHandle xHandle; + xHandle = pImpl->getByName( OUString( id, strlen( id ), RTL_TEXTENCODING_UTF8 ) ); + if ( !xHandle.is() ) + { + DBG_ERROR1( "Failed to fetch widget '%s'", id ); + } + + if ( nId != 0 ) + { + rtl::OString aStr = rtl::OString::valueOf( (sal_Int32) nId ); + xHandle = GetPeerHandle( aStr, 0 ); + } + return xHandle; +} + +WindowImpl::WindowImpl (Context *context, const PeerHandle &peer, Window *window) + : mpWindow (window) + , mpCtx (context) + , mxWindow (peer, uno::UNO_QUERY) + , mxVclPeer (peer, uno::UNO_QUERY) + , mvclWindow (0) + , bFirstTimeVisible (true) +{ +} + +WindowImpl::~WindowImpl () +{ + if (mpWindow) + mpWindow->mpImpl = 0; + if (mvclWindow) + { + VCLXWindow *v = mvclWindow->GetWindowPeer (); + v->SetWindow (0); + mvclWindow->SetComponentInterface (uno::Reference <awt::XWindowPeer> ()); + mvclWindow->SetWindowPeer (uno::Reference <awt::XWindowPeer> (), 0); + delete mvclWindow; + mvclWindow = 0; + } +} + +void WindowImpl::wrapperGone () +{ + mvclWindow = 0; + mpWindow->mpImpl = 0; + mpWindow = 0; + mpCtx = 0; + if ( mxWindow.is() ) + { + uno::Reference< lang::XComponent > xComp( mxWindow, uno::UNO_QUERY ); + mxWindow.clear (); + if ( xComp.is() ) + xComp->dispose(); + } +} + +void SAL_CALL WindowImpl::disposing (lang::EventObject const&) + throw (uno::RuntimeException) +{ + if (mxWindow.is ()) + mxWindow.clear (); +} + +uno::Any WindowImpl::getProperty (char const* name) +{ + if ( !this || !mxVclPeer.is() ) + return css::uno::Any(); + return mxVclPeer->getProperty + ( rtl::OUString( name, strlen( name ), RTL_TEXTENCODING_ASCII_US ) ); +} + +void WindowImpl::setProperty (char const *name, uno::Any any) +{ + if ( !this || !mxVclPeer.is() ) + return; + mxVclPeer->setProperty + ( rtl::OUString( name, strlen( name ), RTL_TEXTENCODING_ASCII_US ), any ); +} + +void WindowImpl::redraw (bool resize) +{ + uno::Reference <awt::XWindow> ref (mxWindow, uno::UNO_QUERY); + ::Window* window = VCLXWindow::GetImplementation (ref)->GetWindow (); + ::Window* parent = window->GetParent(); + ::Rectangle r = Rectangle (parent->GetPosPixel (), + parent->GetSizePixel ()); + parent->Invalidate (r, INVALIDATE_CHILDREN | INVALIDATE_NOCHILDREN ); + if (resize) + parent->SetPosSizePixel (0, 0, 1, 1, awt::PosSize::SIZE); + else + parent->SetPosSizePixel (0, 0, r.nRight - r.nLeft, r.nBottom - r.nTop, + awt::PosSize::SIZE); +} + +Window::Window( WindowImpl *pImpl ) + : mpImpl( pImpl ) +{ + mpImpl->mvclWindow = GetVCLXWindow () ? GetWindow () : 0; +} + +Window::~Window() +{ + /* likely to be an UNO object - with floating references */ + if (mpImpl) + mpImpl->wrapperGone (); + mpImpl = 0; +} + +///IMPL_GET_IMPL( Control ); + +static ControlImpl* null_control_impl = 0; + +ControlImpl &Control::getImpl () const +{ + if (ControlImpl* c = static_cast<ControlImpl *>(mpImpl)) + return *c; + return *null_control_impl; +} + +Control::~Control () +{ + SetGetFocusHdl (Link ()); + SetLoseFocusHdl (Link ()); +} + +void Window::setRes (ResId const& res) +{ +#if RESOURCE_PUBLISH_PROTECTED + // Resources are shut-off from use. Is that really necessary? + Resource &r = *GetWindow (); + r.GetRes (res); +#else /* !RESOURCE_PUBLISH_PROTECTED */ + //We *must* derive. Is this also really necessary? + //Resource r (res); + + // ugh, I wonder which solution is cleaner... + class Resource_open_up : public Resource + { + public: + Resource_open_up (ResId const& r) + : Resource (r) + { + } + static sal_Int32 GetLongRes (void *p) + { + return Resource::GetLongRes (p); + } + void* GetClassRes () + { + return Resource::GetClassRes (); + } + sal_Int32 ReadLongRes () + { + return Resource::ReadLongRes (); + } + UniString ReadStringRes () + { + return Resource::ReadStringRes (); + } + }; + + Resource_open_up r (res); +#endif /* !RESOURCE_PUBLISH_PROTECTED */ + if (sal_uInt32 help_id = (sal_uInt32)r.GetLongRes (static_cast<char *> (r.GetClassRes ()) + 12)) + SetHelpId (help_id); + sal_uInt32 mask = r.ReadLongRes (); + if ( mask & WINDOW_TEXT ) + SetText( r.ReadStringRes ()); +} + +void Window::SetParent( ::Window *parent ) +{ + uno::Reference <awt::XWindow> ref( GetPeer(), uno::UNO_QUERY ); + if (VCLXWindow *vcl = VCLXWindow::GetImplementation( ref )) + if (::Window *window = vcl->GetWindow()) + window->SetParent( parent ); +} + +void Window::SetParent( Window *parent ) +{ + /* Let's hear it for C++: poor man's dynamic binding. */ + parent->ParentSet (this); +} + +void Window::ParentSet (Window *window) +{ + window->SetParent (GetWindow ()); +} + +Context *Window::getContext() +{ + return this && mpImpl ? mpImpl->mpCtx : NULL; +} + +PeerHandle Window::GetPeer() const +{ + if ( !mpImpl ) + return PeerHandle(); + return mpImpl->mxWindow; +} + +uno::Reference<awt::XWindow> Window::GetRef() const +{ + return uno::Reference <awt::XWindow> ( GetPeer(), uno::UNO_QUERY ); +} + +VCLXWindow* Window::GetVCLXWindow() const +{ + return VCLXWindow::GetImplementation( GetRef() ); +} + +::Window* Window::GetWindow() const +{ + return GetVCLXWindow()->GetWindow(); +} + +::Window* Window::GetParent() const +{ + return GetWindow()->GetParent(); +} + +void Window::SetHelpId( sal_uIntPtr id ) +{ + GetWindow()->SetHelpId( id ); +} + +sal_uIntPtr Window::GetHelpId() const +{ + return GetWindow()->GetHelpId(); +} + +void Window::SetSmartHelpId( SmartId const& id, SmartIdUpdateMode mode ) +{ + GetWindow()->SetSmartHelpId( id, mode ); +} + +SmartId Window::GetSmartHelpId() const +{ + return GetWindow()->GetSmartHelpId(); +} + +void Window::EnterWait () +{ + GetWindow()->EnterWait (); +} +void Window::LeaveWait () +{ + GetWindow()->LeaveWait (); +} +bool Window::IsWait () const +{ + return GetWindow()->IsWait (); +} + +bool Window::IsVisible () const +{ + if (GetWindow ()) + return GetWindow()->IsVisible (); + return false; +} + +bool Window::HasChildPathFocus (bool systemWindow) const +{ + return GetWindow()->HasChildPathFocus (systemWindow); +} + +void Window::SetPosPixel (Point const&) +{ +} + +Point Window::GetPosPixel () const +{ + return Point (); +} + +void Window::SetSizePixel (Size const&) +{ +} + +void Window::SetPosSizePixel (Point const&, Size const&) +{ +} + +Size Window::GetSizePixel () const +{ + return Size (); +} + +// void Window::Enable (bool enable, bool child); +// { +// GetWindow ()->Enable (enable, child); +// } + +// void Window::Disable (bool child) +// { +// GetWindow ()->Disable (child); +// } + +bool Window::IsEnabled () const +{ + return GetWindow ()->IsEnabled (); +// if (getImpl().mxWindow.is ()) +// return getImpl ().mxWindow->isEnabled (); +// return false; +} + +void Window::EnableInput (bool enable, bool child) +{ + GetWindow ()->EnableInput (enable, child); +} + +bool Window::IsInputEnabled () const +{ + return GetWindow ()->IsInputEnabled (); +} + +bool Window::HasFocus () const +{ + return GetWindow ()->HasFocus (); +} + +Font& Window::GetFont () const +{ + return const_cast <Font&> (GetWindow ()->GetFont ()); +} + +void Window::SetFont (Font const& font) +{ + GetWindow ()->SetFont (font); +} + +void Window::Invalidate (sal_uInt8 flags) +{ + GetWindow ()->Invalidate (flags); +} + +struct ToolkitVclPropsMap +{ + WinBits vclStyle; + long initAttr; + const char *propName; + + // the value to give the prop to enable/disable it -- not the most brilliant + // type declaration and storage, but does the work... properties are + // either a boolean or a short since they are either a directly wrappers for + // a WinBit, or aggregates related (like Align for WB_LEFT, _RIGHT and _CENTER). + bool isBoolean; + short enableProp, disableProp; +}; + +#define TYPE_BOOL true +#define TYPE_SHORT false +#define NOTYPE 0 +static const ToolkitVclPropsMap toolkitVclPropsMap[] = +{ + { WB_BORDER, awt::WindowAttribute::BORDER, "Border", TYPE_SHORT, 1, 0 }, + { WB_NOBORDER, awt::VclWindowPeerAttribute::NOBORDER, "Border", TYPE_SHORT, 0, 1 }, + { WB_SIZEABLE, awt::WindowAttribute::SIZEABLE, NULL, NOTYPE, 0, 0 }, + { WB_MOVEABLE, awt::WindowAttribute::MOVEABLE, NULL, NOTYPE, 0, 0 }, + { WB_CLOSEABLE, awt::WindowAttribute::CLOSEABLE, NULL, NOTYPE, 0, 0 }, + + { WB_HSCROLL, awt::VclWindowPeerAttribute::HSCROLL, NULL, NOTYPE, 0, 0 }, + { WB_VSCROLL, awt::VclWindowPeerAttribute::VSCROLL, NULL, NOTYPE, 0, 0 }, + { WB_LEFT, awt::VclWindowPeerAttribute::LEFT, "Align", TYPE_SHORT, 0, 0 }, + { WB_CENTER, awt::VclWindowPeerAttribute::CENTER, "Align", TYPE_SHORT, 1, 0 }, + { WB_RIGHT, awt::VclWindowPeerAttribute::RIGHT, "Align", TYPE_SHORT, 2, 0 }, + { WB_SPIN, awt::VclWindowPeerAttribute::SPIN, NULL, NOTYPE, 0, 0 }, + { WB_SORT, awt::VclWindowPeerAttribute::SORT, NULL, NOTYPE, 0, 0 }, + { WB_DROPDOWN, awt::VclWindowPeerAttribute::DROPDOWN, "Dropdown", TYPE_BOOL, 1, 0 }, + { WB_DEFBUTTON, awt::VclWindowPeerAttribute::DEFBUTTON, "DefaultButton", TYPE_BOOL, 1, 0 }, + { WB_READONLY, awt::VclWindowPeerAttribute::READONLY, NULL, NOTYPE, 0, 0 }, + { WB_CLIPCHILDREN, awt::VclWindowPeerAttribute::CLIPCHILDREN, NULL, NOTYPE, 0, 0 }, + { WB_GROUP, awt::VclWindowPeerAttribute::GROUP, NULL, NOTYPE, 0, 0 }, + + { WB_OK, awt::VclWindowPeerAttribute::OK, NULL, NOTYPE, 0, 0 }, + { WB_OK_CANCEL, awt::VclWindowPeerAttribute::OK_CANCEL, NULL, NOTYPE, 0, 0 }, + { WB_YES_NO, awt::VclWindowPeerAttribute::YES_NO, NULL, NOTYPE, 0, 0 }, + { WB_YES_NO_CANCEL, awt::VclWindowPeerAttribute::YES_NO_CANCEL, NULL, NOTYPE, 1, 0 }, + { WB_RETRY_CANCEL, awt::VclWindowPeerAttribute::RETRY_CANCEL, NULL, NOTYPE, 1, 0 }, + { WB_DEF_OK, awt::VclWindowPeerAttribute::DEF_OK, NULL, NOTYPE, 0, 0 }, + { WB_DEF_CANCEL, awt::VclWindowPeerAttribute::DEF_CANCEL, NULL, NOTYPE, 1, 0 }, + { WB_DEF_RETRY, awt::VclWindowPeerAttribute::DEF_RETRY, NULL, NOTYPE, 0, 0 }, + { WB_DEF_YES, awt::VclWindowPeerAttribute::DEF_YES, NULL, NOTYPE, 0, 0 }, + { WB_DEF_NO, awt::VclWindowPeerAttribute::DEF_NO, NULL, NOTYPE, 0, 0 }, + + { WB_AUTOHSCROLL, awt::VclWindowPeerAttribute::AUTOHSCROLL, "AutoHScroll", TYPE_BOOL, 1, 0 }, + { WB_AUTOVSCROLL, awt::VclWindowPeerAttribute::AUTOVSCROLL, "AutoVScroll", TYPE_BOOL, 1, 0 }, + + { WB_WORDBREAK, 0, "MultiLine", TYPE_BOOL, 1, 0 }, + { WB_NOPOINTERFOCUS, 0, "FocusOnClick", TYPE_BOOL, 1, 0 }, + { WB_TOGGLE, 0, "Toggle", TYPE_BOOL, 1, 0 }, + { WB_REPEAT, 0, "Repeat", TYPE_BOOL, 1, 0 }, + { WB_NOHIDESELECTION, 0, "HideInactiveSelection", TYPE_BOOL, 1, 0 }, +}; +#undef TYPE_BOOL +#undef TYPE_SHORT +#undef NOTYPE + +static const int toolkitVclPropsMapLen = + sizeof( toolkitVclPropsMap ) / sizeof( ToolkitVclPropsMap ); + +void Window::SetStyle( WinBits nStyle ) +{ + uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer; + for (int i = 0; i < toolkitVclPropsMapLen; i++) + { + if ( toolkitVclPropsMap[ i ].propName ) + { + short nValue; + if ( nStyle & toolkitVclPropsMap[ i ].vclStyle ) + nValue = toolkitVclPropsMap[ i ].enableProp; + else + nValue = toolkitVclPropsMap[ i ].disableProp; + uno::Any aValue; + if ( toolkitVclPropsMap[ i ].isBoolean ) + aValue = uno::makeAny( (bool) nValue ); + else + aValue = uno::makeAny( (short) nValue ); + mpImpl->setProperty( toolkitVclPropsMap[ i ].propName, aValue ); + } + } +} + +WinBits Window::GetStyle() +{ + uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer; + WinBits ret = 0; + for (int i = 0; i < toolkitVclPropsMapLen; i++) + { + if ( toolkitVclPropsMap[ i ].propName ) + { + short nValue = 0; + if ( toolkitVclPropsMap[ i ].isBoolean ) + { + bool bValue = false; + mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= bValue; + nValue = bValue ? 1 : 0; + } + else + mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= nValue; + if ( nValue == toolkitVclPropsMap[ i ].enableProp ) + ret |= toolkitVclPropsMap[i].vclStyle; + } + } + return ret; +} + +/* Unpleasant way to get an xToolkit pointer ... */ +uno::Reference< awt::XToolkit > getToolkit() +{ + static uno::Reference< awt::XToolkit > xToolkit; + if (!xToolkit.is()) + { + // Urgh ... + xToolkit = uno::Reference< awt::XToolkit >( + ::comphelper::getProcessServiceFactory()->createInstance( + OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ), + uno::UNO_QUERY ); + if ( !xToolkit.is() ) + throw uno::RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM( "failed to create toolkit!") ), + uno::Reference< uno::XInterface >() ); + } + return xToolkit; +} + +PeerHandle Window::CreatePeer( Window *parent, WinBits nStyle, const char *pName) +{ + long nWinAttrbs = 0; + for (int i = 0; i < toolkitVclPropsMapLen; i++) + if ( nStyle & toolkitVclPropsMap[ i ].vclStyle ) + nWinAttrbs |= toolkitVclPropsMap[ i ].initAttr; + + return layoutimpl::WidgetFactory::createWidget (getToolkit(), parent->GetPeer(), OUString::createFromAscii( pName ), nWinAttrbs); +} + +void Window::Enable( bool bEnable ) +{ + if ( !getImpl().mxWindow.is() ) + return; + getImpl().mxWindow->setEnable( bEnable ); +} + +void Window::Show( bool bVisible ) +{ + if ( !getImpl().mxWindow.is() ) + return; + getImpl().mxWindow->setVisible( bVisible ); + if (!bVisible) + getImpl ().bFirstTimeVisible = true; + else if (GetParent() && getImpl().bFirstTimeVisible) + { + getImpl().redraw (); + getImpl().bFirstTimeVisible = false; + } +} + +void Window::GrabFocus() +{ + if ( !getImpl().mxWindow.is() ) + return; + getImpl().mxWindow->setFocus(); +} + +void Window::SetUpdateMode(bool mode) +{ + GetWindow()->SetUpdateMode( mode ); +} + +void Window::SetPointer( Pointer const& pointer ) +{ + GetWindow()->SetPointer( pointer ); +} + +Pointer const& Window::GetPointer() const +{ + return GetWindow()->GetPointer(); +} + +void Window::SetText( OUString const& str ) +{ + GetWindow()->SetText( str ); +} + +String Window::GetText() const +{ + return GetWindow()->GetText(); +} + +sal_Int32 Window::GetCtrlTextWidth (OUString const&) const +{ + return 0; +} + +sal_Int32 Window::GetTextHeight () const +{ + return 0; +} + +Size Window::LogicToPixel( Size const& size, MapMode const&) const +{ + return size; +} + +ControlImpl::ControlImpl (Context *context, const PeerHandle &peer, Window *window) + : WindowImpl( context, peer, window ) +{ +} + +ControlImpl::~ControlImpl () +{ + if ((!!mGetFocusHdl || !!mLoseFocusHdl) && mxWindow.is ()) + /* Disposing will be done @ VCLXWindow::dispose () maFocusListeners.disposeAndClear() + don't do it twice */ + mxWindow.clear (); +} + +void ControlImpl::SetGetFocusHdl (Link const& link) +{ + if (!mLoseFocusHdl || !link) + UpdateListening (link); + mGetFocusHdl = link; +} + +Link& ControlImpl::GetGetFocusHdl () +{ + return mGetFocusHdl; +} + +void ControlImpl::SetLoseFocusHdl (Link const& link) +{ + if (!mGetFocusHdl || !link) + UpdateListening (link); + mLoseFocusHdl = link; +} + +Link& ControlImpl::GetLoseFocusHdl () +{ + return mGetFocusHdl; +} + +void ControlImpl::UpdateListening (Link const& link) +{ + if (!link && (!!mGetFocusHdl || !!mLoseFocusHdl) + && (!mGetFocusHdl || !mLoseFocusHdl)) + mxWindow->removeFocusListener (this); + else if (!!link && !mGetFocusHdl && !mLoseFocusHdl) + mxWindow->addFocusListener (this); +} + +void SAL_CALL ControlImpl::disposing (lang::EventObject const&) + throw (uno::RuntimeException) +{ +/// mxWindow.clear (); +} + +void SAL_CALL ControlImpl::focusGained (awt::FocusEvent const&) + throw (uno::RuntimeException) +{ + mGetFocusHdl.Call (mpWindow); +} + +void SAL_CALL ControlImpl::focusLost (awt::FocusEvent const&) + throw (uno::RuntimeException) +{ + mLoseFocusHdl.Call (mpWindow); +} + +Link& Control::GetGetFocusHdl () +{ + return getImpl ().GetGetFocusHdl (); +} + +void Control::SetGetFocusHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxWindow.is ()) + getImpl ().SetGetFocusHdl (link); +} + +Link& Control::GetLoseFocusHdl () +{ + return getImpl ().GetLoseFocusHdl (); +} + +void Control::SetLoseFocusHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxWindow.is ()) + getImpl ().SetLoseFocusHdl (link); +} + +class DialogImpl : public WindowImpl +{ +public: + uno::Reference< awt::XDialog2 > mxDialog; + DialogImpl( Context *context, PeerHandle const &peer, Window *window ); +}; + +DialogImpl::DialogImpl( Context *context, const PeerHandle &peer, Window *window ) + : WindowImpl( context, peer, window ) + , mxDialog( peer, uno::UNO_QUERY ) +{ +} + +Dialog::Dialog( Window *parent, const char *xml_file, const char *id, sal_uInt32 nId ) + : Context( xml_file ) + , Window( new DialogImpl( this, Context::GetPeerHandle( id, nId ), this ) ) + , bConstruct (true) +{ + if ( parent ) + SetParent( parent ); +} + +Dialog::Dialog( ::Window *parent, const char *xml_file, const char *id, sal_uInt32 nId ) + : Context( xml_file ) + , Window( new DialogImpl( this, Context::GetPeerHandle( id, nId ), this ) ) +{ + if ( parent ) + SetParent( parent ); +} + +Dialog::~Dialog () +{ +} + +IMPL_GET_WINDOW (Dialog); +IMPL_GET_IMPL (Dialog); + +#define MX_DIALOG if (getImpl ().mxDialog.is ()) getImpl ().mxDialog +#define RETURN_MX_DIALOG if (getImpl ().mxDialog.is ()) return getImpl ().mxDialog + +short Dialog::Execute() +{ + RETURN_MX_DIALOG->execute (); + return -1; +} + +void Dialog::EndDialog( long result ) +{ + MX_DIALOG->endDialog (result); +} + +void Dialog::SetText( OUString const& str ) +{ + SetTitle (str); +} + +void Dialog::SetTitle( OUString const& str ) +{ + MX_DIALOG->setTitle (str); +} + +bool Dialog::Close () +{ + EndDialog (false); + return true; +} + +long Dialog::Notify (NotifyEvent& event) +{ + return GetDialog ()->Notify (event); +} + +void Dialog::Initialize (SfxChildWinInfo*) +{ +} + +#define MESSAGE_BOX_MEMBER_INIT\ + Dialog (parent, xml_file, id)\ + , imageError (this, "FI_ERROR")\ + , imageInfo (this, "FI_INFO")\ + , imageQuery (this, "FI_QUERY")\ + , imageWarning (this, "FI_WARNING")\ + , messageText (this, "FT_MESSAGE")\ + , cancelButton (this, "BTN_CANCEL")\ + , helpButton (this, "BTN_HELP")\ + , ignoreButton (this, "BTN_IGNORE")\ + , noButton (this, "BTN_NO")\ + , retryButton (this, "BTN_RETRY")\ + , yesButton (this, "BTN_YES") + +MessageBox::MessageBox (::Window *parent, char const* message, + char const* yes, char const* no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + ignoreButton.Hide (); + retryButton.Hide (); + init (message, yes, no, help_id); +} + +MessageBox::MessageBox (::Window *parent, OUString const& message, + OUString yes, OUString no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + ignoreButton.Hide (); + retryButton.Hide (); + init (message, yes, no, help_id); +} + +#if !defined (__GNUC__) +#define __PRETTY_FUNCTION__ __FUNCTION__ +#endif /* !__GNUC__ */ + +MessageBox::MessageBox (::Window *parent, WinBits bits, char const* message, + char const* yes, char const* no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + // HIG suggests using verbs instead of yes/no/retry etc. + // This constructor provides client-code compatibility: Client code should be fixed. +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: warning, deprecated vcl/Messbox compatibility", __PRETTY_FUNCTION__); +#endif + bits_init (bits, OUString::createFromAscii (message), OUString::createFromAscii (yes), OUString::createFromAscii (no), help_id); +} + +MessageBox::MessageBox (::Window *parent, WinBits bits, OUString const& message, + OUString yes, OUString no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + // HIG suggests using verbs instead of yes/no/retry etc. + // This constructor provides client-code compatibility: Client code should be fixed. +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: warning, deprecated vcl/Messbox compatibility", __PRETTY_FUNCTION__); +#endif + bits_init (bits, message, yes, no, help_id); +} + +void MessageBox::bits_init (WinBits bits, OUString const& message, + OUString yes, OUString no, sal_uIntPtr help_id) +{ + if ( bits & ( WB_OK_CANCEL | WB_OK )) + yes = Button::GetStandardText ( BUTTON_OK ); + if ( bits & (WB_YES_NO | WB_YES_NO_CANCEL )) + { + yes = Button::GetStandardText ( BUTTON_YES ); + no = Button::GetStandardText ( BUTTON_NO ); + } + if (! (bits & (WB_RETRY_CANCEL | WB_YES_NO_CANCEL | WB_ABORT_RETRY_IGNORE ))) + cancelButton.Hide (); + if (! (bits & (WB_RETRY_CANCEL | WB_ABORT_RETRY_IGNORE))) + retryButton.Hide (); + if ( bits & WB_ABORT_RETRY_IGNORE ) + cancelButton.SetText ( Button::GetStandardText (BUTTON_ABORT)); + else + ignoreButton.Hide (); + if ( !(bits & ( WB_OK | WB_OK_CANCEL | WB_YES_NO | WB_YES_NO_CANCEL))) + yesButton.Hide (); + if ( !(bits & ( WB_YES_NO | WB_YES_NO_CANCEL))) + noButton.Hide (); + + init (message, yes, no, help_id); +} + +void MessageBox::init (char const* message, char const* yes, char const* no, sal_uIntPtr help_id) +{ + init ( OUString::createFromAscii (message), OUString::createFromAscii (yes), OUString::createFromAscii (no), help_id); +} + +void MessageBox::init (OUString const& message, OUString const& yes, OUString const& no, sal_uIntPtr help_id) +{ + imageError.Hide (); + imageInfo.Hide (); + imageQuery.Hide (); + imageWarning.Hide (); + if (message.getLength ()) + messageText.SetText (message); + if (yes.getLength ()) + { + yesButton.SetText (yes); + if (yes != OUString (Button::GetStandardText (BUTTON_OK)) + && yes != OUString (Button::GetStandardText (BUTTON_YES))) + SetTitle (yes); + if (no.getLength ()) + noButton.SetText (no); + else + noButton.Hide (); + } + if (help_id) + SetHelpId (help_id); + else + helpButton.Hide (); +} + +#undef MESSAGE_BOX_IMPL +#define MESSAGE_BOX_IMPL(Name)\ + Name##Box::Name##Box (::Window *parent, char const* message,\ + char const* yes, char const* no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + }\ + Name##Box::Name##Box (::Window *parent, OUString const& message,\ + OUString yes, OUString no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + }\ + Name##Box::Name##Box (::Window *parent, WinBits bits, char const* message,\ + char const* yes, char const* no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, bits, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + }\ + Name##Box::Name##Box (::Window *parent, WinBits bits, OUString const& message,\ + OUString yes, OUString no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, bits, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + } + +MESSAGE_BOX_IMPL (Error); +MESSAGE_BOX_IMPL (Info); +MESSAGE_BOX_IMPL (Query); +MESSAGE_BOX_IMPL (Warning); + +class TabControlImpl + : public ControlImpl + , public ::cppu::WeakImplHelper1 <awt::XTabListener> +{ + Link mActivatePageHdl; + Link mDeactivatePageHdl; + +public: + uno::Reference <awt::XSimpleTabController> mxTabControl; + TabControlImpl (Context *context, const PeerHandle &peer, Window *window) + : ControlImpl (context, peer, window) + , mxTabControl (peer, uno::UNO_QUERY) + { + } + + virtual void SAL_CALL disposing (lang::EventObject const& e) + throw (uno::RuntimeException) + { + ControlImpl::disposing (e); + mxTabControl.clear (); + } + + Link& GetActivatePageHdl () + { + return mActivatePageHdl; + } + + void SetActivatePageHdl (Link const& link) + { + if (!mDeactivatePageHdl || !link) + UpdateListening (link); + mActivatePageHdl = link; + } + + Link& GetDeactivatePageHdl () + { + return mDeactivatePageHdl; + } + + void SetDeactivatePageHdl (Link const& link) + { + if (!mActivatePageHdl || !link) + UpdateListening (link); + mDeactivatePageHdl = link; + } + + void UpdateListening (Link const& link) + { + if (!link && (!!mActivatePageHdl || !!mDeactivatePageHdl)) + mxTabControl->removeTabListener (this); + else if (!!link && !mActivatePageHdl && !mDeactivatePageHdl) + mxTabControl->addTabListener (this); + } + + void SAL_CALL activated (sal_Int32) + throw (uno::RuntimeException) + { + mActivatePageHdl.Call (mpWindow); + } + + void SAL_CALL deactivated (sal_Int32) + throw (uno::RuntimeException) + { + mDeactivatePageHdl.Call (mpWindow); + } + + void SAL_CALL inserted (sal_Int32) + throw (uno::RuntimeException) + { + } + + void SAL_CALL removed (sal_Int32) + throw (uno::RuntimeException) + { + } + + void SAL_CALL changed (sal_Int32, uno::Sequence <beans::NamedValue> const&) + throw (uno::RuntimeException) + { + } +}; + +IMPL_GET_WINDOW (TabControl); +IMPL_GET_LAYOUT_VCLXWINDOW (TabControl); + +#define MX_TABCONTROL if (getImpl ().mxTabControl.is ()) getImpl ().mxTabControl +#define RETURN_MX_TABCONTROL if (getImpl ().mxTabControl.is ()) return getImpl ().mxTabControl + +TabControl::~TabControl () +{ + SetActivatePageHdl (Link ()); + SetDeactivatePageHdl (Link ()); +} + +void TabControl::InsertPage (sal_uInt16 id, OUString const& title, sal_uInt16 pos) +{ + (void) pos; +// GetTabControl ()->InsertPage (id, title, pos); +// GetTabControl ()->SetTabPage (id, new ::TabPage (GetTabControl ())); + + MX_TABCONTROL->insertTab (); + SetCurPageId (id); + +#if 1 // colour me loc productive -- NOT +#define ADD_PROP( seq, i, name, val )\ + { \ + beans::NamedValue value; \ + value.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( name ) ); \ + value.Value = uno::makeAny( val ); \ + seq[i] = value; \ + } + + uno::Sequence< beans::NamedValue > seq (1); + ADD_PROP ( seq, 0, "Title", OUString (title) ); + MX_TABCONTROL->setTabProps (id, seq); +#else + GetTabPage (id)->SetText (title); +#endif + +#if 0 + /// This so seems the right solution, but it makes the buttons of the + /// tabdialog move up + + ::TabPage *page = GetTabPage (id); + if (Window *w = dynamic_cast <Window*> (page)) + { + w->SetParent (this); + //GetVCLXTabControl ()->Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (w); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //uno::Reference <uno::XInterface> x (page->GetWindowPeer()); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->::Window::GetWindowPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetComponentInterface (), uno::UNO_QUERY)); + } + getImpl ().redraw (); +#endif +} +void TabControl::RemovePage (sal_uInt16 id) +{ + GetTabControl ()->RemovePage (id); +} +sal_uInt16 TabControl::GetPageCount () const +{ + return GetTabControl ()->GetPageCount (); +} +sal_uInt16 TabControl::GetPageId (sal_uInt16 pos) const +{ + return GetTabControl ()->GetPageId (pos); +} +sal_uInt16 TabControl::GetPagePos (sal_uInt16 id) const +{ + getImpl ().redraw (); + return GetTabControl ()->GetPagePos (id); +} +void TabControl::SetCurPageId (sal_uInt16 id) +{ + getImpl ().redraw (); + GetTabControl ()->SetCurPageId (id); +} +sal_uInt16 TabControl::GetCurPageId () const +{ + return GetTabControl ()->GetCurPageId (); +} +void TabControl::SetTabPage (sal_uInt16 id, ::TabPage* page) +{ + GetTabControl ()->SetTabPage (id, page); + +#if 0 + /// This so seems the right solution, but it makes the buttons of the + /// tabdialog move up + if (Window *w = dynamic_cast <Window*> (page)) + { + w->SetParent (this); + //GetVCLXTabControl ()->Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (w); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetWindowPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetComponentInterface (), uno::UNO_QUERY)); + } +#endif + getImpl ().redraw (); +} +::TabPage* TabControl::GetTabPage (sal_uInt16 id) const +{ + return GetTabControl ()->GetTabPage (id); +} +void TabControl::SetActivatePageHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxTabControl.is ()) + getImpl ().SetActivatePageHdl (link); +} +Link& TabControl::GetActivatePageHdl () const +{ + return getImpl ().GetActivatePageHdl (); +} +void TabControl::SetDeactivatePageHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxTabControl.is ()) + getImpl ().SetDeactivatePageHdl (link); +} +Link& TabControl::GetDeactivatePageHdl () const +{ + return getImpl ().GetDeactivatePageHdl (); +} +void TabControl::SetTabPageSizePixel (Size const& size) +{ + GetTabControl ()->SetTabPageSizePixel (size); +// GetParent()->SetSizePixel (size); +// GetWindow()->SetSizePixel (size); + //GetVCLXTabControl->SetTabSize (size); +} +Size TabControl::GetTabPageSizePixel () const +{ +#if 0 + //return GetTabControl ()->GetTabPageSizePixel (); + static size_t const tab_page_first_index = 1; + for (size_t i = 0; i < GetPageCount (); i++) + { + ::TabPage *p = GetTabPage (i + tab_page_first_index); + //if (dynamic_cast<Windowt*> (p)) + if (i) // URG + return p->GetOptimalSize (WINDOWSIZE_MINIMUM); + } +#endif + return GetTabControl ()->GetTabPageSizePixel (); +} + +IMPL_CONSTRUCTORS (TabControl, Control, "tabcontrol"); +IMPL_GET_IMPL (TabControl); + +class TabPageImpl : public WindowImpl +{ +public: + uno::Reference< awt::XWindow > mxTabPage; + TabPageImpl( Context *context, const PeerHandle &peer, Window *window ) + : WindowImpl( context, peer, window ) + , mxTabPage( peer, uno::UNO_QUERY ) + { + } +}; + +::Window* TabPage::global_parent = 0; +TabControl* TabPage::global_tabcontrol = 0; + +IMPL_GET_IMPL( TabPage ); + +TabPage::TabPage( Window *parent, const char *xml_file, const char *id, sal_uInt32 nId) + : Context( xml_file ) + , Window( new TabPageImpl( this, Context::GetPeerHandle( id, nId ), this ) ) +{ + if ( parent ) + SetParent( parent ); +} + +TabPage::TabPage( ::Window *parent, const char *xml_file, const char *id, sal_uInt32 nId) + : Context( xml_file ) + , Window( new TabPageImpl( this, Context::GetPeerHandle( id, nId ), this ) ) +{ + if ( parent ) + SetParent( parent ); +} + +TabPage::~TabPage() +{ + delete GetTabPage(); +} + +IMPL_GET_WINDOW( TabPage ); + +void TabPage::ActivatePage() +{ +} + +void TabPage::DeactivatePage() +{ +} + +class FixedLineImpl : public ControlImpl +{ +public: + FixedLineImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( FixedLine, Control, "hfixedline" ); +IMPL_GET_IMPL( FixedLine ); + +bool FixedLine::IsEnabled() const +{ + //FIXME + return true; +} + +class FixedTextImpl : public ControlImpl +{ +public: + uno::Reference< awt::XFixedText > mxFixedText; + FixedTextImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxFixedText( peer, uno::UNO_QUERY ) + { + } + + ~FixedTextImpl (); + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException); +}; + +FixedTextImpl::~FixedTextImpl () +{ +} + +void SAL_CALL FixedTextImpl::disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) +{ + ControlImpl::disposing (e); + mxFixedText.clear (); +} + +FixedText::~FixedText () +{ +} + +IMPL_CONSTRUCTORS( FixedText, Control, "fixedtext" ); +IMPL_GET_IMPL( FixedText ); + +void FixedText::SetText( OUString const& rStr ) +{ + if ( !getImpl().mxFixedText.is() ) + return; + getImpl().mxFixedText->setText( rStr ); +} + +class FixedInfoImpl : public FixedTextImpl +{ +public: + FixedInfoImpl( Context *context, const PeerHandle &peer, Window *window ) + : FixedTextImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( FixedInfo, FixedText, "fixedinfo" ); +IMPL_GET_IMPL( FixedInfo ); + +class ProgressBarImpl : public ControlImpl +{ +public: + uno::Reference< awt::XProgressBar > mxProgressBar; + ProgressBarImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxProgressBar( peer, uno::UNO_QUERY ) + { + } + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ControlImpl::disposing (e); + mxProgressBar.clear (); + } +}; + + +class FixedImageImpl: public ControlImpl +{ +public: + uno::Reference< graphic::XGraphic > mxGraphic; + FixedImageImpl( Context *context, const PeerHandle &peer, Window *window) +// const char *pName ) + : ControlImpl( context, peer, window ) + //, mxGraphic( layoutimpl::loadGraphic( pName ) ) + , mxGraphic( peer, uno::UNO_QUERY ) + { + if ( !mxGraphic.is() ) + { + DBG_ERROR( "ERROR: failed to load image: `%s'" /*, pName*/ ); + } +#if 0 + else + getImpl().mxGraphic->...(); +#endif + } +}; + +IMPL_CONSTRUCTORS( FixedImage, Control, "fixedimage" ); +IMPL_GET_IMPL( FixedImage ) + +void FixedImage::setImage( ::Image const& i ) +{ + (void) i; + if ( !getImpl().mxGraphic.is() ) + return; + //FIXME: hack moved to proplist + //getImpl().mxGraphic = +} + +#if 0 + +FixedImage::FixedImage( const char *pName ) + : pImpl( new FixedImageImpl( pName ) ) +{ +} + +FixedImage::~FixedImage() +{ + delete pImpl; +} + +#endif + + +IMPL_CONSTRUCTORS( ProgressBar, Control, "ProgressBar" ); +IMPL_GET_IMPL( ProgressBar ); + +void ProgressBar::SetForegroundColor( util::Color color ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setForegroundColor( color ); +} + +void ProgressBar::SetBackgroundColor( util::Color color ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setBackgroundColor( color ); +} + +void ProgressBar::SetValue( sal_Int32 i ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setValue( i ); +} + +void ProgressBar::SetRange( sal_Int32 min, sal_Int32 max ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setRange( min, max ); +} + +sal_Int32 ProgressBar::GetValue() +{ + if ( !getImpl().mxProgressBar.is() ) + return 0; + return getImpl().mxProgressBar->getValue(); +} + +class PluginImpl: public ControlImpl +{ +public: + ::Control *mpPlugin; + + PluginImpl( Context *context, const PeerHandle &peer, Window *window, :: Control *plugin ) + : ControlImpl( context, peer, window ) + , mpPlugin( plugin ) + { + uno::Reference <awt::XWindow> ref( mxWindow, uno::UNO_QUERY ); + layoutimpl::VCLXPlugin *vcl + = static_cast<layoutimpl::VCLXPlugin*>( VCLXWindow::GetImplementation( ref ) ); + ::Window *parent = vcl->mpWindow->GetParent(); + vcl->SetWindow( plugin ); + vcl->SetPlugin( mpPlugin ); + plugin->SetParent( parent ); + plugin->SetStyle( vcl->mStyle ); + plugin->SetCreatedWithToolkit( true ); + plugin->SetComponentInterface( vcl ); + plugin->Show(); + } +}; + +Plugin::Plugin( Context *context, char const *id, ::Control *plugin ) + : Control( new PluginImpl( context, context->GetPeerHandle( id, 0 ), this, plugin ) ) + , mpPlugin( plugin ) +{ +} + +IMPL_GET_IMPL( Plugin ); + +class LocalizedStringImpl : public WindowImpl +{ +public: + layoutimpl::LocalizedString *mpString; + OUString maString; + LocalizedStringImpl( Context *context, const PeerHandle &peer, Window *window ) + : WindowImpl( context, peer, window ) + , mpString( static_cast<layoutimpl::LocalizedString*>( VCLXWindow::GetImplementation( uno::Reference <awt::XWindow> ( mxWindow, uno::UNO_QUERY ) ) ) ) + , maString () + { + } + OUString getText() + { + if (mpString) + maString = mpString->getText (); + return maString; + } + void setText( OUString const& s ) + { + if (mpString) + mpString->setText( s ); + } +}; + +IMPL_GET_IMPL( LocalizedString ); + +LocalizedString::LocalizedString( Context *context, char const* id ) + : Window( new LocalizedStringImpl( context, context->GetPeerHandle( id, 0 ), this ) ) +{ +} + +String LocalizedString::getString () +{ + return getImpl ().getText (); +} + +OUString LocalizedString::getOUString () +{ + return getImpl ().getText (); +} + +LocalizedString::operator OUString () +{ + return getOUString (); +} + +LocalizedString::operator OUString const& () +{ + getOUString (); + return getImpl ().maString; +} + +LocalizedString::operator String() +{ + getOUString (); + return getImpl ().maString; +} + +String LocalizedString::GetToken (USHORT i, sal_Char c) +{ + return getString ().GetToken (i, c); +} + +OUString LocalizedString::operator= (OUString const& s) +{ + getImpl().setText( s ); + return getImpl().getText(); +} + +OUString LocalizedString::operator+= (OUString const& b) +{ + OUString a = getImpl ().getText (); + a += b; + getImpl ().setText (a); + return getImpl ().getText (); +} + +OUString LocalizedString::operator+= (sal_Unicode const b) +{ + String a = getImpl ().getText (); + a += b; + getImpl ().setText (a); + return getImpl ().getText (); +} + +class InPlugImpl : public WindowImpl +{ +public: + InPlugImpl (Context *context, const PeerHandle &peer, Window *window) + : WindowImpl (context, peer, window) + { + } +}; + +IMPL_GET_IMPL (InPlug); + +static char const *FIXME_set_parent (::Window *parent, char const *xml_file) +{ + layout::TabPage::global_parent = parent; + return xml_file; +} + +InPlug::InPlug (Window *parent, char const* xml_file, char const* id, sal_uInt32 nId) + : Context (FIXME_set_parent (parent ? parent->GetWindow () : 0, xml_file)) + , layout::Window (new InPlugImpl (this, Context::GetPeerHandle (id, nId), this)) +{ + if (parent) + SetParent (parent); + if (::Window *w = dynamic_cast< ::Window* > (this)) + w->SetComponentInterface (GetVCLXWindow ()); +} + +InPlug::InPlug (::Window *parent, char const* xml_file, char const* id, sal_uInt32 nId) + : Context (FIXME_set_parent (parent, xml_file)) + , layout::Window (new InPlugImpl (this, Context::GetPeerHandle (id, nId), this)) +{ + if (parent) + layout::Window::SetParent (parent); + if (::Window *w = dynamic_cast< ::Window* > (this)) + w->SetComponentInterface (GetVCLXWindow ()); +} + +void InPlug::ParentSet (Window *window) +{ + window->SetParent (dynamic_cast< ::Window* > (this)); + + /// FIXME: for standalone run of layout::SfxTabDialog + SetParent (window->GetParent ()); +} + +} // namespace layout diff --git a/toolkit/source/layout/vcl/wrapper.hxx b/toolkit/source/layout/vcl/wrapper.hxx new file mode 100644 index 000000000000..a9d5a6490c31 --- /dev/null +++ b/toolkit/source/layout/vcl/wrapper.hxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile$ + * + * $Revision$ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_VCL_WRAPPER_HXX +#define LAYOUT_VCL_WRAPPER_HXX + +#include <layout/layout.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/awt/XDialog2.hpp> +#include <com/sun/star/awt/XFocusListener.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <cppuhelper/implbase1.hxx> + +#include <cstring> + +namespace layout +{ + +namespace css = com::sun::star; + +class WindowImpl +{ +public: + Window *mpWindow; + Context *mpCtx; + css::uno::Reference< css::awt::XWindow > mxWindow; + css::uno::Reference< css::awt::XVclWindowPeer > mxVclPeer; + ::Window *mvclWindow; + bool bFirstTimeVisible; + + WindowImpl (Context *context, PeerHandle const &peer, Window *window); + virtual ~WindowImpl (); + + void wrapperGone(); + css::uno::Any getProperty (char const *name); + void setProperty (char const *name, css::uno::Any any); + void redraw (bool resize=false); + + // XFocusListener + virtual void SAL_CALL disposing (css::lang::EventObject const&) throw (css::uno::RuntimeException); +}; + +class ControlImpl : public WindowImpl + , public ::cppu::WeakImplHelper1 <css::awt::XFocusListener> +{ +public: + Link mGetFocusHdl; + Link mLoseFocusHdl; + + ControlImpl( Context *context, PeerHandle const& peer, Window *window ); + ~ControlImpl (); + + virtual void SetGetFocusHdl (Link const& link); + Link& GetGetFocusHdl (); + virtual void SetLoseFocusHdl (Link const& link); + Link& GetLoseFocusHdl (); + virtual void UpdateListening (Link const& link); + + // XFocusListener + virtual void SAL_CALL disposing (css::lang::EventObject const&) throw (css::uno::RuntimeException); + void SAL_CALL focusGained (css::awt::FocusEvent const& e) throw (css::uno::RuntimeException); + void SAL_CALL focusLost (css::awt::FocusEvent const& e) throw (css::uno::RuntimeException); +}; + +inline WindowImpl &Window::getImpl() const{ return *(static_cast< WindowImpl * >( mpImpl )); } + +// Helpers for defining boiler-plate constructors ... +// Could in-line in top-level but not with safe static_casts. +#define IMPL_GET_IMPL(t) \ + inline t##Impl &t::getImpl() const \ + { \ + return *(static_cast<t##Impl *>(mpImpl)); \ + } +#define IMPL_CONSTRUCTORS_BODY(t,par,unoName,body) \ + t::t( Context *context, const char *pId, sal_uInt32 nId ) \ + : par( new t##Impl( context, context->GetPeerHandle( pId, nId ), this ) ) \ + { \ + Window *parent = dynamic_cast<Window*> (context);\ + body;\ + if (parent)\ + SetParent (parent);\ + } \ + t::t( Window *parent, WinBits bits) \ + : par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, bits, unoName ), this ) ) \ + { \ + body;\ + if ( parent )\ + SetParent (parent);\ + } \ + t::t( Window *parent, ResId const& res) \ + : par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, 0, unoName ), this ) ) \ + { \ + body;\ + setRes (res);\ + if (parent)\ + SetParent (parent);\ + } +#define IMPL_CONSTRUCTORS(t,par,unoName) IMPL_CONSTRUCTORS_BODY(t, par, unoName, ) +#define IMPL_CONSTRUCTORS_2(t,win_par,other_par,unoName) \ + t::t( Context *context, const char *pId, sal_uInt32 nId ) \ + : win_par( new t##Impl( context, context->GetPeerHandle( pId, nId ), this ) ) \ + , other_par( new other_par##Impl( Window::GetPeer() ) ) \ + { \ + } \ + t::t( Window *parent, WinBits bits) \ + : win_par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, bits, unoName ), this ) ) \ + , other_par( new other_par##Impl( Window::GetPeer() ) ) \ + { \ + } + +#define IMPL_IMPL(t, parent) \ + class t##Impl : public parent##Impl \ + { \ + public: \ + t##Impl( Context *context, PeerHandle const& peer, Window *window ) \ + : parent##Impl( context, peer, window ) \ + { \ + } \ + }; + + +} // namespace layout + +#endif /* LAYOUT_VCL_WRAPPER_HXX */ |