testapp.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. PROGRAM TestApp;
  2. {&PMTYPE PM} { FULL GUI MODE }
  3. { ******************************* REMARK ****************************** }
  4. { This is a basic test program to test the app framework. In use will }
  5. { be menus, statuslines, windows, dialogs, scrollbars, statictext, }
  6. { radiobuttons, check boxes, list boxes and input lines. }
  7. { }
  8. { Working compilers: }
  9. { WINDOWS BPW, VP2, Delphi1, FPC WIN (0.9912) }
  10. { DOS has draw bugs but works for BP and FPC DOS (GO32V2) }
  11. { OS2 dows not work still some PM bits to do }
  12. { }
  13. { Not working: }
  14. { Delphi3, Delphi5 (sus 4) will compile but Tgroup.ForEach etc U/S. }
  15. { Sybil2 Win32 should work but to big for demo mode so unsure! }
  16. { }
  17. { Special things to try out: }
  18. { Check out the standard windows minimize etc icons. }
  19. { }
  20. { }
  21. { Comments: }
  22. { There is alot that may seem more complex than it needs to but }
  23. { I have much more elaborate objects operating such as bitmaps, }
  24. { bitmap buttons, percentage bars etc and they need these hooks. }
  25. { Basically the intention is to be able to port existing TV apps }
  26. { as a start point and then start to optimize and use the new }
  27. { GUI specific objects. I will try to get some documentation }
  28. { done on how everything works because some things are hard to }
  29. { follow in windows. }
  30. { ****************************** END REMARK *** Leon de Boer, 06Nov99 * }
  31. {$I Platform.inc}
  32. USES
  33. {$IFDEF OS_OS2} Os2Def, os2PmApi, Drivers, {$ENDIF}
  34. Objects, Views, Menus, Dialogs, App, { Standard GFV units }
  35. Gadgets;
  36. CONST cmAppToolbar = 1000;
  37. {---------------------------------------------------------------------------}
  38. { TTestAppp OBJECT - STANDARD APPLICATION WITH MENU }
  39. {---------------------------------------------------------------------------}
  40. TYPE
  41. PTVDemo = ^TTVDemo;
  42. TTVDemo = OBJECT (TApplication)
  43. Clock: PClockView;
  44. Heap: PHeapView;
  45. CONSTRUCTOR Init;
  46. PROCEDURE Idle; Virtual;
  47. PROCEDURE InitMenuBar; Virtual;
  48. PROCEDURE InitDeskTop; Virtual;
  49. End;
  50. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  51. { TTvDemo OBJECT METHODS }
  52. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  53. CONSTRUCTOR TTvDemo.Init;
  54. VAR R: TRect;
  55. BEGIN
  56. Inherited Init;
  57. { Initialize demo gadgets }
  58. GetExtent(R);
  59. R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
  60. Clock := New(PClockView, Init(R));
  61. Insert(Clock);
  62. GetExtent(R);
  63. Dec(R.B.X);
  64. R.A.X := R.B.X - 12; R.A.Y := R.B.Y - 1;
  65. Heap := New(PHeapView, Init(R));
  66. Insert(Heap);
  67. END;
  68. procedure TTVDemo.Idle;
  69. function IsTileable(P: PView): Boolean; far;
  70. begin
  71. IsTileable := (P^.Options and ofTileable <> 0) and
  72. (P^.State and sfVisible <> 0);
  73. end;
  74. begin
  75. inherited Idle;
  76. Clock^.Update;
  77. Heap^.Update;
  78. if Desktop^.FirstThat(@IsTileable) <> nil then
  79. EnableCommands([cmTile, cmCascade])
  80. else
  81. DisableCommands([cmTile, cmCascade]);
  82. end;
  83. {--TTvDemo------------------------------------------------------------------}
  84. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Nov99 LdB }
  85. {---------------------------------------------------------------------------}
  86. PROCEDURE TTVDemo.InitMenuBar;
  87. VAR R: TRect;
  88. BEGIN
  89. GetExtent(R); { Get view extents }
  90. R.B.Y := R.A.Y + 1; { One line high }
  91. MenuBar := New(PMenuBar, Init(R, NewMenu(
  92. NewSubMenu('~F~ile', 0, NewMenu(
  93. StdFileMenuItems(Nil)), { Standard file menu }
  94. NewSubMenu('~E~dit', 0, NewMenu(
  95. StdEditMenuItems(Nil)), { Standard edit menu }
  96. NewSubMenu('~W~indow', 0, NewMenu(
  97. StdWindowMenuItems(Nil)), Nil)))))); { Standard window menu }
  98. END;
  99. {--TTvDemo------------------------------------------------------------------}
  100. { InitDesktop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Nov99 LdB }
  101. {---------------------------------------------------------------------------}
  102. PROCEDURE TTvDemo.InitDesktop;
  103. VAR R: TRect; {ToolBar: PToolBar;}
  104. BEGIN
  105. GetExtent(R); { Get app extents }
  106. Inc(R.A.Y); { Adjust top down }
  107. Dec(R.B.Y); { Adjust bottom up }
  108. (* ToolBar := New(PToolBar, Init(R.A.X*FontWidth,
  109. R.A.Y*FontHeight, (R.B.X-R.A.X)*FontWidth, 20,
  110. cmAppToolBar));
  111. If (ToolBar <> Nil) Then Begin
  112. R.A.X := R.A.X*FontWidth;
  113. R.A.Y := R.A.Y*FontHeight + 25;
  114. R.B.X := -R.B.X*FontWidth;
  115. R.B.Y := -R.B.Y*Fontheight;
  116. ToolBar^.AddTool(NewToolEntry(cmQuit, True,
  117. '20X20EXIT', 'ToolBar.Res'));
  118. ToolBar^.AddTool(NewToolEntry(cmNew, True,
  119. '20X20NEW', 'ToolBar.Res'));
  120. ToolBar^.AddTool(NewToolEntry(cmOpen, True,
  121. '20X20LOAD', 'ToolBar.Res'));
  122. Insert(ToolBar);
  123. End;*)
  124. Desktop := New(PDeskTop, Init(R));
  125. END;
  126. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  127. { MAIN PROGRAM START }
  128. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  129. VAR I: Integer; R: TRect; P: PGroup; B: PScrollBar;
  130. List: PStrCollection; Lb: PListBox; MyApp: TTvDemo;
  131. {$IFDEF OS_OS2} Message: QMSg; Event: TEvent; {$ENDIF}
  132. BEGIN
  133. (*SystemPalette := CreateRGBPalette(256); { Create palette }
  134. For I := 0 To 15 Do Begin
  135. GetSystemRGBEntry(I, RGB); { Get palette entry }
  136. AddToRGBPalette(RGB, SystemPalette); { Add entry to palette }
  137. End;*)
  138. MyApp.Init; { Initialize app }
  139. {$IFDEF OS_WINDOWS}
  140. { Create a basic window with static text and radio }
  141. { buttons. The buttons should be orange and white }
  142. R.Assign(5, 1, 35, 16); { Assign area }
  143. P := New(PWindow, Init(R, 'TEST WINDOW 1', 1)); { Create a window }
  144. If (P <> Nil) Then Begin { Window valid }
  145. R.Assign(5, 5, 20, 7); { Assign area }
  146. P^.Insert(New(PInputLine, Init(R, 30)));
  147. P^.Insert(New(PRadioButtons, Init(R,
  148. NewSItem('Test',
  149. NewSITem('Item 2', Nil))))); { Red radio button }
  150. R.Assign(5, 10, 28, 11); { Assign area }
  151. P^.Insert(New(PStaticText, Init(R,
  152. 'SOME STATIC TEXT'))); { Insert static text }
  153. End;
  154. Desktop^.Insert(P); { Insert into desktop }
  155. { Create a basic window with check boxes. The }
  156. { check boxes should be orange and white }
  157. R.Assign(15, 3, 45, 18); { Assign area }
  158. P := New(PWindow, Init(R, 'TEST WINDOW 2', 2)); { Create window 2 }
  159. If (P <> Nil) Then Begin { Window valid }
  160. R.Assign(5, 5, 20, 7); { Assign area }
  161. P^.Insert(New(PCheckBoxes, Init(R,
  162. NewSItem('Test check',
  163. NewSITem('Item 2', Nil))))); { Create check box }
  164. End;
  165. Desktop^.Insert(P); { Insert into desktop }
  166. { Create a basic dialog box. In it are buttons, }
  167. { list boxes, scrollbars, inputlines, checkboxes }
  168. R.Assign(32, 2, 77, 18); { Assign screen area }
  169. P := New(PDialog, Init(R, 'TEST DIALOG')); { Create dialog }
  170. If (P <> Nil) Then Begin { Dialog valid }
  171. R.Assign(5, 5, 20, 7); { Allocate area }
  172. P^.Insert(New(PCheckBoxes, Init(R,
  173. NewSItem('Test',
  174. NewSITem('Item 2', Nil))))); { Insert check box }
  175. R.Assign(5, 2, 20, 3); { Assign area }
  176. B := New(PScrollBar, Init(R)); { Insert scroll bar }
  177. If (B <> Nil) Then Begin { Scrollbar valid }
  178. B^.SetRange(0, 100); { Set scrollbar range }
  179. B^.SetValue(50); { Set position }
  180. P^.Insert(B); { Insert scrollbar }
  181. End;
  182. R.Assign(5, 10, 20, 11); { Assign area }
  183. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  184. R.Assign(5, 13, 20, 14); { Assign area }
  185. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  186. R.Assign(40, 8, 41, 14); { Assign area }
  187. B := New(PScrollBar, Init(R)); { Create scrollbar }
  188. P^.Insert(B); { Insert scrollbar }
  189. R.Assign(25, 8, 40, 14); { Assign area }
  190. Lb := New(PListBox, Init(R, 1, B)); { Create listbox }
  191. P^.Insert(Lb); { Insert listbox }
  192. List := New(PStrCollection, Init(10, 5)); { Create string list }
  193. List^.AtInsert(0, NewStr('Zebra')); { Insert text }
  194. List^.AtInsert(1, NewStr('Apple')); { Insert text }
  195. List^.AtInsert(2, NewStr('Third')); { Insert text }
  196. List^.AtInsert(3, NewStr('Peach')); { Insert text }
  197. List^.AtInsert(4, NewStr('Rabbit')); { Insert text }
  198. List^.AtInsert(5, NewStr('Item six')); { Insert text }
  199. List^.AtInsert(6, NewStr('Jaguar')); { Insert text }
  200. List^.AtInsert(7, NewStr('Melon')); { Insert text }
  201. List^.AtInsert(8, NewStr('Ninth')); { Insert text }
  202. List^.AtInsert(9, NewStr('Last item')); { Insert text }
  203. Lb^.Newlist(List); { Give list to listbox }
  204. R.Assign(30, 2, 40, 4); { Assign area }
  205. P^.Insert(New(PButton, Init(R, '~O~k', 100, bfGrabFocus)));{ Create okay button }
  206. R.Assign(30, 15, 40, 17); { Assign area }
  207. Desktop^.Insert(P); { Insert dialog }
  208. End;
  209. MyApp.Run; { Run the app }
  210. {$ENDIF}
  211. {$IFDEF OS_OS2}
  212. while (MyApp.EndState = 0)
  213. AND WinGetMsg(Anchor, Message, 0, 0, 0) Do Begin
  214. WinDispatchMsg(Anchor, Message);
  215. NextQueuedEvent(Event);
  216. If (event.What <> evNothing)
  217. Then MyApp.handleEvent(Event);
  218. End;
  219. {$ENDIF}
  220. MyApp.Done; { Dispose of app }
  221. {DisposeRGBPalette(SystemPalette);}
  222. END.