View Issue Details

IDProjectCategoryView StatusLast Update
0035336LazarusWidgetsetpublic2019-06-10 22:10
ReporterAlexey Tor.Assigned ToDmitry Boyarintsev 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformmacOS 10.8OSOS Version
Product Version2.1 (SVN)Product Build 
Target VersionFixed in Version 
Summary0035336: Cocoa: TCalendarDialog has incorrect form size
DescriptionForm size is too narrow so 1) part of date display don't fit, 2) buttons Ok/cancel don't fit.
screenshot.
TagsNo tags attached.
Fixed in Revision61192, 61353
LazTarget-
WidgetsetCocoa
Attached Files
  • cal-cocoa.png (38,120 bytes)
    cal-cocoa.png (38,120 bytes)
  • cal2.png (27,100 bytes)
    cal2.png (27,100 bytes)
  • calendardialog_cocoa.diff (2,000 bytes)
    Index: extdlgs.pas
    ===================================================================
    --- extdlgs.pas	(revision 61348)
    +++ extdlgs.pas	(working copy)
    @@ -22,6 +22,7 @@
     
     uses
       Types, Classes, SysUtils, LCLProc, LResources, LCLType, LCLStrConsts,
    +  InterfaceBase, LCLPlatformDef,
       FileUtil, LazFileUtils, Controls, Dialogs, GraphType, Graphics, ExtCtrls,
       StdCtrls, Forms, Calendar, Buttons, Masks, CalcForm;
     
    @@ -194,6 +195,8 @@
         FOKCaption: TCaption;
         FCancelCaption: TCaption;
         FCalendar: TCalendar;
    +    okButton,cancelButton: TButton;
    +    panel: TPanel;
         procedure OnDialogClose(Sender: TObject; var CloseAction: TCloseAction);
         procedure OnDialogCloseQuery(Sender : TObject; var CanClose : boolean);
         procedure OnDialogShow(Sender: TObject);
    @@ -731,7 +734,43 @@
     end;
     
     procedure TCalendarDialog.OnDialogShow(Sender: TObject);
    +var
    +  w   : integer;
    +  mw  : integer;
    +  cw  : integer;
    +  frm : TForm;
    +const
    +  diff = 10;
     begin
    +  if WidgetSet.LCLPlatform = lpCocoa then begin
    +    frm := TForm(Sender);
    +
    +    okButton.Constraints.MinWidth:=0;
    +    okButton.Constraints.MaxWidth:=0;
    +    cancelButton.Constraints.MinWidth:=0;
    +    cancelButton.Constraints.MaxWidth:=0;
    +    okButton.AutoSize:=true;
    +    cancelButton.AutoSize:=true;
    +    FCalendar.AutoSize:=true;
    +
    +    w:=Max(okButton.Width, cancelButton.Width);
    +    cw:=FCalendar.Width;
    +    mw:= w * 2 + diff; // the space between 2 buttons
    +    mw:=Max(cw, mw);
    +
    +    frm.AutoSize:=false;
    +    okButton.AutoSize:=false;
    +    cancelButton.AutoSize:=false;
    +
    +    frm.ClientWidth:=mw;
    +    panel.Anchors:=[];
    +    FCalendar.Align:=alNone;
    +    FCalendar.Left:=(mw-cw) div 2;
    +    okButton.Width:=w;
    +    cancelButton.Width:=w;
    +    cancelButton.Left:=0;
    +    okButton.Left := frm.ClientWidth - okButton.Width;
    +  end;
       DoShow;
     end;
     
    @@ -770,9 +809,6 @@
     const
       dw=8;
       bbs=2;
    -var
    -  okButton,cancelButton: TButton;
    -  panel: TPanel;
     begin
       DlgForm:=TForm.CreateNew(Application, 0);
       try
    
  • cal-fixed.png (24,008 bytes)
    cal-fixed.png (24,008 bytes)
  • calform.diff (2,206 bytes)
    Index: lcl/extdlgs.pas
    ===================================================================
    --- lcl/extdlgs.pas	(revision 61351)
    +++ lcl/extdlgs.pas	(working copy)
    @@ -22,6 +22,7 @@
     
     uses
       Types, Classes, SysUtils, LCLProc, LResources, LCLType, LCLStrConsts,
    +  InterfaceBase, LCLPlatformDef,
       FileUtil, LazFileUtils, Controls, Dialogs, GraphType, Graphics, ExtCtrls,
       StdCtrls, Forms, Calendar, Buttons, Masks, CalcForm;
     
    @@ -194,6 +195,9 @@
         FOKCaption: TCaption;
         FCancelCaption: TCaption;
         FCalendar: TCalendar;
    +    okButton: TButton;
    +    cancelButton: TButton;
    +    panel: TPanel;
         procedure OnDialogClose(Sender: TObject; var CloseAction: TCloseAction);
         procedure OnDialogCloseQuery(Sender : TObject; var CanClose : boolean);
         procedure OnDialogShow(Sender: TObject);
    @@ -731,7 +735,44 @@
     end;
     
     procedure TCalendarDialog.OnDialogShow(Sender: TObject);
    +var
    +  frm: TForm;
    +  NBtnSize, NSpace, NCalSize: integer;
    +const
    +  cSpace = 16; // space between 2 buttons
     begin
    +  // Calendar form size for Cocoa cannot be fixed on WS level
    +  // see issue 35336
    +  if WidgetSet.LCLPlatform = lpCocoa then begin
    +    frm := TForm(Sender);
    +
    +    okButton.Constraints.MinWidth := 0;
    +    okButton.Constraints.MaxWidth := 0;
    +    cancelButton.Constraints.MinWidth := 0;
    +    cancelButton.Constraints.MaxWidth := 0;
    +    okButton.AutoSize := true;
    +    cancelButton.AutoSize := true;
    +    FCalendar.AutoSize := true;
    +
    +    NBtnSize := Max(okButton.Width, cancelButton.Width);
    +    NCalSize := FCalendar.Width;
    +    NSpace := NBtnSize * 2 + cSpace;
    +    NSpace := Max(NCalSize, NSpace);
    +
    +    frm.AutoSize := false;
    +    okButton.AutoSize := false;
    +    cancelButton.AutoSize := false;
    +
    +    frm.ClientWidth := NSpace;
    +    panel.Anchors := [];
    +    FCalendar.Align := alNone;
    +    FCalendar.Left := (NSpace-NCalSize) div 2;
    +    okButton.Width := NBtnSize;
    +    cancelButton.Width := NBtnSize;
    +    cancelButton.Left := 0;
    +    okButton.Left := frm.ClientWidth - okButton.Width;
    +  end;
    +
       DoShow;
     end;
     
    @@ -770,9 +811,6 @@
     const
       dw=8;
       bbs=2;
    -var
    -  okButton,cancelButton: TButton;
    -  panel: TPanel;
     begin
       DlgForm:=TForm.CreateNew(Application, 0);
       try
    
    calform.diff (2,206 bytes)

Activities

Alexey Tor.

2019-04-07 17:02

reporter  

cal-cocoa.png (38,120 bytes)
cal-cocoa.png (38,120 bytes)

Dmitry Boyarintsev

2019-05-10 05:56

developer   ~0116108

please test and close if ok

Alexey Tor.

2019-05-10 10:21

reporter   ~0116111

not fixed 100%: buttons Ok/Cancel still dont fit. Screenshot added.

Alexey Tor.

2019-05-10 10:21

reporter  

cal2.png (27,100 bytes)
cal2.png (27,100 bytes)

Dmitry Boyarintsev

2019-06-10 06:36

developer   ~0116651

here's a proposed patch.
see that it has little to do with cocoa.

calendardialog_cocoa.diff (2,000 bytes)
Index: extdlgs.pas
===================================================================
--- extdlgs.pas	(revision 61348)
+++ extdlgs.pas	(working copy)
@@ -22,6 +22,7 @@
 
 uses
   Types, Classes, SysUtils, LCLProc, LResources, LCLType, LCLStrConsts,
+  InterfaceBase, LCLPlatformDef,
   FileUtil, LazFileUtils, Controls, Dialogs, GraphType, Graphics, ExtCtrls,
   StdCtrls, Forms, Calendar, Buttons, Masks, CalcForm;
 
@@ -194,6 +195,8 @@
     FOKCaption: TCaption;
     FCancelCaption: TCaption;
     FCalendar: TCalendar;
+    okButton,cancelButton: TButton;
+    panel: TPanel;
     procedure OnDialogClose(Sender: TObject; var CloseAction: TCloseAction);
     procedure OnDialogCloseQuery(Sender : TObject; var CanClose : boolean);
     procedure OnDialogShow(Sender: TObject);
@@ -731,7 +734,43 @@
 end;
 
 procedure TCalendarDialog.OnDialogShow(Sender: TObject);
+var
+  w   : integer;
+  mw  : integer;
+  cw  : integer;
+  frm : TForm;
+const
+  diff = 10;
 begin
+  if WidgetSet.LCLPlatform = lpCocoa then begin
+    frm := TForm(Sender);
+
+    okButton.Constraints.MinWidth:=0;
+    okButton.Constraints.MaxWidth:=0;
+    cancelButton.Constraints.MinWidth:=0;
+    cancelButton.Constraints.MaxWidth:=0;
+    okButton.AutoSize:=true;
+    cancelButton.AutoSize:=true;
+    FCalendar.AutoSize:=true;
+
+    w:=Max(okButton.Width, cancelButton.Width);
+    cw:=FCalendar.Width;
+    mw:= w * 2 + diff; // the space between 2 buttons
+    mw:=Max(cw, mw);
+
+    frm.AutoSize:=false;
+    okButton.AutoSize:=false;
+    cancelButton.AutoSize:=false;
+
+    frm.ClientWidth:=mw;
+    panel.Anchors:=[];
+    FCalendar.Align:=alNone;
+    FCalendar.Left:=(mw-cw) div 2;
+    okButton.Width:=w;
+    cancelButton.Width:=w;
+    cancelButton.Left:=0;
+    okButton.Left := frm.ClientWidth - okButton.Width;
+  end;
   DoShow;
 end;
 
@@ -770,9 +809,6 @@
 const
   dw=8;
   bbs=2;
-var
-  okButton,cancelButton: TButton;
-  panel: TPanel;
 begin
   DlgForm:=TForm.CreateNew(Application, 0);
   try

Alexey Tor.

2019-06-10 10:28

reporter   ~0116655

Now almost fixed. screenshot.
a) font of calendar is small
b) buttons don't fit a little

cal-fixed.png (24,008 bytes)
cal-fixed.png (24,008 bytes)

Alexey Tor.

2019-06-10 21:48

reporter   ~0116663

changes in Dmitry's patch: formatted, changed const to 15 pix to fix spacing.
now looks OK on 10.8 and 10.11 (cannot test 10.14).

calform.diff (2,206 bytes)
Index: lcl/extdlgs.pas
===================================================================
--- lcl/extdlgs.pas	(revision 61351)
+++ lcl/extdlgs.pas	(working copy)
@@ -22,6 +22,7 @@
 
 uses
   Types, Classes, SysUtils, LCLProc, LResources, LCLType, LCLStrConsts,
+  InterfaceBase, LCLPlatformDef,
   FileUtil, LazFileUtils, Controls, Dialogs, GraphType, Graphics, ExtCtrls,
   StdCtrls, Forms, Calendar, Buttons, Masks, CalcForm;
 
@@ -194,6 +195,9 @@
     FOKCaption: TCaption;
     FCancelCaption: TCaption;
     FCalendar: TCalendar;
+    okButton: TButton;
+    cancelButton: TButton;
+    panel: TPanel;
     procedure OnDialogClose(Sender: TObject; var CloseAction: TCloseAction);
     procedure OnDialogCloseQuery(Sender : TObject; var CanClose : boolean);
     procedure OnDialogShow(Sender: TObject);
@@ -731,7 +735,44 @@
 end;
 
 procedure TCalendarDialog.OnDialogShow(Sender: TObject);
+var
+  frm: TForm;
+  NBtnSize, NSpace, NCalSize: integer;
+const
+  cSpace = 16; // space between 2 buttons
 begin
+  // Calendar form size for Cocoa cannot be fixed on WS level
+  // see issue 35336
+  if WidgetSet.LCLPlatform = lpCocoa then begin
+    frm := TForm(Sender);
+
+    okButton.Constraints.MinWidth := 0;
+    okButton.Constraints.MaxWidth := 0;
+    cancelButton.Constraints.MinWidth := 0;
+    cancelButton.Constraints.MaxWidth := 0;
+    okButton.AutoSize := true;
+    cancelButton.AutoSize := true;
+    FCalendar.AutoSize := true;
+
+    NBtnSize := Max(okButton.Width, cancelButton.Width);
+    NCalSize := FCalendar.Width;
+    NSpace := NBtnSize * 2 + cSpace;
+    NSpace := Max(NCalSize, NSpace);
+
+    frm.AutoSize := false;
+    okButton.AutoSize := false;
+    cancelButton.AutoSize := false;
+
+    frm.ClientWidth := NSpace;
+    panel.Anchors := [];
+    FCalendar.Align := alNone;
+    FCalendar.Left := (NSpace-NCalSize) div 2;
+    okButton.Width := NBtnSize;
+    cancelButton.Width := NBtnSize;
+    cancelButton.Left := 0;
+    okButton.Left := frm.ClientWidth - okButton.Width;
+  end;
+
   DoShow;
 end;
 
@@ -770,9 +811,6 @@
 const
   dw=8;
   bbs=2;
-var
-  okButton,cancelButton: TButton;
-  panel: TPanel;
 begin
   DlgForm:=TForm.CreateNew(Application, 0);
   try
calform.diff (2,206 bytes)

Dmitry Boyarintsev

2019-06-10 22:10

developer   ~0116664

thanks for the patch, applied.
please test and close if ok

Issue History

Date Modified Username Field Change
2019-04-07 17:02 Alexey Tor. New Issue
2019-04-07 17:02 Alexey Tor. File Added: cal-cocoa.png
2019-05-10 05:56 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2019-05-10 05:56 Dmitry Boyarintsev Status new => resolved
2019-05-10 05:56 Dmitry Boyarintsev Resolution open => fixed
2019-05-10 05:56 Dmitry Boyarintsev Fixed in Revision => 61192
2019-05-10 05:56 Dmitry Boyarintsev LazTarget => -
2019-05-10 05:56 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2019-05-10 05:56 Dmitry Boyarintsev Note Added: 0116108
2019-05-10 10:21 Alexey Tor. Status resolved => assigned
2019-05-10 10:21 Alexey Tor. Resolution fixed => reopened
2019-05-10 10:21 Alexey Tor. Note Added: 0116111
2019-05-10 10:21 Alexey Tor. File Added: cal2.png
2019-06-10 06:36 Dmitry Boyarintsev File Added: calendardialog_cocoa.diff
2019-06-10 06:36 Dmitry Boyarintsev Note Added: 0116651
2019-06-10 06:36 Dmitry Boyarintsev Status assigned => feedback
2019-06-10 10:28 Alexey Tor. File Added: cal-fixed.png
2019-06-10 10:28 Alexey Tor. Note Added: 0116655
2019-06-10 10:28 Alexey Tor. Status feedback => assigned
2019-06-10 21:48 Alexey Tor. File Added: calform.diff
2019-06-10 21:48 Alexey Tor. Note Added: 0116663
2019-06-10 22:10 Dmitry Boyarintsev Status assigned => resolved
2019-06-10 22:10 Dmitry Boyarintsev Resolution reopened => fixed
2019-06-10 22:10 Dmitry Boyarintsev Fixed in Revision 61192 => 61192, 61353
2019-06-10 22:10 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2019-06-10 22:10 Dmitry Boyarintsev Note Added: 0116664