Rewrite all window icon-related Fl_Window API with the window driver approach.

It seems this allows not to #include <windows.h> in the public header files.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11342 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2016-03-10 22:26:40 +00:00
parent 7098924b82
commit 31fcd84ca9
9 changed files with 152 additions and 88 deletions
+2 -23
View File
@@ -23,7 +23,8 @@
#define Fl_Window_H #define Fl_Window_H
#ifdef WIN32 #ifdef WIN32
#include <windows.h> //#include <windows.h>
typedef struct HICON__* HICON;
#endif #endif
#include "Fl_Group.H" #include "Fl_Group.H"
@@ -75,22 +76,6 @@ class FL_EXPORT Fl_Window : public Fl_Group {
Fl_X *i; // points at the system-specific stuff, but exists only after the window is mapped Fl_X *i; // points at the system-specific stuff, but exists only after the window is mapped
Fl_Window_Driver *pWindowDriver; // points at the system-specific stuff at window creatino time Fl_Window_Driver *pWindowDriver; // points at the system-specific stuff at window creatino time
struct icon_data {
const void *legacy_icon;
Fl_RGB_Image **icons;
int count;
#ifdef WIN32
HICON big_icon;
HICON small_icon;
#elif defined(__APPLE__) // PORTME: Fl_Window_Driver - per-window icons, move to FL_X/Fl_Window_Driver
// not needed
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: define storage for per-window icons here if needed"
#else // X11
// not needed
#endif
};
const char* iconlabel_; const char* iconlabel_;
char* xclass_; char* xclass_;
struct icon_data *icon_; struct icon_data *icon_;
@@ -422,12 +407,6 @@ public:
#ifdef WIN32 #ifdef WIN32
static void default_icons(HICON big_icon, HICON small_icon); static void default_icons(HICON big_icon, HICON small_icon);
void icons(HICON big_icon, HICON small_icon); void icons(HICON big_icon, HICON small_icon);
#elif defined(__APPLE__) // PORTME: Fl_Window_Driver - per-window icon
// not needed
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: define functions to handle window icons here if needed"
#else // X11
// not needed
#endif #endif
/* for legacy compatibility */ /* for legacy compatibility */
+7
View File
@@ -36,8 +36,11 @@ class Fl_Image;
*/ */
class FL_EXPORT Fl_Window_Driver { class FL_EXPORT Fl_Window_Driver {
friend class Fl_Window; friend class Fl_Window;
friend class Fl_X;
protected: protected:
Fl_Window *pWindow; Fl_Window *pWindow;
struct icon_data;
icon_data *icon_;
struct shape_data_type; struct shape_data_type;
shape_data_type *shape_data_; ///< non-null means the window has a non-rectangular shape shape_data_type *shape_data_; ///< non-null means the window has a non-rectangular shape
public: public:
@@ -55,6 +58,10 @@ public:
void shape_pixmap_(Fl_Image* pixmap); void shape_pixmap_(Fl_Image* pixmap);
virtual void shape(const Fl_Image* img) {} virtual void shape(const Fl_Image* img) {}
virtual void shape_alpha_(Fl_Image* img, int offset) {} virtual void shape_alpha_(Fl_Image* img, int offset) {}
virtual void icons(const Fl_RGB_Image *icons[], int count) {}
virtual const void *icon() const {return NULL;}
virtual void icon(const void * ic) {}
virtual void free_icons() {}
}; };
+4 -40
View File
@@ -44,8 +44,6 @@ void Fl_Window::_Fl_Window() {
} }
i = 0; i = 0;
xclass_ = 0; xclass_ = 0;
icon_ = new icon_data;
memset(icon_, 0, sizeof(*icon_));
iconlabel_ = 0; iconlabel_ = 0;
resizable(0); resizable(0);
size_range_set = 0; size_range_set = 0;
@@ -91,7 +89,6 @@ Fl_Window::~Fl_Window() {
free(xclass_); free(xclass_);
} }
free_icons(); free_icons();
delete icon_;
delete pWindowDriver; delete pWindowDriver;
} }
@@ -342,61 +339,28 @@ void Fl_Window::icon(const Fl_RGB_Image *icon) {
\see Fl_Window::icon(const Fl_RGB_Image *) \see Fl_Window::icon(const Fl_RGB_Image *)
*/ */
void Fl_Window::icons(const Fl_RGB_Image *icons[], int count) { void Fl_Window::icons(const Fl_RGB_Image *icons[], int count) {
free_icons(); pWindowDriver->icons(icons, count);
if (count > 0) {
icon_->icons = new Fl_RGB_Image*[count];
icon_->count = count;
// FIXME: Fl_RGB_Image lacks const modifiers on methods
for (int i = 0;i < count;i++)
icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy();
}
if (i)
i->set_icons();
} }
/** Gets the current icon window target dependent data. /** Gets the current icon window target dependent data.
\deprecated in 1.3.3 \deprecated in 1.3.3
*/ */
const void *Fl_Window::icon() const { const void *Fl_Window::icon() const {
return icon_->legacy_icon; return pWindowDriver->icon();
} }
/** Sets the current icon window target dependent data. /** Sets the current icon window target dependent data.
\deprecated in 1.3.3 \deprecated in 1.3.3
*/ */
void Fl_Window::icon(const void * ic) { void Fl_Window::icon(const void * ic) {
free_icons(); pWindowDriver->icon(ic);
icon_->legacy_icon = ic;
} }
/** Deletes all icons previously attached to the window. /** Deletes all icons previously attached to the window.
\see Fl_Window::icons(const Fl_RGB_Image *icons[], int count) \see Fl_Window::icons(const Fl_RGB_Image *icons[], int count)
*/ */
void Fl_Window::free_icons() { void Fl_Window::free_icons() {
int i; pWindowDriver->free_icons();
icon_->legacy_icon = 0L;
if (icon_->icons) {
for (i = 0;i < icon_->count;i++)
delete icon_->icons[i];
delete [] icon_->icons;
icon_->icons = 0L;
}
icon_->count = 0;
#ifdef WIN32
if (icon_->big_icon)
DestroyIcon(icon_->big_icon);
if (icon_->small_icon)
DestroyIcon(icon_->small_icon);
icon_->big_icon = NULL;
icon_->small_icon = NULL;
#endif
} }
+12 -19
View File
@@ -25,6 +25,7 @@
#ifndef FL_DOXYGEN #ifndef FL_DOXYGEN
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Window_Driver.H> #include <FL/Fl_Window_Driver.H>
#include <src/Drivers/WinAPI//Fl_WinAPI_Window_Driver.H>
#include <FL/fl_utf8.h> #include <FL/fl_utf8.h>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
@@ -1764,7 +1765,7 @@ Fl_X* Fl_X::make(Fl_Window* w) {
wcw.lpfnWndProc = (WNDPROC)WndProc; wcw.lpfnWndProc = (WNDPROC)WndProc;
wcw.cbClsExtra = wcw.cbWndExtra = 0; wcw.cbClsExtra = wcw.cbWndExtra = 0;
wcw.hInstance = fl_display; wcw.hInstance = fl_display;
if (!w->icon() && !w->icon_->count) if (!w->icon() && !w->pWindowDriver->icon_->count)
w->icon((void *)LoadIcon(NULL, IDI_APPLICATION)); w->icon((void *)LoadIcon(NULL, IDI_APPLICATION));
wcw.hIcon = wcw.hIconSm = (HICON)w->icon(); wcw.hIcon = wcw.hIconSm = (HICON)w->icon();
wcw.hCursor = LoadCursor(NULL, IDC_ARROW); wcw.hCursor = LoadCursor(NULL, IDC_ARROW);
@@ -2175,24 +2176,24 @@ void Fl_X::set_icons() {
big_icon = NULL; big_icon = NULL;
small_icon = NULL; small_icon = NULL;
if (w->icon_->count) { if (w->pWindowDriver->icon_->count) {
const Fl_RGB_Image *best_big, *best_small; const Fl_RGB_Image *best_big, *best_small;
best_big = find_best_icon(GetSystemMetrics(SM_CXICON), best_big = find_best_icon(GetSystemMetrics(SM_CXICON),
(const Fl_RGB_Image **)w->icon_->icons, (const Fl_RGB_Image **)w->pWindowDriver->icon_->icons,
w->icon_->count); w->pWindowDriver->icon_->count);
best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON), best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON),
(const Fl_RGB_Image **)w->icon_->icons, (const Fl_RGB_Image **)w->pWindowDriver->icon_->icons,
w->icon_->count); w->pWindowDriver->icon_->count);
if (best_big != NULL) if (best_big != NULL)
big_icon = image_to_icon(best_big, true, 0, 0); big_icon = image_to_icon(best_big, true, 0, 0);
if (best_small != NULL) if (best_small != NULL)
small_icon = image_to_icon(best_small, true, 0, 0); small_icon = image_to_icon(best_small, true, 0, 0);
} else { } else {
if ((w->icon_->big_icon != NULL) || (w->icon_->small_icon != NULL)) { if ((w->pWindowDriver->icon_->big_icon != NULL) || (w->pWindowDriver->icon_->small_icon != NULL)) {
big_icon = w->icon_->big_icon; big_icon = w->pWindowDriver->icon_->big_icon;
small_icon = w->icon_->small_icon; small_icon = w->pWindowDriver->icon_->small_icon;
} else { } else {
big_icon = default_big_icon; big_icon = default_big_icon;
small_icon = default_small_icon; small_icon = default_small_icon;
@@ -2244,16 +2245,8 @@ void Fl_Window::default_icons(HICON big_icon, HICON small_icon) {
\see Fl_Window::icons(const Fl_RGB_Image *[], int) \see Fl_Window::icons(const Fl_RGB_Image *[], int)
*/ */
void Fl_Window::icons(HICON big_icon, HICON small_icon) { void Fl_Window::icons(HICON big_icon, HICON small_icon) {
free_icons(); ((Fl_WinAPI_Window_Driver*)pWindowDriver)->icons(big_icon, small_icon);
}
if (big_icon != NULL)
icon_->big_icon = CopyIcon(big_icon);
if (small_icon != NULL)
icon_->small_icon = CopyIcon(small_icon);
if (i)
i->set_icons();
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
+5 -5
View File
@@ -2531,8 +2531,8 @@ void Fl_X::make_xid(Fl_Window* win, XVisualInfo *visual, Colormap colormap)
fl_show_iconic = 0; fl_show_iconic = 0;
showit = 0; showit = 0;
} }
if (win->icon_->legacy_icon) { if (win->pWindowDriver->icon_->legacy_icon) {
hints->icon_pixmap = (Pixmap)win->icon_->legacy_icon; hints->icon_pixmap = (Pixmap)win->pWindowDriver->icon_->legacy_icon;
hints->flags |= IconPixmapHint; hints->flags |= IconPixmapHint;
} }
XSetWMHints(fl_display, xp->xid, hints); XSetWMHints(fl_display, xp->xid, hints);
@@ -2728,8 +2728,8 @@ void Fl_X::set_icons() {
unsigned long *net_wm_icons; unsigned long *net_wm_icons;
size_t net_wm_icons_size; size_t net_wm_icons_size;
if (w->icon_->count) { if (w->pWindowDriver->icon_->count) {
icons_to_property((const Fl_RGB_Image **)w->icon_->icons, w->icon_->count, icons_to_property((const Fl_RGB_Image **)w->pWindowDriver->icon_->icons, w->pWindowDriver->icon_->count,
&net_wm_icons, &net_wm_icons_size); &net_wm_icons, &net_wm_icons_size);
} else { } else {
net_wm_icons = default_net_wm_icons; net_wm_icons = default_net_wm_icons;
@@ -2739,7 +2739,7 @@ void Fl_X::set_icons() {
XChangeProperty (fl_display, xid, fl_NET_WM_ICON, XA_CARDINAL, 32, XChangeProperty (fl_display, xid, fl_NET_WM_ICON, XA_CARDINAL, 32,
PropModeReplace, (unsigned char*) net_wm_icons, net_wm_icons_size); PropModeReplace, (unsigned char*) net_wm_icons, net_wm_icons_size);
if (w->icon_->count) { if (w->pWindowDriver->icon_->count) {
delete [] net_wm_icons; delete [] net_wm_icons;
net_wm_icons = 0L; net_wm_icons = 0L;
net_wm_icons_size = 0; net_wm_icons_size = 0;
+14 -1
View File
@@ -26,6 +26,7 @@
#define FL_WINAPI_WINDOW_DRIVER_H #define FL_WINAPI_WINDOW_DRIVER_H
#include <FL/Fl_Window_Driver.H> #include <FL/Fl_Window_Driver.H>
#include <windows.h>
/* /*
Move everything here that manages the native window interface. Move everything here that manages the native window interface.
@@ -42,6 +43,14 @@
? where do we handle the interface between OpenGL/DirectX and Cocoa/WIN32/Glx? ? where do we handle the interface between OpenGL/DirectX and Cocoa/WIN32/Glx?
*/ */
struct Fl_Window_Driver::icon_data {
const void *legacy_icon;
Fl_RGB_Image **icons;
int count;
HICON big_icon;
HICON small_icon;
};
struct Fl_Window_Driver::shape_data_type { struct Fl_Window_Driver::shape_data_type {
int lw_; ///< width of shape image int lw_; ///< width of shape image
int lh_; ///< height of shape image int lh_; ///< height of shape image
@@ -59,10 +68,14 @@ public:
~Fl_WinAPI_Window_Driver(); ~Fl_WinAPI_Window_Driver();
virtual void shape(const Fl_Image* img); virtual void shape(const Fl_Image* img);
virtual void draw(); virtual void draw();
virtual void icons(const Fl_RGB_Image *icons[], int count);
virtual const void *icon() const;
virtual void icon(const void * ic);
virtual void free_icons();
void icons(HICON big_icon, HICON small_icon);
}; };
#endif // FL_WINAPI_WINDOW_DRIVER_H #endif // FL_WINAPI_WINDOW_DRIVER_H
// //
@@ -30,6 +30,8 @@ Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w)
Fl_WinAPI_Window_Driver::Fl_WinAPI_Window_Driver(Fl_Window *win) Fl_WinAPI_Window_Driver::Fl_WinAPI_Window_Driver(Fl_Window *win)
: Fl_Window_Driver(win) : Fl_Window_Driver(win)
{ {
icon_ = new Fl_Window_Driver::icon_data;
memset(icon_, 0, sizeof(Fl_Window_Driver::icon_data));
} }
Fl_WinAPI_Window_Driver::~Fl_WinAPI_Window_Driver() Fl_WinAPI_Window_Driver::~Fl_WinAPI_Window_Driver()
@@ -190,6 +192,61 @@ void Fl_WinAPI_Window_Driver::draw() {
} Fl_Window_Driver::draw(); } Fl_Window_Driver::draw();
} }
void Fl_WinAPI_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) {
free_icons();
if (count > 0) {
icon_->icons = new Fl_RGB_Image*[count];
icon_->count = count;
// FIXME: Fl_RGB_Image lacks const modifiers on methods
for (int i = 0;i < count;i++)
icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy();
}
if (Fl_X::i(pWindow))
Fl_X::i(pWindow)->set_icons();
}
const void *Fl_WinAPI_Window_Driver::icon() const {
return icon_->legacy_icon;
}
void Fl_WinAPI_Window_Driver::icon(const void * ic) {
free_icons();
icon_->legacy_icon = ic;
}
void Fl_WinAPI_Window_Driver::free_icons() {
int i;
icon_->legacy_icon = 0L;
if (icon_->icons) {
for (i = 0;i < icon_->count;i++)
delete icon_->icons[i];
delete [] icon_->icons;
icon_->icons = 0L;
}
icon_->count = 0;
if (icon_->big_icon)
DestroyIcon(icon_->big_icon);
if (icon_->small_icon)
DestroyIcon(icon_->small_icon);
icon_->big_icon = NULL;
icon_->small_icon = NULL;
}
void Fl_WinAPI_Window_Driver::icons(HICON big_icon, HICON small_icon)
{
free_icons();
if (big_icon != NULL)
icon_->big_icon = CopyIcon(big_icon);
if (small_icon != NULL)
icon_->small_icon = CopyIcon(small_icon);
if (Fl_X::i(pWindow))
Fl_X::i(pWindow)->set_icons();
}
// //
// End of "$Id$". // End of "$Id$".
// //
+11
View File
@@ -42,6 +42,13 @@
? where do we handle the interface between OpenGL/DirectX and Cocoa/WIN32/Glx? ? where do we handle the interface between OpenGL/DirectX and Cocoa/WIN32/Glx?
*/ */
struct Fl_Window_Driver::icon_data {
const void *legacy_icon;
Fl_RGB_Image **icons;
int count;
};
struct Fl_Window_Driver::shape_data_type { struct Fl_Window_Driver::shape_data_type {
int lw_; ///< width of shape image int lw_; ///< width of shape image
int lh_; ///< height of shape image int lh_; ///< height of shape image
@@ -62,6 +69,10 @@ public:
virtual void take_focus(); virtual void take_focus();
virtual void shape(const Fl_Image* img); virtual void shape(const Fl_Image* img);
virtual void draw(); virtual void draw();
virtual void icons(const Fl_RGB_Image *icons[], int count);
virtual const void *icon() const;
virtual void icon(const void * ic);
virtual void free_icons();
}; };
+40
View File
@@ -56,6 +56,8 @@ Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w)
Fl_X11_Window_Driver::Fl_X11_Window_Driver(Fl_Window *win) Fl_X11_Window_Driver::Fl_X11_Window_Driver(Fl_Window *win)
: Fl_Window_Driver(win) : Fl_Window_Driver(win)
{ {
icon_ = new Fl_Window_Driver::icon_data;
memset(icon_, 0, sizeof(Fl_Window_Driver::icon_data));
} }
@@ -65,6 +67,7 @@ Fl_X11_Window_Driver::~Fl_X11_Window_Driver()
delete shape_data_->todelete_; delete shape_data_->todelete_;
delete shape_data_; delete shape_data_;
} }
delete icon_;
} }
void Fl_X11_Window_Driver::take_focus() void Fl_X11_Window_Driver::take_focus()
@@ -235,6 +238,43 @@ void Fl_X11_Window_Driver::draw() {
Fl_Window_Driver::draw(); Fl_Window_Driver::draw();
} }
void Fl_X11_Window_Driver::icons(const Fl_RGB_Image *icons[], int count) {
free_icons();
if (count > 0) {
icon_->icons = new Fl_RGB_Image*[count];
icon_->count = count;
// FIXME: Fl_RGB_Image lacks const modifiers on methods
for (int i = 0;i < count;i++)
icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy();
}
if (Fl_X::i(pWindow))
Fl_X::i(pWindow)->set_icons();
}
const void *Fl_X11_Window_Driver::icon() const {
return icon_->legacy_icon;
}
void Fl_X11_Window_Driver::icon(const void * ic) {
free_icons();
icon_->legacy_icon = ic;
}
void Fl_X11_Window_Driver::free_icons() {
int i;
icon_->legacy_icon = 0L;
if (icon_->icons) {
for (i = 0;i < icon_->count;i++)
delete icon_->icons[i];
delete [] icon_->icons;
icon_->icons = 0L;
}
icon_->count = 0;
}
// //
// End of "$Id$". // End of "$Id$".
// //