From 28da3cef35877a595cc36c694a13984698ac32fb Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 11 Jan 2004 11:57:54 +0000 Subject: [PATCH] implemented TCustomListBox.ItemRect for gtk1 intf git-svn-id: trunk@5047 - --- lcl/include/customlistbox.inc | 25 +++++++++++ lcl/include/intfbaselcl.inc | 10 +++++ lcl/include/lclintf.inc | 9 ++++ lcl/include/lclintfh.inc | 4 ++ lcl/interfaces/gtk/gtklclintf.inc | 72 +++++++++++++++++++++++++++++- lcl/interfaces/gtk/gtklclintfh.inc | 4 ++ lcl/stdctrls.pp | 4 ++ 7 files changed, 127 insertions(+), 1 deletion(-) diff --git a/lcl/include/customlistbox.inc b/lcl/include/customlistbox.inc index aa845f1a11..daa4ded20f 100644 --- a/lcl/include/customlistbox.inc +++ b/lcl/include/customlistbox.inc @@ -437,12 +437,19 @@ end; {------------------------------------------------------------------------------ procedure TCustomListBox.Clear + + Delete all items. ------------------------------------------------------------------------------} procedure TCustomListBox.Clear; begin FItems.Clear; end; +{------------------------------------------------------------------------------ + function TCustomListBox.GetIndexAtY(Y: integer): integer; + + Returns item index at y coordinate (including scrolling) +------------------------------------------------------------------------------} function TCustomListBox.GetIndexAtY(Y: integer): integer; begin Result:=-1; @@ -450,5 +457,23 @@ begin Result:=GetListBoxIndexAtY(Self, Y); end; +{------------------------------------------------------------------------------ + function TCustomListBox.ItemRect(Index: Integer): TRect; + + Returns coordinates of an item (including scrolling) + Special: If Index=Count the rectangle is guessed (like VCL). +------------------------------------------------------------------------------} +function TCustomListBox.ItemRect(Index: Integer): TRect; +begin + if (Index>=0) and (Index0) then begin + GetListBoxItemRect(Self,Index-1,Result); + OffsetRect(Result,0,Result.Bottom-Result.Top); + end else begin + FillChar(Result,SizeOf(Result),0); + end; +end; + // back to stdctrls.pp diff --git a/lcl/include/intfbaselcl.inc b/lcl/include/intfbaselcl.inc index b6e958b2c8..795c1c61c4 100644 --- a/lcl/include/intfbaselcl.inc +++ b/lcl/include/intfbaselcl.inc @@ -172,6 +172,13 @@ begin Result := -1; end; +function TInterfaceBase.GetListBoxItemRect(ListBox: TComponent; Index: integer; + var ARect: TRect): boolean; +begin + FillChar(ARect,SizeOf(ARect),0); + Result:=false; +end; + function TInterfaceBase.GetNotebookTabIndexAtPos(Handle: HWND; const ClientPos: TPoint): integer; begin @@ -502,6 +509,9 @@ end; { ============================================================================= $Log$ + Revision 1.10 2004/01/11 11:57:54 mattias + implemented TCustomListBox.ItemRect for gtk1 intf + Revision 1.9 2004/01/10 18:00:42 mattias fixed GetWindowOrgEx, added GetDCOriginRelativeToWindow diff --git a/lcl/include/lclintf.inc b/lcl/include/lclintf.inc index 44de48b227..74653e645c 100644 --- a/lcl/include/lclintf.inc +++ b/lcl/include/lclintf.inc @@ -184,6 +184,12 @@ begin Result := InterfaceObject.GetListBoxIndexAtY(ListBox, y); end; +function GetListBoxItemRect(ListBox: TComponent; Index: integer; + var ARect: TRect): boolean; +begin + Result := InterfaceObject.GetListBoxItemRect(ListBox,Index,ARect); +end; + function GetNotebookTabIndexAtPos(Handle: HWND; const ClientPos: TPoint): integer; begin @@ -485,6 +491,9 @@ end; { ============================================================================= $Log$ + Revision 1.9 2004/01/11 11:57:54 mattias + implemented TCustomListBox.ItemRect for gtk1 intf + Revision 1.8 2004/01/10 18:00:42 mattias fixed GetWindowOrgEx, added GetDCOriginRelativeToWindow diff --git a/lcl/include/lclintfh.inc b/lcl/include/lclintfh.inc index cd21bb6d66..44c92523f5 100644 --- a/lcl/include/lclintfh.inc +++ b/lcl/include/lclintfh.inc @@ -65,6 +65,7 @@ function GetDesignerDC(WindowHandle: HWND): HDC; {$IFDEF IF_BASE_MEMBER}virtual; function GetDeviceRawImageDescription(DC: HDC; Desc: PRawImageDescription): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function GetDeviceSize(DC: HDC; var p: TPoint): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function GetListBoxIndexAtY(ListBox: TComponent; y: integer): integer; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} +function GetListBoxItemRect(ListBox: TComponent; Index: integer; var ARect: TRect): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function GetNotebookTabIndexAtPos(Handle: HWND; const ClientPos: TPoint): integer; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function GetRawImageFromDevice(SrcDC: HDC; const SrcRect: TRect; var NewRawImage: TRawImage): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function GetRawImageFromBitmap(SrcBitmap, SrcMaskBitmap: HBITMAP; const SrcRect: TRect; var NewRawImage: TRawImage): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} @@ -148,6 +149,9 @@ procedure RaiseLastOSError; { ============================================================================= $Log$ + Revision 1.9 2004/01/11 11:57:54 mattias + implemented TCustomListBox.ItemRect for gtk1 intf + Revision 1.8 2004/01/10 18:00:42 mattias fixed GetWindowOrgEx, added GetDCOriginRelativeToWindow diff --git a/lcl/interfaces/gtk/gtklclintf.inc b/lcl/interfaces/gtk/gtklclintf.inc index 443000c0dd..e8ce916bd3 100644 --- a/lcl/interfaces/gtk/gtklclintf.inc +++ b/lcl/interfaces/gtk/gtklclintf.inc @@ -77,7 +77,8 @@ begin Result:=-1; if not (ListBox is TCustomListbox) then exit; - if TCustomListbox(ListBox).FCompStyle in [csListBox, csCheckListBox] then begin + if TCustomListbox(ListBox).FCompStyle in [csListBox, csCheckListBox] then + begin AWidget:=PGtkWidget(TCustomListbox(ListBox).Handle); ListWidget:=PGtkList(GetWidgetInfo(AWidget, True)^.ImplementationWidget); ScrolledWindow:=PGtkScrolledWindow(AWidget); @@ -100,6 +101,72 @@ begin end; {$EndIf} +{------------------------------------------------------------------------------ + function TGTKObject.GetListBoxItemRect(ListBox: TComponent; Index: integer; + var ARect: TRect): boolean; + + ------------------------------------------------------------------------------} +function TGTKObject.GetListBoxItemRect(ListBox: TComponent; Index: integer; + var ARect: TRect): boolean; +{$IFdef GTK2} +var + AWinControl: TWinControl; +begin + Result:=false; + FillChar(ARect,SizeOf(ARect),0); + if not (ListBox is TWinControl) then exit; + AWinControl:=TWinControl(ListBox); + case AWinControl.fCompStyle of + + csListBox, csCheckListBox: + begin + // ToDo + end; + end; +end; +{$Else} +var + ScrolledWindow: PGtkScrolledWindow; + VertAdj: PGTKAdjustment; + AdjValue: integer; + ListWidget: PGtkList; + AWidget: PGtkWidget; + GListItem: PGList; + ListItemWidget: PGtkWidget; +begin + Result:=false; + FillChar(ARect,SizeOf(ARect),0); + if not (ListBox is TCustomListbox) then exit; + + if TCustomListbox(ListBox).FCompStyle in [csListBox, csCheckListBox] then + begin + AWidget:=PGtkWidget(TCustomListbox(ListBox).Handle); + ListWidget:=PGtkList(GetWidgetInfo(AWidget, True)^.ImplementationWidget); + ScrolledWindow:=PGtkScrolledWindow(AWidget); + VertAdj:=gtk_scrolled_window_get_vadjustment(ScrolledWindow); + if VertAdj=nil then + AdjValue:=0 + else + AdjValue:= (-round(VertAdj^.value)); + GListItem:=ListWidget^.children; + while GListItem<>nil do begin + ListItemWidget:=PGtkWidget(GListItem^.data); + if Index=0 then begin + ARect.Left:=0; + ARect.Top:=AdjValue; + ARect.Right:=ListItemWidget^.Allocation.Width; + ARect.Bottom:=ARect.Top+ListItemWidget^.Allocation.Height; + Result:=true; + exit; + end; + inc(AdjValue,ListItemWidget^.Allocation.Height); + dec(Index); + GListItem:=GListItem^.next; + end; + end; +end; +{$EndIf} + {------------------------------------------------------------------------------ Function: LCLCheckMenuItem Params: BaseMenuItem @@ -231,6 +298,9 @@ end; { ============================================================================= $Log$ + Revision 1.8 2004/01/11 11:57:54 mattias + implemented TCustomListBox.ItemRect for gtk1 intf + Revision 1.7 2004/01/09 20:03:13 mattias implemented new statusbar methods in gtk intf diff --git a/lcl/interfaces/gtk/gtklclintfh.inc b/lcl/interfaces/gtk/gtklclintfh.inc index 3d37c69a32..46fa3c1a71 100644 --- a/lcl/interfaces/gtk/gtklclintfh.inc +++ b/lcl/interfaces/gtk/gtklclintfh.inc @@ -31,6 +31,7 @@ //##apiwiz##sps## // Do not remove function GetListBoxIndexAtY(ListBox: TComponent; y: integer): integer; override; +function GetListBoxItemRect(ListBox: TComponent; Index: integer; var ARect: TRect): boolean; override; function LCLCheckMenuItem(BaseMenuItem: TComponent): Boolean; override; function LCLEnableMenuItem(BaseMenuItem: TComponent): Boolean; override; @@ -46,6 +47,9 @@ procedure StatusBarSetStyle(StatusBar: TObject); override; { ============================================================================= $Log$ + Revision 1.7 2004/01/11 11:57:54 mattias + implemented TCustomListBox.ItemRect for gtk1 intf + Revision 1.6 2004/01/09 20:03:13 mattias implemented new statusbar methods in gtk intf diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 78c7827f7e..c4708b3afe 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -383,6 +383,7 @@ type constructor Create(AOwner : TComponent); override; destructor Destroy; override; function GetIndexAtY(Y: integer): integer; + function ItemRect(Index: Integer): TRect; procedure Clear; public property BorderStyle : TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle; @@ -1466,6 +1467,9 @@ end. { ============================================================================= $Log$ + Revision 1.115 2004/01/11 11:57:54 mattias + implemented TCustomListBox.ItemRect for gtk1 intf + Revision 1.114 2004/01/06 17:58:06 mattias fixed setting TRadioButton.Caption for gtk