hi,
.
thanks, dialog is all showing now.. :)
.
now i need help with action listeners(something wrong in what i did),, what
i did is i inherited the class with the listeners  and implemented their
methods, then in the addListener i added keyword (this), (actual code in the
end of the mail for reference).. is this method right?????
.
and how can i get the control from the model?? i tried something,, what i
did is:
(selected statements to show the flow)
mxDialog = Reference< XDialog
>(xDialogProvider->createDialog(sXDLPath),UNO_QUERY_THROW);
Reference< XControl > xControl(mxDialog, UNO_QUERY_THROW);
mxModel = Reference< XNameAccess >(xControl->getModel(), UNO_QUERY_THROW);
mxControlContainer = Reference< XControlContainer
>(mxDialog,UNO_QUERY_THROW);
Reference< XPropertySet > aListBox(mxModel->getByName(C2U("ListBox1")),
UNO_QUERY_THROW);
mxListBox = Reference< XListBox
>(mxControlContainer->getControl(C2U("ListBox1")),UNO_QUERY_THROW);
.
will i get the XListBox using this method??? or any other way??
.
.
regards
kushal
source for reference:
----------------------------------------------------------------------------------------------------------------------------------------------
.hxx file(extra code not shown to reduce size)
-----------------------------------------------------------------------------------------------------------------------------------------------
typedef ::cppu::WeakComponentImplHelper6<
com::sun::star::ui::dialogs::XExecutableDialog,
com::sun::star::lang::XServiceInfo,
com::sun::star::lang::XInitialization,
com::sun::star::beans::XPropertyAccess,
com::sun::star::awt::XActionListener,
 com::sun::star::awt::XItemListener > HTMLExDialogBase;
.
class HTMLExExporterDialog : private cppu::BaseMutex
, public HTMLExDialogBase
{
// lot of other code
public:
// lot of other code
 virtual void SAL_CALL actionPerformed (const
com::sun::star::awt::ActionEvent&)
throw (com::sun::star::uno::RuntimeException);

virtual void SAL_CALL itemStateChanged( com::sun::star::awt::ItemEvent
const&)
throw (com::sun::star::uno::RuntimeException);

virtual void SAL_CALL disposing( com::sun::star::lang::EventObject const& e
)
throw (com::sun::star::uno::RuntimeException);
};

----------------------------------------------------------------------------------------------------------------------------------------------
.cxx file(extra code not shown to reduce size)
-----------------------------------------------------------------------------------------------------------------------------------------------

#define C2U(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
HTMLExExporterDialog::HTMLExExporterDialog(const Reference<
XComponentContext >& xContext)
: HTMLExDialogBase( m_aMutex )
, mxContext( xContext, UNO_QUERY_THROW )
, mxServiceFactory( xContext->getServiceManager(), UNO_QUERY_THROW )
, mxToolkit(mxServiceFactory->createInstanceWithContext(
C2U("com.sun.star.awt.Toolkit"), xContext), UNO_QUERY_THROW )
, mTask( xContext )
, maTemplate( xContext )
{
}
//lots of code removed here
sal_Int16 SAL_CALL HTMLExExporterDialog::execute() throw ( RuntimeException
)
{

Reference< XDialogProvider > xDialogProvider(
mxServiceFactory->createInstanceWithContext(
C2U("com.sun.star.awt.DialogProvider2"), mxContext), UNO_QUERY_THROW );

Reference<com::sun::star::deployment::XPackageInformationProvider>
xProvider( mxContext->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM(
"/singletons/com.sun.star.deployment.PackageInformationProvider"))),UNO_QUERY_THROW);
OUString sURL( xProvider->getPackageLocation(rtl::OUString::createFromAscii(
BOOST_PP_STRINGIZE(HTMLEX_IMPL_IDENTIFIER))));

OUString sXDLPath;
sXDLPath = mTask.normalizeFolderPath( sURL );
sXDLPath += C2U("files/htmlexDialog.xdl");

mxDialog = Reference< XDialog
>(xDialogProvider->createDialog(sXDLPath),UNO_QUERY_THROW);

maTemplate.getTemplates();

Reference< XControl > xControl(mxDialog, UNO_QUERY_THROW);
mxModel = Reference< XNameAccess >(xControl->getModel(), UNO_QUERY_THROW);

mxControlContainer = Reference< XControlContainer
>(mxDialog,UNO_QUERY_THROW);
initialize();

short nRet = mxDialog->execute();
return nRet;

}

//initialize the dialog(overrided function)
void HTMLExExporterDialog::initialize()
{
Reference< XPropertySet > aListBox(mxModel->getByName(C2U("ListBox1")),
UNO_QUERY_THROW);
Sequence< OUString > sTemplateList( maTemplate.mFoundTemplates );
Any aList(sTemplateList);
Sequence< sal_Int16 > sqItem(1);
sqItem[0]=(sal_Int16)0;
Any aItem(sqItem);
aListBox->setPropertyValue(C2U("StringItemList"),aList);
aListBox->setPropertyValue(C2U("SelectedItems"),aItem);

maTemplate.selectTemplate(0);
Reference< XPropertySet >
aPreviewBox(mxModel->getByName(C2U("ImageControl2")), UNO_QUERY_THROW);
Any aImage(maTemplate.PreviewImageURL);
aPreviewBox->setPropertyValue(C2U("ImageURL"),aImage);

Reference< XPropertySet >
aDescriptionBox(mxModel->getByName(C2U("TextField2")), UNO_QUERY_THROW);
Any aDesc(maTemplate.Description);
aDescriptionBox->setPropertyValue(C2U("Text"),aDesc);

mxListBox = Reference< XListBox
>(mxControlContainer->getControl(C2U("ListBox1")),UNO_QUERY_THROW);
mxListBox->addItemListener( this );
}

// action listener
void SAL_CALL HTMLExExporterDialog::actionPerformed (const
awt::ActionEvent&)
throw (uno::RuntimeException)
{
}
// item listener
void SAL_CALL HTMLExExporterDialog::itemStateChanged( awt::ItemEvent const&)
throw (uno::RuntimeException)
{
Reference< XPropertySet > aListBox(mxModel->getByName(C2U("ListBox1")),
UNO_QUERY_THROW);

Any aSelected( aListBox->getPropertyValue(C2U("SelectedItems")) );
sal_Int16 nSerial = *( (sal_Int16*)aSelected.getValue() );
maTemplate.selectTemplate((sal_Int32)nSerial);
Reference< XPropertySet >
aPreviewBox(mxModel->getByName(C2U("ImageControl2")), UNO_QUERY_THROW);
Any aImage(maTemplate.PreviewImageURL);
aPreviewBox->setPropertyValue(C2U("ImageURL"),aImage);

Reference< XPropertySet >
aDescriptionBox(mxModel->getByName(C2U("TextField2")), UNO_QUERY_THROW);
Any aDesc(maTemplate.Description);
aDescriptionBox->setPropertyValue(C2U("Text"),aDesc);

}
//disposing
void SAL_CALL HTMLExExporterDialog::disposing( lang::EventObject const&
/*e*/ )
throw (uno::RuntimeException)
{
};

regards
kushal


2010/11/13 Frank Schönheit <[email protected]>

> Hallo Kushal,
>
> > nope, i dont have any dialog model yet.
> > how can i get that from the XWindow(see code attached for reference)???
>
> Ah, I see ... your code indeed works directly with window peers. This
> will also yield results (obviously, as you already have a working dialog
> :) ), however, it has disadvantages: One is the mentioned
> desktop/theme-dependency: Try switching your desktop theme to another
> (larger or smaller) font, and see how your pixel coordinates won't work
> anymore. Another is that parts of the API you're using is pretty
> unofficial, for instance, the window names to use at the toolkit are not
> officially documented, to my best knowledge.
>
> Okay, first let me suggest how you *should* do that, IMO :)
>
> - create the dialog you want in the Basic dialog editor.
> - search for the resulting .xdl file
> - include this file in your extension
> - at runtime, do the following (pseudo-code, more Java than C++, sorry):
>  XDialogProvider dlgProv = ServiceFactory.createInstance(
>    "com.sun.star.awt.DialogProvider2" )
>  dlgProv.
>  XDialog dialog = dlgProvider.createDialog(
>    "vnd.sun.star.extension://your-extension-identifier/path" +
>      "/within/oxt/file/dialog.xdl";
>  dialog.execute();
>
> This has several advantages:
> - You can edit the dialog within Basic's dialog editor. While it is not
>  the most convenient tool on earth, it still is better than creating
>  the dialog programmatically.
> - Your dialog definition in the XDL file now has APPFONT coordinates,
>  i.e. will not suffer from the desktop/theme size mentioned above.
> - You have access to the dialog model (see below), which will easily
>  allow you to manipulate the dialog at runtime, using a reliable API.
>
> For accessing the model, just do
>  XControl dialogControl = (XControl)dialog;
>  XNameAccess dialogModel = (XNameAccess)dialogControl.getModel();
>
> Now dialogModel contains an object which supports the
> css.awt.UnoControlDialogModel service. This includes support for
> accessing its children, removing and adding children, and property
> support as described in the service.
> The children then are UnoControl*Model instances, including full support
> for all properties described in the respective services.
>
> So, to answer your original question (how to add an image control) in
> this context:
> - add an image control to your dialog in Basic's dialog editor
> - set its "Scale" property (in the property editor) to the desired value
> - at runtime, retrieve the image control model:
>  XPropertySet imageProps = (XPropertySet)dialogModel.getByName(
>    "imageControlName" );
> - set the ImageURL property:
>  imageProps.setPropertyValue( "ImageURL", "vnd.sun.star.extension://" +
>    "your-extension-identifier/path/within/oxt/file/image.jpg" );
> => you're done :)
>
> Your second question about the font attributes would then be answered with:
>  XPropertySet controlProperties = (XPropertySet)dialogModel.getByName(
>    "controlName" );
>  FontDescriptor font = (FontDescriptor)controlProperties.
>    getPropertyValue( "FontDescriptor" );
>  font.Weight = FontWeight.BOLD;
>  controlProperties.setPropertyValue( "FontDescriptor", font );
>
> So, as you see, this approach would make some things easier ...
>
>
> If you'd insist on using your old approach for whatever reasons, then
> you'd need to lookup the window names (as to be passed in the
> WindowDescriptor) in toolkit/source/awt/vclxtoolkit.cxx - as said,
> they're not officially documented, so you'd need to look into the
> implementation. For an image control, "fixedimage" would be the name to
> use.
>
> For setting properties, you could still look up all the properties in
> the respective UnoControl*Model services in css.awt. Then, use the
> XVclWindowPeer::setProperty method of your XWindow: just pass the
> property name as obtained from the UnoControl*Model service description,
> and the desired value. This should work for all properties, including
> FontDescriptor.
>
> Hope this helps
>
> Ciao
> Frank
>
> --
> ORACLE
> Frank Schönheit | Software Engineer | [email protected]
> Oracle Office Productivity: http://www.oracle.com/office
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to