spinctrl.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/spinctrl.h
  3. // Purpose: wxSpinCtrl class
  4. // Author: Robert Roebling
  5. // Modified by:
  6. // Copyright: (c) Robert Roebling
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GTK_SPINCTRL_H_
  10. #define _WX_GTK_SPINCTRL_H_
  11. //-----------------------------------------------------------------------------
  12. // wxSpinCtrlGTKBase - Base class for GTK versions of the wxSpinCtrl[Double]
  13. //
  14. // This class manages a double valued GTK spinctrl through the DoGet/SetXXX
  15. // functions that are made public as Get/SetXXX functions for int or double
  16. // for the wxSpinCtrl and wxSpinCtrlDouble classes respectively to avoid
  17. // function ambiguity.
  18. //-----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_CORE wxSpinCtrlGTKBase : public wxSpinCtrlBase
  20. {
  21. public:
  22. bool Create(wxWindow *parent,
  23. wxWindowID id,
  24. const wxString& value,
  25. const wxPoint& pos,
  26. const wxSize& size,
  27. long style,
  28. double min, double max, double initial,
  29. double inc,
  30. const wxString& name);
  31. // wxSpinCtrl(Double) methods call DoXXX functions of the same name
  32. // accessors
  33. // T GetValue() const
  34. // T GetMin() const
  35. // T GetMax() const
  36. // T GetIncrement() const
  37. virtual bool GetSnapToTicks() const;
  38. // operations
  39. virtual void SetValue(const wxString& value);
  40. // void SetValue(T val)
  41. // void SetRange(T minVal, T maxVal)
  42. // void SetIncrement(T inc)
  43. void SetSnapToTicks( bool snap_to_ticks );
  44. // Select text in the textctrl
  45. void SetSelection(long from, long to);
  46. static wxVisualAttributes
  47. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  48. // implementation
  49. void OnChar( wxKeyEvent &event );
  50. protected:
  51. double DoGetValue() const;
  52. double DoGetMin() const;
  53. double DoGetMax() const;
  54. double DoGetIncrement() const;
  55. void DoSetValue(double val);
  56. void DoSetValue(const wxString& strValue);
  57. void DoSetRange(double min_val, double max_val);
  58. void DoSetIncrement(double inc);
  59. void GtkDisableEvents() const;
  60. void GtkEnableEvents() const;
  61. virtual wxSize DoGetBestSize() const;
  62. virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
  63. virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
  64. // Widgets that use the style->base colour for the BG colour should
  65. // override this and return true.
  66. virtual bool UseGTKStyleBase() const { return true; }
  67. friend class wxSpinCtrlEventDisabler;
  68. DECLARE_EVENT_TABLE()
  69. };
  70. //-----------------------------------------------------------------------------
  71. // wxSpinCtrl - An integer valued spin control
  72. //-----------------------------------------------------------------------------
  73. class WXDLLIMPEXP_CORE wxSpinCtrl : public wxSpinCtrlGTKBase
  74. {
  75. public:
  76. wxSpinCtrl() { Init(); }
  77. wxSpinCtrl(wxWindow *parent,
  78. wxWindowID id = wxID_ANY,
  79. const wxString& value = wxEmptyString,
  80. const wxPoint& pos = wxDefaultPosition,
  81. const wxSize& size = wxDefaultSize,
  82. long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
  83. int min = 0, int max = 100, int initial = 0,
  84. const wxString& name = wxS("wxSpinCtrl"))
  85. {
  86. Init();
  87. Create(parent, id, value, pos, size, style, min, max, initial, name);
  88. }
  89. bool Create(wxWindow *parent,
  90. wxWindowID id = wxID_ANY,
  91. const wxString& value = wxEmptyString,
  92. const wxPoint& pos = wxDefaultPosition,
  93. const wxSize& size = wxDefaultSize,
  94. long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
  95. int min = 0, int max = 100, int initial = 0,
  96. const wxString& name = wxS("wxSpinCtrl"))
  97. {
  98. return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size,
  99. style, min, max, initial, 1, name);
  100. }
  101. // accessors
  102. int GetValue() const { return int(DoGetValue()); }
  103. int GetMin() const { return int(DoGetMin()); }
  104. int GetMax() const { return int(DoGetMax()); }
  105. int GetIncrement() const { return int(DoGetIncrement()); }
  106. // operations
  107. void SetValue(const wxString& value) { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc
  108. void SetValue( int value ) { DoSetValue(value); }
  109. void SetRange( int minVal, int maxVal ) { DoSetRange(minVal, maxVal); }
  110. void SetIncrement(int inc) { DoSetIncrement(inc); }
  111. virtual int GetBase() const { return m_base; }
  112. virtual bool SetBase(int base);
  113. private:
  114. // Common part of all ctors.
  115. void Init()
  116. {
  117. m_base = 10;
  118. }
  119. int m_base;
  120. DECLARE_DYNAMIC_CLASS(wxSpinCtrl)
  121. };
  122. //-----------------------------------------------------------------------------
  123. // wxSpinCtrlDouble - a double valued spin control
  124. //-----------------------------------------------------------------------------
  125. class WXDLLIMPEXP_CORE wxSpinCtrlDouble : public wxSpinCtrlGTKBase
  126. {
  127. public:
  128. wxSpinCtrlDouble() {}
  129. wxSpinCtrlDouble(wxWindow *parent,
  130. wxWindowID id = wxID_ANY,
  131. const wxString& value = wxEmptyString,
  132. const wxPoint& pos = wxDefaultPosition,
  133. const wxSize& size = wxDefaultSize,
  134. long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
  135. double min = 0, double max = 100, double initial = 0,
  136. double inc = 1,
  137. const wxString& name = wxS("wxSpinCtrlDouble"))
  138. {
  139. Create(parent, id, value, pos, size, style,
  140. min, max, initial, inc, name);
  141. }
  142. bool Create(wxWindow *parent,
  143. wxWindowID id = wxID_ANY,
  144. const wxString& value = wxEmptyString,
  145. const wxPoint& pos = wxDefaultPosition,
  146. const wxSize& size = wxDefaultSize,
  147. long style = wxSP_ARROW_KEYS | wxALIGN_RIGHT,
  148. double min = 0, double max = 100, double initial = 0,
  149. double inc = 1,
  150. const wxString& name = wxS("wxSpinCtrlDouble"))
  151. {
  152. return wxSpinCtrlGTKBase::Create(parent, id, value, pos, size,
  153. style, min, max, initial, inc, name);
  154. }
  155. // accessors
  156. double GetValue() const { return DoGetValue(); }
  157. double GetMin() const { return DoGetMin(); }
  158. double GetMax() const { return DoGetMax(); }
  159. double GetIncrement() const { return DoGetIncrement(); }
  160. unsigned GetDigits() const;
  161. // operations
  162. void SetValue(const wxString& value) { wxSpinCtrlGTKBase::SetValue(value); } // visibility problem w/ gcc
  163. void SetValue(double value) { DoSetValue(value); }
  164. void SetRange(double minVal, double maxVal) { DoSetRange(minVal, maxVal); }
  165. void SetIncrement(double inc) { DoSetIncrement(inc); }
  166. void SetDigits(unsigned digits);
  167. virtual int GetBase() const { return 10; }
  168. virtual bool SetBase(int WXUNUSED(base)) { return false; }
  169. DECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble)
  170. };
  171. #endif // _WX_GTK_SPINCTRL_H_