app.pas 56 KB

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