void WorkspacesApp::ArgvReceived(int32 argc, char **argv) { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-' && argv[i][1] == '-') { // evaluate --arguments if (!strcmp(argv[i], "--notitle")) fWindow->SetLook(B_MODAL_WINDOW_LOOK); else if (!strcmp(argv[i], "--noborder")) fWindow->SetLook(B_NO_BORDER_WINDOW_LOOK); else if (!strcmp(argv[i], "--avoidfocus")) fWindow->SetFlags(fWindow->Flags() | B_AVOID_FOCUS); else if (!strcmp(argv[i], "--notmovable")) fWindow->SetFlags(fWindow->Flags() | B_NOT_MOVABLE); else if (!strcmp(argv[i], "--alwaysontop")) fWindow->SetFeel(B_FLOATING_ALL_WINDOW_FEEL); else if (!strcmp(argv[i], "--autoraise")) fWindow->SetAutoRaise(true); else { const char *programName = strrchr(argv[0], '/'); programName = programName ? programName + 1 : argv[0]; Usage(programName); } } else if (isdigit(*argv[i])) { // check for a numeric arg, if not already given activate_workspace(atoi(argv[i])); // if the app is running, don't quit // but if it isn't, cancel the complete run, so it doesn't // open any window if (IsLaunching()) Quit(); } else if (!strcmp(argv[i], "-")) { activate_workspace(current_workspace() - 1); if (IsLaunching()) Quit(); } else if (!strcmp(argv[i], "+")) { activate_workspace(current_workspace() + 1); if (IsLaunching()) Quit(); } else { // some unknown arguments were specified fprintf(stderr, "Invalid argument: %s\n", argv[i]); if (IsLaunching()) Quit(); } } }
void MonitorView::MessageReceived(BMessage* message) { switch (message->what) { case UPDATE_DESKTOP_MSG: { int32 width, height; if (message->FindInt32("width", &width) == B_OK && message->FindInt32("height", &height) == B_OK) SetResolution(width, height); break; } case UPDATE_DESKTOP_COLOR_MSG: { BScreen screen(Window()); rgb_color color = screen.DesktopColor(current_workspace()); if (color != fDesktopColor) { fDesktopColor = color; Invalidate(); } break; } default: BView::MessageReceived(message); break; } }
void BrowserApp::_CreateNewPage(const BString& url, bool fullscreen) { uint32 workspace = 1 << current_workspace(); bool loadedInWindowOnCurrentWorkspace = false; for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (webWindow->Lock()) { if (webWindow->Workspaces() & workspace) { if (webWindow->IsBlankTab()) { if (url.Length() != 0) webWindow->CurrentWebView()->LoadURL(url); } else webWindow->CreateNewTab(url, true); webWindow->Activate(); webWindow->CurrentWebView()->MakeFocus(true); loadedInWindowOnCurrentWorkspace = true; } webWindow->Unlock(); } if (loadedInWindowOnCurrentWorkspace) return; } _CreateNewWindow(url, fullscreen); }
status_t GlutGameMode::Enter() { display_mode* mode = _FindMatchingMode(); if (!mode) return B_BAD_VALUE; BScreen screen; if (!fActive) { // First enter: remember this workspace original mode... fGameModeWorkspace = current_workspace(); screen.GetMode(fGameModeWorkspace, &fOriginalMode); } // Don't make it new default mode for this workspace... status_t status = screen.SetMode(fGameModeWorkspace, mode, false); if (status != B_OK) return status; // Retrieve the new active display mode, which could be // a sligth different than the one we asked for... screen.GetMode(fGameModeWorkspace, &fCurrentMode); if (!fGameModeWindow) { // create a new window fPreviousWindow = glutGetWindow(); fGameModeWindow = glutCreateWindow("glutGameMode"); if (!fGameModeWindow) return Leave(); } else // make sure it's the current window glutSetWindow(fGameModeWindow); BDirectWindow *directWindow = dynamic_cast<BDirectWindow*>(gState.currentWindow->Window()); if (directWindow == NULL) // Hum?! return B_ERROR; // Give it some useless title, except for debugging (thread name). BString name; name << "Game Mode " << fCurrentMode.virtual_width << "x" << fCurrentMode.virtual_height << ":" << _GetModePixelDepth(&fCurrentMode) << "@" << _GetModeRefreshRate(&fCurrentMode); // force the game mode window to fullscreen directWindow->Lock(); directWindow->SetTitle(name.String()); directWindow->SetFullScreen(true); directWindow->Unlock(); fDisplayChanged = true; fActive = true; return B_OK; }
void ScreenWindow::_Apply() { // make checkpoint, so we can undo these changes fUndoScreenMode.UpdateOriginalModes(); status_t status = fScreenMode.Set(fSelected); if (status == B_OK) { // use the mode that has eventually been set and // thus we know to be working; it can differ from // the mode selected by user due to hardware limitation display_mode newMode; BScreen screen(this); screen.GetMode(&newMode); if (fAllWorkspacesItem->IsMarked()) { int32 originatingWorkspace = current_workspace(); for (int32 i = 0; i < count_workspaces(); i++) { if (i != originatingWorkspace) screen.SetMode(i, &newMode, true); } fBootWorkspaceApplied = true; } else { if (current_workspace() == 0) fBootWorkspaceApplied = true; } fActive = fSelected; // TODO: only show alert when this is an unknown mode BWindow* window = new AlertWindow(this); window->Show(); } else { char message[256]; snprintf(message, sizeof(message), B_TRANSLATE("The screen mode could not be set:\n\t%s\n"), screen_errors(status)); BAlert* alert = new BAlert(B_TRANSLATE("Warning"), message, B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); } }
void WorkspacesView::MessageReceived(BMessage* message) { switch (message->what) { case B_ABOUT_REQUESTED: _AboutRequested(); break; case B_MOUSE_WHEEL_CHANGED: { WorkspacesWindow* window = dynamic_cast<WorkspacesWindow*>(Window()); if (window == NULL || !window->SwitchOnWheel()) break; float deltaY = message->FindFloat("be:wheel_delta_y"); if (deltaY > 0.1) activate_workspace(current_workspace() + 1); else if (deltaY < -0.1) activate_workspace(current_workspace() - 1); break; } case kMsgChangeCount: be_roster->Launch(kScreenPrefletSignature); break; case kMsgToggleLiveInDeskbar: { // only actually used from the replicant itself // since HasItem() locks up we just remove directly. BDeskbar deskbar; // we shouldn't do this here actually, but it works for now... deskbar.RemoveItem (kDeskbarItemName); break; } default: BView::MessageReceived(message); break; } }
MonitorView::MonitorView(BRect rect, const char *name, int32 width, int32 height) : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), fMaxWidth(1920), fMaxHeight(1200), fWidth(width), fHeight(height), fDPI(0) { BScreen screen(B_MAIN_SCREEN_ID); fDesktopColor = screen.DesktopColor(current_workspace()); }
status_t ScreenMode::GetOriginalMode(screen_mode& mode, int32 workspace) const { if (workspace == ~0) workspace = current_workspace(); else if(workspace > 31) return B_BAD_INDEX; mode = fOriginal[workspace]; return B_OK; }
///// // workspace changed // void MCMainWin::WorkspaceActivated( int32 ws, bool active) { if(this->ffws == false) { return; } if(active == false) { this->SetWorkspaces(1 << current_workspace()); } }
BackgroundImage * BackgroundImage::Refresh(BackgroundImage *oldBackgroundImage, const BNode *fromNode, bool desktop, BPoseView *poseView) { if (oldBackgroundImage) { oldBackgroundImage->Remove(); delete oldBackgroundImage; } BackgroundImage *result = GetBackgroundImage(fromNode, desktop); if (result && poseView->ViewMode() != kListMode) result->Show(poseView, current_workspace()); return result; }
void t_pgrid::runphysics() { const float time= PHYSICSFRAMEMILLIS/1000.0; if(curmillis-physicstime > 500) { physicstime= curmillis; return; } while(physicstime<curmillis) { editor->phys_tick(time); if(!isphysicspaused()) current_workspace()->image->phys_tick(time); physicstime+= PHYSICSFRAMEMILLIS; } }
status_t ScreenMode::Get(screen_mode& mode, int32 workspace) const { display_mode displayMode; BScreen screen(fWindow); if (workspace == ~0) workspace = current_workspace(); if (screen.GetMode(workspace, &displayMode) != B_OK) return B_ERROR; mode.SetTo(displayMode); return B_OK; }
void TTracker::CloseAllInWorkspace() { AutoLock<WindowList> lock(&fWindowList); int32 currentWorkspace = 1 << current_workspace(); // count from end to beginning so we can remove items safely for (int32 index = fWindowList.CountItems() - 1; index >= 0; index--) { BWindow *window = fWindowList.ItemAt(index); if (window->Workspaces() & currentWorkspace) // avoid the desktop if (!dynamic_cast<BDeskWindow *>(window) && !dynamic_cast<BStatusWindow *>(window)) window->PostMessage(B_QUIT_REQUESTED); } }
team_id CCrossHairDragView::FindTeam(const BPoint &screenPoint) { int32 currentWorkspace = current_workspace(); int32 tokenCount; // Get a list of window tokens in the order of the // z-order of the windows. int32 *tokens = get_token_list(-1, &tokenCount); if(tokens) { for(int32 i=0 ; i<tokenCount; i++) { window_info *windowInfo = get_window_info(tokens[i]); if(!windowInfo) { // That window probably closed. Just go to the next one. continue; } if(!windowInfo->is_mini) { // Not a hidden/minimized window if((windowInfo->workspaces & (1 << currentWorkspace)) != 0) { // Window is on this workspace if( screenPoint.x >= windowInfo->window_left && screenPoint.x <= windowInfo->window_right && screenPoint.y >= windowInfo->window_top && screenPoint.y <= windowInfo->window_bottom ) { // I found a valid window. team_id id = windowInfo->team; free(windowInfo); return id; } } } free(windowInfo); } free(tokens); } return -1; }
status_t ScreenMode::Set(const screen_mode& mode, int32 workspace) { if (!fUpdatedModes) UpdateOriginalModes(); BScreen screen(fWindow); if (workspace == ~0) workspace = current_workspace(); display_mode displayMode; if (!GetDisplayMode(mode, displayMode)) return B_ENTRY_NOT_FOUND; return screen.SetMode(workspace, &displayMode, true); }
BrowserWindow* BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow, bool fullscreen, bool useBlankTab) { // Let's first see if we must target a specific window... if (webWindow && webWindow->Lock()) { if (useBlankTab && webWindow->IsBlankTab()) { if (url.Length() != 0) webWindow->CurrentWebView()->LoadURL(url); } else webWindow->CreateNewTab(url, true); webWindow->Activate(); webWindow->CurrentWebView()->MakeFocus(true); webWindow->Unlock(); return webWindow; } // Otherwise, try to find one in the current workspace uint32 workspace = 1 << current_workspace(); bool loadedInWindowOnCurrentWorkspace = false; for (int i = 0; BWindow* window = WindowAt(i); i++) { webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (webWindow->Lock()) { if (webWindow->Workspaces() & workspace) { if (useBlankTab && webWindow->IsBlankTab()) { if (url.Length() != 0) webWindow->CurrentWebView()->LoadURL(url); } else webWindow->CreateNewTab(url, true); webWindow->Activate(); webWindow->CurrentWebView()->MakeFocus(true); loadedInWindowOnCurrentWorkspace = true; } webWindow->Unlock(); } if (loadedInWindowOnCurrentWorkspace) return webWindow; } // Finally, if no window is available, let's create one. return _CreateNewWindow(url, fullscreen); }
void BFilePanel::Show() { AutoLock<BWindow> lock(fWindow); if (!lock) return; // if the window is already showing, don't jerk the workspaces around, // just pull it to us uint32 workspace = 1UL << (uint32)current_workspace(); uint32 windowWorkspaces = fWindow->Workspaces(); if (!(windowWorkspaces & workspace)) // window in a different workspace, reopen in current fWindow->SetWorkspaces(workspace); if (!IsShowing()) fWindow->Show(); fWindow->Activate(); }
void MainApp::_ShowSettingsWindow() { BAutolock lock(fSettingsWindow); if (!lock.IsLocked()) return; // If the window is already showing, don't jerk the workspaces around, // just pull it to the current one. uint32 workspace = 1UL << (uint32)current_workspace(); uint32 windowWorkspaces = fSettingsWindow->Workspaces(); if ((windowWorkspaces & workspace) == 0) { // window in a different workspace, reopen in current fSettingsWindow->SetWorkspaces(workspace); } if (fSettingsWindow->IsHidden()) fSettingsWindow->Show(); else fSettingsWindow->Activate(); }
void Window1::MessageReceived(BMessage *message) { switch (message->what) { case B_SIMPLE_DATA: { be_app->PostMessage(message); break; } case B_WORKSPACE_ACTIVATED: { Application1 *app=(Application1 *)be_app; app->mkisofs_output->SetWorkspaces(current_workspace()); break; } default: { BWindow::MessageReceived(message); break; } } }
void SelectionWindow::MoveCloseToMouse() { uint32 buttons; BPoint mousePosition; ChildAt((int32)0)->GetMouse(&mousePosition, &buttons); ConvertToScreen(&mousePosition); // Position the window centered around the mouse... BPoint windowPosition = BPoint(mousePosition.x - Frame().Width() / 2, mousePosition.y - Frame().Height() / 2); // ... unless that's outside of the current screen size: BScreen screen; windowPosition.x = MAX(20, MIN(screen.Frame().right - 20 - Frame().Width(), windowPosition.x)); windowPosition.y = MAX(20, MIN(screen.Frame().bottom - 20 - Frame().Height(), windowPosition.y)); MoveTo(windowPosition); SetWorkspaces(1UL << current_workspace()); }
void TTracker::OpenContainerWindow(Model *model, BMessage *originalRefsList, OpenSelector openSelector, uint32 openFlags, bool checkAlreadyOpen, const BMessage *stateMessage) { AutoLock<WindowList> lock(&fWindowList); BContainerWindow *window = NULL; if (checkAlreadyOpen && openSelector != kRunOpenWithWindow) // find out if window already open window = FindContainerWindow(model->NodeRef()); bool someWindowActivated = false; uint32 workspace = (uint32)(1 << current_workspace()); int32 windowCount = 0; while (window) { // At least one window open, just pull to front // make sure we don't jerk workspaces around uint32 windowWorkspaces = window->Workspaces(); if (windowWorkspaces & workspace) { window->Activate(); someWindowActivated = true; } window = FindContainerWindow(model->NodeRef(), ++windowCount); } if (someWindowActivated) { delete model; return; } // If no window was actiated, (none in the current workspace // we open a new one. if (openSelector == kRunOpenWithWindow) { BMessage *refList = NULL; if (!originalRefsList) { // when passing just a single model, stuff it's entry in a single // element list anyway ASSERT(model); refList = new BMessage; refList->AddRef("refs", model->EntryRef()); delete model; model = NULL; } else // clone the message, window adopts it for it's own use refList = new BMessage(*originalRefsList); window = new OpenWithContainerWindow(refList, &fWindowList); } else if (model->IsRoot()) { // window will adopt the model window = new BVolumeWindow(&fWindowList, openFlags); } else if (model->IsQuery()) { // window will adopt the model window = new BQueryContainerWindow(&fWindowList, openFlags); } else // window will adopt the model window = new BContainerWindow(&fWindowList, openFlags); if (model) window->CreatePoseView(model); BMessage restoreStateMessage(kRestoreState); if (stateMessage) restoreStateMessage.AddMessage("state", stateMessage); window->PostMessage(&restoreStateMessage); }
void MainWindow::MessageReceived(BMessage* message) { switch (message->what) { case MSG_LAUNCH: { BView* pointer; if (message->FindPointer("be:source", (void**)&pointer) < B_OK) break; LaunchButton* button = dynamic_cast<LaunchButton*>(pointer); if (button == NULL) break; BString errorMessage; bool launchedByRef = false; if (button->Ref()) { BEntry entry(button->Ref(), true); if (entry.IsDirectory()) { // open in Tracker BMessenger messenger("application/x-vnd.Be-TRAK"); if (messenger.IsValid()) { BMessage trackerMessage(B_REFS_RECEIVED); trackerMessage.AddRef("refs", button->Ref()); status_t ret = messenger.SendMessage(&trackerMessage); if (ret < B_OK) { errorMessage = "Failed to send 'open folder' " "command to Tracker.\n\nError: "; errorMessage << strerror(ret); } else launchedByRef = true; } else errorMessage = "Failed to open folder - is Tracker " "running?"; } else { status_t ret = be_roster->Launch(button->Ref()); if (ret < B_OK && ret != B_ALREADY_RUNNING) { errorMessage = "Failed to launch '"; BPath path(button->Ref()); if (path.InitCheck() >= B_OK) errorMessage << path.Path(); else errorMessage << button->Ref()->name; errorMessage << "'.\n\nError: "; errorMessage << strerror(ret); } else launchedByRef = true; } } if (!launchedByRef && button->AppSignature()) { status_t ret = be_roster->Launch(button->AppSignature()); if (ret != B_OK && ret != B_ALREADY_RUNNING) { errorMessage = "Failed to launch application with " "signature '"; errorMessage << button->AppSignature() << "'.\n\nError: "; errorMessage << strerror(ret); } else { // clear error message on success (might have been // filled when trying to launch by ref) errorMessage = ""; } } else if (!launchedByRef) { errorMessage = "Failed to launch 'something', error in " "Pad data."; } if (errorMessage.Length() > 0) { BAlert* alert = new BAlert("error", errorMessage.String(), "Bummer", NULL, NULL, B_WIDTH_FROM_WIDEST); alert->Go(NULL); } break; } case MSG_ADD_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { fPadView->AddButton(new LaunchButton("launch button", fLastID++, NULL, new BMessage(MSG_LAUNCH)), button); } break; } case MSG_CLEAR_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) button->SetTo((entry_ref*)NULL); break; } case MSG_REMOVE_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { if (fPadView->RemoveButton(button)) delete button; } break; } case MSG_SET_DESCRIPTION: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { const char* name; if (message->FindString("name", &name) >= B_OK) { // message comes from a previous name panel button->SetDescription(name); message->FindRect("frame", &fNamePanelFrame); } else { // message comes from pad view entry_ref* ref = button->Ref(); if (ref) { BString helper("Description for '"); helper << ref->name << "'"; make_sure_frame_is_on_screen(fNamePanelFrame, this); new NamePanel(helper.String(), button->Description(), this, this, new BMessage(*message), fNamePanelFrame); } } } break; } case MSG_ADD_WINDOW: { BMessage settings('sett'); SaveSettings(&settings); message->AddMessage("window", &settings); be_app->PostMessage(message); break; } case MSG_SHOW_BORDER: SetLook(B_TITLED_WINDOW_LOOK); break; case MSG_HIDE_BORDER: SetLook(B_BORDERED_WINDOW_LOOK); break; case MSG_TOGGLE_AUTORAISE: ToggleAutoRaise(); break; case MSG_SHOW_ON_ALL_WORKSPACES: fShowOnAllWorkspaces = !fShowOnAllWorkspaces; if (fShowOnAllWorkspaces) SetWorkspaces(B_ALL_WORKSPACES); else SetWorkspaces(1L << current_workspace()); break; case B_SIMPLE_DATA: case B_REFS_RECEIVED: case B_PASTE: case B_MODIFIERS_CHANGED: break; case B_ABOUT_REQUESTED: be_app->PostMessage(message); break; default: BWindow::MessageReceived(message); break; } }
int32 TExpandoMenuBar::monitor_team_windows(void *arg) { TExpandoMenuBar *teamMenu = (TExpandoMenuBar *)arg; int32 totalItems = 0; bool itemModified = false; TWindowMenuItem *item = NULL; TTeamMenuItem *teamItem = NULL; int32 *tokens = NULL; while (teamMenu->sDoMonitor) { totalItems = teamMenu->CountItems(); // Set all WindowMenuItems to require an update. item = NULL; for (int32 i = 0; i < totalItems; i++) { if (!teamMenu->SubmenuAt(i)){ item = static_cast<TWindowMenuItem *>(teamMenu->ItemAt(i)); item->SetRequireUpdate(); } } // Perform SetTo() on all the items that still exist as well as add new items. itemModified = false; teamItem = NULL; for (int32 i = 0; i < totalItems; i++) { if (teamMenu->SubmenuAt(i)){ teamItem = static_cast<TTeamMenuItem *>(teamMenu->ItemAt(i)); if (teamItem->IsExpanded()) { int32 teamCount = teamItem->Teams()->CountItems(); for (int32 j = 0; j < teamCount; j++) { // The following code is almost a copy/paste from // WindowMenu.cpp team_id theTeam = (team_id)teamItem->Teams()->ItemAt(j); int32 count = 0; tokens = get_token_list(theTeam, &count); for (int32 k = 0; k < count; k++) { window_info *wInfo = get_window_info(tokens[k]); if (wInfo == NULL) continue; if (TWindowMenu::WindowShouldBeListed(wInfo->w_type) && (wInfo->show_hide_level <= 0 || wInfo->is_mini)) { // Check if we have a matching window item... item = teamItem->ExpandedWindowItem(wInfo->id); if (item) { // Lock the window, changing workspaces will fry this. item->SetTo(wInfo->name, wInfo->id, wInfo->is_mini, ((1 << current_workspace()) & wInfo->workspaces) != 0); if (strcmp(wInfo->name, item->Label()) != 0) item->SetLabel(wInfo->name); if (item->ChangedState()) itemModified = true; } else if (teamItem->IsExpanded()) { // Add the item item = new TWindowMenuItem(wInfo->name, wInfo->id, wInfo->is_mini, ((1 << current_workspace()) & wInfo->workspaces) != 0, false); item->ExpandedItem(true); teamMenu->AddItem(item, i + 1); itemModified = true; teamMenu->Window()->Lock(); teamMenu->SizeWindow(); teamMenu->Window()->Unlock(); } } free(wInfo); } free(tokens); } } } } // Remove any remaining items which require an update. for (int32 i = 0; i < totalItems; i++) { if (!teamMenu->SubmenuAt(i)){ item = static_cast<TWindowMenuItem *>(teamMenu->ItemAt(i)); if (item && item->RequiresUpdate()) { item = static_cast<TWindowMenuItem *>(teamMenu->RemoveItem(i)); delete item; totalItems--; teamMenu->Window()->Lock(); teamMenu->SizeWindow(); teamMenu->Window()->Unlock(); } } } // If any of the WindowMenuItems changed state, we need to force a repaint. if (itemModified) { teamMenu->Window()->Lock(); teamMenu->Invalidate(); teamMenu->Window()->Unlock(); } // sleep for a bit... snooze(150000); } return B_OK; }
bool BrowserApp::QuitRequested() { if (fDownloadWindow->DownloadsInProgress()) { BAlert* alert = new BAlert(B_TRANSLATE("Downloads in progress"), B_TRANSLATE("There are still downloads in progress, do you really " "want to quit WebPositive now?"), B_TRANSLATE("Quit"), B_TRANSLATE("Continue downloads")); int32 choice = alert->Go(); if (choice == 1) { if (fWindowCount == 0) { if (fDownloadWindow->Lock()) { fDownloadWindow->SetWorkspaces(1 << current_workspace()); if (fDownloadWindow->IsHidden()) fDownloadWindow->Show(); else fDownloadWindow->Activate(); fDownloadWindow->SetMinimizeOnClose(true); fDownloadWindow->Unlock(); return false; } } else return false; } } fSession->MakeEmpty(); /* See if we got here because the last window is already closed. * In that case we only need to save that one, which is already archived */ BMessage* message = CurrentMessage(); BMessage windowMessage; status_t ret = message->FindMessage("window", &windowMessage); if (ret == B_OK) { fSession->AddMessage("window", &windowMessage); } else { for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (!webWindow->Lock()) continue; BMessage windowArchive; webWindow->Archive(&windowArchive, true); fSession->AddMessage("window", &windowArchive); if (webWindow->QuitRequested()) { fLastWindowFrame = webWindow->WindowFrame(); webWindow->Quit(); i--; } else { webWindow->Unlock(); return false; } } } BWebPage::ShutdownOnce(); fSettings->SetValue("window frame", fLastWindowFrame); if (fDownloadWindow->Lock()) { fSettings->SetValue("downloads window frame", fDownloadWindow->Frame()); fSettings->SetValue("show downloads", !fDownloadWindow->IsHidden()); fDownloadWindow->Unlock(); } if (fSettingsWindow->Lock()) { fSettings->SetValue("settings window frame", fSettingsWindow->Frame()); fSettingsWindow->Unlock(); } if (fConsoleWindow->Lock()) { fSettings->SetValue("console window frame", fConsoleWindow->Frame()); fConsoleWindow->Unlock(); } if (fCookieWindow->Lock()) { fSettings->SetValue("cookie window frame", fCookieWindow->Frame()); fCookieWindow->Unlock(); } BMessage cookieArchive; BNetworkCookieJar& cookieJar = fContext->GetCookieJar(); cookieJar.PurgeForExit(); if (cookieJar.Archive(&cookieArchive) == B_OK) fCookies->SetValue("cookies", cookieArchive); return true; }
bool BrowserApp::QuitRequested() { if (fDownloadWindow->DownloadsInProgress()) { BAlert* alert = new BAlert(B_TRANSLATE("Downloads in progress"), B_TRANSLATE("There are still downloads in progress, do you really " "want to quit WebPositive now?"), B_TRANSLATE("Quit"), B_TRANSLATE("Continue downloads")); int32 choice = alert->Go(); if (choice == 1) { if (fWindowCount == 0) { if (fDownloadWindow->Lock()) { fDownloadWindow->SetWorkspaces(1 << current_workspace()); if (fDownloadWindow->IsHidden()) fDownloadWindow->Show(); else fDownloadWindow->Activate(); fDownloadWindow->SetMinimizeOnClose(true); fDownloadWindow->Unlock(); return false; } } else return false; } } for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (!webWindow->Lock()) continue; if (webWindow->QuitRequested()) { fLastWindowFrame = webWindow->WindowFrame(); webWindow->Quit(); i--; } else { webWindow->Unlock(); return false; } } BWebPage::ShutdownOnce(); fSettings->SetValue("window frame", fLastWindowFrame); if (fDownloadWindow->Lock()) { fSettings->SetValue("downloads window frame", fDownloadWindow->Frame()); fSettings->SetValue("show downloads", !fDownloadWindow->IsHidden()); fDownloadWindow->Unlock(); } if (fSettingsWindow->Lock()) { fSettings->SetValue("settings window frame", fSettingsWindow->Frame()); fSettingsWindow->Unlock(); } BMessage cookieArchive; if (fCookieJar != NULL && fCookieJar->Archive(&cookieArchive) == B_OK) fCookies->SetValue("cookies", cookieArchive); return true; }
void MainWindow::MessageReceived(BMessage* message) { switch (message->what) { case MSG_LAUNCH: { BView* pointer; if (message->FindPointer("be:source", (void**)&pointer) < B_OK) break; LaunchButton* button = dynamic_cast<LaunchButton*>(pointer); if (button == NULL) break; BString errorMessage; bool launchedByRef = false; if (button->Ref()) { BEntry entry(button->Ref(), true); if (entry.IsDirectory()) { // open in Tracker BMessenger messenger("application/x-vnd.Be-TRAK"); if (messenger.IsValid()) { BMessage trackerMessage(B_REFS_RECEIVED); trackerMessage.AddRef("refs", button->Ref()); status_t ret = messenger.SendMessage(&trackerMessage); if (ret < B_OK) { errorMessage = B_TRANSLATE("Failed to send " "'open folder' command to Tracker.\n\nError: "); errorMessage << strerror(ret); } else launchedByRef = true; } else errorMessage = ("Failed to open folder - is Tracker " "running?"); } else { status_t ret = be_roster->Launch(button->Ref()); if (ret < B_OK && ret != B_ALREADY_RUNNING) { BString errStr(B_TRANSLATE("Failed to launch '%1'.\n" "\nError:")); BPath path(button->Ref()); if (path.InitCheck() >= B_OK) errStr.ReplaceFirst("%1", path.Path()); else errStr.ReplaceFirst("%1", button->Ref()->name); errorMessage << errStr.String() << " "; errorMessage << strerror(ret); } else launchedByRef = true; } } if (!launchedByRef && button->AppSignature()) { status_t ret = be_roster->Launch(button->AppSignature()); if (ret != B_OK && ret != B_ALREADY_RUNNING) { BString errStr(B_TRANSLATE("\n\nFailed to launch application " "with signature '%2'.\n\nError:")); errStr.ReplaceFirst("%2", button->AppSignature()); errorMessage << errStr.String() << " "; errorMessage << strerror(ret); } else { // clear error message on success (might have been // filled when trying to launch by ref) errorMessage = ""; } } else if (!launchedByRef) { errorMessage = B_TRANSLATE("Failed to launch 'something', " "error in Pad data."); } if (errorMessage.Length() > 0) { BAlert* alert = new BAlert("error", errorMessage.String(), B_TRANSLATE("Bummer"), NULL, NULL, B_WIDTH_FROM_WIDEST); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(NULL); } break; } case MSG_ADD_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { fPadView->AddButton(new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH)), button); } break; } case MSG_CLEAR_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) button->SetTo((entry_ref*)NULL); break; } case MSG_REMOVE_SLOT: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { if (fPadView->RemoveButton(button)) delete button; } break; } case MSG_SET_DESCRIPTION: { LaunchButton* button; if (message->FindPointer("be:source", (void**)&button) >= B_OK) { const char* name; if (message->FindString("name", &name) >= B_OK) { // message comes from a previous name panel button->SetDescription(name); BRect namePanelFrame; if (message->FindRect("frame", &namePanelFrame) == B_OK) { ((App*)be_app)->SetNamePanelSize( namePanelFrame.Size()); } } else { // message comes from pad view entry_ref* ref = button->Ref(); if (ref) { BString helper(B_TRANSLATE("Description for '%3'")); helper.ReplaceFirst("%3", ref->name); // Place the name panel besides the pad, but give it // the user configured size. BPoint origin = B_ORIGIN; BSize size = ((App*)be_app)->NamePanelSize(); NamePanel* panel = new NamePanel(helper.String(), button->Description(), this, this, new BMessage(*message), size); panel->Layout(true); size = panel->Frame().Size(); BScreen screen(this); BPoint mousePos; uint32 buttons; fPadView->GetMouse(&mousePos, &buttons, false); fPadView->ConvertToScreen(&mousePos); if (fPadView->Orientation() == B_HORIZONTAL) { // Place above or below the pad origin.x = mousePos.x - size.width / 2; if (screen.Frame().bottom - Frame().bottom > size.height + 20) { origin.y = Frame().bottom + 10; } else { origin.y = Frame().top - 10 - size.height; } } else { // Place left or right of the pad origin.y = mousePos.y - size.height / 2; if (screen.Frame().right - Frame().right > size.width + 20) { origin.x = Frame().right + 10; } else { origin.x = Frame().left - 10 - size.width; } } panel->MoveTo(origin); panel->Show(); } } } break; } case MSG_ADD_WINDOW: { BMessage settings('sett'); SaveSettings(&settings); message->AddMessage("window", &settings); be_app->PostMessage(message); break; } case MSG_SHOW_BORDER: SetLook(B_TITLED_WINDOW_LOOK); break; case MSG_HIDE_BORDER: SetLook(B_BORDERED_WINDOW_LOOK); break; case MSG_TOGGLE_AUTORAISE: ToggleAutoRaise(); break; case MSG_SHOW_ON_ALL_WORKSPACES: fShowOnAllWorkspaces = !fShowOnAllWorkspaces; if (fShowOnAllWorkspaces) SetWorkspaces(B_ALL_WORKSPACES); else SetWorkspaces(1L << current_workspace()); break; case B_SIMPLE_DATA: case B_REFS_RECEIVED: case B_PASTE: case B_MODIFIERS_CHANGED: break; default: BWindow::MessageReceived(message); break; } }
void TWindowMenu::AttachedToWindow() { SetFont(be_plain_font); RemoveItems(0, CountItems(), true); int32 miniCount = 0; bool dragging = false; TBarView* barview =(static_cast<TBarApp*>(be_app))->BarView(); if (barview && barview->LockLooper()) { // 'dragging' mode set in BarView::CacheDragData // invoke in MouseEnter in ExpandoMenuBar dragging = barview->Dragging(); if (dragging) { // We don't want to show the menu when dragging, but it's not // possible to remove a submenu once it exists, so we simply hide it // Don't call BMenu::Hide(), it causes the menu to pop up every now // and then. Window()->Hide(); // if in expando (horizontal or vertical) if (barview->Expando()) { SetTrackingHook(barview->MenuTrackingHook, barview->GetTrackingHookData()); } barview->DragStart(); } barview->UnlockLooper(); } int32 parentMenuItems = 0; int32 numTeams = fTeam->CountItems(); for (int32 i = 0; i < numTeams; i++) { team_id theTeam = (team_id)fTeam->ItemAt(i); int32 count = 0; int32* tokens = get_token_list(theTeam, &count); for (int32 j = 0; j < count; j++) { client_window_info* wInfo = get_window_info(tokens[j]); if (wInfo == NULL) continue; if (WindowShouldBeListed(wInfo->feel) && (wInfo->show_hide_level <= 0 || wInfo->is_mini)) { // Don't add new items if we're expanded. We've already done // this, they've just been moved. int32 numItems = CountItems(); int32 addIndex = 0; for (; addIndex < numItems; addIndex++) if (strcasecmp(ItemAt(addIndex)->Label(), wInfo->name) > 0) break; if (!fExpanded) { TWindowMenuItem* item = new TWindowMenuItem(wInfo->name, wInfo->server_token, wInfo->is_mini, ((1 << current_workspace()) & wInfo->workspaces) != 0, dragging); // disable app's window dropping for now if (dragging) item->SetEnabled(false); AddItem(item, TWindowMenuItem::InsertIndexFor(this, 0, item)); } else { TTeamMenuItem* parentItem = static_cast<TTeamMenuItem*>(Superitem()); if (parentItem->ExpandedWindowItem(wInfo->server_token)) { TWindowMenuItem* item = parentItem->ExpandedWindowItem( wInfo->server_token); if (item == NULL) continue; item->SetTo(wInfo->name, wInfo->server_token, wInfo->is_mini, ((1 << current_workspace()) & wInfo->workspaces) != 0, dragging); parentMenuItems++; } } if (wInfo->is_mini) miniCount++; } free(wInfo); } free(tokens); } int32 itemCount = CountItems() + parentMenuItems; if (itemCount < 1) { TWindowMenuItem* noWindowsItem = new TWindowMenuItem("No windows", -1, false, false); noWindowsItem->SetEnabled(false); AddItem(noWindowsItem); // if an application has no windows, this feature makes it easy to quit // it. (but we only add this option if the application is not Tracker.) if (fApplicationSignature.ICompare(kTrackerSignature) != 0) { AddSeparatorItem(); AddItem(new TShowHideMenuItem("Quit application", fTeam, B_QUIT_REQUESTED)); } } else { // if we are in drag mode, then don't add the window controls // to the menu if (!dragging) { TShowHideMenuItem* hide = new TShowHideMenuItem("Hide all", fTeam, B_MINIMIZE_WINDOW); TShowHideMenuItem* show = new TShowHideMenuItem("Show all", fTeam, B_BRING_TO_FRONT); TShowHideMenuItem* close = new TShowHideMenuItem("Close all", fTeam, B_QUIT_REQUESTED); if (miniCount == itemCount) hide->SetEnabled(false); else if (miniCount == 0) show->SetEnabled(false); if (!parentMenuItems) AddSeparatorItem(); AddItem(hide); AddItem(show); AddItem(close); } } BMenu::AttachedToWindow(); }
bool MainWindow::LoadSettings(const BMessage* message) { // restore window positioning BPoint point; bool useAdjust = false; if (message->FindPoint("window position", &point) == B_OK) { fScreenPosition = point; useAdjust = true; } float borderDist; if (message->FindFloat("border distance", &borderDist) == B_OK) { fBorderDist = borderDist; } // restore window frame BRect frame; if (message->FindRect("window frame", &frame) == B_OK) { if (useAdjust) { _AdjustLocation(frame); } else { make_sure_frame_is_on_screen(frame, this); MoveTo(frame.LeftTop()); ResizeTo(frame.Width(), frame.Height()); } } // restore window look window_look look; if (message->FindInt32("window look", (int32*)&look) == B_OK) SetLook(look); // restore orientation int32 orientation; if (message->FindInt32("orientation", &orientation) == B_OK) fPadView->SetOrientation((enum orientation)orientation); // restore icon size int32 iconSize; if (message->FindInt32("icon size", &iconSize) == B_OK) fPadView->SetIconSize(iconSize); // restore ignore double click bool ignoreDoubleClick; if (message->FindBool("ignore double click", &ignoreDoubleClick) == B_OK) fPadView->SetIgnoreDoubleClick(ignoreDoubleClick); // restore buttons const char* path; bool buttonAdded = false; for (int32 i = 0; message->FindString("path", i, &path) >= B_OK; i++) { LaunchButton* button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH)); fPadView->AddButton(button); BString signature; if (message->FindString("signature", i, &signature) >= B_OK && signature.CountChars() > 0) { button->SetTo(signature.String(), true); } BEntry entry(path, true); entry_ref ref; if (entry.Exists() && entry.GetRef(&ref) == B_OK) button->SetTo(&ref); const char* text; if (message->FindString("description", i, &text) >= B_OK) button->SetDescription(text); buttonAdded = true; } // restore auto raise setting bool autoRaise; if (message->FindBool("auto raise", &autoRaise) == B_OK && autoRaise) ToggleAutoRaise(); // store workspace setting bool showOnAllWorkspaces; if (message->FindBool("all workspaces", &showOnAllWorkspaces) == B_OK) fShowOnAllWorkspaces = showOnAllWorkspaces; SetWorkspaces(showOnAllWorkspaces ? B_ALL_WORKSPACES : 1L << current_workspace()); if (!fShowOnAllWorkspaces) { uint32 workspaces; if (message->FindInt32("workspaces", (int32*)&workspaces) == B_OK) SetWorkspaces(workspaces); } return buttonAdded; }
void t_pgrid::run() { bool quit= false; setvbuf(stdout, 0, _IONBF, 0); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_WM_SetCaption("pgrid", "pgrid"); lastmillis= curmillis= SDL_GetTicks(); SDL_ShowCursor(0); SDL_EnableUNICODE(true); gui= new flux_gui(); bool guimouse= false; while(!quit) { lastframephystime= physicstime; lastmillis= curmillis; curmillis= SDL_GetTicks(); SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: case SDL_KEYUP: { if(event.key.keysym.sym==SDLK_ESCAPE) quit= true; if(wnd_getkbdfocus()!=NOWND) { flux_keyboard_event(event.type==SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.unicode&0x7F); } else { current_workspace()->keyboard_event(event.key); editor->keyboard_event(event.key); for(t_dyninputhandler_list::iterator i= dyninputhandlers.begin(); i!=dyninputhandlers.end(); i++) (*i)->keyboard_event(event.key); } keystate[event.key.keysym.sym]= (event.key.state==SDL_PRESSED? 1: 0); break; } case SDL_MOUSEMOTION: flux_mouse_move_event(event.motion.xrel, event.motion.yrel); if( find_prim_pos(event.motion.x, event.motion.y, true) || find_mouse_handler(event.motion.x, event.motion.y) ) guimouse= true; else { guimouse= false; mouse.x= event.motion.x; mouse.y= event.motion.y; mouse.buttons= event.motion.state; current_workspace()->mouse_motion_event(event.motion); editor->mouse_motion_event(event.motion); for(t_dyninputhandler_list::iterator i= dyninputhandlers.begin(); i!=dyninputhandlers.end(); i++) (*i)->mouse_motion_event(event.motion); } break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: { int b= event.button.button; int fluxbutton= (b==SDL_BUTTON_RIGHT? 2: b==SDL_BUTTON_MIDDLE? 3: b)-1; flux_mouse_button_event(fluxbutton, event.type==SDL_MOUSEBUTTONDOWN); if( find_prim_pos(event.button.x, event.button.y, true) || find_mouse_handler(event.button.x, event.button.y) ) { guimouse= true; } else { guimouse= false; wnd_setkbdfocus(NOWND); if(event.type==SDL_MOUSEBUTTONUP) mouse.buttons&= ~(SDL_BUTTON(event.button.button)); else mouse.buttons|= SDL_BUTTON(event.button.button); mouse.x= event.button.x; mouse.y= event.button.y; current_workspace()->mouse_button_event(event.button); editor->mouse_button_event(event.button); for(t_dyninputhandler_list::iterator i= dyninputhandlers.begin(); i!=dyninputhandlers.end(); i++) (*i)->mouse_button_event(event.button); } break; } case SDL_QUIT: quit= true; break; case SDL_VIDEORESIZE: { SDL_Surface *surf= SDL_SetVideoMode(event.resize.w, event.resize.h, 0, SDL_OPENGL|SDL_RESIZABLE); if(!surf) break; screen.sdl_surface= surf; screen.gl_init(event.resize.w, event.resize.h); current_workspace()->centerimage(); break; } case SDL_ACTIVEEVENT: { if(event.active.state&SDL_APPINPUTFOCUS) { hasinputfocus= event.active.gain; SDL_ShowCursor(!hasinputfocus); } if(event.active.state&SDL_APPMOUSEFOCUS) hasmousefocus= event.active.gain; break; } case SDL_VIDEOEXPOSE: { if(!hasinputfocus) { glClear(GL_DEPTH_BUFFER_BIT); current_workspace()->render(); SDL_GL_SwapBuffers(); checkglerror(); } break; } } } int x, y; SDL_GetMouseState(&x, &y); mousepos.x= x; mousepos.y= y; SDL_GetRelativeMouseState(&x, &y); mousevel.x= x; mousevel.y= y; mousevel.mul( 1000.0/(curmillis-lastmillis) ); current_workspace()->image->frame_tick((curmillis-lastmillis)*0.001); runphysics(); if(hasinputfocus) { glClear(GL_DEPTH_BUFFER_BIT); //~ screen.setperspective(); current_workspace()->render(); if(hasmousefocus && !guimouse) editor->render(); #if 1 next_event(); //~ aq_exec(); run_timers(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, screen.width,screen.height, 0, -1000, 1000); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //~ glEnable(GL_POINT_SMOOTH); //~ glPointSize(1.0); //~ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //~ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glColor3f(1,1,1); glDisable(GL_TEXTURE_2D); redraw_rect(&viewport); //~ cliptext(0,0,0,0); update_rect(&viewport); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); #endif gui->tick( (curmillis-lastmillis)*0.001 ); if(guimouse) { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glDisable(GL_DEPTH_TEST); redraw_cursor(); } SDL_GL_SwapBuffers(); checkglerror(); } int delay= 10 - (curmillis-lastmillis); if(!hasinputfocus) SDL_Delay(100); if(delay>0) SDL_Delay(delay); } SDL_WM_GrabInput(SDL_GRAB_OFF); delete gui; gui= 0; }
void EBePrivateWin::DispatchMessage(BMessage *bMsg, BHandler *handler) { bool handled = true; if(bMsg->what == 'etk_') { int32 what = 0; bMsg->FindInt32("etk:what", &what); switch(what) { case ETK_BEOS_QUIT: doQuit = true; PostMessage(B_QUIT_REQUESTED); break; case ETK_BEOS_CONTACT_TO: { fContactor = EMessenger(); const char *buffer = NULL; ssize_t size = -1; if(bMsg->FindData("etk:messenger", B_ANY_TYPE, (const void**)&buffer, &size) != B_OK) break; if(buffer == NULL || size <= 0) break; fContactor.Unflatten(buffer, (size_t)size); } break; case ETK_BEOS_SET_BACKGROUND: { rgb_color bkColor; if(bMsg->FindInt32("background", (int32*)&bkColor) != B_OK) break; fTopView->SetViewColor(bkColor); fTopView->Invalidate(); } break; case ETK_BEOS_SET_LOOK: { int8 look; if(bMsg->FindInt8("look", &look) != B_OK) break; switch((e_window_look)look) { case E_BORDERED_WINDOW_LOOK: SetLook(B_BORDERED_WINDOW_LOOK); break; case E_NO_BORDER_WINDOW_LOOK: SetLook(B_NO_BORDER_WINDOW_LOOK); break; case E_TITLED_WINDOW_LOOK: SetLook(B_TITLED_WINDOW_LOOK); break; case E_DOCUMENT_WINDOW_LOOK: SetLook(B_DOCUMENT_WINDOW_LOOK); break; case E_MODAL_WINDOW_LOOK: SetLook(B_MODAL_WINDOW_LOOK); break; case E_FLOATING_WINDOW_LOOK: SetLook(B_FLOATING_WINDOW_LOOK); break; default: break; } } break; case ETK_BEOS_SET_TITLE: { const char *title = NULL; if(bMsg->FindString("title", &title) != B_OK) break; SetTitle(title); } break; case ETK_BEOS_SET_WORKSPACES: { uint32 workspaces = 0; if(bMsg->FindInt32("workspaces", (int32*)&workspaces) != B_OK) break; if(workspaces == 0) workspaces = current_workspace() + 1; SetWorkspaces(workspaces); } break; case ETK_BEOS_GET_WORKSPACES: { uint32 workspaces = Workspaces(); bMsg->AddInt32("workspaces", *((int32*)&workspaces)); } break; case ETK_BEOS_ICONIFY: if(!IsMinimized()) Minimize(true); break; case ETK_BEOS_SHOW: if(IsHidden()) { uint32 oldFlags = Flags(); SetFlags(oldFlags | B_AVOID_FOCUS); Show(); if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags); } break; case ETK_BEOS_HIDE: if(!IsHidden()) Hide(); break; case ETK_BEOS_RAISE: if(!IsFront()) { uint32 oldFlags = Flags(); SetFlags(oldFlags | B_AVOID_FOCUS); Activate(true); if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags); } break; case ETK_BEOS_LOWER: { BHandler *_frontWin = NULL; if(bMsg->FindPointer("front", (void**)&_frontWin) != B_OK) break; BWindow *frontWin = e_cast_as(_frontWin, BWindow); if(frontWin == NULL) break; SendBehind(frontWin); bMsg->AddBool("done", true); } break; case ETK_BEOS_ACTIVATE: { bool state; if(bMsg->FindBool("state", &state) != B_OK || state == IsActive()) break; Activate(state); } break; case ETK_BEOS_GET_ACTIVATED_STATE: bMsg->AddBool("state", IsActive()); break; case ETK_BEOS_MOVE_RESIZE: { if(bMsg->HasPoint("where")) { BPoint pt; if(bMsg->FindPoint("where", &pt) == B_OK) MoveTo(pt); } if(bMsg->HasFloat("width") && bMsg->HasFloat("height")) { float w = -1, h = -1; bMsg->FindFloat("width", &w); bMsg->FindFloat("height", &h); if(w < 0 || h < 0) break; ResizeTo(w, h); } } break; case ETK_BEOS_DRAW_BITMAP: { BBitmap *bitmap = NULL; BRect srcRect, destRect; const ERegion *clipping = NULL; if(bMsg->FindPointer("bitmap", (void**)&bitmap) != B_OK || bitmap == NULL) break; bMsg->FindRect("src", &srcRect); bMsg->FindRect("dest", &destRect); if(srcRect.IsValid() == false || destRect.IsValid() == false) break; bMsg->FindPointer("clipping", (void**)&clipping); BRegion beRegion; __etk_convert_region(clipping, &beRegion, fTopView->Bounds()); fTopView->ConstrainClippingRegion(&beRegion); fTopView->DrawBitmap(bitmap, srcRect, destRect); } break; case ETK_BEOS_GRAB_MOUSE: case ETK_BEOS_UNGRAB_MOUSE: { uint32 options = (what == ETK_BEOS_GRAB_MOUSE ? B_LOCK_WINDOW_FOCUS : 0); if(fTopView->SetEventMask(B_POINTER_EVENTS, options) != B_OK) break; bMsg->AddBool("state", what == ETK_BEOS_GRAB_MOUSE); } break; case ETK_BEOS_GRAB_KEYBOARD: case ETK_BEOS_UNGRAB_KEYBOARD: { uint32 options = (what == ETK_BEOS_GRAB_KEYBOARD ? B_LOCK_WINDOW_FOCUS : 0); if(fTopView->SetEventMask(B_KEYBOARD_EVENTS, options) != B_OK) break; bMsg->AddBool("state", what == ETK_BEOS_GRAB_KEYBOARD); } break; case ETK_BEOS_QUERY_MOUSE: { BPoint pt; uint32 btns = 0; fTopView->GetMouse(&pt, &btns, false); bMsg->AddInt32("x", (int32)pt.x); bMsg->AddInt32("y", (int32)pt.y); bMsg->AddInt32("buttons", (int32)btns); } break; case ETK_BEOS_SET_SIZE_LIMITS: { BRect r; if(bMsg->FindRect("limits", &r) != B_OK) break; SetSizeLimits(r.left, r.right, r.top, r.bottom); bMsg->AddBool("done", true); } break; case ETK_BEOS_GET_SIZE_LIMITS: { BRect r(-1, -1, -1, -1); GetSizeLimits(&(r.left), &(r.right), &(r.top), &(r.bottom)); bMsg->AddRect("limits", r); } break; default: handled = false; break; } if(handled) { BMessage aMsg(*bMsg); bMsg->SendReply(&aMsg); return; } } switch(bMsg->what) { case B_WINDOW_ACTIVATED: { handled = false; if(fContactor.IsValid() == false) break; EMessage message(E_WINDOW_ACTIVATED); message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); fContactor.SendMessage(&message); } break; case B_MOUSE_DOWN: case B_MOUSE_UP: case B_MOUSE_MOVED: { if(fContactor.IsValid() == false) break; BPoint where; int32 buttons = 0; bMsg->FindPoint("where", &where); if(bMsg->what != B_MOUSE_UP) bMsg->FindInt32("buttons", &buttons); int32 clicks = 1; if(bMsg->what == B_MOUSE_DOWN) { #if 0 bMsg->FindInt32("clicks", &clicks); #else bigtime_t eventTime; if(bMsg->FindInt64("when", &eventTime) == B_OK) { if(eventTime - fPrevMouseDownTime <= CLICK_TIMEOUT) clicks = (fPrevMouseDownCount += 1); else clicks = fPrevMouseDownCount = 1; fPrevMouseDownTime = eventTime; } #endif } EMessage message; if(bMsg->what == B_MOUSE_DOWN) message.what = E_MOUSE_DOWN; else if(bMsg->what == B_MOUSE_UP) message.what = E_MOUSE_UP; else message.what = E_MOUSE_MOVED; message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); if(bMsg->what != B_MOUSE_UP) message.AddInt32("buttons", buttons); if(bMsg->what == B_MOUSE_DOWN) message.AddInt32("clicks", clicks); message.AddPoint("where", EPoint(where.x, where.y)); ConvertToScreen(&where); message.AddPoint("screen_where", EPoint(where.x, where.y)); // TODO: modifiers message.AddMessenger("etk:msg_for_target", fContactor); etk_app->PostMessage(&message); } break; case B_KEY_DOWN: case B_KEY_UP: case B_UNMAPPED_KEY_DOWN: case B_UNMAPPED_KEY_UP: { if(fContactor.IsValid() == false) break; int8 byte[4]; const char *bytes = NULL; int32 numBytes = 0; int32 key = 0; int32 key_repeat = 0; int32 beModifiers = 0; eint32 modifiers = 0; bMsg->FindInt32("key", &key); bMsg->FindInt32("modifiers", &beModifiers); bzero(byte, sizeof(int8) * 4); if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP) { for(int32 i = 0; i < 3; i++) bMsg->FindInt8("byte", i, &byte[i]); if(bMsg->FindString("bytes", &bytes) == B_OK) numBytes = strlen(bytes); // if(bMsg->what == B_KEY_DOWN) bMsg->FindInt32("be:key_repeat", &key_repeat); } else { etk_beos_get_byte(beModifiers, key, (char*)byte); } if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY; if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY; if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY; EMessage message; if(bMsg->what == B_KEY_DOWN) message.what = E_KEY_DOWN; else if(bMsg->what == B_KEY_UP) message.what = E_KEY_UP; else if(bMsg->what == B_UNMAPPED_KEY_DOWN) message.what = E_UNMAPPED_KEY_DOWN; else message.what = E_UNMAPPED_KEY_UP; message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); message.AddInt32("key", key); message.AddInt32("modifiers", modifiers); if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP) { if(bMsg->what == B_KEY_DOWN) message.AddInt32("etk:key_repeat", key_repeat); for(int32 i = 0; i < 3; i++) message.AddInt8("byte", byte[i]); if(!(numBytes != 1 || *bytes != byte[0])) { etk_beos_get_byte(beModifiers, key, (char*)byte); message.AddString("bytes", (char*)byte); } else if(numBytes > 0) { message.AddString("bytes", bytes); } } else if(byte[0] != 0) { message.AddInt8("byte", byte[0]); message.AddString("bytes", (char*)byte); } message.AddMessenger("etk:msg_for_target", fContactor); etk_app->PostMessage(&message); } break; case B_MODIFIERS_CHANGED: { if(fContactor.IsValid() == false) break; eint32 modifiers = 0; eint32 old_modifiers = 0; int32 beModifiers = 0; int32 old_beModifiers = 0; bMsg->FindInt32("modifiers", &beModifiers); bMsg->FindInt32("be:old_modifiers", &old_beModifiers); if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY; if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY; if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY; if(old_beModifiers & B_SHIFT_KEY) old_modifiers |= E_SHIFT_KEY; if(old_beModifiers & B_CONTROL_KEY) old_modifiers |= E_CONTROL_KEY; if(old_beModifiers & B_COMMAND_KEY) old_modifiers |= E_COMMAND_KEY; EMessage message(E_MODIFIERS_CHANGED); message.AddBool("etk:msg_from_gui", true); message.AddInt64("when", e_real_time_clock_usecs()); message.AddInt32("modifiers", modifiers); message.AddInt32("etk:old_modifiers", old_modifiers); message.AddMessenger("etk:msg_for_target", fContactor); etk_app->PostMessage(&message); } break; default: handled = false; break; } if(!handled) BWindow::DispatchMessage(bMsg, handler); }