control.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/control.h
  3. // Purpose: wxControl class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_CONTROL_H_
  11. #define _WX_CONTROL_H_
  12. #include "wx/dynarray.h"
  13. // General item class
  14. class WXDLLIMPEXP_CORE wxControl : public wxControlBase
  15. {
  16. public:
  17. wxControl() { }
  18. wxControl(wxWindow *parent, wxWindowID id,
  19. const wxPoint& pos = wxDefaultPosition,
  20. const wxSize& size = wxDefaultSize, long style = 0,
  21. const wxValidator& validator = wxDefaultValidator,
  22. const wxString& name = wxControlNameStr)
  23. {
  24. Create(parent, id, pos, size, style, validator, name);
  25. }
  26. bool Create(wxWindow *parent, wxWindowID id,
  27. const wxPoint& pos = wxDefaultPosition,
  28. const wxSize& size = wxDefaultSize, long style = 0,
  29. const wxValidator& validator = wxDefaultValidator,
  30. const wxString& name = wxControlNameStr);
  31. // Simulates an event
  32. virtual void Command(wxCommandEvent& event) { ProcessCommand(event); }
  33. // implementation from now on
  34. // --------------------------
  35. virtual wxVisualAttributes GetDefaultAttributes() const
  36. {
  37. return GetClassDefaultAttributes(GetWindowVariant());
  38. }
  39. static wxVisualAttributes
  40. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  41. // Calls the callback and appropriate event handlers
  42. bool ProcessCommand(wxCommandEvent& event);
  43. // MSW-specific
  44. virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
  45. // For ownerdraw items
  46. virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *WXUNUSED(item)) { return false; }
  47. virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *WXUNUSED(item)) { return false; }
  48. const wxArrayLong& GetSubcontrols() const { return m_subControls; }
  49. // default handling of WM_CTLCOLORxxx: this is public so that wxWindow
  50. // could call it
  51. virtual WXHBRUSH MSWControlColor(WXHDC pDC, WXHWND hWnd);
  52. // default style for the control include WS_TABSTOP if it AcceptsFocus()
  53. virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
  54. protected:
  55. // choose the default border for this window
  56. virtual wxBorder GetDefaultBorder() const;
  57. // return default best size (doesn't really make any sense, override this)
  58. virtual wxSize DoGetBestSize() const;
  59. // This is a helper for all wxControls made with UPDOWN native control.
  60. // In wxMSW it was only wxSpinCtrl derived from wxSpinButton but in
  61. // WinCE of Smartphones this happens also for native wxTextCtrl,
  62. // wxChoice and others.
  63. virtual wxSize GetBestSpinnerSize(const bool is_vertical) const;
  64. // create the control of the given Windows class: this is typically called
  65. // from Create() method of the derived class passing its label, pos and
  66. // size parameter (style parameter is not needed because m_windowStyle is
  67. // supposed to had been already set and so is used instead when this
  68. // function is called)
  69. bool MSWCreateControl(const wxChar *classname,
  70. const wxString& label,
  71. const wxPoint& pos,
  72. const wxSize& size);
  73. // NB: the method below is deprecated now, with MSWGetStyle() the method
  74. // above should be used instead! Once all the controls are updated to
  75. // implement MSWGetStyle() this version will disappear.
  76. //
  77. // create the control of the given class with the given style (combination
  78. // of WS_XXX flags, i.e. Windows style, not wxWidgets one), returns
  79. // false if creation failed
  80. //
  81. // All parameters except classname and style are optional, if the
  82. // size/position are not given, they should be set later with SetSize()
  83. // and, label (the title of the window), of course, is left empty. The
  84. // extended style is determined from the style and the app 3D settings
  85. // automatically if it's not specified explicitly.
  86. bool MSWCreateControl(const wxChar *classname,
  87. WXDWORD style,
  88. const wxPoint& pos = wxDefaultPosition,
  89. const wxSize& size = wxDefaultSize,
  90. const wxString& label = wxEmptyString,
  91. WXDWORD exstyle = (WXDWORD)-1);
  92. // call this from the derived class MSWControlColor() if you want to show
  93. // the control greyed out (and opaque)
  94. WXHBRUSH MSWControlColorDisabled(WXHDC pDC);
  95. // common part of the 3 functions above: pass wxNullColour to use the
  96. // appropriate background colour (meaning ours or our parents) or a fixed
  97. // one
  98. virtual WXHBRUSH DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd);
  99. // Look in our GetSubcontrols() for the windows with the given ID.
  100. virtual wxWindow *MSWFindItem(long id, WXHWND hWnd) const;
  101. // for controls like radiobuttons which are really composite this array
  102. // holds the ids (not HWNDs!) of the sub controls
  103. wxArrayLong m_subControls;
  104. private:
  105. DECLARE_DYNAMIC_CLASS_NO_COPY(wxControl)
  106. };
  107. #endif // _WX_CONTROL_H_