Recent

Author Topic: How make own componet with popup window?  (Read 2015 times)

Borneq

  • Full Member
  • ***
  • Posts: 238
How make own componet with popup window?
« on: January 27, 2020, 07:42:42 pm »
Popups are used in menu and combobox.
How can I make own combobox with:
- fast pull down window, no animation
- advanced: colors, fonts
- columns in popup window, this windows must use VirtualTree

Handoko

  • Hero Member
  • *****
  • Posts: 3366
  • My goal: build my own game engine using Lazarus
Re: How make own componet with popup window?
« Reply #1 on: January 27, 2020, 07:49:06 pm »
Not answering your question, but maybe something like this:
https://forum.lazarus.freepascal.org/index.php/topic,37369.msg250939.html#msg250939

Sorry, I'm not familiar with VirtualTree

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How make own componet with popup window?
« Reply #2 on: January 27, 2020, 08:03:06 pm »
OK, how make:
- popup window without frame
- auto close when click anywhere but outside window?

Handoko

  • Hero Member
  • *****
  • Posts: 3366
  • My goal: build my own game engine using Lazarus
Re: How make own componet with popup window?
« Reply #3 on: January 27, 2020, 08:11:01 pm »
I haven't tried but I think it can.

Popup window without frame
Don't use TForm. Instead you runtime generate a TShape, TPaintBox, TPanel (BevelOuter := bvNone), or anything similar to what you want.

Auto close when click outside

Don't use show modal. On the component, you put the code to close it on OnExit event.
« Last Edit: January 27, 2020, 08:22:36 pm by Handoko »

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How make own componet with popup window?
« Reply #4 on: January 30, 2020, 06:13:43 pm »
Lazarus IDE has fantastic popup window in code completion. How I obtaing similar thing? Where are sources of Code Completion?

Handoko

  • Hero Member
  • *****
  • Posts: 3366
  • My goal: build my own game engine using Lazarus
Re: How make own componet with popup window?
« Reply #5 on: January 30, 2020, 06:30:25 pm »
As far as I know that is part of TSynEdit:
https://wiki.lazarus.freepascal.org/SynEdit#Completion_plugins

sash

  • Sr. Member
  • ****
  • Posts: 338
Re: How make own componet with popup window?
« Reply #6 on: January 30, 2020, 08:05:35 pm »
Quick and dirty example:
Code: Pascal  [Select]
  1.   popup := THintWindow.Create(nil);
  2.   with popup do begin
  3.     SetBounds(Mouse.CursorPos.X, Mouse.CursorPos.Y, 200, 200);
  4.     btn := TButton.Create(popup);
  5.     btn.Caption := 'Button!';
  6.     btn.Parent := popup;
  7.     Brush.Color := clRed;
  8.     Show;
  9.   end;
You should take care (figure out) about proper ownership/memory releasing of Popup and its children.
Something like OnClose. Just see how it works in TPopupNotifier or SynEdit.
Lazarus 2.0.6 FPC 3.0.4 x86_64-linux-gtk2 @ Ubuntu 19.10 XFCE

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How make own componet with popup window?
« Reply #7 on: January 31, 2020, 11:00:19 am »
how to close THintWindow when mouse click outside it?
I do
Code: Pascal  [Select]
  1. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   popup.Hide;
  5. end;
  6.  
but this work only when mouse down on pure form, not in any control. How to handle mouse events on whole form, including all controls?
« Last Edit: January 31, 2020, 12:03:23 pm by Borneq »

Handoko

  • Hero Member
  • *****
  • Posts: 3366
  • My goal: build my own game engine using Lazarus
Re: How make own componet with popup window?
« Reply #8 on: January 31, 2020, 12:03:07 pm »
I've just checked THintWindow, it has OnExit event. Maybe you can use it.

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How make own componet with popup window?
« Reply #9 on: January 31, 2020, 12:13:20 pm »
Is possible make form message filtering, mouse messsages before dispatching to controls?

Handoko

  • Hero Member
  • *****
  • Posts: 3366
  • My goal: build my own game engine using Lazarus
Re: How make own componet with popup window?
« Reply #10 on: January 31, 2020, 05:52:06 pm »
Not fully understand what you want to do, here I quickly written a demo. Maybe it can give you some ideas.

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Label1: TLabel;
  17.     Panel1: TPanel;
  18.     Shape1: TShape;
  19.     Timer1: TTimer;
  20.     procedure FormClick(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure Panel1Exit(Sender: TObject);
  23.     procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
  24.       Shift: TShiftState; X, Y: Integer);
  25.     procedure Timer1Timer(Sender: TObject);
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. { TForm1 }
  36.  
  37. procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
  38.   Shift: TShiftState; X, Y: Integer);
  39. var
  40.   NewPos: TPoint;
  41. begin
  42.   NewPos := ScreenToClient(Mouse.CursorPos);
  43.   Panel1.Left    := NewPos.x;
  44.   Panel1.Top     := NewPos.y;
  45.   Panel1.Visible := True;
  46.   Panel1.SetFocus;
  47. end;
  48.  
  49. procedure TForm1.Timer1Timer(Sender: TObject);
  50. begin
  51.   Label1.Caption := 'Now is ' + TimeToStr(Now) + LineEnding +
  52.                     'Click outside to close this box.';
  53. end;
  54.  
  55. procedure TForm1.FormCreate(Sender: TObject);
  56. begin
  57.   Panel1.Visible := False;
  58.   Panel1.Caption := '';
  59. end;
  60.  
  61. procedure TForm1.Panel1Exit(Sender: TObject);
  62. begin
  63.   Panel1.Visible := False;
  64. end;
  65.  
  66. procedure TForm1.FormClick(Sender: TObject);
  67. begin
  68.   Panel1.Visible := False;
  69. end;
  70.  
  71. end.

Click the red rectangle to make the pop up appears.
« Last Edit: January 31, 2020, 06:01:25 pm by Handoko »

Borneq

  • Full Member
  • ***
  • Posts: 238
Re: How make own componet with popup window?
« Reply #11 on: January 31, 2020, 10:56:19 pm »
But TPanel must be in whole inside form, THintWindow is better, in other hand, I can't properly handle OnExit of THintWindow.
TSynCompletion is fine, but
- is complicated
- depend from TCustomSynedit, it can't use TEdit ot TComboBox as control
- the worst: TSynBaseCompletion inherits from TLazSynMultiEditPlugin, is not Synedit angostic.
« Last Edit: January 31, 2020, 11:24:16 pm by Borneq »