testapp.pas 16 KB

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