hi,
.
nope, i dont have any dialog model yet.
how can i get that from the XWindow(see code attached for reference)???
.
or
.
do i have to initialize both with services like below:(in pseudo code)
(XInterface)mxDialogModel( mxMSF->createInstanceWithContext(
C2U("com.sun.star.awt.UnoControlDialogModel" ) , mxContext ),
UNO_QUERY_THROW ),
(XControlModel)mxControlModel( mxDialogModel, UNO_QUERY_THROW ),
(XDialog)mxDialog( mxMSF->createInstanceWithContext(
C2U("com.sun.star.awt.UnoControlDialog" ), mxContext ), UNO_QUERY_THROW ),
(XControl)mxControl( mxDialog, UNO_QUERY_THROW ),
mxControl->setModel( mxControlModel );
mxDialogWindow = Reference< XWindow >( mxDialog, UNO_QUERY_THROW );
how to assign model to window?
??
.
also in my previous implementation, i was using buttons implementing
services "okbutton" and "cancelbutton' to accept or cancel the dialog, which
buttons to add in this approach to perform similar functions??
.
my old dialog code for reference is(removed several parts to shorten size):
.hxx
file\-----------------------------------------------------------------------------------------------------------------------------------------------
#ifndef INCLUDED_HTMLEX_DIALOG_HXX
#define INCLUDED_HTMLEX_DIALOG_HXX
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertyAccess.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/uno/Any.h>
#include <com/sun/star/awt/XToolkit.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XDialog.hpp>
#include <com/sun/star/awt/WindowAttribute.hpp>
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
#include <cppuhelper/compbase4.hxx>
#include <cppuhelper/basemutex.hxx>
#include "logWriter.hxx"
typedef ::cppu::WeakComponentImplHelper4<
com::sun::star::ui::dialogs::XExecutableDialog,
com::sun::star::lang::XServiceInfo,
com::sun::star::lang::XInitialization,
com::sun::star::beans::XPropertyAccess > HTMLExDialogBase;
class HTMLExExporterDialog : private cppu::BaseMutex, public
HTMLExDialogBase
{
private:
com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
mxContext;
com::sun::star::uno::Reference< com::sun::star::lang::XMultiComponentFactory
> mxServiceFactory;
rtl::OUString msTitle;
com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
maSettings;
com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
maSettingsData;
com::sun::star::uno::Reference< com::sun::star::awt::XToolkit > mxToolkit;
com::sun::star::uno::Reference< com::sun::star::awt::XWindow >
mxDialogWindow;
com::sun::star::uno::Reference< com::sun::star::awt::XDialog > mxDialog;
//draw the dialog box
void getDialog();
void DrawDialog();
void putLabel(sal_Int32 nTop, sal_Int32 nLeft, rtl::OUString sText);
logWriter mLog;
public:
//logWriter mLog;
explicit HTMLExExporterDialog( const ::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext >& xContext );
//XExecutableDialog
virtual sal_Int16 SAL_CALL execute() throw (
::com::sun::star::uno::RuntimeException );
virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw (
::com::sun::star::uno::RuntimeException );
//XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName() throw (
::com::sun::star::uno::RuntimeException );
virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString&
ServiceName ) throw ( ::com::sun::star::uno::RuntimeException );
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
getSupportedServiceNames() throw ( ::com::sun::star::uno::RuntimeException
);
//XInitialization
virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence<
::com::sun::star::uno::Any > & aArguments ) throw (
::com::sun::star::uno::Exception );
//XPropertyAccess
virtual ::com::sun::star::uno::Sequence<
::com::sun::star::beans::PropertyValue > SAL_CALL getPropertyValues() throw
( ::com::sun::star::uno::RuntimeException );
virtual void SAL_CALL setPropertyValues( const
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > &
aProps )
throw ( ::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::beans::PropertyVetoException,
::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException );
};
#endif
.
.cxx file
\-----------------------------------------------------------------------------------------------------------------------------------------------------------------
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sdext.hxx"
#include "HTMLExExporterDialog.hxx"
#include <com/sun/star/awt/XButton.hpp>
#include <com/sun/star/awt/XFixedText.hpp>
#include <com/sun/star/awt/XWindowPeer.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#define C2U(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
using rtl::OUString;
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::ui;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::awt;
using namespace com::sun::star::container;
HTMLExExporterDialog::HTMLExExporterDialog(const Reference<
XComponentContext >& xContext)
: HTMLExDialogBase( m_aMutex )
, mxContext( xContext, UNO_QUERY_THROW )
, mxServiceFactory( xContext->getServiceManager(), UNO_QUERY_THROW )
, mxToolkit(xContext->getServiceManager()->createInstanceWithContext(
C2U("com.sun.star.awt.Toolkit"), xContext), UNO_QUERY_THROW )
, mLog(xContext)
{
}
//XInitialization
void SAL_CALL HTMLExExporterDialog::initialize( const Sequence< Any > &
aArguments ) throw ( Exception )
{
//nothing to put here!!
}
//XServiceInfo
OUString SAL_CALL HTMLExExporterDialog::getImplementationName() throw (
RuntimeException )
{
return OUString( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.comp.documents.HTMLExExporterDialog" ) );
}
sal_Bool SAL_CALL HTMLExExporterDialog::supportsService( const OUString&
ServiceName ) throw ( RuntimeException )
{
return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
"com.sun.star.ui.dialogs.FilterOptionsDialog" ) );
}
Sequence< OUString > SAL_CALL
HTMLExExporterDialog::getSupportedServiceNames() throw ( RuntimeException )
{
Sequence< OUString > aReturn(1);
OUString* pString = aReturn.getArray();
pString[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.ui.dialogs.FilterOptionsDialog" ) );
return aReturn;
}
//XPropertyAccess
void SAL_CALL HTMLExExporterDialog::setPropertyValues( const Sequence<
PropertyValue > & aProps ) throw ( UnknownPropertyException,
PropertyVetoException, IllegalArgumentException, WrappedTargetException,
RuntimeException )
{
maSettings = aProps;
sal_Int32 i, nCount;
for ( i = 0, nCount = maSettings.getLength(); i < nCount; i++ )
{
if ( maSettings[ i ].Name.equalsAscii( "FilterData" ) )
{
maSettings[ i ].Value >>= maSettingsData;
break;
}
}
}
Sequence< PropertyValue > SAL_CALL HTMLExExporterDialog::getPropertyValues()
throw ( RuntimeException )
{
sal_Int32 i, nCount;
for ( i = 0, nCount = maSettings.getLength(); i < nCount; i++ )
{
if ( maSettings[ i ].Name.equalsAscii( "FilterData" ) )
break;
}
if ( i == nCount )
maSettings.realloc( ++nCount );
// the "FilterData" Property is an Any that will contain our
PropertySequence of Values
maSettings[ i ].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
"FilterData" ) );
maSettings[ i ].Value <<= maSettingsData;
return maSettings;
}
//XExecutableDialog
void SAL_CALL HTMLExExporterDialog::setTitle( const OUString& aTitle ) throw
( RuntimeException )
{
msTitle = aTitle;
}
sal_Int16 SAL_CALL HTMLExExporterDialog::execute() throw ( RuntimeException
)
{
getDialog();
DrawDialog();
short nRet = mxDialog->execute();
return nRet;
}
//get the dialog box
void HTMLExExporterDialog::getDialog()
{
WindowDescriptor windowDescriptor;
windowDescriptor.Type = WindowClass_TOP;
windowDescriptor.WindowServiceName = C2U("modelessdialog");
windowDescriptor.ParentIndex = -1;
windowDescriptor.Parent = 0;
windowDescriptor.Bounds = Rectangle( 0, 0, 590, 476 );
windowDescriptor.WindowAttributes = WindowAttribute::BORDER
+ WindowAttribute::MOVEABLE
+ WindowAttribute::CLOSEABLE
+ VclWindowPeerAttribute::CLIPCHILDREN;
mxDialogWindow.set( mxToolkit->createWindow( windowDescriptor ),
UNO_QUERY_THROW );
mxDialogWindow->setVisible( sal_True );
Reference< XDialog > xDialog( mxDialogWindow, UNO_QUERY_THROW );
mxDialog.set(xDialog, UNO_QUERY_THROW);
mxDialog->setTitle(C2U("HTML Export Filter settings - OpenOffice.org"));
}
//draw the dialog box
void HTMLExExporterDialog::DrawDialog()
{
mLog.setLogFilePath(OUString(RTL_CONSTASCII_USTRINGPARAM("file:///media/o/dialogLog.txt")));
//put labels
//putLabel(10,10,C2U("hello"));
//export button OK button
WindowDescriptor windowDescriptor;
windowDescriptor.Type = WindowClass_SIMPLE;
windowDescriptor.WindowServiceName = C2U("okbutton");
windowDescriptor.Bounds = Rectangle( 421, 447, 95, 33 );
windowDescriptor.WindowAttributes = VclWindowPeerAttribute::CLIPCHILDREN;
windowDescriptor.ParentIndex = -1;
windowDescriptor.Parent = Reference< XWindowPeer >( mxDialogWindow,
UNO_QUERY_THROW );
Reference< XWindow > xOKButton( mxToolkit->createWindow( windowDescriptor ),
UNO_QUERY_THROW );
Reference< XButton > xButtonOK( xOKButton, UNO_QUERY_THROW );
xButtonOK->setLabel(C2U("Export"));
xOKButton->setVisible( sal_True );
//cancel button
windowDescriptor.Type = WindowClass_SIMPLE;
windowDescriptor.WindowServiceName = C2U("cancelbutton");
windowDescriptor.Bounds = Rectangle( 502, 447, 75, 23 );
windowDescriptor.WindowAttributes = VclWindowPeerAttribute::CLIPCHILDREN;
windowDescriptor.ParentIndex = -1;
windowDescriptor.Parent = Reference< XWindowPeer >( mxDialogWindow,
UNO_QUERY_THROW );
Reference< XWindow > xCancelButton( mxToolkit->createWindow(
windowDescriptor ), UNO_QUERY_THROW );
xCancelButton->setVisible( sal_True );
}
.
regards
kushal
2010/11/4 Frank Schönheit <[email protected]>
> Hello Kushal,
>
> > its my first time developing the dialog boxes, hence need some help.
> > i have a dialog box to be implemented, for reference it can be seen here:
> >
> http://wiki.services.openoffice.org/wiki/OpenOffice.org_Internship/Projects/2010/Customizable_html_export_for_Impress#Option_8
> > .
> > the code i am using to put a "fixedtext"(label) on the dialog is:
> > WindowDescriptor windowDescriptor;
>
> ehm ...
>
> What you do here is to create a mere window peer, without an associated
> control, or even control model.
> While this is possible, some things you'll want to achieve will become
> more difficult by this (admittedly, some will become easier ...)
>
> The correct way to do this would be
> - obtain the dialog model (I suppose you have one, yes?)
> - let it create a control model
> - insert this control model into the dialog model
>
> In pseudo-code, this would look like this
> XMultiServiceFactory controlModelFactory =
> (XMultiServiceFactory)dialogModel;
> XPropertySet controlModel = (XPropertySet)
> controlModelFactory.createInstance(
> "com.sun.star.awt.UnoControlFixedTexModel" )
> controlModel.setPropertyValue( "PositionX", ... );
> controlModel.setPropertyValue( ... );
> XNameContainer modelContainer =
> (XNameContainer)dialogModel;
> modelContainer.insertByName( "MyControl", controlModel );
>
> After the insertion, your dialog window (mxDialogWindow) will
> automatically have a new child window, which corresponds to the control
> model you just inserted.
>
> > windowDescriptor.Type = WindowClass_SIMPLE;
> > windowDescriptor.WindowServiceName = OUString(
> > RTL_CONSTASCII_USTRINGPARAM("fixedtext") );
> > windowDescriptor.Bounds = Rectangle( 6, 46, 59, 13 );
>
> Note that you're using fixed pixel coordinates here. This will work for
> your particular system/desktop/theme, but is likely to break on other
> desktops. The problem is that as soon as, for instance, the font size
> changes, your pixel coordinates will be wrong.
>
> Model properties (PositionX, PositionY, Width, Height), on the other
> hand, use "AppFont" coordinates: "1" means "1/8 of the average
> height/width of a character of the application's UI font". So, when you
> work with models instead of windows, your dialog will automatically
> adjust itself to different desktops.
>
> > the question is,,, how can i set the font properties??? like bold,font
> size
> > etc, i.e FontDescriptor
>
> At the model (controlModel in the above example code), you'd find a
> property "FontDescriptor", being a css.awt.FontDescriptor structure,
> which has all the members you need.
>
> > another question is how can i add images to mxDialogWindow, such that i
> can
> > set its source URL at runtime along with other properties like stretch to
> > fit???
>
> Use the same code as above, but let the dialog's factory create an
> css.awt.UnoControlImageControlModel, and set its ImageURL and ScaleMode
> properties
> (
> http://api.openoffice.org/docs/common/ref/com/sun/star/awt/UnoControlImageControlModel.html
> )
>
> Ciao
> Frank
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>