1 /*----------------------------------------------------------------------------
2 --
3 --  Module:           xtmShowToDo
4 --
5 --  Project:          Xdiary
6 --  System:           xtm - X Desktop Calendar
7 --    Subsystem:      <>
8 --    Function block: <>
9 --
10 --  Description:
11 --    Show what we have to do (a summary of the day entries).
12 --
13 --  Filename:         xtmShowToDo.c
14 --
15 --  Authors:          Roger Larsson, Ulrika Bornetun
16 --  Creation date:    1991-01-24
17 --
18 --
19 --  (C) Copyright Ulrika Bornetun, Roger Larsson (1995)
20 --      All rights reserved
21 --
22 --  Permission to use, copy, modify, and distribute this software and its
23 --  documentation for any purpose and without fee is hereby granted,
24 --  provided that the above copyright notice appear in all copies. Ulrika
25 --  Bornetun and Roger Larsson make no representations about the usability
26 --  of this software for any purpose. It is provided "as is" without express
27 --  or implied warranty.
28 ----------------------------------------------------------------------------*/
29 
30 /* SCCS module identifier. */
31 static char SCCSID[] = "@(#) Module: xtmShowToDo.c, Version: 1.1, Date: 95/02/18 15:52:51";
32 
33 
34 /*----------------------------------------------------------------------------
35 --  Include files
36 ----------------------------------------------------------------------------*/
37 
38 #include <string.h>
39 #include <stdlib.h>
40 #include <stdio.h>
41 
42 #include <X11/Intrinsic.h>
43 #include <X11/Shell.h>
44 
45 #include <Xm/Protocols.h>
46 
47 #include <Xm/Xm.h>
48 #include <Xm/CascadeB.h>
49 #include <Xm/Form.h>
50 #include <Xm/Frame.h>
51 #include <Xm/PushB.h>
52 #include <Xm/RowColumn.h>
53 #include <Xm/ScrolledW.h>
54 #include <Xm/SeparatoG.h>
55 #include <Xm/Text.h>
56 #include <Xm/ToggleB.h>
57 
58 #include "System.h"
59 #include "Message.h"
60 
61 #include "msgXdiary.h"
62 #include "xtmGlobal.h"
63 #include "xtmCalDb.h"
64 #include "xtmDbFilter.h"
65 #include "xtmDbInclude.h"
66 #include "xtmDbMisc.h"
67 #include "xtmDbTools.h"
68 #include "xtmFields.h"
69 #include "xtmFormat.h"
70 #include "xtmHelp.h"
71 #include "xtmIcons.h"
72 #include "xtmPrEntries.h"
73 #include "xtmTools.h"
74 #include "xitError.h"
75 #include "xitFieldSel.h"
76 #include "xitTools.h"
77 #include "XmUbTimeB.h"
78 #include "xtmShowToDo.h"
79 
80 
81 /*----------------------------------------------------------------------------
82 --  Macro definitions
83 ----------------------------------------------------------------------------*/
84 
85 #define max( a, b )  (a < b ? b : a )
86 
87 /* Internal summary flags. */
88 #define ENTRY_FLAGS     (1<<0)
89 
90 /* Windows in the cache? */
91 #define  MAX_CACHE_ENTRIES   3
92 
93 
94 /* Local widgets in the show window. */
95 #define calFs              dataLocalW[  0 ]
96 #define calLa              dataLocalW[  1 ]
97 #define calRc              dataLocalW[  2 ]
98 #define menuBr             dataLocalW[  3 ]
99 #define rangeTb            dataLocalW[  4 ]
100 #define shDayRc            dataLocalW[  5 ]
101 #define shDoLa             dataLocalW[  6 ]
102 #define shLineLa           dataLocalW[  7 ]
103 #define shLineRc           dataLocalW[  8 ]
104 #define shLineTx           dataLocalW[  9 ]
105 #define shWhatLa           dataLocalW[ 10 ]
106 #define textLa             dataLocalW[ 11 ]
107 #define textSw    	   dataLocalW[ 12 ]
108 
109 
110 /*----------------------------------------------------------------------------
111 --  Type declarations
112 ----------------------------------------------------------------------------*/
113 
114 /* Record for summary. */
115 typedef struct {
116 
117   /* Flags to use. */
118   UINT32  flags;
119 
120   /* The summary is for this database. */
121   char  db_name[ XTM_GL_MAX_CAL_NAME + 1 ];
122 
123   /* Look for entries with these tags. */
124   char  search_tags[ 200 ];
125 
126   /* The summary window. */
127   Widget  showW;
128 
129   /* Include handle. */
130   XTM_DI_HANDLE  include_handle;
131 
132   /* Filter record. */
133   XTM_DM_FILTER_REC  filter_rec;
134 
135   /* Filter handle. */
136   XTM_FI_HANDLE  filter_handle;
137 
138   /* Application wide data. */
139   XTM_GL_BASE_DATA_REF  appl_data_ref;
140 
141   /* Reference to printer window. */
142   XTM_PR_HANDLE  pr_handle;
143 
144   /* Callback to inform our creator of specific actions. */
145   void              *user_data;
146   XTM_SD_ACTION_CB  actionCB;
147 
148 } SHOW_REC, *SHOW_REC_REF;
149 
150 
151 /*----------------------------------------------------------------------------
152 --  Global definitions
153 ----------------------------------------------------------------------------*/
154 
155 /* Name of module. */
156 static char  *module_name = "xtmShowToDo";
157 
158 /* IDs for the help windows. */
159 static char  *sum_window_id = "Summary";
160 
161 /* Cache entries. */
162 static Boolean       init_cache = True;
163 static SHOW_REC_REF  cache_entries[ MAX_CACHE_ENTRIES ];
164 
165 
166 /*----------------------------------------------------------------------------
167 --  Function prototypes
168 ----------------------------------------------------------------------------*/
169 
170 static void
171   applyCB( Widget        widget,
172            SHOW_REC_REF  show_ref,
173            XtPointer     call_data );
174 
175 static void
176   calChangedCB( Widget        widget,
177                 SHOW_REC_REF  show_ref,
178                 XtPointer     call_data );
179 
180 static void
181   closeCB( Widget        widget,
182            SHOW_REC_REF  show_ref,
183            XtPointer     call_data );
184 
185 static Widget
186   createShowWindow( SHOW_REC_REF  show_ref,
187                     Widget        parent );
188 
189 static void
190   ctrlMenuCB( Widget                     widget,
191               SHOW_REC_REF               show_ref,
192               XmRowColumnCallbackStruct  *call_data );
193 
194 static void
195   destroyCB( Widget        widget,
196              SHOW_REC_REF  show_ref,
197              XtPointer     call_data );
198 
199 static void
200   filterApplyCB( XTM_FI_REASON      reason,
201                  XTM_DM_FILTER_REC  *filter_ref,
202                  void               *user_data );
203 
204 static void
205   filterCB( Widget        widget,
206             SHOW_REC_REF  show_ref,
207             XtPointer     call_data );
208 
209 static void
210   includeDbApplyCB( XTM_DI_REASON         reason,
211                     XTM_CD_INCL_CALS_REF  new_db_incl_ref,
212                     void                  *user_data );
213 
214 static void
215   infoCB( Widget                     widget,
216           SHOW_REC_REF               show_ref,
217           XmRowColumnCallbackStruct  *call_data );
218 
219 void
220   mapCtrlMenuCB( Widget        widget,
221                  SHOW_REC_REF  show_ref,
222                  XtPointer     call_data );
223 
224 static void
225   printCB( Widget        widget,
226            SHOW_REC_REF  show_ref,
227            XtPointer     call_data );
228 
229 
230 
231 /*----------------------------------------------------------------------------
232 --  Functions
233 ----------------------------------------------------------------------------*/
234 
235 XTM_SD_HANDLE
xtmSdInitialize(XTM_GL_BASE_DATA_REF appl_data_ref,Widget toplevel,char * db_name,XTM_SD_ACTION_CB actionCB,void * user_data)236   xtmSdInitialize( XTM_GL_BASE_DATA_REF  appl_data_ref,
237                    Widget                toplevel,
238                    char                  *db_name,
239                    XTM_SD_ACTION_CB      actionCB,
240                    void                  *user_data )
241 {
242 
243   /* Variables. */
244   Boolean                 ok;
245   int                     index;
246   int                     length;
247   SHOW_REC_REF            show_ref;
248   XTM_CD_CAL_INFO         db_info;
249   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
250 
251 
252   /* Code. */
253 
254   custom_data_ref = appl_data_ref -> custom_data;
255 
256 
257   /* Fetch database information. */
258   ok = xtmCdFetchNamedDb( custom_data_ref -> cal_db_handle,
259                           db_name,
260                           &db_info, NULL );
261   if( ! ok )
262     return( False );
263 
264 
265   /* Minium permissions are read. */
266   if( ! flagIsSet( db_info.operations, XTM_DB_FLAG_MODE_READ ) )
267     return( NULL );
268 
269 
270   /* Initialize the cache? */
271   if( init_cache ) {
272     for( index = 0; index < MAX_CACHE_ENTRIES; index++ )
273       cache_entries[ index ] = NULL;
274 
275     init_cache = False;
276   }
277 
278 
279   /* Anything in the cache? */
280   show_ref = NULL;
281 
282   for( index = 0; index < MAX_CACHE_ENTRIES; index++ ) {
283     if( cache_entries[ index ] != NULL ) {
284       show_ref = cache_entries[ index ];
285       cache_entries[ index ] = NULL;
286 
287       break;
288     }
289   }
290 
291   /* Create the showrecord? */
292   if( show_ref == NULL ) {
293 
294     /* Create and initialize our private data. */
295     show_ref = SysNew( SHOW_REC );
296     if( show_ref == NULL )
297       return( NULL );
298 
299     show_ref -> showW = NULL;
300 
301   } /* if */
302 
303   show_ref -> appl_data_ref    = appl_data_ref;
304   show_ref -> search_tags[ 0 ] = '\0';
305   show_ref -> include_handle   = NULL;
306   show_ref -> filter_handle    = NULL;
307   show_ref -> pr_handle        = NULL;
308   show_ref -> actionCB         = actionCB;
309   show_ref -> user_data        = user_data;
310 
311   show_ref -> filter_rec.flags            = XTM_DM_FLAG_ALL;
312   show_ref -> filter_rec.text_string[ 0 ] = '\0';
313   show_ref -> filter_rec.tag_string[  0 ] = '\0';
314 
315   length = strlen( custom_data_ref -> entry_tags_filter );
316 
317   if( length > 0 && length < XTM_DM_MAX_TAG_SEARCH ) {
318     strcpy( show_ref -> filter_rec.tag_string,
319             custom_data_ref -> entry_tags_filter );
320     flagSet( show_ref -> filter_rec.flags, XTM_DM_FLAG_SEARCH_TAG );
321   }
322 
323   if( custom_data_ref -> display_entry_flags )
324     flagSet( show_ref -> flags, ENTRY_FLAGS );
325 
326   if( strlen( custom_data_ref -> entry_tags_menu ) < 200 )
327     strcpy( show_ref -> search_tags, custom_data_ref -> entry_tags_menu );
328 
329 
330   /* Create a shadow calendar database. */
331   ok = xtmCdCreateShadowEntry( custom_data_ref -> cal_db_handle,
332                                db_name, show_ref -> db_name );
333   if( ! ok ) {
334     SysFree( show_ref );
335 
336     return( NULL );
337   }
338 
339 
340   /* Create the summary window. */
341   if( show_ref -> showW == NULL ) {
342     show_ref -> showW = createShowWindow( show_ref, toplevel );
343 
344     if( show_ref -> showW == NULL ) {
345       xtmCdFreeShadowEntry( custom_data_ref -> cal_db_handle,
346                             show_ref -> db_name );
347       SysFree( show_ref );
348 
349       return( NULL );
350     }
351   }
352 
353 
354   return( (XTM_SD_HANDLE) show_ref );
355 
356 } /* xtmSdInitialize */
357 
358 
359 /*----------------------------------------------------------------------*/
360 
361 void
xtmSdDestroy(XTM_SD_HANDLE show_handle)362   xtmSdDestroy( XTM_SD_HANDLE  show_handle )
363 {
364 
365   /* Variables. */
366   SHOW_REC_REF  show_ref;
367 
368 
369   /* Code. */
370 
371   if( show_handle == NULL )
372     return;
373 
374   /* Our private data. */
375   show_ref = (SHOW_REC_REF) show_handle;
376 
377   /* Destroy the window. */
378   closeCB( NULL, show_ref, NULL );
379 
380 
381   return;
382 
383 } /* xtmSdDestroy */
384 
385 
386 /*----------------------------------------------------------------------*/
387 
388 void
xtmSdDisplaySummary(XTM_SD_HANDLE show_handle,TIM_TIME_REF from_date,TIM_TIME_REF to_date,char * search_tags)389   xtmSdDisplaySummary( XTM_SD_HANDLE  show_handle,
390                        TIM_TIME_REF   from_date,
391                        TIM_TIME_REF   to_date,
392                        char           *search_tags )
393 {
394 
395   /* Variables. */
396   Widget                  mainW;
397   Widget                  tempW;
398   SHOW_REC_REF            show_ref;
399   XTM_GL_BASE_DATA_REF    appl_data_ref;
400   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
401   XTM_CD_CAL_INFO         db_info;
402 
403 
404   /* Code. */
405 
406   show_ref        = (SHOW_REC_REF) show_handle;
407   appl_data_ref   = show_ref -> appl_data_ref;
408   custom_data_ref = appl_data_ref -> custom_data;
409 
410 
411   mainW = XtNameToWidget( show_ref -> showW, "ShowTlBase.ShowTlFo" );
412 
413 
414   /* Calendar we are using. */
415   (void) xtmCdFetchNamedDb( custom_data_ref -> cal_db_handle,
416                             show_ref -> db_name,
417                             &db_info, NULL );
418 
419 
420   /* The fields containing from and to date. */
421   tempW = XtNameToWidget( mainW, "ShDayRc.RangeTb" );
422 
423   XmUbTimeBoxSetStartDate( tempW, from_date );
424   XmUbTimeBoxSetEndDate( tempW, to_date );
425 
426 
427   /* Calendar to use. */
428   tempW = XtNameToWidget( mainW, "CalRc.CalFs" );
429   xitFieldSelectSetCurrent( tempW, db_info.short_name, False );
430 
431 
432   /* Do we search special tags? */
433   if( strlen( search_tags ) > 0 )
434     strcpy( show_ref -> filter_rec.tag_string, search_tags );
435 
436 
437   /* Display the current summary. */
438   tempW = XtNameToWidget( mainW, "ActionFo.ApplyPb" );
439   applyCB( tempW, show_ref, NULL );
440 
441 
442   /* Display the window. */
443   XtPopup( show_ref -> showW, XtGrabNone );
444 
445 
446   /* Make sure the editor window is visable. */
447   XRaiseWindow( XtDisplay( show_ref -> showW ),
448                 XtWindow(  show_ref -> showW ) );
449 
450   XtMapWidget( show_ref -> showW );
451 
452 
453   return;
454 
455 } /* xtmSdDisplaySummary */
456 
457 
458 /*----------------------------------------------------------------------*/
459 
460 void
xtmSdEmptyCache()461   xtmSdEmptyCache()
462 {
463 
464   /* Variables. */
465   int  index;
466 
467 
468   /* Code. */
469 
470   if( ! init_cache )
471     return;
472 
473   for( index = 0; index < MAX_CACHE_ENTRIES; index++ ) {
474     if( cache_entries[ index ] != NULL )
475       XtDestroyWidget( cache_entries[ index ] -> showW );
476 
477     cache_entries[ index ] = NULL;
478   }
479 
480 
481   return;
482 
483 } /* xtmSdEmptyCache */
484 
485 
486 /*----------------------------------------------------------------------*/
487 
488 static Widget
createShowWindow(SHOW_REC_REF show_ref,Widget parent)489   createShowWindow( SHOW_REC_REF  show_ref,
490                     Widget        parent )
491 {
492 
493   /* Variables. */
494   int                     index;
495   char                    buffer[ 50 ];
496   Arg                     args[ 10 ];
497   Cardinal                n;
498   Widget                  dataLocalW[ 13 ];
499   Widget                  menuCasc[ 3 ];
500   Widget                  menuCtrlBu[ 4 ];
501   Widget                  menuFileBu[ 1 ];
502   Widget                  menuHelpBu[ 6 ];
503   Widget                  pulldownMenu[ 3 ];
504   Widget                  showTl;
505   Widget                  toplevel;
506   Widget                  workFo;
507   XTM_GL_BASE_DATA_REF    appl_data_ref;
508   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
509 
510   static char  *pull_downs[] = { "pdown1", "pdown2", "pdown3" };
511 
512   static XIT_TEXT_STRUCT text_field_def[] = {
513     { "ShLineTx", NULL, 1, True },
514   };
515 
516   static XIT_CASCADE_STRUCT menupane[] = {
517     { "", "", "FilePane" },
518     { "", "", "ControlPane" },
519     { "", "", "HelpPane" },
520   };
521 
522   static XIT_MENU_BUTTON_STRUCT file_casc[] = {
523     { "", "", NULL, "CloseBu", True, False, False },
524   };
525 
526   static XIT_MENU_BUTTON_STRUCT ctrl_casc[] = {
527     { "",      "",  NULL, "EntryFlagsBu", True,  True,  False },
528     { XIT_SEP, " ", NULL, "",             False, False, False },
529     { "",      "",  NULL, "FilterBu",     True,  False, False },
530     { "",      "",  NULL, "IncludeBu",    True,  False, False },
531   };
532 
533   static XIT_MENU_BUTTON_STRUCT help_casc[] = {
534     { "", "", NULL, "ContextBu", True, False, False },
535     { "", "", NULL, "WindowsBu", True, False, False },
536     { "", "", NULL, "KeysBu",    True, False, False },
537     { "", "", NULL, "IndexBu",   True, False, False },
538     { "", "", NULL, "HelpBu",    True, False, False },
539     { "", "", NULL, "VersionBu", True, False, False },
540   };
541 
542   static XIT_ACTION_AREA_ITEM  action_buttons[] = {
543     { "", applyCB,  NULL },
544     { "", printCB,  NULL },
545     { "", filterCB, NULL },
546     { "", closeCB,  NULL },
547   };
548 
549 
550   /* Code. */
551 
552   appl_data_ref   = show_ref -> appl_data_ref;
553   custom_data_ref = appl_data_ref -> custom_data;
554 
555 
556   /* Get text for menues and buttons. */
557   action_buttons[ 0 ].label = msgGetText( MXDI_APPLY_BUTTON );
558   action_buttons[ 0 ].data  = show_ref;
559   action_buttons[ 1 ].label = msgGetText( MXDI_PRINT_MENU );
560   action_buttons[ 1 ].data  = show_ref;
561   action_buttons[ 2 ].label = msgGetText( MXDI_FILTER_MENU );
562   action_buttons[ 2 ].data  = show_ref;
563   action_buttons[ 3 ].label = msgGetText( MXDI_CLOSE_BUTTON );
564   action_buttons[ 3 ].data  = show_ref;
565 
566   menupane[ 0 ].title    = msgGetText( MXDI_FILE_MENU );
567   menupane[ 0 ].mnemonic = msgGetText( MXDI_FILE_MENU_ACC );
568   menupane[ 1 ].title    = msgGetText( MXDI_CTRL_MENU );
569   menupane[ 1 ].mnemonic = msgGetText( MXDI_CTRL_MENU_ACC );
570   menupane[ 2 ].title    = msgGetText( MXDI_HELP_MENU );
571   menupane[ 2 ].mnemonic = msgGetText( MXDI_HELP_MENU_ACC );
572 
573   file_casc[ 0 ].title    = msgGetText( MXDI_CLOSE_MENU );
574   file_casc[ 0 ].mnemonic = msgGetText( MXDI_CLOSE_MENU_ACC );
575 
576   ctrl_casc[ 0 ].title    = msgGetText( MXDI_FLAGS_DISPLAY_MENU );
577   ctrl_casc[ 0 ].mnemonic = msgGetText( MXDI_FLAGS_DISPLAY_MENU_ACC );
578   ctrl_casc[ 2 ].title    = msgGetText( MXDI_FILTER_MENU );
579   ctrl_casc[ 2 ].mnemonic = msgGetText( MXDI_FILTER_MENU_ACC );
580   ctrl_casc[ 3 ].title    = msgGetText( MXDI_INCLUDE_MENU );
581   ctrl_casc[ 3 ].mnemonic = msgGetText( MXDI_INCLUDE_MENU_ACC );
582 
583   help_casc[ 0 ].title    = msgGetText( MXDI_HELP_CONTEXT );
584   help_casc[ 0 ].mnemonic = msgGetText( MXDI_HELP_CONTEXT_ACC );
585   help_casc[ 1 ].title    = msgGetText( MXDI_HELP_WINDOWS );
586   help_casc[ 1 ].mnemonic = msgGetText( MXDI_HELP_WINDOWS_ACC );
587   help_casc[ 2 ].title    = msgGetText( MXDI_HELP_KEYS );
588   help_casc[ 2 ].mnemonic = msgGetText( MXDI_HELP_KEYS_ACC );
589   help_casc[ 3 ].title    = msgGetText( MXDI_HELP_INDEX );
590   help_casc[ 3 ].mnemonic = msgGetText( MXDI_HELP_INDEX_ACC );
591   help_casc[ 4 ].title    = msgGetText( MXDI_HELP_HELP );
592   help_casc[ 4 ].mnemonic = msgGetText( MXDI_HELP_HELP_ACC );
593   help_casc[ 5 ].title    = msgGetText( MXDI_HELP_VERSION );
594   help_casc[ 5 ].mnemonic = msgGetText( MXDI_HELP_VERSION_ACC );
595 
596 
597   /* Create a separate window. */
598   toplevel = xitGetToplevelWidget( parent );
599 
600   showTl = xitCreateToplevelDialog( toplevel, "ShowTl",
601                                     1, 0,
602                                     action_buttons,
603                                     XtNumber( action_buttons ) );
604 
605   XtAddCallback( showTl, XmNdestroyCallback,
606                  (XtCallbackProc) destroyCB, (XtPointer) show_ref );
607 
608 
609   /* Close the window if this window is deleted. */
610   {
611     Atom  wm_delete_window;
612 
613     wm_delete_window = XmInternAtom( XtDisplay( showTl ),
614                                      "WM_DELETE_WINDOW", False );
615 
616     XmAddWMProtocols( showTl,  &wm_delete_window, 1 );
617     XmAddWMProtocolCallback( showTl,  wm_delete_window,
618                              (XtCallbackProc) closeCB, (XtPointer) show_ref );
619   } /* block */
620 
621 
622   /* Form to enclose the show window. */
623   workFo = XtNameToWidget( showTl, "ShowTlBase.ShowTlFo" );
624 
625 
626   /* Create the menubar and menu cascades. */
627   menuBr = XmCreateMenuBar( workFo, "MenuBr", args, 0 );
628 
629   n = 0;
630   for( index = 0; index < XtNumber( pulldownMenu ); index++ )
631     pulldownMenu[ index ] = XmCreatePulldownMenu( menuBr,
632                                                   pull_downs[ index ],
633                                                   NULL, n );
634 
635   for( index = 0; index < XtNumber( menuCasc ); index++ )
636     menuCasc[ index ] = xitCreateCascadeButton( menuBr,
637                                                 pulldownMenu[ index ],
638                                                 &menupane[ index ] );
639 
640   /* The help button should be placed to the right. */
641   index = XtNumber( menuCasc ) - 1;
642   n     = 0;
643   XtSetArg( args[ n ], XmNmenuHelpWidget, menuCasc[ index ] ); n++;
644   XtSetValues( menuBr, args, n );
645 
646 
647   /* Create the file menu. */
648   for( index = 0; index < XtNumber( menuFileBu ); index++ )
649     menuFileBu[ index ] = xitCreateMenuPushButton( pulldownMenu[ 0 ],
650                                                    &file_casc[ index ] );
651 
652   XtAddCallback( menuFileBu[ 0 ], XmNactivateCallback,
653                  (XtCallbackProc) closeCB, (XtPointer) show_ref );
654 
655 
656   /* Create the control menu. */
657   XtAddCallback( pulldownMenu[ 1 ], XmNentryCallback,
658                  (XtCallbackProc) ctrlMenuCB, (XtPointer) show_ref );
659   XtAddCallback( pulldownMenu[ 1 ], XmNmapCallback,
660                  (XtCallbackProc) mapCtrlMenuCB, (XtPointer) show_ref );
661 
662   for( index = 0; index < XtNumber( menuCtrlBu ); index++ ) {
663     menuCtrlBu[ index ] = xitCreateMenuPushButton( pulldownMenu[ 1 ],
664                                                    &ctrl_casc[ index ] );
665 
666     if( XmIsPushButton( menuCtrlBu[ index ] ) )
667       XtAddCallback( menuCtrlBu[ index ], XmNactivateCallback,
668                      (XtCallbackProc) ctrlMenuCB, (XtPointer)(intptr_t)index );
669     else if( XmIsToggleButton( menuCtrlBu[ index ] ) )
670       XtAddCallback( menuCtrlBu[ index ], XmNvalueChangedCallback,
671                      (XtCallbackProc) ctrlMenuCB, (XtPointer)(intptr_t)index );
672   }
673 
674 
675   /* Create the help menu. */
676   XtAddCallback( pulldownMenu[ 2 ], XmNentryCallback,
677                  (XtCallbackProc) infoCB, (XtPointer) show_ref );
678 
679   for( index = 0; index < XtNumber( menuHelpBu ); index++ ) {
680     menuHelpBu[ index ] = xitCreateMenuPushButton( pulldownMenu[ 2 ],
681                                                    &help_casc[ index ] );
682 
683     XtAddCallback( menuHelpBu[ index ], XmNactivateCallback,
684                    (XtCallbackProc) infoCB, (XtPointer)(intptr_t)index );
685   }
686 
687   /* We can't do context sensitive help. */
688   XtSetSensitive( menuHelpBu[ 0 ], False );
689 
690 
691   /* Label to do. */
692   shDoLa = xitCreateLabel( workFo, "ShDoLa",
693                            msgGetText( MXDI_SUMMARY_LABEL ),
694                            XmALIGNMENT_BEGINNING );
695 
696 
697   /* Create lablel to hold the text (in a scrolled win). */
698   n = 0;
699   XtSetArg( args[ n ], XmNscrollingPolicy,        XmAUTOMATIC ); n++;
700   XtSetArg( args[ n ], XmNscrollBarDisplayPolicy, XmAS_NEEDED ); n++;
701   textSw = XmCreateScrolledWindow( workFo, "TextSw", args, n );
702 
703   textLa = xitCreateLabelWidget( textSw, "TextLa", " ", -1 );
704 
705   n = 0;
706   XtSetArg( args[ n ], XmNworkWindow, textLa ); n++;
707   XtSetValues( textSw, args, n );
708 
709 
710   /* Calendar selection. */
711   n = 0;
712   XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL ); n++;
713   calRc = XmCreateRowColumn( workFo, "CalRc", args, n );
714 
715   calLa = xitCreateLabel( calRc, "CalLa",
716                           msgGetText( MXDI_DATABASE_LABEL ), -1 );
717 
718   calFs = xtmFlCreateDbField( calRc, "CalFs",
719                               custom_data_ref -> cal_db_handle,
720                               True,
721                               (XtCallbackProc) calChangedCB,
722                               (void *) show_ref );
723 
724 
725   /* Create a show date form. */
726   n = 0;
727   XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL ); n++;
728   XtSetArg( args[ n ], XmNpacking,     XmPACK_TIGHT ); n++;
729   shDayRc = XmCreateRowColumn( workFo, "ShDayRc", args, n );
730 
731   shWhatLa = xitCreateLabel( shDayRc, "ShWhatLa",
732                              msgGetText( MXDI_BETWEEN_DATES ), -1 );
733 
734   /* Date range selector. */
735   rangeTb = xtmFlCreateRangeField( shDayRc, "RangeTb" );
736 
737 
738   /* Lines to display. */
739   n = 0;
740   XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL ); n++;
741   shLineRc = XmCreateRowColumn( workFo, "ShLineRc", args, n );
742 
743   shLineLa = xitCreateLabel( shLineRc, "ShLineLa",
744                              msgGetText( MXDI_SUMMARY_LINES ), -1 );
745 
746   shLineTx = xitCreateTextCols( shLineRc, &text_field_def[ 0 ], 5 );
747 
748   n = 0;
749   XtSetArg( args[ n ], XmNmaxLength, 5 );  n++;
750   XtSetValues( shLineTx, args, n );
751 
752 
753   /* Put the Parts together. */
754   xitAttachWidget( menuBr,
755                    XmATTACH_FORM, NULL, XmATTACH_FORM, NULL,
756                    XmATTACH_FORM, NULL, XmATTACH_NONE, NULL );
757   xitAttachWidget( shDoLa,
758                    XmATTACH_WIDGET, menuBr, XmATTACH_FORM, NULL,
759                    XmATTACH_FORM,   NULL,   XmATTACH_NONE, NULL );
760   xitAttachWidget( textSw,
761                    XmATTACH_WIDGET, shDoLa, XmATTACH_FORM, NULL,
762                    XmATTACH_NONE,   NULL,   XmATTACH_NONE, NULL );
763   xitAttachWidget( calRc,
764                    XmATTACH_WIDGET, textSw, XmATTACH_FORM, NULL,
765                    XmATTACH_NONE,   NULL,   XmATTACH_NONE, NULL );
766   xitAttachWidget( shDayRc,
767                    XmATTACH_WIDGET, calRc, XmATTACH_FORM, NULL,
768                    XmATTACH_NONE,   NULL,  XmATTACH_NONE, NULL );
769   xitAttachWidget( shLineRc,
770                    XmATTACH_WIDGET, shDayRc, XmATTACH_FORM, NULL,
771                    XmATTACH_NONE,   NULL,    XmATTACH_NONE, NULL );
772 
773 
774   /* Make sure there is enough space between the children. */
775   n = 0;
776   XtSetArg( args[ n ], XmNtopOffset,    5 ); n++;
777   XtSetArg( args[ n ], XmNleftOffset,   5 ); n++;
778   XtSetArg( args[ n ], XmNrightOffset,  5 ); n++;
779   XtSetArg( args[ n ], XmNbottomOffset, 5 ); n++;
780   XtSetValues( shDoLa,   args, n );
781   XtSetValues( textSw,   args, n );
782   XtSetValues( shDayRc,  args, n );
783   XtSetValues( shLineRc, args, n );
784   XtSetValues( calRc,    args, n );
785 
786 
787   /* Manage all the children. */
788   XtManageChildren( menuCasc,     XtNumber( menuCasc ) );
789   XtManageChildren( menuCtrlBu,   XtNumber( menuCtrlBu ) );
790   XtManageChildren( menuFileBu,   XtNumber( menuFileBu ) );
791   XtManageChildren( menuHelpBu,   XtNumber( menuHelpBu ) );
792   XtManageChildren( pulldownMenu, XtNumber( pulldownMenu ) );
793 
794   xitManageChildren( dataLocalW,  XtNumber( dataLocalW ) );
795 
796   XtManageChild( showTl );
797 
798 
799   /* Set icon for this window. */
800   xtmIcSetSimpleIcon( showTl, workFo, XTM_IC_ICON_SUMMARY );
801 
802   /* Set the initial sizes. */
803   xitSetSizeToplevelDialog( showTl, True );
804 
805 
806   /* Make the final attachments. */
807   xitAttachWidget( shLineRc,
808                    XmATTACH_NONE, NULL, XmATTACH_FORM, NULL,
809                    XmATTACH_NONE, NULL, XmATTACH_FORM, NULL );
810   xitAttachWidget( shDayRc,
811                    XmATTACH_NONE, NULL, XmATTACH_FORM,   NULL,
812                    XmATTACH_NONE, NULL, XmATTACH_WIDGET, shLineRc );
813   xitAttachWidget( calRc,
814                    XmATTACH_NONE, NULL, XmATTACH_FORM,   NULL,
815                    XmATTACH_NONE, NULL, XmATTACH_WIDGET, shDayRc );
816   xitAttachWidget( textSw,
817                    XmATTACH_WIDGET, shDoLa, XmATTACH_FORM,   NULL,
818                    XmATTACH_FORM,   NULL,   XmATTACH_WIDGET, calRc );
819 
820   /* Number of lines to display. */
821   sprintf( buffer, "%d", custom_data_ref -> summary_def_lines );
822   XmTextSetString( shLineTx, buffer );
823 
824 
825   return( showTl );
826 
827 } /* createShowWindow */
828 
829 
830 /*----------------------------------------------------------------------*/
831 
832 static void
applyCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)833   applyCB( Widget        widget,
834            SHOW_REC_REF  show_ref,
835            XtPointer     call_data )
836 {
837 
838   /* Variables. */
839   int                     SEGMENT_SIZE = 10000;
840   UINT32                  flags;
841   Boolean                 ok;
842   int                     display_lines;
843   int                     items;
844   int                     text_size;
845   char                    buffer[ 100 ];
846   char                    *char_ref;
847   char                    *text_ref;
848   Arg                     args[ 10 ];
849   Cardinal                n;
850   Widget                  mainW;
851   Widget                  tempW;
852   LST_DESC_TYPE           entries;
853   LST_STATUS              lst_status;
854   TIM_DELTA_TYPE          delta;
855   TIM_TIME_REF            from_date;
856   TIM_TIME_REF            last_date = 0;
857   TIM_TIME_REF            to_date;
858   XTM_DB_STATUS           db_status;
859   XTM_GL_BASE_DATA_REF    appl_data_ref;
860   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
861   XTM_CD_CAL_INFO         db_info;
862 
863 
864   /* Code. */
865 
866   appl_data_ref   = show_ref -> appl_data_ref;
867   custom_data_ref = appl_data_ref -> custom_data;
868 
869   mainW = XtNameToWidget( show_ref -> showW, "ShowTlBase.ShowTlFo" );
870 
871 
872   /* Calendar we are using. */
873   (void) xtmCdFetchNamedDb( custom_data_ref -> cal_db_handle,
874                             show_ref -> db_name,
875                             &db_info, NULL );
876 
877 
878   /* Fetch the date range. */
879   tempW = XtNameToWidget( mainW, "ShDayRc.RangeTb" );
880 
881   ok = xtmFoFetchDate( mainW, tempW, XTM_FO_START_DATE, False, &from_date );
882   if( ! ok )
883     return;
884 
885   ok = xtmFoFetchDate( mainW, tempW, XTM_FO_END_DATE, False, &to_date );
886   if( ! ok )
887     return;
888 
889   if( from_date > to_date ) {
890     xitErMessage( show_ref -> showW, XIT_ER_ERROR,
891                   module_name, "applyCB",
892                   msgGetText( MXDI_INVALID_DATE_RANGE ) );
893     return;
894   }
895 
896 
897   /* Number of lines to display? */
898   tempW    = XtNameToWidget( mainW, "ShLineRc.ShLineTx" );
899   char_ref = xitStringGetText( tempW );
900 
901   items = sscanf( char_ref, "%d", &display_lines );
902   if( items != 1 || display_lines < 0 )
903     display_lines = 10000;
904 
905   SysFree( char_ref );
906 
907 
908   /* How many days can we display? */
909   (void) TimDelta( from_date, to_date, &delta );
910 
911   if( delta.days > 366 ) {
912     xitErMessage( show_ref -> showW, XIT_ER_ERROR,
913                   module_name, "applyCB",
914                   msgGetText( MXDI_PRINT_SHOW_TO_MANY_DAYS ) );
915     return;
916   }
917 
918 
919   /* The title contains the current calendar. */
920   sprintf( buffer, "%s %s",
921            db_info.short_name, msgGetText( MXDI_TODO_TITLE ) );
922 
923   n = 0;
924   XtSetArg( args[ n ], XmNtitle, buffer ); n++;
925   XtSetValues( show_ref -> showW, args, n );
926 
927   sprintf( buffer, "%s", db_info.short_name );
928 
929   n = 0;
930   XtSetArg( args[ n ], XmNiconName, buffer ); n++;
931   XtSetValues( show_ref -> showW, args, n );
932 
933 
934   /* Create the list of entries to display. */
935   flags = XTM_DB_FETCH_ALL_TEXT;
936 
937   db_status = xtmDmFetchFilteredEntriesRange(
938                 appl_data_ref,
939                 show_ref      -> db_name,
940                 appl_data_ref -> context,
941                 show_ref      -> showW,
942                 from_date,
943                 to_date,
944                 flags,
945                 &show_ref -> filter_rec,
946                 &entries );
947 
948   if( db_status != XTM_DB_OK ) {
949     xtmDmDeleteEntriesList( entries );
950     return;
951   }
952 
953 
954   /* Initialize data. */
955   text_size = SEGMENT_SIZE;
956   text_ref  = SysMalloc( SEGMENT_SIZE );
957   *text_ref = '\0';
958 
959   lst_status = LstLinkCurrentFirst( entries );
960 
961   /* Create the summary text. */
962   while( lst_status == LST_OK ) {
963 
964     int                   append_size;
965     int                   extend_size;
966     char                  buffer[ 100 ];
967     char                  entry_buffer[ 1000 ];
968     char                  *entry_text;
969     char                  *tmp_ref;
970     XTM_DB_ALL_ENTRY_DEF  entry_record;
971 
972     lst_status = LstLinkGetCurrent( entries, &entry_record );
973 
974     /* Skip this entry? */
975     if( flagIsSet( entry_record.entry.flags, XTM_DB_FLAG_HIDE_IN_SUMMARY ) ) {
976       lst_status = LstLinkCurrentNext( entries );
977       continue;
978     }
979 
980     /* Start to build the entry. */
981     strcpy( entry_buffer, "\n" );
982 
983     /* New date? */
984     if( entry_record.entry.date_stamp != last_date ) {
985       TimFormatStrTime( entry_record.entry.date_stamp, "%d %B %Y, %A\n \n",
986                         buffer, sizeof( buffer ) );
987       if( buffer[ 0 ] == '0' )
988         buffer[ 0 ] = ' ';
989 
990       strcat( entry_buffer, "-------------------------------------------" );
991       strcat( entry_buffer, "-------------------------------------------\n" );
992       strcat( entry_buffer, buffer );
993 
994       last_date = entry_record.entry.date_stamp;
995     }
996 
997     /* Time for the entry. */
998     if( entry_record.entry.entry_type != XTM_DB_DAY_NOTE ) {
999       xtmFoFormatEntryTimes( &entry_record, buffer, sizeof( buffer ) );
1000 
1001       strcat( entry_buffer, buffer );
1002       strcat( entry_buffer, " " );
1003     }
1004 
1005     /* Flags for the entry. */
1006     xtmFoFormatEntryFlags( appl_data_ref -> custom_data, &entry_record,
1007                            buffer, sizeof( buffer ) );
1008 
1009     if( strlen( buffer ) > 0 &&
1010         flagIsSet( show_ref -> flags, ENTRY_FLAGS ) ) {
1011       strcat( entry_buffer, buffer );
1012       strcat( entry_buffer, " " );
1013     }
1014 
1015     /* Included database? */
1016     if( flagIsSet( entry_record.entry.flags, XTM_DB_FLAG_INCLUDE ) ) {
1017       sprintf( buffer, "(%s) ", entry_record.db_name );
1018       strcat( entry_buffer, buffer );
1019     }
1020 
1021     if( entry_record.entry.entry_type != XTM_DB_DAY_NOTE )
1022       strcat( entry_buffer, "\n" );
1023 
1024     /* Format entry text. */
1025     if( entry_record.all_text != NULL )
1026       tmp_ref = entry_record.all_text;
1027     else
1028       tmp_ref = entry_record.entry.text;
1029 
1030     if( entry_record.entry.entry_type == XTM_DB_DAY_NOTE )
1031       entry_text = xtmFoFormatText( tmp_ref, 0, display_lines, 80 );
1032     else
1033       entry_text = xtmFoFormatText( tmp_ref, 2, display_lines, 80 );
1034 
1035     /* Append entry information and text. */
1036     append_size = strlen( entry_buffer );
1037 
1038     if( entry_text != NULL )
1039       append_size = append_size + strlen( entry_text );
1040 
1041     /* Allocate space. */
1042     append_size = append_size + 10;
1043 
1044     if( strlen( text_ref ) + append_size > text_size ) {
1045       extend_size = max( append_size, SEGMENT_SIZE );
1046 
1047       text_size = text_size + extend_size;
1048       text_ref  = SysRealloc( text_ref, text_size );
1049     }
1050 
1051     /* Append the entry information and entry text. */
1052     strcat( text_ref, entry_buffer );
1053 
1054     if( entry_text != NULL ) {
1055       strcat( text_ref, entry_text );
1056 
1057       SysFree( entry_text );
1058     }
1059 
1060     strcat( text_ref, "\n " );
1061 
1062     /* Fetch the next entry. */
1063     lst_status = LstLinkCurrentNext( entries );
1064 
1065   } /* while */
1066 
1067 
1068   /* Set the text. */
1069   tempW = XtNameToWidget( mainW, "TextSw.ClipWindow.TextLa" );
1070 
1071   xitStringSetLabel( tempW, text_ref );
1072 
1073 
1074   /* Clear allocated data. */
1075   xtmDmDeleteEntriesList( entries );
1076 
1077   SysFree( text_ref );
1078 
1079 
1080   return;
1081 
1082 } /* applyCB */
1083 
1084 
1085 /*----------------------------------------------------------------------*/
1086 
1087 static void
calChangedCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)1088   calChangedCB( Widget        widget,
1089                 SHOW_REC_REF  show_ref,
1090                 XtPointer     call_data )
1091 {
1092 
1093   /* Variables. */
1094   char                    *cal_name;
1095   Widget                  mainW;
1096   Widget                  tempW;
1097   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1098   XTM_CD_CAL_INFO         db_info;
1099 
1100 
1101   /* Code. */
1102 
1103   custom_data_ref = show_ref -> appl_data_ref -> custom_data;
1104   mainW = XtNameToWidget( show_ref -> showW, "ShowTlBase.ShowTlFo" );
1105 
1106 
1107   /* Calendar we are using. */
1108   (void) xtmCdFetchNamedDb( custom_data_ref -> cal_db_handle,
1109                             show_ref -> db_name,
1110                             &db_info, NULL );
1111 
1112 
1113   /* Fetch the new database. */
1114   tempW = XtNameToWidget( mainW, "CalRc.CalFs" );
1115   xitFieldSelectGetCurrent( tempW, &cal_name );
1116 
1117 
1118   /* If the calendar is the same as before, just return. */
1119   if( strcmp( cal_name, db_info.short_name ) == 0 ) {
1120     SysFree( cal_name );
1121     return;
1122   }
1123 
1124 
1125   /* Remove the shadow entry and make a new one. */
1126   xtmCdFreeShadowEntry( custom_data_ref -> cal_db_handle,
1127                         show_ref -> db_name );
1128 
1129   (void) xtmCdCreateShadowEntry( custom_data_ref -> cal_db_handle,
1130                                  cal_name, show_ref -> db_name );
1131 
1132   SysFree( cal_name );
1133 
1134 
1135   return;
1136 
1137 } /* calChangedCB */
1138 
1139 
1140 /*----------------------------------------------------------------------*/
1141 
1142 static void
closeCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)1143   closeCB( Widget        widget,
1144            SHOW_REC_REF  show_ref,
1145            XtPointer     call_data )
1146 {
1147 
1148   /* Variables. */
1149   int  index;
1150 
1151 
1152   /* Code. */
1153 
1154   /* Keep the window in cache? */
1155   for( index = 0; index < MAX_CACHE_ENTRIES; index++ ) {
1156     if( cache_entries[ index ] == NULL ) {
1157       cache_entries[ index ] = show_ref;
1158 
1159       destroyCB( NULL, show_ref, NULL );
1160       XtPopdown( show_ref -> showW );
1161 
1162       return;
1163     }
1164   }
1165 
1166   /* Window not kept in cache, really remove it. */
1167   XtDestroyWidget( show_ref -> showW );
1168 
1169 
1170   return;
1171 
1172 } /* closeCB */
1173 
1174 
1175 /*----------------------------------------------------------------------*/
1176 
1177 static void
ctrlMenuCB(Widget widget,SHOW_REC_REF show_ref,XmRowColumnCallbackStruct * call_data)1178   ctrlMenuCB( Widget                     widget,
1179               SHOW_REC_REF               show_ref,
1180               XmRowColumnCallbackStruct  *call_data )
1181 {
1182 
1183   /* Variables. */
1184   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1185 
1186 
1187   /* Code. */
1188 
1189   custom_data_ref = show_ref -> appl_data_ref -> custom_data;
1190 
1191   /* Select what to do. */
1192   switch( (intptr_t) call_data -> data ) {
1193 
1194     /* Display entry flags? */
1195     case 0:
1196       if( XmToggleButtonGetState( call_data -> widget ) )
1197         flagSet( show_ref -> flags, ENTRY_FLAGS );
1198       else
1199         flagClear( show_ref -> flags, ENTRY_FLAGS );
1200 
1201       /* Display again... */
1202       applyCB( show_ref -> showW, show_ref, NULL );
1203       break;
1204 
1205 
1206     /* Filter window. */
1207     case 2:
1208       filterCB( widget, show_ref, NULL );
1209       break;
1210 
1211 
1212     /* Include calendars. */
1213     case 3:
1214       if( show_ref -> include_handle == NULL )
1215         show_ref -> include_handle = xtmDiInitialize(
1216                                        show_ref -> appl_data_ref,
1217                                        show_ref -> showW,
1218                                        False,
1219                                        includeDbApplyCB, (void *) show_ref );
1220 
1221       /* Display the include window. */
1222       xtmDiDisplayIncludeWindow( show_ref -> include_handle,
1223                                  show_ref -> db_name );
1224       break;
1225 
1226   } /* switch */
1227 
1228 
1229   return;
1230 
1231 } /* ctrlMenuCB */
1232 
1233 
1234 /*----------------------------------------------------------------------*/
1235 
1236 static void
destroyCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)1237   destroyCB( Widget        widget,
1238              SHOW_REC_REF  show_ref,
1239              XtPointer     call_data )
1240 {
1241 
1242   /* Variables. */
1243   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1244 
1245 
1246   /* Code. */
1247 
1248   custom_data_ref = show_ref -> appl_data_ref -> custom_data;
1249 
1250 
1251   /* Do we have a user action callback registered? */
1252   if( show_ref -> actionCB != NULL )
1253     (* show_ref -> actionCB)( XTM_SD_REASON_DESTROY, show_ref -> user_data );
1254 
1255 
1256   /* Destroy child windows. */
1257   if( show_ref -> filter_handle != NULL ) {
1258     xtmFiDestroy( show_ref -> filter_handle );
1259     show_ref -> filter_handle = NULL;
1260   }
1261 
1262   if( show_ref -> include_handle != NULL ) {
1263     xtmDiDestroy( show_ref -> include_handle );
1264     show_ref -> include_handle = NULL;
1265   }
1266 
1267   if( show_ref -> pr_handle != NULL ) {
1268     xtmPrDestroy( show_ref -> pr_handle );
1269     show_ref -> pr_handle = NULL;
1270   }
1271 
1272 
1273   /* Release the user data. */
1274   xtmCdFreeShadowEntry( custom_data_ref -> cal_db_handle,
1275                         show_ref -> db_name );
1276 
1277 
1278   /* Release the user data (only if not cached). */
1279   if( widget != NULL )
1280     SysFree( show_ref );
1281 
1282 
1283   return;
1284 
1285 } /* destroyCB */
1286 
1287 
1288 /*----------------------------------------------------------------------*/
1289 
1290 static void
filterApplyCB(XTM_FI_REASON reason,XTM_DM_FILTER_REC * filter_ref,void * user_data)1291   filterApplyCB( XTM_FI_REASON      reason,
1292                  XTM_DM_FILTER_REC  *filter_ref,
1293                  void               *user_data )
1294 {
1295 
1296   /* Variables. */
1297   SHOW_REC_REF  show_ref;
1298 
1299 
1300   /* Code. */
1301 
1302   if( reason != XTM_FI_REASON_APPLY && reason != XTM_FI_REASON_OK )
1303     return;
1304 
1305   show_ref = (SHOW_REC_REF) user_data;
1306 
1307   /* Save the filter. */
1308   memcpy( (void *) &show_ref -> filter_rec,
1309           (void *) filter_ref,
1310           sizeof( XTM_DM_FILTER_REC ) );
1311 
1312 
1313   /* Search again... */
1314   applyCB( show_ref -> showW, show_ref, NULL );
1315 
1316 
1317   return;
1318 
1319 } /* filterApplyCB */
1320 
1321 
1322 /*----------------------------------------------------------------------*/
1323 
1324 static void
filterCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)1325   filterCB( Widget        widget,
1326             SHOW_REC_REF  show_ref,
1327             XtPointer     call_data )
1328 {
1329 
1330   /* Code. */
1331 
1332   /* Initialize the filter? */
1333   if( show_ref -> filter_handle == NULL )
1334     show_ref -> filter_handle = xtmFiInitialize(
1335                                   show_ref -> appl_data_ref,
1336                                   show_ref -> showW,
1337                                   show_ref -> search_tags,
1338                                   False,
1339                                   filterApplyCB, (void *) show_ref );
1340 
1341   /* Display the filter window. */
1342   xtmFiDisplayFilterWindow( show_ref  -> filter_handle,
1343                             &show_ref -> filter_rec );
1344 
1345 
1346   return;
1347 
1348 } /* filterCB */
1349 
1350 
1351 /*----------------------------------------------------------------------*/
1352 
1353 static void
includeDbApplyCB(XTM_DI_REASON reason,XTM_CD_INCL_CALS_REF new_db_incl_ref,void * user_data)1354   includeDbApplyCB( XTM_DI_REASON         reason,
1355                     XTM_CD_INCL_CALS_REF  new_db_incl_ref,
1356                     void                  *user_data )
1357 {
1358 
1359   /* Variables. */
1360   SHOW_REC_REF            show_ref;
1361   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1362   XTM_CD_CAL_INFO         db_info;
1363   XTM_CD_INCL_CALS        db_incl;
1364 
1365 
1366   /* Code. */
1367 
1368   if( reason != XTM_DI_REASON_APPLY && reason != XTM_DI_REASON_OK )
1369     return;
1370 
1371   show_ref        = (SHOW_REC_REF) user_data;
1372   custom_data_ref = show_ref -> appl_data_ref -> custom_data;
1373 
1374 
1375   /* Fetch the current database. */
1376   (void) xtmCdFetchNamedDb( custom_data_ref -> cal_db_handle,
1377                             show_ref -> db_name,
1378                             &db_info, &db_incl );
1379 
1380   /* Save the new include data. */
1381   (void) xtmCdChangeEntry( custom_data_ref -> cal_db_handle,
1382                            show_ref -> db_name,
1383                            &db_info, new_db_incl_ref );
1384 
1385   /* Search again... */
1386   applyCB( show_ref -> showW, show_ref, NULL );
1387 
1388 
1389   return;
1390 
1391 } /* includeDbApplyCB */
1392 
1393 
1394 /*----------------------------------------------------------------------*/
1395 
1396 static void
infoCB(Widget widget,SHOW_REC_REF show_ref,XmRowColumnCallbackStruct * call_data)1397   infoCB( Widget                     widget,
1398           SHOW_REC_REF               show_ref,
1399           XmRowColumnCallbackStruct  *call_data )
1400 {
1401 
1402   /* Code. */
1403 
1404   xtmHlDisplayHelp( show_ref -> appl_data_ref -> info_handle,
1405                     (intptr_t) call_data -> data,
1406                     sum_window_id, "" );
1407 
1408   return;
1409 
1410 } /* infoCB */
1411 
1412 
1413 /*----------------------------------------------------------------------*/
1414 
1415 void
mapCtrlMenuCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)1416   mapCtrlMenuCB( Widget        widget,
1417                  SHOW_REC_REF  show_ref,
1418                  XtPointer     call_data )
1419 {
1420 
1421   /* Variables. */
1422   Widget  tempW;
1423 
1424 
1425   /* Code. */
1426 
1427   /* Display entry flags? */
1428   tempW = XtNameToWidget( widget, "EntryFlagsBu" );
1429   if( flagIsSet( show_ref -> flags, ENTRY_FLAGS ) )
1430     XmToggleButtonSetState( tempW, True, False );
1431   else
1432     XmToggleButtonSetState( tempW, False, False );
1433 
1434 
1435   return;
1436 
1437 } /* mapCtrlMenu */
1438 
1439 
1440 /*----------------------------------------------------------------------*/
1441 
1442 static void
printCB(Widget widget,SHOW_REC_REF show_ref,XtPointer call_data)1443   printCB( Widget        widget,
1444            SHOW_REC_REF  show_ref,
1445            XtPointer     call_data )
1446 {
1447 
1448   /* Variables. */
1449   Boolean               ok;
1450   int                   display_lines;
1451   int                   items;
1452   char                  *char_ref;
1453   Widget                mainW;
1454   Widget                tempW;
1455   TIM_TIME_REF          from_date;
1456   TIM_TIME_REF          to_date;
1457   XTM_GL_BASE_DATA_REF  appl_data_ref;
1458 
1459 
1460   /* Code. */
1461 
1462   appl_data_ref = show_ref -> appl_data_ref;
1463 
1464   mainW = XtNameToWidget( show_ref -> showW, "ShowTlBase.ShowTlFo" );
1465 
1466 
1467   /* Fetch the date range. */
1468   tempW = XtNameToWidget( mainW, "ShDayRc.RangeTb" );
1469 
1470   ok = xtmFoFetchDate( mainW, tempW, XTM_FO_START_DATE, False, &from_date );
1471   if( ! ok )
1472     return;
1473 
1474   ok = xtmFoFetchDate( mainW, tempW, XTM_FO_END_DATE, False, &to_date );
1475   if( ! ok )
1476     return;
1477 
1478   if( from_date > to_date ) {
1479     xitErMessage( show_ref -> showW, XIT_ER_ERROR,
1480                   module_name, "printCB",
1481                   msgGetText( MXDI_INVALID_DATE_RANGE ) );
1482     return;
1483   }
1484 
1485 
1486   /* Number of lines to display? */
1487   tempW    = XtNameToWidget( mainW, "ShLineRc.ShLineTx" );
1488   char_ref = xitStringGetText( tempW );
1489 
1490   items = sscanf( char_ref, "%d", &display_lines );
1491   if( items != 1 || display_lines < 0 )
1492     display_lines = 0;
1493 
1494   SysFree( char_ref );
1495 
1496 
1497   /* Create the printer window. */
1498   if( show_ref -> pr_handle == NULL ) {
1499     show_ref -> pr_handle = xtmPrInitialize(
1500                               appl_data_ref,
1501                               appl_data_ref -> toplevel,
1502                               show_ref -> db_name,
1503                               NULL, NULL );
1504 
1505     if( show_ref -> pr_handle == NULL )
1506       return;
1507   }
1508 
1509   /* Display the printer window. */
1510   xtmPrDisplayPrinter( show_ref -> pr_handle,
1511                        from_date, to_date,
1512                        display_lines,
1513                        &show_ref -> filter_rec );
1514 
1515   /* Inherit the calendar settings. */
1516   xtmPrSetCalendar( show_ref -> pr_handle, show_ref -> db_name );
1517 
1518 
1519   return;
1520 
1521 } /* printCB */
1522