mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 23:06:54 +08:00
Rewrite Fl_Menu.cxx for the driver model.
See the detailed description in menuwindow::handle(int e) of Fl_Menu.cxx of how the menu window class could require 1 or 2 less support functions from the Fl_System_Driver class. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11557 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -112,6 +112,10 @@ public:
|
|||||||
virtual int filename_isdir_quick(const char* n);
|
virtual int filename_isdir_quick(const char* n);
|
||||||
// the default implementation of filename_iext() is in src/filename_ext.cxx and may be enough
|
// the default implementation of filename_iext() is in src/filename_ext.cxx and may be enough
|
||||||
virtual const char *filename_ext(const char *buf);
|
virtual const char *filename_ext(const char *buf);
|
||||||
|
// whether a platform uses additional code in Fl_Menu::handle(int e)
|
||||||
|
virtual int need_menu_handle_part2() {return 0;}
|
||||||
|
// whether a platform uses additional code in Fl_Menu::handle_part1(int e)
|
||||||
|
virtual int need_menu_handle_part1_extra() {return 0;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FL_SYSTEM_DRIVER_H
|
#endif // FL_SYSTEM_DRIVER_H
|
||||||
|
|||||||
+38
-11
@@ -23,6 +23,7 @@
|
|||||||
// Fl_Menu_ widget.
|
// Fl_Menu_ widget.
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
|
#include <FL/Fl_System_Driver.H>
|
||||||
#include <FL/Fl_Menu_Window.H>
|
#include <FL/Fl_Menu_Window.H>
|
||||||
#include <FL/Fl_Menu_.H>
|
#include <FL/Fl_Menu_.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
@@ -119,12 +120,11 @@ public:
|
|||||||
class menuwindow : public Fl_Menu_Window {
|
class menuwindow : public Fl_Menu_Window {
|
||||||
void draw();
|
void draw();
|
||||||
void drawentry(const Fl_Menu_Item*, int i, int erase);
|
void drawentry(const Fl_Menu_Item*, int i, int erase);
|
||||||
|
int handle_part1(int);
|
||||||
|
int handle_part2(int e, int ret);
|
||||||
public:
|
public:
|
||||||
menutitle* title;
|
menutitle* title;
|
||||||
int handle(int);
|
int handle(int);
|
||||||
#if defined (__APPLE__) || defined (USE_X11) // PORTME: Fl_Screen_Driver - menubar
|
|
||||||
int early_hide_handle(int);
|
|
||||||
#endif
|
|
||||||
int itemheight; // zero == menubar
|
int itemheight; // zero == menubar
|
||||||
int numitems;
|
int numitems;
|
||||||
int selected;
|
int selected;
|
||||||
@@ -655,12 +655,41 @@ static int backward(int menu) { // previous item in menu menu if possible
|
|||||||
}
|
}
|
||||||
|
|
||||||
int menuwindow::handle(int e) {
|
int menuwindow::handle(int e) {
|
||||||
#if defined (__APPLE__) || defined (USE_X11) // PORTME: Fl_Screen_Driver - menubar
|
/* In FLTK 1.3.4, the equivalent of handle_part2() is called for the Mac OS and X11 platforms
|
||||||
// This off-route takes care of the "detached menu" bug on OS X.
|
and "svn blame" shows it is here to fix STR #449.
|
||||||
|
But this STR is Mac OS-specific.
|
||||||
|
So, it is unclear why handle_part2() is called also for X11.
|
||||||
|
|
||||||
|
Furthermore, calling handle_part2() for X11 renders the
|
||||||
|
fix for STR #2619 below necessary. If handle_part2() is not called under X11,
|
||||||
|
then STR #2619 does not occur. need_menu_handle_part1_extra() activates this fix.
|
||||||
|
|
||||||
|
FLTK 1.3.4 behavior:
|
||||||
|
Fl::system_driver()->need_menu_handle_part2() returns true on Mac + X11
|
||||||
|
Fl::system_driver()->need_menu_handle_part1_extra() returns true on X11
|
||||||
|
|
||||||
|
Alternative behavior that seems equally correct:
|
||||||
|
Fl::system_driver()->need_menu_handle_part2() returns true on Mac
|
||||||
|
need_menu_handle_part1_extra() does not exist
|
||||||
|
|
||||||
|
Other alternative:
|
||||||
|
Neither need_menu_handle_part2() nor need_menu_handle_part1_extra() exist
|
||||||
|
--> the menuwindow code is entirely cross-platform and simpler.
|
||||||
|
It makes a small difference with Mac OS when resizing a window with a menu on:
|
||||||
|
the menu disappears after the end of the resize rather than at its beginning.
|
||||||
|
Apple applications do close popups at the beginning of resizes.
|
||||||
|
*/
|
||||||
|
static int use_part2 = Fl::system_driver()->need_menu_handle_part2();
|
||||||
|
int ret = handle_part1(e);
|
||||||
|
if (use_part2) ret = handle_part2(e, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int menuwindow::handle_part2(int e, int ret) {
|
||||||
|
// This off-route takes care of the "detached menu" bug on OS X (STR #449).
|
||||||
// Apple event handler requires that we hide all menu windows right
|
// Apple event handler requires that we hide all menu windows right
|
||||||
// now, so that Carbon can continue undisturbed with handling window
|
// now, so that Carbon can continue undisturbed with handling window
|
||||||
// manager events, like dragging the application window.
|
// manager events, like dragging the application window.
|
||||||
int ret = early_hide_handle(e);
|
|
||||||
menustate &pp = *p;
|
menustate &pp = *p;
|
||||||
if (pp.state == DONE_STATE) {
|
if (pp.state == DONE_STATE) {
|
||||||
hide();
|
hide();
|
||||||
@@ -682,8 +711,7 @@ int menuwindow::handle(int e) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int menuwindow::early_hide_handle(int e) {
|
int menuwindow::handle_part1(int e) {
|
||||||
#endif
|
|
||||||
menustate &pp = *p;
|
menustate &pp = *p;
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case FL_KEYBOARD:
|
case FL_KEYBOARD:
|
||||||
@@ -748,12 +776,11 @@ int menuwindow::early_hide_handle(int e) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FL_MOVE:
|
case FL_MOVE:
|
||||||
#if ! (defined(WIN32) || defined(__APPLE__)) // PORTME: Fl_Screen_Driver - menubar
|
static int use_part1_extra = Fl::system_driver()->need_menu_handle_part1_extra();
|
||||||
if (pp.state == DONE_STATE) {
|
if (use_part1_extra && pp.state == DONE_STATE) {
|
||||||
return 1; // Fix for STR #2619
|
return 1; // Fix for STR #2619
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
#endif
|
|
||||||
case FL_ENTER:
|
case FL_ENTER:
|
||||||
case FL_PUSH:
|
case FL_PUSH:
|
||||||
case FL_DRAG:
|
case FL_DRAG:
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
virtual int get_key(int k);
|
virtual int get_key(int k);
|
||||||
virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **) );
|
virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **) );
|
||||||
virtual const char *getpwnam(const char *login);
|
virtual const char *getpwnam(const char *login);
|
||||||
|
virtual int need_menu_handle_part2() {return 1;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FL_DARWIN_SYSTEM_DRIVER_H
|
#endif // FL_DARWIN_SYSTEM_DRIVER_H
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public:
|
|||||||
virtual int get_key(int k);
|
virtual int get_key(int k);
|
||||||
virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **) );
|
virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **) );
|
||||||
virtual const char *getpwnam(const char *login);
|
virtual const char *getpwnam(const char *login);
|
||||||
|
virtual int need_menu_handle_part2() {return 1;}
|
||||||
|
virtual int need_menu_handle_part1_extra() {return 1;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FL_POSIX_SYSTEM_DRIVER_H
|
#endif // FL_POSIX_SYSTEM_DRIVER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user