testapp.pas 15 KB

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