File: xxTimestamp.cc

package info (click to toggle)
xtide 2.6.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,996 kB
  • ctags: 2,617
  • sloc: cpp: 26,266; ansic: 8,105; makefile: 152; yacc: 113; sh: 54; lex: 54
file content (137 lines) | stat: -rw-r--r-- 4,356 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// $Id: xxTimestamp.cc,v 1.2 2003/01/17 17:31:00 flaterco Exp $
/*  xxTimestamp  Get a Timestamp from the user.

    Copyright (C) 1998  David Flater.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "xtide.hh"

void
xxTimestampCallback (Widget w, XtPointer client_data, XtPointer call_data) {
  xxTimestamp *e = (xxTimestamp *)client_data;
  Dstr time_string;
  e->mydialog->val (time_string);
  Timestamp t (time_string, e->timezone, e->xtidecontext->settings);
  if (t.isNull()) {
    Dstr details ("The offending input was ");
    details += time_string;
    details += "\nin the time zone ";
    if (e->xtidecontext->settings->z == "n")
      details += e->timezone;
    else
      details += "UTC0";
    barf (MKTIME_FAILED, details, 0);
  } else {
    (*(e->timestampcallback)) (t, e->ptr);
  }
  delete e;
}

static void
xxTimestampCancelCallback (Widget w, XtPointer client_data, XtPointer
call_data) {
  xxTimestamp *e = (xxTimestamp *)client_data;
  e->dismiss();
}

void
xxTimestamp::dismiss() {
  delete this;
}

xxTimestamp::~xxTimestamp() {
  mypopup->unrealize();
  delete helplabel;
  delete gobutton;
  delete cancelbutton;
  delete mydialog;
  delete spacelabel1;
}

xxTimestamp::xxTimestamp (xxTideContext *in_xtidecontext, xxContext *context,
     void (*in_timestampcallback) (Timestamp t, void *in_ptr),
     void *in_ptr, Timestamp init, const Dstr &in_timezone):
xxWindow (in_xtidecontext, context, 1, XtGrabExclusive) {
  assert (!(init.isNull()));

  ptr = in_ptr;
  timestampcallback = in_timestampcallback;
  timezone = in_timezone;

  mypopup->setTitle ("Select Time");

  Arg labelargs[3] =  {
    {XtNbackground, (XtArgVal)mypopup->pixels[Colors::background]},
    {XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]},
    {XtNborderWidth, (XtArgVal)0}
  };
  Arg buttonargs[4] =  {
    {XtNvisual, (XtArgVal)mypopup->visual},
    {XtNcolormap, (XtArgVal)mypopup->colormap},
    {XtNbackground, (XtArgVal)mypopup->pixels[Colors::button]},
    {XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]}
  };
#if 0
  Arg smallbuttonargs[6] =  {
    {XtNvisual, (XtArgVal)mypopup->visual},
    {XtNcolormap, (XtArgVal)mypopup->colormap},
    {XtNbackground, (XtArgVal)mypopup->pixels[Colors::button]},
    {XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]},
    {XtNfont, (XtArgVal)mypopup->tinyfontstruct},
    {XtNvertSpace, (XtArgVal)0}
  };
#endif

  {
    Dstr f;
    f = "Adjust year, month, day, hours, and minutes to desired time in time\n\
zone ";
    if (in_xtidecontext->settings->z == "n")
      f += in_timezone;
    else
      f += "UTC0";
    f += " using 24-hour notation instead of AM/PM.";
    Widget labelwidget = XtCreateManagedWidget (f.aschar(), labelWidgetClass,
      container->manager, labelargs, 3);
    helplabel = new xxContext (mypopup, labelwidget);
  }

  mydialog = new xxTimestampDialog (xtidecontext, container, "Set:",
    init, timezone);

  {
    Widget labelwidget = XtCreateManagedWidget ("  ", labelWidgetClass,
      container->manager, labelargs, 3);
    spacelabel1 = new xxContext (mypopup, labelwidget);
  }
  {
    Widget buttonwidget = XtCreateManagedWidget ("Go", commandWidgetClass,
      container->manager, buttonargs, 4);
    XtAddCallback (buttonwidget, XtNcallback, xxTimestampCallback,
     (XtPointer)this);
    gobutton = new xxContext (mypopup, buttonwidget);
  }
  {
    Widget buttonwidget = XtCreateManagedWidget ("Cancel", commandWidgetClass,
      container->manager, buttonargs, 4);
    XtAddCallback (buttonwidget, XtNcallback, xxTimestampCancelCallback,
      (XtPointer)this);
    cancelbutton = new xxContext (mypopup, buttonwidget);
  }

  mypopup->realize();
}