Dialog Items.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. // Dialog items example for AMS 2.00 or higher
  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 MIN_AMS 200 // Compile for AMS 2.00 or higher
  7. #define SAVE_SCREEN // Save/Restore LCD Contents
  8. #include <tigcclib.h> // Include All Header Files
  9. static HANDLE FirstPopup, SecondPopup, ThirdPopup,BeginPopup,ExitPopup,EmptyPopup;
  10. static HANDLE MenuWindow;
  11. static char EditBuffer[20], *SecondEditBuffer;
  12. static HANDLE BufferHandle;
  13. static unsigned short Options[6];
  14. static BITMAP unselected=
  15. {
  16. 8,9,
  17. {
  18. 0b11111111,0b10000000,
  19. 0b10000000,0b10000000,
  20. 0b10000000,0b10000000,
  21. 0b10000000,0b10000000,
  22. 0b10000000,0b10000000,
  23. 0b10000000,0b10000000,
  24. 0b10000000,0b10000000,
  25. 0b11111111,0b10000000,
  26. }
  27. };
  28. static BITMAP selected=
  29. {
  30. 8,9,
  31. {
  32. 0b11111111,0b10000000,
  33. 0b10000000,0b10000000,
  34. 0b10000010,0b10000000,
  35. 0b10000100,0b10000000,
  36. 0b10101000,0b10000000,
  37. 0b10010000,0b10000000,
  38. 0b10000000,0b10000000,
  39. 0b11111111,0b10000000,
  40. }
  41. };
  42. enum Items {Scroll_ID,Title_ID,Toolbar_ID,HPopup1_ID,Edit_ID,DPopup1_ID,DEdit_ID,DPopup2_ID,HPopup2_ID,Radio_ID,Exit_ID,OwnerDrawn_ID,Text_ID,XFlags_ID};
  43. #define ItemHeight 10
  44. #define FirstScrollableItemID 3
  45. #define FirstScrollableItemY 33
  46. #define ScrollableItemY(ID) (FirstScrollableItemY+ItemHeight*(ID-FirstScrollableItemID))
  47. HANDLE GetPopup( unsigned short dlgId ) /* This function is called by DialogAddDynamicPulldown whenever it is needed */
  48. {
  49. if(dlgId == DPopup1_ID)
  50. {
  51. return FirstPopup;
  52. }
  53. else
  54. {
  55. return ThirdPopup;
  56. }
  57. }
  58. unsigned short Scroll;
  59. short CallBack( short dlgId, long Value ) /* This function is given as a pointer to DialogNew and can be called whenever it is needed */
  60. {
  61. unsigned short HitKey;
  62. HANDLE MenuHandle = H_NULL;
  63. DIALOG_ITEMS *DlogItems;
  64. WINDOW *WindowStruct;
  65. switch( dlgId )
  66. {
  67. case DB_QACTIVE:
  68. /*When the dialog is scrolled, DB_QACTIVE is sent to all visible items.
  69. It enables to know wich Items are visible, and to change scrolling acording to this.*/
  70. if(Value>=3 && Value<=10)//scrollable Item (other ones are always visible
  71. {
  72. #define ItemY ((Value-FirstScrollableItemID)*ItemHeight)
  73. #define YMaxScrolled (Scroll+ItemHeight*3/*since four Items are disped at a time*/)
  74. //Item Y is the ordinate of this Item, Scroll must be the ordinate of the first visible Item
  75. //and YMaxScrolled is the Ordinate of the last visible Item
  76. //These ordinates are relative to the top of the scroll region
  77. if(ItemY<Scroll) Scroll-=ItemHeight;
  78. //If with the current value of scroll, this item is not visible (too high up),
  79. //It means that it has been scrolled and the value of Scroll must be changed, by substracting ItemHeight
  80. if(ItemY>YMaxScrolled) Scroll+=ItemHeight;
  81. //If with the current value of scroll, this item is not visible (too high down),
  82. //It means that it has been scrolled and the value of Scroll must be changed, by adding ItemHeight
  83. #undef ItemY
  84. #undef YMaxScrolled
  85. }
  86. break;
  87. case Scroll_ID:
  88. return TRUE;
  89. case Title_ID:
  90. return TRUE;
  91. case Toolbar_ID:
  92. MenuHandle = HI_WORD(Value);
  93. HitKey = LO_WORD(Value);
  94. int result = -2;
  95. switch( HitKey )
  96. {
  97. case KEY_F1:
  98. Scroll=0;
  99. return 0;
  100. case KEY_F2:
  101. Scroll=4*ItemHeight;
  102. return 4;
  103. case KEY_F3:
  104. while (result == -2)
  105. {
  106. result = MenuKey (MenuHandle, HitKey);
  107. }
  108. switch(result)
  109. {
  110. case 4:
  111. Scroll=0;return 0;
  112. case 5:
  113. Scroll=4*ItemHeight;return 4;
  114. case 6:
  115. return DB_EXIT;
  116. default:
  117. Scroll=0;
  118. return 0;
  119. }
  120. default:
  121. return 1;
  122. }
  123. break;
  124. case HPopup1_ID:
  125. if (Options[1] == 20)
  126. {
  127. return DB_EXIT;
  128. }
  129. else
  130. {
  131. return DB_REDRAW_AND_CONTINUE;
  132. }
  133. break;
  134. case Edit_ID:
  135. if (0 == strcmp("EXIT", EditBuffer))
  136. return DB_EXIT;
  137. break;
  138. case DPopup1_ID:
  139. if (Options[2] == 20)
  140. return DB_EXIT;
  141. break;
  142. case DEdit_ID:
  143. SecondEditBuffer = HeapDeref(BufferHandle);
  144. if (0 == strcmp("EXIT", SecondEditBuffer))
  145. return DB_EXIT;
  146. break;
  147. case DPopup2_ID:
  148. if (Options[3] == 30)
  149. {
  150. return DB_EXIT;
  151. }
  152. else
  153. {
  154. return DB_REDRAW_AND_CONTINUE;
  155. }
  156. break;
  157. case HPopup2_ID:
  158. return DB_REDRAW_AND_CONTINUE;
  159. break;
  160. case Radio_ID:
  161. return DB_REDRAW_AND_CONTINUE;
  162. case Exit_ID:
  163. return DB_EXIT;
  164. case OwnerDrawn_ID:
  165. DlogItems = (DIALOG_ITEMS *)(((OWNER_DRAW_STRUCT *)Value)->Item);
  166. WindowStruct = (WINDOW *)(((OWNER_DRAW_STRUCT *)Value)->pW);
  167. char Buffer[sizeof("Scroll : xx")];
  168. sprintf(Buffer,"Scroll : %d",Scroll);
  169. WinStrXY( (WindowStruct), 8, 73, Buffer);
  170. WinAttr( (WindowStruct), A_XOR);
  171. // If it is visible, disp my RadioButton
  172. if(Scroll>=30)
  173. {
  174. WinStrXY( (WindowStruct), 8, 93-Scroll, "Show Msg");
  175. WinBitmapPut (WindowStruct, CALCULATOR?63:42, (CALCULATOR?92:91)-Scroll, (Options[5]==1)?&selected:&unselected,A_REPLACE);
  176. }
  177. break;
  178. case DB_GET_EDIT_HANDLE:
  179. return BufferHandle;
  180. break;
  181. default :
  182. return TRUE;
  183. break;
  184. }
  185. return TRUE;
  186. }
  187. void _main(void)
  188. {
  189. static HANDLE DialogWindow;
  190. static WORD Key;
  191. BufferHandle = HeapAlloc (20 * sizeof(char));
  192. SecondEditBuffer = HeapDeref(BufferHandle);
  193. strcpy( SecondEditBuffer, "DYNAMIC" );
  194. if ((MenuWindow = MenuNew(0,0,0)))
  195. {
  196. MenuAddText( MenuWindow, 0, "MENU1", 1, DMF_TOP );
  197. MenuAddText( MenuWindow, 0, "MENU2", 2, DMF_TOP );
  198. MenuAddText( MenuWindow, 0, "SUBITEMS", 3, DMF_TOP_SUB );
  199. MenuAddText( MenuWindow, 3, "MENU SUBITEM 1", 4, DMF_CHILD_SUB );
  200. MenuAddText( MenuWindow, 3, "MENU SUBITEM 2", 5, DMF_CHILD_SUB );
  201. MenuAddText( MenuWindow, 3, "EXIT", 6, DMF_CHILD_SUB );
  202. }
  203. else return;
  204. if ((FirstPopup = PopupNew(NULL,0)))
  205. {
  206. PopupAddText( FirstPopup, -1, "ENTRY 1", 10 );
  207. PopupAddText( FirstPopup, -1, "EXIT DIALOG", 20 );
  208. PopupAddText( FirstPopup, -1, "ENTRY 2", 30 );
  209. }
  210. else return;
  211. if ((SecondPopup = PopupNew(NULL,0)))
  212. {
  213. PopupAddText( SecondPopup, -1, "ENTRY 1", 1 );
  214. PopupAddText( SecondPopup, -1, "ENTRY 2", 2 );
  215. }
  216. else return;
  217. if ((ThirdPopup = PopupNew(NULL,0)))
  218. {
  219. PopupAddText( ThirdPopup, -1, "ENTRY 1", 10);
  220. PopupAddText( ThirdPopup, -1, "ENTRY 2", 20);
  221. PopupAddText( ThirdPopup, -1, "EXIT", 30);
  222. }
  223. if ((BeginPopup = PopupNew(NULL,0)))
  224. {
  225. PopupAddText( BeginPopup, -1, "Use DIALOG_STRUCT", 10);
  226. PopupAddText( BeginPopup, -1, "Use DialogNew", 20);
  227. }
  228. else return;
  229. if((ExitPopup=PopupNew(NULL,0)))
  230. {
  231. PopupAddText( ExitPopup, -1, "Right arrow to exit",1);
  232. }
  233. else return;
  234. if ((EmptyPopup = PopupNew(NULL,0)))
  235. {
  236. PopupAddText( EmptyPopup, -1, "Toggle", 1);
  237. PopupAddText( EmptyPopup, -1, "Toggle", 2);
  238. }
  239. else return;
  240. if ((DialogWindow = DialogNew( 0,0, (DialogNew_t) CallBack)))
  241. {
  242. DialogAddScrollRegion( DialogWindow, DF_CLR_ON_REDRAW, 8, 31,140, 71,FirstScrollableItemID,10,4,8,ItemHeight );
  243. DialogAddTitleEx( DialogWindow, 0, "Dialog Test", BT_OK, BT_CANCEL);
  244. DialogAddMenu( DialogWindow, 0, 0, 12, HLock(MenuWindow), 60 );
  245. DialogAddPulldownEx( DialogWindow, DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(HPopup1_ID), "HPopup 1", FirstPopup, 1);
  246. DialogAddRequestEx( DialogWindow, DF_TAB_ELLIPSES | DF_SCROLLABLE, 8,ScrollableItemY(Edit_ID), "Edit", 0, 10, 10);
  247. DialogAddDynamicPulldown( DialogWindow, DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(DPopup1_ID), "DPopup", &GetPopup, 2 );
  248. DialogAddDynamicRequest( DialogWindow, DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(DEdit_ID), "DEdit", 10);
  249. DialogAddDynamicPulldown( DialogWindow, DF_TAB_ELLIPSES | DF_SCROLLABLE, 8,ScrollableItemY(DPopup2_ID), "DPopup 2", &GetPopup, 3 );
  250. DialogAddPulldownEx( DialogWindow, DF_TAB_ELLIPSES | DF_SCROLLABLE | DF_POPUP_RADIO, 8,ScrollableItemY(HPopup2_ID), "HPopup 2", SecondPopup, 4);
  251. DialogAddPulldownEx( DialogWindow, DF_SCROLLABLE | DF_POPUP_RADIO,(CALCULATOR?75:53),ScrollableItemY(Radio_ID), "", EmptyPopup, 5);
  252. DialogAddPulldownEx( DialogWindow, DF_POPUP_RADIO | DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(Exit_ID), "Exit", ExitPopup,0);
  253. DialogAddTextEx( DialogWindow, DF_OWNER_DRAW, 0, 0, "");
  254. DialogAddTextEx( DialogWindow, 0, 98, 73, "Static Text");
  255. DialogAddXFlags( DialogWindow, 0, XF_VARLINK_SELECT_ONLY,0, 0, 0);
  256. }
  257. else return;
  258. #define ItemsNum 14
  259. #define Strings "Dialog Test\0Hpopup1\0Edit\0DPopup\0DEdit\0DPopup 2\0HPopup 2\0Exit\0Static Text"
  260. static SIZED_DIALOG(ItemsNum,sizeof(Strings)) DialogWindowB={offsetof(SIZED_DIALOG(ItemsNum,0),String), ItemsNum,0, 0,(DialogNew_t) CallBack,
  261. {
  262. {//Scroll
  263. D_SCROLL_REGION,DF_SKIP | DF_CLR_ON_REDRAW,8,31,{.dScrollR={140,71,FirstScrollableItemID,10,4,8,ItemHeight}}
  264. },
  265. {//TiltleEx
  266. D_HEADER,DF_SKIP,0,0,{.dHeader={0,BT_OK,BT_CANCEL}}
  267. },
  268. {//Menu
  269. D_MENU,DF_SKIP,0,12,{.dMenu={0/*will be replaced by HLock(MenuWindow) later*/,60}}
  270. },
  271. {//PulldownEx
  272. D_HPOPUP,DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(HPopup1_ID),{.dHPopUp={12,0/*FirstPopup*/,0,1}}
  273. },
  274. {//RequestEx
  275. D_EDIT_FIELD,DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(Edit_ID),{.dEdit={20,0,10,10}}
  276. },
  277. {//DynamicPulldown
  278. D_DYNPOPUP,DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(DPopup1_ID),{.dDynPopUp={25,&GetPopup,2}}
  279. },
  280. {//DynamicRequest
  281. D_HEDIT,DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(DEdit_ID),{.dEdit={32,0,0,10}}
  282. },
  283. {//DynamicPulldown
  284. D_DYNPOPUP,DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(DPopup2_ID),{.dDynPopUp={38,&GetPopup,3}}
  285. },
  286. {//PulldownEx
  287. D_HPOPUP,DF_TAB_ELLIPSES | DF_SCROLLABLE | DF_POPUP_RADIO, 8, ScrollableItemY(HPopup2_ID),{.dHPopUp={47,0/* SecondPopup*/,0,4}}
  288. },
  289. {//PulldownEx
  290. D_HPOPUP, DF_SCROLLABLE | DF_POPUP_RADIO, 0/*to be changed*/, ScrollableItemY(Radio_ID),{.dHPopUp={11,0/* EmptyPopup*/,0,5}}
  291. },
  292. {//PulldownEx
  293. D_HPOPUP,DF_POPUP_RADIO | DF_TAB_ELLIPSES | DF_SCROLLABLE, 8, ScrollableItemY(Exit_ID),{.dHPopUp={56,0/* ExitPopup*/,0,0}}
  294. },
  295. {//TextEx
  296. D_TEXT,DF_OWNER_DRAW | DF_SKIP, 0, 0,{.dText={11}}
  297. },
  298. {//Text, again
  299. D_TEXT,DF_SKIP, 98, 73,{.dText={61}}
  300. },
  301. {//Xflags
  302. D_XFLAGS,DF_SKIP,0,0,{.dFlags={{XF_VARLINK_SELECT_ONLY,0, 0, 0}}}
  303. },
  304. {//End , verry important
  305. .f={}
  306. }
  307. },
  308. Strings
  309. };
  310. //It is static so that it can include pointers (such as Callback) but no Var.
  311. // Therefore fields with vars must be initialized separately:
  312. DialogWindowB.Fields[2].f.dMenu.Menu=HLock(MenuWindow);
  313. DialogWindowB.Fields[3].f.dHPopUp.hPopUp=FirstPopup;
  314. DialogWindowB.Fields[8].f.dHPopUp.hPopUp=SecondPopup;
  315. DialogWindowB.Fields[9].f.dHPopUp.hPopUp=EmptyPopup;
  316. DialogWindowB.Fields[9].x0=CALCULATOR?75:53;
  317. DialogWindowB.Fields[10].f.dHPopUp.hPopUp=ExitPopup;
  318. Scroll=0;
  319. Options[0] = 10;
  320. Options[1] = 10;
  321. Options[2] = 10;
  322. Options[3] = 20;
  323. Options[4] = 1;
  324. Options[5] = 1;
  325. strcpy( EditBuffer, "TEST" );
  326. do
  327. {
  328. Scroll=0;
  329. if(PopupDo (BeginPopup, CENTER, CENTER, 10)==10)
  330. Dialog((DIALOG *) &DialogWindowB,-1, -1, &EditBuffer[0], &Options[0] );
  331. else
  332. DialogDo( DialogWindow, -1, -1, &EditBuffer[0], &Options[0] );
  333. if(Options[5]==1) Key = DlgMessage("Exit ?", "If you wish to completely exit press ESC, else press ENTER", BT_OK, BT_CANCEL );
  334. } while (Options[5]==1 && KEY_ESC != Key);
  335. HeapFree(EmptyPopup);
  336. HeapFree( ExitPopup);
  337. HeapFree( DialogWindow );
  338. HeapFree( FirstPopup );
  339. HeapFree( SecondPopup );
  340. HeapFree( ThirdPopup );
  341. HeapFree( BeginPopup );
  342. HeapUnlock( MenuWindow );
  343. HeapFree( MenuWindow );
  344. }