wviews.pas 58 KB

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