app.pas 63 KB

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