Better position of the Fl_Printer class in the Fl_Device class hierarchy.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8188 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2011-01-04 21:42:02 +00:00
parent 7b302635e7
commit e11677bfaf
5 changed files with 118 additions and 97 deletions

View File

@ -44,13 +44,12 @@
#include <commdlg.h> #include <commdlg.h>
#endif #endif
#if defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN) #if defined(__APPLE__) || defined(WIN32)
/** /*
\brief Print support under MSWindows and Mac OS X. Print support under MSWindows and Mac OS X.
*
Class Fl_System_Printer is implemented only on the MSWindows and Mac OS X platforms. Class Fl_System_Printer is implemented only on the MSWindows and Mac OS X platforms.
Use Fl_Printer instead that is cross-platform and has the same API. Use Fl_Printer instead that is cross-platform and has the same API.
Fl_Printer is typedef'ed to Fl_System_Printer under MSWindows and Mac OS X.
*/ */
class Fl_System_Printer : public Fl_Paged_Device { class Fl_System_Printer : public Fl_Paged_Device {
private: private:
@ -75,9 +74,6 @@ private:
#endif #endif
public: public:
static const char *device_type; static const char *device_type;
/**
@brief The constructor.
*/
Fl_System_Printer(void); Fl_System_Printer(void);
int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
int start_page (void); int start_page (void);
@ -91,78 +87,28 @@ public:
int end_page (void); int end_page (void);
void end_job (void); void end_job (void);
/**
@brief The destructor.
*/
~Fl_System_Printer(void); ~Fl_System_Printer(void);
#ifndef FL_DOXYGEN
public:
static const char *dialog_title;
static const char *dialog_printer;
static const char *dialog_range;
static const char *dialog_copies;
static const char *dialog_all;
static const char *dialog_pages;
static const char *dialog_from;
static const char *dialog_to;
static const char *dialog_properties;
static const char *dialog_copyNo;
static const char *dialog_print_button;
static const char *dialog_cancel_button;
static const char *dialog_print_to_file;
static const char *property_title;
static const char *property_pagesize;
static const char *property_mode;
static const char *property_use;
static const char *property_save;
static const char *property_cancel;
#endif // FL_DOXYGEN
}; // class Fl_System_Printer }; // class Fl_System_Printer
typedef Fl_System_Printer Fl_Printer;
#endif #endif
#if !(defined(__APPLE__) || defined(WIN32)) #if !(defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN))
/** /*
\brief Print support under Unix/Linux. Print support under Unix/Linux.
*
Class Fl_PostScript_Printer is implemented only on the Unix/Linux platform. Class Fl_PostScript_Printer is implemented only on the Unix/Linux platform.
Use Fl_Printer instead that is cross-platform and has the same API. Use Fl_Printer instead that is cross-platform and has the same API.
Fl_Printer is typedef'ed to Fl_PostScript_Printer under Unix/Linux.
*/ */
class Fl_PostScript_Printer : public Fl_PostScript_File_Device { class Fl_PostScript_Printer : public Fl_PostScript_File_Device {
public: public:
static const char *device_type; static const char *device_type;
int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL); int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL);
#ifndef FL_DOXYGEN
static const char *dialog_title;
static const char *dialog_printer;
static const char *dialog_range;
static const char *dialog_copies;
static const char *dialog_all;
static const char *dialog_pages;
static const char *dialog_from;
static const char *dialog_to;
static const char *dialog_properties;
static const char *dialog_copyNo;
static const char *dialog_print_button;
static const char *dialog_cancel_button;
static const char *dialog_print_to_file;
static const char *property_title;
static const char *property_pagesize;
static const char *property_mode;
static const char *property_use;
static const char *property_save;
static const char *property_cancel;
#endif // FL_DOXYGEN
}; };
typedef Fl_PostScript_Printer Fl_Printer;
#endif #endif
/** /**
* @brief OS-independent print support. * \brief OS-independent print support.
* *
Fl_Printer allows to use all FLTK drawing, color, text, and clip functions, and to have them operate Fl_Printer allows to use all FLTK drawing, color, text, and clip functions, and to have them operate
on printed page(s). There are two main, non exclusive, ways to use it. on printed page(s). There are two main, non exclusive, ways to use it.
@ -175,8 +121,6 @@ typedef Fl_PostScript_Printer Fl_Printer;
In both cases, begin by start_job(), start_page(), printable_rect() and origin() calls In both cases, begin by start_job(), start_page(), printable_rect() and origin() calls
and finish by end_page() and end_job() calls. and finish by end_page() and end_job() calls.
<p><b>Platform specifics</b> <p><b>Platform specifics</b>
<br>Fl_Printer is typedef'ed to Fl_PostScript_Printer under Unix/Linux
and to Fl_System_Printer otherwise. Both classes have the same API.
<ul> <ul>
<li>Unix/Linux platforms: <li>Unix/Linux platforms:
Class Fl_RGB_Image prints but loses its transparency if it has one. Class Fl_RGB_Image prints but loses its transparency if it has one.
@ -195,12 +139,10 @@ typedef Fl_PostScript_Printer Fl_Printer;
<li>Mac OS X platform: all graphics requests print as on display. <li>Mac OS X platform: all graphics requests print as on display.
</ul> </ul>
*/ */
#ifdef FL_DOXYGEN class Fl_Printer : public Fl_Paged_Device {
// this class is NOT compiled. It's here for Doxygen documentation purpose only
class Fl_Printer : public Fl_System_Printer, Fl_PostScript_Printer {
public: public:
static const char *device_type; static const char *device_type;
/** @brief The constructor */ /** \brief The constructor */
Fl_Printer(void); Fl_Printer(void);
int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); int start_job(int pagecount, int *frompage = NULL, int *topage = NULL);
int start_page(void); int start_page(void);
@ -213,7 +155,7 @@ public:
void untranslate(void); void untranslate(void);
int end_page (void); int end_page (void);
void end_job (void); void end_job (void);
/** @brief The destructor */ /** \brief The destructor */
~Fl_Printer(void); ~Fl_Printer(void);
/** \name These attributes are effective under the Xlib platform only. /** \name These attributes are effective under the Xlib platform only.
@ -239,8 +181,13 @@ public:
static const char *property_save; static const char *property_save;
static const char *property_cancel; static const char *property_cancel;
/** \} */ /** \} */
}; private:
#if defined(WIN32) || defined(__APPLE__)
Fl_System_Printer *printer;
#else
Fl_PostScript_Printer *printer;
#endif #endif
};
#endif // Fl_Printer_H #endif // Fl_Printer_H

View File

@ -34,13 +34,13 @@
extern HWND fl_window; extern HWND fl_window;
Fl_Printer::Fl_System_Printer(void) : Fl_Paged_Device() { Fl_System_Printer::Fl_System_Printer(void) : Fl_Paged_Device() {
hPr = NULL; hPr = NULL;
type_ = device_type; type_ = device_type;
driver(fl_graphics_driver); driver(fl_graphics_driver);
} }
Fl_Printer::~Fl_System_Printer(void) { Fl_System_Printer::~Fl_System_Printer(void) {
if (hPr) end_job(); if (hPr) end_job();
} }
@ -61,7 +61,7 @@ static void WIN_SetupPrinterDeviceContext(HDC prHDC)
} }
int Fl_Printer::start_job (int pagecount, int *frompage, int *topage) int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage)
// returns 0 iff OK // returns 0 iff OK
{ {
DWORD commdlgerr; DWORD commdlgerr;
@ -116,7 +116,7 @@ int Fl_Printer::start_job (int pagecount, int *frompage, int *topage)
return err; return err;
} }
void Fl_Printer::end_job (void) void Fl_System_Printer::end_job (void)
{ {
Fl_Display_Device::display_device()->set_current(); Fl_Display_Device::display_device()->set_current();
if (hPr != NULL) { if (hPr != NULL) {
@ -137,7 +137,7 @@ void Fl_Printer::end_job (void)
hPr = NULL; hPr = NULL;
} }
void Fl_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h) void Fl_System_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h)
{ {
POINT physPageSize; POINT physPageSize;
POINT pixelsPerInch; POINT pixelsPerInch;
@ -163,7 +163,7 @@ void Fl_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h)
origin(x_offset, y_offset); origin(x_offset, y_offset);
} }
void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom)
{ {
int x, y, w, h; int x, y, w, h;
absolute_printable_rect(&x, &y, &w, &h); absolute_printable_rect(&x, &y, &w, &h);
@ -173,14 +173,14 @@ void Fl_Printer::margins(int *left, int *top, int *right, int *bottom)
if (bottom) *bottom = y; if (bottom) *bottom = y;
} }
int Fl_Printer::printable_rect(int *w, int *h) int Fl_System_Printer::printable_rect(int *w, int *h)
{ {
int x, y; int x, y;
absolute_printable_rect(&x, &y, w, h); absolute_printable_rect(&x, &y, w, h);
return 0; return 0;
} }
int Fl_Printer::start_page (void) int Fl_System_Printer::start_page (void)
{ {
int rsult, w, h; int rsult, w, h;
@ -201,14 +201,14 @@ int Fl_Printer::start_page (void)
return rsult; return rsult;
} }
void Fl_Printer::origin (int deltax, int deltay) void Fl_System_Printer::origin (int deltax, int deltay)
{ {
SetWindowOrgEx(fl_gc, - left_margin - deltax, - top_margin - deltay, NULL); SetWindowOrgEx(fl_gc, - left_margin - deltax, - top_margin - deltay, NULL);
x_offset = deltax; x_offset = deltax;
y_offset = deltay; y_offset = deltay;
} }
void Fl_Printer::scale (float scalex, float scaley) void Fl_System_Printer::scale (float scalex, float scaley)
{ {
int w, h; int w, h;
SetWindowExtEx(fl_gc, (int)(720 / scalex + 0.5), (int)(720 / scaley + 0.5), NULL); SetWindowExtEx(fl_gc, (int)(720 / scalex + 0.5), (int)(720 / scaley + 0.5), NULL);
@ -216,7 +216,7 @@ void Fl_Printer::scale (float scalex, float scaley)
origin(0, 0); origin(0, 0);
} }
void Fl_Printer::rotate (float rot_angle) void Fl_System_Printer::rotate (float rot_angle)
{ {
XFORM mat; XFORM mat;
float angle; float angle;
@ -229,7 +229,7 @@ void Fl_Printer::rotate (float rot_angle)
SetWorldTransform(fl_gc, &mat); SetWorldTransform(fl_gc, &mat);
} }
int Fl_Printer::end_page (void) int Fl_System_Printer::end_page (void)
{ {
int rsult; int rsult;
@ -261,7 +261,7 @@ static void do_translate(int x, int y)
ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY); ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY);
} }
void Fl_Printer::translate (int x, int y) void Fl_System_Printer::translate (int x, int y)
{ {
do_translate(x, y); do_translate(x, y);
if (translate_stack_depth < translate_stack_max) { if (translate_stack_depth < translate_stack_max) {
@ -271,7 +271,7 @@ void Fl_Printer::translate (int x, int y)
} }
} }
void Fl_Printer::untranslate (void) void Fl_System_Printer::untranslate (void)
{ {
if (translate_stack_depth > 0) { if (translate_stack_depth > 0) {
translate_stack_depth--; translate_stack_depth--;

View File

@ -1471,7 +1471,7 @@ void Fl_PostScript_File_Device::end_job (void)
} }
#if ! (defined(__APPLE__) || defined(WIN32) ) #if ! (defined(__APPLE__) || defined(WIN32) )
int Fl_Printer::start_job(int pages, int *firstpage, int *lastpage) { int Fl_PostScript_Printer::start_job(int pages, int *firstpage, int *lastpage) {
enum Fl_Paged_Device::Page_Format format; enum Fl_Paged_Device::Page_Format format;
enum Fl_Paged_Device::Page_Layout layout; enum Fl_Paged_Device::Page_Layout layout;

View File

@ -77,6 +77,11 @@ const char *Fl_Printer::property_save = "Save";
const char *Fl_Printer::property_cancel = "Cancel"; const char *Fl_Printer::property_cancel = "Cancel";
const char *Fl_Printer::device_type = "Fl_Printer"; const char *Fl_Printer::device_type = "Fl_Printer";
#if defined(__APPLE__) || defined(WIN32)
const char *Fl_System_Printer::device_type = "Fl_Printer";
#elif !defined(FL_DOXYGEN)
const char *Fl_PostScript_Printer::device_type = "Fl_Printer";
#endif
#if defined(__APPLE__) || defined(WIN32) #if defined(__APPLE__) || defined(WIN32)
void Fl_System_Printer::set_current(void) void Fl_System_Printer::set_current(void)
@ -90,6 +95,75 @@ void Fl_System_Printer::set_current(void)
} }
#endif #endif
Fl_Printer::Fl_Printer(void) {
#if defined(WIN32) || defined(__APPLE__)
printer = new Fl_System_Printer();
#else
printer = new Fl_PostScript_Printer();
#endif
}
int Fl_Printer::start_job(int pagecount, int *frompage, int *topage)
{
return printer->start_job(pagecount, frompage, topage);
}
int Fl_Printer::start_page(void)
{
return printer->start_page();
}
int Fl_Printer::printable_rect(int *w, int *h)
{
return printer->printable_rect(w, h);
}
void Fl_Printer::margins(int *left, int *top, int *right, int *bottom)
{
printer->margins(left, top, right, bottom);
}
void Fl_Printer::origin(int x, int y)
{
printer->origin(x, y);
}
void Fl_Printer::scale(float scale_x, float scale_y)
{
printer->scale(scale_x, scale_y);
}
void Fl_Printer::rotate(float angle)
{
printer->rotate(angle);
}
void Fl_Printer::translate(int x, int y)
{
printer->translate(x, y);
}
void Fl_Printer::untranslate(void)
{
printer->untranslate();
}
int Fl_Printer::end_page (void)
{
return printer->end_page();
}
void Fl_Printer::end_job (void)
{
printer->end_job();
}
Fl_Printer::~Fl_Printer(void)
{
delete printer;
}
// //
// End of "$Id$". // End of "$Id$".
// //

View File

@ -47,7 +47,7 @@ Fl_System_Printer::Fl_System_Printer(void)
Fl_System_Printer::~Fl_System_Printer(void) {} Fl_System_Printer::~Fl_System_Printer(void) {}
int Fl_Printer::start_job (int pagecount, int *frompage, int *topage) int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage)
//printing using a Quartz graphics context //printing using a Quartz graphics context
//returns 0 iff OK //returns 0 iff OK
{ {
@ -139,7 +139,7 @@ int Fl_Printer::start_job (int pagecount, int *frompage, int *topage)
return 0; return 0;
} }
void Fl_Printer::margins(int *left, int *top, int *right, int *bottom) void Fl_System_Printer::margins(int *left, int *top, int *right, int *bottom)
{ {
PMPaper paper; PMPaper paper;
PMGetPageFormatPaper(pageFormat, &paper); PMGetPageFormatPaper(pageFormat, &paper);
@ -161,7 +161,7 @@ void Fl_Printer::margins(int *left, int *top, int *right, int *bottom)
} }
} }
int Fl_Printer::printable_rect(int *w, int *h) int Fl_System_Printer::printable_rect(int *w, int *h)
//returns 0 iff OK //returns 0 iff OK
{ {
OSStatus status; OSStatus status;
@ -178,7 +178,7 @@ int Fl_Printer::printable_rect(int *w, int *h)
return 0; return 0;
} }
void Fl_Printer::origin(int x, int y) void Fl_System_Printer::origin(int x, int y)
{ {
x_offset = x; x_offset = x;
y_offset = y; y_offset = y;
@ -191,7 +191,7 @@ void Fl_Printer::origin(int x, int y)
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
} }
void Fl_Printer::scale (float s_x, float s_y) void Fl_System_Printer::scale (float s_x, float s_y)
{ {
scale_x = s_x; scale_x = s_x;
scale_y = s_y; scale_y = s_y;
@ -204,7 +204,7 @@ void Fl_Printer::scale (float s_x, float s_y)
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
} }
void Fl_Printer::rotate (float rot_angle) void Fl_System_Printer::rotate (float rot_angle)
{ {
angle = - rot_angle * M_PI / 180.; angle = - rot_angle * M_PI / 180.;
CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc);
@ -216,20 +216,20 @@ void Fl_Printer::rotate (float rot_angle)
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
} }
void Fl_Printer::translate(int x, int y) void Fl_System_Printer::translate(int x, int y)
{ {
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, x, y ); CGContextTranslateCTM(fl_gc, x, y );
CGContextSaveGState(fl_gc); CGContextSaveGState(fl_gc);
} }
void Fl_Printer::untranslate(void) void Fl_System_Printer::untranslate(void)
{ {
CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc);
CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc);
} }
int Fl_Printer::start_page (void) int Fl_System_Printer::start_page (void)
{ {
OSStatus status = PMSessionBeginPageNoDialog(printSession, pageFormat, NULL); OSStatus status = PMSessionBeginPageNoDialog(printSession, pageFormat, NULL);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@ -278,7 +278,7 @@ int Fl_Printer::start_page (void)
return status != noErr; return status != noErr;
} }
int Fl_Printer::end_page (void) int Fl_System_Printer::end_page (void)
{ {
CGContextFlush(fl_gc); CGContextFlush(fl_gc);
CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc);
@ -289,7 +289,7 @@ int Fl_Printer::end_page (void)
return status != noErr; return status != noErr;
} }
void Fl_Printer::end_job (void) void Fl_System_Printer::end_job (void)
{ {
OSStatus status; OSStatus status;