The R Project SVN R

Rev

Rev 4394 | Rev 5458 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4394 Rev 4649
Line 23... Line 23...
23
 *                          functions + nextpage(printer)
23
 *                          functions + nextpage(printer)
24
 *                          printers can be deleted by 'del(printer)'
24
 *                          printers can be deleted by 'del(printer)'
25
 */
25
 */
26
 
26
 
27
#include "internal.h"
27
#include "internal.h"
-
 
28
#include "rui.h"
28
 
29
 
29
 
30
 
30
/*
31
/*
31
 *  Internal printer deletion function.
32
 *  Internal printer deletion function.
32
 */
33
 */
33
static void private_delprinter(printer obj)
34
static void private_delprinter(printer obj)
34
{
35
{
35
        HDC h = (HDC) obj->handle;
36
    HDC h = (HDC) obj->handle;
36
	if (!obj || !h || (obj->kind != PrinterObject)) return;
37
    if (!obj || !h || (obj->kind != PrinterObject)) return;
37
        EndPage(h);
38
    EndPage(h);
38
        EndDoc(h);
39
    EndDoc(h);
39
        DeleteDC(h);
40
    DeleteDC(h);
40
        return;
41
    return;
41
}
42
}
42
 
43
 
43
/*
44
/*
44
 *  Create/return the base printer object.
45
 *  Create/return the base printer object.
45
 */
46
 */
46
static object get_printer_base(void)
47
static object get_printer_base(void)
47
{
48
{
48
	static object printer_base = NULL;
49
    static object printer_base = NULL;
49
 
50
 
50
	if (! printer_base)
51
    if (! printer_base)
51
		printer_base = new_object(BaseObject, 0, NULL);
52
	printer_base = new_object(BaseObject, 0, NULL);
52
	return printer_base;
53
    return printer_base;
53
}
54
}
54
 
55
 
55
static HDC chooseprinter() {
56
static HDC chooseprinter()
-
 
57
{
56
    PRINTDLG pd;
58
    PRINTDLG pd;
57
    HDC dc;
59
    HDC dc;
58
    char cwd[MAX_PATH];
60
    char cwd[MAX_PATH];
59
 
61
 
60
    GetCurrentDirectory(MAX_PATH,cwd);
62
    GetCurrentDirectory(MAX_PATH,cwd);
61
 
63
 
62
    pd.lStructSize = sizeof( PRINTDLG );
64
    pd.lStructSize = sizeof( PRINTDLG );
63
    pd.hwndOwner=NULL;
65
    pd.hwndOwner = NULL;
64
    pd.hDevMode=(HANDLE)NULL;
66
    pd.hDevMode = (HANDLE)NULL;
65
    pd.hDevNames=(HANDLE)NULL;
67
    pd.hDevNames = (HANDLE)NULL;
66
    pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS |
68
    pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS |
67
               PD_USEDEVMODECOPIES;
69
	PD_USEDEVMODECOPIES;
68
    pd.nFromPage=0;
70
    pd.nFromPage = 0;
69
    pd.nToPage=0;
71
    pd.nToPage = 0;
70
    pd.nMinPage=0;
72
    pd.nMinPage = 0;
71
    pd.nMaxPage=0;
73
    pd.nMaxPage = 0;
72
    pd.nCopies=1;
74
    pd.nCopies = 1;
73
    pd.hInstance=(HINSTANCE)NULL;
75
    pd.hInstance = (HINSTANCE)NULL;
74
    pd.lCustData = (LPARAM)0;
76
    pd.lCustData = (LPARAM)0;
75
    pd.lpfnPrintHook = 0;
77
    pd.lpfnPrintHook = 0;
76
    pd.lpfnSetupHook = 0;
78
    pd.lpfnSetupHook = 0;
77
    pd.lpPrintTemplateName = (LPCSTR) 0;
79
    pd.lpPrintTemplateName = (LPCSTR) 0;
78
    pd.lpSetupTemplateName = (LPCSTR) 0;
80
    pd.lpSetupTemplateName = (LPCSTR) 0;
Line 91... Line 93...
91
    DOCINFO docinfo;
93
    DOCINFO docinfo;
92
    printer obj;
94
    printer obj;
93
    HDC hDC = chooseprinter();
95
    HDC hDC = chooseprinter();
94
    double dd,AL;
96
    double dd,AL;
95
    int ww,hh,x0,y0;
97
    int ww,hh,x0,y0;
-
 
98
 
96
    if ( !hDC) return NULL;
99
    if ( !hDC) return NULL;
97
    obj = new_object(PrinterObject,(HANDLE) hDC,get_printer_base());
100
    obj = new_object(PrinterObject,(HANDLE) hDC,get_printer_base());
98
    if ( !obj ) {
101
    if ( !obj ) {
99
         askok("Insufficient memory for new printer");
102
	R_ShowMessage("Insufficient memory for new printer");
100
         DeleteDC(hDC);
103
	DeleteDC(hDC);
101
         return NULL;
104
	return NULL;
102
    }
105
    }
103
    if ((width==0.0) && (height==0.0)) {
106
    if ((width == 0.0) && (height == 0.0)) {
104
       ww = GetDeviceCaps(hDC,HORZRES);
107
	ww = GetDeviceCaps(hDC, HORZRES);
105
       hh = GetDeviceCaps(hDC,VERTRES);
108
	hh = GetDeviceCaps(hDC, VERTRES);
106
    }
109
    }
107
    else {
110
    else {
108
       if (width < 0.1) width = 0.1;
111
	if (width < 0.1) width = 0.1;
109
       if (height < 0.1) height = 0.1;
112
	if (height < 0.1) height = 0.1;
110
       dd =  GetDeviceCaps(hDC, HORZSIZE) / width;
113
	dd =  GetDeviceCaps(hDC, HORZSIZE) / width;
111
       AL = (dd < 1.0) ? dd : 1.0;
114
	AL = (dd < 1.0) ? dd : 1.0;
112
       dd = GetDeviceCaps(hDC, VERTSIZE) / height;
115
	dd = GetDeviceCaps(hDC, VERTSIZE) / height;
113
       AL = (dd < AL) ? dd : AL;
116
	AL = (dd < AL) ? dd : AL;
114
       ww = (AL * width) * GetDeviceCaps(hDC,LOGPIXELSX) / 25.4;
117
	ww = (AL * width) * GetDeviceCaps(hDC,LOGPIXELSX) / 25.4;
115
       hh = (AL * height) * GetDeviceCaps(hDC,LOGPIXELSY) / 25.4;
118
	hh = (AL * height) * GetDeviceCaps(hDC,LOGPIXELSY) / 25.4;
116
    }
119
    }
117
    x0 = (GetDeviceCaps(hDC,HORZRES) - ww) / 2;
120
    x0 = (GetDeviceCaps(hDC,HORZRES) - ww) / 2;
118
    y0 = (GetDeviceCaps(hDC,VERTRES) - hh) / 2;
121
    y0 = (GetDeviceCaps(hDC,VERTRES) - hh) / 2;
119
    obj->rect= rect(x0,y0,ww,hh);
122
    obj->rect = rect(x0,y0,ww,hh);
120
    obj->depth=GetDeviceCaps(hDC, BITSPIXEL)*
123
    obj->depth = GetDeviceCaps(hDC, BITSPIXEL)*
121
                   GetDeviceCaps(hDC, PLANES);
124
	GetDeviceCaps(hDC, PLANES);
122
    obj->die = private_delprinter;
125
    obj->die = private_delprinter;
123
    obj->drawstate = copydrawstate();
126
    obj->drawstate = copydrawstate();
124
    obj->drawstate->dest = obj;
127
    obj->drawstate->dest = obj;
125
 
128
 
126
    docinfo.cbSize = sizeof(DOCINFO);	/* set this size... */
129
    docinfo.cbSize = sizeof(DOCINFO);	/* set this size... */
Line 128... Line 131...
128
    docinfo.lpszOutput = 0;		/* no file output... */
131
    docinfo.lpszOutput = 0;		/* no file output... */
129
    docinfo.lpszDatatype = 0;
132
    docinfo.lpszDatatype = 0;
130
    docinfo.fwType = 0;
133
    docinfo.fwType = 0;
131
 
134
 
132
    if (StartDoc(hDC, &docinfo) <= 0) {
135
    if (StartDoc(hDC, &docinfo) <= 0) {
133
       askok("Impossible to start the print job");
136
	R_ShowMessage("Unable to start the print job");
134
       del(obj);
137
	del(obj);
135
       return NULL;
138
	return NULL;
136
    }
139
    }
137
 
140
 
138
    StartPage(hDC);
141
    StartPage(hDC);
139
 
142
 
140
    return obj;
143
    return obj;
141
}
144
}
142
 
145
 
143
 
146
 
144
void nextpage(printer p) {
147
void nextpage(printer p)
-
 
148
{
145
   if (!p || (p->kind != PrinterObject)) return;
149
    if (!p || (p->kind != PrinterObject)) return;
146
   EndPage((HDC) p->handle);
150
    EndPage((HDC) p->handle);
147
   StartPage((HDC) p->handle);
151
    StartPage((HDC) p->handle);
148
}
152
}