1 /*----------------------------------------------------------------------------
2 --
3 --  Module:           xtmEditEntry
4 --
5 --  Project:          Xdiary
6 --  System:           xtm - X Desktop Calendar
7 --    Subsystem:      <>
8 --    Function block: <>
9 --
10 --  Description:
11 --    Create and edit a singe time entry.
12 --
13 --  Filename:         xtmEditEntry.c
14 --
15 --  Authors:          Roger Larsson, Ulrika Bornetun
16 --  Creation date:    1990-12-18
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: xtmEditEntry.c, Version: 1.1, Date: 95/02/18 15:52:15";
32 
33 
34 /*----------------------------------------------------------------------------
35 --  Include files
36 ----------------------------------------------------------------------------*/
37 
38 #include <string.h>
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <sys/types.h>
42 #include <sys/signal.h>
43 #include <sys/stat.h>
44 #include <fcntl.h>
45 #include <unistd.h>
46 #include <ctype.h>
47 
48 #include <X11/Intrinsic.h>
49 #include <X11/Shell.h>
50 
51 #include <Xm/Protocols.h>
52 
53 #include <Xm/Xm.h>
54 #include <Xm/BulletinB.h>
55 #include <Xm/Form.h>
56 #include <Xm/Frame.h>
57 #include <Xm/RowColumn.h>
58 #include <Xm/ScrolledW.h>
59 #include <Xm/SeparatoG.h>
60 #include <Xm/Text.h>
61 #include <Xm/ToggleB.h>
62 
63 #include "System.h"
64 #include "LstLinked.h"
65 #include "Message.h"
66 #include "SigHandler.h"
67 #include "TimDate.h"
68 
69 #include "msgXdiary.h"
70 #include "xtmGlobal.h"
71 #include "xtmCalDb.h"
72 #include "xtmCustBase.h"
73 #include "xtmDbMisc.h"
74 #include "xtmDbTools.h"
75 #include "xtmEditAlarm.h"
76 #include "xtmEditPref.h"
77 #include "xtmEditSkip.h"
78 #include "xtmEditStand.h"
79 #include "xtmFields.h"
80 #include "xtmFormat.h"
81 #include "xtmHelp.h"
82 #include "xtmIcons.h"
83 #include "xtmSchedMain.h"
84 #include "xtmTools.h"
85 #include "xtmUpdate.h"
86 #include "xitColorSel.h"
87 #include "xitError.h"
88 #include "xitFieldSel.h"
89 #include "xitTools.h"
90 #include "xitTune.h"
91 #include "XmUbTimeB.h"
92 #include "xtmEditEntry.h"
93 
94 
95 /*----------------------------------------------------------------------------
96 --  Macro definitions
97 ----------------------------------------------------------------------------*/
98 
99 /* Editors in the cache? */
100 #define  MAX_CACHE_ENTRIES   3
101 
102 /* File protection. */
103 #define  MODE_600   (S_IRUSR | S_IWUSR)
104 
105 /* Action on entry/repeated entry part? */
106 #define  SET_ALL_ENTRY       (1<<0)
107 #define  SET_ENTRY           (1<<1)
108 #define  SET_REPEATED_ENTRY  (1<<2)
109 
110 
111 /* Local widgets in the entry edit window. */
112 #define actionRc            dataLocalW[  0 ]
113 #define alarmPb             dataLocalW[  1 ]
114 #define dataEntFo           dataLocalW[  2 ]
115 #define databaseFs          dataLocalW[  3 ]
116 #define databaseLa          dataLocalW[  4 ]
117 #define dateEntTb           dataLocalW[  5 ]
118 #define dateEntLa           dataLocalW[  6 ]
119 #define dayViewPb           dataLocalW[  7 ]
120 #define dummy1Pb            dataLocalW[  8 ]
121 #define durEntFs            dataLocalW[  9 ]
122 #define durEntLa            dataLocalW[ 10 ]
123 #define editorPb            dataLocalW[ 11 ]
124 #define entryDateLa         dataLocalW[ 12 ]
125 #define entryTagFs          dataLocalW[ 13 ]
126 #define entryTagLa          dataLocalW[ 14 ]
127 #define menuBr              dataLocalW[ 15 ]
128 #define miscFo              dataLocalW[ 16 ]
129 #define miscRc              dataLocalW[ 17 ]
130 #define prefPb              dataLocalW[ 18 ]
131 #define selAlarmBu          dataLocalW[ 19 ]
132 #define selFo               dataLocalW[ 20 ]
133 #define selFr               dataLocalW[ 21 ]
134 #define selImpBu            dataLocalW[ 22 ]
135 #define selNoteDoneBu       dataLocalW[ 23 ]
136 #define selPrivateBu        dataLocalW[ 24 ]
137 #define standPb             dataLocalW[ 25 ]
138 #define startEntTb          dataLocalW[ 26 ]
139 #define startEntLa          dataLocalW[ 27 ]
140 #define textEntLa           dataLocalW[ 28 ]
141 #define textEntTx           dataLocalW[ 29 ]
142 #define timeEntFr           dataLocalW[ 30 ]
143 #define timeEntRc           dataLocalW[ 31 ]
144 #define typeAppTb           dataLocalW[ 32 ]
145 #define typeNoteTb          dataLocalW[ 33 ]
146 #define typeRb              dataLocalW[ 34 ]
147 #define typeStandAppTb      dataLocalW[ 35 ]
148 #define typeStandNoteTb     dataLocalW[ 36 ]
149 #define typeStickyNoteTb    dataLocalW[ 37 ]
150 
151 
152 /*----------------------------------------------------------------------------
153 --  Type declarations
154 ----------------------------------------------------------------------------*/
155 
156 /* Times for an entry. */
157 typedef struct {
158   TIM_TIME_REF  date;
159   TIM_TIME_REF  start_time;
160   TIM_TIME_REF  end_time;
161   int           duration;
162 } ENTRY_TIMES_REC, *ENTRY_TIMES_REF;
163 
164 /* Record describing one instance of the appointment editor. */
165 typedef struct {
166 
167   /* New entry to edit? */
168   Boolean  new_entry;
169 
170   /* Did we see the standing window? */
171   Boolean  standing_seen;
172 
173   /* Default duration to use. */
174   int  default_duration;
175 
176   /* Limits used as suggestions. */
177   int  earliest_hour;
178   int  latest_hour;
179   int  min_delta;
180 
181   /* Process id for the editor. */
182   int  editor_pid;
183 
184   /* Signal id to use. */
185   int  signal_id;
186 
187   /* Temp file name. */
188   char  *temp_file;
189 
190   /* Editor window. */
191   Widget  editorW;
192 
193   /* File selection window. */
194   Widget  fileSelectW;
195 
196   /* Default date and time to use. */
197   TIM_TIME_REF  default_date;
198   TIM_TIME_REF  default_time;
199 
200   /* Entry being edited. */
201   XTM_DB_ALL_ENTRY_REF  edit_entry_ref;
202 
203   /* The type of entry we are editing just now. */
204   XTM_DB_ALL_ENTRY_TYPES  entry_type;
205 
206   /* The alarm window. */
207   XTM_EA_HANDLE  alarm_handle;
208 
209   /* The preferences window. */
210   XTM_EP_HANDLE  pref_handle;
211 
212   /* The standing window. */
213   XTM_ES_HANDLE  stand_handle;
214 
215   /* Application wide data. */
216   XTM_GL_BASE_DATA_REF  appl_data_ref;
217 
218   /* Callback and user data to inform our creator of specific actions. */
219   XTM_ED_ACTION_CB  actionCB;
220   void              *user_data;
221 
222 } EDITOR_REC, *EDITOR_REC_REF;
223 
224 
225 /*----------------------------------------------------------------------------
226 --  Global definitions
227 ----------------------------------------------------------------------------*/
228 
229 /* Name of module. */
230 static char  *module_name = "xtmEditEntry";
231 
232 /* IDs for the help windows. */
233 static char  *edit_window_id = "EntryEdit";
234 
235 /* Cache entries. */
236 static Boolean        init_cache = True;
237 static EDITOR_REC_REF  cache_entries[ MAX_CACHE_ENTRIES ];
238 
239 
240 /*----------------------------------------------------------------------------
241 --  Function prototypes
242 ----------------------------------------------------------------------------*/
243 
244 static void
245   alarmCB( Widget          widget,
246            EDITOR_REC_REF  editor_ref,
247            XtPointer       call_data );
248 
249 static void
250   alarmActionCB( XTM_EA_REASON          reason,
251                  void                   *user_data,
252                  XTM_EA_GET_ALARM_DATA  *values );
253 
254 static void
255   applyCB( Widget          widget,
256            EDITOR_REC_REF  editor_ref,
257            XtPointer       call_data );
258 
259 static void
260   cancelCB( Widget          widget,
261             EDITOR_REC_REF  editor_ref,
262             XtPointer       call_data );
263 
264 static Widget
265   createEditWindow( Widget          parent,
266                     EDITOR_REC_REF  editor_ref );
267 
268 static void
269   dayViewCB( Widget          widget,
270              EDITOR_REC_REF  editor_ref,
271              XtPointer       call_data );
272 
273 static void
274   dbChangedCB( Widget          widget,
275                EDITOR_REC_REF  editor_ref,
276                XtPointer       call_data );
277 
278 static void
279   destroyCB( Widget          widget,
280              EDITOR_REC_REF  editor_ref,
281              XtPointer       call_data );
282 
283 static void
284   editorCB( Widget          widget,
285             EDITOR_REC_REF  editor_ref,
286             XtPointer       call_data );
287 
288 static void
289   entryTypeCB( Widget                        widget,
290                EDITOR_REC_REF                editor_ref,
291                XmToggleButtonCallbackStruct  *call_data );
292 
293 static Boolean
294   fetchEntryTimes( EDITOR_REC_REF   editor_ref,
295                    Widget           parentW,
296                    ENTRY_TIMES_REF  entry_times );
297 
298 static Boolean
299   fetchEntryValues( EDITOR_REC_REF        editor_ref,
300                     XTM_DB_ALL_ENTRY_REF  entry_ref,
301                     char                  **entry_text );
302 
303 static void
304   helpCB( Widget                     widget,
305           EDITOR_REC_REF             editor_ref,
306           XmRowColumnCallbackStruct  *call_data );
307 
308 static void
309   includeFileCB( Widget          widget,
310                  EDITOR_REC_REF  editor_ref,
311                  XtPointer       call_data );
312 
313 static void
314   includeFileActionCB( XIT_FILE_SEL_REASON  reason,
315                        char                 *file_name,
316                        void                 *user_data );
317 
318 static void
319   insertEditedFile( EDITOR_REC_REF  editor_ref );
320 
321 static void
322   okCB( Widget          widget,
323         EDITOR_REC_REF  editor_ref,
324         XtPointer       call_data );
325 
326 static void
327   preferencesCB( Widget          widget,
328                  EDITOR_REC_REF  editor_ref,
329                  XtPointer       call_data );
330 
331 static void
332   preferencesActionCB( XTM_EP_REASON         reason,
333                        void                  *user_data,
334                        XTM_EP_GET_PREF_DATA  *values );
335 
336 static Boolean
337   readEntryToEdit( EDITOR_REC_REF  editor_ref,
338                    char            *db_name,
339                    UINT32          entry_id,
340                    Widget          parent );
341 
342 static void
343   removeEditFile( EDITOR_REC_REF  editor_ref );
344 
345 static Boolean
346   saveEntry( EDITOR_REC_REF  editor_ref );
347 
348 
349 static void
350   setEntryValues( EDITOR_REC_REF        editor_ref,
351                   XTM_DB_ALL_ENTRY_REF  entry_ref );
352 
353 static XTM_DB_STATUS
354   setEntryDefault( XTM_GL_BASE_DATA_REF  appl_data_ref,
355                    XTM_DB_ALL_ENTRY_REF  entry_ref,
356                    UINT32                set_parts,
357                    TIM_TIME_REF          entry_date,
358                    TIM_TIME_REF          entry_time,
359                    int                   entry_duration );
360 
361 static void
362   standingCB( Widget          widget,
363               EDITOR_REC_REF  editor_ref,
364               XtPointer       call_data );
365 
366 static void
367   standingActionCB( XTM_ES_REASON          reason,
368                     void                   *user_data,
369                     XTM_ES_GET_STAND_DATA  *values );
370 
371 static void
372   timeFieldChangedCB( Widget          widget,
373                       EDITOR_REC_REF  editor_ref,
374                       XtPointer       call_data );
375 
376 static void
377   updateCanDo( EDITOR_REC_REF editor_ref );
378 
379 static void
380   userEditorDoneCB( int   signal,
381                     void  *user_data );
382 
383 static Boolean
384   writeEditedEntry( XTM_GL_BASE_DATA_REF  appl_data_ref,
385                     Widget                parent,
386                     XTM_DB_ALL_ENTRY_REF  old_entry_ref,
387                     XTM_DB_ALL_ENTRY_REF  new_entry_ref );
388 
389 static void
390   writeEntryDate( EDITOR_REC_REF editor_ref );
391 
392 
393 
394 /*----------------------------------------------------------------------------
395 --  Functions
396 ----------------------------------------------------------------------------*/
397 
398 XTM_ED_HANDLE
xtmEdInitialize(XTM_GL_BASE_DATA_REF appl_data_ref,Widget parent,int default_duration,int earliest_hour,int latest_hour,int min_delta,XTM_ED_ACTION_CB actionCB,void * user_data)399   xtmEdInitialize( XTM_GL_BASE_DATA_REF  appl_data_ref,
400                    Widget                parent,
401                    int                   default_duration,
402                    int                   earliest_hour,
403                    int                   latest_hour,
404                    int                   min_delta,
405                    XTM_ED_ACTION_CB      actionCB,
406                    void                  *user_data )
407 {
408 
409   /* Variables. */
410   int             index;
411   EDITOR_REC_REF  editor_ref;
412 
413 
414   /* Code. */
415 
416   /* Initialize the cache? */
417   if( init_cache ) {
418     for( index = 0; index < MAX_CACHE_ENTRIES; index++ )
419       cache_entries[ index ] = NULL;
420 
421     init_cache = False;
422   }
423 
424 
425   /* Anything in the cache? */
426   editor_ref = NULL;
427 
428   for( index = 0; index < MAX_CACHE_ENTRIES; index++ ) {
429     if( cache_entries[ index ] != NULL ) {
430       editor_ref = cache_entries[ index ];
431       cache_entries[ index ] = NULL;
432 
433       break;
434     }
435   }
436 
437 
438   /* Create the editor record? */
439   if( editor_ref == NULL ) {
440 
441     editor_ref = SysNew( EDITOR_REC );
442     if( editor_ref == NULL )
443       return( NULL );
444 
445     editor_ref -> editorW = NULL;
446 
447   } /* if */
448 
449 
450   editor_ref -> appl_data_ref      = appl_data_ref;
451   editor_ref -> edit_entry_ref     = NULL;
452   editor_ref -> default_duration   = default_duration;
453   editor_ref -> earliest_hour      = earliest_hour;
454   editor_ref -> latest_hour        = latest_hour;
455   editor_ref -> min_delta          = min_delta;
456   editor_ref -> actionCB           = actionCB;
457   editor_ref -> user_data          = user_data;
458   editor_ref -> temp_file          = NULL;
459   editor_ref -> fileSelectW        = NULL;
460   editor_ref -> alarm_handle       = NULL;
461   editor_ref -> pref_handle        = NULL;
462   editor_ref -> stand_handle       = NULL;
463   editor_ref -> editor_pid         = 0;
464   editor_ref -> signal_id          = 0;
465 
466 
467   /* Create the base editor window. */
468   if( editor_ref -> editorW == NULL ) {
469 
470     editor_ref -> editorW = createEditWindow( parent, editor_ref );
471     if( editor_ref -> editorW == NULL ) {
472       SysFree( editor_ref );
473 
474       return( NULL );
475     }
476 
477   } /* if */
478 
479 
480   return( (XTM_ED_HANDLE) editor_ref );
481 
482 } /* xtmEdInitialize */
483 
484 
485 /*----------------------------------------------------------------------*/
486 
487 void
xtmEdEmptyCache()488   xtmEdEmptyCache()
489 {
490 
491   /* Variables. */
492   int  index;
493 
494 
495   /* Code. */
496 
497   if( ! init_cache )
498     return;
499 
500   for( index = 0; index < MAX_CACHE_ENTRIES; index++ ) {
501     if( cache_entries[ index ] != NULL )
502       XtDestroyWidget( cache_entries[ index ] -> editorW );
503 
504     cache_entries[ index ] = NULL;
505   }
506 
507 
508   return;
509 
510 } /* xtmEdEmptyCache */
511 
512 
513 /*----------------------------------------------------------------------*/
514 
515 void
xtmEdDestroy(XTM_ED_HANDLE editor_handle)516   xtmEdDestroy( XTM_ED_HANDLE  editor_handle )
517 {
518 
519   /* Variables. */
520   EDITOR_REC_REF  editor_ref;
521 
522 
523   /* Code. */
524 
525   if( editor_handle == NULL )
526     return;
527 
528   /* Our private data. */
529   editor_ref = (EDITOR_REC_REF) editor_handle;
530 
531   /* Get rid of all windows. */
532   if( editor_ref -> editorW != NULL )
533     cancelCB( NULL, editor_ref, NULL );
534 
535 
536   return;
537 
538 } /* xtmEdDestroy */
539 
540 
541 /*----------------------------------------------------------------------*/
542 
543 void
xtmEdEditEntry(XTM_ED_HANDLE editor_handle,char * db_name,UINT32 entry_id,TIM_TIME_REF use_date,TIM_TIME_REF use_time)544   xtmEdEditEntry( XTM_ED_HANDLE  editor_handle,
545                   char           *db_name,
546                   UINT32         entry_id,
547                   TIM_TIME_REF   use_date,
548                   TIM_TIME_REF   use_time )
549 {
550 
551   /* Variables. */
552   Boolean         ok;
553   Widget          mainW;
554   Widget          tempW;
555   EDITOR_REC_REF  editor_ref;
556 
557 
558   /* Code. */
559 
560   /* Our private data. */
561   editor_ref = (EDITOR_REC_REF) editor_handle;
562 
563   editor_ref -> default_date = use_date;
564   editor_ref -> default_time = use_time;
565 
566   mainW = XtNameToWidget( editor_ref -> editorW,
567                           "ApEditorTlBase.ApEditorTlFo" );
568 
569 
570   /* Read the entry. */
571   ok = readEntryToEdit( editor_ref,
572                         db_name, entry_id, editor_ref -> editorW );
573 
574 
575   /* Make sure the editor window is visable. */
576   XtPopup( editor_ref -> editorW, XtGrabNone );
577 
578   XRaiseWindow( XtDisplay( editor_ref -> editorW ),
579                 XtWindow(  editor_ref -> editorW ) );
580 
581   XtMapWidget( editor_ref -> editorW );
582 
583 
584   /* Set values for our windows. */
585   setEntryValues( editor_ref, editor_ref -> edit_entry_ref );
586 
587 
588   /* Start at the text field. */
589   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
590   xitGrabFocus( tempW );
591 
592 
593   return;
594 
595 } /* xtmEdEditEntry */
596 
597 
598 /*----------------------------------------------------------------------*/
599 
600 void
xtmEdSetValues(XTM_ED_HANDLE editor_handle,UINT32 flags,TIM_TIME_REF use_date,TIM_TIME_REF use_time,UINT32 duration,char * text)601   xtmEdSetValues( XTM_ED_HANDLE  editor_handle,
602                   UINT32         flags,
603                   TIM_TIME_REF   use_date,
604                   TIM_TIME_REF   use_time,
605                   UINT32         duration,
606                   char           *text )
607 {
608 
609   /* Variables. */
610   char                  buffer[ 50 ];
611   Widget                baseW;
612   Widget                mainW;
613   Widget                tempW;
614   EDITOR_REC_REF        editor_ref;
615   XTM_GL_BASE_DATA_REF  appl_data_ref;
616 
617 
618   /* Code. */
619 
620   /* Our private data. */
621   editor_ref    = (EDITOR_REC_REF) editor_handle;
622   appl_data_ref = editor_ref -> appl_data_ref;
623 
624   mainW = XtNameToWidget( editor_ref -> editorW,
625                           "ApEditorTlBase.ApEditorTlFo" );
626 
627 
628   /* Entry is a note. */
629   if( flagIsSet( flags, XTM_ED_SET_IS_NOTE ) ) {
630     baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TypeRb" );
631     tempW = XtNameToWidget( baseW, "TypeNoteTb" );
632 
633     XmToggleButtonSetState( tempW, True, True );
634 
635     baseW = XtNameToWidget( mainW, "SelFr.SelFo" );
636     tempW = XtNameToWidget( baseW, "SelAlarmBu" );
637 
638     XmToggleButtonSetState( tempW, False, False );
639   }
640 
641 
642   /* Date for the entry. */
643   if( flagIsSet( flags, XTM_ED_SET_DATE ) ) {
644     baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
645     tempW = XtNameToWidget( baseW, "DateEntTb" );
646 
647     XmUbTimeBoxSetStartDate( tempW, use_date );
648 
649     if( editor_ref -> edit_entry_ref != NULL )
650       editor_ref -> edit_entry_ref -> stand_entry.from = use_date;
651   }
652 
653 
654   /* Entry start. */
655   if( flagIsSet( flags, XTM_ED_SET_TIME ) ) {
656     baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
657     tempW = XtNameToWidget( baseW, "StartEntTb" );
658 
659     XmUbTimeBoxSetStartTime( tempW, use_time );
660   }
661 
662 
663   /* Duration. */
664   if( flagIsSet( flags, XTM_ED_SET_DURATION ) ) {
665     buffer[ 0 ] = '\0';
666 
667     if( duration > 0 )
668       sprintf( buffer, "%d:%02d", duration / 60, duration % 60 );
669 
670     baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
671     tempW = XtNameToWidget( baseW, "DurEntFs" );
672 
673     xitFieldSelectSetCurrent( tempW, buffer, False );
674   }
675 
676 
677   /* The text entry. */
678   if( flagIsSet( flags, XTM_ED_SET_TEXT ) ) {
679     tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
680 
681     if( text == NULL )
682       XmTextSetString( tempW, "" );
683     else
684       XmTextSetString( tempW, text );
685   }
686 
687 
688   return;
689 
690 } /* xtmEdSetValues */
691 
692 
693 /*----------------------------------------------------------------------*/
694 
695 static Widget
createEditWindow(Widget parent,EDITOR_REC_REF editor_ref)696   createEditWindow( Widget          parent,
697                     EDITOR_REC_REF  editor_ref )
698 {
699 
700   /* Variables. */
701   int                     index;
702   Arg                     args[ 10 ];
703   Cardinal                n;
704   Widget                  dataLocalW[ 38 ];
705   Widget                  editorTl;
706   Widget                  menuCasc[ 2 ];
707   Widget                  menuHelpBu[ 6 ];
708   Widget                  menuFileBu[ 3 ];
709   Widget                  pulldownMenu[ 2 ];
710   Widget                  tempW;
711   Widget                  workFo;
712   XTM_GL_BASE_DATA_REF    appl_data_ref;
713   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
714 
715   static char  def_durations[] =
716     "0:10 0:15 0:30 0:45 1:00 1:30 2:00 4:00 6:00";
717 
718   static char  *pull_downs[] = { "pdown1", "pdown2" };
719 
720   static XIT_PUSH_STRUCT action_button_def[] = {
721     { "AlarmPb",   "", "", True, NULL },
722     { "PrefPb",    "", "", True, NULL },
723     { "StandPb",   "", "", True, NULL },
724     { "EditorPb",  "", "", True, NULL },
725     { "DummyPb",   "", "", True, NULL },
726     { "DayViewPb", "", "", True, NULL },
727   };
728 
729   static XIT_TEXT_STRUCT text_buffer_def[] = {
730     { "TextEntTx", NULL, 5, True },
731   };
732 
733   static XIT_CASCADE_STRUCT menupane[] = {
734     { "", "", "FilePane" },
735     { "", "", "HelpPane" },
736   };
737 
738   static XIT_MENU_BUTTON_STRUCT file_casc[] = {
739     { "",      "",  NULL, "IncludeBu", True,  False, False },
740     { XIT_SEP, " ", NULL, "",          False, False, False },
741     { "",      "",  NULL, "CloseBu",   True,  False, False },
742   };
743 
744   static XIT_MENU_BUTTON_STRUCT help_casc[] = {
745     { "", "", NULL, "ContextBu", True, False, False },
746     { "", "", NULL, "WindowsBu", True, False, False },
747     { "", "", NULL, "KeysBu",    True, False, False },
748     { "", "", NULL, "IndexBu",   True, False, False },
749     { "", "", NULL, "HelpBu",    True, False, False },
750     { "", "", NULL, "VersionBu", True, False, False },
751   };
752 
753   static XIT_ACTION_AREA_ITEM  action_buttons[] = {
754     { "",   okCB,     NULL },
755     { NULL, NULL,     NULL },
756     { "",   applyCB,  NULL },
757     { NULL, NULL,     NULL },
758     { "",   cancelCB, NULL },
759   };
760 
761 
762   /* Code. */
763 
764   appl_data_ref   = editor_ref -> appl_data_ref;
765   custom_data_ref = appl_data_ref -> custom_data;
766 
767   /* Text items. */
768   action_buttons[ 0 ].label = msgGetText( MXDI_OK_BUTTON );
769   action_buttons[ 0 ].data  = editor_ref;
770   action_buttons[ 2 ].label = msgGetText( MXDI_APPLY_BUTTON );
771   action_buttons[ 2 ].data  = editor_ref;
772   action_buttons[ 4 ].label = msgGetText( MXDI_CANCEL_BUTTON );
773   action_buttons[ 4 ].data  = editor_ref;
774 
775 
776   menupane[ 0 ].title    = msgGetText( MXDI_FILE_MENU );
777   menupane[ 0 ].mnemonic = msgGetText( MXDI_FILE_MENU_ACC );
778   menupane[ 1 ].title    = msgGetText( MXDI_HELP_MENU );
779   menupane[ 1 ].mnemonic = msgGetText( MXDI_HELP_MENU_ACC );
780 
781   file_casc[ 0 ].title    = msgGetText( MXDI_INCL_FILE_MENU );
782   file_casc[ 0 ].mnemonic = msgGetText( MXDI_INCL_FILE_MENU_ACC );
783   file_casc[ 2 ].title    = msgGetText( MXDI_CLOSE_MENU );
784   file_casc[ 2 ].mnemonic = msgGetText( MXDI_CLOSE_MENU_ACC );
785 
786   help_casc[ 0 ].title    = msgGetText( MXDI_HELP_CONTEXT );
787   help_casc[ 0 ].mnemonic = msgGetText( MXDI_HELP_CONTEXT_ACC );
788   help_casc[ 1 ].title    = msgGetText( MXDI_HELP_WINDOWS );
789   help_casc[ 1 ].mnemonic = msgGetText( MXDI_HELP_WINDOWS_ACC );
790   help_casc[ 2 ].title    = msgGetText( MXDI_HELP_KEYS );
791   help_casc[ 2 ].mnemonic = msgGetText( MXDI_HELP_KEYS_ACC );
792   help_casc[ 3 ].title    = msgGetText( MXDI_HELP_INDEX );
793   help_casc[ 3 ].mnemonic = msgGetText( MXDI_HELP_INDEX_ACC );
794   help_casc[ 4 ].title    = msgGetText( MXDI_HELP_HELP );
795   help_casc[ 4 ].mnemonic = msgGetText( MXDI_HELP_HELP_ACC );
796   help_casc[ 5 ].title    = msgGetText( MXDI_HELP_VERSION );
797   help_casc[ 5 ].mnemonic = msgGetText( MXDI_HELP_VERSION_ACC );
798 
799   action_button_def[ 0 ].title = msgGetText( MXDI_ALARM_ACTION );
800   action_button_def[ 1 ].title = msgGetText( MXDI_PREF_ACTION );
801   action_button_def[ 2 ].title = msgGetText( MXDI_STAND_ACTION );
802   action_button_def[ 3 ].title = msgGetText( MXDI_MY_EDITOR_ACTION );
803   action_button_def[ 5 ].title = msgGetText( MXDI_DISPLAY_DAY_VIEW );
804 
805 
806   /* Create a separate window. */
807   tempW = xitGetToplevelWidget( parent );
808 
809   editorTl = xitCreateToplevelDialog( tempW, "ApEditorTl",
810                                       1, 0,
811                                       action_buttons,
812                                       XtNumber( action_buttons ) );
813 
814   n = 0;
815   XtSetArg( args[ n ], XmNtitle,    msgGetText( MXDI_ENTRY_TITLE ) ); n++;
816   XtSetArg( args[ n ], XmNiconName, msgGetText( MXDI_ENTRY_IC_TITLE ) ); n++;
817   XtSetValues( editorTl, args, n );
818 
819   XtAddCallback( editorTl,  XmNdestroyCallback,
820                  (XtCallbackProc) destroyCB, (XtPointer) editor_ref );
821 
822   /* Close the window if this window is deleted. */
823   {
824     Atom  wm_delete_window;
825 
826     wm_delete_window = XmInternAtom( XtDisplay( editorTl ),
827                                      "WM_DELETE_WINDOW", False );
828 
829     XmAddWMProtocols( editorTl, &wm_delete_window, 1 );
830     XmAddWMProtocolCallback( editorTl, wm_delete_window,
831                              (XtCallbackProc) cancelCB,
832                              (XtPointer) editor_ref );
833   } /* block */
834 
835 
836   /* Reference to the contents of the window. */
837   workFo = XtNameToWidget( editorTl, "ApEditorTlBase.ApEditorTlFo" );
838 
839 
840   /* Create the menubar and menu cascades. */
841   menuBr = XmCreateMenuBar( workFo, "MenuBr", args, 0 );
842 
843   n = 0;
844   for( index = 0; index < XtNumber( pulldownMenu ); index++ )
845     pulldownMenu[ index ] = XmCreatePulldownMenu( menuBr,
846                                                   pull_downs[ index ],
847                                                   NULL, n );
848 
849   for( index = 0; index < XtNumber( menuCasc ); index++ )
850     menuCasc[ index ] = xitCreateCascadeButton( menuBr,
851                                                 pulldownMenu[ index ],
852                                                 &menupane[ index ] );
853 
854   /* The help button should be placed to the right. */
855   index = XtNumber( menuCasc ) - 1;
856   n     = 0;
857   XtSetArg( args[ n ], XmNmenuHelpWidget, menuCasc[ index ] ); n++;
858   XtSetValues( menuBr, args, n );
859 
860 
861   /* Create the file menu. */
862   for( index = 0; index < XtNumber( menuFileBu ); index++ )
863     menuFileBu[ index ] = xitCreateMenuPushButton( pulldownMenu[ 0 ],
864                                                    &file_casc[ index ] );
865   XtAddCallback( menuFileBu[ 0 ], XmNactivateCallback,
866                  (XtCallbackProc) includeFileCB, (XtPointer) editor_ref );
867   XtAddCallback( menuFileBu[ 2 ], XmNactivateCallback,
868                  (XtCallbackProc) cancelCB, (XtPointer) editor_ref );
869 
870 
871   /* Create the help menu. */
872   XtAddCallback( pulldownMenu[ 1 ], XmNentryCallback,
873                  (XtCallbackProc) helpCB, (XtPointer) editor_ref );
874 
875   for( index = 0; index < XtNumber( menuHelpBu ); index++ ) {
876     menuHelpBu[ index ] = xitCreateMenuPushButton( pulldownMenu[ 1 ],
877                                                    &help_casc[ index ] );
878 
879     XtAddCallback( menuHelpBu[ index ], XmNactivateCallback,
880                    (XtCallbackProc) helpCB, (XtPointer)(intptr_t)index );
881   }
882 
883   /* We can't do context sensitive help. */
884   XtSetSensitive( menuHelpBu[ 0 ], False );
885 
886 
887   /* Header with entry date. */
888   entryDateLa = xitCreateLabel( workFo, "EntryDateLa",
889                                 " \n ", XmALIGNMENT_CENTER );
890 
891 
892   /* Create the time entry form. */
893   timeEntFr = XmCreateFrame( workFo,    "TimeEntFr", args, 0 );
894   dataEntFo = XmCreateForm(  timeEntFr, "DataEntFo", args, 0 );
895 
896 
897   n = 0;
898   XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL  ); n++;
899   XtSetArg( args[ n ], XmNpacking,     XmPACK_COLUMN ); n++;
900   XtSetArg( args[ n ], XmNnumColumns,  3             ); n++;
901   timeEntRc = XmCreateRowColumn( dataEntFo, "TimeEntRc", args, n );
902 
903 
904   /* Entry date. */
905   dateEntLa = xitCreateLabel( timeEntRc, "DateEntLa",
906                               msgGetText( MXDI_DATE_LABEL ), -1 );
907 
908   dateEntTb = xtmFlCreateDateField( timeEntRc, "DateEntTb" );
909 
910   XtAddCallback( dateEntTb, XmNvalueChangedCallback,
911                  (XtCallbackProc) timeFieldChangedCB,
912                  (XtPointer) editor_ref );
913 
914 
915   /* Start time. */
916   startEntLa = xitCreateLabel( timeEntRc, "StartEntLa",
917                                msgGetText( MXDI_ENTRY_START_LABEL ), -1 );
918 
919   startEntTb = xtmFlCreateTimeField( timeEntRc, "StartEntTb" );
920 
921   XtAddCallback( startEntTb, XmNvalueChangedCallback,
922                  (XtCallbackProc) timeFieldChangedCB,
923                  (XtPointer) editor_ref );
924 
925 
926 
927   /* Duration. */
928   durEntLa = xitCreateLabel( timeEntRc, "DurEntLa",
929                              msgGetText( MXDI_ENTRY_DURATION_LABEL ), -1 );
930 
931   durEntFs = xtmFlCreateSelField( timeEntRc, "DurEntFs",
932                                   6, def_durations,
933                                   ' ', True,
934                                   NULL, NULL );
935 
936   tempW = xitFieldSelectGetChild( durEntFs, xitFIELD_SELECT_TEXT_FIELD );
937 
938   XtAddCallback( tempW, XmNvalueChangedCallback,
939                  (XtCallbackProc) timeFieldChangedCB,
940                  (XtPointer) editor_ref );
941 
942 
943   /* Entry types. */
944   n = 0;
945   XtSetArg( args[ n ], XmNpacking, XmPACK_COLUMN ); n++;
946   XtSetArg( args[ n ], XmNradioBehavior, True ); n++;
947   typeRb = XmCreateRowColumn( dataEntFo, "TypeRb", args, n );
948 
949   typeAppTb = xitCreateToggleButton(
950                 typeRb, "TypeAppTb",
951                 msgGetText( MXDI_TYPE_APPOINT ), False );
952 
953   XtAddCallback( typeAppTb, XmNvalueChangedCallback,
954                  (XtCallbackProc) entryTypeCB, (XtPointer) editor_ref );
955 
956 
957   typeStandAppTb = xitCreateToggleButton(
958                      typeRb, "TypeStandAppTb",
959                      msgGetText( MXDI_TYPE_STAND_APPOINT ), False );
960 
961   XtAddCallback( typeStandAppTb, XmNvalueChangedCallback,
962                  (XtCallbackProc) entryTypeCB, (XtPointer) editor_ref );
963 
964 
965   typeNoteTb = xitCreateToggleButton(
966                  typeRb, "TypeNoteTb",
967                  msgGetText( MXDI_TYPE_NOTE ), False );
968 
969   XtAddCallback( typeNoteTb, XmNvalueChangedCallback,
970                  (XtCallbackProc) entryTypeCB, (XtPointer) editor_ref );
971 
972 
973   typeStandNoteTb = xitCreateToggleButton(
974                       typeRb, "TypeStandNoteTb",
975                       msgGetText( MXDI_TYPE_STAND_NOTE ), False );
976 
977   XtAddCallback( typeStandNoteTb, XmNvalueChangedCallback,
978                  (XtCallbackProc) entryTypeCB, (XtPointer) editor_ref );
979 
980 
981   typeStickyNoteTb = xitCreateToggleButton(
982                        typeRb, "TypeStickyNoteTb",
983                        msgGetText( MXDI_TYPE_STICKY_NOTE ), False );
984 
985   XtAddCallback( typeStickyNoteTb, XmNvalueChangedCallback,
986                  (XtCallbackProc) entryTypeCB, (XtPointer) editor_ref );
987 
988 
989   /* Place the elements together. */
990   xitAttachWidget( timeEntRc,
991                    XmATTACH_FORM, NULL, XmATTACH_FORM, NULL,
992                    XmATTACH_NONE, NULL, XmATTACH_NONE, NULL );
993   xitAttachWidget( typeRb,
994                    XmATTACH_FORM, NULL, XmATTACH_WIDGET, timeEntRc,
995                    XmATTACH_NONE, NULL, XmATTACH_NONE,   NULL );
996 
997 
998   /* Create the selection form. */
999   selFr = XmCreateFrame(     workFo, "SelFr", args, 0 );
1000   selFo = XmCreateRowColumn( selFr,  "SelFo", args, 0 );
1001 
1002   selAlarmBu     = xitCreateToggleButton(
1003                      selFo, "SelAlarmBu",
1004                      msgGetText( MXDI_ALARM_BUTTON ), False );
1005 
1006   selImpBu       = xitCreateToggleButton(
1007                      selFo, "SelImpBu",
1008                      msgGetText( MXDI_IMPORTANT_BUTTON ), False );
1009 
1010   selNoteDoneBu  = xitCreateToggleButton(
1011                      selFo, "SelNoteDoneBu",
1012                      msgGetText( MXDI_DONE_BUTTON ), False );
1013 
1014   selPrivateBu   = xitCreateToggleButton(
1015                      selFo, "SelPrivateBu",
1016                      msgGetText( MXDI_PRIVATE_BUTTON ), False );
1017 
1018 
1019 
1020   /* Actions to take. */
1021   n = 0;
1022   XtSetArg( args[ n ], XmNpacking, XmPACK_COLUMN ); n++;
1023   XtSetArg( args[ n ], XmNnumColumns, 2 ); n++;
1024   XtSetArg( args[ n ], XmNspacing, 10 ); n++;
1025   actionRc = XmCreateRowColumn( workFo, "ActionRc", args, n );
1026 
1027   alarmPb   = xitCreatePushButton( actionRc, &action_button_def[ 0 ] );
1028   prefPb    = xitCreatePushButton( actionRc, &action_button_def[ 1 ] );
1029   standPb   = xitCreatePushButton( actionRc, &action_button_def[ 2 ] );
1030   editorPb  = xitCreatePushButton( actionRc, &action_button_def[ 3 ] );
1031   dummy1Pb  = xitCreatePushButton( actionRc, &action_button_def[ 4 ] );
1032   dayViewPb = xitCreatePushButton( actionRc, &action_button_def[ 5 ] );
1033 
1034   XtAddCallback( alarmPb, XmNactivateCallback,
1035                  (XtCallbackProc) alarmCB, (XtPointer) editor_ref );
1036   XtAddCallback( prefPb, XmNactivateCallback,
1037                  (XtCallbackProc) preferencesCB, (XtPointer) editor_ref );
1038   XtAddCallback( standPb, XmNactivateCallback,
1039                  (XtCallbackProc) standingCB, (XtPointer) editor_ref );
1040   XtAddCallback( editorPb, XmNactivateCallback,
1041                  (XtCallbackProc) editorCB, (XtPointer) editor_ref );
1042   XtAddCallback( dayViewPb, XmNactivateCallback,
1043                  (XtCallbackProc) dayViewCB, (XtPointer) editor_ref );
1044 
1045 
1046   /* Create form fot entry tag and database selection. */
1047   miscFo = XmCreateForm( workFo, "MiscFo", args, n );
1048 
1049 
1050   /* Entry tag. */
1051   n = 0;
1052   XtSetArg( args[ n ], XmNorientation, XmHORIZONTAL ); n++;
1053   miscRc = XmCreateRowColumn( miscFo, "MiscRc",  args, n );
1054 
1055   entryTagLa = xitCreateLabel( miscRc, "EntryTagLa",
1056                                msgGetText( MXDI_ENTRY_TAG_LABEL ), -1 );
1057 
1058 
1059   /* Entry tag selections. */
1060   entryTagFs = xtmFlCreateTagsField( miscRc, "EntryTagFs",
1061                                      4,
1062                                      custom_data_ref -> entry_tags_menu,
1063                                      custom_data_ref -> tags_db,
1064                                      NULL, NULL );
1065 
1066   tempW = xitFieldSelectGetChild( entryTagFs, xitFIELD_SELECT_TEXT_FIELD );
1067 
1068 
1069   /* Database selection. */
1070   databaseLa = xitCreateLabel( miscRc, "DatabaseLa",
1071                                msgGetText( MXDI_SAVE_IN_DB_LABEL ), -1 );
1072 
1073 
1074   /* Database selections. */
1075   databaseFs = xtmFlCreateDbField( miscRc, "DatabaseFs",
1076                                    custom_data_ref -> cal_db_handle,
1077                                    True,
1078                                    (XtCallbackProc) dbChangedCB,
1079                                    (void *) editor_ref );
1080 
1081 
1082   /* Entry text label. */
1083   if( custom_data_ref -> text_marker_pos > 0 &&
1084       custom_data_ref -> text_marker_pos < 150 ) {
1085 
1086     char  buffer1[ 200 ];
1087     char  format[ 20 ];
1088 
1089     sprintf( format, "%%-%d.%ds",
1090              custom_data_ref -> text_marker_pos -1,
1091              custom_data_ref -> text_marker_pos -1 );
1092 
1093     sprintf( buffer1, format, msgGetText( MXDI_TEXT_LABEL ) );
1094     strcat( buffer1, "." );
1095 
1096     textEntLa = xitCreateLabel( workFo, "TextEntLa", buffer1, -1 );
1097 
1098   } else {
1099     textEntLa = xitCreateLabel( workFo, "TextEntLa",
1100                                 msgGetText( MXDI_TEXT_LABEL ), -1 );
1101   }
1102 
1103   /* Create the text input form. */
1104   textEntTx = xitCreateTextScrolled( workFo, &text_buffer_def[ 0 ] );
1105 
1106   XtOverrideTranslations( textEntTx, xtm_di_newline_trans );
1107 
1108 
1109   /* Place the various elements together. */
1110   xitAttachWidget( menuBr,
1111                    XmATTACH_FORM, NULL, XmATTACH_FORM, NULL,
1112                    XmATTACH_FORM, NULL, XmATTACH_NONE, NULL );
1113   xitAttachWidget( entryDateLa,
1114                    XmATTACH_WIDGET, menuBr, XmATTACH_FORM, NULL,
1115                    XmATTACH_FORM,   NULL,   XmATTACH_NONE, NULL );
1116   xitAttachWidget( timeEntFr,
1117                    XmATTACH_WIDGET, entryDateLa, XmATTACH_FORM, NULL,
1118                    XmATTACH_NONE,   NULL,        XmATTACH_NONE, NULL );
1119   if( custom_data_ref -> read_only_mode ) {
1120     xitAttachWidget( textEntLa,
1121                      XmATTACH_WIDGET, timeEntFr, XmATTACH_FORM, NULL,
1122                      XmATTACH_NONE,   NULL,      XmATTACH_NONE, NULL );
1123   } else {
1124     xitAttachWidget( selFr,
1125                      XmATTACH_WIDGET, timeEntFr, XmATTACH_FORM, NULL,
1126                      XmATTACH_NONE,   NULL,      XmATTACH_NONE, NULL );
1127     xitAttachWidget( actionRc,
1128                      XmATTACH_WIDGET, timeEntFr, XmATTACH_WIDGET, selFr,
1129                      XmATTACH_NONE,   NULL,      XmATTACH_NONE,   NULL );
1130     xitAttachWidget( miscFo,
1131                      XmATTACH_WIDGET, selFr, XmATTACH_FORM, NULL,
1132                      XmATTACH_NONE,   NULL,  XmATTACH_NONE, NULL );
1133     xitAttachWidget( textEntLa,
1134                      XmATTACH_WIDGET, miscFo, XmATTACH_FORM, NULL,
1135                      XmATTACH_NONE,   NULL,   XmATTACH_NONE, NULL );
1136   }
1137 
1138   xitAttachWidget( XtParent( textEntTx ),
1139                    XmATTACH_WIDGET, textEntLa, XmATTACH_FORM, NULL,
1140                    XmATTACH_NONE,   NULL,      XmATTACH_NONE, NULL );
1141 
1142 
1143   /* Make sure there is enough space between the children. */
1144   n = 0;
1145   XtSetArg( args[ n ], XmNtopOffset,    5 ); n++;
1146   XtSetArg( args[ n ], XmNleftOffset,   5 ); n++;
1147   XtSetArg( args[ n ], XmNrightOffset,  5 ); n++;
1148   XtSetArg( args[ n ], XmNbottomOffset, 5 ); n++;
1149   XtSetValues( entryDateLa,           args, n );
1150   XtSetValues( timeEntRc,             args, n );
1151   XtSetValues( typeRb,                args, n );
1152   XtSetValues( selFr,                 args, n );
1153   XtSetValues( timeEntFr,             args, n );
1154   XtSetValues( actionRc,              args, n );
1155   XtSetValues( miscRc,                args, n );
1156   XtSetValues( textEntLa,             args, n );
1157   XtSetValues( XtParent( textEntTx ), args, n );
1158 
1159 
1160   /* Manage all the children. */
1161   XtManageChildren( menuCasc,   XtNumber( menuCasc ) );
1162   XtManageChildren( menuHelpBu, XtNumber( menuHelpBu ) );
1163   XtManageChildren( menuFileBu, XtNumber( menuFileBu ) );
1164 
1165   xitManageChildren( dataLocalW, XtNumber( dataLocalW ) );
1166 
1167 
1168   /* Set icon for this window. */
1169   xtmIcSetSimpleIcon( editorTl, workFo, XTM_IC_ICON_EDIT_ENTRY );
1170 
1171   /* Set the size of the window. */
1172   xitSetSizeToplevelDialog( editorTl, True );
1173 
1174 
1175   /* Make the final attachments. */
1176   n = 0;
1177   XtSetArg( args[ n ], XmNrightAttachment,  XmATTACH_FORM ); n++;
1178   XtSetArg( args[ n ], XmNbottomAttachment, XmATTACH_FORM ); n++;
1179   XtSetValues( XtParent( textEntTx ), args, n );
1180 
1181   if( custom_data_ref -> read_only_mode ) {
1182     XtUnmanageChild( selFr );
1183     XtUnmanageChild( actionRc );
1184     XtUnmanageChild( miscFo );
1185 
1186     XtSetSensitive( timeEntFr,             False );
1187     XtSetSensitive( XtParent( textEntTx ), False );
1188   } else {
1189     XtUnmapWidget( dummy1Pb );
1190   }
1191 
1192 
1193   return( editorTl );
1194 
1195 } /* createEditWindow */
1196 
1197 
1198 /*----------------------------------------------------------------------*/
1199 
1200 static Boolean
fetchEntryTimes(EDITOR_REC_REF editor_ref,Widget parentW,ENTRY_TIMES_REF entry_times)1201   fetchEntryTimes( EDITOR_REC_REF   editor_ref,
1202                    Widget           parentW,
1203                    ENTRY_TIMES_REF  entry_times )
1204 {
1205 
1206   /* Variables. */
1207   Boolean                 is_appointment = False;
1208   Boolean                 ok;
1209   char                    *char_ref;
1210   Widget                  baseW;
1211   Widget                  mainW;
1212   Widget                  tempW;
1213   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1214 
1215 
1216   /* Code. */
1217 
1218   custom_data_ref = editor_ref -> appl_data_ref -> custom_data;
1219 
1220 
1221   /* Editor window. */
1222   mainW = XtNameToWidget( editor_ref -> editorW,
1223                           "ApEditorTlBase.ApEditorTlFo" );
1224 
1225   /* Default values. */
1226   entry_times -> date       = 0;
1227   entry_times -> start_time = 0;
1228   entry_times -> end_time   = 0;
1229   entry_times -> duration   = 0;
1230 
1231 
1232   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TypeRb" );
1233 
1234   /* Kind of entry. */
1235   tempW = XtNameToWidget( baseW, "TypeAppTb" );
1236   if( XmToggleButtonGetState( tempW ) )
1237     is_appointment = True;
1238 
1239   tempW = XtNameToWidget( baseW, "TypeStandAppTb" );
1240   if( XmToggleButtonGetState( tempW ) )
1241     is_appointment = True;
1242 
1243 
1244   /* Fetch the entry times. */
1245   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
1246 
1247 
1248   /* Date. */
1249   tempW = XtNameToWidget( baseW, "DateEntTb" );
1250 
1251   ok = xtmFoFetchDate( parentW, tempW, XTM_FO_START_DATE, False,
1252                        &entry_times -> date );
1253   if( ! ok )
1254     return( False );
1255 
1256 
1257   /* Start time. */
1258   if( is_appointment ) {
1259     tempW = XtNameToWidget( baseW, "StartEntTb" );
1260 
1261     ok = xtmFoFetchTime( parentW, tempW, XTM_FO_START_TIME, False,
1262                          &entry_times -> start_time );
1263     if( ! ok )
1264       return( False );
1265   }
1266 
1267 
1268   /* Duration. */
1269   if( is_appointment ) {
1270 
1271     tempW = XtNameToWidget( baseW, "DurEntFs" );
1272     xitFieldSelectGetCurrent( tempW, &char_ref );
1273 
1274     ok = xtmFoFetchMinuteTime( char_ref, True, parentW, 23 * 60,
1275                                &entry_times -> duration );
1276 
1277     SysFree( char_ref );
1278     if( ! ok )
1279       return( False );
1280 
1281     if( entry_times -> duration <= 0 ) {
1282       entry_times -> duration = 0;
1283     } else {
1284       entry_times -> end_time = entry_times -> start_time;
1285       TimAddMinutes( &entry_times -> end_time, entry_times -> duration );
1286     }
1287 
1288   } /* if */
1289 
1290 
1291   return( True );
1292 
1293 } /* fetchEntryTimes */
1294 
1295 
1296 /*----------------------------------------------------------------------*/
1297 
1298 static Boolean
fetchEntryValues(EDITOR_REC_REF editor_ref,XTM_DB_ALL_ENTRY_REF entry_ref,char ** entry_text)1299   fetchEntryValues( EDITOR_REC_REF        editor_ref,
1300                     XTM_DB_ALL_ENTRY_REF  entry_ref,
1301                     char                  **entry_text )
1302 {
1303 
1304   /* Variables. */
1305   Boolean               ok;
1306   char                  *char_ref;
1307   Widget                baseW;
1308   Widget                mainW;
1309   Widget                tempW;
1310   ENTRY_TIMES_REC       entry_times;
1311   XTM_GL_BASE_DATA_REF  appl_data_ref;
1312 
1313 
1314   /* Code. */
1315 
1316   appl_data_ref = editor_ref -> appl_data_ref;
1317 
1318 
1319   /* Editor window. */
1320   mainW = XtNameToWidget( editor_ref -> editorW,
1321                           "ApEditorTlBase.ApEditorTlFo" );
1322 
1323   /* Default values. */
1324   entry_ref -> entry.entry_category = XTM_DB_ENTRY_LIST;
1325   entry_ref -> entry.entry_type     = XTM_DB_DAY_ENTRY;
1326 
1327 
1328   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TypeRb" );
1329 
1330   /* Standing appointment. */
1331   tempW = XtNameToWidget( baseW, "TypeStandAppTb" );
1332   if( XmToggleButtonGetState( tempW ) )
1333     entry_ref -> entry.entry_category = XTM_DB_REP_ENTRY_LIST;
1334 
1335   /* Note. */
1336   tempW = XtNameToWidget( baseW, "TypeNoteTb" );
1337   if( XmToggleButtonGetState( tempW ) )
1338     entry_ref -> entry.entry_type = XTM_DB_DAY_NOTE;
1339 
1340   /* Standing note. */
1341   tempW = XtNameToWidget( baseW, "TypeStandNoteTb" );
1342   if( XmToggleButtonGetState( tempW ) ) {
1343     entry_ref -> entry.entry_type     = XTM_DB_DAY_NOTE;
1344     entry_ref -> entry.entry_category = XTM_DB_REP_ENTRY_LIST;
1345   }
1346 
1347   /* Sticky note. */
1348   tempW = XtNameToWidget( baseW, "TypeStickyNoteTb" );
1349   if( XmToggleButtonGetState( tempW ) ) {
1350     entry_ref -> entry.entry_type     = XTM_DB_DAY_NOTE;
1351     entry_ref -> entry.entry_category = XTM_DB_STICKY_LIST;
1352   }
1353 
1354 
1355   /* Fetch the entry times. */
1356   ok = fetchEntryTimes( editor_ref, editor_ref -> editorW, &entry_times );
1357   if( ! ok )
1358     return( False );
1359 
1360   entry_ref -> entry.date_stamp = (UINT32) entry_times.date;
1361   entry_ref -> entry.time_stamp = (UINT32) entry_times.start_time;
1362   entry_ref -> entry.duration   = (UINT16) entry_times.duration;
1363 
1364 
1365   /* Entry flags. */
1366   baseW = XtNameToWidget( mainW, "SelFr.SelFo" );
1367 
1368   /* Alarm selection. */
1369   tempW = XtNameToWidget( baseW, "SelAlarmBu" );
1370   if( XmToggleButtonGetState( tempW ) )
1371     flagSet( entry_ref -> entry.flags, XTM_DB_FLAG_ALARM );
1372   else
1373     flagClear( entry_ref -> entry.flags, XTM_DB_FLAG_ALARM );
1374 
1375 
1376   /* Importance. */
1377   tempW = XtNameToWidget( baseW, "SelImpBu" );
1378   if( XmToggleButtonGetState( tempW ) )
1379     flagSet( entry_ref -> entry.flags, XTM_DB_FLAG_IMPORTANT );
1380   else
1381     flagClear( entry_ref -> entry.flags, XTM_DB_FLAG_IMPORTANT );
1382 
1383 
1384   /* Note done. */
1385   tempW = XtNameToWidget( baseW, "SelNoteDoneBu" );
1386   if( XmToggleButtonGetState( tempW ) )
1387     flagSet( entry_ref -> entry.flags, XTM_DB_FLAG_NOTE_DONE );
1388   else
1389     flagClear( entry_ref -> entry.flags, XTM_DB_FLAG_NOTE_DONE );
1390 
1391 
1392   /* Private. */
1393   tempW = XtNameToWidget( baseW, "SelPrivateBu" );
1394   if( XmToggleButtonGetState( tempW ) )
1395     flagSet( entry_ref -> entry.flags, XTM_DB_FLAG_PRIVATE );
1396   else
1397     flagClear( entry_ref -> entry.flags, XTM_DB_FLAG_PRIVATE );
1398 
1399 
1400   /* Entry tag and database. */
1401   baseW = XtNameToWidget( mainW, "MiscFo.MiscRc" );
1402 
1403   tempW = XtNameToWidget( baseW, "EntryTagFs" );
1404   xitFieldSelectGetCurrent( tempW, &char_ref );
1405 
1406   if( char_ref != NULL ) {
1407     strncpy( entry_ref -> entry.tag, char_ref, XTM_DB_TAG_LEN );
1408     entry_ref -> entry.tag[ XTM_DB_TAG_LEN ] = '\0';
1409 
1410     SysFree( char_ref );
1411   }
1412 
1413 
1414   /* Calendar. */
1415   tempW = XtNameToWidget( baseW, "DatabaseFs" );
1416   xitFieldSelectGetCurrent( tempW, &char_ref );
1417 
1418   if( char_ref == NULL )
1419     return( False );
1420 
1421   if( *char_ref == '\0' ) {
1422     xitErMessage( editor_ref -> editorW, XIT_ER_ERROR,
1423                   module_name, "fetchBaseFromWindow",
1424                   msgGetText( MXDI_NO_DB_SELECTED ) );
1425 
1426     SysFree( char_ref );
1427     return( False );
1428   }
1429 
1430   strcpy(  entry_ref -> db_name, char_ref );
1431   SysFree( char_ref );
1432 
1433 
1434   /* Text for entry. */
1435   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
1436   *entry_text = xitStringGetText( tempW );
1437 
1438   char_ref = *entry_text;
1439   while( isspace( *char_ref ) )
1440     char_ref++;
1441 
1442   /* Entries without text are not saved. */
1443   if( *char_ref == '\0' ) {
1444     xitErMessage( editor_ref -> editorW, XIT_ER_ERROR,
1445                   module_name, "fetchBaseFromWindow",
1446                   msgGetText( MXDI_ENTRY_HAS_NO_TEXT ) );
1447 
1448     /* freeing seems to be already done in exception handling */
1449     return( False );
1450   }
1451 
1452   strncpy( entry_ref -> entry.text, *entry_text, 100 );
1453   entry_ref -> entry.text[ 100 ] = '\0';
1454 
1455 
1456   return( True );
1457 
1458 } /* fetchEntryValues */
1459 
1460 
1461 /*----------------------------------------------------------------------*/
1462 
1463 static Boolean
readEntryToEdit(EDITOR_REC_REF editor_ref,char * db_name,UINT32 entry_id,Widget parent)1464   readEntryToEdit( EDITOR_REC_REF  editor_ref,
1465                    char            *db_name,
1466                    UINT32          entry_id,
1467                    Widget          parent )
1468 {
1469 
1470   /* Variables. */
1471   Boolean                 ok;
1472   XTM_DB_ALL_ENTRY_REF    entry_ref;
1473   XTM_DB_ENTRY_DATABASES  database;
1474   XTM_DB_STATUS           db_status;
1475 
1476 
1477   /* Code. */
1478 
1479   entry_ref = editor_ref -> edit_entry_ref;
1480 
1481   /* If we are editing an entry, free the data. */
1482   if( entry_ref != NULL ) {
1483     SysFree( entry_ref -> all_text );
1484     SysFree( entry_ref );
1485   }
1486 
1487   /* Allocate a record to hold an entry. */
1488   editor_ref -> edit_entry_ref = SysNew( XTM_DB_ALL_ENTRY_DEF );
1489   entry_ref = editor_ref -> edit_entry_ref;
1490 
1491   editor_ref -> new_entry     = True;
1492   editor_ref -> standing_seen = False;
1493 
1494 
1495   /* Default values for the entry. */
1496   setEntryDefault( editor_ref -> appl_data_ref,
1497                    entry_ref,
1498                    (SET_ALL_ENTRY | SET_ENTRY | SET_REPEATED_ENTRY),
1499                    editor_ref -> default_date,
1500                    editor_ref -> default_time,
1501                    editor_ref -> default_duration );
1502 
1503   strcpy( entry_ref -> db_name, db_name );
1504 
1505   /* Enpty entry? */
1506   if( entry_id == 0 )
1507     return( True );
1508 
1509 
1510   /* Open the database. */
1511   ok = xtmDmOpenDatabase( editor_ref -> appl_data_ref,
1512                           db_name, XTM_DB_FLAG_MODE_READ,
1513                           &database );
1514   if( ! ok )
1515     return( False );
1516 
1517 
1518   /* Fetch the entry. */
1519   db_status = xtmDbFetchEntry( &database, entry_id,
1520                                entry_ref, &entry_ref -> all_text );
1521 
1522   xtmDbCloseEntryDb( &database );
1523 
1524 
1525   /* If the entry could not be fetched, it is perhaps removed? */
1526   if( db_status != XTM_DB_OK ) {
1527     xitErMessage( parent, XIT_ER_ERROR,
1528                   module_name, "fetchEntryToEdit",
1529                   msgGetText( MXDI_NO_ENTRY ) );
1530 
1531     return( False );
1532   }
1533 
1534   /* If the entry is not repeated, set the repeated part. */
1535   if( entry_ref -> entry.entry_category == XTM_DB_ENTRY_LIST )
1536     setEntryDefault( editor_ref -> appl_data_ref,
1537                      entry_ref, SET_REPEATED_ENTRY,
1538                      editor_ref -> default_date,
1539                      editor_ref -> default_time,
1540                      editor_ref -> default_duration );
1541 
1542   editor_ref -> new_entry = False;
1543 
1544 
1545   return( True );
1546 
1547 } /* readEntryToEdit */
1548 
1549 
1550 /*----------------------------------------------------------------------*/
1551 
1552 static void
removeEditFile(EDITOR_REC_REF editor_ref)1553   removeEditFile( EDITOR_REC_REF  editor_ref )
1554 {
1555 
1556   /* Variables. */
1557   int     pid;
1558   Widget  mainW;
1559   Widget  tempW;
1560 
1561 
1562   /* Code. */
1563 
1564   /* Kill the editor? */
1565   if( editor_ref -> editor_pid > 0 ) {
1566     pid = editor_ref -> editor_pid;
1567 
1568     editor_ref -> editor_pid = 0;
1569     (void) kill( pid, SIGKILL );
1570   }
1571 
1572   /* Free the file name. */
1573   if( editor_ref -> temp_file != NULL ) {
1574     (void) unlink( editor_ref -> temp_file );
1575 
1576     SysFree( editor_ref -> temp_file );
1577     editor_ref -> temp_file = NULL;
1578   }
1579 
1580   /* Reset the editor or change the text field. */
1581   if( editor_ref -> editorW != NULL ) {
1582     mainW = XtNameToWidget( editor_ref -> editorW,
1583                             "ApEditorTlBase.ApEditorTlFo" );
1584 
1585     tempW = XtNameToWidget( mainW, "ActionRc.EditorPb" );
1586     XtSetSensitive( tempW, True );
1587 
1588     tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
1589     XtSetSensitive( tempW, True );
1590   }
1591 
1592 
1593   return;
1594 
1595 } /* removeEditFile */
1596 
1597 
1598 /*----------------------------------------------------------------------*/
1599 
1600 static Boolean
saveEntry(EDITOR_REC_REF editor_ref)1601   saveEntry( EDITOR_REC_REF  editor_ref )
1602 {
1603 
1604   /* Variables. */
1605   Boolean               ok;
1606   XTM_DB_ALL_ENTRY_REF  new_entry_ref;
1607   XTM_DB_ALL_ENTRY_REF  old_entry_ref;
1608 
1609 
1610   /* Code. */
1611 
1612   new_entry_ref = SysNew( XTM_DB_ALL_ENTRY_DEF );
1613   old_entry_ref = editor_ref -> edit_entry_ref;
1614 
1615   new_entry_ref -> all_text = NULL;
1616 
1617 
1618   /* The new entry is a copy of the old (with the exception of all_text). */
1619   memcpy( new_entry_ref, old_entry_ref, sizeof( XTM_DB_ALL_ENTRY_DEF ) );
1620 
1621 
1622   /* Fetch data entered in windows. */
1623   ok = fetchEntryValues( editor_ref,
1624                          new_entry_ref, &new_entry_ref -> all_text );
1625   if( ! ok )
1626     raise exception;
1627 
1628 
1629   /* Make sure the user sees the standing window. */
1630   if( editor_ref -> appl_data_ref -> custom_data -> prompt_repeat_win ) {
1631 
1632     if( new_entry_ref -> entry.entry_category == XTM_DB_REP_ENTRY_LIST ||
1633         new_entry_ref -> entry.entry_category == XTM_DB_STICKY_LIST ) {
1634 
1635       if( editor_ref -> new_entry && ! editor_ref -> standing_seen ) {
1636         standingCB( editor_ref -> editorW, editor_ref, NULL );
1637 
1638         raise exception;
1639       }
1640     }
1641 
1642   } /* if */
1643 
1644 
1645   /* Save the entry. */
1646   ok = writeEditedEntry( editor_ref -> appl_data_ref,
1647                          editor_ref -> editorW,
1648                          old_entry_ref, new_entry_ref );
1649   if( ! ok )
1650     raise exception;
1651 
1652 
1653   /* The new entry now becomes the old entry (including all_text). */
1654   if( editor_ref -> edit_entry_ref != NULL ) {
1655     SysFree( editor_ref -> edit_entry_ref -> all_text );
1656     SysFree( editor_ref -> edit_entry_ref );
1657   }
1658 
1659   editor_ref -> edit_entry_ref = new_entry_ref;
1660 
1661   editor_ref -> edit_entry_ref -> entry.id = 0;
1662   editor_ref -> edit_entry_ref -> stand_entry.id = 0;
1663 
1664   return( True );
1665 
1666 
1667   /* Exception handler. */
1668   exception:
1669 
1670     if( new_entry_ref -> all_text != NULL )
1671       SysFree( new_entry_ref -> all_text );
1672 
1673     SysFree( new_entry_ref );
1674 
1675     return( False );
1676 
1677 } /* saveEntry */
1678 
1679 
1680 /*----------------------------------------------------------------------*/
1681 
1682 static void
setEntryValues(EDITOR_REC_REF editor_ref,XTM_DB_ALL_ENTRY_REF entry_ref)1683   setEntryValues( EDITOR_REC_REF        editor_ref,
1684                   XTM_DB_ALL_ENTRY_REF  entry_ref )
1685 {
1686 
1687   /* Variables. */
1688   Boolean                 ok;
1689   UINT32                  can_do;
1690   char                    buffer[ 50 ];
1691   Arg                     args[ 5 ];
1692   Cardinal                n;
1693   Widget                  baseW;
1694   Widget                  mainW;
1695   Widget                  tempW;
1696   XTM_GL_BASE_DATA_REF    appl_data_ref;
1697   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1698   XTM_CD_CAL_INFO         db_info;
1699 
1700 
1701   /* Code. */
1702 
1703   appl_data_ref   = editor_ref -> appl_data_ref;
1704   custom_data_ref = appl_data_ref -> custom_data;
1705 
1706   /* Do we have a valid window? */
1707   if( editor_ref -> editorW == NULL )
1708     return;
1709 
1710   mainW = XtNameToWidget( editor_ref -> editorW,
1711                           "ApEditorTlBase.ApEditorTlFo" );
1712 
1713 
1714   /* Fetch info regarding the database for the entry. */
1715   ok = xtmCdFetchNamedDb( appl_data_ref -> custom_data -> cal_db_handle,
1716                           entry_ref -> db_name,
1717                           &db_info, NULL );
1718   if( ! ok )
1719     return;
1720 
1721 
1722   /* Make sure our children don't spoil our size. */
1723   n = 0;
1724   XtSetArg( args[ n ], XmNallowShellResize, False ); n++;
1725   XtSetValues( editor_ref -> editorW, args, n );
1726 
1727 
1728   /* Date for the entry. */
1729   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
1730   tempW = XtNameToWidget( baseW, "DateEntTb" );
1731 
1732   XmUbTimeBoxSetStartDate( tempW, editor_ref -> default_date );
1733 
1734 
1735   /* Entry start. */
1736   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
1737   tempW = XtNameToWidget( baseW, "StartEntTb" );
1738 
1739   if( entry_ref -> entry.entry_type == XTM_DB_DAY_ENTRY )
1740     XmUbTimeBoxSetStartTime( tempW, entry_ref -> entry.time_stamp );
1741   else
1742     XmUbTimeBoxSetStartTimeString( tempW, "" );
1743 
1744 
1745   /* Duration. */
1746   buffer[ 0 ] = '\0';
1747 
1748   switch( entry_ref -> entry.entry_type ) {
1749     case XTM_DB_DAY_ENTRY:
1750       if( entry_ref -> entry.duration > 0 )
1751         sprintf( buffer, "%d:%02d",
1752                  (int) entry_ref -> entry.duration / 60,
1753                  (int) entry_ref -> entry.duration % 60 );
1754       break;
1755   }
1756 
1757   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
1758   tempW = XtNameToWidget( baseW, "DurEntFs" );
1759 
1760   xitFieldSelectSetCurrent( tempW, buffer, False );
1761 
1762 
1763   /* Type of entry. */
1764   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TypeRb" );
1765 
1766   /* No buttons set. */
1767   tempW = XtNameToWidget( baseW, "TypeAppTb" );
1768   XmToggleButtonSetState( tempW, False, False );
1769 
1770   tempW = XtNameToWidget( baseW, "TypeStandAppTb" );
1771   XmToggleButtonSetState( tempW, False, False );
1772 
1773   tempW = XtNameToWidget( baseW, "TypeNoteTb" );
1774   XmToggleButtonSetState( tempW, False, False );
1775 
1776   tempW = XtNameToWidget( baseW, "TypeStandNoteTb" );
1777   XmToggleButtonSetState( tempW, False, False );
1778 
1779   tempW = XtNameToWidget( baseW, "TypeStickyNoteTb" );
1780   XmToggleButtonSetState( tempW, False, False );
1781 
1782 
1783   /* Appointment? */
1784   if( entry_ref -> entry.entry_type == XTM_DB_DAY_ENTRY ) {
1785 
1786     if( entry_ref -> entry.entry_category == XTM_DB_REP_ENTRY_LIST ) {
1787       tempW = XtNameToWidget( baseW, "TypeStandAppTb" );
1788       editor_ref -> entry_type = XTM_DB_TYPE_STAND_APPOINTMENT;
1789 
1790     } else {
1791       tempW = XtNameToWidget( baseW, "TypeAppTb" );
1792       editor_ref -> entry_type = XTM_DB_TYPE_APPOINTMENT;
1793     }
1794 
1795     XmToggleButtonSetState( tempW, True, False );
1796   }
1797 
1798   /* Note? */
1799   if( entry_ref -> entry.entry_type == XTM_DB_DAY_NOTE ) {
1800 
1801     if( entry_ref -> entry.entry_category == XTM_DB_REP_ENTRY_LIST ) {
1802       tempW = XtNameToWidget( baseW, "TypeStandNoteTb" );
1803       editor_ref -> entry_type = XTM_DB_TYPE_STAND_NOTE;
1804 
1805     } else if( entry_ref -> entry.entry_category == XTM_DB_STICKY_LIST ) {
1806       tempW = XtNameToWidget( baseW, "TypeStickyNoteTb" );
1807       editor_ref -> entry_type = XTM_DB_TYPE_STICKY_NOTE;
1808 
1809     } else {
1810       tempW = XtNameToWidget( baseW, "TypeNoteTb" );
1811       editor_ref -> entry_type = XTM_DB_TYPE_NOTE;
1812     }
1813 
1814     XmToggleButtonSetState( tempW, True, False );
1815   }
1816 
1817 
1818   /* Alarm selection. */
1819   baseW = XtNameToWidget( mainW, "SelFr.SelFo" );
1820 
1821   tempW = XtNameToWidget( baseW, "SelAlarmBu" );
1822 
1823   if( flagIsSet( entry_ref -> entry.flags, XTM_DB_FLAG_ALARM ) &&
1824       entry_ref -> entry.entry_type != XTM_DB_DAY_NOTE )
1825     XmToggleButtonSetState( tempW, True, False );
1826   else
1827     XmToggleButtonSetState( tempW, False, False );
1828 
1829 
1830   /* Importance. */
1831   tempW = XtNameToWidget( baseW, "SelImpBu" );
1832 
1833   if( flagIsSet( entry_ref -> entry.flags, XTM_DB_FLAG_IMPORTANT ) )
1834     XmToggleButtonSetState( tempW, True, False );
1835   else
1836     XmToggleButtonSetState( tempW, False, False );
1837 
1838 
1839   /* Note done. */
1840   tempW = XtNameToWidget( baseW, "SelNoteDoneBu" );
1841 
1842   if( entry_ref -> entry.entry_type == XTM_DB_DAY_NOTE &&
1843       flagIsSet( entry_ref -> entry.flags, XTM_DB_FLAG_NOTE_DONE ) )
1844     XmToggleButtonSetState( tempW, True, False );
1845   else
1846     XmToggleButtonSetState( tempW, False, False );
1847 
1848 
1849   /* Private. */
1850   tempW = XtNameToWidget( baseW, "SelPrivateBu" );
1851 
1852   if( flagIsSet( entry_ref -> entry.flags, XTM_DB_FLAG_PRIVATE ) )
1853     XmToggleButtonSetState( tempW, True, False );
1854   else
1855     XmToggleButtonSetState( tempW, False, False );
1856 
1857 
1858   /* Show/hide valid days? */
1859   baseW = XtNameToWidget( mainW, "ActionRc" );
1860   tempW = XtNameToWidget( baseW, "StandPb" );
1861 
1862   if( entry_ref -> entry.entry_category == XTM_DB_REP_ENTRY_LIST ||
1863       entry_ref -> entry.entry_category == XTM_DB_STICKY_LIST )
1864     XtSetSensitive( tempW, True );
1865   else
1866     XtSetSensitive( tempW, False );
1867 
1868 
1869   /* Entry tag and database name. */
1870   baseW = XtNameToWidget( mainW, "MiscFo.MiscRc" );
1871 
1872 
1873   /* Entry tag. */
1874   tempW = XtNameToWidget( baseW, "EntryTagFs" );
1875 
1876   if( entry_ref -> entry.tag[ 0 ] != '\0' )
1877     xitFieldSelectSetCurrent( tempW, entry_ref -> entry.tag, False );
1878   else
1879     xitFieldSelectSetCurrent( tempW, "", False );
1880 
1881 
1882   /* Database name. */
1883   tempW = XtNameToWidget( baseW, "DatabaseFs" );
1884 
1885   xitFieldSelectSetCurrent( tempW, entry_ref -> db_name, False );
1886 
1887 
1888   /* The text entry. */
1889   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
1890 
1891   if( editor_ref -> new_entry ) {
1892     XmTextSetString( tempW, custom_data_ref -> default_entry_text );
1893   } else {
1894     if( entry_ref -> all_text == NULL )
1895       XmTextSetString( tempW, entry_ref -> entry.text );
1896     else
1897       XmTextSetString( tempW, entry_ref -> all_text );
1898   }
1899 
1900 
1901   /* Entry date. */
1902   writeEntryDate( editor_ref );
1903 
1904 
1905   /* What can we do? */
1906   updateCanDo( editor_ref );
1907 
1908 
1909   /* Can we change the private flag? */
1910   baseW = XtNameToWidget( mainW, "SelFr.SelFo" );
1911   tempW = XtNameToWidget( baseW, "SelPrivateBu" );
1912 
1913   if( flagIsSet( db_info.operations, XTM_DB_FLAG_MODE_PRIV ) )
1914     XtSetSensitive( tempW, True );
1915   else
1916     XtSetSensitive( tempW, False );
1917 
1918 
1919   /* Can we save the entries or not? */
1920   xtmDbGetEntryPermissions( db_info.operations,
1921                             entry_ref -> entry.owner,
1922                             entry_ref -> entry.flags,
1923                             &can_do );
1924 
1925   baseW = XtNameToWidget( editor_ref -> editorW, "ApEditorTlBase" );
1926 
1927   if( flagIsSet( can_do, XTM_DB_PROT_CHANGE ) &&
1928       ! appl_data_ref -> custom_data -> read_only_mode ) {
1929 
1930     tempW = XtNameToWidget( baseW, "Bu1" );
1931     XtMapWidget( tempW );
1932 
1933     tempW = XtNameToWidget( baseW, "Bu3" );
1934     XtMapWidget( tempW );
1935 
1936   } else {
1937 
1938     tempW = XtNameToWidget( baseW, "Bu1" );
1939     XtUnmapWidget( tempW );
1940 
1941     tempW = XtNameToWidget( baseW, "Bu3" );
1942     XtUnmapWidget( tempW );
1943 
1944   } /* if */
1945 
1946 
1947   return;
1948 
1949 } /* setEntryValues */
1950 
1951 
1952 /*----------------------------------------------------------------------*/
1953 
1954 static XTM_DB_STATUS
setEntryDefault(XTM_GL_BASE_DATA_REF appl_data_ref,XTM_DB_ALL_ENTRY_REF entry_ref,UINT32 set_parts,TIM_TIME_REF entry_date,TIM_TIME_REF entry_time,int entry_duration)1955   setEntryDefault( XTM_GL_BASE_DATA_REF  appl_data_ref,
1956                    XTM_DB_ALL_ENTRY_REF  entry_ref,
1957                    UINT32                set_parts,
1958                    TIM_TIME_REF          entry_date,
1959                    TIM_TIME_REF          entry_time,
1960                    int                   entry_duration )
1961 {
1962 
1963   /* Variables. */
1964   int                     index;
1965   UINT32                  date_stamp;
1966   UINT32                  default_flags;
1967   UINT32                  time_stamp;
1968   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
1969 
1970 
1971   /* Code. */
1972 
1973   custom_data_ref = appl_data_ref -> custom_data;
1974 
1975   time_stamp = (UINT32) TimMakeTime( 1970, 1, 1,
1976                                      TimHour( entry_time ),
1977                                      TimMinute( entry_time ),
1978                                      0 );
1979 
1980   date_stamp = (UINT32) TimMakeTime( TimIndexOfYear( entry_date ),
1981                                      TimIndexOfMonth( entry_date ),
1982                                      TimIndexOfDay( entry_date ),
1983                                      0, 0, 0 );
1984 
1985   /* All entry data. */
1986   if( flagIsSet( set_parts, SET_ALL_ENTRY ) ) {
1987     entry_ref -> db_name[ 0 ] = '\0';
1988     entry_ref -> all_text     = NULL;
1989   }
1990 
1991   /* Base entry data. */
1992   if( flagIsSet( set_parts, SET_ENTRY ) ) {
1993 
1994     default_flags = 0;
1995 
1996     if( appl_data_ref -> custom_data -> alarm_for_new_app )
1997       flagSet( default_flags, XTM_DB_FLAG_ALARM );
1998 
1999     entry_ref -> entry.id              = 0;
2000     entry_ref -> entry.time_stamp      = time_stamp;
2001     entry_ref -> entry.date_stamp      = date_stamp;
2002     entry_ref -> entry.last_update     = 0;
2003     entry_ref -> entry.owner           = getuid();
2004     entry_ref -> entry.entry_type      = XTM_DB_DAY_ENTRY;
2005     entry_ref -> entry.entry_category  = XTM_DB_ENTRY_LIST;
2006     entry_ref -> entry.duration        = entry_duration;
2007     entry_ref -> entry.flags           = default_flags;
2008     entry_ref -> entry.fg_color_index  = 0;
2009     entry_ref -> entry.bg_color_index  = 0;
2010     entry_ref -> entry.text[ 0 ]       = '\0';
2011 
2012     strncpy( entry_ref -> entry.tag,
2013              appl_data_ref -> custom_data -> default_entry_tag,
2014              XTM_DB_TAG_LEN );
2015     entry_ref -> entry.tag[ XTM_DB_TAG_LEN ] = '\0';
2016 
2017     entry_ref -> entry.alarm_melody    =
2018       appl_data_ref -> custom_data -> default_tune;;
2019     entry_ref -> entry.day_list_lines  =
2020       appl_data_ref -> custom_data -> entry_show_lines;
2021     entry_ref -> entry.alarm_lines     =
2022       appl_data_ref -> custom_data -> alarm_show_lines;
2023 
2024     for( index = 0; index < 5; index++ ) {
2025       entry_ref -> entry.alarm_offset[ index ] =
2026         appl_data_ref -> custom_data -> alarm_offset[ index ];
2027       entry_ref -> entry.alarm_valid[ index ]  =
2028         appl_data_ref -> custom_data -> alarm_valid[ index ];
2029     }
2030 
2031   } /* if */
2032 
2033   /* Repeated entry data. */
2034   if( flagIsSet( set_parts, SET_REPEATED_ENTRY ) ) {
2035 
2036     entry_ref -> stand_entry.id             = 0;
2037     entry_ref -> stand_entry.from           = date_stamp;
2038     entry_ref -> stand_entry.to             = 0;
2039     entry_ref -> stand_entry.flags          = 0;
2040     entry_ref -> stand_entry.every_n        = 0;
2041     entry_ref -> stand_entry.valid_every    = 0;
2042     entry_ref -> stand_entry.skip_week[ 0 ] = 0;
2043     entry_ref -> stand_entry.skip_week[ 1 ] = 0;
2044 
2045     /* We must provide the day valid. */
2046     for( index = 0; index < 7; index++ )
2047       entry_ref -> stand_entry.valid_days[ index ] = 0;
2048 
2049   } /* if */
2050 
2051 
2052   return( XTM_DB_OK );
2053 
2054 } /* setEntryDefault */
2055 
2056 
2057 /*----------------------------------------------------------------------*/
2058 
2059 static void
updateCanDo(EDITOR_REC_REF editor_ref)2060   updateCanDo( EDITOR_REC_REF editor_ref )
2061 {
2062 
2063   /* Variables. */
2064   Boolean  alarms   = True;
2065   Boolean  standing = False;
2066   Widget   mainW;
2067   Widget   tempW;
2068 
2069 
2070   /* Code. */
2071 
2072   mainW = XtNameToWidget( editor_ref -> editorW,
2073                           "ApEditorTlBase.ApEditorTlFo" );
2074 
2075 
2076   if( editor_ref -> entry_type == XTM_DB_TYPE_STAND_APPOINTMENT )
2077     standing = True;
2078 
2079   if( editor_ref -> entry_type == XTM_DB_TYPE_NOTE )
2080     alarms = False;
2081 
2082   if( editor_ref -> entry_type == XTM_DB_TYPE_STAND_NOTE ) {
2083     standing = True;
2084     alarms   = False;
2085   }
2086 
2087   if( editor_ref -> entry_type == XTM_DB_TYPE_STICKY_NOTE ) {
2088     standing = True;
2089     alarms   = False;
2090   }
2091 
2092   /* Alarm and standing buttons sensitive/not sensitive? */
2093   tempW = XtNameToWidget( mainW, "ActionRc.AlarmPb" );
2094   XtSetSensitive( tempW, alarms );
2095 
2096   tempW = XtNameToWidget( mainW, "ActionRc.StandPb" );
2097   XtSetSensitive( tempW, standing );
2098 
2099 
2100   return;
2101 
2102 } /* updateCanDo */
2103 
2104 
2105 /*----------------------------------------------------------------------*/
2106 
2107 static Boolean
writeEditedEntry(XTM_GL_BASE_DATA_REF appl_data_ref,Widget parent,XTM_DB_ALL_ENTRY_REF old_entry_ref,XTM_DB_ALL_ENTRY_REF new_entry_ref)2108   writeEditedEntry( XTM_GL_BASE_DATA_REF  appl_data_ref,
2109                     Widget                parent,
2110                     XTM_DB_ALL_ENTRY_REF  old_entry_ref,
2111                     XTM_DB_ALL_ENTRY_REF  new_entry_ref )
2112 {
2113 
2114   /* Variables. */
2115   Boolean                 ok;
2116   Boolean                 remove_old_entry = False;
2117   Boolean                 use_same_db = False;
2118   UINT32                  id;
2119   char                    *new_db;
2120   char                    *old_db;
2121   XTM_DB_ID_REQUEST       id_request;
2122   XTM_DB_STATUS           db_status;
2123   XTM_DB_ENTRY_DATABASES  database;
2124   XTM_DB_ENTRY_DATABASES  *database_ref = NULL;
2125 
2126 
2127   /* Code. */
2128 
2129   old_db = old_entry_ref -> db_name;
2130   new_db = new_entry_ref -> db_name;
2131 
2132   if( strcmp( old_db, new_db ) == 0 )
2133     use_same_db = True;
2134 
2135 
2136   /* Are we changing an existing entry? */
2137   if( old_entry_ref -> entry.id > 0 )
2138     remove_old_entry = True;
2139 
2140 
2141   /* Remove the old entry? */
2142   if( remove_old_entry ) {
2143 
2144     database_ref = &database;
2145 
2146     /* Open the database. */
2147     ok = xtmDmOpenDatabase( appl_data_ref, old_db, XTM_DB_FLAG_MODE_WRITE,
2148                             database_ref );
2149     if( ! ok )
2150       return( False );
2151 
2152     (void) xtmDbDeleteEntry( database_ref, old_entry_ref -> entry.id );
2153 
2154     /* Let the database stay open? */
2155     if( ! use_same_db ) {
2156       xtmDbCloseEntryDb( database_ref );
2157       database_ref = NULL;
2158     }
2159 
2160   } /* if */
2161 
2162 
2163   /* Save the new entry. */
2164 
2165   /* Do we need to open the database. */
2166   if( database_ref == NULL ) {
2167 
2168     database_ref = &database;
2169 
2170     /* Open the database. */
2171     ok = xtmDmOpenDatabase( appl_data_ref, new_db, XTM_DB_FLAG_MODE_WRITE,
2172                             database_ref );
2173     if( ! ok )
2174       return( False );
2175 
2176   } /* if */
2177 
2178 
2179   /* Generate new entry id. */
2180   id_request.directory  = database_ref -> database_dir;
2181   id_request.operations = 0;
2182   id_request.lock_file  = False;
2183 
2184   db_status = xtmDbGenerateId( &id_request, &id );
2185   if( db_status != XTM_DB_OK )
2186       xitErMessage( NULL, XIT_ER_FATAL,
2187                     module_name, "writeEditedEntry",
2188                     msgGetText( MXDI_ERRMSG_GENERATE_ID ) );
2189 
2190   new_entry_ref -> entry.id       = id;
2191   new_entry_ref -> stand_entry.id = id;
2192 
2193   /* Write the entry. */
2194   db_status = xtmDbInsertEntry( database_ref,
2195                                 new_entry_ref, new_entry_ref -> all_text );
2196   if( db_status != XTM_DB_OK )
2197       xitErMessage( NULL, XIT_ER_FATAL,
2198                     module_name, "writeEditedEntry",
2199                     msgGetText( MXDI_ERRMSG_INSERT_ENTRY ) );
2200 
2201   /* Close the database. */
2202   xtmDbCloseEntryDb( database_ref );
2203 
2204 
2205   return( True );
2206 
2207 } /* writeEditedEntry */
2208 
2209 
2210 /*----------------------------------------------------------------------*/
2211 
2212 static void
writeEntryDate(EDITOR_REC_REF editor_ref)2213   writeEntryDate( EDITOR_REC_REF editor_ref )
2214 {
2215 
2216   /* Variables. */
2217   Boolean          ok;
2218   char             buffer[ 50 ];
2219   char             time_buffer[ 50 ];
2220   Widget           mainW;
2221   Widget           tempW;
2222   ENTRY_TIMES_REC  entry_times;
2223 
2224 
2225   /* Code. */
2226 
2227   mainW = XtNameToWidget( editor_ref -> editorW,
2228                           "ApEditorTlBase.ApEditorTlFo" );
2229 
2230   /* Blank out the current entry date. */
2231   tempW = XtNameToWidget( mainW, "EntryDateLa" );
2232   xitStringSetLabel( tempW, " \n " );
2233 
2234 
2235   /* Fetch the date, start time and duration. */
2236   ok = fetchEntryTimes( editor_ref, NULL, &entry_times );
2237   if( ! ok )
2238     return;
2239 
2240 
2241   time_buffer[ 0 ] = '\0';
2242 
2243   /* Build the entry date */
2244   if( entry_times.date > 0 ) {
2245     xtmFoFormatDate( entry_times.date, buffer, sizeof( buffer ) );
2246 
2247     strcat( time_buffer, buffer );
2248     strcat( time_buffer, ", " );
2249 
2250     TimFormatStrTime( entry_times.date, "%A", buffer, sizeof( buffer ) );
2251     strcat( time_buffer, buffer );
2252   }
2253 
2254   strcat( time_buffer, "\n" );
2255 
2256   /* Build the start time. */
2257   if( entry_times.start_time > 0 ) {
2258     xtmFoFormatTime( entry_times.start_time, buffer, sizeof( buffer ) );
2259 
2260     strcat( time_buffer, buffer );
2261   }
2262 
2263   /* Build the end time. */
2264   if( entry_times.end_time > 0 ) {
2265     xtmFoFormatTime( entry_times.end_time, buffer, sizeof( buffer ) );
2266 
2267     strcat( time_buffer, " - " );
2268     strcat( time_buffer, buffer );
2269   }
2270 
2271   /* Set the new time. */
2272   tempW = XtNameToWidget( mainW, "EntryDateLa" );
2273   xitStringSetLabel( tempW, time_buffer );
2274 
2275 
2276   return;
2277 
2278 } /* writeEntryDate */
2279 
2280 
2281 /*----------------------------------------------------------------------*/
2282 
2283 static void
alarmCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2284   alarmCB( Widget          widget,
2285            EDITOR_REC_REF  editor_ref,
2286            XtPointer       call_data )
2287 {
2288 
2289   /* Variables. */
2290   int                    index;
2291   XTM_DB_ALL_ENTRY_REF   edit_entry_ref;
2292   XTM_EA_SET_ALARM_DATA  values;
2293 
2294 
2295   /* Code. */
2296 
2297   edit_entry_ref = editor_ref -> edit_entry_ref;
2298 
2299   /* If the window is not created, do it. */
2300   if( editor_ref -> alarm_handle == NULL )
2301     editor_ref -> alarm_handle = xtmEaInitialize( editor_ref -> appl_data_ref,
2302                                                   editor_ref -> editorW,
2303                                                   alarmActionCB,
2304                                                   (void *) editor_ref );
2305 
2306   /* Fill the window with data and display it. */
2307   for( index = 0; index < XTM_EA_MAX_ALARMS; index++ ) {
2308     values.alarm_valid[ index ] =
2309       (Boolean) edit_entry_ref -> entry.alarm_valid[ index ];
2310 
2311     values.alarm_offset[ index ] =
2312       (int) edit_entry_ref -> entry.alarm_offset[ index ];
2313   }
2314 
2315   values.alarm_melody = (int) edit_entry_ref -> entry.alarm_melody;
2316   values.alarm_action = edit_entry_ref -> entry.flags;
2317   values.what_action  = edit_entry_ref -> entry.flags;
2318 
2319   xtmEaEditAlarms( editor_ref -> alarm_handle,
2320                    &values );
2321 
2322 
2323   return;
2324 
2325 } /* alarmCB */
2326 
2327 
2328 /*----------------------------------------------------------------------*/
2329 
2330 static void
alarmActionCB(XTM_EA_REASON reason,void * user_data,XTM_EA_GET_ALARM_DATA * values)2331   alarmActionCB( XTM_EA_REASON          reason,
2332                  void                   *user_data,
2333                  XTM_EA_GET_ALARM_DATA  *values )
2334 {
2335 
2336   /* Variables. */
2337   int                    index;
2338   INT16                  min_offset;
2339   XTM_DB_ALL_ENTRY_REF   edit_entry_ref;
2340   EDITOR_REC_REF         editor_ref;
2341 
2342 
2343   /* Code. */
2344 
2345   if( user_data == NULL )
2346     return;
2347 
2348   /* Our private data. */
2349   editor_ref = (EDITOR_REC_REF) user_data;
2350 
2351   edit_entry_ref = editor_ref -> edit_entry_ref;
2352 
2353 
2354   /* Is the window destroyed? */
2355   if( reason == XTM_EA_REASON_DESTROY ) {
2356     editor_ref -> alarm_handle = NULL;
2357 
2358     return;
2359   }
2360 
2361 
2362   /* OK confirmation? */
2363   if( reason == XTM_EA_REASON_OK ) {
2364 
2365     for( index = 0; index < XTM_EA_MAX_ALARMS; index++ ) {
2366       edit_entry_ref -> entry.alarm_valid[ index ] =
2367         (UINT8) values -> alarm_valid[ index ];
2368 
2369       min_offset = (INT16) values -> alarm_offset[ index ];
2370       edit_entry_ref -> entry.alarm_offset[ index ] = min_offset;
2371     }
2372 
2373     edit_entry_ref -> entry.alarm_melody = (UINT8) values -> alarm_melody;
2374 
2375     flagClear( edit_entry_ref -> entry.flags,
2376                (XTM_DB_FLAG_ACTION_ALARM1 | XTM_DB_FLAG_ACTION_ALARM2 |
2377                 XTM_DB_FLAG_ACTION_ALARM3 | XTM_DB_FLAG_ACTION_ALARM4 |
2378                 XTM_DB_FLAG_ACTION_ALARM5) );
2379 
2380     flagClear( edit_entry_ref -> entry.flags,
2381                (XTM_DB_FLAG_ACTION_SCRIPT | XTM_DB_FLAG_ACTION_TEXT ) );
2382 
2383     flagSet( edit_entry_ref -> entry.flags, values -> alarm_action );
2384     flagSet( edit_entry_ref -> entry.flags, values -> what_action );
2385 
2386   } /* if */
2387 
2388 
2389   return;
2390 
2391 } /* alarmActionCB */
2392 
2393 
2394 /*----------------------------------------------------------------------*/
2395 
2396 static void
applyCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2397   applyCB( Widget          widget,
2398            EDITOR_REC_REF  editor_ref,
2399            XtPointer       call_data )
2400 {
2401 
2402   /* Variables. */
2403   Boolean  ok;
2404   Widget   tempW;
2405 
2406 
2407   /* Code. */
2408 
2409   /* Save the entry. */
2410   ok = saveEntry( editor_ref );
2411   if( ! ok )
2412     return;
2413 
2414   /* Do we have a user action callback registered? */
2415   if( editor_ref -> actionCB != NULL )
2416     (* editor_ref -> actionCB)( XTM_ED_REASON_UPDATE,
2417                                 editor_ref -> user_data );
2418 
2419   /* Make sure the user knows the entry is saved. */
2420   tempW = xitCreateInformationDialog(
2421             editor_ref -> editorW, "InformationDialog",
2422 	    msgGetText( MXDI_INFORMATION_LABEL ),
2423             msgGetText( MXDI_ENTRY_IS_SAVED ),
2424             NULL, NULL );
2425 
2426   XmUpdateDisplay( editor_ref -> editorW );
2427 
2428   /* Update the day list/calendar. */
2429   xtmUpDoUpdate( (XTM_UP_CALENDAR | XTM_UP_SCHEDULE | XTM_UP_PLANNER), NULL );
2430 
2431 
2432   return;
2433 
2434 } /* applyCB */
2435 
2436 
2437 /*----------------------------------------------------------------------*/
2438 
2439 static void
cancelCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2440   cancelCB( Widget          widget,
2441             EDITOR_REC_REF  editor_ref,
2442             XtPointer       call_data )
2443 {
2444 
2445   /* Variables. */
2446   int  index;
2447 
2448 
2449   /* Code. */
2450 
2451   removeEditFile( editor_ref );
2452 
2453   if( editor_ref -> actionCB != NULL )
2454     (* editor_ref -> actionCB)( XTM_ED_REASON_DESTROY,
2455                                 editor_ref -> user_data );
2456 
2457   /* Keep the window in cache? */
2458   for( index = 0; index < MAX_CACHE_ENTRIES; index++ ) {
2459     if( cache_entries[ index ] == NULL ) {
2460       cache_entries[ index ] = editor_ref;
2461 
2462       destroyCB( NULL, editor_ref, NULL );
2463       XtPopdown( editor_ref -> editorW );
2464 
2465       return;
2466     }
2467   }
2468 
2469   /* Window not kept in cache, really remove it. */
2470   XtDestroyWidget( editor_ref -> editorW );
2471 
2472 
2473   return;
2474 
2475 } /* cancelCB */
2476 
2477 
2478 /*----------------------------------------------------------------------*/
2479 
2480 static void
dayViewCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2481   dayViewCB( Widget          widget,
2482              EDITOR_REC_REF  editor_ref,
2483              XtPointer       call_data )
2484 {
2485 
2486   /* Variables. */
2487   Boolean                 ok;
2488   Widget                  mainW;
2489   Widget                  tempW;
2490   TIM_TIME_REF            entry_date;
2491   XTM_GL_BASE_DATA_REF    appl_data_ref;
2492   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
2493   XTM_CD_CAL_INFO         db_info;
2494   XTM_SM_HANDLE           sched_handle;
2495 
2496 
2497   /* Code. */
2498 
2499   appl_data_ref   = editor_ref -> appl_data_ref;
2500   custom_data_ref = appl_data_ref -> custom_data;
2501 
2502 
2503   mainW = XtNameToWidget( editor_ref -> editorW,
2504                           "ApEditorTlBase.ApEditorTlFo" );
2505 
2506   /* Fetch the date we want to use. */
2507   tempW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc.DateEntTb" );
2508 
2509   ok = xtmFoFetchDate( mainW, tempW, XTM_FO_START_DATE, False, &entry_date );
2510   if( ! ok )
2511     return;
2512 
2513 
2514   /* Display the day view for this date. */
2515   ok = xtmSmViewLastUsed( entry_date );
2516   if( ok )
2517     return;
2518 
2519 
2520   /* No previous day view found. */
2521   (void) xtmCdFetchDefaultDb( custom_data_ref -> cal_db_handle,
2522                               &db_info, NULL );
2523 
2524   sched_handle = xtmSmInitialize( appl_data_ref,
2525                                   appl_data_ref -> toplevel,
2526                                   db_info.short_name, NULL,
2527                                   NULL, NULL );
2528 
2529   /* Give an error message if the database could not be opened. */
2530   if( sched_handle == NULL ) {
2531     xitErMessage( NULL, XIT_ER_ERROR,
2532                   module_name, "dayViewCB",
2533                   msgGetText( MXDI_ERRMSG_NO_ACCESS_DB ) );
2534     return;
2535   }
2536 
2537   /* Display the schedule. */
2538   xtmSmViewSchedule( sched_handle, entry_date, False );
2539 
2540 
2541   return;
2542 
2543 } /* dayViewCB */
2544 
2545 
2546 /*----------------------------------------------------------------------*/
2547 
2548 static void
dbChangedCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2549   dbChangedCB( Widget          widget,
2550                EDITOR_REC_REF  editor_ref,
2551                XtPointer       call_data )
2552 {
2553 
2554   /* Variables. */
2555   Boolean                 ok;
2556   char                    *db_name;
2557   Widget                  baseW;
2558   Widget                  mainW;
2559   Widget                  tempW;
2560   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
2561   XTM_CD_CAL_INFO         db_info;
2562 
2563 
2564   /* Code. */
2565 
2566   custom_data_ref = editor_ref -> appl_data_ref -> custom_data;
2567 
2568   mainW = XtNameToWidget( editor_ref -> editorW,
2569                           "ApEditorTlBase.ApEditorTlFo" );
2570 
2571   baseW = XtNameToWidget( mainW, "MiscFo.MiscRc" );
2572 
2573 
2574   /* Fetch the name of the new database (we have write access?). */
2575   tempW = XtNameToWidget( baseW, "DatabaseFs" );
2576   xitFieldSelectGetCurrent( tempW, &db_name );
2577 
2578 
2579   /* Database info. */
2580   ok = xtmCdFetchNamedDb( custom_data_ref -> cal_db_handle, db_name,
2581                           &db_info, NULL );
2582   SysFree( db_name );
2583 
2584   if( ! ok )
2585     return;
2586 
2587   if( ! flagIsSet( db_info.operations, XTM_DB_FLAG_MODE_WRITE ) )
2588     return;
2589 
2590 
2591   /* Can we save as private entry. */
2592   baseW = XtNameToWidget( mainW, "SelFr.SelFo" );
2593   tempW = XtNameToWidget( baseW, "SelPrivateBu" );
2594 
2595   if( ! flagIsSet( db_info.operations, XTM_DB_FLAG_MODE_PRIV ) ) {
2596     XmToggleButtonSetState( tempW, False, False );
2597     XtSetSensitive( tempW, False );
2598   } else {
2599     XtSetSensitive( tempW, True );
2600   }
2601 
2602 
2603   /* We can now save the entry. */
2604   baseW = XtNameToWidget( editor_ref -> editorW, "ApEditorTlBase" );
2605 
2606   tempW = XtNameToWidget( baseW, "Bu1" );
2607   XtMapWidget( tempW );
2608 
2609   tempW = XtNameToWidget( baseW, "Bu3" );
2610   XtMapWidget( tempW );
2611 
2612 
2613   return;
2614 
2615 } /* dbChangedCB */
2616 
2617 
2618 /*----------------------------------------------------------------------*/
2619 
2620 static void
destroyCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2621   destroyCB( Widget          widget,
2622              EDITOR_REC_REF  editor_ref,
2623              XtPointer       call_data )
2624 {
2625 
2626   /* Code. */
2627 
2628   /* Do we have a user action callback registered? */
2629   if( editor_ref -> actionCB != NULL )
2630     (* editor_ref -> actionCB)( XTM_ED_REASON_DESTROY,
2631                                 editor_ref -> user_data );
2632 
2633   /* Remove any editor? */
2634   removeEditFile( editor_ref );
2635 
2636   /* File selection. */
2637   if( editor_ref -> fileSelectW != NULL )
2638     XtDestroyWidget( editor_ref -> fileSelectW );
2639 
2640   /* Release the user data. */
2641   if( editor_ref -> edit_entry_ref != NULL ) {
2642     SysFree( editor_ref -> edit_entry_ref -> all_text );
2643     SysFree( editor_ref -> edit_entry_ref );
2644   }
2645 
2646 
2647   /* Release the user data (only if not cached). */
2648   if( widget != NULL )
2649     SysFree( editor_ref );
2650 
2651 
2652   return;
2653 
2654 } /* destroyCB */
2655 
2656 
2657 /*----------------------------------------------------------------------*/
2658 
2659 static void
editorCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2660   editorCB( Widget          widget,
2661             EDITOR_REC_REF  editor_ref,
2662             XtPointer       call_data )
2663 {
2664 
2665   /* Variables. */
2666   int                     file_ref;
2667   char                    *char_ref;
2668   char                    *command;
2669   char                    *entry_text;
2670   char                    *process_args[ 10 ];
2671   Widget                  mainW;
2672   Widget                  tempW;
2673   XTM_GL_CUSTOM_DATA_REF  custom_data_ref;
2674 
2675 
2676   /* Code. */
2677 
2678   custom_data_ref = editor_ref -> appl_data_ref -> custom_data;
2679 
2680   mainW = XtNameToWidget( editor_ref -> editorW,
2681                           "ApEditorTlBase.ApEditorTlFo" );
2682 
2683   /* Fetch the text we are editing. */
2684   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
2685   entry_text = xitStringGetText( tempW );
2686 
2687 
2688   /* Save the text in a working file. */
2689   char_ref = tmpnam( NULL );
2690   editor_ref -> temp_file = SysNewString( char_ref );
2691 
2692   file_ref = creat( editor_ref -> temp_file, (mode_t) MODE_600 );
2693   if( file_ref < 0 ) {
2694     xitErMessage( editor_ref -> editorW, XIT_ER_ERROR,
2695                   module_name, "editorCB",
2696                   msgGetText( MXDI_CANNOT_WRITE_TMP_FILE ) );
2697 
2698     SysFree( entry_text );
2699     return;
2700   }
2701 
2702   (void) lseek( file_ref, 0, SEEK_SET );
2703   (void) write( file_ref, entry_text, strlen( entry_text ) );
2704   close( file_ref );
2705 
2706   SysFree( entry_text );
2707 
2708 
2709   /* Start the editor with the temporary file. */
2710   command = (char *) SysMalloc( strlen( custom_data_ref -> user_editor ) +
2711                                 strlen( editor_ref -> temp_file ) + 20 );
2712   sprintf( command, custom_data_ref -> user_editor,
2713            editor_ref -> temp_file );
2714 
2715   process_args[ 0 ] = "/bin/sh";
2716   process_args[ 1 ] = "-c";
2717   process_args[ 2 ] = command;
2718   process_args[ 3 ] = NULL;
2719 
2720   editor_ref -> editor_pid = xtmToStartProcess(
2721                                editor_ref -> editorW, True,
2722                                msgGetText( MXDI_STARTING_PROCESS_MSG ),
2723                                process_args );
2724   SysFree( command );
2725 
2726   if( editor_ref -> editor_pid <= 0 )
2727     raise exception;
2728 
2729   /* We want to know when the editor exits. */
2730   editor_ref -> signal_id = SigRegister( SIGCHLD, editor_ref -> editor_pid,
2731                                          userEditorDoneCB, editor_ref );
2732 
2733 
2734   /* Don't call the editor or change the text field. */
2735   tempW = XtNameToWidget( mainW, "ActionRc.EditorPb" );
2736   XtSetSensitive( tempW, False );
2737 
2738   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
2739   XtSetSensitive( tempW, False );
2740 
2741 
2742   return;
2743 
2744 
2745   /* Exception handler. */
2746   exception:
2747 
2748     /* We don't need the temporary file. */
2749     removeEditFile( editor_ref );
2750 
2751     return;
2752 
2753 } /* editorCB */
2754 
2755 
2756 /*----------------------------------------------------------------------*/
2757 
2758 static void
entryTypeCB(Widget widget,EDITOR_REC_REF editor_ref,XmToggleButtonCallbackStruct * call_data)2759   entryTypeCB( Widget                        widget,
2760                EDITOR_REC_REF                editor_ref,
2761                XmToggleButtonCallbackStruct  *call_data )
2762 {
2763 
2764   /* Variables. */
2765   Boolean  clear_time = False;
2766   Widget   baseW;
2767   Widget   mainW;
2768   Widget   tempW;
2769 
2770 
2771   /* Code. */
2772 
2773   /* Only react when buttons are selected. */
2774   if( ! call_data -> set )
2775     return;
2776 
2777 
2778   mainW = XtNameToWidget( editor_ref -> editorW,
2779                           "ApEditorTlBase.ApEditorTlFo" );
2780 
2781   baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TypeRb" );
2782 
2783 
2784   editor_ref -> entry_type = XTM_DB_TYPE_APPOINTMENT;
2785 
2786   tempW = XtNameToWidget( baseW, "TypeStandAppTb" );
2787   if( widget == tempW ) {
2788     editor_ref -> entry_type = XTM_DB_TYPE_STAND_APPOINTMENT;
2789   }
2790 
2791   tempW = XtNameToWidget( baseW, "TypeNoteTb" );
2792   if( widget == tempW ) {
2793     clear_time = True;
2794     editor_ref -> entry_type = XTM_DB_TYPE_NOTE;
2795   }
2796 
2797   tempW = XtNameToWidget( baseW, "TypeStandNoteTb" );
2798   if( widget == tempW ) {
2799     clear_time = True;
2800     editor_ref -> entry_type = XTM_DB_TYPE_STAND_NOTE;
2801   }
2802 
2803   tempW = XtNameToWidget( baseW, "TypeStickyNoteTb" );
2804   if( widget == tempW ) {
2805     clear_time = True;
2806     editor_ref -> entry_type = XTM_DB_TYPE_STICKY_NOTE;
2807   }
2808 
2809   /* Clear the time fields? */
2810   if( clear_time ) {
2811     baseW = XtNameToWidget( mainW, "TimeEntFr.DataEntFo.TimeEntRc" );
2812 
2813     tempW = XtNameToWidget( baseW, "StartEntTb" );
2814     XmUbTimeBoxSetStartTimeString( tempW, "" );
2815 
2816     tempW = XtNameToWidget( baseW, "DurEntFs" );
2817     xitFieldSelectSetCurrent( tempW, "", False );
2818   }
2819 
2820   /* What can we do? */
2821   updateCanDo( editor_ref );
2822 
2823 
2824   return;
2825 
2826 } /* entryTypeCB */
2827 
2828 
2829 /*----------------------------------------------------------------------*/
2830 
2831 static void
includeFileCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)2832   includeFileCB( Widget          widget,
2833                  EDITOR_REC_REF  editor_ref,
2834                  XtPointer       call_data )
2835 {
2836 
2837   /* Variables. */
2838   XIT_FILE_SEL_LABELS  labels;
2839 
2840 
2841   /* Code. */
2842 
2843   /* Do we need to create the dialog? */
2844   if( editor_ref -> fileSelectW == NULL ) {
2845 
2846     labels.dir_list_label       = msgGetText( MXDI_DIRECTORY_LABEL );
2847     labels.file_list_label      = msgGetText( MXDI_FILES_LABEL );
2848     labels.filter_label         = msgGetText( MXDI_FILTER_ACTION_LABEL );
2849     labels.selection_label      = msgGetText( MXDI_SELECTION_LABEL );
2850     labels.cancel_button        = msgGetText( MXDI_CANCEL_BUTTON );
2851     labels.filter_button        = msgGetText( MXDI_FILTER_ACTION_LABEL );
2852     labels.ok_button            = msgGetText( MXDI_OK_BUTTON );
2853     labels.no_file_sel_msg      = msgGetText( MXDI_NO_FILE_SELECTED );
2854     labels.cannot_read_file_msg = msgGetText( MXDI_CANNOT_READ_FILE );
2855 
2856     /* The file selection dialog. */
2857     editor_ref -> fileSelectW =
2858       xitCreateFileSelect( editor_ref -> editorW, "FileSelect",
2859                            0, "", &labels,
2860                            includeFileActionCB, (void *) editor_ref );
2861 
2862   } /* if */
2863 
2864   /* Display the dialog. */
2865   xitFileSelectDisplay( editor_ref -> fileSelectW );
2866 
2867 
2868   return;
2869 
2870 } /* includeFileCB */
2871 
2872 
2873 /*----------------------------------------------------------------------*/
2874 
2875 static void
includeFileActionCB(XIT_FILE_SEL_REASON reason,char * file_name,void * user_data)2876   includeFileActionCB( XIT_FILE_SEL_REASON  reason,
2877                        char                 *file_name,
2878                        void                 *user_data )
2879 {
2880 
2881   /* Variables. */
2882   Widget          mainW;
2883   Widget          tempW;
2884   EDITOR_REC_REF  editor_ref;
2885 
2886 
2887   /* Code. */
2888 
2889   editor_ref = (EDITOR_REC_REF) user_data;
2890 
2891   mainW = XtNameToWidget( editor_ref -> editorW,
2892                           "ApEditorTlBase.ApEditorTlFo" );
2893 
2894   /* Only OK reasons. */
2895   if( reason != XIT_FILE_SELECT_OK )
2896     return;
2897 
2898   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
2899   xitStringSetTextFromFile( tempW, file_name );
2900 
2901 
2902   return;
2903 
2904 } /* includeFileActionCB */
2905 
2906 
2907 /*----------------------------------------------------------------------*/
2908 
2909 static void
helpCB(Widget widget,EDITOR_REC_REF editor_ref,XmRowColumnCallbackStruct * call_data)2910   helpCB( Widget                     widget,
2911           EDITOR_REC_REF             editor_ref,
2912           XmRowColumnCallbackStruct  *call_data )
2913 {
2914 
2915   /* Code. */
2916 
2917   xtmHlDisplayHelp( editor_ref -> appl_data_ref -> info_handle,
2918                     (intptr_t) call_data -> data,
2919                     edit_window_id, "" );
2920 
2921   return;
2922 
2923 } /* helpCB */
2924 
2925 
2926 /*----------------------------------------------------------------------*/
2927 
2928 static void
insertEditedFile(EDITOR_REC_REF editor_ref)2929   insertEditedFile( EDITOR_REC_REF  editor_ref )
2930 {
2931 
2932   /* Variables. */
2933   int          file_ref;
2934   int          status;
2935   char         *char_ref;
2936   Widget       mainW;
2937   Widget       tempW;
2938   struct stat  file_info;
2939 
2940 
2941   /* Code. */
2942 
2943   mainW = XtNameToWidget( editor_ref -> editorW,
2944                           "ApEditorTlBase.ApEditorTlFo" );
2945 
2946   /* Make sure the window is visible. */
2947   XRaiseWindow( XtDisplay( editor_ref -> editorW ),
2948                 XtWindow(  editor_ref -> editorW ) );
2949 
2950   XtMapWidget( editor_ref -> editorW );
2951 
2952 
2953   /* Any temporary file? */
2954   if( editor_ref -> temp_file == NULL )
2955     return;
2956 
2957 
2958   /* We can edit the text field again. */
2959   tempW = XtNameToWidget( mainW, "ActionRc.EditorPb" );
2960   XtSetSensitive( tempW, True );
2961 
2962   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
2963   XtSetSensitive( tempW, True );
2964 
2965 
2966   /* Information about the file. */
2967   status = stat( editor_ref -> temp_file, &file_info );
2968   if( status != 0 )
2969     raise exception;
2970 
2971 
2972   /* Go and get the file. */
2973   file_ref = open( editor_ref -> temp_file, O_RDONLY );
2974   if( file_ref < 0 ) {
2975     xitErMessage( editor_ref -> editorW, XIT_ER_ERROR,
2976                   module_name, "editorCB",
2977                   msgGetText( MXDI_CANNOT_READ_TMP_FILE ) );
2978 
2979     raise exception;
2980   }
2981 
2982   char_ref = (char *) SysMalloc( file_info.st_size + 50 );
2983   (void) read( file_ref, char_ref, file_info.st_size );
2984 
2985   close( file_ref );
2986 
2987   *(char_ref + file_info.st_size) = '\0';
2988 
2989   /* Save the text. */
2990   tempW = XtNameToWidget( mainW, "TextEntTxSW.TextEntTx" );
2991   XmTextSetString( tempW, char_ref );
2992 
2993   SysFree( char_ref );
2994 
2995 
2996   /* We don't need the temporary file. */
2997   removeEditFile( editor_ref );
2998 
2999   return;
3000 
3001 
3002   /* Exception handler. */
3003   exception:
3004 
3005     /* We don't need the temporary file. */
3006     removeEditFile( editor_ref );
3007 
3008     return;
3009 
3010 } /* insertEditedFile */
3011 
3012 
3013 /*----------------------------------------------------------------------*/
3014 
3015 static void
okCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)3016   okCB( Widget          widget,
3017         EDITOR_REC_REF  editor_ref,
3018         XtPointer       call_data )
3019 {
3020 
3021   /* Variables. */
3022   Boolean  ok;
3023 
3024 
3025   /* Code. */
3026 
3027   /* Save the entry. */
3028   ok = saveEntry( editor_ref );
3029   if( ! ok )
3030     return;
3031 
3032   /* Do we have a user action callback registered? */
3033   if( editor_ref -> actionCB != NULL )
3034     (* editor_ref -> actionCB)( XTM_ED_REASON_UPDATE,
3035                                 editor_ref -> user_data );
3036 
3037 
3038   /* Procedd as when cancel. */
3039   cancelCB( widget, editor_ref, NULL );
3040 
3041   XmUpdateDisplay( editor_ref -> editorW );
3042 
3043 
3044   /* Update the day list/calendar. */
3045   xtmUpDoUpdate( (XTM_UP_CALENDAR | XTM_UP_SCHEDULE | XTM_UP_PLANNER), NULL );
3046 
3047 
3048   return;
3049 
3050 } /* okCB */
3051 
3052 
3053 /*----------------------------------------------------------------------*/
3054 
3055 static void
preferencesCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)3056   preferencesCB( Widget          widget,
3057                  EDITOR_REC_REF  editor_ref,
3058                  XtPointer       call_data )
3059 {
3060 
3061   /* Variables. */
3062   XTM_DB_ALL_ENTRY_REF  edit_entry_ref;
3063   XTM_EP_SET_PREF_DATA  values;
3064 
3065 
3066   /* Code. */
3067 
3068   edit_entry_ref = editor_ref -> edit_entry_ref;
3069 
3070   /* If the window is not created, do it. */
3071   if( editor_ref -> pref_handle == NULL )
3072     editor_ref -> pref_handle = xtmEpInitialize( editor_ref -> appl_data_ref,
3073                                                  editor_ref -> editorW,
3074                                                  preferencesActionCB,
3075                                                  (void *) editor_ref );
3076 
3077   /* Fill the window with data and display it. */
3078   values.alarm_lines    = (int) edit_entry_ref -> entry.alarm_lines;
3079   values.day_list_lines = (int) edit_entry_ref -> entry.day_list_lines;
3080   values.bg_color_index = (int) edit_entry_ref -> entry.bg_color_index;
3081   values.fg_color_index = (int) edit_entry_ref -> entry.fg_color_index;
3082   values.flags          = edit_entry_ref -> entry.flags;
3083   values.entry_type     = editor_ref -> entry_type;
3084 
3085   xtmEpEditPreferences( editor_ref -> pref_handle,
3086                         &values );
3087 
3088 
3089   return;
3090 
3091 } /* preferencesCB */
3092 
3093 
3094 /*----------------------------------------------------------------------*/
3095 
3096 static void
preferencesActionCB(XTM_EP_REASON reason,void * user_data,XTM_EP_GET_PREF_DATA * values)3097   preferencesActionCB( XTM_EP_REASON         reason,
3098                        void                  *user_data,
3099                        XTM_EP_GET_PREF_DATA  *values )
3100 {
3101 
3102   /* Variables. */
3103   XTM_DB_ALL_ENTRY_REF  edit_entry_ref;
3104   EDITOR_REC_REF        editor_ref;
3105 
3106 
3107   /* Code. */
3108 
3109   if( user_data == NULL )
3110     return;
3111 
3112   /* Our private data. */
3113   editor_ref = (EDITOR_REC_REF) user_data;
3114 
3115   edit_entry_ref = editor_ref -> edit_entry_ref;
3116 
3117 
3118   /* Is the window destroyed? */
3119   if( reason == XTM_EP_REASON_DESTROY ) {
3120     editor_ref -> pref_handle = NULL;
3121 
3122     return;
3123   }
3124 
3125 
3126   /* OK confirmation? */
3127   if( reason == XTM_EP_REASON_OK ) {
3128 
3129     edit_entry_ref -> entry.alarm_lines    = (UINT8) values -> alarm_lines;
3130     edit_entry_ref -> entry.day_list_lines = (UINT8) values -> day_list_lines;
3131     edit_entry_ref -> entry.bg_color_index = (UINT8) values -> bg_color_index;
3132     edit_entry_ref -> entry.fg_color_index = (UINT8) values -> fg_color_index;
3133 
3134     flagClear( edit_entry_ref -> entry.flags,
3135                (XTM_DB_FLAG_HIDE_IN_CALENDAR |
3136                 XTM_DB_FLAG_HIDE_IN_DAY_VIEW |
3137                 XTM_DB_FLAG_HIDE_IN_SUMMARY |
3138                 XTM_DB_FLAG_HIDE_IN_PRINT |
3139                 XTM_DB_FLAG_HIDE_IN_DUMP |
3140                 XTM_DB_FLAG_HIDE_IN_ALARM |
3141                 XTM_DB_FLAG_ONLY_OWNER_DELETE |
3142                 XTM_DB_FLAG_ONLY_OWNER_CHANGE |
3143                 XTM_DB_FLAG_KEEP_IN_BG |
3144                 XTM_DB_FLAG_KEEP_IN_FG) );
3145 
3146     flagSet( edit_entry_ref -> entry.flags, values -> flags );
3147 
3148   } /* if */
3149 
3150 
3151   return;
3152 
3153 } /* preferencesActionCB */
3154 
3155 
3156 /*----------------------------------------------------------------------*/
3157 
3158 static void
standingCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)3159   standingCB( Widget          widget,
3160               EDITOR_REC_REF  editor_ref,
3161               XtPointer       call_data )
3162 {
3163 
3164   /* Variables. */
3165   int                    index;
3166   XTM_DB_ALL_ENTRY_REF   edit_entry_ref;
3167   XTM_ES_SET_STAND_DATA  values;
3168 
3169 
3170   /* Code. */
3171 
3172   editor_ref -> standing_seen = True;
3173 
3174   edit_entry_ref = editor_ref -> edit_entry_ref;
3175 
3176 
3177   /* If the window is not created, do it. */
3178   if( editor_ref -> stand_handle == NULL )
3179     editor_ref -> stand_handle = xtmEsInitialize( editor_ref -> appl_data_ref,
3180                                                   editor_ref -> editorW,
3181                                                   standingActionCB,
3182                                                   (void *) editor_ref );
3183 
3184   /* Fill the window with data and display it. */
3185   for( index = 0; index < 7; index++ )
3186     values.valid_days[ index ] =
3187       (Boolean) edit_entry_ref -> stand_entry.valid_days[ index ];
3188 
3189   values.every_n     = (int) edit_entry_ref -> stand_entry.every_n;
3190   values.valid_every = (int) edit_entry_ref -> stand_entry.valid_every;
3191 
3192   values.from = (TIM_TIME_REF) edit_entry_ref -> stand_entry.from;
3193   values.to   = (TIM_TIME_REF) edit_entry_ref -> stand_entry.to;
3194 
3195   values.flags          = edit_entry_ref -> stand_entry.flags;
3196   values.skip_week[ 0 ] = edit_entry_ref -> stand_entry.skip_week[ 0 ];
3197   values.skip_week[ 1 ] = edit_entry_ref -> stand_entry.skip_week[ 1 ];
3198 
3199   values.default_date = editor_ref -> default_date;
3200   values.entry_type   = editor_ref -> entry_type;
3201 
3202   xtmEsEditStanding( editor_ref -> stand_handle, &values );
3203 
3204 
3205   return;
3206 
3207 } /* standingCB */
3208 
3209 
3210 /*----------------------------------------------------------------------*/
3211 
3212 static void
standingActionCB(XTM_ES_REASON reason,void * user_data,XTM_ES_GET_STAND_DATA * values)3213   standingActionCB( XTM_ES_REASON          reason,
3214                     void                   *user_data,
3215                     XTM_ES_GET_STAND_DATA  *values )
3216 {
3217 
3218   /* Variables. */
3219   int                  index;
3220   XTM_DB_ALL_ENTRY_REF edit_entry_ref;
3221   EDITOR_REC_REF       editor_ref;
3222 
3223 
3224   /* Code. */
3225 
3226   if( user_data == NULL )
3227     return;
3228 
3229   /* Our private data. */
3230   editor_ref = (EDITOR_REC_REF) user_data;
3231 
3232   edit_entry_ref = editor_ref -> edit_entry_ref;
3233 
3234 
3235   /* Is the window destroyed? */
3236   if( reason == XTM_ES_REASON_DESTROY ) {
3237     editor_ref -> stand_handle = NULL;
3238 
3239     return;
3240   }
3241 
3242 
3243   /* OK confirmation? */
3244   if( reason == XTM_ES_REASON_OK ) {
3245 
3246     for( index = 0; index < 7; index++ )
3247       edit_entry_ref -> stand_entry.valid_days[ index ] =
3248         (UINT8) values -> valid_days[ index ];
3249 
3250     edit_entry_ref -> stand_entry.every_n     = (UINT16) values -> every_n;
3251     edit_entry_ref -> stand_entry.valid_every = (UINT8)  values -> valid_every;
3252 
3253     edit_entry_ref -> stand_entry.from = (UINT32) values -> from;
3254     edit_entry_ref -> stand_entry.to   = (UINT32) values -> to;
3255 
3256     edit_entry_ref -> stand_entry.flags          = values -> flags;
3257     edit_entry_ref -> stand_entry.skip_week[ 0 ] = values -> skip_week[ 0 ];
3258     edit_entry_ref -> stand_entry.skip_week[ 1 ] = values -> skip_week[ 1 ];
3259 
3260   } /* if */
3261 
3262 
3263   return;
3264 
3265 } /* standingActionCB */
3266 
3267 
3268 /*----------------------------------------------------------------------*/
3269 
3270 static void
timeFieldChangedCB(Widget widget,EDITOR_REC_REF editor_ref,XtPointer call_data)3271   timeFieldChangedCB( Widget          widget,
3272                       EDITOR_REC_REF  editor_ref,
3273                       XtPointer       call_data )
3274 {
3275 
3276   /* Code. */
3277 
3278   writeEntryDate( editor_ref );
3279 
3280 
3281   return;
3282 
3283 } /* timeFieldChangedCB */
3284 
3285 
3286 /*----------------------------------------------------------------------*/
3287 
3288 static void
userEditorDoneCB(int signal,void * user_data)3289   userEditorDoneCB( int   signal,
3290                     void  *user_data )
3291 {
3292 
3293   /* Variables. */
3294   EDITOR_REC_REF  editor_ref;
3295 
3296 
3297   /* Code. */
3298 
3299   editor_ref = (EDITOR_REC_REF) user_data;
3300 
3301   /* No signal notifications any more. */
3302   SigRemove( editor_ref -> signal_id );
3303 
3304   /* Start a 'NULL' timer to do the update. */
3305   if( editor_ref -> editor_pid != 0 )
3306     XtAppAddTimeOut( editor_ref -> appl_data_ref -> context, 0,
3307                      (XtTimerCallbackProc) insertEditedFile,
3308                      (XtPointer) editor_ref );
3309 
3310   editor_ref -> editor_pid = 0;
3311 
3312 
3313   return;
3314 
3315 } /* userEditorDoneCB */
3316