00001
00002
00003
00004
00005 #include "FigureToPrint.h"
00006 #include "win_mem_alloc.h"
00007 #include "WindowList.h"
00008 #include "../../../modules/graphics/includes/xs2file.h"
00009
00010 extern HINSTANCE hdllInstance;
00011 extern int WindowsPrintScreen;
00012 extern int Printer_XRes;
00013 extern int Printer_YRes;
00014 extern void dos2win32 (char *filename, char *filename1);
00015 extern char GetPrinterOrientation(void);
00016 extern void Setscig_buzyState(BOOL state);
00017
00018 #define MAXSTR 255
00019 static char filename[MAXSTR], filename1[MAXSTR];
00020 extern LS ls;
00021
00022 BOOL FigureToPrint(int figurenumber,BOOL Postscript)
00023 {
00024 BOOL bOK=FALSE;
00025 struct BCG *ScilabGC=NULL;
00026 ScilabGC = getWindowXgcNumber (figurenumber);
00027
00028 if (ScilabGC)
00029 {
00030 if (Postscript)
00031 {
00032 PrintPs (ScilabGC);
00033 }
00034 else
00035 {
00036 CopyPrint (ScilabGC);
00037 }
00038 bOK=TRUE;
00039 }
00040 else bOK=FALSE;
00041 return bOK;
00042 }
00043
00044 int CopyPrint (struct BCG *ScilabGC)
00045 {
00046 int xPage, yPage;
00047 static DOCINFO di = {sizeof (DOCINFO), MSG_SCIMSG12, NULL};
00048 BOOL bError = FALSE;
00049 HDC hDCfromhWnd=NULL;
00050 HDC printer=NULL;
00051 LPGW lpgw;
00052 ABORTPROC lpfnAbortProc;
00053 DLGPROC lpfnPrintDlgProc;
00054 static PRINTDLG pd;
00055 HWND hwnd;
00056 RECT rect,RectRestore;
00057 PRINT pr;
00058
00059 integer SaveCurrentWindow=0;
00060
00061 SaveCurrentWindow=GetCurrentFigureWindows();
00062
00063 Setscig_buzyState(TRUE);
00064
00065 SetCurrentFigureWindows (ScilabGC->CurWindow);
00066
00067 lpgw = ScilabGC->lpgw;
00068 hwnd = ScilabGC->CWindow;
00069 hDCfromhWnd=TryToGetDC (hwnd);
00070
00071 printer = (HDC)GetPrinterDC();
00072
00073 if (NULL == printer)
00074 {
00075
00076 GetClientRect (hwnd, &RectRestore);
00077 scig_replay_hdc ('W', ScilabGC->CurWindow, hDCfromhWnd,RectRestore.right - RectRestore.left, RectRestore.bottom - RectRestore.top, 1);
00078 Setscig_buzyState(FALSE);
00079 return TRUE;
00080 }
00081
00082 pr.hdcPrn = printer;
00083 xPage = GetDeviceCaps (pr.hdcPrn, HORZRES);
00084 yPage = GetDeviceCaps (pr.hdcPrn, VERTRES);
00085
00086 GetClientRect (hwnd, &rect);
00087 SetLastError (0);
00088 if (SetWindowLong (hwnd, 4, (LONG) ((LP_PRINT) & pr)) == 0 && GetLastError () != 0)
00089 {
00090 sciprint (MSG_ERROR34);
00091 Setscig_buzyState(FALSE);
00092 return TRUE;
00093 }
00094 if (SetWindowLong(ScilabGC->hWndParent, 4, (LONG) ((LP_PRINT) & pr)) == 0 && GetLastError () != 0)
00095 {
00096 sciprint (MSG_ERROR34);
00097 Setscig_buzyState(FALSE);
00098 return TRUE;
00099 }
00100 PrintRegister ((LP_PRINT) & pr);
00101 EnableWindow (hwnd, FALSE);
00102
00103 pr.bUserAbort = FALSE;
00104 lpfnPrintDlgProc = (DLGPROC) MyGetProcAddress ("PrintDlgProc",PrintDlgProc);
00105 lpfnAbortProc = (ABORTPROC) MyGetProcAddress ("PrintAbortProc",PrintAbortProc);
00106 pr.hDlgPrint = CreateDialogParam (hdllInstance, "PrintDlgBox", hwnd, lpfnPrintDlgProc, (LPARAM) lpgw->Title);
00107 SetAbortProc (pr.hdcPrn, lpfnAbortProc);
00108
00109 if (StartDoc (pr.hdcPrn, &di) > 0)
00110 {
00111 if (StartPage (pr.hdcPrn) > 0)
00112 {
00113 int scalef = 1;
00114 SetMapMode (pr.hdcPrn, MM_TEXT);
00115 SetBkMode (pr.hdcPrn, TRANSPARENT);
00116 SetTextAlign (pr.hdcPrn, TA_LEFT | TA_BOTTOM);
00117 scalef = (int) (10.0 * ((double) xPage * yPage) / (6800.0 * 4725.0));
00118 GetClientRect (hwnd, &RectRestore);
00119
00120 scig_replay_hdc ('P', ScilabGC->CurWindow, hDCfromhWnd,RectRestore.right - RectRestore.left, RectRestore.bottom - RectRestore.top, 1);
00121 WindowsPrintScreen = 1;
00122 Printer_XRes = GetDeviceCaps (pr.hdcPrn, LOGPIXELSX);
00123 Printer_YRes = GetDeviceCaps (pr.hdcPrn, LOGPIXELSY);
00124 scig_replay_hdc ('P', ScilabGC->CurWindow, printer,xPage, yPage, scalef);
00125 WindowsPrintScreen = 0;
00126
00127 scig_replay_hdc ('W', ScilabGC->CurWindow,hDCfromhWnd,RectRestore.right - RectRestore.left, RectRestore.bottom - RectRestore.top, 1);
00128 if (EndPage (pr.hdcPrn) > 0) EndDoc (pr.hdcPrn);
00129 else bError = TRUE;
00130 }
00131 }
00132 else bError = TRUE;
00133
00134 if (!pr.bUserAbort)
00135 {
00136 EnableWindow (hwnd, TRUE);
00137 DestroyWindow (pr.hDlgPrint);
00138 }
00139 if (printer) {DeleteDC (printer); printer=NULL;}
00140 SetWindowLong (hwnd, 4, (LONG) (0L));
00141 SetWindowLong (ScilabGC->hWndParent, 4, (LONG) (0L));
00142 PrintUnregister ((LP_PRINT) & pr);
00143
00144 ReleaseDC (hwnd, hDCfromhWnd);
00145 SetCurrentFigureWindows (SaveCurrentWindow);
00146
00147 Setscig_buzyState(FALSE);
00148 InvalidateRect(hwnd,NULL,TRUE);
00149
00150 return bError || pr.bUserAbort;
00151 }
00152
00153 void PrintPs (struct BCG *ScilabGC)
00154 {
00155 HDC hPrinterDC=NULL;
00156 char *p1;
00157 char ori;
00159 ls.use_printer = 1;
00160 ls.colored = 1;
00161
00162 hPrinterDC=GetPrinterDC();
00163 if (hPrinterDC) {DeleteDC(hPrinterDC);hPrinterDC=NULL;}
00164
00166 if ((p1 = getenv ("TMPDIR")) == (char *) 0)
00167 {
00168 sciprint (MSG_WARNING15);
00169 return;
00170 }
00171 sprintf (filename, "%s/scilab-%d", p1, (int) ScilabGC->CurWindow);
00172
00173 dos2win32 (filename, filename1);
00174
00175 scig_toPs (ScilabGC->CurWindow, ls.colored, filename1, "Pos");
00176
00177 ori =GetPrinterOrientation();
00178
00179 if (ScilabPsToEps (ori, filename1, filename) == 0)
00180 {
00181 if (gp_printfile (hdllInstance, ScilabGC->hWndParent, filename,(char *) 0) == FALSE) sciprint (MSG_ERROR78);
00182 }
00185 }
00186