Recent

Author Topic: Making a movable TPanel on the Apple Mac [SOLVED]  (Read 2956 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Making a movable TPanel on the Apple Mac [SOLVED]
« on: August 04, 2017, 09:00:24 pm »
Back in my Delphi/Windows days, I used to have some code which allowed me to have a TPanel descendant which was movable at runtime. Long story short, it did this by Self.Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0); where SC_DRAGMOVE = $F012;

Is there an equivalent way of achieving the same effect in Lazarus on the Apple Mac. Presumably, the mechanism would have to be radically different due to the lack of Windows messages.

I can't believe that the notion of movable panels is unheard of in the Apple Mac programming world though. So how is it done?
« Last Edit: August 04, 2017, 09:32:14 pm by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Making a movable TPanel on the Apple Mac
« Reply #1 on: August 04, 2017, 09:18:45 pm »
Back in my Delphi/Windows days, I used to have some code which allowed me to have a TPanel descendant which was movable at runtime.

What's a moveable TPanel and how would you use it/what would you use it for?

Look at LCL TPanel? Is there anything there that corresponds to that?

What about Cocoa native control? Anything there that's like what you want? See AppKit docs. If so, then you could create a custom control based on that.


carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Making a movable TPanel on the Apple Mac [SOLVED]
« Reply #2 on: August 04, 2017, 09:31:53 pm »
I found the following code which does what I want. By movable, I merely meant selectable and movable by the mouse at run-time.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, LCLintf;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Panel1: TPanel;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  18.       Shift: TShiftState; X, Y: Integer);
  19.     procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
  20.       );
  21.     procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  22.       Shift: TShiftState; X, Y: Integer);
  23.   private
  24.     FDownPoint: TPoint;
  25.     FDragging: Boolean;
  26.     FAllowDrag: Boolean;
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   FAllowDrag := True;
  43. end;
  44.  
  45. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  46.   Shift: TShiftState; X, Y: Integer);
  47. begin
  48.   if Button = mbLeft then
  49.     begin
  50.       FDragging := True;
  51.       GetCursorPos(FDownPoint);
  52.       FDownPoint.X := FDownPoint.X - Panel1.Left;
  53.       FDownPoint.Y := FDownPoint.Y - Panel1.Top;
  54.     end;
  55. end;
  56.  
  57. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  58.   Y: Integer);
  59. var
  60.   MovePoint : TPoint;
  61. begin
  62.   if FDragging and FAllowDrag then
  63.     begin
  64.       GetCursorPos(MovePoint);
  65.       Panel1.SetBounds(
  66.         MovePoint.X - FDownPoint.X,
  67.         MovePoint.Y - FDownPoint.Y,
  68.         Panel1.Width, Panel1.Height
  69.       );
  70.     end;
  71. end;
  72.  
  73. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  74.   Shift: TShiftState; X, Y: Integer);
  75. begin
  76.   if Button = mbLeft then
  77.     FDragging := False;
  78. end;
  79.  
  80. end.
  81.  
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: Making a movable TPanel on the Apple Mac [SOLVED]
« Reply #3 on: August 05, 2017, 05:35:01 pm »
Great idea!
This is a very good workaround for my drag and drop problem with cocoa. Since d&d isn't yet available in cocoa, I'm using your idea to simply move (in my case) single words from one list to another using a label.
And, btw, the drag object mechanism does not work on the mac generally (neither carbon nor cocoa), this problem is solved too.
Thanks.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

 

TinyPortal © 2005-2018