mirror of https://github.com/fltk/fltk
Change member function args to Fl_Menu_Bar::play_menu(const Fl_Menu_Item *)
This commit is contained in:
parent
66c37e5128
commit
a9085c3b11
|
@ -92,9 +92,10 @@ public:
|
|||
*/
|
||||
virtual void update() {}
|
||||
/**
|
||||
Opens the menu named \c title of the menubar.
|
||||
Opens the 1st level submenu of the menubar corresponding to \c item.
|
||||
\since 1.4.0
|
||||
*/
|
||||
virtual void play_menu(const char *title);
|
||||
virtual void play_menu(const Fl_Menu_Item *item);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -111,7 +111,7 @@ public:
|
|||
const Fl_Menu_Item *menu() const {return Fl_Menu_::menu();}
|
||||
void menu(const Fl_Menu_Item *m);
|
||||
void update() FL_OVERRIDE;
|
||||
void play_menu(const char *title) FL_OVERRIDE;
|
||||
void play_menu(const Fl_Menu_Item *) FL_OVERRIDE;
|
||||
int add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0);
|
||||
/** Adds a new menu item.
|
||||
\see Fl_Menu_::add(const char* label, int shortcut, Fl_Callback*, void *user_data=0, int flags=0)
|
||||
|
|
|
@ -727,34 +727,40 @@ void fl_mac_set_about(Fl_Callback *cb, void *user_data, int shortcut) {
|
|||
}
|
||||
|
||||
|
||||
void Fl_MacOS_Sys_Menu_Bar_Driver::play_menu(const char *menu_name) {
|
||||
void Fl_MacOS_Sys_Menu_Bar_Driver::play_menu(const Fl_Menu_Item *item) {
|
||||
// Use the accessibility interface to programmatically open a menu of the system menubar
|
||||
char *ts = remove_ampersand(menu_name);
|
||||
NSString *mac_name = [NSString stringWithUTF8String:ts];
|
||||
free(ts);
|
||||
AXUIElementRef appElement = AXUIElementCreateApplication(getpid());
|
||||
AXUIElementRef menuBar;
|
||||
AXError error = AXUIElementCopyAttributeValue(appElement, kAXMenuBarAttribute, (CFTypeRef *)&menuBar);
|
||||
if (error) return;
|
||||
CFIndex count = -1;
|
||||
error = AXUIElementGetAttributeValueCount(menuBar, kAXChildrenAttribute, &count);
|
||||
if (error) { CFRelease(menuBar); return; }
|
||||
NSArray *children = nil;
|
||||
error = AXUIElementCopyAttributeValues(menuBar, kAXChildrenAttribute, 0, count, (CFArrayRef *)&children);
|
||||
if (error) { CFRelease(menuBar); return; }
|
||||
for (id child in children) {
|
||||
AXUIElementRef element = (AXUIElementRef)child;
|
||||
CFIndex count = -1;
|
||||
AXUIElementRef element;
|
||||
NSEnumerator *enumerator = nil;
|
||||
char *label = remove_ampersand(item->label());
|
||||
NSString *mac_name = NSLocalizedString([NSString stringWithUTF8String:label], nil);
|
||||
free(label);
|
||||
AXUIElementRef appElement = AXUIElementCreateApplication(getpid());
|
||||
AXUIElementRef menu_bar = NULL;
|
||||
AXError error = AXUIElementCopyAttributeValue(appElement, kAXMenuBarAttribute, (CFTypeRef *)&menu_bar);
|
||||
if (error) goto way_out;
|
||||
error = AXUIElementGetAttributeValueCount(menu_bar, kAXChildrenAttribute, &count);
|
||||
if (error) goto way_out;
|
||||
error = AXUIElementCopyAttributeValues(menu_bar, kAXChildrenAttribute, 0, count, (CFArrayRef *)&children);
|
||||
if (error) goto way_out;
|
||||
enumerator = [children objectEnumerator];
|
||||
[enumerator nextObject]; // skip Apple menu
|
||||
[enumerator nextObject]; // skip application menu
|
||||
while ((element = (AXUIElementRef)[enumerator nextObject]) != nil) {
|
||||
id title;
|
||||
AXError error = AXUIElementCopyAttributeValue(element, kAXTitleAttribute, (CFTypeRef *)&title);
|
||||
if (!error && [title isEqualToString:mac_name]) {
|
||||
if (error) goto way_out;
|
||||
if ([title isEqualToString:mac_name]) {
|
||||
AXUIElementPerformAction(element, kAXPressAction);
|
||||
CFRelease(title);
|
||||
break;
|
||||
}
|
||||
CFRelease(title);
|
||||
}
|
||||
CFRelease(menuBar);
|
||||
[children release];
|
||||
way_out:
|
||||
if (menu_bar) CFRelease(menu_bar);
|
||||
if (children) [children release];
|
||||
CFRelease(appElement);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,7 @@ Fl_Menu_Bar::Fl_Menu_Bar(int X, int Y, int W, int H,const char *l)
|
|||
}
|
||||
|
||||
|
||||
void Fl_Menu_Bar::play_menu(const char *title) {
|
||||
const Fl_Menu_Item *v = find_item(title);
|
||||
void Fl_Menu_Bar::play_menu(const Fl_Menu_Item *v) {
|
||||
if (v) {
|
||||
v = menu()->pulldown(x(), y(), w(), h(), v, this, 0, 1);
|
||||
picked(v);
|
||||
|
|
|
@ -242,9 +242,9 @@ void Fl_Sys_Menu_Bar::create_window_menu() {
|
|||
}
|
||||
}
|
||||
|
||||
void Fl_Sys_Menu_Bar::play_menu(const char *title) {
|
||||
if (driver()) fl_sys_menu_bar->driver()->play_menu(title);
|
||||
else Fl_Menu_Bar::play_menu(title);
|
||||
void Fl_Sys_Menu_Bar::play_menu(const Fl_Menu_Item *item) {
|
||||
if (driver()) fl_sys_menu_bar->driver()->play_menu(item);
|
||||
else Fl_Menu_Bar::play_menu(item);
|
||||
}
|
||||
|
||||
#if !defined(FL_DOXYGEN)
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
virtual void replace(int index, const char *name) { bar->Fl_Menu_Bar::replace(index, name); }
|
||||
virtual void mode(int i, int fl) { bar->Fl_Menu_Bar::mode(i, fl); }
|
||||
virtual void create_window_menu() {}
|
||||
virtual void play_menu(const char *title) {}
|
||||
virtual void play_menu(const Fl_Menu_Item *) {}
|
||||
static Fl_Sys_Menu_Bar::window_menu_style_enum window_menu_style() { return window_menu_style_; }
|
||||
static void window_menu_style(Fl_Sys_Menu_Bar::window_menu_style_enum style) { window_menu_style_ = style; }
|
||||
};
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void remove_window(Fl_Window *win);
|
||||
void rename_window(Fl_Window *win);
|
||||
static Fl_MacOS_Sys_Menu_Bar_Driver* driver();
|
||||
void play_menu(const char *menu_name) FL_OVERRIDE;
|
||||
void play_menu(const Fl_Menu_Item *) FL_OVERRIDE;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue