mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 17:55:55 +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 = interface(ICommonCallback)
|
||||
procedure SelectionChanged;
|
||||
end;
|
||||
|
||||
{ IWindowCallback }
|
||||
@ -557,6 +556,8 @@ type
|
||||
|
||||
{ TListView }
|
||||
|
||||
{ TCocoaTableListView }
|
||||
|
||||
TCocoaTableListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol)
|
||||
public
|
||||
ListView: TCustomListView; // just reference, don't release
|
||||
@ -572,8 +573,9 @@ type
|
||||
procedure lclClearCallback; override;
|
||||
|
||||
// Own methods, mostly convenience methods
|
||||
procedure setStringValue_forTableColumn_row(AStr: NSString; col, row: NSInteger); message 'setStringValue:forTableColumn:row:';
|
||||
procedure setListViewStringValue_forTableColumn_row(AStr: NSString; col, row: NSInteger); message 'setListViewStringValue:forTableColumn:row:';
|
||||
procedure setStringValue_forCol_row(AStr: NSString; col, row: NSInteger); message 'setStringValue:forCol: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:';
|
||||
procedure reloadDataForRow_column(ARow, ACol: NSInteger); message 'reloadDataForRow:column:';
|
||||
|
||||
@ -2372,7 +2374,7 @@ begin
|
||||
inherited resetCursorRects;
|
||||
end;
|
||||
|
||||
procedure TCocoaTableListView.setStringValue_forTableColumn_row(
|
||||
procedure TCocoaTableListView.setStringValue_forCol_row(
|
||||
AStr: NSString; col, row: NSInteger);
|
||||
var
|
||||
lStringList: TStringList;
|
||||
@ -2418,7 +2420,16 @@ begin
|
||||
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);
|
||||
var
|
||||
lSubItems: TStrings;
|
||||
@ -2567,8 +2578,8 @@ begin
|
||||
|
||||
lColumnIndex := getIndexOfColumn(tableColumn);
|
||||
|
||||
setListViewStringValue_forTableColumn_row(lNewValue, lColumnIndex, row);
|
||||
setStringValue_forTableColumn_row(lNewValue, lColumnIndex, row);
|
||||
setListViewStringValue_forCol_row(lNewValue, lColumnIndex, row);
|
||||
setStringValue_forCol_row(lNewValue, lColumnIndex, row);
|
||||
reloadDataForRow_column(lColumnIndex, row);
|
||||
end;
|
||||
|
||||
@ -2578,9 +2589,42 @@ begin
|
||||
end;
|
||||
|
||||
procedure TCocoaTableListView.tableViewSelectionDidChange(notification: NSNotification);
|
||||
var
|
||||
Msg: TLMNotify;
|
||||
NMLV: TNMListView;
|
||||
OldSel, NewSel: Integer;
|
||||
begin
|
||||
if Assigned(callback) then
|
||||
callback.SelectionChanged;
|
||||
{$IFDEF COCOA_DEBUG_LISTVIEW}
|
||||
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;
|
||||
|
||||
{ TCocoaStringList }
|
||||
|
@ -113,9 +113,9 @@ type
|
||||
//available in 10.7 only//class procedure EndUpdate(const ALV: TCustomListView); 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;
|
||||
//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 GetSelCount(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;
|
||||
end;
|
||||
|
||||
{ TLCLListViewCallback }
|
||||
|
||||
TLCLListViewCallback = class(TLCLCommonCallback, IListViewCallback)
|
||||
public
|
||||
procedure SelectionChanged; virtual;
|
||||
end;
|
||||
TLCLListViewCallBackClass = class of TLCLListViewCallback;
|
||||
|
||||
@ -597,11 +594,16 @@ end;
|
||||
|
||||
class procedure TCocoaWSCustomListView.ItemDelete(const ALV: TCustomListView;
|
||||
const AIndex: Integer);
|
||||
var
|
||||
lTableLV: TCocoaTableListView;
|
||||
lStr: NSString;
|
||||
begin
|
||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||
WriteLn(Format('[TCocoaWSCustomListView.ItemDelete] AIndex=%d', [AIndex]));
|
||||
{$ENDIF}
|
||||
inherited ItemDelete(ALV, AIndex);
|
||||
if not CheckParams(lTableLV, ALV) then Exit;
|
||||
lTableLV.deleteItemForRow(AIndex);
|
||||
lTableLV.reloadData();
|
||||
end;
|
||||
|
||||
class function TCocoaWSCustomListView.ItemDisplayRect(
|
||||
@ -643,7 +645,7 @@ begin
|
||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert] AIndex=%d', [AIndex]));
|
||||
{$ENDIF}
|
||||
CheckParams(lTableLV, ALV);
|
||||
if not CheckParams(lTableLV, ALV) then Exit;
|
||||
lColumnCount := lTableLV.tableColumns.count();
|
||||
{$IFDEF COCOA_DEBUG_TABCONTROL}
|
||||
WriteLn(Format('[TCocoaWSCustomListView.ItemInsert]=> lColumnCount=%d', [lColumnCount]));
|
||||
@ -658,7 +660,7 @@ begin
|
||||
else
|
||||
lStr := '';
|
||||
lNSStr := NSStringUTF8(lStr);
|
||||
lTableLV.setStringValue_forTableColumn_row(lNSStr, i, AIndex);
|
||||
lTableLV.setStringValue_forCol_row(lNSStr, i, AIndex);
|
||||
lNSStr.release;
|
||||
end;
|
||||
lTableLV.reloadData();
|
||||
@ -672,9 +674,9 @@ var
|
||||
lTableLV: TCocoaTableListView;
|
||||
lStr: NSString;
|
||||
begin
|
||||
CheckParams(lTableLV, ALV);
|
||||
if not CheckParams(lTableLV, ALV) then Exit;
|
||||
lStr := NSStringUTF8(AText);
|
||||
lTableLV.setStringValue_forTableColumn_row(lStr, ASubIndex, AItem.Index);
|
||||
lTableLV.setStringValue_forCol_row(lStr, ASubIndex, AItem.Index);
|
||||
lStr.release;
|
||||
end;
|
||||
|
||||
@ -684,12 +686,23 @@ begin
|
||||
inherited ItemShow(ALV, AIndex, AItem, PartialOK);
|
||||
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;
|
||||
const AProp: TListViewProperty; const AIsSet: Boolean);
|
||||
var
|
||||
lTableLV: TCocoaTableListView;
|
||||
begin
|
||||
CheckParams(lTableLV, ALV);
|
||||
if not CheckParams(lTableLV, ALV) then Exit;
|
||||
case AProp of
|
||||
{lvpAutoArrange,
|
||||
lvpCheckboxes,}
|
||||
@ -810,11 +823,4 @@ begin
|
||||
inherited resetCursorRects;
|
||||
end;
|
||||
|
||||
{ TLCLListViewCallback }
|
||||
|
||||
procedure TLCLListViewCallback.SelectionChanged;
|
||||
begin
|
||||
SendSimpleMessage(Target, LM_SELCHANGE);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user