Beispiel #1
0
void LauncherApp::MessageReceived(BMessage* message)
{
    switch (message->what) {
    case LOAD_AT_STARTING: {
        BString url;
        if (message->FindString("url", &url) != B_OK)
        	break;
        bool openNewWindow = false;
        message->FindBool("new window", &openNewWindow);
        LauncherWindow* webWindow = NULL;
        for (int i = 0; BWindow* window = WindowAt(i); i++) {
            webWindow = dynamic_cast<LauncherWindow*>(window);
            if (!webWindow)
            	continue;
            if (!openNewWindow) {
            	// stop at the first window
	            break;
            }
        }
        if (webWindow) {
        	// There should always be at least one window open. If not, maybe we are about
        	// to quit anyway...
        	if (openNewWindow) {
        		// open a new window with an offset to the last window
                newWindow(url);
        	} else {
            	// load the URL in the first window
                webWindow->CurrentWebView()->LoadURL(url.String());
        	}
        }
        break;
    }
    case B_SILENT_RELAUNCH:
    	newWindow("");
    	break;
    case NEW_WINDOW: {
		BString url;
		if (message->FindString("url", &url) != B_OK)
			break;
    	newWindow(url);
    	break;
    }
    case WINDOW_OPENED:
    	m_windowCount++;
    	break;
    case WINDOW_CLOSED:
    	m_windowCount--;
        message->FindRect("window frame", &m_lastWindowFrame);
    	if (m_windowCount <= 0)
    		PostMessage(B_QUIT_REQUESTED);
    	break;

    default:
        BApplication::MessageReceived(message);
        break;
    }
}
Beispiel #2
0
void LauncherApp::newWindow(const BString& url)
{
	m_lastWindowFrame.OffsetBy(20, 20);
	if (!BScreen().Frame().Contains(m_lastWindowFrame))
		m_lastWindowFrame.OffsetTo(50, 50);

	LauncherWindow* window = new LauncherWindow(m_lastWindowFrame);
	window->Show();
	if (url.Length())
	    window->CurrentWebView()->LoadURL(url.String());
}