cocoa: additional methods (nsview, nscontrol, nsbuttons, nstextfield) for handling fpc issue #34411

git-svn-id: trunk@59331 -
This commit is contained in:
dmitry 2018-10-21 05:32:52 +00:00
parent b1d9f29b89
commit 11a50ac7d2
11 changed files with 115 additions and 9 deletions

View File

@ -61,6 +61,19 @@ type
function nextEventMatchingMask_untilDate_inMode_dequeue_(mask: NSUInteger; expiration: NSDate; mode: NSString; deqFlag: ObjCBool): NSEvent; message 'nextEventMatchingMask:untilDate:inMode:dequeue:';
procedure postEvent_atStart_(event: NSEvent; flag: ObjCBool); message 'postEvent:atStart:';
end;
NSButtonFix = objccategory external(NSButton)
procedure setBordered_(flag: ObjCBool); message 'setBordered:';
procedure setAllowsMixedState_(flag: ObjCBool); message 'setAllowsMixedState:';
end;
NSTextFieldFix = objccategory external(NSTextField)
procedure setDrawsBackground_(flag: ObjCBool); message 'setDrawsBackground:';
procedure setBordered_(flag: ObjCBool); message 'setBordered:';
procedure setBezeled_(flag: ObjCBool); message 'setBezeled:';
procedure setEditable_(flag: ObjCBool); message 'setEditable:';
procedure setSelectable_(flag: ObjCBool); message 'setSelectable:';
end;
{$endif}
NSEdgeInsets = packed record
@ -78,6 +91,8 @@ type
function frameForAlignmentRect(ns: NSRect): NSRect; message 'frameForAlignmentRect:';
{$ifdef BOOLFIX}
procedure setHidden_(flag: ObjCBool); message 'setHidden:';
procedure setAutoresizesSubviews_(flag: ObjCBool); message 'setAutoresizesSubviews:';
procedure setNeedsDisplay__(flag: ObjCBool); message 'setNeedsDisplay:';
{$endif}
end;

View File

@ -18,6 +18,7 @@ unit CocoaButtons;
{$modeswitch objectivec1}
{$modeswitch objectivec2}
{$interfaces corba}
{$include cocoadefines.inc}
interface
@ -140,7 +141,11 @@ begin
// so it could be then switched to "On" by Cocoa
if state = NSMixedState then
inherited setState(NSOffState);
{$ifdef BOOLFIX}
setAllowsMixedState_(Ord(false));
{$else}
setAllowsMixedState(false);
{$endif}
end;
end;
end;

View File

@ -493,7 +493,12 @@ begin
if Assigned(aview) then
begin
// forcing LCL compatible "auto-move" mode. Sticking to left/top corner
if not autoresizesSubviews then setAutoresizesSubviews(true);
if not autoresizesSubviews then
{$ifdef BOOLFIX}
setAutoresizesSubviews_(Ord(true));
{$else}
setAutoresizesSubviews(true);
{$endif}
aview.setAutoresizingMask(NSViewMaxXMargin or NSViewMinYMargin);
end;
end;
@ -961,12 +966,20 @@ end;
procedure LCLViewExtension.lclInvalidate;
begin
{$ifdef BOOLFIX}
setNeedsDisplay__(Ord(True));
{$else}
setNeedsDisplay_(True);
{$endif}
end;
procedure LCLViewExtension.lclUpdate;
begin
setNeedsDisplay_(true);
{$ifdef BOOLFIX}
setNeedsDisplay__(Ord(True));
{$else}
setNeedsDisplay_(True);
{$endif}
//display;
end;

View File

@ -193,7 +193,11 @@ begin
// todo: call scroll event?
sc.setDoubleValue(v);
{$ifdef BOOLFIX}
sc.setNeedsDisplay__(Ord(true));
{$else}
sc.setNeedsDisplay_(true);
{$endif}
end;
function AdjustScrollerArrow(sc: TCocoaScrollBar; prt: NSScrollerPart): Boolean;
@ -224,7 +228,11 @@ begin
begin
// todo: call scroll event?
sc.setDoubleValue(v);
{$ifdef BOOLFIX}
sc.setNeedsDisplay__(Ord(true));
{$else}
sc.setNeedsDisplay_(true);
{$endif}
end;
end;
@ -386,7 +394,11 @@ begin
if not NSEqualRects(doc.frame, f) then
begin
doc.setFrame(f);
{$ifdef BOOLFIX}
doc.setNeedsDisplay__(Ord(true));
{$else}
doc.setNeedsDisplay_(true);
{$endif}
end;
end;

View File

@ -131,7 +131,11 @@ begin
else
btn.setImage( NSImage.imageNamed( NSImageNameRightFacingTriangleTemplate ));
{$ifdef BOOLFIX}
btn.setBordered_(Ord(false));
{$else}
btn.setBordered(false);
{$endif}
btn.setTitle(NSString.string_);
btn.sizeToFit();
if not isPrev then btn.setAutoresizingMask(NSViewMinXMargin);

View File

@ -944,7 +944,11 @@ var
Img: NSImage;
begin
Result := inherited initWithFrame(frameRect);
{$ifdef BOOLFIX}
Result.setAutoresizesSubviews_(Ord(True));
{$else}
Result.setAutoresizesSubviews(True);
{$endif}
checkedSubview := NSButton.alloc.init;
checkedSubview.setButtonType(NSSwitchButton);

View File

@ -2577,7 +2577,11 @@ begin
// todo: parse the passed parameters.
// the content of the window could be already prepared
// thus not entire control should be invalided
{$ifdef BOOLFIX}
v.setNeedsDisplay__(Ord(true));
{$else}
v.setNeedsDisplay_(true);
{$endif}
end;
function TCocoaWidgetSet.SelectClipRGN(DC: hDC; RGN: HRGN): Longint;

View File

@ -417,7 +417,11 @@ end;
class procedure TCocoaWSStatusBar.Update(const AStatusBar: TStatusBar);
begin
if not Assigned(AStatusBar) or not (AStatusBar.HandleAllocated) then Exit;
{$ifdef BOOLFIX}
TCocoaStatusBar(AStatusBar.Handle).setNeedsDisplay__(Ord(true));
{$else}
TCocoaStatusBar(AStatusBar.Handle).setNeedsDisplay_(true);
{$endif}
end;
class procedure TCocoaWSStatusBar.GetPreferredSize(const AWinControl: TWinControl;
@ -925,7 +929,11 @@ begin
else
lNSColumn.headerCell.setStringValue(lNSCaption);
{$ifdef BOOLFIX}
lTableLV.headerView.setNeedsDisplay__(Ord(true)); // forces the newly set Value (even for setTitle!)
{$else}
lTableLV.headerView.setNeedsDisplay_(true); // forces the newly set Value (even for setTitle!)
{$endif}
lNSCaption.release;
end;
@ -1329,8 +1337,17 @@ begin
ScrollViewSetScrollStyles(lCocoaLV, AValue);
{$ifdef BOOLFIX}
lCocoaLV.setNeedsDisplay__(Ord(true));
{$else}
lCocoaLV.setNeedsDisplay_(true);
{$endif}
{$ifdef BOOLFIX}
lCocoaLV.documentView.setNeedsDisplay__(Ord(true));
{$else}
lCocoaLV.documentView.setNeedsDisplay_(true);
{$endif}
end;
{ TCocoaWSProgressBar }

View File

@ -18,6 +18,7 @@ unit CocoaWSDialogs;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$modeswitch objectivec2}
{$include cocoadefines.inc}
interface
@ -188,10 +189,17 @@ var
// "Format:" label
lText := NSTextField.alloc.initWithFrame(NSNullRect);
{$ifdef BOOLFIX}
lText.setBezeled_(Ord(False));
lText.setDrawsBackground_(Ord(False));
lText.setEditable_(Ord(False));
lText.setSelectable_(Ord(False));
{$else}
lText.setBezeled(False);
lText.setDrawsBackground(False);
lText.setEditable(False);
lText.setSelectable(False);
{$endif}
lTextStr := NSStringUTF8('Format:');
lText.setStringValue(lTextStr);
lText.sizeToFit;

View File

@ -312,7 +312,11 @@ begin
// Need to figure out why this is happening and resolve at the proper place.
// In the mean time - invalidating contents every time Caption is change
if (AWinControl.HandleAllocated) then
{$ifdef BOOLFIX}
NSView(AWinControl.Handle).setNeedsDisplay__(Ord(true));
{$else}
NSView(AWinControl.Handle).setNeedsDisplay_(true);
{$endif}
end;
{ TLCLWindowCallback }

View File

@ -19,6 +19,7 @@ unit CocoaWSStdCtrls;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$modeswitch objectivec2}
{$include cocoadefines.inc}
interface
@ -33,7 +34,7 @@ uses
WSStdCtrls, WSLCLClasses, WSControls, WSProc,
// LCL Cocoa
CocoaWSCommon, CocoaPrivate, CocoaUtils, CocoaGDIObjects, CocoaButtons,
CocoaTables, CocoaTextEdits, CocoaScrollers;
CocoaTables, CocoaTextEdits, CocoaScrollers, Cocoa_Extra;
type
@ -404,10 +405,11 @@ end;
procedure TextFieldSetBorderStyle(txt: NSTextField; astyle: TBorderStyle);
begin
if not Assigned(txt) then Exit;
if astyle = bsNone then
txt.setBezeled(false)
else
txt.setBezeled(true);
{$ifdef BOOLFIX}
txt.setBezeled_(Ord(astyle <> bsNone));
{$else}
txt.setBezeled(astyle <> bsNone);
{$endif}
end;
procedure RadioButtonSwitchSiblings(checkedRadio: NSButton);
@ -453,8 +455,11 @@ end;
procedure ComboBoxSetBorderStyle(box: NSComboBox; astyle: TBorderStyle);
begin
if astyle = bsNone then box.setBezeled(false)
else box.setBezeled(true);
{$IFDEF BOOLFIX}
box.setBezeled_(Ord(astyle <> bsNone));
{$else}
box.setBezeled(astyle <> bsNone);
{$endif}
end;
{ TLCLRadioButtonCallback }
@ -731,7 +736,11 @@ begin
// changes in AllowGrayed are never sent to WS!
// so it should be checked at create time (and at SetNextState?)
if TCustomCheckBox(AWinControl).AllowGrayed then
{$ifdef BOOLFIX}
NSButton(btn).setAllowsMixedState_(Ord(true));
{$else}
NSButton(btn).setAllowsMixedState(true);
{$endif}
Result := TLCLIntfHandle(btn);
end;
@ -771,7 +780,11 @@ begin
if ACustomCheckBox.HandleAllocated then
begin
if NewState = cbGrayed then
{$ifdef BOOLFIX}
NSButton(ACustomCheckBox.Handle).setAllowsMixedState_(Ord(true));
{$else}
NSButton(ACustomCheckBox.Handle).setAllowsMixedState(true);
{$endif}
NSButton(ACustomCheckBox.Handle).setState(buttonState[NewState]);
end;
end;
@ -838,10 +851,17 @@ var
field: NSTextField;
begin
field := NSTextField(AllocTextField(AWinControl, AParams));
{$ifdef BOOLFIX}
field.setBezeled_(Ord(False));
field.setDrawsBackground_(Ord(False));
field.setEditable_(Ord(False));
field.setSelectable_(Ord(False));
{$else}
field.setBezeled(False);
field.setDrawsBackground(False);
field.setEditable(False);
field.setSelectable(False);
{$endif}
Result:=TLCLIntfHandle(field);
end;