~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/wsci/wprinter.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************
 
2
 * Original source : GNUPLOT - win/wprinter.c 
 
3
 * modified for Scilab 
 
4
 *******************************************
 
5
 *
 
6
 * Copyright (C) 1992   Maurice Castro, Russell Lang
 
7
 *
 
8
 * Permission to use, copy, and distribute this software and its
 
9
 * documentation for any purpose with or without fee is hereby granted, 
 
10
 * provided that the above copyright notice appear in all copies and 
 
11
 * that both that copyright notice and this permission notice appear 
 
12
 * in supporting documentation.
 
13
 *
 
14
 * Permission to modify the software is granted, but not the right to
 
15
 * distribute the modified code.  Modifications are to be distributed 
 
16
 * as patches to released version.
 
17
 *  
 
18
 * This software is provided "as is" without express or implied warranty.
 
19
 *
 
20
 * AUTHORS
 
21
 *   Maurice Castro
 
22
 *   Russell Lang
 
23
 *
 
24
 * Modifications for Scilab 
 
25
 *   Jean-Philipe Chancelier 
 
26
 *   Bugs and mail : Scilab@inria.fr 
 
27
 */
 
28
#ifndef STRICT
 
29
#define STRICT
 
30
#endif
 
31
#include <windows.h>
 
32
#include <windowsx.h>
 
33
 
 
34
#ifndef __GNUC__
 
35
#include <commdlg.h>
 
36
#endif
 
37
 
 
38
#ifndef __ABSC__
 
39
#include <memory.h>
 
40
#endif
 
41
 
 
42
#include "wgnuplib.h"
 
43
#include "wresource.h"
 
44
#include "wcommon.h"
 
45
 
 
46
LPPRINT prlist = NULL;
 
47
/** list of selected printers **/
 
48
 
 
49
/********************************************
 
50
 * A Dialog Box for choosing the size for graphics 
 
51
 * on the printer page 
 
52
 ********************************************/
 
53
 
 
54
EXPORT BOOL CALLBACK
 
55
PrintSizeDlgProc (HWND hdlg, UINT wmsg, WPARAM wparam, LPARAM lparam)
 
56
{
 
57
 
 
58
  char buf[8];
 
59
  LPPRINT lpr;
 
60
  HWND parent;
 
61
  parent = GetParent (hdlg);
 
62
  lpr = (LPPRINT) GetWindowLong (parent, 4);
 
63
  switch (wmsg)
 
64
    {
 
65
    case WM_INITDIALOG:
 
66
      wsprintf (buf, "%d", lpr->pdef.x);
 
67
      SetDlgItemText (hdlg, PSIZE_DEFX, buf);
 
68
      wsprintf (buf, "%d", lpr->pdef.y);
 
69
      SetDlgItemText (hdlg, PSIZE_DEFY, buf);
 
70
      wsprintf (buf, "%d", lpr->poff.x);
 
71
      SetDlgItemText (hdlg, PSIZE_OFFX, buf);
 
72
      wsprintf (buf, "%d", lpr->poff.y);
 
73
      SetDlgItemText (hdlg, PSIZE_OFFY, buf);
 
74
      wsprintf (buf, "%d", lpr->psize.x);
 
75
      SetDlgItemText (hdlg, PSIZE_X, buf);
 
76
      wsprintf (buf, "%d", lpr->psize.y);
 
77
      SetDlgItemText (hdlg, PSIZE_Y, buf);
 
78
      CheckDlgButton (hdlg, PSIZE_DEF, TRUE);
 
79
      EnableWindow (GetDlgItem (hdlg, PSIZE_X), FALSE);
 
80
      EnableWindow (GetDlgItem (hdlg, PSIZE_Y), FALSE);
 
81
      return TRUE;
 
82
    case WM_COMMAND:
 
83
      switch (wparam)
 
84
        {
 
85
        case PSIZE_DEF:
 
86
          EnableWindow (GetDlgItem (hdlg, PSIZE_X), FALSE);
 
87
          EnableWindow (GetDlgItem (hdlg, PSIZE_Y), FALSE);
 
88
          return FALSE;
 
89
        case PSIZE_OTHER:
 
90
          EnableWindow (GetDlgItem (hdlg, PSIZE_X), TRUE);
 
91
          EnableWindow (GetDlgItem (hdlg, PSIZE_Y), TRUE);
 
92
          return FALSE;
 
93
        case IDOK:
 
94
          if (SendDlgItemMessage (hdlg, PSIZE_OTHER, BM_GETCHECK, 0, 0L))
 
95
            {
 
96
              SendDlgItemMessage (hdlg, PSIZE_X, WM_GETTEXT, 7, (LPARAM) ((LPSTR) buf));
 
97
              GetLInt (buf, &lpr->psize.x);
 
98
              SendDlgItemMessage (hdlg, PSIZE_Y, WM_GETTEXT, 7, (LPARAM) ((LPSTR) buf));
 
99
              GetLInt (buf, &lpr->psize.y);
 
100
            }
 
101
          else
 
102
            {
 
103
              lpr->psize.x = lpr->pdef.x;
 
104
              lpr->psize.y = lpr->pdef.y;
 
105
            }
 
106
          SendDlgItemMessage (hdlg, PSIZE_OFFX, WM_GETTEXT, 7, (LPARAM) ((LPSTR) buf));
 
107
          GetLInt (buf, &lpr->poff.x);
 
108
          SendDlgItemMessage (hdlg, PSIZE_OFFY, WM_GETTEXT, 7, (LPARAM) ((LPSTR) buf));
 
109
          GetLInt (buf, &lpr->poff.y);
 
110
 
 
111
          if (lpr->psize.x <= 0)
 
112
            lpr->psize.x = lpr->pdef.x;
 
113
          if (lpr->psize.y <= 0)
 
114
            lpr->psize.y = lpr->pdef.y;
 
115
 
 
116
          EndDialog (hdlg, IDOK);
 
117
          return TRUE;
 
118
        case IDCANCEL:
 
119
          EndDialog (hdlg, IDCANCEL);
 
120
          return TRUE;
 
121
        }
 
122
      break;
 
123
    }
 
124
  return FALSE;
 
125
}
 
126
 
 
127
 
 
128
/* GetWindowLong(hwnd, 4) must be available for use */
 
129
 
 
130
BOOL 
 
131
PrintSize (HDC printer, HWND hwnd, LPRECT lprect)
 
132
{
 
133
  HDC hdc;
 
134
  DLGPROC lpfnPrintSizeDlgProc;
 
135
  BOOL status = FALSE;
 
136
  PRINT pr;
 
137
  SetWindowLong (hwnd, 4, (LONG) ((LPPRINT) & pr));
 
138
  pr.poff.x = 0;
 
139
  pr.poff.y = 0;
 
140
  pr.psize.x = GetDeviceCaps (printer, HORZSIZE);
 
141
  pr.psize.y = GetDeviceCaps (printer, VERTSIZE);
 
142
  hdc = GetDC (hwnd);
 
143
  GetClientRect (hwnd, lprect);
 
144
  pr.pdef.x = MulDiv (lprect->right - lprect->left, 254, 10 * GetDeviceCaps (hdc, LOGPIXELSX));
 
145
  pr.pdef.y = MulDiv (lprect->bottom - lprect->top, 254, 10 * GetDeviceCaps (hdc, LOGPIXELSX));
 
146
  ReleaseDC (hwnd, hdc);
 
147
  lpfnPrintSizeDlgProc = (DLGPROC) MyGetProcAddress ("PrintSizeDlgProc",
 
148
                                                     PrintSizeDlgProc);
 
149
  if (DialogBox (hdllInstance, "PrintSizeDlgBox", hwnd, lpfnPrintSizeDlgProc)
 
150
      == IDOK)
 
151
    {
 
152
      lprect->left = MulDiv (pr.poff.x * 10, GetDeviceCaps (printer, LOGPIXELSX), 254);
 
153
      lprect->top = MulDiv (pr.poff.y * 10, GetDeviceCaps (printer, LOGPIXELSY), 254);
 
154
      lprect->right = lprect->left + MulDiv (pr.psize.x * 10, GetDeviceCaps (printer, LOGPIXELSX), 254);
 
155
      lprect->bottom = lprect->top + MulDiv (pr.psize.y * 10, GetDeviceCaps (printer, LOGPIXELSY), 254);
 
156
      status = TRUE;
 
157
    }
 
158
  SetWindowLong (hwnd, 4, (LONG) (0L));
 
159
  return status;
 
160
}
 
161
 
 
162
/******************************
 
163
 * Deals with a list of printers 
 
164
 ******************************/
 
165
 
 
166
void
 
167
PrintRegister (LPPRINT lpr)
 
168
{
 
169
  LPPRINT next;
 
170
  next = prlist;
 
171
  prlist = lpr;
 
172
  lpr->next = next;
 
173
}
 
174
 
 
175
LPPRINT
 
176
PrintFind (HDC hdc)
 
177
{
 
178
  LPPRINT this;
 
179
  this = prlist;
 
180
  while (this && (this->hdcPrn != hdc))
 
181
    {
 
182
      this = this->next;
 
183
    }
 
184
  return this;
 
185
}
 
186
 
 
187
void
 
188
PrintUnregister (LPPRINT lpr)
 
189
{
 
190
  LPPRINT this, prev;
 
191
  prev = (LPPRINT) NULL;
 
192
  this = prlist;
 
193
  while (this && (this != lpr))
 
194
    {
 
195
      prev = this;
 
196
      this = this->next;
 
197
    }
 
198
  if (this && (this == lpr))
 
199
    {
 
200
      /* unhook it */
 
201
      if (prev)
 
202
        prev->next = this->next;
 
203
      else
 
204
        prlist = this->next;
 
205
    }
 
206
}
 
207
 
 
208
/******************************
 
209
 * PrintDialogBox 
 
210
 ******************************/
 
211
 
 
212
/* GetWindowLong(GetParent(hDlg), 4) must be available for use */
 
213
 
 
214
EXPORT BOOL CALLBACK
 
215
PrintDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 
216
{
 
217
  LPPRINT lpr;
 
218
  HWND parent;
 
219
  parent = GetParent (hDlg);
 
220
  lpr = (LPPRINT) GetWindowLong (parent, 4);
 
221
  switch (message)
 
222
    {
 
223
    case WM_INITDIALOG:
 
224
      lpr->hDlgPrint = hDlg;
 
225
      SetWindowText (hDlg, (LPSTR) lParam);
 
226
      EnableMenuItem (GetSystemMenu (hDlg, FALSE), SC_CLOSE, MF_GRAYED);
 
227
      return TRUE;
 
228
    case WM_COMMAND:
 
229
      lpr->bUserAbort = TRUE;
 
230
      lpr->hDlgPrint = 0;
 
231
      EnableWindow (GetParent (hDlg), TRUE);
 
232
      EndDialog (hDlg, FALSE);
 
233
      return TRUE;
 
234
    }
 
235
  return FALSE;
 
236
}
 
237
 
 
238
 
 
239
EXPORT BOOL CALLBACK
 
240
PrintAbortProc (HDC hdcPrn, int code)
 
241
{
 
242
  MSG msg;
 
243
  LPPRINT lpr;
 
244
  lpr = PrintFind (hdcPrn);
 
245
  while (!lpr->bUserAbort && PeekMessage (&msg, 0, 0, 0, PM_REMOVE))
 
246
    {
 
247
      if (!lpr->hDlgPrint || !IsDialogMessage (lpr->hDlgPrint, &msg))
 
248
        {
 
249
          TranslateMessage (&msg);
 
250
          DispatchMessage (&msg);
 
251
        }
 
252
    }
 
253
  return (!lpr->bUserAbort);
 
254
}