mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 03:56:12 +02:00
cocoa: Starts implementing ListView selection event and item deletion
git-svn-id: trunk@44885 -
This commit is contained in:
parent
aacb2aa6cf
commit
a2ff0824a2
@ -163,7 +163,6 @@ type
|
|||||||
{ IListViewCallBack }
|
{ IListViewCallBack }
|
||||||
|
|
||||||
IListViewCallBack = interface(ICommonCallback)
|
IListViewCallBack = interface(ICommonCallback)
|
||||||
procedure SelectionChanged;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ IWindowCallback }
|
{ IWindowCallback }
|
||||||
@ -557,6 +556,8 @@ type
|
|||||||
|
|
||||||
{ TListView }
|
{ TListView }
|
||||||
|
|
||||||
|
{ TCocoaTableListView }
|
||||||
|
|
||||||
TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol)
|
TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol)
|
||||||
public
|
public
|
||||||
ListView: TCustomListView; // just reference, don't release
|
ListView: TCustomListView; // just reference, don't release
|
||||||
@ -572,8 +573,9 @@ type
|
|||||||
procedure lclClearCallback; override;
|
procedure lclClearCallback; override;
|
||||||
|
|
||||||
// Own methods, mostly convenience methods
|
// Own methods, mostly convenience methods
|
||||||
procedure setStringValue_forTableColumn_row(AStr: NSString; col, row: NSInteger); message 'setStringValue:forTableColumn:row:';
|
procedure setStringValue_forCol_row(AStr: NSString; col, row: NSInteger); message 'setStringValue:forCol:row:';
|
||||||
procedure setListViewStringValue_forTableColumn_row(AStr: NSString; col, row: NSInteger); message 'setListViewStringValue:forTableColumn:row:';
|
procedure deleteItemForRow(row: NSInteger); message 'deleteItemForRow:';
|
||||||
|
procedure setListViewStringValue_forCol_row(AStr: NSString; col, row: NSInteger); message 'setListViewStringValue:forCol:row:';
|
||||||
function getIndexOfColumn(ACol: NSTableColumn): NSInteger; message 'getIndexOfColumn:';
|
function getIndexOfColumn(ACol: NSTableColumn): NSInteger; message 'getIndexOfColumn:';
|
||||||
procedure reloadDataForRow_column(ARow, ACol: NSInteger); message 'reloadDataForRow:column:';
|
procedure reloadDataForRow_column(ARow, ACol: NSInteger); message 'reloadDataForRow:column:';
|
||||||
|
|
||||||
@ -2372,7 +2374,7 @@ begin
|
|||||||
inherited resetCursorRects;
|
inherited resetCursorRects;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaTableListView.setStringValue_forTableColumn_row(
|
procedure TCocoaTableListView.setStringValue_forCol_row(
|
||||||
AStr: NSString; col, row: NSInteger);
|
AStr: NSString; col, row: NSInteger);
|
||||||
var
|
var
|
||||||
lStringList: TStringList;
|
lStringList: TStringList;
|
||||||
@ -2418,7 +2420,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaTableListView.setListViewStringValue_forTableColumn_row(
|
procedure TCocoaTableListView.deleteItemForRow(row: NSInteger);
|
||||||
|
var
|
||||||
|
lStringList: TStringList;
|
||||||
|
begin
|
||||||
|
lStringList := TStringList(Items.Objects[row]);
|
||||||
|
if lStringList <> nil then lStringList.Free;
|
||||||
|
Items.Delete(row);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTableListView.setListViewStringValue_forCol_row(
|
||||||
AStr: NSString; col, row: NSInteger);
|
AStr: NSString; col, row: NSInteger);
|
||||||
var
|
var
|
||||||
lSubItems: TStrings;
|
lSubItems: TStrings;
|
||||||
@ -2567,8 +2578,8 @@ begin
|
|||||||
|
|
||||||
lColumnIndex := getIndexOfColumn(tableColumn);
|
lColumnIndex := getIndexOfColumn(tableColumn);
|
||||||
|
|
||||||
setListViewStringValue_forTableColumn_row(lNewValue, lColumnIndex, row);
|
setListViewStringValue_forCol_row(lNewValue, lColumnIndex, row);
|
||||||
setStringValue_forTableColumn_row(lNewValue, lColumnIndex, row);
|
setStringValue_forCol_row(lNewValue, lColumnIndex, row);
|
||||||
reloadDataForRow_column(lColumnIndex, row);
|
reloadDataForRow_column(lColumnIndex, row);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2578,9 +2589,42 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaTableListView.tableViewSelectionDidChange(notification: NSNotification);
|
procedure TCocoaTableListView.tableViewSelectionDidChange(notification: NSNotification);
|
||||||
|
var
|
||||||
|
Msg: TLMNotify;
|
||||||
|
NMLV: TNMListView;
|
||||||
|
OldSel, NewSel: Integer;
|
||||||
begin
|
begin
|
||||||
if Assigned(callback) then
|
{$IFDEF COCOA_DEBUG_LISTVIEW}
|
||||||
callback.SelectionChanged;
|
WriteLn('[TLCLListViewCallback.SelectionChanged]');
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
NewSel := Self.selectedRow();
|
||||||
|
|
||||||
|
FillChar(Msg{%H-}, SizeOf(Msg), #0);
|
||||||
|
FillChar(NMLV{%H-}, SizeOf(NMLV), #0);
|
||||||
|
|
||||||
|
Msg.Msg := CN_NOTIFY;
|
||||||
|
|
||||||
|
NMLV.hdr.hwndfrom := ListView.Handle;
|
||||||
|
NMLV.hdr.code := LVN_ITEMCHANGED;
|
||||||
|
NMLV.iSubItem := 0;
|
||||||
|
NMLV.uChanged := LVIF_STATE;
|
||||||
|
Msg.NMHdr := @NMLV.hdr;
|
||||||
|
|
||||||
|
// If there was something previously selected:
|
||||||
|
{ if ListView.Selected <> nil then
|
||||||
|
begin
|
||||||
|
OldSel := ListView.Selected.Index;
|
||||||
|
NMLV.iItem := OldSel;
|
||||||
|
NMLV.uNewState := 0;
|
||||||
|
NMLV.uOldState := LVIS_SELECTED;
|
||||||
|
LCLMessageGlue.DeliverMessage(ListView, Msg);
|
||||||
|
end;}
|
||||||
|
|
||||||
|
// Now the new selection
|
||||||
|
NMLV.iItem := NewSel;
|
||||||
|
NMLV.uNewState := LVIS_SELECTED;
|
||||||
|
LCLMessageGlue.DeliverMessage(ListView, Msg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaStringList }
|
{ TCocoaStringList }
|
||||||
|
@ -113,9 +113,9 @@ type
|
|||||||
//available in 10.7 only//class procedure EndUpdate(const ALV: TCustomListView); override;
|
//available in 10.7 only//class procedure EndUpdate(const ALV: TCustomListView); override;
|
||||||
|
|
||||||
(*class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
|
(*class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
|
||||||
//carbon//class function GetDropTarget(const ALV: TCustomListView): Integer; override;
|
//carbon//class function GetDropTarget(const ALV: TCustomListView): Integer; override;*)
|
||||||
class function GetFocused(const ALV: TCustomListView): Integer; override;
|
class function GetFocused(const ALV: TCustomListView): Integer; override;
|
||||||
//carbon//class function GetHoverTime(const ALV: TCustomListView): Integer; override;
|
(*//carbon//class function GetHoverTime(const ALV: TCustomListView): Integer; override;
|
||||||
class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
|
class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
|
||||||
class function GetSelCount(const ALV: TCustomListView): Integer; override;
|
class function GetSelCount(const ALV: TCustomListView): Integer; override;
|
||||||
//carbon//class function GetSelection(const ALV: TCustomListView): Integer; override;
|
//carbon//class function GetSelection(const ALV: TCustomListView): Integer; override;
|
||||||
@ -149,11 +149,8 @@ type
|
|||||||
class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
|
class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLCLListViewCallback }
|
|
||||||
|
|
||||||
TLCLListViewCallback = class(TLCLCommonCallback, IListViewCallback)
|
TLCLListViewCallback = class(TLCLCommonCallback, IListViewCallback)
|
||||||
public
|
public
|
||||||
procedure SelectionChanged; virtual;
|
|
||||||
end;
|
end;
|
||||||
TLCLListViewCallBackClass = class of TLCLListViewCallback;
|
TLCLListViewCallBackClass = class of TLCLListViewCallback;
|
||||||
|
|
||||||
@ -597,11 +594,16 @@ end;
|
|||||||
|
|
||||||
class procedure TCocoaWSCustomListView.ItemDelete(const ALV: TCustomListView;
|
class procedure TCocoaWSCustomListView.ItemDelete(const ALV: TCustomListView;
|
||||||
const AIndex: Integer);
|
const AIndex: Integer);
|
||||||
|
var
|
||||||
|
lTableLV: TCocoaTableListView;
|
||||||
|
lStr: NSString;
|
||||||
begin
|
begin
|
||||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
WriteLn(Format('[TCocoaWSCustomListView.ItemDelete] AIndex=%d', [AIndex]));
|
WriteLn(Format('[TCocoaWSCustomListView.ItemDelete] AIndex=%d', [AIndex]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
inherited ItemDelete(ALV, AIndex);
|
if not CheckParams(lTableLV, ALV) then Exit;
|
||||||
|
lTableLV.deleteItemForRow(AIndex);
|
||||||
|
lTableLV.reloadData();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomListView.ItemDisplayRect(
|
class function TCocoaWSCustomListView.ItemDisplayRect(
|
||||||
@ -643,7 +645,7 @@ begin
|
|||||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex]));
|
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex]));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
CheckParams(lTableLV, ALV);
|
if not CheckParams(lTableLV, ALV) then Exit;
|
||||||
lColumnCount := lTableLV.tableColumns.count();
|
lColumnCount := lTableLV.tableColumns.count();
|
||||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount]));
|
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount]));
|
||||||
@ -658,7 +660,7 @@ begin
|
|||||||
else
|
else
|
||||||
lStr := '';
|
lStr := '';
|
||||||
lNSStr := NSStringUTF8(lStr);
|
lNSStr := NSStringUTF8(lStr);
|
||||||
lTableLV.setStringValue_forTableColumn_row(lNSStr, i, AIndex);
|
lTableLV.setStringValue_forCol_row(lNSStr, i, AIndex);
|
||||||
lNSStr.release;
|
lNSStr.release;
|
||||||
end;
|
end;
|
||||||
lTableLV.reloadData();
|
lTableLV.reloadData();
|
||||||
@ -672,9 +674,9 @@ var
|
|||||||
lTableLV: TCocoaTableListView;
|
lTableLV: TCocoaTableListView;
|
||||||
lStr: NSString;
|
lStr: NSString;
|
||||||
begin
|
begin
|
||||||
CheckParams(lTableLV, ALV);
|
if not CheckParams(lTableLV, ALV) then Exit;
|
||||||
lStr := NSStringUTF8(AText);
|
lStr := NSStringUTF8(AText);
|
||||||
lTableLV.setStringValue_forTableColumn_row(lStr, ASubIndex, AItem.Index);
|
lTableLV.setStringValue_forCol_row(lStr, ASubIndex, AItem.Index);
|
||||||
lStr.release;
|
lStr.release;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -684,12 +686,23 @@ begin
|
|||||||
inherited ItemShow(ALV, AIndex, AItem, PartialOK);
|
inherited ItemShow(ALV, AIndex, AItem, PartialOK);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListView.GetFocused(const ALV: TCustomListView): Integer;
|
||||||
|
var
|
||||||
|
lTableLV: TCocoaTableListView;
|
||||||
|
begin
|
||||||
|
if not CheckParams(lTableLV, ALV) then Exit;
|
||||||
|
Result := lTableLV.selectedRow;
|
||||||
|
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||||
|
WriteLn(Format('[TCocoaWSCustomListView.GetFocused] Result=%d', [Result]));
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomListView.SetProperty(const ALV: TCustomListView;
|
class procedure TCocoaWSCustomListView.SetProperty(const ALV: TCustomListView;
|
||||||
const AProp: TListViewProperty; const AIsSet: Boolean);
|
const AProp: TListViewProperty; const AIsSet: Boolean);
|
||||||
var
|
var
|
||||||
lTableLV: TCocoaTableListView;
|
lTableLV: TCocoaTableListView;
|
||||||
begin
|
begin
|
||||||
CheckParams(lTableLV, ALV);
|
if not CheckParams(lTableLV, ALV) then Exit;
|
||||||
case AProp of
|
case AProp of
|
||||||
{lvpAutoArrange,
|
{lvpAutoArrange,
|
||||||
lvpCheckboxes,}
|
lvpCheckboxes,}
|
||||||
@ -810,11 +823,4 @@ begin
|
|||||||
inherited resetCursorRects;
|
inherited resetCursorRects;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLCLListViewCallback }
|
|
||||||
|
|
||||||
procedure TLCLListViewCallback.SelectionChanged;
|
|
||||||
begin
|
|
||||||
SendSimpleMessage(Target, LM_SELCHANGE);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user