Пример #1
0
void
Application::init() {
    setTitle("bROwSE");

    // This looks nicer than setCssTheme("polished"), but requires some minor CSS adjustments:
    //  + IMG should not be restricted to 100% available width, otherwise CFGs will be scaled down by the browser to a point
    //     which might be unreadable.
    setTheme(new Wt::WBootstrapTheme);

    // Hexdump style sheet rules. The colors here are the same as those used by WAddressSpace.
    styleSheet().addRule(".hexdump_evenrow", "font-family:monospace;");
    styleSheet().addRule(".hexdump_oddrow", "font-family:monospace; background-color:#f9f9f9;");
    styleSheet().addRule(".hexdump_unmapped", "background-color:black;");
    styleSheet().addRule(".hexdump_nochar", "background-color:lightgray;");
    styleSheet().addRule(".hexdump_addr_none", "font-family:monospace;"
                         " background-color:" + toHtml(darken(Color::red, 0.25)) + ";");
    styleSheet().addRule(".hexdump_addr_r", "font-family:monospace;"
                         "background-color:" + toHtml(Color::RGB(0.9, 0.8, 0)) + ";");
    styleSheet().addRule(".hexdump_addr_w", "font-family:monospace;"
                         " background-color:" + toHtml(fade(darken(Color::red, 0.25), 0.75)) + ";");
    styleSheet().addRule(".hexdump_addr_x", "font-family:monospace;"
                         " background-color:" + toHtml(darken(Color::green, 0.15)) + ";");
    styleSheet().addRule(".hexdump_addr_rw", "font-family:monospace;"
                         " background-color:" + toHtml(fade(Color::RGB(0.9, 0.8, 0), 0.75)) + ";");
    styleSheet().addRule(".hexdump_addr_rx", "font-family:monospace;"
                         " background-color:" + toHtml(darken(Color::green, 0.15)) + ";"); // same as execute-only
    styleSheet().addRule(".hexdump_addr_wx", "font-family:monospace;"
                         " background-color:" + toHtml(fade(darken(Color::green, 0.15), 0.75)) + ";");
    styleSheet().addRule(".hexdump_addr_rwx", "font-family:monospace;"
                         " background-color:" + toHtml(fade(darken(Color::green, 0.15), 0.75)) + ";");

    // Status message style sheet rules.
    styleSheet().addRule(".status_oddrow", "background-color:#f9f9f9;");
    styleSheet().addRule(".status_info", "background-color:#b5ffb3;");// light green
    styleSheet().addRule(".status_warn", "background-color:#f8ff81;");// light yellow
    styleSheet().addRule(".status_error", "background-color:#ffd781;");// light orange
    styleSheet().addRule(".status_fatal", "background-color:#ff8181;");// light red

    // Strings table style sheet rules
    styleSheet().addRule(".strings_oddrow", "background-color:#f9f9f9;");
    styleSheet().addRule(".strings_matched", "background-color:#fff195;");// light yellow

    // So other threads can obtain a lock, modify the DOM, and then call triggerUpdate.
    enableUpdates(true);

    // The application has mutually exclusive phases that are children of a stacked widget
    Wt::WVBoxLayout *vbox = new Wt::WVBoxLayout;
    root()->setLayout(vbox);
    wStacked_ = new Wt::WStackedWidget;
    vbox->addWidget(wStacked_);

    //--------------
    // Splash phase
    //--------------
    WSplash *wSplash = new WSplash;
    wSplash->clicked().connect(boost::bind(&Wt::WStackedWidget::setCurrentIndex, wStacked_, InteractivePhase));
    ASSERT_require(wStacked_->count() == SplashPhase);
    wStacked_->addWidget(wSplash);
    wStacked_->setCurrentIndex(SplashPhase);

    //------------
    // Busy phase
    //------------
    ctx_.busy = new WBusy(ctx_);
    ctx_.busy->workStarted().connect(boost::bind(&Wt::WStackedWidget::setCurrentIndex, wStacked_, BusyPhase));
    ctx_.busy->workFinished().connect(boost::bind(&Wt::WStackedWidget::setCurrentIndex, wStacked_, InteractivePhase));
    ASSERT_require(wStacked_->count() == BusyPhase);
    wStacked_->addWidget(ctx_.busy);

    //-------------------
    // Interactive phase
    //-------------------
    wInteractivePhase_ = new Wt::WContainerWidget;
    ASSERT_require(wStacked_->count() == InteractivePhase);
    wStacked_->addWidget(wInteractivePhase_);

    // Grid layout
    wInteractivePhase_->setLayout(wGrid_ = new Wt::WGridLayout);
    wGrid_->setRowStretch(1, 1);
    wGrid_->setColumnStretch(1, 1);

    // Logo (reset button)
    // FIXME[Robb P. Matzke 2014-12-27]: eventually this should be a reset button
    Wt::WImage *wLogo = new Wt::WImage("/images/logo.png");
    wLogo->setToolTip("Click here to reset the server");
    wLogo->clicked().connect(boost::bind(killServer));
    wLogo->resize(32, 32);
    wGrid_->addWidget(wLogo, 0, 0);
    wGrid_->addWidget(new Wt::WText("bROwSE: Binary ROSE On-line Workbench for Specimen Exploration"), 0, 1);

    // The central region the page is a set of tabs that are visible or not depending on the context
    wGrid_->addWidget(instantiateMainTabs(), 1, 1);

    // East side is a tool pane
    Wt::WContainerWidget *rightPane = new Wt::WContainerWidget;
    wGrid_->addWidget(rightPane, 1, 2);

    wSemantics_ = new WSemantics(ctx_, rightPane);

    wCrossRefs_ = new WCrossReferences(rightPane);
    wCrossRefs_->referenceClicked().connect(boost::bind(&Application::gotoReference, this, _1));

    // The bottom center is the status area
    wStatusBar_ = new WStatusBar;
    wStatus_->messageArrived().connect(boost::bind(&WStatusBar::appendMessage, wStatusBar_, _1));
    wGrid_->addWidget(wStatusBar_, 2, 1);

    //---------
    // Startup
    //---------

    wPartitioner_->memoryMapProvider(wMemoryMap_);
    showHideTabs();
}