QNX RTOS v4 Knowledge Base
QNX RTOS v4 Knowledge Base
Title |
Handling multiple instances of a window |
Ref. No. |
QNX.000009773 |
Category(ies) |
Development |
Issue |
We have created a Window module in PhAB with several widgets. The user creates multiple windows of this type by clicking on a button. If more than one window is open at the time, what is the way to access the widgets inside these windows?
|
Solution |
If you have more than one instance of a window module displayed at a time, then you will have a problem accessing the widgets in the window. The problem stems from the fact that ABW_INSTANCE_NAME for any widget in a window module points to the last created instance of that widget. If you have more than one instance of the window, than you have more than one instance of the widget within the window created.
Let's say that you have the following window module:
_______________________________________ | | | My Application | |______________________________________| | | | search_win-> | | _________________x09 | | | | | | | Text Widget |<-name_txt | | |________________| | | | | _________________ | | | | | | | Search |<-search_bin | | |________________| | | | |______________________________________|
A sample search window If you have two instances of it on the screen at the same time and the user clicks on the Search button, how can you get the value in the Name text widget? Since two instances of the window exist, two instances of the text widget exist. ABW_name_txt points to the last instance of the text widgets that was created.
The solution lies in the fact that ABN_name_txt can be used to refer to both instances of name_txt, provided you have the widget pointer to the window that contains the desired text widget. This is done using the ApGetWidgetPtr() function:
PtWidget_t *window_wgt, *text_wgt; text_wgt = ApGetWidgetPtr(window_wgt, ABN_name_txt);
Where do you get window_wgt? In the above case, you'd have a code callback on the Search button. The first parameter passed to that code callback is the widget pointer to the Search button. You can use ApGetInstance() To get a pointer to the window that contains the Search button.
So the callback would become:
int search_callback (PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo) { x09char *name; x09PtArg_t arg; x09PtWidget_t *window_wgt, *text_wgt; //Get the window that the Search button is in x09window_wgt = ApGetInstance(widget); //Given the window, find the text widget x09text_wgt = ApGetWidgetPtr(window_wgt, ABN_name_txt); // now get the text x09PtSetArg(&arg, Pt_ARG_TEXT_STRING, &name, 0); x09PtGetResources(text_wgt, 1, &arg); //The 'name' variable now points to the correct name text //Process the text as appropriate ... x09return(Pt_CONTINUE); }
x09
|
|