Difference between revisions of "Going further with Dialog and Component"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Counter with Numeric Field)
m
Line 33: Line 33:
 
</source>
 
</source>
 
The change are not important enough to be discussed deeply.
 
The change are not important enough to be discussed deeply.
 
=This Document Home Page=
 
 
[[Image:HomePageCpp.png]] [[Using_Cpp_with_the_OOo_SDK|Return to Document Home page]]
 
 
=See also=
 
*[[FR/Documentation/Composants_et_boite_de_dialogue|French version of this chapter]]
 
*[[Constructing_Components|Constructing Components]]
 
*The corresponding paragraph [[Documentation/DevGuide/WritingUNO/Accessing_Dialogs|in Developer's Guide]]
 
*[[Framework/Article/Generic_UNO_Interfaces_for_complex_toolbar_controls|Generic UNO Interfaces for complex toolbar controls]]
 
*[[Uno/Cpp/Tutorials/Introduction_to_Cpp_Uno|C++ and UNO tutorial]]
 
*[[Development/Cpp/Helper/ServiceDecl|Service Declaration]]
 
*[[Development/Cpp/Helper/OPropertyContainerHelper|Registering properties]]
 
*[[Tutorial_UNO_Library|UNO tutorial]]
 
*[[Tutorial_UNO_IDL|UNO IDL]]
 
*[[Extensions_Packager|Extensions Packager]] (BasicAddonBuilder from [mailto:paolomantovani@openoffice.org Paolo Mantovani])
 
*[[BASIC/UNO_Object_Browser|BASIC UNO Object Browser]] : You can see the corresponding code as a complex component.
 
*[[API/Samples/Java/Office/MinimalComponent|Minimal Java Component]]
 
*[[Documentation/BASIC_Guide|OOoBasic Guide]]
 
*Managing [[Documentation/BASIC_Guide/Dialogs|Dialogs]] in OOoBasic.
 
*[[Documentation/BASIC_Guide/Interface_Overview|Contextual Objects in OOoBasic]]
 
 
[[Category:Development]]
 
[[Category:Cpp]]
 
[[Category:Uno]]
 
[[Category:Tutorial]]
 
[[Category:Extensions]]
 
[[Category:Add-In]]
 
[[Category:Add-On]]
 
  
 
=Using Radio buttons=
 
=Using Radio buttons=
Line 114: Line 85:
 
}
 
}
 
</source>
 
</source>
 +
 +
=This Document Home Page=
 +
 +
[[Image:HomePageCpp.png]] [[Using_Cpp_with_the_OOo_SDK|Return to Document Home page]]
 +
 +
=See also=
 +
*[[FR/Documentation/Composants_et_boite_de_dialogue|French version of this chapter]]
 +
*[[Constructing_Components|Constructing Components]]
 +
*The corresponding paragraph [[Documentation/DevGuide/WritingUNO/Accessing_Dialogs|in Developer's Guide]]
 +
*[[Framework/Article/Generic_UNO_Interfaces_for_complex_toolbar_controls|Generic UNO Interfaces for complex toolbar controls]]
 +
*[[Uno/Cpp/Tutorials/Introduction_to_Cpp_Uno|C++ and UNO tutorial]]
 +
*[[Development/Cpp/Helper/ServiceDecl|Service Declaration]]
 +
*[[Development/Cpp/Helper/OPropertyContainerHelper|Registering properties]]
 +
*[[Tutorial_UNO_Library|UNO tutorial]]
 +
*[[Tutorial_UNO_IDL|UNO IDL]]
 +
*[[Extensions_Packager|Extensions Packager]] (BasicAddonBuilder from [mailto:paolomantovani@openoffice.org Paolo Mantovani])
 +
*[[BASIC/UNO_Object_Browser|BASIC UNO Object Browser]] : You can see the corresponding code as a complex component.
 +
*[[API/Samples/Java/Office/MinimalComponent|Minimal Java Component]]
 +
*[[Documentation/BASIC_Guide|OOoBasic Guide]]
 +
*Managing [[Documentation/BASIC_Guide/Dialogs|Dialogs]] in OOoBasic.
 +
*[[Documentation/BASIC_Guide/Interface_Overview|Contextual Objects in OOoBasic]]
 +
 +
[[Category:Development]]
 +
[[Category:Cpp]]
 +
[[Category:Uno]]
 +
[[Category:Tutorial]]
 +
[[Category:Extensions]]
 +
[[Category:Add-In]]
 +
[[Category:Add-On]]

Revision as of 13:59, 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 aspec is unchanged we don't provide a snapshot.

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.

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

HomePageCpp.png Return to Document Home page

See also

Personal tools