Author: manolo
Date: 2010-04-19 13:04:47 -0700 (Mon, 19 Apr 2010)
New Revision: 7533
Log:
Device hierarchy functional and documented.
Modified:
branches/branch-1.3-Fl_Printer/FL/Fl_Device.H
branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H
branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H
branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx
branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx
branches/branch-1.3-Fl_Printer/src/Fl_Device.cxx
branches/branch-1.3-Fl_Printer/src/Fl_GDI_Printer.cxx
branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx
branches/branch-1.3-Fl_Printer/src/Fl_Printer.cxx
branches/branch-1.3-Fl_Printer/src/Fl_Quartz_Printer.mm
Modified: branches/branch-1.3-Fl_Printer/FL/Fl_Device.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Device.H 2010-04-19 19:44:21 UTC
(rev 7532)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Device.H 2010-04-19 20:04:47 UTC
(rev 7533)
@@ -72,6 +72,10 @@
protected:
/** \brief The device type */
const char *type_;
+ /** \brief A string that identifies each subclass of Fl_Device.
+ *
+ Function type() applied to a device of this class returns this string.
+ */
static const char *device_type;
public:
/**
@@ -86,7 +90,7 @@
};
/**
- \brief A virtual class subclassed so that FLTK drawing functions use various
graphics drivers.
+ \brief A virtual class subclassed for each graphics driver FLTK uses.
*
The protected virtual methods of this class are those that a graphics driver
should implement to
support all of FLTK drawing functions.
@@ -279,7 +283,6 @@
virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int
cy) {};
public:
- /** A name that identifies each subclass of Fl_Device */
static const char *device_type;
Fl_Graphics_Driver() {};
@@ -331,15 +334,18 @@
*/
class Fl_Surface_Device : public Fl_Device {
protected:
+ /** \brief The graphics driver in use by this surface. */
Fl_Graphics_Driver *driver;
+ /** \brief Constructor that sets the graphics driver to use for the created
surface. */
Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {driver =
graphics_driver; };
public:
/** \brief the surface's graphics context, if there's one, NULL otherwise */
void *gc;
static const char *device_type;
- static Fl_Graphics_Driver *current();
- virtual Fl_Graphics_Driver *set_current(void);
- void set_driver(Fl_Graphics_Driver *graphics_driver) {driver =
graphics_driver;};
+ virtual void set_current(void);
+ /** \brief Sets the graphics driver of this drawing surface. */
+ inline void set_driver(Fl_Graphics_Driver *graphics_driver) {driver =
graphics_driver;};
+ /** \brief Returns the graphics driver of this drawing surface. */
inline Fl_Graphics_Driver *get_driver() {return driver; };
/** \brief the surface that currently receives graphics output */
static Fl_Surface_Device *surface() {return fl_surface; };
Modified: branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H 2010-04-19
19:44:21 UTC (rev 7532)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_PSfile_Device.H 2010-04-19
20:04:47 UTC (rev 7533)
@@ -250,6 +250,8 @@
\brief To send graphical output to a PostScript file.
*/
class Fl_PostScript_File_Device : public Fl_Paged_Device {
+protected:
+ Fl_PostScript_Graphics_Driver *get_driver();
public:
static const char *device_type;
Fl_PostScript_File_Device();
Modified: branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H
===================================================================
--- branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H 2010-04-19 19:44:21 UTC
(rev 7532)
+++ branches/branch-1.3-Fl_Printer/FL/Fl_Printer.H 2010-04-19 20:04:47 UTC
(rev 7533)
@@ -63,7 +63,7 @@
Fl_Printer myprinter;
myprinter.start_job();
\endcode
- Use Fl_PSfile_Device::file_chooser_title to customize the title of the file
chooser dialog that opens
+ Use Fl_PostScript_File_Device::file_chooser_title to customize the title of
the file chooser dialog that opens
when using the "Print To File" option of the print dialog.
Class Fl_RGB_Image prints but loses its transparency if it has one.
<li>MSWindows platform: Transparent Fl_RGB_Image 's don't print with exact
transparency on most printers.
@@ -100,17 +100,10 @@
int printable_rect(int *w, int *h);
void margins(int *left, int *top, int *right, int *bottom);
void origin(int x, int y);
-#ifdef FL_DOXYGEN
- void origin(int *x, int *y);
-#endif
void scale (float scale_x, float scale_y);
void rotate(float angle);
void translate(int x, int y);
void untranslate(void);
-#ifdef FL_DOXYGEN
- void print_widget(Fl_Widget* widget, int delta_x = 0, int delta_y = 0);
- void print_window_part(Fl_Window *win, int x, int y, int w, int h, int
delta_x = 0, int delta_y = 0);
-#endif
int end_page (void);
void end_job (void);
@@ -133,7 +126,7 @@
#endif // Fl_Printer (platform-dependent)
// Fl_Printer:: common for all platforms
- Fl_Graphics_Driver *set_current(void);
+ void set_current();
static const char *device_type;
public: // just to be sure ...
Modified: branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx 2010-04-19
19:44:21 UTC (rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Abstract_Printer.cxx 2010-04-19
20:04:47 UTC (rev 7533)
@@ -129,7 +129,8 @@
void Fl_Paged_Device::print_window_part(Fl_Window *win, int x, int y, int w,
int h, int delta_x, int delta_y)
{
int slice, width, offset, count = 0;
- Fl_Graphics_Driver *current =
Fl_Display_Device::display_device()->set_current();
+ Fl_Surface_Device *current = Fl_Surface_Device::surface();
+ Fl_Display_Device::display_device()->set_current();
Fl_Window *save_front = Fl::first_window();
win->show();
fl_gc = NULL;
@@ -147,8 +148,7 @@
image_data[count++] = fl_read_image(NULL, x + offset, y, width, h);
}
save_front->show();
- //current->set_current();
- fl_device = current;
+ current->set_current();
for ( int i = 0, offset = 0; i < count; i++, offset += slice) {
width = slice;
if (offset + width > w) width = w - offset;
Modified: branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx 2010-04-19
19:44:21 UTC (rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Clipboard_Device.cxx 2010-04-19
20:04:47 UTC (rev 7533)
@@ -24,7 +24,7 @@
//
// http://www.fltk.org/str.php
//
-#if defined(WIN32) || defined(__APPLE__)
+#if defined(WIN32) || defined(__APPLE__) || defined(FL_DOXYGEN)
#ifdef __APPLE__
#include "Fl_Clipboard_Device_mac.cxx"
Modified: branches/branch-1.3-Fl_Printer/src/Fl_Device.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Device.cxx 2010-04-19 19:44:21 UTC
(rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Device.cxx 2010-04-19 20:04:47 UTC
(rev 7533)
@@ -33,35 +33,24 @@
const char *Fl_Surface_Device::device_type = "Fl_Surface_Device";
const char *Fl_Display_Device::device_type = "Fl_Display_Device";
const char *Fl_Graphics_Driver::device_type = "Fl_Graphics_Driver";
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(FL_DOXYGEN)
const char *Fl_Quartz_Graphics_Driver::device_type =
"Fl_Quartz_Graphics_Driver";
-#elif defined(WIN32)
+#endif
+#if defined(WIN32) || defined(FL_DOXYGEN)
const char *Fl_GDI_Graphics_Driver::device_type = "Fl_GDI_Graphics_Driver";
-#else
+#endif
+#if !(defined(__APPLE__) || defined(WIN32))
const char *Fl_Xlib_Graphics_Driver::device_type = "Fl_Xlib_Graphics_Driver";
#endif
-/**
- @brief Sets this device (display, printer, local file) as the target of
future graphics calls.
- *
- @return The current target device of graphics calls.
- */
-Fl_Graphics_Driver *Fl_Surface_Device::set_current(void)
+/** \brief Use this drawing surface for future graphics requests. */
+void Fl_Surface_Device::set_current(void)
{
- Fl_Graphics_Driver *current = fl_device;
fl_device = driver;
- return current;
+ fl_surface = this;
}
-/**
- @brief Returns the current target device of graphics calls.
- */
-Fl_Graphics_Driver *Fl_Surface_Device::current(void)
-{
- return fl_device;
-}
-
//
// End of "$Id: Fl_Device.cxx 7520 2010-04-16 20:19:09Z manolo $".
//
Modified: branches/branch-1.3-Fl_Printer/src/Fl_GDI_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_GDI_Printer.cxx 2010-04-19
19:44:21 UTC (rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_GDI_Printer.cxx 2010-04-19
20:04:47 UTC (rev 7533)
@@ -37,7 +37,7 @@
Fl_Printer::Fl_Printer(void) : Fl_Paged_Device() {
hPr = NULL;
type_ = device_type;
- driver = Fl_Surface_Device::current();
+ driver = fl_device;
}
Fl_Printer::~Fl_Printer(void) {
@@ -112,7 +112,6 @@
WIN_SetupPrinterDeviceContext (hPr);
gc = (void *)fl_gc;
this->set_current();
- fl_surface = this;
}
return err;
}
@@ -136,7 +135,6 @@
}
}
hPr = NULL;
- fl_surface = Fl_Display_Device::display_device();
}
void Fl_Printer::absolute_printable_rect(int *x, int *y, int *w, int *h)
Modified: branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx 2010-04-19
19:44:21 UTC (rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_PS_Printer.cxx 2010-04-19
20:04:47 UTC (rev 7533)
@@ -34,6 +34,7 @@
const char *Fl_PostScript_Graphics_Driver::device_type =
"Fl_PostScript_Graphics_Driver";
const char *Fl_PostScript_File_Device::device_type =
"Fl_PostScript_File_Device";
+/** \brief Label of the PostScript file chooser window */
const char *Fl_PostScript_File_Device::file_chooser_title = "Select a .ps
file";
/**
@@ -59,11 +60,20 @@
type_ = device_type;
#ifdef __APPLE__
gc = fl_gc; // the display context is used by fl_text_extents()
-#elif !defined(WIN32)
+#endif
driver = new Fl_PostScript_Graphics_Driver();
-#endif
}
+
/**
+ \brief Returns the PostScript driver of this drawing surface.
+ */
+Fl_PostScript_Graphics_Driver *Fl_PostScript_File_Device::get_driver(void)
+{
+ return (Fl_PostScript_Graphics_Driver*)driver;
+}
+
+
+/**
@brief Begins the session where all graphics requests will go to a local
PostScript file.
*
Opens a file dialog entitled with
Fl_PostScript_File_Device::file_chooser_title to select an output PostScript
file.
@@ -81,12 +91,12 @@
fnfc.filter("PostScript\t*.ps\n");
// Show native chooser
if ( fnfc.show() ) return 1;
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
ps->output = fopen(fnfc.filename(), "w");
if(ps->output == NULL) return 2;
ps->ps_filename_ = strdup(fnfc.filename());
ps->start_postscript(pagecount, format, layout);
- fl_surface = this;
+ this->set_current();
return 0;
}
@@ -102,11 +112,11 @@
*/
int Fl_PostScript_File_Device::start_job (FILE *ps_output, int pagecount, enum
Fl_PostScript_Graphics_Driver::Page_Format format, enum
Fl_PostScript_Graphics_Driver::Page_Layout layout)
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
ps->output = ps_output;
ps->ps_filename_ = NULL;
ps->start_postscript(pagecount, format, layout);
- fl_surface = this;
+ this->set_current();
return 0;
}
@@ -114,7 +124,7 @@
@brief The destructor.
*/
Fl_PostScript_File_Device::~Fl_PostScript_File_Device() {
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
if (ps->ps_filename_) free(ps->ps_filename_);
if (driver) delete driver;
}
@@ -481,7 +491,6 @@
//returns 0 iff OK
{
int w, h, x;
- //this->set_current(); ???
if (format == A4) {
left_margin = 18;
top_margin = 18;
@@ -1200,7 +1209,7 @@
void Fl_PostScript_File_Device::margins(int *left, int *top, int *right, int
*bottom) // to implement
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
if(left) *left = (int)(ps->left_margin / ps->scale_x + .5);
if(right) *right = (int)(ps->left_margin / ps->scale_x + .5);
if(top) *top = (int)(ps->top_margin / ps->scale_y + .5);
@@ -1210,7 +1219,7 @@
int Fl_PostScript_File_Device::printable_rect(int *w, int *h)
//returns 0 iff OK
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
if(w) *w = (int)((ps->pw_ - 2 * ps->left_margin) / ps->scale_x + .5);
if(h) *h = (int)((ps->ph_ - 2 * ps->top_margin) / ps->scale_y + .5);
return 0;
@@ -1220,14 +1229,14 @@
{
x_offset = x;
y_offset = y;
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
fprintf(ps->output, "GR GR GS %d %d TR %f %f SC %d %d TR %f rotate GS\n",
ps->left_margin, ps->top_margin, ps->scale_x, ps->scale_y, x, y,
ps->angle);
}
void Fl_PostScript_File_Device::scale (float s_x, float s_y)
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
ps->scale_x = s_x;
ps->scale_y = s_y;
fprintf(ps->output, "GR GR GS %d %d TR %f %f SC %f rotate GS\n",
@@ -1236,7 +1245,7 @@
void Fl_PostScript_File_Device::rotate (float rot_angle)
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
ps->angle = - rot_angle;
fprintf(ps->output, "GR GR GS %d %d TR %f %f SC %d %d TR %f rotate GS\n",
ps->left_margin, ps->top_margin, ps->scale_x, ps->scale_y, x_offset,
y_offset, ps->angle);
@@ -1244,20 +1253,17 @@
void Fl_PostScript_File_Device::translate(int x, int y)
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
- fprintf(ps->output, "GS %d %d translate GS\n", x, y);
+ fprintf(get_driver()->output, "GS %d %d translate GS\n", x, y);
}
void Fl_PostScript_File_Device::untranslate(void)
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
- fprintf(ps->output, "GR GR\n");
+ fprintf(get_driver()->output, "GR GR\n");
}
int Fl_PostScript_File_Device::start_page (void)
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
- fl_device = driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
ps->page(ps->page_format_);
x_offset = 0;
y_offset = 0;
@@ -1275,7 +1281,7 @@
void Fl_PostScript_File_Device::end_job (void)
// finishes PostScript & closes file
{
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
if (ps->nPages) { // for eps nPages is 0 so it is fine ....
fprintf(ps->output, "CR\nGR\nGR\nGR\nSP\n restore\n");
if (!ps->pages_){
@@ -1305,7 +1311,6 @@
}
if (ps->close_cmd_) (*ps->close_cmd_)(ps->output);
Fl_Display_Device::display_device()->set_current();
- fl_surface = Fl_Display_Device::display_device();
}
#if ! (defined(__APPLE__) || defined(WIN32) )
@@ -1365,13 +1370,13 @@
printer, print_collate_button->value() ? 1 :
(int)(print_copies->value() + 0.5),
"FLTK", media);
- Fl_PostScript_Graphics_Driver *ps = (Fl_PostScript_Graphics_Driver*)driver;
+ Fl_PostScript_Graphics_Driver *ps = get_driver();
ps->output = popen(command, "w");
if (!ps->output) {
fl_alert("could not run command: %s\n",command);
return 1;
}
- fl_surface = this;
+ this->set_current();
return ps->start_postscript(pages, format, layout); // start printing
}
Modified: branches/branch-1.3-Fl_Printer/src/Fl_Printer.cxx
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Printer.cxx 2010-04-19 19:44:21 UTC
(rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Printer.cxx 2010-04-19 20:04:47 UTC
(rev 7533)
@@ -60,7 +60,7 @@
const char *Fl_Printer::device_type = "Fl_Printer";
-Fl_Graphics_Driver *Fl_Printer::set_current(void)
+void Fl_Printer::set_current()
{
#ifdef __APPLE__
fl_gc = (CGContextRef)gc;
@@ -69,7 +69,7 @@
#else
fl_gc = (_XGC*)gc;
#endif
- return this->Fl_Surface_Device::set_current();
+ this->Fl_Surface_Device::set_current();
}
//
Modified: branches/branch-1.3-Fl_Printer/src/Fl_Quartz_Printer.mm
===================================================================
--- branches/branch-1.3-Fl_Printer/src/Fl_Quartz_Printer.mm 2010-04-19
19:44:21 UTC (rev 7532)
+++ branches/branch-1.3-Fl_Printer/src/Fl_Quartz_Printer.mm 2010-04-19
20:04:47 UTC (rev 7533)
@@ -41,7 +41,7 @@
y_offset = 0;
scale_x = scale_y = 1.;
type_ = device_type;
- driver = Fl_Surface_Device::current();
+ driver = fl_device;
}
Fl_Printer::~Fl_Printer(void) {}
@@ -127,7 +127,6 @@
if (status != noErr) return 1;
y_offset = x_offset = 0;
this->set_current();
- fl_surface = this;
return 0;
}
@@ -291,7 +290,6 @@
}
PMSessionEndDocumentNoDialog(printSession);
Fl_Display_Device::display_device()->set_current();
- fl_surface = Fl_Display_Device::display_device();
fl_gc = 0;
Fl::first_window()->show();
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit