wviews.pas 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$I globdir.inc}
  12. unit WViews;
  13. interface
  14. uses Objects,Drivers,Views,Menus,Dialogs;
  15. const
  16. evIdle = $8000;
  17. cmLocalMenu = 54100;
  18. cmUpdate = 54101;
  19. cmListFocusChanged = 54102;
  20. CPlainCluster = #7#8#9#9;
  21. type
  22. PCenterDialog = ^TCenterDialog;
  23. TCenterDialog = object(TDialog)
  24. constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  25. end;
  26. PAdvancedMenuBox = ^TAdvancedMenuBox;
  27. TAdvancedMenuBox = object(TMenuBox)
  28. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  29. AParentMenu: PMenuView): PMenuView; virtual;
  30. function Execute: Word; virtual;
  31. end;
  32. PAdvancedMenuPopUp = ^TAdvancedMenuPopup;
  33. TAdvancedMenuPopUp = object(TMenuPopup)
  34. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  35. AParentMenu: PMenuView): PMenuView; virtual;
  36. function Execute: Word; virtual;
  37. end;
  38. PAdvancedMenuBar = ^TAdvancedMenuBar;
  39. TAdvancedMenuBar = object(TMenuBar)
  40. constructor Init(var Bounds: TRect; AMenu: PMenu);
  41. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  42. AParentMenu: PMenuView): PMenuView; virtual;
  43. procedure Update; virtual;
  44. function GetMenuItem(cm : word) : PMenuItem;
  45. procedure HandleEvent(var Event: TEvent); virtual;
  46. function Execute: Word; virtual;
  47. end;
  48. PAdvancedStaticText = ^TAdvancedStaticText;
  49. TAdvancedStaticText = object(TStaticText)
  50. procedure SetText(S: string); virtual;
  51. end;
  52. PAdvancedListBox = ^TAdvancedListBox;
  53. TAdvancedListBox = object(TListBox)
  54. Default: boolean;
  55. procedure FocusItem(Item: sw_integer); virtual;
  56. procedure HandleEvent(var Event: TEvent); virtual;
  57. constructor Load(var S: TStream);
  58. procedure Store(var S: TStream);
  59. end;
  60. TLocalMenuListBox = object(TAdvancedListBox)
  61. procedure HandleEvent(var Event: TEvent); virtual;
  62. procedure LocalMenu(P: TPoint); virtual;
  63. function GetLocalMenu: PMenu; virtual;
  64. function GetCommandTarget: PView; virtual;
  65. private
  66. LastLocalCmd: word;
  67. end;
  68. PColorStaticText = ^TColorStaticText;
  69. TColorStaticText = object(TAdvancedStaticText)
  70. Color: word;
  71. DontWrap: boolean;
  72. Delta: TPoint;
  73. constructor Init(var Bounds: TRect; AText: String; AColor: word);
  74. procedure Draw; virtual;
  75. constructor Load(var S: TStream);
  76. procedure Store(var S: TStream);
  77. end;
  78. PHSListBox = ^THSListBox;
  79. THSListBox = object(TLocalMenuListBox)
  80. constructor Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  81. end;
  82. PDlgWindow = ^TDlgWindow;
  83. TDlgWindow = object(TDialog)
  84. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer);
  85. end;
  86. PAdvancedStatusLine = ^TAdvancedStatusLine;
  87. TAdvancedStatusLine = object(TStatusLine)
  88. StatusText: PString;
  89. function GetStatusText: string; virtual;
  90. procedure SetStatusText(const S: string); virtual;
  91. procedure ClearStatusText; virtual;
  92. procedure Draw; virtual;
  93. end;
  94. PDropDownListBox = ^TDropDownListBox;
  95. PDDHelperLB = ^TDDHelperLB;
  96. TDDHelperLB = object(TLocalMenuListBox)
  97. constructor Init(ALink: PDropDownListBox; var Bounds: TRect; ANumCols: Word; AScrollBar: PScrollBar);
  98. procedure HandleEvent(var Event: TEvent); virtual;
  99. procedure SetState(AState: Word; Enable: Boolean); virtual;
  100. procedure SelectItem(Item: Sw_Integer); virtual;
  101. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  102. function GetLocalMenu: PMenu; virtual;
  103. function GetCommandTarget: PView; virtual;
  104. private
  105. Link : PDropDownListBox;
  106. LastTT: longint;
  107. InClose: boolean;
  108. end;
  109. TDropDownListBox = object(TView)
  110. Text: string;
  111. Focused: sw_integer;
  112. List: PCollection;
  113. constructor Init(var Bounds: TRect; ADropLineCount: Sw_integer; AList: PCollection);
  114. procedure HandleEvent(var Event: TEvent); virtual;
  115. function GetText(Item: pointer; MaxLen: sw_integer): string; virtual;
  116. procedure NewList(AList: PCollection); virtual;
  117. procedure CreateListBox(var R: TRect);
  118. procedure DropList(Drop: boolean); virtual;
  119. function GetItemCount: sw_integer; virtual;
  120. procedure FocusItem(Item: sw_integer); virtual;
  121. function LBGetLocalMenu: PMenu; virtual;
  122. function LBGetCommandTarget: PView; virtual;
  123. procedure SetState(AState: Word; Enable: Boolean); virtual;
  124. procedure Draw; virtual;
  125. function GetPalette: PPalette; virtual;
  126. destructor Done; virtual;
  127. private
  128. DropLineCount: Sw_integer;
  129. ListDropped : boolean;
  130. ListBox : PDDHelperLB;
  131. SB : PScrollBar;
  132. end;
  133. PGroupView = ^TGroupView;
  134. TGroupView = object(TLabel)
  135. constructor Init(var Bounds: TRect; AText: String; ALink: PView);
  136. procedure Draw; virtual;
  137. end;
  138. PPlainCheckBoxes = ^TPlainCheckBoxes;
  139. TPlainCheckBoxes = object(TCheckBoxes)
  140. function GetPalette: PPalette; virtual;
  141. end;
  142. PPlainRadioButtons = ^TPlainRadioButtons;
  143. TPlainRadioButtons = object(TRadioButtons)
  144. function GetPalette: PPalette; virtual;
  145. end;
  146. procedure InsertOK(ADialog: PDialog);
  147. procedure InsertButtons(ADialog: PDialog);
  148. procedure Bug(const S: string; Params: pointer);
  149. procedure ErrorBox(const S: string; Params: pointer);
  150. procedure WarningBox(const S: string; Params: pointer);
  151. procedure InformationBox(const S: string; Params: pointer);
  152. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  153. procedure ShowMessage(Msg: string);
  154. procedure HideMessage;
  155. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  156. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  157. function IsSubMenu(P: PMenuItem): boolean;
  158. function IsSeparator(P: PMenuItem): boolean;
  159. function UpdateMenu(M: PMenu): boolean;
  160. function SearchSubMenu(M: PMenu; Index: Sw_integer): PMenuItem;
  161. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  162. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  163. function GetMenuItemBefore(Menu:PMenu; BeforeOf: PMenuItem): PMenuItem;
  164. procedure NotImplemented;
  165. procedure RegisterWViews;
  166. implementation
  167. uses Mouse,
  168. Commands,App,MsgBox,
  169. WUtils;
  170. {$ifndef NOOBJREG}
  171. const
  172. RAdvancedListBox: TStreamRec = (
  173. ObjType: 1120;
  174. VmtLink: Ofs(TypeOf(TAdvancedListBox)^);
  175. Load: @TAdvancedListBox.Load;
  176. Store: @TAdvancedListBox.Store
  177. );
  178. RColorStaticText: TStreamRec = (
  179. ObjType: 1121;
  180. VmtLink: Ofs(TypeOf(TColorStaticText)^);
  181. Load: @TColorStaticText.Load;
  182. Store: @TColorStaticText.Store
  183. );
  184. RHSListBox: TStreamRec = (
  185. ObjType: 1122;
  186. VmtLink: Ofs(TypeOf(THSListBox)^);
  187. Load: @THSListBox.Load;
  188. Store: @THSListBox.Store
  189. );
  190. RDlgWindow: TStreamRec = (
  191. ObjType: 1123;
  192. VmtLink: Ofs(TypeOf(TDlgWindow)^);
  193. Load: @TDlgWindow.Load;
  194. Store: @TDlgWindow.Store
  195. );
  196. {$endif}
  197. const
  198. MessageDialog : PCenterDialog = nil;
  199. {*****************************************************************************
  200. TCenterDialog
  201. *****************************************************************************}
  202. constructor TCenterDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  203. begin
  204. inherited Init(Bounds,ATitle);
  205. Options:=Options or ofCentered;
  206. end;
  207. function TAdvancedMenuBox.NewSubView(var Bounds: TRect; AMenu: PMenu;
  208. AParentMenu: PMenuView): PMenuView;
  209. begin
  210. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  211. end;
  212. function TAdvancedMenuBox.Execute: word;
  213. type
  214. MenuAction = (DoNothing, DoSelect, DoReturn);
  215. var
  216. AutoSelect: Boolean;
  217. Action: MenuAction;
  218. Ch: Char;
  219. Result: Word;
  220. ItemShown, P: PMenuItem;
  221. Target: PMenuView;
  222. R: TRect;
  223. E: TEvent;
  224. MouseActive: Boolean;
  225. function IsDisabled(Item: PMenuItem): boolean;
  226. var Found: boolean;
  227. begin
  228. Found:=Item^.Disabled or IsSeparator(Item);
  229. if (Found=false) and (IsSubMenu(Item)=false) then
  230. Found:=CommandEnabled(Item^.Command)=false;
  231. IsDisabled:=Found;
  232. end;
  233. procedure TrackMouse;
  234. var
  235. Mouse: TPoint;
  236. R: TRect;
  237. OldC: PMenuItem;
  238. begin
  239. MakeLocal(E.Where, Mouse);
  240. OldC:=Current;
  241. Current := Menu^.Items;
  242. while Current <> nil do
  243. begin
  244. GetItemRect(Current, R);
  245. if R.Contains(Mouse) then
  246. begin
  247. MouseActive := True;
  248. Break;
  249. end;
  250. Current := Current^.Next;
  251. end;
  252. if (Current<>nil) and IsDisabled(Current) then
  253. begin
  254. Current:={OldC}nil;
  255. MouseActive:=false;
  256. end;
  257. end;
  258. procedure TrackKey(FindNext: Boolean);
  259. procedure NextItem;
  260. begin
  261. Current := Current^.Next;
  262. if Current = nil then Current := Menu^.Items;
  263. end;
  264. procedure PrevItem;
  265. var
  266. P: PMenuItem;
  267. begin
  268. P := Current;
  269. if P = Menu^.Items then P := nil;
  270. repeat NextItem until Current^.Next = P;
  271. end;
  272. begin
  273. if Current <> nil then
  274. repeat
  275. if FindNext then NextItem else PrevItem;
  276. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  277. end;
  278. function MouseInOwner: Boolean;
  279. var
  280. Mouse: TPoint;
  281. R: TRect;
  282. begin
  283. MouseInOwner := False;
  284. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  285. begin
  286. ParentMenu^.MakeLocal(E.Where, Mouse);
  287. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  288. MouseInOwner := R.Contains(Mouse);
  289. end;
  290. end;
  291. function MouseInMenus: Boolean;
  292. var
  293. P: PMenuView;
  294. begin
  295. P := ParentMenu;
  296. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  297. P := P^.ParentMenu;
  298. MouseInMenus := P <> nil;
  299. end;
  300. function TopMenu: PMenuView;
  301. var
  302. P: PMenuView;
  303. begin
  304. P := @Self;
  305. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  306. TopMenu := P;
  307. end;
  308. begin
  309. AutoSelect := False; E.What:=evNothing;
  310. Result := 0;
  311. ItemShown := nil;
  312. Current := Menu^.Default;
  313. MouseActive := False;
  314. if UpdateMenu(Menu) then
  315. begin
  316. if Current<>nil then
  317. if Current^.Disabled then
  318. TrackKey(true);
  319. repeat
  320. Action := DoNothing;
  321. GetEvent(E);
  322. case E.What of
  323. evMouseDown:
  324. if MouseInView(E.Where) or MouseInOwner then
  325. begin
  326. TrackMouse;
  327. if Size.Y = 1 then AutoSelect := True;
  328. end else Action := DoReturn;
  329. evMouseUp:
  330. begin
  331. TrackMouse;
  332. if MouseInOwner then
  333. Current := Menu^.Default
  334. else
  335. if (Current <> nil) and (Current^.Name <> nil) then
  336. Action := DoSelect
  337. else
  338. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  339. else
  340. begin
  341. Current := Menu^.Default;
  342. if Current = nil then Current := Menu^.Items;
  343. Action := DoNothing;
  344. end;
  345. end;
  346. evMouseMove:
  347. if E.Buttons <> 0 then
  348. begin
  349. TrackMouse;
  350. if not (MouseInView(E.Where) or MouseInOwner) and
  351. MouseInMenus then Action := DoReturn;
  352. end;
  353. evKeyDown:
  354. case CtrlToArrow(E.KeyCode) of
  355. kbUp, kbDown:
  356. if Size.Y <> 1 then
  357. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  358. if E.KeyCode = kbDown then AutoSelect := True;
  359. kbLeft, kbRight:
  360. if ParentMenu = nil then
  361. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  362. Action := DoReturn;
  363. kbHome, kbEnd:
  364. if Size.Y <> 1 then
  365. begin
  366. Current := Menu^.Items;
  367. if E.KeyCode = kbEnd then TrackKey(False);
  368. end;
  369. kbEnter:
  370. begin
  371. if Size.Y = 1 then AutoSelect := True;
  372. Action := DoSelect;
  373. end;
  374. kbEsc:
  375. begin
  376. Action := DoReturn;
  377. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  378. ClearEvent(E);
  379. end;
  380. else
  381. Target := @Self;
  382. Ch := GetAltChar(E.KeyCode);
  383. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  384. P := Target^.FindItem(Ch);
  385. if P = nil then
  386. begin
  387. P := TopMenu^.HotKey(E.KeyCode);
  388. if (P <> nil) and CommandEnabled(P^.Command) then
  389. begin
  390. Result := P^.Command;
  391. Action := DoReturn;
  392. end
  393. end else
  394. if Target = @Self then
  395. begin
  396. if Size.Y = 1 then AutoSelect := True;
  397. Action := DoSelect;
  398. Current := P;
  399. end else
  400. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  401. Action := DoReturn;
  402. end;
  403. evCommand:
  404. if E.Command = cmMenu then
  405. begin
  406. AutoSelect := False;
  407. if ParentMenu <> nil then Action := DoReturn;
  408. end else Action := DoReturn;
  409. end;
  410. if ItemShown <> Current then
  411. begin
  412. ItemShown := Current;
  413. DrawView;
  414. end;
  415. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  416. if Current <> nil then with Current^ do if Name <> nil then
  417. if Command = 0 then
  418. begin
  419. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  420. GetItemRect(Current, R);
  421. R.A.X := R.A.X + Origin.X;
  422. R.A.Y := R.B.Y + Origin.Y;
  423. R.B := Owner^.Size;
  424. if Size.Y = 1 then Dec(R.A.X);
  425. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  426. Result := Owner^.ExecView(Target);
  427. Dispose(Target, Done);
  428. end else if Action = DoSelect then Result := Command;
  429. if (Result <> 0) and CommandEnabled(Result) then
  430. begin
  431. Action := DoReturn;
  432. ClearEvent(E);
  433. end
  434. else
  435. Result := 0;
  436. until Action = DoReturn;
  437. end;
  438. if E.What <> evNothing then
  439. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  440. if Current <> nil then
  441. begin
  442. Menu^.Default := Current;
  443. Current := nil;
  444. DrawView;
  445. end;
  446. Execute := Result;
  447. end;
  448. function TAdvancedMenuPopup.NewSubView(var Bounds: TRect; AMenu: PMenu;
  449. AParentMenu: PMenuView): PMenuView;
  450. begin
  451. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  452. end;
  453. function TAdvancedMenuPopup.Execute: word;
  454. type
  455. MenuAction = (DoNothing, DoSelect, DoReturn);
  456. var
  457. AutoSelect: Boolean;
  458. Action: MenuAction;
  459. Ch: Char;
  460. Result: Word;
  461. ItemShown, P: PMenuItem;
  462. Target: PMenuView;
  463. R: TRect;
  464. E: TEvent;
  465. MouseActive: Boolean;
  466. function IsDisabled(Item: PMenuItem): boolean;
  467. var Found: boolean;
  468. begin
  469. Found:=Item^.Disabled or IsSeparator(Item);
  470. if (Found=false) and (IsSubMenu(Item)=false) then
  471. Found:=CommandEnabled(Item^.Command)=false;
  472. IsDisabled:=Found;
  473. end;
  474. procedure TrackMouse;
  475. var
  476. Mouse: TPoint;
  477. R: TRect;
  478. OldC: PMenuItem;
  479. begin
  480. MakeLocal(E.Where, Mouse);
  481. OldC:=Current;
  482. Current := Menu^.Items;
  483. while Current <> nil do
  484. begin
  485. GetItemRect(Current, R);
  486. if R.Contains(Mouse) then
  487. begin
  488. MouseActive := True;
  489. Break;
  490. end;
  491. Current := Current^.Next;
  492. end;
  493. if (Current<>nil) and IsDisabled(Current) then
  494. begin
  495. Current:={OldC}nil;
  496. MouseActive:=false;
  497. end;
  498. end;
  499. procedure TrackKey(FindNext: Boolean);
  500. procedure NextItem;
  501. begin
  502. Current := Current^.Next;
  503. if Current = nil then Current := Menu^.Items;
  504. end;
  505. procedure PrevItem;
  506. var
  507. P: PMenuItem;
  508. begin
  509. P := Current;
  510. if P = Menu^.Items then P := nil;
  511. repeat NextItem until Current^.Next = P;
  512. end;
  513. begin
  514. if Current <> nil then
  515. repeat
  516. if FindNext then NextItem else PrevItem;
  517. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  518. end;
  519. function MouseInOwner: Boolean;
  520. var
  521. Mouse: TPoint;
  522. R: TRect;
  523. begin
  524. MouseInOwner := False;
  525. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  526. begin
  527. ParentMenu^.MakeLocal(E.Where, Mouse);
  528. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  529. MouseInOwner := R.Contains(Mouse);
  530. end;
  531. end;
  532. function MouseInMenus: Boolean;
  533. var
  534. P: PMenuView;
  535. begin
  536. P := ParentMenu;
  537. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  538. P := P^.ParentMenu;
  539. MouseInMenus := P <> nil;
  540. end;
  541. function TopMenu: PMenuView;
  542. var
  543. P: PMenuView;
  544. begin
  545. P := @Self;
  546. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  547. TopMenu := P;
  548. end;
  549. begin
  550. AutoSelect := False; E.What:=evNothing;
  551. Result := 0;
  552. ItemShown := nil;
  553. Current := Menu^.Default;
  554. MouseActive := False;
  555. if UpdateMenu(Menu) then
  556. begin
  557. if Current<>nil then
  558. if Current^.Disabled then
  559. TrackKey(true);
  560. repeat
  561. Action := DoNothing;
  562. GetEvent(E);
  563. case E.What of
  564. evMouseDown:
  565. if MouseInView(E.Where) or MouseInOwner then
  566. begin
  567. TrackMouse;
  568. if Size.Y = 1 then AutoSelect := True;
  569. end else Action := DoReturn;
  570. evMouseUp:
  571. begin
  572. TrackMouse;
  573. if MouseInOwner then
  574. Current := Menu^.Default
  575. else
  576. if (Current <> nil) and (Current^.Name <> nil) then
  577. Action := DoSelect
  578. else
  579. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  580. else
  581. begin
  582. Current := Menu^.Default;
  583. if Current = nil then Current := Menu^.Items;
  584. Action := DoNothing;
  585. end;
  586. end;
  587. evMouseMove:
  588. if E.Buttons <> 0 then
  589. begin
  590. TrackMouse;
  591. if not (MouseInView(E.Where) or MouseInOwner) and
  592. MouseInMenus then Action := DoReturn;
  593. end;
  594. evKeyDown:
  595. case CtrlToArrow(E.KeyCode) of
  596. kbUp, kbDown:
  597. if Size.Y <> 1 then
  598. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  599. if E.KeyCode = kbDown then AutoSelect := True;
  600. kbLeft, kbRight:
  601. if ParentMenu = nil then
  602. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  603. Action := DoReturn;
  604. kbHome, kbEnd:
  605. if Size.Y <> 1 then
  606. begin
  607. Current := Menu^.Items;
  608. if E.KeyCode = kbEnd then TrackKey(False);
  609. end;
  610. kbEnter:
  611. begin
  612. if Size.Y = 1 then AutoSelect := True;
  613. Action := DoSelect;
  614. end;
  615. kbEsc:
  616. begin
  617. Action := DoReturn;
  618. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  619. ClearEvent(E);
  620. end;
  621. else
  622. Target := @Self;
  623. Ch := GetAltChar(E.KeyCode);
  624. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  625. P := Target^.FindItem(Ch);
  626. if P = nil then
  627. begin
  628. P := TopMenu^.HotKey(E.KeyCode);
  629. if (P <> nil) and CommandEnabled(P^.Command) then
  630. begin
  631. Result := P^.Command;
  632. Action := DoReturn;
  633. end
  634. end else
  635. if Target = @Self then
  636. begin
  637. if Size.Y = 1 then AutoSelect := True;
  638. Action := DoSelect;
  639. Current := P;
  640. end else
  641. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  642. Action := DoReturn;
  643. end;
  644. evCommand:
  645. if E.Command = cmMenu then
  646. begin
  647. AutoSelect := False;
  648. if ParentMenu <> nil then Action := DoReturn;
  649. end else Action := DoReturn;
  650. end;
  651. if ItemShown <> Current then
  652. begin
  653. ItemShown := Current;
  654. DrawView;
  655. end;
  656. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  657. if Current <> nil then with Current^ do if Name <> nil then
  658. if Command = 0 then
  659. begin
  660. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  661. GetItemRect(Current, R);
  662. R.A.X := R.A.X + Origin.X;
  663. R.A.Y := R.B.Y + Origin.Y;
  664. R.B := Owner^.Size;
  665. if Size.Y = 1 then Dec(R.A.X);
  666. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  667. Result := Owner^.ExecView(Target);
  668. Dispose(Target, Done);
  669. end else if Action = DoSelect then Result := Command;
  670. if (Result <> 0) and CommandEnabled(Result) then
  671. begin
  672. Action := DoReturn;
  673. ClearEvent(E);
  674. end
  675. else
  676. Result := 0;
  677. until Action = DoReturn;
  678. end;
  679. if E.What <> evNothing then
  680. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  681. if Current <> nil then
  682. begin
  683. Menu^.Default := Current;
  684. Current := nil;
  685. DrawView;
  686. end;
  687. Execute := Result;
  688. end;
  689. constructor TAdvancedMenuBar.Init(var Bounds: TRect; AMenu: PMenu);
  690. begin
  691. inherited Init(Bounds, AMenu);
  692. EventMask:=EventMask or evBroadcast;
  693. GrowMode:=gfGrowHiX;
  694. end;
  695. function TAdvancedMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  696. AParentMenu: PMenuView): PMenuView;
  697. begin
  698. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  699. end;
  700. procedure TAdvancedMenuBar.Update;
  701. begin
  702. UpdateMenu(Menu);
  703. DrawView;
  704. end;
  705. function TAdvancedMenuBar.GetMenuItem(cm : word) : PMenuItem;
  706. type
  707. PItemChain = ^TItemChain;
  708. TItemChain = record
  709. Next : PMenuItem;
  710. Up : PItemChain;
  711. end;
  712. var Cur : PMenuItem;
  713. Up,NUp : PItemChain;
  714. begin
  715. Cur:=Menu^.Items;
  716. Up:=nil;
  717. if cm=0 then
  718. begin
  719. GetMenuItem:=nil;
  720. exit;
  721. end;
  722. while assigned(Cur) and (Cur^.Command<>cm) do
  723. begin
  724. if (Cur^.Command=0) and assigned(Cur^.SubMenu) and
  725. assigned(Cur^.Name) and
  726. assigned(Cur^.SubMenu^.Items) then
  727. {subMenu}
  728. begin
  729. If assigned(Cur^.Next) then
  730. begin
  731. New(Nup);
  732. Nup^.Up:=Up;
  733. Nup^.next:=Cur^.Next;
  734. Up:=Nup;
  735. end;
  736. Cur:=Cur^.SubMenu^.Items;
  737. end
  738. else
  739. { normal item }
  740. begin
  741. if assigned(Cur^.Next) then
  742. Cur:=Cur^.Next
  743. else if assigned(Up) then
  744. begin
  745. Cur:=Up^.next;
  746. NUp:=Up;
  747. Up:=Up^.Up;
  748. Dispose(NUp);
  749. end
  750. else
  751. Cur:=Nil;
  752. end;
  753. end;
  754. GetMenuItem:=Cur;
  755. While assigned(Up) do
  756. begin
  757. NUp:=Up;
  758. Up:=Up^.up;
  759. Dispose(NUp);
  760. end;
  761. end;
  762. procedure TAdvancedMenuBar.HandleEvent(var Event: TEvent);
  763. begin
  764. case Event.What of
  765. evBroadcast :
  766. case Event.Command of
  767. cmCommandSetChanged : Update;
  768. cmUpdate : Update;
  769. end;
  770. end;
  771. inherited HandleEvent(Event);
  772. end;
  773. function TAdvancedMenuBar.Execute: word;
  774. type
  775. MenuAction = (DoNothing, DoSelect, DoReturn);
  776. var
  777. AutoSelect: Boolean;
  778. Action: MenuAction;
  779. Ch: Char;
  780. Result: Word;
  781. ItemShown, P: PMenuItem;
  782. Target: PMenuView;
  783. R: TRect;
  784. E: TEvent;
  785. MouseActive: Boolean;
  786. function IsDisabled(Item: PMenuItem): boolean;
  787. var Dis : boolean;
  788. begin
  789. Dis:=Item^.Disabled or IsSeparator(Item);
  790. if (Dis=false) and (IsSubMenu(Item)=false) then
  791. Dis:=CommandEnabled(Item^.Command)=false;
  792. IsDisabled:=Dis;
  793. end;
  794. procedure TrackMouse;
  795. var
  796. Mouse: TPoint;
  797. R: TRect;
  798. OldC: PMenuItem;
  799. begin
  800. MakeLocal(E.Where, Mouse);
  801. OldC:=Current;
  802. Current := Menu^.Items;
  803. while Current <> nil do
  804. begin
  805. GetItemRect(Current, R);
  806. if R.Contains(Mouse) then
  807. begin
  808. MouseActive := True;
  809. Break;
  810. end;
  811. Current := Current^.Next;
  812. end;
  813. if (Current<>nil) and IsDisabled(Current) then
  814. Current:=nil;
  815. end;
  816. procedure TrackKey(FindNext: Boolean);
  817. procedure NextItem;
  818. begin
  819. Current := Current^.Next;
  820. if Current = nil then Current := Menu^.Items;
  821. end;
  822. procedure PrevItem;
  823. var
  824. P: PMenuItem;
  825. begin
  826. P := Current;
  827. if P = Menu^.Items then P := nil;
  828. repeat NextItem until Current^.Next = P;
  829. end;
  830. begin
  831. if Current <> nil then
  832. repeat
  833. if FindNext then NextItem else PrevItem;
  834. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  835. end;
  836. function MouseInOwner: Boolean;
  837. var
  838. Mouse: TPoint;
  839. R: TRect;
  840. begin
  841. MouseInOwner := False;
  842. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  843. begin
  844. ParentMenu^.MakeLocal(E.Where, Mouse);
  845. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  846. MouseInOwner := R.Contains(Mouse);
  847. end;
  848. end;
  849. function MouseInMenus: Boolean;
  850. var
  851. P: PMenuView;
  852. begin
  853. P := ParentMenu;
  854. while (P <> nil) and not P^.MouseInView(E.Where) do P := P^.ParentMenu;
  855. MouseInMenus := P <> nil;
  856. end;
  857. function TopMenu: PMenuView;
  858. var
  859. P: PMenuView;
  860. begin
  861. P := @Self;
  862. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  863. TopMenu := P;
  864. end;
  865. begin
  866. AutoSelect := False; E.What:=evNothing;
  867. Result := 0;
  868. ItemShown := nil;
  869. Current := Menu^.Default;
  870. MouseActive := False;
  871. if UpdateMenu(Menu) then
  872. begin
  873. if Current<>nil then
  874. if Current^.Disabled then
  875. TrackKey(true);
  876. repeat
  877. Action := DoNothing;
  878. GetEvent(E);
  879. case E.What of
  880. evMouseDown:
  881. if MouseInView(E.Where) or MouseInOwner then
  882. begin
  883. TrackMouse;
  884. if Size.Y = 1 then AutoSelect := True;
  885. end else Action := DoReturn;
  886. evMouseUp:
  887. begin
  888. TrackMouse;
  889. if MouseInOwner then
  890. Current := Menu^.Default
  891. else
  892. if (Current <> nil) and (Current^.Name <> nil) then
  893. Action := DoSelect
  894. else
  895. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  896. else
  897. begin
  898. Current := Menu^.Default;
  899. if Current = nil then Current := Menu^.Items;
  900. Action := DoNothing;
  901. end;
  902. end;
  903. evMouseMove:
  904. if E.Buttons <> 0 then
  905. begin
  906. TrackMouse;
  907. if not (MouseInView(E.Where) or MouseInOwner) and
  908. MouseInMenus then Action := DoReturn;
  909. end;
  910. evKeyDown:
  911. case CtrlToArrow(E.KeyCode) of
  912. kbUp, kbDown:
  913. if Size.Y <> 1 then
  914. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  915. if E.KeyCode = kbDown then AutoSelect := True;
  916. kbLeft, kbRight:
  917. if ParentMenu = nil then
  918. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  919. Action := DoReturn;
  920. kbHome, kbEnd:
  921. if Size.Y <> 1 then
  922. begin
  923. Current := Menu^.Items;
  924. if E.KeyCode = kbEnd then TrackKey(False);
  925. end;
  926. kbEnter:
  927. begin
  928. if Size.Y = 1 then AutoSelect := True;
  929. Action := DoSelect;
  930. end;
  931. kbEsc:
  932. begin
  933. Action := DoReturn;
  934. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  935. ClearEvent(E);
  936. end;
  937. else
  938. Target := @Self;
  939. Ch := GetAltChar(E.KeyCode);
  940. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  941. P := Target^.FindItem(Ch);
  942. if P = nil then
  943. begin
  944. P := TopMenu^.HotKey(E.KeyCode);
  945. if (P <> nil) and CommandEnabled(P^.Command) then
  946. begin
  947. Result := P^.Command;
  948. Action := DoReturn;
  949. end
  950. end else
  951. if Target = @Self then
  952. begin
  953. if Size.Y = 1 then AutoSelect := True;
  954. Action := DoSelect;
  955. Current := P;
  956. end else
  957. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  958. Action := DoReturn;
  959. end;
  960. evCommand:
  961. if E.Command = cmMenu then
  962. begin
  963. AutoSelect := False;
  964. if ParentMenu <> nil then Action := DoReturn;
  965. end else Action := DoReturn;
  966. end;
  967. if ItemShown <> Current then
  968. begin
  969. ItemShown := Current;
  970. DrawView;
  971. end;
  972. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  973. if Current <> nil then with Current^ do if Name <> nil then
  974. if Command = 0 then
  975. begin
  976. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  977. GetItemRect(Current, R);
  978. R.A.X := R.A.X + Origin.X;
  979. R.A.Y := R.B.Y + Origin.Y;
  980. R.B := Owner^.Size;
  981. if Size.Y = 1 then Dec(R.A.X);
  982. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  983. Result := Owner^.ExecView(Target);
  984. Dispose(Target, Done);
  985. end else if Action = DoSelect then Result := Command;
  986. if (Result <> 0) and CommandEnabled(Result) then
  987. begin
  988. Action := DoReturn;
  989. ClearEvent(E);
  990. end
  991. else
  992. Result := 0;
  993. until Action = DoReturn;
  994. end;
  995. if E.What <> evNothing then
  996. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  997. if Current <> nil then
  998. begin
  999. Menu^.Default := Current;
  1000. Current := nil;
  1001. DrawView;
  1002. end;
  1003. Execute := Result;
  1004. end;
  1005. procedure TAdvancedStaticText.SetText(S: string);
  1006. begin
  1007. if Text<>nil then DisposeStr(Text);
  1008. Text:=NewStr(S);
  1009. DrawView;
  1010. end;
  1011. procedure TAdvancedListBox.FocusItem(Item: sw_integer);
  1012. var OFocused: sw_integer;
  1013. begin
  1014. OFocused:=Focused;
  1015. inherited FocusItem(Item);
  1016. if Focused<>OFocused then
  1017. Message(Owner,evBroadcast,cmListFocusChanged,@Self);
  1018. end;
  1019. procedure TAdvancedListBox.HandleEvent(var Event: TEvent);
  1020. begin
  1021. case Event.What of
  1022. evMouseDown :
  1023. if MouseInView(Event.Where) and (Event.Double) then
  1024. begin
  1025. inherited HandleEvent(Event);
  1026. if Range>Focused then SelectItem(Focused);
  1027. end;
  1028. evBroadcast :
  1029. case Event.Command of
  1030. cmListItemSelected :
  1031. Message(Owner,evBroadcast,cmDefault,nil);
  1032. end;
  1033. end;
  1034. inherited HandleEvent(Event);
  1035. end;
  1036. constructor TColorStaticText.Init(var Bounds: TRect; AText: String; AColor: word);
  1037. begin
  1038. inherited Init(Bounds,AText);
  1039. Color:=AColor;
  1040. end;
  1041. procedure TColorStaticText.Draw;
  1042. procedure MoveColorTxt(var b;const curs:string;c:word);
  1043. var
  1044. p : ^word;
  1045. i : sw_integer;
  1046. col : byte;
  1047. tilde : boolean;
  1048. begin
  1049. tilde:=false;
  1050. col:=lo(c);
  1051. p:=@b;
  1052. i:=0;
  1053. while (i<length(Curs)) do
  1054. begin
  1055. Inc(i);
  1056. case CurS[i] of
  1057. #1 :
  1058. begin
  1059. Inc(i);
  1060. Col:=ord(curS[i]);
  1061. end;
  1062. #2 :
  1063. begin
  1064. if tilde then
  1065. col:=hi(Color)
  1066. else
  1067. col:=lo(Color)
  1068. end;
  1069. '~' :
  1070. begin
  1071. tilde:=not tilde;
  1072. if tilde then
  1073. col:=hi(Color)
  1074. else
  1075. col:=lo(Color)
  1076. end;
  1077. else
  1078. begin
  1079. p^:=(col shl 8) or ord(curs[i]);
  1080. inc(p);
  1081. end;
  1082. end;
  1083. end;
  1084. end;
  1085. var
  1086. C: word;
  1087. Center: Boolean;
  1088. I, J, L, P, Y: Sw_Integer;
  1089. B: TDrawBuffer;
  1090. S: String;
  1091. T: string;
  1092. CurS: string;
  1093. TildeCount,Po: Sw_integer;
  1094. TempS: string;
  1095. begin
  1096. if Size.X=0 then Exit;
  1097. if DontWrap=false then
  1098. begin
  1099. C:=Color;
  1100. GetText(S);
  1101. L := Length(S);
  1102. P := 1;
  1103. Y := 0;
  1104. Center := False;
  1105. while Y < Size.Y do
  1106. begin
  1107. MoveChar(B, ' ', Lo(C), Size.X);
  1108. if P <= L then
  1109. begin
  1110. if S[P] = #3 then
  1111. begin
  1112. Center := True;
  1113. Inc(P);
  1114. end;
  1115. I := P;
  1116. repeat
  1117. J := P;
  1118. while (P <= L) and (S[P] = ' ') do Inc(P);
  1119. while (P <= L) and (S[P] <> ' ') and (S[P] <> #13) do Inc(P);
  1120. until (P > L) or (P >= I + Size.X) or (S[P] = #13);
  1121. TildeCount:=0; TempS:=copy(S,I,P-I);
  1122. repeat
  1123. Po:=Pos('~',TempS);
  1124. if Po>0 then begin Inc(TildeCount); Delete(TempS,1,Po); end;
  1125. until Po=0;
  1126. if P > I + Size.X + TildeCount then
  1127. if J > I then P := J else P := I + Size.X;
  1128. T:=copy(S,I,P-I);
  1129. if Center then J := (Size.X - {P + I}CStrLen(T)) div 2 else J := 0;
  1130. MoveColorTxt(B[J],T,C);
  1131. while (P <= L) and (S[P] = ' ') do Inc(P);
  1132. if (P <= L) and (S[P] = #13) then
  1133. begin
  1134. Center := False;
  1135. Inc(P);
  1136. if (P <= L) and (S[P] = #10) then Inc(P);
  1137. end;
  1138. end;
  1139. WriteLine(0, Y, Size.X, 1, B);
  1140. Inc(Y);
  1141. end;
  1142. end { Wrap=false } else
  1143. begin
  1144. C := Color;
  1145. GetText(S);
  1146. I:=1;
  1147. for Y:=0 to Size.Y-1 do
  1148. begin
  1149. MoveChar(B, ' ', Lo(C), Size.X);
  1150. CurS:='';
  1151. if S<>'' then
  1152. begin
  1153. P:=Pos(#13,S);
  1154. if P=0 then P:=length(S)+1;
  1155. CurS:=copy(S,1,P-1);
  1156. CurS:=copy(CurS,Delta.X+1,255);
  1157. CurS:=copy(CurS,1,MaxViewWidth);
  1158. Delete(S,1,P);
  1159. end;
  1160. if CurS<>'' then
  1161. MoveColorTxt(B,CurS,C);
  1162. WriteLine(0,Y,Size.X,1,B);
  1163. end;
  1164. end;
  1165. end;
  1166. constructor TColorStaticText.Load(var S: TStream);
  1167. begin
  1168. inherited Load(S);
  1169. S.Read(Color,SizeOf(Color));
  1170. S.Read(DontWrap,SizeOf(DontWrap));
  1171. S.Read(Delta,SizeOf(Delta));
  1172. end;
  1173. procedure TColorStaticText.Store(var S: TStream);
  1174. begin
  1175. inherited Store(S);
  1176. S.Write(Color,SizeOf(Color));
  1177. S.Write(DontWrap,SizeOf(DontWrap));
  1178. S.Write(Delta,SizeOf(Delta));
  1179. end;
  1180. constructor THSListBox.Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  1181. begin
  1182. inherited Init(Bounds,ANumCols,AVScrollBar);
  1183. HScrollBar:=AHScrollBar;
  1184. end;
  1185. constructor TDlgWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Sw_Integer);
  1186. begin
  1187. inherited Init(Bounds,ATitle);
  1188. Number:=ANumber;
  1189. Flags:=Flags or (wfMove + wfGrow + wfClose + wfZoom);
  1190. end;
  1191. procedure TLocalMenuListBox.LocalMenu(P: TPoint);
  1192. var M: PMenu;
  1193. MV: PAdvancedMenuPopUp;
  1194. R: TRect;
  1195. Re: word;
  1196. begin
  1197. M:=GetLocalMenu;
  1198. if M=nil then Exit;
  1199. if LastLocalCmd<>0 then
  1200. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  1201. Desktop^.GetExtent(R);
  1202. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  1203. New(MV, Init(R, M));
  1204. Re:=Application^.ExecView(MV);
  1205. if M^.Default=nil then LastLocalCmd:=0
  1206. else LastLocalCmd:=M^.Default^.Command;
  1207. Dispose(MV, Done);
  1208. if Re<>0 then
  1209. Message(GetCommandTarget,evCommand,Re,@Self);
  1210. end;
  1211. function TLocalMenuListBox.GetLocalMenu: PMenu;
  1212. begin
  1213. GetLocalMenu:=nil;
  1214. { Abstract;}
  1215. end;
  1216. function TLocalMenuListBox.GetCommandTarget: PView;
  1217. begin
  1218. GetCommandTarget:=@Self;
  1219. end;
  1220. procedure TLocalMenuListBox.HandleEvent(var Event: TEvent);
  1221. var DontClear: boolean;
  1222. P: TPoint;
  1223. begin
  1224. case Event.What of
  1225. evMouseDown :
  1226. if MouseInView(Event.Where) and (Event.Buttons=mbRightButton) then
  1227. begin
  1228. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  1229. LocalMenu(P);
  1230. ClearEvent(Event);
  1231. end;
  1232. evKeyDown :
  1233. begin
  1234. DontClear:=false;
  1235. case Event.KeyCode of
  1236. kbAltF10 : Message(@Self,evCommand,cmLocalMenu,@Self);
  1237. else DontClear:=true;
  1238. end;
  1239. if DontClear=false then ClearEvent(Event);
  1240. end;
  1241. evCommand :
  1242. begin
  1243. DontClear:=false;
  1244. case Event.Command of
  1245. cmLocalMenu :
  1246. begin
  1247. P:=Cursor; Inc(P.X); Inc(P.Y);
  1248. LocalMenu(P);
  1249. end;
  1250. else DontClear:=true;
  1251. end;
  1252. if not DontClear then ClearEvent(Event);
  1253. end;
  1254. end;
  1255. inherited HandleEvent(Event);
  1256. end;
  1257. function TAdvancedStatusLine.GetStatusText: string;
  1258. var S: string;
  1259. begin
  1260. if StatusText=nil then S:='' else S:=StatusText^;
  1261. GetStatusText:=S;
  1262. end;
  1263. procedure TAdvancedStatusLine.SetStatusText(const S: string);
  1264. begin
  1265. if StatusText<>nil then DisposeStr(StatusText);
  1266. StatusText:=NewStr(S);
  1267. DrawView;
  1268. end;
  1269. procedure TAdvancedStatusLine.ClearStatusText;
  1270. begin
  1271. SetStatusText('');
  1272. end;
  1273. procedure TAdvancedStatusLine.Draw;
  1274. var B: TDrawBuffer;
  1275. C: word;
  1276. S: string;
  1277. begin
  1278. S:=GetStatusText;
  1279. if S='' then inherited Draw else
  1280. begin
  1281. C:=GetColor(1);
  1282. MoveChar(B,' ',C,Size.X);
  1283. MoveStr(B[1],S,C);
  1284. WriteLine(0,0,Size.X,Size.Y,B);
  1285. end;
  1286. end;
  1287. procedure Bug(const S: string; Params: pointer);
  1288. begin
  1289. ErrorBox('Bug check failed: '+S+#13+'Please report to author!',Params);
  1290. end;
  1291. procedure ErrorBox(const S: string; Params: pointer);
  1292. begin
  1293. MessageBox(S,Params,mfError+mfInsertInApp+mfOKButton);
  1294. end;
  1295. procedure WarningBox(const S: string; Params: pointer);
  1296. begin
  1297. MessageBox(S,Params,mfWarning+mfInsertInApp+mfOKButton);
  1298. end;
  1299. procedure InformationBox(const S: string; Params: pointer);
  1300. begin
  1301. MessageBox(S,Params,mfInformation+mfInsertInApp+mfOKButton);
  1302. end;
  1303. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  1304. begin
  1305. ConfirmBox:=MessageBox(S,Params,mfConfirmation+mfInsertInApp+mfYesButton+mfNoButton+integer(CanCancel)*mfCancelButton);
  1306. end;
  1307. function IsSeparator(P: PMenuItem): boolean;
  1308. begin
  1309. IsSeparator:=(P<>nil) and (P^.Name=nil) and (P^.HelpCtx=hcNoContext);
  1310. end;
  1311. function IsSubMenu(P: PMenuItem): boolean;
  1312. begin
  1313. IsSubMenu:=(P<>nil) and (P^.Name<>nil) and (P^.Command=0) and (P^.SubMenu<>nil);
  1314. end;
  1315. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  1316. var P,I: PMenuItem;
  1317. begin
  1318. I:=nil;
  1319. if Menu=nil then P:=nil else P:=Menu^.Items;
  1320. while (P<>nil) and (I=nil) do
  1321. begin
  1322. if IsSubMenu(P) then
  1323. I:=SearchMenuItem(P^.SubMenu,Cmd);
  1324. if I=nil then
  1325. if P^.Command=Cmd then I:=P else
  1326. P:=P^.Next;
  1327. end;
  1328. SearchMenuItem:=I;
  1329. end;
  1330. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  1331. begin
  1332. if Menu=nil then Exit;
  1333. if Menu^.Param<>nil then DisposeStr(Menu^.Param);
  1334. Menu^.Param:=NewStr(Param);
  1335. end;
  1336. function UpdateMenu(M: PMenu): boolean;
  1337. var P: PMenuItem;
  1338. IsEnabled: boolean;
  1339. begin
  1340. if M=nil then begin UpdateMenu:=false; Exit; end;
  1341. P:=M^.Items; IsEnabled:=false;
  1342. while (P<>nil) do
  1343. begin
  1344. if IsSubMenu(P) then
  1345. P^.Disabled:=not UpdateMenu(P^.SubMenu);
  1346. if (IsSeparator(P)=false) and (P^.Disabled=false) and (Application^.CommandEnabled(P^.Command)=true) then
  1347. IsEnabled:=true;
  1348. P:=P^.Next;
  1349. end;
  1350. UpdateMenu:=IsEnabled;
  1351. end;
  1352. function SearchSubMenu(M: PMenu; Index: Sw_integer): PMenuItem;
  1353. var P,C: PMenuItem;
  1354. Count: Sw_integer;
  1355. begin
  1356. P:=nil; Count:=-1;
  1357. if M<>nil then C:=M^.Items else C:=nil;
  1358. while (C<>nil) and (P=nil) do
  1359. begin
  1360. if IsSubMenu(C) then
  1361. begin
  1362. Inc(Count);
  1363. if Count=Index then P:=C;
  1364. end;
  1365. C:=C^.Next;
  1366. end;
  1367. SearchSubMenu:=P;
  1368. end;
  1369. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  1370. var P: PMenuItem;
  1371. begin
  1372. if (M=nil) or (I=nil) then Exit;
  1373. I^.Next:=nil;
  1374. if M^.Items=nil then M^.Items:=I else
  1375. begin
  1376. P:=M^.Items;
  1377. while (P^.Next<>nil) do P:=P^.Next;
  1378. P^.Next:=I;
  1379. end;
  1380. end;
  1381. procedure DisposeMenuItem(P: PMenuItem);
  1382. begin
  1383. if P<>nil then
  1384. begin
  1385. if IsSubMenu(P) then DisposeMenu(P^.SubMenu) else
  1386. if IsSeparator(P)=false then
  1387. if P^.Param<>nil then DisposeStr(P^.Param);
  1388. if P^.Name<>nil then DisposeStr(P^.Name);
  1389. Dispose(P);
  1390. end;
  1391. end;
  1392. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  1393. var P,PrevP: PMenuItem;
  1394. begin
  1395. if (Menu=nil) or (I=nil) then Exit;
  1396. P:=Menu^.Items; PrevP:=nil;
  1397. while (P<>nil) do
  1398. begin
  1399. if P=I then
  1400. begin
  1401. if Menu^.Items<>I then PrevP^.Next:=P^.Next
  1402. else Menu^.Items:=P^.Next;
  1403. DisposeMenuItem(P);
  1404. Break;
  1405. end;
  1406. PrevP:=P; P:=P^.Next;
  1407. end;
  1408. end;
  1409. function GetMenuItemBefore(Menu: PMenu; BeforeOf: PMenuItem): PMenuItem;
  1410. var P,C: PMenuItem;
  1411. begin
  1412. P:=nil;
  1413. if Menu<>nil then C:=Menu^.Items else C:=nil;
  1414. while (C<>nil) do
  1415. begin
  1416. if C^.Next=BeforeOf then begin P:=C; Break; end;
  1417. C:=C^.Next;
  1418. end;
  1419. GetMenuItemBefore:=P;
  1420. end;
  1421. procedure NotImplemented;
  1422. begin
  1423. InformationBox( #3'This function is not'#13+
  1424. #3+'yet implemented...'#13+
  1425. #3+'Sorry',nil);
  1426. end;
  1427. procedure InsertButtons(ADialog: PDialog);
  1428. var R : TRect;
  1429. W,H : Sw_integer;
  1430. X : Sw_integer;
  1431. X1,X2: Sw_integer;
  1432. begin
  1433. with ADialog^ do
  1434. begin
  1435. GetExtent(R);
  1436. W:=R.B.X-R.A.X; H:=(R.B.Y-R.A.Y);
  1437. R.Assign(0,0,W,H+3); ChangeBounds(R);
  1438. X:=W div 2; X1:=X div 2+1; X2:=X+X1-1;
  1439. R.Assign(X1-3,H,X1+7,H+2);
  1440. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfDefault)));
  1441. R.Assign(X2-7,H,X2+3,H+2);
  1442. Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  1443. SelectNext(true);
  1444. end;
  1445. end;
  1446. procedure InsertOK(ADialog: PDialog);
  1447. var BW: Sw_integer;
  1448. R: TRect;
  1449. begin
  1450. with ADialog^ do
  1451. begin
  1452. GetBounds(R); R.Grow(0,1); Inc(R.B.Y);
  1453. ChangeBounds(R);
  1454. BW:=10;
  1455. R.A.Y:=R.B.Y-2; R.B.Y:=R.A.Y+2;
  1456. R.A.X:=R.A.X+(R.B.X-R.A.X-BW) div 2; R.B.X:=R.A.X+BW;
  1457. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfDefault)));
  1458. SelectNext(true);
  1459. end;
  1460. end;
  1461. procedure ShowMessage(Msg: string);
  1462. var R: TRect;
  1463. Width: Sw_integer;
  1464. begin
  1465. Width:=length(Msg)+4*2;
  1466. if Width<(Desktop^.Size.X div 2) then Width:=(Desktop^.Size.X div 2);
  1467. R.Assign(0,0,Width,5);
  1468. New(MessageDialog, Init(R, ''));
  1469. with MessageDialog^ do
  1470. begin
  1471. Flags:=0;
  1472. GetExtent(R); R.Grow(-4,-2);
  1473. if copy(Msg,1,1)<>^C then Msg:=^C+Msg;
  1474. Insert(New(PStaticText, Init(R, Msg)));
  1475. end;
  1476. Application^.Insert(MessageDialog);
  1477. end;
  1478. procedure HideMessage;
  1479. begin
  1480. if MessageDialog<>nil then
  1481. begin
  1482. Application^.Delete(MessageDialog);
  1483. Dispose(MessageDialog, Done);
  1484. MessageDialog:=nil;
  1485. end;
  1486. end;
  1487. constructor TDDHelperLB.Init(ALink: PDropDownListBox; var Bounds: TRect; ANumCols: Word; AScrollBar: PScrollBar);
  1488. begin
  1489. inherited Init(Bounds,ANumCols,AScrollBar);
  1490. EventMask:=EventMask or (evMouseMove+evIdle);
  1491. { Options:=Options or ofPreProcess;}
  1492. Link:=ALink;
  1493. end;
  1494. procedure TDDHelperLB.SetState(AState: Word; Enable: Boolean);
  1495. var OState: longint;
  1496. begin
  1497. OState:=State;
  1498. inherited SetState(AState,Enable);
  1499. { if (((State xor OState) and sfFocused)<>0) and (GetState(sfFocused)=false) then
  1500. Link^.DropList(false);}
  1501. end;
  1502. function TDDHelperLB.GetText(Item,MaxLen: Sw_Integer): String;
  1503. var P: pointer;
  1504. S: string;
  1505. begin
  1506. P:=List^.At(Item);
  1507. if Link=nil then S:='' else
  1508. S:=Link^.GetText(P,MaxLen);
  1509. GetText:=S;
  1510. end;
  1511. function TDDHelperLB.GetLocalMenu: PMenu;
  1512. begin
  1513. GetLocalMenu:=Link^.LBGetLocalMenu;
  1514. end;
  1515. function TDDHelperLB.GetCommandTarget: PView;
  1516. begin
  1517. GetCommandTarget:=Link^.LBGetCommandTarget;
  1518. end;
  1519. procedure TDDHelperLB.HandleEvent(var Event: TEvent);
  1520. const
  1521. MouseAutosToSkip = 4;
  1522. var
  1523. Mouse : TPoint;
  1524. OldItem, NewItem : Sw_Integer;
  1525. ColWidth,Count : Sw_Word;
  1526. GoSelectItem: sw_integer;
  1527. MouseWhere: TPoint;
  1528. begin
  1529. GoSelectItem:=-1;
  1530. TView.HandleEvent(Event);
  1531. case Event.What of
  1532. evMouseDown :
  1533. if MouseInView(Event.Where)=false then
  1534. GoSelectItem:=-2
  1535. else
  1536. begin
  1537. ColWidth := Size.X div NumCols + 1;
  1538. OldItem := Focused;
  1539. MakeLocal(Event.Where, Mouse);
  1540. if MouseInView(Event.Where) then
  1541. NewItem := Mouse.Y + (Size.Y * (Mouse.X div ColWidth)) + TopItem
  1542. else
  1543. NewItem := OldItem;
  1544. Count := 0;
  1545. repeat
  1546. if NewItem <> OldItem then
  1547. begin
  1548. FocusItemNum(NewItem);
  1549. DrawView;
  1550. end;
  1551. OldItem := NewItem;
  1552. MakeLocal(Event.Where, Mouse);
  1553. if MouseInView(Event.Where) then
  1554. NewItem := Mouse.Y + (Size.Y * (Mouse.X div ColWidth)) + TopItem
  1555. else
  1556. begin
  1557. if NumCols = 1 then
  1558. begin
  1559. if Event.What = evMouseAuto then Inc(Count);
  1560. if Count = MouseAutosToSkip then
  1561. begin
  1562. Count := 0;
  1563. if Mouse.Y < 0 then NewItem := Focused-1
  1564. else if Mouse.Y >= Size.Y then NewItem := Focused+1;
  1565. end;
  1566. end
  1567. else
  1568. begin
  1569. if Event.What = evMouseAuto then Inc(Count);
  1570. if Count = MouseAutosToSkip then
  1571. begin
  1572. Count := 0;
  1573. if Mouse.X < 0 then NewItem := Focused-Size.Y
  1574. else if Mouse.X >= Size.X then NewItem := Focused+Size.Y
  1575. else if Mouse.Y < 0 then
  1576. NewItem := Focused - Focused mod Size.Y
  1577. else if Mouse.Y > Size.Y then
  1578. NewItem := Focused - Focused mod Size.Y + Size.Y - 1;
  1579. end
  1580. end;
  1581. end;
  1582. until not MouseEvent(Event, evMouseMove + evMouseAuto);
  1583. FocusItemNum(NewItem);
  1584. DrawView;
  1585. if Event.Double and (Range > Focused) then SelectItem(Focused);
  1586. ClearEvent(Event);
  1587. GoSelectItem:=Focused;
  1588. end;
  1589. evMouseMove,evMouseAuto:
  1590. if GetState(sfFocused) then
  1591. if MouseInView(Event.Where) then
  1592. begin
  1593. MakeLocal(Event.Where,Mouse);
  1594. FocusItemNum(TopItem+Mouse.Y);
  1595. ClearEvent(Event);
  1596. end;
  1597. evKeyDown :
  1598. begin
  1599. if (Event.KeyCode=kbEsc) then
  1600. begin
  1601. GoSelectItem:=-2;
  1602. ClearEvent(Event);
  1603. end else
  1604. if (Event.CharCode = ' ') and (Focused < Range) then
  1605. begin
  1606. GoSelectItem:=Focused;
  1607. NewItem := Focused;
  1608. end
  1609. else
  1610. case CtrlToArrow(Event.KeyCode) of
  1611. kbUp : NewItem := Focused - 1;
  1612. kbDown : NewItem := Focused + 1;
  1613. kbRight: if NumCols > 1 then NewItem := Focused + Size.Y else Exit;
  1614. kbLeft : if NumCols > 1 then NewItem := Focused - Size.Y else Exit;
  1615. kbPgDn : NewItem := Focused + Size.Y * NumCols;
  1616. kbPgUp : NewItem := Focused - Size.Y * NumCols;
  1617. kbHome : NewItem := TopItem;
  1618. kbEnd : NewItem := TopItem + (Size.Y * NumCols) - 1;
  1619. kbCtrlPgDn: NewItem := Range - 1;
  1620. kbCtrlPgUp: NewItem := 0;
  1621. else
  1622. Exit;
  1623. end;
  1624. FocusItemNum(NewItem);
  1625. DrawView;
  1626. ClearEvent(Event);
  1627. end;
  1628. evBroadcast :
  1629. case Event.Command of
  1630. cmReceivedFocus :
  1631. if (Event.InfoPtr<>@Self) and (InClose=false) then
  1632. begin
  1633. GoSelectItem:=-2;
  1634. end;
  1635. else
  1636. if Options and ofSelectable <> 0 then
  1637. if (Event.Command = cmScrollBarClicked) and
  1638. ((Event.InfoPtr = HScrollBar) or (Event.InfoPtr = VScrollBar)) then
  1639. Select
  1640. else
  1641. if (Event.Command = cmScrollBarChanged) then
  1642. begin
  1643. if (VScrollBar = Event.InfoPtr) then
  1644. begin
  1645. FocusItemNum(VScrollBar^.Value);
  1646. DrawView;
  1647. end
  1648. else
  1649. if (HScrollBar = Event.InfoPtr) then
  1650. DrawView;
  1651. end;
  1652. end;
  1653. evIdle :
  1654. begin
  1655. MouseWhere.X:=MouseWhereX shr 3; MouseWhere.Y:=MouseWhereY shr 3;
  1656. if MouseInView(MouseWhere)=false then
  1657. if abs(GetDosTicks-LastTT)>=1 then
  1658. begin
  1659. LastTT:=GetDosTicks;
  1660. MakeLocal(MouseWhere,Mouse);
  1661. if ((Mouse.Y<-1) or (Mouse.Y>=Size.Y)) and
  1662. ((0<=Mouse.X) and (Mouse.X<Size.X)) then
  1663. if Range>0 then
  1664. if Mouse.Y<0 then
  1665. FocusItemNum(Focused-(0-Mouse.Y))
  1666. else
  1667. FocusItemNum(Focused+(Mouse.Y-(Size.Y-1)));
  1668. end;
  1669. end;
  1670. end;
  1671. if (Range>0) and (GoSelectItem<>-1) then
  1672. begin
  1673. InClose:=true;
  1674. if GoSelectItem=-2 then
  1675. Link^.DropList(false)
  1676. else
  1677. SelectItem(GoSelectItem);
  1678. end;
  1679. end;
  1680. procedure TDDHelperLB.SelectItem(Item: Sw_Integer);
  1681. begin
  1682. inherited SelectItem(Item);
  1683. Link^.FocusItem(Focused);
  1684. Link^.DropList(false);
  1685. end;
  1686. constructor TDropDownListBox.Init(var Bounds: TRect; ADropLineCount: Sw_integer; AList: PCollection);
  1687. begin
  1688. inherited Init(Bounds);
  1689. Options:=Options or (ofSelectable);
  1690. EventMask:=EventMask or (evBroadcast);
  1691. DropLineCount:=ADropLineCount;
  1692. NewList(AList);
  1693. end;
  1694. procedure TDropDownListBox.HandleEvent(var Event: TEvent);
  1695. var DontClear: boolean;
  1696. Count: sw_integer;
  1697. begin
  1698. case Event.What of
  1699. evKeyDown :
  1700. if GetState(sfFocused) then
  1701. begin
  1702. DontClear:=false;
  1703. Count:=GetItemCount;
  1704. if Count>0 then
  1705. case Event.KeyCode of
  1706. kbUp :
  1707. if Focused>0 then
  1708. FocusItem(Focused-1);
  1709. kbDown :
  1710. if Focused<Count-1 then
  1711. FocusItem(Focused+1);
  1712. kbHome :
  1713. FocusItem(0);
  1714. kbEnd :
  1715. FocusItem(Count-1);
  1716. kbPgDn :
  1717. DropList(true);
  1718. else DontClear:=true;
  1719. end;
  1720. if DontClear=false then ClearEvent(Event);
  1721. end;
  1722. evBroadcast :
  1723. case Event.Command of
  1724. { cmReleasedFocus :
  1725. if (ListBox<>nil) and (Event.InfoPtr=ListBox) then
  1726. DropList(false);}
  1727. cmListItemSelected :
  1728. if (ListBox<>nil) and (Event.InfoPtr=ListBox) then
  1729. begin
  1730. FocusItem(ListBox^.Focused);
  1731. Text:=GetText(List^.At(Focused),255);
  1732. DrawView;
  1733. DropList(false);
  1734. end;
  1735. end;
  1736. evMouseDown :
  1737. if MouseInView(Event.Where) then
  1738. begin
  1739. DropList(not ListDropped);
  1740. ClearEvent(Event);
  1741. end;
  1742. end;
  1743. inherited HandleEvent(Event);
  1744. end;
  1745. function TDropDownListBox.GetText(Item: pointer; MaxLen: Sw_integer): string;
  1746. var S: string;
  1747. begin
  1748. S:=GetStr(Item);
  1749. GetText:=copy(S,1,MaxLen);
  1750. end;
  1751. procedure TDropDownListBox.NewList(AList: PCollection);
  1752. begin
  1753. if List<>nil then Dispose(List, Done); List:=nil;
  1754. List:=AList; FocusItem(0);
  1755. end;
  1756. procedure TDropDownListBox.CreateListBox(var R: TRect);
  1757. var R2: TRect;
  1758. begin
  1759. R2.Copy(R); R2.A.X:=R2.B.X-1;
  1760. New(SB, Init(R2));
  1761. Dec(R.B.X);
  1762. New(ListBox, Init(@Self,R,1,SB));
  1763. end;
  1764. procedure TDropDownListBox.DropList(Drop: boolean);
  1765. var R: TRect;
  1766. begin
  1767. if ListDropped=Drop then Exit;
  1768. if Drop then
  1769. begin
  1770. R.Assign(Origin.X+1,Origin.Y+Size.Y,Origin.X+Size.X,Origin.Y+Size.Y+DropLineCount);
  1771. if Owner<>nil then Owner^.Lock;
  1772. CreateListBox(R);
  1773. if SB<>nil then
  1774. Owner^.Insert(SB);
  1775. if ListBox<>nil then
  1776. begin
  1777. ListBox^.NewList(List);
  1778. ListBox^.FocusItem(Focused);
  1779. Owner^.Insert(ListBox);
  1780. end;
  1781. if Owner<>nil then Owner^.UnLock;
  1782. end
  1783. else
  1784. begin
  1785. if Owner<>nil then Owner^.Lock;
  1786. if ListBox<>nil then
  1787. begin
  1788. { ListBox^.List:=nil;}
  1789. Dispose(ListBox, Done);
  1790. ListBox:=nil;
  1791. end;
  1792. if SB<>nil then
  1793. begin
  1794. Dispose(SB, Done);
  1795. SB:=nil;
  1796. end;
  1797. Select;
  1798. if Owner<>nil then Owner^.UnLock;
  1799. end;
  1800. ListDropped:=Drop;
  1801. DrawView;
  1802. end;
  1803. function TDropDownListBox.GetItemCount: sw_integer;
  1804. var Count: sw_integer;
  1805. begin
  1806. if assigned(List)=false then Count:=0 else
  1807. Count:=List^.Count;
  1808. GetItemCount:=Count;
  1809. end;
  1810. procedure TDropDownListBox.FocusItem(Item: sw_integer);
  1811. var P: pointer;
  1812. begin
  1813. Focused:=Item;
  1814. if assigned(ListBox) and (Item>=0) then
  1815. ListBox^.FocusItem(Item);
  1816. if (GetItemCount>0) and (Focused>=0) then
  1817. begin
  1818. P:=List^.At(Focused);
  1819. Text:=GetText(P,Size.X-4);
  1820. end;
  1821. DrawView;
  1822. end;
  1823. function TDropDownListBox.LBGetLocalMenu: PMenu;
  1824. begin
  1825. LBGetLocalMenu:=nil;
  1826. end;
  1827. function TDropDownListBox.LBGetCommandTarget: PView;
  1828. begin
  1829. LBGetCommandTarget:=@Self;
  1830. end;
  1831. procedure TDropDownListBox.SetState(AState: Word; Enable: Boolean);
  1832. begin
  1833. inherited SetState(AState,Enable);
  1834. if (AState and (sfSelected + sfActive + sfFocused)) <> 0 then DrawView;
  1835. end;
  1836. procedure TDropDownListBox.Draw;
  1837. var B: TDrawBuffer;
  1838. C,TextC: word;
  1839. LC: char;
  1840. begin
  1841. if GetState(sfFocused)=false then
  1842. begin
  1843. C:=GetColor(2);
  1844. TextC:=GetColor(2);
  1845. end
  1846. else
  1847. begin
  1848. C:=GetColor(3);
  1849. TextC:=GetColor(3);
  1850. end;
  1851. MoveChar(B,' ',C,Size.X);
  1852. MoveStr(B[1],copy(Text,1,Size.X-2),TextC);
  1853. if ListDropped then LC:=#30 else LC:=#31;
  1854. MoveChar(B[Size.X-2],LC,C,1);
  1855. WriteLine(0,0,Size.X,Size.Y,B);
  1856. end;
  1857. function TDropDownListBox.GetPalette: PPalette;
  1858. const P: string[length(CListViewer)] = CListViewer;
  1859. begin
  1860. GetPalette:=@P;
  1861. end;
  1862. destructor TDropDownListBox.Done;
  1863. begin
  1864. if ListDropped then DropList(false);
  1865. inherited Done;
  1866. end;
  1867. constructor TGroupView.Init(var Bounds: TRect; AText: String; ALink: PView);
  1868. begin
  1869. inherited Init(Bounds,AText,ALink);
  1870. end;
  1871. procedure TGroupView.Draw;
  1872. var B: TDrawBuffer;
  1873. FrameC,LabelC: word;
  1874. begin
  1875. FrameC:=GetColor(1);
  1876. if Light then
  1877. LabelC:=GetColor(2)+GetColor(4) shl 8
  1878. else
  1879. LabelC:=GetColor(1)+GetColor(3) shl 8;
  1880. { First Line }
  1881. MoveChar(B[0],'Ú',FrameC,1);
  1882. MoveChar(B[1],'Ä',FrameC,Size.X-2);
  1883. MoveChar(B[Size.X-1],'¿',FrameC,1);
  1884. if Text<>nil then
  1885. begin
  1886. MoveCStr(B[1],' '+Text^+' ',LabelC);
  1887. end;
  1888. WriteLine(0,0,Size.X,1,B);
  1889. { Mid Lines }
  1890. MoveChar(B[0],'³',FrameC,1);
  1891. MoveChar(B[1],' ',FrameC,Size.X-2);
  1892. MoveChar(B[Size.X-1],'³',FrameC,1);
  1893. WriteLine(0,1,Size.X,Size.Y-2,B);
  1894. { Last Line }
  1895. MoveChar(B[0],'À',FrameC,1);
  1896. MoveChar(B[1],'Ä',FrameC,Size.X-2);
  1897. MoveChar(B[Size.X-1],'Ù',FrameC,1);
  1898. WriteLine(0,Size.Y-1,Size.X,1,B);
  1899. end;
  1900. function TPlainCheckBoxes.GetPalette: PPalette;
  1901. const P: string[length(CPlainCluster)] = CPlainCluster;
  1902. begin
  1903. GetPalette:=@P;
  1904. end;
  1905. function TPlainRadioButtons.GetPalette: PPalette;
  1906. const P: string[length(CPlainCluster)] = CPlainCluster;
  1907. begin
  1908. GetPalette:=@P;
  1909. end;
  1910. constructor TAdvancedListBox.Load(var S: TStream);
  1911. begin
  1912. inherited Load(S);
  1913. S.Read(Default,SizeOf(Default));
  1914. end;
  1915. procedure TAdvancedListBox.Store(var S: TStream);
  1916. begin
  1917. inherited Store(S);
  1918. S.Write(Default,SizeOf(Default));
  1919. end;
  1920. procedure RegisterWViews;
  1921. begin
  1922. {$ifndef NOOBJREG}
  1923. RegisterType(RAdvancedListBox);
  1924. RegisterType(RColorStaticText);
  1925. RegisterType(RHSListBox);
  1926. RegisterType(RDlgWindow);
  1927. {$endif}
  1928. end;
  1929. END.
  1930. {
  1931. $Log$
  1932. Revision 1.11 2000-01-10 15:53:37 pierre
  1933. * WViews objects were not registered
  1934. Revision 1.10 1999/08/03 20:22:46 peter
  1935. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  1936. + Desktop saving should work now
  1937. - History saved
  1938. - Clipboard content saved
  1939. - Desktop saved
  1940. - Symbol info saved
  1941. * syntax-highlight bug fixed, which compared special keywords case sensitive
  1942. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  1943. * with 'whole words only' set, the editor didn't found occourences of the
  1944. searched text, if the text appeared previously in the same line, but didn't
  1945. satisfied the 'whole-word' condition
  1946. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  1947. (ie. the beginning of the selection)
  1948. * when started typing in a new line, but not at the start (X=0) of it,
  1949. the editor inserted the text one character more to left as it should...
  1950. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  1951. * Shift shouldn't cause so much trouble in TCodeEditor now...
  1952. * Syntax highlight had problems recognizing a special symbol if it was
  1953. prefixed by another symbol character in the source text
  1954. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  1955. Revision 1.9 1999/06/28 19:32:37 peter
  1956. * fixes from gabor
  1957. Revision 1.8 1999/06/28 12:29:56 pierre
  1958. *GetMenuItem fixed
  1959. Revision 1.7 1999/06/25 00:30:34 pierre
  1960. + TAdvancedMenuBar.GetMenuItem(by command number)
  1961. Revision 1.6 1999/04/07 21:56:07 peter
  1962. + object support for browser
  1963. * html help fixes
  1964. * more desktop saving things
  1965. * NODEBUG directive to exclude debugger
  1966. Revision 1.5 1999/03/23 16:16:44 peter
  1967. * linux fixes
  1968. Revision 1.4 1999/03/23 15:11:42 peter
  1969. * desktop saving things
  1970. * vesa mode
  1971. * preferences dialog
  1972. Revision 1.3 1999/03/19 16:04:35 peter
  1973. * new compiler dialog
  1974. Revision 1.2 1999/03/08 14:58:23 peter
  1975. + prompt with dialogs for tools
  1976. Revision 1.1 1999/03/01 15:51:43 peter
  1977. + Log
  1978. }