testapp.pas 14 KB

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