GADGET.CPP 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\gadget.cpv 2.18 16 Oct 1995 16:49:40 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : GADGET.CPP *
  26. * *
  27. * Programmer : Maria del Mar McCready Legg *
  28. * Joe L. Bostic *
  29. * *
  30. * Start Date : 01/03/95 *
  31. * *
  32. * Last Update : July 8, 1995 [JLB] *
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * GadgetClass::Action -- Base action for gadget. *
  37. * GadgetClass::Clear_Focus -- Clears the focus if this gadget has it. *
  38. * GadgetClass::Delete_List -- Deletes all gadget objects in list. *
  39. * GadgetClass::Disable -- Disables the gaget from input processing. *
  40. * GadgetClass::Draw_All -- Forces all gadgets in list to be redrawn. *
  41. * GadgetClass::Draw_Me -- Gadget redraw action (flag control). *
  42. * GadgetClass::Enable -- Enables the gadget. *
  43. * GadgetClass::Extract_Gadget -- Sweeps through the gadget chain to find gadget specified. *
  44. * GadgetClass::Flag_To_Redraw -- Flags this gadget to be redrawn. *
  45. * GadgetClass::GadgetClass -- Constructor for gadget object. *
  46. * GadgetClass::GadgetClass -- Default constructor for a gadget class object. *
  47. * GadgetClass::Get_Next -- Returns a pointer to the next gadget in the chain. *
  48. * GadgetClass::Get_Prev -- Fetches a pointer to the previous gadget. *
  49. * GadgetClass::Has_Focus -- Checks if this object currently has the keyboard focus. *
  50. * GadgetClass::Remove -- Removes the specified gagdet from the list. *
  51. * GadgetClass::Set_Focus -- Sets focus to this gadget. *
  52. * GadgetClass::Sticky_Process -- Handles the sticky flag processing. *
  53. * GadgetClass::~GadgetClass -- Destructor for gadget object. *
  54. * GadgetClass::Is_List_To_Redraw -- tells if any gadget in the list needs redrawing *
  55. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  56. #include "function.h"
  57. #include <filepcx.h>
  58. #include <io.h>
  59. /*
  60. ** This records the current gadget the the gadget system is "stuck on". Such a
  61. ** gadget will be processed to the exclusion of all others until the mouse button
  62. ** is no longer pressed.
  63. */
  64. GadgetClass * GadgetClass::StuckOn = 0;
  65. /*
  66. ** This is a copy of a pointer to the last list used by the gadget input system.
  67. ** If a change of list is detected, then all gadgets are forced to be redrawn.
  68. */
  69. GadgetClass * GadgetClass::LastList = 0;
  70. /*
  71. ** This points to the gadget that is intercepting all keyboard events.
  72. */
  73. GadgetClass * GadgetClass::Focused = 0;
  74. /***********************************************************************************************
  75. * GadgetClass::GadgetClass -- Constructor for gadget object. *
  76. * *
  77. * This is the normal constructor for gadget objects. A gadget object is only concerned *
  78. * with the region on the screen to considered "its own" as well as the flags that tell *
  79. * what mouse action should be recognized when the mouse is over this screen area. *
  80. * *
  81. * INPUT: x,y -- Coordinates (in pixels) of the upper left hand corner of the region that *
  82. * will be "owned" by this gadget. *
  83. * *
  84. * w,h -- Width and height (in pixels) of this gadget's region. *
  85. * *
  86. * flags -- The flags (mouse conditions) that will cause this gadget's action *
  87. * function to be called. *
  88. * *
  89. * OUTPUT: none *
  90. * *
  91. * WARNINGS: none *
  92. * *
  93. * HISTORY: *
  94. * 01/03/1995 MML : Created. *
  95. *=============================================================================================*/
  96. GadgetClass::GadgetClass(int x, int y, int w, int h, unsigned flags, int sticky)
  97. {
  98. X = x;
  99. Y = y;
  100. Width = w;
  101. Height = h;
  102. Flags = flags;
  103. IsToRepaint = false;
  104. IsSticky = sticky;
  105. IsDisabled = false;
  106. if (IsSticky) {
  107. Flags |= LEFTPRESS|LEFTRELEASE;
  108. }
  109. }
  110. /***********************************************************************************************
  111. * GadgetClass::~GadgetClass -- Destructor for gadget object. *
  112. * *
  113. * This is the destructor for the gadget object. It will clear the focus from this gadget *
  114. * if this gadget currently has the focus. *
  115. * *
  116. * INPUT: none *
  117. * *
  118. * OUTPUT: none *
  119. * *
  120. * WARNINGS: none *
  121. * *
  122. * HISTORY: *
  123. * 07/08/1995 JLB : Created. *
  124. *=============================================================================================*/
  125. GadgetClass::~GadgetClass(void)
  126. {
  127. if (Has_Focus()) {
  128. Clear_Focus();
  129. }
  130. }
  131. /***************************************************************************
  132. * GADGETCLASS::CLICKEDON -- If a mouse click is detected within gadget's *
  133. * area and the appropriate flag is set, then call Action(). *
  134. * *
  135. * INPUT: int key, int mousex, int mousey *
  136. * *
  137. * OUTPUT: true or false *
  138. * *
  139. * WARNINGS: none. *
  140. * *
  141. * HISTORY: 01/03/1995 MML : Created. *
  142. *=========================================================================*/
  143. int GadgetClass::Clicked_On(KeyNumType & key, unsigned flags, int mousex, int mousey)
  144. {
  145. /*
  146. ** Set flags to match only those events that occur AND are being looked for. If
  147. ** the result is NULL, then we know that this button should be ignored.
  148. */
  149. flags &= Flags;
  150. /*
  151. ** If keyboard input should be processed by this "gadget" and keyboard input is
  152. ** detected, then always call the action function. It is up to the action function
  153. ** in this case to either ignore the keyboard input or not.
  154. **
  155. ** For mouse actions, check to see if the mouse is in the region of the button
  156. ** before calling the associated action function. This is the typical action for
  157. ** buttons.
  158. */
  159. if (this == StuckOn ||
  160. (flags & KEYBOARD) ||
  161. (flags && (unsigned)(mousex - X) < Width && (unsigned)(mousey - Y) < Height)) {
  162. return(Action(flags, key));
  163. }
  164. return(false);
  165. }
  166. /***********************************************************************************************
  167. * GadgetClass::Enable -- Enables the gadget. *
  168. * *
  169. * This function enables the gadget. An enabled gadget will be processed for input *
  170. * purposes. *
  171. * *
  172. * INPUT: none *
  173. * *
  174. * OUTPUT: none *
  175. * *
  176. * WARNINGS: none *
  177. * *
  178. * HISTORY: *
  179. * 01/15/1995 JLB : Created. *
  180. *=============================================================================================*/
  181. void GadgetClass::Enable(void)
  182. {
  183. IsDisabled = false;
  184. IsToRepaint = true;
  185. Clear_Focus();
  186. }
  187. /***********************************************************************************************
  188. * GadgetClass::Disable -- Disables the gaget from input processing. *
  189. * *
  190. * This routine will disable the gadget. A disabled gadget might be rendered, but is *
  191. * ignored for input processing. *
  192. * *
  193. * INPUT: none *
  194. * *
  195. * OUTPUT: none *
  196. * *
  197. * WARNINGS: none *
  198. * *
  199. * HISTORY: *
  200. * 01/15/1995 JLB : Created. *
  201. *=============================================================================================*/
  202. void GadgetClass::Disable(void)
  203. {
  204. IsDisabled = true;
  205. IsToRepaint = true;
  206. Clear_Focus();
  207. }
  208. /***********************************************************************************************
  209. * GadgetClass::Remove -- Removes the specified gagdet from the list. *
  210. * *
  211. * Use this routine if an individual gadget needs to be removed from the list of gadgets. *
  212. * *
  213. * INPUT: none *
  214. * *
  215. * OUTPUT: bool; Was the specified gadget found and removed? A false indicates that the *
  216. * gadget wasn't in the list. *
  217. * *
  218. * WARNINGS: none *
  219. * *
  220. * HISTORY: *
  221. * 01/15/1995 JLB : Created. *
  222. *=============================================================================================*/
  223. GadgetClass * GadgetClass::Remove(void)
  224. {
  225. Clear_Focus();
  226. return(GadgetClass *)LinkClass::Remove();
  227. }
  228. /***********************************************************************************************
  229. * GadgetClass::Get_Next -- Returns a pointer to the next gadget in the chain. *
  230. * *
  231. * This returns with the next gadget's pointer. It is identical to the base Get_Next() *
  232. * function, but returns a pointer to a GadgetClass object. *
  233. * *
  234. * INPUT: none *
  235. * *
  236. * OUTPUT: Returns with a pointer to the next gadget in the list. *
  237. * *
  238. * WARNINGS: none *
  239. * *
  240. * HISTORY: *
  241. * 01/15/1995 JLB : Created. *
  242. *=============================================================================================*/
  243. GadgetClass * GadgetClass::Get_Next(void) const
  244. {
  245. return(GadgetClass*)LinkClass::Get_Next();
  246. }
  247. /***********************************************************************************************
  248. * GadgetClass::Get_Prev -- Fetches a pointer to the previous gadget. *
  249. * *
  250. * This routine will return the previous gadget in the list. It is identical to the base *
  251. * function Get_Prev, but returns a pointer to a GadgetClass object. *
  252. * *
  253. * INPUT: none *
  254. * *
  255. * OUTPUT: Returns with a pointer to the previous gadget in the list. *
  256. * *
  257. * WARNINGS: none *
  258. * *
  259. * HISTORY: *
  260. * 01/15/1995 JLB : Created. *
  261. *=============================================================================================*/
  262. GadgetClass * GadgetClass::Get_Prev(void) const
  263. {
  264. return(GadgetClass*)LinkClass::Get_Prev();
  265. }
  266. /***********************************************************************************************
  267. * GadgetClass::Delete_List -- Deletes all gadget objects in list. *
  268. * *
  269. * This function will delete all gadgets in the list. It is the counterpart to the *
  270. * Create_One_Of functions. *
  271. * *
  272. * INPUT: none *
  273. * *
  274. * OUTPUT: none *
  275. * *
  276. * WARNINGS: Any references to these gadget become invalidated by this routine. *
  277. * *
  278. * HISTORY: *
  279. * 01/15/1995 JLB : Created. *
  280. *=============================================================================================*/
  281. void GadgetClass::Delete_List(void)
  282. {
  283. GadgetClass * g = this;
  284. /*
  285. ** Move to head of the list.
  286. */
  287. while (g->Get_Prev()) {
  288. g = g->Get_Prev();
  289. }
  290. /*
  291. ** First delete all the gadgets following the first one. The reason the first one
  292. ** is kept around is that sometimes deleting one gadget will result in related gadgets
  293. ** in the same list also being deleted. The first gadget will always contain the
  294. ** correct gadget pointer.
  295. */
  296. while (g) {
  297. g->Clear_Focus();
  298. GadgetClass * temp = g;
  299. g = g->Get_Next();
  300. delete temp;
  301. }
  302. }
  303. /***********************************************************************************************
  304. * GadgetClass::Action -- Base action for gadget. *
  305. * *
  306. * This handles the base level action that a gadget performs when a qualifying input event *
  307. * is detected. This sets the redraw flag and returns true (to stop further processing). *
  308. * If no qualifying input event was detected, but this routine was called anyway, then *
  309. * don't perform any action. The call to this routine, in that case, must have been forced *
  310. * for some other reason. *
  311. * *
  312. * INPUT: flag -- The input event bits that qualify for this gadget. A NULL indicates that *
  313. * no qualifying event occured. *
  314. * *
  315. * OUTPUT: bool; Should further gadget list processing be aborted? *
  316. * *
  317. * WARNINGS: none *
  318. * *
  319. * HISTORY: *
  320. * 01/15/1995 JLB : Created. *
  321. *=============================================================================================*/
  322. int GadgetClass::Action(unsigned flags, KeyNumType &)
  323. {
  324. /*
  325. ** If any of the event flags are active, then this indicates that something probably
  326. ** has changed the gadget. Flag the gadget to be redrawn. Also, make sure that
  327. ** any sticky flags are cleared up.
  328. */
  329. if (flags) {
  330. IsToRepaint = true;
  331. Sticky_Process(flags);
  332. return(true);
  333. }
  334. return(false);
  335. }
  336. /***********************************************************************************************
  337. * GadgetClass::Draw_Me -- Gadget redraw action (flag control). *
  338. * *
  339. * At this level, there is no actual rendering taking place with the call to Draw_Me, but *
  340. * the IsToRepaint flag must be cleared. Derived objects will call this routine and if it *
  341. * returns true, they will perform their custom rendering. *
  342. * *
  343. * INPUT: forced -- Is this redraw forced by outside circumstances? *
  344. * *
  345. * OUTPUT: bool; Should the gadget imagery be redrawn? *
  346. * *
  347. * WARNINGS: none *
  348. * *
  349. * HISTORY: *
  350. * 01/14/1995 JLB : Created. *
  351. *=============================================================================================*/
  352. int GadgetClass::Draw_Me(int forced)
  353. {
  354. if (forced || IsToRepaint) {
  355. IsToRepaint = false;
  356. return(true);
  357. }
  358. return(false);
  359. }
  360. /***********************************************************************************************
  361. * GadgetClass::Draw_All -- Forces all gadgets in list to be redrawn. *
  362. * *
  363. * Use this function to cause all gadget in the list to be redrawn regardless of the state *
  364. * of the IsToRepaint flag. *
  365. * *
  366. * INPUT: none *
  367. * *
  368. * OUTPUT: none *
  369. * *
  370. * WARNINGS: none *
  371. * *
  372. * HISTORY: *
  373. * 01/03/1995 MML : Created. *
  374. *=============================================================================================*/
  375. void GadgetClass::Draw_All(bool forced)
  376. {
  377. GadgetClass *gadget = this;
  378. while (gadget != NULL) {
  379. gadget->Draw_Me(forced);
  380. gadget = gadget->Get_Next();
  381. }
  382. }
  383. /***************************************************************************
  384. * GADGETCLASS::PROCESSLIST -- Check list for a mouse click within a gadget*
  385. * *
  386. * INPUT: none. *
  387. * *
  388. * OUTPUT: key pressed. *
  389. * *
  390. * WARNINGS: none. *
  391. * *
  392. * HISTORY: 01/03/1995 MML : Created. *
  393. *=========================================================================*/
  394. KeyNumType GadgetClass::Input(void)
  395. {
  396. int mousex, mousey;
  397. KeyNumType key;
  398. unsigned flags;
  399. int forced = false;
  400. /*
  401. ** Record this list so that a forced redraw only occurs the FIRST time the
  402. ** gadget list is passed to this routine.
  403. */
  404. if (LastList != this) {
  405. LastList = this;
  406. forced = true;
  407. StuckOn = NULL;
  408. Focused = NULL;
  409. }
  410. /*
  411. ** Fetch any pending keyboard input.
  412. */
  413. key = Keyboard::Check();
  414. if (key) {
  415. key = Keyboard::Get();
  416. }
  417. #ifdef SCENARIO_EDITOR
  418. if ( key == KN_K ){
  419. /*
  420. ** time to create a screen shot using the PCX code (if it works)
  421. */
  422. GraphicBufferClass temp_page( SeenBuff.Get_Width(),
  423. SeenBuff.Get_Height(),
  424. NULL,
  425. SeenBuff.Get_Width() * SeenBuff.Get_Height());
  426. char filename[30];
  427. SeenBuff.Blit(temp_page);
  428. for (int lp = 0; lp < 99; lp ++) {
  429. if (lp < 10) {
  430. sprintf(filename, "scrsht0%d.pcx", lp);
  431. } else {
  432. sprintf(filename, "scrsht%d.pcx", lp);
  433. }
  434. if (access(filename, F_OK) == -1)
  435. break;
  436. }
  437. Write_PCX_File(filename, temp_page, (unsigned char *)CurrentPalette);
  438. //Map.Place_Random_Crate();
  439. }
  440. #endif //SCENARIO_EDITOR
  441. /*
  442. ** For mouse button clicks, the mouse position is actually held in the MouseQ...
  443. ** globals rather than their normal Mouse... globals. This is because we need to
  444. ** know the position of the mouse at the exact instant when the click occured
  445. ** rather the the mouse position at the time we get around to this function.
  446. */
  447. if (((key&0x10FF) == KN_LMOUSE) || ((key&0x10FF) == KN_RMOUSE)) {
  448. mousex = _Kbd->MouseQX;
  449. mousey = _Kbd->MouseQY;
  450. } else {
  451. mousex = Get_Mouse_X();
  452. mousey = Get_Mouse_Y();
  453. }
  454. /*
  455. ** Set the mouse button state flags. These will be passed to the individual
  456. ** buttons so that they can determine what action to perform (if any).
  457. */
  458. flags = 0;
  459. if (key) {
  460. if (key == KN_LMOUSE) {
  461. flags |= LEFTPRESS;
  462. }
  463. if (key == KN_RMOUSE) {
  464. flags |= RIGHTPRESS;
  465. }
  466. if (key == (KN_LMOUSE | KN_RLSE_BIT)) {
  467. flags |= LEFTRELEASE;
  468. }
  469. if (key == (KN_RMOUSE | KN_RLSE_BIT)) {
  470. flags |= RIGHTRELEASE;
  471. }
  472. }
  473. /*
  474. ** If the mouse wasn't responsible for this key code, then it must be from
  475. ** the keyboard. Flag this fact.
  476. */
  477. if (key && !flags) {
  478. flags |= KEYBOARD;
  479. }
  480. /*
  481. ** Mouse button up or down action is ignored if there is a keyboard event. This
  482. ** allows keyboard events to fall through normally even if the mouse is over a
  483. ** gadget that is flagged for LEFTUP or RIGHTUP.
  484. */
  485. if (!key) {
  486. /*
  487. ** Check for the mouse being held down. We can't use the normal input system
  488. ** for this, so we must examine the actual current state of the mouse
  489. ** buttons. As a side note, if we determine that the mouse button isn't being
  490. ** held down, then we automatically know that it must be up -- set the flag
  491. ** accordingly.
  492. */
  493. if (Keyboard::Down(KN_LMOUSE)) {
  494. flags |= LEFTHELD;
  495. } else {
  496. flags |= LEFTUP;
  497. }
  498. if (Keyboard::Down(KN_RMOUSE)) {
  499. flags |= RIGHTHELD;
  500. } else {
  501. flags |= RIGHTUP;
  502. }
  503. }
  504. /*
  505. ** If "sticky" processing is active, then only process the stuck gadget.
  506. */
  507. if (StuckOn) {
  508. StuckOn->Draw_Me(false);
  509. StuckOn->Clicked_On(key, flags, mousex, mousey);
  510. if (StuckOn) {
  511. StuckOn->Draw_Me(false);
  512. }
  513. } else {
  514. /*
  515. ** If there is a gadget that has the keyboard focus, then route all keyboard
  516. ** events to it.
  517. */
  518. if (Focused && (flags & KEYBOARD)) {
  519. Focused->Draw_Me(false);
  520. Focused->Clicked_On(key, flags, mousex, mousey);
  521. if (Focused) {
  522. Focused->Draw_Me(false);
  523. }
  524. } else {
  525. /*
  526. ** Sweep through all the buttons in the chain and pass the current button state
  527. ** and keyboard input data to them. These routines will detect whether they should
  528. ** perform some action and return a flag to this effect. They also have the option
  529. ** of changing the key value so that an appropriate return value is use for this
  530. ** processing routine.
  531. */
  532. GadgetClass *next_button = this;
  533. while (next_button != NULL) {
  534. /*
  535. ** Maybe redraw the button if it needs to or is being forced to redraw.
  536. */
  537. next_button->Draw_Me(forced);
  538. if (!next_button->IsDisabled) {
  539. /*
  540. ** Process this button. If the button was recognized and action was
  541. ** performed, then bail from further processing (speed reasons?).
  542. */
  543. if (next_button->Clicked_On(key, flags, mousex, mousey)) {
  544. /*
  545. ** Some buttons will require repainting when they perform some action.
  546. ** Do so at this time.
  547. */
  548. next_button->Draw_Me(false);
  549. break;
  550. }
  551. }
  552. next_button = next_button->Get_Next();
  553. }
  554. }
  555. }
  556. return(key);
  557. }
  558. /***********************************************************************************************
  559. * GadgetClass::Extract_Gadget -- Sweeps through the gadget chain to find gadget specified. *
  560. * *
  561. * This examines the gadget list looking for on that has the same ID as specified. If that *
  562. * gadget was found, then a pointer to it is returned. Since only ControlClass gadgets *
  563. * or ones derived from it can have an ID value, we know that the returned pointer is at *
  564. * least of the ControlClass type. *
  565. * *
  566. * INPUT: id -- The ID number to scan for. Zero is not a legal ID number and if passed in, *
  567. * a NULL will always be returned. *
  568. * *
  569. * OUTPUT: Returns with a pointer to the ControlClass gadget that has the matching ID number. *
  570. * If no matching gadget was found, then NULL is returned. *
  571. * *
  572. * WARNINGS: If there happens to be more than one gadget with a matching ID, this routine *
  573. * will return a pointer to the first one only. *
  574. * *
  575. * HISTORY: *
  576. * 01/16/1995 JLB : Created. *
  577. *=============================================================================================*/
  578. ControlClass * GadgetClass::Extract_Gadget(unsigned id)
  579. {
  580. GadgetClass * g = this;
  581. if (id) {
  582. while (g) {
  583. if (g->Get_ID() == id) {
  584. return((ControlClass *)g);
  585. }
  586. g = g->Get_Next();
  587. }
  588. }
  589. return(0);
  590. }
  591. /***********************************************************************************************
  592. * GadgetClass::Flag_To_Redraw -- Flags this gadget to be redrawn. *
  593. * *
  594. * Use this routine to flag the gadget to be redrawn. A gadget so flagged will have its *
  595. * Draw_Me function called at the next available opportunity. Usually, this is the next *
  596. * time the Input() function is called. *
  597. * *
  598. * INPUT: none *
  599. * *
  600. * OUTPUT: none *
  601. * *
  602. * WARNINGS: none *
  603. * *
  604. * HISTORY: *
  605. * 01/16/1995 JLB : Created. *
  606. *=============================================================================================*/
  607. void GadgetClass::Flag_To_Redraw(void)
  608. {
  609. IsToRepaint = true;
  610. }
  611. /***********************************************************************************************
  612. * GadgetClass::Sticky_Process -- Handles the sticky flag processing. *
  613. * *
  614. * This function examines the event flags and handles any "sticky" processing required. *
  615. * Sticky processing is when the button is flagged with the "IsSticky" bit and it will *
  616. * be processed to the exclusion of all other gadgets while the mouse button is held *
  617. * down. *
  618. * *
  619. * INPUT: flags -- The event flags that triggered the call to this routine. *
  620. * *
  621. * OUTPUT: none *
  622. * *
  623. * WARNINGS: none *
  624. * *
  625. * HISTORY: *
  626. * 01/16/1995 JLB : Created. *
  627. *=============================================================================================*/
  628. void GadgetClass::Sticky_Process(unsigned flags)
  629. {
  630. if (IsSticky && (flags & LEFTPRESS)) {
  631. StuckOn = this;
  632. }
  633. if (StuckOn == this && (flags & LEFTRELEASE)) {
  634. StuckOn = 0;
  635. }
  636. }
  637. /***********************************************************************************************
  638. * GadgetClass::Set_Focus -- Sets focus to this gadget. *
  639. * *
  640. * This will set the focus to this gadget regardless of any current focus setting. If there *
  641. * is another gadget that has focus, it will have its focus cleared before this gadget will *
  642. * get the focus. A focused gadget is one that has all keyboard input routed to it. *
  643. * *
  644. * INPUT: none *
  645. * *
  646. * OUTPUT: none *
  647. * *
  648. * WARNINGS: none *
  649. * *
  650. * HISTORY: *
  651. * 01/25/1995 JLB : Created. *
  652. *=============================================================================================*/
  653. void GadgetClass::Set_Focus(void)
  654. {
  655. if (Focused) {
  656. Focused->Flag_To_Redraw();
  657. Focused->Clear_Focus();
  658. }
  659. Flags |= KEYBOARD;
  660. Focused = this;
  661. }
  662. /***********************************************************************************************
  663. * GadgetClass::Clear_Focus -- Clears the focus if this gadget has it. *
  664. * *
  665. * Use this function to clear the focus for the gadget. If the gadget doesn't currently *
  666. * have focus, then this routine will do nothing. For added functionality, overload this *
  667. * virtual function so that gadget specific actions may be take when focus is lost. *
  668. * *
  669. * INPUT: none *
  670. * *
  671. * OUTPUT: none *
  672. * *
  673. * WARNINGS: none *
  674. * *
  675. * HISTORY: *
  676. * 01/25/1995 JLB : Created. *
  677. *=============================================================================================*/
  678. void GadgetClass::Clear_Focus(void)
  679. {
  680. if (Focused == this) {
  681. Flags &= ~KEYBOARD;
  682. Focused = 0;
  683. }
  684. }
  685. /***********************************************************************************************
  686. * GadgetClass::Has_Focus -- Checks if this object currently has the keyboard focus. *
  687. * *
  688. * If this object has the keyboard focus, then this routine will return true. When the *
  689. * gadget has keyboard focus, all keyboard events get routed to the gadget. *
  690. * *
  691. * INPUT: none *
  692. * *
  693. * OUTPUT: bool; Does this gadget have the keyboard focus? *
  694. * *
  695. * WARNINGS: none *
  696. * *
  697. * HISTORY: *
  698. * 01/21/1995 JLB : Created. *
  699. *=============================================================================================*/
  700. bool GadgetClass::Has_Focus(void)
  701. {
  702. return(this == Focused);
  703. }
  704. /***********************************************************************************************
  705. * GadgetClass::Is_List_To_Redraw -- tells if any gadget in the list needs redrawing *
  706. * *
  707. * This function is mostly for supporting HidPage drawing. If it returns true, it means *
  708. * the application needs to re-blit the HidPage forward, after calling the list's Input(). *
  709. * *
  710. * INPUT: none *
  711. * *
  712. * OUTPUT: true = an item needs redrawing, false = no items need redrawing *
  713. * *
  714. * WARNINGS: It is assumed 'this' is the head of the list. *
  715. * *
  716. * HISTORY: *
  717. * 01/03/1995 MML : Created. *
  718. *=============================================================================================*/
  719. int GadgetClass::Is_List_To_Redraw(void)
  720. {
  721. GadgetClass *gadget = this;
  722. while (gadget != NULL) {
  723. if (gadget->IsToRepaint)
  724. return (true);
  725. gadget = gadget->Get_Next();
  726. }
  727. return (false);
  728. }