⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combobox.hpp

📁 ncbi源码
💻 HPP
字号:
/* * =========================================================================== * PRODUCTION $Log: combobox.hpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:52:05  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15 * PRODUCTION * =========================================================================== */#ifndef GUI_WIDGETS_FL___COMBOBOX__HPP#define GUI_WIDGETS_FL___COMBOBOX__HPP/*  $Id: combobox.hpp,v 1000.2 2004/06/01 19:52:05 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.hpp -- dropdown combobox widget for FLTK** ---------------------------------------------------------------------------*/#include <corelib/ncbistd.hpp>#include <gui/gui.hpp>#include <FL/Fl.H>#include <FL/Fl_Hold_Browser.H>#include <FL/Fl_Menu_Window.H>#include <FL/Fl_Input.H>#include <string>#include <vector>#include <map>#include <memory>class Fl_Button;class Fl_Box;/** @addtogroup GUI_FltkWidgets * * @{ */BEGIN_NCBI_SCOPE/// CComboBox widget -- combination input box & drop-down list box/// /// callback conditions:////// FL_WHEN_CHANGED --> executes when ENTER/UNFOCUS/CLOSE DROPDOWN,///                     matches an entry in the list, and///                     value has changed./// FL_WHEN_NOT_CHANGED --> executes when ENTER/UNFOCUS/CLOSE DROPDOWN  and///                         matches an entry in the list/// FL_WHEN_RELEASE_ALWAYS --> executes when ENTER/UNFOCUS/CLOSE DROPDOWNclass NCBI_GUIWIDGETS_FL_EXPORT CComboBox : public Fl_Group{public:    enum ETypeFlags {        eRestrictToEntries = 0x1, //only allow input of the specified type        eCaseSensitive     = 0x2    };    CComboBox(int x, int y, int w, int h, const char* label = NULL);    int popup_height(void) const { return m_Browser->h(); }    void popup_height(int h) { m_Browser->size(m_Browser->w(), h); }    /// Add an entry to the browser, plus an optional abbreviation for that    /// entry    void Add(const char* entry, const char* abbrev = NULL);    /// Clear all entries from browser    void clear(void);    /// Set type using ETypeFlags above    void type(unsigned char t);    unsigned char type(void) const { return Fl_Widget::type(); }    void value(const char*);    const char* value(void) const;    int value_index(void) const;//< returns -1 if value not in list of optionspublic:    class CMap : public map<string, int> {    public:        const_iterator FindExact(const char*, bool caseSense = false) const;        const_iterator FindInitial(const char*, bool caseSense = false) const;        pair<iterator, bool> Add(const char*, int, bool caseSense = false);    };protected:    typedef vector<string>   TEntries;    /// Popupwin class makes up for deficiencies of Fl::grab() function    class CPopupWin : public Fl_Menu_Window {    public:        CPopupWin(int x, int y, int w, int h);        virtual int handle(int event);    private:        Fl_Widget *m_MouseOver;    };    /// Modified version of Fl_Input that:    /// 1) has an undo feature    /// 2) if ctrl key combination is pressed, checks parent window for    ///    shortcuts; iff none is found, then Fl_Input is passed the key    class CInput : public Fl_Input {    public:        CInput(int x, int y, int w, int h) :            Fl_Input(x,y,w,h), m_Mark(0), m_Position(0) {}        virtual int handle(int e);        void Undo(void);    private:        string m_Value;        int m_Mark, m_Position;    };    /// Modified version of Fl_Hold_Browser that will (initially) select    /// the first entry upon receiving a down arrow instead of jumping to the    /// second    class CBrowser : public Fl_Hold_Browser {    public:        CBrowser(int x, int y, int w, int h) : Fl_Hold_Browser(x,y,w,h) {}        virtual int handle(int e);    };protected:    virtual int handle(int event);    void x_OpenBrowser(void);    void x_CloseBrowser(void);private:    static void s_ButtonCB(Fl_Widget *, CComboBox* c) {        c->x_ButtonClicked();    }    static void s_CloseCB(Fl_Widget *, CComboBox* c) {        c->x_CloseBrowser();    }    static void s_InputCB(Fl_Widget *, CComboBox* c) {        c->x_Keypressed();    }    static void s_BrowserCB(Fl_Widget *, CComboBox* c) {        c->x_ItemSelected();    }    void x_MaybeCallback(void);    void x_ButtonClicked(void);    void x_Keypressed(void);    void x_ItemSelected(void);    CPopupWin  *m_PopupWin;    Fl_Box     *m_ResizeBox;    Fl_Box     *m_Box;    CInput     *m_Input;    Fl_Button  *m_Button;    CBrowser   *m_Browser;    string      m_PrevValue;    bool        m_InKeypressed; //recursive call guard    TEntries       m_Entries;    auto_ptr<CMap> m_EntryMap;};//////////// inline methods ////////////////-----------------------------------------------------------------------------//PRE : c string; whether or not we should pay attention to case//POST: iterator pointing to the entry that equals 'k' (if any)inline CComboBox::CMap::const_iteratorCComboBox::CMap::FindExact(const char* k, bool caseSensitive) const{    if (caseSensitive) {        return find(k);    } else {        string up(k);        return find(NStr::ToUpper(up));    }}//-----------------------------------------------------------------------------//PRE : c string; whether or not we should pay attention to case//POST: iterator pointing to the entry that begins with 'k' (if any)inline CComboBox::CMap::const_iteratorCComboBox::CMap::FindInitial(const char* k, bool caseSensitive) const{    string up;    if (!caseSensitive) {        up = k;        NStr::ToUpper(up);        k = up.c_str();    };    const_iterator i = lower_bound(k);    if (i == end()  ||  i->first.find(k) == string::npos) {        return end();    } else {        return i;    }}//-----------------------------------------------------------------------------//PRE : c string; whether or not we should pay attention to case//POST: <'k',x> added, with k capitalized if we're ignoring caseinline pair<CComboBox::CMap::iterator, bool>CComboBox::CMap::Add(const char* k, int x, bool caseSense){    if (!caseSense) {        string up(k);        return insert(value_type(NStr::ToUpper(up), x));    } else {        return insert(value_type(k, x));    }}END_NCBI_SCOPE/* @} *//** ===========================================================================* $Log: combobox.hpp,v $* Revision 1000.2  2004/06/01 19:52:05  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15** Revision 1.15  2004/05/11 18:55:14  dicuccio* Added doxygen modules info** Revision 1.14  2004/05/03 12:47:08  dicuccio* Added #include for gui/gui.hpp.  gui/utils ->gui/objutils where needed.** Revision 1.13  2004/02/09 16:49:57  johnson* added popup_height get/set methods** Revision 1.12  2004/01/21 23:55:39  johnson* fix to get popup working correctly after resize** Revision 1.11  2004/01/13 21:15:29  johnson* made popup a top-level window so it will appear even if combobox is at the* bottom of the parent window** Revision 1.10  2003/12/12 17:59:45  ivanov* Made CComboBox::CMap public to avoid compilation error on MSVC 7** Revision 1.9  2003/10/14 22:50:30  johnson* added method to clear browser** Revision 1.8  2003/09/24 18:21:09  dicuccio* Rearranged #include statements to avoid a compiler warning on MSVC** Revision 1.7  2003/09/16 14:37:14  dicuccio* Cleaned up and clarified export specifiers - added a new specifier for each* library** Revision 1.6  2003/08/30 16:40:37  dicuccio* Minor fixes: #include guard to top, fixed return value of accessor in internal* class to meet MSVC's requirements** Revision 1.5  2003/08/30 15:06:18  ucko* +<memory> for auto_ptr<>** Revision 1.4  2003/08/29 18:29:38  johnson* Numerous tweaks & adjustments: replaced Fl_Input with class that does *not** automatically swallows ctrl key shortcuts; case in/sensitive matching;* multiple abbreviations for a given entry; smoothed internal access to map** Revision 1.3  2003/08/26 13:19:05  johnson* added value set function** Revision 1.2  2003/08/21 12:24:00  dicuccio* Changed #include guard.  Minor formatting changes.  Added to ncbi namespace.** Revision 1.1  2003/08/19 18:16:41  johnson* initial revision** ===========================================================================*/#endif // GUI_WIDGETS_FL___COMBOBOX__HPP

⌨️ 快捷键说明

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