void CronoView::MessageReceived(BMessage *message) { switch(message->what) { case MSG_CLOSE: { be_app->PostMessage(B_QUIT_REQUESTED); break; } case MSG_ABOUT: { AboutRequested(); break; } case MSG_HOMEPAGE: { const char* homepage = CRONO_HOMEPAGE_URL; be_roster->Launch("text/html",1, const_cast<char**>(&homepage)); break; } case MSG_HELP: { const char* guide = CRONO_USERGUIDE_URL; be_roster->Launch("text/html",1, const_cast<char**>(&guide)); break; } case MSG_SETTINGS: { BRect windowRect(150,150,460,445); SettingsWindow *settWindow = new SettingsWindow(windowRect, fCore); settWindow->Show(); break; } case MSG_START: { status_t ret = fCore->Start(); if (ret != B_OK) { BString str("\nError starting Crono :\n"); str << strerror(ret); BAlert *alert = new BAlert("Error", str.String(), "OK", NULL, NULL, B_WIDTH_FROM_WIDEST, B_EVEN_SPACING, B_INFO_ALERT); alert->Go(); break; } fStartButton->SetEnabled(false); fStopButton->SetEnabled(true); fStopButton->MakeDefault(true); fEditMenu->FindItem(MSG_SETTINGS)->SetEnabled(false); fFileMenu->FindItem(MSG_START)->SetEnabled(false); fFileMenu->FindItem(MSG_STOP)->SetEnabled(true); break; } case MSG_STOP: { fCore->Stop(); fStopButton->SetEnabled(false); fStartButton->SetEnabled(true); fStartButton->MakeDefault(true); fEditMenu->FindItem(MSG_SETTINGS)->SetEnabled(true); fFileMenu->FindItem(MSG_START)->SetEnabled(true); fFileMenu->FindItem(MSG_STOP)->SetEnabled(false); break; } case MSG_VOLUME: { float position = fVolumeSlider->Position(); fCore->SetVolume(position); fVolumeSlider->SetLabel(BString() << position); break; } case MSG_METER_RADIO: { int selected = _GetCurrentMeter(); // If "Other" is selected, enable the fTempoEntry if (fTempoRadios[4]->Value() == true) { fTempoEntry->SetEnabled(true); } else { fTempoEntry->SetEnabled(false); } fCore->SetMeter(selected); if (gCronoSettings.AccentTable) _SetAccentCheckBox(selected); break; } case MSG_METER_ENTRY: { int position = abs(atoi(fTempoEntry->Text())); if (position < 1) { fTempoEntry->SetText("1"); position = 1; return; } else if (position > 100) { fTempoEntry->SetText("100"); position = 100; } fCore->SetMeter(position); _SetAccentCheckBox(position); break; } case MSG_SPEED_ENTRY: { unsigned bpm = abs(atoi(fSpeedEntry->Text())); if (bpm > MAX_SPEED) { fSpeedEntry->SetText(BString() << MAX_SPEED); bpm = MAX_SPEED; } else if (bpm < MIN_SPEED) { fSpeedEntry->SetText(BString() << MIN_SPEED); bpm = MIN_SPEED; } fCore->SetSpeed(((int) bpm)); fSpeedSlider->SetPosition(((float) bpm / MAX_SPEED)); printf("Crono Speed: %s %d\n", fSpeedEntry->Text(), bpm); _UpdateTempoName(bpm); break; } case MSG_SPEED_SLIDER: { int v = fSpeedSlider->Value(); BString str; fSpeedEntry->SetText(str << v); fCore->SetSpeed(v); _UpdateTempoName(v); break; } case MSG_ACCENT_TABLE: { bool marked = !fAccentTableItem->IsMarked(); gCronoSettings.AccentTable = marked; _ShowTable(marked); break; } default: BView::MessageReceived(message); } }
void BrowserWindow::HandleMessage( Message * pcMsg ) { BrowserWebView *pcWebView = GetCurrentWebView(); switch( pcMsg->GetCode() ) { case ID_URL_CHANGED: { bool bFinal = false; pcMsg->FindBool( "final", &bFinal ); if( bFinal ) { String cURL = ""; int nSelection = -1; if( pcMsg->FindInt32( "selection", &nSelection ) == EOK ) cURL = m_pcUrlEdit->GetItem( nSelection ); else { cURL = m_pcUrlEdit->GetCurrentString(); m_pcUrlEdit->AppendItem( cURL ); } OpenURL( cURL ); } break; } case ID_SET_STATUS_BAR_TEXT: { String cText; if( pcMsg->FindString( "text", &cText ) == EOK ) m_pcStatusBar->SetText( "text", cText ); break; } case ID_CLEAR_STATUS_BAR_TEXT: { m_pcStatusBar->SetText( "text", "" ); break; } case ID_CREATE_WINDOW: { BrowserWindow *pcWindow; String cURL; Rect cFrame; /* Use the supplied dimensions if they've been provided, otherwise clone the current Window */ if( pcMsg->FindRect( "frame", &cFrame ) != EOK ) cFrame = GetFrame(); pcWindow = new BrowserWindow( cFrame ); if( pcMsg->FindString( "url", &cURL ) == EOK ) pcWindow->OpenURL( cURL ); pcWindow->Show(); pcWindow->MakeFocus(); /* Tell BrowserApp about the new window */ Application::GetInstance()->PostMessage( ID_WINDOW_OPENED ); if( pcMsg->IsSourceWaiting() ) { WebCore::Page *pcPage; View *pcTab; /* The new window will only have one tab at this stage so it's safe to always get tab #0 */ pcTab = pcWindow->m_pcTabView->GetTabView( 0 ); pcPage = static_cast<BrowserWebView*>( pcTab )->GetWebCoreFrame()->page(); Message cReply( ID_CREATE_WINDOW_REPLY ); cReply.AddPointer( "page", pcPage ); pcMsg->SendReply( &cReply ); } break; } case ID_CREATE_TAB: { String cURL; if( pcMsg->FindString( "url", &cURL ) == EOK ) { uint nTabIndex; nTabIndex = CreateTab( cURL ); if( pcMsg->IsSourceWaiting() ) { WebCore::Page *pcPage; View *pcTab; pcTab = m_pcTabView->GetTabView( nTabIndex ); pcPage = static_cast<BrowserWebView*>( pcTab )->GetWebCoreFrame()->page(); Message cReply( ID_CREATE_WINDOW_REPLY ); cReply.AddPointer( "page", pcPage ); pcMsg->SendReply( &cReply ); } } break; } case ID_BUTTON_BACK: { pcWebView->GoBack(); UpdateButtonState( false ); break; } case ID_BUTTON_FORWARD: { pcWebView->GoForward(); UpdateButtonState( false ); break; } case ID_BUTTON_RELOAD: { pcWebView->Reload(); break; } case ID_BUTTON_STOP: { pcWebView->Stop(); UpdateButtonState( false ); break; } case ID_BUTTON_HOME: { OpenURL( m_pcSettings->GetString( "homepage", "about:blank" ) ); break; } case ID_MENU_APP_ABOUT: { Alert* pcAbout = new Alert( "About Webster", "Webster " WEBSTER_VERSION " (Alpha)\nA WebCore based web browser\n\n© Copyright Kristian Van Der Vliet, 2008\nArno Klenke, 2004-2007\nKurt Skauen, 2001\n" "\nWebster is released under the Gnu Public License (GPL)\n", Alert::ALERT_INFO, 0x00, "Ok", NULL ); pcAbout->Go( NULL ); break; } case ID_MENU_WIN_NEW_TAB: { CreateTab( "" ); break; } case ID_MENU_WIN_CLOSE_TAB: { DestroyTab( m_pcTabView->GetSelection() ); break; } case ID_MENU_EDIT_CUT: { pcWebView->Cut(); break; } case ID_MENU_EDIT_COPY: { pcWebView->Copy(); break; } case ID_MENU_EDIT_PASTE: { pcWebView->Paste(); break; } case ID_MENU_EDIT_DELETE: { pcWebView->Delete(); break; } case ID_MENU_SETTINGS_CONFIGURE: { Rect cSettingsFrame = m_pcGuiSettings->GetRect( "settings", m_cSettingsFrame ); SettingsWindow *pcSettingsWindow = new SettingsWindow( cSettingsFrame, "Webster settings", this, m_pcWebSettings, m_pcSettings, m_pcGuiSettings ); pcSettingsWindow->Show(); pcSettingsWindow->MakeFocus(); break; } case ID_SETTINGS_SAVE: { Settings *pcSettings; if( pcMsg->FindPointer( "settings", (void**)&pcSettings ) == EOK ) { delete m_pcSettings; m_pcSettings = pcSettings; m_pcSettings->Save(); } WebSettings *pcWebSettings; if( pcMsg->FindPointer( "web_settings", (void**)&pcWebSettings ) == EOK ) { delete m_pcWebSettings; m_pcWebSettings = pcWebSettings; } break; } case ID_SETTINGS_APPLY: { Settings *pcSettings; if( pcMsg->FindPointer( "settings", (void**)&pcSettings ) == EOK ) { delete m_pcSettings; m_pcSettings = pcSettings; } WebSettings *pcWebSettings; if( pcMsg->FindPointer( "web_settings", (void**)&pcWebSettings ) == EOK ) { delete m_pcWebSettings; m_pcWebSettings = pcWebSettings; } break; } case ID_MENU_BOOKMARKS_ADD: { String cShortTitle, cLongTitle, cURL; pcWebView->GetTitle( cShortTitle, cLongTitle ); cURL = pcWebView->GetCurrentURL(); m_pcBookmarksManager->AddBookmark( cLongTitle, cURL ); break; } case ID_MENU_BOOKMARKS_MANAGE: { String cPath; if( pcMsg->FindString( "path", &cPath ) != EOK ) break; /* XXXKV: This is a really rubbish way to manage bookmarks: we should have a proper in-application dialog to do it */ /* Open a filebrowser window */ if( fork() == 0 ) { set_thread_priority( -1, 0 ); execlp( "/system/bin/FileBrowser", "/system/bin/FileBrowser", cPath.c_str(), NULL ); } break; } case ID_BOOKMARK_GO: { String cURL; if( pcMsg->FindString( "url", &cURL ) == EOK ) OpenURL( cURL ); break; } case ID_TAB_CHANGED: { ChangeTab( m_pcTabView->GetSelection() ); break; } case ID_WEBVIEW_SET_TITLE: { String cShortTitle, cLongTitle; uint nTabIndex; if( pcMsg->FindString( "short", &cShortTitle ) == EOK && pcMsg->FindString( "long", &cLongTitle ) == EOK && pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK ) { m_pcTabView->SetTabTitle( nTabIndex, cShortTitle ); /* If this is the currently selected tab, set the Window title to the full page title */ if( nTabIndex == m_pcTabView->GetSelection() ) SetTitle( cLongTitle ); } break; } case ID_WEBVIEW_LOAD_STARTED: { String cURL; uint nTabIndex; if( pcMsg->FindString( "url", &cURL ) == EOK && pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK ) { if( nTabIndex == m_pcTabView->GetSelection() ) { m_pcUrlEdit->SetCurrentString( cURL.c_str() ); UpdateButtonState( true ); } } break; } case ID_WEBVIEW_LOAD_FINISHED: { uint nTabIndex; if( pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK ) if( nTabIndex == m_pcTabView->GetSelection() ) UpdateButtonState( false ); break; } default: { fprintf( stderr, "Unknown message with code #%d\n", pcMsg->GetCode() ); Window::HandleMessage( pcMsg ); break; } } }