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

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m (Counter with Numeric Field)
Line 1: Line 1:
 
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.
 
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=
 
=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.
+
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 <idl>com.sun.star.awt.XNumericField</idl> interface and see what can be done with this interface : only <code>getvalue</code> and <code>setValue</code> will be used in this section, but you can play with other methods.
 
Have a look at <idl>com.sun.star.awt.XNumericField</idl> interface and see what can be done with this interface : only <code>getvalue</code> and <code>setValue</code> will be used in this section, but you can play with other methods.
Line 32: Line 32:
 
}
 
}
 
</source>
 
</source>
The change are not important enough to be discussed deeply.
+
The change are not important enough to be discussed deeply. We turn now to the radio button problem.
  
 
=Using Radio buttons=
 
=Using Radio buttons=

Revision as of 14:01, 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

HomePageCpp.png Return to Document Home page

See also

Personal tools