1 // $Id: xxTimestamp.cc 4497 2012-05-27 00:33:09Z flaterco $
2 
3 /*  xxTimestamp  Get a Timestamp from the user.  If successful, pass it
4     to caller.timestamp (newTime).
5 
6     Copyright (C) 1998  David Flater.
7 
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "xtide.hh"
23 #include "xxMultiChoice.hh"
24 #include "xxTimestampDialog.hh"
25 #include "xxTimestamp.hh"
26 
27 
xxTimestampCallback(Widget w unusedParameter,XtPointer client_data,XtPointer call_data unusedParameter)28 static void xxTimestampCallback (Widget w unusedParameter,
29 				 XtPointer client_data,
30 				 XtPointer call_data unusedParameter) {
31   assert (client_data);
32   xxTimestamp *timestamp ((xxTimestamp *)client_data);
33   timestamp->callback();
34   delete timestamp->dismiss();
35 }
36 
37 
callback()38 void xxTimestamp::callback() {
39   Dstr timeString;
40   dialog->val (timeString);
41   Timestamp t (timeString, _timezone);
42   if (t.isNull())
43     Global::cant_mktime (timeString, _timezone, Error::nonfatal);
44   else
45     _caller.timestamp (t);
46 }
47 
48 
xxTimestampCancelCallback(Widget w unusedParameter,XtPointer client_data,XtPointer call_data unusedParameter)49 static void xxTimestampCancelCallback (Widget w unusedParameter,
50 				       XtPointer client_data,
51 				       XtPointer call_data unusedParameter) {
52   assert (client_data);
53   delete ((xxTimestamp *)client_data)->dismiss();
54 }
55 
56 
~xxTimestamp()57 xxTimestamp::~xxTimestamp() {
58   unrealize();
59   _caller.noClose = false;
60 }
61 
62 
xxTimestamp(const xxWidget & parent,xxPredictionWindow & caller,Timestamp initTime,const Dstr & timezone)63 xxTimestamp::xxTimestamp (const xxWidget &parent,
64 			  xxPredictionWindow &caller,
65 			  Timestamp initTime,
66 			  const Dstr &timezone):
67   xxWindow (parent, boxContainer, XtGrabExclusive),
68   _caller(caller),
69   _timezone(timezone) {
70   _caller.noClose = true;
71 
72   assert (!initTime.isNull());
73 
74   setTitle ("Select Time");
75 
76   Arg labelArgs[3] =  {
77     {XtNbackground, (XtArgVal)xxX::pixels[Colors::background]},
78     {XtNforeground, (XtArgVal)xxX::pixels[Colors::foreground]},
79     {XtNborderWidth, (XtArgVal)0}
80   };
81   Arg buttonArgs[4] =  {
82     {XtNvisual, (XtArgVal)xxX::visual},
83     {XtNcolormap, (XtArgVal)xxX::colormap},
84     {XtNbackground, (XtArgVal)xxX::pixels[Colors::button]},
85     {XtNforeground, (XtArgVal)xxX::pixels[Colors::foreground]}
86   };
87 
88   {
89     Dstr f ("Adjust year, month, day, hours, and minutes to desired time in time\n\
90 zone ");
91     if (Global::settings["z"].c == 'n')
92       f += _timezone;
93     else
94       f += "UTC0";
95     f += " using 24-hour notation instead of AM/PM.";
96     Widget labelWidget = xxX::createXtWidget (f.aschar(), labelWidgetClass,
97       container->widget(), labelArgs, 3);
98     helpLabel = xxX::wrap (labelWidget);
99   }
100 
101   dialog = std::auto_ptr<xxTimestampDialog> (new xxTimestampDialog (
102 								   *container,
103 								   "Set:",
104 								   initTime,
105 								   _timezone));
106   {
107     Widget labelWidget = xxX::createXtWidget ("  ", labelWidgetClass,
108       container->widget(), labelArgs, 3);
109     spaceLabel = xxX::wrap (labelWidget);
110   }{
111     Widget buttonWidget = xxX::createXtWidget ("Go", commandWidgetClass,
112       container->widget(), buttonArgs, 4);
113     XtAddCallback (buttonWidget, XtNcallback, xxTimestampCallback,
114      (XtPointer)this);
115     goButton = xxX::wrap (buttonWidget);
116   }{
117     Widget buttonWidget = xxX::createXtWidget ("Cancel", commandWidgetClass,
118       container->widget(), buttonArgs, 4);
119     XtAddCallback (buttonWidget, XtNcallback, xxTimestampCancelCallback,
120       (XtPointer)this);
121     cancelButton = xxX::wrap (buttonWidget);
122   }
123 
124   realize();
125 }
126 
127 // Cleanup2006 Done
128