toplevel.cpp

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

CPP
695
字号
/* * =========================================================================== * PRODUCTION $Log: toplevel.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:14:14  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: toplevel.cpp,v 1000.1 2004/06/01 21:14:14 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: *    CTopLevel -- top-level MDI window */#include <ncbi_pch.hpp>#include <gui/widgets/toplevel/toplevel.hpp>#include <FL/Fl.H>#include <FL/Fl_Box.H>#include <FL/Fl_Button.H>#include <FL/Fl_Group.H>#include <FL/Fl_Pixmap.H>#include <FL/Fl_Double_Window.H>#include <FL/fl_draw.H>#include "icon_tray.hpp"#include <algorithm>#include <math.h>BEGIN_NCBI_SCOPE//// static pixmaps// these are for the buttons in the system tray//static const char* sc_minimize_xpm[] = {    " 8 8 2 1",    "  c #111111",    "X c None",    "XXXXXXXX",    "XXXXXXXX",    "XXXXXXXX",    "XXXXXXXX",    "XXXXXXXX",    "XXXXXXXX",    "        ",    "        "};static const char* sc_maximize_xpm[] = {    " 8 8 2 1",    "  c #111111",    "X c None",    "        ",    "        ",    " XXXXXX ",    " XXXXXX ",    " XXXXXX ",    " XXXXXX ",    " XXXXXX ",    "        "};static const char* sc_close_xpm[] = {    "8 8 3 1",    "  c #111111",    ". c #616561",    "X c None",    " .XXXX. ",    ". .XX. .",    "X. .. .X",    "XX.  .XX",    "XX.  .XX",    "X. .. .X",    ". .XX. .",    " .XXXX. ",};//// static accessors - forwarded to CChildFrame//Fl_Boxtype CTopLevel::GetSysButtonBox(void){    return CChildFrame::GetSysButtonBox();}void CTopLevel::SetSysButtonBox(Fl_Boxtype box){    CChildFrame::SetSysButtonBox(box);}Fl_Color CTopLevel::GetSysButtonColor(void){    return CChildFrame::GetSysButtonColor();}void CTopLevel::SetSysButtonColor(Fl_Color color){    CChildFrame::SetSysButtonColor(color);}Fl_Color CTopLevel::GetSelectedColor(void){    return CChildFrame::GetSelectedColor();}void CTopLevel::SetSelectedColor(Fl_Color color){    CChildFrame::SetSelectedColor(color);}Fl_Font CTopLevel::GetTitleFont(void){    return CChildFrame::GetTitleFont();}void CTopLevel::SetTitleFont(Fl_Font font){    CChildFrame::SetTitleFont(font);}Fl_Color CTopLevel::GetTitleColor(void){    return CChildFrame::GetTitleColor();}void CTopLevel::SetTitleColor(Fl_Color color){    CChildFrame::SetTitleColor(color);}int CTopLevel::GetTitleSize(void){    return CChildFrame::GetTitleSize();}void CTopLevel::SetTitleSize(int size){    CChildFrame::SetTitleSize(size);}int CTopLevel::GetTitleAlign(void){    return CChildFrame::GetTitleAlign();}void CTopLevel::SetTitleAlign(int align){    CChildFrame::SetTitleAlign(align);}////// class CTopLevel////CTopLevel::CTopLevel(int x, int y, int wid, int ht, const char* label)    : Fl_Double_Window(x, y, wid, ht, label),      m_Selected(NULL),      m_IconTray(NULL),      m_MinimizeXPM(new Fl_Pixmap(sc_minimize_xpm)),      m_MaximizeXPM(new Fl_Pixmap(sc_maximize_xpm)),      m_CloseXPM   (new Fl_Pixmap(sc_close_xpm)),      m_LastChildX(0),      m_LastChildY(10){}CTopLevel::~CTopLevel(){    delete m_MaximizeXPM;    delete m_MinimizeXPM;    delete m_CloseXPM;}//// add a child to our window//void CTopLevel::AddChild(CChild* child){    if (!child) {        return;    }    //    // create a new frame to hold the child    //    child->hide();    // determine where this child will occur    m_LastChildX += CChildFrame::GetTitleBarHeight();    m_LastChildY += CChildFrame::GetTitleBarHeight();    if (m_LastChildX > w() - CChildFrame::GetTitleBarHeight()) {        m_LastChildX = 0;    }    if (m_LastChildY > h() - CChildFrame::GetTitleBarHeight()) {        m_LastChildY = 0;    }    //    // positions for our frame and subwidgets    //    // pseudoconstants constrolling our layout    const int button_w = 11 + Fl::box_dw(CChildFrame::GetSysButtonBox());    const int button_h = 11 + Fl::box_dh(CChildFrame::GetSysButtonBox());    const int x_step = button_w + 2;    CChildFrame::SetTitleBarHeight(max (CChildFrame::GetTitleSize() + 3,                                        button_h + 3));    // frame positions - dependent on our child window    Fl_Boxtype frame_box = FL_UP_BOX;    int frame_x = m_LastChildX;    int frame_y = m_LastChildY;    int frame_w = child->w() + Fl::box_dw(frame_box);    int frame_h = child->h() + Fl::box_dh(frame_box) +                  CChildFrame::GetTitleBarHeight();    // reposition our child relative to the new frame    child->position(frame_x + Fl::box_dx(frame_box),                    frame_y + Fl::box_dy(frame_box) +                    CChildFrame::GetTitleBarHeight());    // title group - encompasses the entire title bar    int title_group_x = 0 + Fl::box_dx(frame_box);    int title_group_y = 0 + Fl::box_dy(frame_box);    int title_group_w = frame_w - Fl::box_dw(frame_box) - 1;    int title_group_h = CChildFrame::GetTitleBarHeight();    // system buttons group    int sysbutt_x = 0 + frame_w - Fl::box_dw(frame_box) - x_step * 3 + 2;    int sysbutt_y = 0 + Fl::box_dy(frame_box);    int sysbutt_w = title_group_w - (sysbutt_x - 0) - 2;    int sysbutt_h = CChildFrame::GetTitleBarHeight();    // title label    int title_x = title_group_x;    int title_y = title_group_y;    int title_w = title_group_w - sysbutt_w - 5;    int title_h = title_group_h;    // offsets for buttons    int button_y = sysbutt_y + (sysbutt_h - button_h + 1) / 2;    // create the parent frame    CChildFrame* frame = new CChildFrame(frame_x, frame_y, frame_w, frame_h);    frame->box(frame_box);    // title bar    // this has a few system buttons in it    Fl_Group* title_bar =  new Fl_Group(title_group_x, title_group_y,                                        title_group_w, title_group_h);    title_bar->clear_visible_focus();    // spacer to prevent system buttons from resizing    // this also holds the title    Fl_Group* spacer = new Fl_Group(title_x, title_y, title_w, title_h,                                    child->label());    spacer->box       (FL_NO_BOX);    spacer->color     (CChildFrame::GetSelectedColor());    spacer->align     (CChildFrame::GetTitleAlign() | FL_ALIGN_INSIDE);    spacer->labelcolor(CChildFrame::GetTitleColor());    spacer->labelfont (CChildFrame::GetTitleFont());    spacer->labelsize (CChildFrame::GetTitleSize());    spacer->clear_visible_focus();    spacer->end();    title_bar->resizable(spacer);    // system buttons, grouped to prevent resize and to facilitate easier event    // screening    Fl_Group* sys_buttons = new Fl_Group(sysbutt_x, sysbutt_y,                                         sysbutt_w, sysbutt_h);    sys_buttons->box(FL_NO_BOX);    sys_buttons->clear_visible_focus();    // minimize button    Fl_Button* minimize = new Fl_Button(sysbutt_x, button_y,                                        button_w, button_h);    minimize->image   (m_MinimizeXPM);    minimize->box     (CChildFrame::GetSysButtonBox());    minimize->color   (CChildFrame::GetSysButtonColor());    minimize->tooltip ("Minimize this window");    minimize->callback((Fl_Callback*)&CTopLevel::x_StaticCB_Minimize, this);    minimize->clear_visible_focus();    // maximize button    Fl_Button* maximize = new Fl_Button(sysbutt_x + x_step, button_y,                                        button_w, button_h);    maximize->image   (m_MaximizeXPM);    maximize->box     (CChildFrame::GetSysButtonBox());    maximize->color   (CChildFrame::GetSysButtonColor());    maximize->tooltip ("Maximize this window");    maximize->callback((Fl_Callback*)&CTopLevel::x_StaticCB_Maximize, this);    maximize->clear_visible_focus();    // close button    Fl_Button* close = new Fl_Button(sysbutt_x + x_step * 2, button_y,

⌨️ 快捷键说明

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