Field.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * Field.c
  6. *
  7. * Copyright (C) 2000-2002 Pieter Spronck, All Rights Reserved
  8. *
  9. * Additional coding by Sam Anderson (rulez2@home.com)
  10. * Additional coding by Samuel Goldstein (palm@fogbound.net)
  11. *
  12. * Some code of Matt Lee's Dope Wars program has been used.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. *
  28. * You can contact the author at space_trader@hotmail.com
  29. *
  30. * For those who are familiar with the classic game Elite: many of the
  31. * ideas in Space Trader are heavily inspired by Elite.
  32. *
  33. **********************************************************************/
  34. // *************************************************************************
  35. // Field.c - Functions Include:
  36. // Handle SetField( FormPtr frm, int Nr, char* Value, int Size, Boolean Focus )
  37. // void GetField( FormPtr frm, int Nr, char* Value, Handle AmountH )
  38. // void SetCheckBox( FormPtr frm, int Nr, Boolean Value )
  39. // Boolean GetCheckBox( FormPtr frm, int Nr )
  40. //
  41. // Modifications:
  42. // mm/dd/yy - description - author
  43. // *************************************************************************
  44. #include "external.h"
  45. // *************************************************************************
  46. // Set Field
  47. // *************************************************************************
  48. Handle SetField( FormPtr frm, int Nr, char* Value, int Size, Boolean Focus )
  49. {
  50. Word objIndex;
  51. CharPtr AmountP;
  52. Handle AmountH;
  53. objIndex = FrmGetObjectIndex( frm, Nr );
  54. AmountH = MemHandleNew( Size );
  55. AmountP = MemHandleLock( AmountH );
  56. StrCopy( AmountP, Value );
  57. MemPtrUnlock( AmountP );
  58. FldSetTextHandle( FrmGetObjectPtr( frm, objIndex ), AmountH );
  59. if (Focus)
  60. FrmSetFocus( frm, objIndex );
  61. return AmountH;
  62. }
  63. // *************************************************************************
  64. // Get Field
  65. // *************************************************************************
  66. void GetField( FormPtr frm, int Nr, char* Value, Handle AmountH )
  67. {
  68. Word objIndex;
  69. CharPtr AmountP;
  70. objIndex = FrmGetObjectIndex( frm, Nr );
  71. FldSetTextHandle( FrmGetObjectPtr( frm, objIndex ), 0 );
  72. AmountP = MemHandleLock( AmountH );
  73. StrCopy( Value, AmountP );
  74. MemPtrUnlock( AmountP );
  75. MemHandleFree( AmountH );
  76. }
  77. // *************************************************************************
  78. // Set Trigger List value
  79. // *************************************************************************
  80. void SetTriggerList( FormPtr frm, int Nr, int Index )
  81. {
  82. Word objIndex;
  83. ControlPtr cp;
  84. objIndex = FrmGetObjectIndex( frm, Nr );
  85. cp = (ControlPtr)FrmGetObjectPtr( frm, objIndex );
  86. LstSetSelection( cp, Index );
  87. }
  88. // *************************************************************************
  89. // Set Control Label
  90. // *************************************************************************
  91. void SetControlLabel( FormPtr frm, int Nr, Char * Label )
  92. {
  93. Word objIndex;
  94. ControlPtr cp;
  95. objIndex = FrmGetObjectIndex( frm, Nr );
  96. cp = (ControlPtr)FrmGetObjectPtr( frm, objIndex );
  97. CtlSetLabel( cp, Label );
  98. }
  99. // *************************************************************************
  100. // Get Trigger List value
  101. // *************************************************************************
  102. int GetTriggerList( FormPtr frm, int Nr)
  103. {
  104. Word objIndex;
  105. ControlPtr cp;
  106. objIndex = FrmGetObjectIndex( frm, Nr );
  107. cp = (ControlPtr)FrmGetObjectPtr( frm, objIndex );
  108. return LstGetSelection( cp );
  109. }
  110. // *************************************************************************
  111. // Set Checkbox value
  112. // *************************************************************************
  113. void SetCheckBox( FormPtr frm, int Nr, Boolean Value )
  114. {
  115. Word objIndex;
  116. ControlPtr cp;
  117. objIndex = FrmGetObjectIndex( frm, Nr );
  118. cp = (ControlPtr)FrmGetObjectPtr( frm, objIndex );
  119. CtlSetValue( cp, (Value ? 1 : 0) );
  120. }
  121. // *************************************************************************
  122. // Get Checkbox value
  123. // *************************************************************************
  124. Boolean GetCheckBox( FormPtr frm, int Nr )
  125. {
  126. Word objIndex;
  127. ControlPtr cp;
  128. objIndex = FrmGetObjectIndex( frm, Nr );
  129. cp = (ControlPtr)FrmGetObjectPtr( frm, objIndex );
  130. if (CtlGetValue( cp ) == 0)
  131. return false;
  132. else
  133. return true;
  134. }