Annotation of OpenXM_contrib/gnuplot/os2/dialogs.c, Revision 1.1
1.1 ! maekawa 1: #ifdef INCRCSDATA
! 2: static char RCSid[]="$Id: dialogs.c,v 1.9 1998/03/22 22:34:20 drd Exp $" ;
! 3: #endif
! 4:
! 5: /****************************************************************************
! 6:
! 7: PROGRAM: gnupmdrv
! 8:
! 9: Outboard PM driver for GNUPLOT 3.3
! 10:
! 11: MODULE: dialogs.c Dialog procedures for gnupmdrv
! 12:
! 13: ****************************************************************************/
! 14:
! 15: /* PM driver for GNUPLOT */
! 16:
! 17: /*[
! 18: * Copyright 1992, 1993, 1998 Roger Fearick
! 19: *
! 20: * Permission to use, copy, and distribute this software and its
! 21: * documentation for any purpose with or without fee is hereby granted,
! 22: * provided that the above copyright notice appear in all copies and
! 23: * that both that copyright notice and this permission notice appear
! 24: * in supporting documentation.
! 25: *
! 26: * Permission to modify the software is granted, but not the right to
! 27: * distribute the complete modified source code. Modifications are to
! 28: * be distributed as patches to the released version. Permission to
! 29: * distribute binaries produced by compiling modified sources is granted,
! 30: * provided you
! 31: * 1. distribute the corresponding source modifications from the
! 32: * released version in the form of a patch file along with the binaries,
! 33: * 2. add special version identification to distinguish your version
! 34: * in addition to the base release version number,
! 35: * 3. provide your name and address as the primary contact for the
! 36: * support of your modified version, and
! 37: * 4. retain our contact information in regard to use of the base
! 38: * software.
! 39: * Permission to distribute the released version of the source code along
! 40: * with corresponding source modifications in the form of a patch file is
! 41: * granted with same provisions 2 through 4 for binary distributions.
! 42: *
! 43: * This software is provided "as is" without express or implied warranty
! 44: * to the extent permitted by applicable law.
! 45: ]*/
! 46:
! 47: /*
! 48: * AUTHOR
! 49: *
! 50: * Gnuplot driver for OS/2: Roger Fearick
! 51: *
! 52: * Send your comments or suggestions to
! 53: * info-gnuplot@dartmouth.edu.
! 54: * This is a mailing list; to join it send a note to
! 55: * majordomo@dartmouth.edu.
! 56: * Send bug reports to
! 57: * bug-gnuplot@dartmouth.edu.
! 58: **/
! 59:
! 60: #define INCL_PM
! 61: #define INCL_WIN
! 62: #define INCL_DEV
! 63: #define INCL_SPL
! 64: #define INCL_SPLDOSPRINT
! 65: #define INCL_WINDIALOGS
! 66: #define INCL_WINBUTTONS
! 67: #define INCL_WINSYS
! 68: #define INCL_WINFRAMEMGR
! 69: #define INCL_WINPOINTERS
! 70: #define INCL_WINTRACKRECT
! 71: #define INCL_WINENTRYFIELDS
! 72: #define INCL_WINWINDOWMGR
! 73: #include <os2.h>
! 74: #include <math.h>
! 75: #include <stdio.h>
! 76: #include <stdlib.h>
! 77: #include <string.h>
! 78: #include "gnupmdrv.h"
! 79:
! 80: /* struct for printer capabilities */
! 81:
! 82: static struct {
! 83: long lTech ; // printer technology
! 84: long lVer ; // driver version
! 85: long lWidth ; // page width in pels
! 86: long lHeight ; // page height in pels
! 87: long lWChars ; // page width in chars
! 88: long lHChars ; // page height in chars
! 89: long lHorRes ; // horizontal resolution pels / metre
! 90: long lVertRes ; // vertical resolution pels / metre
! 91: } prCaps ;
! 92:
! 93: ULONG GetPrinters( PPRQINFO3* pprq, ULONG *pcTot ) ;
! 94:
! 95:
! 96: MRESULT EXPENTRY QPrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
! 97: /*
! 98: ** Query print area and printer setup
! 99: */
! 100: {
! 101: static PQPRINT pqp = NULL ;
! 102: static SWP swp ;
! 103: static RECTL rectlDef ;
! 104: TRACKINFO ti ;
! 105: RECTL rectlBox ;
! 106: HDC hdc ;
! 107: ULONG ulStyle ;
! 108: char *psz ;
! 109:
! 110: switch ( usMsg ) {
! 111:
! 112: case WM_INITDLG :
! 113:
! 114: pqp = (PQPRINT) PVOIDFROMMP( mp2 ) ;
! 115: if( pqp->caps & QP_CAPS_FILE ) {
! 116: ulStyle = WinQueryWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
! 117: QWL_STYLE ) ;
! 118: WinSetWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
! 119: QWL_STYLE, ulStyle ^ DT_HALFTONE ) ;
! 120: }
! 121: else {
! 122: WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
! 123: EM_SETREADONLY, (MPARAM)TRUE, 0L ) ;
! 124: }
! 125: WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
! 126: &rectlDef ) ;
! 127:
! 128: case WM_USER_SET_DATA :
! 129:
! 130: psz = *pqp->piPrinter->pszComment ? pqp->piPrinter->pszComment :
! 131: pqp->piPrinter->pszName ;
! 132: WinSetDlgItemText( hwnd, IDD_PRINTNAME, psz ) ;
! 133: WinSetDlgItemFloatF( hwnd, IDD_QPRXSIZE, 1, pqp->xsize ) ;
! 134: WinSetDlgItemFloatF( hwnd, IDD_QPRYSIZE, 1, pqp->ysize ) ;
! 135: WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
! 136: WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
! 137: WinQueryWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
! 138: &swp ) ;
! 139: {
! 140: int y = rectlDef.yTop ;
! 141: rectlBox = rectlDef ;
! 142: if( pqp->xsize < pqp->ysize )
! 143: rectlBox.xRight = rectlDef.yTop * pqp->xsize/pqp->ysize ;
! 144: else {
! 145: int x = rectlDef.yTop * pqp->ysize/pqp->xsize ;
! 146: rectlBox.yTop = x ;
! 147: rectlBox.xRight = y ;
! 148: }
! 149: }
! 150: WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
! 151: NULLHANDLE, 0, 0, (short) rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE ) ;
! 152: {
! 153: double ratio = 1.560 ;
! 154: double xs = rectlBox.xRight - rectlBox.xLeft ;
! 155: double ys = rectlBox.yTop - rectlBox.yBottom ;
! 156: if( ys > xs/ratio ) { /* reduce ys to fit */
! 157: rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ;
! 158: }
! 159: else if( ys < xs/ratio ) { /* reduce xs to fit */
! 160: rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
! 161: }
! 162: }
! 163: rectlBox.xRight *= pqp->xfrac ;
! 164: rectlBox.yTop *= pqp->yfrac ;
! 165: WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
! 166: NULLHANDLE,
! 167: swp.x, swp.y, //+(short)(swp.cy*(1.0-pqp->yfrac)),
! 168: (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
! 169: break ;
! 170:
! 171: case WM_COMMAND :
! 172:
! 173: switch ( SHORT1FROMMP(mp1) ) {
! 174:
! 175: case DID_OK:
! 176: WinQueryDlgItemFloat( hwnd, IDD_QPRXFRAC, &pqp->xfrac ) ;
! 177: WinQueryDlgItemFloat( hwnd, IDD_QPRYFRAC, &pqp->yfrac ) ;
! 178:
! 179: if( pqp->caps & QP_CAPS_FILE ) {
! 180: WinQueryDlgItemText( hwnd, IDD_QPRNAME, 32, pqp->szFilename ) ;
! 181: }
! 182: break ;
! 183:
! 184: case IDD_QPRSETPR: /* printer setup */
! 185: if( SetPrinterMode( hwnd, pqp ) == 1 ) {
! 186: if( (hdc = OpenPrinterDC( WinQueryAnchorBlock( hwnd ),
! 187: pqp,
! 188: OD_INFO,
! 189: NULL )) != DEV_ERROR ) {
! 190: DevQueryCaps( hdc, CAPS_TECHNOLOGY, (long)sizeof(prCaps)/sizeof(long), (PLONG)&prCaps ) ;
! 191: DevCloseDC( hdc ) ;
! 192: pqp->xsize = (float)100.0* (float) prCaps.lWidth / (float) prCaps.lHorRes ; // in cm
! 193: pqp->ysize = (float)100.0* (float) prCaps.lHeight / (float) prCaps.lVertRes ; // in cm
! 194: WinSendMsg( hwnd, WM_USER_SET_DATA, 0L, 0L ) ;
! 195: }
! 196: }
! 197: return 0L ;
! 198:
! 199: case IDD_QPRTRACK : /* track plot area */
! 200: WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
! 201: &rectlBox ) ;
! 202: {
! 203: double ratio = 1.560 ;
! 204: double xs = rectlBox.xRight - rectlBox.xLeft ;
! 205: double ys = rectlBox.yTop - rectlBox.yBottom ;
! 206: if( ys > xs/ratio ) { /* reduce ys to fit */
! 207: rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ;
! 208: }
! 209: else if( ys < xs/ratio ) { /* reduce xs to fit */
! 210: rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
! 211: }
! 212: }
! 213: ti.cxBorder = ti.cyBorder = 2 ;
! 214: ti.cxGrid = ti.cyGrid = 0 ;
! 215: ti.cxKeyboard = ti.cyKeyboard = 2 ;
! 216: ti.ptlMinTrackSize.x = ti.ptlMinTrackSize.y = 2 ;
! 217: ti.rclBoundary = rectlBox ;
! 218: ti.ptlMaxTrackSize.x = rectlBox.xRight ;
! 219: ti.ptlMaxTrackSize.y = rectlBox.yTop ;
! 220: ti.rclTrack.xRight = pqp->xfrac * rectlBox.xRight ;
! 221: ti.rclTrack.yTop = pqp->yfrac*rectlBox.yTop ;
! 222: ti.rclTrack.xLeft = 0 ;
! 223: ti.rclTrack.yBottom = 0 ;//(1.0-pqp->yfrac) * rectlBox.yTop ;
! 224: ti.fs = TF_RIGHT|TF_TOP|TF_STANDARD|TF_SETPOINTERPOS|TF_ALLINBOUNDARY ;
! 225: WinSetPointer( HWND_DESKTOP,
! 226: WinQuerySysPointer( HWND_DESKTOP, SPTR_SIZENWSE, FALSE ) ) ;
! 227: WinTrackRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
! 228: NULLHANDLE,
! 229: &ti ) ;
! 230: pqp->xfrac = (float)ti.rclTrack.xRight / (float)rectlBox.xRight ;
! 231: pqp->yfrac = ((float)(ti.rclTrack.yTop-ti.rclTrack.yBottom) / (float)rectlBox.yTop) ;
! 232: rectlBox.yTop = ti.rclTrack.yTop - ti.rclTrack.yBottom ;
! 233: rectlBox.xRight = ti.rclTrack.xRight ;
! 234: {
! 235: double ratio = 1.560 ;
! 236: double xs = rectlBox.xRight - rectlBox.xLeft ;
! 237: double ys = rectlBox.yTop - rectlBox.yBottom ;
! 238: if( ys > xs/ratio ) { /* reduce ys to fit */
! 239: rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ;
! 240: }
! 241: else if( ys < xs/ratio ) { /* reduce xs to fit */
! 242: rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
! 243: }
! 244: }
! 245: WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
! 246: NULLHANDLE,
! 247: swp.x, swp.y,//+(short)(swp.cy*(1.0-pqp->yfrac)),
! 248: (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
! 249: WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
! 250: WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
! 251: return 0L ;
! 252:
! 253: default:
! 254: break ;
! 255: }
! 256:
! 257: default:
! 258: break ;
! 259: }
! 260: /* fall through to the default control processing */
! 261:
! 262: return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
! 263: }
! 264:
! 265: MRESULT EXPENTRY QPrintersDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
! 266: /*
! 267: ** Query printers and allow selection
! 268: */
! 269: {
! 270: static HWND hwndLB ;
! 271: static PPRQINFO3 pprq=NULL ;
! 272: static ULONG cPrinters ;
! 273: static USHORT usItem ;
! 274: static char *szPrinterName ;
! 275: int i, iSelect ;
! 276: char *psz ;
! 277:
! 278: switch ( usMsg ) {
! 279:
! 280: case WM_INITDLG :
! 281:
! 282: szPrinterName = (char*) PVOIDFROMMP( mp2 ) ;
! 283: iSelect = 0 ;
! 284: GetPrinters( &pprq, &cPrinters ) ;
! 285: hwndLB = WinWindowFromID( hwnd, IDD_QPRSLIST ) ;
! 286: for( i=0; i<cPrinters;i++ ) {
! 287: psz = *pprq[i].pszComment ? pprq[i].pszComment :
! 288: pprq[i].pszName ;
! 289: WinSendMsg( hwndLB,
! 290: LM_INSERTITEM,
! 291: (MPARAM)LIT_END,
! 292: MPFROMP(psz) ) ;
! 293: if( strcmp( pprq[i].pszName, szPrinterName ) == 0 )
! 294: iSelect = i ;
! 295: }
! 296:
! 297: WinSendMsg( hwndLB,
! 298: LM_SELECTITEM,
! 299: MPFROMSHORT( iSelect ),
! 300: (MPARAM)TRUE ) ;
! 301:
! 302: break ;
! 303:
! 304: case WM_COMMAND :
! 305:
! 306: switch ( SHORT1FROMMP(mp1) ) {
! 307:
! 308: case DID_OK:
! 309: strcpy( szPrinterName, pprq[usItem].pszName ) ;
! 310: case DID_CANCEL:
! 311: free( pprq ) ;
! 312: pprq = NULL;
! 313: break ;
! 314: }
! 315: break ;
! 316:
! 317: case WM_CONTROL:
! 318:
! 319: if( SHORT1FROMMP( mp1 ) == IDD_QPRSLIST ) {
! 320: if( SHORT2FROMMP( mp1 ) == LN_SELECT ) {
! 321: usItem = (ULONG)WinSendMsg( hwndLB,
! 322: LM_QUERYSELECTION,
! 323: 0L,
! 324: 0L ) ;
! 325: }
! 326: }
! 327:
! 328: default:
! 329: break ;
! 330: }
! 331: /* fall through to the default control processing */
! 332: return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
! 333: }
! 334:
! 335: ULONG GetPrinters( PPRQINFO3 *pprq, ULONG *pcTot )
! 336: /*
! 337: ** get a list of printers
! 338: */
! 339: {
! 340: ULONG rc ;
! 341: ULONG cQueues, cbData ;
! 342:
! 343: rc = SplEnumQueue( NULL, 3, NULL, 0, &cQueues, pcTot, &cbData, NULL ) ;
! 344:
! 345: if( *pprq != NULL ) {
! 346: free( *pprq ) ;
! 347: *pprq = NULL ;
! 348: }
! 349: if( *pcTot == 0 ) { /* no printers */
! 350: return 0 ;
! 351: }
! 352: *pprq = malloc( cbData ) ;
! 353: rc = SplEnumQueue( NULL,
! 354: 3,
! 355: *pprq,
! 356: cbData,
! 357: &cQueues,
! 358: pcTot,
! 359: &cbData,
! 360: NULL ) ;
! 361: return *pcTot ;
! 362: }
! 363:
! 364: MRESULT EXPENTRY PauseMsgDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
! 365: /*
! 366: ** Pause message dialog box proc
! 367: */
! 368: {
! 369: static PPAUSEDATA ppdata = NULL ;
! 370: char *pszText ;
! 371: switch ( usMsg ) {
! 372:
! 373: case WM_INITDLG :
! 374: /* set the position so user can move out the way, and
! 375: have it come back there next time */
! 376: ppdata = (PPAUSEDATA) PVOIDFROMMP( mp2 ) ;
! 377: if( ppdata->pswp != NULL )
! 378: WinSetWindowPos( hwnd, HWND_TOP, ppdata->pswp->x, ppdata->pswp->y,
! 379: 0, 0, SWP_MOVE ) ;
! 380: pszText = ppdata->pszMessage ;
! 381: while(*pszText==' ') ++pszText ;
! 382: WinSetDlgItemText( hwnd, IDD_PAUSETEXT, pszText ) ;
! 383: break ;
! 384:
! 385: case WM_COMMAND :
! 386: switch ( SHORT1FROMMP(mp1) ) {
! 387: case DID_OK:
! 388: case DID_CANCEL:
! 389: WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
! 390: WM_PAUSEEND,
! 391: SHORT1FROMMP(mp1)==DID_OK?(MPARAM)1L:0L,
! 392: 0L ) ;
! 393: if( ppdata->pswp == NULL ) ppdata->pswp = (PSWP)malloc( sizeof(SWP) ) ;
! 394: WinQueryWindowPos( hwnd, ppdata->pswp ) ;
! 395: WinDismissDlg( hwnd, 0 ) ;
! 396: break ;
! 397: case IDM_PRINT:
! 398: WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
! 399: WM_COMMAND,
! 400: MPFROMSHORT(IDM_PRINT),
! 401: 0L ) ;
! 402: return 0 ;
! 403: default:
! 404: break ;
! 405: }
! 406: default:
! 407: break ;
! 408: }
! 409: /* fall through to the default control processing */
! 410: return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
! 411: }
! 412:
! 413: void WinSetDlgItemFloatF( HWND hwnd, USHORT usID, int nDec, float flValue )
! 414: /*
! 415: */
! 416: {
! 417: char achBuffer [ 34 ], *szCvt ; // default string field size ...
! 418: int iDec ;
! 419: int iSign ;
! 420: char fmt[32] ;
! 421: sprintf( fmt, "%%12.%df", nDec ) ;
! 422: sprintf( achBuffer, fmt, flValue ) ;
! 423: WinSetDlgItemText( hwnd, usID, achBuffer ) ;
! 424: }
! 425:
! 426: void WinSetDlgItemFloat( HWND hwnd, USHORT usID, float flValue )
! 427: /*
! 428: */
! 429: {
! 430: char achBuffer [ 34 ] ; // default string field size ...
! 431: char fmt[10] ;
! 432: sprintf( fmt, "%%12.%df", 4 ) ;
! 433: sprintf( achBuffer, fmt, flValue ) ;
! 434: WinSetDlgItemText( hwnd, usID, achBuffer ) ;
! 435: WinSetDlgItemText( hwnd, usID, achBuffer ) ;
! 436: }
! 437:
! 438: void WinQueryDlgItemFloat( HWND hwnd, USHORT usID, float *pflValue )
! 439: /*
! 440: */
! 441: {
! 442: char achBuffer [ 34 ] ; // default string field size ...
! 443: ULONG ulTemp ;
! 444:
! 445: WinQueryDlgItemText( hwnd, usID, 34, achBuffer ) ;
! 446: *pflValue = (float) atof( achBuffer ) ;
! 447: }
! 448:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>