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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
|
// $Id: xxDrawable.cc,v 1.3 2003/02/11 21:25:10 flaterco Exp $
/* xxDrawable Abstract class for all tide-predicting windows.
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"
xxDrawable::xxDrawable (xxTideContext *in_tidecontext, xxContext
*in_xxcontext, Station *in_station, int needcontainer):
xxWindow (in_tidecontext, in_xxcontext, needcontainer) {
assert (station = in_station);
savebutton = markbutton = helpbutton = dismissbutton =
optionsbutton = optionsmenu = graphbutton = textbutton =
rawbutton = mediumrarebutton =
aspectbutton = clockbutton = chooserbutton = timestampbutton =
unitsbutton = rootbutton = stepbutton = NULL;
}
xxDrawable::~xxDrawable() {
// Station might have been "stolen"
if (station) {
if (station->is_reference_station()) {
ReferenceStation *r = (ReferenceStation *)station;
delete r;
} else {
SubordinateStation *r = (SubordinateStation *)station;
delete r;
}
}
mypopup->unrealize();
if (savebutton)
delete savebutton;
if (markbutton)
delete markbutton;
if (unitsbutton)
delete unitsbutton;
if (timestampbutton)
delete timestampbutton;
if (helpbutton)
delete helpbutton;
if (dismissbutton)
delete dismissbutton;
if (graphbutton)
delete graphbutton;
if (textbutton)
delete textbutton;
if (rawbutton)
delete rawbutton;
if (mediumrarebutton)
delete mediumrarebutton;
if (aspectbutton)
delete aspectbutton;
if (stepbutton)
delete stepbutton;
if (clockbutton)
delete clockbutton;
if (chooserbutton)
delete chooserbutton;
if (rootbutton)
delete rootbutton;
if (optionsbutton)
delete optionsbutton;
if (optionsmenu)
delete optionsmenu;
}
static void
dismissCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->dismiss();
}
static void
helpCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->help();
}
static void
saveCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->save();
}
static void
markCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->mark();
}
static void
unitsCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
if (d->station) {
PredictionValue::Unit u = d->station->myUnits;
switch (u.mytype) {
case PredictionValue::Unit::Feet:
u.mytype = PredictionValue::Unit::Meters;
break;
case PredictionValue::Unit::Meters:
u.mytype = PredictionValue::Unit::Feet;
break;
default:
assert (0);
}
d->station->setUnits (u);
}
d->redraw();
}
static void
timestampCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->timestamp();
}
static void
aspectCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->aspect();
}
static void
stepCallback (Widget w, XtPointer client_data, XtPointer call_data) {
((xxDrawable*)client_data)->step();
}
void
xxDrawableGraphCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
if (d->station)
d->xtidecontext->root->newGraph (d->station->clone(), d->t);
}
void
xxDrawableTextCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
if (d->station)
d->xtidecontext->root->newText (d->station->clone(), d->t);
}
void
xxDrawableRawCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
if (d->station)
d->xtidecontext->root->newRaw (d->station->clone(), d->t);
}
void
xxDrawableMediumRareCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
if (d->station)
d->xtidecontext->root->newMediumRare (d->station->clone(), d->t);
}
void
xxDrawableClockCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
if (d->station)
d->xtidecontext->root->newClock (d->station->clone());
}
void
xxDrawableChooserCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
// If it has to index, this could take a while, and somebody might close
// the window before this callback returns, resulting in a seggie. So
// stifle such attempts.
d->noclose = 1;
d->xtidecontext->root->newChooser ();
d->noclose = 0;
}
void
xxDrawableControlPanelCallback (Widget w, XtPointer client_data, XtPointer call_data) {
xxDrawable *d = ((xxDrawable*)client_data);
d->xtidecontext->root->show ();
}
void
xxDrawableMarkCallback (PredictionValue *marklevel, void *in_ptr) {
xxDrawable *d = (xxDrawable *)in_ptr;
if (d->station->markLevel)
delete d->station->markLevel;
d->station->markLevel = marklevel;
d->redraw();
}
void xxDrawableTimestampCallback (Timestamp t, void *in_ptr) {
xxDrawable *d = (xxDrawable *)in_ptr;
d->t = t;
d->redraw();
}
void
xxDrawableAspectCallback (double aspect, void *in_ptr) {
assert (aspect > 0.0);
xxDrawable *d = (xxDrawable *)in_ptr;
d->station->aspect = aspect;
d->redraw();
}
void
xxDrawableStepCallback (Interval step, void *in_ptr) {
assert (step > Interval (0));
xxDrawable *d = (xxDrawable *)in_ptr;
d->station->step = step;
d->redraw();
}
void xxDrawable::mark() {
char temp[80];
if (station->markLevel)
sprintf (temp, "%f", station->markLevel->val());
else
strcpy (temp, "-0.25");
(void) new xxMarkLevel (xtidecontext, mypopup, xxDrawableMarkCallback, this,
station->constants->datum().Units(), temp);
}
void xxDrawable::timestamp() {
assert (!is_clock());
assert (station);
(void) new xxTimestamp (xtidecontext, mypopup, xxDrawableTimestampCallback, this, t,
station->timeZone);
}
void xxDrawable::aspect() {
char temp[80];
sprintf (temp, "%f", station->aspect);
(void) new xxAspect (xtidecontext, mypopup, xxDrawableAspectCallback, this, temp);
}
void xxDrawable::step() {
(void) new xxStep (xtidecontext, mypopup, xxDrawableStepCallback, this,
station->step);
}
void xxDrawable::addNormalButtons (Widget below_this, Widget beside_this) {
assert (mypopup);
assert (container);
Arg boxbuttonargs[5] = {
{XtNvisual, (XtArgVal)mypopup->visual},
{XtNcolormap, (XtArgVal)mypopup->colormap},
{XtNbackground, (XtArgVal)mypopup->pixels[Colors::button]},
{XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]},
{"menuName", (XtArgVal)"optionsmenu"}
};
Arg formbuttonargs[11] = {
{XtNfromHoriz, (XtArgVal)beside_this},
{XtNfromVert, (XtArgVal)below_this},
{XtNvisual, (XtArgVal)mypopup->visual},
{XtNcolormap, (XtArgVal)mypopup->colormap},
{XtNbackground, (XtArgVal)mypopup->pixels[Colors::button]},
{XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]},
{XtNleft, (XtArgVal)XawChainLeft},
{XtNright, (XtArgVal)XawChainLeft},
{XtNtop, (XtArgVal)XawChainBottom},
{XtNbottom, (XtArgVal)XawChainBottom},
{"menuName", (XtArgVal)"optionsmenu"}
};
// To avoid having to repeat all those args several times,
// XtNfromHoriz gets overwritten and the last one is only used for
// the options button (by diddling the length passed to
// XtCreateManagedWidget).
Arg *buttonargs;
int numbuttonargs;
if (containertype == 1) {
buttonargs = boxbuttonargs;
numbuttonargs = 4;
} else {
buttonargs = formbuttonargs;
numbuttonargs = 10;
}
// The options menu
{
Widget optionsbuttonwidget = XtCreateManagedWidget ("Options",
menuButtonWidgetClass, container->manager, buttonargs, numbuttonargs+1);
optionsbutton = new xxContext (mypopup, optionsbuttonwidget);
formbuttonargs[0].value = (XtArgVal)optionsbuttonwidget;
}
{
Widget menushell = XtCreatePopupShell ("optionsmenu",
simpleMenuWidgetClass, optionsbutton->manager, buttonargs, numbuttonargs);
optionsmenu = new xxContext (mypopup, menushell);
}
// Buttons on the options menu
{
Widget buttonwidget = XtCreateManagedWidget ("Save", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, saveCallback, (XtPointer)this);
savebutton = new xxContext (mypopup, buttonwidget);
}
if (!(is_rare())) {
// While we're waiting for goto to come back into style...
while (station) {
// Mark doesn't work in the really hairy cases, so don't offer them
// a button.
if (!(station->is_reference_station())) {
SubordinateStation *sb = (SubordinateStation *)station;
if (sb->residualOffsets)
break;
}
Widget buttonwidget = XtCreateManagedWidget ("Set Mark", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, markCallback, (XtPointer)this);
markbutton = new xxContext (mypopup, buttonwidget);
break;
}
}
if (station) {
if (!(station->isCurrent)) {
Widget buttonwidget = XtCreateManagedWidget ("Convert ft<->m", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, unitsCallback, (XtPointer)this);
unitsbutton = new xxContext (mypopup, buttonwidget);
}
}
if (!(is_clock())) {
Widget buttonwidget = XtCreateManagedWidget ("Set Time", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, timestampCallback, (XtPointer)this);
timestampbutton = new xxContext (mypopup, buttonwidget);
}
if (is_graph()) {
Widget buttonwidget = XtCreateManagedWidget ("Set Aspect", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, aspectCallback, (XtPointer)this);
aspectbutton = new xxContext (mypopup, buttonwidget);
}
if (is_rare()) {
Widget buttonwidget = XtCreateManagedWidget ("Set Step", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, stepCallback, (XtPointer)this);
stepbutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("New Graph Window", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableGraphCallback, (XtPointer)this);
graphbutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("New Text Window", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableTextCallback, (XtPointer)this);
textbutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("New Raw Mode Window", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableRawCallback, (XtPointer)this);
rawbutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("New Medium Rare Mode Window", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableMediumRareCallback, (XtPointer)this);
mediumrarebutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("New Clock Window", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableClockCallback, (XtPointer)this);
clockbutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("New Location Chooser", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableChooserCallback, (XtPointer)this);
chooserbutton = new xxContext (mypopup, buttonwidget);
}
{
Widget buttonwidget = XtCreateManagedWidget ("Control Panel", smeBSBObjectClass,
optionsmenu->manager, boxbuttonargs, 4);
XtAddCallback (buttonwidget, XtNcallback, xxDrawableControlPanelCallback, (XtPointer)this);
rootbutton = new xxContext (mypopup, buttonwidget);
}
// Top level buttons
{
Widget buttonwidget = XtCreateManagedWidget ("Dismiss", commandWidgetClass,
container->manager, buttonargs, numbuttonargs);
XtAddCallback (buttonwidget, XtNcallback, dismissCallback,
(XtPointer)this);
dismissbutton = new xxContext (mypopup, buttonwidget);
formbuttonargs[0].value = (XtArgVal)buttonwidget;
}
{
Widget buttonwidget = XtCreateManagedWidget ("?", commandWidgetClass,
container->manager, buttonargs, numbuttonargs);
XtAddCallback (buttonwidget, XtNcallback, helpCallback,
(XtPointer)this);
helpbutton = new xxContext (mypopup, buttonwidget);
}
}
int
xxDrawable::is_graph() {
return 0;
}
int
xxDrawable::is_clock() {
return 0;
}
int
xxDrawable::is_rare() {
return 0;
}
void xxDrawable::global_redraw() {
xxWindow::global_redraw();
if (station) {
// 2003-02-11
// Applying and unapplying the Infer setting necessitates
// reloading of stations. Here we are relying on the fact that
// Station::clone does a reload rather than just copy memory.
// Danger...
Station *delme = station;
station = delme->clone();
delete delme;
if (!(xtidecontext->settings->u.isNull())) {
if (xtidecontext->settings->u != "x") {
PredictionValue::Unit u (xtidecontext->settings->u);
station->setUnits (u);
}
}
}
redraw();
Arg buttonargs[2] = {
{XtNbackground, (XtArgVal)mypopup->pixels[Colors::button]},
{XtNforeground, (XtArgVal)mypopup->pixels[Colors::foreground]}
};
if (optionsbutton)
XtSetValues (optionsbutton->manager, buttonargs, 2);
if (optionsmenu)
XtSetValues (optionsmenu->manager, buttonargs, 2);
if (savebutton)
XtSetValues (savebutton->manager, buttonargs, 2);
if (markbutton)
XtSetValues (markbutton->manager, buttonargs, 2);
if (unitsbutton)
XtSetValues (unitsbutton->manager, buttonargs, 2);
if (timestampbutton)
XtSetValues (timestampbutton->manager, buttonargs, 2);
if (aspectbutton)
XtSetValues (aspectbutton->manager, buttonargs, 2);
if (stepbutton)
XtSetValues (stepbutton->manager, buttonargs, 2);
if (graphbutton)
XtSetValues (graphbutton->manager, buttonargs, 2);
if (textbutton)
XtSetValues (textbutton->manager, buttonargs, 2);
if (rawbutton)
XtSetValues (rawbutton->manager, buttonargs, 2);
if (mediumrarebutton)
XtSetValues (mediumrarebutton->manager, buttonargs, 2);
if (clockbutton)
XtSetValues (clockbutton->manager, buttonargs, 2);
if (chooserbutton)
XtSetValues (chooserbutton->manager, buttonargs, 2);
if (rootbutton)
XtSetValues (rootbutton->manager, buttonargs, 2);
if (dismissbutton)
XtSetValues (dismissbutton->manager, buttonargs, 2);
if (helpbutton)
XtSetValues (helpbutton->manager, buttonargs, 2);
}
|