app.pas 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. { $Id$}
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GRAPHICAL clone of APP.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  9. { [email protected] - primary e-mail addr }
  10. { [email protected] - backup e-mail addr }
  11. { }
  12. {****************[ THIS CODE IS FREEWARE ]*****************}
  13. { }
  14. { This sourcecode is released for the purpose to }
  15. { promote the pascal language on all platforms. You may }
  16. { redistribute it and/or modify with the following }
  17. { DISCLAIMER. }
  18. { }
  19. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  20. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  21. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  22. { }
  23. {*****************[ SUPPORTED PLATFORMS ]******************}
  24. { }
  25. { Only Free Pascal Compiler supported }
  26. { }
  27. {**********************************************************}
  28. UNIT App;
  29. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  30. INTERFACE
  31. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  32. {====Include file to sort compiler platform out =====================}
  33. {$I Platform.inc}
  34. {====================================================================}
  35. {==== Compiler directives ===========================================}
  36. {$X+} { Extended syntax is ok }
  37. {$R-} { Disable range checking }
  38. {$S-} { Disable Stack Checking }
  39. {$I-} { Disable IO Checking }
  40. {$Q-} { Disable Overflow Checking }
  41. {$V-} { Turn off strict VAR strings }
  42. {====================================================================}
  43. USES
  44. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  45. Windows, { Standard units }
  46. {$ENDIF}
  47. {$IFDEF OS_OS2} { OS2 CODE }
  48. {$IFDEF PPC_FPC}
  49. Os2Def, DosCalls, PmWin, { Standard units }
  50. {$ELSE}
  51. Os2Def, Os2Base, OS2PmApi, { Standard units }
  52. {$ENDIF}
  53. {$ENDIF}
  54. Dos,
  55. Video,
  56. FVCommon, Memory, { GFV standard units }
  57. Objects, Drivers, Views, Menus, HistList, Dialogs,
  58. msgbox, fvconsts;
  59. {***************************************************************************}
  60. { PUBLIC CONSTANTS }
  61. {***************************************************************************}
  62. {---------------------------------------------------------------------------}
  63. { STANDARD APPLICATION COMMAND CONSTANTS }
  64. {---------------------------------------------------------------------------}
  65. CONST
  66. cmNew = 30; { Open new file }
  67. cmOpen = 31; { Open a file }
  68. cmSave = 32; { Save current }
  69. cmSaveAs = 33; { Save current as }
  70. cmSaveAll = 34; { Save all files }
  71. cmChangeDir = 35; { Change directories }
  72. cmDosShell = 36; { Dos shell }
  73. cmCloseAll = 37; { Close all windows }
  74. {---------------------------------------------------------------------------}
  75. { TApplication PALETTE ENTRIES }
  76. {---------------------------------------------------------------------------}
  77. CONST
  78. apColor = 0; { Coloured app }
  79. apBlackWhite = 1; { B&W application }
  80. apMonochrome = 2; { Monochrome app }
  81. {---------------------------------------------------------------------------}
  82. { TBackGround PALETTES }
  83. {---------------------------------------------------------------------------}
  84. CONST
  85. CBackground = #1; { Background colour }
  86. {---------------------------------------------------------------------------}
  87. { TApplication PALETTES }
  88. {---------------------------------------------------------------------------}
  89. CONST
  90. { Turbo Vision 1.0 Color Palettes }
  91. CColor =
  92. #$81#$70#$78#$74#$20#$28#$24#$17#$1F#$1A#$31#$31#$1E#$71#$1F +
  93. #$37#$3F#$3A#$13#$13#$3E#$21#$3F#$70#$7F#$7A#$13#$13#$70#$7F#$7E +
  94. #$70#$7F#$7A#$13#$13#$70#$70#$7F#$7E#$20#$2B#$2F#$78#$2E#$70#$30 +
  95. #$3F#$3E#$1F#$2F#$1A#$20#$72#$31#$31#$30#$2F#$3E#$31#$13#$38#$00;
  96. CBlackWhite =
  97. #$70#$70#$78#$7F#$07#$07#$0F#$07#$0F#$07#$70#$70#$07#$70#$0F +
  98. #$07#$0F#$07#$70#$70#$07#$70#$0F#$70#$7F#$7F#$70#$07#$70#$07#$0F +
  99. #$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
  100. #$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00;
  101. CMonochrome =
  102. #$70#$07#$07#$0F#$70#$70#$70#$07#$0F#$07#$70#$70#$07#$70#$00 +
  103. #$07#$0F#$07#$70#$70#$07#$70#$00#$70#$70#$70#$07#$07#$70#$07#$00 +
  104. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  105. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00;
  106. { Turbo Vision 2.0 Color Palettes }
  107. CAppColor =
  108. #$71#$70#$78#$74#$20#$28#$24#$17#$1F#$1A#$31#$31#$1E#$71#$1F +
  109. #$37#$3F#$3A#$13#$13#$3E#$21#$3F#$70#$7F#$7A#$13#$13#$70#$7F#$7E +
  110. #$70#$7F#$7A#$13#$13#$70#$70#$7F#$7E#$20#$2B#$2F#$78#$2E#$70#$30 +
  111. #$3F#$3E#$1F#$2F#$1A#$20#$72#$31#$31#$30#$2F#$3E#$31#$13#$38#$00 +
  112. #$17#$1F#$1A#$71#$71#$1E#$17#$1F#$1E#$20#$2B#$2F#$78#$2E#$10#$30 +
  113. #$3F#$3E#$70#$2F#$7A#$20#$12#$31#$31#$30#$2F#$3E#$31#$13#$38#$00 +
  114. #$37#$3F#$3A#$13#$13#$3E#$30#$3F#$3E#$20#$2B#$2F#$78#$2E#$30#$70 +
  115. #$7F#$7E#$1F#$2F#$1A#$20#$32#$31#$71#$70#$2F#$7E#$71#$13#$38#$00;
  116. CAppBlackWhite =
  117. #$70#$70#$78#$7F#$07#$07#$0F#$07#$0F#$07#$70#$70#$07#$70#$0F +
  118. #$07#$0F#$07#$70#$70#$07#$70#$0F#$70#$7F#$7F#$70#$07#$70#$07#$0F +
  119. #$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
  120. #$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00 +
  121. #$07#$0F#$0F#$07#$70#$07#$07#$0F#$0F#$70#$78#$7F#$08#$7F#$08#$70 +
  122. #$7F#$7F#$7F#$0F#$70#$70#$07#$70#$70#$70#$07#$7F#$70#$07#$78#$00 +
  123. #$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
  124. #$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00;
  125. CAppMonochrome =
  126. #$70#$07#$07#$0F#$70#$70#$70#$07#$0F#$07#$70#$70#$07#$70#$00 +
  127. #$07#$0F#$07#$70#$70#$07#$70#$00#$70#$70#$70#$07#$07#$70#$07#$00 +
  128. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  129. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
  130. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  131. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
  132. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  133. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00;
  134. {---------------------------------------------------------------------------}
  135. { STANDRARD HELP CONTEXT CONSTANTS }
  136. {---------------------------------------------------------------------------}
  137. CONST
  138. { Note: range $FF00 - $FFFF of help contexts are reserved by Borland }
  139. hcNew = $FF01; { New file help }
  140. hcOpen = $FF02; { Open file help }
  141. hcSave = $FF03; { Save file help }
  142. hcSaveAs = $FF04; { Save file as help }
  143. hcSaveAll = $FF05; { Save all files help }
  144. hcChangeDir = $FF06; { Change dir help }
  145. hcDosShell = $FF07; { Dos shell help }
  146. hcExit = $FF08; { Exit program help }
  147. hcUndo = $FF10; { Clipboard undo help }
  148. hcCut = $FF11; { Clipboard cut help }
  149. hcCopy = $FF12; { Clipboard copy help }
  150. hcPaste = $FF13; { Clipboard paste help }
  151. hcClear = $FF14; { Clipboard clear help }
  152. hcTile = $FF20; { Desktop tile help }
  153. hcCascade = $FF21; { Desktop cascade help }
  154. hcCloseAll = $FF22; { Desktop close all }
  155. hcResize = $FF23; { Window resize help }
  156. hcZoom = $FF24; { Window zoom help }
  157. hcNext = $FF25; { Window next help }
  158. hcPrev = $FF26; { Window previous help }
  159. hcClose = $FF27; { Window close help }
  160. {***************************************************************************}
  161. { PUBLIC OBJECT DEFINITIONS }
  162. {***************************************************************************}
  163. {---------------------------------------------------------------------------}
  164. { TBackGround OBJECT - BACKGROUND OBJECT }
  165. {---------------------------------------------------------------------------}
  166. TYPE
  167. TBackGround = OBJECT (TView)
  168. Pattern: Char; { Background pattern }
  169. CONSTRUCTOR Init (Var Bounds: TRect; APattern: Char);
  170. CONSTRUCTOR Load (Var S: TStream);
  171. FUNCTION GetPalette: PPalette; Virtual;
  172. PROCEDURE Draw; Virtual;
  173. PROCEDURE Store (Var S: TStream);
  174. END;
  175. PBackGround = ^TBackGround;
  176. {---------------------------------------------------------------------------}
  177. { TDeskTop OBJECT - DESKTOP OBJECT }
  178. {---------------------------------------------------------------------------}
  179. TYPE
  180. TDeskTop = OBJECT (TGroup)
  181. Background : PBackground; { Background view }
  182. TileColumnsFirst: Boolean; { Tile direction }
  183. CONSTRUCTOR Init (Var Bounds: TRect);
  184. CONSTRUCTOR Load (Var S: TStream);
  185. PROCEDURE TileError; Virtual;
  186. PROCEDURE InitBackGround; Virtual;
  187. PROCEDURE Tile (Var R: TRect);
  188. PROCEDURE Store (Var S: TStream);
  189. PROCEDURE Cascade (Var R: TRect);
  190. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  191. END;
  192. PDeskTop = ^TDeskTop;
  193. {---------------------------------------------------------------------------}
  194. { TProgram OBJECT - PROGRAM ANCESTOR OBJECT }
  195. {---------------------------------------------------------------------------}
  196. TYPE
  197. TProgram = OBJECT (TGroup)
  198. CONSTRUCTOR Init;
  199. DESTRUCTOR Done; Virtual;
  200. FUNCTION GetPalette: PPalette; Virtual;
  201. FUNCTION CanMoveFocus: Boolean;
  202. FUNCTION ValidView (P: PView): PView;
  203. FUNCTION InsertWindow (P: PWindow): PWindow;
  204. FUNCTION ExecuteDialog (P: PDialog; Data: Pointer): Word;
  205. PROCEDURE Run; Virtual;
  206. PROCEDURE Idle; Virtual;
  207. PROCEDURE InitScreen; Virtual;
  208. procedure DoneScreen; virtual;
  209. PROCEDURE InitDeskTop; Virtual;
  210. PROCEDURE OutOfMemory; Virtual;
  211. PROCEDURE InitMenuBar; Virtual;
  212. PROCEDURE InitStatusLine; Virtual;
  213. PROCEDURE SetScreenMode (Mode: Word);
  214. PROCEDURE SetScreenVideoMode(const Mode: TVideoMode);
  215. PROCEDURE PutEvent (Var Event: TEvent); Virtual;
  216. PROCEDURE GetEvent (Var Event: TEvent); Virtual;
  217. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  218. END;
  219. PProgram = ^TProgram;
  220. {---------------------------------------------------------------------------}
  221. { TApplication OBJECT - APPLICATION OBJECT }
  222. {---------------------------------------------------------------------------}
  223. TYPE
  224. TApplication = OBJECT (TProgram)
  225. CONSTRUCTOR Init;
  226. DESTRUCTOR Done; Virtual;
  227. PROCEDURE Tile;
  228. PROCEDURE Cascade;
  229. PROCEDURE DosShell;
  230. PROCEDURE GetTileRect (Var R: TRect); Virtual;
  231. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  232. procedure WriteShellMsg; virtual;
  233. END;
  234. PApplication = ^TApplication; { Application ptr }
  235. {***************************************************************************}
  236. { INTERFACE ROUTINES }
  237. {***************************************************************************}
  238. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  239. { STANDARD MENU AND STATUS LINES ROUTINES }
  240. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  241. {-StdStatusKeys------------------------------------------------------
  242. Returns a pointer to a linked list of commonly used status line keys.
  243. The default status line for TApplication uses StdStatusKeys as its
  244. complete list of status keys.
  245. 22Oct99 LdB
  246. ---------------------------------------------------------------------}
  247. FUNCTION StdStatusKeys (Next: PStatusItem): PStatusItem;
  248. {-StdFileMenuItems---------------------------------------------------
  249. Returns a pointer to a list of menu items for a standard File menu.
  250. The standard File menu items are New, Open, Save, Save As, Save All,
  251. Change Dir, OS Shell, and Exit.
  252. 22Oct99 LdB
  253. ---------------------------------------------------------------------}
  254. FUNCTION StdFileMenuItems (Next: PMenuItem): PMenuItem;
  255. {-StdEditMenuItems---------------------------------------------------
  256. Returns a pointer to a list of menu items for a standard Edit menu.
  257. The standard Edit menu items are Undo, Cut, Copy, Paste, and Clear.
  258. 22Oct99 LdB
  259. ---------------------------------------------------------------------}
  260. FUNCTION StdEditMenuItems (Next: PMenuItem): PMenuItem;
  261. {-StdWindowMenuItems-------------------------------------------------
  262. Returns a pointer to a list of menu items for a standard Window menu.
  263. The standard Window menu items are Tile, Cascade, Close All,
  264. Size/Move, Zoom, Next, Previous, and Close.
  265. 22Oct99 LdB
  266. ---------------------------------------------------------------------}
  267. FUNCTION StdWindowMenuItems (Next: PMenuItem): PMenuItem;
  268. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  269. { OBJECT REGISTER ROUTINES }
  270. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  271. {-RegisterApp--------------------------------------------------------
  272. Calls RegisterType for each of the object types defined in this unit.
  273. 22oct99 LdB
  274. ---------------------------------------------------------------------}
  275. PROCEDURE RegisterApp;
  276. {***************************************************************************}
  277. { OBJECT REGISTRATION }
  278. {***************************************************************************}
  279. {---------------------------------------------------------------------------}
  280. { TBackGround STREAM REGISTRATION }
  281. {---------------------------------------------------------------------------}
  282. CONST
  283. RBackGround: TStreamRec = (
  284. ObjType: idBackground; { Register id = 30 }
  285. VmtLink: TypeOf(TBackGround);
  286. Load: @TBackGround.Load; { Object load method }
  287. Store: @TBackGround.Store { Object store method }
  288. );
  289. {---------------------------------------------------------------------------}
  290. { TDeskTop STREAM REGISTRATION }
  291. {---------------------------------------------------------------------------}
  292. CONST
  293. RDeskTop: TStreamRec = (
  294. ObjType: idDesktop; { Register id = 31 }
  295. VmtLink: TypeOf(TDeskTop);
  296. Load: @TDeskTop.Load; { Object load method }
  297. Store: @TDeskTop.Store { Object store method }
  298. );
  299. {***************************************************************************}
  300. { INITIALIZED PUBLIC VARIABLES }
  301. {***************************************************************************}
  302. {---------------------------------------------------------------------------}
  303. { INITIALIZED PUBLIC VARIABLES }
  304. {---------------------------------------------------------------------------}
  305. CONST
  306. AppPalette: Integer = apColor; { Application colour }
  307. Desktop: PDeskTop = Nil; { Desktop object }
  308. MenuBar: PMenuView = Nil; { Application menu }
  309. StatusLine: PStatusLine = Nil; { App status line }
  310. Application : PApplication = Nil; { Application object }
  311. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  312. IMPLEMENTATION
  313. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  314. uses
  315. Mouse,Resource;
  316. {***************************************************************************}
  317. { PRIVATE DEFINED CONSTANTS }
  318. {***************************************************************************}
  319. {***************************************************************************}
  320. { PRIVATE INITIALIZED VARIABLES }
  321. {***************************************************************************}
  322. {---------------------------------------------------------------------------}
  323. { INITIALIZED PRIVATE VARIABLES }
  324. {---------------------------------------------------------------------------}
  325. CONST Pending: TEvent = (What: evNothing); { Pending event }
  326. {---------------------------------------------------------------------------}
  327. { Tileable -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  328. {---------------------------------------------------------------------------}
  329. FUNCTION Tileable (P: PView): Boolean;
  330. BEGIN
  331. Tileable := (P^.Options AND ofTileable <> 0) AND { View is tileable }
  332. (P^.State AND sfVisible <> 0); { View is visible }
  333. END;
  334. {---------------------------------------------------------------------------}
  335. { ISqr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  336. {---------------------------------------------------------------------------}
  337. FUNCTION ISqr (X: Sw_Integer): Sw_Integer;
  338. VAR I: Sw_Integer;
  339. BEGIN
  340. I := 0; { Set value to zero }
  341. Repeat
  342. Inc(I); { Inc value }
  343. Until (I * I > X); { Repeat till Sqr > X }
  344. ISqr := I - 1; { Return result }
  345. END;
  346. {---------------------------------------------------------------------------}
  347. { MostEqualDivisors -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  348. {---------------------------------------------------------------------------}
  349. PROCEDURE MostEqualDivisors (N: Integer; Var X, Y: Integer; FavorY: Boolean);
  350. VAR I: Integer;
  351. BEGIN
  352. I := ISqr(N); { Int square of N }
  353. If ((N MOD I) <> 0) Then { Initial guess }
  354. If ((N MOD (I+1)) = 0) Then Inc(I); { Add one row/column }
  355. If (I < (N DIV I)) Then I := N DIV I; { In first page }
  356. If FavorY Then Begin { Horz preferred }
  357. X := N DIV I; { Calc x position }
  358. Y := I; { Set y position }
  359. End Else Begin { Vert preferred }
  360. Y := N DIV I; { Calc y position }
  361. X := I; { Set x position }
  362. End;
  363. END;
  364. {***************************************************************************}
  365. { OBJECT METHODS }
  366. {***************************************************************************}
  367. {--TBackGround--------------------------------------------------------------}
  368. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  369. {---------------------------------------------------------------------------}
  370. CONSTRUCTOR TBackGround.Init (Var Bounds: TRect; APattern: Char);
  371. BEGIN
  372. Inherited Init(Bounds); { Call ancestor }
  373. GrowMode := gfGrowHiX + gfGrowHiY; { Set grow modes }
  374. Pattern := APattern; { Hold pattern }
  375. END;
  376. {--TBackGround--------------------------------------------------------------}
  377. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  378. {---------------------------------------------------------------------------}
  379. CONSTRUCTOR TBackGround.Load (Var S: TStream);
  380. BEGIN
  381. Inherited Load(S); { Call ancestor }
  382. S.Read(Pattern, SizeOf(Pattern)); { Read pattern data }
  383. END;
  384. {--TBackGround--------------------------------------------------------------}
  385. { GetPalette -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  386. {---------------------------------------------------------------------------}
  387. FUNCTION TBackGround.GetPalette: PPalette;
  388. CONST P: String[Length(CBackGround)] = CbackGround; { Always normal string }
  389. BEGIN
  390. GetPalette := @P; { Return palette }
  391. END;
  392. {--TBackGround--------------------------------------------------------------}
  393. { DrawBackground -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  394. {---------------------------------------------------------------------------}
  395. PROCEDURE TBackground.Draw;
  396. VAR B: TDrawBuffer;
  397. BEGIN
  398. MoveChar(B, Pattern, GetColor($01), Size.X); { Fill draw buffer }
  399. WriteLine(0, 0, Size.X, Size.Y, B); { Draw to area }
  400. END;
  401. {--TBackGround--------------------------------------------------------------}
  402. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  403. {---------------------------------------------------------------------------}
  404. PROCEDURE TBackGround.Store (Var S: TStream);
  405. BEGIN
  406. TView.Store(S); { TView store called }
  407. S.Write(Pattern, SizeOf(Pattern)); { Write pattern data }
  408. END;
  409. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  410. { TDesktop OBJECT METHODS }
  411. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  412. {--TDesktop-----------------------------------------------------------------}
  413. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  414. {---------------------------------------------------------------------------}
  415. CONSTRUCTOR TDesktop.Init (Var Bounds: Objects.TRect);
  416. BEGIN
  417. Inherited Init(Bounds); { Call ancestor }
  418. GrowMode := gfGrowHiX + gfGrowHiY; { Set growmode }
  419. InitBackground; { Create background }
  420. If (Background <> Nil) Then Insert(Background); { Insert background }
  421. END;
  422. {--TDesktop-----------------------------------------------------------------}
  423. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  424. {---------------------------------------------------------------------------}
  425. CONSTRUCTOR TDesktop.Load (Var S: TStream);
  426. BEGIN
  427. Inherited Load(S); { Call ancestor }
  428. GetSubViewPtr(S, Background); { Load background }
  429. S.Read(TileColumnsFirst, SizeOf(TileColumnsFirst));{ Read data }
  430. END;
  431. {--TDesktop-----------------------------------------------------------------}
  432. { TileError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  433. {---------------------------------------------------------------------------}
  434. PROCEDURE TDeskTop.TileError;
  435. BEGIN { Abstract method }
  436. END;
  437. {--TDesktop-----------------------------------------------------------------}
  438. { InitBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  439. {---------------------------------------------------------------------------}
  440. PROCEDURE TDesktop.InitBackground;
  441. CONST Ch: Char = #176;
  442. VAR R: TRect;
  443. BEGIN
  444. GetExtent(R); { Get desktop extents }
  445. BackGround := New(PBackground, Init(R, Ch)); { Insert a background }
  446. END;
  447. {--TDesktop-----------------------------------------------------------------}
  448. { Tile -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  449. {---------------------------------------------------------------------------}
  450. PROCEDURE TDeskTop.Tile (Var R: TRect);
  451. VAR NumCols, NumRows, NumTileable, LeftOver, TileNum: Integer;
  452. FUNCTION DividerLoc (Lo, Hi, Num, Pos: Integer): Integer;
  453. BEGIN
  454. DividerLoc := LongInt( LongInt(Hi - Lo) * Pos)
  455. DIV Num + Lo; { Calc position }
  456. END;
  457. PROCEDURE DoCountTileable (P: PView); {$IFNDEF PPC_FPC}FAR;{$ENDIF}
  458. BEGIN
  459. If Tileable(P) Then Inc(NumTileable); { Count tileable views }
  460. END;
  461. PROCEDURE CalcTileRect (Pos: Integer; Var NR: TRect);
  462. VAR X, Y, D: Integer;
  463. BEGIN
  464. D := (NumCols - LeftOver) * NumRows; { Calc d value }
  465. If (Pos<D) Then Begin
  466. X := Pos DIV NumRows; Y := Pos MOD NumRows; { Calc positions }
  467. End Else Begin
  468. X := (Pos - D) div (NumRows + 1) +
  469. (NumCols - LeftOver); { Calc x position }
  470. Y := (Pos - D) mod (NumRows + 1); { Calc y position }
  471. End;
  472. NR.A.X := DividerLoc(R.A.X, R.B.X, NumCols, X); { Top left x position }
  473. NR.B.X := DividerLoc(R.A.X, R.B.X, NumCols, X+1);{ Right x position }
  474. If (Pos >= D) Then Begin
  475. NR.A.Y := DividerLoc(R.A.Y, R.B.Y,NumRows+1,Y);{ Top y position }
  476. NR.B.Y := DividerLoc(R.A.Y, R.B.Y, NumRows+1,
  477. Y+1); { Bottom y position }
  478. End Else Begin
  479. NR.A.Y := DividerLoc(R.A.Y, R.B.Y,NumRows,Y); { Top y position }
  480. NR.B.Y := DividerLoc(R.A.Y, R.B.Y, NumRows,
  481. Y+1); { Bottom y position }
  482. End;
  483. END;
  484. PROCEDURE DoTile(P: PView); {$IFNDEF PPC_FPC}FAR;{$ENDIF}
  485. VAR PState: Word; R: TRect;
  486. BEGIN
  487. If Tileable(P) Then Begin
  488. CalcTileRect(TileNum, R); { Calc tileable area }
  489. PState := P^.State; { Hold view state }
  490. P^.State := P^.State AND NOT sfVisible; { Temp not visible }
  491. P^.Locate(R); { Locate view }
  492. P^.State := PState; { Restore view state }
  493. Dec(TileNum); { One less to tile }
  494. End;
  495. END;
  496. BEGIN
  497. NumTileable := 0; { Zero tileable count }
  498. ForEach(@DoCountTileable); { Count tileable views }
  499. If (NumTileable>0) Then Begin
  500. MostEqualDivisors(NumTileable, NumCols, NumRows,
  501. NOT TileColumnsFirst); { Do pre calcs }
  502. If ((R.B.X - R.A.X) DIV NumCols = 0) OR
  503. ((R.B.Y - R.A.Y) DIV NumRows = 0) Then TileError { Can't tile }
  504. Else Begin
  505. LeftOver := NumTileable MOD NumCols; { Left over count }
  506. TileNum := NumTileable-1; { Tileable views }
  507. ForEach(@DoTile); { Tile each view }
  508. DrawView; { Now redraw }
  509. End;
  510. End;
  511. END;
  512. {--TDesktop-----------------------------------------------------------------}
  513. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  514. {---------------------------------------------------------------------------}
  515. PROCEDURE TDesktop.Store (Var S: TStream);
  516. BEGIN
  517. TGroup.Store(S); { Call group store }
  518. PutSubViewPtr(S, Background); { Store background }
  519. S.Write(TileColumnsFirst,SizeOf(TileColumnsFirst));{ Write data }
  520. END;
  521. {--TDesktop-----------------------------------------------------------------}
  522. { Cascade -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  523. {---------------------------------------------------------------------------}
  524. PROCEDURE TDeskTop.Cascade (Var R: TRect);
  525. VAR CascadeNum: Integer; LastView: PView; Min, Max: TPoint;
  526. PROCEDURE DoCount (P: PView); {$IFNDEF PPC_FPC}FAR;{$ENDIF}
  527. BEGIN
  528. If Tileable(P) Then Begin
  529. Inc(CascadeNum); LastView := P; { Count cascadable }
  530. End;
  531. END;
  532. PROCEDURE DoCascade (P: PView); {$IFNDEF PPC_FPC}FAR;{$ENDIF}
  533. VAR PState: Word; NR: TRect;
  534. BEGIN
  535. If Tileable(P) AND (CascadeNum >= 0) Then Begin { View cascadable }
  536. NR.Copy(R); { Copy rect area }
  537. Inc(NR.A.X, CascadeNum); { Inc x position }
  538. Inc(NR.A.Y, CascadeNum); { Inc y position }
  539. PState := P^.State; { Hold view state }
  540. P^.State := P^.State AND NOT sfVisible; { Temp stop draw }
  541. P^.Locate(NR); { Locate the view }
  542. P^.State := PState; { Now allow draws }
  543. Dec(CascadeNum); { Dec count }
  544. End;
  545. END;
  546. BEGIN
  547. CascadeNum := 0; { Zero cascade count }
  548. ForEach(@DoCount); { Count cascadable }
  549. If (CascadeNum>0) Then Begin
  550. LastView^.SizeLimits(Min, Max); { Check size limits }
  551. If (Min.X > R.B.X - R.A.X - CascadeNum) OR
  552. (Min.Y > R.B.Y - R.A.Y - CascadeNum) Then
  553. TileError Else Begin { Check for error }
  554. Dec(CascadeNum); { One less view }
  555. ForEach(@DoCascade); { Cascade view }
  556. DrawView; { Redraw now }
  557. End;
  558. End;
  559. END;
  560. {--TDesktop-----------------------------------------------------------------}
  561. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  562. {---------------------------------------------------------------------------}
  563. PROCEDURE TDesktop.HandleEvent (Var Event: TEvent);
  564. BEGIN
  565. Inherited HandleEvent(Event); { Call ancestor }
  566. If (Event.What = evCommand) Then Begin
  567. Case Event.Command of { Command event }
  568. cmNext: FocusNext(False); { Focus next view }
  569. cmPrev: If (BackGround <> Nil) Then Begin
  570. If Valid(cmReleasedFocus) Then
  571. Current^.PutInFrontOf(Background); { Focus last view }
  572. End Else FocusNext(True); { Focus prior view }
  573. Else Exit;
  574. End;
  575. ClearEvent(Event); { Clear the event }
  576. End;
  577. END;
  578. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  579. { TProgram OBJECT METHODS }
  580. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  581. {--TProgram-----------------------------------------------------------------}
  582. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  583. {---------------------------------------------------------------------------}
  584. CONSTRUCTOR TProgram.Init;
  585. VAR R: TRect;
  586. BEGIN
  587. R.Assign(0, 0, ScreenWidth, ScreenHeight); { Full screen area }
  588. Inherited Init(R); { Call ancestor }
  589. Application := @Self; { Set application ptr }
  590. InitScreen; { Initialize screen }
  591. State := sfVisible + sfSelected + sfFocused +
  592. sfModal + sfExposed; { Deafult states }
  593. Options := 0; { No options set }
  594. Size.X := ScreenWidth; { Set x size value }
  595. Size.Y := ScreenHeight; { Set y size value }
  596. InitStatusLine; { Create status line }
  597. InitMenuBar; { Create a bar menu }
  598. InitDesktop; { Create desktop }
  599. If (Desktop <> Nil) Then Insert(Desktop); { Insert desktop }
  600. If (StatusLine <> Nil) Then Insert(StatusLine); { Insert status line }
  601. If (MenuBar <> Nil) Then Insert(MenuBar); { Insert menu bar }
  602. END;
  603. {--TProgram-----------------------------------------------------------------}
  604. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  605. {---------------------------------------------------------------------------}
  606. DESTRUCTOR TProgram.Done;
  607. BEGIN
  608. { Do not free the Buffer of Video Unit }
  609. If Buffer = Views.PVideoBuf(VideoBuf) then
  610. Buffer:=nil;
  611. If (Desktop <> Nil) Then Dispose(Desktop, Done); { Destroy desktop }
  612. If (MenuBar <> Nil) Then Dispose(MenuBar, Done); { Destroy menu bar }
  613. If (StatusLine <> Nil) Then
  614. Dispose(StatusLine, Done); { Destroy status line }
  615. Application := Nil; { Clear application }
  616. Inherited Done; { Call ancestor }
  617. END;
  618. {--TProgram-----------------------------------------------------------------}
  619. { GetPalette -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  620. {---------------------------------------------------------------------------}
  621. FUNCTION TProgram.GetPalette: PPalette;
  622. CONST P: Array[apColor..apMonochrome] Of String = (CAppColor, CAppBlackWhite,
  623. CAppMonochrome);
  624. BEGIN
  625. GetPalette := @P[AppPalette]; { Return palette }
  626. END;
  627. {--TProgram-----------------------------------------------------------------}
  628. { CanMoveFocus -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 23Sep97 LdB }
  629. {---------------------------------------------------------------------------}
  630. FUNCTION TProgram.CanMoveFocus: Boolean;
  631. BEGIN
  632. If (Desktop <> Nil) Then { Valid desktop view }
  633. CanMovefocus := DeskTop^.Valid(cmReleasedFocus) { Check focus move }
  634. Else CanMoveFocus := True; { No desktop who cares! }
  635. END;
  636. {--TProgram-----------------------------------------------------------------}
  637. { ValidView -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  638. {---------------------------------------------------------------------------}
  639. FUNCTION TProgram.ValidView (P: PView): PView;
  640. BEGIN
  641. ValidView := Nil; { Preset failure }
  642. If (P <> Nil) Then Begin
  643. If LowMemory Then Begin { Check memroy }
  644. Dispose(P, Done); { Dispose view }
  645. OutOfMemory; { Call out of memory }
  646. Exit; { Now exit }
  647. End;
  648. If NOT P^.Valid(cmValid) Then Begin { Check view valid }
  649. Dispose(P, Done); { Dipose view }
  650. Exit; { Now exit }
  651. End;
  652. ValidView := P; { Return view }
  653. End;
  654. END;
  655. {--TProgram-----------------------------------------------------------------}
  656. { InsertWindow -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  657. {---------------------------------------------------------------------------}
  658. FUNCTION TProgram.InsertWindow (P: PWindow): PWindow;
  659. BEGIN
  660. InsertWindow := Nil; { Preset failure }
  661. If (ValidView(P) <> Nil) Then { Check view valid }
  662. If (CanMoveFocus) AND (Desktop <> Nil) { Can we move focus }
  663. Then Begin
  664. Desktop^.Insert(P); { Insert window }
  665. InsertWindow := P; { Return view ptr }
  666. End Else Dispose(P, Done); { Dispose view }
  667. END;
  668. {--TProgram-----------------------------------------------------------------}
  669. { ExecuteDialog -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  670. {---------------------------------------------------------------------------}
  671. FUNCTION TProgram.ExecuteDialog (P: PDialog; Data: Pointer): Word;
  672. VAR ExecResult: Word;
  673. BEGIN
  674. ExecuteDialog := cmCancel; { Preset cancel }
  675. If (ValidView(P) <> Nil) Then Begin { Check view valid }
  676. If (Data <> Nil) Then P^.SetData(Data^); { Set data }
  677. If (P <> Nil) Then P^.SelectDefaultView; { Select default }
  678. ExecResult := Desktop^.ExecView(P); { Execute view }
  679. If (ExecResult <> cmCancel) AND (Data <> Nil)
  680. Then P^.GetData(Data^); { Get data back }
  681. Dispose(P, Done); { Dispose of dialog }
  682. ExecuteDialog := ExecResult; { Return result }
  683. End;
  684. END;
  685. {--TProgram-----------------------------------------------------------------}
  686. { Run -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  687. {---------------------------------------------------------------------------}
  688. PROCEDURE TProgram.Run;
  689. BEGIN
  690. Execute; { Call execute }
  691. END;
  692. {--TProgram-----------------------------------------------------------------}
  693. { Idle -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  694. {---------------------------------------------------------------------------}
  695. PROCEDURE TProgram.Idle;
  696. BEGIN
  697. If (StatusLine <> Nil) Then StatusLine^.Update; { Update statusline }
  698. If CommandSetChanged Then Begin { Check command change }
  699. Message(@Self, evBroadcast, cmCommandSetChanged,
  700. Nil); { Send message }
  701. CommandSetChanged := False; { Clear flag }
  702. End;
  703. GiveUpTimeSlice;
  704. END;
  705. {--TProgram-----------------------------------------------------------------}
  706. { InitScreen -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  707. {---------------------------------------------------------------------------}
  708. PROCEDURE TProgram.InitScreen;
  709. BEGIN
  710. { the orginal code can't be used here because of the limited
  711. video unit capabilities, the mono modus can't be handled
  712. }
  713. Drivers.InitVideo;
  714. if (ScreenMode.Col div ScreenMode.Row<2) then
  715. ShadowSize.X := 1
  716. else
  717. ShadowSize.X := 2;
  718. ShadowSize.Y := 1;
  719. ShowMarkers := False;
  720. if ScreenMode.color then
  721. AppPalette := apColor
  722. else
  723. AppPalette := apBlackWhite;
  724. Buffer := Views.PVideoBuf(VideoBuf);
  725. END;
  726. procedure TProgram.DoneScreen;
  727. begin
  728. Drivers.DoneVideo;
  729. Buffer:=nil;
  730. end;
  731. {--TProgram-----------------------------------------------------------------}
  732. { InitDeskTop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  733. {---------------------------------------------------------------------------}
  734. PROCEDURE TProgram.InitDesktop;
  735. VAR R: TRect;
  736. BEGIN
  737. GetExtent(R); { Get view extent }
  738. If (MenuBar <> Nil) Then Inc(R.A.Y); { Adjust top down }
  739. If (StatusLine <> Nil) Then Dec(R.B.Y); { Adjust bottom up }
  740. DeskTop := New(PDesktop, Init(R)); { Create desktop }
  741. END;
  742. {--TProgram-----------------------------------------------------------------}
  743. { OutOfMemory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  744. {---------------------------------------------------------------------------}
  745. PROCEDURE TProgram.OutOfMemory;
  746. BEGIN { Abstract method }
  747. END;
  748. {--TProgram-----------------------------------------------------------------}
  749. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  750. {---------------------------------------------------------------------------}
  751. PROCEDURE TProgram.InitMenuBar;
  752. VAR R: TRect;
  753. BEGIN
  754. GetExtent(R); { Get view extents }
  755. R.B.Y := R.A.Y + 1; { One line high }
  756. MenuBar := New(PMenuBar, Init(R, Nil)); { Create menu bar }
  757. END;
  758. {--TProgram-----------------------------------------------------------------}
  759. { InitStatusLine -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  760. {---------------------------------------------------------------------------}
  761. PROCEDURE TProgram.InitStatusLine;
  762. VAR R: TRect;
  763. BEGIN
  764. GetExtent(R); { Get view extents }
  765. R.A.Y := R.B.Y - 1; { One line high }
  766. New(StatusLine, Init(R,
  767. NewStatusDef(0, $FFFF,
  768. NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  769. StdStatusKeys(Nil)), Nil))); { Default status line }
  770. END;
  771. {--TProgram-----------------------------------------------------------------}
  772. { SetScreenMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  773. {---------------------------------------------------------------------------}
  774. PROCEDURE TProgram.SetScreenMode (Mode: Word);
  775. var
  776. R: TRect;
  777. begin
  778. HideMouse;
  779. DoneMemory;
  780. InitMemory;
  781. InitScreen;
  782. Buffer := Views.PVideoBuf(VideoBuf);
  783. R.Assign(0, 0, ScreenWidth, ScreenHeight);
  784. ChangeBounds(R);
  785. ShowMouse;
  786. end;
  787. procedure TProgram.SetScreenVideoMode(const Mode: TVideoMode);
  788. var
  789. R: TRect;
  790. begin
  791. DoneMouse;
  792. DoneMemory;
  793. ScreenMode:=Mode;
  794. InitMouse;
  795. InitMemory;
  796. InitScreen;
  797. Video.SetVideoMode(Mode);
  798. Buffer := Views.PVideoBuf(VideoBuf);
  799. R.Assign(0, 0, ScreenWidth, ScreenHeight);
  800. ChangeBounds(R);
  801. ShowMouse;
  802. end;
  803. {--TProgram-----------------------------------------------------------------}
  804. { PutEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  805. {---------------------------------------------------------------------------}
  806. PROCEDURE TProgram.PutEvent (Var Event: TEvent);
  807. BEGIN
  808. Pending := Event; { Set pending event }
  809. END;
  810. {--TProgram-----------------------------------------------------------------}
  811. { GetEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10May98 LdB }
  812. {---------------------------------------------------------------------------}
  813. PROCEDURE TProgram.GetEvent (Var Event: TEvent);
  814. BEGIN
  815. Event.What := evNothing;
  816. If (Event.What = evNothing) Then Begin
  817. If (Pending.What <> evNothing) Then Begin { Pending event }
  818. Event := Pending; { Load pending event }
  819. Pending.What := evNothing; { Clear pending event }
  820. End Else Begin
  821. NextQueuedEvent(Event); { Next queued event }
  822. If (Event.What = evNothing) Then Begin
  823. GetKeyEvent(Event); { Fetch key event }
  824. If (Event.What = evKeyDown) then
  825. Begin
  826. if Event.keyCode = kbAltF12 then
  827. ReDraw;
  828. End;
  829. If (Event.What = evNothing) Then Begin { No mouse event }
  830. Drivers.GetMouseEvent(Event); { Load mouse event }
  831. If (Event.What = evNothing) Then
  832. begin
  833. Drivers.GetSystemEvent(Event); { Load system event }
  834. If (Event.What = evNothing) Then
  835. Idle; { Idle if no event }
  836. end;
  837. End;
  838. End;
  839. End;
  840. End;
  841. END;
  842. {--TProgram-----------------------------------------------------------------}
  843. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  844. {---------------------------------------------------------------------------}
  845. PROCEDURE TProgram.HandleEvent (Var Event: TEvent);
  846. VAR C: Char;
  847. BEGIN
  848. If (Event.What = evKeyDown) Then Begin { Key press event }
  849. C := GetAltChar(Event.KeyCode); { Get alt char code }
  850. If (C >= '1') AND (C <= '9') Then
  851. If (Message(Desktop, evBroadCast, cmSelectWindowNum,
  852. Pointer(Byte(C) - $30)) <> Nil) { Select window }
  853. Then ClearEvent(Event); { Clear event }
  854. End;
  855. Inherited HandleEvent(Event); { Call ancestor }
  856. If (Event.What = evCommand) AND { Command event }
  857. (Event.Command = cmQuit) Then Begin { Quit command }
  858. EndModal(cmQuit); { Endmodal operation }
  859. ClearEvent(Event); { Clear event }
  860. End;
  861. END;
  862. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  863. { TApplication OBJECT METHODS }
  864. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  865. {--TApplication-------------------------------------------------------------}
  866. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  867. {---------------------------------------------------------------------------}
  868. CONSTRUCTOR TApplication.Init;
  869. BEGIN
  870. InitMemory; { Start memory up }
  871. Drivers.InitVideo; { Start video up }
  872. Drivers.InitEvents; { Start event drive }
  873. Drivers.InitSysError; { Start system error }
  874. InitHistory; { Start history up }
  875. InitResource;
  876. InitMsgBox;
  877. Inherited Init; { Call ancestor }
  878. { init mouse and cursor }
  879. Video.SetCursorType(crHidden);
  880. Mouse.SetMouseXY(1,1);
  881. END;
  882. {--TApplication-------------------------------------------------------------}
  883. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  884. {---------------------------------------------------------------------------}
  885. DESTRUCTOR TApplication.Done;
  886. BEGIN
  887. Inherited Done; { Call ancestor }
  888. DoneHistory; { Close history }
  889. DoneResource;
  890. Drivers.DoneSysError; { Close system error }
  891. Drivers.DoneEvents; { Close event drive }
  892. DoneScreen;
  893. DoneMemory; { Close memory }
  894. END;
  895. {--TApplication-------------------------------------------------------------}
  896. { Tile -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  897. {---------------------------------------------------------------------------}
  898. PROCEDURE TApplication.Tile;
  899. VAR R: TRect;
  900. BEGIN
  901. GetTileRect(R); { Tileable area }
  902. If (Desktop <> Nil) Then Desktop^.Tile(R); { Tile desktop }
  903. END;
  904. {--TApplication-------------------------------------------------------------}
  905. { Cascade -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  906. {---------------------------------------------------------------------------}
  907. PROCEDURE TApplication.Cascade;
  908. VAR R: TRect;
  909. BEGIN
  910. GetTileRect(R); { Cascade area }
  911. If (Desktop <> Nil) Then Desktop^.Cascade(R); { Cascade desktop }
  912. END;
  913. {--TApplication-------------------------------------------------------------}
  914. { DosShell -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  915. {---------------------------------------------------------------------------}
  916. PROCEDURE TApplication.DosShell;
  917. BEGIN { Compatability only }
  918. DoneSysError;
  919. DoneEvents;
  920. DoneScreen;
  921. DoneDosMem;
  922. WriteShellMsg;
  923. SwapVectors;
  924. Exec(GetEnv('COMSPEC'), '');
  925. SwapVectors;
  926. InitDosMem;
  927. InitScreen;
  928. InitEvents;
  929. InitSysError;
  930. Redraw;
  931. END;
  932. {--TApplication-------------------------------------------------------------}
  933. { GetTileRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  934. {---------------------------------------------------------------------------}
  935. PROCEDURE TApplication.GetTileRect (Var R: TRect);
  936. BEGIN
  937. If (DeskTop <> Nil) Then Desktop^.GetExtent(R) { Desktop extents }
  938. Else GetExtent(R); { Our extents }
  939. END;
  940. {--TApplication-------------------------------------------------------------}
  941. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  942. {---------------------------------------------------------------------------}
  943. PROCEDURE TApplication.HandleEvent (Var Event: TEvent);
  944. BEGIN
  945. Inherited HandleEvent(Event); { Call ancestor }
  946. If (Event.What = evCommand) Then Begin
  947. Case Event.Command Of
  948. cmTile: Tile; { Tile request }
  949. cmCascade: Cascade; { Cascade request }
  950. cmDosShell: DosShell; { DOS shell request }
  951. Else Exit; { Unhandled exit }
  952. End;
  953. ClearEvent(Event); { Clear the event }
  954. End;
  955. END;
  956. procedure TApplication.WriteShellMsg;
  957. begin
  958. PrintStr(Strings^.Get(sTypeExitOnReturn));
  959. end;
  960. {***************************************************************************}
  961. { INTERFACE ROUTINES }
  962. {***************************************************************************}
  963. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  964. { STANDARD MENU AND STATUS LINES ROUTINES }
  965. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  966. {---------------------------------------------------------------------------}
  967. { StdStatusKeys -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  968. {---------------------------------------------------------------------------}
  969. FUNCTION StdStatusKeys (Next: PStatusItem): PStatusItem;
  970. BEGIN
  971. StdStatusKeys :=
  972. NewStatusKey('', kbAltX, cmQuit,
  973. NewStatusKey('', kbF10, cmMenu,
  974. NewStatusKey('', kbAltF3, cmClose,
  975. NewStatusKey('', kbF5, cmZoom,
  976. NewStatusKey('', kbCtrlF5, cmResize,
  977. NewStatusKey('', kbF6, cmNext,
  978. NewStatusKey('', kbShiftF6, cmPrev,
  979. Next)))))));
  980. END;
  981. {---------------------------------------------------------------------------}
  982. { StdFileMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  983. {---------------------------------------------------------------------------}
  984. FUNCTION StdFileMenuItems (Next: PMenuItem): PMenuItem;
  985. BEGIN
  986. StdFileMenuItems :=
  987. NewItem('~N~ew', '', kbNoKey, cmNew, hcNew,
  988. NewItem('~O~pen...', 'F3', kbF3, cmOpen, hcOpen,
  989. NewItem('~S~ave', 'F2', kbF2, cmSave, hcSave,
  990. NewItem('S~a~ve as...', '', kbNoKey, cmSaveAs, hcSaveAs,
  991. NewItem('Save a~l~l', '', kbNoKey, cmSaveAll, hcSaveAll,
  992. NewLine(
  993. NewItem('~C~hange dir...', '', kbNoKey, cmChangeDir, hcChangeDir,
  994. NewItem('OS shell', '', kbNoKey, cmDosShell, hcDosShell,
  995. NewItem('E~x~it', 'Alt+X', kbAltX, cmQuit, hcExit,
  996. Next)))))))));
  997. END;
  998. {---------------------------------------------------------------------------}
  999. { StdEditMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1000. {---------------------------------------------------------------------------}
  1001. FUNCTION StdEditMenuItems (Next: PMenuItem): PMenuItem;
  1002. BEGIN
  1003. StdEditMenuItems :=
  1004. NewItem('~U~ndo', '', kbAltBack, cmUndo, hcUndo,
  1005. NewLine(
  1006. NewItem('Cu~t~', 'Shift+Del', kbShiftDel, cmCut, hcCut,
  1007. NewItem('~C~opy', 'Ctrl+Ins', kbCtrlIns, cmCopy, hcCopy,
  1008. NewItem('~P~aste', 'Shift+Ins', kbShiftIns, cmPaste, hcPaste,
  1009. NewItem('C~l~ear', 'Ctrl+Del', kbCtrlDel, cmClear, hcClear,
  1010. Next))))));
  1011. END;
  1012. {---------------------------------------------------------------------------}
  1013. { StdWindowMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1014. {---------------------------------------------------------------------------}
  1015. FUNCTION StdWindowMenuItems (Next: PMenuItem): PMenuItem;
  1016. BEGIN
  1017. StdWindowMenuItems :=
  1018. NewItem('~T~ile', '', kbNoKey, cmTile, hcTile,
  1019. NewItem('C~a~scade', '', kbNoKey, cmCascade, hcCascade,
  1020. NewItem('Cl~o~se all', '', kbNoKey, cmCloseAll, hcCloseAll,
  1021. NewLine(
  1022. NewItem('~S~ize/Move','Ctrl+F5', kbCtrlF5, cmResize, hcResize,
  1023. NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcZoom,
  1024. NewItem('~N~ext', 'F6', kbF6, cmNext, hcNext,
  1025. NewItem('~P~revious', 'Shift+F6', kbShiftF6, cmPrev, hcPrev,
  1026. NewItem('~C~lose', 'Alt+F3', kbAltF3, cmClose, hcClose,
  1027. Next)))))))));
  1028. END;
  1029. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1030. { OBJECT REGISTER ROUTINES }
  1031. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1032. {---------------------------------------------------------------------------}
  1033. { RegisterApp -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1034. {---------------------------------------------------------------------------}
  1035. PROCEDURE RegisterApp;
  1036. BEGIN
  1037. RegisterType(RBackground); { Register background }
  1038. RegisterType(RDesktop); { Register desktop }
  1039. END;
  1040. END.
  1041. {
  1042. $Log$
  1043. Revision 1.29 2004-12-22 15:27:30 peter
  1044. * call giveuptimeslice to prevent busy loop with idle
  1045. Revision 1.28 2004/12/19 20:20:48 hajny
  1046. * ObjType references constants from fvconsts
  1047. Revision 1.27 2004/12/18 16:18:47 peter
  1048. win32 fixes
  1049. Revision 1.26 2004/11/06 22:03:06 peter
  1050. * fixed mouse
  1051. Revision 1.25 2004/11/06 17:08:48 peter
  1052. * drawing of tview merged from old fv code
  1053. }