Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Modal Dialog Example
Ref. No. QNX.000009532
Category(ies) Development
Issue We need to create a modal dialog.  Do you have any examples?
Solution Note that this procedure is fully described and defined here:
Photon microGUI->Programmers Guide->Interprocess Communication and Lengthy Operations->Lengthy Operations->Modal Dialogs

For more eager developers who need an example, here is the basic outline:

- Create a blocking function that will block input to the parent window, and all other windows.
e.g.
void BlockWindows( int block )
{
  PtWidget_t *widget;
  PtArg_t argt;
  PtSetArg( &argt, Pt_ARG_FLAGS, block ? Pt_BLOCKED : 0, Pt_BLOCKED );
  widget = NULL;

  while( NULL != ( widget = PtNextTopLevelWidget( widget ) ) )
    if ( PtWidgetIsClass( widget, PtWindow ) )
      PtSetResources( widget, 1, &argt );
}      // **** See note at bottom regarding PtNextTopLevelWidget ***

- Calling this function will be as easy as:
BlockWindows( 1 );             
// block the parent window or all windows.

- Using PtModalStart() and PtModalEnd(), invoke your module:
e.g.
count = PtModalStart();
ApCreateModule( ABM_your_module, NULL, NULL );
while( !var_set_when_module_is_destroyed ){
  PtProcessEvent();
}
  PtModalEnd( count );

- Unblock everything previously blocked by calling your function:
e.g.
BlockWindows( 0 );             
// unblock what we blocked.

***NOTE***

If you don't have the latest Photon 1.13 patch then you may not have the PtNextTopLevelWidget() function, so here it is just in case

PtWidget_t *PtNextTopLevelWidget( PtWidget_t *widget )
{
PtWidgetList_t *wlp;

if( !widget )
{
        if( _Pt_->top_level )
        return _Pt_->top_level->widget;
    return NULL;
}
widget = PtFindDisjoint( widget );

for( wlp = _Pt_->top_level; wlp; wlp = wlp->next )
        if( wlp->widget == widget && wlp->next )
                return wlp->next->widget;
return NULL;
}