2 static char RCSid[]="$Id: dialogs.c,v 1.7 2005/01/04 13:01:34 mikulik Exp $" ;
5 /****************************************************************************
9 Outboard PM driver for GNUPLOT 3.x
11 MODULE: dialogs.c Dialog procedures for gnupmdrv
13 ****************************************************************************/
15 /* PM driver for GNUPLOT */
18 * Copyright 1992, 1993, 1998, 2004 Roger Fearick
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.
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,
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
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.
43 * This software is provided "as is" without express or implied warranty
44 * to the extent permitted by applicable law.
50 * Gnuplot driver for OS/2: Roger Fearick
57 #define INCL_SPLDOSPRINT
58 #define INCL_WINDIALOGS
59 #define INCL_WINBUTTONS
61 #define INCL_WINFRAMEMGR
62 #define INCL_WINPOINTERS
63 #define INCL_WINTRACKRECT
64 #define INCL_WINENTRYFIELDS
65 #define INCL_WINWINDOWMGR
73 /* struct for printer capabilities */
76 long lTech ; // printer technology
77 long lVer ; // driver version
78 long lWidth ; // page width in pels
79 long lHeight ; // page height in pels
80 long lWChars ; // page width in chars
81 long lHChars ; // page height in chars
82 long lHorRes ; // horizontal resolution pels / metre
83 long lVertRes ; // vertical resolution pels / metre
86 ULONG GetPrinters( PPRQINFO3* pprq, ULONG *pcTot ) ;
89 MRESULT EXPENTRY QPrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
91 ** Query print area and printer setup
94 static PQPRINT pqp = NULL ;
96 static RECTL rectlDef ;
107 pqp = (PQPRINT) PVOIDFROMMP( mp2 ) ;
108 if( pqp->caps & QP_CAPS_FILE ) {
109 ulStyle = WinQueryWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
111 WinSetWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
112 QWL_STYLE, ulStyle ^ DT_HALFTONE ) ;
115 WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
116 EM_SETREADONLY, (MPARAM)TRUE, 0L ) ;
118 WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
121 case WM_USER_SET_DATA :
123 psz = *pqp->piPrinter->pszComment ? pqp->piPrinter->pszComment :
124 pqp->piPrinter->pszName ;
125 WinSetDlgItemText( hwnd, IDD_PRINTNAME, psz ) ;
126 WinSetDlgItemFloatF( hwnd, IDD_QPRXSIZE, 1, pqp->xsize ) ;
127 WinSetDlgItemFloatF( hwnd, IDD_QPRYSIZE, 1, pqp->ysize ) ;
128 WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
129 WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
130 WinQueryWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
133 int y = rectlDef.yTop ;
134 rectlBox = rectlDef ;
135 if( pqp->xsize < pqp->ysize )
136 rectlBox.xRight = rectlDef.yTop * pqp->xsize/pqp->ysize ;
138 int x = rectlDef.yTop * pqp->ysize/pqp->xsize ;
140 rectlBox.xRight = y ;
143 WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
144 NULLHANDLE, 0, 0, (short) rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE ) ;
146 double ratio = 1.560 ;
147 double xs = rectlBox.xRight - rectlBox.xLeft ;
148 double ys = rectlBox.yTop - rectlBox.yBottom ;
149 if( ys > xs/ratio ) { /* reduce ys to fit */
150 rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ;
152 else if( ys < xs/ratio ) { /* reduce xs to fit */
153 rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
156 rectlBox.xRight *= pqp->xfrac ;
157 rectlBox.yTop *= pqp->yfrac ;
158 WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
160 swp.x, swp.y, //+(short)(swp.cy*(1.0-pqp->yfrac)),
161 (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
166 switch ( SHORT1FROMMP(mp1) ) {
169 WinQueryDlgItemFloat( hwnd, IDD_QPRXFRAC, &pqp->xfrac ) ;
170 WinQueryDlgItemFloat( hwnd, IDD_QPRYFRAC, &pqp->yfrac ) ;
172 if( pqp->caps & QP_CAPS_FILE ) {
173 WinQueryDlgItemText( hwnd, IDD_QPRNAME, 32, pqp->szFilename ) ;
177 case IDD_QPRSETPR: /* printer setup */
178 if( SetPrinterMode( hwnd, pqp ) == 1 ) {
179 if( (hdc = OpenPrinterDC( WinQueryAnchorBlock( hwnd ),
182 NULL )) != DEV_ERROR ) {
183 DevQueryCaps( hdc, CAPS_TECHNOLOGY, (long)sizeof(prCaps)/sizeof(long), (PLONG)&prCaps ) ;
185 pqp->xsize = (float)100.0* (float) prCaps.lWidth / (float) prCaps.lHorRes ; // in cm
186 pqp->ysize = (float)100.0* (float) prCaps.lHeight / (float) prCaps.lVertRes ; // in cm
187 WinSendMsg( hwnd, WM_USER_SET_DATA, 0L, 0L ) ;
192 case IDD_QPRTRACK : /* track plot area */
193 WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
196 double ratio = 1.560 ;
197 double xs = rectlBox.xRight - rectlBox.xLeft ;
198 double ys = rectlBox.yTop - rectlBox.yBottom ;
199 if( ys > xs/ratio ) { /* reduce ys to fit */
200 rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ;
202 else if( ys < xs/ratio ) { /* reduce xs to fit */
203 rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
206 ti.cxBorder = ti.cyBorder = 2 ;
207 ti.cxGrid = ti.cyGrid = 0 ;
208 ti.cxKeyboard = ti.cyKeyboard = 2 ;
209 ti.ptlMinTrackSize.x = ti.ptlMinTrackSize.y = 2 ;
210 ti.rclBoundary = rectlBox ;
211 ti.ptlMaxTrackSize.x = rectlBox.xRight ;
212 ti.ptlMaxTrackSize.y = rectlBox.yTop ;
213 ti.rclTrack.xRight = pqp->xfrac * rectlBox.xRight ;
214 ti.rclTrack.yTop = pqp->yfrac*rectlBox.yTop ;
215 ti.rclTrack.xLeft = 0 ;
216 ti.rclTrack.yBottom = 0 ;//(1.0-pqp->yfrac) * rectlBox.yTop ;
217 ti.fs = TF_RIGHT|TF_TOP|TF_STANDARD|TF_SETPOINTERPOS|TF_ALLINBOUNDARY ;
218 WinSetPointer( HWND_DESKTOP,
219 WinQuerySysPointer( HWND_DESKTOP, SPTR_SIZENWSE, FALSE ) ) ;
220 WinTrackRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
223 pqp->xfrac = (float)ti.rclTrack.xRight / (float)rectlBox.xRight ;
224 pqp->yfrac = ((float)(ti.rclTrack.yTop-ti.rclTrack.yBottom) / (float)rectlBox.yTop) ;
225 rectlBox.yTop = ti.rclTrack.yTop - ti.rclTrack.yBottom ;
226 rectlBox.xRight = ti.rclTrack.xRight ;
228 double ratio = 1.560 ;
229 double xs = rectlBox.xRight - rectlBox.xLeft ;
230 double ys = rectlBox.yTop - rectlBox.yBottom ;
231 if( ys > xs/ratio ) { /* reduce ys to fit */
232 rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ;
234 else if( ys < xs/ratio ) { /* reduce xs to fit */
235 rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
238 WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
240 swp.x, swp.y,//+(short)(swp.cy*(1.0-pqp->yfrac)),
241 (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
242 WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
243 WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
253 /* fall through to the default control processing */
255 return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
258 MRESULT EXPENTRY QPrintersDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
260 ** Query printers and allow selection
264 static PPRQINFO3 pprq=NULL ;
265 static ULONG cPrinters ;
266 static USHORT usItem ;
267 static char *szPrinterName ;
275 szPrinterName = (char*) PVOIDFROMMP( mp2 ) ;
277 GetPrinters( &pprq, &cPrinters ) ;
278 hwndLB = WinWindowFromID( hwnd, IDD_QPRSLIST ) ;
279 for( i=0; i<cPrinters;i++ ) {
280 psz = *pprq[i].pszComment ? pprq[i].pszComment :
286 if( strcmp( pprq[i].pszName, szPrinterName ) == 0 )
292 MPFROMSHORT( iSelect ),
299 switch ( SHORT1FROMMP(mp1) ) {
302 strcpy( szPrinterName, pprq[usItem].pszName ) ;
312 if( SHORT1FROMMP( mp1 ) == IDD_QPRSLIST ) {
313 if( SHORT2FROMMP( mp1 ) == LN_SELECT ) {
314 usItem = (ULONG)WinSendMsg( hwndLB,
324 /* fall through to the default control processing */
325 return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
328 ULONG GetPrinters( PPRQINFO3 *pprq, ULONG *pcTot )
330 ** get a list of printers
334 ULONG cQueues, cbData ;
336 rc = SplEnumQueue( NULL, 3, NULL, 0, &cQueues, pcTot, &cbData, NULL ) ;
338 if( *pprq != NULL ) {
342 if( *pcTot == 0 ) { /* no printers */
345 *pprq = malloc( cbData ) ;
346 rc = SplEnumQueue( NULL,
357 MRESULT EXPENTRY PauseMsgDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
359 ** Pause message dialog box proc
362 static PPAUSEDATA ppdata = NULL ;
367 /* set the position so user can move out the way, and
368 have it come back there next time */
369 ppdata = (PPAUSEDATA) PVOIDFROMMP( mp2 ) ;
370 if( ppdata->pswp != NULL )
371 WinSetWindowPos( hwnd, HWND_TOP, ppdata->pswp->x, ppdata->pswp->y,
373 pszText = ppdata->pszMessage ;
374 while(*pszText==' ') ++pszText ;
375 WinSetDlgItemText( hwnd, IDD_PAUSETEXT, pszText ) ;
379 switch ( SHORT1FROMMP(mp1) ) {
382 WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
384 SHORT1FROMMP(mp1)==DID_OK?(MPARAM)1L:0L,
386 if( ppdata->pswp == NULL ) ppdata->pswp = (PSWP)malloc( sizeof(SWP) ) ;
387 WinQueryWindowPos( hwnd, ppdata->pswp ) ;
388 WinDismissDlg( hwnd, 0 ) ;
391 WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
393 MPFROMSHORT(IDM_PRINT),
402 /* fall through to the default control processing */
403 return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
406 void WinSetDlgItemFloatF( HWND hwnd, USHORT usID, int nDec, float flValue )
410 char achBuffer [ 34 ]; // default string field size ...
413 sprintf( fmt, "%%12.%df", nDec ) ;
414 sprintf( achBuffer, fmt, flValue ) ;
415 WinSetDlgItemText( hwnd, usID, achBuffer ) ;
418 void WinSetDlgItemFloat( HWND hwnd, USHORT usID, float flValue )
422 char achBuffer [ 34 ] ; // default string field size ...
425 sprintf( fmt, "%%12.%df", 4 ) ;
426 sprintf( achBuffer, fmt, flValue ) ;
427 WinSetDlgItemText( hwnd, usID, achBuffer ) ;
428 WinSetDlgItemText( hwnd, usID, achBuffer ) ;
431 void WinQueryDlgItemFloat( HWND hwnd, USHORT usID, float *pflValue )
435 char achBuffer [ 34 ] ; // default string field size ...
437 WinQueryDlgItemText( hwnd, usID, 34, achBuffer ) ;
438 *pflValue = (float) atof( achBuffer ) ;
441 MRESULT EXPENTRY SendCommandDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
443 ** Dialog for sending a command to gnuplot
444 ** //PM Petr Mikulik, 17. 8. 1999
447 #define TEXT_LENGTH 80
448 static char buf[TEXT_LENGTH+1];
449 extern void gp_execute (char *s);
454 WinSendDlgItemMsg( hwnd, IDM_DO_SENDCOMMAND, EM_SETTEXTLIMIT,
455 MPFROMSHORT (TEXT_LENGTH), 0L );
456 WinSetDlgItemText( hwnd, IDM_DO_SENDCOMMAND, buf );
457 WinSendDlgItemMsg( hwnd, IDM_DO_SENDCOMMAND, EM_SETSEL,
458 MPFROM2SHORT (0, strlen(buf)), 0L );
459 return (MRESULT)FALSE;
462 switch (COMMANDMSG (&msg)->cmd)
465 WinQueryDlgItemText( hwnd, IDM_DO_SENDCOMMAND, sizeof(buf), buf );
466 WinDismissDlg( hwnd, TRUE );
470 WinDismissDlg( hwnd, FALSE );
475 return ( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );