gdicmn.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gdicmn.h
  3. // Purpose: Common GDI classes, types and declarations
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GDICMNH__
  11. #define _WX_GDICMNH__
  12. // ---------------------------------------------------------------------------
  13. // headers
  14. // ---------------------------------------------------------------------------
  15. #include "wx/defs.h"
  16. #include "wx/list.h"
  17. #include "wx/string.h"
  18. #include "wx/fontenc.h"
  19. #include "wx/hashmap.h"
  20. #include "wx/math.h"
  21. // ---------------------------------------------------------------------------
  22. // forward declarations
  23. // ---------------------------------------------------------------------------
  24. class WXDLLIMPEXP_FWD_CORE wxBitmap;
  25. class WXDLLIMPEXP_FWD_CORE wxBrush;
  26. class WXDLLIMPEXP_FWD_CORE wxColour;
  27. class WXDLLIMPEXP_FWD_CORE wxCursor;
  28. class WXDLLIMPEXP_FWD_CORE wxFont;
  29. class WXDLLIMPEXP_FWD_CORE wxIcon;
  30. class WXDLLIMPEXP_FWD_CORE wxPalette;
  31. class WXDLLIMPEXP_FWD_CORE wxPen;
  32. class WXDLLIMPEXP_FWD_CORE wxRegion;
  33. class WXDLLIMPEXP_FWD_BASE wxString;
  34. class WXDLLIMPEXP_FWD_CORE wxIconBundle;
  35. class WXDLLIMPEXP_FWD_CORE wxPoint;
  36. // ---------------------------------------------------------------------------
  37. // constants
  38. // ---------------------------------------------------------------------------
  39. // Bitmap flags
  40. enum wxBitmapType
  41. {
  42. wxBITMAP_TYPE_INVALID, // should be == 0 for compatibility!
  43. wxBITMAP_TYPE_BMP,
  44. wxBITMAP_TYPE_BMP_RESOURCE,
  45. wxBITMAP_TYPE_RESOURCE = wxBITMAP_TYPE_BMP_RESOURCE,
  46. wxBITMAP_TYPE_ICO,
  47. wxBITMAP_TYPE_ICO_RESOURCE,
  48. wxBITMAP_TYPE_CUR,
  49. wxBITMAP_TYPE_CUR_RESOURCE,
  50. wxBITMAP_TYPE_XBM,
  51. wxBITMAP_TYPE_XBM_DATA,
  52. wxBITMAP_TYPE_XPM,
  53. wxBITMAP_TYPE_XPM_DATA,
  54. wxBITMAP_TYPE_TIFF,
  55. wxBITMAP_TYPE_TIF = wxBITMAP_TYPE_TIFF,
  56. wxBITMAP_TYPE_TIFF_RESOURCE,
  57. wxBITMAP_TYPE_TIF_RESOURCE = wxBITMAP_TYPE_TIFF_RESOURCE,
  58. wxBITMAP_TYPE_GIF,
  59. wxBITMAP_TYPE_GIF_RESOURCE,
  60. wxBITMAP_TYPE_PNG,
  61. wxBITMAP_TYPE_PNG_RESOURCE,
  62. wxBITMAP_TYPE_JPEG,
  63. wxBITMAP_TYPE_JPEG_RESOURCE,
  64. wxBITMAP_TYPE_PNM,
  65. wxBITMAP_TYPE_PNM_RESOURCE,
  66. wxBITMAP_TYPE_PCX,
  67. wxBITMAP_TYPE_PCX_RESOURCE,
  68. wxBITMAP_TYPE_PICT,
  69. wxBITMAP_TYPE_PICT_RESOURCE,
  70. wxBITMAP_TYPE_ICON,
  71. wxBITMAP_TYPE_ICON_RESOURCE,
  72. wxBITMAP_TYPE_ANI,
  73. wxBITMAP_TYPE_IFF,
  74. wxBITMAP_TYPE_TGA,
  75. wxBITMAP_TYPE_MACCURSOR,
  76. wxBITMAP_TYPE_MACCURSOR_RESOURCE,
  77. wxBITMAP_TYPE_MAX,
  78. wxBITMAP_TYPE_ANY = 50
  79. };
  80. // Polygon filling mode
  81. enum wxPolygonFillMode
  82. {
  83. wxODDEVEN_RULE = 1,
  84. wxWINDING_RULE
  85. };
  86. // Standard cursors
  87. enum wxStockCursor
  88. {
  89. wxCURSOR_NONE, // should be 0
  90. wxCURSOR_ARROW,
  91. wxCURSOR_RIGHT_ARROW,
  92. wxCURSOR_BULLSEYE,
  93. wxCURSOR_CHAR,
  94. wxCURSOR_CROSS,
  95. wxCURSOR_HAND,
  96. wxCURSOR_IBEAM,
  97. wxCURSOR_LEFT_BUTTON,
  98. wxCURSOR_MAGNIFIER,
  99. wxCURSOR_MIDDLE_BUTTON,
  100. wxCURSOR_NO_ENTRY,
  101. wxCURSOR_PAINT_BRUSH,
  102. wxCURSOR_PENCIL,
  103. wxCURSOR_POINT_LEFT,
  104. wxCURSOR_POINT_RIGHT,
  105. wxCURSOR_QUESTION_ARROW,
  106. wxCURSOR_RIGHT_BUTTON,
  107. wxCURSOR_SIZENESW,
  108. wxCURSOR_SIZENS,
  109. wxCURSOR_SIZENWSE,
  110. wxCURSOR_SIZEWE,
  111. wxCURSOR_SIZING,
  112. wxCURSOR_SPRAYCAN,
  113. wxCURSOR_WAIT,
  114. wxCURSOR_WATCH,
  115. wxCURSOR_BLANK,
  116. #ifdef __WXGTK__
  117. wxCURSOR_DEFAULT, // standard X11 cursor
  118. #endif
  119. #ifdef __WXMAC__
  120. wxCURSOR_COPY_ARROW , // MacOS Theme Plus arrow
  121. #endif
  122. #ifdef __X__
  123. // Not yet implemented for Windows
  124. wxCURSOR_CROSS_REVERSE,
  125. wxCURSOR_DOUBLE_ARROW,
  126. wxCURSOR_BASED_ARROW_UP,
  127. wxCURSOR_BASED_ARROW_DOWN,
  128. #endif // X11
  129. wxCURSOR_ARROWWAIT,
  130. #ifdef __WXMAC__
  131. wxCURSOR_OPEN_HAND,
  132. wxCURSOR_CLOSED_HAND,
  133. #endif
  134. wxCURSOR_MAX
  135. };
  136. #ifndef __WXGTK__
  137. #define wxCURSOR_DEFAULT wxCURSOR_ARROW
  138. #endif
  139. #ifndef __WXMAC__
  140. // TODO CS supply openhand and closedhand cursors
  141. #define wxCURSOR_OPEN_HAND wxCURSOR_HAND
  142. #define wxCURSOR_CLOSED_HAND wxCURSOR_HAND
  143. #endif
  144. // ---------------------------------------------------------------------------
  145. // macros
  146. // ---------------------------------------------------------------------------
  147. #if defined(__WINDOWS__) || defined(__WXPM__)
  148. #define wxHAS_IMAGES_IN_RESOURCES
  149. #endif
  150. /* Useful macro for creating icons portably, for example:
  151. wxIcon *icon = new wxICON(sample);
  152. expands into:
  153. wxIcon *icon = new wxIcon("sample"); // On Windows
  154. wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
  155. */
  156. #ifdef __WINDOWS__
  157. // Load from a resource
  158. #define wxICON(X) wxIcon(wxT(#X))
  159. #elif defined(__WXPM__)
  160. // Load from a resource
  161. #define wxICON(X) wxIcon(wxT(#X))
  162. #elif defined(__WXDFB__)
  163. // Initialize from an included XPM
  164. #define wxICON(X) wxIcon( X##_xpm )
  165. #elif defined(__WXGTK__)
  166. // Initialize from an included XPM
  167. #define wxICON(X) wxIcon( X##_xpm )
  168. #elif defined(__WXMAC__)
  169. // Initialize from an included XPM
  170. #define wxICON(X) wxIcon( X##_xpm )
  171. #elif defined(__WXMOTIF__)
  172. // Initialize from an included XPM
  173. #define wxICON(X) wxIcon( X##_xpm )
  174. #elif defined(__WXX11__)
  175. // Initialize from an included XPM
  176. #define wxICON(X) wxIcon( X##_xpm )
  177. #else
  178. // This will usually mean something on any platform
  179. #define wxICON(X) wxIcon(wxT(#X))
  180. #endif // platform
  181. /* Another macro: this one is for portable creation of bitmaps. We assume that
  182. under Unix bitmaps live in XPMs and under Windows they're in ressources.
  183. */
  184. #if defined(__WINDOWS__) || defined(__WXPM__)
  185. #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_BMP_RESOURCE)
  186. #elif defined(__WXGTK__) || \
  187. defined(__WXMOTIF__) || \
  188. defined(__WXX11__) || \
  189. defined(__WXMAC__) || \
  190. defined(__WXDFB__) || \
  191. defined(__WXCOCOA__)
  192. // Initialize from an included XPM
  193. #define wxBITMAP(name) wxBitmap(name##_xpm)
  194. #else // other platforms
  195. #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM)
  196. #endif // platform
  197. // Macro for creating wxBitmap from in-memory PNG data.
  198. //
  199. // It reads PNG data from name_png static byte arrays that can be created using
  200. // e.g. misc/scripts/png2c.py.
  201. //
  202. // This macro exists mostly as a helper for wxBITMAP_PNG() below but also
  203. // because it's slightly more convenient to use than NewFromPNGData() directly.
  204. #define wxBITMAP_PNG_FROM_DATA(name) \
  205. wxBitmap::NewFromPNGData(name##_png, WXSIZEOF(name##_png))
  206. // Similar to wxBITMAP but used for the bitmaps in PNG format.
  207. //
  208. // Under Windows they should be embedded into the resource file using RT_RCDATA
  209. // resource type and under OS X the PNG file with the specified name must be
  210. // available in the resource subdirectory of the bundle. Elsewhere, this is
  211. // exactly the same thing as wxBITMAP_PNG_FROM_DATA() described above.
  212. #if defined(__WINDOWS__) || defined(__WXOSX__)
  213. #define wxBITMAP_PNG(name) wxBitmap(wxS(#name), wxBITMAP_TYPE_PNG_RESOURCE)
  214. #else
  215. #define wxBITMAP_PNG(name) wxBITMAP_PNG_FROM_DATA(name)
  216. #endif
  217. // ===========================================================================
  218. // classes
  219. // ===========================================================================
  220. // ---------------------------------------------------------------------------
  221. // wxSize
  222. // ---------------------------------------------------------------------------
  223. class WXDLLIMPEXP_CORE wxSize
  224. {
  225. public:
  226. // members are public for compatibility, don't use them directly.
  227. int x, y;
  228. // constructors
  229. wxSize() : x(0), y(0) { }
  230. wxSize(int xx, int yy) : x(xx), y(yy) { }
  231. // no copy ctor or assignment operator - the defaults are ok
  232. wxSize& operator+=(const wxSize& sz) { x += sz.x; y += sz.y; return *this; }
  233. wxSize& operator-=(const wxSize& sz) { x -= sz.x; y -= sz.y; return *this; }
  234. wxSize& operator/=(int i) { x /= i; y /= i; return *this; }
  235. wxSize& operator*=(int i) { x *= i; y *= i; return *this; }
  236. wxSize& operator/=(unsigned int i) { x /= i; y /= i; return *this; }
  237. wxSize& operator*=(unsigned int i) { x *= i; y *= i; return *this; }
  238. wxSize& operator/=(long i) { x /= i; y /= i; return *this; }
  239. wxSize& operator*=(long i) { x *= i; y *= i; return *this; }
  240. wxSize& operator/=(unsigned long i) { x /= i; y /= i; return *this; }
  241. wxSize& operator*=(unsigned long i) { x *= i; y *= i; return *this; }
  242. wxSize& operator/=(double i) { x = int(x/i); y = int(y/i); return *this; }
  243. wxSize& operator*=(double i) { x = int(x*i); y = int(y*i); return *this; }
  244. void IncTo(const wxSize& sz)
  245. { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; }
  246. void DecTo(const wxSize& sz)
  247. { if ( sz.x < x ) x = sz.x; if ( sz.y < y ) y = sz.y; }
  248. void DecToIfSpecified(const wxSize& sz)
  249. {
  250. if ( sz.x != wxDefaultCoord && sz.x < x )
  251. x = sz.x;
  252. if ( sz.y != wxDefaultCoord && sz.y < y )
  253. y = sz.y;
  254. }
  255. void IncBy(int dx, int dy) { x += dx; y += dy; }
  256. void IncBy(const wxPoint& pt);
  257. void IncBy(const wxSize& sz) { IncBy(sz.x, sz.y); }
  258. void IncBy(int d) { IncBy(d, d); }
  259. void DecBy(int dx, int dy) { IncBy(-dx, -dy); }
  260. void DecBy(const wxPoint& pt);
  261. void DecBy(const wxSize& sz) { DecBy(sz.x, sz.y); }
  262. void DecBy(int d) { DecBy(d, d); }
  263. wxSize& Scale(float xscale, float yscale)
  264. { x = (int)(x*xscale); y = (int)(y*yscale); return *this; }
  265. // accessors
  266. void Set(int xx, int yy) { x = xx; y = yy; }
  267. void SetWidth(int w) { x = w; }
  268. void SetHeight(int h) { y = h; }
  269. int GetWidth() const { return x; }
  270. int GetHeight() const { return y; }
  271. bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; }
  272. // combine this size with the other one replacing the default (i.e. equal
  273. // to wxDefaultCoord) components of this object with those of the other
  274. void SetDefaults(const wxSize& size)
  275. {
  276. if ( x == wxDefaultCoord )
  277. x = size.x;
  278. if ( y == wxDefaultCoord )
  279. y = size.y;
  280. }
  281. // compatibility
  282. int GetX() const { return x; }
  283. int GetY() const { return y; }
  284. };
  285. inline bool operator==(const wxSize& s1, const wxSize& s2)
  286. {
  287. return s1.x == s2.x && s1.y == s2.y;
  288. }
  289. inline bool operator!=(const wxSize& s1, const wxSize& s2)
  290. {
  291. return s1.x != s2.x || s1.y != s2.y;
  292. }
  293. inline wxSize operator+(const wxSize& s1, const wxSize& s2)
  294. {
  295. return wxSize(s1.x + s2.x, s1.y + s2.y);
  296. }
  297. inline wxSize operator-(const wxSize& s1, const wxSize& s2)
  298. {
  299. return wxSize(s1.x - s2.x, s1.y - s2.y);
  300. }
  301. inline wxSize operator/(const wxSize& s, int i)
  302. {
  303. return wxSize(s.x / i, s.y / i);
  304. }
  305. inline wxSize operator*(const wxSize& s, int i)
  306. {
  307. return wxSize(s.x * i, s.y * i);
  308. }
  309. inline wxSize operator*(int i, const wxSize& s)
  310. {
  311. return wxSize(s.x * i, s.y * i);
  312. }
  313. inline wxSize operator/(const wxSize& s, unsigned int i)
  314. {
  315. return wxSize(s.x / i, s.y / i);
  316. }
  317. inline wxSize operator*(const wxSize& s, unsigned int i)
  318. {
  319. return wxSize(s.x * i, s.y * i);
  320. }
  321. inline wxSize operator*(unsigned int i, const wxSize& s)
  322. {
  323. return wxSize(s.x * i, s.y * i);
  324. }
  325. inline wxSize operator/(const wxSize& s, long i)
  326. {
  327. return wxSize(s.x / i, s.y / i);
  328. }
  329. inline wxSize operator*(const wxSize& s, long i)
  330. {
  331. return wxSize(int(s.x * i), int(s.y * i));
  332. }
  333. inline wxSize operator*(long i, const wxSize& s)
  334. {
  335. return wxSize(int(s.x * i), int(s.y * i));
  336. }
  337. inline wxSize operator/(const wxSize& s, unsigned long i)
  338. {
  339. return wxSize(int(s.x / i), int(s.y / i));
  340. }
  341. inline wxSize operator*(const wxSize& s, unsigned long i)
  342. {
  343. return wxSize(int(s.x * i), int(s.y * i));
  344. }
  345. inline wxSize operator*(unsigned long i, const wxSize& s)
  346. {
  347. return wxSize(int(s.x * i), int(s.y * i));
  348. }
  349. inline wxSize operator*(const wxSize& s, double i)
  350. {
  351. return wxSize(int(s.x * i), int(s.y * i));
  352. }
  353. inline wxSize operator*(double i, const wxSize& s)
  354. {
  355. return wxSize(int(s.x * i), int(s.y * i));
  356. }
  357. // ---------------------------------------------------------------------------
  358. // Point classes: with real or integer coordinates
  359. // ---------------------------------------------------------------------------
  360. class WXDLLIMPEXP_CORE wxRealPoint
  361. {
  362. public:
  363. double x;
  364. double y;
  365. wxRealPoint() : x(0.0), y(0.0) { }
  366. wxRealPoint(double xx, double yy) : x(xx), y(yy) { }
  367. wxRealPoint(const wxPoint& pt);
  368. // no copy ctor or assignment operator - the defaults are ok
  369. //assignment operators
  370. wxRealPoint& operator+=(const wxRealPoint& p) { x += p.x; y += p.y; return *this; }
  371. wxRealPoint& operator-=(const wxRealPoint& p) { x -= p.x; y -= p.y; return *this; }
  372. wxRealPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; }
  373. wxRealPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; }
  374. };
  375. inline bool operator==(const wxRealPoint& p1, const wxRealPoint& p2)
  376. {
  377. return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y);
  378. }
  379. inline bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2)
  380. {
  381. return !(p1 == p2);
  382. }
  383. inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2)
  384. {
  385. return wxRealPoint(p1.x + p2.x, p1.y + p2.y);
  386. }
  387. inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2)
  388. {
  389. return wxRealPoint(p1.x - p2.x, p1.y - p2.y);
  390. }
  391. inline wxRealPoint operator/(const wxRealPoint& s, int i)
  392. {
  393. return wxRealPoint(s.x / i, s.y / i);
  394. }
  395. inline wxRealPoint operator*(const wxRealPoint& s, int i)
  396. {
  397. return wxRealPoint(s.x * i, s.y * i);
  398. }
  399. inline wxRealPoint operator*(int i, const wxRealPoint& s)
  400. {
  401. return wxRealPoint(s.x * i, s.y * i);
  402. }
  403. inline wxRealPoint operator/(const wxRealPoint& s, unsigned int i)
  404. {
  405. return wxRealPoint(s.x / i, s.y / i);
  406. }
  407. inline wxRealPoint operator*(const wxRealPoint& s, unsigned int i)
  408. {
  409. return wxRealPoint(s.x * i, s.y * i);
  410. }
  411. inline wxRealPoint operator*(unsigned int i, const wxRealPoint& s)
  412. {
  413. return wxRealPoint(s.x * i, s.y * i);
  414. }
  415. inline wxRealPoint operator/(const wxRealPoint& s, long i)
  416. {
  417. return wxRealPoint(s.x / i, s.y / i);
  418. }
  419. inline wxRealPoint operator*(const wxRealPoint& s, long i)
  420. {
  421. return wxRealPoint(s.x * i, s.y * i);
  422. }
  423. inline wxRealPoint operator*(long i, const wxRealPoint& s)
  424. {
  425. return wxRealPoint(s.x * i, s.y * i);
  426. }
  427. inline wxRealPoint operator/(const wxRealPoint& s, unsigned long i)
  428. {
  429. return wxRealPoint(s.x / i, s.y / i);
  430. }
  431. inline wxRealPoint operator*(const wxRealPoint& s, unsigned long i)
  432. {
  433. return wxRealPoint(s.x * i, s.y * i);
  434. }
  435. inline wxRealPoint operator*(unsigned long i, const wxRealPoint& s)
  436. {
  437. return wxRealPoint(s.x * i, s.y * i);
  438. }
  439. inline wxRealPoint operator*(const wxRealPoint& s, double i)
  440. {
  441. return wxRealPoint(int(s.x * i), int(s.y * i));
  442. }
  443. inline wxRealPoint operator*(double i, const wxRealPoint& s)
  444. {
  445. return wxRealPoint(int(s.x * i), int(s.y * i));
  446. }
  447. // ----------------------------------------------------------------------------
  448. // wxPoint: 2D point with integer coordinates
  449. // ----------------------------------------------------------------------------
  450. class WXDLLIMPEXP_CORE wxPoint
  451. {
  452. public:
  453. int x, y;
  454. wxPoint() : x(0), y(0) { }
  455. wxPoint(int xx, int yy) : x(xx), y(yy) { }
  456. wxPoint(const wxRealPoint& pt) : x(int(pt.x)), y(int(pt.y)) { }
  457. // no copy ctor or assignment operator - the defaults are ok
  458. //assignment operators
  459. wxPoint& operator+=(const wxPoint& p) { x += p.x; y += p.y; return *this; }
  460. wxPoint& operator-=(const wxPoint& p) { x -= p.x; y -= p.y; return *this; }
  461. wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; }
  462. wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; }
  463. // check if both components are set/initialized
  464. bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; }
  465. // fill in the unset components with the values from the other point
  466. void SetDefaults(const wxPoint& pt)
  467. {
  468. if ( x == wxDefaultCoord )
  469. x = pt.x;
  470. if ( y == wxDefaultCoord )
  471. y = pt.y;
  472. }
  473. };
  474. // comparison
  475. inline bool operator==(const wxPoint& p1, const wxPoint& p2)
  476. {
  477. return p1.x == p2.x && p1.y == p2.y;
  478. }
  479. inline bool operator!=(const wxPoint& p1, const wxPoint& p2)
  480. {
  481. return !(p1 == p2);
  482. }
  483. // arithmetic operations (component wise)
  484. inline wxPoint operator+(const wxPoint& p1, const wxPoint& p2)
  485. {
  486. return wxPoint(p1.x + p2.x, p1.y + p2.y);
  487. }
  488. inline wxPoint operator-(const wxPoint& p1, const wxPoint& p2)
  489. {
  490. return wxPoint(p1.x - p2.x, p1.y - p2.y);
  491. }
  492. inline wxPoint operator+(const wxPoint& p, const wxSize& s)
  493. {
  494. return wxPoint(p.x + s.x, p.y + s.y);
  495. }
  496. inline wxPoint operator-(const wxPoint& p, const wxSize& s)
  497. {
  498. return wxPoint(p.x - s.x, p.y - s.y);
  499. }
  500. inline wxPoint operator+(const wxSize& s, const wxPoint& p)
  501. {
  502. return wxPoint(p.x + s.x, p.y + s.y);
  503. }
  504. inline wxPoint operator-(const wxSize& s, const wxPoint& p)
  505. {
  506. return wxPoint(s.x - p.x, s.y - p.y);
  507. }
  508. inline wxPoint operator-(const wxPoint& p)
  509. {
  510. return wxPoint(-p.x, -p.y);
  511. }
  512. inline wxPoint operator/(const wxPoint& s, int i)
  513. {
  514. return wxPoint(s.x / i, s.y / i);
  515. }
  516. inline wxPoint operator*(const wxPoint& s, int i)
  517. {
  518. return wxPoint(s.x * i, s.y * i);
  519. }
  520. inline wxPoint operator*(int i, const wxPoint& s)
  521. {
  522. return wxPoint(s.x * i, s.y * i);
  523. }
  524. inline wxPoint operator/(const wxPoint& s, unsigned int i)
  525. {
  526. return wxPoint(s.x / i, s.y / i);
  527. }
  528. inline wxPoint operator*(const wxPoint& s, unsigned int i)
  529. {
  530. return wxPoint(s.x * i, s.y * i);
  531. }
  532. inline wxPoint operator*(unsigned int i, const wxPoint& s)
  533. {
  534. return wxPoint(s.x * i, s.y * i);
  535. }
  536. inline wxPoint operator/(const wxPoint& s, long i)
  537. {
  538. return wxPoint(s.x / i, s.y / i);
  539. }
  540. inline wxPoint operator*(const wxPoint& s, long i)
  541. {
  542. return wxPoint(int(s.x * i), int(s.y * i));
  543. }
  544. inline wxPoint operator*(long i, const wxPoint& s)
  545. {
  546. return wxPoint(int(s.x * i), int(s.y * i));
  547. }
  548. inline wxPoint operator/(const wxPoint& s, unsigned long i)
  549. {
  550. return wxPoint(s.x / i, s.y / i);
  551. }
  552. inline wxPoint operator*(const wxPoint& s, unsigned long i)
  553. {
  554. return wxPoint(int(s.x * i), int(s.y * i));
  555. }
  556. inline wxPoint operator*(unsigned long i, const wxPoint& s)
  557. {
  558. return wxPoint(int(s.x * i), int(s.y * i));
  559. }
  560. inline wxPoint operator*(const wxPoint& s, double i)
  561. {
  562. return wxPoint(int(s.x * i), int(s.y * i));
  563. }
  564. inline wxPoint operator*(double i, const wxPoint& s)
  565. {
  566. return wxPoint(int(s.x * i), int(s.y * i));
  567. }
  568. WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE);
  569. // ---------------------------------------------------------------------------
  570. // wxRect
  571. // ---------------------------------------------------------------------------
  572. class WXDLLIMPEXP_CORE wxRect
  573. {
  574. public:
  575. wxRect()
  576. : x(0), y(0), width(0), height(0)
  577. { }
  578. wxRect(int xx, int yy, int ww, int hh)
  579. : x(xx), y(yy), width(ww), height(hh)
  580. { }
  581. wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
  582. wxRect(const wxPoint& pt, const wxSize& size)
  583. : x(pt.x), y(pt.y), width(size.x), height(size.y)
  584. { }
  585. wxRect(const wxSize& size)
  586. : x(0), y(0), width(size.x), height(size.y)
  587. { }
  588. // default copy ctor and assignment operators ok
  589. int GetX() const { return x; }
  590. void SetX(int xx) { x = xx; }
  591. int GetY() const { return y; }
  592. void SetY(int yy) { y = yy; }
  593. int GetWidth() const { return width; }
  594. void SetWidth(int w) { width = w; }
  595. int GetHeight() const { return height; }
  596. void SetHeight(int h) { height = h; }
  597. wxPoint GetPosition() const { return wxPoint(x, y); }
  598. void SetPosition( const wxPoint &p ) { x = p.x; y = p.y; }
  599. wxSize GetSize() const { return wxSize(width, height); }
  600. void SetSize( const wxSize &s ) { width = s.GetWidth(); height = s.GetHeight(); }
  601. bool IsEmpty() const { return (width <= 0) || (height <= 0); }
  602. int GetLeft() const { return x; }
  603. int GetTop() const { return y; }
  604. int GetBottom() const { return y + height - 1; }
  605. int GetRight() const { return x + width - 1; }
  606. void SetLeft(int left) { x = left; }
  607. void SetRight(int right) { width = right - x + 1; }
  608. void SetTop(int top) { y = top; }
  609. void SetBottom(int bottom) { height = bottom - y + 1; }
  610. wxPoint GetTopLeft() const { return GetPosition(); }
  611. wxPoint GetLeftTop() const { return GetTopLeft(); }
  612. void SetTopLeft(const wxPoint &p) { SetPosition(p); }
  613. void SetLeftTop(const wxPoint &p) { SetTopLeft(p); }
  614. wxPoint GetBottomRight() const { return wxPoint(GetRight(), GetBottom()); }
  615. wxPoint GetRightBottom() const { return GetBottomRight(); }
  616. void SetBottomRight(const wxPoint &p) { SetRight(p.x); SetBottom(p.y); }
  617. void SetRightBottom(const wxPoint &p) { SetBottomRight(p); }
  618. wxPoint GetTopRight() const { return wxPoint(GetRight(), GetTop()); }
  619. wxPoint GetRightTop() const { return GetTopRight(); }
  620. void SetTopRight(const wxPoint &p) { SetRight(p.x); SetTop(p.y); }
  621. void SetRightTop(const wxPoint &p) { SetTopRight(p); }
  622. wxPoint GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); }
  623. wxPoint GetLeftBottom() const { return GetBottomLeft(); }
  624. void SetBottomLeft(const wxPoint &p) { SetLeft(p.x); SetBottom(p.y); }
  625. void SetLeftBottom(const wxPoint &p) { SetBottomLeft(p); }
  626. // operations with rect
  627. wxRect& Inflate(wxCoord dx, wxCoord dy);
  628. wxRect& Inflate(const wxSize& d) { return Inflate(d.x, d.y); }
  629. wxRect& Inflate(wxCoord d) { return Inflate(d, d); }
  630. wxRect Inflate(wxCoord dx, wxCoord dy) const
  631. {
  632. wxRect r = *this;
  633. r.Inflate(dx, dy);
  634. return r;
  635. }
  636. wxRect& Deflate(wxCoord dx, wxCoord dy) { return Inflate(-dx, -dy); }
  637. wxRect& Deflate(const wxSize& d) { return Inflate(-d.x, -d.y); }
  638. wxRect& Deflate(wxCoord d) { return Inflate(-d); }
  639. wxRect Deflate(wxCoord dx, wxCoord dy) const
  640. {
  641. wxRect r = *this;
  642. r.Deflate(dx, dy);
  643. return r;
  644. }
  645. void Offset(wxCoord dx, wxCoord dy) { x += dx; y += dy; }
  646. void Offset(const wxPoint& pt) { Offset(pt.x, pt.y); }
  647. wxRect& Intersect(const wxRect& rect);
  648. wxRect Intersect(const wxRect& rect) const
  649. {
  650. wxRect r = *this;
  651. r.Intersect(rect);
  652. return r;
  653. }
  654. wxRect& Union(const wxRect& rect);
  655. wxRect Union(const wxRect& rect) const
  656. {
  657. wxRect r = *this;
  658. r.Union(rect);
  659. return r;
  660. }
  661. // return true if the point is (not strcitly) inside the rect
  662. bool Contains(int x, int y) const;
  663. bool Contains(const wxPoint& pt) const { return Contains(pt.x, pt.y); }
  664. // return true if the rectangle 'rect' is (not strictly) inside this rect
  665. bool Contains(const wxRect& rect) const;
  666. #if WXWIN_COMPATIBILITY_2_6
  667. // use Contains() instead
  668. wxDEPRECATED( bool Inside(int x, int y) const );
  669. wxDEPRECATED( bool Inside(const wxPoint& pt) const );
  670. wxDEPRECATED( bool Inside(const wxRect& rect) const );
  671. #endif // WXWIN_COMPATIBILITY_2_6
  672. // return true if the rectangles have a non empty intersection
  673. bool Intersects(const wxRect& rect) const;
  674. // like Union() but don't ignore empty rectangles
  675. wxRect& operator+=(const wxRect& rect);
  676. // intersections of two rectrangles not testing for empty rectangles
  677. wxRect& operator*=(const wxRect& rect);
  678. // centre this rectangle in the given (usually, but not necessarily,
  679. // larger) one
  680. wxRect CentreIn(const wxRect& r, int dir = wxBOTH) const
  681. {
  682. return wxRect(dir & wxHORIZONTAL ? r.x + (r.width - width)/2 : x,
  683. dir & wxVERTICAL ? r.y + (r.height - height)/2 : y,
  684. width, height);
  685. }
  686. wxRect CenterIn(const wxRect& r, int dir = wxBOTH) const
  687. {
  688. return CentreIn(r, dir);
  689. }
  690. public:
  691. int x, y, width, height;
  692. };
  693. // compare rectangles
  694. inline bool operator==(const wxRect& r1, const wxRect& r2)
  695. {
  696. return (r1.x == r2.x) && (r1.y == r2.y) &&
  697. (r1.width == r2.width) && (r1.height == r2.height);
  698. }
  699. inline bool operator!=(const wxRect& r1, const wxRect& r2)
  700. {
  701. return !(r1 == r2);
  702. }
  703. // like Union() but don't treat empty rectangles specially
  704. WXDLLIMPEXP_CORE wxRect operator+(const wxRect& r1, const wxRect& r2);
  705. // intersections of two rectangles
  706. WXDLLIMPEXP_CORE wxRect operator*(const wxRect& r1, const wxRect& r2);
  707. #if WXWIN_COMPATIBILITY_2_6
  708. inline bool wxRect::Inside(int cx, int cy) const { return Contains(cx, cy); }
  709. inline bool wxRect::Inside(const wxPoint& pt) const { return Contains(pt); }
  710. inline bool wxRect::Inside(const wxRect& rect) const { return Contains(rect); }
  711. #endif // WXWIN_COMPATIBILITY_2_6
  712. // define functions which couldn't be defined above because of declarations
  713. // order
  714. inline void wxSize::IncBy(const wxPoint& pt) { IncBy(pt.x, pt.y); }
  715. inline void wxSize::DecBy(const wxPoint& pt) { DecBy(pt.x, pt.y); }
  716. // ---------------------------------------------------------------------------
  717. // Management of pens, brushes and fonts
  718. // ---------------------------------------------------------------------------
  719. typedef wxInt8 wxDash;
  720. class WXDLLIMPEXP_CORE wxGDIObjListBase {
  721. public:
  722. wxGDIObjListBase();
  723. ~wxGDIObjListBase();
  724. protected:
  725. wxList list;
  726. };
  727. WX_DECLARE_STRING_HASH_MAP(wxColour*, wxStringToColourHashMap);
  728. class WXDLLIMPEXP_CORE wxColourDatabase
  729. {
  730. public:
  731. wxColourDatabase();
  732. ~wxColourDatabase();
  733. // find colour by name or name for the given colour
  734. wxColour Find(const wxString& name) const;
  735. wxString FindName(const wxColour& colour) const;
  736. // add a new colour to the database
  737. void AddColour(const wxString& name, const wxColour& colour);
  738. #if WXWIN_COMPATIBILITY_2_6
  739. // deprecated, use Find() instead
  740. wxDEPRECATED( wxColour *FindColour(const wxString& name) );
  741. #endif // WXWIN_COMPATIBILITY_2_6
  742. #ifdef __WXPM__
  743. // PM keeps its own type of colour table
  744. long* m_palTable;
  745. size_t m_nSize;
  746. #endif
  747. private:
  748. // load the database with the built in colour values when called for the
  749. // first time, do nothing after this
  750. void Initialize();
  751. wxStringToColourHashMap *m_map;
  752. };
  753. class WXDLLIMPEXP_CORE wxResourceCache: public wxList
  754. {
  755. public:
  756. wxResourceCache() { }
  757. #if !wxUSE_STD_CONTAINERS
  758. wxResourceCache(const unsigned int keyType) : wxList(keyType) { }
  759. #endif
  760. virtual ~wxResourceCache();
  761. };
  762. // ---------------------------------------------------------------------------
  763. // global variables
  764. // ---------------------------------------------------------------------------
  765. /* Stock objects
  766. wxStockGDI creates the stock GDI objects on demand. Pointers to the
  767. created objects are stored in the ms_stockObject array, which is indexed
  768. by the Item enum values. Platorm-specific fonts can be created by
  769. implementing a derived class with an override for the GetFont function.
  770. wxStockGDI operates as a singleton, accessed through the ms_instance
  771. pointer. By default this pointer is set to an instance of wxStockGDI.
  772. A derived class must arrange to set this pointer to an instance of itself.
  773. */
  774. class WXDLLIMPEXP_CORE wxStockGDI
  775. {
  776. public:
  777. enum Item {
  778. BRUSH_BLACK,
  779. BRUSH_BLUE,
  780. BRUSH_CYAN,
  781. BRUSH_GREEN,
  782. BRUSH_YELLOW,
  783. BRUSH_GREY,
  784. BRUSH_LIGHTGREY,
  785. BRUSH_MEDIUMGREY,
  786. BRUSH_RED,
  787. BRUSH_TRANSPARENT,
  788. BRUSH_WHITE,
  789. COLOUR_BLACK,
  790. COLOUR_BLUE,
  791. COLOUR_CYAN,
  792. COLOUR_GREEN,
  793. COLOUR_YELLOW,
  794. COLOUR_LIGHTGREY,
  795. COLOUR_RED,
  796. COLOUR_WHITE,
  797. CURSOR_CROSS,
  798. CURSOR_HOURGLASS,
  799. CURSOR_STANDARD,
  800. FONT_ITALIC,
  801. FONT_NORMAL,
  802. FONT_SMALL,
  803. FONT_SWISS,
  804. PEN_BLACK,
  805. PEN_BLACKDASHED,
  806. PEN_BLUE,
  807. PEN_CYAN,
  808. PEN_GREEN,
  809. PEN_YELLOW,
  810. PEN_GREY,
  811. PEN_LIGHTGREY,
  812. PEN_MEDIUMGREY,
  813. PEN_RED,
  814. PEN_TRANSPARENT,
  815. PEN_WHITE,
  816. ITEMCOUNT
  817. };
  818. wxStockGDI();
  819. virtual ~wxStockGDI();
  820. static void DeleteAll();
  821. static wxStockGDI& instance() { return *ms_instance; }
  822. static const wxBrush* GetBrush(Item item);
  823. static const wxColour* GetColour(Item item);
  824. static const wxCursor* GetCursor(Item item);
  825. // Can be overridden by platform-specific derived classes
  826. virtual const wxFont* GetFont(Item item);
  827. static const wxPen* GetPen(Item item);
  828. protected:
  829. static wxStockGDI* ms_instance;
  830. static wxObject* ms_stockObject[ITEMCOUNT];
  831. wxDECLARE_NO_COPY_CLASS(wxStockGDI);
  832. };
  833. #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC)
  834. #define wxNORMAL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_NORMAL)
  835. #define wxSMALL_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SMALL)
  836. #define wxSWISS_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_SWISS)
  837. #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED)
  838. #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK)
  839. #define wxBLUE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLUE)
  840. #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN)
  841. #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN)
  842. #define wxYELLOW_PEN wxStockGDI::GetPen(wxStockGDI::PEN_YELLOW)
  843. #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY)
  844. #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY)
  845. #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY)
  846. #define wxRED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_RED)
  847. #define wxTRANSPARENT_PEN wxStockGDI::GetPen(wxStockGDI::PEN_TRANSPARENT)
  848. #define wxWHITE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_WHITE)
  849. #define wxBLACK_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLACK)
  850. #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE)
  851. #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN)
  852. #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN)
  853. #define wxYELLOW_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_YELLOW)
  854. #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY)
  855. #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY)
  856. #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY)
  857. #define wxRED_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_RED)
  858. #define wxTRANSPARENT_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_TRANSPARENT)
  859. #define wxWHITE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_WHITE)
  860. #define wxBLACK wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
  861. #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
  862. #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
  863. #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
  864. #define wxYELLOW wxStockGDI::GetColour(wxStockGDI::COLOUR_YELLOW)
  865. #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
  866. #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
  867. #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)
  868. #define wxCROSS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_CROSS)
  869. #define wxHOURGLASS_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_HOURGLASS)
  870. #define wxSTANDARD_CURSOR wxStockGDI::GetCursor(wxStockGDI::CURSOR_STANDARD)
  871. // 'Null' objects
  872. extern WXDLLIMPEXP_DATA_CORE(wxBitmap) wxNullBitmap;
  873. extern WXDLLIMPEXP_DATA_CORE(wxIcon) wxNullIcon;
  874. extern WXDLLIMPEXP_DATA_CORE(wxCursor) wxNullCursor;
  875. extern WXDLLIMPEXP_DATA_CORE(wxPen) wxNullPen;
  876. extern WXDLLIMPEXP_DATA_CORE(wxBrush) wxNullBrush;
  877. extern WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette;
  878. extern WXDLLIMPEXP_DATA_CORE(wxFont) wxNullFont;
  879. extern WXDLLIMPEXP_DATA_CORE(wxColour) wxNullColour;
  880. extern WXDLLIMPEXP_DATA_CORE(wxIconBundle) wxNullIconBundle;
  881. extern WXDLLIMPEXP_DATA_CORE(wxColourDatabase*) wxTheColourDatabase;
  882. extern WXDLLIMPEXP_DATA_CORE(const char) wxPanelNameStr[];
  883. extern WXDLLIMPEXP_DATA_CORE(const wxSize) wxDefaultSize;
  884. extern WXDLLIMPEXP_DATA_CORE(const wxPoint) wxDefaultPosition;
  885. // ---------------------------------------------------------------------------
  886. // global functions
  887. // ---------------------------------------------------------------------------
  888. // resource management
  889. extern void WXDLLIMPEXP_CORE wxInitializeStockLists();
  890. extern void WXDLLIMPEXP_CORE wxDeleteStockLists();
  891. // is the display colour (or monochrome)?
  892. extern bool WXDLLIMPEXP_CORE wxColourDisplay();
  893. // Returns depth of screen
  894. extern int WXDLLIMPEXP_CORE wxDisplayDepth();
  895. #define wxGetDisplayDepth wxDisplayDepth
  896. // get the display size
  897. extern void WXDLLIMPEXP_CORE wxDisplaySize(int *width, int *height);
  898. extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySize();
  899. extern void WXDLLIMPEXP_CORE wxDisplaySizeMM(int *width, int *height);
  900. extern wxSize WXDLLIMPEXP_CORE wxGetDisplaySizeMM();
  901. extern wxSize WXDLLIMPEXP_CORE wxGetDisplayPPI();
  902. // Get position and size of the display workarea
  903. extern void WXDLLIMPEXP_CORE wxClientDisplayRect(int *x, int *y, int *width, int *height);
  904. extern wxRect WXDLLIMPEXP_CORE wxGetClientDisplayRect();
  905. // set global cursor
  906. extern void WXDLLIMPEXP_CORE wxSetCursor(const wxCursor& cursor);
  907. #endif
  908. // _WX_GDICMNH__