guiItem.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // GuiItem.H
  21. //
  22. // History:
  23. // 01/13/97 JMI Started tracking history of this file.
  24. // Added ListBox to Type enum.
  25. // Added CopyParms().
  26. //
  27. // 01/14/97 JMI Added IsDynamic().
  28. //
  29. // 01/16/97 JMI Added IsClicked(), SetClicked(), and m_sClicked.
  30. //
  31. // 01/18/97 JMI Added static DoFocus() to handle simple input focus. Also,
  32. // converted Do() to taking an RInputEvent* instead of a
  33. // long*.
  34. //
  35. // 01/20/97 JMI Added GetItemFromPoint() to get a GUI from the tree that
  36. // contains the specified point.
  37. //
  38. // 01/21/97 JMI Added static array of strings describing types.
  39. //
  40. // 01/23/97 JMI Added new member m_sFocusPos which dictates where
  41. // (relative to the client x, y) to draw the focus
  42. // rectangle.
  43. // Added this functionality to inline DrawFocus().
  44. // Also, changed SetEventArea() so it includes more than
  45. // just the client by default.
  46. //
  47. // 01/26/97 JMI Altered static HotCall to accept an RHot* instead of a
  48. // ULONG 'as per' new RHot callbacks.
  49. //
  50. // 02/05/97 JMI Added enum for new PushBtn (RPushBtn).
  51. //
  52. // 02/05/97 JMI Now SetParent() calls OnLoseChild() for parent losing
  53. // child and OnGainChild() for parent gaining child.
  54. //
  55. // 03/10/97 JMI Added TopPosToClient() and ClientPosToTop().
  56. //
  57. // 03/13/97 JMI Added SetText(long lId, char* pszFrmt, ...);
  58. // Added GetVal(long lId) and GetText(long lId, char*);
  59. //
  60. // 03/19/97 JMI Converted to using the RHot::m_iecUser (was using
  61. // RHot::m_epcUser) so HotCall and CursorEvent now take
  62. // RInputEvent ptrs.
  63. //
  64. // 04/01/97 JMI Changed short m_sCanBeFocused (TRUE, FALSE) to
  65. // m_targetFocus (Self, Parent, Sibling).
  66. // Also, now FocusNext() and FocusPrev() will only focus
  67. // items that are activated (i.e., IsActivated() != FALSE).
  68. //
  69. // 04/10/97 JMI Added components for background resource.
  70. // Added font cell height member.
  71. //
  72. // 04/10/97 JMI Added enum MultiBtn for RMultiBtn.
  73. //
  74. // 04/24/97 JMI Added m_u32TextShadowColor.
  75. //
  76. // 06/08/97 MJR Removed tests for NULL pointers from Destroy(). This
  77. // was originally intended to avoid getting an obnoxious
  78. // TRACE message from RImage and RPal. The problem was
  79. // that the RImage's special data was not getting freed
  80. // as a result of this test. The solution was to get rid
  81. // of the tests as well as the pointless TRACE messages
  82. // in RImage and RPal.
  83. //
  84. // 06/30/97 MJR Moved SetVisible() into .cpp because the declaration of
  85. // a static inside of it was causing problems with mac
  86. // precompiled headers.
  87. //
  88. // MJR Added RSP_SAFE_GUI_REF() and RSP_SAFE_GUI_REF_VOID().
  89. //
  90. // 07/01/97 JMI Moved a bunch of functions (some that cannot be
  91. // inlined (b/c they are virtual) ) into the guiItem.cpp.
  92. //
  93. // 07/04/97 JMI Added IsChild().
  94. //
  95. // 07/07/97 JMI Added TextEffectsFlags, m_sTextShadowOffsetX,
  96. // and m_sTextShadowOffsetY.
  97. // Also, added SetTextEffects().
  98. //
  99. // 09/12/97 JMI Made ReadMembers() and WriteMembers() public.
  100. //
  101. // JMI Added GetCurrentFileVersion().
  102. //
  103. // 10/06/99 JMI Added m_fnInputEvent.
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. //
  107. // See CPP for description.
  108. //
  109. //////////////////////////////////////////////////////////////////////////////
  110. #ifndef GUIITEM_H
  111. #define GUIITEM_H
  112. //////////////////////////////////////////////////////////////////////////////
  113. // Please see the CPP file for an explanation of this API.
  114. //////////////////////////////////////////////////////////////////////////////
  115. //////////////////////////////////////////////////////////////////////////////
  116. // Headers.
  117. //////////////////////////////////////////////////////////////////////////////
  118. #include "System.h"
  119. // If PATHS_IN_INCLUDES macro is defined, we can utilized relative
  120. // paths to a header file. In this case we generally go off of our
  121. // RSPiX root directory. System.h MUST be included before this macro
  122. // is evaluated. System.h is the header that, based on the current
  123. // platform (or more so in this case on the compiler), defines
  124. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  125. // instead.
  126. #ifdef PATHS_IN_INCLUDES
  127. #include "GREEN/Image/Image.h"
  128. #include "ORANGE/CDT/List.h"
  129. #include "GREEN/BLiT/BLIT.H"
  130. #include "GREEN/Hot/hot.h"
  131. #include "ORANGE/Props/Props.h"
  132. #include "ORANGE/File/file.h"
  133. #include "CYAN/cyan.h"
  134. #else
  135. #include "list.h"
  136. #include "Image.h"
  137. #include "BLIT.H"
  138. #include "hot.h"
  139. #include "props.h"
  140. #include "file.h"
  141. #include "cyan.h"
  142. #endif // PATHS_IN_INCLUDES
  143. //////////////////////////////////////////////////////////////////////////////
  144. // Macros.
  145. //////////////////////////////////////////////////////////////////////////////
  146. #define GUI_MAX_STR 1024
  147. #define RSP_SAFE_GUI_REF_VOID(pgui, ref) ((pgui) ? (pgui)->ref : (void)0)
  148. #define RSP_SAFE_GUI_REF(pgui, ref) ((pgui) ? (pgui)->ref : 0)
  149. //////////////////////////////////////////////////////////////////////////////
  150. // Typedefs.
  151. //////////////////////////////////////////////////////////////////////////////
  152. //////////////////////////////////////////////////////////////////////////////
  153. class RGuiItem : public RProps <U32, U32>
  154. {
  155. public: // Construction/Destruction.
  156. // Default constructor.
  157. RGuiItem(void);
  158. // Destructor.
  159. virtual ~RGuiItem(void);
  160. //////////////////////////////////////////////////////////////////////////////
  161. public: // Typedefs/Enums.
  162. typedef enum // Values for member flags.
  163. {
  164. // Values for m_sJustification.
  165. Left, // Left justified.
  166. Centered, // Centered.
  167. Justified, // Justified.
  168. Right, // Right justified.
  169. } Justification;
  170. typedef enum
  171. {
  172. // Values for m_sTextEffects.
  173. Shadow = 0x0001, // Shadows text by m_sTextShadowOffsetX, m_sTextShadowOffsetY.
  174. Bold = 0x0002, // Bold text (NYI).
  175. Italic = 0x0004, // Italicized text (NYI).
  176. ThreeD = 0x0008, // 3D (NYI; NSIEWB (not sure if ever will be)).
  177. } TextEffectsFlags;
  178. typedef enum // This type's value indicates a RGuiItem's or descendant's
  179. // type.
  180. {
  181. GuiItem, // Generic GuiItem.
  182. Txt, // RTxt item.
  183. Btn, // RBtn item.
  184. Edit, // REdit item.
  185. ScrollBar, // RScrollBar item.
  186. Dlg, // RDlg item.
  187. ListBox, // RListBox item.
  188. PushBtn, // RPushBtn item.
  189. MultiBtn, // RMultiBtn item.
  190. // Insert new type ABOVE this line.
  191. // Note that Metrowerks requires that there be no comma on the last
  192. // entry of an enum definition.
  193. NumGuiTypes // Placeholder and number of types.
  194. } Type;
  195. typedef enum // Target.
  196. {
  197. // Note that Parent and Self are assigned values that
  198. // aid in backward compatability with older file versions.
  199. Parent = FALSE, // Target this item's parent for action.
  200. Self = TRUE, // Target this item for action.
  201. Sibling, // Target a sibling of this item.
  202. Child, // Target first child of this item.
  203. // Insert new targets ABOVE this line.
  204. NumTargets // Placeholder and number of targets.
  205. } Target;
  206. typedef enum // Placement type.
  207. {
  208. Center = 0x01, // Center item or center tiled block of item.
  209. Tile = 0x02, // Tile item.
  210. // Insert new
  211. } Placement;
  212. // User callback to draw region.
  213. typedef void (*DrawCall)( // Returns nothing.
  214. RGuiItem* pgui, // The RGuiItem being drawn (this).
  215. RImage* pim, // Data to draw; if NULL, erase rect in prc.
  216. RRect* prc); // Where/amount to draw/erase in blue coords.
  217. // User callback to draw background.
  218. typedef void (*BackCall)( // Returns nothing.
  219. RGuiItem* pgui, // The RGuiItem being composed (this).
  220. RImage* pim, // Image to draw into. Try to stay within
  221. // prc please.
  222. RRect* prc); // Where to in image.
  223. // User callback on btn released within button.
  224. typedef void (*BtnUpCall)( // Returns nothing. Called on button released in
  225. // m_hot when active.
  226. RGuiItem* pgui); // this.
  227. // User callback on any input event directed to GUI via it's RHot (m_hot).
  228. typedef void (*InputEventCall)( // Returns nothing.
  229. RGuiItem* pgui, // In: this.
  230. RInputEvent* pie); // In: Input event that motivated callback.
  231. // Out: Typically pie->sUsed = TRUE if used.
  232. // NOTE: sPosX and sPosY are already mapped
  233. // into pgui's coordinate system.
  234. // User callback to get a resource.
  235. typedef short (*GetResCall)( // Returns 0 on success; non-zero on failure.
  236. RGuiItem* pgui); // this.
  237. // User callback to release a resource.
  238. typedef void (*ReleaseResCall)( // Returns nothing.
  239. RGuiItem* pgui); // this.
  240. public: // Methods.
  241. ////////////////////////////////////////////////////////////////////////
  242. // General.
  243. ////////////////////////////////////////////////////////////////////////
  244. // Set font utilized for text. For now, you must set this, but
  245. // eventually I hope to have a built in default font embedded into the
  246. // library so we can display text even when we can't find our assets.
  247. void SetFont(RFont* pfnt, short sHeight)
  248. { m_pprint->SetFont(sHeight, pfnt); }
  249. // Set the text that represents this item.
  250. void SetText(
  251. char* pszFrmt, // sprintf formatted format string.
  252. ...); // Corresponding good stuff.
  253. // Set the text that represents the specified child item.
  254. short SetText( // Returns 0 if item found, non-zero otherwise.
  255. long lId, // Child item ID (can identify this item).
  256. char* pszFrmt, // sprintf formatted format string.
  257. ...); // Corresponding good stuff.
  258. // Set the justification of m_pprint to the current RGuiItem member
  259. // setting.
  260. void SetJustification(void) // Returns nothing.
  261. {
  262. switch (m_justification)
  263. {
  264. case Left:
  265. m_pprint->SetJustifyLeft();
  266. break;
  267. case Centered:
  268. m_pprint->SetJustifyCenter();
  269. break;
  270. case Right:
  271. m_pprint->SetJustifyRight();
  272. break;
  273. default:
  274. TRACE("SetJustification(): Invalid m_justification value.\n");
  275. break;
  276. }
  277. }
  278. // Sets up the current text effects on m_pprint to match this
  279. // GUI's settings.
  280. void SetTextEffects(void); // Returns nothing.
  281. // Creates a displayable Gui. Call SetFont and SetText before calling
  282. // this as it calls Compose.
  283. virtual // If you override this, call this base if possible.
  284. short Create( // Returns 0 on success.
  285. short sX, // X position relative to "parent" item.
  286. short sY, // Y position relative to "parent" item.
  287. short sW, // Width.
  288. short sH, // Height.
  289. short sDepth); // Color depth.
  290. // Destroys dynamic display data.
  291. virtual // If you override this, call this base if possible.
  292. void Destroy(void); // Returns nothing.
  293. // Draw this item and all its subitems into the provided RImage.
  294. virtual // If you override this, call this base if possible.
  295. short Draw( // Returns 0 on success.
  296. RImage* pimDst, // Destination image.
  297. short sDstX = 0, // X position in destination.
  298. short sDstY = 0, // Y position in destination.
  299. short sSrcX = 0, // X position in source.
  300. short sSrcY = 0, // Y position in source.
  301. short sW = 0, // Amount to draw.
  302. short sH = 0, // Amount to draw.
  303. RRect* prc = NULL); // Clip to.
  304. // Pass up a message to redraw the specified region.
  305. virtual // If you override this, call this base if possible.
  306. short Redraw( // Returns 0 on success.
  307. short sSrcX = 0, // X position to start drawing from.
  308. short sSrcY = 0, // Y position to start drawing from.
  309. short sW = 0, // Amount to draw.
  310. short sH = 0); // Amount to draw.
  311. // Blit this item only into provided RImage. Used by Draw().
  312. virtual // If you override this, call this base if possible.
  313. short Blit( // Returns 0 on success.
  314. RImage* pimDst, // Destination image.
  315. short sDstX, // X position in destination.
  316. short sDstY, // Y position in destination.
  317. short sSrcX = 0, // X position in source.
  318. short sSrcY = 0, // Y position in source.
  319. short sW = 0, // Amount to draw.
  320. short sH = 0, // Amount to draw.
  321. RRect* prc = NULL); // Clip to.
  322. // Draw text in m_szText in m_u32TextColor with transparent
  323. // background at sX, sY with sW and m_sJustification.
  324. // Does nothing if m_szText is empty.
  325. virtual // If you override this, call this base if possible.
  326. short DrawText( // Returns 0 on success.
  327. short sX, // X position in image.
  328. short sY, // Y position in image.
  329. short sW = 0, // Width of text area.
  330. short sH = 0, // Height of test area.
  331. RImage* pim = NULL); // Destination image. NULL == use m_im.
  332. // Ask user to erase area specified.
  333. virtual // If you override this, call this base if possible.
  334. void Erase( // Returns nothing.
  335. short sX = 0, // X position to erase.
  336. short sY = 0, // Y position to erase.
  337. short sW = 0, // Width to erase.
  338. short sH = 0); // Height to erase.
  339. // Move this item to sX, sY.
  340. virtual // If you override this, call this base if possible.
  341. void Move( // Returns nothing.
  342. short sX, // New x position.
  343. short sY); // New y position.
  344. // Cursor event notification.
  345. // Events in event area.
  346. virtual // If you override this, call this base if possible.
  347. void CursorEvent( // Returns nothing.
  348. RInputEvent* pie); // In: Most recent user input event.
  349. // Out: pie->sUsed = TRUE, if used.
  350. // Callback from RHot.
  351. // Events in hot area.
  352. virtual // If you override this, call this base if possible.
  353. void HotCall( // Returns nothing.
  354. RInputEvent* pie); // In: Most recent user input event.
  355. // Out: pie->sUsed = TRUE, if used.
  356. // Activate or deactivate mouse reaction for this gui item only.
  357. // If the item has m_sActive set to TRUE, it will be activated.
  358. virtual // If you override this, call this base if possible.
  359. void SetActive( // Returns nothing.
  360. short sActive); // TRUE to make active, FALSE otherwise.
  361. // Hide or show GUI item and child items. Causes RHots to be
  362. // deactivated for both this and child items.
  363. // DOES NOT CHANGE THE VISIBLE STATUS OF CHILD ITEMS.
  364. virtual // If you override this, call this base if possible.
  365. void SetVisible( // Returns nothing.
  366. short sVisible); // TRUE to make visible, FALSE otherwise.
  367. // Change parent. Removes from old parent's list and adds to new.
  368. // New can be NULL (so can old).
  369. virtual // If you override this, call this base if possible.
  370. void SetParent(RGuiItem* pguiParent);
  371. // Draw border.
  372. virtual // If you override this, call this base if possible.
  373. void DrawBorder( // Returns nothing.
  374. RImage* pim = NULL, // Dest image, uses m_im if NULL.
  375. short sInvert = FALSE); // Inverts border if TRUE.
  376. // Draw background. Calls user callback m_backcall if provided.
  377. virtual // If you override this, call this base if possible.
  378. void DrawBackground( // Returns nothing.
  379. RImage* pim = NULL); // Dest image, uses m_im if NULL.
  380. // Draw background resource, if one is specified.
  381. // Utilizes m_*BkdRes* parameters to get, place, and BLiT the resource.
  382. virtual // If you override this, call this base if possible.
  383. void DrawBackgroundRes( // Returns nothing.
  384. RImage* pim = NULL); // Dest image, uses m_im, if NULL.
  385. // Compose item.
  386. virtual // If you override this, call this base if possible.
  387. void Compose( // Returns nothing.
  388. RImage* pim = NULL); // Dest image, uses m_im if NULL.
  389. // Do one iteration of processing. This is useful on items that need to
  390. // poll frequently or do something every once in a while that is not
  391. // triggered by an event.
  392. virtual // If you override this, call this base if possible.
  393. void Do( // Returns nothing.
  394. RInputEvent* pie); // In: Most recent user input event.
  395. // Out: pie->sUsed = TRUE, if used.
  396. // Set this item's event area. This is the area where cursor events are
  397. // interesting to the item.
  398. virtual // If you override this, call this base if possible.
  399. void SetEventArea(void); // Returns nothing.
  400. // Set this item's hot area. This should be the total dimensions of this
  401. // item.
  402. virtual // If you override this, call this base if possible.
  403. void SetHotArea(void); // Returns nothing.
  404. // Copy basic parameters regarding appearance and use from this item to
  405. // the specified one.
  406. virtual // If you override this, call this base if possible.
  407. void CopyParms( // Returns nothing.
  408. RGuiItem* pguiDst); // Destination for parameters from this item.
  409. // Called by SetParent() when a GUI is losing a child item.
  410. virtual // If you override this, call this base, if possible.
  411. void OnLoseChild( // Returns nothing.
  412. RGuiItem* pguiChild); // Child item we're about to lose.
  413. // Called by SetParent() when a GUI is gaining a child item.
  414. virtual // If you override this, call this base, if possible.
  415. void OnGainChild( // Returns nothing.
  416. RGuiItem* pguiChild); // Child item we're about to gain.
  417. // This will open the specified file with read access in an RFile and
  418. // pass it to Load(RFile*).
  419. // NOTE: There is a static version of this function that will detect
  420. // the type of the root item from the file and allocate an item of
  421. // that type before loading. Useful for loading generic *.GUI files.
  422. // See LoadInstance(char*).
  423. short Load( // Returns 0 on success.
  424. char* pszFileName); // Name of file to load from.
  425. // This will load the GUI tree (i.e., 'this' item and its children).
  426. // If you override this function, you should call this base version
  427. // to have it load the base class members.
  428. // NOTE: There is a static version of this function that will detect
  429. // the type of the root item from the file and allocate an item of
  430. // that type before loading. Useful for loading generic *.GUI files.
  431. // See LoadInstance(RFile*).
  432. virtual // If you override this, call this base if possible.
  433. short Load( // Returns 0 on success.
  434. RFile* pfile); // RFile open with read access to load from.
  435. // This will open the specified file with write access in an RFile and
  436. // pass it to Save(RFile*).
  437. short Save( // Returns 0 on success.
  438. char* pszFileName); // Name of file to save to.
  439. // This will save the GUI tree (i.e., 'this' item and its children).
  440. // If you override this function, you should call this base version
  441. // to have it save the base class members.
  442. virtual // If you override this, call this base if possible.
  443. short Save( // Returns 0 on success.
  444. RFile* pfile); // RFile open with write access to save to.
  445. // Sets the 'clicked' status.
  446. void SetClicked( // Returns nothing.
  447. short sClicked); // New 'clicked' status.
  448. // Draws focus for item if m_sShowFocus is TRUE.
  449. virtual // If you override this, call this base if possible.
  450. void DrawFocus( // Returns nothing.
  451. RImage* pimDst, // Destination image.
  452. short sDstX = 0, // X offset in destination.
  453. short sDstY = 0, // Y offset in destination.
  454. RRect* prc = NULL); // Clip to.
  455. // Called by the static implementation of SetFocus() on the item gaining
  456. // the focus.
  457. // It is okay to call SetFocus() from this function.
  458. virtual // If you override this, call this base if possible.
  459. void OnGainFocus(void);
  460. // Called by the static implementation of SetFocus() on the item losing
  461. // the focus.
  462. // It is okay to call SetFocus() from this function.
  463. virtual // If you override this, call this base if possible.
  464. void OnLoseFocus(void);
  465. // Sets the current focus GUI pointer to this GUI.
  466. RGuiItem* SetFocus(void); // Returns pointer to GUI losing the focus.
  467. // Gets the optional resource image named m_szBkdResName for this item
  468. // into m_pimBkdRes.
  469. // Each call to this function should have a corresponding call to
  470. // ReleaseRes().
  471. // This function can result in a callback.
  472. virtual // If you override this, call this base if possible.
  473. short GetRes(void);
  474. // Releases the optional resource image previously gotten by a call to
  475. // GetRes().
  476. // Each call to this function should correspond to a previous call to
  477. // GetRes(). You should not call this function if the corresponding
  478. // GetRes() failed.
  479. // This function can result in a callback.
  480. virtual // If you override this, call this base if possible.
  481. void ReleaseRes(void);
  482. //////////////////////////////////////////////////////////////////////////////
  483. public: // Static
  484. // Sets the current focus GUI pointer to the supplied GUI.
  485. // NOTE: Eventually, this function may do more, so it is better to call
  486. // it than simply setting ms_pguiFocus to your gui.
  487. static RGuiItem* SetFocus( // Returns pointer to GUI losing the focus.
  488. RGuiItem* pguiNewFocus); // New item to focus or NULL for none.
  489. // Moves the focus to the next GUI at the same level as the current
  490. // ms_pguiFocus. Does not affect current focus for top-level guis.
  491. static RGuiItem* FocusNext(void); // Returns new item with focus or NULL,
  492. // if none.
  493. // Moves the focus to the previous GUI at the same level as the current
  494. // ms_pguiFocus. Does not affect current focus for top-level guis.
  495. static RGuiItem* FocusPrev(void); // Returns new item with focus or NULL,
  496. // if none.
  497. // Sends the event to the GUI focused via Do(), and, if event is not
  498. // used, checks for keys that might change the focus.
  499. static void DoFocus( // Returns nothing.
  500. RInputEvent* pie); // In: Most recent user input event.
  501. // Out: pie->sUsed = TRUE, if used.
  502. // Creates the specified object and returns a pointer to it.
  503. // The object is created with new, so use delete to destroy the object.
  504. static RGuiItem* CreateGuiItem( // Returns the allocated type on success.
  505. // Returns NULL on error.
  506. Type type); // Type of GuiItem to allocate. Must be one
  507. // of the enums that is a member of
  508. // RGuiItem::Type.
  509. // Destroys the specified object utilizing the 'type' to make sure all
  510. // appropriate destruction for that type is done. This function is
  511. // useful for delete'ing objects that may be descendants of RGuiItem
  512. // when you do not know the type of the object. Note this only works
  513. // for standard types.
  514. static void DestroyGuiItem( // Returns nothing.
  515. RGuiItem* pgui); // Pointer to gui to deallocate.
  516. // Instantiate a GUI tree from a file. Allocates a GUI item of the
  517. // proper (specified in the file) type and loads it using the specified
  518. // file.
  519. static RGuiItem* LoadInstantiate( // Returns newly allocated GUI item
  520. // on success or NULL on failure.
  521. char* pszFileName); // Name of file to instantiate from.
  522. // Instantiate a GUI tree from a file. Allocates a GUI item of the
  523. // proper (specified in the file) type and loads it using the specified
  524. // file.
  525. static RGuiItem* LoadInstantiate( // Returns newly allocated GUI item
  526. // on success or NULL on failure.
  527. RFile* pfile); // Pointer to open GUI file.
  528. // Read item's members from file.
  529. virtual // If you override this, call this base if possible.
  530. short ReadMembers( // Returns 0 on success.
  531. RFile* pfile, // File to read from.
  532. U32 u32Version); // File format version to use.
  533. // Write item's members to file.
  534. virtual // If you override this, call this base if possible.
  535. short WriteMembers( // Returns 0 on success.
  536. RFile* pfile); // File to write to.
  537. public:
  538. ////////////////////////////////////////////////////////////////////////
  539. // Querries.
  540. ////////////////////////////////////////////////////////////////////////
  541. // Get the text that represents this item.
  542. short GetText( // Returns 0 on success.
  543. char* pszText, // Location to copy text to.
  544. short sMax); // Total memory pointed to by pszText.
  545. // Get the text that represents the specified item.
  546. short GetText( // Returns 0 on success.
  547. long lId, // In: Child item ID (can identify this item).
  548. char* pszText, // Out: Location to copy text to.
  549. short sMax); // In: Total memory pointed to by pszText.
  550. // Get the number represented by the text in this item.
  551. long GetVal(void); // Returns value.
  552. // Get the number represented by the text in the specified item.
  553. long GetVal( // Returns value.
  554. long lId); // In: Child item ID (can identify this item).
  555. // Get the RImage that contains the item. Feel free to Convert() this
  556. // to even a transparent type. Blah ha ha.
  557. RImage* GetImage(void) // Returns a pointer to this dialog's RImage.
  558. { return &m_im; }
  559. // Get the parent of this gui item.
  560. RGuiItem* GetParent(void) // Returns parent RGuiItem*.
  561. { return m_pguiParent; }
  562. // Gets the thickness of the top/left border (including border edge effect).
  563. virtual
  564. short GetTopLeftBorderThickness(void); // Returns border thickness
  565. // including edge effect.
  566. // Gets the thickness of the bottom/right border (including border edge effect).
  567. virtual
  568. short GetBottomRightBorderThickness(void); // Returns border thickness
  569. // including edge effect.
  570. // Get the "client" area (i.e., non-border/title area) relative to this
  571. // item.
  572. virtual // If you override this, call this base if possible.
  573. void GetClient( // Returns nothing.
  574. short* psX, // Out: X position unless NULL.
  575. short* psY, // Out: Y position unless NULL.
  576. short* psW, // Out: Width unless NULL.
  577. short* psH); // Out: Height unless NULL.
  578. // Get the "hot" area (i.e., clickable area) relative to this item.
  579. virtual // If you override this, call this base if possible.
  580. void GetHotArea( // Returns nothing.
  581. short* psX, // Out: X position unless NULL.
  582. short* psY, // Out: Y position unless NULL.
  583. short* psW, // Out: Width unless NULL.
  584. short* psH); // Out: Height unless NULL.
  585. // Change the position specified to a top-level coord.
  586. void ChildPosToTop( // Returns nothing.
  587. short* psX, // In: Child pos, Out: Top level pos.
  588. short* psY); // In: Child pos, Out: Top level pos.
  589. // Change the position specified to a child coord.
  590. void TopPosToChild( // Returns nothing.
  591. short* psX, // In: Top level pos, Out: Child pos.
  592. short* psY); // In: Top level pos, Out: Child pos.
  593. // Change the position specified to a top-level coord.
  594. void ClientPosToTop( // Returns nothing.
  595. short* psX, // In: Client pos, Out: Top level pos.
  596. short* psY) // In: Client pos, Out: Top level pos.
  597. {
  598. // Get client position.
  599. short sClientX, sClientY;
  600. GetClient(&sClientX, &sClientY, NULL, NULL);
  601. // Offset.
  602. *psX += sClientX;
  603. *psY += sClientY;
  604. // Convert to top.
  605. ChildPosToTop(psX, psY);
  606. }
  607. // Change the position specified to a client coord.
  608. void TopPosToClient( // Returns nothing.
  609. short* psX, // In: Top level pos, Out: Client pos.
  610. short* psY) // In: Top level pos, Out: Client pos.
  611. {
  612. // Convert to child.
  613. TopPosToChild(psX, psY);
  614. // Get client position.
  615. short sClientX, sClientY;
  616. GetClient(&sClientX, &sClientY, NULL, NULL);
  617. // Offset.
  618. *psX -= sClientX;
  619. *psY -= sClientY;
  620. }
  621. // Get the first item with the supplied ID from this among RGuiItem and
  622. // its children.
  623. RGuiItem* GetItemFromId( // Returns pointer to RGuiItem, if found;
  624. // otherwise, returns NULL.
  625. long lId) // ID of RGuiItem to find.
  626. {
  627. RGuiItem* pguiRes = NULL; // Assume not found.
  628. // First check this item . . .
  629. if (m_lId != lId)
  630. {
  631. // Check children.
  632. RGuiItem* pgui = m_listguiChildren.GetHead();
  633. while (pgui != NULL && pguiRes == NULL)
  634. {
  635. // Check pgui and its children.
  636. pguiRes = pgui->GetItemFromId(lId);
  637. pgui = m_listguiChildren.GetNext();
  638. }
  639. }
  640. else
  641. {
  642. // This item is it.
  643. pguiRes = this;
  644. }
  645. return pguiRes;
  646. }
  647. // Get the item at the specified point that has the
  648. // specified parameters.
  649. RGuiItem* GetItemFromPoint( // Returns item ptr, if item found;
  650. // NULL on failure.
  651. short sPosX, // X position.
  652. short sPosY, // Y position.
  653. short sActive = TRUE, // If TRUE, only searches active items.
  654. // If FALSE, searches all items.
  655. short sEventArea = TRUE); // If TRUE, only checks items' event areas.
  656. // If FALSE, checks items' entire hot regions.
  657. // Gets the child depth (i.e., how many ancestors until top-level).
  658. short GetChildDepth(void) // Returns child depth.
  659. {
  660. short sDepth = 0;
  661. RGuiItem* pguiParent = GetParent();
  662. while (pguiParent != NULL)
  663. {
  664. // Increase depth.
  665. sDepth++;
  666. // Get parent of this parent.
  667. pguiParent = pguiParent->GetParent();
  668. }
  669. return sDepth;
  670. }
  671. // Determine if the specified item is an ancestor of this item.
  672. short IsAncestor( // Returns TRUE if pgui is an ancestor of this item.
  673. // Returns FALSE otherwise.
  674. RGuiItem* pgui) // GUI that may be an ancestor.
  675. {
  676. short sRes = FALSE;
  677. RGuiItem* pguiParent = GetParent();
  678. while (pguiParent != NULL && sRes == FALSE)
  679. {
  680. if (pguiParent == pgui)
  681. {
  682. // Found item is an ancestor.
  683. sRes = TRUE;
  684. }
  685. pguiParent = pguiParent->GetParent();
  686. }
  687. return sRes;
  688. }
  689. // See if item is currently activated.
  690. short IsActivated(void) // Returns TRUE if this item is activated (which
  691. // is different from active (active items become
  692. // activated when visible)).
  693. {
  694. return m_hot.IsActive();
  695. }
  696. // Returns TRUE if this item was allocated with CreateGuiItem().
  697. short IsDynamic(void); // Returns TRUE if this item was allocated with
  698. // CreateGuiItem().
  699. // Returns TRUE if this item is considered 'Clicked'. For example, the
  700. // default implementation makes this TRUE if the cursor was pressed AND
  701. // released within this item's hot area.
  702. short IsClicked(void) // Returns TRUE, if this item was 'Clicked';
  703. // FALSE, otherwise.
  704. {
  705. return m_sClicked;
  706. }
  707. // Returns TRUE if the specified item is a direct descendant of
  708. // this item; FALSE, otherwise.
  709. // NOTE: Must be direct descendant; children of children don't count.
  710. short IsChild(
  711. RGuiItem* pguiChild) // In: Item to check.
  712. {
  713. if (pguiChild->GetParent() == this)
  714. return TRUE;
  715. return FALSE;
  716. }
  717. // Get the current file version (that is, the file version a file
  718. // written from this GUI right now would be).
  719. static U32 GetCurrentFileVersion(void);
  720. //////////////////////////////////////////////////////////////////////////////
  721. public: // Static
  722. //////////////////////////////////////////////////////////////////////////////
  723. //////////////////////////////////////////////////////////////////////////////
  724. protected: // Internal functions.
  725. // Pass callbacks from RHot on to appropriate instance.
  726. static void HotCall(
  727. RHot* phot, // In: Ptr to RHot that generated event.
  728. RInputEvent* pie) // In: Most recent user input event.
  729. // Out: pie->sUsed = TRUE, if used.
  730. { ((RGuiItem*)(phot->m_ulUser))->HotCall(pie); }
  731. // Read header for this GUI item.
  732. static short ReadHeader( // Returns 0 on success.
  733. RFile* pfile, // In: File to read from.
  734. U32* pu32Version, // Out: File format version.
  735. Type* ptype); // Out: Type of GUI item stored.
  736. // Save item's children to the specified file.
  737. virtual
  738. short SaveChildren( // Returns 0 on success.
  739. RFile* pfile); // File to save to.
  740. // Load item's children from the specified file.
  741. virtual
  742. short LoadChildren( // Returns 0 on success.
  743. RFile* pfile); // File to load from.
  744. //////////////////////////////////////////////////////////////////////////////
  745. public: // Member variables.
  746. RImage m_im; // RImage representing this item
  747. // visually.
  748. RList<RGuiItem> m_listguiChildren; // List of items "inside" this item.
  749. short m_sX; // X position. 0 on construction.
  750. short m_sY; // Y position. 0 on construction.
  751. RPrint* m_pprint; // Used to display text. Also,
  752. // stores font settings. By default,
  753. // this points to &ms_print, but it
  754. // can be changed to point to a dif-
  755. // ferent one.
  756. short m_sFontCellHeight; // Cell height for text.
  757. char m_szText[GUI_MAX_STR]; // Text for this item.
  758. short m_sEventAreaX; // X coord of area in which we care
  759. // about cursor events.
  760. short m_sEventAreaY; // Y coord of area in which we care
  761. // about cursor events.
  762. short m_sEventAreaW; // Width of area in which we care
  763. // about cursor events.
  764. short m_sEventAreaH; // Height of area in which we care
  765. // about cursor events.
  766. RHot m_hot; // Area in which we get clickage.
  767. short m_sPressed; // TRUE if our hot area is currently
  768. // pressed.
  769. DrawCall m_drawcall; // User callback to draw/erase a region.
  770. BackCall m_backcall; // User callback to draw background in
  771. // item.
  772. BtnUpCall m_bcUser; // User callback on button up in m_hot
  773. // when active.
  774. InputEventCall m_fnInputEvent; // User callback when input event
  775. // is directed at this GUI via its
  776. // RHot (m_hot).
  777. U32 m_u32BorderColor;
  778. U32 m_u32BorderShadowColor;
  779. U32 m_u32BorderHighlightColor;
  780. U32 m_u32BorderEdgeColor;
  781. U32 m_u32TextColor; // 0 indicates transparency.
  782. U32 m_u32BackColor;
  783. U32 m_u32TextShadowColor;
  784. short m_sTextEffects; // Flags for text effects.
  785. short m_sTextShadowOffsetX; // Offset along X axis for text shadow.
  786. short m_sTextShadowOffsetY; // Offset along Y axis for text shadow.
  787. short m_sBorderThickness;
  788. Justification m_justification; // { RGuiItem::Right, RGuiItem::Center, RGuiItem::Left }
  789. ULONG m_ulUserInstance; // Space that can be used in any way by
  790. // the user but is intended to represent
  791. // a user instance structure such as a
  792. // struct or class.
  793. ULONG m_ulUserData; // Space that can be used in any way by
  794. // the user and has no particular intended
  795. // use.
  796. short m_sInvertedBorder; // TRUE if border is inverted; FALSE
  797. // otherwise.
  798. Type m_type; // Indicates type of GUI item.
  799. short m_sTransparent; // TRUE, if this should be blt'ed via
  800. // a transparent blit call; FALSE,
  801. // otherwise. Note that this cannot
  802. // override transparent Image formats
  803. // (e.g., FSPR8 will always be blt'ed
  804. // with transparency).
  805. U32 m_u32TransparentColor; // Color used for transparency
  806. // when using transparent blit
  807. // call.
  808. long m_lId; // ID. Used to identify this RGuiItem
  809. // from others. See GetItemFromId().
  810. Target m_targetFocus; // Target when focus received.
  811. short m_sShowFocus; // TRUE if this item shows feedback,
  812. // usually via DrawFocus(), when it
  813. // has the focus.
  814. short m_sFocusPos; // Position at which DrawFocus() will
  815. // draw the focus rectangle relative
  816. // to the client area. For example,
  817. // -1 would but it just outside the
  818. // client area.
  819. U32 m_u32FocusColor; // Color to draw focus with.
  820. short m_sClicked; // TRUE if this item is considered
  821. // 'Clicked'. For example, the default
  822. // implementation makes this TRUE if
  823. // the cursor was pressed AND released
  824. // within this item's hot area.
  825. char m_szBkdResName[RSP_MAX_PATH]; // Name of background res
  826. // file to get into
  827. // m_pimBkdRes.
  828. short m_sBkdResTransparent; // TRUE, if m_pimBkdRes is to be
  829. // BLiT'ed transparently; FALSE,
  830. // otherwise.
  831. U32 m_u32BkdResTransparentColor; // Transparency color for
  832. // m_pimBkdRes when
  833. // BLiT'ed transparently.
  834. short m_sBkdResPlacement; // Combination of |'ed
  835. // Placement enum values.
  836. RImage* m_pimBkdRes; // Background resource image.
  837. GetResCall m_fnGetRes; // User callback to get background res
  838. // (m_pimBkdRes).
  839. ReleaseResCall m_fnReleaseRes; // User callback to release background
  840. // res (m_pimBkdRes).
  841. // These members should be changed only via SetVisible() and SetActive().
  842. short m_sVisible; // TRUE if Draw() is to draw this item
  843. // and its children; FALSE, otherwise.
  844. short m_sActive; // TRUE if the RHot is to be activated
  845. // when visible.
  846. protected: // Internal typedefs.
  847. protected: // Protected member variables.
  848. RGuiItem* m_pguiParent;
  849. //////////////////// Statics ////////////////////////////////////////////
  850. public:
  851. static RPrint ms_print; // This is the main RPrint that all
  852. // GUI items default to.
  853. static RGuiItem* ms_pguiFocus; // Higher level APIs can use this as
  854. // their current point of input
  855. // focus.
  856. static char* ms_apszTypes[NumGuiTypes]; // Array of strings
  857. // indexed by type.
  858. };
  859. #endif // GUIITEM_H
  860. //////////////////////////////////////////////////////////////////////////////
  861. // EOF
  862. //////////////////////////////////////////////////////////////////////////////