combobox.cpp
来自「ncbi源码」· C++ 代码 · 共 622 行 · 第 1/2 页
CPP
622 行
/* * =========================================================================== * PRODUCTION $Log: combobox.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 21:08:58 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * PRODUCTION * =========================================================================== *//* $Id: combobox.cpp,v 1000.3 2004/06/01 21:08:58 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. * * =========================================================================== * * Author: Philip Johnson * * File Description: combobox.cpp -- dropdown combobox widget for FLTK * */#include <ncbi_pch.hpp>#include <corelib/ncbistl.hpp>#include <gui/widgets/fl/combobox.hpp>#include <FL/Fl_Box.H>#include <FL/Fl_Button.H>#include <FL/Fl_Input.H>BEGIN_NCBI_SCOPE//-----------------------------------------------------------------------------// PRE : undo information stored in member variables// POST: the previous value, position & mark have been restoredvoid CComboBox::CInput::Undo(void){ value(m_Value.c_str()); position(m_Position, m_Mark);}//-----------------------------------------------------------------------------// PRE : input event// POST: if ctrl pressed, parent window is checked for shortcuts; current// input information (value, mark, position) is stored for undo purposesint CComboBox::CInput::handle(int e){ if (e == FL_KEYBOARD) { if ((Fl::event_state() & FL_CTRL) && window()->handle(FL_SHORTCUT)) { //check for shortcuts return 1; } m_Value = value(); m_Mark = mark(); m_Position = position(); } return Fl_Input::handle(e);}//-----------------------------------------------------------------------------// PRE : browser event// POST: standard browser event handler; if value() is 0 & down arrow// pressed, value changed to 1 (bug in std handler changes the value to 2)int CComboBox::CBrowser::handle(int e){ if (e == FL_KEYBOARD && Fl::event_key() == FL_Down && value() == 0) { value(1); do_callback(); return 1; } return Fl_Hold_Browser::handle(e);}//-----------------------------------------------------------------------------// PRE : a widget// POST: whether the current event *ROOT* is found within the box specified// by the widgetbool EventRootInside(Fl_Widget *w) { if (!w) { return false; } return !(Fl::event_x_root() < w->x() || Fl::event_x_root() >= w->x() + w->w() || Fl::event_y_root() < w->y() || Fl::event_y_root() >= w->y() + w->h());}//-----------------------------------------------------------------------------// PRE : standard fltk boundaries// POST: popupwin createdCComboBox::CPopupWin::CPopupWin(int x, int y, int w, int h) : Fl_Menu_Window(x,y,w,h), m_MouseOver(NULL){ clear_border(); size_range(1,1);}//-----------------------------------------------------------------------------// PRE : a grabbed event // POST: event passed to leaf widgets as appropriateint CComboBox::CPopupWin::handle(int event){ switch (event) { case FL_SHOW: m_MouseOver = NULL; break; case FL_MOVE: { // We moved outside the top-level window; close it! Fl_Window *top = Fl::first_window(); if (top == this) { top = Fl::next_window(top); } if (!EventRootInside(top) && !EventRootInside(this)) { do_callback(); return 1; } } { // Identify & process leave events int childI; for (childI = children() - 1; childI >= 0 && !Fl::event_inside(child(childI)); --childI); if (childI < 0) { if (m_MouseOver) { m_MouseOver->handle(FL_LEAVE); m_MouseOver = NULL; } } else if (child(childI) != m_MouseOver) { if (m_MouseOver) { m_MouseOver->handle(FL_LEAVE); } m_MouseOver = child(childI); } } break; case FL_PUSH: if (Fl::event_x() < 0 || Fl::event_x() >= w() || Fl::event_y() < 0 || Fl::event_y() >= h()) { do_callback(); return 1; } break; case FL_KEYBOARD: case FL_SHORTCUT: switch(Fl::event_key()) { case FL_Tab: case FL_Enter: case FL_Escape: case FL_Control_L: case FL_Alt_L: case FL_Alt_R: do_callback(); return 0; default: break; } for (int childI = children()-1; childI >= 0; --childI) { if (child(childI)->handle(event) != 0) { return 1; } } break; default: break; } return Fl_Menu_Window::handle(event);}//-----------------------------------------------------------------------------// PRE :// POST:CComboBox::CComboBox(int x, int y, int w, int h, const char* label) : Fl_Group(x,y,w,h+1, label), m_InKeypressed(false), m_EntryMap(new CMap){ when(FL_WHEN_CHANGED); int dx = Fl::box_dx(FL_DOWN_FRAME); int dy = Fl::box_dy(FL_DOWN_FRAME); int buttonD = h-2*dy; { m_Box = new Fl_Box(FL_DOWN_FRAME, x,y,w,h, NULL); m_Input = new CInput(x+dx, y+dy, w-2*dx-buttonD-1, buttonD); m_Input->box(FL_FLAT_BOX); m_Input->when(FL_WHEN_CHANGED); m_Input->callback((Fl_Callback*) s_InputCB, this); m_Button = new Fl_Button(x+(w-dx-buttonD), y+dy, buttonD,buttonD); m_Button->clear_visible_focus(); m_Button->label("@-12>"); m_Button->callback((Fl_Callback*) s_ButtonCB, this); } // Hidden window, mimics group Fl_Group::current(0); m_PopupWin = new CPopupWin(x, y, w, h*4); { m_Browser = new CBrowser(0, h, w, h*3); m_Browser->box(FL_BORDER_BOX); m_Browser->callback((Fl_Callback*) s_BrowserCB, this); } begin(); m_PopupWin->resizable(m_PopupWin); m_PopupWin->callback((Fl_Callback*) s_CloseCB, this); m_PopupWin->end(); m_PopupWin->hide(); m_ResizeBox = new Fl_Box(m_Input->x(), m_Input->y(), m_Input->w(), 1); m_ResizeBox->hide(); resizable(m_ResizeBox); end();}//-----------------------------------------------------------------------------// PRE : event for whole combobox// POST: open browser on down arrow; close browser on escapeint CComboBox::handle(int event){ switch (event) { case FL_KEYBOARD: switch (Fl::event_key()) { case FL_Down: case FL_Up: { int curr = value_index(); if (curr == -1 || !((m_Input->mark() == 0 && m_Input->position() == m_Input->size()) || (m_Input->position() == 0 && m_Input->mark() == m_Input->size()))) { x_OpenBrowser(); } else { int next = (Fl::event_key() == FL_Down) ? curr+1 : curr-1; if (next >= 0 && next < (int) m_Entries.size()) { value(m_Entries[next].c_str()); } } return 1; } case FL_Enter: x_MaybeCallback(); default: break; } break; case FL_UNFOCUS: x_MaybeCallback(); break; default: break; } return Fl_Group::handle(event);};//-----------------------------------------------------------------------------// PRE : new value for combobox// POST: input box set to that value; browser scrolled to it as, if possiblevoid CComboBox::value(const char* s){ m_Input->value(s); int idx = value_index(); if (idx != -1) { m_Browser->value(idx+1); }}//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?