toplevel.cpp

来自「ncbi源码」· C++ 代码 · 共 695 行 · 第 1/2 页

CPP
695
字号
                                     button_w, button_h);    close->image   (m_CloseXPM);    close->box     (CChildFrame::GetSysButtonBox());    close->color   (CChildFrame::GetSysButtonColor());    close->tooltip ("Hide this window");    close->callback((Fl_Callback*)&CTopLevel::x_StaticCB_Close, this);    close->clear_visible_focus();    // end sys group    sys_buttons->end();    // end title bar    title_bar->end();    // end frame    frame->end();    add(*frame);    // create a frame manager class    frame->m_TitleBar   = title_bar;    frame->m_SysButtons = sys_buttons;    frame->m_Title      = spacer;    frame->Attach(child);    m_Children.push_back(frame);    frame->show();    child->show();    // and select our current frame    x_SetSelected(frame);}void CTopLevel::x_SetSelected(CChildFrame* frame){    if (m_Selected) {        m_Selected->m_Title->box(FL_NO_BOX);        m_Selected->m_Title->redraw();    }    // determine our new selection    // if the selection is NULL and we have kids, we automatically select the    // last child ( = topmost)    m_Selected = frame;    if ( !m_Selected ) {        return;    }    // cycle the child to the end of the array of children    // this has the effect of raising the window and provides us with correct    // selection order    TChildren::iterator iter =        std::find(m_Children.begin(), m_Children.end(), m_Selected);    if (iter != m_Children.end()) {        CChildFrame* frame = *iter;        m_Children.erase(iter);        m_Children.push_back(frame);    }    // we re-add the frame    // this keeps the child array in sync with m_Children    add(m_Selected);    //m_Selected->hide();    m_Selected->show();    // make sure the title bar is correctly highlighted    m_Selected->m_Title->box(FL_ROUNDED_BOX);    m_Selected->m_Title->redraw();}int CTopLevel::handle(int event){    switch (event) {        //        // FL_PUSH: handle mouse click events        // We need to distinguish a few things here:        //        // title bar single click - begin drag or select new child        // frame border single click - begin resize or select new child        // system buttons single click - select new child and pass on to button        //    case FL_PUSH:        if ( !m_Selected  ||  !Fl::event_inside(m_Selected) )  {             // try to select another child             // we scan in reverse, as this scans top-most down             TChildren::reverse_iterator start(m_Children.end());             TChildren::reverse_iterator stop (m_Children.begin());             for ( ;  start != stop;  ++start) {                 CChildFrame* child = *start;                 if (child->visible()  &&  Fl::event_inside(child)) {                     x_SetSelected(child);                     if (Fl::event_inside(child->m_SysButtons)) {                         // we select the window, but let the child process                         // the event                         break;                     }                     // claim the event for our own, don't pass on to children                     // or parent                     return 1;                 }             }        }        break;    default:        break;    }    return Fl_Double_Window::handle(event);}void CTopLevel::resize(int x, int y, int w, int h){    if (m_Selected  &&  m_Selected->GetMaximized()) {        m_Selected->resize(0, 0, w, h);    }    Fl_Double_Window::resize(x, y, w, h);}//// Force all windows to cascade//void CTopLevel::Cascade(void){    if (m_Selected  &&  m_Selected->GetMaximized()) {        return;    }    int pos_x = 0;    int pos_y = 0;    int step  = CChildFrame::GetTitleBarHeight();    NON_CONST_ITERATE (TChildren, iter, m_Children) {        CChildFrame* frame = *iter;        if ( !frame->visible()  ||  frame->GetMinimized() ) {            continue;        }        frame->position(pos_x, pos_y);        pos_x += step;        pos_y += step;        if (pos_x > w() - 100) {            pos_x = 0;        }        if (pos_y > h() - step) {            pos_y = 0;        }    }}void CTopLevel::Tile(void){    if (m_Children.size() == 0  ||        (m_Selected  &&  m_Selected->GetMaximized())) {        return;    }    // firstly, count the number of kids we evaluate    int kids = 0;    ITERATE (TChildren, iter, m_Children) {        const CChildFrame* frame = *iter;        if ( !frame->visible()  ||  frame->GetMinimized() ) {            continue;        }        ++kids;    }    // determine the optimal number of rows and columns    float s = (float)::sqrt((double)kids);    int kids_w = (int)s;    int kids_h = kids_w;    if (kids_w < s) {        ++kids_w;    }    while (kids_w * kids_h < kids) {        ++kids_h;    }    int child_width  = w() / kids_w;    int child_height = h() / kids_h;    for (TChildren::size_type i = 0, j = 0;  i < m_Children.size();  ++i) {        CChildFrame* frame = m_Children[i];        if ( !frame->visible()  ||  frame->GetMinimized() ) {            continue;        }        int pos_x = (j % kids_w) * child_width;        int pos_y = (j / kids_w) * child_height;        ++j;        frame->resize(pos_x, pos_y, child_width, child_height);    }}//// Window Maximization//void CTopLevel::x_Maximize(void){    if ( !m_Selected ) {        return;    }    if ( m_Selected->GetMaximized()) {        m_Selected->m_State = CChildFrame::eNormal;        m_Selected->resize(m_Selected->m_SavedPos[0],                           m_Selected->m_SavedPos[1],                           m_Selected->m_SavedPos[2],                           m_Selected->m_SavedPos[3]);        // must redraw the whole thing        redraw();    } else {        m_Selected->m_SavedPos[0] = m_Selected->x();        m_Selected->m_SavedPos[1] = m_Selected->y();        m_Selected->m_SavedPos[2] = m_Selected->w();        m_Selected->m_SavedPos[3] = m_Selected->h();        m_Selected->m_State = CChildFrame::eMaximized;        m_Selected->resize(0, 0, w(), h());        m_Selected->redraw();    }}void CTopLevel::x_StaticCB_Maximize(Fl_Widget* w, void* data){    if ( !data ) {        return;    }    CTopLevel* toplevel = reinterpret_cast<CTopLevel*> (data);    toplevel->x_Maximize();}//// Window Minimization / iconification//void CTopLevel::x_Minimize(void){    //FIXME: implement this#if 0    if ( !m_Selected ) {        return;    }    if ( !m_IconTray ) {        m_IconTray = new CIconTray(0, 0, w(), h());        m_IconTray->box(FL_NO_BOX);        insert(*m_IconTray, 0);    }    m_IconTray->Add(m_Selected);    redraw();#endif}void CTopLevel::x_StaticCB_Minimize(Fl_Widget*, void* data){    CTopLevel* frame = reinterpret_cast<CTopLevel*> (data);    if (frame) {        frame->x_Minimize();    }}//// Window "close"// This is really hide - true deletion is handled elsewhere//void CTopLevel::x_Close(void){    if ( !m_Selected ) {        return;    }    m_Selected->hide();}void CTopLevel::x_StaticCB_Close(Fl_Widget*, void* data){    if ( !data ) {        return;    }    CTopLevel* toplevel = reinterpret_cast<CTopLevel*> (data);    toplevel->x_Close();}END_NCBI_SCOPE/* * =========================================================================== * $Log: toplevel.cpp,v $ * Revision 1000.1  2004/06/01 21:14:14  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * * Revision 1.9  2004/05/21 22:27:56  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.8  2004/05/03 13:23:58  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.7  2003/07/25 13:38:44  dicuccio * Minor clean-up in issuing redraw events * * Revision 1.6  2003/03/25 13:17:50  dicuccio * Fix (hopefully) MIPS compile - be explicit about which sqrt() is being used * * Revision 1.5  2003/03/17 19:48:52  dicuccio * Fixed xpm specifications to make WorkShop compiler happy. * * Revision 1.4  2003/03/17 14:55:41  dicuccio * Lots of clean-up.  Fixed memory leaks in test program; added more explicit * destruction pathway to support integration into Genome Workbench.  Added * explicit calls to cascade / tile widgets in a toplevel workspace. * * Revision 1.3  2003/03/07 18:14:58  dicuccio * Code clean-up.  Added missing accessors for look-n-feel statics; aligned * accessors in code * * Revision 1.2  2003/03/07 17:49:25  dicuccio * Small clean-ups.  Added description for each class. * * Revision 1.1  2003/03/07 17:36:08  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?