testapp.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. Insert(Clock);
  97. GetExtent(R);
  98. ClipboardWindow := New(PEditWindow, Init(R, '', wnNoNumber));
  99. if ValidView(ClipboardWindow) <> nil then
  100. begin
  101. ClipboardWindow^.Hide;
  102. ClipboardWindow^.Editor^.CanUndo := False;
  103. InsertWindow(ClipboardWindow);
  104. Clipboard := ClipboardWindow^.Editor;
  105. end;
  106. END;
  107. procedure TTVDemo.Idle;
  108. function IsTileable(P: PView): Boolean; far;
  109. begin
  110. IsTileable := (P^.Options and ofTileable <> 0) and
  111. (P^.State and sfVisible <> 0);
  112. end;
  113. {$ifdef DEBUG}
  114. Var
  115. WasSet : boolean;
  116. {$endif DEBUG}
  117. begin
  118. inherited Idle;
  119. {$ifdef DEBUG}
  120. if WriteDebugInfo then
  121. begin
  122. WasSet:=true;
  123. WriteDebugInfo:=false;
  124. end
  125. else
  126. WasSet:=false;
  127. if WriteDebugInfo then
  128. {$endif DEBUG}
  129. Clock^.Update;
  130. Heap^.Update;
  131. {$ifdef DEBUG}
  132. if WasSet then
  133. WriteDebugInfo:=true;
  134. {$endif DEBUG}
  135. if Desktop^.FirstThat(@IsTileable) <> nil then
  136. EnableCommands([cmTile, cmCascade])
  137. else
  138. DisableCommands([cmTile, cmCascade]);
  139. end;
  140. PROCEDURE TTVDemo.HandleEvent(var Event : TEvent);
  141. BEGIN
  142. Inherited HandleEvent(Event); { Call ancestor }
  143. If (Event.What = evCommand) Then Begin
  144. Case Event.Command Of
  145. cmClipBoard:
  146. begin
  147. ClipboardWindow^.Select;
  148. ClipboardWindow^.Show;
  149. end;
  150. cmNew : NewEditWindow;
  151. cmOpen : OpenFile;
  152. cmWindow1 : Window1;
  153. cmWindow2 : Window2;
  154. cmWindow3 : Window3;
  155. cmTimedBox: TimedBox;
  156. cmAscii : AsciiWindow;
  157. cmCloseWindow1 : CloseWindow(P1);
  158. cmCloseWindow2 : CloseWindow(P2);
  159. cmCloseWindow3 : CloseWindow(P3);
  160. cmAbout: ShowAboutBox;
  161. Else Exit; { Unhandled exit }
  162. End;
  163. End;
  164. ClearEvent(Event);
  165. END;
  166. {--TTvDemo------------------------------------------------------------------}
  167. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 05Nov99 LdB }
  168. {---------------------------------------------------------------------------}
  169. PROCEDURE TTVDemo.InitMenuBar;
  170. VAR R: TRect;
  171. BEGIN
  172. GetExtent(R); { Get view extents }
  173. R.B.Y := R.A.Y + 1; { One line high }
  174. MenuBar := New(PMenuBar, Init(R, NewMenu(
  175. NewSubMenu('~F~ile', 0, NewMenu(
  176. StdFileMenuItems(Nil)), { Standard file menu }
  177. NewSubMenu('~E~dit', 0, NewMenu(
  178. StdEditMenuItems(
  179. NewLine(
  180. NewItem('~V~iew Clipboard', '', kbNoKey, cmClipboard, hcNoContext,
  181. nil)))), { Standard edit menu plus view clipboard}
  182. NewSubMenu('~T~est', 0, NewMenu(
  183. NewItem('~A~scii Chart','',kbNoKey,cmAscii,hcNoContext,
  184. NewItem('Window ~1~','',kbNoKey,cmWindow1,hcNoContext,
  185. NewItem('Window ~2~','',kbNoKey,cmWindow2,hcNoContext,
  186. NewItem('Window ~3~','',kbNoKey,cmWindow3,hcNoContext,
  187. NewItem('~T~imed Box','',kbNoKey,cmTimedBox,hcNoContext,
  188. NewItem('Close Window 1','',kbNoKey,cmCloseWindow1,hcNoContext,
  189. NewItem('Close Window 2','',kbNoKey,cmCloseWindow2,hcNoContext,
  190. NewItem('Close Window 3','',kbNoKey,cmCloseWindow3,hcNoContext,
  191. Nil))))))))),
  192. NewSubMenu('~W~indow', 0, NewMenu(
  193. StdWindowMenuItems(Nil)), { Standard window menu }
  194. NewSubMenu('~H~elp', hcNoContext, NewMenu(
  195. NewItem('~A~bout...','',kbNoKey,cmAbout,hcNoContext,
  196. nil)),
  197. nil))))) //end NewSubMenus
  198. ))); //end MenuBar
  199. END;
  200. {--TTvDemo------------------------------------------------------------------}
  201. { InitDesktop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Nov99 LdB }
  202. {---------------------------------------------------------------------------}
  203. PROCEDURE TTvDemo.InitDesktop;
  204. VAR R: TRect; {ToolBar: PToolBar;}
  205. BEGIN
  206. GetExtent(R); { Get app extents }
  207. Inc(R.A.Y); { Adjust top down }
  208. Dec(R.B.Y); { Adjust bottom up }
  209. (* ToolBar := New(PToolBar, Init(R.A.X*FontWidth,
  210. R.A.Y*FontHeight, (R.B.X-R.A.X)*FontWidth, 20,
  211. cmAppToolBar));
  212. If (ToolBar <> Nil) Then Begin
  213. R.A.X := R.A.X*FontWidth;
  214. R.A.Y := R.A.Y*FontHeight + 25;
  215. R.B.X := -R.B.X*FontWidth;
  216. R.B.Y := -R.B.Y*Fontheight;
  217. ToolBar^.AddTool(NewToolEntry(cmQuit, True,
  218. '20X20EXIT', 'ToolBar.Res'));
  219. ToolBar^.AddTool(NewToolEntry(cmNew, True,
  220. '20X20NEW', 'ToolBar.Res'));
  221. ToolBar^.AddTool(NewToolEntry(cmOpen, True,
  222. '20X20LOAD', 'ToolBar.Res'));
  223. Insert(ToolBar);
  224. End;*)
  225. Desktop := New(PDeskTop, Init(R));
  226. END;
  227. procedure TTVDemo.InitStatusLine;
  228. var
  229. R: TRect;
  230. begin
  231. GetExtent(R);
  232. R.A.Y := R.B.Y - 1;
  233. R.B.X := R.B.X - 12;
  234. New(StatusLine,
  235. Init(R,
  236. NewStatusDef(0, $EFFF,
  237. NewStatusKey('~F3~ Open', kbF3, cmOpen,
  238. NewStatusKey('~F4~ New', kbF4, cmNew,
  239. NewStatusKey('~Alt+F3~ Close', kbAltF3, cmClose,
  240. StdStatusKeys(nil
  241. )))),nil
  242. )
  243. )
  244. );
  245. GetExtent(R);
  246. R.A.X := R.B.X - 12; R.A.Y := R.B.Y - 1;
  247. Heap := New(PHeapView, Init(R));
  248. Insert(Heap);
  249. end;
  250. PROCEDURE TTvDemo.Window1;
  251. VAR R: TRect; P: PGroup;
  252. BEGIN
  253. { Create a basic window with static text and radio }
  254. { buttons. The buttons should be orange and white }
  255. R.Assign(5, 1, 35, 16); { Assign area }
  256. P := New(PWindow, Init(R, 'TEST WINDOW 1', 1)); { Create a window }
  257. If (P <> Nil) Then Begin { Window valid }
  258. R.Assign(5, 5, 20, 6); { Assign area }
  259. P^.Insert(New(PInputLine, Init(R, 30)));
  260. R.Assign(5, 8, 20, 9); { Assign area }
  261. P^.Insert(New(PRadioButtons, Init(R,
  262. NewSItem('Test',
  263. NewSITem('Item 2', Nil))))); { Red radio button }
  264. R.Assign(5, 10, 28, 11); { Assign area }
  265. P^.Insert(New(PStaticText, Init(R,
  266. 'SOME STATIC TEXT'))); { Insert static text }
  267. End;
  268. Desktop^.Insert(P); { Insert into desktop }
  269. P1:=P;
  270. END;
  271. PROCEDURE TTvDemo.AsciiWindow;
  272. begin
  273. if ASCIIChart=nil then
  274. begin
  275. New(ASCIIChart, Init);
  276. Desktop^.Insert(ASCIIChart);
  277. end
  278. else
  279. ASCIIChart^.Focus;
  280. end;
  281. PROCEDURE TTVDemo.ShowAboutBox;
  282. begin
  283. MessageBox(#3'Free Vision TUI Framework'#13 +
  284. #3'Test/Demo Application'#13+
  285. #3'(www.freepascal.org)',
  286. nil, mfInformation or mfOKButton);
  287. end;
  288. PROCEDURE TTVDemo.NewEditWindow;
  289. var
  290. R: TRect;
  291. begin
  292. R.Assign(0, 0, 60, 20);
  293. InsertWindow(New(PEditWindow, Init(R, '', wnNoNumber)));
  294. end;
  295. PROCEDURE TTVDemo.OpenFile;
  296. var
  297. R: TRect;
  298. FileDialog: PFileDialog;
  299. FileName: FNameStr;
  300. const
  301. FDOptions: Word = fdOKButton or fdOpenButton;
  302. begin
  303. FileName := '*.*';
  304. New(FileDialog, Init(FileName, 'Open file', '~F~ile name', FDOptions, 1));
  305. if ExecuteDialog(FileDialog, @FileName) <> cmCancel then
  306. begin
  307. R.Assign(0, 0, 75, 20);
  308. InsertWindow(New(PEditWindow, Init(R, FileName, wnNoNumber)));
  309. end;
  310. end;
  311. PROCEDURE TTvDemo.TimedBox;
  312. var
  313. X: longint;
  314. S: string;
  315. begin
  316. X := TimedMessageBox ('Everything OK?', nil, mfConfirmation or mfOKCancel, 10);
  317. case X of
  318. cmCancel: MessageBox ('cmCancel', nil, mfOKButton);
  319. cmOK: MessageBox ('cmOK', nil, mfOKButton);
  320. else
  321. begin
  322. Str (X, S);
  323. MessageBox (S, nil, mfOKButton);
  324. end;
  325. end;
  326. end;
  327. PROCEDURE TTvDemo.CloseWindow(var P : PGroup);
  328. BEGIN
  329. If Assigned(P) then
  330. BEGIN
  331. Desktop^.Delete(P);
  332. Dispose(P,Done);
  333. P:=Nil;
  334. END;
  335. END;
  336. PROCEDURE TTvDemo.Window2;
  337. VAR R: TRect; P: PGroup;
  338. BEGIN
  339. { Create a basic window with check boxes. The }
  340. { check boxes should be orange and white }
  341. R.Assign(15, 3, 45, 18); { Assign area }
  342. P := New(PWindow, Init(R, 'TEST WINDOW 2', 2)); { Create window 2 }
  343. If (P <> Nil) Then Begin { Window valid }
  344. R.Assign(5, 5, 20, 7); { Assign area }
  345. P^.Insert(New(PCheckBoxes, Init(R,
  346. NewSItem('Test check',
  347. NewSITem('Item 2', Nil))))); { Create check box }
  348. End;
  349. Desktop^.Insert(P); { Insert into desktop }
  350. P2:=P;
  351. END;
  352. PROCEDURE TTvDemo.Window3;
  353. VAR R: TRect; P: PGroup; B: PScrollBar;
  354. List: PStrCollection; Lb: PListBox;
  355. BEGIN
  356. { Create a basic dialog box. In it are buttons, }
  357. { list boxes, scrollbars, inputlines, checkboxes }
  358. R.Assign(32, 2, 77, 18); { Assign screen area }
  359. P := New(PDialog, Init(R, 'TEST DIALOG')); { Create dialog }
  360. If (P <> Nil) Then Begin { Dialog valid }
  361. R.Assign(5, 5, 20, 7); { Allocate area }
  362. P^.Insert(New(PCheckBoxes, Init(R,
  363. NewSItem('Test',
  364. NewSITem('Item 2', Nil))))); { Insert check box }
  365. R.Assign(5, 2, 20, 3); { Assign area }
  366. B := New(PScrollBar, Init(R)); { Insert scroll bar }
  367. If (B <> Nil) Then Begin { Scrollbar valid }
  368. B^.SetRange(0, 100); { Set scrollbar range }
  369. B^.SetValue(50); { Set position }
  370. P^.Insert(B); { Insert scrollbar }
  371. End;
  372. R.Assign(5, 10, 20, 11); { Assign area }
  373. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  374. R.Assign(5, 13, 20, 14); { Assign area }
  375. P^.Insert(New(PInputLine, Init(R, 60))); { Create input line }
  376. R.Assign(40, 8, 41, 14); { Assign area }
  377. B := New(PScrollBar, Init(R)); { Create scrollbar }
  378. P^.Insert(B); { Insert scrollbar }
  379. R.Assign(25, 8, 40, 14); { Assign area }
  380. Lb := New(PListBox, Init(R, 1, B)); { Create listbox }
  381. P^.Insert(Lb); { Insert listbox }
  382. List := New(PStrCollection, Init(10, 5)); { Create string list }
  383. List^.AtInsert(0, NewStr('Zebra')); { Insert text }
  384. List^.AtInsert(1, NewStr('Apple')); { Insert text }
  385. List^.AtInsert(2, NewStr('Third')); { Insert text }
  386. List^.AtInsert(3, NewStr('Peach')); { Insert text }
  387. List^.AtInsert(4, NewStr('Rabbit')); { Insert text }
  388. List^.AtInsert(5, NewStr('Item six')); { Insert text }
  389. List^.AtInsert(6, NewStr('Jaguar')); { Insert text }
  390. List^.AtInsert(7, NewStr('Melon')); { Insert text }
  391. List^.AtInsert(8, NewStr('Ninth')); { Insert text }
  392. List^.AtInsert(9, NewStr('Last item')); { Insert text }
  393. Lb^.Newlist(List); { Give list to listbox }
  394. R.Assign(30, 2, 40, 4); { Assign area }
  395. P^.Insert(New(PButton, Init(R, '~O~k', 100, bfGrabFocus)));{ Create okay button }
  396. R.Assign(30, 15, 40, 17); { Assign area }
  397. Desktop^.Insert(P); { Insert dialog }
  398. P3:=P;
  399. End;
  400. END;
  401. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  402. { MAIN PROGRAM START }
  403. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  404. VAR I: Integer; R: TRect; P: PGroup; MyApp: TTvDemo;
  405. {$IFDEF OS2PM}
  406. {$IFDEF OS_OS2} Message: QMSg; Event: TEvent; {$ENDIF}
  407. {$ENDIF OS2PM}
  408. BEGIN
  409. (*SystemPalette := CreateRGBPalette(256); { Create palette }
  410. For I := 0 To 15 Do Begin
  411. GetSystemRGBEntry(I, RGB); { Get palette entry }
  412. AddToRGBPalette(RGB, SystemPalette); { Add entry to palette }
  413. End;*)
  414. MyApp.Init; { Initialize app }
  415. MyApp.Run; { Run the app }
  416. {$IFDEF OS2PM}
  417. {$IFDEF OS_OS2}
  418. while (MyApp.EndState = 0)
  419. AND WinGetMsg(Anchor, Message, 0, 0, 0) Do Begin
  420. WinDispatchMsg(Anchor, Message);
  421. NextQueuedEvent(Event);
  422. If (event.What <> evNothing)
  423. Then MyApp.handleEvent(Event);
  424. End;
  425. {$ENDIF}
  426. {$ENDIF OS2PM}
  427. MyApp.Done; { Dispose of app }
  428. {DisposeRGBPalette(SystemPalette);}
  429. END.