OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Initialize a listbox to show
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
adipan
General User
General User


Joined: 19 Apr 2005
Posts: 48
Location: Noida, India

PostPosted: Thu Jun 02, 2005 6:22 am    Post subject: Initialize a listbox to show Reply with quote

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
View user's profile Send private message Yahoo Messenger
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Jun 02, 2005 8:02 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
adipan
General User
General User


Joined: 19 Apr 2005
Posts: 48
Location: Noida, India

PostPosted: Thu Jun 02, 2005 10:54 pm    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Jun 03, 2005 8:16 am    Post subject: Reply with quote

OK I have to try C++ listbox programming. Perhaps to morrow.
_________________
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
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Sat Jun 04, 2005 3:49 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
adipan
General User
General User


Joined: 19 Apr 2005
Posts: 48
Location: Noida, India

PostPosted: Mon Jun 06, 2005 7:11 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
adipan
General User
General User


Joined: 19 Apr 2005
Posts: 48
Location: Noida, India

PostPosted: Mon Jun 06, 2005 8:24 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon Jun 06, 2005 9:02 am    Post subject: Reply with quote

OK but don't see how do you obtain XListBox interface.
_________________
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
View user's profile Send private message Visit poster's website
adipan
General User
General User


Joined: 19 Apr 2005
Posts: 48
Location: Noida, India

PostPosted: Mon Jun 06, 2005 9:21 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Tue Jun 07, 2005 9:49 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Tue Jun 07, 2005 9:58 am    Post subject: Reply with quote

If you don't understand exacly what I mean you can ask in this thread. But be patient, I will be not at home during three days.
I will publish what I have done with dialog and Reflection in the code snippet but I have to clean a little the code and add somethings.
Hope that helps.
_________________
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
View user's profile Send private message Visit poster's website
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Tue Jun 07, 2005 7:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
adipan
General User
General User


Joined: 19 Apr 2005
Posts: 48
Location: Noida, India

PostPosted: Wed Jun 08, 2005 2:23 am    Post subject: Reply with quote

Danad:
I tried to see if there is any difference between your VB code and mine in C++...and I cant find any Sad. 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
View user's profile Send private message Yahoo Messenger
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Wed Jun 08, 2005 12:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Jun 10, 2005 11:13 am    Post subject: Reply with quote

Frankly speaking I have not tried your code. I will see to morrow.
_________________
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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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