cocoa: simplify Calendar implementation. Setting default localTimeZone to localTime zone

git-svn-id: trunk@61432 -
This commit is contained in:
dmitry 2019-06-20 03:33:10 +00:00
parent 5080a98675
commit fb9c361376
2 changed files with 14 additions and 60 deletions

View File

@ -11,15 +11,11 @@ uses
type
IDatePickerCallback = interface(ICommonCallback)
Procedure MouseBtnUp;
end;
{ TCocoaDatePicker }
TCocoaDatePicker = objcclass(NSDatePicker)
public
callback: IDatePickerCallback;
callback: ICommonCallback;
autoResize: boolean;
retainAspectRatio: boolean;
@ -54,16 +50,19 @@ begin
oldDate:= NSDateToDateTime(Self.dateValue);
if not callback.MouseUpDownEvent(event) then
begin
// Without this, Cocoa will not update our NSDatePicker date...
inherited mouseDown(event);
// After mouse event, has our date changed
newDate:= NSDateToDateTime(Self.dateValue);
if oldDate <> newDate then
callback.SendOnChange;
// After mouse event, has our date changed
newDate:= NSDateToDateTime(Self.dateValue);
if oldDate <> newDate then
callback.SendOnChange;
// This also calls OnClick....
callback.MouseBtnUp;
// This also calls OnClick....
if Assigned(Callback) then
callback.MouseUpDownEvent(event, true);
end;
end;
end;
@ -149,8 +148,7 @@ end;
procedure TCocoaDatePicker.mouseDragged(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseMove(event) then
//inherited mouseDragged(event)
;
inherited mouseDragged(event);
end;
procedure TCocoaDatePicker.otherMouseDown(event: NSEvent);

View File

@ -26,16 +26,7 @@ const
NSEraDatePickerElementFlag = $0100;
type
TLCLDatePickerCallback = class(TLCLCommonCallback, IDatePickerCallback)
public
procedure MouseBtnUp; virtual;
end;
TLCLDatePickerCallBackClass = class of TLCLDatePickerCallBack;
TCocoaWSCustomCalendar = class(TWSCustomCalendar)
private
class procedure SetMouseTracking(winHandle: THandle; const AParams: TCreateParams);
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetDateTime(const ACalendar: TCustomCalendar): TDateTime; override;
@ -55,16 +46,9 @@ begin
Result:= AnsiString(NSStringToString(value));
end;
procedure TLCLDatePickerCallback.MouseBtnUp;
begin
if not Owner.lclIsEnabled() then Exit;
SendSimpleMessage(Target, LM_LBUTTONUP);
end;
function AllocDatePicker(const ATarget: TWinControl; const AParams: TCreateParams): TCocoaDatePicker;
var
ns : NSString;
tz : NSTimeZone;
nsc: NSString;
c : NSCalendar;
flags : NSDatePickerElementFlags;
@ -77,9 +61,7 @@ begin
flags:= NSYearMonthDayDatePickerElementFlag;
Result.setDatePickerElements(flags);
ns:= AnsiStrToNSStr('GMT+00:00');
tz:= NSTimeZone.alloc.initWithName(ns);
Result.setTimeZone(tz);
Result.setTimeZone(NSTimeZone.localTimeZone);
Result.setDateValue(DateTimeToNSDate(Now));
@ -88,11 +70,10 @@ begin
mode:= singleDateMode;
Result.setDatePickerMode(mode);
nsc:= AnsiStrToNSStr(''); // NSCalendarIdentifierISO8601 NSCalendarIdentifierGregorian
c := NSCalendar.alloc.initWithCalendarIdentifier(nsc);
c := NSCalendar.alloc.initWithCalendarIdentifier(NSString.string_);
Result.setCalendar(c);
TCocoaDatePicker(Result).callback:= TLCLDatePickerCallBackClass.Create(Result, ATarget);
TCocoaDatePicker(Result).callback:= TLCLCommonCallback.Create(Result, ATarget);
Result.setBezeled(True);
@ -112,13 +93,6 @@ begin
if Assigned(dp) then
begin
NSDatePickerCell(TLCLIntfHandle(dp)).setDatePickerStyle(NSDatePickerStyle_ClockCal);
// Must have Top/Left @ Zero...
Params:= AParams;
Params.X:= 0;
Params.Y:= 0;
// This should be called when OnMouseMove is assigned...
SetMouseTracking(TLCLIntfHandle(dp), Params);
end;
Result:= TLCLIntfHandle(dp);
@ -144,23 +118,5 @@ begin
Result:= cpTitle;
end;
class procedure TCocoaWSCustomCalendar.SetMouseTracking(winHandle: THandle; const AParams: TCreateParams);
var
ta : NSTrackingArea;
r : NSRect;
opt : NSTrackingAreaOptions;
begin
r.origin.x := AParams.X;
r.origin.y := AParams.Y;
r.size.height:= AParams.Height;
r.size.width := AParams.Width;
opt:= NSTrackingMouseEnteredAndExited + NSTrackingMouseMoved + NSTrackingActiveAlways;
ta:= NSTrackingArea.alloc.initWithRect_options_owner_userInfo(r, opt, id(winHandle), nil);
TCocoaDatePicker(winHandle).addTrackingArea(ta);
end;
end.