Dialog Items AMS1.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Dialog items example for all AMS versions
  2. // Example contributed by Wazabbe and Sébastien Leurent
  3. #define USE_TI89 // Compile for TI-89
  4. #define USE_TI92PLUS // Compile for TI-92 Plus
  5. #define USE_V200 // Compile for V200
  6. // #define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
  7. #define MIN_AMS 100 // Compile for AMS 1.00 or higher
  8. #define SAVE_SCREEN // Save/Restore LCD Contents
  9. #include <tigcclib.h> // Include All Header Files
  10. static HANDLE FirstPopup,SecondPopup, ThirdPopup;
  11. static char EditBuffer[20], *SecondEditBuffer;
  12. static HANDLE BufferHandle;
  13. static unsigned short Options[5];
  14. extern void MenuWindow;
  15. asm("
  16. .align 2
  17. MenuWindow:
  18. dc.w MenuWindowFirstString-MenuWindow,2,5,18+100*0x100,3,0,0,0,-1,-1
  19. dc.w MT_TEXT+1,MW_1-MenuWindowFirstString
  20. dc.w MT_TEXT+2,MW_2-MenuWindowFirstString
  21. dc.w MT_TEXT+3+MT_CASCADE,MW_3-MenuWindowFirstString,MW_sub-MenuWindow
  22. dc.l -1
  23. MW_sub: dc.w MT_TEXT+4,MW_4-MenuWindowFirstString
  24. dc.w MT_TEXT+5,MW_5-MenuWindowFirstString
  25. dc.l -1
  26. MenuWindowFirstString:
  27. MW_1: .asciz \"MENU1\"
  28. MW_2: .asciz \"MENU2\"
  29. MW_3: .asciz \"SUBITEMS\"
  30. MW_4: .asciz \"MENU SUBITEM 1\"
  31. MW_5: .asciz \"MENU SUBITEM 2\"
  32. ");
  33. HANDLE GetPopup( unsigned short dlgId ) /* This function is called by DialogAddDynamicPulldown whenever it is needed */
  34. {
  35. if(dlgId == 5)
  36. {
  37. return FirstPopup;
  38. }
  39. else
  40. {
  41. return ThirdPopup;
  42. }
  43. }
  44. long CallBack( short dlgId, long Value ) /* This function is given as a pointer to DialogNew and can be called whenever it is needed */
  45. {
  46. unsigned short HitKey;
  47. HANDLE MenuHandle = H_NULL;
  48. switch( dlgId )
  49. {
  50. case 0:
  51. return TRUE;
  52. case 1:
  53. return TRUE;
  54. case 2:
  55. MenuHandle = HI_WORD(Value);
  56. HitKey = LO_WORD(Value);
  57. int result = -2;
  58. switch( HitKey )
  59. {
  60. case KEY_F1:
  61. return 0;
  62. case KEY_F2:
  63. return 3;
  64. case KEY_F3:
  65. while (result == -2)
  66. {
  67. result = MenuKey (MenuHandle, HitKey);
  68. }
  69. switch(result)
  70. {
  71. case 4:
  72. return 0;
  73. case 5:
  74. return 3;
  75. default:
  76. return 0;
  77. }
  78. default:
  79. return 1;
  80. }
  81. break;
  82. case 3:
  83. if (Options[1] == 20)
  84. {
  85. return DB_EXIT;
  86. }
  87. else
  88. {
  89. return DB_REDRAW_AND_CONTINUE;
  90. }
  91. break;
  92. case 4:
  93. if (0 == strcmp("EXIT", EditBuffer))
  94. return DB_EXIT;
  95. break;
  96. case 5:
  97. if (Options[2] == 20)
  98. return DB_EXIT;
  99. break;
  100. case 6:
  101. SecondEditBuffer = HeapDeref(BufferHandle);
  102. if (0 == strcmp("EXIT", SecondEditBuffer))
  103. return DB_EXIT;
  104. break;
  105. case 7:
  106. if (Options[3] == 30)
  107. {
  108. return DB_EXIT;
  109. }
  110. else
  111. {
  112. return DB_REDRAW_AND_CONTINUE;
  113. }
  114. break;
  115. case 8:
  116. return DB_REDRAW_AND_CONTINUE;
  117. break;
  118. case 9:
  119. if (Options[1] == 20)
  120. {
  121. return DB_EXIT;
  122. }
  123. else
  124. {
  125. return DB_REDRAW_AND_CONTINUE;
  126. }
  127. break;
  128. case DB_QACTIVE:
  129. return TRUE;
  130. break;
  131. case DB_GET_EDIT_HANDLE:
  132. return BufferHandle;
  133. break;
  134. default :
  135. return TRUE;
  136. break;
  137. }
  138. return TRUE;
  139. }
  140. void _main(void)
  141. {
  142. static WORD Key;
  143. BufferHandle = HeapAlloc (20 * sizeof(char));
  144. SecondEditBuffer = HeapDeref(BufferHandle);
  145. strcpy( SecondEditBuffer, "DYNAMIC" );
  146. // On AMS 1.xx, Menus made with MenuNew and MenuAddText can't have submenus
  147. //the help of MenuPoup explains this (pseudo-)structure
  148. if ((FirstPopup = PopupNew(NULL,0)))
  149. {
  150. PopupAddText( FirstPopup, -1, "ENTRY 1", 10 );
  151. PopupAddText( FirstPopup, -1, "EXIT DIALOG", 20 );
  152. PopupAddText( FirstPopup, -1, "ENTRY 2", 30 );
  153. }
  154. else return;
  155. if ((SecondPopup = PopupNew(NULL,0)))
  156. {
  157. PopupAddText( SecondPopup, -1, "ENTRY 1", 10 );
  158. PopupAddText( SecondPopup, -1, "ENTRY 2", 20 );
  159. }
  160. else return;
  161. if ((ThirdPopup = PopupNew(NULL,0)))
  162. {
  163. PopupAddText( ThirdPopup, -1, "ENTRY 1", 10);
  164. PopupAddText( ThirdPopup, -1, "ENTRY 2", 20);
  165. PopupAddText( ThirdPopup, -1, "EXIT", 30);
  166. }
  167. else return;
  168. #define ItemsNum 11
  169. #define Strings "Dialog Test\0Hpopup1\0Edit\0DPopup\0DEdit\0DPopup 2\0HPopup 2\0HPopup 1.2\0Static Text\0Exit"
  170. static SIZED_DIALOG(ItemsNum,sizeof(Strings)) DialogWindow={offsetof(SIZED_DIALOG(ItemsNum,0),String), ItemsNum,150, 93,(DialogNew_t) CallBack,
  171. {
  172. {//Scroll
  173. D_SCROLL_REGION,DF_SKIP | DF_CLR_ON_REDRAW,8,31,{.dScrollR={140,71,3,9,4,7,10}}
  174. },
  175. {//TiltleEx
  176. D_HEADER,DF_SKIP,0,0,{.dHeader={0,BT_OK,BT_CANCEL}}
  177. },
  178. {//Menu
  179. D_MENU,DF_SKIP,20,12,{.dMenu={&MenuWindow,0}}
  180. },
  181. {//PulldownEx
  182. D_HPOPUP,DF_SCROLLABLE, 8, 33,{.dHPopUp={12,0/*FirstPopup*/,0,1}}
  183. },
  184. {//RequestEx
  185. D_EDIT_FIELD,DF_SCROLLABLE, 8, 43,{.dEdit={20,0,10,10}}
  186. },
  187. {//DynamicPulldown
  188. D_DYNPOPUP,DF_SCROLLABLE, 8, 53,{.dDynPopUp={25,&GetPopup,2}}
  189. },
  190. {//DynamicRequest
  191. D_HEDIT,DF_SCROLLABLE, 8, 63,{.dEdit={32,0,0,10}}
  192. },
  193. {//DynamicPulldown
  194. D_DYNPOPUP,DF_SCROLLABLE, 8, 73,{.dDynPopUp={38,&GetPopup,3}}
  195. },
  196. {//PulldownEx
  197. D_HPOPUP,DF_SCROLLABLE, 8, 83,{.dHPopUp={47,0/*SecondPopup*/,0,4}}
  198. },
  199. {//PulldownEx
  200. D_HPOPUP,DF_SCROLLABLE, 8, 93,{.dHPopUp={56,0/* FirstPopup*/,0,1}}
  201. },
  202. {//Text
  203. D_TEXT,DF_SKIP, 98, 73,{.dText={67}}
  204. },
  205. {//End , verry important
  206. .f={}
  207. }
  208. },
  209. Strings
  210. };
  211. //It is static so that it can include pointers (such as Callback) but no Var.
  212. // Therefore fields with vars must be initialized separately:
  213. DialogWindow.Fields[3].f.dHPopUp.hPopUp=FirstPopup;
  214. DialogWindow.Fields[8].f.dHPopUp.hPopUp=SecondPopup;
  215. DialogWindow.Fields[9].f.dHPopUp.hPopUp=FirstPopup;
  216. Options[0] = 10;
  217. Options[1] = 10;
  218. Options[2] = 10;
  219. Options[3] = 20;
  220. strcpy( EditBuffer, "TEST" );
  221. do
  222. {
  223. Dialog((DIALOG *) &DialogWindow,-1, -1, &EditBuffer[0], &Options[0] );
  224. Key = DlgMessage("Exit ?", "exit : ESC ; else : ENTER", BT_OK, BT_CANCEL );
  225. } while (KEY_ESC != Key);
  226. HeapFree( FirstPopup );
  227. HeapFree( SecondPopup );
  228. HeapFree( ThirdPopup );
  229. }