From 4beb3b88e88c3ea070d0437d28b732a6f9d41174 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 5 Jan 2011 10:21:45 +0000 Subject: [PATCH] Renamed Fl_Device::type() to Fl_Device::class_name() to avoid conflict or confusion with Fl_Widget::type(). Added a setter function Fl_Device::class_name(const char *). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8190 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Device.H | 40 +++++++++++++++++++------------------ FL/Fl_Paged_Device.H | 4 ++-- FL/Fl_PostScript.H | 4 ++-- FL/Fl_Printer.H | 6 +++--- FL/x.H | 2 +- src/Fl_Bitmap.cxx | 2 +- src/Fl_Device.cxx | 14 ++++++------- src/Fl_Double_Window.cxx | 4 ++-- src/Fl_GDI_Printer.cxx | 2 +- src/Fl_Paged_Device.cxx | 2 +- src/Fl_Pixmap.cxx | 2 +- src/Fl_PostScript.cxx | 8 ++++---- src/Fl_Printer.cxx | 6 +++--- src/Fl_Quartz_Printer.mm | 2 +- src/Fl_cocoa.mm | 2 +- src/Fl_win32.cxx | 2 +- src/fl_draw_image_win32.cxx | 2 +- src/fl_draw_pixmap.cxx | 2 +- src/fl_font_win32.cxx | 2 +- src/fl_line_style.cxx | 2 +- src/fl_rect.cxx | 6 +++--- 21 files changed, 59 insertions(+), 57 deletions(-) diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index bb369d917..e128108dc 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -63,24 +63,26 @@ typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf); \brief All graphical output devices and all graphics systems. */ class FL_EXPORT Fl_Device { +private: + const char *type_; // pointer to class name protected: - /** \brief The device type */ - const char *type_; + /** \brief Sets the class name */ + inline void class_name(const char *name) { type_ = name;}; /** \brief A string that identifies each subclass of Fl_Device. - * - Function type() applied to a device of this class returns this string. + + Function class_name() applied to a device of this class returns this string. */ - static const char *device_type; + static const char *class_id; public: /** - @brief An RTTI emulation of device classes. + \brief Returns the name of the class of this object. * - The type of an instance of an Fl_Device subclass can be checked with code such as: + The class of an instance of an Fl_Device subclass can be checked with code such as: \code - if ( instance->type() == Fl_Printer::device_type ) { ... } + if ( instance->class_name() == Fl_Printer::class_id ) { ... } \endcode */ - inline const char *type() {return type_;}; + inline const char *class_name() {return type_;}; }; /** @@ -275,7 +277,7 @@ protected: virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {}; public: - static const char *device_type; + static const char *class_id; /** \brief The destructor */ virtual ~Fl_Graphics_Driver() {}; }; @@ -289,8 +291,8 @@ public: class FL_EXPORT Fl_Quartz_Graphics_Driver : public Fl_Graphics_Driver { public: /** \brief The constructor. */ - Fl_Quartz_Graphics_Driver() { type_ = device_type; }; - static const char *device_type; + Fl_Quartz_Graphics_Driver() { class_name( class_id); }; + static const char *class_id; void color(Fl_Color c); void color(uchar r, uchar g, uchar b); void draw(const char* str, int n, int x, int y); @@ -315,8 +317,8 @@ public: class FL_EXPORT Fl_GDI_Graphics_Driver : public Fl_Graphics_Driver { public: /** \brief The constructor. */ - Fl_GDI_Graphics_Driver() { type_ = device_type; }; - static const char *device_type; + Fl_GDI_Graphics_Driver() { class_name ( class_id); }; + static const char *class_id; void color(Fl_Color c); void color(uchar r, uchar g, uchar b); void draw(const char* str, int n, int x, int y); @@ -341,8 +343,8 @@ public: class Fl_Xlib_Graphics_Driver : public Fl_Graphics_Driver { public: /** \brief The constructor. */ - Fl_Xlib_Graphics_Driver() { type_ = device_type; }; - static const char *device_type; + Fl_Xlib_Graphics_Driver() { class_name ( class_id); }; + static const char *class_id; void color(Fl_Color c); void color(uchar r, uchar g, uchar b); void draw(const char* str, int n, int x, int y); @@ -369,7 +371,7 @@ protected: /** \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: - static const char *device_type; + static const char *class_id; virtual void set_current(void); /** \brief Sets the graphics driver of this drawing surface. */ inline void driver(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver;}; @@ -386,9 +388,9 @@ public: */ class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device { public: - static const char *device_type; + static const char *class_id; /** \brief A constructor that sets the graphics driver used by the display */ - Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device( graphics_driver) { type_ = device_type; }; + Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device( graphics_driver) { class_name( class_id); }; /** @brief Returns the platform's display device. */ diff --git a/FL/Fl_Paged_Device.H b/FL/Fl_Paged_Device.H index 1efb2aed1..99ac9e332 100644 --- a/FL/Fl_Paged_Device.H +++ b/FL/Fl_Paged_Device.H @@ -130,11 +130,11 @@ protected: void delete_image_list(); #endif /** \brief The constructor */ - Fl_Paged_Device() : Fl_Surface_Device(NULL) {type_ = device_type;}; + Fl_Paged_Device() : Fl_Surface_Device(NULL) {class_name( class_id);}; /** \brief The destructor */ virtual ~Fl_Paged_Device() {}; public: - static const char *device_type; + static const char *class_id; virtual int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); virtual int start_page(void); virtual int printable_rect(int *w, int *h); diff --git a/FL/Fl_PostScript.H b/FL/Fl_PostScript.H index 96ac6fb08..f6c4fdd55 100644 --- a/FL/Fl_PostScript.H +++ b/FL/Fl_PostScript.H @@ -63,7 +63,7 @@ */ class Fl_PostScript_Graphics_Driver : public Fl_Graphics_Driver { public: - static const char *device_type; + static const char *class_id; #ifndef FL_DOXYGEN public: enum SHAPE{NONE=0, LINE, LOOP, POLYGON, POINTS}; @@ -227,7 +227,7 @@ class Fl_PostScript_File_Device : public Fl_Paged_Device { protected: Fl_PostScript_Graphics_Driver *driver(); public: - static const char *device_type; + static const char *class_id; Fl_PostScript_File_Device(); ~Fl_PostScript_File_Device(); int start_job(int pagecount, enum Fl_Paged_Device::Page_Format format = Fl_Paged_Device::A4, diff --git a/FL/Fl_Printer.H b/FL/Fl_Printer.H index 50628e5db..ebb02095b 100644 --- a/FL/Fl_Printer.H +++ b/FL/Fl_Printer.H @@ -73,7 +73,7 @@ private: void absolute_printable_rect(int *x, int *y, int *w, int *h); #endif public: - static const char *device_type; + static const char *class_id; Fl_System_Printer(void); int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); int start_page (void); @@ -101,7 +101,7 @@ public: */ class Fl_PostScript_Printer : public Fl_PostScript_File_Device { public: - static const char *device_type; + static const char *class_id; int start_job(int pages, int *firstpage = NULL, int *lastpage = NULL); }; @@ -141,7 +141,7 @@ public: */ class Fl_Printer : public Fl_Paged_Device { public: - static const char *device_type; + static const char *class_id; /** \brief The constructor */ Fl_Printer(void); int start_job(int pagecount, int *frompage = NULL, int *topage = NULL); diff --git a/FL/x.H b/FL/x.H index 92ffc24c6..fc0222e14 100644 --- a/FL/x.H +++ b/FL/x.H @@ -112,7 +112,7 @@ extern FL_EXPORT ulong fl_event_time; typedef ulong Fl_Offscreen; # define fl_create_offscreen(w,h) \ XCreatePixmap(fl_display, \ - (fl_surface->type() == Fl_Display_Device::device_type ? \ + (fl_surface->class_name() == Fl_Display_Device::class_id ? \ fl_window : fl_xid(Fl::first_window()) ) , \ w, h, fl_visual->depth) // begin/end are macros that save the old state in local variables: diff --git a/src/Fl_Bitmap.cxx b/src/Fl_Bitmap.cxx index c28e2a4d5..1c49dc530 100644 --- a/src/Fl_Bitmap.cxx +++ b/src/Fl_Bitmap.cxx @@ -304,7 +304,7 @@ void Fl_GDI_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, HDC tempdc; int save; BOOL use_print_algo = false; - if (fl_surface->type() == Fl_Printer::device_type) { + if (fl_surface->class_name() == Fl_Printer::class_id) { static HMODULE hMod = NULL; if (!hMod) { hMod = LoadLibrary("MSIMG32.DLL"); diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx index 9b65a8233..d74ce11fb 100644 --- a/src/Fl_Device.cxx +++ b/src/Fl_Device.cxx @@ -29,18 +29,18 @@ #include #include -const char *Fl_Device::device_type = "Fl_Device"; -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"; +const char *Fl_Device::class_id = "Fl_Device"; +const char *Fl_Surface_Device::class_id = "Fl_Surface_Device"; +const char *Fl_Display_Device::class_id = "Fl_Display_Device"; +const char *Fl_Graphics_Driver::class_id = "Fl_Graphics_Driver"; #if defined(__APPLE__) || defined(FL_DOXYGEN) -const char *Fl_Quartz_Graphics_Driver::device_type = "Fl_Quartz_Graphics_Driver"; +const char *Fl_Quartz_Graphics_Driver::class_id = "Fl_Quartz_Graphics_Driver"; #endif #if defined(WIN32) || defined(FL_DOXYGEN) -const char *Fl_GDI_Graphics_Driver::device_type = "Fl_GDI_Graphics_Driver"; +const char *Fl_GDI_Graphics_Driver::class_id = "Fl_GDI_Graphics_Driver"; #endif #if !(defined(__APPLE__) || defined(WIN32)) -const char *Fl_Xlib_Graphics_Driver::device_type = "Fl_Xlib_Graphics_Driver"; +const char *Fl_Xlib_Graphics_Driver::class_id = "Fl_Xlib_Graphics_Driver"; #endif diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx index 1a91cee89..1df1da37c 100644 --- a/src/Fl_Double_Window.cxx +++ b/src/Fl_Double_Window.cxx @@ -180,8 +180,8 @@ void fl_copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int src BOOL alpha_ok = 0; // first try to alpha blend // if to printer, always try alpha_blend - int to_display = Fl_Surface_Device::surface()->type() == Fl_Display_Device::device_type; // true iff display output - if ( (to_display && fl_can_do_alpha_blending()) || Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { + int to_display = Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id; // true iff display output + if ( (to_display && fl_can_do_alpha_blending()) || Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) { alpha_ok = fl_alpha_blend(fl_gc, x, y, w, h, new_gc, srcx, srcy, w, h, blendfunc); } // if that failed (it shouldn't), still copy the bitmap over, but now alpha is 1 diff --git a/src/Fl_GDI_Printer.cxx b/src/Fl_GDI_Printer.cxx index d65efaddd..bcd1569ab 100644 --- a/src/Fl_GDI_Printer.cxx +++ b/src/Fl_GDI_Printer.cxx @@ -36,7 +36,7 @@ extern HWND fl_window; Fl_System_Printer::Fl_System_Printer(void) : Fl_Paged_Device() { hPr = NULL; - type_ = device_type; + class_name(class_id); driver(fl_graphics_driver); } diff --git a/src/Fl_Paged_Device.cxx b/src/Fl_Paged_Device.cxx index 2b14b08cd..dd3e32dec 100644 --- a/src/Fl_Paged_Device.cxx +++ b/src/Fl_Paged_Device.cxx @@ -32,7 +32,7 @@ #include #include -const char *Fl_Paged_Device::device_type = "Fl_Paged_Device"; +const char *Fl_Paged_Device::class_id = "Fl_Paged_Device"; /** diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index a61796e53..18f533761 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -145,7 +145,7 @@ void Fl_GDI_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP } fl_end_offscreen(); } - if (fl_surface->type() == Fl_Printer::device_type) { + if (fl_surface->class_name() == Fl_Printer::class_id) { typedef BOOL (WINAPI* fl_transp_func) (HDC,int,int,int,int,HDC,int,int,int,int,UINT); static HMODULE hMod = NULL; static fl_transp_func fl_TransparentBlt = NULL; diff --git a/src/Fl_PostScript.cxx b/src/Fl_PostScript.cxx index 5e98e899e..712cd3253 100644 --- a/src/Fl_PostScript.cxx +++ b/src/Fl_PostScript.cxx @@ -32,8 +32,8 @@ #include #include -const char *Fl_PostScript_Graphics_Driver::device_type = "Fl_PostScript_Graphics_Driver"; -const char *Fl_PostScript_File_Device::device_type = "Fl_PostScript_File_Device"; +const char *Fl_PostScript_Graphics_Driver::class_id = "Fl_PostScript_Graphics_Driver"; +const char *Fl_PostScript_File_Device::class_id = "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"; @@ -47,7 +47,7 @@ Fl_PostScript_Graphics_Driver::Fl_PostScript_Graphics_Driver(void) lang_level_ = 2; mask = 0; ps_filename_ = NULL; - type_ = device_type; + class_name(class_id); scale_x = scale_y = 1.; bg_r = bg_g = bg_b = 255; } @@ -62,7 +62,7 @@ Fl_PostScript_Graphics_Driver::~Fl_PostScript_Graphics_Driver() { */ Fl_PostScript_File_Device::Fl_PostScript_File_Device(void) { - type_ = device_type; + class_name(class_id); #ifdef __APPLE__ gc = fl_gc; // the display context is used by fl_text_extents() #endif diff --git a/src/Fl_Printer.cxx b/src/Fl_Printer.cxx index a1c33a661..3ed78a826 100644 --- a/src/Fl_Printer.cxx +++ b/src/Fl_Printer.cxx @@ -76,11 +76,11 @@ const char *Fl_Printer::property_save = "Save"; /** [this text may be customized at run-time] */ const char *Fl_Printer::property_cancel = "Cancel"; -const char *Fl_Printer::device_type = "Fl_Printer"; +const char *Fl_Printer::class_id = "Fl_Printer"; #if defined(__APPLE__) || defined(WIN32) -const char *Fl_System_Printer::device_type = "Fl_Printer"; +const char *Fl_System_Printer::class_id = "Fl_Printer"; #elif !defined(FL_DOXYGEN) -const char *Fl_PostScript_Printer::device_type = "Fl_Printer"; +const char *Fl_PostScript_Printer::class_id = "Fl_Printer"; #endif #if defined(__APPLE__) || defined(WIN32) diff --git a/src/Fl_Quartz_Printer.mm b/src/Fl_Quartz_Printer.mm index 31de4137a..23bef5c55 100644 --- a/src/Fl_Quartz_Printer.mm +++ b/src/Fl_Quartz_Printer.mm @@ -40,7 +40,7 @@ Fl_System_Printer::Fl_System_Printer(void) x_offset = 0; y_offset = 0; scale_x = scale_y = 1.; - type_ = device_type; + class_name(class_id); gc = 0; driver(fl_graphics_driver); } diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 7df208a97..40d0c104f 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -3256,7 +3256,7 @@ WindowRef Fl_X::window_ref() // so a CGRect matches exactly what is denoted x,y,w,h for clipping purposes CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h) { - if ( Fl_Surface_Device::surface()->type() == Fl_Printer::device_type ) return CGRectMake(x, y, w-1.5 , h-1.5 ); + if ( Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id ) return CGRectMake(x, y, w-1.5 , h-1.5 ); return CGRectMake(x, y, w > 0 ? w - 0.9 : 0, h > 0 ? h - 0.9 : 0); } diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index e8a09d2d0..bba615ad0 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1911,7 +1911,7 @@ void fl_cleanup_dc_list(void) { // clean up the list } Fl_Region XRectangleRegion(int x, int y, int w, int h) { - if (Fl_Surface_Device::surface()->type() == Fl_Display_Device::device_type) return CreateRectRgn(x,y,x+w,y+h); + if (Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id) return CreateRectRgn(x,y,x+w,y+h); // because rotation may apply, the rectangle becomes a polygon in device coords POINT pt[4] = { {x, y}, {x + w, y}, {x + w, y + h}, {x, y + h} }; LPtoDP(fl_gc, pt, 4); diff --git a/src/fl_draw_image_win32.cxx b/src/fl_draw_image_win32.cxx index 77f36038e..c9b3fd46a 100644 --- a/src/fl_draw_image_win32.cxx +++ b/src/fl_draw_image_win32.cxx @@ -255,7 +255,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, } } } - if(Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { + if(Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) { // if print context, device and logical units are not equal, so SetDIBitsToDevice // does not do the expected job, whereas StretchDIBits does it. StretchDIBits(fl_gc, x, y+j-k, w, k, 0, 0, w, k, diff --git a/src/fl_draw_pixmap.cxx b/src/fl_draw_pixmap.cxx index c1e64cf1e..25b485952 100644 --- a/src/fl_draw_pixmap.cxx +++ b/src/fl_draw_pixmap.cxx @@ -341,7 +341,7 @@ int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) { #endif #ifdef __APPLE_QUARTZ__ - if (fl_graphics_driver->type() == Fl_Quartz_Graphics_Driver::device_type ) { + if (fl_graphics_driver->class_name() == Fl_Quartz_Graphics_Driver::class_id ) { bool transparent = (transparent_index>=0); transparent = true; U32 *array = new U32[d.w * d.h], *q = array; diff --git a/src/fl_font_win32.cxx b/src/fl_font_win32.cxx index 31760c463..63d51686a 100644 --- a/src/fl_font_win32.cxx +++ b/src/fl_font_win32.cxx @@ -250,7 +250,7 @@ static void on_printer_extents_update(int &dx, int &dy, int &w, int &h) // if printer context, extents shd be converted to logical coords #define EXTENTS_UPDATE(x,y,w,h) \ - if (Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { on_printer_extents_update(x,y,w,h); } + if (Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) { on_printer_extents_update(x,y,w,h); } static unsigned short *ext_buff = NULL; // UTF-16 converted version of input UTF-8 string static unsigned wc_len = 0; // current string buffer dimension diff --git a/src/fl_line_style.cxx b/src/fl_line_style.cxx index 87f00678c..a22b1c30a 100644 --- a/src/fl_line_style.cxx +++ b/src/fl_line_style.cxx @@ -127,7 +127,7 @@ void Fl_Graphics_Driver::line_style(int style, int width, char* dashes) { fl_quartz_line_width_ = (float)width; fl_quartz_line_cap_ = Cap[(style>>8)&3]; // when printing kCGLineCapSquare seems better for solid lines - if ( Fl_Surface_Device::surface()->type() == Fl_Printer::device_type && style == FL_SOLID && dashes == NULL ) { + if ( Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id && style == FL_SOLID && dashes == NULL ) { fl_quartz_line_cap_ = kCGLineCapSquare; } fl_quartz_line_join_ = Join[(style>>12)&3]; diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx index b050c01cf..ea9c10949 100644 --- a/src/fl_rect.cxx +++ b/src/fl_rect.cxx @@ -49,7 +49,7 @@ extern int fl_line_width_; #ifdef __APPLE_QUARTZ__ extern float fl_quartz_line_width_; -#define USINGQUARTZPRINTER (Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) +#define USINGQUARTZPRINTER (Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) #endif #ifdef USE_X11 @@ -627,7 +627,7 @@ int Fl_Graphics_Driver::not_clipped(int x, int y, int w, int h) { return XRectInRegion(r, x, y, w, h); #elif defined(WIN32) RECT rect; - if (Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { // in case of print context, convert coords from logical to device + if (Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) { // in case of print context, convert coords from logical to device POINT pt[2] = { {x, y}, {x + w, y + h} }; LPtoDP(fl_gc, pt, 2); rect.left = pt[0].x; rect.top = pt[0].y; rect.right = pt[1].x; rect.bottom = pt[1].y; @@ -687,7 +687,7 @@ int Fl_Graphics_Driver::clip_box(int x, int y, int w, int h, int& X, int& Y, int } else { // partial intersection RECT rect; GetRgnBox(temp, &rect); - if(Fl_Surface_Device::surface()->type() == Fl_Printer::device_type) { // if print context, convert coords from device to logical + if(Fl_Surface_Device::surface()->class_name() == Fl_Printer::class_id) { // if print context, convert coords from device to logical POINT pt[2] = { {rect.left, rect.top}, {rect.right, rect.bottom} }; DPtoLP(fl_gc, pt, 2); X = pt[0].x; Y = pt[0].y; W = pt[1].x - X; H = pt[1].y - Y;