child_frame.cpp
来自「ncbi源码」· C++ 代码 · 共 433 行
CPP
433 行
/* * =========================================================================== * PRODUCTION $Log: child_frame.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:14:10 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//* $Id: child_frame.cpp,v 1000.1 2004/06/01 21:14:10 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: * CChildFrame -- internal widget class that represents the frame * surrounding a given MDI child */#include <ncbi_pch.hpp>#include "child_frame.hpp"#include <FL/fl_draw.H>BEGIN_NCBI_SCOPE//// look-and-feel statics//Fl_Boxtype CChildFrame::sm_SysButtonBox = FL_UP_BOX;Fl_Color CChildFrame::sm_SysButtonColor = fl_rgb_color(224, 224, 224);Fl_Color CChildFrame::sm_SelectedColor = fl_rgb_color( 0, 0, 128);Fl_Font CChildFrame::sm_TitleFont = FL_HELVETICA_BOLD;int CChildFrame::sm_TitleAlign = FL_ALIGN_CENTER | FL_ALIGN_INSIDE;int CChildFrame::sm_TitleSize = 12;Fl_Color CChildFrame::sm_TitleColor = fl_rgb_color(224, 224, 0);int CChildFrame::sm_TitleBarHeight = 15;//// static accessors////// system button box type - this is the outline box type for the system button// tray// Fl_Boxtype CChildFrame::GetSysButtonBox(void){ return sm_SysButtonBox;}void CChildFrame::SetSysButtonBox(Fl_Boxtype box){ sm_SysButtonBox = box;}//// system button color - this defines the background color for the system// buttons//Fl_Color CChildFrame::GetSysButtonColor(void){ return sm_SysButtonColor;}void CChildFrame::SetSysButtonColor(Fl_Color color){ sm_SysButtonColor = color;}//// selected color - this is the background color for the title when selected//Fl_Color CChildFrame::GetSelectedColor(void){ return sm_SelectedColor;}void CChildFrame::SetSelectedColor(Fl_Color color){ sm_SelectedColor = color;}//// title bar height - this is used internally to set the height of a title bar//int CChildFrame::GetTitleBarHeight(void){ return sm_TitleBarHeight;}void CChildFrame::SetTitleBarHeight(int h){ sm_TitleBarHeight = h;}//// title color - this is the color of the text in the title bar//Fl_Color CChildFrame::GetTitleColor(void){ return sm_TitleColor;}void CChildFrame::SetTitleColor(Fl_Color color){ sm_TitleColor = color;}//// title font - default is bold, helvetica font//Fl_Font CChildFrame::GetTitleFont(void){ return sm_TitleFont;}void CChildFrame::SetTitleFont(Fl_Font font){ sm_TitleFont = font;}//// title alignment - bitmask of Fl_Align styles//int CChildFrame::GetTitleAlign(void){ return sm_TitleAlign;}void CChildFrame::SetTitleAlign(int align){ sm_TitleAlign = align;}//// title size - font height in pixels (not points!)//int CChildFrame::GetTitleSize(void){ return sm_TitleSize;}void CChildFrame::SetTitleSize(int size){ sm_TitleSize = size;}//// // CChildFrame////CChildFrame::CChildFrame(int x, int y, int w, int h, const char* label) : Fl_Window(x, y, w, h, label), m_TitleBar(NULL), m_Title(NULL), m_SysButtons(NULL), m_Child(NULL){ m_SavedPos[0] = m_SavedPos[1] = m_SavedPos[2] = m_SavedPos[3] = 0;}CChildFrame::~CChildFrame(){ // detach our child, if it exists if (m_Child) { remove(m_Child); }}void CChildFrame::Attach(CChild* child){ Detach(); m_Child = child; if (m_Child) { add(m_Child); resizable(m_Child); m_Child->position(Fl::box_dx(box()), Fl::box_dy(box()) + GetTitleBarHeight()); m_Child->x_SetFrame(this); }}void CChildFrame::Detach(void){ if (m_Child) { remove(m_Child); m_Child->x_SetFrame(NULL); }}int CChildFrame::handle(int event){ int last_x = m_LastMousePos.first; int last_y = m_LastMousePos.second; m_LastMousePos.first = Fl::event_x(); m_LastMousePos.second = Fl::event_y(); switch (event) { case FL_PUSH: m_DragState = eIdle; if (Fl::event_shift() || Fl::event_ctrl() || Fl::event_alt() || Fl::event_button() != 1 || GetMaximized() || Fl::event_inside(m_SysButtons) || Fl::event_inside(m_Child)) { break; } if (Fl::event_inside(m_TitleBar)) { m_DragState = eMoving; } else { m_DragState = eResizing; // we also need to determine which edges we're dragging m_BorderDrag = 0; if (Fl::event_x() < 10) { m_BorderDrag |= fLeftBorderDrag; } else if ( w() - Fl::event_x() < 10) { m_BorderDrag |= fRightBorderDrag; } if (Fl::event_y() < 10) { m_BorderDrag |= fTopBorderDrag; } else if (h() - Fl::event_y() < 10) { m_BorderDrag |= fBottomBorderDrag; } } m_DragSize[0] = x(); m_DragSize[1] = y(); m_DragSize[2] = w(); m_DragSize[3] = h(); return 1; case FL_DRAG: if (Fl::event_shift() || Fl::event_ctrl() || Fl::event_alt() || Fl::event_button() != 1) { m_DragState = eIdle; break; } switch (m_DragState) { case eNormal: break; case eMoving: // title bar drag = move window {{ int new_x = m_DragSize[0] + Fl::event_x() - last_x; int new_y = m_DragSize[1] + Fl::event_y() - last_y; new_x = max(0, new_x); new_y = max(0, new_y); new_x = min(parent()->w() - 100, new_x); new_y = min(parent()->h() - sm_TitleBarHeight, new_y); m_DragSize[0] = new_x; m_DragSize[1] = new_y; window()->cursor(FL_CURSOR_MOVE); window()->make_current(); fl_line_style(0, 2); fl_overlay_rect(m_DragSize[0], m_DragSize[1], m_DragSize[2], m_DragSize[3]); fl_line_style(0, 1); }} return 1; case eResizing: {{ int dx = 0; int dy = 0; int dw = 0; int dh = 0; int mouse_x = Fl::event_x(); int mouse_y = Fl::event_y(); if (m_BorderDrag & fLeftBorderDrag) { dx = mouse_x - last_x; dw -= dx; } else if (m_BorderDrag & fRightBorderDrag) { dw = mouse_x - last_x; } if (m_BorderDrag & fTopBorderDrag) { dy = mouse_y - last_y; dh -= dy; } else if (m_BorderDrag & fBottomBorderDrag) { dh = mouse_y - last_y; } m_DragSize[0] += dx; m_DragSize[1] += dy; m_DragSize[2] += dw; m_DragSize[3] += dh; m_DragSize[2] = max(100, m_DragSize[2]); m_DragSize[3] = max(100, m_DragSize[3]); window()->make_current(); fl_line_style(0, 2); fl_overlay_rect(m_DragSize[0], m_DragSize[1], m_DragSize[2], m_DragSize[3]); fl_line_style(0, 1); }} return 1; default: break; } break; case FL_RELEASE: switch (m_DragState) { case eMoving: case eResizing: {{ int min_x = min(x(), m_DragSize[0]); int min_y = min(y(), m_DragSize[1]); int max_x = max(x() + w(), m_DragSize[0] + m_DragSize[2]); int max_y = max(y() + w(), m_DragSize[1] + m_DragSize[3]); resize(m_DragSize[0], m_DragSize[1], m_DragSize[2], m_DragSize[3]); /** parent()->damage(FL_DAMAGE_ALL, min_x, min_y, max_x - min_x, max_y - min_y); **/ }} window()->cursor(FL_CURSOR_DEFAULT); window()->make_current(); fl_line_style(0, 2); fl_overlay_clear(); fl_line_style(0, 1); m_DragState = eIdle; return 1; default: break; } default: break; } return Fl_Window::handle(event);}void CChildFrame::label(const char* text){ m_Title->label(text);}const char* CChildFrame::label(void) const{ return m_TitleBar->label();}END_NCBI_SCOPE/* * =========================================================================== * $Log: child_frame.cpp,v $ * Revision 1000.1 2004/06/01 21:14:10 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6 2004/05/21 22:27:56 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.5 2003/07/25 13:38:44 dicuccio * Minor clean-up in issuing redraw events * * 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 + -
显示快捷键?