Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comctl32/monthcal.c
5968 views
1
/*
2
* Month calendar control
3
*
4
* Copyright 1998, 1999 Eric Kohl ([email protected])
5
* Copyright 1999 Alex Priem ([email protected])
6
* Copyright 1999 Chris Morgan <[email protected]> and
7
* James Abbatiello <[email protected]>
8
* Copyright 2000 Uwe Bonnes <[email protected]>
9
* Copyright 2009-2011 Nikolay Sivov
10
*
11
* This library is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public
13
* License as published by the Free Software Foundation; either
14
* version 2.1 of the License, or (at your option) any later version.
15
*
16
* This library is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* Lesser General Public License for more details.
20
*
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with this library; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24
*
25
* TODO:
26
* -- MCM_[GS]ETUNICODEFORMAT
27
* -- handle resources better (doesn't work now);
28
* -- take care of internationalization.
29
* -- keyboard handling.
30
* -- search for FIXME
31
*/
32
33
#include <math.h>
34
#include <stdarg.h>
35
#include <stdio.h>
36
#include <stdlib.h>
37
#include <string.h>
38
39
#include "windef.h"
40
#include "winbase.h"
41
#include "wingdi.h"
42
#include "winuser.h"
43
#include "winnls.h"
44
#include "commctrl.h"
45
#include "comctl32.h"
46
#include "wine/debug.h"
47
48
WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
49
50
#define MC_SEL_LBUTUP 1 /* Left button released */
51
#define MC_SEL_LBUTDOWN 2 /* Left button pressed in calendar */
52
#define MC_PREVPRESSED 4 /* Prev month button pressed */
53
#define MC_NEXTPRESSED 8 /* Next month button pressed */
54
#define MC_PREVNEXTMONTHDELAY 350 /* when continuously pressing `next/prev
55
month', wait 350 ms before going
56
to the next/prev month */
57
#define MC_TODAYUPDATEDELAY 120000 /* time between today check for update (2 min) */
58
59
#define MC_PREVNEXTMONTHTIMER 1 /* Timer IDs */
60
#define MC_TODAYUPDATETIMER 2
61
62
#define MC_CALENDAR_PADDING 6
63
64
/* convert from days to 100 nanoseconds unit - used as FILETIME unit */
65
#define DAYSTO100NSECS(days) (((ULONGLONG)(days))*24*60*60*10000000)
66
67
enum CachedPen
68
{
69
PenRed = 0,
70
PenText,
71
PenLast
72
};
73
74
enum CachedBrush
75
{
76
BrushTitle = 0,
77
BrushMonth,
78
BrushBackground,
79
BrushLast
80
};
81
82
/* single calendar data */
83
typedef struct _CALENDAR_INFO
84
{
85
RECT title; /* rect for the header above the calendar */
86
RECT titlemonth; /* the 'month name' text in the header */
87
RECT titleyear; /* the 'year number' text in the header */
88
RECT wdays; /* week days at top */
89
RECT days; /* calendar area */
90
RECT weeknums; /* week numbers at left side */
91
92
SYSTEMTIME month;/* contains calendar main month/year */
93
} CALENDAR_INFO;
94
95
typedef struct
96
{
97
HWND hwndSelf;
98
DWORD dwStyle; /* cached GWL_STYLE */
99
100
COLORREF colors[MCSC_TRAILINGTEXT+1];
101
HBRUSH brushes[BrushLast];
102
HPEN pens[PenLast];
103
104
HFONT hFont;
105
HFONT hBoldFont;
106
int textHeight;
107
int height_increment;
108
int width_increment;
109
INT delta; /* scroll rate; # of months that the */
110
/* control moves when user clicks a scroll button */
111
int firstDay; /* Start month calendar with firstDay's day,
112
stored in SYSTEMTIME format */
113
BOOL firstDaySet; /* first week day differs from locale defined */
114
115
BOOL isUnicode; /* value set with MCM_SETUNICODE format */
116
117
MONTHDAYSTATE *monthdayState;
118
SYSTEMTIME todaysDate;
119
BOOL todaySet; /* Today was forced with MCM_SETTODAY */
120
int status; /* See MC_SEL flags */
121
SYSTEMTIME firstSel; /* first selected day */
122
INT maxSelCount;
123
SYSTEMTIME minSel; /* contains single selection when used without MCS_MULTISELECT */
124
SYSTEMTIME maxSel;
125
SYSTEMTIME focusedSel; /* date currently focused with mouse movement */
126
DWORD rangeValid;
127
SYSTEMTIME minDate;
128
SYSTEMTIME maxDate;
129
130
RECT titlebtnnext; /* the `next month' button in the header */
131
RECT titlebtnprev; /* the `prev month' button in the header */
132
RECT todayrect; /* `today: xx/xx/xx' text rect */
133
HWND hwndNotify; /* Window to receive the notifications */
134
HWND hWndYearEdit; /* Window Handle of edit box to handle years */
135
HWND hWndYearUpDown;/* Window Handle of updown box to handle years */
136
WNDPROC EditWndProc; /* original Edit window procedure */
137
138
CALENDAR_INFO *calendars;
139
SIZE dim; /* [cx,cy] - dimensions of calendars matrix, row/column count */
140
} MONTHCAL_INFO, *LPMONTHCAL_INFO;
141
142
/* empty SYSTEMTIME const */
143
static const SYSTEMTIME st_null;
144
/* valid date limits */
145
static const SYSTEMTIME max_allowed_date = { /* wYear */ 9999, /* wMonth */ 12, /* wDayOfWeek */ 0, /* wDay */ 31 };
146
static const SYSTEMTIME min_allowed_date = { /* wYear */ 1752, /* wMonth */ 9, /* wDayOfWeek */ 0, /* wDay */ 14 };
147
148
/* Prev/Next buttons */
149
enum nav_direction
150
{
151
DIRECTION_BACKWARD,
152
DIRECTION_FORWARD
153
};
154
155
/* helper functions */
156
static inline INT MONTHCAL_GetCalCount(const MONTHCAL_INFO *infoPtr)
157
{
158
return infoPtr->dim.cx * infoPtr->dim.cy;
159
}
160
161
/* send a single MCN_SELCHANGE notification */
162
static inline void MONTHCAL_NotifySelectionChange(const MONTHCAL_INFO *infoPtr)
163
{
164
NMSELCHANGE nmsc;
165
166
nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
167
nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
168
nmsc.nmhdr.code = MCN_SELCHANGE;
169
nmsc.stSelStart = infoPtr->minSel;
170
nmsc.stSelStart.wDayOfWeek = 0;
171
if(infoPtr->dwStyle & MCS_MULTISELECT){
172
nmsc.stSelEnd = infoPtr->maxSel;
173
nmsc.stSelEnd.wDayOfWeek = 0;
174
}
175
else
176
nmsc.stSelEnd = st_null;
177
178
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
179
}
180
181
/* send a single MCN_SELECT notification */
182
static inline void MONTHCAL_NotifySelect(const MONTHCAL_INFO *infoPtr)
183
{
184
NMSELCHANGE nmsc;
185
186
nmsc.nmhdr.hwndFrom = infoPtr->hwndSelf;
187
nmsc.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
188
nmsc.nmhdr.code = MCN_SELECT;
189
nmsc.stSelStart = infoPtr->minSel;
190
nmsc.stSelStart.wDayOfWeek = 0;
191
if(infoPtr->dwStyle & MCS_MULTISELECT){
192
nmsc.stSelEnd = infoPtr->maxSel;
193
nmsc.stSelEnd.wDayOfWeek = 0;
194
}
195
else
196
nmsc.stSelEnd = st_null;
197
198
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
199
}
200
201
static inline int MONTHCAL_MonthDiff(const SYSTEMTIME *left, const SYSTEMTIME *right)
202
{
203
return (right->wYear - left->wYear)*12 + right->wMonth - left->wMonth;
204
}
205
206
/* returns the number of days in any given month, checking for leap days */
207
/* January is 1, December is 12 */
208
int MONTHCAL_MonthLength(int month, int year)
209
{
210
static const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
211
/* Wrap around, this eases handling. Getting length only we shouldn't care
212
about year change here cause January and December have
213
the same day quantity */
214
if(month == 0)
215
month = 12;
216
else if(month == 13)
217
month = 1;
218
219
/* special case for calendar transition year */
220
if(month == min_allowed_date.wMonth && year == min_allowed_date.wYear) return 19;
221
222
/* if we have a leap year add 1 day to February */
223
/* a leap year is a year either divisible by 400 */
224
/* or divisible by 4 and not by 100 */
225
if(month == 2) { /* February */
226
return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
227
(year%4 == 0)) ? 1 : 0);
228
}
229
else {
230
return mdays[month - 1];
231
}
232
}
233
234
/* compares timestamps using date part only */
235
static inline BOOL MONTHCAL_IsDateEqual(const SYSTEMTIME *first, const SYSTEMTIME *second)
236
{
237
return (first->wYear == second->wYear) && (first->wMonth == second->wMonth) &&
238
(first->wDay == second->wDay);
239
}
240
241
/* make sure that date fields are valid */
242
static BOOL MONTHCAL_ValidateDate(const SYSTEMTIME *time)
243
{
244
if (time->wMonth < 1 || time->wMonth > 12 )
245
return FALSE;
246
if (time->wDay == 0 || time->wDay > MONTHCAL_MonthLength(time->wMonth, time->wYear))
247
return FALSE;
248
249
return TRUE;
250
}
251
252
/* Copies timestamp part only.
253
*
254
* PARAMETERS
255
*
256
* [I] from : source date
257
* [O] to : dest date
258
*/
259
static void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
260
{
261
to->wHour = from->wHour;
262
to->wMinute = from->wMinute;
263
to->wSecond = from->wSecond;
264
}
265
266
/* Copies date part only.
267
*
268
* PARAMETERS
269
*
270
* [I] from : source date
271
* [O] to : dest date
272
*/
273
static void MONTHCAL_CopyDate(const SYSTEMTIME *from, SYSTEMTIME *to)
274
{
275
to->wYear = from->wYear;
276
to->wMonth = from->wMonth;
277
to->wDay = from->wDay;
278
to->wDayOfWeek = from->wDayOfWeek;
279
}
280
281
/* Compares two dates in SYSTEMTIME format
282
*
283
* PARAMETERS
284
*
285
* [I] first : pointer to valid first date data to compare
286
* [I] second : pointer to valid second date data to compare
287
*
288
* RETURN VALUE
289
*
290
* -1 : first < second
291
* 0 : first == second
292
* 1 : first > second
293
*
294
* Note that no date validation performed, already validated values expected.
295
*/
296
LONG MONTHCAL_CompareSystemTime(const SYSTEMTIME *first, const SYSTEMTIME *second)
297
{
298
FILETIME ft_first, ft_second;
299
300
SystemTimeToFileTime(first, &ft_first);
301
SystemTimeToFileTime(second, &ft_second);
302
303
return CompareFileTime(&ft_first, &ft_second);
304
}
305
306
static LONG MONTHCAL_CompareMonths(const SYSTEMTIME *first, const SYSTEMTIME *second)
307
{
308
SYSTEMTIME st_first, st_second;
309
310
st_first = st_second = st_null;
311
MONTHCAL_CopyDate(first, &st_first);
312
MONTHCAL_CopyDate(second, &st_second);
313
st_first.wDay = st_second.wDay = 1;
314
315
return MONTHCAL_CompareSystemTime(&st_first, &st_second);
316
}
317
318
static LONG MONTHCAL_CompareDate(const SYSTEMTIME *first, const SYSTEMTIME *second)
319
{
320
SYSTEMTIME st_first, st_second;
321
322
st_first = st_second = st_null;
323
MONTHCAL_CopyDate(first, &st_first);
324
MONTHCAL_CopyDate(second, &st_second);
325
326
return MONTHCAL_CompareSystemTime(&st_first, &st_second);
327
}
328
329
/* Checks largest possible date range and configured one
330
*
331
* PARAMETERS
332
*
333
* [I] infoPtr : valid pointer to control data
334
* [I] date : pointer to valid date data to check
335
* [I] fix : make date fit valid range
336
*
337
* RETURN VALUE
338
*
339
* TRUE - date within largest and configured range
340
* FALSE - date is outside largest or configured range
341
*/
342
static BOOL MONTHCAL_IsDateInValidRange(const MONTHCAL_INFO *infoPtr,
343
SYSTEMTIME *date, BOOL fix)
344
{
345
const SYSTEMTIME *fix_st = NULL;
346
347
if(MONTHCAL_CompareSystemTime(date, &max_allowed_date) == 1) {
348
fix_st = &max_allowed_date;
349
}
350
else if(MONTHCAL_CompareSystemTime(date, &min_allowed_date) == -1) {
351
fix_st = &min_allowed_date;
352
}
353
else {
354
if(infoPtr->rangeValid & GDTR_MAX) {
355
if((MONTHCAL_CompareSystemTime(date, &infoPtr->maxDate) == 1)) {
356
fix_st = &infoPtr->maxDate;
357
}
358
}
359
360
if(infoPtr->rangeValid & GDTR_MIN) {
361
if((MONTHCAL_CompareSystemTime(date, &infoPtr->minDate) == -1)) {
362
fix_st = &infoPtr->minDate;
363
}
364
}
365
}
366
367
if (fix && fix_st) {
368
date->wYear = fix_st->wYear;
369
date->wMonth = fix_st->wMonth;
370
}
371
372
return !fix_st;
373
}
374
375
/* Checks passed range width with configured maximum selection count
376
*
377
* PARAMETERS
378
*
379
* [I] infoPtr : valid pointer to control data
380
* [I] range0 : pointer to valid date data (requested bound)
381
* [I] range1 : pointer to valid date data (primary bound)
382
* [O] adjust : returns adjusted range bound to fit maximum range (optional)
383
*
384
* Adjust value computed basing on primary bound and current maximum selection
385
* count. For simple range check (without adjusted value required) (range0, range1)
386
* relation means nothing.
387
*
388
* RETURN VALUE
389
*
390
* TRUE - range is shorter or equal to maximum
391
* FALSE - range is larger than maximum
392
*/
393
static BOOL MONTHCAL_IsSelRangeValid(const MONTHCAL_INFO *infoPtr,
394
const SYSTEMTIME *range0,
395
const SYSTEMTIME *range1,
396
SYSTEMTIME *adjust)
397
{
398
ULARGE_INTEGER ul_range0, ul_range1, ul_diff;
399
FILETIME ft_range0, ft_range1;
400
LONG cmp;
401
402
SystemTimeToFileTime(range0, &ft_range0);
403
SystemTimeToFileTime(range1, &ft_range1);
404
405
ul_range0.u.LowPart = ft_range0.dwLowDateTime;
406
ul_range0.u.HighPart = ft_range0.dwHighDateTime;
407
ul_range1.u.LowPart = ft_range1.dwLowDateTime;
408
ul_range1.u.HighPart = ft_range1.dwHighDateTime;
409
410
cmp = CompareFileTime(&ft_range0, &ft_range1);
411
412
if(cmp == 1)
413
ul_diff.QuadPart = ul_range0.QuadPart - ul_range1.QuadPart;
414
else
415
ul_diff.QuadPart = -ul_range0.QuadPart + ul_range1.QuadPart;
416
417
if(ul_diff.QuadPart >= DAYSTO100NSECS(infoPtr->maxSelCount)) {
418
419
if(adjust) {
420
if(cmp == 1)
421
ul_range0.QuadPart = ul_range1.QuadPart + DAYSTO100NSECS(infoPtr->maxSelCount - 1);
422
else
423
ul_range0.QuadPart = ul_range1.QuadPart - DAYSTO100NSECS(infoPtr->maxSelCount - 1);
424
425
ft_range0.dwLowDateTime = ul_range0.u.LowPart;
426
ft_range0.dwHighDateTime = ul_range0.u.HighPart;
427
FileTimeToSystemTime(&ft_range0, adjust);
428
}
429
430
return FALSE;
431
}
432
else return TRUE;
433
}
434
435
/* Used in MCM_SETRANGE/MCM_SETSELRANGE to determine resulting time part.
436
Milliseconds are intentionally not validated. */
437
static BOOL MONTHCAL_ValidateTime(const SYSTEMTIME *time)
438
{
439
if((time->wHour > 24) || (time->wMinute > 59) || (time->wSecond > 59))
440
return FALSE;
441
else
442
return TRUE;
443
}
444
445
/* Note:Depending on DST, this may be offset by a day.
446
Need to find out if we're on a DST place & adjust the clock accordingly.
447
Above function assumes we have a valid data.
448
Valid for year>1752; 1 <= d <= 31, 1 <= m <= 12.
449
0 = Sunday.
450
*/
451
452
/* Returns the day in the week
453
*
454
* PARAMETERS
455
* [i] date : input date
456
* [I] inplace : set calculated value back to date structure
457
*
458
* RETURN VALUE
459
* day of week in SYSTEMTIME format: (0 == sunday,..., 6 == saturday)
460
*/
461
int MONTHCAL_CalculateDayOfWeek(SYSTEMTIME *date, BOOL inplace)
462
{
463
SYSTEMTIME st = st_null;
464
FILETIME ft;
465
466
MONTHCAL_CopyDate(date, &st);
467
468
SystemTimeToFileTime(&st, &ft);
469
FileTimeToSystemTime(&ft, &st);
470
471
if (inplace) date->wDayOfWeek = st.wDayOfWeek;
472
473
return st.wDayOfWeek;
474
}
475
476
/* add/subtract 'months' from date */
477
static inline void MONTHCAL_GetMonth(SYSTEMTIME *date, INT months)
478
{
479
INT length, m = date->wMonth + months;
480
481
date->wYear += m > 0 ? (m - 1) / 12 : m / 12 - 1;
482
date->wMonth = m > 0 ? (m - 1) % 12 + 1 : 12 + m % 12;
483
/* fix moving from last day in a month */
484
length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
485
if(date->wDay > length) date->wDay = length;
486
MONTHCAL_CalculateDayOfWeek(date, TRUE);
487
}
488
489
/* properly updates date to point on next month */
490
static inline void MONTHCAL_GetNextMonth(SYSTEMTIME *date)
491
{
492
MONTHCAL_GetMonth(date, 1);
493
}
494
495
/* properly updates date to point on prev month */
496
static inline void MONTHCAL_GetPrevMonth(SYSTEMTIME *date)
497
{
498
MONTHCAL_GetMonth(date, -1);
499
}
500
501
/* Returns full date for a first currently visible day */
502
static void MONTHCAL_GetMinDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
503
{
504
/* zero indexed calendar has the earliest date */
505
SYSTEMTIME st_first = infoPtr->calendars[0].month;
506
INT firstDay;
507
508
st_first.wDay = 1;
509
firstDay = MONTHCAL_CalculateDayOfWeek(&st_first, FALSE);
510
511
*date = infoPtr->calendars[0].month;
512
MONTHCAL_GetPrevMonth(date);
513
514
date->wDay = MONTHCAL_MonthLength(date->wMonth, date->wYear) +
515
(infoPtr->firstDay - firstDay) % 7 + 1;
516
517
if(date->wDay > MONTHCAL_MonthLength(date->wMonth, date->wYear))
518
date->wDay -= 7;
519
520
/* fix day of week */
521
MONTHCAL_CalculateDayOfWeek(date, TRUE);
522
}
523
524
/* Returns full date for a last currently visible day */
525
static void MONTHCAL_GetMaxDate(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *date)
526
{
527
/* the latest date is in latest calendar */
528
SYSTEMTIME st, *lt_month = &infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
529
INT first_day;
530
531
*date = *lt_month;
532
st = *lt_month;
533
534
/* day of week of first day of current month */
535
st.wDay = 1;
536
first_day = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
537
538
MONTHCAL_GetNextMonth(date);
539
MONTHCAL_GetPrevMonth(&st);
540
541
/* last calendar starts with some date from previous month that not displayed */
542
st.wDay = MONTHCAL_MonthLength(st.wMonth, st.wYear) +
543
(infoPtr->firstDay - first_day) % 7 + 1;
544
if (st.wDay > MONTHCAL_MonthLength(st.wMonth, st.wYear)) st.wDay -= 7;
545
546
/* Use month length to get max day. 42 means max day count in calendar area */
547
date->wDay = 42 - (MONTHCAL_MonthLength(st.wMonth, st.wYear) - st.wDay + 1) -
548
MONTHCAL_MonthLength(lt_month->wMonth, lt_month->wYear);
549
550
/* fix day of week */
551
MONTHCAL_CalculateDayOfWeek(date, TRUE);
552
}
553
554
/* From a given point calculate the row, column and day in the calendar,
555
'day == 0' means the last day of the last month. */
556
static int MONTHCAL_GetDayFromPos(const MONTHCAL_INFO *infoPtr, POINT pt, INT calIdx)
557
{
558
SYSTEMTIME st = infoPtr->calendars[calIdx].month;
559
int firstDay, col, row;
560
RECT client;
561
562
GetClientRect(infoPtr->hwndSelf, &client);
563
564
/* if the point is outside the x bounds of the window put it at the boundary */
565
if (pt.x > client.right) pt.x = client.right;
566
567
col = (pt.x - infoPtr->calendars[calIdx].days.left ) / infoPtr->width_increment;
568
row = (pt.y - infoPtr->calendars[calIdx].days.top ) / infoPtr->height_increment;
569
570
st.wDay = 1;
571
firstDay = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
572
return col + 7 * row - firstDay;
573
}
574
575
/* Get day position for given date and calendar
576
*
577
* PARAMETERS
578
*
579
* [I] infoPtr : pointer to control data
580
* [I] date : date value
581
* [O] col : day column (zero based)
582
* [O] row : week column (zero based)
583
* [I] calIdx : calendar index
584
*/
585
static void MONTHCAL_GetDayPos(const MONTHCAL_INFO *infoPtr, const SYSTEMTIME *date,
586
INT *col, INT *row, INT calIdx)
587
{
588
SYSTEMTIME st = infoPtr->calendars[calIdx].month;
589
INT first;
590
591
st.wDay = 1;
592
first = (MONTHCAL_CalculateDayOfWeek(&st, FALSE) + 6 - infoPtr->firstDay) % 7;
593
594
if (calIdx == 0 || calIdx == MONTHCAL_GetCalCount(infoPtr)-1) {
595
const SYSTEMTIME *cal = &infoPtr->calendars[calIdx].month;
596
LONG cmp = MONTHCAL_CompareMonths(date, &st);
597
598
/* previous month */
599
if (cmp == -1) {
600
*col = (first - MONTHCAL_MonthLength(date->wMonth, cal->wYear) + date->wDay) % 7;
601
*row = 0;
602
return;
603
}
604
605
/* next month calculation is same as for current, just add current month length */
606
if (cmp == 1)
607
first += MONTHCAL_MonthLength(cal->wMonth, cal->wYear);
608
}
609
610
*col = (date->wDay + first) % 7;
611
*row = (date->wDay + first - *col) / 7;
612
}
613
614
/* returns bounding box for day in given position in given calendar */
615
static inline void MONTHCAL_GetDayRectI(const MONTHCAL_INFO *infoPtr, RECT *r,
616
INT col, INT row, INT calIdx)
617
{
618
r->left = infoPtr->calendars[calIdx].days.left + col * infoPtr->width_increment;
619
r->right = r->left + infoPtr->width_increment;
620
r->top = infoPtr->calendars[calIdx].days.top + row * infoPtr->height_increment;
621
r->bottom = r->top + infoPtr->textHeight;
622
}
623
624
/* Returns bounding box for given date
625
*
626
* NOTE: when calendar index is unknown pass -1
627
*/
628
static BOOL MONTHCAL_GetDayRect(const MONTHCAL_INFO *infoPtr, const SYSTEMTIME *date, RECT *r, INT calIdx)
629
{
630
INT col, row;
631
632
if (!MONTHCAL_ValidateDate(date))
633
{
634
SetRectEmpty(r);
635
return FALSE;
636
}
637
638
if (calIdx == -1)
639
{
640
INT cmp = MONTHCAL_CompareMonths(date, &infoPtr->calendars[0].month);
641
642
if (cmp <= 0)
643
calIdx = 0;
644
else
645
{
646
cmp = MONTHCAL_CompareMonths(date, &infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month);
647
if (cmp >= 0)
648
calIdx = MONTHCAL_GetCalCount(infoPtr)-1;
649
else
650
{
651
for (calIdx = 1; calIdx < MONTHCAL_GetCalCount(infoPtr)-1; calIdx++)
652
if (MONTHCAL_CompareMonths(date, &infoPtr->calendars[calIdx].month) == 0)
653
break;
654
}
655
}
656
}
657
658
MONTHCAL_GetDayPos(infoPtr, date, &col, &row, calIdx);
659
MONTHCAL_GetDayRectI(infoPtr, r, col, row, calIdx);
660
661
return TRUE;
662
}
663
664
static LRESULT
665
MONTHCAL_GetMonthRange(const MONTHCAL_INFO *infoPtr, DWORD flag, SYSTEMTIME *st)
666
{
667
INT range;
668
669
TRACE("flags %#lx, st %p\n", flag, st);
670
671
switch (flag) {
672
case GMR_VISIBLE:
673
{
674
if (st)
675
{
676
st[0] = infoPtr->calendars[0].month;
677
st[1] = infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
678
679
if (st[0].wMonth == min_allowed_date.wMonth &&
680
st[0].wYear == min_allowed_date.wYear)
681
{
682
st[0].wDay = min_allowed_date.wDay;
683
}
684
else
685
st[0].wDay = 1;
686
MONTHCAL_CalculateDayOfWeek(&st[0], TRUE);
687
688
st[1].wDay = MONTHCAL_MonthLength(st[1].wMonth, st[1].wYear);
689
MONTHCAL_CalculateDayOfWeek(&st[1], TRUE);
690
}
691
692
range = MONTHCAL_GetCalCount(infoPtr);
693
break;
694
}
695
case GMR_DAYSTATE:
696
{
697
if (st)
698
{
699
MONTHCAL_GetMinDate(infoPtr, &st[0]);
700
MONTHCAL_GetMaxDate(infoPtr, &st[1]);
701
}
702
/* include two partially visible months */
703
range = MONTHCAL_GetCalCount(infoPtr) + 2;
704
break;
705
}
706
default:
707
WARN("Unknown flag value, got %ld\n", flag);
708
range = 0;
709
}
710
711
return range;
712
}
713
714
/* Focused day helper:
715
716
- set focused date to given value;
717
- reset to zero value if NULL passed;
718
- invalidate previous and new day rectangle only if needed.
719
720
Returns TRUE if focused day changed, FALSE otherwise.
721
*/
722
static BOOL MONTHCAL_SetDayFocus(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *st)
723
{
724
RECT r;
725
726
if(st)
727
{
728
/* there's nothing to do if it's the same date,
729
mouse move within same date rectangle case */
730
if(MONTHCAL_IsDateEqual(&infoPtr->focusedSel, st)) return FALSE;
731
732
/* invalidate old focused day */
733
if (MONTHCAL_GetDayRect(infoPtr, &infoPtr->focusedSel, &r, -1))
734
InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
735
736
infoPtr->focusedSel = *st;
737
}
738
739
/* On set invalidates new day, on reset clears previous focused day. */
740
if (MONTHCAL_GetDayRect(infoPtr, &infoPtr->focusedSel, &r, -1))
741
InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
742
743
if(!st && MONTHCAL_ValidateDate(&infoPtr->focusedSel))
744
infoPtr->focusedSel = st_null;
745
746
return TRUE;
747
}
748
749
/* draw today boundary box for specified rectangle */
750
static void MONTHCAL_Circle(const MONTHCAL_INFO *infoPtr, HDC hdc, const RECT *r)
751
{
752
HPEN old_pen = SelectObject(hdc, infoPtr->pens[PenRed]);
753
HBRUSH old_brush;
754
755
old_brush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
756
Rectangle(hdc, r->left, r->top, r->right, r->bottom);
757
758
SelectObject(hdc, old_brush);
759
SelectObject(hdc, old_pen);
760
}
761
762
/* Draw today day mark rectangle
763
*
764
* [I] hdc : context to draw in
765
* [I] date : day to mark with rectangle
766
*
767
*/
768
static void MONTHCAL_CircleDay(const MONTHCAL_INFO *infoPtr, HDC hdc,
769
const SYSTEMTIME *date)
770
{
771
RECT r;
772
773
MONTHCAL_GetDayRect(infoPtr, date, &r, -1);
774
MONTHCAL_Circle(infoPtr, hdc, &r);
775
}
776
777
static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, const SYSTEMTIME *st,
778
int bold, const PAINTSTRUCT *ps)
779
{
780
WCHAR buf[10];
781
RECT r, r_temp;
782
COLORREF oldCol = 0;
783
COLORREF oldBk = 0;
784
INT old_bkmode, selection;
785
786
/* no need to check styles: when selection is not valid, it is set to zero.
787
1 < day < 31, so everything is OK */
788
MONTHCAL_GetDayRect(infoPtr, st, &r, -1);
789
if(!IntersectRect(&r_temp, &(ps->rcPaint), &r)) return;
790
791
if ((MONTHCAL_CompareDate(st, &infoPtr->minSel) >= 0) &&
792
(MONTHCAL_CompareDate(st, &infoPtr->maxSel) <= 0))
793
{
794
TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
795
TRACE("%s\n", wine_dbgstr_rect(&r));
796
oldCol = SetTextColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
797
oldBk = SetBkColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
798
FillRect(hdc, &r, infoPtr->brushes[BrushTitle]);
799
800
selection = 1;
801
}
802
else
803
selection = 0;
804
805
SelectObject(hdc, bold ? infoPtr->hBoldFont : infoPtr->hFont);
806
807
old_bkmode = SetBkMode(hdc, TRANSPARENT);
808
wsprintfW(buf, L"%d", st->wDay);
809
DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
810
SetBkMode(hdc, old_bkmode);
811
812
if (selection)
813
{
814
SetTextColor(hdc, oldCol);
815
SetBkColor(hdc, oldBk);
816
}
817
}
818
819
static void MONTHCAL_PaintButton(MONTHCAL_INFO *infoPtr, HDC hdc, enum nav_direction button)
820
{
821
RECT *r = button == DIRECTION_FORWARD ? &infoPtr->titlebtnnext : &infoPtr->titlebtnprev;
822
BOOL pressed = button == DIRECTION_FORWARD ? infoPtr->status & MC_NEXTPRESSED :
823
infoPtr->status & MC_PREVPRESSED;
824
int style;
825
826
#if __WINE_COMCTL32_VERSION == 6
827
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
828
829
if (theme)
830
{
831
static const int states[] = {
832
/* Prev button */
833
ABS_LEFTNORMAL, ABS_LEFTPRESSED, ABS_LEFTDISABLED,
834
/* Next button */
835
ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, ABS_RIGHTDISABLED
836
};
837
int stateNum = button == DIRECTION_FORWARD ? 3 : 0;
838
if (pressed)
839
stateNum += 1;
840
else
841
{
842
if (infoPtr->dwStyle & WS_DISABLED) stateNum += 2;
843
}
844
DrawThemeBackground (theme, hdc, SBP_ARROWBTN, states[stateNum], r, NULL);
845
return;
846
}
847
#endif
848
849
style = button == DIRECTION_FORWARD ? DFCS_SCROLLRIGHT : DFCS_SCROLLLEFT;
850
if (pressed)
851
style |= DFCS_PUSHED;
852
else
853
{
854
if (infoPtr->dwStyle & WS_DISABLED)
855
style |= DFCS_INACTIVE;
856
}
857
858
DrawFrameControl(hdc, r, DFC_SCROLL, style);
859
}
860
861
/* paint a title with buttons and month/year string */
862
static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
863
{
864
RECT *title = &infoPtr->calendars[calIdx].title;
865
const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
866
WCHAR monthW[80], strW[80], fmtW[80], yearW[6] /* valid year range is 1601-30827 */;
867
int yearoffset, monthoffset, shiftX;
868
SIZE sz;
869
870
/* fill header box */
871
FillRect(hdc, title, infoPtr->brushes[BrushTitle]);
872
873
/* month/year string */
874
SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
875
SetTextColor(hdc, infoPtr->colors[MCSC_TITLETEXT]);
876
SelectObject(hdc, infoPtr->hBoldFont);
877
878
/* draw formatted date string */
879
GetDateFormatW(LOCALE_USER_DEFAULT, DATE_YEARMONTH, st, NULL, strW, ARRAY_SIZE(strW));
880
DrawTextW(hdc, strW, lstrlenW(strW), title, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
881
882
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SYEARMONTH, fmtW, ARRAY_SIZE(fmtW));
883
wsprintfW(yearW, L"%ld", st->wYear);
884
885
/* month is trickier as it's possible to have different format pictures, we'll
886
test for M, MM, MMM, and MMMM */
887
if (wcsstr(fmtW, L"MMMM"))
888
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+st->wMonth-1, monthW, ARRAY_SIZE(monthW));
889
else if (wcsstr(fmtW, L"MMM"))
890
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SABBREVMONTHNAME1+st->wMonth-1, monthW, ARRAY_SIZE(monthW));
891
else if (wcsstr(fmtW, L"MM"))
892
wsprintfW(monthW, L"%02d", st->wMonth);
893
else
894
wsprintfW(monthW, L"%d", st->wMonth);
895
896
/* update hit boxes */
897
yearoffset = 0;
898
while (strW[yearoffset])
899
{
900
if (!wcsncmp(&strW[yearoffset], yearW, lstrlenW(yearW)))
901
break;
902
yearoffset++;
903
}
904
905
monthoffset = 0;
906
while (strW[monthoffset])
907
{
908
if (!wcsncmp(&strW[monthoffset], monthW, lstrlenW(monthW)))
909
break;
910
monthoffset++;
911
}
912
913
/* for left limits use offsets */
914
sz.cx = 0;
915
if (yearoffset)
916
GetTextExtentPoint32W(hdc, strW, yearoffset, &sz);
917
infoPtr->calendars[calIdx].titleyear.left = sz.cx;
918
919
sz.cx = 0;
920
if (monthoffset)
921
GetTextExtentPoint32W(hdc, strW, monthoffset, &sz);
922
infoPtr->calendars[calIdx].titlemonth.left = sz.cx;
923
924
/* for right limits use actual string parts lengths */
925
GetTextExtentPoint32W(hdc, &strW[yearoffset], lstrlenW(yearW), &sz);
926
infoPtr->calendars[calIdx].titleyear.right = infoPtr->calendars[calIdx].titleyear.left + sz.cx;
927
928
GetTextExtentPoint32W(hdc, monthW, lstrlenW(monthW), &sz);
929
infoPtr->calendars[calIdx].titlemonth.right = infoPtr->calendars[calIdx].titlemonth.left + sz.cx;
930
931
/* Finally translate rectangles to match center aligned string,
932
hit rectangles are relative to title rectangle before translation. */
933
GetTextExtentPoint32W(hdc, strW, lstrlenW(strW), &sz);
934
shiftX = (title->right - title->left - sz.cx) / 2 + title->left;
935
OffsetRect(&infoPtr->calendars[calIdx].titleyear, shiftX, 0);
936
OffsetRect(&infoPtr->calendars[calIdx].titlemonth, shiftX, 0);
937
}
938
939
static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
940
{
941
const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
942
INT mindays, weeknum, weeknum1, startofprescal;
943
INT i, prev_month;
944
SYSTEMTIME st;
945
WCHAR buf[80];
946
HPEN old_pen;
947
RECT r;
948
949
if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
950
951
MONTHCAL_GetMinDate(infoPtr, &st);
952
startofprescal = st.wDay;
953
st = *date;
954
955
prev_month = date->wMonth - 1;
956
if(prev_month == 0) prev_month = 12;
957
958
/*
959
Rules what week to call the first week of a new year:
960
LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
961
The week containing Jan 1 is the first week of year
962
LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
963
First week of year must contain 4 days of the new year
964
LOCALE_IFIRSTWEEKOFYEAR == 1 (what countries?)
965
The first week of the year must contain only days of the new year
966
*/
967
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, ARRAY_SIZE(buf));
968
weeknum = wcstol(buf, NULL, 10);
969
switch (weeknum)
970
{
971
case 1: mindays = 6;
972
break;
973
case 2: mindays = 3;
974
break;
975
case 0: mindays = 0;
976
break;
977
default:
978
WARN("Unknown LOCALE_IFIRSTWEEKOFYEAR value %d, defaulting to 0\n", weeknum);
979
mindays = 0;
980
}
981
982
if (date->wMonth == 1)
983
{
984
/* calculate all those exceptions for January */
985
st.wDay = st.wMonth = 1;
986
weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
987
if ((infoPtr->firstDay - weeknum1) % 7 > mindays)
988
weeknum = 1;
989
else
990
{
991
weeknum = 0;
992
for(i = 0; i < 11; i++)
993
weeknum += MONTHCAL_MonthLength(i+1, date->wYear - 1);
994
995
weeknum += startofprescal + 7;
996
weeknum /= 7;
997
st.wYear -= 1;
998
weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
999
if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
1000
}
1001
}
1002
else
1003
{
1004
weeknum = 0;
1005
for(i = 0; i < prev_month - 1; i++)
1006
weeknum += MONTHCAL_MonthLength(i+1, date->wYear);
1007
1008
weeknum += startofprescal + 7;
1009
weeknum /= 7;
1010
st.wDay = st.wMonth = 1;
1011
weeknum1 = MONTHCAL_CalculateDayOfWeek(&st, FALSE);
1012
if ((infoPtr->firstDay - weeknum1) % 7 > mindays) weeknum++;
1013
}
1014
1015
r = infoPtr->calendars[calIdx].weeknums;
1016
1017
/* erase whole week numbers area */
1018
FillRect(hdc, &r, infoPtr->brushes[BrushMonth]);
1019
SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
1020
1021
/* reduce rectangle to one week number */
1022
r.bottom = r.top + infoPtr->height_increment;
1023
1024
for(i = 0; i < 6; i++) {
1025
if((i == 0) && (weeknum > 50))
1026
{
1027
wsprintfW(buf, L"%d", weeknum);
1028
weeknum = 0;
1029
}
1030
else if((i == 5) && (weeknum > 47))
1031
{
1032
wsprintfW(buf, L"%d", 1);
1033
}
1034
else
1035
wsprintfW(buf, L"%d", weeknum + i);
1036
1037
DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
1038
OffsetRect(&r, 0, infoPtr->height_increment);
1039
}
1040
1041
/* line separator for week numbers column */
1042
old_pen = SelectObject(hdc, infoPtr->pens[PenText]);
1043
MoveToEx(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.top + 3 , NULL);
1044
LineTo(hdc, infoPtr->calendars[calIdx].weeknums.right, infoPtr->calendars[calIdx].weeknums.bottom);
1045
SelectObject(hdc, old_pen);
1046
}
1047
1048
/* bottom today date */
1049
static void MONTHCAL_PaintTodayTitle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1050
{
1051
WCHAR buf_todayW[30], buf_dateW[20], buf[80];
1052
RECT text_rect, box_rect;
1053
HFONT old_font;
1054
INT col;
1055
1056
if(infoPtr->dwStyle & MCS_NOTODAY) return;
1057
1058
LoadStringW(COMCTL32_hModule, IDM_TODAY, buf_todayW, ARRAY_SIZE(buf_todayW));
1059
col = infoPtr->dwStyle & MCS_NOTODAYCIRCLE ? 0 : 1;
1060
if (infoPtr->dwStyle & MCS_WEEKNUMBERS) col--;
1061
/* label is located below first calendar last row */
1062
MONTHCAL_GetDayRectI(infoPtr, &text_rect, col, 6, infoPtr->dim.cx * infoPtr->dim.cy - infoPtr->dim.cx);
1063
box_rect = text_rect;
1064
1065
GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &infoPtr->todaysDate, NULL, buf_dateW, ARRAY_SIZE(buf_dateW));
1066
old_font = SelectObject(hdc, infoPtr->hBoldFont);
1067
SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
1068
1069
wsprintfW(buf, L"%s %s", buf_todayW, buf_dateW);
1070
DrawTextW(hdc, buf, -1, &text_rect, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1071
DrawTextW(hdc, buf, -1, &text_rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
1072
1073
if(!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE)) {
1074
OffsetRect(&box_rect, -infoPtr->width_increment, 0);
1075
MONTHCAL_Circle(infoPtr, hdc, &box_rect);
1076
}
1077
1078
SelectObject(hdc, old_font);
1079
}
1080
1081
/* today mark + focus */
1082
static void MONTHCAL_PaintFocusAndCircle(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1083
{
1084
/* circle today date if only it's in fully visible month */
1085
if (!(infoPtr->dwStyle & MCS_NOTODAYCIRCLE))
1086
{
1087
INT i;
1088
1089
for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1090
if (!MONTHCAL_CompareMonths(&infoPtr->todaysDate, &infoPtr->calendars[i].month))
1091
{
1092
MONTHCAL_CircleDay(infoPtr, hdc, &infoPtr->todaysDate);
1093
break;
1094
}
1095
}
1096
1097
if (!MONTHCAL_IsDateEqual(&infoPtr->focusedSel, &st_null))
1098
{
1099
RECT r;
1100
MONTHCAL_GetDayRect(infoPtr, &infoPtr->focusedSel, &r, -1);
1101
DrawFocusRect(hdc, &r);
1102
}
1103
}
1104
1105
/* months before first calendar month and after last calendar month */
1106
static void MONTHCAL_PaintLeadTrailMonths(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1107
{
1108
INT mask, index;
1109
UINT length;
1110
SYSTEMTIME st_max, st;
1111
1112
if (infoPtr->dwStyle & MCS_NOTRAILINGDATES) return;
1113
1114
SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
1115
1116
/* draw prev month */
1117
MONTHCAL_GetMinDate(infoPtr, &st);
1118
mask = 1 << (st.wDay-1);
1119
/* December and January both 31 days long, so no worries if wrapped */
1120
length = MONTHCAL_MonthLength(infoPtr->calendars[0].month.wMonth - 1,
1121
infoPtr->calendars[0].month.wYear);
1122
index = 0;
1123
while(st.wDay <= length)
1124
{
1125
MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[index] & mask, ps);
1126
mask <<= 1;
1127
st.wDay++;
1128
}
1129
1130
/* draw next month */
1131
st = infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
1132
st.wDay = 1;
1133
MONTHCAL_GetNextMonth(&st);
1134
MONTHCAL_GetMaxDate(infoPtr, &st_max);
1135
mask = 1;
1136
index = MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0)-1;
1137
while(st.wDay <= st_max.wDay)
1138
{
1139
MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[index] & mask, ps);
1140
mask <<= 1;
1141
st.wDay++;
1142
}
1143
}
1144
1145
static int get_localized_dayname(const MONTHCAL_INFO *infoPtr, unsigned int day, WCHAR *buff, unsigned int count)
1146
{
1147
LCTYPE lctype;
1148
1149
if (infoPtr->dwStyle & MCS_SHORTDAYSOFWEEK)
1150
lctype = LOCALE_SSHORTESTDAYNAME1 + day;
1151
else
1152
lctype = LOCALE_SABBREVDAYNAME1 + day;
1153
1154
return GetLocaleInfoW(LOCALE_USER_DEFAULT, lctype, buff, count);
1155
}
1156
1157
/* paint a calendar area */
1158
static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps, INT calIdx)
1159
{
1160
const SYSTEMTIME *date = &infoPtr->calendars[calIdx].month;
1161
INT i, j;
1162
UINT length;
1163
RECT r, fill_bk_rect;
1164
SYSTEMTIME st;
1165
WCHAR buf[80];
1166
HPEN old_pen;
1167
int mask;
1168
1169
/* fill whole days area - from week days area to today note rectangle */
1170
fill_bk_rect = infoPtr->calendars[calIdx].wdays;
1171
fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
1172
(infoPtr->todayrect.bottom - infoPtr->todayrect.top);
1173
1174
FillRect(hdc, &fill_bk_rect, infoPtr->brushes[BrushMonth]);
1175
1176
/* draw line under day abbreviations */
1177
old_pen = SelectObject(hdc, infoPtr->pens[PenText]);
1178
MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
1179
infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1, NULL);
1180
LineTo(hdc, infoPtr->calendars[calIdx].days.right - 3,
1181
infoPtr->calendars[calIdx].title.bottom + infoPtr->textHeight + 1);
1182
SelectObject(hdc, old_pen);
1183
1184
infoPtr->calendars[calIdx].wdays.left = infoPtr->calendars[calIdx].days.left =
1185
infoPtr->calendars[calIdx].weeknums.right;
1186
1187
/* draw day abbreviations */
1188
SelectObject(hdc, infoPtr->hFont);
1189
SetBkColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
1190
SetTextColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
1191
/* rectangle to draw a single day abbreviation within */
1192
r = infoPtr->calendars[calIdx].wdays;
1193
r.right = r.left + infoPtr->width_increment;
1194
1195
i = infoPtr->firstDay;
1196
for(j = 0; j < 7; j++) {
1197
get_localized_dayname(infoPtr, (i + j + 6) % 7, buf, ARRAY_SIZE(buf));
1198
DrawTextW(hdc, buf, lstrlenW(buf), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
1199
OffsetRect(&r, infoPtr->width_increment, 0);
1200
}
1201
1202
/* draw current month */
1203
SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
1204
st = *date;
1205
st.wDay = 1;
1206
mask = 1;
1207
length = MONTHCAL_MonthLength(date->wMonth, date->wYear);
1208
while(st.wDay <= length)
1209
{
1210
MONTHCAL_DrawDay(infoPtr, hdc, &st, infoPtr->monthdayState[calIdx+1] & mask, ps);
1211
mask <<= 1;
1212
st.wDay++;
1213
}
1214
}
1215
1216
static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRUCT *ps)
1217
{
1218
COLORREF old_text_clr, old_bk_clr;
1219
HFONT old_font;
1220
INT i;
1221
1222
old_text_clr = SetTextColor(hdc, comctl32_color.clrWindowText);
1223
old_bk_clr = GetBkColor(hdc);
1224
old_font = GetCurrentObject(hdc, OBJ_FONT);
1225
1226
for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1227
{
1228
RECT *title = &infoPtr->calendars[i].title;
1229
RECT r;
1230
1231
/* draw title, redraw all its elements */
1232
if (IntersectRect(&r, &(ps->rcPaint), title))
1233
MONTHCAL_PaintTitle(infoPtr, hdc, ps, i);
1234
1235
/* draw calendar area */
1236
UnionRect(&r, &infoPtr->calendars[i].wdays, &infoPtr->todayrect);
1237
if (IntersectRect(&r, &(ps->rcPaint), &r))
1238
MONTHCAL_PaintCalendar(infoPtr, hdc, ps, i);
1239
1240
/* week numbers */
1241
MONTHCAL_PaintWeeknumbers(infoPtr, hdc, ps, i);
1242
}
1243
1244
/* partially visible months */
1245
MONTHCAL_PaintLeadTrailMonths(infoPtr, hdc, ps);
1246
1247
/* focus and today rectangle */
1248
MONTHCAL_PaintFocusAndCircle(infoPtr, hdc, ps);
1249
1250
/* today at the bottom left */
1251
MONTHCAL_PaintTodayTitle(infoPtr, hdc, ps);
1252
1253
/* navigation buttons */
1254
MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_BACKWARD);
1255
MONTHCAL_PaintButton(infoPtr, hdc, DIRECTION_FORWARD);
1256
1257
/* restore context */
1258
SetBkColor(hdc, old_bk_clr);
1259
SelectObject(hdc, old_font);
1260
SetTextColor(hdc, old_text_clr);
1261
}
1262
1263
static LRESULT
1264
MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, RECT *rect)
1265
{
1266
TRACE("rect %p\n", rect);
1267
1268
if(!rect) return FALSE;
1269
1270
*rect = infoPtr->calendars[0].title;
1271
rect->bottom = infoPtr->calendars[0].days.bottom + infoPtr->todayrect.bottom -
1272
infoPtr->todayrect.top;
1273
1274
AdjustWindowRect(rect, infoPtr->dwStyle, FALSE);
1275
1276
/* minimal rectangle is zero based */
1277
OffsetRect(rect, -rect->left, -rect->top);
1278
1279
TRACE("%s\n", wine_dbgstr_rect(rect));
1280
1281
return TRUE;
1282
}
1283
1284
static COLORREF
1285
MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, UINT index)
1286
{
1287
TRACE("%p, %d\n", infoPtr, index);
1288
1289
if (index > MCSC_TRAILINGTEXT) return -1;
1290
return infoPtr->colors[index];
1291
}
1292
1293
static LRESULT
1294
MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
1295
{
1296
enum CachedBrush type;
1297
COLORREF prev;
1298
1299
TRACE("%p, %d: color %#lx\n", infoPtr, index, color);
1300
1301
if (index > MCSC_TRAILINGTEXT) return -1;
1302
1303
prev = infoPtr->colors[index];
1304
infoPtr->colors[index] = color;
1305
1306
/* update cached brush */
1307
switch (index)
1308
{
1309
case MCSC_BACKGROUND:
1310
type = BrushBackground;
1311
break;
1312
case MCSC_TITLEBK:
1313
type = BrushTitle;
1314
break;
1315
case MCSC_MONTHBK:
1316
type = BrushMonth;
1317
break;
1318
default:
1319
type = BrushLast;
1320
}
1321
1322
if (type != BrushLast)
1323
{
1324
DeleteObject(infoPtr->brushes[type]);
1325
infoPtr->brushes[type] = CreateSolidBrush(color);
1326
}
1327
1328
/* update cached pen */
1329
if (index == MCSC_TEXT)
1330
{
1331
DeleteObject(infoPtr->pens[PenText]);
1332
infoPtr->pens[PenText] = CreatePen(PS_SOLID, 1, infoPtr->colors[index]);
1333
}
1334
1335
InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND);
1336
return prev;
1337
}
1338
1339
static LRESULT
1340
MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
1341
{
1342
TRACE("\n");
1343
1344
if(infoPtr->delta)
1345
return infoPtr->delta;
1346
1347
return MONTHCAL_GetMonthRange(infoPtr, GMR_VISIBLE, NULL);
1348
}
1349
1350
1351
static LRESULT
1352
MONTHCAL_SetMonthDelta(MONTHCAL_INFO *infoPtr, INT delta)
1353
{
1354
INT prev = infoPtr->delta;
1355
1356
TRACE("delta %d\n", delta);
1357
1358
infoPtr->delta = delta;
1359
return prev;
1360
}
1361
1362
1363
static inline LRESULT
1364
MONTHCAL_GetFirstDayOfWeek(const MONTHCAL_INFO *infoPtr)
1365
{
1366
int day;
1367
1368
/* convert from SYSTEMTIME to locale format */
1369
day = (infoPtr->firstDay >= 0) ? (infoPtr->firstDay+6)%7 : infoPtr->firstDay;
1370
1371
return MAKELONG(day, infoPtr->firstDaySet);
1372
}
1373
1374
1375
/* Sets the first day of the week that will appear in the control
1376
*
1377
*
1378
* PARAMETERS:
1379
* [I] infoPtr : valid pointer to control data
1380
* [I] day : day number to set as new first day (0 == Monday,...,6 == Sunday)
1381
*
1382
*
1383
* RETURN VALUE:
1384
* Low word contains previous first day,
1385
* high word indicates was first day forced with this message before or is
1386
* locale defined (TRUE - was forced, FALSE - wasn't).
1387
*
1388
* FIXME: this needs to be implemented properly in MONTHCAL_Refresh()
1389
* FIXME: we need more error checking here
1390
*/
1391
static LRESULT
1392
MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, INT day)
1393
{
1394
LRESULT prev = MONTHCAL_GetFirstDayOfWeek(infoPtr);
1395
int new_day;
1396
1397
TRACE("%d\n", day);
1398
1399
if(day == -1)
1400
{
1401
WCHAR buf[80];
1402
1403
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, ARRAY_SIZE(buf));
1404
TRACE("%s %d\n", debugstr_w(buf), lstrlenW(buf));
1405
1406
new_day = wcstol(buf, NULL, 10);
1407
1408
infoPtr->firstDaySet = FALSE;
1409
}
1410
else if(day >= 7)
1411
{
1412
new_day = 6; /* max first day allowed */
1413
infoPtr->firstDaySet = TRUE;
1414
}
1415
else
1416
{
1417
/* Native behaviour for that case is broken: invalid date number >31
1418
got displayed at (0,0) position, current month starts always from
1419
(1,0) position. Should be implemented here as well only if there's
1420
nothing else to do. */
1421
if (day < -1)
1422
FIXME("No bug compatibility for day=%d\n", day);
1423
1424
new_day = day;
1425
infoPtr->firstDaySet = TRUE;
1426
}
1427
1428
/* convert from locale to SYSTEMTIME format */
1429
infoPtr->firstDay = (new_day >= 0) ? (++new_day) % 7 : new_day;
1430
1431
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1432
1433
return prev;
1434
}
1435
1436
static LRESULT
1437
MONTHCAL_GetMaxTodayWidth(const MONTHCAL_INFO *infoPtr)
1438
{
1439
return(infoPtr->todayrect.right - infoPtr->todayrect.left);
1440
}
1441
1442
static LRESULT
1443
MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, SHORT limits, SYSTEMTIME *range)
1444
{
1445
FILETIME ft_min, ft_max;
1446
1447
TRACE("%x %p\n", limits, range);
1448
1449
if ((limits & GDTR_MIN && !MONTHCAL_ValidateDate(&range[0])) ||
1450
(limits & GDTR_MAX && !MONTHCAL_ValidateDate(&range[1])))
1451
return FALSE;
1452
1453
infoPtr->rangeValid = 0;
1454
infoPtr->minDate = infoPtr->maxDate = st_null;
1455
1456
if (limits & GDTR_MIN)
1457
{
1458
if (!MONTHCAL_ValidateTime(&range[0]))
1459
MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1460
1461
infoPtr->minDate = range[0];
1462
infoPtr->rangeValid |= GDTR_MIN;
1463
}
1464
if (limits & GDTR_MAX)
1465
{
1466
if (!MONTHCAL_ValidateTime(&range[1]))
1467
MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1468
1469
infoPtr->maxDate = range[1];
1470
infoPtr->rangeValid |= GDTR_MAX;
1471
}
1472
1473
/* Only one limit set - we are done */
1474
if ((infoPtr->rangeValid & (GDTR_MIN | GDTR_MAX)) != (GDTR_MIN | GDTR_MAX))
1475
return TRUE;
1476
1477
SystemTimeToFileTime(&infoPtr->maxDate, &ft_max);
1478
SystemTimeToFileTime(&infoPtr->minDate, &ft_min);
1479
1480
if (CompareFileTime(&ft_min, &ft_max) >= 0)
1481
{
1482
if ((limits & (GDTR_MIN | GDTR_MAX)) == (GDTR_MIN | GDTR_MAX))
1483
{
1484
/* Native swaps limits only when both limits are being set. */
1485
SYSTEMTIME st_tmp = infoPtr->minDate;
1486
infoPtr->minDate = infoPtr->maxDate;
1487
infoPtr->maxDate = st_tmp;
1488
}
1489
else
1490
{
1491
/* reset the other limit */
1492
if (limits & GDTR_MIN) infoPtr->maxDate = st_null;
1493
if (limits & GDTR_MAX) infoPtr->minDate = st_null;
1494
infoPtr->rangeValid &= limits & GDTR_MIN ? ~GDTR_MAX : ~GDTR_MIN;
1495
}
1496
}
1497
1498
return TRUE;
1499
}
1500
1501
1502
static LRESULT
1503
MONTHCAL_GetRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1504
{
1505
TRACE("%p\n", range);
1506
1507
if (!range) return 0;
1508
1509
range[1] = infoPtr->maxDate;
1510
range[0] = infoPtr->minDate;
1511
1512
return infoPtr->rangeValid;
1513
}
1514
1515
1516
static LRESULT
1517
MONTHCAL_SetDayState(const MONTHCAL_INFO *infoPtr, INT months, MONTHDAYSTATE *states)
1518
{
1519
TRACE("%p %d %p\n", infoPtr, months, states);
1520
1521
if (!(infoPtr->dwStyle & MCS_DAYSTATE)) return 0;
1522
if (months != MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0)) return 0;
1523
1524
memcpy(infoPtr->monthdayState, states, months*sizeof(MONTHDAYSTATE));
1525
1526
return 1;
1527
}
1528
1529
static LRESULT
1530
MONTHCAL_GetCurSel(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1531
{
1532
TRACE("%p\n", curSel);
1533
if(!curSel) return FALSE;
1534
if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1535
1536
*curSel = infoPtr->minSel;
1537
TRACE("%d/%d/%d\n", curSel->wYear, curSel->wMonth, curSel->wDay);
1538
return TRUE;
1539
}
1540
1541
static LRESULT
1542
MONTHCAL_SetCurSel(MONTHCAL_INFO *infoPtr, SYSTEMTIME *curSel)
1543
{
1544
SYSTEMTIME prev = infoPtr->minSel, selection;
1545
INT diff;
1546
WORD day;
1547
1548
TRACE("%p\n", curSel);
1549
if(!curSel) return FALSE;
1550
if(infoPtr->dwStyle & MCS_MULTISELECT) return FALSE;
1551
1552
if(!MONTHCAL_ValidateDate(curSel)) return FALSE;
1553
/* exit earlier if selection equals current */
1554
if (MONTHCAL_IsDateEqual(&infoPtr->minSel, curSel)) return TRUE;
1555
1556
selection = *curSel;
1557
selection.wHour = selection.wMinute = selection.wSecond = selection.wMilliseconds = 0;
1558
MONTHCAL_CalculateDayOfWeek(&selection, TRUE);
1559
1560
if(!MONTHCAL_IsDateInValidRange(infoPtr, &selection, FALSE)) return FALSE;
1561
1562
/* scroll calendars only if we have to */
1563
diff = MONTHCAL_MonthDiff(&infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month, curSel);
1564
if (diff <= 0)
1565
{
1566
diff = MONTHCAL_MonthDiff(&infoPtr->calendars[0].month, curSel);
1567
if (diff > 0) diff = 0;
1568
}
1569
1570
if (diff != 0)
1571
{
1572
INT i;
1573
1574
for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1575
MONTHCAL_GetMonth(&infoPtr->calendars[i].month, diff);
1576
}
1577
1578
/* we need to store time part as it is */
1579
selection = *curSel;
1580
MONTHCAL_CalculateDayOfWeek(&selection, TRUE);
1581
infoPtr->minSel = infoPtr->maxSel = selection;
1582
1583
/* if selection is still in current month, reduce rectangle */
1584
day = prev.wDay;
1585
prev.wDay = curSel->wDay;
1586
if (MONTHCAL_IsDateEqual(&prev, curSel))
1587
{
1588
RECT r_prev, r_new;
1589
1590
prev.wDay = day;
1591
MONTHCAL_GetDayRect(infoPtr, &prev, &r_prev, -1);
1592
MONTHCAL_GetDayRect(infoPtr, curSel, &r_new, -1);
1593
1594
InvalidateRect(infoPtr->hwndSelf, &r_prev, FALSE);
1595
InvalidateRect(infoPtr->hwndSelf, &r_new, FALSE);
1596
}
1597
else
1598
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1599
1600
return TRUE;
1601
}
1602
1603
1604
static LRESULT
1605
MONTHCAL_GetMaxSelCount(const MONTHCAL_INFO *infoPtr)
1606
{
1607
return infoPtr->maxSelCount;
1608
}
1609
1610
1611
static LRESULT
1612
MONTHCAL_SetMaxSelCount(MONTHCAL_INFO *infoPtr, INT max)
1613
{
1614
TRACE("%d\n", max);
1615
1616
if(!(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1617
if(max <= 0) return FALSE;
1618
1619
infoPtr->maxSelCount = max;
1620
1621
return TRUE;
1622
}
1623
1624
1625
static LRESULT
1626
MONTHCAL_GetSelRange(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1627
{
1628
TRACE("%p\n", range);
1629
1630
if(!range) return FALSE;
1631
1632
if(infoPtr->dwStyle & MCS_MULTISELECT)
1633
{
1634
range[1] = infoPtr->maxSel;
1635
range[0] = infoPtr->minSel;
1636
TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1637
return TRUE;
1638
}
1639
1640
return FALSE;
1641
}
1642
1643
1644
static LRESULT
1645
MONTHCAL_SetSelRange(MONTHCAL_INFO *infoPtr, SYSTEMTIME *range)
1646
{
1647
SYSTEMTIME old_range[2];
1648
INT diff;
1649
1650
TRACE("%p\n", range);
1651
1652
if(!range || !(infoPtr->dwStyle & MCS_MULTISELECT)) return FALSE;
1653
1654
/* adjust timestamps */
1655
if(!MONTHCAL_ValidateTime(&range[0])) MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[0]);
1656
if(!MONTHCAL_ValidateTime(&range[1])) MONTHCAL_CopyTime(&infoPtr->todaysDate, &range[1]);
1657
1658
/* maximum range exceeded */
1659
if(!MONTHCAL_IsSelRangeValid(infoPtr, &range[0], &range[1], NULL)) return FALSE;
1660
1661
old_range[0] = infoPtr->minSel;
1662
old_range[1] = infoPtr->maxSel;
1663
1664
/* swap if min > max */
1665
if(MONTHCAL_CompareSystemTime(&range[0], &range[1]) <= 0)
1666
{
1667
infoPtr->minSel = range[0];
1668
infoPtr->maxSel = range[1];
1669
}
1670
else
1671
{
1672
infoPtr->minSel = range[1];
1673
infoPtr->maxSel = range[0];
1674
}
1675
1676
diff = MONTHCAL_MonthDiff(&infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month, &infoPtr->maxSel);
1677
if (diff < 0)
1678
{
1679
diff = MONTHCAL_MonthDiff(&infoPtr->calendars[0].month, &infoPtr->maxSel);
1680
if (diff > 0) diff = 0;
1681
}
1682
1683
if (diff != 0)
1684
{
1685
INT i;
1686
1687
for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1688
MONTHCAL_GetMonth(&infoPtr->calendars[i].month, diff);
1689
}
1690
1691
/* update day of week */
1692
MONTHCAL_CalculateDayOfWeek(&infoPtr->minSel, TRUE);
1693
MONTHCAL_CalculateDayOfWeek(&infoPtr->maxSel, TRUE);
1694
1695
/* redraw if bounds changed */
1696
/* FIXME: no actual need to redraw everything */
1697
if(!MONTHCAL_IsDateEqual(&old_range[0], &range[0]) ||
1698
!MONTHCAL_IsDateEqual(&old_range[1], &range[1]))
1699
{
1700
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1701
}
1702
1703
TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
1704
return TRUE;
1705
}
1706
1707
1708
static LRESULT
1709
MONTHCAL_GetToday(const MONTHCAL_INFO *infoPtr, SYSTEMTIME *today)
1710
{
1711
TRACE("%p\n", today);
1712
1713
if(!today) return FALSE;
1714
*today = infoPtr->todaysDate;
1715
return TRUE;
1716
}
1717
1718
/* Internal helper for MCM_SETTODAY handler and auto update timer handler
1719
*
1720
* RETURN VALUE
1721
*
1722
* TRUE - today date changed
1723
* FALSE - today date isn't changed
1724
*/
1725
static BOOL
1726
MONTHCAL_UpdateToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1727
{
1728
RECT rect;
1729
1730
if (MONTHCAL_IsDateEqual(today, &infoPtr->todaysDate))
1731
return FALSE;
1732
1733
/* Invalidate old and new today day rectangle, and today label. */
1734
if (MONTHCAL_GetDayRect(infoPtr, &infoPtr->todaysDate, &rect, -1))
1735
InvalidateRect(infoPtr->hwndSelf, &rect, FALSE);
1736
1737
if (MONTHCAL_GetDayRect(infoPtr, today, &rect, -1))
1738
InvalidateRect(infoPtr->hwndSelf, &rect, FALSE);
1739
1740
infoPtr->todaysDate = *today;
1741
1742
InvalidateRect(infoPtr->hwndSelf, &infoPtr->todayrect, FALSE);
1743
return TRUE;
1744
}
1745
1746
/* MCM_SETTODAT handler */
1747
static LRESULT
1748
MONTHCAL_SetToday(MONTHCAL_INFO *infoPtr, const SYSTEMTIME *today)
1749
{
1750
TRACE("%p\n", today);
1751
1752
if (today)
1753
{
1754
/* remember if date was set successfully */
1755
if (MONTHCAL_UpdateToday(infoPtr, today)) infoPtr->todaySet = TRUE;
1756
}
1757
1758
return 0;
1759
}
1760
1761
/* returns calendar index containing specified point, or -1 if it's background */
1762
static INT MONTHCAL_GetCalendarFromPoint(const MONTHCAL_INFO *infoPtr, const POINT *pt)
1763
{
1764
RECT r;
1765
INT i;
1766
1767
for (i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1768
{
1769
/* whole bounding rectangle allows some optimization to compute */
1770
r.left = infoPtr->calendars[i].title.left;
1771
r.top = infoPtr->calendars[i].title.top;
1772
r.bottom = infoPtr->calendars[i].days.bottom;
1773
r.right = infoPtr->calendars[i].days.right;
1774
1775
if (PtInRect(&r, *pt)) return i;
1776
}
1777
1778
return -1;
1779
}
1780
1781
static inline UINT fill_hittest_info(const MCHITTESTINFO *src, MCHITTESTINFO *dest)
1782
{
1783
dest->uHit = src->uHit;
1784
dest->st = src->st;
1785
1786
if (dest->cbSize == sizeof(MCHITTESTINFO))
1787
memcpy(&dest->rc, &src->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1788
1789
return src->uHit;
1790
}
1791
1792
static LRESULT
1793
MONTHCAL_HitTest(const MONTHCAL_INFO *infoPtr, MCHITTESTINFO *lpht)
1794
{
1795
MCHITTESTINFO htinfo;
1796
SYSTEMTIME *ht_month;
1797
INT day, calIdx;
1798
1799
if(!lpht || lpht->cbSize < MCHITTESTINFO_V1_SIZE) return -1;
1800
1801
htinfo.st = st_null;
1802
htinfo.uHit = 0;
1803
1804
/* we should preserve passed fields if hit area doesn't need them */
1805
if (lpht->cbSize == sizeof(MCHITTESTINFO))
1806
memcpy(&htinfo.rc, &lpht->rc, sizeof(MCHITTESTINFO) - MCHITTESTINFO_V1_SIZE);
1807
1808
/* guess in what calendar we are */
1809
calIdx = MONTHCAL_GetCalendarFromPoint(infoPtr, &lpht->pt);
1810
if (calIdx == -1)
1811
{
1812
if (PtInRect(&infoPtr->todayrect, lpht->pt))
1813
{
1814
htinfo.uHit = MCHT_TODAYLINK;
1815
htinfo.rc = infoPtr->todayrect;
1816
}
1817
else
1818
/* outside of calendar area? What's left must be background :-) */
1819
htinfo.uHit = MCHT_CALENDARBK;
1820
1821
return fill_hittest_info(&htinfo, lpht);
1822
}
1823
1824
/* are we in the header? */
1825
if (PtInRect(&infoPtr->calendars[calIdx].title, lpht->pt)) {
1826
/* FIXME: buttons hittesting could be optimized cause maximum
1827
two calendars have buttons */
1828
if (calIdx == 0 && PtInRect(&infoPtr->titlebtnprev, lpht->pt))
1829
{
1830
htinfo.uHit = MCHT_TITLEBTNPREV;
1831
htinfo.rc = infoPtr->titlebtnprev;
1832
}
1833
else if (PtInRect(&infoPtr->titlebtnnext, lpht->pt))
1834
{
1835
htinfo.uHit = MCHT_TITLEBTNNEXT;
1836
htinfo.rc = infoPtr->titlebtnnext;
1837
}
1838
else if (PtInRect(&infoPtr->calendars[calIdx].titlemonth, lpht->pt))
1839
{
1840
htinfo.uHit = MCHT_TITLEMONTH;
1841
htinfo.rc = infoPtr->calendars[calIdx].titlemonth;
1842
htinfo.iOffset = calIdx;
1843
}
1844
else if (PtInRect(&infoPtr->calendars[calIdx].titleyear, lpht->pt))
1845
{
1846
htinfo.uHit = MCHT_TITLEYEAR;
1847
htinfo.rc = infoPtr->calendars[calIdx].titleyear;
1848
htinfo.iOffset = calIdx;
1849
}
1850
else
1851
{
1852
htinfo.uHit = MCHT_TITLE;
1853
htinfo.rc = infoPtr->calendars[calIdx].title;
1854
htinfo.iOffset = calIdx;
1855
}
1856
1857
return fill_hittest_info(&htinfo, lpht);
1858
}
1859
1860
ht_month = &infoPtr->calendars[calIdx].month;
1861
/* days area (including week days and week numbers) */
1862
day = MONTHCAL_GetDayFromPos(infoPtr, lpht->pt, calIdx);
1863
if (PtInRect(&infoPtr->calendars[calIdx].wdays, lpht->pt))
1864
{
1865
htinfo.uHit = MCHT_CALENDARDAY;
1866
htinfo.iOffset = calIdx;
1867
htinfo.st.wYear = ht_month->wYear;
1868
htinfo.st.wMonth = (day < 1) ? ht_month->wMonth -1 : ht_month->wMonth;
1869
htinfo.st.wDay = (day < 1) ?
1870
MONTHCAL_MonthLength(ht_month->wMonth-1, ht_month->wYear) - day : day;
1871
1872
MONTHCAL_GetDayPos(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow, calIdx);
1873
}
1874
else if(PtInRect(&infoPtr->calendars[calIdx].weeknums, lpht->pt))
1875
{
1876
htinfo.uHit = MCHT_CALENDARWEEKNUM;
1877
htinfo.st.wYear = ht_month->wYear;
1878
htinfo.iOffset = calIdx;
1879
1880
if (day < 1)
1881
{
1882
htinfo.st.wMonth = ht_month->wMonth - 1;
1883
htinfo.st.wDay = MONTHCAL_MonthLength(ht_month->wMonth-1, ht_month->wYear) - day;
1884
}
1885
else if (day > MONTHCAL_MonthLength(ht_month->wMonth, ht_month->wYear))
1886
{
1887
htinfo.st.wMonth = ht_month->wMonth + 1;
1888
htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month->wMonth, ht_month->wYear);
1889
}
1890
else
1891
{
1892
htinfo.st.wMonth = ht_month->wMonth;
1893
htinfo.st.wDay = day;
1894
}
1895
}
1896
else if(PtInRect(&infoPtr->calendars[calIdx].days, lpht->pt))
1897
{
1898
htinfo.iOffset = calIdx;
1899
htinfo.st.wDay = ht_month->wDay;
1900
htinfo.st.wYear = ht_month->wYear;
1901
htinfo.st.wMonth = ht_month->wMonth;
1902
/* previous month only valid for first calendar */
1903
if (day < 1 && calIdx == 0)
1904
{
1905
htinfo.uHit = MCHT_CALENDARDATEPREV;
1906
MONTHCAL_GetPrevMonth(&htinfo.st);
1907
htinfo.st.wDay = MONTHCAL_MonthLength(htinfo.st.wMonth, htinfo.st.wYear) + day;
1908
}
1909
/* next month only valid for last calendar */
1910
else if (day > MONTHCAL_MonthLength(ht_month->wMonth, ht_month->wYear) &&
1911
calIdx == MONTHCAL_GetCalCount(infoPtr)-1)
1912
{
1913
htinfo.uHit = MCHT_CALENDARDATENEXT;
1914
MONTHCAL_GetNextMonth(&htinfo.st);
1915
htinfo.st.wDay = day - MONTHCAL_MonthLength(ht_month->wMonth, ht_month->wYear);
1916
}
1917
/* multiple calendars case - blank areas for previous/next month */
1918
else if (day < 1 || day > MONTHCAL_MonthLength(ht_month->wMonth, ht_month->wYear))
1919
{
1920
htinfo.uHit = MCHT_CALENDARBK;
1921
}
1922
else
1923
{
1924
htinfo.uHit = MCHT_CALENDARDATE;
1925
htinfo.st.wDay = day;
1926
}
1927
1928
MONTHCAL_GetDayPos(infoPtr, &htinfo.st, &htinfo.iCol, &htinfo.iRow, calIdx);
1929
MONTHCAL_GetDayRectI(infoPtr, &htinfo.rc, htinfo.iCol, htinfo.iRow, calIdx);
1930
/* always update day of week */
1931
MONTHCAL_CalculateDayOfWeek(&htinfo.st, TRUE);
1932
}
1933
1934
return fill_hittest_info(&htinfo, lpht);
1935
}
1936
1937
/* MCN_GETDAYSTATE notification helper */
1938
static void MONTHCAL_NotifyDayState(MONTHCAL_INFO *infoPtr)
1939
{
1940
MONTHDAYSTATE *state;
1941
NMDAYSTATE nmds;
1942
1943
if (!(infoPtr->dwStyle & MCS_DAYSTATE)) return;
1944
1945
nmds.nmhdr.hwndFrom = infoPtr->hwndSelf;
1946
nmds.nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
1947
nmds.nmhdr.code = MCN_GETDAYSTATE;
1948
nmds.cDayState = MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0);
1949
nmds.prgDayState = state = Alloc(nmds.cDayState * sizeof(MONTHDAYSTATE));
1950
1951
MONTHCAL_GetMinDate(infoPtr, &nmds.stStart);
1952
nmds.stStart.wDay = 1;
1953
1954
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmds.nmhdr.idFrom, (LPARAM)&nmds);
1955
memcpy(infoPtr->monthdayState, nmds.prgDayState,
1956
MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0)*sizeof(MONTHDAYSTATE));
1957
1958
Free(state);
1959
}
1960
1961
/* no valid range check performed */
1962
static void MONTHCAL_Scroll(MONTHCAL_INFO *infoPtr, INT delta, BOOL keep_selection)
1963
{
1964
INT i, selIdx = -1;
1965
1966
for(i = 0; i < MONTHCAL_GetCalCount(infoPtr); i++)
1967
{
1968
/* save selection position to shift it later */
1969
if (selIdx == -1 && MONTHCAL_CompareMonths(&infoPtr->minSel, &infoPtr->calendars[i].month) == 0)
1970
selIdx = i;
1971
1972
MONTHCAL_GetMonth(&infoPtr->calendars[i].month, delta);
1973
}
1974
1975
if (keep_selection)
1976
return;
1977
1978
/* selection is always shifted to first calendar */
1979
if (infoPtr->dwStyle & MCS_MULTISELECT)
1980
{
1981
SYSTEMTIME range[2];
1982
1983
MONTHCAL_GetSelRange(infoPtr, range);
1984
MONTHCAL_GetMonth(&range[0], delta - selIdx);
1985
MONTHCAL_GetMonth(&range[1], delta - selIdx);
1986
MONTHCAL_SetSelRange(infoPtr, range);
1987
}
1988
else
1989
{
1990
SYSTEMTIME st = infoPtr->minSel;
1991
1992
MONTHCAL_GetMonth(&st, delta - selIdx);
1993
MONTHCAL_SetCurSel(infoPtr, &st);
1994
}
1995
}
1996
1997
static void MONTHCAL_GoToMonth(MONTHCAL_INFO *infoPtr, enum nav_direction direction)
1998
{
1999
INT delta = infoPtr->delta ? infoPtr->delta : MONTHCAL_GetCalCount(infoPtr);
2000
BOOL keep_selection;
2001
SYSTEMTIME st;
2002
2003
TRACE("%s\n", direction == DIRECTION_BACKWARD ? "back" : "fwd");
2004
2005
/* check if change allowed by range set */
2006
if(direction == DIRECTION_BACKWARD)
2007
{
2008
st = infoPtr->calendars[0].month;
2009
MONTHCAL_GetMonth(&st, -delta);
2010
}
2011
else
2012
{
2013
st = infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
2014
MONTHCAL_GetMonth(&st, delta);
2015
}
2016
2017
if(!MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE)) return;
2018
2019
keep_selection = infoPtr->dwStyle & MCS_NOSELCHANGEONNAV;
2020
MONTHCAL_Scroll(infoPtr, direction == DIRECTION_BACKWARD ? -delta : delta, keep_selection);
2021
MONTHCAL_NotifyDayState(infoPtr);
2022
if (!keep_selection)
2023
MONTHCAL_NotifySelectionChange(infoPtr);
2024
}
2025
2026
static LRESULT
2027
MONTHCAL_RButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2028
{
2029
HMENU hMenu;
2030
POINT menupoint;
2031
WCHAR buf[32];
2032
2033
hMenu = CreatePopupMenu();
2034
LoadStringW(COMCTL32_hModule, IDM_GOTODAY, buf, ARRAY_SIZE(buf));
2035
AppendMenuW(hMenu, MF_STRING|MF_ENABLED, 1, buf);
2036
menupoint.x = (short)LOWORD(lParam);
2037
menupoint.y = (short)HIWORD(lParam);
2038
ClientToScreen(infoPtr->hwndSelf, &menupoint);
2039
if( TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
2040
menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL))
2041
{
2042
if (infoPtr->dwStyle & MCS_MULTISELECT)
2043
{
2044
SYSTEMTIME range[2];
2045
2046
range[0] = range[1] = infoPtr->todaysDate;
2047
MONTHCAL_SetSelRange(infoPtr, range);
2048
}
2049
else
2050
MONTHCAL_SetCurSel(infoPtr, &infoPtr->todaysDate);
2051
2052
MONTHCAL_NotifySelectionChange(infoPtr);
2053
MONTHCAL_NotifySelect(infoPtr);
2054
}
2055
2056
return 0;
2057
}
2058
2059
/***
2060
* DESCRIPTION:
2061
* Subclassed edit control windproc function
2062
*
2063
* PARAMETER(S):
2064
* [I] hwnd : the edit window handle
2065
* [I] uMsg : the message that is to be processed
2066
* [I] wParam : first message parameter
2067
* [I] lParam : second message parameter
2068
*
2069
*/
2070
static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2071
{
2072
MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(GetParent(hwnd), 0);
2073
2074
TRACE("hwnd %p, uMsg %x, wParam %Ix, lParam %Ix\n", hwnd, uMsg, wParam, lParam);
2075
2076
switch (uMsg)
2077
{
2078
case WM_GETDLGCODE:
2079
return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
2080
2081
case WM_DESTROY:
2082
{
2083
WNDPROC editProc = infoPtr->EditWndProc;
2084
infoPtr->EditWndProc = NULL;
2085
SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (DWORD_PTR)editProc);
2086
return CallWindowProcW(editProc, hwnd, uMsg, wParam, lParam);
2087
}
2088
2089
case WM_KILLFOCUS:
2090
break;
2091
2092
case WM_KEYDOWN:
2093
if ((VK_ESCAPE == (INT)wParam) || (VK_RETURN == (INT)wParam))
2094
break;
2095
2096
default:
2097
return CallWindowProcW(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam);
2098
}
2099
2100
SendMessageW(infoPtr->hWndYearUpDown, WM_CLOSE, 0, 0);
2101
SendMessageW(hwnd, WM_CLOSE, 0, 0);
2102
return 0;
2103
}
2104
2105
/* creates updown control and edit box */
2106
static void MONTHCAL_EditYear(MONTHCAL_INFO *infoPtr, INT calIdx)
2107
{
2108
RECT *rc = &infoPtr->calendars[calIdx].titleyear;
2109
RECT *title = &infoPtr->calendars[calIdx].title;
2110
2111
infoPtr->hWndYearEdit =
2112
CreateWindowExW(0, WC_EDITW, 0, WS_VISIBLE | WS_CHILD | ES_READONLY,
2113
rc->left + 3, (title->bottom + title->top - infoPtr->textHeight) / 2,
2114
rc->right - rc->left + 4,
2115
infoPtr->textHeight, infoPtr->hwndSelf,
2116
NULL, NULL, NULL);
2117
2118
SendMessageW(infoPtr->hWndYearEdit, WM_SETFONT, (WPARAM)infoPtr->hBoldFont, TRUE);
2119
2120
infoPtr->hWndYearUpDown =
2121
CreateWindowExW(0, UPDOWN_CLASSW, 0,
2122
WS_VISIBLE | WS_CHILD | UDS_SETBUDDYINT | UDS_NOTHOUSANDS | UDS_ARROWKEYS,
2123
rc->right + 7, (title->bottom + title->top - infoPtr->textHeight) / 2,
2124
18, infoPtr->textHeight, infoPtr->hwndSelf,
2125
NULL, NULL, NULL);
2126
2127
/* attach edit box */
2128
SendMessageW(infoPtr->hWndYearUpDown, UDM_SETRANGE, 0,
2129
MAKELONG(max_allowed_date.wYear, min_allowed_date.wYear));
2130
SendMessageW(infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM)infoPtr->hWndYearEdit, 0);
2131
SendMessageW(infoPtr->hWndYearUpDown, UDM_SETPOS, 0, infoPtr->calendars[calIdx].month.wYear);
2132
2133
/* subclass edit box */
2134
infoPtr->EditWndProc = (WNDPROC)SetWindowLongPtrW(infoPtr->hWndYearEdit,
2135
GWLP_WNDPROC, (DWORD_PTR)EditWndProc);
2136
2137
SetFocus(infoPtr->hWndYearEdit);
2138
}
2139
2140
static LRESULT
2141
MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2142
{
2143
MCHITTESTINFO ht;
2144
DWORD hit;
2145
2146
/* Actually we don't need input focus for calendar, this is used to kill
2147
year updown and its buddy edit box */
2148
if (IsWindow(infoPtr->hWndYearUpDown))
2149
{
2150
SetFocus(infoPtr->hwndSelf);
2151
return 0;
2152
}
2153
2154
SetCapture(infoPtr->hwndSelf);
2155
2156
ht.cbSize = sizeof(MCHITTESTINFO);
2157
ht.pt.x = (short)LOWORD(lParam);
2158
ht.pt.y = (short)HIWORD(lParam);
2159
2160
hit = MONTHCAL_HitTest(infoPtr, &ht);
2161
2162
TRACE("%lx at %s\n", hit, wine_dbgstr_point(&ht.pt));
2163
2164
switch(hit)
2165
{
2166
case MCHT_TITLEBTNNEXT:
2167
MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2168
infoPtr->status = MC_NEXTPRESSED;
2169
SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2170
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2171
return 0;
2172
2173
case MCHT_TITLEBTNPREV:
2174
MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2175
infoPtr->status = MC_PREVPRESSED;
2176
SetTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER, MC_PREVNEXTMONTHDELAY, 0);
2177
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2178
return 0;
2179
2180
case MCHT_TITLEMONTH:
2181
{
2182
HMENU hMenu = CreatePopupMenu();
2183
WCHAR buf[32];
2184
POINT menupoint;
2185
INT i;
2186
2187
for (i = 0; i < 12; i++)
2188
{
2189
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1+i, buf, ARRAY_SIZE(buf));
2190
AppendMenuW(hMenu, MF_STRING|MF_ENABLED, i + 1, buf);
2191
}
2192
menupoint.x = ht.pt.x;
2193
menupoint.y = ht.pt.y;
2194
ClientToScreen(infoPtr->hwndSelf, &menupoint);
2195
i = TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RIGHTBUTTON | TPM_RETURNCMD,
2196
menupoint.x, menupoint.y, 0, infoPtr->hwndSelf, NULL);
2197
2198
if ((i > 0) && (i < 13) && infoPtr->calendars[ht.iOffset].month.wMonth != i)
2199
{
2200
INT delta = i - infoPtr->calendars[ht.iOffset].month.wMonth;
2201
SYSTEMTIME st;
2202
2203
/* check if change allowed by range set */
2204
st = delta < 0 ? infoPtr->calendars[0].month :
2205
infoPtr->calendars[MONTHCAL_GetCalCount(infoPtr)-1].month;
2206
MONTHCAL_GetMonth(&st, delta);
2207
2208
if (MONTHCAL_IsDateInValidRange(infoPtr, &st, FALSE))
2209
{
2210
MONTHCAL_Scroll(infoPtr, delta, FALSE);
2211
MONTHCAL_NotifyDayState(infoPtr);
2212
MONTHCAL_NotifySelectionChange(infoPtr);
2213
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2214
}
2215
}
2216
return 0;
2217
}
2218
case MCHT_TITLEYEAR:
2219
{
2220
MONTHCAL_EditYear(infoPtr, ht.iOffset);
2221
return 0;
2222
}
2223
case MCHT_TODAYLINK:
2224
{
2225
if (infoPtr->dwStyle & MCS_MULTISELECT)
2226
{
2227
SYSTEMTIME range[2];
2228
2229
range[0] = range[1] = infoPtr->todaysDate;
2230
MONTHCAL_SetSelRange(infoPtr, range);
2231
}
2232
else
2233
MONTHCAL_SetCurSel(infoPtr, &infoPtr->todaysDate);
2234
2235
MONTHCAL_NotifySelectionChange(infoPtr);
2236
MONTHCAL_NotifySelect(infoPtr);
2237
return 0;
2238
}
2239
case MCHT_CALENDARDATENEXT:
2240
case MCHT_CALENDARDATEPREV:
2241
case MCHT_CALENDARDATE:
2242
{
2243
SYSTEMTIME st[2];
2244
2245
MONTHCAL_CopyDate(&ht.st, &infoPtr->firstSel);
2246
2247
st[0] = st[1] = ht.st;
2248
/* clear selection range */
2249
MONTHCAL_SetSelRange(infoPtr, st);
2250
2251
infoPtr->status = MC_SEL_LBUTDOWN;
2252
if (MONTHCAL_SetDayFocus(infoPtr, &ht.st) && (infoPtr->dwStyle & MCS_MULTISELECT))
2253
MONTHCAL_NotifySelectionChange(infoPtr);
2254
return 0;
2255
}
2256
}
2257
2258
return 1;
2259
}
2260
2261
2262
static LRESULT
2263
MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2264
{
2265
NMHDR nmhdr;
2266
MCHITTESTINFO ht;
2267
DWORD hit;
2268
2269
TRACE("\n");
2270
2271
if(infoPtr->status & (MC_PREVPRESSED | MC_NEXTPRESSED)) {
2272
RECT *r;
2273
2274
KillTimer(infoPtr->hwndSelf, MC_PREVNEXTMONTHTIMER);
2275
r = infoPtr->status & MC_PREVPRESSED ? &infoPtr->titlebtnprev : &infoPtr->titlebtnnext;
2276
infoPtr->status &= ~(MC_PREVPRESSED | MC_NEXTPRESSED);
2277
2278
InvalidateRect(infoPtr->hwndSelf, r, FALSE);
2279
}
2280
2281
ReleaseCapture();
2282
2283
/* always send NM_RELEASEDCAPTURE notification */
2284
nmhdr.hwndFrom = infoPtr->hwndSelf;
2285
nmhdr.idFrom = GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_ID);
2286
nmhdr.code = NM_RELEASEDCAPTURE;
2287
TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
2288
2289
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
2290
2291
if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2292
2293
ht.cbSize = sizeof(MCHITTESTINFO);
2294
ht.pt.x = (short)LOWORD(lParam);
2295
ht.pt.y = (short)HIWORD(lParam);
2296
hit = MONTHCAL_HitTest(infoPtr, &ht);
2297
2298
infoPtr->status = MC_SEL_LBUTUP;
2299
MONTHCAL_SetDayFocus(infoPtr, NULL);
2300
2301
if((hit & MCHT_CALENDARDATE) == MCHT_CALENDARDATE)
2302
{
2303
SYSTEMTIME sel = infoPtr->minSel;
2304
2305
/* will be invalidated here */
2306
MONTHCAL_SetCurSel(infoPtr, &ht.st);
2307
2308
/* send MCN_SELCHANGE only if new date selected */
2309
if (!MONTHCAL_IsDateEqual(&sel, &ht.st))
2310
MONTHCAL_NotifySelectionChange(infoPtr);
2311
2312
MONTHCAL_NotifySelect(infoPtr);
2313
}
2314
2315
return 0;
2316
}
2317
2318
2319
static LRESULT
2320
MONTHCAL_Timer(MONTHCAL_INFO *infoPtr, WPARAM id)
2321
{
2322
TRACE("%Id\n", id);
2323
2324
switch(id) {
2325
case MC_PREVNEXTMONTHTIMER:
2326
if(infoPtr->status & MC_NEXTPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_FORWARD);
2327
if(infoPtr->status & MC_PREVPRESSED) MONTHCAL_GoToMonth(infoPtr, DIRECTION_BACKWARD);
2328
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2329
break;
2330
case MC_TODAYUPDATETIMER:
2331
{
2332
SYSTEMTIME st;
2333
2334
if(infoPtr->todaySet) return 0;
2335
2336
GetLocalTime(&st);
2337
MONTHCAL_UpdateToday(infoPtr, &st);
2338
2339
/* notification sent anyway */
2340
MONTHCAL_NotifySelectionChange(infoPtr);
2341
2342
return 0;
2343
}
2344
default:
2345
ERR("got unknown timer %Id\n", id);
2346
break;
2347
}
2348
2349
return 0;
2350
}
2351
2352
2353
static LRESULT
2354
MONTHCAL_MouseMove(MONTHCAL_INFO *infoPtr, LPARAM lParam)
2355
{
2356
MCHITTESTINFO ht;
2357
SYSTEMTIME st_ht;
2358
INT hit;
2359
RECT r;
2360
2361
if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
2362
2363
ht.cbSize = sizeof(MCHITTESTINFO);
2364
ht.pt.x = (short)LOWORD(lParam);
2365
ht.pt.y = (short)HIWORD(lParam);
2366
ht.iOffset = -1;
2367
2368
hit = MONTHCAL_HitTest(infoPtr, &ht);
2369
2370
/* not on the calendar date numbers? bail out */
2371
TRACE("hit:%x\n",hit);
2372
if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE)
2373
{
2374
MONTHCAL_SetDayFocus(infoPtr, NULL);
2375
return 0;
2376
}
2377
2378
st_ht = ht.st;
2379
2380
/* if pointer is over focused day still there's nothing to do */
2381
if(!MONTHCAL_SetDayFocus(infoPtr, &ht.st)) return 0;
2382
2383
MONTHCAL_GetDayRect(infoPtr, &ht.st, &r, ht.iOffset);
2384
2385
if(infoPtr->dwStyle & MCS_MULTISELECT) {
2386
SYSTEMTIME st[2];
2387
2388
MONTHCAL_GetSelRange(infoPtr, st);
2389
2390
/* If we're still at the first selected date and range is empty, return.
2391
If range isn't empty we should change range to a single firstSel */
2392
if(MONTHCAL_IsDateEqual(&infoPtr->firstSel, &st_ht) &&
2393
MONTHCAL_IsDateEqual(&st[0], &st[1])) goto done;
2394
2395
MONTHCAL_IsSelRangeValid(infoPtr, &st_ht, &infoPtr->firstSel, &st_ht);
2396
2397
st[0] = infoPtr->firstSel;
2398
/* we should overwrite timestamp here */
2399
MONTHCAL_CopyDate(&st_ht, &st[1]);
2400
2401
/* bounds will be swapped here if needed */
2402
MONTHCAL_SetSelRange(infoPtr, st);
2403
2404
return 0;
2405
}
2406
2407
done:
2408
2409
/* FIXME: this should specify a rectangle containing only the days that changed
2410
using InvalidateRect */
2411
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2412
2413
return 0;
2414
}
2415
2416
2417
static LRESULT
2418
MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
2419
{
2420
HDC hdc;
2421
PAINTSTRUCT ps;
2422
2423
if (hdc_paint)
2424
{
2425
GetClientRect(infoPtr->hwndSelf, &ps.rcPaint);
2426
hdc = hdc_paint;
2427
}
2428
else
2429
hdc = BeginPaint(infoPtr->hwndSelf, &ps);
2430
2431
MONTHCAL_Refresh(infoPtr, hdc, &ps);
2432
if (!hdc_paint) EndPaint(infoPtr->hwndSelf, &ps);
2433
return 0;
2434
}
2435
2436
static LRESULT
2437
MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
2438
{
2439
RECT rc;
2440
2441
if (!GetClipBox(hdc, &rc)) return FALSE;
2442
2443
FillRect(hdc, &rc, infoPtr->brushes[BrushBackground]);
2444
2445
return TRUE;
2446
}
2447
2448
static LRESULT
2449
MONTHCAL_PrintClient(MONTHCAL_INFO *infoPtr, HDC hdc, DWORD options)
2450
{
2451
FIXME("Partial Stub: (hdc %p options %#lx)\n", hdc, options);
2452
2453
if ((options & PRF_CHECKVISIBLE) && !IsWindowVisible(infoPtr->hwndSelf))
2454
return 0;
2455
2456
if (options & PRF_ERASEBKGND)
2457
MONTHCAL_EraseBkgnd(infoPtr, hdc);
2458
2459
if (options & PRF_CLIENT)
2460
MONTHCAL_Paint(infoPtr, hdc);
2461
2462
return 0;
2463
}
2464
2465
static LRESULT
2466
MONTHCAL_SetFocus(const MONTHCAL_INFO *infoPtr)
2467
{
2468
TRACE("\n");
2469
2470
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2471
2472
return 0;
2473
}
2474
2475
/* sets the size information */
2476
static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
2477
{
2478
RECT *title=&infoPtr->calendars[0].title;
2479
RECT *prev=&infoPtr->titlebtnprev;
2480
RECT *next=&infoPtr->titlebtnnext;
2481
RECT *titlemonth=&infoPtr->calendars[0].titlemonth;
2482
RECT *titleyear=&infoPtr->calendars[0].titleyear;
2483
RECT *wdays=&infoPtr->calendars[0].wdays;
2484
RECT *weeknumrect=&infoPtr->calendars[0].weeknums;
2485
RECT *days=&infoPtr->calendars[0].days;
2486
RECT *todayrect=&infoPtr->todayrect;
2487
2488
INT xdiv, dx, dy, i, j, x, y, c_dx, c_dy;
2489
WCHAR buff[80];
2490
TEXTMETRICW tm;
2491
INT day_width;
2492
RECT client;
2493
HFONT font;
2494
SIZE size;
2495
HDC hdc;
2496
2497
GetClientRect(infoPtr->hwndSelf, &client);
2498
2499
hdc = GetDC(infoPtr->hwndSelf);
2500
font = SelectObject(hdc, infoPtr->hFont);
2501
2502
/* get the height and width of each day's text */
2503
GetTextMetricsW(hdc, &tm);
2504
infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
2505
2506
/* find widest day name for current locale and font */
2507
day_width = 0;
2508
for (i = 0; i < 7; i++)
2509
{
2510
SIZE sz;
2511
2512
if (get_localized_dayname(infoPtr, i, buff, ARRAY_SIZE(buff)))
2513
{
2514
GetTextExtentPoint32W(hdc, buff, lstrlenW(buff), &sz);
2515
if (sz.cx > day_width) day_width = sz.cx;
2516
}
2517
else /* locale independent fallback on failure */
2518
{
2519
GetTextExtentPoint32W(hdc, L"Sun", 3, &sz);
2520
day_width = sz.cx;
2521
break;
2522
}
2523
}
2524
2525
day_width += 2;
2526
2527
/* recalculate the height and width increments and offsets */
2528
size.cx = 0;
2529
GetTextExtentPoint32W(hdc, L"00", 2, &size);
2530
2531
/* restore the originally selected font */
2532
SelectObject(hdc, font);
2533
ReleaseDC(infoPtr->hwndSelf, hdc);
2534
2535
xdiv = (infoPtr->dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
2536
2537
infoPtr->width_increment = max(day_width, size.cx * 2 + 4);
2538
infoPtr->height_increment = infoPtr->textHeight;
2539
2540
/* calculate title area */
2541
title->top = 0;
2542
title->bottom = 3 * infoPtr->height_increment / 2;
2543
title->left = 0;
2544
title->right = infoPtr->width_increment * xdiv;
2545
2546
/* set the dimensions of the next and previous buttons and center */
2547
/* the month text vertically */
2548
prev->top = next->top = title->top + 4;
2549
prev->bottom = next->bottom = title->bottom - 4;
2550
prev->left = title->left + 4;
2551
prev->right = prev->left + (title->bottom - title->top);
2552
next->right = title->right - 4;
2553
next->left = next->right - (title->bottom - title->top);
2554
2555
/* titlemonth->left and right change based upon the current month
2556
and are recalculated in refresh as the current month may change
2557
without the control being resized */
2558
titlemonth->top = titleyear->top = title->top + (infoPtr->height_increment)/2;
2559
titlemonth->bottom = titleyear->bottom = title->bottom - (infoPtr->height_increment)/2;
2560
2561
/* week numbers */
2562
weeknumrect->left = 0;
2563
weeknumrect->right = infoPtr->dwStyle & MCS_WEEKNUMBERS ? prev->right : 0;
2564
2565
/* days abbreviated names */
2566
wdays->left = days->left = weeknumrect->right;
2567
wdays->right = days->right = wdays->left + 7 * infoPtr->width_increment;
2568
wdays->top = title->bottom;
2569
wdays->bottom = wdays->top + infoPtr->height_increment;
2570
2571
days->top = weeknumrect->top = wdays->bottom;
2572
days->bottom = weeknumrect->bottom = days->top + 6 * infoPtr->height_increment;
2573
2574
todayrect->left = 0;
2575
todayrect->right = title->right;
2576
todayrect->top = days->bottom;
2577
todayrect->bottom = days->bottom + infoPtr->height_increment;
2578
2579
/* compute calendar count, update all calendars */
2580
x = (client.right + MC_CALENDAR_PADDING) / (title->right - title->left + MC_CALENDAR_PADDING);
2581
/* today label affects whole height */
2582
if (infoPtr->dwStyle & MCS_NOTODAY)
2583
y = (client.bottom + MC_CALENDAR_PADDING) / (days->bottom - title->top + MC_CALENDAR_PADDING);
2584
else
2585
y = (client.bottom - todayrect->bottom + todayrect->top + MC_CALENDAR_PADDING) /
2586
(days->bottom - title->top + MC_CALENDAR_PADDING);
2587
2588
/* TODO: ensure that count is properly adjusted to fit 12 months constraint */
2589
if (x == 0) x = 1;
2590
if (y == 0) y = 1;
2591
2592
if (x*y != MONTHCAL_GetCalCount(infoPtr))
2593
{
2594
infoPtr->dim.cx = x;
2595
infoPtr->dim.cy = y;
2596
infoPtr->calendars = ReAlloc(infoPtr->calendars, MONTHCAL_GetCalCount(infoPtr)*sizeof(CALENDAR_INFO));
2597
2598
infoPtr->monthdayState = ReAlloc(infoPtr->monthdayState,
2599
MONTHCAL_GetMonthRange(infoPtr, GMR_DAYSTATE, 0)*sizeof(MONTHDAYSTATE));
2600
MONTHCAL_NotifyDayState(infoPtr);
2601
2602
/* update pointers that we'll need */
2603
title = &infoPtr->calendars[0].title;
2604
wdays = &infoPtr->calendars[0].wdays;
2605
days = &infoPtr->calendars[0].days;
2606
}
2607
2608
for (i = 1; i < MONTHCAL_GetCalCount(infoPtr); i++)
2609
{
2610
/* set months */
2611
infoPtr->calendars[i] = infoPtr->calendars[0];
2612
MONTHCAL_GetMonth(&infoPtr->calendars[i].month, i);
2613
}
2614
2615
/* offset all rectangles to center in client area */
2616
c_dx = (client.right - x * title->right - MC_CALENDAR_PADDING * (x-1)) / 2;
2617
c_dy = (client.bottom - y * todayrect->bottom - MC_CALENDAR_PADDING * (y-1)) / 2;
2618
2619
/* if calendar doesn't fit client area show it at left/top bounds */
2620
if (title->left + c_dx < 0) c_dx = 0;
2621
if (title->top + c_dy < 0) c_dy = 0;
2622
2623
for (i = 0; i < y; i++)
2624
{
2625
for (j = 0; j < x; j++)
2626
{
2627
dx = j*(title->right - title->left + MC_CALENDAR_PADDING) + c_dx;
2628
dy = i*(days->bottom - title->top + MC_CALENDAR_PADDING) + c_dy;
2629
2630
OffsetRect(&infoPtr->calendars[i*x+j].title, dx, dy);
2631
OffsetRect(&infoPtr->calendars[i*x+j].titlemonth, dx, dy);
2632
OffsetRect(&infoPtr->calendars[i*x+j].titleyear, dx, dy);
2633
OffsetRect(&infoPtr->calendars[i*x+j].wdays, dx, dy);
2634
OffsetRect(&infoPtr->calendars[i*x+j].weeknums, dx, dy);
2635
OffsetRect(&infoPtr->calendars[i*x+j].days, dx, dy);
2636
}
2637
}
2638
2639
OffsetRect(prev, c_dx, c_dy);
2640
OffsetRect(next, (x-1)*(title->right - title->left + MC_CALENDAR_PADDING) + c_dx, c_dy);
2641
2642
i = infoPtr->dim.cx * infoPtr->dim.cy - infoPtr->dim.cx;
2643
todayrect->left = infoPtr->calendars[i].title.left;
2644
todayrect->right = infoPtr->calendars[i].title.right;
2645
todayrect->top = infoPtr->calendars[i].days.bottom;
2646
todayrect->bottom = infoPtr->calendars[i].days.bottom + infoPtr->height_increment;
2647
2648
TRACE("dx=%d dy=%d client[%s] title[%s] wdays[%s] days[%s] today[%s]\n",
2649
infoPtr->width_increment,infoPtr->height_increment,
2650
wine_dbgstr_rect(&client),
2651
wine_dbgstr_rect(title),
2652
wine_dbgstr_rect(wdays),
2653
wine_dbgstr_rect(days),
2654
wine_dbgstr_rect(todayrect));
2655
}
2656
2657
static LRESULT MONTHCAL_Size(MONTHCAL_INFO *infoPtr, int Width, int Height)
2658
{
2659
TRACE("(width=%d, height=%d)\n", Width, Height);
2660
2661
MONTHCAL_UpdateSize(infoPtr);
2662
InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
2663
2664
return 0;
2665
}
2666
2667
static LRESULT MONTHCAL_GetFont(const MONTHCAL_INFO *infoPtr)
2668
{
2669
return (LRESULT)infoPtr->hFont;
2670
}
2671
2672
static LRESULT MONTHCAL_SetFont(MONTHCAL_INFO *infoPtr, HFONT hFont, BOOL redraw)
2673
{
2674
HFONT hOldFont;
2675
LOGFONTW lf;
2676
2677
if (!hFont) return 0;
2678
2679
hOldFont = infoPtr->hFont;
2680
infoPtr->hFont = hFont;
2681
2682
GetObjectW(infoPtr->hFont, sizeof(lf), &lf);
2683
lf.lfWeight = FW_BOLD;
2684
infoPtr->hBoldFont = CreateFontIndirectW(&lf);
2685
2686
MONTHCAL_UpdateSize(infoPtr);
2687
2688
if (redraw)
2689
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2690
2691
return (LRESULT)hOldFont;
2692
}
2693
2694
static INT MONTHCAL_StyleChanged(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2695
const STYLESTRUCT *lpss)
2696
{
2697
TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType, lpss->styleOld, lpss->styleNew);
2698
2699
if (wStyleType != GWL_STYLE) return 0;
2700
2701
infoPtr->dwStyle = lpss->styleNew;
2702
2703
/* make room for week numbers */
2704
if ((lpss->styleNew ^ lpss->styleOld) & (MCS_WEEKNUMBERS | MCS_SHORTDAYSOFWEEK))
2705
MONTHCAL_UpdateSize(infoPtr);
2706
2707
return 0;
2708
}
2709
2710
static INT MONTHCAL_StyleChanging(MONTHCAL_INFO *infoPtr, WPARAM wStyleType,
2711
STYLESTRUCT *lpss)
2712
{
2713
TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType, lpss->styleOld, lpss->styleNew);
2714
2715
/* block MCS_MULTISELECT change */
2716
if ((lpss->styleNew ^ lpss->styleOld) & MCS_MULTISELECT)
2717
{
2718
if (lpss->styleOld & MCS_MULTISELECT)
2719
lpss->styleNew |= MCS_MULTISELECT;
2720
else
2721
lpss->styleNew &= ~MCS_MULTISELECT;
2722
}
2723
2724
/* block MCS_DAYSTATE change */
2725
if ((lpss->styleNew ^ lpss->styleOld) & MCS_DAYSTATE)
2726
{
2727
if (lpss->styleOld & MCS_DAYSTATE)
2728
lpss->styleNew |= MCS_DAYSTATE;
2729
else
2730
lpss->styleNew &= ~MCS_DAYSTATE;
2731
}
2732
2733
return 0;
2734
}
2735
2736
/* FIXME: check whether dateMin/dateMax need to be adjusted. */
2737
static LRESULT
2738
MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
2739
{
2740
MONTHCAL_INFO *infoPtr;
2741
2742
/* allocate memory for info structure */
2743
infoPtr = Alloc(sizeof(*infoPtr));
2744
SetWindowLongPtrW(hwnd, 0, (DWORD_PTR)infoPtr);
2745
2746
if (infoPtr == NULL) {
2747
ERR("could not allocate info memory!\n");
2748
return 0;
2749
}
2750
2751
infoPtr->hwndSelf = hwnd;
2752
infoPtr->hwndNotify = lpcs->hwndParent;
2753
infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
2754
infoPtr->dim.cx = infoPtr->dim.cy = 1;
2755
infoPtr->calendars = Alloc(sizeof(*infoPtr->calendars));
2756
if (!infoPtr->calendars) goto fail;
2757
infoPtr->monthdayState = Alloc(3 * sizeof(*infoPtr->monthdayState));
2758
if (!infoPtr->monthdayState) goto fail;
2759
2760
/* initialize info structure */
2761
/* FIXME: calculate systemtime ->> localtime(subtract timezoneinfo) */
2762
2763
GetLocalTime(&infoPtr->todaysDate);
2764
MONTHCAL_SetFirstDayOfWeek(infoPtr, -1);
2765
2766
infoPtr->maxSelCount = (infoPtr->dwStyle & MCS_MULTISELECT) ? 7 : 1;
2767
2768
infoPtr->colors[MCSC_BACKGROUND] = comctl32_color.clrWindow;
2769
infoPtr->colors[MCSC_TEXT] = comctl32_color.clrWindowText;
2770
infoPtr->colors[MCSC_TITLEBK] = comctl32_color.clrActiveCaption;
2771
infoPtr->colors[MCSC_TITLETEXT] = comctl32_color.clrWindow;
2772
infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
2773
infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
2774
2775
infoPtr->brushes[BrushBackground] = CreateSolidBrush(infoPtr->colors[MCSC_BACKGROUND]);
2776
infoPtr->brushes[BrushTitle] = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
2777
infoPtr->brushes[BrushMonth] = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
2778
2779
infoPtr->pens[PenRed] = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
2780
infoPtr->pens[PenText] = CreatePen(PS_SOLID, 1, infoPtr->colors[MCSC_TEXT]);
2781
2782
infoPtr->minSel = infoPtr->todaysDate;
2783
infoPtr->maxSel = infoPtr->todaysDate;
2784
infoPtr->calendars[0].month = infoPtr->todaysDate;
2785
infoPtr->isUnicode = TRUE;
2786
2787
/* setup control layout and day state data */
2788
MONTHCAL_UpdateSize(infoPtr);
2789
2790
/* today auto update timer, to be freed only on control destruction */
2791
SetTimer(infoPtr->hwndSelf, MC_TODAYUPDATETIMER, MC_TODAYUPDATEDELAY, 0);
2792
2793
COMCTL32_OpenThemeForWindow(infoPtr->hwndSelf, L"Scrollbar");
2794
2795
return 0;
2796
2797
fail:
2798
Free(infoPtr->monthdayState);
2799
Free(infoPtr->calendars);
2800
Free(infoPtr);
2801
return 0;
2802
}
2803
2804
static LRESULT
2805
MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
2806
{
2807
INT i;
2808
2809
Free(infoPtr->monthdayState);
2810
Free(infoPtr->calendars);
2811
SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
2812
2813
COMCTL32_CloseThemeForWindow(infoPtr->hwndSelf);
2814
2815
for (i = 0; i < BrushLast; i++) DeleteObject(infoPtr->brushes[i]);
2816
for (i = 0; i < PenLast; i++) DeleteObject(infoPtr->pens[i]);
2817
2818
Free(infoPtr);
2819
return 0;
2820
}
2821
2822
/*
2823
* Handler for WM_NOTIFY messages
2824
*/
2825
static LRESULT
2826
MONTHCAL_Notify(MONTHCAL_INFO *infoPtr, NMHDR *hdr)
2827
{
2828
/* notification from year edit updown */
2829
if (hdr->code == UDN_DELTAPOS)
2830
{
2831
NMUPDOWN *nmud = (NMUPDOWN*)hdr;
2832
2833
if (hdr->hwndFrom == infoPtr->hWndYearUpDown && nmud->iDelta)
2834
{
2835
/* year value limits are set up explicitly after updown creation */
2836
MONTHCAL_Scroll(infoPtr, 12 * nmud->iDelta, FALSE);
2837
MONTHCAL_NotifyDayState(infoPtr);
2838
MONTHCAL_NotifySelectionChange(infoPtr);
2839
}
2840
}
2841
return 0;
2842
}
2843
2844
static inline BOOL
2845
MONTHCAL_SetUnicodeFormat(MONTHCAL_INFO *infoPtr, BOOL isUnicode)
2846
{
2847
BOOL prev = infoPtr->isUnicode;
2848
infoPtr->isUnicode = isUnicode;
2849
return prev;
2850
}
2851
2852
static inline BOOL
2853
MONTHCAL_GetUnicodeFormat(const MONTHCAL_INFO *infoPtr)
2854
{
2855
return infoPtr->isUnicode;
2856
}
2857
2858
static LRESULT WINAPI
2859
MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2860
{
2861
MONTHCAL_INFO *infoPtr = (MONTHCAL_INFO *)GetWindowLongPtrW(hwnd, 0);
2862
2863
TRACE("hwnd %p, msg %x, wparam %Ix, lparam %Ix\n", hwnd, uMsg, wParam, lParam);
2864
2865
if (!infoPtr && (uMsg != WM_CREATE))
2866
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
2867
switch(uMsg)
2868
{
2869
case MCM_GETCURSEL:
2870
return MONTHCAL_GetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2871
2872
case MCM_SETCURSEL:
2873
return MONTHCAL_SetCurSel(infoPtr, (LPSYSTEMTIME)lParam);
2874
2875
case MCM_GETMAXSELCOUNT:
2876
return MONTHCAL_GetMaxSelCount(infoPtr);
2877
2878
case MCM_SETMAXSELCOUNT:
2879
return MONTHCAL_SetMaxSelCount(infoPtr, wParam);
2880
2881
case MCM_GETSELRANGE:
2882
return MONTHCAL_GetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2883
2884
case MCM_SETSELRANGE:
2885
return MONTHCAL_SetSelRange(infoPtr, (LPSYSTEMTIME)lParam);
2886
2887
case MCM_GETMONTHRANGE:
2888
return MONTHCAL_GetMonthRange(infoPtr, wParam, (SYSTEMTIME*)lParam);
2889
2890
case MCM_SETDAYSTATE:
2891
return MONTHCAL_SetDayState(infoPtr, (INT)wParam, (LPMONTHDAYSTATE)lParam);
2892
2893
case MCM_GETMINREQRECT:
2894
return MONTHCAL_GetMinReqRect(infoPtr, (LPRECT)lParam);
2895
2896
case MCM_GETCOLOR:
2897
return MONTHCAL_GetColor(infoPtr, wParam);
2898
2899
case MCM_SETCOLOR:
2900
return MONTHCAL_SetColor(infoPtr, wParam, (COLORREF)lParam);
2901
2902
case MCM_GETTODAY:
2903
return MONTHCAL_GetToday(infoPtr, (LPSYSTEMTIME)lParam);
2904
2905
case MCM_SETTODAY:
2906
return MONTHCAL_SetToday(infoPtr, (LPSYSTEMTIME)lParam);
2907
2908
case MCM_HITTEST:
2909
return MONTHCAL_HitTest(infoPtr, (PMCHITTESTINFO)lParam);
2910
2911
case MCM_GETFIRSTDAYOFWEEK:
2912
return MONTHCAL_GetFirstDayOfWeek(infoPtr);
2913
2914
case MCM_SETFIRSTDAYOFWEEK:
2915
return MONTHCAL_SetFirstDayOfWeek(infoPtr, (INT)lParam);
2916
2917
case MCM_GETRANGE:
2918
return MONTHCAL_GetRange(infoPtr, (LPSYSTEMTIME)lParam);
2919
2920
case MCM_SETRANGE:
2921
return MONTHCAL_SetRange(infoPtr, (SHORT)wParam, (LPSYSTEMTIME)lParam);
2922
2923
case MCM_GETMONTHDELTA:
2924
return MONTHCAL_GetMonthDelta(infoPtr);
2925
2926
case MCM_SETMONTHDELTA:
2927
return MONTHCAL_SetMonthDelta(infoPtr, wParam);
2928
2929
case MCM_GETMAXTODAYWIDTH:
2930
return MONTHCAL_GetMaxTodayWidth(infoPtr);
2931
2932
case MCM_SETUNICODEFORMAT:
2933
return MONTHCAL_SetUnicodeFormat(infoPtr, (BOOL)wParam);
2934
2935
case MCM_GETUNICODEFORMAT:
2936
return MONTHCAL_GetUnicodeFormat(infoPtr);
2937
2938
case MCM_GETCALENDARCOUNT:
2939
return MONTHCAL_GetCalCount(infoPtr);
2940
2941
case WM_GETDLGCODE:
2942
return DLGC_WANTARROWS | DLGC_WANTCHARS;
2943
2944
case WM_RBUTTONUP:
2945
return MONTHCAL_RButtonUp(infoPtr, lParam);
2946
2947
case WM_LBUTTONDOWN:
2948
return MONTHCAL_LButtonDown(infoPtr, lParam);
2949
2950
case WM_MOUSEMOVE:
2951
return MONTHCAL_MouseMove(infoPtr, lParam);
2952
2953
case WM_LBUTTONUP:
2954
return MONTHCAL_LButtonUp(infoPtr, lParam);
2955
2956
case WM_PAINT:
2957
return MONTHCAL_Paint(infoPtr, (HDC)wParam);
2958
2959
case WM_PRINTCLIENT:
2960
return MONTHCAL_PrintClient(infoPtr, (HDC)wParam, (DWORD)lParam);
2961
2962
case WM_ERASEBKGND:
2963
return MONTHCAL_EraseBkgnd(infoPtr, (HDC)wParam);
2964
2965
case WM_SETFOCUS:
2966
return MONTHCAL_SetFocus(infoPtr);
2967
2968
case WM_SIZE:
2969
return MONTHCAL_Size(infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2970
2971
case WM_NOTIFY:
2972
return MONTHCAL_Notify(infoPtr, (NMHDR*)lParam);
2973
2974
case WM_CREATE:
2975
return MONTHCAL_Create(hwnd, (LPCREATESTRUCTW)lParam);
2976
2977
case WM_SETFONT:
2978
return MONTHCAL_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
2979
2980
case WM_GETFONT:
2981
return MONTHCAL_GetFont(infoPtr);
2982
2983
case WM_TIMER:
2984
return MONTHCAL_Timer(infoPtr, wParam);
2985
2986
case WM_THEMECHANGED:
2987
return COMCTL32_ThemeChanged(infoPtr->hwndSelf, L"Scrollbar", TRUE, TRUE);
2988
2989
case WM_DESTROY:
2990
return MONTHCAL_Destroy(infoPtr);
2991
2992
case WM_SYSCOLORCHANGE:
2993
COMCTL32_RefreshSysColors();
2994
return 0;
2995
2996
case WM_STYLECHANGED:
2997
return MONTHCAL_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2998
2999
case WM_STYLECHANGING:
3000
return MONTHCAL_StyleChanging(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
3001
3002
default:
3003
if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
3004
ERR( "unknown msg %04x, wp %Ix, lp %Ix\n", uMsg, wParam, lParam);
3005
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
3006
}
3007
}
3008
3009
3010
void
3011
MONTHCAL_Register(void)
3012
{
3013
WNDCLASSW wndClass;
3014
3015
ZeroMemory(&wndClass, sizeof(WNDCLASSW));
3016
wndClass.style = CS_GLOBALCLASS;
3017
wndClass.lpfnWndProc = MONTHCAL_WindowProc;
3018
wndClass.cbClsExtra = 0;
3019
wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
3020
wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
3021
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
3022
wndClass.lpszClassName = MONTHCAL_CLASSW;
3023
3024
RegisterClassW(&wndClass);
3025
}
3026
3027
3028
void
3029
MONTHCAL_Unregister(void)
3030
{
3031
UnregisterClassW(MONTHCAL_CLASSW, NULL);
3032
}
3033
3034