testapp.pas 14 KB

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