mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 22:40:15 +02:00
cocoa: redoing the fix for 30847 - instead of processing all items on every change of combobox item, just doing change whenever they are needed
git-svn-id: trunk@60970 -
This commit is contained in:
parent
73e6567b0f
commit
1fa1d582f2
@ -181,12 +181,11 @@ type
|
|||||||
protected
|
protected
|
||||||
FOwner: TCocoaComboBox;
|
FOwner: TCocoaComboBox;
|
||||||
FReadOnlyOwner: TCocoaReadOnlyComboBox;
|
FReadOnlyOwner: TCocoaReadOnlyComboBox;
|
||||||
FPreChangeListCount: Integer;
|
procedure InsertItem(Index: Integer; const S: string; O: TObject); override;
|
||||||
procedure Changed; override;
|
|
||||||
procedure Changing; override;
|
|
||||||
public
|
public
|
||||||
// Pass only 1 owner and nil for the other ones
|
// Pass only 1 owner and nil for the other ones
|
||||||
constructor Create(AOwner: TCocoaComboBox; AReadOnlyOwner: TCocoaReadOnlyComboBox);
|
constructor Create(AOwner: TCocoaComboBox; AReadOnlyOwner: TCocoaReadOnlyComboBox);
|
||||||
|
procedure Delete(Index: Integer); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IComboboxCallBack = interface(ICommonCallBack)
|
IComboboxCallBack = interface(ICommonCallBack)
|
||||||
@ -1110,65 +1109,58 @@ end;
|
|||||||
|
|
||||||
{ TCocoaComboBoxList }
|
{ TCocoaComboBoxList }
|
||||||
|
|
||||||
procedure TCocoaComboBoxList.Changed;
|
procedure TCocoaComboBoxList.InsertItem(Index: Integer; const S: string;
|
||||||
|
O: TObject);
|
||||||
var
|
var
|
||||||
i: Integer;
|
astr : NSString;
|
||||||
nsstr: NSString;
|
mn : NSMenuItem;
|
||||||
lItems: array of NSMenuItem;
|
menuItem : TCocoaReadOnlyView;
|
||||||
menuItem: TCocoaReadOnlyView;
|
|
||||||
track: NSTrackingArea;
|
track: NSTrackingArea;
|
||||||
begin
|
begin
|
||||||
if FOwner <> nil then
|
inherited InsertItem(Index, S, O);
|
||||||
fOwner.reloadData;
|
if FReadOnlyOwner =nil then Exit;
|
||||||
if FReadOnlyOwner <> nil then
|
|
||||||
|
// Adding an item with its final name will cause it to be deleted,
|
||||||
|
// so we need to first add all items with unique names, and then
|
||||||
|
// rename all of them, see bug 30847
|
||||||
|
astr := nsstr('@@@add');
|
||||||
|
if Index >= FReadOnlyOwner.numberOfItems then
|
||||||
begin
|
begin
|
||||||
// store the current item
|
FReadOnlyOwner.addItemWithTitle(astr);
|
||||||
FReadOnlyOwner.lastSelectedItemIndex := FReadOnlyOwner.indexOfSelectedItem;
|
Index := FReadOnlyOwner.numberOfItems-1;
|
||||||
|
end else
|
||||||
|
FReadOnlyOwner.insertItemWithTitle_atIndex(astr, Index);
|
||||||
|
|
||||||
FReadOnlyOwner.removeAllItems();
|
mn := FReadOnlyOwner.itemAtIndex(Index);
|
||||||
// Adding an item with its final name will cause it to be deleted,
|
if not Assigned(mn) then Exit;
|
||||||
// so we need to first add all items with unique names, and then
|
|
||||||
// rename all of them, see bug 30847
|
|
||||||
SetLength(lItems, Count);
|
|
||||||
for i := 0 to Count-1 do
|
|
||||||
begin
|
|
||||||
nsstr := NSStringUtf8(Format('unique_item_%d', [i]));
|
|
||||||
FReadOnlyOwner.addItemWithTitle(nsstr);
|
|
||||||
lItems[i] := FReadOnlyOwner.lastItem;
|
|
||||||
nsstr.release;
|
|
||||||
end;
|
|
||||||
for i := 0 to Count-1 do
|
|
||||||
begin
|
|
||||||
nsstr := NSStringUtf8(Strings[i]);
|
|
||||||
lItems[i].setTitle(nsstr);
|
|
||||||
if FReadOnlyOwner.isOwnerDrawn then
|
|
||||||
begin
|
|
||||||
menuItem := TCocoaReadOnlyView.alloc.initWithFrame( NSMakeRect(0,0, FReadOnlyOwner.frame.size.width, COMBOBOX_RO_MENUITEM_HEIGHT) );
|
|
||||||
menuItem.itemIndex := i;
|
|
||||||
menuItem.combobox := FReadOnlyOwner;
|
|
||||||
|
|
||||||
track:=NSTrackingArea(NSTrackingArea.alloc).initWithRect_options_owner_userInfo(
|
astr := NSStringUtf8(S);
|
||||||
menuItem.bounds
|
mn.setTitle(astr);
|
||||||
, NSTrackingMouseEnteredAndExited or NSTrackingActiveAlways
|
astr.release;
|
||||||
, menuItem, nil);
|
|
||||||
menuItem.addTrackingArea(track);
|
|
||||||
track.release;
|
|
||||||
lItems[i].setView(menuItem);
|
|
||||||
end;
|
|
||||||
|
|
||||||
nsstr.release;
|
if FReadOnlyOwner.isOwnerDrawn then
|
||||||
end;
|
begin
|
||||||
SetLength(lItems, 0);
|
menuItem := TCocoaReadOnlyView.alloc.initWithFrame( NSMakeRect(0,0, FReadOnlyOwner.frame.size.width, COMBOBOX_RO_MENUITEM_HEIGHT) );
|
||||||
|
menuItem.itemIndex := Index;
|
||||||
|
menuItem.combobox := FReadOnlyOwner;
|
||||||
|
|
||||||
// reset the selected item
|
track:=NSTrackingArea(NSTrackingArea.alloc).initWithRect_options_owner_userInfo(
|
||||||
FReadOnlyOwner.selectItemAtIndex(FReadOnlyOwner.lastSelectedItemIndex);
|
menuItem.bounds
|
||||||
|
, NSTrackingMouseEnteredAndExited or NSTrackingActiveAlways
|
||||||
|
, menuItem, nil);
|
||||||
|
menuItem.addTrackingArea(track);
|
||||||
|
track.release;
|
||||||
|
mn.setView(menuItem);
|
||||||
end;
|
end;
|
||||||
inherited Changed;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaComboBoxList.Changing;
|
procedure TCocoaComboBoxList.Delete(Index: Integer);
|
||||||
begin
|
begin
|
||||||
FPreChangeListCount := Count;
|
inherited Delete(Index);
|
||||||
|
if FReadOnlyOwner = nil then Exit;
|
||||||
|
if (Index>=0) and (Index < FReadOnlyOwner.numberOfItems) then
|
||||||
|
FReadOnlyOwner.removeItemAtIndex(Index);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCocoaComboBoxList.Create(AOwner: TCocoaComboBox; AReadOnlyOwner: TCocoaReadOnlyComboBox);
|
constructor TCocoaComboBoxList.Create(AOwner: TCocoaComboBox; AReadOnlyOwner: TCocoaReadOnlyComboBox);
|
||||||
|
Loading…
Reference in New Issue
Block a user