void NotificationWindow::WorkspaceActivated(int32 /*workspace*/, bool active) { // Ensure window is in the correct position if (active) ResizeAll(); }
void NotificationWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_NODE_MONITOR: { LoadSettings(); LoadAppFilters(); break; } case kResizeToFit: ResizeAll(); break; case B_COUNT_PROPERTIES: { BMessage reply(B_REPLY); BMessage specifier; const char* property = NULL; bool messageOkay = true; if (message->FindMessage("specifiers", 0, &specifier) != B_OK) messageOkay = false; if (specifier.FindString("property", &property) != B_OK) messageOkay = false; if (strcmp(property, "message") != 0) messageOkay = false; if (messageOkay) reply.AddInt32("result", fViews.size()); else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } message->SendReply(&reply); break; } case B_CREATE_PROPERTY: case kNotificationMessage: { int32 type; const char* content = NULL; const char* title = NULL; const char* app = NULL; BMessage reply(B_REPLY); bool messageOkay = true; if (message->FindInt32("type", &type) != B_OK) type = B_INFORMATION_NOTIFICATION; if (message->FindString("content", &content) != B_OK) messageOkay = false; if (message->FindString("title", &title) != B_OK) messageOkay = false; if (message->FindString("app", &app) != B_OK && message->FindString("appTitle", &app) != B_OK) messageOkay = false; if (messageOkay) { NotificationView* view = new NotificationView(this, (notification_type)type, app, title, content, new BMessage(*message)); appfilter_t::iterator fIt = fAppFilters.find(app); bool allow = false; if (fIt == fAppFilters.end()) { app_info info; BMessenger messenger = message->ReturnAddress(); if (messenger.IsValid()) be_roster->GetRunningAppInfo(messenger.Team(), &info); else be_roster->GetAppInfo("application/x-vnd.Be-SHEL", &info); AppUsage* appUsage = new AppUsage(info.ref, app, true); fAppFilters[app] = appUsage; appUsage->Allowed(title, (notification_type)type); allow = true; } else allow = fIt->second->Allowed(title, (notification_type)type); if (allow) { appview_t::iterator aIt = fAppViews.find(app); AppGroupView* group = NULL; if (aIt == fAppViews.end()) { group = new AppGroupView(this, app); fAppViews[app] = group; fBorder->AddChild(group); } else group = aIt->second; group->AddInfo(view); ResizeAll(); reply.AddInt32("error", B_OK); } else reply.AddInt32("error", B_NOT_ALLOWED); } else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } message->SendReply(&reply); break; } case kRemoveView: { void* _ptr; message->FindPointer("view", &_ptr); NotificationView* info = reinterpret_cast<NotificationView*>(_ptr); fBorder->RemoveChild(info); std::vector<NotificationView*>::iterator i = find(fViews.begin(), fViews.end(), info); if (i != fViews.end()) fViews.erase(i); delete info; ResizeAll(); break; } default: BWindow::MessageReceived(message); } }
BOOL CALLBACK PreferencesDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { static HWND hBrowser; static Bool browser_changed; Bool toolbar_changed, lagbox_changed, temp; CommSettings *comm = &config.comm; OPENFILENAME ofn; static char *dir; // Working directory before dialog (OpenFile may change it) int new_val; switch (message) { case WM_INITDIALOG: CenterWindow(hDlg, GetParent(hDlg)); if (hPreferencesDialog != NULL) { EndDialog(hDlg, IDCANCEL); return FALSE; } hPreferencesDialog = hDlg; hBrowser = GetDlgItem(hDlg, IDC_BROWSER); Edit_LimitText(hBrowser, MAX_PATH); SetWindowFont(hBrowser, GetFont(FONT_INPUT), FALSE); SetWindowText(hBrowser, config.browser); CheckDlgButton(hDlg, IDC_SCROLLLOCK, config.scroll_lock); CheckDlgButton(hDlg, IDC_DRAWNAMES, config.draw_names); CheckDlgButton(hDlg, IDC_TOOLTIPS, config.tooltips); CheckDlgButton(hDlg, IDC_PAIN, config.pain); CheckDlgButton(hDlg, IDC_INVNUM, config.inventory_num); CheckDlgButton(hDlg, IDC_SAFETY, config.aggressive); CheckDlgButton(hDlg, IDC_BOUNCE, config.bounce); CheckDlgButton(hDlg, IDC_TOOLBAR, config.toolbar); CheckDlgButton(hDlg, IDS_LATENCY0, config.lagbox); CheckDlgButton(hDlg, IDC_PROFANE, config.antiprofane); CheckDlgButton(hDlg, IDC_DRAWMAP, config.drawmap); CheckDlgButton(hDlg, IDC_MAP_ANNOTATIONS, config.map_annotations); CheckDlgButton(hDlg, IDC_MUSIC, config.play_music); CheckDlgButton(hDlg, IDC_SOUNDFX, config.play_sound); CheckDlgButton(hDlg, IDC_LOOPSOUNDS, config.play_loop_sounds); CheckDlgButton(hDlg, IDC_RANDSOUNDS, config.play_random_sounds); EnableWindow(GetDlgItem(hDlg, IDC_LOOPSOUNDS), IsDlgButtonChecked(hDlg, IDC_SOUNDFX)); EnableWindow(GetDlgItem(hDlg, IDC_RANDSOUNDS), IsDlgButtonChecked(hDlg, IDC_SOUNDFX)); CheckRadioButton(hDlg, IDC_TARGETHALO1, IDC_TARGETHALO3, config.halocolor + IDC_TARGETHALO1); CheckDlgButton(hDlg, IDC_COLORCODES, config.colorcodes); Trackbar_SetRange(GetDlgItem(hDlg, IDC_SOUND_VOLUME), 0, CONFIG_MAX_VOLUME, FALSE); Trackbar_SetRange(GetDlgItem(hDlg, IDC_MUSIC_VOLUME), 0, CONFIG_MAX_VOLUME, FALSE); Trackbar_SetPos(GetDlgItem(hDlg, IDC_SOUND_VOLUME), config.sound_volume); Trackbar_SetPos(GetDlgItem(hDlg, IDC_MUSIC_VOLUME), config.music_volume); dir = (char *) SafeMalloc(MAX_PATH + 1); GetWorkingDirectory(dir, MAX_PATH); browser_changed = False; return TRUE; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_BROWSER: if (GET_WM_COMMAND_CMD(wParam, lParam) != EN_CHANGE) break; browser_changed = True; return TRUE; case IDC_FIND: memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; ofn.lpstrFilter = EXE_filter; ofn.lpstrFile = config.browser; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if (GetOpenFileName(&ofn)) { SetWindowText(hBrowser, config.browser); browser_changed = True; } else debug(("GetOpenFileName failed, error = %d\n", CommDlgExtendedError())); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_SOUNDFX: EnableWindow(GetDlgItem(hDlg, IDC_LOOPSOUNDS), IsDlgButtonChecked(hDlg, IDC_SOUNDFX)); EnableWindow(GetDlgItem(hDlg, IDC_RANDSOUNDS), IsDlgButtonChecked(hDlg, IDC_SOUNDFX)); return TRUE; case IDC_PROFANESETTINGS: if (IDOK == DialogBox(hInst, MAKEINTRESOURCE(IDC_PROFANESETTINGS), hDlg, ProfanityDialogProc)) CheckDlgButton(hDlg, IDC_PROFANE, TRUE); return TRUE; case IDOK: Edit_GetText(hBrowser, config.browser, MAX_PATH); if (browser_changed) config.default_browser = False; config.scroll_lock = IsDlgButtonChecked(hDlg, IDC_SCROLLLOCK); config.draw_names = IsDlgButtonChecked(hDlg, IDC_DRAWNAMES); config.tooltips = IsDlgButtonChecked(hDlg, IDC_TOOLTIPS); config.pain = IsDlgButtonChecked(hDlg, IDC_PAIN); config.inventory_num = IsDlgButtonChecked(hDlg, IDC_INVNUM); config.aggressive = IsDlgButtonChecked(hDlg, IDC_SAFETY); config.bounce = IsDlgButtonChecked(hDlg, IDC_BOUNCE); config.antiprofane = IsDlgButtonChecked(hDlg, IDC_PROFANE); config.drawmap = IsDlgButtonChecked(hDlg, IDC_DRAWMAP); config.map_annotations = IsDlgButtonChecked(hDlg, IDC_MAP_ANNOTATIONS); temp = IsDlgButtonChecked(hDlg, IDC_TOOLBAR); toolbar_changed = (temp != config.toolbar); config.toolbar = temp; temp = IsDlgButtonChecked(hDlg, IDS_LATENCY0); lagbox_changed = (temp != config.lagbox); config.lagbox = temp; if (IsDlgButtonChecked(hDlg, IDC_MUSIC) != config.play_music) UserToggleMusic(config.play_music); config.play_music = IsDlgButtonChecked(hDlg, IDC_MUSIC); config.play_sound = IsDlgButtonChecked(hDlg, IDC_SOUNDFX); config.play_loop_sounds = IsDlgButtonChecked(hDlg, IDC_LOOPSOUNDS); config.play_random_sounds = IsDlgButtonChecked(hDlg, IDC_RANDSOUNDS); if (!config.play_sound) SoundAbort(); new_val = Trackbar_GetPos(GetDlgItem(hDlg, IDC_MUSIC_VOLUME)); if (new_val != config.music_volume) { config.music_volume = new_val; ResetMusicVolume(); } // Don't need to dynamically update sound volume, because // looping sounds are updated as player moves around. config.sound_volume = Trackbar_GetPos(GetDlgItem(hDlg, IDC_SOUND_VOLUME)); if( IsDlgButtonChecked( hDlg, IDC_TARGETHALO1 ) == BST_CHECKED ) config.halocolor = 0; else if( IsDlgButtonChecked( hDlg, IDC_TARGETHALO2 ) == BST_CHECKED ) config.halocolor = 1; else config.halocolor = 2; config.colorcodes = IsDlgButtonChecked(hDlg, IDC_COLORCODES); // Redraw main window to reflect new settings if (toolbar_changed || lagbox_changed) { ResizeAll(); } else { InvalidateRect(hMain, NULL, TRUE); RedrawAll(); } EditBoxSetNormalFormat(); EndDialog(hDlg, IDOK); return TRUE; } break; case WM_DESTROY: // Restore working drive and directory if (chdir(dir) != 0) debug(("chdir failed to %s\n", dir)); SafeFree(dir); hPreferencesDialog = NULL; return TRUE; } return FALSE; }