1 /*----------------------------------------------------------------------------
2 --
3 --  Module:           XmUbMonthDisplay
4 --
5 --  Project:          XmUb - Ulle's Motif widgets
6 --  System:
7 --    Subsystem:      <>
8 --    Function block: <>
9 --
10 --  Description:
11 --    This is the public header file for the widget.
12 --
13 --    The month display widget displays the name and year of a month and
14 --    the dates according to the day in the week. Optionally, arrow buttons
15 --    for stepping forwards and backwards month-wise or year-wise are
16 --    included.
17 --    The user may select a date by clicking on it. When that happens, a
18 --    callback is invoked.
19 --
20 --  Filename:         XmUbMonthD.h
21 --
22 --  Authors:          Roger Larsson, Ulrika Bornetun
23 --  Creation date:    1993-09-26
24 --
25 --
26 --  (C) Copyright Ulrika Bornetun, Roger Larsson (1995)
27 --      All rights reserved
28 --
29 --  Permission to use, copy, modify, and distribute this software and its
30 --  documentation for any purpose and without fee is hereby granted,
31 --  provided that the above copyright notice appear in all copies. Ulrika
32 --  Bornetun and Roger Larsson make no representations about the usability
33 --  of this software for any purpose. It is provided "as is" without express
34 --  or implied warranty.
35 ----------------------------------------------------------------------------*/
36 
37 /* SCCS module identifier. */
38 /* SCCSID = @(#) Module: XmUbMonthD.h, Version: 1.1, Date: 95/02/18 15:10:08 */
39 
40 #ifndef _XmUbMonthD_h
41 #define _XmUbMonthD_h
42 
43 /*----------------------------------------------------------------------------
44 --  Include files
45 ----------------------------------------------------------------------------*/
46 
47 #include <stdio.h>
48 #include <time.h>
49 #include <X11/StringDefs.h>
50 #include <Xm/Xm.h>
51 
52 /*----------------------------------------------------------------------------
53 --  Resources for the month display widget.
54 --  All XmManager resources apply.
55 --  The following list describes resources added in this widget.
56 --
57 --  XmUbNmdiArrowSpacing              CSG
58 --      XmCSpacing
59 --    The vertical spacing between the date display and the arrow buttons
60 --    (if any).
61 --    Type:    Dimension
62 --    Default: 2
63 --
64 --  XmUbNmdiCurrentMonth              CSG
65 --      XmUbCMdiCurrentMonth
66 --    The number of the month that is currently being displayed.
67 --    An integer in the range 1 .. 12.
68 --    Type:    int
69 --    Default: dynamic (the current month)
70 --
71 --  XmUbNmdiCurrentYear               CSG
72 --      XmUbCMdiCurrentYear
73 --    The number of the year that is currently being displayed.
74 --    Type:    int
75 --    Default: dynamic (the current year)
76 --
77 --  XmUbNmdiDateSelectedCallback      CSG
78 --      XmCCallback
79 --    Callback(s) that is called when a date was selected.
80 --    Callback reason: XmUbCR_DATE_SELECTED.
81 --    Type:    XtCallbackList
82 --    Default: NULL
83 --
84 --  XmUbNmdiDayChars                  CG
85 --      XmUbCMdiDayChars
86 --    The max number of characters to show in the day name. If 0, no
87 --    abbreviation of the string returned by strftime( "%a" ) is done.
88 --    Type:    int
89 --    Default: 2
90 --
91 --  XmUbNmdiEnableSeparator           CG
92 --      XmUbCMdiEnableSeparator
93 --    If True, a separator is created betweeen the row column and the arrow
94 --    labels, but only if at least one arrow label is enabled.
95 --    If False, no separator is created.
96 --    Type:    Boolean
97 --    Default: True
98 --
99 --  XmUbNmdiFillOutWeek               CSG
100 --      XmUbCMdiFillOutWeek
101 --    If True, the week display is filled out with days from the preceding and
102 --    following months. If False, these positions are left empty.
103 --    Type:    Boolean
104 --    Default: True
105 --
106 --  XmUbNmdiLabelSpacing              CSG
107 --      XmCSpacing
108 --    The vertical spacing between the date display and the title.
109 --    Type:    Dimension
110 --    Default: 2
111 --
112 --  XmNmarginHeight                   CSG
113 --      XmCMarginHeight
114 --    The margin used at the top and the bottom of the widget.
115 --    Type:    Dimension
116 --    Default: 0
117 --
118 --  XmNmarginWidth                    CSG
119 --      XmCMarginWidth
120 --    The margin used at the left and right ends of the widget.
121 --    Type:    Dimension
122 --    Default: 0
123 --
124 --  XmUbNmdiMonthArrows               CG
125 --      XmUbCMdiMonthArrows
126 --    If True, arrow buttons for month scrolling are created below the month
127 --    display.
128 --    Type:    Boolean
129 --    Default: True
130 --
131 --  XmUbNmdiMonthLabel                CSG
132 --      XmUbCMdiMonthLabel
133 --    The text to be displayed in the month scrolling label, if enabled.
134 --    If none is specified, a default string will be used.
135 --    The string is copied internally. A copy is returned by XtGetValues.
136 --    Type:    XmString
137 --    Default: NULL
138 --
139 --  XmUbNmdiNewMonthCallback          CSG
140 --      XmCCallback
141 --    Callback(s) that is called when a new month is displayed.
142 --    Callback reason: XmUbCR_NEW_MONTH.
143 --    Type:    XtCallbackList
144 --    Default: NULL
145 --
146 --  XmUbNmdiOtherMonthForeground      CSG
147 --      XmCForeground
148 --    The color in which the dates of the adjoining months are displayed.
149 --    Only applicable if XmUbNmdiFillOutWeek is True.
150 --    Type:    Pixel
151 --    Default: the default foreground color
152 --
153 --  XmUbNmdiRecomputeHeight           CSG
154 --      XmUbCMdiRecomputeHeight
155 --    If True, the height of the widget is dynamically calculated. If False,
156 --    the user set height is kept. The resource is forced to False if the user
157 --    sets a height.
158 --    Type:    Boolean
159 --    Default: True
160 --
161 --  XmUbNmdiRecomputeWidth            CSG
162 --      XmUbCMdiRecomputeWidth
163 --    If True, the width of the widget is dynamically calculated. If False,
164 --    the user set width is kept. The resource is forced to False if the user
165 --    sets a width.
166 --    Type:    Boolean
167 --    Default: True
168 --
169 --  XmUbNmdiSaturdayForeground        CSG
170 --      XmCForeground
171 --    The foreground color used for Saturdays.
172 --    Type:    Pixel
173 --    Default: the default foreground color
174 --
175 --  XmUbNmdiSundayForeground          CSG
176 --      XmCForeground
177 --    The foreground color used for Sundays.
178 --    Type:    Pixel
179 --    Default: the default foreground color
180 --
181 --  XmUbNmdiTitleAlignment            CSG
182 --      XmCAlignment
183 --    The alignment of the month title.
184 --    Valid values are XmALIGNMENT_BEGINNING, XmALIGNMENT_CENTER and
185 --    XmALIGNMENT_END.
186 --    Type:    unsigned char
187 --    Default: XmALIGNMENT_CENTER
188 --
189 --  XmUbNmdiTitleCallback             CSG
190 --      XmCCallback
191 --    Callback(s) that is called when the title bar is pressed.
192 --    If the resource is True, the current month and year will be set
193 --    before this callback is invoked.
194 --    Callback reason: XmUbCR_TITLE_PRESSED.
195 --    Type:    XtCallbackList
196 --    Default: NULL
197 --
198 --  XmUbNmdiTitleShadows              CG
199 --      XmUbCMdiTitleShadows
200 --    If True, the title bar pushbutton will have a shadow thickness of 1.
201 --    If False, no shadows will be drawn.
202 --    Set this resource to False if there is no action on the title bar.
203 --    Type:    Boolean
204 --    Default: True
205 --
206 --  XmUbNmdiTodayForeground           CSG
207 --      XmCForeground
208 --    The foreground color used for the current date.
209 --    Type:    Pixel
210 --    Default: the default foreground color
211 --
212 --  XmUbNmdiUpdateDayCallback         CSG
213 --      XmCCallback
214 --    Callback(s) that is called before a new date is displayed.
215 --    Callback reason: XmUbCR_UPDATE_DAY
216 --    Type:    XtCallbackList
217 --    Default: NULL
218 --
219 --  XmUbNmdiUseDefaultTitleCallback   CSG
220 --      XmUbCMdiUseDefaultTitleCallback
221 --    If True, the current month and year are set when the user presses the
222 --    title bar. If False, nothing is done.
223 --    The user's XmUbNmdiTitleCallback is called anyway, in the case of True
224 --    after the month and year have been set.
225 --    Type:    Boolean
226 --    Default: True
227 --
228 --  XmUbNmdiWeekdayForeground         CSG
229 --      XmCForeground
230 --    The color in which the weekdays of the current month are displayed.
231 --    Type:    Pixel
232 --    Default: the default foreground color
233 --
234 --  XmUbNmdiWeekLabel                 CG
235 --      XmUbCMdiWeekLabel
236 --    The label displayed on the same level as the day name, in the week
237 --    number column. Only used if XmUbNmdiWeekNumbers is True.
238 --    If NULL, a default string is used.
239 --    The string is copied internally. A copy is returned by XtGetValues.
240 --    Type:    XmString
241 --    Default: NULL
242 --
243 --  XmUbNmdiWeekNumberForeground      CSG
244 --      XmCForeground
245 --    The color in which to display the week numbers.
246 --    Only used if XmUbNmdiWeekNumbers is True.
247 --    Type:    Pixel
248 --    Default: the default foreground color
249 --
250 --  XmUbNmdiWeekNumbers               CG
251 --      XmUbCMdiWeekNumbers
252 --    If True, week numbers are displayed to the left of the day numbers.
253 --    If False, no week numbers are displayed.
254 --    Type:    Boolean
255 --    Default: True
256 --
257 --  XmUbNmdiYearArrows                CG
258 --      XmUbCMdiYearArrows
259 --    If True, arrow buttons for year scrolling are created below the month
260 --    display.
261 --    Type:    Boolean
262 --    Default: True
263 --
264 --  XmUbNmdiYearLabel                 CSG
265 --      XmUbCMdiYearLabel
266 --    The text to be displayed in the year scrolling label, if enabled.
267 --    If none is specified, a default string will be used.
268 --    The string is copied internally. A copy is returned by XtGetValues.
269 --    Type:    XmString
270 --    Default: NULL
271 --
272 ----------------------------------------------------------------------------*/
273 
274 /*----------------------------------------------------------------------------
275 --  Macro definitions
276 ----------------------------------------------------------------------------*/
277 
278 #define XmUbNmdiArrowSpacing              "mdiArrowSpacing"
279 #define XmUbNmdiCurrentMonth              "mdiCurrentMonth"
280 #define XmUbNmdiCurrentYear               "mdiCurrentYear"
281 #define XmUbNmdiDateSelectedCallback      "mdiDateSelectedCallback"
282 #define XmUbNmdiDayChars                  "mdiDayChars"
283 #define XmUbNmdiEnableSeparator           "mdiEnableSeparator"
284 #define XmUbNmdiFillOutWeek               "mdiFillOutWeek"
285 #define XmUbNmdiLabelSpacing              "mdiLabelSpacing"
286 #define XmUbNmdiMonthArrows               "mdiMonthArrows"
287 #define XmUbNmdiMonthLabel                "mdiMonthLabel"
288 #define XmUbNmdiNewMonthCallback          "mdiNewMonthCallback"
289 #define XmUbNmdiOtherMonthForeground      "mdiOtherMonthForeground"
290 #define XmUbNmdiRecomputeHeight           "mdiRecomputeHeight"
291 #define XmUbNmdiRecomputeWidth            "mdiRecomputeWidth"
292 #define XmUbNmdiSaturdayForeground        "mdiSaturdayForeground"
293 #define XmUbNmdiSundayForeground          "mdiSundayForeground"
294 #define XmUbNmdiTitleAlignment            "mdiTitleAlignment"
295 #define XmUbNmdiTitleCallback             "mdiTitleCallback"
296 #define XmUbNmdiTitleShadows              "mdiTitleShadows"
297 #define XmUbNmdiTodayForeground           "mdiTodayForeground"
298 #define XmUbNmdiUpdateDayCallback         "mdiUpdateDayCallback"
299 #define XmUbNmdiUseDefaultTitleCallback   "mdiUseDefaultTitleCallback"
300 #define XmUbNmdiWeekdayForeground         "mdiWeekdayForeground"
301 #define XmUbNmdiWeekLabel                 "mdiWeekLabel"
302 #define XmUbNmdiWeekNumberForeground      "mdiWeekNumberForeground"
303 #define XmUbNmdiWeekNumbers               "mdiWeekNumbers"
304 #define XmUbNmdiYearArrows                "mdiYearArrows"
305 #define XmUbNmdiYearLabel                 "mdiYearLabel"
306 
307 #define XmUbCMdiCurrentMonth              "MdiCurrentMonth"
308 #define XmUbCMdiCurrentYear               "MdiCurrentYear"
309 #define XmUbCMdiDayChars                  "MdiDayChars"
310 #define XmUbCMdiFillOutWeek               "MdiFillOutWeek"
311 #define XmUbCMdiEnableSeparator           "MdiEnableSeparator"
312 #define XmUbCMdiMonthArrows               "MdiMonthArrows"
313 #define XmUbCMdiMonthLabel                "MdiMonthLabel"
314 #define XmUbCMdiRecomputeHeight           "MdiRecomputeHeight"
315 #define XmUbCMdiRecomputeWidth            "MdiRecomputeWidth"
316 #define XmUbCMdiTitleShadows              "MdiTitleShadows"
317 #define XmUbCMdiUseDefaultTitleCallback   "MdiUseDefaultTitleCallback"
318 #define XmUbCMdiWeekLabel                 "MdiWeekLabel"
319 #define XmUbCMdiWeekNumbers               "MdiWeekNumbers"
320 #define XmUbCMdiYearArrows                "MdiYearArrows"
321 #define XmUbCMdiYearLabel                 "MdiYearLabel"
322 
323 
324 /* Id's for children retrieval. */
325 #define XmUbMD_CHILD_TITLE          0
326 #define XmUbMD_CHILD_ROW_COLUMN     1
327 #define XmUbMD_CHILD_YEAR_ARROW     2
328 #define XmUbMD_CHILD_MONTH_ARROW    3
329 #define XmUbMD_CHILD_WEEK_RC        4
330 #define XmUbMD_CHILD_SEPARATOR      5
331 
332 #define XmUbMD_FIRST_CHILD  XmUbMD_CHILD_TITLE
333 #define XmUbMD_LAST_CHILD   XmUbMD_CHILD_SEPARATOR
334 
335 /* Callback reasons. */
336 #define XmUbCR_DATE_SELECTED   0
337 #define XmUbCR_NEW_MONTH       1
338 #define XmUbCR_TITLE_PRESSED   2
339 #define XmUbCR_UPDATE_DAY      3
340 #define XmUbCR_UPDATE_WEEK     4
341 
342 /*----------------------------------------------------------------------------
343 --  Type declarations
344 ----------------------------------------------------------------------------*/
345 
346 typedef enum { XmUbCURRENT_MONTH,
347                XmUbPREVIOUS_MONTH,
348                XmUbNEXT_MONTH } XmUbWhichMonth;
349 
350 /* Callback structure. */
351 
352 typedef struct {
353 
354   int      reason;
355   XEvent   *event;
356   Widget   child;
357   Boolean  range;
358 
359   int      selected_day;
360   int      selected_month;
361   int      selected_year;
362 
363   int      end_day;
364   int      end_month;
365   int      end_year;
366 
367 } XmUbMonthDisplayCallbackStruct;
368 
369 
370 typedef struct {
371 
372   int             reason;
373   XEvent          *event;
374   int             day;
375   int             month;
376   int             year;
377   int             weekday;
378   int             day_num_in_year;
379   int             week_number;
380   Pixel           foreground;
381   Pixel           background;
382   Pixel           frame;
383   Boolean         use_shadows;
384   Boolean         mapped;
385   Pixel           default_foreground;
386   Pixel           default_background;
387   Pixel           default_frame;
388   Boolean         default_mapped;
389   XmUbWhichMonth  which_month;
390   int             loop_index;
391   Boolean         today;
392 
393 } XmUbMdiUpdateDayCallbackStruct;
394 
395 /*
396 -- CALLBACKS
397 --
398 -- XmUbNmdiDateSelectedCallback
399 --   Called when a date or week button is pressed.
400 --
401 --   reason              XmUbCR_DATE_SELECTED
402 --   event               The button press callback event.
403 --   child               The widget id for the button that was pressed.
404 --   range               True if a range was selected, False if a date.
405 --                       If True, the end_... fields are valid.
406 --   selected_day        The day number that was selected. (1..31)
407 --   selected_month      The month that was selected. (1..12)
408 --                       May be different from the current month.
409 --   selected_year       The year that was selected. (1970..)
410 --                       May be different from the current year.
411 --   end_day             The end day number if a range was selected.
412 --   end_month           The end month number if a range was selected.
413 --   end_year            The end year if a range was selected.
414 --
415 -- XmUbNmdiNewMonthCallback
416 --   Called when a new month is displayed.
417 --   Enables the user to set fore- and background colors and frames, as well
418 --   as setting the keyboard focus for the new month.
419 --   To enable correct setup at start, this callback is also invoked when
420 --   the widget is exposed for the first time.
421 --
422 --   reason              XmUbCR_NEW_MONTH
423 --   event               NULL
424 --   selected_month      The new month. (1..12)
425 --   selected_year       The new year. (1970..)
426 --
427 --    selected_year and selected_month are always equal to the current year
428 --    and the current month.
429 --
430 -- XmUbNmdiTitleCallback
431 --   Called when the title bar is pressed.
432 --   See also resource XmUbNmdiUseDefaultTitleCallback.
433 --
434 --   reason              XmUbCR_TITLE_PRESSED
435 --   event               The button press event for the title button.
436 --   selected_month      The current month. (1..12)
437 --   selected_year       The current year. (1970..)
438 --
439 -- XmUbNmdiUpdateDayCallback
440 --   Called when a new date is about to be displayed.
441 --   If this callback is set, the widget does not set the colors when a new
442 --   date is displayed. Instead, the current colors are extracted and put
443 --   in the callback structure. The user may then change these colors in the
444 --   callback function. The processed values are then set in the widget after
445 --   the callback has returned.
446 --   If no callback is set, the widget displays the dates according to its
447 --   resources.
448 --
449 --   The callback structure is of the type XmUbMdiUpdateDayCallbackStruct.
450 --
451 --   reason              XmUbCR_UPDATE_DAY
452 --   event               NULL
453 --   day                 The day that is about to be displayed.
454 --   month               The current month. (1..12)
455 --   year                The current year. (1970..)
456 --   weekday             The day of the week ( 1 = Monday,... 7 = Sunday)
457 --   day_num_in_year     The day number in the year.
458 --   week_number         The number of the current week.
459 --   foreground          The current foreground color.
460 --   background          The current background color.
461 --   frame               The current frame color.
462 --   use_shadows         Always set to False. If user sets this field to
463 --                       True, the default shadow colors are used, overriding
464 --                       the frame color.
465 --   mapped              True if the date is mapped, False if not.
466 --   default_foreground  The new foreground color according to resources.
467 --   default_background  The new background color according to resources.
468 --   default_frame       The new frame color according to resources.
469 --   default_mapped      The mapped status according to resources.
470 --   which_month         If the date is in the current month, the one before
471 --                       or the one after.
472 --   loop_index          The loop index of the date.
473 --   today               True if the day in question is "today".
474 --
475 --  The callback is also called when week numbers are updated.
476 --  The following fields are then valid.
477 --
478 --   reason              XmUbCR_UPDATE_WEEK
479 --   event               NULL
480 --   day                 The day of the first day in the week.
481 --   month               The month of the first day in the week.
482 --   year                The year of the first day in the week.
483 --   week_number         The number of the current week.
484 --   foreground          The current foreground color.
485 --   background          The current background color.
486 --   frame               The current frame color.
487 --   use_shadows         Always set to False. If user sets this field to
488 --                       True, the default shadow colors are used, overriding
489 --                       the frame color.
490 --   mapped              True if the button is mapped, False if not.
491 --   default_foreground  The new foreground color according to resources.
492 --   default_background  The new background color according to resources.
493 --   default_frame       The new frame color according to resources.
494 --   default_mapped      The mapped status according to resources.
495 --   loop_index          The loop index of the date.
496 --
497 */
498 
499 /*----------------------------------------------------------------------------
500 --  Global definitions
501 ----------------------------------------------------------------------------*/
502 
503 /* Class record constants. */
504 extern WidgetClass xmUbMonthDisplayWidgetClass;
505 
506 
507 typedef struct _XmUbMonthDisplayClassRec *XmUbMonthDisplayWidgetClass;
508 typedef struct _XmUbMonthDisplayRec      *XmUbMonthDisplayWidget;
509 
510 
511 /*----------------------------------------------------------------------------
512 --  Function prototypes
513 ----------------------------------------------------------------------------*/
514 
515 Widget
516   XmUbCreateMonthDisplay( Widget    parent,
517                           String    name,
518                           ArgList   arglist,
519                           Cardinal  argcount );
520 
521 Widget
522   XmUbMonthDisplayGetChild( Widget  widget,
523                             int     child );
524 
525 /* Sets the keyboard focus to the day_number in the current month. */
526 void
527   XmUbMonthDisplaySetFocusToDay( Widget  widget,
528                                  int     day_number );
529 
530 void
531   XmUbMonthDisplaySetDateBackground( Widget  widget,
532                                      int     day_number,
533                                      Pixel   bg );
534 
535 void
536   XmUbMonthDisplaySetDateForeground( Widget  widget,
537                                      int     day_number,
538                                      Pixel   fg );
539 
540 void
541   XmUbMonthDisplaySetDateFrame( Widget  widget,
542                                 int     day_number,
543                                 Pixel   color );
544 
545 /* Year and month may be set to zero. In that case, their values are not
546    changed, but a redisplay is triggered anyway. */
547 void
548   XmUbMonthDisplaySetMonth( Widget  widget,
549                             int     year,
550                             int     month );
551 
552 #endif
553 
554 
555