mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 21:20:46 +02:00
cocoa: splitting up comboboxlist box for ROCMB and CMB (oop approach). Implementing text change for RO item. #35607
git-svn-id: trunk@61257 -
This commit is contained in:
parent
0df144030a
commit
c33f7b3553
@ -175,17 +175,16 @@ type
|
|||||||
|
|
||||||
{ TCocoaComboBoxList }
|
{ TCocoaComboBoxList }
|
||||||
|
|
||||||
TCocoaComboBoxList = class(TStringList)
|
TCocoaComboBoxList = class(TStringList);
|
||||||
|
|
||||||
|
TCocoaEditComboBoxList = class(TCocoaComboBoxList)
|
||||||
protected
|
protected
|
||||||
FOwner: TCocoaComboBox;
|
FOwner: TCocoaComboBox;
|
||||||
FReadOnlyOwner: TCocoaReadOnlyComboBox;
|
|
||||||
procedure InsertItem(Index: Integer; const S: string; O: TObject); override;
|
procedure InsertItem(Index: Integer; const S: string; O: TObject); override;
|
||||||
procedure Changed; override;
|
procedure Changed; 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);
|
||||||
procedure Delete(Index: Integer); override;
|
|
||||||
procedure Clear; override;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IComboboxCallBack = interface(ICommonCallBack)
|
IComboboxCallBack = interface(ICommonCallBack)
|
||||||
@ -279,6 +278,20 @@ type
|
|||||||
procedure mouseExited(theEvent: NSEvent); override;
|
procedure mouseExited(theEvent: NSEvent); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaReadOnlyComboBoxList }
|
||||||
|
|
||||||
|
TCocoaReadOnlyComboBoxList = class(TCocoaComboBoxList)
|
||||||
|
protected
|
||||||
|
FOwner: TCocoaReadOnlyComboBox;
|
||||||
|
procedure InsertItem(Index: Integer; const S: string; O: TObject); override;
|
||||||
|
procedure Put(Index: Integer; const S: string); override;
|
||||||
|
public
|
||||||
|
// Pass only 1 owner and nil for the other ones
|
||||||
|
constructor Create(AOwner: TCocoaReadOnlyComboBox);
|
||||||
|
procedure Delete(Index: Integer); override;
|
||||||
|
procedure Clear; override;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaReadOnlyComboBox }
|
{ TCocoaReadOnlyComboBox }
|
||||||
|
|
||||||
TCocoaReadOnlyComboBox = objcclass(NSPopUpButton)
|
TCocoaReadOnlyComboBox = objcclass(NSPopUpButton)
|
||||||
@ -432,6 +445,86 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaReadOnlyComboBoxList }
|
||||||
|
|
||||||
|
procedure TCocoaReadOnlyComboBoxList.InsertItem(Index: Integer;
|
||||||
|
const S: string; O: TObject);
|
||||||
|
var
|
||||||
|
astr : NSString;
|
||||||
|
mn : NSMenuItem;
|
||||||
|
menuItem : TCocoaReadOnlyView;
|
||||||
|
track: NSTrackingArea;
|
||||||
|
begin
|
||||||
|
inherited InsertItem(Index, S, O);
|
||||||
|
|
||||||
|
// 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 >= FOwner.numberOfItems then
|
||||||
|
begin
|
||||||
|
FOwner.addItemWithTitle(astr);
|
||||||
|
Index := FOwner.numberOfItems-1;
|
||||||
|
end else
|
||||||
|
FOwner.insertItemWithTitle_atIndex(astr, Index);
|
||||||
|
|
||||||
|
mn := FOwner.itemAtIndex(Index);
|
||||||
|
if not Assigned(mn) then Exit;
|
||||||
|
|
||||||
|
astr := NSStringUtf8(S);
|
||||||
|
mn.setTitle(astr);
|
||||||
|
astr.release;
|
||||||
|
|
||||||
|
if FOwner.isOwnerDrawn then
|
||||||
|
begin
|
||||||
|
menuItem := TCocoaReadOnlyView.alloc.initWithFrame( NSMakeRect(0,0, FOwner.frame.size.width, COMBOBOX_RO_MENUITEM_HEIGHT) );
|
||||||
|
menuItem.itemIndex := Index;
|
||||||
|
menuItem.combobox := FOwner;
|
||||||
|
|
||||||
|
track:=NSTrackingArea(NSTrackingArea.alloc).initWithRect_options_owner_userInfo(
|
||||||
|
menuItem.bounds
|
||||||
|
, NSTrackingMouseEnteredAndExited or NSTrackingActiveAlways
|
||||||
|
, menuItem, nil);
|
||||||
|
menuItem.addTrackingArea(track);
|
||||||
|
track.release;
|
||||||
|
mn.setView(menuItem);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaReadOnlyComboBoxList.Put(Index: Integer; const S: string);
|
||||||
|
var
|
||||||
|
astr: NSString;
|
||||||
|
mn : NSMenuItem;
|
||||||
|
begin
|
||||||
|
inherited Put(Index, S);
|
||||||
|
if ((index >= 0) and (Index <= FOwner.numberOfItems)) then
|
||||||
|
begin
|
||||||
|
mn := FOwner.itemAtIndex(Index);
|
||||||
|
astr := NSStringUtf8(S);
|
||||||
|
mn.setTitle(astr);
|
||||||
|
astr.release;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TCocoaReadOnlyComboBoxList.Create(AOwner: TCocoaReadOnlyComboBox);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FOwner := AOwner;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaReadOnlyComboBoxList.Delete(Index: Integer);
|
||||||
|
begin
|
||||||
|
inherited Delete(Index);
|
||||||
|
if (Index>=0) and (Index < FOwner.numberOfItems) then
|
||||||
|
FOwner.removeItemAtIndex(Index);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaReadOnlyComboBoxList.Clear;
|
||||||
|
begin
|
||||||
|
inherited Clear;
|
||||||
|
FOwner.removeAllItems;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCococaFieldEditorExt }
|
{ TCococaFieldEditorExt }
|
||||||
|
|
||||||
function TCococaFieldEditorExt.lclGetCallback: ICommonCallback;
|
function TCococaFieldEditorExt.lclGetCallback: ICommonCallback;
|
||||||
@ -1076,83 +1169,25 @@ begin
|
|||||||
inherited mouseMoved(event);
|
inherited mouseMoved(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaComboBoxList }
|
{ TCocoaEditComboBoxList }
|
||||||
|
|
||||||
procedure TCocoaComboBoxList.InsertItem(Index: Integer; const S: string;
|
procedure TCocoaEditComboBoxList.InsertItem(Index: Integer; const S: string;
|
||||||
O: TObject);
|
O: TObject);
|
||||||
var
|
|
||||||
astr : NSString;
|
|
||||||
mn : NSMenuItem;
|
|
||||||
menuItem : TCocoaReadOnlyView;
|
|
||||||
track: NSTrackingArea;
|
|
||||||
begin
|
begin
|
||||||
inherited InsertItem(Index, S, O);
|
inherited InsertItem(Index, S, O);
|
||||||
|
FOwner.noteNumberOfItemsChanged;
|
||||||
if FOwner <> nil then FOwner.noteNumberOfItemsChanged;
|
|
||||||
|
|
||||||
if FReadOnlyOwner =nil then Exit;
|
|
||||||
|
|
||||||
// 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
|
|
||||||
FReadOnlyOwner.addItemWithTitle(astr);
|
|
||||||
Index := FReadOnlyOwner.numberOfItems-1;
|
|
||||||
end else
|
|
||||||
FReadOnlyOwner.insertItemWithTitle_atIndex(astr, Index);
|
|
||||||
|
|
||||||
mn := FReadOnlyOwner.itemAtIndex(Index);
|
|
||||||
if not Assigned(mn) then Exit;
|
|
||||||
|
|
||||||
astr := NSStringUtf8(S);
|
|
||||||
mn.setTitle(astr);
|
|
||||||
astr.release;
|
|
||||||
|
|
||||||
if FReadOnlyOwner.isOwnerDrawn then
|
|
||||||
begin
|
|
||||||
menuItem := TCocoaReadOnlyView.alloc.initWithFrame( NSMakeRect(0,0, FReadOnlyOwner.frame.size.width, COMBOBOX_RO_MENUITEM_HEIGHT) );
|
|
||||||
menuItem.itemIndex := Index;
|
|
||||||
menuItem.combobox := FReadOnlyOwner;
|
|
||||||
|
|
||||||
track:=NSTrackingArea(NSTrackingArea.alloc).initWithRect_options_owner_userInfo(
|
|
||||||
menuItem.bounds
|
|
||||||
, NSTrackingMouseEnteredAndExited or NSTrackingActiveAlways
|
|
||||||
, menuItem, nil);
|
|
||||||
menuItem.addTrackingArea(track);
|
|
||||||
track.release;
|
|
||||||
mn.setView(menuItem);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaComboBoxList.Changed;
|
procedure TCocoaEditComboBoxList.Changed;
|
||||||
begin
|
begin
|
||||||
inherited Changed;
|
inherited Changed;
|
||||||
if Assigned(FOwner) then FOwner.reloadData;
|
FOwner.reloadData;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaComboBoxList.Delete(Index: Integer);
|
constructor TCocoaEditComboBoxList.Create(AOwner: TCocoaComboBox);
|
||||||
begin
|
|
||||||
inherited Delete(Index);
|
|
||||||
if FOwner <> nil then FOwner.noteNumberOfItemsChanged;
|
|
||||||
if FReadOnlyOwner = nil then Exit;
|
|
||||||
if (Index>=0) and (Index < FReadOnlyOwner.numberOfItems) then
|
|
||||||
FReadOnlyOwner.removeItemAtIndex(Index);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCocoaComboBoxList.Clear;
|
|
||||||
begin
|
|
||||||
inherited Clear;
|
|
||||||
if FReadOnlyOwner <> nil then
|
|
||||||
FReadOnlyOwner.removeAllItems;
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor TCocoaComboBoxList.Create(AOwner: TCocoaComboBox; AReadOnlyOwner: TCocoaReadOnlyComboBox);
|
|
||||||
begin
|
begin
|
||||||
|
inherited Create;
|
||||||
FOwner := AOwner;
|
FOwner := AOwner;
|
||||||
FReadOnlyOwner := AReadOnlyOwner;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaComboBox }
|
{ TCocoaComboBox }
|
||||||
|
@ -1649,7 +1649,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
rocmb := NSView(TCocoaReadOnlyComboBox.alloc).lclInitWithCreateParams(AParams);
|
rocmb := NSView(TCocoaReadOnlyComboBox.alloc).lclInitWithCreateParams(AParams);
|
||||||
if not Assigned(rocmb) then Exit;
|
if not Assigned(rocmb) then Exit;
|
||||||
rocmb.list:=TCocoaComboBoxList.Create(nil, rocmb);
|
rocmb.list:=TCocoaReadOnlyComboBoxList.Create(rocmb);
|
||||||
rocmb.setTarget(rocmb);
|
rocmb.setTarget(rocmb);
|
||||||
rocmb.setAction(objcselector('comboboxAction:'));
|
rocmb.setAction(objcselector('comboboxAction:'));
|
||||||
rocmb.selectItemAtIndex(rocmb.lastSelectedItemIndex);
|
rocmb.selectItemAtIndex(rocmb.lastSelectedItemIndex);
|
||||||
@ -1663,7 +1663,7 @@ begin
|
|||||||
cmb := NSView(TCocoaComboBox.alloc).lclInitWithCreateParams(AParams);
|
cmb := NSView(TCocoaComboBox.alloc).lclInitWithCreateParams(AParams);
|
||||||
if not Assigned(cmb) then Exit;
|
if not Assigned(cmb) then Exit;
|
||||||
//cmb.setCell(TCocoaComboBoxCell.alloc.initTextCell(NSString.string_));
|
//cmb.setCell(TCocoaComboBoxCell.alloc.initTextCell(NSString.string_));
|
||||||
cmb.list:=TCocoaComboBoxList.Create(cmb, nil);
|
cmb.list:=TCocoaEditComboBoxList.Create(cmb);
|
||||||
cmb.setUsesDataSource(true);
|
cmb.setUsesDataSource(true);
|
||||||
cmb.setDataSource(cmb);
|
cmb.setDataSource(cmb);
|
||||||
cmb.setDelegate(cmb);
|
cmb.setDelegate(cmb);
|
||||||
|
Loading…
Reference in New Issue
Block a user