View Issue Details

IDProjectCategoryView StatusLast Update
0037450LazarusLCLpublic2020-09-24 17:50
ReporterCyrax Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformLinux x86_64OSArch 
Product Version2.1 (SVN) 
Summary0037450: Somehow DisplaySettings property of TCalendar does not seem to be applied during runtime of a project.
DescriptionIf I set DisplaySettings property to different value - e.g I want to enable dsShowWeekNumbers - via Object Inspector, the component will change its appearance in design time.
However if I run the project, changes to DisplaySettings property will not be applied and component will keep its default appearance.

Also if I reopen the project in the Lazarus IDE, TCalendar component seems to be reset its default view although DisplaySettings property retains its previously modified value.
Tagspatch
Fixed in Revisionr63732
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

Cyrax

2020-07-30 05:50

reporter  

Cyrax

2020-07-30 12:47

reporter   ~0124417

Attached patch fixes this bug.
gtk2wscalendar.pp.diff (1,961 bytes)   
diff --git a/lcl/interfaces/gtk2/gtk2wscalendar.pp b/lcl/interfaces/gtk2/gtk2wscalendar.pp
index 432a585ae7..ab80fd3871 100644
--- a/lcl/interfaces/gtk2/gtk2wscalendar.pp
+++ b/lcl/interfaces/gtk2/gtk2wscalendar.pp
@@ -85,6 +85,23 @@ type
     max_week_char_width: guint;
   end;
   PGtkCalendarPrivate = ^TGtkCalendarPrivate;
+  TGtkCalendarInternalTimer = record
+    AGtkCalendar: PGtkCalendar;
+    ATimerSourceID: guint;
+    gtkcalendardisplayoptions: TGtkCalendarDisplayOptions;
+  end;
+  PGtkCalendarInternalTimer = ^TGtkCalendarInternalTimer;
+
+function SetCalendarDisplayOptionsTimer(data: gpointer): gboolean; cdecl;
+Var
+  AGtkCalendarInternalTimer : PGtkCalendarInternalTimer absolute data;
+  Agboolean : gboolean;
+begin
+  Result := False;
+  gtk_Calendar_Display_options(AGtkCalendarInternalTimer^.AGtkCalendar, AGtkCalendarInternalTimer^.gtkcalendardisplayoptions);
+  Agboolean := g_source_remove(AGtkCalendarInternalTimer^.ATimerSourceID);
+  Dispose(AGtkCalendarInternalTimer);
+end;
 
 { TGtk2WSCustomCalendar }
 
@@ -267,6 +284,7 @@ class procedure TGtk2WSCustomCalendar.SetDisplaySettings(const ACalendar: TCusto
 var
   num: dword;
   gtkcalendardisplayoptions : TGtkCalendarDisplayOptions;
+  AGtkCalendarInternalTimer : PGtkCalendarInternalTimer;
 begin
   if not WSCheckHandleAllocated(ACalendar, 'SetDisplaySettings') then
     Exit;
@@ -288,7 +306,11 @@ begin
     num := Num  + (1 shl 4);
   }
   gtkCalendarDisplayOptions := TGtkCalendarDisplayOptions(num);
-  gtk_Calendar_Display_options(GetCalendar(ACalendar), gtkCalendarDisplayOptions);
+
+  New(AGtkCalendarInternalTimer);
+  AGtkCalendarInternalTimer^.AGtkCalendar := GetCalendar(ACalendar);
+  AGtkCalendarInternalTimer^.gtkcalendardisplayoptions := gtkCalendarDisplayOptions;
+  AGtkCalendarInternalTimer^.ATimerSourceID := g_timeout_add(1, @SetCalendarDisplayOptionsTimer, AGtkCalendarInternalTimer);
 end;
 
 class procedure TGtk2WSCustomCalendar.GetPreferredSize(
gtk2wscalendar.pp.diff (1,961 bytes)   

Cyrax

2020-07-30 14:15

reporter   ~0124420

Attached updated patch and test project.
gtk2wscalendar-2.pp.diff (2,135 bytes)   
diff --git a/lcl/interfaces/gtk2/gtk2wscalendar.pp b/lcl/interfaces/gtk2/gtk2wscalendar.pp
index 432a585ae7..e382f0356f 100644
--- a/lcl/interfaces/gtk2/gtk2wscalendar.pp
+++ b/lcl/interfaces/gtk2/gtk2wscalendar.pp
@@ -85,6 +85,25 @@ type
     max_week_char_width: guint;
   end;
   PGtkCalendarPrivate = ^TGtkCalendarPrivate;
+  TGtkCalendarInternalTimer = record
+    ACalendar : TCustomCalendar;
+    gtkcalendardisplayoptions: TGtkCalendarDisplayOptions;
+    ATimerSourceID: guint;
+  end;
+  PGtkCalendarInternalTimer = ^TGtkCalendarInternalTimer;
+
+function SetCalendarDisplayOptionsTimer(data: gpointer): gboolean; cdecl;
+Var
+  AGtkCalendarInternalTimer : PGtkCalendarInternalTimer absolute data;
+  Agboolean : gboolean;
+  AGtkCalendar: PGtkCalendar;
+begin
+  Result := False;
+  AGtkCalendar := TGtk2WSCustomCalendar.GetCalendar(AGtkCalendarInternalTimer^.ACalendar);
+  gtk_Calendar_Display_options(AGtkCalendar, AGtkCalendarInternalTimer^.gtkcalendardisplayoptions);
+  Agboolean := g_source_remove(AGtkCalendarInternalTimer^.ATimerSourceID);
+  Dispose(AGtkCalendarInternalTimer);
+end;
 
 { TGtk2WSCustomCalendar }
 
@@ -267,9 +286,11 @@ class procedure TGtk2WSCustomCalendar.SetDisplaySettings(const ACalendar: TCusto
 var
   num: dword;
   gtkcalendardisplayoptions : TGtkCalendarDisplayOptions;
+  AGtkCalendarInternalTimer : PGtkCalendarInternalTimer;
 begin
   if not WSCheckHandleAllocated(ACalendar, 'SetDisplaySettings') then
     Exit;
+
   num := 0;
   if (dsShowHeadings in ADisplaySettings) then
     num := Num + (1 shl 0);
@@ -288,7 +309,11 @@ begin
     num := Num  + (1 shl 4);
   }
   gtkCalendarDisplayOptions := TGtkCalendarDisplayOptions(num);
-  gtk_Calendar_Display_options(GetCalendar(ACalendar), gtkCalendarDisplayOptions);
+
+  New(AGtkCalendarInternalTimer);
+  AGtkCalendarInternalTimer^.ACalendar := ACalendar;
+  AGtkCalendarInternalTimer^.gtkcalendardisplayoptions := gtkCalendarDisplayOptions;
+  AGtkCalendarInternalTimer^.ATimerSourceID := g_timeout_add(1, @SetCalendarDisplayOptionsTimer, AGtkCalendarInternalTimer);
 end;
 
 class procedure TGtk2WSCustomCalendar.GetPreferredSize(
gtk2wscalendar-2.pp.diff (2,135 bytes)   
project1.zip (128,630 bytes)

Juha Manninen

2020-08-13 17:33

developer   ~0124848

Applied, thanks.

Issue History

Date Modified Username Field Change
2020-07-30 05:50 Cyrax New Issue
2020-07-30 05:50 Cyrax File Added: DisplaySettings lost during project load 2.png
2020-07-30 12:47 Cyrax Note Added: 0124417
2020-07-30 12:47 Cyrax File Added: gtk2wscalendar.pp.diff
2020-07-30 12:47 Cyrax Tag Attached: patch
2020-07-30 14:15 Cyrax Note Added: 0124420
2020-07-30 14:15 Cyrax File Added: gtk2wscalendar-2.pp.diff
2020-07-30 14:15 Cyrax File Added: project1.zip
2020-08-13 16:50 Juha Manninen Assigned To => Juha Manninen
2020-08-13 16:50 Juha Manninen Status new => assigned
2020-08-13 17:33 Juha Manninen Status assigned => resolved
2020-08-13 17:33 Juha Manninen Resolution open => fixed
2020-08-13 17:33 Juha Manninen Fixed in Revision => r63732
2020-08-13 17:33 Juha Manninen LazTarget => -
2020-08-13 17:33 Juha Manninen Widgetset GTK 2 => GTK 2
2020-08-13 17:33 Juha Manninen Note Added: 0124848
2020-09-24 17:50 Cyrax Status resolved => closed