| View previous topic :: View next topic |
| Author |
Message |
adipan General User

Joined: 19 Apr 2005 Posts: 48 Location: Noida, India
|
Posted: Thu Jun 02, 2005 6:22 am Post subject: Initialize a listbox to show |
|
|
Please find below a code snippet:
Reference< XListBox> xPSetFixedText(xFixedTextControl,UNO_QUERY);
xPSetFixedText->addItems (seqStrlistItems , 0);
//Try to set focus to first row of added data
xPSetFixedText->selectItemPos (sal_Int16(0), sal_Bool(true) );
xPSetFixedText->makeVisible (sal_Int16(0));
//Check if I am successful
sal_Int16 selItem = xPSetFixedText->getSelectedItemPos ();
printf ("Selected Item Pos :%d", selItem);
The printf stills show selItem as -1, and the initial listbox comes with a blank row. When I select the listbox, then it shows all the items I have entered after the blank row, and blank row disappears once I choose one the valid items.
It looks like a common problem, I am not using right approach. Also, this is a DropDown list. Any comments? _________________ Aditya Pandey |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Thu Jun 02, 2005 8:02 am Post subject: |
|
|
My answer is based on supositions because I have not the entire code.
First of all, I have no experience with listbox in C++. The subject is interesting and i hope to explore it in the futur.
I think you make confusions between, the code, the dialog and what you see. I have myself encounter similar problem and only understand it for two days ago.
| Code: |
//Check if I am successful
sal_Int16 selItem = xPSetFixedText->getSelectedItemPos ();
printf ("Selected Item Pos :%d", selItem);
|
What do you expect from this code ? This code can gives you a result only if it is execuded in parallel with :
| Code: |
xDialog->execute();
|
In other words if this code is not in an event listener I don't see why it should give you a result because the dialog is not running ! _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|
| Back to top |
|
 |
adipan General User

Joined: 19 Apr 2005 Posts: 48 Location: Noida, India
|
Posted: Thu Jun 02, 2005 10:54 pm Post subject: |
|
|
Thanks for your reply.
I didnt want to make my post long, so didnt include the call for
xDialog->execute()
I am doing execute on dialog (but before that, I need to set all the properties of the widgets that come on the dialog, among them a listbox).
What happens when dialog first appears is that, listbox (with a dropdown)..has visible a blank row...which should not be there...only the items I inserted should be there....
When I click and select an item from the listbox, then it shows me only the items that I entered and blank row disappears once something has been selected. _________________ Aditya Pandey |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Sat Jun 04, 2005 3:49 am Post subject: |
|
|
I have not programmed Dialog box for a long time and then spend a lot of time to obtain a XListBox service without success.
In :
| Code: |
Reference< XListBox> xPSetFixedText(xFixedTextControl,UNO_QUERY);
xPSetFixedText->addItems (seqStrlistItems , 0);
|
then name of variable xFixedTextControl giives me the wrong way. I suppose you keep this name from a previous example.
Then I have tried make this code working :
| Code: |
Reference< XInterface > xlistBoxModel = xMultiServiceFactory->createInstance(
OUString::createFromAscii("com.sun.star.awt.UnoControlListBoxModel"));
if (xlistBoxModel.is()) printf("OK ListBoxModel\n"); else printf("Error ... ListBoxModel\n");
Reference< XPropertySet > xPSetLabel(xlistBoxModel,UNO_QUERY);
if (xPSetLabel.is()) printf("OK XPropertySet2\n"); else printf("Error ... XPropertySet2\n");
value=20; val <<= value;
xPSetLabel->setPropertyValue(OUString::createFromAscii("PositionX"),val);
value=10; val <<= value;
xPSetLabel->setPropertyValue(OUString::createFromAscii("PositionY"),val);
value=110; val <<= value;
xPSetLabel->setPropertyValue(OUString::createFromAscii("Width"),val);
value=50; val <<= value;
xPSetLabel->setPropertyValue(OUString::createFromAscii("Height"),val);
val <<=OUString::createFromAscii("Label1");
xPSetLabel->setPropertyValue(OUString::createFromAscii("Name"),val);
xPSetLabel->setPropertyValue(OUString::createFromAscii("TabIndex"),makeAny((short)2));
Reference<XListBox> xFixedText(xlistBoxModel,UNO_QUERY);
if (xFixedText.is()) printf("OK List Box\n"); else printf("Error ... List Box\n");
|
as you see to obtain the XListBox service. But it doesn't work ! Always "Error ... List Box\n" is printed out.
Again the question :
How do you obtain the interface XListBox ? _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|
| Back to top |
|
 |
adipan General User

Joined: 19 Apr 2005 Posts: 48 Location: Noida, India
|
Posted: Mon Jun 06, 2005 7:11 am Post subject: |
|
|
Hi SergeM
Thanks for looking up on this.
I would post a snippet related to how to create a listbox (or a text box) in some time. I am just posting this, so your effort on getting a listbox is not spent. _________________ Aditya Pandey |
|
| Back to top |
|
 |
adipan General User

Joined: 19 Apr 2005 Posts: 48 Location: Noida, India
|
Posted: Mon Jun 06, 2005 8:24 am Post subject: |
|
|
Please find below code for adding a listbox.
Basically, a dialogModel's own factory is required to create a listbox. Using XPropertySet
property for the listbox could be set, and finally a dialogModel's name container is required to insert the listbox.
void construct_dialog (Reference< XMultiServiceFactory > xServiceManager, const Reference< XFrame >& xFrame)
{
//Check input parameter
if( xServiceManager != NULL && xServiceManager.is() ){
printf( "Connected sucessfully to the office\n" );
}
else return;
//Setup dialog model
Reference< XInterface > xDialogModel =
xServiceManager->createInstance(
OUString::createFromAscii("com.sun.star.awt.UnoControlDialogModel"));
if (xdialogModel.is()) printf("OK XDialogModel\n");
else {
printf("Error ... XDialogModel\n");
return ;
}
// create the child control models of the dialog and set their properties
Reference< XNameContainer > xNameCont(xDialogModel,UNO_QUERY);
if (xNameCont.is()) printf("OK XNameContainer\n");
else
{ printf("Error ... XNameContainer\n");
return ;
}
//Note: xDialogMSFactory used for dialog instead of xServiceManager [Application Main window]
Reference< XMultiServiceFactory > xDialogMSFactory( xDialogModel,UNO_QUERY);
Any val;
Reference< XInterface > xControlModel = xDialogMSFactory->createInstance(OUString::createFromAscii("com.sun.star.awt.UnoControlListBoxModel"));
if (xControlModel.is()) printf("OK Listbox\n", );
else
{ printf("Error ... %s\n");
return ;
}
val <<= xControlModel;
xNameCont->insertByName(OUString::createFromAscii("listBox1") ,val);
} _________________ Aditya Pandey |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
adipan General User

Joined: 19 Apr 2005 Posts: 48 Location: Noida, India
|
Posted: Mon Jun 06, 2005 9:21 am Post subject: |
|
|
Oops...
Please see this in continuation of my earlier code....Code lines are increasing too much. Sorry about that.
// create the dialog control and set the model
Reference< XInterface >dialog = xServiceManager->createInstance(
OUString::createFromAscii("com.sun.star.awt.UnoControlDialog"));
if (dialog.is()) printf("OK dialog\n"); else printf("Error ... dialog\n");
Reference< XControl > xControl(dialog,UNO_QUERY);
if (xControl.is()) printf("OK XControl\n"); else printf("Error ... XControl\n");
Reference< XControlModel > xControlModel(xDialogModel,UNO_QUERY);
if (xControlModel.is()) printf("OK xControlModel\n"); else printf("Error ... xControlModel\n");
xControl->setModel(xControlModel);
Reference< XControlContainer > xControlCont(dialog,UNO_QUERY);
xMyControlCont = xControlCont;
if (xControlCont.is())
{
printf("OK xControlContainer\n");
Reference< XInterface > objectListBox=xControlCont->getControl(OUString::createFromAscii("listBox1"));
if (objectListBox.is()) printf("OK ListBox XInterface\n");
else
{ printf("Error ... ListBox XInterface\n");
return ;
}
Reference< XControl > xListControl(objectListBox,UNO_QUERY);
if (xListControl.is())
printf ("OK...FixedTextcontrol");
else
return;
Reference< XListBox> xPSetListBox(xListControl,UNO_QUERY);
if (xPSetListBox.is())
printf ("SUCCESS in List Box\n");
else return;
xPSetListBox->removeItems(0, xPSetFixedText->getItemCount());
xPSetListBox->addItems (seqStrlistItems , 0);
xPSetListBox->selectItemPos (sal_Int16(0), sal_Bool(true) );
xPSetListBox->makeVisible (sal_Int16(0));
sal_Int16 selItem = xPSetListBox->getSelectedItemPos ();
printf ("Selected Item Pos :%d", selItem);
}
else printf("Error ... xControlContainer\n"); _________________ Aditya Pandey |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Tue Jun 07, 2005 9:49 am Post subject: |
|
|
As I explained in the first answer, this code cannot work (in my opinion), because when you try to obtain a result of something selected in the listbox this listbox is not on the screen ! This listbox comes in the screen only when you call Dialog.execute() and when you launch this dialog.execute() you cannot execute an otherC++ instruction. Then I see only two ways to achieve your goal :
- using thread
- using callback : or event listener.
I have encounter exacly the same problem but with a "com.sun.star.awt.UnoControlEditModel" : I wanted to use this control to write something in it and I prepare this control as you do it and then want to put the text in it but never obtain the corresponding interface ! After few days stopping around this problem I come back with the idea that I do the things in the wrong way !
I decided to attach the writing of the text to an event listener and it works because now when I ask the XTextComponent interface the dialog box is running.
Conclusion : ********** Important ************
when this code is executed
| Code: |
Reference< XListBox> xPSetListBox(xListControl,UNO_QUERY);
if (xPSetListBox.is())
printf ("SUCCESS in List Box\n");
else return; |
you have to see the dialogBox on the screen. If not xPSetListBox is NULL or something similar. _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
Danad OOo Advocate

Joined: 22 Feb 2004 Posts: 293 Location: Brasil
|
Posted: Tue Jun 07, 2005 7:12 pm Post subject: |
|
|
With OOo Basic selectItemPos doesn't work for run-time dialogs. But it works for IDE dialogs (before execute call).
| Code: |
Sub create_DialogWithListBox
' Based on Dev's Guide sample
'
dialogModel = createUnoService("com.sun.star.awt.UnoControlDialogModel")
dialogModel.setPropertyValue("PositionX", 100)
dialogModel.setPropertyValue("PositionY", 100)
dialogModel.setPropertyValue("Width", 150)
dialogModel.setPropertyValue("Height", 100)
dialogModel.setPropertyValue("Title", "Runtime Dialog Demo")
'
'// create the listbox model and set the properties
lbModel = dialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel" )
lbModel.setPropertyValue("PositionX", 50)
lbModel.setPropertyValue("PositionY", 30)
lbModel.setPropertyValue("Width", 50)
lbModel.setPropertyValue("Height", 14)
lbName = "my_LBName"
lbModel.setPropertyValue("Name", lbName)
lbModel.setPropertyValue("TabIndex", 0)
lbModel.setPropertyValue("Dropdown", True)
'
'// insert the control models into the dialog model
dialogModel.insertByName(lbName, lbModel)
'
'// create the dialog control and set the model
dialog = createUnoService("com.sun.star.awt.UnoControlDialog")
dialog.setModel(dialogModel)
'
' get ListBox control
xListBox = dialog.getControl(lbName)
aItens = Array ("Item 1","Item 2","Item 3","Item 4","Item 5")
xListBox.addItems(aItens(), 0)
xListBox.setDropDownLineCount(5)
' <<<=== WORKS WITH IDE DIALOG
xListBox.selectItemPos(0, True)
xListBox.makeVisible(0)
'print xListBox.getSelectedItemPos()
' ======================== >>>
'
'// execute the dialog
dialog.setVisible(True)
dialog.execute()
'
'// dispose the dialog
dialog.dispose()
End Sub
|
Perhaps I'm missing sth.
HTH
(OOo 1.1.3 / WinXP) |
|
| Back to top |
|
 |
adipan General User

Joined: 19 Apr 2005 Posts: 48 Location: Noida, India
|
Posted: Wed Jun 08, 2005 2:23 am Post subject: |
|
|
Danad:
I tried to see if there is any difference between your VB code and mine in C++...and I cant find any . What is the difference between IDE dialogs and run-time dialogs?
SergeM:
I can find XListBox interface...as I can easily addItems on the listbox in my code.
But when dialog box appears ..there is an empty row..and when I click and select one of the added items...the empty row in listbox at top disappears.
Thats why I did same as what Danad has done in this part:
' <<<=== WORKS WITH IDE DIALOG
xListBox.selectItemPos(0, True)
xListBox.makeVisible(0)
'print xListBox.getSelectedItemPos()
' ======================== >>>
getSelectedItemPos() comes to be -1 for me. And, I dont know if selectedItemPos and makeVisible work. But, xListBox smart pointer is not null for me. _________________ Aditya Pandey |
|
| Back to top |
|
 |
Danad OOo Advocate

Joined: 22 Feb 2004 Posts: 293 Location: Brasil
|
Posted: Wed Jun 08, 2005 12:30 pm Post subject: |
|
|
| Quote: |
What is the difference between IDE dialogs and run-time dialogs?
|
OOo has an IDE with a Code Editor (Basic) and a Dialog Editor.
For IDE dialogs, I mean dialogs created with IDE Dialog Editor (with this kind of dialogs selectItemPos works).
For run-time dialogs, I mean dialogs created by code.
Sorry my english. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
|