📄 sel_list_controller.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: sel_list_controller.hpp,v $ * PRODUCTION Revision 1000.3 2004/04/12 18:16:13 gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.9 * PRODUCTION * =========================================================================== */#ifndef GUI_WIDGETS_ALNMULTI___SEL_LIST_CONTROLLER__HPP#define GUI_WIDGETS_ALNMULTI___SEL_LIST_CONTROLLER__HPP/* $Id: sel_list_controller.hpp,v 1000.3 2004/04/12 18:16:13 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: Andrey Yazhuk * * File Description: * */#include <corelib/ncbistl.hpp>#include <gui/widgets/aln_multiple/list_mvc.hpp>#include <gui/widgets/gl/ievent_handler.hpp>#include <FL/Enumerations.H>BEGIN_NCBI_SCOPE/////////////////////////////////////////////////////////////////////////////////// class CSelListControllertemplate <class Item> class CSelListController : public IEventHandler{public: typedef Item TItem; typedef ISelListModel<Item> TSelListModel; CSelListController(); virtual ~CSelListController(); /// IEventHandler implementation. virtual int handle(CGUIEvent& event, CGlPane& Pane);protected: // specialized event handlers virtual int x_OnMousePush(CGUIEvent& event); virtual int x_OnMouseDrag(CGUIEvent& event); virtual int x_OnMouseRelease(CGUIEvent& event); virtual int x_OnMouseMove(); virtual int x_OnMouseWheel(); virtual int x_OnKeyDown(CGUIEvent& event); // functions to be overriden in the inherited class virtual TSelListModel* SLC_GetModel() = 0; virtual int SLC_GetLineByWindowY(int WinY, bool b_clip = false) = 0; virtual int SLC_GetHeight() = 0; // view size in pixels virtual void SLC_VertScrollToMakeVisible(int index) = 0; void x_MoveSelectionBy(int Shift, bool bShift, bool bCtrl); void x_MoveSelLineByPage(bool bDown, bool bShift, bool bCtrl); void x_SelectTo(int index, bool bShift, bool bCtrl); void x_SelectFocusedItem(bool bDeselectEn); protected: bool m_bProcessMouseUp;};template<class Item> CSelListController<Item>::CSelListController(): m_bProcessMouseUp(false){}template<class Item> CSelListController<Item>::~CSelListController(){}template<class Item> int CSelListController<Item>::handle(CGUIEvent& event, CGlPane& pane){ switch(event.GetFLTKEvent()) { case FL_PUSH: return x_OnMousePush(event); case FL_DRAG: return x_OnMouseDrag(event); case FL_RELEASE: return x_OnMouseRelease(event); case FL_MOVE: return x_OnMouseMove(); case FL_MOUSEWHEEL: return x_OnMouseWheel(); case FL_KEYDOWN: return x_OnKeyDown(event); default: return 0; }}template<class Item> int CSelListController<Item>::x_OnMousePush(CGUIEvent& event){ m_bProcessMouseUp = false; TSelListModel* pModel = SLC_GetModel(); if(pModel) { int index = SLC_GetLineByWindowY(Fl::event_y(), true); CGUIEvent::EGUIState state = event.GetGUIState(); int Btn = Fl::event_button(); //### if(index == -1) { m_bProcessMouseUp = true; } else { if(event.GetGUISignal() == CGUIEvent::eSelectSignal) { if(Btn == FL_LEFT_MOUSE) { // left mouse button pressed //if(State == 0) { if(state == CGUIEvent::eSelectState) { m_bProcessMouseUp = pModel->SLM_IsItemSelected(index); if(m_bProcessMouseUp) pModel->SLM_FocusItem(index); // change focus, selection will be changed on MouseUp else pModel->SLM_SelectSingleItem(index); //} else if(State & FL_SHIFT) { } else if(state == CGUIEvent::eSelectExtState) { pModel->SLM_SelectTo(index); //} else if(State == FL_CTRL) { } else if(state == CGUIEvent::eSelectIncState) { m_bProcessMouseUp = true; } } else if(Btn == FL_RIGHT_MOUSE) { // right mouse buttton pressed //if(State == 0) { if(state == CGUIEvent::eSelectState) { pModel->SLM_SelectSingleItem(index); //} else if(State & FL_SHIFT) { } else if(state == CGUIEvent::eSelectExtState) { m_bProcessMouseUp = true; } } } } } fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); return 1;}template<class Item> int CSelListController<Item>::x_OnMouseDrag(CGUIEvent& event){ m_bProcessMouseUp = false; fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); return 1;}template<class Item> int CSelListController<Item>::x_OnMouseRelease(CGUIEvent& event){ TSelListModel* pModel = SLC_GetModel(); if(pModel && m_bProcessMouseUp) { int index = SLC_GetLineByWindowY(Fl::event_y(), true); CGUIEvent::EGUIState state = event.GetGUIState(); int Btn = Fl::event_button(); if(index == -1) { pModel->SLM_SelectAll(false); } else { //if(Btn == FL_LEFT_MOUSE && State == FL_CTRL) { if(Btn == FL_LEFT_MOUSE && state == CGUIEvent::eSelectIncState) { pModel->SLM_InvertSingleItem(index); } else if((Btn == FL_LEFT_MOUSE && state == CGUIEvent::eSelectState) || (Btn == FL_RIGHT_MOUSE && state == CGUIEvent::eSelectExtState)) { pModel->SLM_SelectSingleItem(index); } } } m_bProcessMouseUp = false; fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); return 1;}template<class Item> int CSelListController<Item>::x_OnMouseMove(){ fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); return 1;}template<class Item> int CSelListController<Item>::x_OnMouseWheel(){ fl_cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); return 0;}template<class Item> int CSelListController<Item>::x_OnKeyDown(CGUIEvent& event){ TSelListModel* pModel = SLC_GetModel(); if(pModel) { int Key = Fl::event_key(); CGUIEvent::EGUIState state = event.GetGUIState(); //bool b_shift = (Fl::event_state() & FL_SHIFT) != 0; //bool b_ctrl = (Fl::event_state() & FL_CTRL) != 0; bool b_shift = state == CGUIEvent::eSelectExtState; bool b_ctrl = state == CGUIEvent::eSelectIncState; switch(Key) { case FL_Home: x_SelectTo(0, b_shift, b_ctrl); break; case FL_End: x_SelectTo(pModel->SLM_GetItemsCount()-1, b_shift, b_ctrl); break; case FL_Down: x_MoveSelectionBy(1, b_shift, b_ctrl); break; case FL_Up: x_MoveSelectionBy(-1, b_shift, b_ctrl); break; case FL_Page_Up: x_MoveSelLineByPage(false, b_shift, b_ctrl); break; case FL_Page_Down: x_MoveSelLineByPage(true, b_shift, b_ctrl); break; case ' ': x_SelectFocusedItem(b_ctrl); break; case 'a': case 'A': if(b_ctrl) pModel->SLM_SelectAll(true); break; } } return 0;}template<class Item> void CSelListController<Item>::x_MoveSelectionBy(int Shift, bool b_shift, bool b_ctrl){ TSelListModel* pModel = SLC_GetModel(); if(pModel) { int N = pModel->SLM_GetItemsCount(); if(N > 0) { int iFocused = pModel->SLM_GetFocusedItemIndex(); iFocused = max(iFocused, 0); iFocused += Shift; iFocused = max(iFocused, 0); iFocused = min(iFocused, N - 1); x_SelectTo(iFocused, b_shift, b_ctrl); } }}template<class Item> void CSelListController<Item>::x_SelectTo(int index, bool b_shift, bool b_ctrl){ TSelListModel* pModel = SLC_GetModel(); if(pModel) { if(b_shift) { pModel->SLM_SelectTo(index); } else { if(b_ctrl) { pModel->SLM_FocusItem(index); } else { pModel->SLM_SelectSingleItem(index); } } SLC_VertScrollToMakeVisible(index); }} template<class Item> void CSelListController<Item>::x_MoveSelLineByPage(bool bDown, bool b_shift, bool b_ctrl){ TSelListModel* pModel = SLC_GetModel(); if(pModel) { if(bDown) { // page Down int PosY = SLC_GetHeight(); int iBottom = SLC_GetLineByWindowY(PosY); int iFocused = pModel->SLM_GetFocusedItemIndex(); if(iFocused == iBottom) { // page down PosY += PosY; iBottom = SLC_GetLineByWindowY(PosY); } if(iBottom == -1) iBottom = pModel->SLM_GetItemsCount()-1; x_SelectTo(iBottom, b_shift, b_ctrl); } else { // page Up int iTop = SLC_GetLineByWindowY(0); int iFocused = pModel->SLM_GetFocusedItemIndex(); if(iFocused == iTop) { // page down int PosY = SLC_GetHeight(); iTop = SLC_GetLineByWindowY(PosY); } if(iTop == -1) iTop = min(0, pModel->SLM_GetItemsCount()-1); if(iTop > -1) x_SelectTo(iTop, b_shift, b_ctrl); } }}template<class Item> void CSelListController<Item>::x_SelectFocusedItem(bool bDeselectEn){ TSelListModel* pModel = SLC_GetModel(); if(pModel) { int iFocused = pModel->SLM_GetFocusedItemIndex(); if(iFocused != -1) { bool bSel = pModel->SLM_IsItemSelected(iFocused); if( ! bSel || (bSel && bDeselectEn)) pModel->SLM_InvertSingleItem(iFocused); } }}END_NCBI_SCOPE/* * =========================================================================== * $Log: sel_list_controller.hpp,v $ * Revision 1000.3 2004/04/12 18:16:13 gouriano * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.9 * * Revision 1.9 2004/03/17 20:08:00 yazhuk * Removed obsolete includes * * Revision 1.8 2004/01/15 20:10:05 yazhuk * Fixed "invisible items are selected" bug, clean-up * * Revision 1.7 2003/12/22 16:29:22 yazhuk * Bugfix for x_OnMouseWheel() * * Revision 1.6 2003/12/18 21:17:44 yazhuk * Converted CSelListController to template class * * Revision 1.5 2003/12/01 16:42:13 yazhuk * Refactored event handling - introduced CGUIEvent * * Revision 1.4 2003/11/17 21:17:23 yazhuk * Updated include for ievent_handler.hpp * * Revision 1.3 2003/10/20 15:45:31 yazhuk * Inherited from IEventHandler * * Revision 1.2 2003/09/23 20:45:14 yazhuk * Added #include <corelib/ncbistl.hpp> * * Revision 1.1 2003/09/10 20:56:44 yazhuk * Moved CSelListController to a separate file * * =========================================================================== */#endif // GUI_WIDGETS_ALNMULTI___SEL_LIST_CONTROLLER__HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -