| View previous topic :: View next topic |
| Author |
Message |
eduzs OOo Advocate


Joined: 07 Feb 2005 Posts: 356 Location: RJ, BRAZIL
|
Posted: Tue Jun 14, 2005 2:35 pm Post subject: how to "disable" a numericfield |
|
|
How do I disable (user cant enter in the control) a numericfield control in a basic project??
Thanx |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
eduzs OOo Advocate


Joined: 07 Feb 2005 Posts: 356 Location: RJ, BRAZIL
|
Posted: Wed Jun 15, 2005 2:30 pm Post subject: |
|
|
In a dialog.
something like that.
| Code: | | oDlgCalcPSS.getcontrol("F1").setproperty("Enabled") = true |
How to correctly set this?
Thanks |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Thu Jun 16, 2005 6:38 am Post subject: |
|
|
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a week.
So, lets go fishing through the documentation. (I sure hope this excursion is helpful to anyone out there.)
oDlgCalcPSS is an UnoControlDialog. That is, it is the dialog control, not the dialog model.
Looking at the documentaiton for UnoControlDialog, you can see that UnoControlDialog includes the service UnoControlContainer. (In fact, any container of other controls will have the UnoControlContainer service.)
Since a dialog is a container of controls, and has the UnoControlContainer service, it has all features of UnoControlContainer.
Looking at UnoControlContainer, you can see that it implements the interface XControlContainer. This interface offers the method getControl(). , a method that you already know about. But what does getControl() do?
As you can see, the documentation of getControl() says
| getControl() documenation wrote: | Description
returns the control with the specified name.
|
Note, that getControl() returns the control, NOT the model of the control. This means that instead of returning a model (such as UnoControlNumericFieldModel in this case), it returns the actual control (such as UnoControlNumericField in this case).
An important concept is that every control has both a control and a model of the control. So if you have a numeric field, it has both a control and a model. Calling getControl() gets you the control, but not the model.
Note that earlier in this thread, I mentioend that the model had the property Enabled. If you had a control model, you could simply....
oModel.Enabled = false
But since you used getControl() you do not have the model.
There are two possible solutions.
1. Use getControl() to get the control, and then from the control, get the model. Then set the Enabled property of the model.
2. Use getControl() to get the control, and then use some method directly on the control to disable the control.
I'll explore both possible solutions.
First to navigate from the control to its model.
Note that every control, such as UnoControlNumericField ultimately includes the service UnoControl. That is, all controls descend from UnoControl. In this case, UnoControlNumericField, includes UnoControlEdit, which includes UnoControl.
The UnoControl service offers several interfaces, including the XControl interface. The XControl interface has the convenient handy-dandy method getModel(), which returns the control's model.
So, from any control (that inherits UnoControl), you can simply call getModel() to go from the control to the model.
oF1Control = oDlgCalcPSS.getControl( "F1" ) ' get the control
oF1Model = oF1Control.getModel() ' get the model from the control
oF1Model.Enabled = false ' set a property on the model
Second, how to directly disable the control without going through the model.
As I mentioned, the UnoControlNumericField includes (indirectly via. way of UnoControlEdit) the service UnoControl. We also saw that UnoControl has the interface XControl. But as you can plainly see, UnoControl has several interfaces. Besides XControl, another interface offered by UnoControl is the XWindow interface.
As you can see, the XWindow interface has the handy method setEnable().
Therefore, every control is an UnoControl, and every UnoControl has an XWindow, which has setEnable().
Therefore, UnoControlNumericField has setEnable().
oF1Control = oDlgCalcPSS.getControl( "F1" ) ' get the control
oF1Control.setEnable( false ) ' use method available at XWindow interface
Or even on a single line, which brings us to the end of our fishing...
oDlgCalcPSS.getControl( "F1" ).setEnable( false )
See Also....
Dialog boxes
============
Modeless dialog
http://www.oooforum.org/forum/viewtopic.phtml?p=75478#75478
http://www.oooforum.org/forum/viewtopic.php?t=4926
http://www.oooforum.org/forum/viewtopic.php?t=4601
http://www.oooforum.org/forum/viewtopic.php?p=16293#16293
Dialogs on the fly...
http://www.oooforum.org/forum/viewtopic.php?t=3130
Enable / Disable buttons
http://www.oooforum.org/forum/viewtopic.php?t=4007
Change image of graphic
http://www.oooforum.org/forum/viewtopic.php?t=3479
Center dialog box on screen
http://www.oooforum.org/forum/viewtopic.php?p=52909#52909
Explanation of dialog control vs. model, how to disable control
http://www.oooforum.org/forum/viewtopic.phtml?p=82140#82140 _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Niamorh General User

Joined: 13 Jun 2005 Posts: 15
|
Posted: Fri Jun 17, 2005 1:24 am Post subject: |
|
|
| Code: | | oDlgCalcPSS.getControl( "F1" ).getModel().Enabled = false |
This must be correct too then ? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri Jun 17, 2005 7:23 am Post subject: |
|
|
| Niamorh wrote: | | Code: | | oDlgCalcPSS.getControl( "F1" ).getModel().Enabled = false |
This must be correct too then ? |
It should be, in theory. But I have not actually tried that one in practice.
Wow, you must have understood my message.
Teach a man to fish and you feed him for a week. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|