statusbr.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/statusbr.h
  3. // Purpose: wxStatusBar class interface
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 05.02.00
  7. // Copyright: (c) Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_STATUSBR_H_BASE_
  11. #define _WX_STATUSBR_H_BASE_
  12. #include "wx/defs.h"
  13. #if wxUSE_STATUSBAR
  14. #include "wx/control.h"
  15. #include "wx/list.h"
  16. #include "wx/dynarray.h"
  17. extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[];
  18. // ----------------------------------------------------------------------------
  19. // wxStatusBar constants
  20. // ----------------------------------------------------------------------------
  21. // wxStatusBar styles
  22. #define wxSTB_SIZEGRIP 0x0010
  23. #define wxSTB_SHOW_TIPS 0x0020
  24. #define wxSTB_ELLIPSIZE_START 0x0040
  25. #define wxSTB_ELLIPSIZE_MIDDLE 0x0080
  26. #define wxSTB_ELLIPSIZE_END 0x0100
  27. #define wxSTB_DEFAULT_STYLE (wxSTB_SIZEGRIP|wxSTB_ELLIPSIZE_END|wxSTB_SHOW_TIPS|wxFULL_REPAINT_ON_RESIZE)
  28. // old compat style name:
  29. #define wxST_SIZEGRIP wxSTB_SIZEGRIP
  30. // style flags for wxStatusBar fields
  31. #define wxSB_NORMAL 0x0000
  32. #define wxSB_FLAT 0x0001
  33. #define wxSB_RAISED 0x0002
  34. #define wxSB_SUNKEN 0x0003
  35. // ----------------------------------------------------------------------------
  36. // wxStatusBarPane: an helper for wxStatusBar
  37. // ----------------------------------------------------------------------------
  38. class WXDLLIMPEXP_CORE wxStatusBarPane
  39. {
  40. public:
  41. wxStatusBarPane(int style = wxSB_NORMAL, int width = 0)
  42. : m_nStyle(style), m_nWidth(width)
  43. { m_bEllipsized = false; }
  44. int GetWidth() const { return m_nWidth; }
  45. int GetStyle() const { return m_nStyle; }
  46. wxString GetText() const { return m_text; }
  47. // implementation-only from now on
  48. // -------------------------------
  49. bool IsEllipsized() const
  50. { return m_bEllipsized; }
  51. void SetIsEllipsized(bool isEllipsized) { m_bEllipsized = isEllipsized; }
  52. void SetWidth(int width) { m_nWidth = width; }
  53. void SetStyle(int style) { m_nStyle = style; }
  54. // set text, return true if it changed or false if it was already set to
  55. // this value
  56. bool SetText(const wxString& text);
  57. // save the existing text on top of our stack and make the new text
  58. // current; return true if the text really changed
  59. bool PushText(const wxString& text);
  60. // restore the message saved by the last call to Push() (unless it was
  61. // changed by an intervening call to SetText()) and return true if we
  62. // really restored anything
  63. bool PopText();
  64. private:
  65. int m_nStyle;
  66. int m_nWidth; // may be negative, indicating a variable-width field
  67. wxString m_text;
  68. // the array used to keep the previous values of this pane after a
  69. // PushStatusText() call, its top element is the value to restore after the
  70. // next PopStatusText() call while the currently shown value is always in
  71. // m_text
  72. wxArrayString m_arrStack;
  73. // is the currently shown value shown with ellipsis in the status bar?
  74. bool m_bEllipsized;
  75. };
  76. WX_DECLARE_EXPORTED_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray);
  77. // ----------------------------------------------------------------------------
  78. // wxStatusBar: a window near the bottom of the frame used for status info
  79. // ----------------------------------------------------------------------------
  80. class WXDLLIMPEXP_CORE wxStatusBarBase : public wxControl
  81. {
  82. public:
  83. wxStatusBarBase();
  84. virtual ~wxStatusBarBase();
  85. // field count
  86. // -----------
  87. // set the number of fields and call SetStatusWidths(widths) if widths are
  88. // given
  89. virtual void SetFieldsCount(int number = 1, const int *widths = NULL);
  90. int GetFieldsCount() const { return (int)m_panes.GetCount(); }
  91. // field text
  92. // ----------
  93. // just change or get the currently shown text
  94. void SetStatusText(const wxString& text, int number = 0);
  95. wxString GetStatusText(int number = 0) const;
  96. // change the currently shown text to the new one and save the current
  97. // value to be restored by the next call to PopStatusText()
  98. void PushStatusText(const wxString& text, int number = 0);
  99. void PopStatusText(int number = 0);
  100. // fields widths
  101. // -------------
  102. // set status field widths as absolute numbers: positive widths mean that
  103. // the field has the specified absolute width, negative widths are
  104. // interpreted as the sizer options, i.e. the extra space (total space
  105. // minus the sum of fixed width fields) is divided between the fields with
  106. // negative width according to the abs value of the width (field with width
  107. // -2 grows twice as much as one with width -1 &c)
  108. virtual void SetStatusWidths(int n, const int widths[]);
  109. int GetStatusWidth(int n) const
  110. { return m_panes[n].GetWidth(); }
  111. // field styles
  112. // ------------
  113. // Set the field border style to one of wxSB_XXX values.
  114. virtual void SetStatusStyles(int n, const int styles[]);
  115. int GetStatusStyle(int n) const
  116. { return m_panes[n].GetStyle(); }
  117. // geometry
  118. // --------
  119. // Get the position and size of the field's internal bounding rectangle
  120. virtual bool GetFieldRect(int i, wxRect& rect) const = 0;
  121. // sets the minimal vertical size of the status bar
  122. virtual void SetMinHeight(int height) = 0;
  123. // get the dimensions of the horizontal and vertical borders
  124. virtual int GetBorderX() const = 0;
  125. virtual int GetBorderY() const = 0;
  126. wxSize GetBorders() const
  127. { return wxSize(GetBorderX(), GetBorderY()); }
  128. // miscellaneous
  129. // -------------
  130. const wxStatusBarPane& GetField(int n) const
  131. { return m_panes[n]; }
  132. // wxWindow overrides:
  133. // don't want status bars to accept the focus at all
  134. virtual bool AcceptsFocus() const { return false; }
  135. // the client size of a toplevel window doesn't include the status bar
  136. virtual bool CanBeOutsideClientArea() const { return true; }
  137. protected:
  138. // called after the status bar pane text changed and should update its
  139. // display
  140. virtual void DoUpdateStatusText(int number) = 0;
  141. // wxWindow overrides:
  142. #if wxUSE_TOOLTIPS
  143. virtual void DoSetToolTip( wxToolTip *tip )
  144. {
  145. wxASSERT_MSG(!HasFlag(wxSTB_SHOW_TIPS),
  146. "Do not set tooltip(s) manually when using wxSTB_SHOW_TIPS!");
  147. wxWindow::DoSetToolTip(tip);
  148. }
  149. #endif // wxUSE_TOOLTIPS
  150. virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  151. // internal helpers & data:
  152. // calculate the real field widths for the given total available size
  153. wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const;
  154. // should be called to remember if the pane text is currently being show
  155. // ellipsized or not
  156. void SetEllipsizedFlag(int n, bool isEllipsized);
  157. // the array with the pane infos:
  158. wxStatusBarPaneArray m_panes;
  159. // if true overrides the width info of the wxStatusBarPanes
  160. bool m_bSameWidthForAllPanes;
  161. wxDECLARE_NO_COPY_CLASS(wxStatusBarBase);
  162. };
  163. // ----------------------------------------------------------------------------
  164. // include the actual wxStatusBar class declaration
  165. // ----------------------------------------------------------------------------
  166. #if defined(__WXUNIVERSAL__)
  167. #define wxStatusBarUniv wxStatusBar
  168. #include "wx/univ/statusbr.h"
  169. #elif defined(__WXMSW__) && wxUSE_NATIVE_STATUSBAR
  170. #include "wx/msw/statusbar.h"
  171. #elif defined(__WXMAC__)
  172. #define wxStatusBarMac wxStatusBar
  173. #include "wx/generic/statusbr.h"
  174. #include "wx/osx/statusbr.h"
  175. #else
  176. #define wxStatusBarGeneric wxStatusBar
  177. #include "wx/generic/statusbr.h"
  178. #endif
  179. #endif // wxUSE_STATUSBAR
  180. #endif
  181. // _WX_STATUSBR_H_BASE_