testapp.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. PROGRAM TestApp;
  2. { $UNDEF OS2PM}
  3. {$IFDEF OS2PM}
  4. {&PMTYPE PM} { FULL GUI MODE }
  5. {$ENDIF OS2PM}
  6. { ******************************* REMARK ****************************** }
  7. { This is a basic test program to test the app framework. In use will }
  8. { be menus, statuslines, windows, dialogs, scrollbars, statictext, }
  9. { radiobuttons, check boxes, list boxes and input lines. }
  10. { }
  11. { Working compilers: }
  12. { WINDOWS BPW, VP2, Delphi1, FPC WIN (0.9912) }
  13. { DOS has draw bugs but works for BP and FPC DOS (GO32V2) }
  14. { OS2 dows not work still some PM bits to do }
  15. { }
  16. { Not working: }
  17. { Delphi3, Delphi5 (sus 4) will compile but Tgroup.ForEach etc U/S. }
  18. { Sybil2 Win32 should work but to big for demo mode so unsure! }
  19. { }
  20. { Special things to try out: }
  21. { Check out the standard windows minimize etc icons. }
  22. { }
  23. { }
  24. { Comments: }
  25. { There is alot that may seem more complex than it needs to but }
  26. { I have much more elaborate objects operating such as bitmaps, }
  27. { bitmap buttons, percentage bars etc and they need these hooks. }
  28. { Basically the intention is to be able to port existing TV apps }
  29. { as a start point and then start to optimize and use the new }
  30. { GUI specific objects. I will try to get some documentation }
  31. { done on how everything works because some things are hard to }
  32. { follow in windows. }
  33. { ****************************** END REMARK *** Leon de Boer, 06Nov99 * }
  34. {$I Platform.inc}
  35. USES
  36. {$IFDEF OS2PM}
  37. {$IFDEF OS_OS2} Os2Def, os2PmApi, {$ENDIF}
  38. {$ENDIF OS2PM}
  39. Objects, Drivers, Views, Menus, Dialogs, App, { Standard GFV units }
  40. FVConsts,
  41. {$ifdef TEST}
  42. AsciiTab,
  43. {$endif TEST}
  44. {$ifdef DEBUG}
  45. Gfvgraph,
  46. {$endif DEBUG}
  47. Gadgets, TimedDlg, MsgBox;
  48. CONST cmAppToolbar = 1000;
  49. cmWindow1 = 1001;
  50. cmWindow2 = 1002;
  51. cmWindow3 = 1003;
  52. cmTimedBox = 1004;
  53. cmAscii = 1010;
  54. cmCloseWindow1 = 1101;
  55. cmCloseWindow2 = 1102;
  56. cmCloseWindow3 = 1103;
  57. {---------------------------------------------------------------------------}
  58. { TTestAppp OBJECT - STANDARD APPLICATION WITH MENU }
  59. {---------------------------------------------------------------------------}
  60. TYPE
  61. PTVDemo = ^TTVDemo;
  62. TTVDemo = OBJECT (TApplication)
  63. Clock: PClockView;
  64. Heap: PHeapView;
  65. P1,P2,P3 : PGroup;
  66. {$ifdef TEST}
  67. ASCIIChart : PAsciiChart;
  68. {$endif TEST}
  69. CONSTRUCTOR Init;
  70. PROCEDURE Idle; Virtual;
  71. PROCEDURE HandleEvent(var Event : TEvent);virtual;
  72. PROCEDURE InitMenuBar; Virtual;
  73. PROCEDURE InitDeskTop; Virtual;
  74. PROCEDURE Window1;
  75. PROCEDURE Window2;
  76. PROCEDURE Window3;
  77. PROCEDURE TimedBox;
  78. PROCEDURE AsciiWindow;
  79. PROCEDURE CloseWindow(var P : PGroup);
  80. End;
  81. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  82. { TTvDemo OBJECT METHODS }
  83. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  84. CONSTRUCTOR TTvDemo.Init;
  85. VAR R: TRect;
  86. BEGIN
  87. Inherited Init;
  88. { Initialize demo gadgets }
  89. GetExtent(R);
  90. R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
  91. Clock := New(PClockView, Init(R));
  92. Insert(Clock);
  93. GetExtent(R);
  94. Dec(R.B.X);
  95. R.A.X := R.B.X - 12; R.A.Y := R.B.Y - 1;
  96. Heap := New(PHeapView, Init(R));
  97. Insert(Heap);
  98. END;
  99. procedure TTVDemo.Idle;
  100. function IsTileable(P: PView): Boolean; far;
  101. begin
  102. IsTileable := (P^.Options and ofTileable <> 0) and
  103. (P^.State and sfVisible <> 0);
  104. end;
  105. {$ifdef DEBUG}
  106. Var
  107. WasSet : boolean;
  108. {$endif DEBUG}
  109. begin
  110. inherited Idle;
  111. {$ifdef DEBUG}
  112. if WriteDebugInfo then
  113. begin
  114. WasSet:=true;
  115. WriteDebugInfo:=false;
  116. end
  117. else
  118. WasSet:=false;
  119. if WriteDebugInfo then
  120. {$endif DEBUG}
  121. Clock^.Update;
  122. Heap^.Update;
  123. {$ifdef DEBUG}
  124. if WasSet then
  125. WriteDebugInfo:=true;
  126. {$endif DEBUG}
  127. if Desktop^.FirstThat(@IsTileable) <> nil then
  128. EnableCommands([cmTile, cmCascade])
  129. else
  130. DisableCommands([cmTile, cmCascade]);
  131. end;
  132. PROCEDURE TTVDemo.HandleEvent(var Event : TEvent);
  133. BEGIN
  134. Inherited HandleEvent(Event); { Call ancestor }
  135. If (Event.What = evCommand) Then Begin
  136. Case Event.Command Of
  137. cmWindow1 : Window1;
  138. cmWindow2 : Window2;
  139. cmWindow3 : Window3;
  140. cmTimedBox: TimedBox;
  141. cmAscii : AsciiWindow;
  142. cmCloseWindow1 : CloseWindow(P1);
  143. cmCloseWindow2 : CloseWindow(P2);
  144. cmCloseWindow3 : CloseWindow(P3);
  145. Else Exit; { Unhandled exit }
  146. End;
  147. End;
  148. ClearEvent(Event);
  149. END;
  150. {--TTvDemo------------------------------------------------------------------}
  151. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Nov99 LdB }
  152. {---------------------------------------------------------------------------}
  153. PROCEDURE TTVDemo.InitMenuBar;
  154. VAR R: TRect;
  155. BEGIN
  156. GetExtent(R); { Get view extents }
  157. R.B.Y := R.A.Y + 1; { One line high }
  158. MenuBar := New(PMenuBar, Init(R, NewMenu(
  159. NewSubMenu('~F~ile', 0, NewMenu(
  160. StdFileMenuItems(Nil)), { Standard file menu }
  161. NewSubMenu('~E~dit', 0, NewMenu(
  162. StdEditMenuItems(Nil)), { Standard edit menu }
  163. NewSubMenu('~T~est', 0, NewMenu(
  164. NewItem('Ascii Chart','',kbNoKey,cmAscii,hcNoContext,
  165. NewItem('Window 1','',kbNoKey,cmWindow1,hcNoContext,
  166. NewItem('Window 2','',kbNoKey,cmWindow2,hcNoContext,
  167. NewItem('Window 3','',kbNoKey,cmWindow3,hcNoContext,
  168. NewItem('Timed Box','',kbNoKey,cmTimedBox,hcNoContext,
  169. NewItem('Close Window 1','',kbNoKey,cmCloseWindow1,hcNoContext,
  170. NewItem('Close Window 2','',kbNoKey,cmCloseWindow2,hcNoContext,
  171. NewItem('Close Window 3','',kbNoKey,cmCloseWindow3,hcNoContext,
  172. Nil))))))))),
  173. NewSubMenu('~W~indow', 0, NewMenu(
  174. StdWindowMenuItems(Nil)), Nil))))))); { Standard window menu }
  175. END;
  176. {--TTvDemo------------------------------------------------------------------}
  177. { InitDesktop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Nov99 LdB }
  178. {---------------------------------------------------------------------------}
  179. PROCEDURE TTvDemo.InitDesktop;
  180. VAR R: TRect; {ToolBar: PToolBar;}
  181. BEGIN
  182. GetExtent(R); { Get app extents }
  183. Inc(R.A.Y); { Adjust top down }
  184. Dec(R.B.Y); { Adjust bottom up }
  185. (* ToolBar := New(PToolBar, Init(R.A.X*FontWidth,
  186. R.A.Y*FontHeight, (R.B.X-R.A.X)*FontWidth, 20,
  187. cmAppToolBar));
  188. If (ToolBar <> Nil) Then Begin
  189. R.A.X := R.A.X*FontWidth;
  190. R.A.Y := R.A.Y*FontHeight + 25;
  191. R.B.X := -R.B.X*FontWidth;
  192. R.B.Y := -R.B.Y*Fontheight;
  193. ToolBar^.AddTool(NewToolEntry(cmQuit, True,
  194. '20X20EXIT', 'ToolBar.Res'));
  195. ToolBar^.AddTool(NewToolEntry(cmNew, True,
  196. '20X20NEW', 'ToolBar.Res'));
  197. ToolBar^.AddTool(NewToolEntry(cmOpen, True,
  198. '20X20LOAD', 'ToolBar.Res'));
  199. Insert(ToolBar);
  200. End;*)
  201. Desktop := New(PDeskTop, Init(R));
  202. END;
  203. PROCEDURE TTvDemo.Window1;
  204. VAR R: TRect; P: PGroup;
  205. BEGIN
  206. { Create a basic window with static text and radio }
  207. { buttons. The buttons should be orange and white }
  208. R.Assign(5, 1, 35, 16); { Assign area }
  209. P := New(PWindow, Init(R, 'TEST WINDOW 1', 1)); { Create a window }
  210. If (P <> Nil) Then Begin { Window valid }
  211. R.Assign(5, 5, 20, 6); { Assign area }
  212. P^.Insert(New(PInputLine, Init(R, 30)));
  213. R.Assign(5, 8, 20, 9); { Assign area }
  214. P^.Insert(New(PRadioButtons, Init(R,
  215. NewSItem('Test',
  216. NewSITem('Item 2', Nil))))); { Red radio button }
  217. R.Assign(5, 10, 28, 11); { Assign area }
  218. P^.Insert(New(PStaticText, Init(R,
  219. 'SOME STATIC TEXT'))); { Insert static text }
  220. End;
  221. Desktop^.Insert(P); { Insert into desktop }
  222. P1:=P;
  223. END;
  224. PROCEDURE TTvDemo.AsciiWindow;
  225. begin
  226. {$ifdef TEST}
  227. if ASCIIChart=nil then
  228. begin
  229. New(ASCIIChart, Init);
  230. Desktop^.Insert(ASCIIChart);
  231. end
  232. else
  233. ASCIIChart^.Focus;
  234. {$endif TEST}
  235. end;
  236. PROCEDURE TTvDemo.TimedBox;
  237. var
  238. X: longint;
  239. S: string;
  240. begin
  241. X := TimedMessageBox ('Everything OK?', nil, mfConfirmation or mfOKCancel, 10);
  242. case X of
  243. cmCancel: MessageBox ('cmCancel', nil, mfOKButton);
  244. cmOK: MessageBox ('cmOK', nil, mfOKButton);
  245. else
  246. begin
  247. Str (X, S);
  248. MessageBox (S, nil, mfOKButton);
  249. end;
  250. end;
  251. end;
  252. PROCEDURE TTvDemo.CloseWindow(var P : PGroup);
  253. BEGIN
  254. If Assigned(P) then
  255. BEGIN
  256. Desktop^.Delete(P);
  257. Dispose(P,Done);
  258. P:=Nil;
  259. END;
  260. END;
  261. PROCEDURE TTvDemo.Window2;
  262. VAR R: TRect; P: PGroup;
  263. BEGIN
  264. { Create a basic window with check boxes. The }
  265. { check boxes should be orange and white }
  266. R.Assign(15, 3, 45, 18); { Assign area }
  267. P := New(PWindow, Init(R, 'TEST WINDOW 2', 2)); { Create window 2 }
  268. If (P <> Nil) Then Begin { Window valid }
  269. R.Assign(5, 5, 20, 7); { Assign area }
  270. P^.Insert(New(PCheckBoxes, Init(R,
  271. NewSItem('Test check',
  272. NewSITem('Item 2', Nil))))); { Create check box }
  273. End;
  274. Desktop^.Insert(P); { Insert into desktop }
  275. P2:=P;
  276. END;
  277. PROCEDURE TTvDemo.Window3;
  278. VAR R: TRect; P: PGroup; B: PScrollBar;
  279. List: PStrCollection; Lb: PListBox;
  280. BEGIN
  281. { Create a basic dialog box. In it are buttons, }
  282. { list boxes, scrollbars, inputlines, checkboxes }
  283. R.Assign(32, 2, 77, 18); { Assign screen area }
  284. P := New(PDialog, Init(R, 'TEST DIALOG')); { Create dialog }
  285. If (P <> Nil) Then Begin { Dialog valid }
  286. R.Assign(5, 5, 20, 7); { Allocate area }
  287. P^.Insert(New(PCheckBoxes, Init(R,
  288. NewSItem('Test',
  289. NewSITem('Item 2', Nil))))); { Insert check box }
  290. R.Assign(5, 2, 20, 3); { Assign area }
  291. B := New(PScrollBar, Init(R)); { Insert scroll bar }
  292. If (B <> Nil) Then Begin { Scrollbar valid }
  293. B^.SetRange(0, 100); { Set scrollbar range }
  294. B^.SetValue(50); { Set position }
  295. P^.Insert(B); { Insert scrollbar }
  296. End;
  297. R.Assign(5, 10, 20, 11); { Assign area }
  298. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  299. R.Assign(5, 13, 20, 14); { Assign area }
  300. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  301. R.Assign(40, 8, 41, 14); { Assign area }
  302. B := New(PScrollBar, Init(R)); { Create scrollbar }
  303. P^.Insert(B); { Insert scrollbar }
  304. R.Assign(25, 8, 40, 14); { Assign area }
  305. Lb := New(PListBox, Init(R, 1, B)); { Create listbox }
  306. P^.Insert(Lb); { Insert listbox }
  307. List := New(PStrCollection, Init(10, 5)); { Create string list }
  308. List^.AtInsert(0, NewStr('Zebra')); { Insert text }
  309. List^.AtInsert(1, NewStr('Apple')); { Insert text }
  310. List^.AtInsert(2, NewStr('Third')); { Insert text }
  311. List^.AtInsert(3, NewStr('Peach')); { Insert text }
  312. List^.AtInsert(4, NewStr('Rabbit')); { Insert text }
  313. List^.AtInsert(5, NewStr('Item six')); { Insert text }
  314. List^.AtInsert(6, NewStr('Jaguar')); { Insert text }
  315. List^.AtInsert(7, NewStr('Melon')); { Insert text }
  316. List^.AtInsert(8, NewStr('Ninth')); { Insert text }
  317. List^.AtInsert(9, NewStr('Last item')); { Insert text }
  318. Lb^.Newlist(List); { Give list to listbox }
  319. R.Assign(30, 2, 40, 4); { Assign area }
  320. P^.Insert(New(PButton, Init(R, '~O~k', 100, bfGrabFocus)));{ Create okay button }
  321. R.Assign(30, 15, 40, 17); { Assign area }
  322. Desktop^.Insert(P); { Insert dialog }
  323. P3:=P;
  324. End;
  325. END;
  326. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  327. { MAIN PROGRAM START }
  328. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  329. VAR I: Integer; R: TRect; P: PGroup; MyApp: TTvDemo;
  330. {$IFDEF OS2PM}
  331. {$IFDEF OS_OS2} Message: QMSg; Event: TEvent; {$ENDIF}
  332. {$ENDIF OS2PM}
  333. BEGIN
  334. (*SystemPalette := CreateRGBPalette(256); { Create palette }
  335. For I := 0 To 15 Do Begin
  336. GetSystemRGBEntry(I, RGB); { Get palette entry }
  337. AddToRGBPalette(RGB, SystemPalette); { Add entry to palette }
  338. End;*)
  339. MyApp.Init; { Initialize app }
  340. MyApp.Run; { Run the app }
  341. {$IFDEF OS2PM}
  342. {$IFDEF OS_OS2}
  343. while (MyApp.EndState = 0)
  344. AND WinGetMsg(Anchor, Message, 0, 0, 0) Do Begin
  345. WinDispatchMsg(Anchor, Message);
  346. NextQueuedEvent(Event);
  347. If (event.What <> evNothing)
  348. Then MyApp.handleEvent(Event);
  349. End;
  350. {$ENDIF}
  351. {$ENDIF OS2PM}
  352. MyApp.Done; { Dispose of app }
  353. {DisposeRGBPalette(SystemPalette);}
  354. END.