[Tfug] wxWidgets (GTK+) ShowModal dialog question.

Joe Blais joe.blais at pti-instruments.com
Tue Jan 30 14:21:20 MST 2007


Hello -

Being new to Linux, and it's X11 gui stuff, I wonder if anyone sees issues
with this scenario.

I'm doing a project where I don't want a bunch of cpu hits when newing and
deleting GUI stuff, that could cause delays in a more-faster running app
that the gui communicates with (we don't need no stinkin real time).

The GUI uses wxWidgets - It seems like a good thing - and it apparently
wraps GTK+.

In the main form, I new all the main dialogs that I expect to use.  I have a
simple container with an array that contains enum types for each dialog.
Initially the values in the array contain the enum for the main screen (no
fancy drop down menu's because touch screens only want thumb sized buttons)
and the current index is set to 0.

In the initial login event, a successful login will call a Display method...

void MainForm::OnLogin( event )
{
  int iRet = mpLogin->ShowModal() ;
  if ( iRet == wxID_OK )
    ShowCurrentDialog() ;
}

void MainForm::ShowCurrentDialog( void )
{
  int iRet = wxID_OK ;
  switch ( gDlgStack.GetNext() )
  {
    case eMain :
      iRet = mpMain->ShowModal() ; // only way to cancel the app
      break ;
    case eSetup :
      mpSetup->ShowModal() ;
      break ;
    .. more cases .....
  }
  if ( iRet != wxID_CANCEL )
    ShowCurrentDialog() ;
}
...
each dialog then does something like this when it wants the next display ...
void MainDlg::OnSetup( void )
{
  gDlgStack.ShowNext( eSetup ) ;
  EndModal( wxID_OK ) ;
}
as opposed to....
{
  DlgSetup dlg(this) ;
  dlg.ShowModal() ;
}


Then each dialog calls the container with it's request for the next dialog
(increments the current counter and sets the requested enum), or says it's
done (decrements the current counter).  The re-entrant method seems to just
be happy showing whatever is requested (I just have main and login working).
The main screen is the only one that allows the user to exit with a cancel
request.

Besides weird things like getting stuck on a screen, does anyone know if the
re-entrant stuff which is being called in an event callback in the main
form, is a bad idea in terms of eating up the entire memory of the machine,
or other ugliness??

I want all the screens to be modal, and I felt funny about a ShowModal,
calling another ShowModal, which calls another ShowModal...  This way I
really only have the main from and one dialog (other than small pop-ups)
being displayed.  I can't get into a situation where the ShowModals end up
calling themselves in a loop when the user pops around from screen to
screen.

Winders likes to new all the displays itself, so I think it must be doing
something like this as well.

Anyway -- any comments?  -- my style is a bit verbose, but it makes stepping
through much easier than having things in registers and junk that I can't
watch and set breaks on...without having to learn how....

Thanks

Joe





More information about the tfug mailing list