app.pas 63 KB

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