Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

Using Existing Dialogs with TQMotifDialog

[ Previous: Using Custom TQDialogs ] [ Home ] [ Next: Using TQt Main Window Classes ]

As mentioned earlier, the Print dialog cannot be replaced until we have converted the View widget. The Print dialog will be removed once we have finished our migration, since we will use TQPrinter instead. Based on this information, we decide that it is not worth replacing the Print dialog with a custom TQDialog replacement. Instead, we will keep the Motif based dialog and use TQMotifDialog to integrate the dialog with the application.

Modality Requirements

Modality with TQDialog is different from Motif. The TQDialog::exec() function does not return until the dialog is finished. In Motif, modality is simply a property of the shell, and the application programmer must write TQDialog::exec() style functionality if they want that behavior.

Since we will be using TQMotifDialog (which is a TQDialog subclass), we will need to have an accept and a reject callback for each dialog we integrate with TQMotifDialog. The predefined Motif dialogs have these already: the XmNokCallback and XmNcancelCallback callbacks. However, the Print dialog only has an accept callback (the XmdNprintCallback), but it does not have a reject callback. We need to add this.

This is easily done. We add an XtCallbackList for the XmNcancelCallback callback in Xmd/PrintP.h:


We add the XmNcancelCallback callback to the list of resources for the XmdPrint widget class in Xmd/Print.c:


We need to activate this callback whenever we unmanage the widget and do not activate the print callback, which is in the do_help_cb() function:


... and in the unmanage_cb() function:


Integrating the Print Dialog

Now that the Print dialog has the appropriate accept and reject callbacks, we can use TQMotifDialog. First we need to include the TQMotifDialog header in todo.cpp.


We add a ShowPrintDialog() function which will create and execute the print dialog.


We change the Print menu item callback to call the new ShowPrintDialog() function. We pass the top-level TQMotifWidget, which we will use as the parent for the dialog.


The ShowPrintDialog() function creates the Print dialog and executes it. We use the XmdNprintCallback callback to accept the dialog and the XmNcancelCallback callback to reject the dialog. We can do this easily by using the TQMotifDialog::acceptCallback() and TQMotifDialog::rejectCallback() functions, respectively. We also ensure that the print callback continues to call the Print() function as before.


After we build the project, the application runs and operates as expected. There is no visual or behavioral difference, even though the Print dialog is using TQMotifDialog.

[ Previous: Using Custom TQDialogs ] [ Home ] [ Next: Using TQt Main Window Classes ]


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8