testapp.pas 17 KB

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