| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1990,91 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.4 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoXtPrintDialog |
| 47 |
| |
| 48 |
| Author(s): Dave Immel |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
|
| 54 |
#include <Inventor/SbPList.h> |
| 55 |
#include <Inventor/SoOffscreenRenderer.h> |
| 56 |
#include <Inventor/SoOutput.h> |
| 57 |
#include <Inventor/SoPath.h> |
| 58 |
#include <Inventor/Xt/SoXt.h> |
| 59 |
#include <Inventor/Xt/SoXtPrintDialog.h> |
| 60 |
#include <Inventor/errors/SoDebugError.h> |
| 61 |
#include <Inventor/nodes/SoNode.h> |
| 62 |
#include <Inventor/actions/SoGLRenderAction.h> |
| 63 |
#include <Inventor/actions/SoWriteAction.h> |
| 64 |
#include <Inventor/Xt/SoXtResource.h> |
| 65 |
|
| 66 |
#include <assert.h> |
| 67 |
#include <fcntl.h> |
| 68 |
#include <signal.h> |
| 69 |
#include <errno.h> |
| 70 |
#include <cstdio> |
| 71 |
#include <cstring> |
| 72 |
#include <sys/types.h> |
| 73 |
#include <sys/wait.h> |
| 74 |
#include <unistd.h> |
| 75 |
#include <cstdlib> |
| 76 |
|
| 77 |
#include <X11/StringDefs.h> |
| 78 |
#include <Xm/BulletinB.h> |
| 79 |
#include <Xm/Form.h> |
| 80 |
#include <Xm/Label.h> |
| 81 |
#include <Xm/LabelG.h> |
| 82 |
#include <Xm/List.h> |
| 83 |
#include <Xm/PushB.h> |
| 84 |
#include <Xm/PushBG.h> |
| 85 |
#include <Xm/RowColumn.h> |
| 86 |
#include <Xm/SeparatoG.h> |
| 87 |
#include <Xm/Text.h> |
| 88 |
#include <Xm/ToggleB.h> |
| 89 |
#include <GL/gl.h> |
| 90 |
|
| 91 |
|
| 92 |
// Definitions for PostScript Output |
| 93 |
#define INITIALXRES 288 |
| 94 |
#define INITIALYRES 378 |
| 95 |
#define FULLPAGEXSIZE (8.5) |
| 96 |
#define FULLPAGEYSIZE (11.0) |
| 97 |
#define PNTS (72.27) |
| 98 |
#define PAGEXSIZE (8.0) |
| 99 |
#define PAGEYSIZE (10.5) |
| 100 |
#define PAGEMARGIN (0.25) |
| 101 |
#define SO_PRINTER_STRLEN 32 |
| 102 |
#define INCHES_PER_MM 3.937008e-02 |
| 103 |
#define POINTS_PER_INCH 72.27 |
| 104 |
|
| 105 |
|
| 106 |
#define PRINTER_MENU_HEIGHT 330 |
| 107 |
#define RGB_FILE_MENU_HEIGHT 220 |
| 108 |
#define POSTSCRIPT_FILE_MENU_HEIGHT 275 |
| 109 |
|
| 110 |
#define PRINTER_NAME(INDEX) ((char *) ((*printers)[INDEX])) |
| 111 |
#if 0 |
| 112 |
#define ADD_STYLE_BUTTON(KONST) \ |
| 113 |
sButtons[KONST] = XmCreatePushButtonGadget (stylePopup, \ |
| 114 |
styleLabels[KONST], wargs, 1); \ |
| 115 |
XtAddCallback (sButtons[KONST], XmNactivateCallback, \ |
| 116 |
(XtCallbackProc) SoXtPrintDialog::stylePopupCB, \ |
| 117 |
(XtPointer)(KONST)); |
| 118 |
#endif |
| 119 |
|
| 120 |
|
| 121 |
// Resources for labels. +++ |
| 122 |
typedef struct { |
| 123 |
char *pageOutput; |
| 124 |
char *toPrinter; |
| 125 |
char *toFile; |
| 126 |
char *fileFormat; |
| 127 |
char *postScript; |
| 128 |
char *rgb; |
| 129 |
char *resolution; |
| 130 |
char *fileName; |
| 131 |
char *printQuality; |
| 132 |
char *high; |
| 133 |
char *draft; |
| 134 |
char *pageFormat; |
| 135 |
char *portrait; |
| 136 |
char *landscape; |
| 137 |
char *printSize; |
| 138 |
char *printer; |
| 139 |
char *dpi; |
| 140 |
char *message; |
| 141 |
char *quitB; |
| 142 |
char *printB; |
| 143 |
char *holzn1; |
| 144 |
char *holzn2; |
| 145 |
char *vertc1; |
| 146 |
char *by; |
| 147 |
} RES_LABELS; |
| 148 |
static RES_LABELS rl; |
| 149 |
static char *defaults[]={ |
| 150 |
"Page Output:", |
| 151 |
"To Printer", |
| 152 |
"To File", |
| 153 |
"File Format:", |
| 154 |
"PostScript", |
| 155 |
"RGB", |
| 156 |
"Resolution:", |
| 157 |
"File Name:", |
| 158 |
"Print Quality:", |
| 159 |
"High", |
| 160 |
"Draft", |
| 161 |
"Page Format:", |
| 162 |
"Portrait", |
| 163 |
"Landscape", |
| 164 |
"Print Size (inches):", |
| 165 |
"Printer:", |
| 166 |
"DPI:", |
| 167 |
"Message:", |
| 168 |
"Quit", |
| 169 |
"Print", |
| 170 |
"7", |
| 171 |
"5", |
| 172 |
"7", |
| 173 |
"by" |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
// ??? COMPAT 2.0 |
| 178 |
// |
| 179 |
// This addition is being made to enable the programmer to pass in an |
| 180 |
// SoGLRenderAction to be used when rendering. To insure binary |
| 181 |
// compatibility, a static list of structures will be kept to record |
| 182 |
// the instances of this class with the print dialogs that are |
| 183 |
// set with them. |
| 184 |
// |
| 185 |
|
| 186 |
class _SoPrintDialogItem { |
| 187 |
public: |
| 188 |
_SoPrintDialogItem(SoGLRenderAction *glAct, SoXtPrintDialog *p) |
| 189 |
{ act = glAct; printDialog = p;} |
| 190 |
SoGLRenderAction *act; // The render action used with this instance |
| 191 |
SoXtPrintDialog *printDialog;// The instance of the print dialog |
| 192 |
}; |
| 193 |
|
| 194 |
// The list of print dialogs and their render actions |
| 195 |
static SbPList *printDialogList = NULL; |
| 196 |
|
| 197 |
//////////////////////////////////////////////////////////////////////// |
| 198 |
// |
| 199 |
// Description: |
| 200 |
// ??? COMPAT 2.0 |
| 201 |
// Find the instance of the _SoPrintDialogItem class that corresponds |
| 202 |
// to this instance of the SoXtPrintDialog class. |
| 203 |
// |
| 204 |
// Use: internal |
| 205 |
|
| 206 |
static _SoPrintDialogItem *_SoFindPrintDialog(const SoXtPrintDialog *dialog) |
| 207 |
|
| 208 |
// |
| 209 |
//////////////////////////////////////////////////////////////////////// |
| 210 |
{ |
| 211 |
// If no class instances have been stored, return NULL |
| 212 |
if (printDialogList == NULL) |
| 213 |
return NULL; |
| 214 |
|
| 215 |
for (int i=0; i<printDialogList->getLength(); i++) { |
| 216 |
|
| 217 |
_SoPrintDialogItem *item = (_SoPrintDialogItem *)(*printDialogList)[i]; |
| 218 |
if (item->printDialog == dialog) |
| 219 |
return item; |
| 220 |
} |
| 221 |
|
| 222 |
// A render action has not been set with this instance. Return NULL. |
| 223 |
return NULL; |
| 224 |
} |
| 225 |
|
| 226 |
//////////////////////////////////////////////////////////////////////// |
| 227 |
// |
| 228 |
// Public constructor - build the widget right now |
| 229 |
// |
| 230 |
SoXtPrintDialog::SoXtPrintDialog( |
| 231 |
Widget parent, |
| 232 |
const char *name, |
| 233 |
SbBool buildInsideParent) |
| 234 |
: SoXtComponent( |
| 235 |
parent, |
| 236 |
name, |
| 237 |
buildInsideParent) |
| 238 |
// |
| 239 |
//////////////////////////////////////////////////////////////////////// |
| 240 |
{ |
| 241 |
// In this case, print dialog is what the app wants, so buildNow = TRUE |
| 242 |
constructorCommon(TRUE); |
| 243 |
} |
| 244 |
|
| 245 |
//////////////////////////////////////////////////////////////////////// |
| 246 |
// |
| 247 |
// SoEXTENDER constructor - the subclass tells us whether to build or not |
| 248 |
// |
| 249 |
SoXtPrintDialog::SoXtPrintDialog( |
| 250 |
Widget parent, |
| 251 |
const char *name, |
| 252 |
SbBool buildInsideParent, |
| 253 |
SbBool buildNow) |
| 254 |
: SoXtComponent( |
| 255 |
parent, |
| 256 |
name, |
| 257 |
buildInsideParent) |
| 258 |
// |
| 259 |
//////////////////////////////////////////////////////////////////////// |
| 260 |
{ |
| 261 |
// In this case, print dialog may be what the app wants, |
| 262 |
// or it may want a subclass of print dialog. Pass along buildNow |
| 263 |
// as it was passed to us. |
| 264 |
constructorCommon(buildNow); |
| 265 |
} |
| 266 |
|
| 267 |
//////////////////////////////////////////////////////////////////////// |
| 268 |
// |
| 269 |
// Called by the constructors |
| 270 |
// |
| 271 |
// private |
| 272 |
// |
| 273 |
void |
| 274 |
SoXtPrintDialog::constructorCommon(SbBool buildNow) |
| 275 |
// |
| 276 |
////////////////////////////////////////////////////////////////////// |
| 277 |
{ |
| 278 |
printDone = TRUE; |
| 279 |
highQuality = TRUE; |
| 280 |
portraitFormat = TRUE; |
| 281 |
printerOutput = TRUE; |
| 282 |
postScriptOutput = TRUE; |
| 283 |
nodeMostRecent = TRUE; |
| 284 |
rootNode = NULL; |
| 285 |
rootPath = NULL; |
| 286 |
defaultPrinter = NULL; |
| 287 |
printerHorizSize = NULL; |
| 288 |
printerVertSize = NULL; |
| 289 |
postScriptHorizSize = NULL; |
| 290 |
postScriptVertSize = NULL; |
| 291 |
rgbHorizSize = NULL; |
| 292 |
rgbVertSize = NULL; |
| 293 |
alreadyUpdated = FALSE; |
| 294 |
printers = new SbPList; |
| 295 |
printRes.setValue(INITIALXRES, INITIALYRES); |
| 296 |
printSize.setValue(printRes[0]/SoOffscreenRenderer::getScreenPixelsPerInch(), |
| 297 |
printRes[1]/SoOffscreenRenderer::getScreenPixelsPerInch()); |
| 298 |
|
| 299 |
// |
| 300 |
// Create the list of available printers. |
| 301 |
// |
| 302 |
getPrinterList(); |
| 303 |
|
| 304 |
// Build the widget tree, and let SoXtComponent know about our base widget. |
| 305 |
if (buildNow) { |
| 306 |
Widget w = buildWidget(getParentWidget()); |
| 307 |
setBaseWidget(w); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
/////////////////////////////////////////////////////////////////////// |
| 312 |
// |
| 313 |
// Description: |
| 314 |
// Destructor. |
| 315 |
// |
| 316 |
// Use: public |
| 317 |
|
| 318 |
SoXtPrintDialog::~SoXtPrintDialog() |
| 319 |
|
| 320 |
// |
| 321 |
////////////////////////////////////////////////////////////////////// |
| 322 |
{ |
| 323 |
// ??? COMPAT 2.0 |
| 324 |
// |
| 325 |
// Get the print dialog item from the list and delete the render action. |
| 326 |
// Then, remove the item from the list and delete it. |
| 327 |
// |
| 328 |
_SoPrintDialogItem *item = _SoFindPrintDialog(this); |
| 329 |
if (item != NULL) { |
| 330 |
delete item->act; |
| 331 |
printDialogList->remove(printDialogList->find(item)); |
| 332 |
delete item; |
| 333 |
} |
| 334 |
|
| 335 |
for (int i = 0; i < printers->getLength(); i++) { |
| 336 |
if (PRINTER_NAME(i) != NULL) free(PRINTER_NAME(i)); |
| 337 |
} |
| 338 |
delete printers; |
| 339 |
if (defaultPrinter != NULL) free(defaultPrinter); |
| 340 |
|
| 341 |
if (rootNode != NULL) |
| 342 |
rootNode->unref(); |
| 343 |
} |
| 344 |
|
| 345 |
//////////////////////////////////////////////////////////////////////// |
| 346 |
// |
| 347 |
// Description: |
| 348 |
// Get the render action. |
| 349 |
// |
| 350 |
// Use: public |
| 351 |
|
| 352 |
SoGLRenderAction * |
| 353 |
SoXtPrintDialog::getGLRenderAction() |
| 354 |
|
| 355 |
|
| 356 |
// |
| 357 |
//////////////////////////////////////////////////////////////////////// |
| 358 |
{ |
| 359 |
// ??? COMPAT 2.0 |
| 360 |
// |
| 361 |
// Find the list item and return the action associated with it. |
| 362 |
// If there is none, allocate one and put it on the list. Return |
| 363 |
// the new action. |
| 364 |
// |
| 365 |
_SoPrintDialogItem *printItem = _SoFindPrintDialog(this); |
| 366 |
if (printItem == NULL) { |
| 367 |
SbViewportRegion tmpRegion(100, 100); |
| 368 |
SoGLRenderAction *tmpAct = new SoGLRenderAction(tmpRegion); |
| 369 |
printItem = new _SoPrintDialogItem(tmpAct, this); |
| 370 |
|
| 371 |
// If the printDialogList is NULL, allocate one and add the new |
| 372 |
// item to it. |
| 373 |
if (printDialogList == NULL) { |
| 374 |
printDialogList = new SbPList(4); |
| 375 |
} |
| 376 |
printDialogList->append(printItem); |
| 377 |
} |
| 378 |
|
| 379 |
return (printItem->act); |
| 380 |
} |
| 381 |
|
| 382 |
//////////////////////////////////////////////////////////////////////// |
| 383 |
// |
| 384 |
// Description: |
| 385 |
// Set the render action. |
| 386 |
// |
| 387 |
// Use: public |
| 388 |
|
| 389 |
void |
| 390 |
SoXtPrintDialog::setGLRenderAction( |
| 391 |
const SoGLRenderAction *act ) |
| 392 |
|
| 393 |
|
| 394 |
// |
| 395 |
//////////////////////////////////////////////////////////////////////// |
| 396 |
{ |
| 397 |
// ??? COMPAT 2.0 |
| 398 |
// |
| 399 |
// Find the list item and load the new render action into it. |
| 400 |
// If there is currently no render action associated with this |
| 401 |
// instance, create one. Store the new action in the item. |
| 402 |
// |
| 403 |
_SoPrintDialogItem *item = _SoFindPrintDialog(this); |
| 404 |
|
| 405 |
if (item == NULL) { |
| 406 |
item = new _SoPrintDialogItem((SoGLRenderAction *)act, this); |
| 407 |
|
| 408 |
// If the printDialogList is NULL, allocate one and add the new |
| 409 |
// item to it. |
| 410 |
if (printDialogList == NULL) { |
| 411 |
printDialogList = new SbPList(4); |
| 412 |
} |
| 413 |
printDialogList->append(item); |
| 414 |
} |
| 415 |
|
| 416 |
item->act = (SoGLRenderAction *)act; |
| 417 |
} |
| 418 |
|
| 419 |
/////////////////////////////////////////////////////////////////////// |
| 420 |
// |
| 421 |
// Description: |
| 422 |
// Set the root of the scene graph to print. |
| 423 |
// |
| 424 |
// Use: public |
| 425 |
// |
| 426 |
void |
| 427 |
SoXtPrintDialog::setSceneGraph( SoNode *root ) |
| 428 |
// |
| 429 |
////////////////////////////////////////////////////////////////////// |
| 430 |
{ |
| 431 |
if ( root != NULL ) |
| 432 |
root->ref(); |
| 433 |
|
| 434 |
if (rootNode != NULL) |
| 435 |
rootNode->unref(); |
| 436 |
|
| 437 |
rootNode = root; |
| 438 |
|
| 439 |
if (rootNode != NULL) |
| 440 |
nodeMostRecent = TRUE; |
| 441 |
} |
| 442 |
|
| 443 |
/////////////////////////////////////////////////////////////////////// |
| 444 |
// |
| 445 |
// Description: |
| 446 |
// Set the root path of the scene graph to print. |
| 447 |
// |
| 448 |
// Use: public |
| 449 |
// |
| 450 |
void |
| 451 |
SoXtPrintDialog::setSceneGraph( SoPath *root ) |
| 452 |
// |
| 453 |
////////////////////////////////////////////////////////////////////// |
| 454 |
{ |
| 455 |
if ( root != NULL ) |
| 456 |
root->ref(); |
| 457 |
|
| 458 |
if (rootPath != NULL) |
| 459 |
rootPath->unref(); |
| 460 |
|
| 461 |
rootPath = root; |
| 462 |
|
| 463 |
if (rootPath != NULL) |
| 464 |
nodeMostRecent = FALSE; |
| 465 |
} |
| 466 |
|
| 467 |
/////////////////////////////////////////////////////////////////////// |
| 468 |
// |
| 469 |
// Description: |
| 470 |
// Set the size of the print |
| 471 |
// |
| 472 |
// Use: public |
| 473 |
// |
| 474 |
void |
| 475 |
SoXtPrintDialog::setPrintSize( const SbVec2f &psize ) |
| 476 |
// |
| 477 |
////////////////////////////////////////////////////////////////////// |
| 478 |
{ |
| 479 |
printSize = psize; |
| 480 |
printRes.setValue( |
| 481 |
(short)(printSize[0]*SoOffscreenRenderer::getScreenPixelsPerInch()), |
| 482 |
(short)(printSize[1]*SoOffscreenRenderer::getScreenPixelsPerInch())); |
| 483 |
|
| 484 |
updateTextports(); |
| 485 |
} |
| 486 |
|
| 487 |
/////////////////////////////////////////////////////////////////////// |
| 488 |
// |
| 489 |
// Description: |
| 490 |
// Set the size of the print in pixels |
| 491 |
// |
| 492 |
// Use: public |
| 493 |
// |
| 494 |
void |
| 495 |
SoXtPrintDialog::setPrintSize( const SbVec2s &psize ) |
| 496 |
// |
| 497 |
////////////////////////////////////////////////////////////////////// |
| 498 |
{ |
| 499 |
printRes = psize; |
| 500 |
printSize.setValue( |
| 501 |
printRes[0]/SoOffscreenRenderer::getScreenPixelsPerInch(), |
| 502 |
printRes[1]/SoOffscreenRenderer::getScreenPixelsPerInch()); |
| 503 |
|
| 504 |
updateTextports(); |
| 505 |
} |
| 506 |
|
| 507 |
/////////////////////////////////////////////////////////////////////// |
| 508 |
// |
| 509 |
// Description: |
| 510 |
// This builds the widget. |
| 511 |
// |
| 512 |
// Use: public |
| 513 |
|
| 514 |
Widget |
| 515 |
SoXtPrintDialog::buildWidget(Widget parent) |
| 516 |
|
| 517 |
// |
| 518 |
////////////////////////////////////////////////////////////////////// |
| 519 |
{ |
| 520 |
XmString printMsg; |
| 521 |
Arg wargs[16]; |
| 522 |
int n; |
| 523 |
|
| 524 |
// |
| 525 |
// "widget" is the main widget for the print widget. labels and their |
| 526 |
// associated radio buttons, a label and scrollList widget for selecting |
| 527 |
// a printer, a label and text widget for typing a filename, quit and |
| 528 |
// print buttons, and a message text widget. |
| 529 |
// |
| 530 |
n = 0; |
| 531 |
Widget widget = XtCreateWidget(getWidgetName(), xmBulletinBoardWidgetClass, |
| 532 |
parent, NULL, 0); |
| 533 |
XtSetArg( wargs[n], XmNmarginWidth, 10 ); n++; |
| 534 |
XtSetValues( widget, wargs, n ); |
| 535 |
|
| 536 |
|
| 537 |
// get resources... |
| 538 |
SoXtResource xr(widget); |
| 539 |
if (!xr.getResource( "pageOutput", "PageOutput", rl.pageOutput )) |
| 540 |
rl.pageOutput = defaults[0]; |
| 541 |
if (!xr.getResource( "toPrinter", "ToPrinter", rl.toPrinter )) |
| 542 |
rl.toPrinter = defaults[1]; |
| 543 |
if (!xr.getResource( "toFile", "ToFile", rl.toFile )) |
| 544 |
rl.toFile = defaults[2]; |
| 545 |
if (!xr.getResource( "fileFormat", "FileFormat", rl.fileFormat )) |
| 546 |
rl.fileFormat = defaults[3]; |
| 547 |
if (!xr.getResource( "postScript", "PostScript", rl.postScript )) |
| 548 |
rl.postScript = defaults[4]; |
| 549 |
if (!xr.getResource( "rgb", "RGB", rl.rgb )) |
| 550 |
rl.rgb = defaults[5]; |
| 551 |
if (!xr.getResource( "resolution", "Resolution", rl.resolution )) |
| 552 |
rl.resolution = defaults[6]; |
| 553 |
if (!xr.getResource( "fileName", "FileName", rl.fileName )) |
| 554 |
rl.fileName = defaults[7]; |
| 555 |
if (!xr.getResource( "printQuality", "PrintQuality", rl.printQuality )) |
| 556 |
rl.printQuality = defaults[8]; |
| 557 |
if (!xr.getResource( "high", "High", rl.high )) |
| 558 |
rl.high = defaults[9]; |
| 559 |
if (!xr.getResource( "draft", "Draft", rl.draft )) |
| 560 |
rl.draft = defaults[10]; |
| 561 |
if (!xr.getResource( "pageFormat", "PageFormat", rl.pageFormat )) |
| 562 |
rl.pageFormat = defaults[11]; |
| 563 |
if (!xr.getResource( "portrait", "Portrait", rl.portrait )) |
| 564 |
rl.portrait = defaults[12]; |
| 565 |
if (!xr.getResource( "landscape", "Landscape", rl.landscape )) |
| 566 |
rl.landscape = defaults[13]; |
| 567 |
if (!xr.getResource( "printSize", "PrintSize", rl.printSize )) |
| 568 |
rl.printSize = defaults[14]; |
| 569 |
if (!xr.getResource( "printer", "Printer", rl.printer )) |
| 570 |
rl.printer = defaults[15]; |
| 571 |
if (!xr.getResource( "dpi", "DPI", rl.dpi )) |
| 572 |
rl.dpi = defaults[16]; |
| 573 |
if (!xr.getResource( "message", "Message", rl.message )) |
| 574 |
rl.message = defaults[17]; |
| 575 |
if (!xr.getResource( "quitB", "QuitB", rl.quitB )) |
| 576 |
rl.quitB = defaults[18]; |
| 577 |
if (!xr.getResource( "printB", "PrintB", rl.printB )) |
| 578 |
rl.printB = defaults[19]; |
| 579 |
if (!xr.getResource( "holznColumn1", "HolznColumn1", rl.holzn1 )) |
| 580 |
rl.holzn1 = defaults[20]; |
| 581 |
if (!xr.getResource( "holznColumn2", "HolznColumn2", rl.holzn2 )) |
| 582 |
rl.holzn2 = defaults[21]; |
| 583 |
if (!xr.getResource( "vertcColumn1", "VertcColumn1", rl.vertc1 )) |
| 584 |
rl.vertc1 = defaults[22]; |
| 585 |
if (!xr.getResource( "byLabel", "ByLabel", rl.by )) |
| 586 |
rl.by = defaults[23]; |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
// Build the radio button for the Page Output. |
| 591 |
buildRadioButton( rl.pageOutput, rl.toPrinter, rl.toFile, 120, 5, |
| 592 |
widget, (XtCallbackProc) SoXtPrintDialog::outputCB); |
| 593 |
|
| 594 |
// |
| 595 |
// Create the Quit and Print buttons, and the message textport. These |
| 596 |
// will change position as the menu changes. |
| 597 |
// |
| 598 |
n = 0; |
| 599 |
printMsg = XmStringCreate ( rl.quitB, XmSTRING_DEFAULT_CHARSET); |
| 600 |
XtSetArg( wargs[n], XmNx, 180 ); n++; |
| 601 |
XtSetArg( wargs[n], XmNy, 170 ); n++; |
| 602 |
XtSetArg( wargs[n], XmNwidth, 70 ); n++; |
| 603 |
XtSetArg( wargs[n], XmNheight, 30 ); n++; |
| 604 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 605 |
XtSetArg( wargs[n], XmNlabelString, printMsg ); n++; |
| 606 |
quitButton = XtCreateManagedWidget (NULL, xmPushButtonWidgetClass, |
| 607 |
widget, wargs, n); |
| 608 |
XtAddCallback (quitButton, XmNactivateCallback, |
| 609 |
(XtCallbackProc) SoXtPrintDialog::quitCB, (XtPointer)(this)); |
| 610 |
XmStringFree(printMsg); |
| 611 |
|
| 612 |
n = 0; |
| 613 |
printMsg = XmStringCreate (rl.printB, XmSTRING_DEFAULT_CHARSET); |
| 614 |
XtSetArg( wargs[n], XmNx, 270 ); n++; |
| 615 |
XtSetArg( wargs[n], XmNy, 170 ); n++; |
| 616 |
XtSetArg( wargs[n], XmNwidth, 70 ); n++; |
| 617 |
XtSetArg( wargs[n], XmNheight, 30 ); n++; |
| 618 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 619 |
XtSetArg( wargs[n], XmNlabelString, printMsg ); n++; |
| 620 |
printButton = XtCreateManagedWidget (NULL, xmPushButtonWidgetClass, |
| 621 |
widget, wargs, n); |
| 622 |
XtAddCallback (printButton, XmNactivateCallback, |
| 623 |
(XtCallbackProc) SoXtPrintDialog::printCB, (XtPointer)(this)); |
| 624 |
XmStringFree(printMsg); |
| 625 |
|
| 626 |
n = 0; |
| 627 |
printMsg = XmStringCreate( rl.message, XmSTRING_DEFAULT_CHARSET); |
| 628 |
XtSetArg( wargs[n], XmNy, 180 ); n++; |
| 629 |
XtSetArg( wargs[n], XmNlabelString, printMsg ); n++; |
| 630 |
messageLabelWidget = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 631 |
widget, wargs, n); |
| 632 |
n = 0; |
| 633 |
XtSetArg( wargs[n], XmNy, 210 ); n++; |
| 634 |
XtSetArg( wargs[n], XmNwidth, 330 ); n++; |
| 635 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 636 |
XtSetArg( wargs[n], XmNeditable, FALSE ); n++; |
| 637 |
messageWidget = XtCreateManagedWidget (NULL, xmTextWidgetClass, |
| 638 |
widget, wargs, n); |
| 639 |
XmStringFree(printMsg); |
| 640 |
|
| 641 |
// Create the widget storing the file format radio buttons |
| 642 |
n = 0; |
| 643 |
fileFormatWidget = XtCreateWidget (NULL, xmBulletinBoardWidgetClass, |
| 644 |
widget, NULL, 0); |
| 645 |
XtSetArg( wargs[n], XmNmarginHeight, 0 ); n++; |
| 646 |
XtSetArg( wargs[n], XmNmarginWidth, 0 ); n++; |
| 647 |
XtSetArg( wargs[n], XmNx, 0 ); n++; |
| 648 |
XtSetArg( wargs[n], XmNy, 40 ); n++; |
| 649 |
XtSetValues( fileFormatWidget, wargs, n ); |
| 650 |
buildRadioButton( rl.fileFormat, rl.postScript, rl.rgb, |
| 651 |
110, 0, fileFormatWidget, |
| 652 |
(XtCallbackProc) SoXtPrintDialog::fileFormatCB); |
| 653 |
|
| 654 |
// |
| 655 |
// Three subwidgets will contain file specific and printer specific UI. |
| 656 |
// Each will be managed and unmanaged depending on the printerMenu flag. |
| 657 |
// |
| 658 |
buildToPrinterWidget( widget ); |
| 659 |
buildToPostScriptFileWidget( widget ); |
| 660 |
buildToRGBFileWidget( widget ); |
| 661 |
setPrintSize(printSize); |
| 662 |
setPrintSize(printRes); |
| 663 |
XtSetArg( wargs[0], XmNx, 0 ); |
| 664 |
XtSetArg( wargs[1], XmNy, 40 ); |
| 665 |
XtSetValues( toPrinterWidget, wargs, 2 ); |
| 666 |
XtSetArg( wargs[0], XmNx, 0 ); |
| 667 |
XtSetArg( wargs[1], XmNy, 40 ); |
| 668 |
XtSetValues( toPostScriptFileWidget, wargs, 2 ); |
| 669 |
XtSetValues( toRGBFileWidget, wargs, 2 ); |
| 670 |
if (printerOutput) |
| 671 |
XtManageChild( toPrinterWidget ); |
| 672 |
else if (postScriptOutput) |
| 673 |
XtManageChild( toPostScriptFileWidget ); |
| 674 |
else |
| 675 |
XtManageChild( toRGBFileWidget ); |
| 676 |
|
| 677 |
// |
| 678 |
// Place the quit, print, and message textports |
| 679 |
// |
| 680 |
placeBottomOfDialog( this ); |
| 681 |
|
| 682 |
return widget; |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
/////////////////////////////////////////////////////////////////////// |
| 688 |
// |
| 689 |
// Description: |
| 690 |
// This builds the toPrinterWidget widget. |
| 691 |
// |
| 692 |
// Use: protected |
| 693 |
|
| 694 |
void |
| 695 |
SoXtPrintDialog::buildToPrinterWidget( Widget parent ) |
| 696 |
|
| 697 |
// |
| 698 |
////////////////////////////////////////////////////////////////////// |
| 699 |
{ |
| 700 |
XmString labelMsg; |
| 701 |
Widget list, label; |
| 702 |
Arg wargs[16]; |
| 703 |
int i, n; |
| 704 |
|
| 705 |
toPrinterWidget = XtCreateManagedWidget (getWidgetName(), |
| 706 |
xmBulletinBoardWidgetClass, parent, NULL, 0); |
| 707 |
n = 0; |
| 708 |
XtSetArg( wargs[n], XmNmarginHeight, 0 ); n++; |
| 709 |
XtSetArg( wargs[n], XmNmarginWidth, 0 ); n++; |
| 710 |
XtSetValues( toPrinterWidget, wargs, n ); |
| 711 |
|
| 712 |
// Build radio buttons for the Print Quality and Page Format |
| 713 |
buildRadioButton( rl.printQuality, rl.high, rl.draft, 110, 0, |
| 714 |
toPrinterWidget, (XtCallbackProc) SoXtPrintDialog::qualityCB); |
| 715 |
buildRadioButton( rl.pageFormat, rl.portrait, rl.landscape, 110, 30, |
| 716 |
toPrinterWidget, (XtCallbackProc) SoXtPrintDialog::pageFormatCB); |
| 717 |
|
| 718 |
// Build the fields for entering the Print Size |
| 719 |
buildSizeFields( rl.printSize, 60, toPrinterWidget, |
| 720 |
printerHorizSize, printerVertSize, |
| 721 |
(XtCallbackProc) SoXtPrintDialog::printerHorizSizeCB, |
| 722 |
(XtCallbackProc) SoXtPrintDialog::printerVertSizeCB ); |
| 723 |
|
| 724 |
// |
| 725 |
// Create the list of printer names |
| 726 |
// |
| 727 |
n = 0; |
| 728 |
labelMsg = XmStringCreate ( rl.printer, XmSTRING_DEFAULT_CHARSET); |
| 729 |
XtSetArg( wargs[n], XmNy, 90 ); n++; |
| 730 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 731 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 732 |
toPrinterWidget, wargs, n); |
| 733 |
XmStringFree(labelMsg); |
| 734 |
|
| 735 |
n = 0; |
| 736 |
XtSetArg( wargs[n], XmNx, 110 ); n++; |
| 737 |
XtSetArg( wargs[n], XmNy, 90 ); n++; |
| 738 |
XtSetArg( wargs[n], XmNwidth, 220 ); n++; |
| 739 |
XtSetArg( wargs[n], XmNheight, 100 ); n++; |
| 740 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 741 |
XtSetArg( wargs[n], XmNselectionPolicy, XmSINGLE_SELECT); n++; |
| 742 |
list = XmCreateScrolledList(toPrinterWidget, "printerList", wargs, n); |
| 743 |
XtAddCallback(list, |
| 744 |
XmNsingleSelectionCallback, |
| 745 |
(XtCallbackProc) SoXtPrintDialog::listPick, |
| 746 |
(XtPointer) this); |
| 747 |
XtManageChild (list); |
| 748 |
|
| 749 |
// fill the list with printer names |
| 750 |
whichPrinter = -1; |
| 751 |
for (i = 0; i < printers->getLength(); i++) |
| 752 |
{ |
| 753 |
XmString listItem = XmStringCreate (PRINTER_NAME(i), |
| 754 |
XmSTRING_DEFAULT_CHARSET); |
| 755 |
XmListAddItemUnselected (list, listItem, 0); |
| 756 |
XmStringFree(listItem); // XmList made a copy |
| 757 |
|
| 758 |
// if this is the default, then select it. (list count starts at 1) |
| 759 |
if (strcmp(PRINTER_NAME(i), defaultPrinter) == 0) { |
| 760 |
XmListSelectPos (list, i+1, FALSE); |
| 761 |
whichPrinter = i; |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
// Build the field for entering the DPI |
| 766 |
buildDPIField( 120, toPrinterWidget, printerDPIField, |
| 767 |
(XtCallbackProc) SoXtPrintDialog::printerDPICB ); |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
/////////////////////////////////////////////////////////////////////// |
| 773 |
// |
| 774 |
// Description: |
| 775 |
// This builds the toPostScriptFileWidget widget. |
| 776 |
// |
| 777 |
// Use: protected |
| 778 |
|
| 779 |
void |
| 780 |
SoXtPrintDialog::buildToPostScriptFileWidget( Widget parent ) |
| 781 |
|
| 782 |
// |
| 783 |
////////////////////////////////////////////////////////////////////// |
| 784 |
{ |
| 785 |
XmString labelMsg; |
| 786 |
Widget label; |
| 787 |
Arg wargs[4]; |
| 788 |
int n; |
| 789 |
|
| 790 |
n = 0; |
| 791 |
toPostScriptFileWidget = XtCreateWidget (NULL, xmBulletinBoardWidgetClass, |
| 792 |
parent, NULL, 0); |
| 793 |
XtSetArg( wargs[n], XmNmarginHeight, 0 ); n++; |
| 794 |
XtSetArg( wargs[n], XmNmarginWidth, 0 ); n++; |
| 795 |
XtSetValues( toPostScriptFileWidget, wargs, n ); |
| 796 |
|
| 797 |
// Build radio buttons for the Print Quality |
| 798 |
buildRadioButton( rl.printQuality, rl.high, rl.draft, 110, 30, |
| 799 |
toPostScriptFileWidget, |
| 800 |
(XtCallbackProc) SoXtPrintDialog::qualityCB); |
| 801 |
|
| 802 |
// Build the fields for entering the Print Size |
| 803 |
buildSizeFields( rl.printSize, 60, toPostScriptFileWidget, |
| 804 |
postScriptHorizSize, postScriptVertSize, |
| 805 |
(XtCallbackProc) SoXtPrintDialog::postScriptHorizSizeCB, |
| 806 |
(XtCallbackProc) SoXtPrintDialog::postScriptVertSizeCB ); |
| 807 |
|
| 808 |
// |
| 809 |
// Create the FileName label and textport. |
| 810 |
// |
| 811 |
n = 0; |
| 812 |
labelMsg = XmStringCreate (rl.fileName, XmSTRING_DEFAULT_CHARSET); |
| 813 |
XtSetArg( wargs[n], XmNy, 90 ); n++; |
| 814 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 815 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 816 |
toPostScriptFileWidget, wargs, n); |
| 817 |
XmStringFree(labelMsg); |
| 818 |
|
| 819 |
n = 0; |
| 820 |
XtSetArg( wargs[n], XmNx, 100 ); n++; |
| 821 |
XtSetArg( wargs[n], XmNy, 90 ); n++; |
| 822 |
XtSetArg( wargs[n], XmNwidth, 230 ); n++; |
| 823 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 824 |
postScriptFilenameWidget = XtCreateManagedWidget (NULL, xmTextWidgetClass, |
| 825 |
toPostScriptFileWidget, wargs, n); |
| 826 |
// Build the field for entering the DPI |
| 827 |
buildDPIField( 130, toPostScriptFileWidget, postScriptDPIField, |
| 828 |
(XtCallbackProc) SoXtPrintDialog::postScriptDPICB ); |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
/////////////////////////////////////////////////////////////////////// |
| 834 |
// |
| 835 |
// Description: |
| 836 |
// This builds the toRGBFileWidget widget. |
| 837 |
// |
| 838 |
// Use: protected |
| 839 |
|
| 840 |
void |
| 841 |
SoXtPrintDialog::buildToRGBFileWidget( Widget parent ) |
| 842 |
|
| 843 |
// |
| 844 |
////////////////////////////////////////////////////////////////////// |
| 845 |
{ |
| 846 |
XmString labelMsg; |
| 847 |
Widget label; |
| 848 |
Arg wargs[4]; |
| 849 |
int n; |
| 850 |
|
| 851 |
n = 0; |
| 852 |
toRGBFileWidget = XtCreateWidget (NULL, xmBulletinBoardWidgetClass, |
| 853 |
parent, NULL, 0); |
| 854 |
XtSetArg( wargs[n], XmNmarginHeight, 0 ); n++; |
| 855 |
XtSetArg( wargs[n], XmNmarginWidth, 0 ); n++; |
| 856 |
XtSetValues( toRGBFileWidget, wargs, n ); |
| 857 |
|
| 858 |
// Build radio buttons for the Print Quality |
| 859 |
buildRadioButton( rl.fileFormat, rl.postScript, rl.rgb, 110, 0, |
| 860 |
toRGBFileWidget, |
| 861 |
(XtCallbackProc) SoXtPrintDialog::fileFormatCB); |
| 862 |
|
| 863 |
// Build the fields for entering the Print Size |
| 864 |
buildSizeFields( rl.resolution, 30, toRGBFileWidget, |
| 865 |
rgbHorizSize, rgbVertSize, |
| 866 |
(XtCallbackProc) SoXtPrintDialog::rgbHorizSizeCB, |
| 867 |
(XtCallbackProc) SoXtPrintDialog::rgbVertSizeCB ); |
| 868 |
|
| 869 |
// Initialize the horizontal and vertical size textports |
| 870 |
char tc[8]; |
| 871 |
sprintf(tc, "%d", printRes[0]); |
| 872 |
XmTextSetString (rgbHorizSize, tc); |
| 873 |
sprintf(tc, "%d", printRes[1]); |
| 874 |
XmTextSetString (rgbVertSize, tc); |
| 875 |
|
| 876 |
// Create the FileName label and textport. |
| 877 |
n = 0; |
| 878 |
labelMsg = XmStringCreate (rl.fileName, XmSTRING_DEFAULT_CHARSET); |
| 879 |
XtSetArg( wargs[n], XmNy, 60 ); n++; |
| 880 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 881 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 882 |
toRGBFileWidget, wargs, n); |
| 883 |
XmStringFree(labelMsg); |
| 884 |
|
| 885 |
n = 0; |
| 886 |
XtSetArg( wargs[n], XmNx, 100 ); n++; |
| 887 |
XtSetArg( wargs[n], XmNy, 60 ); n++; |
| 888 |
XtSetArg( wargs[n], XmNwidth, 230 ); n++; |
| 889 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 890 |
rgbFilenameWidget = XtCreateManagedWidget (NULL, xmTextWidgetClass, |
| 891 |
toRGBFileWidget, wargs, n); |
| 892 |
} |
| 893 |
|
| 894 |
/////////////////////////////////////////////////////////////////////// |
| 895 |
// |
| 896 |
// Description: |
| 897 |
// This builds a Radio Button. |
| 898 |
// |
| 899 |
// Use: protected |
| 900 |
|
| 901 |
void |
| 902 |
SoXtPrintDialog::buildRadioButton( |
| 903 |
char *title, |
| 904 |
char *label1, |
| 905 |
char *label2, |
| 906 |
int horizontalPlacement, |
| 907 |
int verticalPlacement, |
| 908 |
Widget parent, |
| 909 |
XtCallbackProc cb ) |
| 910 |
|
| 911 |
// |
| 912 |
////////////////////////////////////////////////////////////////////// |
| 913 |
{ |
| 914 |
XmString labelMsg; |
| 915 |
Widget buttons, b, label; |
| 916 |
Arg wargs[4]; |
| 917 |
int n; |
| 918 |
|
| 919 |
// |
| 920 |
// Create the Radio Button. It is a horizontal RowColumn widget |
| 921 |
// composed of a label widget and a RadioBox widget. |
| 922 |
// |
| 923 |
n = 0; |
| 924 |
labelMsg = XmStringCreate( title, XmSTRING_DEFAULT_CHARSET); |
| 925 |
XtSetArg( wargs[n], XmNx, 0 ); n++; |
| 926 |
XtSetArg( wargs[n], XmNy, verticalPlacement ); n++; |
| 927 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 928 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 929 |
parent, wargs, n); |
| 930 |
XmStringFree(labelMsg); |
| 931 |
|
| 932 |
n = 0; |
| 933 |
XtSetArg( wargs[n], XmNx, horizontalPlacement ); n++; |
| 934 |
XtSetArg( wargs[n], XmNy, verticalPlacement ); n++; |
| 935 |
XtSetArg( wargs[n], XmNorientation, XmHORIZONTAL ); n++; |
| 936 |
XtSetArg( wargs[n], XmNpacking, XmPACK_NONE ); n++; |
| 937 |
buttons = XmCreateRadioBox(parent, "radioToggles", wargs, n); |
| 938 |
XtManageChild (buttons); |
| 939 |
|
| 940 |
n = 0; |
| 941 |
labelMsg = XmStringCreate (label1, XmSTRING_DEFAULT_CHARSET); |
| 942 |
XtSetArg( wargs[n], XmNset, TRUE ); n++; |
| 943 |
XtSetArg( wargs[n], XmNx, 10 ); n++; |
| 944 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 945 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 946 |
b = XtCreateManagedWidget("radioButton1", xmToggleButtonWidgetClass, |
| 947 |
buttons, wargs, n); |
| 948 |
XtAddCallback (b, XmNvalueChangedCallback, cb, (XtPointer)(this)); |
| 949 |
XmStringFree(labelMsg); |
| 950 |
|
| 951 |
n = 0; |
| 952 |
labelMsg = XmStringCreate (label2, XmSTRING_DEFAULT_CHARSET); |
| 953 |
XtSetArg( wargs[n], XmNx, 100 ); n++; |
| 954 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 955 |
XtSetArg( wargs[n], XmNhighlightThickness, 0 ); n++; |
| 956 |
b = XtCreateManagedWidget("radioButton2", xmToggleButtonWidgetClass, |
| 957 |
buttons, wargs, n); |
| 958 |
XmStringFree(labelMsg); |
| 959 |
} |
| 960 |
|
| 961 |
/////////////////////////////////////////////////////////////////////// |
| 962 |
// |
| 963 |
// Description: |
| 964 |
// This builds a set of two text fields for entering horizontal |
| 965 |
// and vertical sizes. |
| 966 |
// |
| 967 |
// Use: protected |
| 968 |
|
| 969 |
void |
| 970 |
SoXtPrintDialog::buildSizeFields( |
| 971 |
char *title, |
| 972 |
int verticalPlacement, |
| 973 |
Widget parent, |
| 974 |
Widget &horizField, |
| 975 |
Widget &vertField, |
| 976 |
XtCallbackProc cb1, |
| 977 |
XtCallbackProc cb2 ) |
| 978 |
|
| 979 |
// |
| 980 |
////////////////////////////////////////////////////////////////////// |
| 981 |
{ |
| 982 |
XmString labelMsg; |
| 983 |
Widget label; |
| 984 |
Arg wargs[4]; |
| 985 |
int n; |
| 986 |
|
| 987 |
// |
| 988 |
// Create the Print Size row. It is a label with two text widgets |
| 989 |
// for the horizontal and vertical sizes of the print. |
| 990 |
// |
| 991 |
n = 0; |
| 992 |
labelMsg = XmStringCreate (title, XmSTRING_DEFAULT_CHARSET); |
| 993 |
XtSetArg( wargs[n], XmNy, verticalPlacement ); n++; |
| 994 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 995 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 996 |
parent, wargs, n); |
| 997 |
XmStringFree(labelMsg); |
| 998 |
|
| 999 |
n = 0; |
| 1000 |
XtSetArg( wargs[n], XmNx, 150 ); n++; |
| 1001 |
XtSetArg( wargs[n], XmNy, verticalPlacement-3 ); n++; |
| 1002 |
XtSetArg( wargs[n], XmNhighlightThickness, 1); n++; |
| 1003 |
XtSetArg( wargs[n], XmNcolumns, atoi(rl.holzn1)); n++; |
| 1004 |
horizField = XtCreateManagedWidget("horizontalSize", xmTextWidgetClass, |
| 1005 |
parent, wargs, n); |
| 1006 |
if (cb1 != NULL) |
| 1007 |
XtAddCallback(horizField, XmNactivateCallback, cb1, (XtPointer) this); |
| 1008 |
|
| 1009 |
n = 0; |
| 1010 |
labelMsg = XmStringCreate (rl.by, XmSTRING_DEFAULT_CHARSET); |
| 1011 |
XtSetArg( wargs[n], XmNx, 226 ); n++; |
| 1012 |
XtSetArg( wargs[n], XmNy, verticalPlacement ); n++; |
| 1013 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 1014 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 1015 |
parent, wargs, n); |
| 1016 |
XmStringFree(labelMsg); |
| 1017 |
|
| 1018 |
n = 0; |
| 1019 |
XtSetArg( wargs[n], XmNx, 258 ); n++; |
| 1020 |
XtSetArg( wargs[n], XmNy, verticalPlacement-3 ); n++; |
| 1021 |
XtSetArg( wargs[n], XmNhighlightThickness, 1); n++; |
| 1022 |
XtSetArg( wargs[n], XmNcolumns, atoi(rl.vertc1)); n++; |
| 1023 |
vertField = XtCreateManagedWidget("verticalSize", xmTextWidgetClass, |
| 1024 |
parent, wargs, n); |
| 1025 |
if (cb2 != NULL) |
| 1026 |
XtAddCallback(vertField, XmNactivateCallback, cb2, (XtPointer) this); |
| 1027 |
} |
| 1028 |
|
| 1029 |
/////////////////////////////////////////////////////////////////////// |
| 1030 |
// |
| 1031 |
// Description: |
| 1032 |
// This builds a field containing the DPI of the desired print. |
| 1033 |
// |
| 1034 |
// Use: protected |
| 1035 |
|
| 1036 |
void |
| 1037 |
SoXtPrintDialog::buildDPIField( |
| 1038 |
int verticalPlacement, |
| 1039 |
Widget parent, |
| 1040 |
Widget &dpiField, |
| 1041 |
XtCallbackProc cb ) |
| 1042 |
|
| 1043 |
// |
| 1044 |
/////////////////////////////////////////////////////////////////////// |
| 1045 |
{ |
| 1046 |
XmString labelMsg; |
| 1047 |
Widget label; |
| 1048 |
Arg wargs[4]; |
| 1049 |
int n; |
| 1050 |
|
| 1051 |
n = 0; |
| 1052 |
labelMsg = XmStringCreate ( rl.dpi, XmSTRING_DEFAULT_CHARSET); |
| 1053 |
XtSetArg( wargs[n], XmNy, verticalPlacement ); n++; |
| 1054 |
XtSetArg( wargs[n], XmNlabelString, labelMsg ); n++; |
| 1055 |
label = XtCreateManagedWidget (NULL, xmLabelWidgetClass, |
| 1056 |
parent, wargs, n); |
| 1057 |
XmStringFree(labelMsg); |
| 1058 |
|
| 1059 |
n = 0; |
| 1060 |
XtSetArg( wargs[n], XmNx, 40 ); n++; |
| 1061 |
XtSetArg( wargs[n], XmNy, verticalPlacement-3 ); n++; |
| 1062 |
XtSetArg( wargs[n], XmNhighlightThickness, 1); n++; |
| 1063 |
XtSetArg( wargs[n], XmNcolumns, atoi(rl.holzn2)); n++; |
| 1064 |
dpiField = XtCreateManagedWidget("horizontalSize", xmTextWidgetClass, |
| 1065 |
parent, wargs, n); |
| 1066 |
XtAddCallback(dpiField, XmNactivateCallback, cb, (XtPointer) this); |
| 1067 |
XmTextSetString (dpiField, "100"); |
| 1068 |
} |
| 1069 |
|
| 1070 |
/////////////////////////////////////////////////////////////////////// |
| 1071 |
// |
| 1072 |
// Description: |
| 1073 |
// This places the quit and text buttons and the message textport |
| 1074 |
// depending on whether the toFileWidget or toPrinterWidget is |
| 1075 |
// currently being displayed. |
| 1076 |
// |
| 1077 |
// Use: protected |
| 1078 |
|
| 1079 |
void |
| 1080 |
SoXtPrintDialog::placeBottomOfDialog( |
| 1081 |
SoXtPrintDialog *ptr ) |
| 1082 |
|
| 1083 |
// |
| 1084 |
////////////////////////////////////////////////////////////////////// |
| 1085 |
{ |
| 1086 |
Arg wargs[1]; |
| 1087 |
|
| 1088 |
if (ptr->printerOutput) |
| 1089 |
{ |
| 1090 |
XtSetArg( wargs[0], XmNy, 240 ); |
| 1091 |
XtSetValues( ptr->quitButton, wargs, 1 ); |
| 1092 |
XtSetValues( ptr->printButton, wargs, 1 ); |
| 1093 |
|
| 1094 |
XtSetArg( wargs[0], XmNy, 260 ); |
| 1095 |
XtSetValues( ptr->messageLabelWidget, wargs, 1 ); |
| 1096 |
XtSetArg( wargs[0], XmNy, 280 ); |
| 1097 |
XtSetValues( ptr->messageWidget, wargs, 1 ); |
| 1098 |
} |
| 1099 |
else if (ptr->postScriptOutput) |
| 1100 |
{ |
| 1101 |
XtSetArg( wargs[0], XmNy, 205 ); |
| 1102 |
XtSetValues( ptr->messageLabelWidget, wargs, 1 ); |
| 1103 |
XtSetArg( wargs[0], XmNy, 225 ); |
| 1104 |
XtSetValues( ptr->messageWidget, wargs, 1 ); |
| 1105 |
XtSetArg( wargs[0], XmNy, 175 ); |
| 1106 |
XtSetValues( ptr->quitButton, wargs, 1 ); |
| 1107 |
XtSetValues( ptr->printButton, wargs, 1 ); |
| 1108 |
} |
| 1109 |
else |
| 1110 |
{ |
| 1111 |
XtSetArg( wargs[0], XmNy, 150 ); |
| 1112 |
XtSetValues( ptr->messageLabelWidget, wargs, 1 ); |
| 1113 |
XtSetArg( wargs[0], XmNy, 170 ); |
| 1114 |
XtSetValues( ptr->messageWidget, wargs, 1 ); |
| 1115 |
XtSetArg( wargs[0], XmNy, 135 ); |
| 1116 |
XtSetValues( ptr->quitButton, wargs, 1 ); |
| 1117 |
XtSetValues( ptr->printButton, wargs, 1 ); |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
/////////////////////////////////////////////////////////////////////// |
| 1122 |
// |
| 1123 |
// Description: |
| 1124 |
// This routine is called when a Print Quality radio button is pressed. |
| 1125 |
// |
| 1126 |
// Use: private |
| 1127 |
|
| 1128 |
void |
| 1129 |
SoXtPrintDialog::qualityCB( |
| 1130 |
Widget, |
| 1131 |
SoXtPrintDialog *ptr, |
| 1132 |
XmAnyCallbackStruct *) |
| 1133 |
// |
| 1134 |
////////////////////////////////////////////////////////////////////// |
| 1135 |
{ |
| 1136 |
ptr->highQuality = (ptr->highQuality) ? FALSE : TRUE; |
| 1137 |
} |
| 1138 |
|
| 1139 |
/////////////////////////////////////////////////////////////////////// |
| 1140 |
// |
| 1141 |
// Description: |
| 1142 |
// This routine is called when a Page Format radio button is pressed. |
| 1143 |
// |
| 1144 |
// Use: private |
| 1145 |
|
| 1146 |
void |
| 1147 |
SoXtPrintDialog::pageFormatCB( |
| 1148 |
Widget, |
| 1149 |
SoXtPrintDialog *ptr, |
| 1150 |
XmAnyCallbackStruct *) |
| 1151 |
// |
| 1152 |
////////////////////////////////////////////////////////////////////// |
| 1153 |
{ |
| 1154 |
ptr->portraitFormat = (ptr->portraitFormat) ? FALSE : TRUE; |
| 1155 |
} |
| 1156 |
|
| 1157 |
/////////////////////////////////////////////////////////////////////// |
| 1158 |
// |
| 1159 |
// Description: |
| 1160 |
// This routine is called when the rgb horizontal size field |
| 1161 |
// is modified. |
| 1162 |
// |
| 1163 |
// Use: private |
| 1164 |
|
| 1165 |
void |
| 1166 |
SoXtPrintDialog::rgbHorizSizeCB( |
| 1167 |
Widget, |
| 1168 |
SoXtPrintDialog *ptr, |
| 1169 |
XmAnyCallbackStruct *) |
| 1170 |
// |
| 1171 |
////////////////////////////////////////////////////////////////////// |
| 1172 |
{ |
| 1173 |
if (ptr->alreadyUpdated) |
| 1174 |
return; |
| 1175 |
|
| 1176 |
char *text = XmTextGetString (ptr->rgbHorizSize); |
| 1177 |
short x = (short)atoi(text); |
| 1178 |
XtFree(text); |
| 1179 |
text = XmTextGetString (ptr->rgbVertSize); |
| 1180 |
short y = (short)atoi(text); |
| 1181 |
XtFree(text); |
| 1182 |
ptr->setPrintSize(SbVec2s(x, y)); |
| 1183 |
|
| 1184 |
// make the text field loose the focus |
| 1185 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1186 |
XmTRAVERSE_CURRENT); |
| 1187 |
} |
| 1188 |
|
| 1189 |
/////////////////////////////////////////////////////////////////////// |
| 1190 |
// |
| 1191 |
// Description: |
| 1192 |
// This routine is called when the printer vertical size field |
| 1193 |
// is modified. |
| 1194 |
// |
| 1195 |
// Use: private |
| 1196 |
|
| 1197 |
void |
| 1198 |
SoXtPrintDialog::rgbVertSizeCB( |
| 1199 |
Widget, |
| 1200 |
SoXtPrintDialog *ptr, |
| 1201 |
XmAnyCallbackStruct *) |
| 1202 |
// |
| 1203 |
////////////////////////////////////////////////////////////////////// |
| 1204 |
{ |
| 1205 |
if (ptr->alreadyUpdated) |
| 1206 |
return; |
| 1207 |
|
| 1208 |
char *text = XmTextGetString (ptr->rgbHorizSize); |
| 1209 |
short x = (short)atoi(text); |
| 1210 |
XtFree(text); |
| 1211 |
text = XmTextGetString (ptr->rgbVertSize); |
| 1212 |
short y = (short)atoi(text); |
| 1213 |
XtFree(text); |
| 1214 |
ptr->setPrintSize(SbVec2s(x, y)); |
| 1215 |
|
| 1216 |
// make the text field loose the focus |
| 1217 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1218 |
XmTRAVERSE_CURRENT); |
| 1219 |
} |
| 1220 |
|
| 1221 |
/////////////////////////////////////////////////////////////////////// |
| 1222 |
// |
| 1223 |
// Description: |
| 1224 |
// This routine is called when the printer horizontal size field |
| 1225 |
// is modified. |
| 1226 |
// |
| 1227 |
// Use: private |
| 1228 |
|
| 1229 |
void |
| 1230 |
SoXtPrintDialog::printerHorizSizeCB( |
| 1231 |
Widget, |
| 1232 |
SoXtPrintDialog *ptr, |
| 1233 |
XmAnyCallbackStruct *) |
| 1234 |
// |
| 1235 |
////////////////////////////////////////////////////////////////////// |
| 1236 |
{ |
| 1237 |
if (ptr->alreadyUpdated) |
| 1238 |
return; |
| 1239 |
|
| 1240 |
char *text = XmTextGetString (ptr->printerHorizSize); |
| 1241 |
float x = atof(text); |
| 1242 |
XtFree(text); |
| 1243 |
text = XmTextGetString (ptr->printerVertSize); |
| 1244 |
float y = atof(text); |
| 1245 |
XtFree(text); |
| 1246 |
ptr->setPrintSize(SbVec2f(x, y)); |
| 1247 |
|
| 1248 |
// make the text field loose the focus |
| 1249 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1250 |
XmTRAVERSE_CURRENT); |
| 1251 |
} |
| 1252 |
|
| 1253 |
/////////////////////////////////////////////////////////////////////// |
| 1254 |
// |
| 1255 |
// Description: |
| 1256 |
// This routine is called when the printer vertical size field |
| 1257 |
// is modified. |
| 1258 |
// |
| 1259 |
// Use: private |
| 1260 |
|
| 1261 |
void |
| 1262 |
SoXtPrintDialog::printerVertSizeCB( |
| 1263 |
Widget, |
| 1264 |
SoXtPrintDialog *ptr, |
| 1265 |
XmAnyCallbackStruct *) |
| 1266 |
// |
| 1267 |
////////////////////////////////////////////////////////////////////// |
| 1268 |
{ |
| 1269 |
if (ptr->alreadyUpdated) |
| 1270 |
return; |
| 1271 |
|
| 1272 |
char *text = XmTextGetString (ptr->printerHorizSize); |
| 1273 |
float x = atof(text); |
| 1274 |
XtFree(text); |
| 1275 |
text = XmTextGetString (ptr->printerVertSize); |
| 1276 |
float y = atof(text); |
| 1277 |
XtFree(text); |
| 1278 |
ptr->setPrintSize(SbVec2f(x, y)); |
| 1279 |
|
| 1280 |
// make the text field loose the focus |
| 1281 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1282 |
XmTRAVERSE_CURRENT); |
| 1283 |
} |
| 1284 |
|
| 1285 |
/////////////////////////////////////////////////////////////////////// |
| 1286 |
// |
| 1287 |
// Description: |
| 1288 |
// This routine is called when the PostScript horizontal size field |
| 1289 |
// is modified. |
| 1290 |
// |
| 1291 |
// Use: private |
| 1292 |
|
| 1293 |
void |
| 1294 |
SoXtPrintDialog::postScriptHorizSizeCB( |
| 1295 |
Widget, |
| 1296 |
SoXtPrintDialog *ptr, |
| 1297 |
XmAnyCallbackStruct *) |
| 1298 |
// |
| 1299 |
////////////////////////////////////////////////////////////////////// |
| 1300 |
{ |
| 1301 |
if (ptr->alreadyUpdated) |
| 1302 |
return; |
| 1303 |
|
| 1304 |
char *text = XmTextGetString (ptr->postScriptHorizSize); |
| 1305 |
float x = atof(text); |
| 1306 |
XtFree(text); |
| 1307 |
text = XmTextGetString (ptr->postScriptVertSize); |
| 1308 |
float y = atof(text); |
| 1309 |
XtFree(text); |
| 1310 |
ptr->setPrintSize(SbVec2f(x, y)); |
| 1311 |
|
| 1312 |
// make the text field loose the focus |
| 1313 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1314 |
XmTRAVERSE_CURRENT); |
| 1315 |
} |
| 1316 |
|
| 1317 |
/////////////////////////////////////////////////////////////////////// |
| 1318 |
// |
| 1319 |
// Description: |
| 1320 |
// This routine is called when the PostScript vertical size field |
| 1321 |
// is modified. |
| 1322 |
// |
| 1323 |
// Use: private |
| 1324 |
|
| 1325 |
void |
| 1326 |
SoXtPrintDialog::postScriptVertSizeCB( |
| 1327 |
Widget, |
| 1328 |
SoXtPrintDialog *ptr, |
| 1329 |
XmAnyCallbackStruct *) |
| 1330 |
// |
| 1331 |
////////////////////////////////////////////////////////////////////// |
| 1332 |
{ |
| 1333 |
if (ptr->alreadyUpdated) |
| 1334 |
return; |
| 1335 |
|
| 1336 |
char *text = XmTextGetString (ptr->postScriptHorizSize); |
| 1337 |
float x = atof(text); |
| 1338 |
XtFree(text); |
| 1339 |
text = XmTextGetString (ptr->postScriptVertSize); |
| 1340 |
float y = atof(text); |
| 1341 |
XtFree(text); |
| 1342 |
ptr->setPrintSize(SbVec2f(x, y)); |
| 1343 |
|
| 1344 |
// make the text field loose the focus |
| 1345 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1346 |
XmTRAVERSE_CURRENT); |
| 1347 |
} |
| 1348 |
|
| 1349 |
/////////////////////////////////////////////////////////////////////// |
| 1350 |
// |
| 1351 |
// Description: |
| 1352 |
// This routine is called when the printer DPI field |
| 1353 |
// is modified. |
| 1354 |
// |
| 1355 |
// Use: private |
| 1356 |
|
| 1357 |
void |
| 1358 |
SoXtPrintDialog::printerDPICB( |
| 1359 |
Widget, |
| 1360 |
SoXtPrintDialog *ptr, |
| 1361 |
XmAnyCallbackStruct *) |
| 1362 |
// |
| 1363 |
////////////////////////////////////////////////////////////////////// |
| 1364 |
{ |
| 1365 |
if (ptr->alreadyUpdated) { |
| 1366 |
ptr->alreadyUpdated = FALSE; |
| 1367 |
return; |
| 1368 |
} |
| 1369 |
ptr->alreadyUpdated = TRUE; |
| 1370 |
char *text = XmTextGetString (ptr->printerDPIField); |
| 1371 |
XmTextSetString (ptr->postScriptDPIField, text); |
| 1372 |
XtFree(text); |
| 1373 |
|
| 1374 |
// make the text field loose the focus |
| 1375 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1376 |
XmTRAVERSE_CURRENT); |
| 1377 |
} |
| 1378 |
|
| 1379 |
/////////////////////////////////////////////////////////////////////// |
| 1380 |
// |
| 1381 |
// Description: |
| 1382 |
// This routine is called when the PostScript DPI field |
| 1383 |
// is modified. |
| 1384 |
// |
| 1385 |
// Use: private |
| 1386 |
|
| 1387 |
void |
| 1388 |
SoXtPrintDialog::postScriptDPICB( |
| 1389 |
Widget, |
| 1390 |
SoXtPrintDialog *ptr, |
| 1391 |
XmAnyCallbackStruct *) |
| 1392 |
// |
| 1393 |
////////////////////////////////////////////////////////////////////// |
| 1394 |
{ |
| 1395 |
if (ptr->alreadyUpdated) { |
| 1396 |
ptr->alreadyUpdated = FALSE; |
| 1397 |
return; |
| 1398 |
} |
| 1399 |
ptr->alreadyUpdated = TRUE; |
| 1400 |
char *text = XmTextGetString (ptr->postScriptDPIField); |
| 1401 |
XmTextSetString (ptr->printerDPIField, text); |
| 1402 |
XtFree(text); |
| 1403 |
|
| 1404 |
// make the text field loose the focus |
| 1405 |
XmProcessTraversal(SoXt::getShellWidget(ptr->getWidget()), |
| 1406 |
XmTRAVERSE_CURRENT); |
| 1407 |
} |
| 1408 |
|
| 1409 |
/////////////////////////////////////////////////////////////////////// |
| 1410 |
// |
| 1411 |
// Description: |
| 1412 |
// This routine is called when an Output radio button is pressed. |
| 1413 |
// |
| 1414 |
// Use: private |
| 1415 |
|
| 1416 |
void |
| 1417 |
SoXtPrintDialog::outputCB( |
| 1418 |
Widget, |
| 1419 |
SoXtPrintDialog *ptr, |
| 1420 |
XmAnyCallbackStruct *) |
| 1421 |
// |
| 1422 |
////////////////////////////////////////////////////////////////////// |
| 1423 |
{ |
| 1424 |
short height; |
| 1425 |
|
| 1426 |
ptr->printerOutput = (ptr->printerOutput) ? FALSE : TRUE; |
| 1427 |
|
| 1428 |
// |
| 1429 |
// Display the correct portion of the dialog and adjust the bottom |
| 1430 |
// of the dialog. |
| 1431 |
// |
| 1432 |
if (ptr->printerOutput) |
| 1433 |
{ |
| 1434 |
XtUnmanageChild( ptr->fileFormatWidget ); |
| 1435 |
if (ptr->postScriptOutput) |
| 1436 |
XtUnmanageChild( ptr->toRGBFileWidget ); |
| 1437 |
else |
| 1438 |
XtUnmanageChild( ptr->toPostScriptFileWidget ); |
| 1439 |
XtManageChild( ptr->toPrinterWidget ); |
| 1440 |
height = PRINTER_MENU_HEIGHT; |
| 1441 |
} |
| 1442 |
else if (ptr->postScriptOutput) |
| 1443 |
{ |
| 1444 |
XtUnmanageChild( ptr->toPrinterWidget ); |
| 1445 |
XtManageChild( ptr->fileFormatWidget ); |
| 1446 |
XtManageChild( ptr->toPostScriptFileWidget ); |
| 1447 |
height = POSTSCRIPT_FILE_MENU_HEIGHT; |
| 1448 |
} |
| 1449 |
else |
| 1450 |
{ |
| 1451 |
XtUnmanageChild( ptr->toPrinterWidget ); |
| 1452 |
XtManageChild( ptr->fileFormatWidget ); |
| 1453 |
XtManageChild( ptr->toRGBFileWidget ); |
| 1454 |
height = RGB_FILE_MENU_HEIGHT; |
| 1455 |
} |
| 1456 |
|
| 1457 |
// |
| 1458 |
// check if window needs to be resized |
| 1459 |
// |
| 1460 |
if (ptr->isTopLevelShell()) { |
| 1461 |
|
| 1462 |
// get current window height and set the new height |
| 1463 |
SbVec2s size = ptr->getSize(); |
| 1464 |
size[1] = height; |
| 1465 |
ptr->setSize(size); |
| 1466 |
} |
| 1467 |
|
| 1468 |
ptr->placeBottomOfDialog( ptr ); |
| 1469 |
} |
| 1470 |
|
| 1471 |
/////////////////////////////////////////////////////////////////////// |
| 1472 |
// |
| 1473 |
// Description: |
| 1474 |
// This routine is called when an Output radio button is pressed. |
| 1475 |
// |
| 1476 |
// Use: private |
| 1477 |
|
| 1478 |
void |
| 1479 |
SoXtPrintDialog::fileFormatCB( |
| 1480 |
Widget, |
| 1481 |
SoXtPrintDialog *ptr, |
| 1482 |
XmAnyCallbackStruct *) |
| 1483 |
// |
| 1484 |
////////////////////////////////////////////////////////////////////// |
| 1485 |
{ |
| 1486 |
short height; |
| 1487 |
|
| 1488 |
ptr->postScriptOutput = (ptr->postScriptOutput) ? FALSE : TRUE; |
| 1489 |
|
| 1490 |
// |
| 1491 |
// Display the correct portion of the dialog and adjust the bottom |
| 1492 |
// of the dialog. |
| 1493 |
// |
| 1494 |
if (ptr->postScriptOutput) |
| 1495 |
{ |
| 1496 |
XtUnmanageChild( ptr->toRGBFileWidget ); |
| 1497 |
XtManageChild( ptr->toPostScriptFileWidget ); |
| 1498 |
height = POSTSCRIPT_FILE_MENU_HEIGHT; |
| 1499 |
} |
| 1500 |
else |
| 1501 |
{ |
| 1502 |
XtUnmanageChild( ptr->toPostScriptFileWidget ); |
| 1503 |
XtManageChild( ptr->toRGBFileWidget ); |
| 1504 |
height = RGB_FILE_MENU_HEIGHT; |
| 1505 |
} |
| 1506 |
|
| 1507 |
// |
| 1508 |
// check if window needs to be resized |
| 1509 |
// |
| 1510 |
if (ptr->isTopLevelShell()) { |
| 1511 |
|
| 1512 |
// get current window height and set the new height |
| 1513 |
SbVec2s size = ptr->getSize(); |
| 1514 |
size[1] = height; |
| 1515 |
ptr->setSize(size); |
| 1516 |
} |
| 1517 |
|
| 1518 |
ptr->placeBottomOfDialog( ptr ); |
| 1519 |
} |
| 1520 |
|
| 1521 |
/////////////////////////////////////////////////////////////////////// |
| 1522 |
// |
| 1523 |
// Description: |
| 1524 |
// This callback is invoked when the Quit button is pressed. |
| 1525 |
// |
| 1526 |
// Use: private |
| 1527 |
|
| 1528 |
void |
| 1529 |
SoXtPrintDialog::quitCB( |
| 1530 |
Widget, |
| 1531 |
SoXtPrintDialog *ptr, |
| 1532 |
XmAnyCallbackStruct *) |
| 1533 |
// |
| 1534 |
////////////////////////////////////////////////////////////////////// |
| 1535 |
{ |
| 1536 |
ptr->hide(); |
| 1537 |
} |
| 1538 |
|
| 1539 |
//////////////////////////////////////////////////////////////////////// |
| 1540 |
// |
| 1541 |
// Called by Xt when a list item is picked. |
| 1542 |
// |
| 1543 |
// Use: static private |
| 1544 |
// |
| 1545 |
void |
| 1546 |
SoXtPrintDialog::listPick( |
| 1547 |
Widget, |
| 1548 |
SoXtPrintDialog *ptr, |
| 1549 |
XmAnyCallbackStruct *list) |
| 1550 |
// |
| 1551 |
//////////////////////////////////////////////////////////////////////// |
| 1552 |
{ |
| 1553 |
// our array is indexed from 0, the list is indexed from 1 |
| 1554 |
ptr->whichPrinter = ((XmListCallbackStruct *) list)->item_position - 1; |
| 1555 |
} |
| 1556 |
|
| 1557 |
/////////////////////////////////////////////////////////////////////// |
| 1558 |
// |
| 1559 |
// Description: |
| 1560 |
// This routine is called when the Print button of the SoXtPrintDialog |
| 1561 |
// widget is pressed. It gets the current text string from the |
| 1562 |
// textWidget and uses it as the filename into which to write |
| 1563 |
// the PostScript output data. (This is called by the printCallback()) |
| 1564 |
// |
| 1565 |
// Use: private |
| 1566 |
|
| 1567 |
void |
| 1568 |
SoXtPrintDialog::print() |
| 1569 |
// |
| 1570 |
////////////////////////////////////////////////////////////////////// |
| 1571 |
{ |
| 1572 |
SoOutput outFile; |
| 1573 |
FILE *fileP = NULL; |
| 1574 |
char *printerName; |
| 1575 |
char tempPSFileName[64]; |
| 1576 |
char *text; |
| 1577 |
char *fileName = NULL; |
| 1578 |
SbColor bgColor(0.0, 0.0, 0.0); |
| 1579 |
SoOffscreenRenderer *renderer; |
| 1580 |
|
| 1581 |
XmTextSetString (messageWidget, "Printing in progress..."); |
| 1582 |
XmUpdateDisplay(messageWidget); |
| 1583 |
|
| 1584 |
// |
| 1585 |
// Invoke the beforeList callbacks |
| 1586 |
// |
| 1587 |
beforeList.invokeCallbacks ((void *)this); |
| 1588 |
|
| 1589 |
// Get Xt Strings. Update the print size. |
| 1590 |
char *dpiString = XmTextGetString(printerDPIField); |
| 1591 |
if (postScriptOutput) { |
| 1592 |
float fx, fy; |
| 1593 |
if (printerOutput) { |
| 1594 |
text = XmTextGetString (printerHorizSize); |
| 1595 |
fx = atof(text); |
| 1596 |
XtFree(text); |
| 1597 |
text = XmTextGetString (printerVertSize); |
| 1598 |
fy = atof(text); |
| 1599 |
XtFree(text); |
| 1600 |
setPrintSize(SbVec2f(fx, fy)); |
| 1601 |
} |
| 1602 |
else { |
| 1603 |
text = XmTextGetString (postScriptHorizSize); |
| 1604 |
fx = atof(text); |
| 1605 |
XtFree(text); |
| 1606 |
text = XmTextGetString (postScriptVertSize); |
| 1607 |
fy = atof(text); |
| 1608 |
XtFree(text); |
| 1609 |
setPrintSize(SbVec2f(fx, fy)); |
| 1610 |
} |
| 1611 |
} |
| 1612 |
else { |
| 1613 |
text = XmTextGetString (rgbHorizSize); |
| 1614 |
short sx = (short)atoi(text); |
| 1615 |
XtFree(text); |
| 1616 |
text = XmTextGetString (rgbVertSize); |
| 1617 |
short sy = (short)atoi(text); |
| 1618 |
XtFree(text); |
| 1619 |
setPrintSize(SbVec2s(sx, sy)); |
| 1620 |
} |
| 1621 |
// make the text fields loose focus |
| 1622 |
XmProcessTraversal(SoXt::getShellWidget(getWidget()), |
| 1623 |
XmTRAVERSE_CURRENT); |
| 1624 |
|
| 1625 |
if (rootNode == NULL) |
| 1626 |
{ |
| 1627 |
XmTextSetString (messageWidget, "ERROR: Empty database."); |
| 1628 |
XmUpdateDisplay(messageWidget); |
| 1629 |
afterList.invokeCallbacks ((void *)this); |
| 1630 |
return; |
| 1631 |
} |
| 1632 |
|
| 1633 |
// If Draft Quality, halve the resolution |
| 1634 |
SbVec2s renderRes = printRes; |
| 1635 |
if (!highQuality) |
| 1636 |
renderRes /= 2; |
| 1637 |
|
| 1638 |
// If rendering to PostScript, adjust the rendering resolution to account |
| 1639 |
// for the specified DPI. |
| 1640 |
if (printerOutput || postScriptOutput) { |
| 1641 |
float renderDPI = atof(dpiString); |
| 1642 |
renderRes *= |
| 1643 |
(renderDPI / SoOffscreenRenderer::getScreenPixelsPerInch()); |
| 1644 |
|
| 1645 |
// For postScript Printing, set the backgroundColor to white. This |
| 1646 |
// should probably be changed to get the color from a color editor. |
| 1647 |
bgColor.setValue(1.0, 1.0, 1.0); |
| 1648 |
} |
| 1649 |
|
| 1650 |
// Check the viewport size to make sure the image can be rendered |
| 1651 |
// on the current DISPLAY |
| 1652 |
SbVec2s maxRes = SoOffscreenRenderer::getMaximumResolution(); |
| 1653 |
|
| 1654 |
if ((renderRes[0] > maxRes[0]) || (renderRes[1] > maxRes[1])) { |
| 1655 |
char tmpStr[64]; |
| 1656 |
|
| 1657 |
sprintf(tmpStr, "ERROR: Exceeds %d by %d.", |
| 1658 |
maxRes[0], maxRes[1] ); |
| 1659 |
XmTextSetString (messageWidget, tmpStr); |
| 1660 |
XmUpdateDisplay(messageWidget); |
| 1661 |
afterList.invokeCallbacks ((void *)this); |
| 1662 |
return; |
| 1663 |
} |
| 1664 |
|
| 1665 |
SbViewportRegion vpRegion(renderRes); |
| 1666 |
vpRegion.setPixelsPerInch(atof(dpiString)); |
| 1667 |
|
| 1668 |
// ??? COMPAT 2.0 |
| 1669 |
// |
| 1670 |
// Create a render action and fill it in with the viewport region |
| 1671 |
// defined by the dialog, and other attributes from the stored |
| 1672 |
// render action. Use this new render action with the offscreen |
| 1673 |
// renderer. |
| 1674 |
SoGLRenderAction act(vpRegion); |
| 1675 |
_SoPrintDialogItem *item = _SoFindPrintDialog(this); |
| 1676 |
|
| 1677 |
if (item != NULL) { |
| 1678 |
act.setTransparencyType(item->act->getTransparencyType()); |
| 1679 |
act.setSmoothing(item->act->isSmoothing()); |
| 1680 |
act.setNumPasses(item->act->getNumPasses()); |
| 1681 |
} |
| 1682 |
|
| 1683 |
renderer = new SoOffscreenRenderer(&act); |
| 1684 |
renderer->setBackgroundColor(bgColor); |
| 1685 |
|
| 1686 |
// |
| 1687 |
// Render the database! |
| 1688 |
// |
| 1689 |
if (nodeMostRecent) { |
| 1690 |
if (!renderer->render(rootNode)) { |
| 1691 |
XmTextSetString (messageWidget, "ERROR: Could not execute print."); |
| 1692 |
XmUpdateDisplay(messageWidget); |
| 1693 |
afterList.invokeCallbacks ((void *)this); |
| 1694 |
delete renderer; |
| 1695 |
return; |
| 1696 |
} |
| 1697 |
} |
| 1698 |
else |
| 1699 |
{ |
| 1700 |
if (!renderer->render(rootPath)) { |
| 1701 |
XmTextSetString (messageWidget, "ERROR: Could not execute print."); |
| 1702 |
XmUpdateDisplay(messageWidget); |
| 1703 |
afterList.invokeCallbacks ((void *)this); |
| 1704 |
delete renderer; |
| 1705 |
return; |
| 1706 |
} |
| 1707 |
} |
| 1708 |
|
| 1709 |
// |
| 1710 |
// Are we printing to a printer or a file? |
| 1711 |
// |
| 1712 |
if (printerOutput) { |
| 1713 |
if (whichPrinter < 0) |
| 1714 |
{ |
| 1715 |
XmTextSetString (messageWidget, "ERROR: No printer."); |
| 1716 |
XmUpdateDisplay(messageWidget); |
| 1717 |
afterList.invokeCallbacks ((void *)this); |
| 1718 |
delete renderer; |
| 1719 |
return; |
| 1720 |
} |
| 1721 |
|
| 1722 |
printerName = PRINTER_NAME(whichPrinter); |
| 1723 |
|
| 1724 |
// |
| 1725 |
// Open a temporary filename to write the data into. Look at the |
| 1726 |
// environment variable TMPDIR and write the file there. |
| 1727 |
// |
| 1728 |
char *tmpdir = getenv("TMPDIR"); |
| 1729 |
|
| 1730 |
if (tmpdir == NULL) |
| 1731 |
(void)sprintf (tempPSFileName, "/tmp/.sop%d.ps", getpid()); |
| 1732 |
else |
| 1733 |
(void)sprintf (tempPSFileName, "%s/.sop%d.ps", tmpdir, getpid()); |
| 1734 |
if ((fileP = fopen (tempPSFileName, "w")) == NULL) |
| 1735 |
{ |
| 1736 |
char str[64]; |
| 1737 |
sprintf(str, "ERROR: Couldn't open %s", tempPSFileName); |
| 1738 |
XmTextSetString (messageWidget, str); |
| 1739 |
XmUpdateDisplay(messageWidget); |
| 1740 |
afterList.invokeCallbacks ((void *)this); |
| 1741 |
delete renderer; |
| 1742 |
return; |
| 1743 |
} |
| 1744 |
|
| 1745 |
// |
| 1746 |
// If the print is to be landscape format, rotate the print |
| 1747 |
// 90 degrees and translate it up by a margin. Write the appropriate |
| 1748 |
// PostScript commands to the temporary PostScript file. |
| 1749 |
// |
| 1750 |
fprintf(fileP, "%%!PS-Adobe-2.0\n"); |
| 1751 |
if (!portraitFormat) |
| 1752 |
{ |
| 1753 |
fprintf(fileP, "%f %f translate\n", |
| 1754 |
PNTS*(PAGEMARGIN), |
| 1755 |
PNTS*(FULLPAGEYSIZE-PAGEMARGIN)); |
| 1756 |
fprintf(fileP,"-90.0 rotate\n"); |
| 1757 |
} |
| 1758 |
else |
| 1759 |
{ |
| 1760 |
fprintf(fileP, "%f %f translate\n", |
| 1761 |
PNTS*(PAGEMARGIN), |
| 1762 |
PNTS*(PAGEMARGIN)); |
| 1763 |
} |
| 1764 |
|
| 1765 |
renderer->writeToPostScript( fileP, printSize ); |
| 1766 |
fflush (fileP); |
| 1767 |
fclose (fileP); |
| 1768 |
|
| 1769 |
// Send the file to the printer |
| 1770 |
|
| 1771 |
#ifdef __sgi |
| 1772 |
union wait waitStatus; |
| 1773 |
#else |
| 1774 |
int waitStatus; |
| 1775 |
typedef void (*SIG_PF)(int); |
| 1776 |
#endif // __sgi |
| 1777 |
SIG_PF childstat; |
| 1778 |
pid_t wpid; |
| 1779 |
|
| 1780 |
// |
| 1781 |
// Save old function and restore default behavior. |
| 1782 |
// |
| 1783 |
childstat = signal (SIGCHLD, SIG_DFL); |
| 1784 |
if (!(wpid=fork())) { |
| 1785 |
if (*printerName == 0) |
| 1786 |
execlp("lp", "lp", "-c", "-s", tempPSFileName, (char*) 0); |
| 1787 |
else { |
| 1788 |
char popt[SO_PRINTER_STRLEN]; |
| 1789 |
sprintf(popt, "-d%s", printerName); |
| 1790 |
execlp("lp", "lp", "-c", popt, "-s", tempPSFileName, (char*) 0); |
| 1791 |
} |
| 1792 |
} |
| 1793 |
(void)waitpid(wpid, (int *)(&waitStatus), 0); |
| 1794 |
// |
| 1795 |
// Restore catching dead babies. |
| 1796 |
// |
| 1797 |
(void) signal(SIGCHLD, childstat); |
| 1798 |
#ifdef __sgi |
| 1799 |
if (!(WIFEXITED(waitStatus) && waitStatus.w_retcode == 0)) |
| 1800 |
#else |
| 1801 |
if (!(WIFEXITED(waitStatus) && WEXITSTATUS(waitStatus) == 0)) |
| 1802 |
#endif // __sgi |
| 1803 |
SoDebugError::post("SoXtPrintDialog::print", |
| 1804 |
"Print Error. Diagnose with Print Manager."); |
| 1805 |
unlink(tempPSFileName); |
| 1806 |
} |
| 1807 |
else |
| 1808 |
{ |
| 1809 |
// |
| 1810 |
// Send to file. Get the file name from the textWidget and open |
| 1811 |
// the file. |
| 1812 |
// |
| 1813 |
if (postScriptOutput) |
| 1814 |
fileName = XmTextGetString (postScriptFilenameWidget); |
| 1815 |
else |
| 1816 |
fileName = XmTextGetString (rgbFilenameWidget); |
| 1817 |
if (strlen(fileName) == 0) |
| 1818 |
{ |
| 1819 |
XmTextSetString (messageWidget, "ERROR: No file name."); |
| 1820 |
XmUpdateDisplay(messageWidget); |
| 1821 |
afterList.invokeCallbacks ((void *)this); |
| 1822 |
XtFree (fileName); |
| 1823 |
delete renderer; |
| 1824 |
return; |
| 1825 |
} |
| 1826 |
|
| 1827 |
if (!outFile.openFile (fileName)) |
| 1828 |
{ |
| 1829 |
XmTextSetString (messageWidget, "ERROR: Could not open file."); |
| 1830 |
XmUpdateDisplay(messageWidget); |
| 1831 |
afterList.invokeCallbacks ((void *)this); |
| 1832 |
XtFree (fileName); |
| 1833 |
delete renderer; |
| 1834 |
return; |
| 1835 |
} |
| 1836 |
if (postScriptOutput) { |
| 1837 |
if (!renderer->writeToPostScript( outFile.getFilePointer(), |
| 1838 |
printSize )) |
| 1839 |
{ |
| 1840 |
XmTextSetString (messageWidget, "ERROR: Could not get data."); |
| 1841 |
XmUpdateDisplay(messageWidget); |
| 1842 |
outFile.closeFile(); |
| 1843 |
afterList.invokeCallbacks ((void *)this); |
| 1844 |
XtFree (fileName); |
| 1845 |
delete renderer; |
| 1846 |
return; |
| 1847 |
} |
| 1848 |
} |
| 1849 |
else if (!renderer->writeToRGB( outFile.getFilePointer() )) |
| 1850 |
{ |
| 1851 |
XmTextSetString (messageWidget, "ERROR: Could not get data."); |
| 1852 |
XmUpdateDisplay(messageWidget); |
| 1853 |
outFile.closeFile(); |
| 1854 |
XtFree (fileName); |
| 1855 |
afterList.invokeCallbacks ((void *)this); |
| 1856 |
delete renderer; |
| 1857 |
return; |
| 1858 |
} |
| 1859 |
|
| 1860 |
outFile.closeFile(); |
| 1861 |
XtFree (fileName); |
| 1862 |
} |
| 1863 |
|
| 1864 |
// |
| 1865 |
// Invoke the afterList callbacks |
| 1866 |
// |
| 1867 |
afterList.invokeCallbacks ((void *)this); |
| 1868 |
|
| 1869 |
XmTextSetString (messageWidget, "Printing completed."); |
| 1870 |
XmUpdateDisplay(messageWidget); |
| 1871 |
delete renderer; |
| 1872 |
XtFree (dpiString); |
| 1873 |
} |
| 1874 |
|
| 1875 |
/////////////////////////////////////////////////////////////////////// |
| 1876 |
// |
| 1877 |
// Description: |
| 1878 |
// This routine is called when the Print button of the SoXtPrintDialog |
| 1879 |
// widget is pressed. It calls print(). |
| 1880 |
// |
| 1881 |
// Use: private |
| 1882 |
|
| 1883 |
void |
| 1884 |
SoXtPrintDialog::printCB( |
| 1885 |
Widget, |
| 1886 |
SoXtPrintDialog *ptr, |
| 1887 |
XmAnyCallbackStruct *) |
| 1888 |
// |
| 1889 |
////////////////////////////////////////////////////////////////////// |
| 1890 |
{ |
| 1891 |
ptr->print(); |
| 1892 |
} |
| 1893 |
|
| 1894 |
/////////////////////////////////////////////////////////////////////// |
| 1895 |
// |
| 1896 |
// Description: |
| 1897 |
// Update the textports with new sizes |
| 1898 |
// |
| 1899 |
// Use: protected |
| 1900 |
// |
| 1901 |
void |
| 1902 |
SoXtPrintDialog::updateTextports() |
| 1903 |
// |
| 1904 |
////////////////////////////////////////////////////////////////////// |
| 1905 |
{ |
| 1906 |
alreadyUpdated = TRUE; |
| 1907 |
// Send the new size to the widgets |
| 1908 |
char tc[12]; |
| 1909 |
sprintf(tc, "%.3f", printSize[0]); |
| 1910 |
XmTextSetString (printerHorizSize, tc); |
| 1911 |
XmTextSetString (postScriptHorizSize, tc); |
| 1912 |
sprintf(tc, "%.3f", printSize[1]); |
| 1913 |
XmTextSetString (printerVertSize, tc); |
| 1914 |
XmTextSetString (postScriptVertSize, tc); |
| 1915 |
sprintf(tc, "%d", printRes[0]); |
| 1916 |
XmTextSetString (rgbHorizSize, tc); |
| 1917 |
sprintf(tc, "%d", printRes[1]); |
| 1918 |
XmTextSetString (rgbVertSize, tc); |
| 1919 |
|
| 1920 |
// If the textports are currently managed, update them |
| 1921 |
if (XtIsManaged(printerHorizSize)) { |
| 1922 |
XmUpdateDisplay(printerHorizSize); |
| 1923 |
XmUpdateDisplay(printerVertSize); |
| 1924 |
} |
| 1925 |
else if (XtIsManaged(postScriptHorizSize)) { |
| 1926 |
XmUpdateDisplay(postScriptHorizSize); |
| 1927 |
XmUpdateDisplay(postScriptVertSize); |
| 1928 |
} |
| 1929 |
if (XtIsManaged(rgbHorizSize)) { |
| 1930 |
XmUpdateDisplay(rgbHorizSize); |
| 1931 |
XmUpdateDisplay(rgbVertSize); |
| 1932 |
} |
| 1933 |
alreadyUpdated = FALSE; |
| 1934 |
} |
| 1935 |
|
| 1936 |
|
| 1937 |
/////////////////////////////////////////////////////////////////////// |
| 1938 |
// |
| 1939 |
// Description: |
| 1940 |
// This routine gets the list of available printers for printing. |
| 1941 |
// |
| 1942 |
// Use: private |
| 1943 |
|
| 1944 |
void |
| 1945 |
SoXtPrintDialog::getPrinterList() |
| 1946 |
|
| 1947 |
// |
| 1948 |
////////////////////////////////////////////////////////////////////// |
| 1949 |
{ |
| 1950 |
FILE *fp; |
| 1951 |
char line[80]; |
| 1952 |
SbBool firstTime = TRUE; |
| 1953 |
|
| 1954 |
fp = popen("lpstat -d -a | awk '/accepting/ {if ($2 != \"not\") print $1}; /^system default destination:/ { print $4 }; /^no system default destination/ { print \"none\"} '", "r"); |
| 1955 |
while (fgets(line, 80, fp) != NULL) { |
| 1956 |
line[strlen(line)-1] = 0; |
| 1957 |
if (firstTime) { |
| 1958 |
defaultPrinter = strdup(line); |
| 1959 |
firstTime = FALSE; |
| 1960 |
} |
| 1961 |
else printers->append(strdup(line)); |
| 1962 |
} |
| 1963 |
pclose(fp); |
| 1964 |
} |
| 1965 |
|
| 1966 |
// |
| 1967 |
// redefine those generic virtual functions |
| 1968 |
// |
| 1969 |
const char * |
| 1970 |
SoXtPrintDialog::getDefaultWidgetName() const |
| 1971 |
{ return "SoXtPrintDialog"; } |
| 1972 |
|
| 1973 |
const char * |
| 1974 |
SoXtPrintDialog::getDefaultTitle() const |
| 1975 |
{ return "Print Dialog"; } |
| 1976 |
|
| 1977 |
const char * |
| 1978 |
SoXtPrintDialog::getDefaultIconTitle() const |
| 1979 |
{ return "Print Dialog"; } |
| 1980 |
|