window.h 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/window.h
  3. // Purpose: wxWindowBase class - the interface of wxWindow
  4. // Author: Vadim Zeitlin
  5. // Modified by: Ron Lee
  6. // Created: 01/02/97
  7. // Copyright: (c) Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_WINDOW_H_BASE_
  11. #define _WX_WINDOW_H_BASE_
  12. // ----------------------------------------------------------------------------
  13. // headers which we must include here
  14. // ----------------------------------------------------------------------------
  15. #include "wx/event.h" // the base class
  16. #include "wx/list.h" // defines wxWindowList
  17. #include "wx/cursor.h" // we have member variables of these classes
  18. #include "wx/font.h" // so we can't do without them
  19. #include "wx/colour.h"
  20. #include "wx/region.h"
  21. #include "wx/utils.h"
  22. #include "wx/intl.h"
  23. #include "wx/validate.h" // for wxDefaultValidator (always include it)
  24. #if wxUSE_PALETTE
  25. #include "wx/palette.h"
  26. #endif // wxUSE_PALETTE
  27. #if wxUSE_ACCEL
  28. #include "wx/accel.h"
  29. #endif // wxUSE_ACCEL
  30. #if wxUSE_ACCESSIBILITY
  31. #include "wx/access.h"
  32. #endif
  33. // when building wxUniv/Foo we don't want the code for native menu use to be
  34. // compiled in - it should only be used when building real wxFoo
  35. #ifdef __WXUNIVERSAL__
  36. #define wxUSE_MENUS_NATIVE 0
  37. #else // !__WXUNIVERSAL__
  38. #define wxUSE_MENUS_NATIVE wxUSE_MENUS
  39. #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
  40. // Define this macro if the corresponding operating system handles the state
  41. // of children windows automatically when the parent is enabled/disabled.
  42. // Otherwise wx itself must ensure that when the parent is disabled its
  43. // children are disabled too, and their initial state is restored when the
  44. // parent is enabled back.
  45. #if defined(__WXMSW__) || defined(__WXPM__)
  46. // must do everything ourselves
  47. #undef wxHAS_NATIVE_ENABLED_MANAGEMENT
  48. #elif defined(__WXOSX__)
  49. #if wxOSX_USE_CARBON
  50. #define wxHAS_NATIVE_ENABLED_MANAGEMENT
  51. #else
  52. // must do everything ourselves
  53. #undef wxHAS_NATIVE_ENABLED_MANAGEMENT
  54. #endif
  55. #else
  56. #define wxHAS_NATIVE_ENABLED_MANAGEMENT
  57. #endif
  58. // ----------------------------------------------------------------------------
  59. // forward declarations
  60. // ----------------------------------------------------------------------------
  61. class WXDLLIMPEXP_FWD_CORE wxCaret;
  62. class WXDLLIMPEXP_FWD_CORE wxControl;
  63. class WXDLLIMPEXP_FWD_CORE wxCursor;
  64. class WXDLLIMPEXP_FWD_CORE wxDC;
  65. class WXDLLIMPEXP_FWD_CORE wxDropTarget;
  66. class WXDLLIMPEXP_FWD_CORE wxLayoutConstraints;
  67. class WXDLLIMPEXP_FWD_CORE wxSizer;
  68. class WXDLLIMPEXP_FWD_CORE wxToolTip;
  69. class WXDLLIMPEXP_FWD_CORE wxWindowBase;
  70. class WXDLLIMPEXP_FWD_CORE wxWindow;
  71. class WXDLLIMPEXP_FWD_CORE wxScrollHelper;
  72. #if wxUSE_ACCESSIBILITY
  73. class WXDLLIMPEXP_FWD_CORE wxAccessible;
  74. #endif
  75. // ----------------------------------------------------------------------------
  76. // helper stuff used by wxWindow
  77. // ----------------------------------------------------------------------------
  78. // struct containing all the visual attributes of a control
  79. struct WXDLLIMPEXP_CORE wxVisualAttributes
  80. {
  81. // the font used for control label/text inside it
  82. wxFont font;
  83. // the foreground colour
  84. wxColour colFg;
  85. // the background colour, may be wxNullColour if the controls background
  86. // colour is not solid
  87. wxColour colBg;
  88. };
  89. // different window variants, on platforms like eg mac uses different
  90. // rendering sizes
  91. enum wxWindowVariant
  92. {
  93. wxWINDOW_VARIANT_NORMAL, // Normal size
  94. wxWINDOW_VARIANT_SMALL, // Smaller size (about 25 % smaller than normal)
  95. wxWINDOW_VARIANT_MINI, // Mini size (about 33 % smaller than normal)
  96. wxWINDOW_VARIANT_LARGE, // Large size (about 25 % larger than normal)
  97. wxWINDOW_VARIANT_MAX
  98. };
  99. #if wxUSE_SYSTEM_OPTIONS
  100. #define wxWINDOW_DEFAULT_VARIANT wxT("window-default-variant")
  101. #endif
  102. // valid values for Show/HideWithEffect()
  103. enum wxShowEffect
  104. {
  105. wxSHOW_EFFECT_NONE,
  106. wxSHOW_EFFECT_ROLL_TO_LEFT,
  107. wxSHOW_EFFECT_ROLL_TO_RIGHT,
  108. wxSHOW_EFFECT_ROLL_TO_TOP,
  109. wxSHOW_EFFECT_ROLL_TO_BOTTOM,
  110. wxSHOW_EFFECT_SLIDE_TO_LEFT,
  111. wxSHOW_EFFECT_SLIDE_TO_RIGHT,
  112. wxSHOW_EFFECT_SLIDE_TO_TOP,
  113. wxSHOW_EFFECT_SLIDE_TO_BOTTOM,
  114. wxSHOW_EFFECT_BLEND,
  115. wxSHOW_EFFECT_EXPAND,
  116. wxSHOW_EFFECT_MAX
  117. };
  118. // flags for SendSizeEvent()
  119. enum
  120. {
  121. wxSEND_EVENT_POST = 1
  122. };
  123. // ----------------------------------------------------------------------------
  124. // (pseudo)template list classes
  125. // ----------------------------------------------------------------------------
  126. WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLIMPEXP_CORE);
  127. // ----------------------------------------------------------------------------
  128. // global variables
  129. // ----------------------------------------------------------------------------
  130. extern WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
  131. // declared here for compatibility only, main declaration is in wx/app.h
  132. extern WXDLLIMPEXP_DATA_BASE(wxList) wxPendingDelete;
  133. // ----------------------------------------------------------------------------
  134. // wxWindowBase is the base class for all GUI controls/widgets, this is the public
  135. // interface of this class.
  136. //
  137. // Event handler: windows have themselves as their event handlers by default,
  138. // but their event handlers could be set to another object entirely. This
  139. // separation can reduce the amount of derivation required, and allow
  140. // alteration of a window's functionality (e.g. by a resource editor that
  141. // temporarily switches event handlers).
  142. // ----------------------------------------------------------------------------
  143. class WXDLLIMPEXP_CORE wxWindowBase : public wxEvtHandler
  144. {
  145. public:
  146. // creating the window
  147. // -------------------
  148. // default ctor, initializes everything which can be initialized before
  149. // Create()
  150. wxWindowBase() ;
  151. virtual ~wxWindowBase();
  152. // deleting the window
  153. // -------------------
  154. // ask the window to close itself, return true if the event handler
  155. // honoured our request
  156. bool Close( bool force = false );
  157. // the following functions delete the C++ objects (the window itself
  158. // or its children) as well as the GUI windows and normally should
  159. // never be used directly
  160. // delete window unconditionally (dangerous!), returns true if ok
  161. virtual bool Destroy();
  162. // delete all children of this window, returns true if ok
  163. bool DestroyChildren();
  164. // is the window being deleted?
  165. bool IsBeingDeleted() const;
  166. // window attributes
  167. // -----------------
  168. // label is just the same as the title (but for, e.g., buttons it
  169. // makes more sense to speak about labels), title access
  170. // is available from wxTLW classes only (frames, dialogs)
  171. virtual void SetLabel(const wxString& label) = 0;
  172. virtual wxString GetLabel() const = 0;
  173. // the window name is used for ressource setting in X, it is not the
  174. // same as the window title/label
  175. virtual void SetName( const wxString &name ) { m_windowName = name; }
  176. virtual wxString GetName() const { return m_windowName; }
  177. // sets the window variant, calls internally DoSetVariant if variant
  178. // has changed
  179. void SetWindowVariant(wxWindowVariant variant);
  180. wxWindowVariant GetWindowVariant() const { return m_windowVariant; }
  181. // get or change the layout direction (LTR or RTL) for this window,
  182. // wxLayout_Default is returned if layout direction is not supported
  183. virtual wxLayoutDirection GetLayoutDirection() const
  184. { return wxLayout_Default; }
  185. virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir))
  186. { }
  187. // mirror coordinates for RTL layout if this window uses it and if the
  188. // mirroring is not done automatically like Win32
  189. virtual wxCoord AdjustForLayoutDirection(wxCoord x,
  190. wxCoord width,
  191. wxCoord widthTotal) const;
  192. // window id uniquely identifies the window among its siblings unless
  193. // it is wxID_ANY which means "don't care"
  194. void SetId( wxWindowID winid ) { m_windowId = winid; }
  195. wxWindowID GetId() const { return m_windowId; }
  196. // generate a unique id (or count of them consecutively), returns a
  197. // valid id in the auto-id range or wxID_NONE if failed. If using
  198. // autoid management, it will mark the id as reserved until it is
  199. // used (by assigning it to a wxWindowIDRef) or unreserved.
  200. static wxWindowID NewControlId(int count = 1)
  201. {
  202. return wxIdManager::ReserveId(count);
  203. }
  204. // If an ID generated from NewControlId is not assigned to a wxWindowIDRef,
  205. // it must be unreserved
  206. static void UnreserveControlId(wxWindowID id, int count = 1)
  207. {
  208. wxIdManager::UnreserveId(id, count);
  209. }
  210. // moving/resizing
  211. // ---------------
  212. // set the window size and/or position
  213. void SetSize( int x, int y, int width, int height,
  214. int sizeFlags = wxSIZE_AUTO )
  215. { DoSetSize(x, y, width, height, sizeFlags); }
  216. void SetSize( int width, int height )
  217. { DoSetSize( wxDefaultCoord, wxDefaultCoord, width, height, wxSIZE_USE_EXISTING ); }
  218. void SetSize( const wxSize& size )
  219. { SetSize( size.x, size.y); }
  220. void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
  221. { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
  222. void Move(int x, int y, int flags = wxSIZE_USE_EXISTING)
  223. { DoSetSize(x, y, wxDefaultCoord, wxDefaultCoord, flags); }
  224. void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
  225. { Move(pt.x, pt.y, flags); }
  226. void SetPosition(const wxPoint& pt) { Move(pt); }
  227. // Z-order
  228. virtual void Raise() = 0;
  229. virtual void Lower() = 0;
  230. // client size is the size of area available for subwindows
  231. void SetClientSize( int width, int height )
  232. { DoSetClientSize(width, height); }
  233. void SetClientSize( const wxSize& size )
  234. { DoSetClientSize(size.x, size.y); }
  235. void SetClientSize(const wxRect& rect)
  236. { SetClientSize( rect.width, rect.height ); }
  237. // get the window position (pointers may be NULL): notice that it is in
  238. // client coordinates for child windows and screen coordinates for the
  239. // top level ones, use GetScreenPosition() if you need screen
  240. // coordinates for all kinds of windows
  241. void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
  242. wxPoint GetPosition() const
  243. {
  244. int x, y;
  245. DoGetPosition(&x, &y);
  246. return wxPoint(x, y);
  247. }
  248. // get the window position in screen coordinates
  249. void GetScreenPosition(int *x, int *y) const { DoGetScreenPosition(x, y); }
  250. wxPoint GetScreenPosition() const
  251. {
  252. int x, y;
  253. DoGetScreenPosition(&x, &y);
  254. return wxPoint(x, y);
  255. }
  256. // get the window size (pointers may be NULL)
  257. void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
  258. wxSize GetSize() const
  259. {
  260. int w, h;
  261. DoGetSize(& w, & h);
  262. return wxSize(w, h);
  263. }
  264. void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
  265. wxSize GetClientSize() const
  266. {
  267. int w, h;
  268. DoGetClientSize(&w, &h);
  269. return wxSize(w, h);
  270. }
  271. // get the position and size at once
  272. wxRect GetRect() const
  273. {
  274. int x, y, w, h;
  275. GetPosition(&x, &y);
  276. GetSize(&w, &h);
  277. return wxRect(x, y, w, h);
  278. }
  279. wxRect GetScreenRect() const
  280. {
  281. int x, y, w, h;
  282. GetScreenPosition(&x, &y);
  283. GetSize(&w, &h);
  284. return wxRect(x, y, w, h);
  285. }
  286. // get the origin of the client area of the window relative to the
  287. // window top left corner (the client area may be shifted because of
  288. // the borders, scrollbars, other decorations...)
  289. virtual wxPoint GetClientAreaOrigin() const;
  290. // get the client rectangle in window (i.e. client) coordinates
  291. wxRect GetClientRect() const
  292. {
  293. return wxRect(GetClientAreaOrigin(), GetClientSize());
  294. }
  295. // client<->window size conversion
  296. virtual wxSize ClientToWindowSize(const wxSize& size) const;
  297. virtual wxSize WindowToClientSize(const wxSize& size) const;
  298. // get the size best suited for the window (in fact, minimal
  299. // acceptable size using which it will still look "nice" in
  300. // most situations)
  301. wxSize GetBestSize() const;
  302. void GetBestSize(int *w, int *h) const
  303. {
  304. wxSize s = GetBestSize();
  305. if ( w )
  306. *w = s.x;
  307. if ( h )
  308. *h = s.y;
  309. }
  310. // Determine the best size in the other direction if one of them is
  311. // fixed. This is used with windows that can wrap their contents and
  312. // returns input-independent best size for the others.
  313. int GetBestHeight(int width) const;
  314. int GetBestWidth(int height) const;
  315. void SetScrollHelper( wxScrollHelper *sh ) { m_scrollHelper = sh; }
  316. wxScrollHelper *GetScrollHelper() { return m_scrollHelper; }
  317. // reset the cached best size value so it will be recalculated the
  318. // next time it is needed.
  319. void InvalidateBestSize();
  320. void CacheBestSize(const wxSize& size) const
  321. { wxConstCast(this, wxWindowBase)->m_bestSizeCache = size; }
  322. // This function will merge the window's best size into the window's
  323. // minimum size, giving priority to the min size components, and
  324. // returns the results.
  325. virtual wxSize GetEffectiveMinSize() const;
  326. wxDEPRECATED_MSG("use GetEffectiveMinSize() instead")
  327. wxSize GetBestFittingSize() const;
  328. wxDEPRECATED_MSG("use GetEffectiveMinSize() instead")
  329. wxSize GetAdjustedMinSize() const;
  330. // A 'Smart' SetSize that will fill in default size values with 'best'
  331. // size. Sets the minsize to what was passed in.
  332. void SetInitialSize(const wxSize& size=wxDefaultSize);
  333. wxDEPRECATED_MSG("use SetInitialSize() instead")
  334. void SetBestFittingSize(const wxSize& size=wxDefaultSize);
  335. // the generic centre function - centers the window on parent by`
  336. // default or on screen if it doesn't have parent or
  337. // wxCENTER_ON_SCREEN flag is given
  338. void Centre(int dir = wxBOTH) { DoCentre(dir); }
  339. void Center(int dir = wxBOTH) { DoCentre(dir); }
  340. // centre with respect to the parent window
  341. void CentreOnParent(int dir = wxBOTH) { DoCentre(dir); }
  342. void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); }
  343. // set window size to wrap around its children
  344. virtual void Fit();
  345. // set virtual size to satisfy children
  346. virtual void FitInside();
  347. // SetSizeHints is actually for setting the size hints
  348. // for the wxTLW for a Window Manager - hence the name -
  349. // and it is therefore overridden in wxTLW to do that.
  350. // In wxWindow(Base), it has (unfortunately) been abused
  351. // to mean the same as SetMinSize() and SetMaxSize().
  352. virtual void SetSizeHints( int minW, int minH,
  353. int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
  354. int incW = wxDefaultCoord, int incH = wxDefaultCoord )
  355. { DoSetSizeHints(minW, minH, maxW, maxH, incW, incH); }
  356. void SetSizeHints( const wxSize& minSize,
  357. const wxSize& maxSize=wxDefaultSize,
  358. const wxSize& incSize=wxDefaultSize)
  359. { DoSetSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y, incSize.x, incSize.y); }
  360. #if WXWIN_COMPATIBILITY_2_8
  361. // these are useless and do nothing since wxWidgets 2.9
  362. wxDEPRECATED( virtual void SetVirtualSizeHints( int minW, int minH,
  363. int maxW = wxDefaultCoord, int maxH = wxDefaultCoord ) );
  364. wxDEPRECATED( void SetVirtualSizeHints( const wxSize& minSize,
  365. const wxSize& maxSize=wxDefaultSize) );
  366. #endif // WXWIN_COMPATIBILITY_2_8
  367. // Call these to override what GetBestSize() returns. This
  368. // method is only virtual because it is overridden in wxTLW
  369. // as a different API for SetSizeHints().
  370. virtual void SetMinSize(const wxSize& minSize);
  371. virtual void SetMaxSize(const wxSize& maxSize);
  372. // Like Set*Size, but for client, not window, size
  373. virtual void SetMinClientSize(const wxSize& size)
  374. { SetMinSize(ClientToWindowSize(size)); }
  375. virtual void SetMaxClientSize(const wxSize& size)
  376. { SetMaxSize(ClientToWindowSize(size)); }
  377. // Override these methods to impose restrictions on min/max size.
  378. // The easier way is to call SetMinSize() and SetMaxSize() which
  379. // will have the same effect. Doing both is non-sense.
  380. virtual wxSize GetMinSize() const { return wxSize(m_minWidth, m_minHeight); }
  381. virtual wxSize GetMaxSize() const { return wxSize(m_maxWidth, m_maxHeight); }
  382. // Like Get*Size, but for client, not window, size
  383. virtual wxSize GetMinClientSize() const
  384. { return WindowToClientSize(GetMinSize()); }
  385. virtual wxSize GetMaxClientSize() const
  386. { return WindowToClientSize(GetMaxSize()); }
  387. // Get the min and max values one by one
  388. int GetMinWidth() const { return GetMinSize().x; }
  389. int GetMinHeight() const { return GetMinSize().y; }
  390. int GetMaxWidth() const { return GetMaxSize().x; }
  391. int GetMaxHeight() const { return GetMaxSize().y; }
  392. // Methods for accessing the virtual size of a window. For most
  393. // windows this is just the client area of the window, but for
  394. // some like scrolled windows it is more or less independent of
  395. // the screen window size. You may override the DoXXXVirtual
  396. // methods below for classes where that is the case.
  397. void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); }
  398. void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); }
  399. wxSize GetVirtualSize() const { return DoGetVirtualSize(); }
  400. void GetVirtualSize( int *x, int *y ) const
  401. {
  402. wxSize s( DoGetVirtualSize() );
  403. if( x )
  404. *x = s.GetWidth();
  405. if( y )
  406. *y = s.GetHeight();
  407. }
  408. // Override these methods for windows that have a virtual size
  409. // independent of their client size. eg. the virtual area of a
  410. // wxScrolledWindow.
  411. virtual void DoSetVirtualSize( int x, int y );
  412. virtual wxSize DoGetVirtualSize() const;
  413. // Return the largest of ClientSize and BestSize (as determined
  414. // by a sizer, interior children, or other means)
  415. virtual wxSize GetBestVirtualSize() const
  416. {
  417. wxSize client( GetClientSize() );
  418. wxSize best( GetBestSize() );
  419. return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) );
  420. }
  421. // returns the magnification of the content of this window
  422. // eg 2.0 for a window on a retina screen
  423. virtual double GetContentScaleFactor() const
  424. { return 1.0; }
  425. // return the size of the left/right and top/bottom borders in x and y
  426. // components of the result respectively
  427. virtual wxSize GetWindowBorderSize() const;
  428. // wxSizer and friends use this to give a chance to a component to recalc
  429. // its min size once one of the final size components is known. Override
  430. // this function when that is useful (such as for wxStaticText which can
  431. // stretch over several lines). Parameter availableOtherDir
  432. // tells the item how much more space there is available in the opposite
  433. // direction (-1 if unknown).
  434. virtual bool
  435. InformFirstDirection(int direction, int size, int availableOtherDir);
  436. // sends a size event to the window using its current size -- this has an
  437. // effect of refreshing the window layout
  438. //
  439. // by default the event is sent, i.e. processed immediately, but if flags
  440. // value includes wxSEND_EVENT_POST then it's posted, i.e. only schedule
  441. // for later processing
  442. virtual void SendSizeEvent(int flags = 0);
  443. // this is a safe wrapper for GetParent()->SendSizeEvent(): it checks that
  444. // we have a parent window and it's not in process of being deleted
  445. //
  446. // this is used by controls such as tool/status bars changes to which must
  447. // also result in parent re-layout
  448. void SendSizeEventToParent(int flags = 0);
  449. // this is a more readable synonym for SendSizeEvent(wxSEND_EVENT_POST)
  450. void PostSizeEvent() { SendSizeEvent(wxSEND_EVENT_POST); }
  451. // this is the same as SendSizeEventToParent() but using PostSizeEvent()
  452. void PostSizeEventToParent() { SendSizeEventToParent(wxSEND_EVENT_POST); }
  453. // These functions should be used before repositioning the children of
  454. // this window to reduce flicker or, in MSW case, even avoid display
  455. // corruption in some situations (so they're more than just optimization).
  456. //
  457. // EndRepositioningChildren() should be called if and only if
  458. // BeginRepositioningChildren() returns true. To ensure that this is always
  459. // done automatically, use ChildrenRepositioningGuard class below.
  460. virtual bool BeginRepositioningChildren() { return false; }
  461. virtual void EndRepositioningChildren() { }
  462. // A simple helper which ensures that EndRepositioningChildren() is called
  463. // from its dtor if and only if calling BeginRepositioningChildren() from
  464. // the ctor returned true.
  465. class ChildrenRepositioningGuard
  466. {
  467. public:
  468. // Notice that window can be NULL here, for convenience. In this case
  469. // this class simply doesn't do anything.
  470. wxEXPLICIT ChildrenRepositioningGuard(wxWindowBase* win)
  471. : m_win(win),
  472. m_callEnd(win && win->BeginRepositioningChildren())
  473. {
  474. }
  475. ~ChildrenRepositioningGuard()
  476. {
  477. if ( m_callEnd )
  478. m_win->EndRepositioningChildren();
  479. }
  480. private:
  481. wxWindowBase* const m_win;
  482. const bool m_callEnd;
  483. wxDECLARE_NO_COPY_CLASS(ChildrenRepositioningGuard);
  484. };
  485. // window state
  486. // ------------
  487. // returns true if window was shown/hidden, false if the nothing was
  488. // done (window was already shown/hidden)
  489. virtual bool Show( bool show = true );
  490. bool Hide() { return Show(false); }
  491. // show or hide the window with a special effect, not implemented on
  492. // most platforms (where it is the same as Show()/Hide() respectively)
  493. //
  494. // timeout specifies how long the animation should take, in ms, the
  495. // default value of 0 means to use the default (system-dependent) value
  496. virtual bool ShowWithEffect(wxShowEffect WXUNUSED(effect),
  497. unsigned WXUNUSED(timeout) = 0)
  498. {
  499. return Show();
  500. }
  501. virtual bool HideWithEffect(wxShowEffect WXUNUSED(effect),
  502. unsigned WXUNUSED(timeout) = 0)
  503. {
  504. return Hide();
  505. }
  506. // returns true if window was enabled/disabled, false if nothing done
  507. virtual bool Enable( bool enable = true );
  508. bool Disable() { return Enable(false); }
  509. virtual bool IsShown() const { return m_isShown; }
  510. // returns true if the window is really enabled and false otherwise,
  511. // whether because it had been explicitly disabled itself or because
  512. // its parent is currently disabled -- then this method returns false
  513. // whatever is the intrinsic state of this window, use IsThisEnabled(0
  514. // to retrieve it. In other words, this relation always holds:
  515. //
  516. // IsEnabled() == IsThisEnabled() && parent.IsEnabled()
  517. //
  518. bool IsEnabled() const;
  519. // returns the internal window state independently of the parent(s)
  520. // state, i.e. the state in which the window would be if all its
  521. // parents were enabled (use IsEnabled() above to get the effective
  522. // window state)
  523. bool IsThisEnabled() const { return m_isEnabled; }
  524. // returns true if the window is visible, i.e. IsShown() returns true
  525. // if called on it and all its parents up to the first TLW
  526. virtual bool IsShownOnScreen() const;
  527. // get/set window style (setting style won't update the window and so
  528. // is only useful for internal usage)
  529. virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
  530. virtual long GetWindowStyleFlag() const { return m_windowStyle; }
  531. // just some (somewhat shorter) synonyms
  532. void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
  533. long GetWindowStyle() const { return GetWindowStyleFlag(); }
  534. // check if the flag is set
  535. bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
  536. virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
  537. // turn the flag on if it had been turned off before and vice versa,
  538. // return true if the flag is currently turned on
  539. bool ToggleWindowStyle(int flag);
  540. // extra style: the less often used style bits which can't be set with
  541. // SetWindowStyleFlag()
  542. virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
  543. long GetExtraStyle() const { return m_exStyle; }
  544. bool HasExtraStyle(int exFlag) const { return (m_exStyle & exFlag) != 0; }
  545. #if WXWIN_COMPATIBILITY_2_8
  546. // make the window modal (all other windows unresponsive)
  547. wxDEPRECATED( virtual void MakeModal(bool modal = true) );
  548. #endif
  549. // (primitive) theming support
  550. // ---------------------------
  551. virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
  552. virtual bool GetThemeEnabled() const { return m_themeEnabled; }
  553. // focus and keyboard handling
  554. // ---------------------------
  555. // set focus to this window
  556. virtual void SetFocus() = 0;
  557. // set focus to this window as the result of a keyboard action
  558. virtual void SetFocusFromKbd() { SetFocus(); }
  559. // return the window which currently has the focus or NULL
  560. static wxWindow *FindFocus();
  561. static wxWindow *DoFindFocus() /* = 0: implement in derived classes */;
  562. // return true if the window has focus (handles composite windows
  563. // correctly - returns true if GetMainWindowOfCompositeControl()
  564. // has focus)
  565. virtual bool HasFocus() const;
  566. // can this window have focus in principle?
  567. //
  568. // the difference between AcceptsFocus[FromKeyboard]() and CanAcceptFocus
  569. // [FromKeyboard]() is that the former functions are meant to be
  570. // overridden in the derived classes to simply return false if the
  571. // control can't have focus, while the latter are meant to be used by
  572. // this class clients and take into account the current window state
  573. virtual bool AcceptsFocus() const { return true; }
  574. // can this window or one of its children accept focus?
  575. //
  576. // usually it's the same as AcceptsFocus() but is overridden for
  577. // container windows
  578. virtual bool AcceptsFocusRecursively() const { return AcceptsFocus(); }
  579. // can this window be given focus by keyboard navigation? if not, the
  580. // only way to give it focus (provided it accepts it at all) is to
  581. // click it
  582. virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
  583. // Can this window be focused right now, in its current state? This
  584. // shouldn't be called at all if AcceptsFocus() returns false.
  585. //
  586. // It is a convenient helper for the various functions using it below
  587. // but also a hook allowing to override the default logic for some rare
  588. // cases (currently just wxRadioBox in wxMSW) when it's inappropriate.
  589. virtual bool CanBeFocused() const { return IsShown() && IsEnabled(); }
  590. // can this window itself have focus?
  591. bool IsFocusable() const { return AcceptsFocus() && CanBeFocused(); }
  592. // can this window have focus right now?
  593. //
  594. // if this method returns true, it means that calling SetFocus() will
  595. // put focus either to this window or one of its children, if you need
  596. // to know whether this window accepts focus itself, use IsFocusable()
  597. bool CanAcceptFocus() const
  598. { return AcceptsFocusRecursively() && CanBeFocused(); }
  599. // can this window be assigned focus from keyboard right now?
  600. bool CanAcceptFocusFromKeyboard() const
  601. { return AcceptsFocusFromKeyboard() && CanBeFocused(); }
  602. // call this when the return value of AcceptsFocus() changes
  603. virtual void SetCanFocus(bool WXUNUSED(canFocus)) { }
  604. // navigates inside this window
  605. bool NavigateIn(int flags = wxNavigationKeyEvent::IsForward)
  606. { return DoNavigateIn(flags); }
  607. // navigates in the specified direction from this window, this is
  608. // equivalent to GetParent()->NavigateIn()
  609. bool Navigate(int flags = wxNavigationKeyEvent::IsForward)
  610. { return m_parent && ((wxWindowBase *)m_parent)->DoNavigateIn(flags); }
  611. // this function will generate the appropriate call to Navigate() if the
  612. // key event is one normally used for keyboard navigation and return true
  613. // in this case
  614. bool HandleAsNavigationKey(const wxKeyEvent& event);
  615. // move this window just before/after the specified one in tab order
  616. // (the other window must be our sibling!)
  617. void MoveBeforeInTabOrder(wxWindow *win)
  618. { DoMoveInTabOrder(win, OrderBefore); }
  619. void MoveAfterInTabOrder(wxWindow *win)
  620. { DoMoveInTabOrder(win, OrderAfter); }
  621. // parent/children relations
  622. // -------------------------
  623. // get the list of children
  624. const wxWindowList& GetChildren() const { return m_children; }
  625. wxWindowList& GetChildren() { return m_children; }
  626. // needed just for extended runtime
  627. const wxWindowList& GetWindowChildren() const { return GetChildren() ; }
  628. // get the window before/after this one in the parents children list,
  629. // returns NULL if this is the first/last window
  630. wxWindow *GetPrevSibling() const { return DoGetSibling(OrderBefore); }
  631. wxWindow *GetNextSibling() const { return DoGetSibling(OrderAfter); }
  632. // get the parent or the parent of the parent
  633. wxWindow *GetParent() const { return m_parent; }
  634. inline wxWindow *GetGrandParent() const;
  635. // is this window a top level one?
  636. virtual bool IsTopLevel() const;
  637. // is this window a child or grand child of this one (inside the same
  638. // TLW)?
  639. bool IsDescendant(wxWindowBase* win) const;
  640. // it doesn't really change parent, use Reparent() instead
  641. void SetParent( wxWindowBase *parent );
  642. // change the real parent of this window, return true if the parent
  643. // was changed, false otherwise (error or newParent == oldParent)
  644. virtual bool Reparent( wxWindowBase *newParent );
  645. // implementation mostly
  646. virtual void AddChild( wxWindowBase *child );
  647. virtual void RemoveChild( wxWindowBase *child );
  648. // returns true if the child is in the client area of the window, i.e. is
  649. // not scrollbar, toolbar etc.
  650. virtual bool IsClientAreaChild(const wxWindow *WXUNUSED(child)) const
  651. { return true; }
  652. // looking for windows
  653. // -------------------
  654. // find window among the descendants of this one either by id or by
  655. // name (return NULL if not found)
  656. wxWindow *FindWindow(long winid) const;
  657. wxWindow *FindWindow(const wxString& name) const;
  658. // Find a window among any window (all return NULL if not found)
  659. static wxWindow *FindWindowById( long winid, const wxWindow *parent = NULL );
  660. static wxWindow *FindWindowByName( const wxString& name,
  661. const wxWindow *parent = NULL );
  662. static wxWindow *FindWindowByLabel( const wxString& label,
  663. const wxWindow *parent = NULL );
  664. // event handler stuff
  665. // -------------------
  666. // get the current event handler
  667. wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
  668. // replace the event handler (allows to completely subclass the
  669. // window)
  670. void SetEventHandler( wxEvtHandler *handler );
  671. // push/pop event handler: allows to chain a custom event handler to
  672. // alreasy existing ones
  673. void PushEventHandler( wxEvtHandler *handler );
  674. wxEvtHandler *PopEventHandler( bool deleteHandler = false );
  675. // find the given handler in the event handler chain and remove (but
  676. // not delete) it from the event handler chain, return true if it was
  677. // found and false otherwise (this also results in an assert failure so
  678. // this function should only be called when the handler is supposed to
  679. // be there)
  680. bool RemoveEventHandler(wxEvtHandler *handler);
  681. // Process an event by calling GetEventHandler()->ProcessEvent(): this
  682. // is a straightforward replacement for ProcessEvent() itself which
  683. // shouldn't be used directly with windows as it doesn't take into
  684. // account any event handlers associated with the window
  685. bool ProcessWindowEvent(wxEvent& event)
  686. { return GetEventHandler()->ProcessEvent(event); }
  687. // Call GetEventHandler()->ProcessEventLocally(): this should be used
  688. // instead of calling ProcessEventLocally() directly on the window
  689. // itself as this wouldn't take any pushed event handlers into account
  690. // correctly
  691. bool ProcessWindowEventLocally(wxEvent& event)
  692. { return GetEventHandler()->ProcessEventLocally(event); }
  693. // Process an event by calling GetEventHandler()->ProcessEvent() and
  694. // handling any exceptions thrown by event handlers. It's mostly useful
  695. // when processing wx events when called from C code (e.g. in GTK+
  696. // callback) when the exception wouldn't correctly propagate to
  697. // wxEventLoop.
  698. bool HandleWindowEvent(wxEvent& event) const;
  699. // disable wxEvtHandler double-linked list mechanism:
  700. virtual void SetNextHandler(wxEvtHandler *handler);
  701. virtual void SetPreviousHandler(wxEvtHandler *handler);
  702. // Watcom doesn't allow reducing access with using access declaration, see
  703. // #10749
  704. #ifndef __WATCOMC__
  705. protected:
  706. // NOTE: we change the access specifier of the following wxEvtHandler functions
  707. // so that the user won't be able to call them directly.
  708. // Calling wxWindow::ProcessEvent in fact only works when there are NO
  709. // event handlers pushed on the window.
  710. // To ensure correct operation, instead of wxWindow::ProcessEvent
  711. // you must always call wxWindow::GetEventHandler()->ProcessEvent()
  712. // or HandleWindowEvent().
  713. // The same holds for all other wxEvtHandler functions.
  714. using wxEvtHandler::ProcessEvent;
  715. using wxEvtHandler::ProcessEventLocally;
  716. #if wxUSE_THREADS
  717. using wxEvtHandler::ProcessThreadEvent;
  718. #endif
  719. using wxEvtHandler::SafelyProcessEvent;
  720. using wxEvtHandler::ProcessPendingEvents;
  721. using wxEvtHandler::AddPendingEvent;
  722. using wxEvtHandler::QueueEvent;
  723. #endif // __WATCOMC__
  724. public:
  725. // validators
  726. // ----------
  727. #if wxUSE_VALIDATORS
  728. // a window may have an associated validator which is used to control
  729. // user input
  730. virtual void SetValidator( const wxValidator &validator );
  731. virtual wxValidator *GetValidator() { return m_windowValidator; }
  732. #endif // wxUSE_VALIDATORS
  733. // dialog oriented functions
  734. // -------------------------
  735. // validate the correctness of input, return true if ok
  736. virtual bool Validate();
  737. // transfer data between internal and GUI representations
  738. virtual bool TransferDataToWindow();
  739. virtual bool TransferDataFromWindow();
  740. virtual void InitDialog();
  741. #if wxUSE_ACCEL
  742. // accelerators
  743. // ------------
  744. virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
  745. { m_acceleratorTable = accel; }
  746. wxAcceleratorTable *GetAcceleratorTable()
  747. { return &m_acceleratorTable; }
  748. #endif // wxUSE_ACCEL
  749. #if wxUSE_HOTKEY
  750. // hot keys (system wide accelerators)
  751. // -----------------------------------
  752. virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
  753. virtual bool UnregisterHotKey(int hotkeyId);
  754. #endif // wxUSE_HOTKEY
  755. // dialog units translations
  756. // -------------------------
  757. wxPoint ConvertPixelsToDialog( const wxPoint& pt ) const;
  758. wxPoint ConvertDialogToPixels( const wxPoint& pt ) const;
  759. wxSize ConvertPixelsToDialog( const wxSize& sz ) const
  760. {
  761. wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
  762. return wxSize(pt.x, pt.y);
  763. }
  764. wxSize ConvertDialogToPixels( const wxSize& sz ) const
  765. {
  766. wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
  767. return wxSize(pt.x, pt.y);
  768. }
  769. // mouse functions
  770. // ---------------
  771. // move the mouse to the specified position
  772. virtual void WarpPointer(int x, int y) = 0;
  773. // start or end mouse capture, these functions maintain the stack of
  774. // windows having captured the mouse and after calling ReleaseMouse()
  775. // the mouse is not released but returns to the window which had had
  776. // captured it previously (if any)
  777. void CaptureMouse();
  778. void ReleaseMouse();
  779. // get the window which currently captures the mouse or NULL
  780. static wxWindow *GetCapture();
  781. // does this window have the capture?
  782. virtual bool HasCapture() const
  783. { return (wxWindow *)this == GetCapture(); }
  784. // painting the window
  785. // -------------------
  786. // mark the specified rectangle (or the whole window) as "dirty" so it
  787. // will be repainted
  788. virtual void Refresh( bool eraseBackground = true,
  789. const wxRect *rect = (const wxRect *) NULL ) = 0;
  790. // a less awkward wrapper for Refresh
  791. void RefreshRect(const wxRect& rect, bool eraseBackground = true)
  792. {
  793. Refresh(eraseBackground, &rect);
  794. }
  795. // repaint all invalid areas of the window immediately
  796. virtual void Update() { }
  797. // clear the window background
  798. virtual void ClearBackground();
  799. // freeze the window: don't redraw it until it is thawed
  800. void Freeze();
  801. // thaw the window: redraw it after it had been frozen
  802. void Thaw();
  803. // return true if window had been frozen and not unthawed yet
  804. bool IsFrozen() const { return m_freezeCount != 0; }
  805. // adjust DC for drawing on this window
  806. virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
  807. // return true if the window contents is double buffered by the system
  808. virtual bool IsDoubleBuffered() const { return false; }
  809. // the update region of the window contains the areas which must be
  810. // repainted by the program
  811. const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
  812. wxRegion& GetUpdateRegion() { return m_updateRegion; }
  813. // get the update rectangleregion bounding box in client coords
  814. wxRect GetUpdateClientRect() const;
  815. // these functions verify whether the given point/rectangle belongs to
  816. // (or at least intersects with) the update region
  817. virtual bool DoIsExposed( int x, int y ) const;
  818. virtual bool DoIsExposed( int x, int y, int w, int h ) const;
  819. bool IsExposed( int x, int y ) const
  820. { return DoIsExposed(x, y); }
  821. bool IsExposed( int x, int y, int w, int h ) const
  822. { return DoIsExposed(x, y, w, h); }
  823. bool IsExposed( const wxPoint& pt ) const
  824. { return DoIsExposed(pt.x, pt.y); }
  825. bool IsExposed( const wxRect& rect ) const
  826. { return DoIsExposed(rect.x, rect.y, rect.width, rect.height); }
  827. // colours, fonts and cursors
  828. // --------------------------
  829. // get the default attributes for the controls of this class: we
  830. // provide a virtual function which can be used to query the default
  831. // attributes of an existing control and a static function which can
  832. // be used even when no existing object of the given class is
  833. // available, but which won't return any styles specific to this
  834. // particular control, of course (e.g. "Ok" button might have
  835. // different -- bold for example -- font)
  836. virtual wxVisualAttributes GetDefaultAttributes() const
  837. {
  838. return GetClassDefaultAttributes(GetWindowVariant());
  839. }
  840. static wxVisualAttributes
  841. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  842. // set/retrieve the window colours (system defaults are used by
  843. // default): SetXXX() functions return true if colour was changed,
  844. // SetDefaultXXX() reset the "m_inheritXXX" flag after setting the
  845. // value to prevent it from being inherited by our children
  846. virtual bool SetBackgroundColour(const wxColour& colour);
  847. void SetOwnBackgroundColour(const wxColour& colour)
  848. {
  849. if ( SetBackgroundColour(colour) )
  850. m_inheritBgCol = false;
  851. }
  852. wxColour GetBackgroundColour() const;
  853. bool InheritsBackgroundColour() const
  854. {
  855. return m_inheritBgCol;
  856. }
  857. bool UseBgCol() const
  858. {
  859. return m_hasBgCol;
  860. }
  861. virtual bool SetForegroundColour(const wxColour& colour);
  862. void SetOwnForegroundColour(const wxColour& colour)
  863. {
  864. if ( SetForegroundColour(colour) )
  865. m_inheritFgCol = false;
  866. }
  867. wxColour GetForegroundColour() const;
  868. // Set/get the background style.
  869. virtual bool SetBackgroundStyle(wxBackgroundStyle style);
  870. wxBackgroundStyle GetBackgroundStyle() const
  871. { return m_backgroundStyle; }
  872. // returns true if the control has "transparent" areas such as a
  873. // wxStaticText and wxCheckBox and the background should be adapted
  874. // from a parent window
  875. virtual bool HasTransparentBackground() { return false; }
  876. // Returns true if background transparency is supported for this
  877. // window, i.e. if calling SetBackgroundStyle(wxBG_STYLE_TRANSPARENT)
  878. // has a chance of succeeding. If reason argument is non-NULL, returns a
  879. // user-readable explanation of why it isn't supported if the return
  880. // value is false.
  881. virtual bool IsTransparentBackgroundSupported(wxString* reason = NULL) const;
  882. // set/retrieve the font for the window (SetFont() returns true if the
  883. // font really changed)
  884. virtual bool SetFont(const wxFont& font) = 0;
  885. void SetOwnFont(const wxFont& font)
  886. {
  887. if ( SetFont(font) )
  888. m_inheritFont = false;
  889. }
  890. wxFont GetFont() const;
  891. // set/retrieve the cursor for this window (SetCursor() returns true
  892. // if the cursor was really changed)
  893. virtual bool SetCursor( const wxCursor &cursor );
  894. const wxCursor& GetCursor() const { return m_cursor; }
  895. #if wxUSE_CARET
  896. // associate a caret with the window
  897. void SetCaret(wxCaret *caret);
  898. // get the current caret (may be NULL)
  899. wxCaret *GetCaret() const { return m_caret; }
  900. #endif // wxUSE_CARET
  901. // get the (average) character size for the current font
  902. virtual int GetCharHeight() const = 0;
  903. virtual int GetCharWidth() const = 0;
  904. // get the width/height/... of the text using current or specified
  905. // font
  906. void GetTextExtent(const wxString& string,
  907. int *x, int *y,
  908. int *descent = NULL,
  909. int *externalLeading = NULL,
  910. const wxFont *font = NULL) const
  911. {
  912. DoGetTextExtent(string, x, y, descent, externalLeading, font);
  913. }
  914. wxSize GetTextExtent(const wxString& string) const
  915. {
  916. wxCoord w, h;
  917. GetTextExtent(string, &w, &h);
  918. return wxSize(w, h);
  919. }
  920. // client <-> screen coords
  921. // ------------------------
  922. // translate to/from screen/client coordinates (pointers may be NULL)
  923. void ClientToScreen( int *x, int *y ) const
  924. { DoClientToScreen(x, y); }
  925. void ScreenToClient( int *x, int *y ) const
  926. { DoScreenToClient(x, y); }
  927. // wxPoint interface to do the same thing
  928. wxPoint ClientToScreen(const wxPoint& pt) const
  929. {
  930. int x = pt.x, y = pt.y;
  931. DoClientToScreen(&x, &y);
  932. return wxPoint(x, y);
  933. }
  934. wxPoint ScreenToClient(const wxPoint& pt) const
  935. {
  936. int x = pt.x, y = pt.y;
  937. DoScreenToClient(&x, &y);
  938. return wxPoint(x, y);
  939. }
  940. // test where the given (in client coords) point lies
  941. wxHitTest HitTest(wxCoord x, wxCoord y) const
  942. { return DoHitTest(x, y); }
  943. wxHitTest HitTest(const wxPoint& pt) const
  944. { return DoHitTest(pt.x, pt.y); }
  945. // misc
  946. // ----
  947. // get the window border style from the given flags: this is different from
  948. // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
  949. // translate wxBORDER_DEFAULT to something reasonable
  950. wxBorder GetBorder(long flags) const;
  951. // get border for the flags of this window
  952. wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
  953. // send wxUpdateUIEvents to this window, and children if recurse is true
  954. virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
  955. // do the window-specific processing after processing the update event
  956. virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
  957. #if wxUSE_MENUS
  958. // show popup menu at the given position, generate events for the items
  959. // selected in it
  960. bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition)
  961. { return PopupMenu(menu, pos.x, pos.y); }
  962. bool PopupMenu(wxMenu *menu, int x, int y);
  963. // simply return the id of the selected item or wxID_NONE without
  964. // generating any events
  965. int GetPopupMenuSelectionFromUser(wxMenu& menu,
  966. const wxPoint& pos = wxDefaultPosition)
  967. { return DoGetPopupMenuSelectionFromUser(menu, pos.x, pos.y); }
  968. int GetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y)
  969. { return DoGetPopupMenuSelectionFromUser(menu, x, y); }
  970. #endif // wxUSE_MENUS
  971. // override this method to return true for controls having multiple pages
  972. virtual bool HasMultiplePages() const { return false; }
  973. // scrollbars
  974. // ----------
  975. // can the window have the scrollbar in this orientation?
  976. virtual bool CanScroll(int orient) const;
  977. // does the window have the scrollbar in this orientation?
  978. bool HasScrollbar(int orient) const;
  979. // configure the window scrollbars
  980. virtual void SetScrollbar( int orient,
  981. int pos,
  982. int thumbvisible,
  983. int range,
  984. bool refresh = true ) = 0;
  985. virtual void SetScrollPos( int orient, int pos, bool refresh = true ) = 0;
  986. virtual int GetScrollPos( int orient ) const = 0;
  987. virtual int GetScrollThumb( int orient ) const = 0;
  988. virtual int GetScrollRange( int orient ) const = 0;
  989. // scroll window to the specified position
  990. virtual void ScrollWindow( int dx, int dy,
  991. const wxRect* rect = NULL ) = 0;
  992. // scrolls window by line/page: note that not all controls support this
  993. //
  994. // return true if the position changed, false otherwise
  995. virtual bool ScrollLines(int WXUNUSED(lines)) { return false; }
  996. virtual bool ScrollPages(int WXUNUSED(pages)) { return false; }
  997. // convenient wrappers for ScrollLines/Pages
  998. bool LineUp() { return ScrollLines(-1); }
  999. bool LineDown() { return ScrollLines(1); }
  1000. bool PageUp() { return ScrollPages(-1); }
  1001. bool PageDown() { return ScrollPages(1); }
  1002. // call this to always show one or both scrollbars, even if the window
  1003. // is big enough to not require them
  1004. virtual void AlwaysShowScrollbars(bool WXUNUSED(horz) = true,
  1005. bool WXUNUSED(vert) = true)
  1006. {
  1007. }
  1008. // return true if AlwaysShowScrollbars() had been called before for the
  1009. // corresponding orientation
  1010. virtual bool IsScrollbarAlwaysShown(int WXUNUSED(orient)) const
  1011. {
  1012. return false;
  1013. }
  1014. // context-sensitive help
  1015. // ----------------------
  1016. // these are the convenience functions wrapping wxHelpProvider methods
  1017. #if wxUSE_HELP
  1018. // associate this help text with this window
  1019. void SetHelpText(const wxString& text);
  1020. #if WXWIN_COMPATIBILITY_2_8
  1021. // Associate this help text with all windows with the same id as this one.
  1022. // Don't use this, do wxHelpProvider::Get()->AddHelp(id, text);
  1023. wxDEPRECATED( void SetHelpTextForId(const wxString& text) );
  1024. #endif // WXWIN_COMPATIBILITY_2_8
  1025. // get the help string associated with the given position in this window
  1026. //
  1027. // notice that pt may be invalid if event origin is keyboard or unknown
  1028. // and this method should return the global window help text then
  1029. virtual wxString GetHelpTextAtPoint(const wxPoint& pt,
  1030. wxHelpEvent::Origin origin) const;
  1031. // returns the position-independent help text
  1032. wxString GetHelpText() const
  1033. {
  1034. return GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Unknown);
  1035. }
  1036. #else // !wxUSE_HELP
  1037. // silently ignore SetHelpText() calls
  1038. void SetHelpText(const wxString& WXUNUSED(text)) { }
  1039. void SetHelpTextForId(const wxString& WXUNUSED(text)) { }
  1040. #endif // wxUSE_HELP
  1041. // tooltips
  1042. // --------
  1043. #if wxUSE_TOOLTIPS
  1044. // the easiest way to set a tooltip for a window is to use this method
  1045. void SetToolTip( const wxString &tip );
  1046. // attach a tooltip to the window, pointer can be NULL to remove
  1047. // existing tooltip
  1048. void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
  1049. // more readable synonym for SetToolTip(NULL)
  1050. void UnsetToolTip() { SetToolTip(NULL); }
  1051. // get the associated tooltip or NULL if none
  1052. wxToolTip* GetToolTip() const { return m_tooltip; }
  1053. wxString GetToolTipText() const;
  1054. // Use the same tool tip as the given one (which can be NULL to indicate
  1055. // that no tooltip should be used) for this window. This is currently only
  1056. // used by wxCompositeWindow::DoSetToolTip() implementation and is not part
  1057. // of the public wx API.
  1058. //
  1059. // Returns true if tip was valid and we copied it or false if it was NULL
  1060. // and we reset our own tooltip too.
  1061. bool CopyToolTip(wxToolTip *tip);
  1062. #else // !wxUSE_TOOLTIPS
  1063. // make it much easier to compile apps in an environment
  1064. // that doesn't support tooltips, such as PocketPC
  1065. void SetToolTip(const wxString & WXUNUSED(tip)) { }
  1066. void UnsetToolTip() { }
  1067. #endif // wxUSE_TOOLTIPS/!wxUSE_TOOLTIPS
  1068. // drag and drop
  1069. // -------------
  1070. #if wxUSE_DRAG_AND_DROP
  1071. // set/retrieve the drop target associated with this window (may be
  1072. // NULL; it's owned by the window and will be deleted by it)
  1073. virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
  1074. virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
  1075. // Accept files for dragging
  1076. virtual void DragAcceptFiles(bool accept)
  1077. #ifdef __WXMSW__
  1078. // it does have common implementation but not for MSW which has its own
  1079. // native version of it
  1080. = 0
  1081. #endif // __WXMSW__
  1082. ;
  1083. #endif // wxUSE_DRAG_AND_DROP
  1084. // constraints and sizers
  1085. // ----------------------
  1086. #if wxUSE_CONSTRAINTS
  1087. // set the constraints for this window or retrieve them (may be NULL)
  1088. void SetConstraints( wxLayoutConstraints *constraints );
  1089. wxLayoutConstraints *GetConstraints() const { return m_constraints; }
  1090. // implementation only
  1091. void UnsetConstraints(wxLayoutConstraints *c);
  1092. wxWindowList *GetConstraintsInvolvedIn() const
  1093. { return m_constraintsInvolvedIn; }
  1094. void AddConstraintReference(wxWindowBase *otherWin);
  1095. void RemoveConstraintReference(wxWindowBase *otherWin);
  1096. void DeleteRelatedConstraints();
  1097. void ResetConstraints();
  1098. // these methods may be overridden for special layout algorithms
  1099. virtual void SetConstraintSizes(bool recurse = true);
  1100. virtual bool LayoutPhase1(int *noChanges);
  1101. virtual bool LayoutPhase2(int *noChanges);
  1102. virtual bool DoPhase(int phase);
  1103. // these methods are virtual but normally won't be overridden
  1104. virtual void SetSizeConstraint(int x, int y, int w, int h);
  1105. virtual void MoveConstraint(int x, int y);
  1106. virtual void GetSizeConstraint(int *w, int *h) const ;
  1107. virtual void GetClientSizeConstraint(int *w, int *h) const ;
  1108. virtual void GetPositionConstraint(int *x, int *y) const ;
  1109. #endif // wxUSE_CONSTRAINTS
  1110. // when using constraints or sizers, it makes sense to update
  1111. // children positions automatically whenever the window is resized
  1112. // - this is done if autoLayout is on
  1113. void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
  1114. bool GetAutoLayout() const { return m_autoLayout; }
  1115. // lay out the window and its children
  1116. virtual bool Layout();
  1117. // sizers
  1118. void SetSizer(wxSizer *sizer, bool deleteOld = true );
  1119. void SetSizerAndFit( wxSizer *sizer, bool deleteOld = true );
  1120. wxSizer *GetSizer() const { return m_windowSizer; }
  1121. // Track if this window is a member of a sizer
  1122. void SetContainingSizer(wxSizer* sizer);
  1123. wxSizer *GetContainingSizer() const { return m_containingSizer; }
  1124. // accessibility
  1125. // ----------------------
  1126. #if wxUSE_ACCESSIBILITY
  1127. // Override to create a specific accessible object.
  1128. virtual wxAccessible* CreateAccessible();
  1129. // Sets the accessible object.
  1130. void SetAccessible(wxAccessible* accessible) ;
  1131. // Returns the accessible object.
  1132. wxAccessible* GetAccessible() { return m_accessible; }
  1133. // Returns the accessible object, creating if necessary.
  1134. wxAccessible* GetOrCreateAccessible() ;
  1135. #endif
  1136. // Set window transparency if the platform supports it
  1137. virtual bool SetTransparent(wxByte WXUNUSED(alpha)) { return false; }
  1138. virtual bool CanSetTransparent() { return false; }
  1139. // implementation
  1140. // --------------
  1141. // event handlers
  1142. void OnSysColourChanged( wxSysColourChangedEvent& event );
  1143. void OnInitDialog( wxInitDialogEvent &event );
  1144. void OnMiddleClick( wxMouseEvent& event );
  1145. #if wxUSE_HELP
  1146. void OnHelp(wxHelpEvent& event);
  1147. #endif // wxUSE_HELP
  1148. // virtual function for implementing internal idle
  1149. // behaviour
  1150. virtual void OnInternalIdle();
  1151. // Send idle event to window and all subwindows
  1152. // Returns true if more idle time is requested.
  1153. virtual bool SendIdleEvents(wxIdleEvent& event);
  1154. // get the handle of the window for the underlying window system: this
  1155. // is only used for wxWin itself or for user code which wants to call
  1156. // platform-specific APIs
  1157. virtual WXWidget GetHandle() const = 0;
  1158. // associate the window with a new native handle
  1159. virtual void AssociateHandle(WXWidget WXUNUSED(handle)) { }
  1160. // dissociate the current native handle from the window
  1161. virtual void DissociateHandle() { }
  1162. #if wxUSE_PALETTE
  1163. // Store the palette used by DCs in wxWindow so that the dcs can share
  1164. // a palette. And we can respond to palette messages.
  1165. wxPalette GetPalette() const { return m_palette; }
  1166. // When palette is changed tell the DC to set the system palette to the
  1167. // new one.
  1168. void SetPalette(const wxPalette& pal);
  1169. // return true if we have a specific palette
  1170. bool HasCustomPalette() const { return m_hasCustomPalette; }
  1171. // return the first parent window with a custom palette or NULL
  1172. wxWindow *GetAncestorWithCustomPalette() const;
  1173. #endif // wxUSE_PALETTE
  1174. // inherit the parents visual attributes if they had been explicitly set
  1175. // by the user (i.e. we don't inherit default attributes) and if we don't
  1176. // have our own explicitly set
  1177. virtual void InheritAttributes();
  1178. // returns false from here if this window doesn't want to inherit the
  1179. // parents colours even if InheritAttributes() would normally do it
  1180. //
  1181. // this just provides a simple way to customize InheritAttributes()
  1182. // behaviour in the most common case
  1183. virtual bool ShouldInheritColours() const { return false; }
  1184. // returns true if the window can be positioned outside of parent's client
  1185. // area (normal windows can't, but e.g. menubar or statusbar can):
  1186. virtual bool CanBeOutsideClientArea() const { return false; }
  1187. // returns true if the platform should explicitly apply a theme border. Currently
  1188. // used only by Windows
  1189. virtual bool CanApplyThemeBorder() const { return true; }
  1190. // returns the main window of composite control; this is the window
  1191. // that FindFocus returns if the focus is in one of composite control's
  1192. // windows
  1193. virtual wxWindow *GetMainWindowOfCompositeControl()
  1194. { return (wxWindow*)this; }
  1195. // If this function returns true, keyboard navigation events shouldn't
  1196. // escape from it. A typical example of such "navigation domain" is a top
  1197. // level window because pressing TAB in one of them must not transfer focus
  1198. // to a different top level window. But it's not limited to them, e.g. MDI
  1199. // children frames are not top level windows (and their IsTopLevel()
  1200. // returns false) but still are self-contained navigation domains as well.
  1201. virtual bool IsTopNavigationDomain() const { return false; }
  1202. protected:
  1203. // helper for the derived class Create() methods: the first overload, with
  1204. // validator parameter, should be used for child windows while the second
  1205. // one is used for top level ones
  1206. bool CreateBase(wxWindowBase *parent,
  1207. wxWindowID winid,
  1208. const wxPoint& pos = wxDefaultPosition,
  1209. const wxSize& size = wxDefaultSize,
  1210. long style = 0,
  1211. const wxValidator& validator = wxDefaultValidator,
  1212. const wxString& name = wxPanelNameStr);
  1213. bool CreateBase(wxWindowBase *parent,
  1214. wxWindowID winid,
  1215. const wxPoint& pos,
  1216. const wxSize& size,
  1217. long style,
  1218. const wxString& name);
  1219. // event handling specific to wxWindow
  1220. virtual bool TryBefore(wxEvent& event);
  1221. virtual bool TryAfter(wxEvent& event);
  1222. enum WindowOrder
  1223. {
  1224. OrderBefore, // insert before the given window
  1225. OrderAfter // insert after the given window
  1226. };
  1227. // common part of GetPrev/NextSibling()
  1228. wxWindow *DoGetSibling(WindowOrder order) const;
  1229. // common part of MoveBefore/AfterInTabOrder()
  1230. virtual void DoMoveInTabOrder(wxWindow *win, WindowOrder move);
  1231. // implementation of Navigate() and NavigateIn()
  1232. virtual bool DoNavigateIn(int flags);
  1233. #if wxUSE_CONSTRAINTS
  1234. // satisfy the constraints for the windows but don't set the window sizes
  1235. void SatisfyConstraints();
  1236. #endif // wxUSE_CONSTRAINTS
  1237. // Send the wxWindowDestroyEvent if not done yet and sets m_isBeingDeleted
  1238. // to true
  1239. void SendDestroyEvent();
  1240. // this method should be implemented to use operating system specific code
  1241. // to really enable/disable the widget, it will only be called when we
  1242. // really need to enable/disable window and so no additional checks on the
  1243. // widgets state are necessary
  1244. virtual void DoEnable(bool WXUNUSED(enable)) { }
  1245. // the window id - a number which uniquely identifies a window among
  1246. // its siblings unless it is wxID_ANY
  1247. wxWindowIDRef m_windowId;
  1248. // the parent window of this window (or NULL) and the list of the children
  1249. // of this window
  1250. wxWindow *m_parent;
  1251. wxWindowList m_children;
  1252. // the minimal allowed size for the window (no minimal size if variable(s)
  1253. // contain(s) wxDefaultCoord)
  1254. int m_minWidth,
  1255. m_minHeight,
  1256. m_maxWidth,
  1257. m_maxHeight;
  1258. // event handler for this window: usually is just 'this' but may be
  1259. // changed with SetEventHandler()
  1260. wxEvtHandler *m_eventHandler;
  1261. #if wxUSE_VALIDATORS
  1262. // associated validator or NULL if none
  1263. wxValidator *m_windowValidator;
  1264. #endif // wxUSE_VALIDATORS
  1265. #if wxUSE_DRAG_AND_DROP
  1266. wxDropTarget *m_dropTarget;
  1267. #endif // wxUSE_DRAG_AND_DROP
  1268. // visual window attributes
  1269. wxCursor m_cursor;
  1270. wxFont m_font; // see m_hasFont
  1271. wxColour m_backgroundColour, // m_hasBgCol
  1272. m_foregroundColour; // m_hasFgCol
  1273. #if wxUSE_CARET
  1274. wxCaret *m_caret;
  1275. #endif // wxUSE_CARET
  1276. // the region which should be repainted in response to paint event
  1277. wxRegion m_updateRegion;
  1278. #if wxUSE_ACCEL
  1279. // the accelerator table for the window which translates key strokes into
  1280. // command events
  1281. wxAcceleratorTable m_acceleratorTable;
  1282. #endif // wxUSE_ACCEL
  1283. // the tooltip for this window (may be NULL)
  1284. #if wxUSE_TOOLTIPS
  1285. wxToolTip *m_tooltip;
  1286. #endif // wxUSE_TOOLTIPS
  1287. // constraints and sizers
  1288. #if wxUSE_CONSTRAINTS
  1289. // the constraints for this window or NULL
  1290. wxLayoutConstraints *m_constraints;
  1291. // constraints this window is involved in
  1292. wxWindowList *m_constraintsInvolvedIn;
  1293. #endif // wxUSE_CONSTRAINTS
  1294. // this window's sizer
  1295. wxSizer *m_windowSizer;
  1296. // The sizer this window is a member of, if any
  1297. wxSizer *m_containingSizer;
  1298. // Layout() window automatically when its size changes?
  1299. bool m_autoLayout:1;
  1300. // window state
  1301. bool m_isShown:1;
  1302. bool m_isEnabled:1;
  1303. bool m_isBeingDeleted:1;
  1304. // was the window colours/font explicitly changed by user?
  1305. bool m_hasBgCol:1;
  1306. bool m_hasFgCol:1;
  1307. bool m_hasFont:1;
  1308. // and should it be inherited by children?
  1309. bool m_inheritBgCol:1;
  1310. bool m_inheritFgCol:1;
  1311. bool m_inheritFont:1;
  1312. // window attributes
  1313. long m_windowStyle,
  1314. m_exStyle;
  1315. wxString m_windowName;
  1316. bool m_themeEnabled;
  1317. wxBackgroundStyle m_backgroundStyle;
  1318. #if wxUSE_PALETTE
  1319. wxPalette m_palette;
  1320. bool m_hasCustomPalette;
  1321. #endif // wxUSE_PALETTE
  1322. #if wxUSE_ACCESSIBILITY
  1323. wxAccessible* m_accessible;
  1324. #endif
  1325. // Virtual size (scrolling)
  1326. wxSize m_virtualSize;
  1327. wxScrollHelper *m_scrollHelper;
  1328. wxWindowVariant m_windowVariant ;
  1329. // override this to change the default (i.e. used when no style is
  1330. // specified) border for the window class
  1331. virtual wxBorder GetDefaultBorder() const;
  1332. // this allows you to implement standard control borders without
  1333. // repeating the code in different classes that are not derived from
  1334. // wxControl
  1335. virtual wxBorder GetDefaultBorderForControl() const { return wxBORDER_THEME; }
  1336. // Get the default size for the new window if no explicit size given. TLWs
  1337. // have their own default size so this is just for non top-level windows.
  1338. static int WidthDefault(int w) { return w == wxDefaultCoord ? 20 : w; }
  1339. static int HeightDefault(int h) { return h == wxDefaultCoord ? 20 : h; }
  1340. // Used to save the results of DoGetBestSize so it doesn't need to be
  1341. // recalculated each time the value is needed.
  1342. wxSize m_bestSizeCache;
  1343. wxDEPRECATED_MSG("use SetInitialSize() instead.")
  1344. void SetBestSize(const wxSize& size);
  1345. wxDEPRECATED_MSG("use SetInitialSize() instead.")
  1346. virtual void SetInitialBestSize(const wxSize& size);
  1347. // more pure virtual functions
  1348. // ---------------------------
  1349. // NB: we must have DoSomething() function when Something() is an overloaded
  1350. // method: indeed, we can't just have "virtual Something()" in case when
  1351. // the function is overloaded because then we'd have to make virtual all
  1352. // the variants (otherwise only the virtual function may be called on a
  1353. // pointer to derived class according to C++ rules) which is, in
  1354. // general, absolutely not needed. So instead we implement all
  1355. // overloaded Something()s in terms of DoSomething() which will be the
  1356. // only one to be virtual.
  1357. // text extent
  1358. virtual void DoGetTextExtent(const wxString& string,
  1359. int *x, int *y,
  1360. int *descent = NULL,
  1361. int *externalLeading = NULL,
  1362. const wxFont *font = NULL) const = 0;
  1363. // coordinates translation
  1364. virtual void DoClientToScreen( int *x, int *y ) const = 0;
  1365. virtual void DoScreenToClient( int *x, int *y ) const = 0;
  1366. virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
  1367. // capture/release the mouse, used by Capture/ReleaseMouse()
  1368. virtual void DoCaptureMouse() = 0;
  1369. virtual void DoReleaseMouse() = 0;
  1370. // retrieve the position/size of the window
  1371. virtual void DoGetPosition(int *x, int *y) const = 0;
  1372. virtual void DoGetScreenPosition(int *x, int *y) const;
  1373. virtual void DoGetSize(int *width, int *height) const = 0;
  1374. virtual void DoGetClientSize(int *width, int *height) const = 0;
  1375. // get the size which best suits the window: for a control, it would be
  1376. // the minimal size which doesn't truncate the control, for a panel - the
  1377. // same size as it would have after a call to Fit()
  1378. virtual wxSize DoGetBestSize() const;
  1379. // this method can be overridden instead of DoGetBestSize() if it computes
  1380. // the best size of the client area of the window only, excluding borders
  1381. // (GetBorderSize() will be used to add them)
  1382. virtual wxSize DoGetBestClientSize() const { return wxDefaultSize; }
  1383. // These two methods can be overridden to implement intelligent
  1384. // width-for-height and/or height-for-width best size determination for the
  1385. // window. By default the fixed best size is used.
  1386. virtual int DoGetBestClientHeight(int WXUNUSED(width)) const
  1387. { return wxDefaultCoord; }
  1388. virtual int DoGetBestClientWidth(int WXUNUSED(height)) const
  1389. { return wxDefaultCoord; }
  1390. // this is the virtual function to be overridden in any derived class which
  1391. // wants to change how SetSize() or Move() works - it is called by all
  1392. // versions of these functions in the base class
  1393. virtual void DoSetSize(int x, int y,
  1394. int width, int height,
  1395. int sizeFlags = wxSIZE_AUTO) = 0;
  1396. // same as DoSetSize() for the client size
  1397. virtual void DoSetClientSize(int width, int height) = 0;
  1398. virtual void DoSetSizeHints( int minW, int minH,
  1399. int maxW, int maxH,
  1400. int incW, int incH );
  1401. // return the total size of the window borders, i.e. the sum of the widths
  1402. // of the left and the right border in the x component of the returned size
  1403. // and the sum of the heights of the top and bottom borders in the y one
  1404. //
  1405. // NB: this is currently only implemented properly for wxMSW, wxGTK and
  1406. // wxUniv and doesn't behave correctly in the presence of scrollbars in
  1407. // the other ports
  1408. virtual wxSize DoGetBorderSize() const;
  1409. // move the window to the specified location and resize it: this is called
  1410. // from both DoSetSize() and DoSetClientSize() and would usually just
  1411. // reposition this window except for composite controls which will want to
  1412. // arrange themselves inside the given rectangle
  1413. //
  1414. // Important note: the coordinates passed to this method are in parent's
  1415. // *window* coordinates and not parent's client coordinates (as the values
  1416. // passed to DoSetSize and returned by DoGetPosition are)!
  1417. virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
  1418. // centre the window in the specified direction on parent, note that
  1419. // wxCENTRE_ON_SCREEN shouldn't be specified here, it only makes sense for
  1420. // TLWs
  1421. virtual void DoCentre(int dir);
  1422. #if wxUSE_TOOLTIPS
  1423. virtual void DoSetToolTip( wxToolTip *tip );
  1424. #endif // wxUSE_TOOLTIPS
  1425. #if wxUSE_MENUS
  1426. virtual bool DoPopupMenu(wxMenu *menu, int x, int y) = 0;
  1427. #endif // wxUSE_MENUS
  1428. // Makes an adjustment to the window position to make it relative to the
  1429. // parents client area, e.g. if the parent is a frame with a toolbar, its
  1430. // (0, 0) is just below the toolbar
  1431. virtual void AdjustForParentClientOrigin(int& x, int& y,
  1432. int sizeFlags = 0) const;
  1433. // implements the window variants
  1434. virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
  1435. // really freeze/thaw the window (should have port-specific implementation)
  1436. virtual void DoFreeze() { }
  1437. virtual void DoThaw() { }
  1438. // Must be called when mouse capture is lost to send
  1439. // wxMouseCaptureLostEvent to windows on capture stack.
  1440. static void NotifyCaptureLost();
  1441. private:
  1442. // recursively call our own and our children DoEnable() when the
  1443. // enabled/disabled status changed because a parent window had been
  1444. // enabled/disabled
  1445. void NotifyWindowOnEnableChange(bool enabled);
  1446. #if wxUSE_MENUS
  1447. // temporary event handlers used by GetPopupMenuSelectionFromUser()
  1448. void InternalOnPopupMenu(wxCommandEvent& event);
  1449. void InternalOnPopupMenuUpdate(wxUpdateUIEvent& event);
  1450. // implementation of the public GetPopupMenuSelectionFromUser() method
  1451. int DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y);
  1452. #endif // wxUSE_MENUS
  1453. // layout the window children when its size changes unless this was
  1454. // explicitly disabled with SetAutoLayout(false)
  1455. void InternalOnSize(wxSizeEvent& event);
  1456. // base for dialog unit conversion, i.e. average character size
  1457. wxSize GetDlgUnitBase() const;
  1458. // number of Freeze() calls minus the number of Thaw() calls: we're frozen
  1459. // (i.e. not being updated) if it is positive
  1460. unsigned int m_freezeCount;
  1461. DECLARE_ABSTRACT_CLASS(wxWindowBase)
  1462. wxDECLARE_NO_COPY_CLASS(wxWindowBase);
  1463. DECLARE_EVENT_TABLE()
  1464. };
  1465. // Inlines for some deprecated methods
  1466. inline wxSize wxWindowBase::GetBestFittingSize() const
  1467. {
  1468. return GetEffectiveMinSize();
  1469. }
  1470. inline void wxWindowBase::SetBestFittingSize(const wxSize& size)
  1471. {
  1472. SetInitialSize(size);
  1473. }
  1474. inline void wxWindowBase::SetBestSize(const wxSize& size)
  1475. {
  1476. SetInitialSize(size);
  1477. }
  1478. inline void wxWindowBase::SetInitialBestSize(const wxSize& size)
  1479. {
  1480. SetInitialSize(size);
  1481. }
  1482. // ----------------------------------------------------------------------------
  1483. // now include the declaration of wxWindow class
  1484. // ----------------------------------------------------------------------------
  1485. // include the declaration of the platform-specific class
  1486. #if defined(__WXMSW__)
  1487. #ifdef __WXUNIVERSAL__
  1488. #define wxWindowNative wxWindowMSW
  1489. #else // !wxUniv
  1490. #define wxWindowMSW wxWindow
  1491. #endif // wxUniv/!wxUniv
  1492. #include "wx/msw/window.h"
  1493. #elif defined(__WXMOTIF__)
  1494. #include "wx/motif/window.h"
  1495. #elif defined(__WXGTK20__)
  1496. #ifdef __WXUNIVERSAL__
  1497. #define wxWindowNative wxWindowGTK
  1498. #else // !wxUniv
  1499. #define wxWindowGTK wxWindow
  1500. #endif // wxUniv
  1501. #include "wx/gtk/window.h"
  1502. #elif defined(__WXGTK__)
  1503. #ifdef __WXUNIVERSAL__
  1504. #define wxWindowNative wxWindowGTK
  1505. #else // !wxUniv
  1506. #define wxWindowGTK wxWindow
  1507. #endif // wxUniv
  1508. #include "wx/gtk1/window.h"
  1509. #elif defined(__WXX11__)
  1510. #ifdef __WXUNIVERSAL__
  1511. #define wxWindowNative wxWindowX11
  1512. #else // !wxUniv
  1513. #define wxWindowX11 wxWindow
  1514. #endif // wxUniv
  1515. #include "wx/x11/window.h"
  1516. #elif defined(__WXDFB__)
  1517. #define wxWindowNative wxWindowDFB
  1518. #include "wx/dfb/window.h"
  1519. #elif defined(__WXMAC__)
  1520. #ifdef __WXUNIVERSAL__
  1521. #define wxWindowNative wxWindowMac
  1522. #else // !wxUniv
  1523. #define wxWindowMac wxWindow
  1524. #endif // wxUniv
  1525. #include "wx/osx/window.h"
  1526. #elif defined(__WXCOCOA__)
  1527. #ifdef __WXUNIVERSAL__
  1528. #define wxWindowNative wxWindowCocoa
  1529. #else // !wxUniv
  1530. #define wxWindowCocoa wxWindow
  1531. #endif // wxUniv
  1532. #include "wx/cocoa/window.h"
  1533. #elif defined(__WXPM__)
  1534. #ifdef __WXUNIVERSAL__
  1535. #define wxWindowNative wxWindowOS2
  1536. #else // !wxUniv
  1537. #define wxWindowOS2 wxWindow
  1538. #endif // wxUniv/!wxUniv
  1539. #include "wx/os2/window.h"
  1540. #endif
  1541. // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
  1542. // for the native ports we already have defined it above
  1543. #if defined(__WXUNIVERSAL__)
  1544. #ifndef wxWindowNative
  1545. #error "wxWindowNative must be defined above!"
  1546. #endif
  1547. #include "wx/univ/window.h"
  1548. #endif // wxUniv
  1549. // ----------------------------------------------------------------------------
  1550. // inline functions which couldn't be declared in the class body because of
  1551. // forward dependencies
  1552. // ----------------------------------------------------------------------------
  1553. inline wxWindow *wxWindowBase::GetGrandParent() const
  1554. {
  1555. return m_parent ? m_parent->GetParent() : NULL;
  1556. }
  1557. // ----------------------------------------------------------------------------
  1558. // global functions
  1559. // ----------------------------------------------------------------------------
  1560. // Find the wxWindow at the current mouse position, also returning the mouse
  1561. // position.
  1562. extern WXDLLIMPEXP_CORE wxWindow* wxFindWindowAtPointer(wxPoint& pt);
  1563. // Get the current mouse position.
  1564. extern WXDLLIMPEXP_CORE wxPoint wxGetMousePosition();
  1565. // get the currently active window of this application or NULL
  1566. extern WXDLLIMPEXP_CORE wxWindow *wxGetActiveWindow();
  1567. // get the (first) top level parent window
  1568. WXDLLIMPEXP_CORE wxWindow* wxGetTopLevelParent(wxWindow *win);
  1569. #if WXWIN_COMPATIBILITY_2_6
  1570. wxDEPRECATED_MSG("use wxWindow::NewControlId() instead")
  1571. inline wxWindowID NewControlId() { return wxWindowBase::NewControlId(); }
  1572. #endif // WXWIN_COMPATIBILITY_2_6
  1573. #if wxUSE_ACCESSIBILITY
  1574. // ----------------------------------------------------------------------------
  1575. // accessible object for windows
  1576. // ----------------------------------------------------------------------------
  1577. class WXDLLIMPEXP_CORE wxWindowAccessible: public wxAccessible
  1578. {
  1579. public:
  1580. wxWindowAccessible(wxWindow* win): wxAccessible(win) { if (win) win->SetAccessible(this); }
  1581. virtual ~wxWindowAccessible() {}
  1582. // Overridables
  1583. // Can return either a child object, or an integer
  1584. // representing the child element, starting from 1.
  1585. virtual wxAccStatus HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject);
  1586. // Returns the rectangle for this object (id = 0) or a child element (id > 0).
  1587. virtual wxAccStatus GetLocation(wxRect& rect, int elementId);
  1588. // Navigates from fromId to toId/toObject.
  1589. virtual wxAccStatus Navigate(wxNavDir navDir, int fromId,
  1590. int* toId, wxAccessible** toObject);
  1591. // Gets the name of the specified object.
  1592. virtual wxAccStatus GetName(int childId, wxString* name);
  1593. // Gets the number of children.
  1594. virtual wxAccStatus GetChildCount(int* childCount);
  1595. // Gets the specified child (starting from 1).
  1596. // If *child is NULL and return value is wxACC_OK,
  1597. // this means that the child is a simple element and
  1598. // not an accessible object.
  1599. virtual wxAccStatus GetChild(int childId, wxAccessible** child);
  1600. // Gets the parent, or NULL.
  1601. virtual wxAccStatus GetParent(wxAccessible** parent);
  1602. // Performs the default action. childId is 0 (the action for this object)
  1603. // or > 0 (the action for a child).
  1604. // Return wxACC_NOT_SUPPORTED if there is no default action for this
  1605. // window (e.g. an edit control).
  1606. virtual wxAccStatus DoDefaultAction(int childId);
  1607. // Gets the default action for this object (0) or > 0 (the action for a child).
  1608. // Return wxACC_OK even if there is no action. actionName is the action, or the empty
  1609. // string if there is no action.
  1610. // The retrieved string describes the action that is performed on an object,
  1611. // not what the object does as a result. For example, a toolbar button that prints
  1612. // a document has a default action of "Press" rather than "Prints the current document."
  1613. virtual wxAccStatus GetDefaultAction(int childId, wxString* actionName);
  1614. // Returns the description for this object or a child.
  1615. virtual wxAccStatus GetDescription(int childId, wxString* description);
  1616. // Returns help text for this object or a child, similar to tooltip text.
  1617. virtual wxAccStatus GetHelpText(int childId, wxString* helpText);
  1618. // Returns the keyboard shortcut for this object or child.
  1619. // Return e.g. ALT+K
  1620. virtual wxAccStatus GetKeyboardShortcut(int childId, wxString* shortcut);
  1621. // Returns a role constant.
  1622. virtual wxAccStatus GetRole(int childId, wxAccRole* role);
  1623. // Returns a state constant.
  1624. virtual wxAccStatus GetState(int childId, long* state);
  1625. // Returns a localized string representing the value for the object
  1626. // or child.
  1627. virtual wxAccStatus GetValue(int childId, wxString* strValue);
  1628. // Selects the object or child.
  1629. virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags);
  1630. // Gets the window with the keyboard focus.
  1631. // If childId is 0 and child is NULL, no object in
  1632. // this subhierarchy has the focus.
  1633. // If this object has the focus, child should be 'this'.
  1634. virtual wxAccStatus GetFocus(int* childId, wxAccessible** child);
  1635. #if wxUSE_VARIANT
  1636. // Gets a variant representing the selected children
  1637. // of this object.
  1638. // Acceptable values:
  1639. // - a null variant (IsNull() returns true)
  1640. // - a list variant (GetType() == wxT("list")
  1641. // - an integer representing the selected child element,
  1642. // or 0 if this object is selected (GetType() == wxT("long")
  1643. // - a "void*" pointer to a wxAccessible child object
  1644. virtual wxAccStatus GetSelections(wxVariant* selections);
  1645. #endif // wxUSE_VARIANT
  1646. };
  1647. #endif // wxUSE_ACCESSIBILITY
  1648. #endif // _WX_WINDOW_H_BASE_