/*!
    This function is a reimplementation of QWidget::showEvent(). The
    reimplemented function handles the given \a event by ensuring that the
    dialog widget is managed and hidden.
*/
void QtMotifDialog::showEvent(QShowEvent *event)
{
    if (!event->spontaneous()) {
        // tell motif about modality
        Arg args[1];
        XtSetArg( args[0], XmNdialogStyle,
                  (testAttribute(Qt::WA_ShowModal)
                   ? XmDIALOG_FULL_APPLICATION_MODAL :
                   XmDIALOG_MODELESS));
        XtSetValues( d->shell, args, 1 );
        XtSetMappedWhenManaged( d->shell, False );
        if ( d->dialog ) {
            XtManageChild( d->dialog );

            XSync(x11Info().display(), FALSE);
            XSync(QtMotif::display(), FALSE);
        } else if ( !parentWidget() ) {
            adjustSize();
            QApplication::sendPostedEvents(this, QEvent::Resize);

            Widget p = XtParent( d->shell ), s = p;
            while ( s != NULL && !XtIsShell( s ) ) // find the shell
                s = XtParent( s );

            if ( p && s ) {
                int offx = ( (  XtWidth( p ) -  width() ) / 2 );
                int offy = ( ( XtHeight( p ) - height() ) / 2 );
                move( XtX ( s ) + offx, XtY( s ) + offy );
            }
        }
        XtSetMappedWhenManaged( d->shell, True );
    }
    QDialog::showEvent(event);

}
Exemple #2
0
void KXtWidget::init(const char* name, WidgetClass widget_class,
                    Widget parent, QWidget* qparent,
                    ArgList args, Cardinal num_args,
                    bool managed)
{
    need_reroot=FALSE;
    xtparent = 0;
    if (parent ) {
        Q_ASSERT(!qparent);
        xtw = XtCreateWidget(name, widget_class, parent, args, num_args);
        if ( widget_class == qWidgetClass )
            ((QWidgetRec*)xtw)->qwidget.qxtwidget = this;
        xtparent = parent;
        if (managed)
            XtManageChild(xtw);
    } else {
        Q_ASSERT(!managed);

        String n, c;
        XtGetApplicationNameAndClass(qt_xdisplay(), &n, &c);
        xtw = XtAppCreateShell(n, c, widget_class, qt_xdisplay(),
                               args, num_args);
        if ( widget_class == qWidgetClass )
            ((QWidgetRec*)xtw)->qwidget.qxtwidget = this;
    }

    if ( qparent ) {
        XtResizeWidget( xtw, 100, 100, 0 );
        XtSetMappedWhenManaged(xtw, False);
        XtRealizeWidget(xtw);
        XSync(qt_xdisplay(), False);    // I want all windows to be created now
        XReparentWindow(qt_xdisplay(), XtWindow(xtw), qparent->winId(), x(), y());
        XtSetMappedWhenManaged(xtw, True);
        need_reroot=TRUE;
    }

    Arg reqargs[20];
    Cardinal nargs=0;
    XtSetArg(reqargs[nargs], XtNx, x());        nargs++;
    XtSetArg(reqargs[nargs], XtNy, y());        nargs++;
    XtSetArg(reqargs[nargs], XtNwidth, width());        nargs++;
    XtSetArg(reqargs[nargs], XtNheight, height());      nargs++;
    //XtSetArg(reqargs[nargs], "mappedWhenManaged", False);     nargs++;
    XtSetValues(xtw, reqargs, nargs);

    //#### destroy();   MLK

    if (!parent || XtIsRealized(parent))
        XtRealizeWidget(xtw);
}
Exemple #3
0
bool wxPopupWindow::Create( wxWindow *parent, int flags )
{
    if( !wxPopupWindowBase::Create( parent, flags ) )
        return false;

    SetParent( parent );
    if( parent )
        parent->AddChild( this );

    Widget popup = XtVaCreatePopupShell( "shell",
                                         overrideShellWidgetClass,
                                         (Widget)wxTheApp->GetTopLevelWidget(),
                                         NULL );

    m_mainWidget = (WXWidget)popup;

    wxAddWindowToTable( (Widget) m_mainWidget, this );

    DoSetSizeIntr( -1, -1, 100, 100, 0, true );

    XtSetMappedWhenManaged( popup, False );
    XtRealizeWidget( popup );
    XtManageChild ( popup );
/*
    XtTranslations ptr;
    XtOverrideTranslations (popup,
        ptr = XtParseTranslationTable ("<Configure>: resize()"));
    XtFree ((char *) ptr);
*/
    return true;
}
Exemple #4
0
void
awt_util_hide(Widget w)
{
    if (w == NULL) {
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
        JNU_ThrowNullPointerException(env,"NullPointerException");
        return;
    }
    XtSetMappedWhenManaged(w, False);
}
Exemple #5
0
WXWidget wxCreateTopLevelRealizedWidget( WXDisplay* WXUNUSED(display) )
{
    Widget rTlw = XtVaCreateWidget( "dummy_widget", topLevelShellWidgetClass,
                                    (Widget)wxTheApp->GetTopLevelWidget(),
                                    NULL );
    XtSetMappedWhenManaged( rTlw, False );
    XtRealizeWidget( rTlw );

    return (WXWidget)rTlw;
}
/*!
    \internal
    Sets the dialog widget for the QtMotifDialog to \a w.
*/
void QtMotifDialog::insertChild( Widget w )
{
    if ( d->dialog != NULL && d->dialog != w ) {
	qWarning( "QtMotifDialog::insertChild: cannot insert widget since one child\n"
		  "                           has been inserted already." );
	return;
    }

    d->dialog = w;

    XtSetMappedWhenManaged( d->shell, True );
}
/*!
    \internal
    Wraps the Motif dialog by setting the X window for the
    QtMotifDialog to the X window id of the dialog shell.
*/
void QtMotifDialog::realize( Widget w )
{
    // use the winid of the dialog shell, reparent any children we have
    if ( XtWindow( w ) != winId() ) {
	XSync(QtMotif::display(), FALSE);

	XtSetMappedWhenManaged( d->shell, False );

	// save the window title
	QString wtitle = windowTitle();
	if (wtitle.isEmpty()) {
 	    char *t = 0;
 	    XtVaGetValues(w, XtNtitle, &t, NULL);
 	    wtitle = QString::fromLocal8Bit(t);
	}
        setWindowTitle(QString()); // make sure setWindowTitle() works below

        QString icontext = windowIconText();
        if (icontext.isEmpty()) {
 	    char *iconName = 0;
 	    XtVaGetValues(w, XtNiconName, &iconName, NULL);
 	    icontext = QString::fromLocal8Bit(iconName);
        }
        setWindowIconText(QString()); // make sure setWindowTitle() works below

	Window newid = XtWindow(w);
	QObjectList list = children();
	for (int i = 0; i < list.size(); ++i) {
	    QWidget *widget = qobject_cast<QWidget*>(list.at(i));
	    if (!widget || widget->isWindow()) continue;

	    XReparentWindow(widget->x11Info().display(), widget->winId(), newid,
			    widget->x(), widget->y());
	}
	QApplication::syncX();

	create( newid, true, true );

	// restore the window title and icon text
 	if (!wtitle.isEmpty())
 	    setWindowTitle(wtitle);
        if (!icontext.isEmpty())
            setWindowIconText(icontext);

	// if this dialog was created without a QWidget parent, then the transient
	// for will be set to the root window, which is not acceptable.
	// instead, set it to the window id of the shell's parent
	if ( ! parent() && XtParent( d->shell ) )
	    XSetTransientForHint(x11Info().display(), newid, XtWindow(XtParent(d->shell)));
    }
    QtMotif::registerWidget( this );
}
Exemple #8
0
Widget
XmPrintSetup(
             Widget           video_widget,
             Screen           *print_screen,
             String            print_shell_name,
             ArgList           args,
             Cardinal          num_args)
{
    String video_name, video_class ;
    Widget pappshell ;
    Widget print_shell;
    Display  *print_display = DisplayOfScreen(print_screen);

    /* get to the video app root shell */
    while(!XtIsApplicationShell(video_widget))
	video_widget = XtParent(video_widget);

    if (!video_widget) return NULL;

    XtGetApplicationNameAndClass(XtDisplay(video_widget),
                                 &video_name, &video_class);

    /* we want to be able to specify things like:
       dtpad.print*textFontList: somefont
       dtpad.print*background:white
       so we create a first shell unrealized and them a popup
       named "print".
       */
    pappshell = XtVaAppCreateShell(video_name, video_class,
                                   applicationShellWidgetClass, 
                                   print_display, 
                                   XmNscreen, print_screen, 
                                   NULL);

    /* then create the XmPrintShell */
    print_shell = XtCreatePopupShell(print_shell_name, 
				     xmPrintShellWidgetClass, 
				     pappshell, args, num_args);

    /* Add callback to destroy application Shell parent. */
    XtAddCallback(print_shell, XmNdestroyCallback, 
                  _XmDestroyParentCallback, (XtPointer) NULL) ;

    /* we're mapping/unmapping at start/end page time */
    XtSetMappedWhenManaged(print_shell, False);

    /* realize the shell now, so that XmPrintPopupPDM works dy default */
    XtRealizeWidget(print_shell);

    return print_shell ;
}
Exemple #9
0
BOOL CWnd::xd_show_window(int nCmdShow)
{
    // Changes the visibility state of a child widget
    // by mapping or unmapping it or a child gadget by
    // managing or unmanaging it.

    Boolean wasvisible = TRUE;
    Boolean gadget     = XmIsGadget(_xd_rootwidget);

    if (gadget)
	wasvisible = XtIsManaged(_xd_rootwidget);
    else
	XtVaGetValues(_xd_rootwidget, XmNmappedWhenManaged, &wasvisible, NULL);

    switch(nCmdShow)
    {
	case SW_HIDE:       if (gadget)
				XtUnmanageChild(_xd_rootwidget);
			    else
				XtSetMappedWhenManaged(_xd_rootwidget, FALSE);
			    break;

	case SW_RESTORE:    if (gadget)
				XtManageChild(_xd_rootwidget);
			    else
				XtSetMappedWhenManaged(_xd_rootwidget, TRUE);
			    break;

        case SW_SHOW:            XtManageChild(_xd_rootwidget);
                            break;

	default:            cerr << "CWnd::ShowWindow: Only SW_HIDE and SW_RESTORE supported for child windows" << endl;
    }

    return wasvisible;
}
Exemple #10
0
void
awt_util_show(Widget w)
{
/*
    extern Boolean  scrollBugWorkAround;
*/
    if (w == NULL) {
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
        JNU_ThrowNullPointerException(env,"NullPointerException");
        return;
    }
    XtSetMappedWhenManaged(w, True);
/*
  XXX: causes problems on 2.5
    if (!scrollBugWorkAround) {
        awt_setWidgetGravity(w, StaticGravity);
    }
*/
}
Exemple #11
0
// Relacement for Qt function - add Xt stuff for top-level widgets
Window qt_XCreateWindow( const QWidget* qw, Display *display, Window parent,
			 int x, int y, uint w, uint h,
			 int borderwidth, int depth,
			 uint windowclass, Visual *visual,
			 ulong valuemask, XSetWindowAttributes *attributes )
{
    // ### This isA will not work - we are still in QWidget's constructor.
    if ( qw->isTopLevel() && !qw->isA("QNPWidget") ) {
	// ### not sure it is good to use name() and className().
	bool cmap = valuemask & CWColormap;
	Widget xtw = XtVaAppCreateShell( qw->name(), qw->className(),
	    applicationShellWidgetClass, display,
	    XtNx, x, XtNy, y, XtNwidth, w, XtNheight, h,
	    XtNborderWidth, borderwidth, XtNdepth, depth,
	    XtNvisual, visual,
	    cmap ? XtNcolormap : 0, cmap ? attributes->colormap : 0,
	    0, 0 );

	// Ensure it has a window, and get it.
	XtSetMappedWhenManaged( xtw, FALSE );
	XtRealizeWidget( xtw );
	Window xw = XtWindow( xtw );

	// Set the attributes (directly)
	XChangeWindowAttributes( display, xw, valuemask, attributes );

	// Inform us on enter/leave
	XtAddEventHandler( xtw, EnterWindowMask, TRUE, enter_event_handler, 0 );
	XtAddEventHandler( xtw, LeaveWindowMask, TRUE, leave_event_handler, 0 );

	// Return Xt's window for the widget
	return xw;
    } else {
	Window window = XCreateWindow( display, parent, x, y, w, h, borderwidth, depth,
			      windowclass, visual, valuemask, attributes );
	return window;
    }
}
Exemple #12
0
void
WmPanelistShow (Widget w)

{
   SwitchData * switch_data;
   Dimension switch_rc_height;   
   Dimension switch_button_height;   

   Dimension width = XtWidth(panel.shell);
   Dimension height = XtHeight(panel.shell);
   Position x = XtX(panel.shell);
   Position y = XtY(panel.shell);
   Dimension screen_width;

   Display * display;

   CompositeWidget  cw;
   Widget         * widget_list;
   DtWmHints        vHints;

   String    shell_geometry = NULL;
   char      geometry_buffer[32];

   XSizeHints   hints;
   long	        supplied;

   int i;
   Arg al[20];
   int ac;
   


   /*  Find the switch data for later processing  */
   
   switch_data = NULL;
   
   for (i = 0; i < panel.box_data_count; i++)
   {
      if (panel.box_data[i]->switch_data != NULL)
      {
         switch_data = panel.box_data[i]->switch_data;
         break;
      }
   }


   /*  Realize the shell so that it is sized properly for later  */
   /*  positioning and child repositioning.                      */

   XtRealizeWidget (panel.shell);


   /*  See if a geometry has been set.  */
   
   ac = 0;
   XtSetArg (al[ac], XmNgeometry, &shell_geometry);  ac++;
   XtGetValues (panel.shell, al, ac);


   /*  If the shell has no default geometry, construct a default    */
   /*  which will center the panel along the bottom of the display  */

   width = XtWidth (panel.shell);
   screen_width = WidthOfScreen (XtScreen (panel.shell));
   display = XtDisplay (panel.shell);

   if (shell_geometry == NULL)
   {
      Position  x;
      char      geometry_buffer[32];

      if (panel.element_values[PANEL_GEOMETRY].string_value != NULL)
      {
         shell_geometry = panel.element_values[PANEL_GEOMETRY].parsed_value;
      }
      else
      {
         x = (screen_width > width) ? (Position)(screen_width - width) / 2 : 0;
         sprintf (geometry_buffer, "+%d-0", x);
         shell_geometry = geometry_buffer;
      }
      
      XtSetArg (al[0], XmNgeometry, shell_geometry);
      XtSetValues (panel.shell, al, 1);
   }


   /*  Adjust the positions of the buttons within the switch  */
   /*  so that they are spaced nicely.                        */

   if (switch_data != NULL)
   {
      UpdateSwitchGeometry (switch_data->box_data);


      /*  Reposition or adjust the front panel if it is either off  */
      /*  the right edge of the screen or larger than the screen    */

      if (width > screen_width)
      {
         Arg al[1];

         while (width > screen_width && 
                panel.switch_row_count < switch_data->switch_count)
         {	    
            panel.switch_row_count++;

            XtSetArg (al[0], XmNnumColumns, panel.switch_row_count);
            XtSetValues (switch_data->rc, al, 1);

            width = XtWidth (panel.shell);
         }
      }
   }

   SetGeometry (panel.shell, shell_geometry, &x, &y);
   WorkspaceAdjustPanelPosition (x, y, XtWidth (panel.shell),
                                 XtHeight (panel.shell));


   /* Set hints to avoid interactive placement */

   if (XGetWMNormalHints(display, XtWindow(panel.shell),
                         &hints, &supplied) != 0)
   {
      hints.flags |= USPosition|USSize;
      XSetWMNormalHints(display, XtWindow(panel.shell), &hints);
   }


   /*  Set the shells icon and title for when it is minimized  */
   
   if (switch_data != NULL)
   {
      int current_workspace = switch_data->active_switch;

      XtSetArg (al[0], XmNiconName, switch_data->switch_names[current_workspace]);
      XtSetArg (al[1], XmNtitle, switch_data->switch_names[current_workspace]);
      XtSetValues (panel.shell, al, 2);
   }


   /*  Set panel's window manager hints.  */

   vHints.flags = DtWM_HINTS_BEHAVIORS;
   vHints.behaviors = DtWM_BEHAVIOR_PANEL;
   _DtWsmSetDtWmHints (XtDisplay(panel.shell), XtWindow (panel.shell), &vHints);


   /*  Set the subpanel's transientShell to update transientFor and  */
   /*  Set the subpanel hints.                                       */

   vHints.behaviors |= DtWM_BEHAVIOR_SUBPANEL;
   vHints.flags |= DtWM_HINTS_ATTACH_WINDOW;
   vHints.attachWindow = XtWindow (panel.shell);

   for (i = 0, widget_list = M_PopupList (panel.shell); 
        i < M_NumPopups (panel.shell); i++)
   {
      cw = (CompositeWidget) widget_list[i];

      ac = 0;
      XtSetArg (al[ac], XmNtransientFor, NULL);  ac++;
      XtSetValues ((Widget) cw, al, ac);

      ac = 0;
      XtSetArg (al[ac], XmNtransientFor, panel.shell);  ac++;
      XtSetValues ((Widget) cw, al, ac);

      if (M_NumChildren (cw) > 0)
      {
         XtRealizeWidget ((M_Children (cw))[0]);
         _DtWsmSetDtWmHints (XtDisplay (panel.shell), 
                             XtWindow (widget_list[i]), &vHints);
      }
   }


   /*  Set the push recall list and count into the window manager's  */
   /*  screen global data.                                           */
   
   PushRecallSetData ();


   /*  Set up the callback ot the workspace management API for  */
   /*  catching changes in workspace configuration.             */
      
   DtWsmAddWorkspaceModifiedCallback(panel.shell,
                                     WorkspaceModifyCB, (XtPointer)switch_data);


   /*  Get the front panel displayed  */

   XtSetMappedWhenManaged (panel.shell, True);
   XtPopup (panel.shell, XtGrabNone);


   /*  Restore the session information  */

   SessionRestoreData ();


   /*  Set up the window and geometry information for the embedded clients  */

   for (i = 0; i < panel.embedded_client_count; i++)
      EmbeddedClientSetGeometry (&(((WmFpEmbeddedClientList) panel.embedded_client_list)[i]));


   /*  Set the embedded client list and count into the window manager's  */
   /*  screen global data.                                               */

   EmbeddedClientSetData ();
}
int do_hello_world( int argc, char *argv[], const char *printername, const char *toFile, const char *sample_string )
{
    XtAppContext         app;                                                   
    Widget               toplevel,                                              
                         shell,                                                 
                         print_shell,                                           
                         hello;                                                 
    long                 dpi_x = 0L,
                         dpi_y = 0L;                                                 
    char                 fontname[256]; /* BUG: is this really big enougth ? */ 
    XFontStruct         *textFont;                                              
    XmFontList           textFontList;                                          
    Cardinal             n;                                                     
    Arg                  args[10];                                              
    MyPrintCallbackData  mpcd;
       
    if( doPrint )
    {
      /* Get printer, either by "name" (foobar) or "name@display" (foobar@gaja:5) */
      if( XpuGetPrinter(printername, &pdpy, &pcontext) != 1 )
        Error(("XpuGetPrinter failure.\n"));
     
      /* Configure the print context (paper size, title etc.)
       * We must do this before creating any Xt widgets - otherwise they will
       * make wrong assuptions about fonts, resultions etc. ...
       */
      XpuSetJobTitle(pdpy, pcontext, "Simple Xprint XawPrintShell widget demo");
      
      /* Configuration done, set the context */
      XpSetContext(pdpy, pcontext);

      /* Get default printer resolution */   
      if( XpuGetResolution(pdpy, pcontext, &dpi_x, &dpi_y) != 1 )
      {
        fprintf(stderr, "No default resolution for printer '%s'\n", printername);
        XpuClosePrinterDisplay(pdpy, pcontext);
        return(EXIT_FAILURE);
      }

      pscreen = XpGetScreenOfContext(pdpy, pcontext);
    }
    else
    {
      pdpy = XOpenDisplay(NULL);
      if( !pdpy )
        Error(("XOpenDisplay failure.\n"));

      dpi_x = dpi_y = 0L;
      
      pscreen = XDefaultScreenOfDisplay(pdpy);
    }  

    toplevel = XawOpenApplication(&app, 
                                  pdpy, pscreen,
                                  "xpawprintshelldemo", "XpXawPrintShellDemo",
                                  applicationShellWidgetClass,
                                  &argc, argv);

    if( !toplevel )
      Error(("XawOpenApplication failure.\n"));

    if( doPrint )
    {
      n = 0;
      /* Override any geometry resource settings as XawPrintShell adjusts it's size
       * to the current page siue when |XawPrintLAYOUTMODE_DRAWABLEAREA| or
       * |XawPrintLAYOUTMODE_PAGESIZE| are used. */
      XtSetArg(args[n], XtNgeometry,    "+0+0");                          n++;
      XtSetArg(args[n], XawNlayoutMode, XawPrintLAYOUTMODE_DRAWABLEAREA); n++;
      print_shell = XtCreatePopupShell("myprintshell", 
                                       xawPrintShellWidgetClass, 
                                       toplevel, args, n);

      /* we're mapping/unmapping at start/end page time */
      XtSetMappedWhenManaged(print_shell, False);
      
      shell = print_shell;
    }
    else
    {
      shell = toplevel;
    }

    sprintf(fontname, "-adobe-courier-medium-r-normal--40-*-%ld-%ld-*-*-iso8859-1", dpi_x, dpi_y);
    textFont = XLoadQueryFont(pdpy, fontname);
    if( !textFont )
    {          
      sprintf(fontname, "-*-*-*-*-*-*-*-160-%ld-%ld-*-*-iso8859-1", dpi_x, dpi_y);
      textFont = XLoadQueryFont(pdpy, fontname);
    }
    if( !textFont )
      Error(("XLoadQueryFont failure.\n"));
    textFontList = XmFontListCreate(textFont, XmSTRING_DEFAULT_CHARSET);     

    n = 0;
    /* Make sure the cursor is off, current Xprt servers do not seem to like
     * blinking cursors that much... ;-/ */
    XtSetArg(args[n], XmNcursorPositionVisible, False);              n++;
    XtSetArg(args[n], XmNvalue,                 sample_string);      n++;
    XtSetArg(args[n], XmNfontList,              textFontList);       n++;
    XtSetArg(args[n], XmNeditMode,              XmMULTI_LINE_EDIT);  n++;
    
    hello = XmCreateText(shell, "mytext", args, n);
    if( !hello )
      Error(("XmCreateText failure.\n"));
      
    XtManageChild(hello);
    XtRealizeWidget(toplevel);
    XtRealizeWidget(shell);
    
    if( doPrint )
    {
      int   num_total_rows;
      short num_visible_rows;
      int   num_pages;

      pdpy      = XtDisplay(toplevel);
      pdrawable = XtWindow(toplevel);
      if( !pdpy || !pdrawable )
        Error(("No display.\n"));
      
      /* Make sure that the Xt machinery is really using the right screen (assertion) */
      if( XpGetScreenOfContext(XtDisplay(toplevel), pcontext) != XtScreen(toplevel) )
        Error(("Widget's screen != print screen. BAD.\n"));
                  
      /* Get number of rows visible per page and the number of total rows 
       * in the whole text widget... */
      n = 0;
      XtSetArg(args[n], XmNrows,       &num_visible_rows); n++ ;
      XtSetArg(args[n], XmNtotalLines, &num_total_rows);   n++ ;
      XtGetValues(hello, args, n);

      /* Take away one row to match the one-line overlapping used by the
       * "next-page" action proc */      
      num_visible_rows -= 1;

      /* Calculate the number of pages */
      num_pages = (num_total_rows+num_visible_rows-1) / num_visible_rows;
      Log(("Printing %d pages (num_total_rows=%d, num_visible_rows=%d)...\n", 
           num_pages, num_total_rows, num_visible_rows));
      
      /* Prepare our own context data for the print shell callbacks */
      mpcd.num_pages          = num_pages;
      mpcd.printshell_content = hello;
      mpcd.num_visible_rows   = num_visible_rows;
      mpcd.appcontext         = app;
      
      /* Setup the print shell callbacks... */
      XtAddCallback(print_shell,  XawNpageSetupCallback, PrintOnePageCB,  (XtPointer)&mpcd);
      XtAddCallback(print_shell,  XawNstartJobCallback,  PrintStartJobCB, NULL);
      XtAddCallback(print_shell,  XawNendJobCallback,    PrintEndJobCB,   (XtPointer)&mpcd);  

      /* ... and finally start the print job. */
      if( toFile )
      {
        printtofile_handle = XpuStartJobToFile(pdpy, pcontext, toFile);
        if( !printtofile_handle )
        {
          perror("XpuStartJobToFile failure");
          Error(("XpuStartJobToFile failure."));
        }
      }
      else
      {
        XpuStartJobToSpooler(pdpy);
      }
    }
    
    XtAppMainLoop(app);
    
    if( doPrint )
    {
      if( toFile )
      {
        if( XpuWaitForPrintFileChild(printtofile_handle) != XPGetDocFinished )
        {
          fprintf(stderr, "%s: Error while printing to file.\n", ProgramName);
        }
      }

      PrintSpoolerCommandResults(pdpy, pcontext);    

      /* We have to use XpDestroyContext() and XtCloseDisplay() instead
       * of XpuClosePrinterDisplay() to make libXt happy... */
      if( pcontext != None )
        XpDestroyContext(pdpy, pcontext);
      XtCloseDisplay(pdpy);
    }
   
    return EXIT_SUCCESS;
}
static void
ComputeLayout(Widget widget, Bool query, Bool destroy_scrollbars)
{
    ViewportWidget w = (ViewportWidget)widget;
    Widget child = w->viewport.child;
    Widget clip = w->viewport.clip;
    ViewportConstraints constraints =
	(ViewportConstraints)clip->core.constraints;
    Bool needshoriz, needsvert;
    int clip_width, clip_height;
    XtWidgetGeometry intended;

    if (child == NULL)
	return;

    clip_width = XtWidth(w);
    clip_height = XtHeight(w);
    intended.request_mode = CWBorderWidth;
    intended.border_width = 0;

    if (w->viewport.forcebars) {
	needsvert = w->viewport.allowvert;
	needshoriz = w->viewport.allowhoriz;
	ComputeWithForceBars(widget, query, &intended,
			     &clip_width, &clip_height);
    }
    else {
	Dimension prev_width, prev_height;
	XtGeometryMask prev_mode;
	XtWidgetGeometry preferred;

	needshoriz = needsvert = False;

	/*
	 * intended.{width,height} caches the eventual child dimensions,
	 * but we don't set the mode bits until after we decide that the
	 * child's preferences are not acceptable
	 */
	if (!w->viewport.allowhoriz)
	    intended.request_mode |= CWWidth;

	if (XtWidth(child) < clip_width)
	    intended.width = clip_width;
	else
	    intended.width = XtWidth(child);

	if (XtHeight(child) < clip_height)
	    intended.height = clip_height;
	else
	    intended.height = XtHeight(child);

	if (!w->viewport.allowvert)
	    intended.request_mode |= CWHeight;

	if (!query) {
	    preferred.width = XtWidth(child);
	    preferred.height = XtHeight(child);
	}
	do { /* while intended != prev  */
	    if (query) {
		(void)XtQueryGeometry(child, &intended, &preferred);
		if (!(preferred.request_mode & CWWidth))
		    preferred.width = intended.width;
		if (!(preferred.request_mode & CWHeight))
		    preferred.height = intended.height;
	    }
	    prev_width = intended.width;
	    prev_height = intended.height;
	    prev_mode = intended.request_mode;
	    /*
	     * note that having once decided to turn on either bar
	     * we'll not change our mind until we're next resized,
	     * thus avoiding potential oscillations
	     */
#define CheckHoriz() \
	    if (w->viewport.allowhoriz &&				\
		preferred.width > clip_width) {				\
		if (!needshoriz) {					\
		    Widget bar;						\
									\
		    needshoriz = True;					\
		    if ((bar = w->viewport.horiz_bar) == NULL)		\
			bar = CreateScrollbar(w, True);			\
		    clip_height -= XtHeight(bar) + XtBorderWidth(bar);	\
		    if (clip_height < 1)				\
			clip_height = 1;				\
		}							\
		intended.width = preferred.width;			\
	    }

	    CheckHoriz();
	    if (w->viewport.allowvert && preferred.height > clip_height) {
		if (!needsvert) {
		    Widget bar;
		    needsvert = True;
		    if ((bar = w->viewport.vert_bar) == NULL)
			bar = CreateScrollbar(w, False);
		    clip_width -= XtWidth(bar) + XtBorderWidth(bar);
		    if (clip_width < 1)
			clip_width = 1;
		    CheckHoriz();
		}
		intended.height = preferred.height;
	    }
	    if (!w->viewport.allowhoriz || preferred.width < clip_width) {
		intended.width = clip_width;
		intended.request_mode |= CWWidth;
	    }
	    if (!w->viewport.allowvert || preferred.height < clip_height) {
		intended.height = clip_height;
		intended.request_mode |= CWHeight;
	    }
	} while (intended.request_mode != prev_mode
		 || (intended.request_mode & CWWidth
		     && intended.width != prev_width)
		 || (intended.request_mode & CWHeight
		     && intended.height != prev_height));
    }

    if (XtIsRealized(clip))
	XRaiseWindow(XtDisplay(clip), XtWindow(clip));

    XtMoveWidget(clip,
		 needsvert ? w->viewport.useright ? 0 :
		 XtWidth(w->viewport.vert_bar)
		 + XtBorderWidth(w->viewport.vert_bar) : 0,
		 needshoriz ? w->viewport.usebottom ? 0 :
		 XtHeight(w->viewport.horiz_bar)
		 + XtBorderWidth(w->viewport.horiz_bar) : 0);
    XtResizeWidget(clip, clip_width, clip_height, 0);

    if (w->viewport.horiz_bar != NULL) {
	Widget bar = w->viewport.horiz_bar;

	if (!needshoriz) {
	    constraints->form.vert_base = NULL;
	    if (destroy_scrollbars) {
		XtDestroyWidget(bar);
		w->viewport.horiz_bar = NULL;
	    }
	}
	else {
	    int bw = XtBorderWidth(bar);

	    XtResizeWidget(bar, clip_width, XtHeight(bar), bw);
	    XtMoveWidget(bar,
			 needsvert && !w->viewport.useright
			 ? XtWidth(w->viewport.vert_bar) : -bw,
			 w->viewport.usebottom
			 ? XtHeight(w) - XtHeight(bar) - bw : -bw);
	    XtSetMappedWhenManaged(bar, True);
	}
    }

    if (w->viewport.vert_bar != NULL) {
	Widget bar = w->viewport.vert_bar;

	if (!needsvert)	{
	    constraints->form.horiz_base = NULL;
	    if (destroy_scrollbars) {
		XtDestroyWidget(bar);
		w->viewport.vert_bar = NULL;
	    }
	}
	else {
	    int bw = bar->core.border_width;

	    XtResizeWidget(bar, XtWidth(bar), clip_height, bw);
	    XtMoveWidget(bar,
			w->viewport.useright
			? XtWidth(w) - XtWidth(bar) - bw : -bw,
			needshoriz && !w->viewport.usebottom
			? XtHeight(w->viewport.horiz_bar) : -bw);
	   XtSetMappedWhenManaged(bar, True);
	}
    }

    if (child != NULL) {
	XtResizeWidget(child, intended.width, intended.height, 0);
	MoveChild(w, needshoriz ? XtX(child) : 0,	needsvert ? XtY(child) : 0);
    }

    SendReport (w, XawPRAll);
}