Difference between revisions of "Going further with Dialog and Component"
SergeMoutou (Talk | contribs) m (→A simple solution) |
SergeMoutou (Talk | contribs) m (→A simple solution) |
||
Line 43: | Line 43: | ||
For this problem the <idl>com.sun.star.awt.XRadioButton</idl> interface is your friend. We present now the corresponding code, and again with only the <code>callHandlerMethod</code>. Have a look at [[Component_and_Dialog#Firing_the_Component_Methods_with_XDialogEventHandler_Interface|the previous chapter]] if you want to remember you how it works. We intend to provide two solutions for this example. We begin with a solution which use only the four methods of the counter. | For this problem the <idl>com.sun.star.awt.XRadioButton</idl> interface is your friend. We present now the corresponding code, and again with only the <code>callHandlerMethod</code>. Have a look at [[Component_and_Dialog#Firing_the_Component_Methods_with_XDialogEventHandler_Interface|the previous chapter]] if you want to remember you how it works. We intend to provide two solutions for this example. We begin with a solution which use only the four methods of the counter. | ||
==A simple solution== | ==A simple solution== | ||
− | This solution keeps the four previous methods managed by <code>callHandlerMethod()</code> named "foo1", "foo2", .. "foo4". | + | This solution keeps the four previous methods managed by <code>callHandlerMethod()</code> named "foo1", "foo2", .. "foo4" of the <idl>com.sun.star.awt.XDialogEventHandler</idl> interface. |
<source lang="cpp"> | <source lang="cpp"> | ||
sal_Bool SAL_CALL MyCounterImpl::callHandlerMethod(const Reference< XDialog >& xDialog,const Any& EventObject,const OUString & MethodName ) throw(WrappedTargetException, RuntimeException ){ | sal_Bool SAL_CALL MyCounterImpl::callHandlerMethod(const Reference< XDialog >& xDialog,const Any& EventObject,const OUString & MethodName ) throw(WrappedTargetException, RuntimeException ){ |
Revision as of 09:28, 27 June 2009
In the previous chapter we use and program only two kinds of control in our dialog. We intend in this chapter to further and use a lot of control and then see how things work in this area. You cannot read this chapter befor reading the previous one.
We begin again with our counter.
Contents
Counter with Numeric Field
When we design the dialog working with our counter, we use two text controls for our numeric data. Because text controls are often used our preceding example is important, but it's time now to improve our design and use a numeric field control. Because the dialog aspect is unchanged we don't provide a snapshot of the dialog.
Have a look at com.sun.star.awt.XNumericField interface and see what can be done with this interface : only getvalue
and setValue
will be used in this section, but you can play with other methods.
We provide only the callHandlerMethod
function method (see the previous chapter and also the corresponding com.sun.star.awt.XDialogEventHandler interface). Here is the corresponding code.
sal_Bool SAL_CALL MyCounterImpl::callHandlerMethod(const Reference< XDialog >& xDialog,const Any& EventObject,const OUString & MethodName ) throw(WrappedTargetException, RuntimeException ){ if (MethodName.equalsAscii("foo1")){//increment increment(); return sal_True; } if (MethodName.equalsAscii("foo2")){//decrement decrement(); return sal_True; } if (MethodName.equalsAscii("foo3")){ //setCount Reference< XControlContainer > xControlContainer(xDialog,UNO_QUERY); Reference< XControl > xControl=xControlContainer->getControl(OUString::createFromAscii("NumericField1")); Reference< XNumericField > xNumericField(xControl,UNO_QUERY); setCount((sal_Int32)xNumericField->getValue()); return sal_True; } if (MethodName.equalsAscii("foo4")){ //getCount Reference< XControlContainer > xControlContainer(xDialog,UNO_QUERY); Reference< XControl > xControl=xControlContainer->getControl(OUString::createFromAscii("NumericField2")); Reference< XNumericField > xNumericField(xControl,UNO_QUERY); xNumericField->setValue(getCount()); return sal_True; } return sal_False; }
The change are not important enough to be discussed deeply. We turn now to the radio button problem.
Using Radio buttons
Radio buttons are usually used to select one item in a small list. We want use radio button to select the increment or decrement. Here is a snapshot of our dialog :
For this problem the com.sun.star.awt.XRadioButton interface is your friend. We present now the corresponding code, and again with only the callHandlerMethod
. Have a look at the previous chapter if you want to remember you how it works. We intend to provide two solutions for this example. We begin with a solution which use only the four methods of the counter.
A simple solution
This solution keeps the four previous methods managed by callHandlerMethod()
named "foo1", "foo2", .. "foo4" of the com.sun.star.awt.XDialogEventHandler interface.
sal_Bool SAL_CALL MyCounterImpl::callHandlerMethod(const Reference< XDialog >& xDialog,const Any& EventObject,const OUString & MethodName ) throw(WrappedTargetException, RuntimeException ){ if (MethodName.equalsAscii("foo1")){//increment Reference< XControlContainer > xControlContainer(xDialog,UNO_QUERY); Reference< XControl > xControl=xControlContainer->getControl(OUString::createFromAscii("OptionButton1")); Reference< XRadioButton > xRadioButton(xControl,UNO_QUERY); if (xRadioButton->getState()) m_nDelta=1; xControl=xControlContainer->getControl(OUString::createFromAscii("OptionButton2")); Reference< XRadioButton > xRadioButton2(xControl,UNO_QUERY); if (xRadioButton2->getState()) m_nDelta=5; xControl=xControlContainer->getControl(OUString::createFromAscii("OptionButton3")); Reference< XRadioButton > xRadioButton3(xControl,UNO_QUERY); if (xRadioButton3->getState()) m_nDelta=10; increment(); return sal_True; } if (MethodName.equalsAscii("foo2")){//decrement Reference< XControlContainer > xControlContainer(xDialog,UNO_QUERY); Reference< XControl > xControl=xControlContainer->getControl(OUString::createFromAscii("OptionButton1")); Reference< XRadioButton > xRadioButton(xControl,UNO_QUERY); if (xRadioButton->getState()) m_nDelta=1; xControl=xControlContainer->getControl(OUString::createFromAscii("OptionButton2")); Reference< XRadioButton > xRadioButton2(xControl,UNO_QUERY); if (xRadioButton2->getState()) m_nDelta=5; xControl=xControlContainer->getControl(OUString::createFromAscii("OptionButton3")); Reference< XRadioButton > xRadioButton3(xControl,UNO_QUERY); if (xRadioButton3->getState()) m_nDelta=10; decrement(); return sal_True; } if (MethodName.equalsAscii("foo3")){ //setCount Reference< XControlContainer > xControlContainer(xDialog,UNO_QUERY); Reference< XControl > xControl=xControlContainer->getControl(OUString::createFromAscii("NumericField1")); Reference< XNumericField > xNumericField(xControl,UNO_QUERY); setCount((sal_Int32)xNumericField->getValue()); return sal_True; } if (MethodName.equalsAscii("foo4")){ //getCount Reference< XControlContainer > xControlContainer(xDialog,UNO_QUERY); Reference< XControl > xControl=xControlContainer->getControl(OUString::createFromAscii("NumericField2")); Reference< XNumericField > xNumericField(xControl,UNO_QUERY); xNumericField->setValue(getCount()); return sal_True; } return sal_False; }
As you can see only increment()
and decrement()
methods are looking for the radiobutton which is set. No event is fired when setting or cleared a radio button in this example. But it is possible to call a method when status is changed : note in this case, you have to provide a method for every buttons. Let's us now examine this second solution.
This Document Home Page
See also
- Constructing Components
- Component and Dialog
- The New Tree Contol
- The corresponding paragraph in Developer's Guide
- Generic UNO Interfaces for complex toolbar controls
- C++ and UNO tutorial
- Service Declaration
- Registering properties
- UNO tutorial
- UNO IDL
- Extensions Packager (BasicAddonBuilder from Paolo Mantovani)
- BASIC UNO Object Browser : You can see the corresponding code as a complex component.
- Minimal Java Component
- OOoBasic Guide
- Managing Dialogs in OOoBasic.
- Contextual Objects in OOoBasic