Add example code to Fl_Window_Driver.

Some refactoring of a take_focus() function into driver structures (not too happy with it, because it has some kind of bug fix. However, shouldn't *all* Fl_Windows always have an FL_Window_Driver?)

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11196 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2016-02-19 22:37:41 +00:00
parent 052401a34e
commit 399501783c
7 changed files with 33 additions and 17 deletions

View File

@ -636,6 +636,8 @@ public:
*/ */
int decorated_h(); int decorated_h();
Fl_Window_Driver *driver() { return i; }
}; };
#endif #endif

View File

@ -38,6 +38,8 @@ public:
Fl_Window_Driver(Fl_Window *); Fl_Window_Driver(Fl_Window *);
virtual ~Fl_Window_Driver(); virtual ~Fl_Window_Driver();
static Fl_Window_Driver *newWindowDriver(Fl_Window *); static Fl_Window_Driver *newWindowDriver(Fl_Window *);
virtual void take_focus() { }
}; };

View File

@ -1001,24 +1001,16 @@ void Fl::focus(Fl_Widget *o) {
if (!w1) w1 = o->window(); if (!w1) w1 = o->window();
while (w1) { win=w1; w1=win->window(); } while (w1) { win=w1; w1=win->window(); }
if (win) { if (win) {
#ifdef __APPLE__ // PORTME: Fl_Window_Driver - platform window focus if (fl_xfocus != win) {
if (fl_xfocus != win) { Fl_Window_Driver *drvr = win->driver();
Fl_X *x = Fl_X::i(win); #ifdef USE_X11 // platform fix
if (x) x->set_key_window(); if (!Fl_X::ewmh_supported()) win->show(); // Old WMs, XMapRaised
} else if (drvr) drvr->take_focus();
#elif defined(USE_X11) #else
if (fl_xfocus != win) { if (drvr) drvr->take_focus();
Fl_X *x = Fl_X::i(win);
if (!Fl_X::ewmh_supported())
win->show(); // Old WMs, XMapRaised
else if (x) // New WMs use the NETWM attribute:
Fl_X::activate_window(x->xid);
}
#elif defined(WIN32)
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: handle platform specifics for change of keyboard focus here"
#endif #endif
fl_xfocus = win; fl_xfocus = win;
}
} }
} }
// take focus from the old focused window // take focus from the old focused window

View File

@ -33,6 +33,14 @@ Fl_Cocoa_Window_Driver::Fl_Cocoa_Window_Driver(Fl_Window *win)
} }
extern Fl_Window *fl_xfocus;
void Fl_Cocoa_Window_Driver::take_focus()
{
set_key_window();
}
// //
// End of "$Id$". // End of "$Id$".

View File

@ -46,6 +46,7 @@ class FL_EXPORT Fl_Cocoa_Window_Driver : public Fl_Window_Driver
{ {
public: public:
Fl_Cocoa_Window_Driver(Fl_Window*); Fl_Cocoa_Window_Driver(Fl_Window*);
virtual void take_focus();
}; };

View File

@ -33,6 +33,16 @@ Fl_X11_Window_Driver::Fl_X11_Window_Driver(Fl_Window *win)
} }
void Fl_X11_Window_Driver::take_focus()
{
if (!Fl_X::ewmh_supported())
win->show(); // Old WMs, XMapRaised
else if (x) // New WMs use the NETWM attribute:
Fl_X::activate_window(x->xid);
}
}
// //
// End of "$Id$". // End of "$Id$".
// //

View File

@ -46,6 +46,7 @@ class FL_EXPORT Fl_X11_Window_Driver : public Fl_Window_Driver
{ {
public: public:
Fl_X11_Window_Driver(Fl_Window*); Fl_X11_Window_Driver(Fl_Window*);
virtual void take_focus();
}; };