app.pas 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  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. {Initscreen is passive only, i.e. it detects the video size and capabilities
  711. after initalization. Active video initalization is the task of Tapplication.}
  712. BEGIN
  713. { the orginal code can't be used here because of the limited
  714. video unit capabilities, the mono modus can't be handled
  715. }
  716. { Drivers.InitVideo;}
  717. if (ScreenMode.Col div ScreenMode.Row<2) then
  718. ShadowSize.X := 1
  719. else
  720. ShadowSize.X := 2;
  721. ShadowSize.Y := 1;
  722. ShowMarkers := False;
  723. if ScreenMode.color then
  724. AppPalette := apColor
  725. else
  726. AppPalette := apBlackWhite;
  727. Buffer := Views.PVideoBuf(VideoBuf);
  728. END;
  729. {procedure TProgram.DoneScreen;
  730. begin
  731. Drivers.DoneVideo;
  732. Buffer:=nil;
  733. end;}
  734. {--TProgram-----------------------------------------------------------------}
  735. { InitDeskTop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  736. {---------------------------------------------------------------------------}
  737. PROCEDURE TProgram.InitDesktop;
  738. VAR R: TRect;
  739. BEGIN
  740. GetExtent(R); { Get view extent }
  741. If (MenuBar <> Nil) Then Inc(R.A.Y); { Adjust top down }
  742. If (StatusLine <> Nil) Then Dec(R.B.Y); { Adjust bottom up }
  743. DeskTop := New(PDesktop, Init(R)); { Create desktop }
  744. END;
  745. {--TProgram-----------------------------------------------------------------}
  746. { OutOfMemory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  747. {---------------------------------------------------------------------------}
  748. PROCEDURE TProgram.OutOfMemory;
  749. BEGIN { Abstract method }
  750. END;
  751. {--TProgram-----------------------------------------------------------------}
  752. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  753. {---------------------------------------------------------------------------}
  754. PROCEDURE TProgram.InitMenuBar;
  755. VAR R: TRect;
  756. BEGIN
  757. GetExtent(R); { Get view extents }
  758. R.B.Y := R.A.Y + 1; { One line high }
  759. MenuBar := New(PMenuBar, Init(R, Nil)); { Create menu bar }
  760. END;
  761. {--TProgram-----------------------------------------------------------------}
  762. { InitStatusLine -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  763. {---------------------------------------------------------------------------}
  764. PROCEDURE TProgram.InitStatusLine;
  765. VAR R: TRect;
  766. BEGIN
  767. GetExtent(R); { Get view extents }
  768. R.A.Y := R.B.Y - 1; { One line high }
  769. New(StatusLine, Init(R,
  770. NewStatusDef(0, $FFFF,
  771. NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  772. StdStatusKeys(Nil)), Nil))); { Default status line }
  773. END;
  774. {--TProgram-----------------------------------------------------------------}
  775. { SetScreenMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  776. {---------------------------------------------------------------------------}
  777. PROCEDURE TProgram.SetScreenMode (Mode: Word);
  778. var
  779. R: TRect;
  780. begin
  781. HideMouse;
  782. { DoneMemory;}
  783. { InitMemory;}
  784. InitScreen;
  785. Buffer := Views.PVideoBuf(VideoBuf);
  786. R.Assign(0, 0, ScreenWidth, ScreenHeight);
  787. ChangeBounds(R);
  788. ShowMouse;
  789. end;
  790. procedure TProgram.SetScreenVideoMode(const Mode: TVideoMode);
  791. var
  792. R: TRect;
  793. begin
  794. DoneMouse;
  795. { DoneMemory;}
  796. ScreenMode:=Mode;
  797. InitMouse;
  798. { InitMemory;}
  799. InitScreen;
  800. Video.SetVideoMode(Mode);
  801. ScreenWidth:=Video.ScreenWidth;
  802. ScreenHeight:=Video.ScreenHeight;
  803. Buffer := Views.PVideoBuf(VideoBuf);
  804. R.Assign(0, 0, ScreenWidth, ScreenHeight);
  805. ChangeBounds(R);
  806. ShowMouse;
  807. end;
  808. {--TProgram-----------------------------------------------------------------}
  809. { PutEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  810. {---------------------------------------------------------------------------}
  811. PROCEDURE TProgram.PutEvent (Var Event: TEvent);
  812. BEGIN
  813. Pending := Event; { Set pending event }
  814. END;
  815. {--TProgram-----------------------------------------------------------------}
  816. { GetEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10May98 LdB }
  817. {---------------------------------------------------------------------------}
  818. PROCEDURE TProgram.GetEvent (Var Event: TEvent);
  819. BEGIN
  820. Event.What := evNothing;
  821. If (Event.What = evNothing) Then Begin
  822. If (Pending.What <> evNothing) Then Begin { Pending event }
  823. Event := Pending; { Load pending event }
  824. Pending.What := evNothing; { Clear pending event }
  825. End Else Begin
  826. NextQueuedEvent(Event); { Next queued event }
  827. If (Event.What = evNothing) Then Begin
  828. GetKeyEvent(Event); { Fetch key event }
  829. If (Event.What = evKeyDown) then
  830. Begin
  831. if Event.keyCode = kbAltF12 then
  832. ReDraw;
  833. End;
  834. If (Event.What = evNothing) Then Begin { No mouse event }
  835. Drivers.GetMouseEvent(Event); { Load mouse event }
  836. If (Event.What = evNothing) Then
  837. begin
  838. Drivers.GetSystemEvent(Event); { Load system event }
  839. If (Event.What = evNothing) Then
  840. Idle; { Idle if no event }
  841. end;
  842. End;
  843. End;
  844. End;
  845. End;
  846. END;
  847. {--TProgram-----------------------------------------------------------------}
  848. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  849. {---------------------------------------------------------------------------}
  850. PROCEDURE TProgram.HandleEvent (Var Event: TEvent);
  851. VAR C: Char;
  852. BEGIN
  853. If (Event.What = evKeyDown) Then Begin { Key press event }
  854. C := GetAltChar(Event.KeyCode); { Get alt char code }
  855. If (C >= '1') AND (C <= '9') Then
  856. If (Message(Desktop, evBroadCast, cmSelectWindowNum,
  857. Pointer(Byte(C) - $30)) <> Nil) { Select window }
  858. Then ClearEvent(Event); { Clear event }
  859. End;
  860. Inherited HandleEvent(Event); { Call ancestor }
  861. If (Event.What = evCommand) AND { Command event }
  862. (Event.Command = cmQuit) Then Begin { Quit command }
  863. EndModal(cmQuit); { Endmodal operation }
  864. ClearEvent(Event); { Clear event }
  865. End;
  866. END;
  867. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  868. { TApplication OBJECT METHODS }
  869. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  870. {--TApplication-------------------------------------------------------------}
  871. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  872. {---------------------------------------------------------------------------}
  873. CONSTRUCTOR TApplication.Init;
  874. BEGIN
  875. { InitMemory;} { Start memory up }
  876. initkeyboard;
  877. Drivers.InitVideo; { Start video up }
  878. Drivers.InitEvents; { Start event drive }
  879. Drivers.InitSysError; { Start system error }
  880. InitHistory; { Start history up }
  881. InitResource;
  882. InitMsgBox;
  883. Inherited Init; { Call ancestor }
  884. { init mouse and cursor }
  885. Video.SetCursorType(crHidden);
  886. Mouse.SetMouseXY(1,1);
  887. END;
  888. {--TApplication-------------------------------------------------------------}
  889. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  890. {---------------------------------------------------------------------------}
  891. DESTRUCTOR TApplication.Done;
  892. BEGIN
  893. Inherited Done; { Call ancestor }
  894. DoneHistory; { Close history }
  895. DoneResource;
  896. Drivers.DoneSysError; { Close system error }
  897. Drivers.DoneEvents; { Close event drive }
  898. drivers.donevideo;
  899. { DoneMemory;} { Close memory }
  900. donekeyboard;
  901. END;
  902. {--TApplication-------------------------------------------------------------}
  903. { Tile -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  904. {---------------------------------------------------------------------------}
  905. PROCEDURE TApplication.Tile;
  906. VAR R: TRect;
  907. BEGIN
  908. GetTileRect(R); { Tileable area }
  909. If (Desktop <> Nil) Then Desktop^.Tile(R); { Tile desktop }
  910. END;
  911. {--TApplication-------------------------------------------------------------}
  912. { Cascade -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  913. {---------------------------------------------------------------------------}
  914. PROCEDURE TApplication.Cascade;
  915. VAR R: TRect;
  916. BEGIN
  917. GetTileRect(R); { Cascade area }
  918. If (Desktop <> Nil) Then Desktop^.Cascade(R); { Cascade desktop }
  919. END;
  920. {--TApplication-------------------------------------------------------------}
  921. { DosShell -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  922. {---------------------------------------------------------------------------}
  923. PROCEDURE TApplication.DosShell;
  924. {$ifdef unix}
  925. var s:string;
  926. {$endif}
  927. BEGIN { Compatability only }
  928. DoneSysError;
  929. DoneEvents;
  930. drivers.donevideo;
  931. drivers.donekeyboard;
  932. { DoneDosMem;}
  933. WriteShellMsg;
  934. {$ifdef Unix}
  935. s:=getenv('SHELL');
  936. if s='' then
  937. s:='/bin/sh';
  938. exec(s,'');
  939. {$else}
  940. SwapVectors;
  941. Exec(GetEnv('COMSPEC'), '');
  942. SwapVectors;
  943. {$endif}
  944. { InitDosMem;}
  945. drivers.initkeyboard;
  946. drivers.initvideo;
  947. InitScreen;
  948. InitEvents;
  949. InitSysError;
  950. Redraw;
  951. END;
  952. {--TApplication-------------------------------------------------------------}
  953. { GetTileRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  954. {---------------------------------------------------------------------------}
  955. PROCEDURE TApplication.GetTileRect (Var R: TRect);
  956. BEGIN
  957. If (DeskTop <> Nil) Then Desktop^.GetExtent(R) { Desktop extents }
  958. Else GetExtent(R); { Our extents }
  959. END;
  960. {--TApplication-------------------------------------------------------------}
  961. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  962. {---------------------------------------------------------------------------}
  963. PROCEDURE TApplication.HandleEvent (Var Event: TEvent);
  964. BEGIN
  965. Inherited HandleEvent(Event); { Call ancestor }
  966. If (Event.What = evCommand) Then Begin
  967. Case Event.Command Of
  968. cmTile: Tile; { Tile request }
  969. cmCascade: Cascade; { Cascade request }
  970. cmDosShell: DosShell; { DOS shell request }
  971. Else Exit; { Unhandled exit }
  972. End;
  973. ClearEvent(Event); { Clear the event }
  974. End;
  975. END;
  976. procedure TApplication.WriteShellMsg;
  977. begin
  978. writeln(Strings^.Get(sTypeExitOnReturn));
  979. end;
  980. {***************************************************************************}
  981. { INTERFACE ROUTINES }
  982. {***************************************************************************}
  983. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  984. { STANDARD MENU AND STATUS LINES ROUTINES }
  985. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  986. {---------------------------------------------------------------------------}
  987. { StdStatusKeys -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  988. {---------------------------------------------------------------------------}
  989. FUNCTION StdStatusKeys (Next: PStatusItem): PStatusItem;
  990. BEGIN
  991. StdStatusKeys :=
  992. NewStatusKey('', kbAltX, cmQuit,
  993. NewStatusKey('', kbF10, cmMenu,
  994. NewStatusKey('', kbAltF3, cmClose,
  995. NewStatusKey('', kbF5, cmZoom,
  996. NewStatusKey('', kbCtrlF5, cmResize,
  997. NewStatusKey('', kbF6, cmNext,
  998. NewStatusKey('', kbShiftF6, cmPrev,
  999. Next)))))));
  1000. END;
  1001. {---------------------------------------------------------------------------}
  1002. { StdFileMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1003. {---------------------------------------------------------------------------}
  1004. FUNCTION StdFileMenuItems (Next: PMenuItem): PMenuItem;
  1005. BEGIN
  1006. StdFileMenuItems :=
  1007. NewItem('~N~ew', '', kbNoKey, cmNew, hcNew,
  1008. NewItem('~O~pen...', 'F3', kbF3, cmOpen, hcOpen,
  1009. NewItem('~S~ave', 'F2', kbF2, cmSave, hcSave,
  1010. NewItem('S~a~ve as...', '', kbNoKey, cmSaveAs, hcSaveAs,
  1011. NewItem('Save a~l~l', '', kbNoKey, cmSaveAll, hcSaveAll,
  1012. NewLine(
  1013. NewItem('~C~hange dir...', '', kbNoKey, cmChangeDir, hcChangeDir,
  1014. NewItem('OS shell', '', kbNoKey, cmDosShell, hcDosShell,
  1015. NewItem('E~x~it', 'Alt+X', kbAltX, cmQuit, hcExit,
  1016. Next)))))))));
  1017. END;
  1018. {---------------------------------------------------------------------------}
  1019. { StdEditMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1020. {---------------------------------------------------------------------------}
  1021. FUNCTION StdEditMenuItems (Next: PMenuItem): PMenuItem;
  1022. BEGIN
  1023. StdEditMenuItems :=
  1024. NewItem('~U~ndo', '', kbAltBack, cmUndo, hcUndo,
  1025. NewLine(
  1026. NewItem('Cu~t~', 'Shift+Del', kbShiftDel, cmCut, hcCut,
  1027. NewItem('~C~opy', 'Ctrl+Ins', kbCtrlIns, cmCopy, hcCopy,
  1028. NewItem('~P~aste', 'Shift+Ins', kbShiftIns, cmPaste, hcPaste,
  1029. NewItem('C~l~ear', 'Ctrl+Del', kbCtrlDel, cmClear, hcClear,
  1030. Next))))));
  1031. END;
  1032. {---------------------------------------------------------------------------}
  1033. { StdWindowMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1034. {---------------------------------------------------------------------------}
  1035. FUNCTION StdWindowMenuItems (Next: PMenuItem): PMenuItem;
  1036. BEGIN
  1037. StdWindowMenuItems :=
  1038. NewItem('~T~ile', '', kbNoKey, cmTile, hcTile,
  1039. NewItem('C~a~scade', '', kbNoKey, cmCascade, hcCascade,
  1040. NewItem('Cl~o~se all', '', kbNoKey, cmCloseAll, hcCloseAll,
  1041. NewLine(
  1042. NewItem('~S~ize/Move','Ctrl+F5', kbCtrlF5, cmResize, hcResize,
  1043. NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcZoom,
  1044. NewItem('~N~ext', 'F6', kbF6, cmNext, hcNext,
  1045. NewItem('~P~revious', 'Shift+F6', kbShiftF6, cmPrev, hcPrev,
  1046. NewItem('~C~lose', 'Alt+F3', kbAltF3, cmClose, hcClose,
  1047. Next)))))))));
  1048. END;
  1049. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1050. { OBJECT REGISTER ROUTINES }
  1051. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1052. {---------------------------------------------------------------------------}
  1053. { RegisterApp -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1054. {---------------------------------------------------------------------------}
  1055. PROCEDURE RegisterApp;
  1056. BEGIN
  1057. RegisterType(RBackground); { Register background }
  1058. RegisterType(RDesktop); { Register desktop }
  1059. END;
  1060. END.