dlg.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. // DLG.CPP
  21. //
  22. // History:
  23. // 08/07/96 JMI Started.
  24. //
  25. // 08/12/96 JMI Now does not have a title bar when there is no text in
  26. // m_szText. Sets the hot to the entire client in that
  27. // case.
  28. //
  29. // 08/12/96 JMI Now utilizes CGuiItem::DrawText to draw text and over-
  30. // rides CGuiItem's default justification to CENTERED.
  31. //
  32. // 09/24/96 JMI Changed all BLU_MB?_* macros to RSP_MB?_* macros.
  33. //
  34. // 10/31/96 JMI Changed:
  35. // Old label: New label:
  36. // ========= =========
  37. // CDlg RDlg
  38. // CImage RImage
  39. // CGuiItem RGuiItem
  40. // CENTERED RGuiItem::Centered
  41. //
  42. // 11/27/96 JMI Added initialization of m_type to identify this type
  43. // of GUI item and virtual base function void Do(void).
  44. //
  45. // 12/19/96 JMI Uses new m_justification (as m_sJustification) and
  46. // upgraded to new RFont/RPrint.
  47. //
  48. // 12/31/96 JMI Do() now calls base implementation in RGuiItem.
  49. //
  50. // 01/01/96 JMI Now overrides GetHot() to restrict hot area to the title
  51. // bar, when present. Also, Compose() no longer sets hot
  52. // area (now done by base class).
  53. //
  54. // 01/04/96 JMI Upgraded HotCall() to new CursorEvent(). This upgrade
  55. // is in response to RGuiItem now using relative RHots.
  56. // Now m_hot.m_sX/Y is parent item relative just like
  57. // m_sX/Y. This should simplify a lot of stuff and even
  58. // fix some odd features like being able to click a GUI
  59. // item that exceeds the boundary of its parent. This fix
  60. // will be essential for the not-yet-existent RListBox since
  61. // it will most likely scroll many children through a small
  62. // client area.
  63. // Now there are two regions associated with cursor events.
  64. // The first is the 'hot' area. This is the area that m_hot
  65. // is set to include. Child items can only receive cursor
  66. // events through this area. The second is the 'event' area.
  67. // This is the area where the item really is actually con-
  68. // cerned with cursor events. Example: For a Dlg, the
  69. // entire window is the 'hot' area and the title bar is the
  70. // 'event' area.
  71. //
  72. // 01/18/97 JMI Converted Do() to take an RInputEvent* instead of a
  73. // long*.
  74. //
  75. // 01/23/97 JMI Changed Do() such that you cannot drag an item outside
  76. // of its parent. I was reluctant to do this b/c it assumes
  77. // you are using the RSPiX Blue coordinate system, but then
  78. // I realized that since it is calling rspGetMouse(), it was
  79. // already using this coordinate system. When the RHots
  80. // start supporting Move events, I'll change this to work on
  81. // the callback and to not call rspSetMouse().
  82. //
  83. // 03/19/97 JMI Converted to using the RHot::m_iecUser (was using
  84. // RHot::m_epcUser) so HotCall and CursorEvent now take
  85. // RInputEvent ptrs.
  86. //
  87. // 03/28/97 JMI RSP_MB0_DOUBLECLICK is now treated the same as
  88. // RSP_MB0_PRESSED.
  89. //
  90. // 04/10/97 JMI Now uses m_sFontCellHeight instead of GetPos() to get
  91. // cell height.
  92. //
  93. // 07/01/97 JMI Was passing a deference of the ptr parm to SET as 2nd
  94. // arg.
  95. //
  96. //////////////////////////////////////////////////////////////////////////////
  97. //
  98. // This a GUI item that is based on the basic RGuiItem. It provides one
  99. // additional function (Do) that allows it to be moved. Simply not calling
  100. // the Do function will keep it from being moved.
  101. // This overrides HotCall() to get information about where a click in its CHot
  102. // occurred.
  103. // This overrides Compose() to add a title bar and set the dimensions of
  104. // the CHot to the title bar.
  105. // This overrides GetClient() to allow space for the title bar, when present.
  106. // This overrides GetHot() to restrict hot area to title bar, when present.
  107. //
  108. // Enhancements/Uses:
  109. // To change the background of a button, see RGuiItem.
  110. //
  111. //////////////////////////////////////////////////////////////////////////////
  112. //////////////////////////////////////////////////////////////////////////////
  113. // Headers.
  114. //////////////////////////////////////////////////////////////////////////////
  115. #include "Blue.h"
  116. #ifdef PATHS_IN_INCLUDES
  117. #include "ORANGE/GUI/dlg.h"
  118. #else
  119. #include "dlg.h"
  120. #endif // PATHS_IN_INCLUDES
  121. //////////////////////////////////////////////////////////////////////////////
  122. // Module specific macros.
  123. //////////////////////////////////////////////////////////////////////////////
  124. // Sets val to def if val is -1.
  125. #define DEF(val, def) ((val == -1) ? def : val)
  126. // Sets a value pointed to if ptr is not NULL.
  127. #define SET(pval, val) ((pval != NULL) ? *pval = val : val)
  128. //////////////////////////////////////////////////////////////////////////////
  129. // Module specific typedefs.
  130. //////////////////////////////////////////////////////////////////////////////
  131. //////////////////////////////////////////////////////////////////////////////
  132. // Module specific (static) variables.
  133. //////////////////////////////////////////////////////////////////////////////
  134. //////////////////////////////////////////////////////////////////////////////
  135. // Construction/Destruction.
  136. //////////////////////////////////////////////////////////////////////////////
  137. //////////////////////////////////////////////////////////////////////////////
  138. //
  139. // Default constructor.
  140. //
  141. //////////////////////////////////////////////////////////////////////////////
  142. RDlg::RDlg()
  143. {
  144. // Override RGuiItem's default justification.
  145. m_justification = RGuiItem::Centered;
  146. m_type = Dlg; // Indicates type of GUI item.
  147. }
  148. //////////////////////////////////////////////////////////////////////////////
  149. //
  150. // Destructor.
  151. //
  152. //////////////////////////////////////////////////////////////////////////////
  153. RDlg::~RDlg()
  154. {
  155. }
  156. ////////////////////////////////////////////////////////////////////////
  157. // Methods.
  158. ////////////////////////////////////////////////////////////////////////
  159. ////////////////////////////////////////////////////////////////////////
  160. //
  161. // Does as Dlg would Do.
  162. //
  163. ////////////////////////////////////////////////////////////////////////
  164. void RDlg::Do( // Returns nothing.
  165. RInputEvent* pie) // In: Most recent user input event.
  166. // Out: pie->sUsed = TRUE, if used.
  167. {
  168. // Call base.
  169. RGuiItem::Do(pie);
  170. // If we're active . . .
  171. if (m_hot.IsActive() != FALSE)
  172. {
  173. // If we're pressed . . .
  174. if (m_sPressed != FALSE)
  175. {
  176. short sTopPosX, sTopPosY;
  177. short sPosX, sPosY;
  178. short sParentW, sParentH;
  179. // Get mouse position RSPiX relative.
  180. rspGetMouse(&sTopPosX, &sTopPosY, NULL);
  181. sPosX = sTopPosX;
  182. sPosY = sTopPosY;
  183. RGuiItem* pguiParent = GetParent();
  184. if (pguiParent != NULL)
  185. {
  186. pguiParent->TopPosToChild(&sPosX, &sPosY);
  187. sParentW = pguiParent->m_im.m_sWidth;
  188. sParentH = pguiParent->m_im.m_sHeight;
  189. }
  190. else
  191. {
  192. rspGetVideoMode(NULL, NULL, NULL, NULL, &sParentW, &sParentH);
  193. }
  194. // Stay within parent.
  195. short sClippedPosX = MAX((short)0, MIN(sPosX, sParentW) );
  196. short sClippedPosY = MAX((short)0, MIN(sPosY, sParentH) );
  197. // If clipped . . .
  198. if (sClippedPosX != sPosX || sClippedPosY != sPosY)
  199. {
  200. // Reposition cursor based on clipped position.
  201. rspSetMouse(
  202. sClippedPosX + sTopPosX - sPosX,
  203. sClippedPosY + sTopPosY - sPosY);
  204. }
  205. // Finally move to new position.
  206. Move( sClippedPosX - m_sMoveOffsetX,
  207. sClippedPosY - m_sMoveOffsetY);
  208. }
  209. }
  210. }
  211. ////////////////////////////////////////////////////////////////////////
  212. //
  213. // Cursor event notification.
  214. // Events in event area.
  215. // (virtual).
  216. //
  217. ////////////////////////////////////////////////////////////////////////
  218. void RDlg::CursorEvent( // Returns nothing.
  219. RInputEvent* pie) // In: Most recent user input event.
  220. // Out: pie->sUsed = TRUE, if used.
  221. {
  222. RGuiItem::CursorEvent(pie);
  223. switch (pie->sEvent)
  224. {
  225. case RSP_MB0_DOUBLECLICK:
  226. case RSP_MB0_PRESSED:
  227. // Store offsets for nice drag.
  228. m_sMoveOffsetX = pie->sPosX;
  229. m_sMoveOffsetY = pie->sPosY;
  230. // Note that we used it.
  231. pie->sUsed = TRUE;
  232. break;
  233. }
  234. }
  235. ////////////////////////////////////////////////////////////////////////
  236. //
  237. // Compose item.
  238. //
  239. ////////////////////////////////////////////////////////////////////////
  240. void RDlg::Compose( // Returns nothing.
  241. RImage* pim /*= NULL*/) // Dest image, uses m_im if NULL.
  242. {
  243. if (pim == NULL)
  244. {
  245. pim = &m_im;
  246. }
  247. // Call base (draws border and background).
  248. RGuiItem::Compose(pim);
  249. // Draw dlg stuff.
  250. short sX, sY, sW, sH;
  251. // Get client relative to border (minus title) so we know where to
  252. // put title.
  253. RGuiItem::GetClient(&sX, &sY, &sW, &sH);
  254. // Draw text.
  255. if (m_szText[0] != '\0')
  256. {
  257. short sTextHeight = m_sFontCellHeight;
  258. // Draw title bar.
  259. rspRect( m_u32BorderColor, pim,
  260. sX, sY,
  261. sW,
  262. sTextHeight);
  263. DrawText(sX, sY, sW, sTextHeight, pim);
  264. }
  265. }
  266. //////////////////////////////////////////////////////////////////////////////
  267. //
  268. // Set this item's event area. This is the area where cursor events are
  269. // interesting to the item.
  270. // (virtual).
  271. //
  272. //////////////////////////////////////////////////////////////////////////////
  273. void RDlg::SetEventArea(void) // Returns nothing.
  274. {
  275. // Call base to set to defaults.
  276. RGuiItem::GetClient(
  277. &m_sEventAreaX,
  278. &m_sEventAreaY,
  279. &m_sEventAreaW,
  280. &m_sEventAreaH);
  281. // If there is title text . . .
  282. if (m_szText[0] != '\0')
  283. {
  284. // Use height of text.
  285. m_sEventAreaH = m_sFontCellHeight;
  286. }
  287. }
  288. ////////////////////////////////////////////////////////////////////////
  289. // Querries.
  290. ////////////////////////////////////////////////////////////////////////
  291. //////////////////////////////////////////////////////////////////////////////
  292. //
  293. // Get the "client" area (i.e., non-border/title area) relative to this
  294. // item. Calls base class version.
  295. //
  296. //////////////////////////////////////////////////////////////////////////////
  297. void RDlg::GetClient( // Returns nothing.
  298. short* psX, // Out: X position unless NULL.
  299. short* psY, // Out: Y position unless NULL.
  300. short* psW, // Out: Width unless NULL.
  301. short* psH) // Out: Height unless NULL.
  302. {
  303. // Call base.
  304. RGuiItem::GetClient(psX, psY, psW, psH);
  305. // If there is title text . . .
  306. if (m_szText[0] != '\0')
  307. {
  308. // Reduce for title bar.
  309. if (psY)
  310. *psY = *psY + m_sFontCellHeight;
  311. if (psH)
  312. *psH = *psH - m_sFontCellHeight;
  313. }
  314. }
  315. //////////////////////////////////////////////////////////////////////////////
  316. // EOF
  317. //////////////////////////////////////////////////////////////////////////////