Move set_cursor() member functions from class Fl_X to classes Fl_Window_Driver and derived.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11652 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-18 14:31:07 +00:00
parent 516d0e5f9c
commit 0629b40afd
13 changed files with 48 additions and 31 deletions

View File

@ -139,6 +139,10 @@ public:
virtual void show_with_args_end(int argc, char **argv) {}
virtual int can_do_overlay();
virtual void redraw_overlay();
// --- window cursor stuff
virtual int set_cursor(Fl_Cursor);
virtual int set_cursor(const Fl_RGB_Image*, int, int);
// --- window shape stuff
void shape_pixmap_(Fl_Image* pixmap); // platform-independent, support function

View File

@ -129,7 +129,6 @@ public:
Fl_Region region;
Fl_X *next; // chain of mapped windows
int wait_for_expose;
NSCursor *cursor;
static Fl_X* first;
static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;}
static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
@ -153,8 +152,6 @@ public:
static void GL_cleardrawable(void);
void destroy(void);
void set_key_window(void);
int set_cursor(Fl_Cursor);
int set_cursor(const Fl_RGB_Image*, int, int);
static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
private:

View File

@ -56,8 +56,6 @@ public:
Fl_X *next;
int wait_for_expose;
HDC private_dc; // used for OpenGL
HCURSOR cursor;
int custom_cursor;
HDC saved_hdc; // saves the handle of the DC currently loaded
// static variables, static functions and member functions
static Fl_X* first;
@ -67,8 +65,6 @@ public:
void make_fullscreen(int X, int Y, int W, int H);
void set_minmax(LPMINMAXINFO minmax);
void mapraise();
int set_cursor(Fl_Cursor);
int set_cursor(const Fl_RGB_Image*, int, int);
static Fl_X* make(Fl_Window*);
};
extern FL_EXPORT UINT fl_wake_msg;

2
FL/x.H
View File

@ -120,8 +120,6 @@ public:
char wait_for_expose;
static Fl_X* first;
static Fl_X* i(const Fl_Window* wi) {return wi->i;}
int set_cursor(Fl_Cursor);
int set_cursor(const Fl_RGB_Image*, int, int);
static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
static Fl_X* set_xid(Fl_Window*, Window);
};

View File

@ -232,6 +232,14 @@ void Fl_Window_Driver::flush()
pWindow->flush();
}
int Fl_Window_Driver::set_cursor(Fl_Cursor) {
return 0;
}
int Fl_Window_Driver::set_cursor(const Fl_RGB_Image*, int, int) {
return 0;
}
//
// End of "$Id$".
//

View File

@ -2318,8 +2318,8 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
if (!i) return; // fix for STR #3128
// We have to have at least one cursor rect for invalidateCursorRectsForView
// to work, hence the "else" clause.
if (i->cursor)
[self addCursorRect:[self visibleRect] cursor:(NSCursor*)i->cursor];
if (((Fl_Cocoa_Window_Driver*)w->driver())->cursor)
[self addCursorRect:[self visibleRect] cursor:((Fl_Cocoa_Window_Driver*)w->driver())->cursor];
else
[self addCursorRect:[self visibleRect] cursor:[NSCursor arrowCursor]];
}
@ -2947,7 +2947,6 @@ void Fl_X::make(Fl_Window* w)
x->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows
x->region = 0;
x->subRect(0);
x->cursor = NULL;
((Fl_Cocoa_Window_Driver*)w->pWindowDriver)->gc = 0;
x->mapped_to_retina(false);
x->changed_resolution(false);
@ -3519,10 +3518,9 @@ void Fl_Cocoa_Window_Driver::map() {
// after a subwindow has been unmapped, it has lost its parent window and its frame may be wrong
[xid setSubwindowFrame];
}
Fl_X *i = Fl_X::i(pWindow);
if (i->cursor) {
[(NSCursor*)i->cursor release];
i->cursor = NULL;
if (cursor) {
[cursor release];
cursor = NULL;
}
}
@ -3571,7 +3569,7 @@ static NSImage *CGBitmapContextToNSImage(CGContextRef c)
return [image autorelease];
}
int Fl_X::set_cursor(Fl_Cursor c)
int Fl_Cocoa_Window_Driver::set_cursor(Fl_Cursor c)
{
if (cursor) {
[(NSCursor*)cursor release];
@ -3596,12 +3594,12 @@ int Fl_X::set_cursor(Fl_Cursor c)
[(NSCursor*)cursor retain];
[(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
[(NSWindow*)fl_xid(pWindow) invalidateCursorRectsForView:[(NSWindow*)fl_xid(pWindow) contentView]];
return 1;
}
int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
int Fl_Cocoa_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
if (cursor) {
[(NSCursor*)cursor release];
cursor = NULL;
@ -3665,7 +3663,7 @@ int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
initWithImage:nsimage
hotSpot:NSMakePoint(hotx, hoty)];
[(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
[(NSWindow*)fl_xid(pWindow) invalidateCursorRectsForView:[(NSWindow*)fl_xid(pWindow) contentView]];
[bitmap release];
[nsimage release];

View File

@ -1383,7 +1383,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT) {
while (window->parent()) window = window->window();
SetCursor(Fl_X::i(window)->cursor);
SetCursor(((Fl_WinAPI_Window_Driver*)window->driver())->cursor);
return 0;
}
break;
@ -1800,8 +1800,9 @@ Fl_X* Fl_X::make(Fl_Window* w) {
x->w = w; w->i = x;
x->region = 0;
x->private_dc = 0;
x->cursor = LoadCursor(NULL, IDC_ARROW);
x->custom_cursor = 0;
Fl_WinAPI_Window_Driver *driver = (Fl_WinAPI_Window_Driver*)w->driver();
driver->cursor = LoadCursor(NULL, IDC_ARROW);
driver->custom_cursor = 0;
if (!fl_codepage) fl_get_codepage();
WCHAR *lab = NULL;
@ -2160,7 +2161,7 @@ void Fl_WinAPI_Window_Driver::set_icons() {
# define IDC_HAND MAKEINTRESOURCE(32649)
#endif // !IDC_HAND
int Fl_X::set_cursor(Fl_Cursor c) {
int Fl_WinAPI_Window_Driver::set_cursor(Fl_Cursor c) {
LPSTR n;
HCURSOR new_cursor;
@ -2211,7 +2212,7 @@ int Fl_X::set_cursor(Fl_Cursor c) {
return 1;
}
int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
int Fl_WinAPI_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
HCURSOR new_cursor;
new_cursor = image_to_icon(image, false, hotx, hoty);

View File

@ -2666,7 +2666,7 @@ void Fl_X11_Window_Driver::set_icons() {
////////////////////////////////////////////////////////////////
int Fl_X::set_cursor(Fl_Cursor c) {
int Fl_X11_Window_Driver::set_cursor(Fl_Cursor c) {
/* The cursors are cached, because creating one takes 0.5ms including
opening, reading, and closing theme files. They are kept until program
@ -2720,12 +2720,12 @@ int Fl_X::set_cursor(Fl_Cursor c) {
#undef cache_cursor
XDefineCursor(fl_display, xid, xc);
XDefineCursor(fl_display, fl_xid(pWindow), xc);
return 1;
}
int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
int Fl_X11_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
#if ! HAVE_XCURSOR
return 0;
#else
@ -2769,7 +2769,7 @@ int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
cursor->yhot = hoty;
xc = XcursorImageLoadCursor(fl_display, cursor);
XDefineCursor(fl_display, xid, xc);
XDefineCursor(fl_display, fl_xid(pWindow), xc);
XFreeCursor(fl_display, xc);
XcursorImageDestroy(cursor);

View File

@ -32,8 +32,10 @@ class Fl_Image;
class Fl_Window;
#ifdef __OBJC__
@class CALayer;
@class NSCursor;
#else
class CALayer;
class NSCursor;
#endif // __OBJC__
/*
@ -69,6 +71,7 @@ public:
Fl_Cocoa_Window_Driver(Fl_Window*);
~Fl_Cocoa_Window_Driver();
CGContextRef gc; // graphics context
NSCursor *cursor;
static void q_release_context(Fl_Cocoa_Window_Driver *x = 0); // free all resources associated with gc
// --- window data
@ -94,6 +97,9 @@ public:
virtual void size_range();
virtual void iconize();
virtual void decoration_sizes(int *top, int *left, int *right, int *bottom);
// --- window cursor stuff
virtual int set_cursor(Fl_Cursor);
virtual int set_cursor(const Fl_RGB_Image*, int, int);
virtual void shape(const Fl_Image* img);
// that one is implemented in Fl_Cocoa.mm because it uses Objective-c

View File

@ -36,6 +36,7 @@ Fl_Window_Driver *Fl_Window_Driver::newWindowDriver(Fl_Window *w)
Fl_Cocoa_Window_Driver::Fl_Cocoa_Window_Driver(Fl_Window *win)
: Fl_Window_Driver(win)
{
cursor = nil;
}

View File

@ -70,6 +70,8 @@ public:
~Fl_WinAPI_Window_Driver();
struct icon_data *icon_;
HCURSOR cursor;
int custom_cursor;
// --- window data
virtual int decorated_w();
virtual int decorated_h();
@ -89,6 +91,9 @@ public:
virtual void fullscreen_off(int X, int Y, int W, int H);
virtual void iconize();
virtual void decoration_sizes(int *top, int *left, int *right, int *bottom);
// --- window cursor stuff
virtual int set_cursor(Fl_Cursor);
virtual int set_cursor(const Fl_RGB_Image*, int, int);
virtual void shape(const Fl_Image* img);
virtual void icons(const Fl_RGB_Image *icons[], int count);

View File

@ -107,6 +107,9 @@ public:
virtual void decoration_sizes(int *top, int *left, int *right, int *bottom);
virtual void show_with_args_begin();
virtual void show_with_args_end(int argc, char **argv);
// --- window cursor stuff
virtual int set_cursor(Fl_Cursor);
virtual int set_cursor(const Fl_RGB_Image*, int, int);
virtual void shape(const Fl_Image* img);
virtual void icons(const Fl_RGB_Image *icons[], int count);

View File

@ -131,7 +131,7 @@ void Fl_Window::cursor(Fl_Cursor c) {
if (!i)
return;
ret = i->set_cursor(c);
ret = pWindowDriver->set_cursor(c);
if (ret)
return;
@ -168,7 +168,7 @@ void Fl_Window::cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
if (!i)
return;
ret = i->set_cursor(image, hotx, hoty);
ret = pWindowDriver->set_cursor(image, hotx, hoty);
if (ret)
return;