dock_frame.cpp

来自「ncbi源码」· C++ 代码 · 共 436 行

CPP
436
字号
/* * =========================================================================== * PRODUCTION $Log: dock_frame.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:08:22  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2 * PRODUCTION * =========================================================================== *//*  $Id: dock_frame.cpp,v 1000.1 2004/06/01 21:08:22 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: *    CDockFrame -- internal widget class that represents the frame *                   surrounding a given MDI child */#include <ncbi_pch.hpp>#include "dock_frame.hpp"#include <FL/Fl_Box.H>#include <FL/Fl_Button.H>#include <FL/Fl_Pixmap.H>BEGIN_NCBI_SCOPEstatic void s_RedockLeft_cb(Fl_Widget* w, void* data){    CDockFrame* frame = reinterpret_cast<CDockFrame*>(data);    if (frame) {        frame->RedockLeft();    }}static void s_RedockRight_cb(Fl_Widget* w, void* data){    CDockFrame* frame = reinterpret_cast<CDockFrame*>(data);    if (frame) {        frame->RedockRight();    }}static void s_RedockBottom_cb(Fl_Widget* w, void* data){    CDockFrame* frame = reinterpret_cast<CDockFrame*>(data);    if (frame) {        frame->RedockBottom();    }}static void s_RedockTop_cb(Fl_Widget* w, void* data){    CDockFrame* frame = reinterpret_cast<CDockFrame*>(data);    if (frame) {        frame->RedockTop();    }}static void s_Remove_cb(Fl_Widget* w, void* data){    CDockFrame* frame = reinterpret_cast<CDockFrame*>(data);    if (frame) {        frame->Remove();    }}CDockFrame::CDockFrame(CDockWidget* parent,                       int x, int y, int w, int h, const char* label)    : Fl_Group(x, y, w, h, label)    , m_Parent(parent)    , m_Owner(false){}CDockFrame::~CDockFrame(){    // detach our child, if it exists    Detach();}void CDockFrame::Attach(Fl_Widget* child, bool owner){    Detach();    m_Child = child;    m_Owner = owner;    // our border    const size_t border_h = 10;    const size_t control_btn_w = 8;    const size_t control_btn_h = 8;    const size_t control_btn_spacing = 2;    const size_t control_btn_panel_w = (control_btn_w+ control_btn_spacing) * 5;    {{        // our control group        Fl_Box* box       = NULL;        Fl_Button* button = NULL;        Fl_Group* group   = new Fl_Group(x(), y(), w(), border_h);        group->box(FL_FLAT_BOX);        const size_t gripper_w = group->w() - 3 -            (control_btn_panel_w + control_btn_spacing);        const size_t gripper_h = 3;        // gripper bars        box = new Fl_Box(group->x() + 2, group->y() + 2,                         gripper_w, gripper_h);        box->box(FL_THIN_UP_FRAME);        box->clear_visible_focus();        //group->add(box);        group->resizable(box);            box = new Fl_Box(group->x() + 2,                         group->y() + border_h - gripper_h - 2,                         gripper_w, gripper_h);        box->box(FL_THIN_UP_FRAME);        box->clear_visible_focus();        //group->add(box);        // buttons        size_t control_x = group->x() + gripper_w + control_btn_spacing * 2;        button = new Fl_Button(control_x, group->y() + 1,                               control_btn_w, control_btn_h);        button->box(FL_THIN_UP_FRAME);        button->image(x_GetDockPositionImg(CDockWidget::eDock_Left));        button->clear_visible_focus();        button->tooltip("Re-dock this window on the left");        button->callback(s_RedockLeft_cb, this);        control_x += control_btn_w + control_btn_spacing;        button = new Fl_Button(control_x, group->y() + 1,                               control_btn_w, control_btn_h);        button->box(FL_THIN_UP_FRAME);        button->image(x_GetDockPositionImg(CDockWidget::eDock_Right));        button->clear_visible_focus();        button->callback(s_RedockRight_cb, this);        button->tooltip("Re-dock this window on the right");        control_x += control_btn_w + control_btn_spacing;        button = new Fl_Button(control_x, group->y() + 1,                               control_btn_w, control_btn_h);        button->box(FL_THIN_UP_FRAME);        button->image(x_GetDockPositionImg(CDockWidget::eDock_Top));        button->clear_visible_focus();        button->callback(s_RedockTop_cb, this);        button->tooltip("Re-dock this window on the top");        control_x += control_btn_w + control_btn_spacing;        button = new Fl_Button(control_x, group->y() + 1,                               control_btn_w, control_btn_h);        button->box(FL_THIN_UP_FRAME);        button->image(x_GetDockPositionImg(CDockWidget::eDock_Bottom));        button->clear_visible_focus();        button->callback(s_RedockBottom_cb, this);        button->tooltip("Re-dock this window on the bottom");        control_x += control_btn_w + control_btn_spacing;        button = new Fl_Button(control_x, group->y() + 1,                               control_btn_w, control_btn_h);        button->box(FL_THIN_UP_FRAME);        button->image(x_GetDockCloseImg());        button->clear_visible_focus();        button->tooltip("Remove this view from the dock");        control_x += control_btn_w + control_btn_spacing;        //group->add        group->end();        add(group);    }}    if (m_Child) {        m_Child->box(FL_THIN_DOWN_BOX);        m_Child->resize(x(), y() + border_h, w(), h() + - border_h);        add(m_Child);        resizable(m_Child);    }}void CDockFrame::Detach(void){    if (m_Child) {        remove(m_Child);        if (m_Owner) {            delete m_Child;        }    }    m_Child = NULL;    m_Owner = false;}int CDockFrame::handle(int event){    return Fl_Group::handle(event);}void CDockFrame::x_Redock(CDockWidget::EDockPosition pos){    if (m_Parent) {        bool old_owner = m_Owner;        m_Owner = false;        m_Parent->Undock(m_Child);        m_Parent->Dock(m_Child, pos, old_owner);    }}void CDockFrame::RedockLeft(){    x_Redock(CDockWidget::eDock_Left);}void CDockFrame::RedockRight(){    x_Redock(CDockWidget::eDock_Right);}void CDockFrame::RedockTop(){    x_Redock(CDockWidget::eDock_Top);}void CDockFrame::RedockBottom(){    x_Redock(CDockWidget::eDock_Bottom);}void CDockFrame::Remove(){}////////////////////////////////////////////////////////////////////////////////// Control button images///Fl_Pixmap* CDockFrame::sm_DockLeftImg = NULL;Fl_Pixmap* CDockFrame::sm_DockRightImg = NULL;Fl_Pixmap* CDockFrame::sm_DockTopImg = NULL;Fl_Pixmap* CDockFrame::sm_DockBottomImg = NULL;Fl_Pixmap* CDockFrame::sm_DockCloseImg = NULL;Fl_Pixmap* CDockFrame::x_GetDockPositionImg(CDockWidget::EDockPosition pos){    switch (pos) {    case CDockWidget::eDock_Right:        {{            static const char * sc_DockRight[] = {                "8 8 2 1",                " 	c None",                ".	c #444040",                "         ",                "   .     ",                "   ..    ",                "   ...   ",                "   ...   ",                "   ..    ",                "   .     ",                "         "            };            if ( !sm_DockRightImg) {                sm_DockRightImg = new Fl_Pixmap(sc_DockRight);            }            return sm_DockRightImg;        }}        break;    case CDockWidget::eDock_Left:        {{            static const char * sc_DockLeft[] = {                "8 8 2 1",                " 	c None",                ".	c #444040",                "        ",                "    .   ",                "   ..   ",                "  ...   ",                "  ...   ",                "   ..   ",                "    .   ",                "        "            };            if ( !sm_DockLeftImg) {                sm_DockLeftImg = new Fl_Pixmap(sc_DockLeft);            }            return sm_DockLeftImg;        }}        break;    case CDockWidget::eDock_Bottom:        {{            static const char * sc_DockBottom[] = {                "8 8 2 1",                " 	c None",                ".	c #444040",                "        ",                "        ",                " ...... ",                "  ....  ",                "   ..   ",                "        ",                "        ",                "        "            };            if ( !sm_DockBottomImg) {                sm_DockBottomImg = new Fl_Pixmap(sc_DockBottom);            }            return sm_DockBottomImg;        }}        break;    case CDockWidget::eDock_Top:        {{            static const char * sc_DockTop[] = {                "8 8 2 1",                " 	c None",                ".	c #444040",                "        ",                "        ",                "   ..   ",                "  ....  ",                " ...... ",                "        ",                "        ",                "        "            };            if ( !sm_DockTopImg) {                sm_DockTopImg = new Fl_Pixmap(sc_DockTop);            }            return sm_DockTopImg;        }}        break;    default:        LOG_POST(Error << "Error: unhandled dock image type");        break;    }    return NULL;}Fl_Pixmap* CDockFrame::x_GetDockCloseImg(void){    static const char * sc_DockClose[] = {        "8 8 3 1",        " 	c None",        "*	c #444040",        ".	c #c0c0c0",        "        ",        " *.  .* ",        "  *..*  ",        "   **   ",        "   **   ",        "  *..*  ",        " *.  .* ",        "        "    };    if ( !sm_DockCloseImg) {        sm_DockCloseImg = new Fl_Pixmap(sc_DockClose);    }    return sm_DockCloseImg;}END_NCBI_SCOPE/* * =========================================================================== * $Log: dock_frame.cpp,v $ * Revision 1000.1  2004/06/01 21:08:22  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2 * * Revision 1.2  2004/05/21 22:27:53  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.1  2004/01/08 16:45:31  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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