Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Luder2018-07-12 07:03:33 -0400
committerAlexander Kurtakov2018-07-18 06:24:21 -0400
commitf52c1ef6cd579938729028029e412ebe7cc5b6b1 (patch)
treecbbb74956311efe605f570920015b8326a59ccab
parent5685d5b505a4f711d6f35b7ef1c9caaa7b904456 (diff)
downloadeclipse.platform.swt-f52c1ef6cd579938729028029e412ebe7cc5b6b1.tar.gz
eclipse.platform.swt-f52c1ef6cd579938729028029e412ebe7cc5b6b1.tar.xz
eclipse.platform.swt-f52c1ef6cd579938729028029e412ebe7cc5b6b1.zip
Bug 536024 [Win32][GTK] Show calendar week in SWT.CALENDAR Added
SWT.CALENDAR_WEEKNUMBERS constant ControlExample-DateTime: added checkbox to enable week numbers Snippet250: Adapted to show week numbers [GTK] DateTime - set GTK_CALENDAR_SHOW_WEEK_NUMBERS, if SWT.CALENDAR_WEEKNUMBERS is set [win32] DateTime - set MCS_WEEKNUMBERS style, if SWT.CALENDAR_WEEKNUMBERS is set - added OS.DTM_SETMCSTYLE (sets the style of the date and time picker) Change-Id: I5c35de0df3706d0fedae7374d67d6e7fe2f10c94 Signed-off-by: Christoph Luder <christoph.luder@gmail.com>
-rw-r--r--bundles/org.eclipse.swt/.settings/.api_filters9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java20
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java14
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DateTimeTab.java11
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet250.java4
7 files changed, 60 insertions, 11 deletions
diff --git a/bundles/org.eclipse.swt/.settings/.api_filters b/bundles/org.eclipse.swt/.settings/.api_filters
index f517944624..bcc9c37500 100644
--- a/bundles/org.eclipse.swt/.settings/.api_filters
+++ b/bundles/org.eclipse.swt/.settings/.api_filters
@@ -465,9 +465,6 @@
</message_arguments>
</filter>
</resource>
- <resource path="Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTree.java">
- <filter comment="Bug 475833 - Delete TableTree and related items" id="0"/>
- </resource>
<resource path="Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTree.java" type="org.eclipse.swt.custom.TableTree">
<filter comment="Bug 475833 - Delete TableTree and related items" id="336744520">
<message_arguments>
@@ -1218,6 +1215,12 @@
<message_argument value="ALT_GR"/>
</message_arguments>
</filter>
+ <filter id="336658481">
+ <message_arguments>
+ <message_argument value="org.eclipse.swt.SWT"/>
+ <message_argument value="CALENDAR_WEEKNUMBERS"/>
+ </message_arguments>
+ </filter>
<filter comment="Bug 525305: Provide SWT.OpenUrl event" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.swt.SWT"/>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
index bac2c3c179..a7c4c48119 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
@@ -409,6 +409,7 @@ public class OS extends C {
public static final int DT_WORDBREAK = 0x10;
public static final int DTM_FIRST = 0x1000;
public static final int DTM_GETSYSTEMTIME = DTM_FIRST + 1;
+ public static final int DTM_SETMCSTYLE = DTM_FIRST + 11;
public static final int DTM_GETIDEALSIZE = DTM_FIRST + 15;
public static final int DTM_SETFORMAT = DTM_FIRST + 50;
public static final int DTM_SETSYSTEMTIME = DTM_FIRST + 2;
@@ -957,6 +958,7 @@ public class OS extends C {
public static final int MCN_SELCHANGE = MCN_FIRST + 1;
public static final int MCN_SELECT = MCN_FIRST + 4;
public static final int MCS_NOTODAY = 0x0010;
+ public static final int MCS_WEEKNUMBERS = 0x0004;
public static final int MDIS_ALLCHILDSTYLES = 0x0001;
public static final int MDT_EFFECTIVE_DPI = 0;
public static final int MFS_CHECKED = 0x8;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
index 46495f76f8..ea709c0fb6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
@@ -2178,6 +2178,17 @@ public class SWT {
public static final int CALENDAR = 1 << 10;
/**
+ * Style constant for displaying the week numbers.
+ * <br>Note that this is a <em>HINT</em> and is supported on Windows & GTK platforms only.
+ * <p><b>Used By:</b><ul>
+ * <li><code>DateTime</code></li>
+ * </ul></p>
+ *
+ * @since 3.108
+ */
+ public static final int CALENDAR_WEEKNUMBERS = 1 << 14;
+
+ /**
* Style constant for short date/time format (value is 1&lt;&lt;15).
* <p>
* A short date displays the month and year.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
index ebf0805cf4..2d1e48aaa2 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java
@@ -39,7 +39,7 @@ import org.eclipse.swt.internal.gtk.*;
* </p>
* <dl>
* <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
+ * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN, CALENDAR_WEEKNUMBERS</dd>
* <dt><b>Events:</b></dt>
* <dd>DefaultSelection, Selection</dd>
* </dl>
@@ -132,6 +132,7 @@ public class DateTime extends Composite {
* @see SWT#DATE
* @see SWT#TIME
* @see SWT#CALENDAR
+ * @see SWT#CALENDAR_WEEKNUMBERS
* @see SWT#SHORT
* @see SWT#MEDIUM
* @see SWT#LONG
@@ -404,7 +405,12 @@ private void createHandleForCalendar () {
containerHandle = calendarHandle;
GTK.gtk_container_add (fixedHandle, calendarHandle);
- GTK.gtk_calendar_set_display_options (calendarHandle, GTK.GTK_CALENDAR_SHOW_HEADING | GTK.GTK_CALENDAR_SHOW_DAY_NAMES);
+
+ int flags = GTK.GTK_CALENDAR_SHOW_HEADING | GTK.GTK_CALENDAR_SHOW_DAY_NAMES;
+ if (showWeekNumbers()) {
+ flags |= GTK.GTK_CALENDAR_SHOW_WEEK_NUMBERS;
+ }
+ GTK.gtk_calendar_set_display_options (calendarHandle, flags);
GTK.gtk_widget_show (calendarHandle);
}
@@ -484,7 +490,11 @@ void createDropDownButton () {
void createPopupShell (int year, int month, int day) {
popupShell = new Shell (getShell (), SWT.NO_TRIM | SWT.ON_TOP);
- popupCalendar = new DateTime (popupShell, SWT.CALENDAR);
+ int popupStyle = SWT.CALENDAR;
+ if (showWeekNumbers()) {
+ popupStyle |= SWT.CALENDAR_WEEKNUMBERS;
+ }
+ popupCalendar = new DateTime (popupShell, popupStyle);
if (font != null) popupCalendar.setFont (font);
if (fg != null) popupCalendar.setForeground (fg);
if (bg != null) popupCalendar.setBackground (bg);
@@ -989,6 +999,10 @@ private boolean isReadOnly () {
return ((style & SWT.READ_ONLY) != 0);
}
+private boolean showWeekNumbers() {
+ return ((style & SWT.CALENDAR_WEEKNUMBERS) != 0);
+}
+
void initAccessible () {
Accessible accessible = getAccessible ();
accessible.addAccessibleListener (new AccessibleAdapter () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java
index 5b61b7a51f..bb6982f98b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java
@@ -10,10 +10,10 @@
*******************************************************************************/
package org.eclipse.swt.widgets;
-import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.internal.win32.*;
/**
* Instances of this class are selectable user interface
@@ -25,7 +25,7 @@ import org.eclipse.swt.graphics.*;
* </p>
* <dl>
* <dt><b>Styles:</b></dt>
- * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd>
+ * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN, CALENDAR_WEEKNUMBERS</dd>
* <dt><b>Events:</b></dt>
* <dd>DefaultSelection, Selection</dd>
* </dl>
@@ -149,6 +149,7 @@ public class DateTime extends Composite {
* @see SWT#DATE
* @see SWT#TIME
* @see SWT#CALENDAR
+ * @see SWT#CALENDAR_WEEKNUMBERS
* @see SWT#SHORT
* @see SWT#MEDIUM
* @see SWT#LONG
@@ -233,6 +234,12 @@ protected void checkSubclass () {
width = rect.right;
height = rect.bottom;
} else {
+ // customize the style of the drop-down calendar, to get the correct size
+ if ((style & SWT.CALENDAR_WEEKNUMBERS) != 0) {
+ // get current style and add week numbers to the calendar drop-down
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ OS.SendMessage(handle, OS.DTM_SETMCSTYLE, 0, bits | OS.MCS_WEEKNUMBERS);
+ }
SIZE size = new SIZE ();
OS.SendMessage(handle, OS.DTM_GETIDEALSIZE, 0, size);
width = size.cx;
@@ -701,6 +708,9 @@ public void setYear (int year) {
@Override
int widgetStyle () {
int bits = super.widgetStyle () | OS.WS_TABSTOP;
+ if ((style & SWT.CALENDAR_WEEKNUMBERS) != 0) {
+ bits |= OS.MCS_WEEKNUMBERS;
+ }
if ((style & SWT.CALENDAR) != 0) return bits | OS.MCS_NOTODAY;
/*
* Bug in Windows: When WS_CLIPCHILDREN is set in a
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DateTimeTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DateTimeTab.java
index 3baf54fb44..f3d4ea6e2a 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DateTimeTab.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/DateTimeTab.java
@@ -25,7 +25,7 @@ class DateTimeTab extends Tab {
Group dateTimeGroup;
/* Style widgets added to the "Style" group */
- Button dateButton, timeButton, calendarButton, shortButton, mediumButton, longButton, dropDownButton;
+ Button dateButton, timeButton, calendarButton, shortButton, mediumButton, longButton, dropDownButton, weekNumbersButton;
/**
* Creates the Tab within a given instance of ControlExample.
@@ -63,6 +63,7 @@ class DateTimeTab extends Tab {
if (mediumButton.getSelection ()) style |= SWT.MEDIUM;
if (longButton.getSelection ()) style |= SWT.LONG;
if (dropDownButton.getSelection ()) style |= SWT.DROP_DOWN;
+ if (weekNumbersButton.getSelection ()) style |= SWT.CALENDAR_WEEKNUMBERS;
/* Create the example widgets */
dateTime1 = new DateTime (dateTimeGroup, style);
@@ -92,6 +93,8 @@ class DateTimeTab extends Tab {
longButton.setText("SWT.LONG");
dropDownButton = new Button(styleGroup, SWT.CHECK);
dropDownButton.setText("SWT.DROP_DOWN");
+ weekNumbersButton = new Button(styleGroup, SWT.CHECK);
+ weekNumbersButton.setText("SWT.CALENDAR_WEEKNUMBERS");
borderButton = new Button(styleGroup, SWT.CHECK);
borderButton.setText("SWT.BORDER");
}
@@ -148,6 +151,12 @@ class DateTimeTab extends Tab {
dropDownButton.setSelection(false);
dropDownButton.setEnabled(false);
}
+ if ((dateTime1.getStyle() & SWT.CALENDAR) != 0 || (dateTime1.getStyle() & SWT.DROP_DOWN) != 0) {
+ weekNumbersButton.setEnabled(true);
+ } else {
+ weekNumbersButton.setEnabled(false);
+ weekNumbersButton.setSelection(false);
+ }
borderButton.setEnabled(false);
}
}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet250.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet250.java
index 30741a2579..f2252768d9 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet250.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet250.java
@@ -31,10 +31,10 @@ public static void main (String [] args) {
Shell shell = new Shell (display);
shell.setLayout (new RowLayout ());
- DateTime calendar = new DateTime (shell, SWT.CALENDAR);
+ DateTime calendar = new DateTime (shell, SWT.CALENDAR | SWT.CALENDAR_WEEKNUMBERS);
calendar.addSelectionListener (widgetSelectedAdapter(e -> System.out.println ("calendar date changed")));
- DateTime calendarDropDown = new DateTime (shell, SWT.DROP_DOWN);
+ DateTime calendarDropDown = new DateTime (shell, SWT.DROP_DOWN | SWT.CALENDAR_WEEKNUMBERS);
calendarDropDown.addSelectionListener (
widgetSelectedAdapter(e -> System.out.println ("calendar date changed via drop-down")));

Back to the top