Difference between revisions of "Going further with Dialog and Component"
SergeMoutou (Talk | contribs) m (→Counter with Numeric Field) |
SergeMoutou (Talk | contribs) m (→Using Radio buttons) |
||
Line 36: | Line 36: | ||
=Using Radio buttons= | =Using Radio buttons= | ||
We want use radio button to select the increment or decrement. Here is a snapshot of our dialog : | We want use radio button to select the increment or decrement. Here is a snapshot of our dialog : | ||
+ | |||
+ | [[Image:CounterDialog2.png|center|thumb|600px|Our Second Counter Dialog]] | ||
For this problem the <idl>com.sun.star.awt.XRadioButton</idl> interface is your friend. | For this problem the <idl>com.sun.star.awt.XRadioButton</idl> interface is your friend. |
Revision as of 14:06, 26 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. We begin again with our counter.
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. 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
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.
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; }
This Document Home Page
See also
- French version of this chapter
- Constructing Components
- 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