app.pas 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. { $Id$}
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GRAPHICAL clone of APP.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  9. { [email protected] - primary e-mail addr }
  10. { [email protected] - backup e-mail addr }
  11. { }
  12. {****************[ THIS CODE IS FREEWARE ]*****************}
  13. { }
  14. { This sourcecode is released for the purpose to }
  15. { promote the pascal language on all platforms. You may }
  16. { redistribute it and/or modify with the following }
  17. { DISCLAIMER. }
  18. { }
  19. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  20. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  21. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  22. { }
  23. {*****************[ SUPPORTED PLATFORMS ]******************}
  24. { 16 and 32 Bit compilers }
  25. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  26. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  27. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  28. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  29. { - Delphi 1.0+ (16 Bit) }
  30. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  31. { - Virtual Pascal 2.0+ (32 Bit) }
  32. { - FPC 0.9912+ (32 Bit) }
  33. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  34. { }
  35. {******************[ REVISION HISTORY ]********************}
  36. { Version Date Fix }
  37. { ------- --------- --------------------------------- }
  38. { 1.00 12 Dec 96 First multi platform release }
  39. { 1.10 12 Sep 97 FPK pascal 0.92 conversion added. }
  40. { 1.20 29 Aug 97 Platform.inc sort added. }
  41. { 1.30 05 May 98 Virtual pascal 2.0 code added. }
  42. { 1.40 22 Oct 99 Object registration added. }
  43. { 1.50 22 Oct 99 Complete recheck preformed }
  44. { 1.51 03 Nov 99 FPC Windows support added }
  45. { 1.60 26 Nov 99 Graphics stuff moved to GFVGraph }
  46. {**********************************************************}
  47. UNIT App;
  48. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  49. INTERFACE
  50. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  51. {====Include file to sort compiler platform out =====================}
  52. {$I Platform.inc}
  53. {====================================================================}
  54. {==== Compiler directives ===========================================}
  55. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  56. {$F-} { Near calls are okay }
  57. {$A+} { Word Align Data }
  58. {$B-} { Allow short circuit boolean evaluations }
  59. {$O+} { This unit may be overlaid }
  60. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  61. {$P-} { Normal string variables }
  62. {$N-} { No 80x87 code generation }
  63. {$E+} { Emulation is on }
  64. {$ENDIF}
  65. {$X+} { Extended syntax is ok }
  66. {$R-} { Disable range checking }
  67. {$S-} { Disable Stack Checking }
  68. {$I-} { Disable IO Checking }
  69. {$Q-} { Disable Overflow Checking }
  70. {$V-} { Turn off strict VAR strings }
  71. {====================================================================}
  72. USES
  73. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  74. {$IFNDEF PPC_SPEED} { NON SPEED COMPILER }
  75. {$IFDEF PPC_FPC} { FPC WINDOWS COMPILER }
  76. Windows, { Standard units }
  77. {$ELSE} { OTHER COMPILERS }
  78. WinTypes,WinProcs, { Standard units }
  79. {$ENDIF}
  80. {$IFNDEF PPC_DELPHI} { NON DELPHI1 COMPILER }
  81. {$IFDEF BIT_16} Win31, {$ENDIF} { 16 BIT WIN 3.1 UNIT }
  82. {$ENDIF}
  83. {$ELSE} { SPEEDSOFT COMPILER }
  84. WinBase, WinDef, { Standard units }
  85. {$ENDIF}
  86. {$IFDEF PPC_DELPHI} { DELPHI COMPILERS }
  87. Messages, { Standard unit }
  88. {$ENDIF}
  89. {$ENDIF}
  90. {$IFDEF OS_OS2} { OS2 CODE }
  91. Os2Def, Os2Base, OS2PmApi, { Standard units }
  92. {$ENDIF}
  93. GFVGraph, { GFV standard unit }
  94. Common, Memory, { GFV standard units }
  95. Objects, Drivers, Views, Menus, HistList, Dialogs; { GFV standard units }
  96. {***************************************************************************}
  97. { PUBLIC CONSTANTS }
  98. {***************************************************************************}
  99. {---------------------------------------------------------------------------}
  100. { STANDARD APPLICATION COMMAND CONSTANTS }
  101. {---------------------------------------------------------------------------}
  102. CONST
  103. cmNew = 30; { Open new file }
  104. cmOpen = 31; { Open a file }
  105. cmSave = 32; { Save current }
  106. cmSaveAs = 33; { Save current as }
  107. cmSaveAll = 34; { Save all files }
  108. cmChangeDir = 35; { Change directories }
  109. cmDosShell = 36; { Dos shell }
  110. cmCloseAll = 37; { Close all windows }
  111. {---------------------------------------------------------------------------}
  112. { TApplication PALETTE ENTRIES }
  113. {---------------------------------------------------------------------------}
  114. CONST
  115. apColor = 0; { Coloured app }
  116. apBlackWhite = 1; { B&W application }
  117. apMonochrome = 2; { Monochrome app }
  118. {---------------------------------------------------------------------------}
  119. { TBackGround PALETTES }
  120. {---------------------------------------------------------------------------}
  121. CONST
  122. CBackground = #1; { Background colour }
  123. {---------------------------------------------------------------------------}
  124. { TApplication PALETTES }
  125. {---------------------------------------------------------------------------}
  126. CONST
  127. { Turbo Vision 1.0 Color Palettes }
  128. CColor =
  129. #$81#$70#$78#$74#$20#$28#$24#$17#$1F#$1A#$31#$31#$1E#$71#$1F +
  130. #$37#$3F#$3A#$13#$13#$3E#$21#$3F#$70#$7F#$7A#$13#$13#$70#$7F#$7E +
  131. #$70#$7F#$7A#$13#$13#$70#$70#$7F#$7E#$20#$2B#$2F#$78#$2E#$70#$30 +
  132. #$3F#$3E#$1F#$2F#$1A#$20#$72#$31#$31#$30#$2F#$3E#$31#$13#$38#$00;
  133. CBlackWhite =
  134. #$70#$70#$78#$7F#$07#$07#$0F#$07#$0F#$07#$70#$70#$07#$70#$0F +
  135. #$07#$0F#$07#$70#$70#$07#$70#$0F#$70#$7F#$7F#$70#$07#$70#$07#$0F +
  136. #$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
  137. #$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00;
  138. CMonochrome =
  139. #$70#$07#$07#$0F#$70#$70#$70#$07#$0F#$07#$70#$70#$07#$70#$00 +
  140. #$07#$0F#$07#$70#$70#$07#$70#$00#$70#$70#$70#$07#$07#$70#$07#$00 +
  141. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  142. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00;
  143. { Turbo Vision 2.0 Color Palettes }
  144. CAppColor =
  145. {$IFDEF OS_WINDOWS}#$81+{$ELSE}#$71+{$ENDIF}
  146. #$70#$78#$74#$20#$28#$24#$17#$1F#$1A#$31#$31#$1E#$71#$1F +
  147. #$37#$3F#$3A#$13#$13#$3E#$21#$3F#$70#$7F#$7A#$13#$13#$70#$7F#$7E +
  148. #$70#$7F#$7A#$13#$13#$70#$70#$7F#$7E#$20#$2B#$2F#$78#$2E#$70#$30 +
  149. #$3F#$3E#$1F#$2F#$1A#$20#$72#$31#$31#$30#$2F#$3E#$31#$13#$38#$00 +
  150. #$17#$1F#$1A#$71#$71#$1E#$17#$1F#$1E#$20#$2B#$2F#$78#$2E#$10#$30 +
  151. #$3F#$3E#$70#$2F#$7A#$20#$12#$31#$31#$30#$2F#$3E#$31#$13#$38#$00 +
  152. #$37#$3F#$3A#$13#$13#$3E#$30#$3F#$3E#$20#$2B#$2F#$78#$2E#$30#$70 +
  153. #$7F#$7E#$1F#$2F#$1A#$20#$32#$31#$71#$70#$2F#$7E#$71#$13#$38#$00;
  154. CAppBlackWhite =
  155. #$70#$70#$78#$7F#$07#$07#$0F#$07#$0F#$07#$70#$70#$07#$70#$0F +
  156. #$07#$0F#$07#$70#$70#$07#$70#$0F#$70#$7F#$7F#$70#$07#$70#$07#$0F +
  157. #$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
  158. #$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00 +
  159. #$07#$0F#$0F#$07#$70#$07#$07#$0F#$0F#$70#$78#$7F#$08#$7F#$08#$70 +
  160. #$7F#$7F#$7F#$0F#$70#$70#$07#$70#$70#$70#$07#$7F#$70#$07#$78#$00 +
  161. #$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
  162. #$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00;
  163. CAppMonochrome =
  164. #$70#$07#$07#$0F#$70#$70#$70#$07#$0F#$07#$70#$70#$07#$70#$00 +
  165. #$07#$0F#$07#$70#$70#$07#$70#$00#$70#$70#$70#$07#$07#$70#$07#$00 +
  166. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  167. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
  168. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  169. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
  170. #$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
  171. #$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00;
  172. {---------------------------------------------------------------------------}
  173. { STANDRARD HELP CONTEXT CONSTANTS }
  174. {---------------------------------------------------------------------------}
  175. CONST
  176. { Note: range $FF00 - $FFFF of help contexts are reserved by Borland }
  177. hcNew = $FF01; { New file help }
  178. hcOpen = $FF02; { Open file help }
  179. hcSave = $FF03; { Save file help }
  180. hcSaveAs = $FF04; { Save file as help }
  181. hcSaveAll = $FF05; { Save all files help }
  182. hcChangeDir = $FF06; { Change dir help }
  183. hcDosShell = $FF07; { Dos shell help }
  184. hcExit = $FF08; { Exit program help }
  185. hcUndo = $FF10; { Clipboard undo help }
  186. hcCut = $FF11; { Clipboard cut help }
  187. hcCopy = $FF12; { Clipboard copy help }
  188. hcPaste = $FF13; { Clipboard paste help }
  189. hcClear = $FF14; { Clipboard clear help }
  190. hcTile = $FF20; { Desktop tile help }
  191. hcCascade = $FF21; { Desktop cascade help }
  192. hcCloseAll = $FF22; { Desktop close all }
  193. hcResize = $FF23; { Window resize help }
  194. hcZoom = $FF24; { Window zoom help }
  195. hcNext = $FF25; { Window next help }
  196. hcPrev = $FF26; { Window previous help }
  197. hcClose = $FF27; { Window close help }
  198. {***************************************************************************}
  199. { PUBLIC OBJECT DEFINITIONS }
  200. {***************************************************************************}
  201. {---------------------------------------------------------------------------}
  202. { TBackGround OBJECT - BACKGROUND OBJECT }
  203. {---------------------------------------------------------------------------}
  204. TYPE
  205. TBackGround = OBJECT (TView)
  206. Pattern: Char; { Background pattern }
  207. CONSTRUCTOR Init (Var Bounds: TRect; APattern: Char);
  208. CONSTRUCTOR Load (Var S: TStream);
  209. FUNCTION GetPalette: PPalette; Virtual;
  210. PROCEDURE DrawBackGround; Virtual;
  211. PROCEDURE Store (Var S: TStream);
  212. END;
  213. PBackGround = ^TBackGround;
  214. {---------------------------------------------------------------------------}
  215. { TDeskTop OBJECT - DESKTOP OBJECT }
  216. {---------------------------------------------------------------------------}
  217. TYPE
  218. TDeskTop = OBJECT (TGroup)
  219. Background : PBackground; { Background view }
  220. TileColumnsFirst: Boolean; { Tile direction }
  221. CONSTRUCTOR Init (Var Bounds: TRect);
  222. CONSTRUCTOR Load (Var S: TStream);
  223. PROCEDURE TileError; Virtual;
  224. PROCEDURE InitBackGround; Virtual;
  225. PROCEDURE Tile (Var R: TRect);
  226. PROCEDURE Store (Var S: TStream);
  227. PROCEDURE Cascade (Var R: TRect);
  228. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  229. END;
  230. PDeskTop = ^TDeskTop;
  231. {---------------------------------------------------------------------------}
  232. { TProgram OBJECT - PROGRAM ANCESTOR OBJECT }
  233. {---------------------------------------------------------------------------}
  234. TYPE
  235. TProgram = OBJECT (TGroup)
  236. CONSTRUCTOR Init;
  237. DESTRUCTOR Done; Virtual;
  238. FUNCTION GetPalette: PPalette; Virtual;
  239. FUNCTION CanMoveFocus: Boolean;
  240. FUNCTION ValidView (P: PView): PView;
  241. FUNCTION InsertWindow (P: PWindow): PWindow;
  242. FUNCTION ExecuteDialog (P: PDialog; Data: Pointer): Word;
  243. PROCEDURE Run; Virtual;
  244. PROCEDURE Idle; Virtual;
  245. PROCEDURE InitScreen; Virtual;
  246. PROCEDURE InitDeskTop; Virtual;
  247. PROCEDURE OutOfMemory; Virtual;
  248. PROCEDURE InitMenuBar; Virtual;
  249. PROCEDURE InitStatusLine; Virtual;
  250. PROCEDURE SetScreenMode (Mode: Word);
  251. PROCEDURE PutEvent (Var Event: TEvent); Virtual;
  252. PROCEDURE GetEvent (Var Event: TEvent); Virtual;
  253. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  254. {$IFNDEF OS_DOS} { WIN/NT/OS2 CODE }
  255. FUNCTION GetClassName: String; Virtual;
  256. FUNCTION GetClassText: String; Virtual;
  257. FUNCTION GetClassAttr: LongInt; Virtual;
  258. FUNCTION GetMsgHandler: Pointer; Virtual;
  259. {$ENDIF}
  260. END;
  261. PProgram = ^TProgram;
  262. {---------------------------------------------------------------------------}
  263. { TApplication OBJECT - APPLICATION OBJECT }
  264. {---------------------------------------------------------------------------}
  265. TYPE
  266. TApplication = OBJECT (TProgram)
  267. CONSTRUCTOR Init;
  268. DESTRUCTOR Done; Virtual;
  269. PROCEDURE Tile;
  270. PROCEDURE Cascade;
  271. PROCEDURE DosShell;
  272. PROCEDURE GetTileRect (Var R: TRect); Virtual;
  273. PROCEDURE HandleEvent (Var Event: TEvent); Virtual;
  274. END;
  275. PApplication = ^TApplication; { Application ptr }
  276. {***************************************************************************}
  277. { INTERFACE ROUTINES }
  278. {***************************************************************************}
  279. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  280. { STANDARD MENU AND STATUS LINES ROUTINES }
  281. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  282. {-StdStatusKeys------------------------------------------------------
  283. Returns a pointer to a linked list of commonly used status line keys.
  284. The default status line for TApplication uses StdStatusKeys as its
  285. complete list of status keys.
  286. 22Oct99 LdB
  287. ---------------------------------------------------------------------}
  288. FUNCTION StdStatusKeys (Next: PStatusItem): PStatusItem;
  289. {-StdFileMenuItems---------------------------------------------------
  290. Returns a pointer to a list of menu items for a standard File menu.
  291. The standard File menu items are New, Open, Save, Save As, Save All,
  292. Change Dir, OS Shell, and Exit.
  293. 22Oct99 LdB
  294. ---------------------------------------------------------------------}
  295. FUNCTION StdFileMenuItems (Next: PMenuItem): PMenuItem;
  296. {-StdEditMenuItems---------------------------------------------------
  297. Returns a pointer to a list of menu items for a standard Edit menu.
  298. The standard Edit menu items are Undo, Cut, Copy, Paste, and Clear.
  299. 22Oct99 LdB
  300. ---------------------------------------------------------------------}
  301. FUNCTION StdEditMenuItems (Next: PMenuItem): PMenuItem;
  302. {-StdWindowMenuItems-------------------------------------------------
  303. Returns a pointer to a list of menu items for a standard Window menu.
  304. The standard Window menu items are Tile, Cascade, Close All,
  305. Size/Move, Zoom, Next, Previous, and Close.
  306. 22Oct99 LdB
  307. ---------------------------------------------------------------------}
  308. FUNCTION StdWindowMenuItems (Next: PMenuItem): PMenuItem;
  309. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  310. { OBJECT REGISTER ROUTINES }
  311. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  312. {-RegisterApp--------------------------------------------------------
  313. Calls RegisterType for each of the object types defined in this unit.
  314. 22oct99 LdB
  315. ---------------------------------------------------------------------}
  316. PROCEDURE RegisterApp;
  317. {***************************************************************************}
  318. { OBJECT REGISTRATION }
  319. {***************************************************************************}
  320. {---------------------------------------------------------------------------}
  321. { TBackGround STREAM REGISTRATION }
  322. {---------------------------------------------------------------------------}
  323. CONST
  324. RBackGround: TStreamRec = (
  325. ObjType: 30; { Register id = 30 }
  326. {$IFDEF BP_VMTLink} { BP style VMT link }
  327. VmtLink: Ofs(TypeOf(TBackGround)^);
  328. {$ELSE} { Alt style VMT link }
  329. VmtLink: TypeOf(TBackGround);
  330. {$ENDIF}
  331. Load: @TBackGround.Load; { Object load method }
  332. Store: @TBackGround.Store { Object store method }
  333. );
  334. {---------------------------------------------------------------------------}
  335. { TDeskTop STREAM REGISTRATION }
  336. {---------------------------------------------------------------------------}
  337. CONST
  338. RDeskTop: TStreamRec = (
  339. ObjType: 31; { Register id = 31 }
  340. {$IFDEF BP_VMTLink} { BP style VMT link }
  341. VmtLink: Ofs(TypeOf(TDeskTop)^);
  342. {$ELSE} { Alt style VMT link }
  343. VmtLink: TypeOf(TDeskTop);
  344. {$ENDIF}
  345. Load: @TDeskTop.Load; { Object load method }
  346. Store: @TDeskTop.Store { Object store method }
  347. );
  348. {***************************************************************************}
  349. { INITIALIZED PUBLIC VARIABLES }
  350. {***************************************************************************}
  351. {---------------------------------------------------------------------------}
  352. { INITIALIZED PUBLIC VARIABLES }
  353. {---------------------------------------------------------------------------}
  354. CONST
  355. AppPalette: Integer = apColor; { Application colour }
  356. Desktop: PDeskTop = Nil; { Desktop object }
  357. MenuBar: PMenuView = Nil; { Application menu }
  358. StatusLine: PStatusLine = Nil; { App status line }
  359. Application : PApplication = Nil; { Application object }
  360. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  361. IMPLEMENTATION
  362. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  363. {$ifdef Use_API}
  364. uses
  365. Video,Mouse;
  366. {$endif Use_API}
  367. {***************************************************************************}
  368. { PRIVATE DEFINED CONSTANTS }
  369. {***************************************************************************}
  370. {***************************************************************************}
  371. { PRIVATE INITIALIZED VARIABLES }
  372. {***************************************************************************}
  373. {---------------------------------------------------------------------------}
  374. { INITIALIZED PRIVATE VARIABLES }
  375. {---------------------------------------------------------------------------}
  376. CONST Pending: TEvent = (What: evNothing); { Pending event }
  377. {***************************************************************************}
  378. { PRIVATE INTERNAL ROUTINES }
  379. {***************************************************************************}
  380. {$IFDEF OS_WINDOWS}
  381. {---------------------------------------------------------------------------}
  382. { AppMsgHandler -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 13May98 LdB }
  383. {---------------------------------------------------------------------------}
  384. FUNCTION TvAppMsgHandler (Wnd: hWnd; iMessage, wParam: Sw_Word;
  385. lParam: LongInt): LongInt; {$IFDEF BIT_16} EXPORT; {$ELSE} STDCALL; {$ENDIF}
  386. VAR Event: TEvent; P: PView; Mm: ^TMinMaxInfo;
  387. BEGIN
  388. {$IFDEF BIT_16} { 16 BIT CODE }
  389. PtrRec(P).Seg := GetProp(Wnd, ViewSeg); { Fetch seg property }
  390. PtrRec(P).Ofs := GetProp(Wnd, ViewOfs); { Fetch ofs property }
  391. {$ENDIF}
  392. {$IFDEF BIT_32} { 32 BIT CODE }
  393. LongInt(P) := GetProp(Wnd, ViewPtr); { Fetch view property }
  394. {$ENDIF}
  395. TvAppMsgHandler := 0; { Preset zero return }
  396. Event.What := evNothing; { Preset no event }
  397. Case iMessage Of
  398. WM_Destroy:; { Destroy window }
  399. WM_Close: Begin
  400. Event.What := evCommand; { Command event }
  401. Event.Command := cmQuit; { Quit command }
  402. Event.InfoPtr := Nil; { Clear info ptr }
  403. End;
  404. WM_GetMinMaxInfo: Begin { Get minmax info }
  405. TvAppMsgHandler := DefWindowProc(Wnd,
  406. iMessage, wParam, lParam); { Default handler }
  407. Mm := Pointer(lParam); { Create pointer }
  408. Mm^.ptMaxSize.X := SysScreenWidth; { Max x size }
  409. Mm^.ptMaxSize.Y := SysScreenHeight; { Max y size }
  410. Mm^.ptMinTrackSize.X := MinWinSize.X *
  411. SysFontWidth; { Drag min x size }
  412. Mm^.ptMinTrackSize.Y := MinWinSize.Y *
  413. SysFontHeight; { Drag min y size }
  414. Mm^.ptMaxTrackSize.X := SysScreenWidth; { Drag max x size }
  415. Mm^.ptMaxTrackSize.Y := SysScreenHeight; { Drag max y size }
  416. End;
  417. Else Begin { Unhandled message }
  418. TvAppMsgHandler := DefWindowProc(Wnd,
  419. iMessage, wParam, lParam); { Default handler }
  420. Exit; { Now exit }
  421. End;
  422. End;
  423. If (Event.What <> evNothing) Then { Check any FV event }
  424. PutEventInQueue(Event); { Put event in queue }
  425. END;
  426. {$ENDIF}
  427. {$IFDEF OS_OS2} { OS2 CODE }
  428. FUNCTION TvAppMsgHandler(Wnd: HWnd; Msg: ULong; Mp1, Mp2: MParam): MResult; CDECL;
  429. VAR Event: TEvent; P: PView;
  430. BEGIN
  431. Event.What := evNothing; { Preset no event }
  432. TvAppMsgHandler := 0; { Preset zero return }
  433. Case Msg Of
  434. WM_Destroy:; { Destroy window }
  435. WM_Close: Begin
  436. Event.What := evCommand; { Command event }
  437. Event.Command := cmQuit; { Quit command }
  438. Event.InfoPtr := Nil; { Clear info ptr }
  439. End;
  440. Else Begin { Unhandled message }
  441. TvAppMsgHandler := WinDefWindowProc(Wnd,
  442. Msg, Mp1, Mp2); { Call std handler }
  443. Exit; { Now exit }
  444. End;
  445. End;
  446. If (Event.What <> evNothing) Then { Check any FV event }
  447. PutEventInQueue(Event); { Put event in queue }
  448. END;
  449. {$ENDIF}
  450. {---------------------------------------------------------------------------}
  451. { Tileable -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  452. {---------------------------------------------------------------------------}
  453. FUNCTION Tileable (P: PView): Boolean;
  454. BEGIN
  455. Tileable := (P^.Options AND ofTileable <> 0) AND { View is tileable }
  456. (P^.State AND sfVisible <> 0); { View is visible }
  457. END;
  458. {---------------------------------------------------------------------------}
  459. { ISqr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  460. {---------------------------------------------------------------------------}
  461. FUNCTION ISqr (X: Sw_Integer): Sw_Integer;
  462. VAR I: Sw_Integer;
  463. BEGIN
  464. I := 0; { Set value to zero }
  465. Repeat
  466. Inc(I); { Inc value }
  467. Until (I * I > X); { Repeat till Sqr > X }
  468. ISqr := I - 1; { Return result }
  469. END;
  470. {---------------------------------------------------------------------------}
  471. { MostEqualDivisors -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  472. {---------------------------------------------------------------------------}
  473. PROCEDURE MostEqualDivisors (N: Integer; Var X, Y: Integer; FavorY: Boolean);
  474. VAR I: Integer;
  475. BEGIN
  476. I := ISqr(N); { Int square of N }
  477. If ((N MOD I) <> 0) Then { Initial guess }
  478. If ((N MOD (I+1)) = 0) Then Inc(I); { Add one row/column }
  479. If (I < (N DIV I)) Then I := N DIV I; { In first page }
  480. If FavorY Then Begin { Horz preferred }
  481. X := N DIV I; { Calc x position }
  482. Y := I; { Set y position }
  483. End Else Begin { Vert preferred }
  484. Y := N DIV I; { Calc y position }
  485. X := I; { Set x position }
  486. End;
  487. END;
  488. {***************************************************************************}
  489. { OBJECT METHODS }
  490. {***************************************************************************}
  491. {--TBackGround--------------------------------------------------------------}
  492. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  493. {---------------------------------------------------------------------------}
  494. CONSTRUCTOR TBackGround.Init (Var Bounds: TRect; APattern: Char);
  495. BEGIN
  496. Inherited Init(Bounds); { Call ancestor }
  497. GrowMode := gfGrowHiX + gfGrowHiY; { Set grow modes }
  498. Pattern := APattern; { Hold pattern }
  499. END;
  500. {--TBackGround--------------------------------------------------------------}
  501. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  502. {---------------------------------------------------------------------------}
  503. CONSTRUCTOR TBackGround.Load (Var S: TStream);
  504. BEGIN
  505. Inherited Load(S); { Call ancestor }
  506. S.Read(Pattern, SizeOf(Pattern)); { Read pattern data }
  507. END;
  508. {--TBackGround--------------------------------------------------------------}
  509. { GetPalette -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  510. {---------------------------------------------------------------------------}
  511. FUNCTION TBackGround.GetPalette: PPalette;
  512. {$IFDEF PPC_DELPHI3} { DELPHI3+ COMPILER }
  513. CONST P: String = CBackGround; { Possible huge string }
  514. {$ELSE} { OTHER COMPILERS }
  515. CONST P: String[Length(CBackGround)] = CbackGround; { Always normal string }
  516. {$ENDIF}
  517. BEGIN
  518. GetPalette := @P; { Return palette }
  519. END;
  520. {--TBackGround--------------------------------------------------------------}
  521. { DrawBackground -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  522. {---------------------------------------------------------------------------}
  523. PROCEDURE TBackground.DrawBackground;
  524. VAR B: TDrawBuffer;
  525. BEGIN
  526. MoveChar(B, Pattern, GetColor($01), Size.X); { Fill draw buffer }
  527. WriteLine(0, 0, Size.X, Size.Y, B); { Draw to area }
  528. END;
  529. {--TBackGround--------------------------------------------------------------}
  530. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  531. {---------------------------------------------------------------------------}
  532. PROCEDURE TBackGround.Store (Var S: TStream);
  533. BEGIN
  534. TView.Store(S); { TView store called }
  535. S.Write(Pattern, SizeOf(Pattern)); { Write pattern data }
  536. END;
  537. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  538. { TDesktop OBJECT METHODS }
  539. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  540. {--TDesktop-----------------------------------------------------------------}
  541. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  542. {---------------------------------------------------------------------------}
  543. CONSTRUCTOR TDesktop.Init (Var Bounds: Objects.TRect);
  544. BEGIN
  545. Inherited Init(Bounds); { Call ancestor }
  546. GrowMode := gfGrowHiX + gfGrowHiY; { Set growmode }
  547. InitBackground; { Create background }
  548. If (Background <> Nil) Then Insert(Background); { Insert background }
  549. END;
  550. {--TDesktop-----------------------------------------------------------------}
  551. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  552. {---------------------------------------------------------------------------}
  553. CONSTRUCTOR TDesktop.Load (Var S: TStream);
  554. BEGIN
  555. Inherited Load(S); { Call ancestor }
  556. GetSubViewPtr(S, Background); { Load background }
  557. S.Read(TileColumnsFirst, SizeOf(TileColumnsFirst));{ Read data }
  558. END;
  559. {--TDesktop-----------------------------------------------------------------}
  560. { TileError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  561. {---------------------------------------------------------------------------}
  562. PROCEDURE TDeskTop.TileError;
  563. BEGIN { Abstract method }
  564. END;
  565. {--TDesktop-----------------------------------------------------------------}
  566. { InitBackGround -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  567. {---------------------------------------------------------------------------}
  568. PROCEDURE TDesktop.InitBackground;
  569. {$IFNDEF OS_WINDOWS} CONST Ch: Char = #176; {$ELSE} CONST Ch: Char = #167; {$ENDIF}
  570. VAR R: TRect;
  571. BEGIN
  572. GetExtent(R); { Get desktop extents }
  573. BackGround := New(PBackground, Init(R, Ch)); { Insert a background }
  574. END;
  575. {--TDesktop-----------------------------------------------------------------}
  576. { Tile -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  577. {---------------------------------------------------------------------------}
  578. PROCEDURE TDeskTop.Tile (Var R: TRect);
  579. VAR NumCols, NumRows, NumTileable, LeftOver, TileNum: Integer;
  580. FUNCTION DividerLoc (Lo, Hi, Num, Pos: Integer): Integer;
  581. BEGIN
  582. DividerLoc := LongInt( LongInt(Hi - Lo) * Pos)
  583. DIV Num + Lo; { Calc position }
  584. END;
  585. PROCEDURE DoCountTileable (P: PView); FAR;
  586. BEGIN
  587. If Tileable(P) Then Inc(NumTileable); { Count tileable views }
  588. END;
  589. PROCEDURE CalcTileRect (Pos: Integer; Var NR: TRect);
  590. VAR X, Y, D: Integer;
  591. BEGIN
  592. D := (NumCols - LeftOver) * NumRows; { Calc d value }
  593. If (Pos<D) Then Begin
  594. X := Pos DIV NumRows; Y := Pos MOD NumRows; { Calc positions }
  595. End Else Begin
  596. X := (Pos - D) div (NumRows + 1) +
  597. (NumCols - LeftOver); { Calc x position }
  598. Y := (Pos - D) mod (NumRows + 1); { Calc y position }
  599. End;
  600. NR.A.X := DividerLoc(R.A.X, R.B.X, NumCols, X); { Top left x position }
  601. NR.B.X := DividerLoc(R.A.X, R.B.X, NumCols, X+1);{ Right x position }
  602. If (Pos >= D) Then Begin
  603. NR.A.Y := DividerLoc(R.A.Y, R.B.Y,NumRows+1,Y);{ Top y position }
  604. NR.B.Y := DividerLoc(R.A.Y, R.B.Y, NumRows+1,
  605. Y+1); { Bottom y position }
  606. End Else Begin
  607. NR.A.Y := DividerLoc(R.A.Y, R.B.Y,NumRows,Y); { Top y position }
  608. NR.B.Y := DividerLoc(R.A.Y, R.B.Y, NumRows,
  609. Y+1); { Bottom y position }
  610. End;
  611. END;
  612. PROCEDURE DoTile(P: PView); FAR;
  613. VAR PState: Word; R: TRect;
  614. BEGIN
  615. If Tileable(P) Then Begin
  616. CalcTileRect(TileNum, R); { Calc tileable area }
  617. PState := P^.State; { Hold view state }
  618. P^.State := P^.State AND NOT sfVisible; { Temp not visible }
  619. P^.Locate(R); { Locate view }
  620. P^.State := PState; { Restore view state }
  621. Dec(TileNum); { One less to tile }
  622. End;
  623. END;
  624. BEGIN
  625. NumTileable := 0; { Zero tileable count }
  626. ForEach(@DoCountTileable); { Count tileable views }
  627. If (NumTileable>0) Then Begin
  628. MostEqualDivisors(NumTileable, NumCols, NumRows,
  629. NOT TileColumnsFirst); { Do pre calcs }
  630. If ((R.B.X - R.A.X) DIV NumCols = 0) OR
  631. ((R.B.Y - R.A.Y) DIV NumRows = 0) Then TileError { Can't tile }
  632. Else Begin
  633. LeftOver := NumTileable MOD NumCols; { Left over count }
  634. TileNum := NumTileable-1; { Tileable views }
  635. ForEach(@DoTile); { Tile each view }
  636. DrawView; { Now redraw }
  637. End;
  638. End;
  639. END;
  640. {--TDesktop-----------------------------------------------------------------}
  641. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  642. {---------------------------------------------------------------------------}
  643. PROCEDURE TDesktop.Store (Var S: TStream);
  644. BEGIN
  645. TGroup.Store(S); { Call group store }
  646. PutSubViewPtr(S, Background); { Store background }
  647. S.Write(TileColumnsFirst,SizeOf(TileColumnsFirst));{ Write data }
  648. END;
  649. {--TDesktop-----------------------------------------------------------------}
  650. { Cascade -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  651. {---------------------------------------------------------------------------}
  652. PROCEDURE TDeskTop.Cascade (Var R: TRect);
  653. VAR CascadeNum: Integer; LastView: PView; Min, Max: TPoint;
  654. PROCEDURE DoCount (P: PView); FAR;
  655. BEGIN
  656. If Tileable(P) Then Begin
  657. Inc(CascadeNum); LastView := P; { Count cascadable }
  658. End;
  659. END;
  660. PROCEDURE DoCascade (P: PView); FAR;
  661. VAR PState: Word; NR: TRect;
  662. BEGIN
  663. If Tileable(P) AND (CascadeNum >= 0) Then Begin { View cascadable }
  664. NR.Copy(R); { Copy rect area }
  665. Inc(NR.A.X, CascadeNum); { Inc x position }
  666. Inc(NR.A.Y, CascadeNum); { Inc y position }
  667. PState := P^.State; { Hold view state }
  668. P^.State := P^.State AND NOT sfVisible; { Temp stop draw }
  669. P^.Locate(NR); { Locate the view }
  670. P^.State := PState; { Now allow draws }
  671. Dec(CascadeNum); { Dec count }
  672. End;
  673. END;
  674. BEGIN
  675. CascadeNum := 0; { Zero cascade count }
  676. ForEach(@DoCount); { Count cascadable }
  677. If (CascadeNum>0) Then Begin
  678. LastView^.SizeLimits(Min, Max); { Check size limits }
  679. If (Min.X > R.B.X - R.A.X - CascadeNum) OR
  680. (Min.Y > R.B.Y - R.A.Y - CascadeNum) Then
  681. TileError Else Begin { Check for error }
  682. Dec(CascadeNum); { One less view }
  683. ForEach(@DoCascade); { Cascade view }
  684. DrawView; { Redraw now }
  685. End;
  686. End;
  687. END;
  688. {--TDesktop-----------------------------------------------------------------}
  689. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 11May98 LdB }
  690. {---------------------------------------------------------------------------}
  691. PROCEDURE TDesktop.HandleEvent (Var Event: TEvent);
  692. BEGIN
  693. Inherited HandleEvent(Event); { Call ancestor }
  694. If (Event.What = evCommand) Then Begin
  695. Case Event.Command of { Command event }
  696. cmNext: FocusNext(False); { Focus next view }
  697. cmPrev: If (BackGround <> Nil) Then Begin
  698. If Valid(cmReleasedFocus) Then
  699. Current^.PutInFrontOf(Background); { Focus last view }
  700. End Else FocusNext(True); { Focus prior view }
  701. Else Exit;
  702. End;
  703. ClearEvent(Event); { Clear the event }
  704. End;
  705. END;
  706. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  707. { TProgram OBJECT METHODS }
  708. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  709. CONST TvProgramClassName = 'TVPROGRAM'+#0; { TV program class }
  710. {--TProgram-----------------------------------------------------------------}
  711. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  712. {---------------------------------------------------------------------------}
  713. CONSTRUCTOR TProgram.Init;
  714. VAR I: Integer; R: TRect; {$IFDEF OS_WINDOWS} ODc: HDc; {$ENDIF}
  715. BEGIN
  716. Application := @Self; { Set application ptr }
  717. InitScreen; { Initialize screen }
  718. R.Assign(0, 0, -(GetMaxX(TextModeGFV)+1),
  719. -(GetMaxY(TextModeGFV)+1)); { Full screen area }
  720. Inherited Init(R); { Call ancestor }
  721. State := sfVisible + sfSelected + sfFocused +
  722. sfModal + sfExposed; { Deafult states }
  723. Options := 0; { No options set }
  724. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  725. ODc := GetDc(GetDeskTopWindow); { Get desktop context }
  726. For I := 0 To 15 Do Begin
  727. ColBrush[I] := CreateSolidBrush(GetNearestColor(
  728. ODc, ColRef[I])); { Create brushes }
  729. ColPen[I] := CreatePen(ps_Solid, 1,
  730. GetNearestColor(ODc, ColRef[I])); { Create pens }
  731. End;
  732. ReleaseDC(GetDeskTopWindow, ODc); { Release context }
  733. CreateWindowNow(sw_ShowNormal); { Create app window }
  734. {$ENDIF}
  735. {$IFDEF OS_OS2}
  736. CreateWindowNow(swp_Show); { Create app window }
  737. {$ENDIF}
  738. {$IFNDEF OS_DOS} { WIN/NT/OS2 CODE }
  739. AppWindow := HWindow; { Set app window handle }
  740. Size.X := ScreenWidth; { Set x size value }
  741. Size.Y := ScreenHeight; { Set y size value }
  742. RawSize.X := ScreenWidth * SysFontWidth; { Set rawsize x }
  743. RawSize.Y := ScreenHeight * SysFontHeight - 1; { Set rawsize y }
  744. {$ENDIF}
  745. InitStatusLine; { Init status line }
  746. If (StatusLine <> Nil) Then Insert(StatusLine); { Insert status line }
  747. InitMenuBar; { Create a bar menu }
  748. If (MenuBar <> Nil) Then Insert(MenuBar); { Insert menu bar }
  749. InitDesktop; { Create desktop }
  750. If (Desktop <> Nil) Then Insert(Desktop); { Insert desktop }
  751. END;
  752. {--TProgram-----------------------------------------------------------------}
  753. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  754. {---------------------------------------------------------------------------}
  755. DESTRUCTOR TProgram.Done;
  756. VAR I: Integer;
  757. BEGIN
  758. If (Desktop <> Nil) Then Dispose(Desktop, Done); { Destroy desktop }
  759. If (MenuBar <> Nil) Then Dispose(MenuBar, Done); { Destroy menu bar }
  760. If (StatusLine <> Nil) Then
  761. Dispose(StatusLine, Done); { Destroy status line }
  762. Application := Nil; { Clear application }
  763. Inherited Done; { Call ancestor }
  764. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  765. For I := 0 To 15 Do DeleteObject(ColBrush[I]); { Delete brushes }
  766. For I := 0 To 15 Do DeleteObject(ColPen[I]); { Delete pens }
  767. {$ENDIF}
  768. {$IFNDEF OS_DOS} { WIN/NT/OS2 CODE }
  769. AppWindow := 0; { Zero app window handle }
  770. {$ENDIF}
  771. END;
  772. {--TProgram-----------------------------------------------------------------}
  773. { GetPalette -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  774. {---------------------------------------------------------------------------}
  775. FUNCTION TProgram.GetPalette: PPalette;
  776. CONST P: Array[apColor..apMonochrome] Of String = (CAppColor, CAppBlackWhite,
  777. CAppMonochrome);
  778. BEGIN
  779. GetPalette := @P[AppPalette]; { Return palette }
  780. END;
  781. {--TProgram-----------------------------------------------------------------}
  782. { CanMoveFocus -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 23Sep97 LdB }
  783. {---------------------------------------------------------------------------}
  784. FUNCTION TProgram.CanMoveFocus: Boolean;
  785. BEGIN
  786. If (Desktop <> Nil) Then { Valid desktop view }
  787. CanMovefocus := DeskTop^.Valid(cmReleasedFocus) { Check focus move }
  788. Else CanMoveFocus := True; { No desktop who cares! }
  789. END;
  790. {--TProgram-----------------------------------------------------------------}
  791. { ValidView -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  792. {---------------------------------------------------------------------------}
  793. FUNCTION TProgram.ValidView (P: PView): PView;
  794. BEGIN
  795. ValidView := Nil; { Preset failure }
  796. If (P <> Nil) Then Begin
  797. If LowMemory Then Begin { Check memroy }
  798. Dispose(P, Done); { Dispose view }
  799. OutOfMemory; { Call out of memory }
  800. Exit; { Now exit }
  801. End;
  802. If NOT P^.Valid(cmValid) Then Begin { Check view valid }
  803. Dispose(P, Done); { Dipose view }
  804. Exit; { Now exit }
  805. End;
  806. ValidView := P; { Return view }
  807. End;
  808. END;
  809. {--TProgram-----------------------------------------------------------------}
  810. { InsertWindow -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  811. {---------------------------------------------------------------------------}
  812. FUNCTION TProgram.InsertWindow (P: PWindow): PWindow;
  813. BEGIN
  814. InsertWindow := Nil; { Preset failure }
  815. If (ValidView(P) <> Nil) Then { Check view valid }
  816. If (CanMoveFocus) AND (Desktop <> Nil) { Can we move focus }
  817. Then Begin
  818. Desktop^.Insert(P); { Insert window }
  819. InsertWindow := P; { Return view ptr }
  820. End Else Dispose(P, Done); { Dispose view }
  821. END;
  822. {--TProgram-----------------------------------------------------------------}
  823. { ExecuteDialog -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  824. {---------------------------------------------------------------------------}
  825. FUNCTION TProgram.ExecuteDialog (P: PDialog; Data: Pointer): Word;
  826. VAR ExecResult: Word;
  827. BEGIN
  828. ExecuteDialog := cmCancel; { Preset cancel }
  829. If (ValidView(P) <> Nil) Then Begin { Check view valid }
  830. If (Data <> Nil) Then P^.SetData(Data^); { Set data }
  831. If (P <> Nil) Then P^.SelectDefaultView; { Select default }
  832. ExecResult := Desktop^.ExecView(P); { Execute view }
  833. If (ExecResult <> cmCancel) AND (Data <> Nil)
  834. Then P^.GetData(Data^); { Get data back }
  835. Dispose(P, Done); { Dispose of dialog }
  836. ExecuteDialog := ExecResult; { Return result }
  837. End;
  838. END;
  839. {--TProgram-----------------------------------------------------------------}
  840. { Run -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  841. {---------------------------------------------------------------------------}
  842. PROCEDURE TProgram.Run;
  843. BEGIN
  844. Execute; { Call execute }
  845. END;
  846. {--TProgram-----------------------------------------------------------------}
  847. { Idle -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  848. {---------------------------------------------------------------------------}
  849. PROCEDURE TProgram.Idle;
  850. BEGIN
  851. If (StatusLine <> Nil) Then StatusLine^.Update; { Update statusline }
  852. If CommandSetChanged Then Begin { Check command change }
  853. Message(@Self, evBroadcast, cmCommandSetChanged,
  854. Nil); { Send message }
  855. CommandSetChanged := False; { Clear flag }
  856. End;
  857. END;
  858. {--TProgram-----------------------------------------------------------------}
  859. { InitScreen -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  860. {---------------------------------------------------------------------------}
  861. PROCEDURE TProgram.InitScreen;
  862. BEGIN
  863. {$ifndef Use_API}
  864. If (Lo(ScreenMode) <> smMono) Then Begin { Coloured mode }
  865. If (ScreenMode AND smFont8x8 <> 0) Then
  866. ShadowSize.X := 1 Else { Single bit shadow }
  867. ShadowSize.X := 2; { Double size }
  868. ShadowSize.Y := 1; ShowMarkers := False; { Set variables }
  869. If (Lo(ScreenMode) = smBW80) Then
  870. AppPalette := apBlackWhite Else { B & W palette }
  871. AppPalette := apColor; { Coloured palette }
  872. End Else Begin
  873. ShadowSize.X := 0; { No x shadow size }
  874. ShadowSize.Y := 0; { No y shadow size }
  875. ShowMarkers := True; { Show markers }
  876. AppPalette := apMonochrome; { Mono palette }
  877. End;
  878. {$else Use_API}
  879. { the orginal code can't be used here because of the limited
  880. video unit capabilities, the mono modus can't be handled
  881. }
  882. if (ScreenMode.Col div ScreenMode.Row<2) then
  883. ShadowSize.X := 1
  884. else
  885. ShadowSize.X := 2;
  886. ShadowSize.Y := 1;
  887. ShowMarkers := False;
  888. if ScreenMode.color then
  889. AppPalette := apColor
  890. else
  891. AppPalette := apBlackWhite;
  892. Buffer := Views.PVideoBuf(VideoBuf);
  893. {$endif Use_API}
  894. END;
  895. {--TProgram-----------------------------------------------------------------}
  896. { InitDeskTop -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  897. {---------------------------------------------------------------------------}
  898. PROCEDURE TProgram.InitDesktop;
  899. VAR R: TRect;
  900. BEGIN
  901. GetExtent(R); { Get view extent }
  902. If (MenuBar <> Nil) Then Inc(R.A.Y); { Adjust top down }
  903. If (StatusLine <> Nil) Then Dec(R.B.Y); { Adjust bottom up }
  904. DeskTop := New(PDesktop, Init(R)); { Create desktop }
  905. END;
  906. {--TProgram-----------------------------------------------------------------}
  907. { OutOfMemory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08May98 LdB }
  908. {---------------------------------------------------------------------------}
  909. PROCEDURE TProgram.OutOfMemory;
  910. BEGIN { Abstract method }
  911. END;
  912. {--TProgram-----------------------------------------------------------------}
  913. { InitMenuBar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  914. {---------------------------------------------------------------------------}
  915. PROCEDURE TProgram.InitMenuBar;
  916. VAR R: TRect;
  917. BEGIN
  918. GetExtent(R); { Get view extents }
  919. R.B.Y := R.A.Y + 1; { One line high }
  920. MenuBar := New(PMenuBar, Init(R, Nil)); { Create menu bar }
  921. END;
  922. {--TProgram-----------------------------------------------------------------}
  923. { InitStatusLine -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  924. {---------------------------------------------------------------------------}
  925. PROCEDURE TProgram.InitStatusLine;
  926. VAR R: TRect;
  927. BEGIN
  928. GetExtent(R); { Get view extents }
  929. R.A.Y := R.B.Y - 1; { One line high }
  930. New(StatusLine, Init(R,
  931. NewStatusDef(0, $FFFF,
  932. NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  933. StdStatusKeys(Nil)), Nil))); { Default status line }
  934. END;
  935. {--TProgram-----------------------------------------------------------------}
  936. { SetScreenMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  937. {---------------------------------------------------------------------------}
  938. PROCEDURE TProgram.SetScreenMode (Mode: Word);
  939. BEGIN { Compatability only }
  940. END;
  941. {--TProgram-----------------------------------------------------------------}
  942. { PutEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  943. {---------------------------------------------------------------------------}
  944. PROCEDURE TProgram.PutEvent (Var Event: TEvent);
  945. BEGIN
  946. Pending := Event; { Set pending event }
  947. END;
  948. {--TProgram-----------------------------------------------------------------}
  949. { GetEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10May98 LdB }
  950. {---------------------------------------------------------------------------}
  951. PROCEDURE TProgram.GetEvent (Var Event: TEvent);
  952. BEGIN
  953. Event.What := evNothing;
  954. If (Event.What = evNothing) Then Begin
  955. If (Pending.What <> evNothing) Then Begin { Pending event }
  956. Event := Pending; { Load pending event }
  957. Pending.What := evNothing; { Clear pending event }
  958. End Else Begin
  959. NextQueuedEvent(Event); { Next queued event }
  960. If (Event.What = evNothing) Then Begin
  961. GetKeyEvent(Event); { Fetch key event }
  962. If (Event.What = evNothing) Then Begin { No mouse event }
  963. Drivers.GetMouseEvent(Event); { Load mouse event }
  964. If (Event.What = evNothing) Then Idle; { Idle if no event }
  965. End;
  966. End;
  967. End;
  968. End;
  969. END;
  970. {--TProgram-----------------------------------------------------------------}
  971. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 12Sep97 LdB }
  972. {---------------------------------------------------------------------------}
  973. PROCEDURE TProgram.HandleEvent (Var Event: TEvent);
  974. VAR C: Char;
  975. BEGIN
  976. If (Event.What = evKeyDown) Then Begin { Key press event }
  977. C := GetAltChar(Event.KeyCode); { Get alt char code }
  978. If (C >= '1') AND (C <= '9') Then
  979. If (Message(Desktop, evBroadCast, cmSelectWindowNum,
  980. Pointer(Byte(C) - $30)) <> Nil) { Select window }
  981. Then ClearEvent(Event); { Clear event }
  982. End;
  983. Inherited HandleEvent(Event); { Call ancestor }
  984. If (Event.What = evCommand) AND { Command event }
  985. (Event.Command = cmQuit) Then Begin { Quit command }
  986. EndModal(cmQuit); { Endmodal operation }
  987. ClearEvent(Event); { Clear event }
  988. End;
  989. END;
  990. {$IFNDEF OS_DOS}
  991. {***************************************************************************}
  992. { TProgram OBJECT WIN/NT/OS2 ONLY METHODS }
  993. {***************************************************************************}
  994. {--TProgram-----------------------------------------------------------------}
  995. { GetClassText -> Platforms WIN/NT/OS2 - Checked 18Mar98 LdB }
  996. {---------------------------------------------------------------------------}
  997. FUNCTION TProgram.GetClassText: String;
  998. VAR S: String; {$IFDEF OS_OS2} I: Integer; {$ENDIF}
  999. BEGIN
  1000. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  1001. {$IFDEF PPC_DELPHI3} { DELPHI3+ CODE }
  1002. SetLength(S, 255); { Make string not empty }
  1003. SetLength(S, GetModuleFilename( 0, PChar(S),
  1004. Length(S) ) ); { Fetch module name }
  1005. {$ELSE} { OTHER COMPILERS }
  1006. S[0] := Chr(GetModuleFileName(HInstance, @S[1],
  1007. 255)); { Fetch module name }
  1008. {$ENDIF}
  1009. {$ENDIF}
  1010. {$IFDEF OS_OS2} { OS2 CODE }
  1011. WinQuerySessionTitle(Anchor, 0, @S[1], 255); { Fetch session name }
  1012. I := 1; { Start on first }
  1013. While (S[I] <> #0) AND (I<255) Do Inc(I); { Find pchar end }
  1014. S[0] := Chr(I); { Set string length }
  1015. {$ENDIF}
  1016. GetClassText := S; { Return the string }
  1017. END;
  1018. {--TProgram-----------------------------------------------------------------}
  1019. { GetClassName -> Platforms WIN/NT/OS2 - Updated 13May98 LdB }
  1020. {---------------------------------------------------------------------------}
  1021. FUNCTION TProgram.GetClassName: String;
  1022. BEGIN
  1023. GetClassName := TvProgramClassName; { Program class name }
  1024. END;
  1025. {--TProgram-----------------------------------------------------------------}
  1026. { GetClassAttr -> Platforms WIN/NT/OS2 - Checked 17Mar98 LdB }
  1027. {---------------------------------------------------------------------------}
  1028. FUNCTION TProgram.GetClassAttr: LongInt;
  1029. VAr Li: LongInt;
  1030. BEGIN
  1031. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  1032. Li := Inherited GetClassAttr; { Call ancestor }
  1033. Li := Li AND NOT ws_Child; { Not child view }
  1034. GetClassAttr := Li OR ws_OverlappedWindow; { Overlapping window }
  1035. {$ENDIF}
  1036. {$IFDEF OS_OS2} { OS2 CODE }
  1037. GetClassAttr := fcf_TitleBar OR fcf_SysMenu OR
  1038. fcf_SizeBorder OR fcf_MinMax OR fcf_TaskList OR
  1039. fcf_NoByteAlign; { Window defaults }
  1040. {$ENDIF}
  1041. END;
  1042. {--TProgram-----------------------------------------------------------------}
  1043. { GetMsghandler -> Platforms WIN/NT/OS2 - Updated 13May98 LdB }
  1044. {---------------------------------------------------------------------------}
  1045. FUNCTION TProgram.GetMsgHandler: Pointer;
  1046. BEGIN
  1047. GetMsgHandler := @TvAppMsgHandler; { Application handler }
  1048. END;
  1049. {$ENDIF}
  1050. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1051. { TApplication OBJECT METHODS }
  1052. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1053. {--TApplication-------------------------------------------------------------}
  1054. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1055. {---------------------------------------------------------------------------}
  1056. CONSTRUCTOR TApplication.Init;
  1057. BEGIN
  1058. InitMemory; { Start memory up }
  1059. InitVideo; { Start video up }
  1060. InitEvents; { Start event drive }
  1061. InitSysError; { Start system error }
  1062. InitHistory; { Start history up }
  1063. Inherited Init; { Call ancestor }
  1064. END;
  1065. {--TApplication-------------------------------------------------------------}
  1066. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1067. {---------------------------------------------------------------------------}
  1068. DESTRUCTOR TApplication.Done;
  1069. BEGIN
  1070. Inherited Done; { Call ancestor }
  1071. DoneHistory; { Close history }
  1072. DoneSysError; { Close system error }
  1073. DoneEvents; { Close event drive }
  1074. DoneVideo; { Close video }
  1075. DoneMemory; { Close memory }
  1076. END;
  1077. {--TApplication-------------------------------------------------------------}
  1078. { Tile -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1079. {---------------------------------------------------------------------------}
  1080. PROCEDURE TApplication.Tile;
  1081. VAR R: TRect;
  1082. BEGIN
  1083. GetTileRect(R); { Tileable area }
  1084. If (Desktop <> Nil) Then Desktop^.Tile(R); { Tile desktop }
  1085. END;
  1086. {--TApplication-------------------------------------------------------------}
  1087. { Cascade -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1088. {---------------------------------------------------------------------------}
  1089. PROCEDURE TApplication.Cascade;
  1090. VAR R: TRect;
  1091. BEGIN
  1092. GetTileRect(R); { Cascade area }
  1093. If (Desktop <> Nil) Then Desktop^.Cascade(R); { Cascade desktop }
  1094. END;
  1095. {--TApplication-------------------------------------------------------------}
  1096. { DosShell -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Oct99 LdB }
  1097. {---------------------------------------------------------------------------}
  1098. PROCEDURE TApplication.DosShell;
  1099. BEGIN { Compatability only }
  1100. END;
  1101. {--TApplication-------------------------------------------------------------}
  1102. { GetTileRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1103. {---------------------------------------------------------------------------}
  1104. PROCEDURE TApplication.GetTileRect (Var R: TRect);
  1105. BEGIN
  1106. If (DeskTop <> Nil) Then Desktop^.GetExtent(R) { Desktop extents }
  1107. Else GetExtent(R); { Our extents }
  1108. END;
  1109. {--TApplication-------------------------------------------------------------}
  1110. { HandleEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1111. {---------------------------------------------------------------------------}
  1112. PROCEDURE TApplication.HandleEvent (Var Event: TEvent);
  1113. BEGIN
  1114. Inherited HandleEvent(Event); { Call ancestor }
  1115. If (Event.What = evCommand) Then Begin
  1116. Case Event.Command Of
  1117. cmTile: Tile; { Tile request }
  1118. cmCascade: Cascade; { Cascade request }
  1119. cmDosShell: DosShell; { DOS shell request }
  1120. Else Exit; { Unhandled exit }
  1121. End;
  1122. ClearEvent(Event); { Clear the event }
  1123. End;
  1124. END;
  1125. {***************************************************************************}
  1126. { INTERFACE ROUTINES }
  1127. {***************************************************************************}
  1128. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1129. { STANDARD MENU AND STATUS LINES ROUTINES }
  1130. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1131. {---------------------------------------------------------------------------}
  1132. { StdStatusKeys -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1133. {---------------------------------------------------------------------------}
  1134. FUNCTION StdStatusKeys (Next: PStatusItem): PStatusItem;
  1135. BEGIN
  1136. StdStatusKeys :=
  1137. NewStatusKey('', kbAltX, cmQuit,
  1138. NewStatusKey('', kbF10, cmMenu,
  1139. NewStatusKey('', kbAltF3, cmClose,
  1140. NewStatusKey('', kbF5, cmZoom,
  1141. NewStatusKey('', kbCtrlF5, cmResize,
  1142. NewStatusKey('', kbF6, cmNext,
  1143. NewStatusKey('', kbShiftF6, cmPrev,
  1144. Next)))))));
  1145. END;
  1146. {---------------------------------------------------------------------------}
  1147. { StdFileMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1148. {---------------------------------------------------------------------------}
  1149. FUNCTION StdFileMenuItems (Next: PMenuItem): PMenuItem;
  1150. BEGIN
  1151. StdFileMenuItems :=
  1152. NewItem('~N~ew', '', kbNoKey, cmNew, hcNew,
  1153. NewItem('~O~pen...', 'F3', kbF3, cmOpen, hcOpen,
  1154. NewItem('~S~ave', 'F2', kbF2, cmSave, hcSave,
  1155. NewItem('S~a~ve as...', '', kbNoKey, cmSaveAs, hcSaveAs,
  1156. NewItem('Save a~l~l', '', kbNoKey, cmSaveAll, hcSaveAll,
  1157. NewLine(
  1158. NewItem('~C~hange dir...', '', kbNoKey, cmChangeDir, hcChangeDir,
  1159. NewItem('OS shell', '', kbNoKey, cmDosShell, hcDosShell,
  1160. NewItem('E~x~it', 'Alt+X', kbAltX, cmQuit, hcExit,
  1161. Next)))))))));
  1162. END;
  1163. {---------------------------------------------------------------------------}
  1164. { StdEditMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1165. {---------------------------------------------------------------------------}
  1166. FUNCTION StdEditMenuItems (Next: PMenuItem): PMenuItem;
  1167. BEGIN
  1168. StdEditMenuItems :=
  1169. NewItem('~U~ndo', '', kbAltBack, cmUndo, hcUndo,
  1170. NewLine(
  1171. NewItem('Cu~t~', 'Shift+Del', kbShiftDel, cmCut, hcCut,
  1172. NewItem('~C~opy', 'Ctrl+Ins', kbCtrlIns, cmCopy, hcCopy,
  1173. NewItem('~P~aste', 'Shift+Ins', kbShiftIns, cmPaste, hcPaste,
  1174. NewItem('C~l~ear', 'Ctrl+Del', kbCtrlDel, cmClear, hcClear,
  1175. Next))))));
  1176. END;
  1177. {---------------------------------------------------------------------------}
  1178. { StdWindowMenuItems -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1179. {---------------------------------------------------------------------------}
  1180. FUNCTION StdWindowMenuItems (Next: PMenuItem): PMenuItem;
  1181. BEGIN
  1182. StdWindowMenuItems :=
  1183. NewItem('~T~ile', '', kbNoKey, cmTile, hcTile,
  1184. NewItem('C~a~scade', '', kbNoKey, cmCascade, hcCascade,
  1185. NewItem('Cl~o~se all', '', kbNoKey, cmCloseAll, hcCloseAll,
  1186. NewLine(
  1187. NewItem('~S~ize/Move','Ctrl+F5', kbCtrlF5, cmResize, hcResize,
  1188. NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcZoom,
  1189. NewItem('~N~ext', 'F6', kbF6, cmNext, hcNext,
  1190. NewItem('~P~revious', 'Shift+F6', kbShiftF6, cmPrev, hcPrev,
  1191. NewItem('~C~lose', 'Alt+F3', kbAltF3, cmClose, hcClose,
  1192. Next)))))))));
  1193. END;
  1194. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1195. { OBJECT REGISTER ROUTINES }
  1196. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1197. {---------------------------------------------------------------------------}
  1198. { RegisterApp -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct99 LdB }
  1199. {---------------------------------------------------------------------------}
  1200. PROCEDURE RegisterApp;
  1201. BEGIN
  1202. RegisterType(RBackground); { Register background }
  1203. RegisterType(RDesktop); { Register desktop }
  1204. END;
  1205. END.
  1206. {
  1207. $Log$
  1208. Revision 1.4 2001-04-10 21:57:55 pierre
  1209. + first adds for Use_API define
  1210. Revision 1.3 2001/04/10 21:29:54 pierre
  1211. * import of Leon de Boer's files
  1212. Revision 1.2 2000/08/24 11:43:13 marco
  1213. * Added CVS log and ID entries.
  1214. }