app.pas 53 KB

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