app.pas 65 KB

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