NCBI C++ ToolKit
checkedlistctrl.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: checkedlistctrl.cpp 46536 2021-06-28 12:37:36Z shkeda $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
37 #include <wx/imaglist.h>
38 
39 #if( wxMAJOR_VERSION == 3 && wxMINOR_VERSION == 0 )
40 wxDEFINE_EVENT(wxEVT_LIST_ITEM_CHECKED, wxListEvent);
41 #endif
42 
44 
46 
47 BEGIN_EVENT_TABLE(wxCheckedListCtrl, wxListCtrl)
48  EVT_LEFT_DOWN(wxCheckedListCtrl::OnMouseEvent)
50 
52 {
53 }
54 
55 wxCheckedListCtrl::wxCheckedListCtrl(wxWindow *parent, wxWindowID winid, const wxPoint& pos, const wxSize& size,
56  long style, const wxValidator& validator, const wxString &name)
57 : m_ImageList()
58 {
59  Create(parent, winid, pos, size, style, validator, name);
60 }
61 
63 {
64  delete m_ImageList;
65 }
66 
67 bool wxCheckedListCtrl::Create(wxWindow *parent, wxWindowID winid, const wxPoint& pos, const wxSize& size,
68  long style, const wxValidator& validator, const wxString &name)
69 {
70  if (!wxListCtrl::Create(parent, winid, pos, size, style, validator, name))
71  return FALSE;
72 
74  SetImageList(m_ImageList, wxIMAGE_LIST_SMALL);
75 
76  return TRUE;
77 }
78 
79 void wxCheckedListCtrl::OnMouseEvent(wxMouseEvent& event)
80 {
81  if (event.LeftDown())
82  {
83  int flags;
84  long item = HitTest(event.GetPosition(), flags);
85  if (item > -1 && (flags & wxLIST_HITTEST_ONITEMICON))
86  {
87  SetChecked(item, !IsChecked(item));
88  wxListEvent le(wxEVT_LIST_ITEM_CHECKED, GetId());
89  le.m_itemIndex = item;
90  le.SetEventObject(this);
91  GetEventHandler()->ProcessEvent(le);
92  }
93  else
94  event.Skip();
95  }
96  else
97  {
98  event.Skip();
99  }
100 }
101 
102 bool wxCheckedListCtrl::IsChecked(long item) const
103 {
104  wxListItem info;
105  info.m_mask = wxLIST_MASK_IMAGE;
106  info.m_itemId = item;
107 
108  if (GetItem(info))
109  {
110  return (info.m_image == 1 || info.m_image == 3);
111  }
112  else
113  return FALSE;
114 }
115 
116 void wxCheckedListCtrl::SetChecked(long item, bool checked)
117 {
118  wxListItem info;
119  info.m_mask = wxLIST_MASK_IMAGE;
120  info.m_itemId = item;
121  if (GetItem(info) && info.m_image == 3) // is disabled?
122  return;
123 
124  SetItemImage(item, (checked ? 1 : 0), -1);
125 }
126 
128 
void OnMouseEvent(wxMouseEvent &event)
bool Create(wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxLC_REPORT, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxListCtrlNameStr)
bool IsChecked(long item) const
void SetChecked(long item, bool checked)
wxImageList * m_ImageList
static uch flags
wxDEFINE_EVENT(WIDTH_EVENT, wxCommandEvent)
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
bool le(T x_, T y_, T round_)
Definition: njn_approx.hpp:84
@ FALSE
Definition: testodbc.c:27
@ TRUE
Definition: testodbc.c:27
wxImageList * CreateCheckboxImages(wxWindow *wnd)
Definition: wx_utils.cpp:1352
Modified on Sat Dec 09 04:47:01 2023 by modify_doxy.py rev. 669887