mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 08:40:23 +02:00
cocoa: bug #28784 - Many improvements to TListBox in Cocoa
git-svn-id: trunk@52541 -
This commit is contained in:
parent
d6c8fdd305
commit
86397bb4fb
@ -208,7 +208,13 @@ var
|
|||||||
messageText: NSString;
|
messageText: NSString;
|
||||||
I: Integer;
|
I: Integer;
|
||||||
aButton: NSButton;
|
aButton: NSButton;
|
||||||
|
Str: string;
|
||||||
begin
|
begin
|
||||||
|
{Str := 'TCocoaWidgetSet.PromptUser DialogCaption: ' + DialogCaption +
|
||||||
|
' DialogMessage: ' + DialogMessage + ' DialogType: ' + DbgS(DialogType) +
|
||||||
|
' ButtonCount: ' + DbgS(ButtonCount) + ' DefaultIndex: ' +
|
||||||
|
DbgS(DefaultIndex) + ' EscapeResult: ' + DbgS(EscapeResult);
|
||||||
|
Result := -1;}
|
||||||
{$IFDEF VerboseLCLIntf}
|
{$IFDEF VerboseLCLIntf}
|
||||||
DebugLn('TCocoaWidgetSet.PromptUser DialogCaption: ' + DialogCaption +
|
DebugLn('TCocoaWidgetSet.PromptUser DialogCaption: ' + DialogCaption +
|
||||||
' DialogMessage: ' + DialogMessage + ' DialogType: ' + DbgS(DialogType) +
|
' DialogMessage: ' + DialogMessage + ' DialogType: ' + DbgS(DialogType) +
|
||||||
|
@ -8,7 +8,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
classes,
|
classes,
|
||||||
MacOSAll, CocoaAll,
|
MacOSAll, CocoaAll,
|
||||||
Types, LCLType, LCLProc, menus;
|
Types, LCLType, LCLProc, menus, forms, controls;
|
||||||
|
|
||||||
const
|
const
|
||||||
LCLEventSubTypeMessage = MaxShort - 1;
|
LCLEventSubTypeMessage = MaxShort - 1;
|
||||||
@ -40,6 +40,7 @@ function NSRectToRect(const NS: NSRect): TRect;
|
|||||||
|
|
||||||
procedure NSToLCLRect(const ns: NSRect; ParentHeight: Single; out lcl: TRect);
|
procedure NSToLCLRect(const ns: NSRect; ParentHeight: Single; out lcl: TRect);
|
||||||
procedure LCLToNSRect(const lcl: TRect; ParentHeight: Single; out ns: NSRect);
|
procedure LCLToNSRect(const lcl: TRect; ParentHeight: Single; out ns: NSRect);
|
||||||
|
function LCLCoordsToCocoa(AControl: TControl; X, Y: Integer): NSPoint;
|
||||||
|
|
||||||
function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
||||||
|
|
||||||
@ -357,6 +358,12 @@ begin
|
|||||||
ns.size.height:=lcl.Bottom-lcl.Top;
|
ns.size.height:=lcl.Bottom-lcl.Top;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function LCLCoordsToCocoa(AControl: TControl; X, Y: Integer): NSPoint;
|
||||||
|
begin
|
||||||
|
Result.x := X;
|
||||||
|
Result.y := Screen.Height - Y;
|
||||||
|
if AControl <> nil then Result.y := Result.y - AControl.Height;
|
||||||
|
end;
|
||||||
|
|
||||||
function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
function CreateParamsToNSRect(const params: TCreateParams): NSRect;
|
||||||
begin
|
begin
|
||||||
|
@ -585,13 +585,6 @@ end;
|
|||||||
|
|
||||||
{ TCocoaWSPopupMenu }
|
{ TCocoaWSPopupMenu }
|
||||||
|
|
||||||
function LCLCoordsToCocoa(AControl: TControl; X, Y: Integer): NSPoint;
|
|
||||||
begin
|
|
||||||
Result.x := X;
|
|
||||||
Result.y := Screen.Height - Y;
|
|
||||||
if AControl <> nil then Result.y := Result.y - AControl.Height;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TCocoaWSPopupMenu.Popup
|
Method: TCocoaWSPopupMenu.Popup
|
||||||
Params: APopupMenu - LCL popup menu
|
Params: APopupMenu - LCL popup menu
|
||||||
|
@ -94,22 +94,22 @@ type
|
|||||||
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
||||||
published
|
published
|
||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
{class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override; }
|
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
|
||||||
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
|
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
|
||||||
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
|
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
|
||||||
{ class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
|
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
|
||||||
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;}
|
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
|
||||||
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
|
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
|
||||||
{class function GetTopIndex(const ACustomListBox: TCustomListBox): integer; override;
|
class function GetTopIndex(const ACustomListBox: TCustomListBox): integer; override;
|
||||||
|
|
||||||
class procedure SelectItem(const ACustomListBox: TCustomListBox; AIndex: integer; ASelected: boolean); override;
|
class procedure SelectItem(const ACustomListBox: TCustomListBox; AIndex: integer; ASelected: boolean); override;
|
||||||
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
//class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
||||||
//class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
|
//class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
|
||||||
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
|
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
|
||||||
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean); override;
|
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean); override;
|
||||||
class procedure SetStyle(const ACustomListBox: TCustomListBox); override;
|
{class procedure SetStyle(const ACustomListBox: TCustomListBox); override;
|
||||||
class procedure SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); override;
|
class procedure SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); override;}
|
||||||
class procedure SetTopIndex(const ACustomListBox: TCustomListBox; const NewTopIndex: integer); override;}
|
class procedure SetTopIndex(const ACustomListBox: TCustomListBox; const NewTopIndex: integer); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomEdit }
|
{ TCocoaWSCustomEdit }
|
||||||
@ -1157,6 +1157,7 @@ class function TCocoaWSCustomListBox.CreateHandle(const AWinControl:TWinControl;
|
|||||||
var
|
var
|
||||||
list : TCocoaListBox;
|
list : TCocoaListBox;
|
||||||
scroll : TCocoaScrollView;
|
scroll : TCocoaScrollView;
|
||||||
|
lclListBox: TCustomListBox absolute AWinControl;
|
||||||
begin
|
begin
|
||||||
list := NSView(TCocoaListBox.alloc).lclInitWithCreateParams(AParams);
|
list := NSView(TCocoaListBox.alloc).lclInitWithCreateParams(AParams);
|
||||||
if not Assigned(list) then
|
if not Assigned(list) then
|
||||||
@ -1170,7 +1171,7 @@ begin
|
|||||||
list.setHeaderView(nil);
|
list.setHeaderView(nil);
|
||||||
list.setDataSource(list);
|
list.setDataSource(list);
|
||||||
list.setDelegate(list);
|
list.setDelegate(list);
|
||||||
|
list.setAllowsMultipleSelection(lclListBox.MultiSelect);
|
||||||
|
|
||||||
scroll := EmbedInScrollView(list);
|
scroll := EmbedInScrollView(list);
|
||||||
if not Assigned(scroll) then
|
if not Assigned(scroll) then
|
||||||
@ -1185,52 +1186,127 @@ begin
|
|||||||
Result := TLCLIntfHandle(scroll);
|
Result := TLCLIntfHandle(scroll);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomListBox.GetStrings(const ACustomListBox: TCustomListBox):TStrings;
|
class function TCocoaWSCustomListBox.GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer;
|
||||||
var
|
var
|
||||||
view : TCocoaListBox;
|
list: TCocoaListBox;
|
||||||
|
lPoint: NSPoint;
|
||||||
begin
|
begin
|
||||||
view:=GetListBox(ACustomListBox);
|
list := GetListBox(ACustomListBox);
|
||||||
if not Assigned(view) then
|
if not Assigned(list) then Exit();
|
||||||
Result:=nil
|
lPoint := LCLCoordsToCocoa(ACustomListBox, X, Y);
|
||||||
else
|
Result := list.rowAtPoint(lPoint);
|
||||||
Result:=view.list;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomListBox.GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean;
|
class function TCocoaWSCustomListBox.GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean;
|
||||||
var view : TCocoaListBox;
|
var
|
||||||
|
view: TCocoaListBox;
|
||||||
r:NSRect;
|
r:NSRect;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
view:=GetListBox(ACustomListBox);
|
view := GetListBox(ACustomListBox);
|
||||||
if not Assigned(view) then
|
if not Assigned(view) then Exit(False);
|
||||||
begin
|
|
||||||
Result:=false;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
r:=view.frameOfCellAtColumn_row(0,index);
|
r:=view.frameOfCellAtColumn_row(0,index);
|
||||||
Arect:=NSRectToRect(r);
|
Arect:=NSRectToRect(r);
|
||||||
Result := True;
|
Result := True;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomListBox.GetItemIndex(const ACustomListBox: TCustomListBox): integer;
|
class function TCocoaWSCustomListBox.GetItemIndex(const ACustomListBox: TCustomListBox): integer;
|
||||||
var
|
var
|
||||||
view : TCocoaListBox;
|
view: TCocoaListBox;
|
||||||
indexset: NSIndexSet;
|
indexset: NSIndexSet;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
view:=GetListBox(ACustomListBox);
|
view:=GetListBox(ACustomListBox);
|
||||||
if not Assigned(view) then
|
if not Assigned(view) then Exit(-1);
|
||||||
begin
|
|
||||||
Result:=-1;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
indexset:=view.selectedRowIndexes();
|
indexset:=view.selectedRowIndexes();
|
||||||
result:=indexset.firstIndex;
|
result:=indexset.firstIndex;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListBox.GetSelCount(const ACustomListBox: TCustomListBox): integer;
|
||||||
|
var
|
||||||
|
view: TCocoaListBox;
|
||||||
|
selection: NSIndexSet;
|
||||||
|
begin
|
||||||
|
view := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(view) then Exit(0);
|
||||||
|
selection := view.selectedRowIndexes();
|
||||||
|
Result := selection.count();
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListBox.GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean;
|
||||||
|
var
|
||||||
|
view: TCocoaListBox;
|
||||||
|
selection: NSIndexSet;
|
||||||
|
begin
|
||||||
|
view := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(view) then Exit(False);
|
||||||
|
if AIndex < 0 then Exit(False);
|
||||||
|
selection := view.selectedRowIndexes();
|
||||||
|
Result := selection.containsIndex(AIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListBox.GetStrings(const ACustomListBox: TCustomListBox):TStrings;
|
||||||
|
var
|
||||||
|
view: TCocoaListBox;
|
||||||
|
begin
|
||||||
|
view := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(view) then Exit(nil);
|
||||||
|
Result := view.list;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListBox.GetTopIndex(const ACustomListBox: TCustomListBox): integer;
|
||||||
|
var
|
||||||
|
view: TCocoaListBox;
|
||||||
|
visibleRect: NSRect;
|
||||||
|
visibleRange: NSRange;
|
||||||
|
begin
|
||||||
|
view := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(view) then Exit(-1);
|
||||||
|
visibleRect := view.visibleRect();
|
||||||
|
visibleRange := view.rowsInRect(visibleRect);
|
||||||
|
Result := visibleRange.location;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCocoaWSCustomListBox.SelectItem(const ACustomListBox: TCustomListBox; AIndex: integer; ASelected: boolean);
|
||||||
|
var
|
||||||
|
list: TCocoaListBox;
|
||||||
|
begin
|
||||||
|
list := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(list) then Exit();
|
||||||
|
if ASelected then
|
||||||
|
list.selectRow_byExtendingSelection(AIndex, True)
|
||||||
|
else
|
||||||
|
list.deselectRow(AIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCocoaWSCustomListBox.SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer);
|
||||||
|
var
|
||||||
|
list: TCocoaListBox;
|
||||||
|
begin
|
||||||
|
list := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(list) then Exit();
|
||||||
|
list.selectRow_byExtendingSelection(AIndex, False);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCocoaWSCustomListBox.SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean);
|
||||||
|
var
|
||||||
|
list: TCocoaListBox;
|
||||||
|
begin
|
||||||
|
list := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(list) then Exit();
|
||||||
|
list.setAllowsMultipleSelection(AMultiSelect);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TCocoaWSCustomListBox.SetTopIndex(const ACustomListBox: TCustomListBox; const NewTopIndex: integer);
|
||||||
|
var
|
||||||
|
view: TCocoaListBox;
|
||||||
|
begin
|
||||||
|
view := GetListBox(ACustomListBox);
|
||||||
|
if not Assigned(view) then Exit();
|
||||||
|
view.scrollRowToVisible(NewTopIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user