testapp.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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, Drivers, {$ENDIF}
  35. Objects, Views, Menus, Dialogs, App, { Standard GFV units }
  36. Gadgets;
  37. CONST cmAppToolbar = 1000;
  38. {---------------------------------------------------------------------------}
  39. { TTestAppp OBJECT - STANDARD APPLICATION WITH MENU }
  40. {---------------------------------------------------------------------------}
  41. TYPE
  42. PTVDemo = ^TTVDemo;
  43. TTVDemo = OBJECT (TApplication)
  44. Clock: PClockView;
  45. Heap: PHeapView;
  46. CONSTRUCTOR Init;
  47. PROCEDURE Idle; Virtual;
  48. PROCEDURE InitMenuBar; Virtual;
  49. PROCEDURE InitDeskTop; Virtual;
  50. End;
  51. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  52. { TTvDemo OBJECT METHODS }
  53. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  54. CONSTRUCTOR TTvDemo.Init;
  55. VAR R: TRect;
  56. BEGIN
  57. Inherited Init;
  58. { Initialize demo gadgets }
  59. GetExtent(R);
  60. R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
  61. Clock := New(PClockView, Init(R));
  62. Insert(Clock);
  63. GetExtent(R);
  64. Dec(R.B.X);
  65. R.A.X := R.B.X - 12; R.A.Y := R.B.Y - 1;
  66. Heap := New(PHeapView, Init(R));
  67. Insert(Heap);
  68. END;
  69. procedure TTVDemo.Idle;
  70. function IsTileable(P: PView): Boolean; far;
  71. begin
  72. IsTileable := (P^.Options and ofTileable <> 0) and
  73. (P^.State and sfVisible <> 0);
  74. end;
  75. begin
  76. inherited Idle;
  77. Clock^.Update;
  78. Heap^.Update;
  79. if Desktop^.FirstThat(@IsTileable) <> nil then
  80. EnableCommands([cmTile, cmCascade])
  81. else
  82. DisableCommands([cmTile, cmCascade]);
  83. end;
  84. {--TTvDemo------------------------------------------------------------------}
  85. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Nov99 LdB }
  86. {---------------------------------------------------------------------------}
  87. PROCEDURE TTVDemo.InitMenuBar;
  88. VAR R: TRect;
  89. BEGIN
  90. GetExtent(R); { Get view extents }
  91. R.B.Y := R.A.Y + 1; { One line high }
  92. MenuBar := New(PMenuBar, Init(R, NewMenu(
  93. NewSubMenu('~F~ile', 0, NewMenu(
  94. StdFileMenuItems(Nil)), { Standard file menu }
  95. NewSubMenu('~E~dit', 0, NewMenu(
  96. StdEditMenuItems(Nil)), { Standard edit menu }
  97. NewSubMenu('~W~indow', 0, NewMenu(
  98. StdWindowMenuItems(Nil)), Nil)))))); { Standard window menu }
  99. END;
  100. {--TTvDemo------------------------------------------------------------------}
  101. { InitDesktop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Nov99 LdB }
  102. {---------------------------------------------------------------------------}
  103. PROCEDURE TTvDemo.InitDesktop;
  104. VAR R: TRect; {ToolBar: PToolBar;}
  105. BEGIN
  106. GetExtent(R); { Get app extents }
  107. Inc(R.A.Y); { Adjust top down }
  108. Dec(R.B.Y); { Adjust bottom up }
  109. (* ToolBar := New(PToolBar, Init(R.A.X*FontWidth,
  110. R.A.Y*FontHeight, (R.B.X-R.A.X)*FontWidth, 20,
  111. cmAppToolBar));
  112. If (ToolBar <> Nil) Then Begin
  113. R.A.X := R.A.X*FontWidth;
  114. R.A.Y := R.A.Y*FontHeight + 25;
  115. R.B.X := -R.B.X*FontWidth;
  116. R.B.Y := -R.B.Y*Fontheight;
  117. ToolBar^.AddTool(NewToolEntry(cmQuit, True,
  118. '20X20EXIT', 'ToolBar.Res'));
  119. ToolBar^.AddTool(NewToolEntry(cmNew, True,
  120. '20X20NEW', 'ToolBar.Res'));
  121. ToolBar^.AddTool(NewToolEntry(cmOpen, True,
  122. '20X20LOAD', 'ToolBar.Res'));
  123. Insert(ToolBar);
  124. End;*)
  125. Desktop := New(PDeskTop, Init(R));
  126. END;
  127. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  128. { MAIN PROGRAM START }
  129. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  130. VAR I: Integer; R: TRect; P: PGroup; B: PScrollBar;
  131. List: PStrCollection; Lb: PListBox; MyApp: TTvDemo;
  132. {$IFDEF OS_OS2} Message: QMSg; Event: TEvent; {$ENDIF}
  133. BEGIN
  134. (*SystemPalette := CreateRGBPalette(256); { Create palette }
  135. For I := 0 To 15 Do Begin
  136. GetSystemRGBEntry(I, RGB); { Get palette entry }
  137. AddToRGBPalette(RGB, SystemPalette); { Add entry to palette }
  138. End;*)
  139. MyApp.Init; { Initialize app }
  140. {$IFDEF OS_WINDOWS}
  141. { Create a basic window with static text and radio }
  142. { buttons. The buttons should be orange and white }
  143. R.Assign(5, 1, 35, 16); { Assign area }
  144. P := New(PWindow, Init(R, 'TEST WINDOW 1', 1)); { Create a window }
  145. If (P <> Nil) Then Begin { Window valid }
  146. R.Assign(5, 5, 20, 7); { Assign area }
  147. P^.Insert(New(PInputLine, Init(R, 30)));
  148. P^.Insert(New(PRadioButtons, Init(R,
  149. NewSItem('Test',
  150. NewSITem('Item 2', Nil))))); { Red radio button }
  151. R.Assign(5, 10, 28, 11); { Assign area }
  152. P^.Insert(New(PStaticText, Init(R,
  153. 'SOME STATIC TEXT'))); { Insert static text }
  154. End;
  155. Desktop^.Insert(P); { Insert into desktop }
  156. { Create a basic window with check boxes. The }
  157. { check boxes should be orange and white }
  158. R.Assign(15, 3, 45, 18); { Assign area }
  159. P := New(PWindow, Init(R, 'TEST WINDOW 2', 2)); { Create window 2 }
  160. If (P <> Nil) Then Begin { Window valid }
  161. R.Assign(5, 5, 20, 7); { Assign area }
  162. P^.Insert(New(PCheckBoxes, Init(R,
  163. NewSItem('Test check',
  164. NewSITem('Item 2', Nil))))); { Create check box }
  165. End;
  166. Desktop^.Insert(P); { Insert into desktop }
  167. { Create a basic dialog box. In it are buttons, }
  168. { list boxes, scrollbars, inputlines, checkboxes }
  169. R.Assign(32, 2, 77, 18); { Assign screen area }
  170. P := New(PDialog, Init(R, 'TEST DIALOG')); { Create dialog }
  171. If (P <> Nil) Then Begin { Dialog valid }
  172. R.Assign(5, 5, 20, 7); { Allocate area }
  173. P^.Insert(New(PCheckBoxes, Init(R,
  174. NewSItem('Test',
  175. NewSITem('Item 2', Nil))))); { Insert check box }
  176. R.Assign(5, 2, 20, 3); { Assign area }
  177. B := New(PScrollBar, Init(R)); { Insert scroll bar }
  178. If (B <> Nil) Then Begin { Scrollbar valid }
  179. B^.SetRange(0, 100); { Set scrollbar range }
  180. B^.SetValue(50); { Set position }
  181. P^.Insert(B); { Insert scrollbar }
  182. End;
  183. R.Assign(5, 10, 20, 11); { Assign area }
  184. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  185. R.Assign(5, 13, 20, 14); { Assign area }
  186. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  187. R.Assign(40, 8, 41, 14); { Assign area }
  188. B := New(PScrollBar, Init(R)); { Create scrollbar }
  189. P^.Insert(B); { Insert scrollbar }
  190. R.Assign(25, 8, 40, 14); { Assign area }
  191. Lb := New(PListBox, Init(R, 1, B)); { Create listbox }
  192. P^.Insert(Lb); { Insert listbox }
  193. List := New(PStrCollection, Init(10, 5)); { Create string list }
  194. List^.AtInsert(0, NewStr('Zebra')); { Insert text }
  195. List^.AtInsert(1, NewStr('Apple')); { Insert text }
  196. List^.AtInsert(2, NewStr('Third')); { Insert text }
  197. List^.AtInsert(3, NewStr('Peach')); { Insert text }
  198. List^.AtInsert(4, NewStr('Rabbit')); { Insert text }
  199. List^.AtInsert(5, NewStr('Item six')); { Insert text }
  200. List^.AtInsert(6, NewStr('Jaguar')); { Insert text }
  201. List^.AtInsert(7, NewStr('Melon')); { Insert text }
  202. List^.AtInsert(8, NewStr('Ninth')); { Insert text }
  203. List^.AtInsert(9, NewStr('Last item')); { Insert text }
  204. Lb^.Newlist(List); { Give list to listbox }
  205. R.Assign(30, 2, 40, 4); { Assign area }
  206. P^.Insert(New(PButton, Init(R, '~O~k', 100, bfGrabFocus)));{ Create okay button }
  207. R.Assign(30, 15, 40, 17); { Assign area }
  208. Desktop^.Insert(P); { Insert dialog }
  209. End;
  210. MyApp.Run; { Run the app }
  211. {$ENDIF}
  212. {$IFDEF OS_OS2}
  213. while (MyApp.EndState = 0)
  214. AND WinGetMsg(Anchor, Message, 0, 0, 0) Do Begin
  215. WinDispatchMsg(Anchor, Message);
  216. NextQueuedEvent(Event);
  217. If (event.What <> evNothing)
  218. Then MyApp.handleEvent(Event);
  219. End;
  220. {$ENDIF}
  221. MyApp.Done; { Dispose of app }
  222. {DisposeRGBPalette(SystemPalette);}
  223. END.
  224. {
  225. $Log$
  226. Revision 1.2 2000-08-24 12:00:22 marco
  227. * CVS log and ID tags
  228. }