You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KOLMHToolTip.pas 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. //{$DEFINE DEBUG}
  2. {$IFDEF DEBUG}
  3. {$DEFINE interface}
  4. {$DEFINE implementation}
  5. {$DEFINE initialization}
  6. {$DEFINE finalization}
  7. {$ENDIF}
  8. {$IFDEF Frame}
  9. unit KOLMHToolTip;
  10. interface
  11. uses Windows, KOL, Messages;
  12. type
  13. {$ENDIF Frame}
  14. {$IFDEF interface}
  15. TFE = (eTextColor, eBkColor, eAPDelay, eRDelay, eIDelay);
  16. TFI = record
  17. FE: set of TFE;
  18. Colors: array[0..1] of TColor;
  19. Delays: array[0..3] of Integer;
  20. end;
  21. PMHToolTipManager = ^TMHToolTipManager;
  22. TKOLMHToolTipManager = PMHToolTipManager;
  23. PMHToolTip = ^TMHToolTip;
  24. TKOLMHToolTip = PMHToolTip;
  25. {$ENDIF interface}
  26. {$IFDEF pre_interface}
  27. PMHHint = ^TMHHint;
  28. TKOLMHHint = PMHHint;
  29. {$ENDIF pre_interface}
  30. {$IFDEF interface}
  31. TMHToolTipManager = object(TObj)
  32. protected
  33. destructor Destroy; virtual;
  34. public
  35. TTT: array of PMHToolTip;
  36. function AddTip: Integer;
  37. function FindNeed(FI: TFI): PMHToolTip;
  38. function CreateNeed(FI: TFI): PMHToolTip;
  39. end;
  40. TMHHint = object(TObj)
  41. private
  42. function GetManager:PMHToolTipManager;
  43. // Spec
  44. procedure ProcBegin(var TI: TToolInfo);
  45. procedure ProcEnd(var TI: TToolInfo);
  46. procedure ReConnect(FI: TFI);
  47. procedure MoveTool(T1: PMHToolTip);
  48. procedure CreateToolTip;
  49. function GetFI: TFI;
  50. // Group
  51. function GetDelay(const Index: Integer): Integer;
  52. procedure SetDelay(const Index: Integer; const Value: Integer);
  53. function GetColor(const Index: Integer): TColor;
  54. procedure SetColor(const Index: Integer; const Value: TColor);
  55. // Local
  56. procedure SetText(Value: KOLString);
  57. function GetText: KOLString;
  58. public
  59. ToolTip: PMHToolTip;
  60. HasTool: Boolean;
  61. Parent: PControl;
  62. destructor Destroy; virtual;
  63. procedure Pop;
  64. procedure Popup;
  65. property AutoPopDelay: Integer index 2 read GetDelay write SetDelay;
  66. property InitialDelay: Integer index 3 read GetDelay write SetDelay;
  67. property ReshowDelay: Integer index 1 read GetDelay write SetDelay;
  68. property TextColor: TColor index 1 read GetColor write SetColor;
  69. property BkColor: TColor index 0 read GetColor write SetColor;
  70. property Text: KOLString read GetText write SetText;
  71. end;
  72. TMHToolTip = object(TObj)
  73. private
  74. fHandle: THandle;
  75. Count: Integer;
  76. function GetDelay(const Index: Integer): Integer;
  77. procedure SetDelay(const Index: Integer; const Value: Integer);
  78. function GetColor(const Index: Integer): TColor;
  79. procedure SetColor(const Index: Integer; const Value: TColor);
  80. function GetMaxWidth: Integer;
  81. procedure SetMaxWidth(const Value: Integer);
  82. function GetMargin: TRect;
  83. procedure SetMargin(const Value: TRect);
  84. function GetActivate: Boolean;
  85. procedure SetActivate(const Value: Boolean);
  86. // function GetText: string;
  87. // procedure SetText(const Value: string);
  88. // function GetToolCount: Integer;
  89. // function GetTool(Index: Integer): TToolInfo;
  90. protected
  91. public
  92. destructor Destroy; virtual;
  93. procedure Pop;
  94. procedure Popup;
  95. procedure Update;
  96. // function GetInfo: TToolInfo; // Hide in Info
  97. // procedure SetInfo(Value: TToolInfo);
  98. // handle:Thandle;
  99. // procedure SetC(C: PControl);
  100. // procedure SetI(C: PControl; S: string);
  101. // procedure Add(Value: TToolInfo);
  102. // procedure Delete(Value: TToolInfo);
  103. // function Connect(Value: PControl): Integer;
  104. // property OnCloseUp: TOnEvent read GetOnDropDown write SetOnDropDown;
  105. property AutoPopDelay: Integer index 2 read GetDelay write SetDelay;
  106. property InitialDelay: Integer index 3 read GetDelay write SetDelay;
  107. property ReshowDelay: Integer index 1 read GetDelay write SetDelay;
  108. property TextColor: TColor index 1 read GetColor write SetColor;
  109. property BkColor: TColor index 0 read GetColor write SetColor;
  110. property MaxWidth: Integer read GetMaxWidth write SetMaxWidth;
  111. property Margin: TRect read GetMargin write SetMargin;
  112. property Activate: Boolean read GetActivate write SetActivate;
  113. property Handle: THandle read fHandle;
  114. // property Text: string read GetText write SetText;
  115. // property ToolCount: Integer read GetToolCount;
  116. // property Tools[Index: Integer]: TToolInfo read GetTool;
  117. end;
  118. const
  119. Dummy = 0;
  120. function NewHint(A: PControl): PMHHint;
  121. function NewManager: PMHToolTipManager;
  122. function NewMHToolTip(AParent: PControl): PMHToolTip;
  123. var
  124. Manager: PMHToolTipManager;
  125. {$ENDIF interface}
  126. {$IFDEF Frame}
  127. implementation
  128. {$ENDIF Frame}
  129. {$IFDEF implementation}
  130. const
  131. Dummy1 = 1;
  132. TTDT_AUTOMATIC = 0;
  133. TTDT_RESHOW = 1;
  134. TTDT_AUTOPOP = 2;
  135. TTDT_INITIAL = 3;
  136. //function WndProcMHDateTimePicker(Sender: PControl; var Msg: TMsg; var Rslt: Integer): Boolean;
  137. {begin
  138. Result := False;}
  139. //end;
  140. function NewMHToolTip(AParent: PControl): PMHToolTip;
  141. //var
  142. // Data: PDateTimePickerData;
  143. // T: TWndClassEx;
  144. // a: integer;
  145. const
  146. CS_DROPSHADOW = $00020000;
  147. begin
  148. DoInitCommonControls(ICC_BAR_CLASSES);
  149. New(Result, Create);
  150. Result.fHandle := CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, '', 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, AParent.GetWindowHandle, 0, HInstance, nil);
  151. // SetClassLong(Result.handle,GCL_STYLE,CS_DROPSHADOW);
  152. // Result := PMHToolTip(_NewControl(AParent, TOOLTIPS_CLASS, 0, False, 0)); //PMHToolTip(_NewCommonControl(AParent,TOOLTIPS_CLASS, 0{TTS_ALWAYSTIP}{WS_CHILD or WS_VISIBLE},False,0));
  153. // Result.Style:=0;
  154. // Result.ExStyle:=0;
  155. // GetMem(Data,Sizeof(Data^));
  156. // FillChar(Data^,Sizeof(Data^),0);
  157. // a:=SetClassLong(Result.Handle,GCL_STYLE,CS_DROPSHADOW);
  158. // ShowMessage(Int2Str(a));
  159. // Result.CustomData:=Data;
  160. { T.cbSize:=SizeOf(T);
  161. GetClassInfoEx(hInstance,TOOLTIPS_CLASS,T);
  162. T.style:=T.style or CS_DROPSHADOW;
  163. T.hInstance:=hInstance;
  164. T.lpszClassName:='ZharovHint';
  165. a:=RegisterClassEx(T);
  166. ShowMessage(Int2Str(a)); }
  167. // Result.handle := CreateWindowEx(0, {'ZharovHint'} TOOLTIPS_CLASS, '', 0 {orCS_DROPSHADOW or WS_POPUP or WS_BORDER or CS_SAVEBITS or WS_CHILD or WS_CLIPSIBLINGS}, CW_USEDEFAULT, CW_USEDEFAULT,
  168. // CW_USEDEFAULT, CW_USEDEFAULT, AParent.Handle, 0, HInstance, nil);
  169. // Data.ttt:=CreateWindowEx (CS_IMEWS_EX_TOOLWINDOW or WS_EX_CONTROLPARENT{ or CS_SAVEBITS or WS_POPUP or WS_BORDER}{65536},{'ZharovHint'}TOOLTIPS_CLASS,'',{WS_CHILD or}{ WS_VISIBLE}{100663296}{WS_EX_TOOLWINDOW}CS_DROPSHADOW or WS_POPUP or WS_BORDER or CS_SAVEBITS or WS_CHILD or WS_CLIPSIBLINGS,CW_USEDEFAULT,CW_USEDEFAULT,
  170. // CW_USEDEFAULT,CW_USEDEFAULT,AParent.Handle,0,HInstance,NIL);
  171. // SetClassLong(Data.ttt,GCL_STYLE,CS_DROPSHADOW);
  172. // SendMessage (Data.ttt,TTM_SETDELAYTIME,TTDT_INITIAL,5);
  173. // SendMessage (Data.ttt,TTM_SETDELAYTIME,TTDT_RESHOW,20);
  174. // SendMessage (Result.handle,TTM_SETDELAYTIME,TTDT_AUTOPOP,2000);
  175. // Result.CreateWindow;
  176. // Result.Parent := AParent;
  177. // Result.Perform(TTM_SETTIPTEXTCOLOR,clRed,0);
  178. // SendMessage (Result.handle,TTM_SETTIPTEXTCOLOR,clBlue,0);
  179. // SendMessage (Result.handle,TTM_SETTIPTEXTCOLOR,clRed,0);
  180. // Result.Color:=clRed;
  181. // Result.Font.Color:=clRed;
  182. // Data.FCalColors:=NewMonthCalColors(Result);
  183. // Data.FOnDropDown:=nil;
  184. // Result.AttachProc(WndProcMHDateTimePicker);
  185. // Result.AttachProc(WndProcMHDateTimePicker);
  186. end;
  187. {procedure TMHToolTip.SetC(C: PControl);
  188. var
  189. TI: TToolInfo;
  190. R: Trect;
  191. // Data:PDateTimePickerData;
  192. begin
  193. R := C.ClientRect;
  194. // Control:= C.Handle;
  195. with TI do
  196. begin
  197. cbSize := SizeOf(TI);
  198. uFlags := TTF_SUBCLASS; // or TTF_IDISHWND;
  199. hWnd := C.GetWindowHandle; //Control;
  200. uId := 0;
  201. rect.Left := R.Left;
  202. rect.Top := R.Top;
  203. rect.Right := R.Right;
  204. rect.Bottom := R.Bottom;
  205. hInst := 0;
  206. lpszText := Pchar('I am ' + C.Caption);
  207. end;
  208. PostMessage(handle, TTM_ADDTOOL, 0, DWORD(@TI));
  209. // Perform(TTM_ADDTOOL, 0, DWord(@TI));
  210. end; }
  211. function TMHToolTip.GetDelay(const Index: Integer): Integer;
  212. begin
  213. Result := SendMessage(fHandle, TTM_GETDELAYTIME, Index, 0);
  214. end;
  215. procedure TMHToolTip.SetDelay(const Index, Value: Integer);
  216. begin
  217. SendMessage(handle, TTM_SETDELAYTIME, Index, MAKELONG(Value, 0));
  218. end;
  219. function TMHToolTip.GetColor(const Index: Integer): TColor;
  220. begin
  221. Result := SendMessage(handle, TTM_GETTIPBKCOLOR + Index, 0, 0);
  222. end;
  223. procedure TMHToolTip.SetColor(const Index: Integer; const Value: TColor);
  224. begin
  225. SendMessage(handle, TTM_SETTIPBKCOLOR + Index, Value, 0);
  226. end;
  227. function TMHToolTip.GetMaxWidth: Integer;
  228. begin
  229. Result := SendMessage(fHandle, TTM_GETMAXTIPWIDTH, 0, 0);
  230. end;
  231. procedure TMHToolTip.SetMaxWidth(const Value: Integer);
  232. begin
  233. SendMessage(fHandle, TTM_SETMAXTIPWIDTH, 0, Value);
  234. end;
  235. {procedure TMHToolTip.SetI(C: PControl; S: string);
  236. var
  237. TI: TToolInfo;
  238. R: Trect;
  239. // Data:PDateTimePickerData;
  240. begin
  241. R := C.ClientRect;
  242. // Control:= C.Handle;
  243. with TI do
  244. begin
  245. cbSize := SizeOf(TI);
  246. uFlags := TTF_SUBCLASS;
  247. hWnd := C.GetWindowHandle; //Control;
  248. uId := 0;
  249. rect.Left := R.Left;
  250. rect.Top := R.Top;
  251. rect.Right := R.Right;
  252. rect.Bottom := R.Bottom;
  253. hInst := 0;
  254. lpszText := PChar(S);
  255. end;
  256. // PostMessage (handle,TTM_ADDTOOL,0,DWORD (@TI));
  257. // Perform(TTM_SETTOOLINFO, 0, DWord(@TI));
  258. end; }
  259. function TMHToolTip.GetMargin: TRect;
  260. begin
  261. SendMessage(fHandle, TTM_GETMARGIN, 0, DWord(@Result));
  262. end;
  263. procedure TMHToolTip.SetMargin(const Value: TRect);
  264. begin
  265. SendMessage(fHandle, TTM_SETMARGIN, 0, DWord(@Value));
  266. end;
  267. function TMHToolTip.GetActivate: Boolean;
  268. begin
  269. // ??????
  270. Result := False;
  271. end;
  272. procedure TMHToolTip.SetActivate(const Value: Boolean);
  273. begin
  274. SendMessage(fHandle, TTM_ACTIVATE, DWord(Value), 0);
  275. end;
  276. procedure TMHToolTip.Pop;
  277. begin
  278. SendMessage(fHandle, TTM_POP, 0, 0);
  279. end;
  280. procedure TMHToolTip.Popup;
  281. begin
  282. SendMessage(fHandle, $0422 {TTM_POPUP}, 0, 0);
  283. end;
  284. {function TMHToolTip.GetText: string;
  285. begin
  286. end;
  287. procedure TMHToolTip.SetText(const Value: string);
  288. var
  289. TI: TToolInfo;
  290. begin
  291. TI := GetInfo;
  292. TI.lpszText := PChar(Value);
  293. SetInfo(TI);
  294. end; }
  295. {function TMHToolTip.GetInfo: TToolInfo;
  296. begin
  297. with Result do
  298. begin
  299. // ????
  300. FillChar(Result, SizeOf(Result), 0);
  301. cbSize := SizeOf(Result);
  302. // hWnd := Parent.GetWindowHandle;
  303. uId := 0;
  304. end;
  305. // Perform(TTM_GETTOOLINFO, 0, DWord(@Result));
  306. end;
  307. procedure TMHToolTip.SetInfo(Value: TToolInfo);
  308. begin
  309. // Perform(TTM_SETTOOLINFO, 0, DWord(@Value));
  310. end;}
  311. {function TMHToolTip.GetToolCount: Integer;
  312. begin
  313. // Result := Perform(TTM_GETTOOLCOUNT, 0, 0);
  314. end;
  315. function TMHToolTip.GetTool(Index: Integer): TToolInfo;
  316. begin
  317. FillChar(Result, SizeOf(Result), 0); // ????
  318. Result.cbSize := SizeOf(Result);
  319. // Perform(TTM_ENUMTOOLS, Index, DWord(@Result));
  320. end; }
  321. {procedure TMHToolTip.Add(Value: TToolInfo);
  322. begin
  323. // Perform(TTM_ADDTOOL, 0, DWord(@Value));
  324. end;}
  325. {procedure TMHToolTip.Delete(Value: TToolInfo);
  326. begin
  327. // Perform(TTM_DELTOOL, 0, DWord(@Value));
  328. end;}
  329. procedure TMHToolTip.Update;
  330. begin
  331. inherited; // ???
  332. SendMessage(fHandle, TTM_UPDATE, 0, 0);
  333. end;
  334. function NewHint(A: PControl): PMHHint;
  335. begin
  336. New(Result, Create);
  337. with Result^ do
  338. begin
  339. Parent := A;
  340. ToolTip := nil; // ???
  341. HasTool := False; // ???
  342. end;
  343. A.Add2AutoFree(Result);
  344. end;
  345. function NewManager: PMHToolTipManager;
  346. begin
  347. New(Result, Create);
  348. end;
  349. { TMHHint }
  350. function TMHHint.GetDelay(const Index: Integer): Integer;
  351. begin
  352. // CreateToolTip;
  353. Result := 0;
  354. if Assigned(ToolTip) then
  355. Result := ToolTip.GetDelay(Index);
  356. end;
  357. function TMHHint.GetFI: TFI;
  358. begin
  359. /// !!! DANGER-WITH !!!
  360. with Result, ToolTip^ do
  361. begin
  362. FE := FE + [eTextColor];
  363. Colors[1] := TextColor;
  364. FE := FE + [eBkColor];
  365. Colors[0] := BkColor;
  366. FE := FE + [eAPDelay];
  367. Delays[TTDT_AUTOPOP] := AutoPopDelay;
  368. FE := FE + [eRDelay];
  369. Delays[TTDT_RESHOW] := ReshowDelay;
  370. FE := FE + [eIDelay];
  371. Delays[TTDT_INITIAL] := InitialDelay;
  372. end;
  373. end;
  374. procedure TMHHint.ReConnect(FI: TFI);
  375. var
  376. TMP: PMHToolTip;
  377. begin
  378. with GetManager^ do
  379. begin
  380. TMP := FindNeed(FI);
  381. if not Assigned(TMP) then
  382. TMP := CreateNeed(FI);
  383. if Assigned(ToolTip) and HasTool then
  384. MoveTool(TMP);
  385. ToolTip := TMP;
  386. end;
  387. end;
  388. procedure TMHHint.MoveTool(T1: PMHToolTip);
  389. var
  390. TI: TToolInfo;
  391. TextL: array[0..255] of KOLChar;
  392. begin
  393. if T1 = ToolTip then
  394. Exit;
  395. with TI do
  396. begin
  397. cbSize := SizeOf(TI);
  398. hWnd := Parent.GetWindowHandle;
  399. uId := Parent.GetWindowHandle;
  400. lpszText := @TextL[0];
  401. end;
  402. SendMessage(ToolTip.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
  403. SendMessage(ToolTip.handle, TTM_DELTOOL, 0, DWORD(@TI));
  404. ToolTip.Count := ToolTip.Count - 1;
  405. SendMessage(T1.handle, TTM_ADDTOOL, 0, DWORD(@TI));
  406. T1.Count := T1.Count - 1;
  407. HasTool := True;
  408. end;
  409. procedure TMHHint.SetColor(const Index: Integer; const Value: TColor);
  410. var
  411. FI: TFI;
  412. begin
  413. if Assigned(ToolTip) then
  414. begin
  415. if ToolTip.Count + Byte(not HasTool) = 1 then
  416. begin
  417. ToolTip.SetColor(Index, Value);
  418. Exit;
  419. end;
  420. FI := GetFI;
  421. end;
  422. case Index of
  423. 0: FI.FE := FI.FE + [eBkColor];
  424. 1: FI.FE := FI.FE + [eTextColor];
  425. end;
  426. FI.Colors[Index] := Value;
  427. ReConnect(FI);
  428. end;
  429. function TMHHint.GetColor(const Index: Integer): TColor;
  430. begin
  431. Result := 0;
  432. if Assigned(ToolTip) then
  433. Result := ToolTip.GetColor(Index);
  434. end;
  435. procedure TMHHint.SetDelay(const Index, Value: Integer);
  436. var
  437. FI: TFI;
  438. begin
  439. if Assigned(ToolTip) then
  440. begin
  441. if ToolTip.Count + Byte(not HasTool) = 1 then
  442. begin
  443. ToolTip.SetDelay(Index, Value);
  444. Exit;
  445. end;
  446. FI := GetFI;
  447. end;
  448. case Index of
  449. TTDT_AUTOPOP: FI.FE := FI.FE + [eAPDelay]; // Spec
  450. TTDT_INITIAL: FI.FE := FI.FE + [eIDelay]; // Spec
  451. TTDT_RESHOW: FI.FE := FI.FE + [eRDelay]; // Spec
  452. end; //case
  453. FI.Delays[Index] := Value; //Spec
  454. ReConnect(FI);
  455. end;
  456. procedure TMHHint.SetText(Value: KOLString);
  457. var
  458. TI: TToolInfo;
  459. begin
  460. ProcBegin(TI);
  461. with TI do
  462. begin
  463. uFlags := TTF_SUBCLASS or TTF_IDISHWND; // Spec
  464. lpszText := PKOLChar(Value); // Spec
  465. end;
  466. procEnd(TI);
  467. if HasTool then
  468. begin
  469. TI.lpszText := PKOLChar(Value);
  470. SendMessage(ToolTip.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
  471. end;
  472. end;
  473. (*
  474. procedure TMHHint.SetText(Value: string);
  475. var
  476. TI: TToolInfo;
  477. R: Trect;
  478. TextLine: array[0..255] of Char;
  479. begin
  480. if not Assigned(ToolTip) then
  481. begin
  482. if Length(Manager.TTT) = 0 then
  483. Manager.AddTip;
  484. ToolTip := Manager.TTT[0];
  485. end;
  486. with TI do
  487. begin
  488. cbSize := SizeOf(TI);
  489. hWnd := Parent.GetWindowHandle;
  490. uId := Parent.GetWindowHandle;
  491. hInst := 0;
  492. end;
  493. if not HasTool {TTool = -1} then
  494. begin
  495. R := Parent.ClientRect;
  496. // Control:= C.Handle;
  497. with TI do
  498. begin
  499. // cbSize := SizeOf(TI);
  500. uFlags := TTF_SUBCLASS;
  501. // hWnd := Parent.GetWindowHandle; //Control;
  502. // uId := Parent.GetWindowHandle;
  503. rect.Left := R.Left;
  504. rect.Top := R.Top;
  505. rect.Right := R.Right;
  506. rect.Bottom := R.Bottom;
  507. // hInst := 0;
  508. lpszText := PChar(Value);
  509. end;
  510. SendMessage({Manager.TTT[TTip]} ToolTip.handle, TTM_ADDTOOL, 0, DWORD(@TI));
  511. HasTool := True;
  512. // TTool := 0;
  513. ToolTip {Manager.TTT[TTip]}.Count := ToolTip {Manager.TTT[TTip]}.Count + 1;
  514. end
  515. else
  516. begin
  517. with TI do
  518. begin
  519. // ????
  520. // FillChar(TI, SizeOf(TI), 0);
  521. // cbSize := SizeOf(TI);
  522. // hWnd := Parent.GetWindowHandle;
  523. // uId := Parent.GetWindowHandle;
  524. lpszText := @TextLine; //PChar(S);
  525. end;
  526. SendMessage(ToolTip {Manager.TTT[TTip]}.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
  527. TI.lpszText := PChar(Value);
  528. // Perform(TTM_GETTOOLINFO, 0, DWord(@Result));
  529. SendMessage(ToolTip {Manager.TTT[TTip]}.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
  530. end;
  531. // Manager.TTT[TTip].Tool[TTool].SSSetText(Value);
  532. end;
  533. *)
  534. { TMHToolTipManager }
  535. {function TMHToolTipManager.AddColor(C: TColor): Integer;
  536. begin
  537. SetLength(TTT, Length(TTT) + 1);
  538. TTT[Length(TTT) - 1] := NewMHToolTip(Applet);
  539. TTT[Length(TTT) - 1].SetColor(1, C);
  540. Result := Length(TTT) - 1;
  541. end; }
  542. function TMHToolTipManager.AddTip: Integer;
  543. begin
  544. SetLength(TTT, Length(TTT) + 1);
  545. TTT[Length(TTT) - 1] := NewMHToolTip(Applet);
  546. Result := Length(TTT) - 1;
  547. end;
  548. {function TMHToolTip.Connect(Value: PControl): Integer;
  549. var
  550. TI: TToolInfo;
  551. R: Trect;
  552. // Data:PDateTimePickerData;
  553. begin
  554. R := Value.ClientRect;
  555. // Control:= C.Handle;
  556. with TI do
  557. begin
  558. cbSize := SizeOf(TI);
  559. uFlags := TTF_SUBCLASS;
  560. hWnd := Value.GetWindowHandle; //Control;
  561. uId := Value.GetWindowHandle;
  562. rect.Left := R.Left;
  563. rect.Top := R.Top;
  564. rect.Right := R.Right;
  565. rect.Bottom := R.Bottom;
  566. hInst := 0;
  567. lpszText := PChar('Super');
  568. end;
  569. PostMessage(handle, TTM_ADDTOOL, 0, DWORD(@TI));
  570. // Perform(TTM_ADDTOOL, 0, DWord(@TI));
  571. end;}
  572. {function TMHToolTipManager.FindTip(N: Integer): Integer;
  573. begin
  574. Result := -1;
  575. end;}
  576. function TMHToolTipManager.FindNeed(FI: TFI): PMHToolTip;
  577. var
  578. i: Integer;
  579. begin
  580. Result := nil;
  581. for i := 0 to length(TTT) - 1 do
  582. begin
  583. if ((eTextColor in FI.FE) and (not (FI.Colors[1] = TTT[i].TextColor))) or
  584. ((eBkColor in FI.FE) and (not (FI.Colors[0] = TTT[i].BkColor))) or
  585. ((eAPDelay in FI.FE) and (not (FI.Delays[TTDT_AUTOPOP] = TTT[i].AutoPopDelay))) or
  586. ((eIDelay in FI.FE) and (not (FI.Delays[TTDT_INITIAL] = TTT[i].InitialDelay))) or
  587. ((eRDelay in FI.FE) and (not (FI.Delays[TTDT_RESHOW] = TTT[i].ReshowDelay))) then
  588. Continue;
  589. Result := TTT[i];
  590. Break;
  591. end;
  592. end;
  593. function TMHToolTipManager.CreateNeed(FI: TFI): PMHToolTip;
  594. begin
  595. Setlength(TTT, length(TTT) + 1);
  596. TTT[length(TTT) - 1] := NewMHToolTip(Applet);
  597. with TTT[length(TTT) - 1]^ do
  598. begin
  599. if (eTextColor in FI.FE) then
  600. TextColor := FI.Colors[1];
  601. if (eBkColor in FI.FE) then
  602. BkColor := FI.Colors[0];
  603. if (eAPDelay in FI.FE) then
  604. AutoPopDelay := FI.Delays[TTDT_AUTOPOP];
  605. if (eIDelay in FI.FE) then
  606. InitialDelay := FI.Delays[TTDT_INITIAL];
  607. if (eRDelay in FI.FE) then
  608. ReshowDelay := FI.Delays[TTDT_RESHOW];
  609. end;
  610. Result := TTT[length(TTT) - 1];
  611. end;
  612. procedure TMHHint.ProcBegin(var TI: TToolInfo);
  613. begin
  614. CreateToolTip;
  615. with TI do
  616. begin
  617. cbSize := SizeOf(TI);
  618. hWnd := Parent.GetWindowHandle;
  619. uId := Parent.GetWindowHandle;
  620. hInst := 0;
  621. end;
  622. end;
  623. procedure TMHHint.ProcEnd(var TI: TToolInfo);
  624. var
  625. TextLine: array[0..255] of KOLChar;
  626. begin
  627. if not HasTool then
  628. begin
  629. SendMessage(ToolTip.handle, TTM_ADDTOOL, 0, DWORD(@TI));
  630. HasTool := True;
  631. ToolTip.Count := ToolTip.Count + 1;
  632. end
  633. else
  634. begin
  635. with TI do
  636. begin
  637. lpszText := @TextLine[0];
  638. end;
  639. SendMessage(ToolTip.handle, TTM_SETTOOLINFO, 0, DWord(@TI));
  640. end;
  641. end;
  642. destructor TMHToolTipManager.Destroy;
  643. var
  644. i: Integer;
  645. begin
  646. for i := 0 to Length(TTT) - 1 do
  647. TTT[i].Free;
  648. SetLength(TTT, 0);
  649. inherited;
  650. end;
  651. procedure TMHHint.Pop;
  652. begin
  653. if Assigned(ToolTip) and (HasTool) then
  654. begin // ^^^^^^^^^^^^ ???
  655. // CreateToolTip;
  656. ToolTip.Pop;
  657. end;
  658. end;
  659. procedure TMHHint.Popup;
  660. begin
  661. if Assigned(ToolTip) and (HasTool) then
  662. begin // ^^^^^^^^^^^^ ???
  663. // CreateToolTip;
  664. ToolTip.Popup;
  665. end;
  666. end;
  667. destructor TMHHint.Destroy;
  668. var
  669. TI: TToolInfo;
  670. i: integer;
  671. begin
  672. with TI do
  673. begin
  674. cbSize := SizeOf(TI);
  675. hWnd := Parent.GetWindowHandle;
  676. uId := Parent.GetWindowHandle;
  677. end;
  678. SendMessage(ToolTip.handle, TTM_DELTOOL, 0, DWORD(@TI));
  679. ToolTip.Count := ToolTip.Count - 1;
  680. if ToolTip.Count <= 0 then begin
  681. i:=Length(Manager.TTT);
  682. if i > 1 then begin
  683. Manager.TTT[i - 1].Free;
  684. SetLength(Manager.TTT, i - 1);
  685. end
  686. else
  687. Free_And_Nil(Manager);
  688. end;
  689. inherited;
  690. end;
  691. destructor TMHToolTip.Destroy;
  692. begin
  693. inherited;
  694. end;
  695. procedure TMHHint.CreateToolTip;
  696. begin
  697. if not Assigned(ToolTip) then
  698. begin
  699. if Length(GetManager.TTT) = 0 then
  700. GetManager.AddTip;
  701. ToolTip := GetManager.TTT[0];
  702. end;
  703. end;
  704. function TMHHint.GetText: KOLString;
  705. var
  706. TI: TToolInfo;
  707. TextL: array[0..255] of KOLChar;
  708. begin
  709. if Assigned(ToolTip) and (HasTool) then
  710. begin
  711. // !!!
  712. with TI do
  713. begin
  714. // ????
  715. // FillChar(TI, SizeOf(TI), 0);
  716. cbSize := SizeOf(TI);
  717. hWnd := Parent.GetWindowHandle;
  718. uId := Parent.GetWindowHandle;
  719. lpszText := @TextL[0];
  720. end;
  721. SendMessage(ToolTip.handle, TTM_GETTOOLINFO, 0, DWord(@TI));
  722. Result := TextL; //TI.lpszText;// := PChar(Value);
  723. end;
  724. end;
  725. function TMHHint.GetManager: PMHToolTipManager;
  726. begin
  727. if Manager=nil then
  728. Manager:=NewManager;
  729. Result:=Manager;
  730. end;
  731. {$ENDIF implementation}
  732. {$IFDEF Frame}
  733. initialization
  734. {$ENDIF Frame}
  735. {$IFDEF initialization}
  736. Manager := NewManager;
  737. {$ENDIF initialization}
  738. {$IFDEF Frame}
  739. finalization
  740. {$ENDIF Frame}
  741. {$IFDEF finalization}
  742. // Manager.Free;
  743. {$ENDIF finalization}
  744. {$IFDEF Frame}
  745. end.
  746. {$ENDIF Frame}
  747. {$IFDEF function}
  748. function GetHint: PMHHint;
  749. {$ENDIF function}
  750. {$IFDEF public}
  751. property Hint: PMHHint read GetHint;
  752. {$ENDIF public}
  753. {$IFDEF code}
  754. function TControl.GetHint: PMHHint;
  755. begin
  756. if fHint = nil then
  757. fHint := NewHint(@Self);
  758. Result := fHint;
  759. end;
  760. {$ENDIF code}
  761. {$IFDEF MHdestroy}
  762. fHint.Free;
  763. {$ENDIF MHdestroy}
  764. {$IFDEF var}
  765. fHint: PMHHint;
  766. {$ENDIF var}