app.pas 56 KB

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