NCBI C++ ToolKit
wx_tools.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: wx_tools.hpp 37964 2008-05-21 15:57:16Z thiessen $
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: Paul Thiessen
27 *
28 * File Description:
29 * custom wx GUI controls
30 *
31 * ===========================================================================
32 */
33 
34 #ifndef WX_TOOLS__HPP
35 #define WX_TOOLS__HPP
36 
37 #include <corelib/ncbistd.hpp>
38 
39 #ifdef __WXMSW__
40 #include <windows.h>
41 #include <wx/msw/winundef.h>
42 #endif
43 #include <wx/wx.h>
44 #include <wx/spinbutt.h>
45 #include <wx/spinctrl.h>
46 
47 
49 
50 // "spin control" height
51 #if defined(__WXMSW__)
52 static const int SPIN_CTRL_HEIGHT = 20;
53 #elif defined(__WXGTK__)
54 static const int SPIN_CTRL_HEIGHT = 20;
55 #elif defined(__WXMAC__)
56 static const int SPIN_CTRL_HEIGHT = 24;
57 #endif
58 
59 extern const int WX_TOOLS_NOTIFY_CHANGED;
60 
61 
62 /////////////////////////////////////////////////////////////////////////////////////
63 // the class from which my custom integer/float spin ctrls are derived
64 /////////////////////////////////////////////////////////////////////////////////////
65 
67 
69 {
70  friend class NotifyingSpinButton;
71 
72 private:
73  virtual void OnSpinButtonUp(wxSpinEvent& event) = 0;
74  virtual void OnSpinButtonDown(wxSpinEvent& event) = 0;
75 
76 public:
77  virtual ~CustomSpinCtrl(void) { }
78 };
79 
80 
81 /////////////////////////////////////////////////////////////////////////////////////
82 // a spin button that notifies a parent when button pressed
83 /////////////////////////////////////////////////////////////////////////////////////
84 
85 class NotifyingSpinButton : public wxSpinButton
86 {
87 private:
89  void OnSpinButtonUp(wxSpinEvent& event);
90  void OnSpinButtonDown(wxSpinEvent& event);
91 
92  DECLARE_EVENT_TABLE()
93 
94 public:
96  wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
97  const wxSize& size = wxDefaultSize, long style = wxSP_HORIZONTAL) :
98  wxSpinButton(parent, id, pos, size, style), notify(toNotify) { }
99 };
100 
101 
102 /////////////////////////////////////////////////////////////////////////////////////
103 // a wxTextCtrl that only accepts valid floating point values (turns red otherwise)
104 /////////////////////////////////////////////////////////////////////////////////////
105 
106 class IntegerTextCtrl : public wxTextCtrl
107 {
108 public:
109  IntegerTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString,
110  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
111  const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
112 
113  void SetAllowedRange(int min, int max, int incr);
114  bool IsValidInteger(void) const;
115 
116 private:
118 
119  void DoValidate(wxCommandEvent& event);
120  void OnChange(wxCommandEvent& event);
121 
122  DECLARE_EVENT_TABLE()
123 };
124 
125 
126 /////////////////////////////////////////////////////////////////////////////////
127 // my own special integer spin control - for more control over text box
128 /////////////////////////////////////////////////////////////////////////////////
129 
131 {
132 public:
133  IntegerSpinCtrl(wxWindow* parent,
134  int min, int max, int increment, int initial,
135  const wxPoint& textCtrlPos, const wxSize& textCtrlSize, long textCtrlStyle,
136  const wxPoint& spinCtrlPos, const wxSize& spinCtrlSize);
137  virtual ~IntegerSpinCtrl(void) { }
138 
139  bool GetInteger(int *value) const;
140  bool GetUnsignedInteger(unsigned int *value) const;
141  bool SetInteger(int value);
142 
143 private:
147 
148  void OnSpinButtonUp(wxSpinEvent& event);
149  void OnSpinButtonDown(wxSpinEvent& event);
150 
151 public:
152  wxTextCtrl * GetTextCtrl(void) const { return iTextCtrl; }
153  wxSpinButton * GetSpinButton(void) const { return spinButton; }
154 };
155 
156 
157 /////////////////////////////////////////////////////////////////////////////////////
158 // a wxTextCtrl that only accepts valid floating point values (turns red otherwise)
159 /////////////////////////////////////////////////////////////////////////////////////
160 
161 class FloatingPointTextCtrl : public wxTextCtrl
162 {
163 public:
164  FloatingPointTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString,
165  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
166  const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
167 
168  void SetAllowedRange(double min, double max);
169  bool IsValidDouble(void) const;
170 
171 private:
172  double minVal, maxVal;
173 
174  void DoValidate(wxCommandEvent& event);
175  void OnChange(wxCommandEvent& event);
176 
177  DECLARE_EVENT_TABLE()
178 };
179 
180 
181 /////////////////////////////////////////////////////////////////////////////////
182 // like wxSpinCtrl, except works on floating point values
183 /////////////////////////////////////////////////////////////////////////////////
184 
186 {
187 public:
188  FloatingPointSpinCtrl(wxWindow* parent,
189  double min, double max, double increment, double initial,
190  const wxPoint& textCtrlPos, const wxSize& textCtrlSize, long textCtrlStyle,
191  const wxPoint& spinCtrlPos, const wxSize& spinCtrlSize);
192  virtual ~FloatingPointSpinCtrl(void) { }
193 
194  bool GetDouble(double *value) const;
195  bool SetDouble(double value);
196 
197 private:
201 
202  void OnSpinButtonUp(wxSpinEvent& event);
203  void OnSpinButtonDown(wxSpinEvent& event);
204 
205 public:
206  wxTextCtrl * GetTextCtrl(void) const { return fpTextCtrl; }
207  wxSpinButton * GetSpinButton(void) const { return spinButton; }
208 };
209 
210 
211 /////////////////////////////////////////////////////////////////////////////////
212 // dialog that asks user for a floating point value
213 /////////////////////////////////////////////////////////////////////////////////
214 
215 class GetFloatingPointDialog : public wxDialog
216 {
217 public:
218  GetFloatingPointDialog(wxWindow* parent, const wxString& message, const wxString& title,
219  double min, double max, double increment, double initial);
221 
222  double GetValue(void);
223 
224 private:
225  wxButton *buttonOK;
227 
228  void OnCloseWindow(wxCloseEvent& event);
229  void OnButton(wxCommandEvent& event);
230 
231  DECLARE_EVENT_TABLE()
232 };
233 
235 
236 #endif // WX_TOOLS__HPP
virtual void OnSpinButtonDown(wxSpinEvent &event)=0
virtual void OnSpinButtonUp(wxSpinEvent &event)=0
virtual ~CustomSpinCtrl(void)
Definition: wx_tools.hpp:77
bool GetDouble(double *value) const
Definition: wx_tools.cpp:289
wxSpinButton * GetSpinButton(void) const
Definition: wx_tools.hpp:207
virtual ~FloatingPointSpinCtrl(void)
Definition: wx_tools.hpp:192
void OnSpinButtonDown(wxSpinEvent &event)
Definition: wx_tools.cpp:280
NotifyingSpinButton * spinButton
Definition: wx_tools.hpp:199
FloatingPointSpinCtrl(wxWindow *parent, double min, double max, double increment, double initial, const wxPoint &textCtrlPos, const wxSize &textCtrlSize, long textCtrlStyle, const wxPoint &spinCtrlPos, const wxSize &spinCtrlSize)
Definition: wx_tools.cpp:240
void OnSpinButtonUp(wxSpinEvent &event)
Definition: wx_tools.cpp:271
FloatingPointTextCtrl * fpTextCtrl
Definition: wx_tools.hpp:198
bool SetDouble(double value)
Definition: wx_tools.cpp:259
wxTextCtrl * GetTextCtrl(void) const
Definition: wx_tools.hpp:206
void SetAllowedRange(double min, double max)
Definition: wx_tools.cpp:223
bool IsValidDouble(void) const
Definition: wx_tools.cpp:229
FloatingPointTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxTextCtrlNameStr)
Definition: wx_tools.cpp:201
void OnChange(wxCommandEvent &event)
Definition: wx_tools.cpp:218
void DoValidate(wxCommandEvent &event)
Definition: wx_tools.cpp:209
FloatingPointSpinCtrl * fpSpinCtrl
Definition: wx_tools.hpp:226
void OnButton(wxCommandEvent &event)
Definition: wx_tools.cpp:347
GetFloatingPointDialog(wxWindow *parent, const wxString &message, const wxString &title, double min, double max, double increment, double initial)
Definition: wx_tools.cpp:304
double GetValue(void)
Definition: wx_tools.cpp:340
void OnCloseWindow(wxCloseEvent &event)
Definition: wx_tools.cpp:360
IntegerTextCtrl * iTextCtrl
Definition: wx_tools.hpp:144
NotifyingSpinButton * spinButton
Definition: wx_tools.hpp:145
IntegerSpinCtrl(wxWindow *parent, int min, int max, int increment, int initial, const wxPoint &textCtrlPos, const wxSize &textCtrlSize, long textCtrlStyle, const wxPoint &spinCtrlPos, const wxSize &spinCtrlSize)
Definition: wx_tools.cpp:124
bool GetUnsignedInteger(unsigned int *value) const
Definition: wx_tools.cpp:181
bool GetInteger(int *value) const
Definition: wx_tools.cpp:173
wxTextCtrl * GetTextCtrl(void) const
Definition: wx_tools.hpp:152
void OnSpinButtonUp(wxSpinEvent &event)
Definition: wx_tools.cpp:155
bool SetInteger(int value)
Definition: wx_tools.cpp:143
virtual ~IntegerSpinCtrl(void)
Definition: wx_tools.hpp:137
wxSpinButton * GetSpinButton(void) const
Definition: wx_tools.hpp:153
void OnSpinButtonDown(wxSpinEvent &event)
Definition: wx_tools.cpp:164
IntegerTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxTextCtrlNameStr)
Definition: wx_tools.cpp:81
void SetAllowedRange(int min, int max, int incr)
Definition: wx_tools.cpp:103
bool IsValidInteger(void) const
Definition: wx_tools.cpp:110
void DoValidate(wxCommandEvent &event)
Definition: wx_tools.cpp:89
void OnChange(wxCommandEvent &event)
Definition: wx_tools.cpp:98
void OnSpinButtonUp(wxSpinEvent &event)
Definition: wx_tools.cpp:59
void OnSpinButtonDown(wxSpinEvent &event)
Definition: wx_tools.cpp:65
CustomSpinCtrl * notify
Definition: wx_tools.hpp:88
char value[7]
Definition: config.c:431
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const struct ncbi::grid::netcache::search::fields::SIZE size
T max(T x_, T y_)
T min(T x_, T y_)
const int WX_TOOLS_NOTIFY_CHANGED
Definition: wx_tools.cpp:43
#define const
Definition: zconf.h:230
Modified on Mon Feb 26 04:00:37 2024 by modify_doxy.py rev. 669887