mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-11 20:00:30 +01:00
cocoa: rework the change notification, moving it to cocoa classes
git-svn-id: trunk@57175 -
This commit is contained in:
parent
57d058fa9c
commit
2275f8e3ae
@ -642,6 +642,7 @@ type
|
||||
procedure comboBoxSelectionIsChanging(notification: NSNotification); message 'comboBoxSelectionIsChanging:';
|
||||
//
|
||||
function lclIsHandle: Boolean; override;
|
||||
procedure setStringValue(avalue: NSString); override;
|
||||
end;
|
||||
|
||||
{ TCocoaReadOnlyComboBox }
|
||||
@ -662,6 +663,7 @@ type
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
procedure comboboxAction(sender: id); message 'comboboxAction:';
|
||||
function stringValue: NSString; override;
|
||||
end;
|
||||
|
||||
{ TCocoaScrollBar }
|
||||
@ -4562,6 +4564,22 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TCocoaComboBox.setStringValue(avalue: NSString);
|
||||
var
|
||||
ch : Boolean;
|
||||
s : NSString;
|
||||
begin
|
||||
s := stringValue;
|
||||
ch := (Assigned(s)
|
||||
and Assigned(avalue)
|
||||
and (s.compare(avalue) <> NSOrderedSame));
|
||||
|
||||
inherited setStringValue(avalue);
|
||||
|
||||
if ch and Assigned(callback) then
|
||||
callback.SendOnChange;
|
||||
end;
|
||||
|
||||
function TCocoaComboBox.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -4650,8 +4668,12 @@ begin
|
||||
callback.ComboBoxWillDismiss;
|
||||
end;
|
||||
|
||||
procedure TCocoaComboBox.comboboxSelectionDidChange(notification: NSNotification);
|
||||
procedure TCocoaComboBox.comboBoxSelectionDidChange(notification: NSNotification);
|
||||
var
|
||||
txt : NSString;
|
||||
begin
|
||||
txt := comboBox_objectValueForItemAtIndex_(self, indexOfSelectedItem);
|
||||
if Assigned(txt) then setStringValue( txt );
|
||||
callback.ComboBoxSelectionDidChange;
|
||||
end;
|
||||
|
||||
@ -4712,14 +4734,24 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TCocoaReadOnlyComboBox.comboBoxAction(sender: id);
|
||||
procedure TCocoaReadOnlyComboBox.comboboxAction(sender: id);
|
||||
begin
|
||||
//setTitle(NSSTR(PChar(Format('%d=%d', [indexOfSelectedItem, lastSelectedItemIndex])))); // <= for debugging
|
||||
if Assigned(callback) then
|
||||
callback.SendOnChange;
|
||||
if (indexOfSelectedItem <> lastSelectedItemIndex) and (callback <> nil) then
|
||||
callback.ComboBoxSelectionDidChange;
|
||||
lastSelectedItemIndex := indexOfSelectedItem;
|
||||
end;
|
||||
|
||||
function TCocoaReadOnlyComboBox.stringValue: NSString;
|
||||
begin
|
||||
if Assigned(selectedItem) then
|
||||
Result:=selectedItem.title
|
||||
else
|
||||
Result:=inherited stringValue;
|
||||
end;
|
||||
|
||||
{ TCocoaProgressIndicator }
|
||||
|
||||
function TCocoaProgressIndicator.acceptsFirstResponder: Boolean;
|
||||
|
||||
@ -458,18 +458,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure TLCLComboboxCallback.ComboBoxSelectionDidChange;
|
||||
var
|
||||
txt : NSString;
|
||||
begin
|
||||
// Cocoa changes text only after selectionDidChange notification
|
||||
// LCL expectes it to happen before. (Windows order of events is Changed -> SelChanged)
|
||||
// Must set text manually here.
|
||||
// Maybe Text-changing code should be moved under TCocoaComboBox class instead.
|
||||
txt := TCocoaComboBox( Owner ).comboBox_objectValueForItemAtIndex_( TCocoaComboBox( Owner ),
|
||||
TCocoaComboBox( Owner ).indexOfSelectedItem);
|
||||
if Assigned(txt) then TCocoaComboBox( Owner ).setStringValue( txt );
|
||||
SendSimpleMessage(Target, LM_CHANGED);
|
||||
|
||||
SendSimpleMessage(Target, LM_SELCHANGE);
|
||||
end;
|
||||
|
||||
@ -1275,31 +1264,30 @@ var
|
||||
rocmb: TCocoaReadOnlyComboBox;
|
||||
begin
|
||||
Result:=0;
|
||||
|
||||
if TCustomComboBox(AWinControl).ReadOnly then
|
||||
begin
|
||||
rocmb := NSView(TCocoaReadOnlyComboBox.alloc).lclInitWithCreateParams(AParams);
|
||||
if not Assigned(rocmb) then Exit;
|
||||
rocmb.Owner := TCustomComboBox(AWinControl);
|
||||
rocmb.callback:=TLCLComboboxCallback.Create(rocmb, AWinControl);
|
||||
rocmb.list:=TCocoaComboBoxList.Create(nil, rocmb);
|
||||
rocmb.setTarget(rocmb);
|
||||
rocmb.setAction(objcselector('comboboxAction:'));
|
||||
rocmb.selectItemAtIndex(rocmb.lastSelectedItemIndex);
|
||||
rocmb.callback:=TLCLComboboxCallback.Create(rocmb, AWinControl);
|
||||
Result:=TLCLIntfHandle(rocmb);
|
||||
end
|
||||
else
|
||||
begin
|
||||
cmb := NSView(TCocoaComboBox.alloc).lclInitWithCreateParams(AParams);
|
||||
if not Assigned(cmb) then Exit;
|
||||
cmb.callback:=TLCLComboboxCallback.Create(cmb, AWinControl);
|
||||
cmb.list:=TCocoaComboBoxList.Create(cmb, nil);
|
||||
cmb.setUsesDataSource(true);
|
||||
cmb.setDataSource(cmb);
|
||||
cmb.setDelegate(cmb);
|
||||
cmb.setStringValue(NSStringUtf8(AParams.Caption));
|
||||
cmb.callback:=TLCLComboboxCallback.Create(cmb, AWinControl);
|
||||
Result:=TLCLIntfHandle(cmb);
|
||||
end;
|
||||
|
||||
//todo: 26 pixels is the height of 'normal' combobox. The value is taken from the Interface Builder!
|
||||
// use the correct way to set the size constraints
|
||||
AWinControl.Constraints.SetInterfaceConstraints(0,26,0,26);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user