testapp.pas 16 KB

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