Applied the 'recap.zip' files to the Cocoa patch. About diaog now correct. Much other stuff should work better now. Exciting!

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6965 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher
2009-12-12 18:26:12 +00:00
parent 3f689a7d2f
commit 64716f01e2
4 changed files with 300 additions and 273 deletions
+4
View File
@@ -29,6 +29,7 @@
#define Fl_Sys_Menu_Bar_H #define Fl_Sys_Menu_Bar_H
#include "Fl_Menu_Bar.H" #include "Fl_Menu_Bar.H"
#include "x.H"
#ifdef __APPLE__ #ifdef __APPLE__
@@ -39,8 +40,11 @@ public:
Fl_Sys_Menu_Bar(int x,int y,int w,int h,const char *l=0) Fl_Sys_Menu_Bar(int x,int y,int w,int h,const char *l=0)
: Fl_Menu_Bar(x,y,w,h,l) { : Fl_Menu_Bar(x,y,w,h,l) {
deactivate(); // don't let the old area take events deactivate(); // don't let the old area take events
fl_sys_menu_bar = this;
} }
void menu(const Fl_Menu_Item *m); void menu(const Fl_Menu_Item *m);
int add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0);
void remove(int n);
}; };
#else #else
+50 -16
View File
@@ -65,6 +65,7 @@
#ifdef __APPLE_COCOA__ #ifdef __APPLE_COCOA__
extern void *MACMenuOrItemOperation(const char *operation, ...); extern void *MACMenuOrItemOperation(const char *operation, ...);
extern void *MACmainMenu(void);
#define MenuHandle void * #define MenuHandle void *
#endif #endif
@@ -253,28 +254,23 @@ static void createSubMenu( void * mh, pFl_Menu_Item &mm )
} }
/** static void convertToMenuBar(const Fl_Menu_Item *mm)
* create a system menu bar using the given list of menu structs //convert a complete Fl_Menu_Item array into a series of menus in the top menu bar
* //ALL PREVIOUS SYSTEM MENUS, EXCEPT APPLICATION MENU, ARE REPLACED BY THE NEW DATA
* \author Matthias Melcher
*
* @param m list of Fl_Menu_Item
*/
extern void *MACmainMenu(void);
void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
{ {
fl_open_display(); int count;//first, delete all existing system menus
Fl_Menu_Bar::menu( m ); MACMenuOrItemOperation("numberOfItems", MACmainMenu(), &count);
fl_sys_menu_bar = this; for(int i = count - 1; i > 0; i--) {
MACMenuOrItemOperation("removeItem", MACmainMenu(), i);
}
const Fl_Menu_Item *mm = m; //now convert FLTK stuff into MacOS menus
for (;;) for (;;)
{ {
if ( !mm || !mm->text ) if ( !mm || !mm->text )
break; break;
char visible = mm->visible() ? 1 : 0; char visible = mm->visible() ? 1 : 0;
MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm, NULL); MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm, NULL);
if ( mm->flags & FL_SUBMENU ) if ( mm->flags & FL_SUBMENU )
createSubMenu( MACmainMenu(), mm ); createSubMenu( MACmainMenu(), mm );
else if ( mm->flags & FL_SUBMENU_POINTER ) { else if ( mm->flags & FL_SUBMENU_POINTER ) {
@@ -288,6 +284,45 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
} }
} }
/**
* create a system menu bar using the given list of menu structs
*
* \author Matthias Melcher
*
* @param m list of Fl_Menu_Item
*/
void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
{
fl_open_display();
Fl_Menu_Bar::menu( m );
convertToMenuBar(m);
}
/**
* Adds to the system menu bar a new menu item, with a title string, shortcut int,
* callback, argument to the callback, and flags.
*
* @see Fl_Menu_::add(const char* label, int shortcut, Fl_Callback *cb, void *user_data, int flags)
*/
int Fl_Sys_Menu_Bar::add(const char* label, int shortcut, Fl_Callback *cb, void *user_data, int flags)
{
fl_open_display();
int rank = Fl_Menu_::add(label, shortcut, cb, user_data, flags);
convertToMenuBar(Fl_Menu_::menu());
return rank;
}
/**
* remove an item from the system menu bar
*
* @param n the rank of the item to remove
*/
void Fl_Sys_Menu_Bar::remove(int n)
{
Fl_Menu_::remove(n);
convertToMenuBar(Fl_Menu_::menu());
}
#else #else
static void catMenuFlags( const Fl_Menu_Item *m, char *dst ) static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
@@ -298,7 +333,6 @@ static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
strcat( dst, "(" ); strcat( dst, "(" );
} }
/** /**
* create a sub menu for a specific menu handle * create a sub menu for a specific menu handle
*/ */
+7 -18
View File
@@ -645,20 +645,6 @@ static double do_queued_events( double time = 0.0 )
fl_unlock_function(); fl_unlock_function();
//necessary so that after closing a non-FLTK window (e.g., Fl_Native_File_Chooser)
//the front window turns main again
Fl_Window *w = Fl::first_window();
if (w) {
NSWindow *cw = (NSWindow*)Fl_X::i(w)->xid;
if([cw isVisible] && ![cw isMiniaturized] && ([cw styleMask] & NSTitledWindowMask) ) {
if(![cw isKeyWindow]) {//always make Fl::first_window() the key window
[cw makeKeyAndOrderFront:nil];
}
if(![cw isMainWindow]) {//always make Fl::first_window() the main window
[cw makeMainWindow];
}
}
}
//necessary so that after closing a non-FLTK window (e.g., Fl_Native_File_Chooser) //necessary so that after closing a non-FLTK window (e.g., Fl_Native_File_Chooser)
//the front window turns key again //the front window turns key again
if([NSApp keyWindow] == nil) { if([NSApp keyWindow] == nil) {
@@ -2843,7 +2829,8 @@ static void createAppleMenu(void)
- (void) setFlMenuItem:(const Fl_Menu_Item*)flItem; - (void) setFlMenuItem:(const Fl_Menu_Item*)flItem;
- (void) doCallback:(id)unused; - (void) doCallback:(id)unused;
- (void) directCallback:(id)unused; - (void) directCallback:(id)unused;
- (Fl_Menu_Item*)getFlMenuItem;@end - (Fl_Menu_Item*)getFlMenuItem;
@end
@implementation FLMenuItem @implementation FLMenuItem
- (void) setFlMenuItem:(const Fl_Menu_Item*)flItem - (void) setFlMenuItem:(const Fl_Menu_Item*)flItem
{ {
@@ -2893,7 +2880,7 @@ void *MACcreateMenu(const char *name)
return (void *)mymenu; return (void *)mymenu;
} }
void fl_mac_set_about( Fl_Menu_Item *flItem ) void fl_mac_set_about( const Fl_Menu_Item *flItem )
/** /**
* Mac OS: attaches an Fl_Menu_Item to the "About myprog" item of the system application menu. * Mac OS: attaches an Fl_Menu_Item to the "About myprog" item of the system application menu.
* \note Only the shortcut_, callback_ and user_data_ fields of the Fl_Menu_Item* \p flItem are used. * \note Only the shortcut_, callback_ and user_data_ fields of the Fl_Menu_Item* \p flItem are used.
@@ -2912,7 +2899,8 @@ void fl_mac_set_about( Fl_Menu_Item *flItem )
MACMenuOrItemOperation("setKeyEquivalent", item, flItem->shortcut() & 0xff); MACMenuOrItemOperation("setKeyEquivalent", item, flItem->shortcut() & 0xff);
MACMenuOrItemOperation("setKeyEquivalentModifierMask", item, flItem->shortcut() ); MACMenuOrItemOperation("setKeyEquivalentModifierMask", item, flItem->shortcut() );
} }
[item setFlMenuItem:flItem]; [appleMenu insertItem:item atIndex:0]; [item setFlMenuItem:flItem];
[appleMenu insertItem:item atIndex:0];
CFRelease(cfname); CFRelease(cfname);
[item setTarget:item]; [item setTarget:item];
} }
@@ -3021,7 +3009,8 @@ void *MACMenuOrItemOperation(const char *operation, ...)
value = va_arg(ap, int); value = va_arg(ap, int);
[menu removeItem:[menu itemAtIndex:value]]; [menu removeItem:[menu itemAtIndex:value]];
} }
else if(strcmp(operation, "getFlMenuItem") == 0) {//arguments: NSMenu*, int. Returns the item's Fl_Menu_Item* menu = va_arg(ap, NSMenu*); else if(strcmp(operation, "getFlMenuItem") == 0) {//arguments: NSMenu*, int. Returns the item's Fl_Menu_Item*
menu = va_arg(ap, NSMenu*);
value = va_arg(ap, int); value = va_arg(ap, int);
retval = [(FLMenuItem *)[menu itemAtIndex:value] getFlMenuItem]; retval = [(FLMenuItem *)[menu itemAtIndex:value] getFlMenuItem];
} }