當OS X中的某個應用程序有多個窗口(許多打開的文檔,每個窗口都在自己的窗口中)時,似乎它們共享相同的系統菜單,至少在FLTK中。有沒有辦法找到最近選擇的窗口從菜單中發送一個事件給它?Mac OS X中的FLTK窗口共享相同的系統菜單
這裏是我的設置(Mac OS X 10.6.2,FLTK 1.3.3):有Shell
類與系統菜單。每一次新的文檔被打開,新Shell
創建:
#ifdef __APPLE__
void Shell::macOpen(const char *fileName)
{
// If there are empty shell, open the model in it
if (s_empty != 0)
{
...
s_empty = 0;
}
// Otherwise, create new shell with the model
else
{
char *args[1];
args[0] = (char *) fileName;
new Shell(1, args, s_conf, s_dct, fileName, 1);
}
}
#endif
然後我跟蹤的最近選擇Shell
將其保存到static Shell *Shell::s_current
:
int Shell::handle(int event)
{
...
case FL_FOCUS:
#ifdef __APPLE__
// We just selected some shell, it is current.
s_current = this;
cout << "Select shell with address: [" << s_current << "]" << endl;
#endif
return 1;
...
}
這片似乎工作,因爲我可以看到的痕跡,每次我選擇一些Shell
:
Select shell with address: [0x8206db0]
Select shell with address: [0x82375f0]
Select shell with address: [0x5d20650]
Select shell with address: [0x82375f0]
現在,給出:
Shell *Shell::currentShell(Fl_Widget *w)
{
cout << "Widget address: [" << w << "]" << endl;
Shell *result = 0;
if (w != 0)
{
result = (Shell *) w->window();
cout << "Widget wingow address: [" << result << "]" << endl;
}
#ifdef __APPLE__
else
{
result = s_current;
cout << "Last selected shell address: [" << result << "]" << endl;
}
#endif
return result;
}
我有一些回調:
void Shell::shortcutCB(Fl_Widget *w, void *data)
{
cout << "Shortcut" << endl;
Shell *ref = currentShell(w);
if (ref != 0)
{
...
}
}
當這個回調是從菜單中執行多Shell
s爲開,我得到以下錯誤:
Bus error
,不留痕跡,從要麼是Shell::shortcutCB
要麼是Shell::currentShell
。當唯一的Shell
是開放的,都完美的作品。如果有更多的Shell
已打開,並且我關閉了所有其中一個,則錯誤再次出現。從Shell
內的某個窗口小部件調用相同的回調或從鍵盤快捷方式發送時,沒有任何問題。