Skip to content

Fix: click a date picker to pick and step a part of the date - #860

Open
DTW-Thalion wants to merge 5 commits into
gnustep:masterfrom
DTW-Thalion:feature/datepicker-mouse
Open

Fix: click a date picker to pick and step a part of the date#860
DTW-Thalion wants to merge 5 commits into
gnustep:masterfrom
DTW-Thalion:feature/datepicker-mouse

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

A date picker could only be reached with the tab key, and the text field and stepper style drew no stepper.

A click now takes the keyboard and picks the part of the date under the pointer, so the arrow keys and the digits act on the part that was clicked. The style that asks for a stepper draws one at its trailing edge through the theme, keeps room for it in the cell size and in the text it draws, and a click on the upper or lower half of it steps the part that is picked and sends the action. A click that lands on no part is left to NSControl as before.

The stepper does not repeat while the button is held. The clock and calendar style is not part of this. The branch is cut off #859, which is itself cut off #858, and needs both.

Tests/gui/NSDatePicker/mouse.m holds 9 assertions. Before the change the first click reaches NSControl and waits there for a mouse up that a test has no way to send, so the file cannot run at all; after it the 9 assertions pass. Tests/gui runs 4384 assertions green.

Refers to #95

NSDatePickerCell gave its formatter no format, so the cell had nothing
to draw from and fell back to the description of the date object. The
picker showed a full date and time whatever its datePickerElements were,
in the local time zone rather than the one it was set to, and in a form
no locale writes.

Build the format from the elements. Each element contributes a letter to
a template, and the pattern generator returns the pattern that locale
writes those elements in; a build without ICU has no generator and gets
a fixed order instead. The format is rebuilt whenever the elements or
the locale change.

NSCell keeps the text its formatter made at the time the value was set,
and -[NSDateFormatter stringForObjectValue:] builds that text from a
%-style format rather than from the pattern, so take -stringValue from
-stringFromDate: instead. A cell decoded without a formatter gets one,
as a cell built in code does.
A date picker took no keys at all, so the date it held could only be
changed in code.

The pattern the cell shows is split into the parts the locale writes.
The left and right arrow keys move between those parts, the up and down
arrow keys step the part they are on, and a digit types into it. A step
is a step of the calendar, so it carries into the parts above it, a day
the next month is too short for moves back to that month's last day, and
the result stays inside the minimum and maximum dates. A digit joins the
digits already typed while the number they make can still grow, and is
taken on its own once it cannot.

The part being edited is drawn the way selected text is, while the
picker holds the keyboard of a key window. An edit sends the action of
the control. The delegate is asked to validate the proposed date, both
for an edit and for a date set in code, and the date it hands back is
the one the picker takes.

NSDatePickerCell holds three more ivars, for the part being edited and
for the digits typed into it.
A date picker could only be reached with the tab key, and the text field
and stepper style drew no stepper.

A click takes the keyboard and picks the part of the date under the
pointer, so the arrow keys and the digits go to the part that was
clicked. The style that asks for a stepper draws one at its trailing
edge through the theme, keeps room for it in the cell size and in the
text, and a click on its upper or lower half steps the part that is
picked. A click that lands on no part is left to NSControl as before.

The stepper does not repeat while the button is held.
@DTW-Thalion
DTW-Thalion requested a review from fredkiefer as a code owner July 29, 2026 20:22
GCC has no declaration of it in this file and takes the return value for
an id, which does not compile.
START_SET creates an autorelease pool and END_SET releases it, so the pool
these tests create around the set is redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant