diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-12 23:21:17 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-12 23:21:17 +0000 |
commit | 2a4f80da527ce0f4e8ec53004c965fb809b05a37 (patch) | |
tree | 0a8ccaa8c2ae2057c1284b27b0ca1ce698c90ad5 /prototypes | |
parent | a015704448d74b4da577658a498e2a776d117851 (diff) | |
download | fpGUI-2a4f80da527ce0f4e8ec53004c965fb809b05a37.tar.xz |
fpgui2: Implemented WindowToScreen which translates coordinates.
fpgui2: Fixed up the painting issues of TfpgComboBox.
fpgui2: TfpgComboBox dropdown is now painted and appears in the correct location and size.
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/fpgui2/source/core/gdi/gfx_gdi.pas | 17 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/gfxbase.pas | 17 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/x11/gfx_x11.pas | 23 | ||||
-rw-r--r-- | prototypes/fpgui2/source/gui/gui_combobox.pas | 62 |
4 files changed, 104 insertions, 15 deletions
diff --git a/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas b/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas index d29d1384..c155dff9 100644 --- a/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas +++ b/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas @@ -127,7 +127,8 @@ type procedure DoReleaseWindowHandle; override; function HandleIsValid: boolean; override; procedure DoUpdateWindowPosition(aleft, atop, awidth, aheight: TfpgCoord); override; - procedure DoMoveWindow(x, y: TfpgCoord); + procedure DoMoveWindow(const x: TfpgCoord; const y: TfpgCoord); override; + function DoWindowToScreen(ASource: TfpgWindowBase; const AScreenPos: TPoint): TPoint; override; //procedure MoveToScreenCenter; override; procedure DoSetWindowTitle(const atitle: string); property WinHandle: TfpgWinHandle read FWinHandle; @@ -873,12 +874,22 @@ begin FWinHandle := 0; end; -procedure TfpgWindowImpl.DoMoveWindow(x, y: TfpgCoord); +procedure TfpgWindowImpl.DoMoveWindow(const x: TfpgCoord; const y: TfpgCoord); begin - if FWinHandle > 0 then + if HandleIsValid then Windows.SetWindowPos(WinHandle, 0, x, y, 0, 0, SWP_NOZORDER or SWP_NOSIZE or SWP_NOREDRAW); end; +function TfpgWindowImpl.DoWindowToScreen(ASource: TfpgWindowBase; const AScreenPos: TPoint): TPoint; +begin + if not HandleIsValid then + Exit; //==> + + Result.X := AScreenPos.X; + Result.Y := AScreenPos.Y; + ClientToScreen(TfpgWindowImpl(ASource).WinHandle, Result); +end; + { procedure TfpgWindowImpl.MoveToScreenCenter; var diff --git a/prototypes/fpgui2/source/core/gfxbase.pas b/prototypes/fpgui2/source/core/gfxbase.pas index f1a6193d..ff4a390b 100644 --- a/prototypes/fpgui2/source/core/gfxbase.pas +++ b/prototypes/fpgui2/source/core/gfxbase.pas @@ -267,6 +267,8 @@ type end; + { TfpgWindowBase } + TfpgWindowBase = class(TComponent) private FParent: TfpgWindowBase; @@ -284,6 +286,8 @@ type procedure DoUpdateWindowPosition(aleft, atop, awidth, aheight: TfpgCoord); virtual; abstract; procedure DoAllocateWindowHandle(AParent: TfpgWindowBase); virtual; abstract; procedure DoReleaseWindowHandle; virtual; abstract; + procedure DoMoveWindow(const x: TfpgCoord; const y: TfpgCoord); virtual; abstract; + function DoWindowToScreen(ASource: TfpgWindowBase; const AScreenPos: TPoint): TPoint; virtual; abstract; procedure SetParent(const AValue: TfpgWindowBase); virtual; function GetParent: TfpgWindowBase; virtual; function GetCanvas: TfpgCanvasBase; virtual; @@ -317,6 +321,8 @@ type function Right: TfpgCoord; function Bottom: TfpgCoord; procedure UpdateWindowPosition; + procedure MoveWindow(const x: TfpgCoord; const y: TfpgCoord); + function WindowToScreen(ASource: TfpgWindowBase; const AScreenPos: TPoint): TPoint; property HasHandle: boolean read HandleIsValid; property WindowType: TWindowType read FWindowType write FWindowType; property WindowAttributes: TWindowAttributes read FWindowAttributes write FWindowAttributes; @@ -464,6 +470,17 @@ begin DoUpdateWindowPosition(FLeft, FTop, FWidth, FHeight); end; +procedure TfpgWindowBase.MoveWindow(const x: TfpgCoord; const y: TfpgCoord); +begin + DoMoveWindow(x, y); +end; + +function TfpgWindowBase.WindowToScreen(ASource: TfpgWindowBase; + const AScreenPos: TPoint): TPoint; +begin + Result := DoWindowToScreen(ASource, AScreenPos); +end; + { TfpgCanvasBase } constructor TfpgCanvasBase.Create; diff --git a/prototypes/fpgui2/source/core/x11/gfx_x11.pas b/prototypes/fpgui2/source/core/x11/gfx_x11.pas index 650758db..f1f0e994 100644 --- a/prototypes/fpgui2/source/core/x11/gfx_x11.pas +++ b/prototypes/fpgui2/source/core/x11/gfx_x11.pas @@ -115,6 +115,8 @@ type end; + { TfpgWindowImpl } + TfpgWindowImpl = class(TfpgWindowBase) protected FWinHandle: TfpgWinHandle; @@ -123,7 +125,8 @@ type procedure DoReleaseWindowHandle; override; function HandleIsValid: boolean; override; procedure DoSetWindowTitle(const atitle: string); - procedure DoMoveWindow(x, y: TfpgCoord); + procedure DoMoveWindow(const x: TfpgCoord; const y: TfpgCoord); override; + function DoWindowToScreen(ASource: TfpgWindowBase; const AScreenPos: TPoint): TPoint; override; procedure DoUpdateWindowPosition(aleft, atop, awidth, aheight: TfpgCoord); override; property WinHandle: TfpgWinHandle read FWinHandle; { Event processing methods } @@ -919,12 +922,28 @@ begin Result := (FWinHandle > 0); end; -procedure TfpgWindowImpl.DoMoveWindow(x, y: TfpgCoord); +procedure TfpgWindowImpl.DoMoveWindow(const x: TfpgCoord; const y: TfpgCoord); begin if FWinHandle > 0 then XMoveWindow(xapplication.display, FWinHandle, x, y); end; +function TfpgWindowImpl.DoWindowToScreen(ASource: TfpgWindowBase; const AScreenPos: TPoint): TPoint; +var + dx: integer; + dy: integer; + cw : TfpgWinHandle; +begin +// if not HandleIsValid then +// Exit; //==> + + XTranslateCoordinates(xapplication.display, TfpgWindowImpl(ASource).WinHandle, + XDefaultRootWindow(xapplication.display), AScreenPos.X, AScreenPos.Y, @dx, @dy, @cw); + + Result.X := dx; + Result.Y := dy; +end; + procedure TfpgWindowImpl.DoUpdateWindowPosition(aleft, atop, awidth, aheight: TfpgCoord); var w: longword; diff --git a/prototypes/fpgui2/source/gui/gui_combobox.pas b/prototypes/fpgui2/source/gui/gui_combobox.pas index 46b85268..17cc0003 100644 --- a/prototypes/fpgui2/source/gui/gui_combobox.pas +++ b/prototypes/fpgui2/source/gui/gui_combobox.pas @@ -14,6 +14,8 @@ uses type + { TfpgCustomComboBox } + TfpgCustomComboBox = class(TfpgWidget) private FDropDownCount: integer; @@ -29,6 +31,7 @@ type procedure HandlePaint; override; public constructor Create(AOwner: TComponent); override; + procedure AfterConstruction; override; end; @@ -52,6 +55,36 @@ type TPrivateWidget = class(TfpgWidget) end; + { TDropDownWindow } + + TDropDownWindow = class(TfpgForm) + protected + procedure EvPaint; override; + public + constructor Create(AOwner: TComponent); override; + end; + +{ TDropDownWindow } + +procedure TDropDownWindow.EvPaint; +begin + Canvas.BeginDraw; + inherited EvPaint; + Canvas.Clear(clWhite); + Canvas.SetColor(clYellow); + Canvas.SetLineStyle(2, lsSolid); + Canvas.DrawRectangle(1, 1, Width-1, Height-1); + Canvas.EndDraw; +end; + +constructor TDropDownWindow.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + WindowType := wtPopup; + WindowAttributes := []; + WindowPosition := wpUser; +end; + function CreateComboBox(AOwner: TComponent; x, y, w: TfpgCoord; AList: TStringList): TfpgComboBox; begin @@ -75,16 +108,17 @@ begin end; procedure TfpgCustomComboBox.DoDropDown; +var + pt: TPoint; begin if (not Assigned(FDropDown)) or (not FDropDown.HasHandle) then begin - FDropDown := TfpgForm.Create(nil); - FDropDown.WindowType := wtPopup; - FDropDown.Sizeable := False; - FDropDown.Left := Left; - FDropDown.Top := Top + Height; + pt := WindowToScreen(Parent, Point(Left, Top+Height)); + FDropDown := TDropDownWindow.Create(nil); + FDropDown.Left := pt.X; + FDropDown.Top := pt.Y; FDropDown.Width := Width; - FDropDown.Height := DropDownCount * Height; + FDropDown.Height := (DropDownCount * (Height-4)); FDropDown.Show; end else @@ -96,7 +130,6 @@ end; procedure TfpgCustomComboBox.InternalBtnClick(Sender: TObject); begin - TPrivateWidget(FInternalBtn).MoveAndResize(Width - min(Height, 20) - 3, 2, Height - 4, Height - 4); DoDropDown; end; @@ -130,8 +163,8 @@ begin Canvas.FillRectAngle(2, 2, Width - 4, Height - 4); // Canvas.FillRectAngle(0,0,Width,Height); - // pgfStyle.DrawButtonFace(canvas, width - min(height, 20)-3, 2, height-4, height-4, [btnIsEmbedded]); - // pgfStyle.DrawDirectionArrow(canvas, width - height + 1, 1, height-2, height-2, 1); +// fpgStyle.DrawButtonFace(canvas, width - min(height, 20)-3, 2, height-4, height-4, [btnIsEmbedded]); +// fpgStyle.DrawDirectionArrow(canvas, width - height + 1, 1, height-2, height-2, 1); Canvas.EndDraw; end; @@ -141,9 +174,18 @@ begin inherited Create(AOwner); FBackgroundColor := clBoxColor; FDropDownCount := 8; + FWidth := 120; + Height := 23; +end; + +procedure TfpgCustomComboBox.AfterConstruction; +begin + inherited AfterConstruction; + if not Assigned(FInternalBtn) then begin - FInternalBtn := CreateButton(self, Width - min(Height, 20) - 3, 2, Height - 4, '', @InternalBtnClick); + FInternalBtn := CreateButton(self, (Width-19), 2, 18, '', @InternalBtnClick); + FInternalBtn.Height := 19; FInternalBtn.Embedded := True; FInternalBtn.Parent := self; FInternalBtn.ImageName := 'sys.sb.down'; |