Added code to get the active window for menu events on Mac OS X. Will test next.

This commit is contained in:
Pietro Gagliardi 2015-05-03 21:05:55 -04:00
parent 62424fbd79
commit d25c954d9f
3 changed files with 21 additions and 2 deletions

View File

@ -59,8 +59,8 @@ enum {
item = (struct menuItem *) [v pointerValue];
if (item->type == typeCheckbox)
uiMenuItemSetChecked(uiMenuItem(item), !uiMenuItemChecked(uiMenuItem(item)));
// TODO get key window
(*(item->onClicked))(uiMenuItem(item), NULL, item->onClickedData);
// use the key window as the source of the menu event; it's the active window
(*(item->onClicked))(uiMenuItem(item), windowFromNSWindow([NSApp keyWindow]), item->onClickedData);
}
- (void)register:(NSMenuItem *)item to:(struct menuItem *)smi

View File

@ -42,3 +42,6 @@ extern void disableAutocorrect(NSTextView *);
// entry.m
extern void finishNewTextField(NSTextField *, BOOL);
// window.m
extern uiWindow *windowFromNSWindow(NSWindow *);

View File

@ -6,12 +6,18 @@
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
}
- (uiWindow *)getuiWindow;
- (void)setuiWindow:(uiWindow *)ww;
- (void)setOnClosing:(int (*)(uiWindow *, void *))f data:(void *)data;
@end
@implementation windowDelegate
- (uiWindow *)getuiWindow
{
return self->w;
}
- (void)setuiWindow:(uiWindow *)ww
{
self->w = ww;
@ -218,3 +224,13 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
return uiWindow(w);
}
uiWindow *windowFromNSWindow(NSWindow *w)
{
windowDelegate *d;
if (w == nil)
return NULL;
d = (windowDelegate *) [w delegate];
return [d getuiWindow];
}