testcalendar.c 21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* example-start calendar calendar.c */
/*
 * Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson, Mattias Grnlund
 * Copyright (C) 2000 Tony Gale
 *
 * 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.
 */

21
#include "config.h"
22 23
#include <stdio.h>
#include <string.h>
Manish Singh's avatar
Manish Singh committed
24
#include <gtk/gtk.h>
25

26 27
#define DEF_PAD 12
#define DEF_PAD_SMALL 6
28 29 30

#define TM_YEAR_BASE 1900

31 32
typedef struct _CalendarData
{
33 34 35
  GtkWidget *calendar_widget;
  GtkWidget *flag_checkboxes[6];
  gboolean  settings[6];
36 37 38 39 40 41
  GtkWidget *font_dialog;
  GtkWidget *window;
  GtkWidget *prev2_sig;
  GtkWidget *prev_sig;
  GtkWidget *last_sig;
  GtkWidget *month;
42 43 44 45

  GHashTable    *details_table;
  GtkTextBuffer *details_buffer;
  guint          details_changed;
46 47
} CalendarData;

48 49
enum
{
50 51 52 53 54 55 56 57 58 59 60
  calendar_show_header,
  calendar_show_days,
  calendar_month_change, 
  calendar_show_week,
  calendar_monday_first
};

/*
 * GtkCalendar
 */

61 62
static void
calendar_date_to_string (CalendarData *data,
63
			      char         *buffer,
Manish Singh's avatar
Manish Singh committed
64
			      gint          buff_len)
65
{
66 67
  GDate *date;
  guint year, month, day;
68

69 70 71 72 73 74
  gtk_calendar_get_date (GTK_CALENDAR(data->window),
			 &year, &month, &day);
  date = g_date_new_dmy (day, month + 1, year);
  g_date_strftime (buffer, buff_len-1, "%x", date);

  g_date_free (date);
75 76
}

77 78 79 80 81 82 83 84 85 86 87
static void
calendar_set_detail (CalendarData *data,
                     guint         year,
                     guint         month,
                     guint         day,
                     gchar        *detail)
{
  gchar *key = g_strdup_printf ("%04d-%02d-%02d", year, month + 1, day);
  g_hash_table_replace (data->details_table, key, detail);
}

88
static gchar*
89 90 91 92 93 94 95 96 97 98 99 100
calendar_get_detail (CalendarData *data,
                     guint         year,
                     guint         month,
                     guint         day)
{
  const gchar *detail;
  gchar *key;

  key = g_strdup_printf ("%04d-%02d-%02d", year, month + 1, day);
  detail = g_hash_table_lookup (data->details_table, key);
  g_free (key);

101
  return (detail ? g_strdup (detail) : NULL);
102 103 104 105 106 107
}

static void
calendar_update_details (CalendarData *data)
{
  guint year, month, day;
108
  gchar *detail;
109 110 111 112 113 114 115

  gtk_calendar_get_date (GTK_CALENDAR (data->calendar_widget), &year, &month, &day);
  detail = calendar_get_detail (data, year, month, day);

  g_signal_handler_block (data->details_buffer, data->details_changed);
  gtk_text_buffer_set_text (data->details_buffer, detail ? detail : "", -1);
  g_signal_handler_unblock (data->details_buffer, data->details_changed);
116 117

  g_free (detail);
118 119 120 121
}

static void
calendar_set_signal_strings (char         *sig_str,
122 123
				  CalendarData *data)
{
Manish Singh's avatar
Manish Singh committed
124
  const gchar *prev_sig;
125

Manish Singh's avatar
Manish Singh committed
126
  prev_sig = gtk_label_get_text (GTK_LABEL (data->prev_sig));
127 128
  gtk_label_set_text (GTK_LABEL (data->prev2_sig), prev_sig);

Manish Singh's avatar
Manish Singh committed
129
  prev_sig = gtk_label_get_text (GTK_LABEL (data->last_sig));
130 131 132 133
  gtk_label_set_text (GTK_LABEL (data->prev_sig), prev_sig);
  gtk_label_set_text (GTK_LABEL (data->last_sig), sig_str);
}

134 135
static void
calendar_month_changed (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
136
                             CalendarData *data)
137 138 139 140 141 142 143
{
  char buffer[256] = "month_changed: ";

  calendar_date_to_string (data, buffer+15, 256-15);
  calendar_set_signal_strings (buffer, data);
}

144 145
static void
calendar_day_selected (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
146
                            CalendarData *data)
147 148 149 150 151
{
  char buffer[256] = "day_selected: ";

  calendar_date_to_string (data, buffer+14, 256-14);
  calendar_set_signal_strings (buffer, data);
152 153

  calendar_update_details (data);
154 155
}

156 157
static void
calendar_day_selected_double_click (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
158
                                         CalendarData *data)
159 160
{
  char buffer[256] = "day_selected_double_click: ";
161
  guint day;
162 163 164 165

  calendar_date_to_string (data, buffer+27, 256-27);
  calendar_set_signal_strings (buffer, data);

Manish Singh's avatar
Manish Singh committed
166
  gtk_calendar_get_date (GTK_CALENDAR (data->window),
167
			 NULL, NULL, &day);
168

169 170
  if (GTK_CALENDAR (data->window)->marked_date[day-1] == 0) {
    gtk_calendar_mark_day (GTK_CALENDAR (data->window), day);
171
  } else { 
172
    gtk_calendar_unmark_day (GTK_CALENDAR (data->window), day);
173 174 175
  }
}

176 177
static void
calendar_prev_month (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
178
                          CalendarData *data)
179 180 181 182 183 184 185
{
  char buffer[256] = "prev_month: ";

  calendar_date_to_string (data, buffer+12, 256-12);
  calendar_set_signal_strings (buffer, data);
}

186 187 188
static void
calendar_next_month (GtkWidget    *widget,
                     CalendarData *data)
189 190 191 192 193 194 195
{
  char buffer[256] = "next_month: ";

  calendar_date_to_string (data, buffer+12, 256-12);
  calendar_set_signal_strings (buffer, data);
}

196 197 198
static void
calendar_prev_year (GtkWidget    *widget,
                    CalendarData *data)
199 200 201 202 203 204 205
{
  char buffer[256] = "prev_year: ";

  calendar_date_to_string (data, buffer+11, 256-11);
  calendar_set_signal_strings (buffer, data);
}

206 207 208
static void
calendar_next_year (GtkWidget    *widget,
                    CalendarData *data)
209 210 211 212 213 214 215 216
{
  char buffer[256] = "next_year: ";

  calendar_date_to_string (data, buffer+11, 256-11);
  calendar_set_signal_strings (buffer, data);
}


217 218
static void
calendar_set_flags (CalendarData *calendar)
219
{
220 221 222
  gint options = 0, i;

  for (i = 0; i < G_N_ELEMENTS (calendar->settings); i++)
223
    if (calendar->settings[i])
224 225
      options=options + (1 << i);

226
  if (calendar->window)
Matthias Clasen's avatar
Matthias Clasen committed
227
    gtk_calendar_set_display_options (GTK_CALENDAR (calendar->window), options);
228 229
}

230 231 232
static void
calendar_toggle_flag (GtkWidget    *toggle,
                      CalendarData *calendar)
233 234
{
  gint i;
235 236

  for (i = 0; i < G_N_ELEMENTS (calendar->flag_checkboxes); i++)
237
    if (calendar->flag_checkboxes[i] == toggle)
238
      calendar->settings[i] = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle));
239 240 241 242 243

  calendar_set_flags(calendar);
  
}

244 245
void calendar_select_font (GtkWidget    *button,
                                 CalendarData *calendar)
246
{
247
  const char *font = NULL;
248 249 250
  GtkRcStyle *style;

  if (calendar->window)
251 252 253
    font = gtk_font_button_get_font_name (GTK_FONT_BUTTON (button));

  if (font)
254 255 256
	{
	  style = gtk_rc_style_new ();
	  pango_font_description_free (style->font_desc);
257
      style->font_desc = pango_font_description_from_string (font);
258 259
	  gtk_widget_modify_style (calendar->window, style);
	}
260 261
}

262
static gchar*
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
calendar_detail_cb (GtkCalendar *calendar,
                    guint        year,
                    guint        month,
                    guint        day,
                    gpointer     data)
{
  return calendar_get_detail (data, year, month, day);
}

static void
calendar_details_changed (GtkTextBuffer *buffer,
                          CalendarData  *data)
{
  GtkTextIter start, end;
  guint year, month, day;
  gchar *detail;

  gtk_text_buffer_get_start_iter(buffer, &start);
  gtk_text_buffer_get_end_iter(buffer, &end);

  gtk_calendar_get_date (GTK_CALENDAR (data->calendar_widget), &year, &month, &day);
  detail = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);

  if (!detail[0])
    {
      g_free (detail);
      detail = NULL;
290 291
    }

292 293
  calendar_set_detail (data, year, month, day, detail);
  gtk_widget_queue_resize (data->calendar_widget);
294 295
}

296 297
static void
demonstrate_details (CalendarData *data)
298
{
299 300 301
  static char *rainbow[] = { "#900", "#980", "#390", "#095", "#059", "#309", "#908" };
  GtkCalendar *calendar = GTK_CALENDAR (data->calendar_widget);
  gint row, col;
302

303 304 305 306 307
  for (row = 0; row < 6; ++row)
    for (col = 0; col < 7; ++col)
      {
        gint year, month, day;
        gchar *detail;
308
    
309 310 311 312
        year = calendar->year;
        month = calendar->month;
        month += calendar->day_month[row][col];
        day = calendar->day[row][col];
313
    
314 315 316 317 318 319 320 321 322
        if (month < 1)
          {
            month += 12;
            year -= 1;
          }
        else if (month > 12)
          {
            month -= 12;
            year += 1;
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

        detail = g_strdup_printf ("<span color='%s'>yadda\n"
                                  "(%04d-%02d-%02d)</span>",
                                  rainbow[(day - 1) % 7],
                                  year, month, day);

        calendar_set_detail (data, year, month - 1, day, detail);
      }

  gtk_widget_queue_resize (data->calendar_widget);
  calendar_update_details (data);
}

static void
reset_details (CalendarData *data)
{
  g_hash_table_remove_all (data->details_table);
  gtk_widget_queue_resize (data->calendar_widget);
  calendar_update_details (data);
}

static void
calendar_toggle_details (GtkWidget    *widget,
                         CalendarData *data)
{
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    gtk_calendar_set_detail_func (GTK_CALENDAR (data->calendar_widget),
                                  calendar_detail_cb, data, NULL);
352
  else
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    gtk_calendar_set_detail_func (GTK_CALENDAR (data->calendar_widget),
                                  NULL, NULL, NULL);
}

static GtkWidget*
create_expander (const char *caption,
                 GtkWidget  *child,
                 gdouble     xscale,
                 gdouble     yscale)
{
  GtkWidget *expander = gtk_expander_new ("");
  GtkWidget *label = gtk_expander_get_label_widget (GTK_EXPANDER (expander));
  GtkWidget *align = gtk_alignment_new (0, 0, xscale, yscale);

  gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 18, 0);
  gtk_label_set_markup (GTK_LABEL (label), caption);

  gtk_container_add (GTK_CONTAINER (expander), align);
  gtk_container_add (GTK_CONTAINER (align), child);
372

373
  return expander;
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
static GtkWidget*
create_frame (const char *caption,
              GtkWidget  *child,
              gdouble     xscale,
              gdouble     yscale)
{
  GtkWidget *frame = gtk_frame_new ("");
  GtkWidget *label = gtk_frame_get_label_widget (GTK_FRAME (frame));
  GtkWidget *align = gtk_alignment_new (0, 0, xscale, yscale);

  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
  gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 18, 0);
  gtk_label_set_markup (GTK_LABEL (label), caption);

  gtk_container_add (GTK_CONTAINER (frame), align);
  gtk_container_add (GTK_CONTAINER (align), child);

  return frame;
}

static void
detail_width_changed (GtkSpinButton *button,
                      CalendarData  *data)
{
  gint value = (gint) gtk_spin_button_get_value (button);
  gtk_calendar_set_detail_width_chars (GTK_CALENDAR (data->calendar_widget), value);
}

static void
detail_height_changed (GtkSpinButton *button,
                      CalendarData  *data)
{
  gint value = (gint) gtk_spin_button_get_value (button);
  gtk_calendar_set_detail_height_rows (GTK_CALENDAR (data->calendar_widget), value);
}

static void
create_calendar(void)
414 415
{
  static CalendarData calendar_data;
416 417 418 419 420 421 422 423

  GtkWidget *window, *hpaned, *vbox, *rpane, *hbox;
  GtkWidget *calendar, *toggle, *scroller, *button;
  GtkWidget *frame, *label, *bbox, *align, *details;

  GtkSizeGroup *size;
  GtkStyle *style;
  gchar *font;
424 425 426
  gint i;
  
  struct {
427
    gboolean init;
428 429 430
    char *label;
  } flags[] =
    {
431 432 433 434 435
      { TRUE,  "Show _Heading" },
      { TRUE,  "Show Day _Names" },
      { FALSE, "No Month _Change" },
      { TRUE,  "Show _Week Numbers" },
      { FALSE, "Week Start _Monday" },
436
      { TRUE,  "Show De_tails" },
437 438 439 440
    };

  calendar_data.window = NULL;
  calendar_data.font_dialog = NULL;
441
  calendar_data.details_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
442

443 444
  for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
    calendar_data.settings[i] = 0;
445 446

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
Manish Singh's avatar
Manish Singh committed
447
  gtk_window_set_title (GTK_WINDOW (window), "GtkCalendar Example");
448
  gtk_container_set_border_width (GTK_CONTAINER (window), 12);
Manish Singh's avatar
Manish Singh committed
449 450 451 452 453 454 455
  g_signal_connect (window, "destroy",
		    G_CALLBACK (gtk_main_quit),
		    NULL);
  g_signal_connect (window, "delete-event",
		    G_CALLBACK (gtk_false),
		    NULL);

456
  hpaned = gtk_hpaned_new ();
457

458
  /* Calendar widget */
459

460 461 462 463
  calendar = gtk_calendar_new ();
  calendar_data.calendar_widget = calendar;
  frame = create_frame ("<b>Calendar</b>", calendar, 0, 0);
  gtk_paned_pack1 (GTK_PANED (hpaned), frame, TRUE, FALSE);
464 465 466

  calendar_data.window = calendar;
  calendar_set_flags(&calendar_data);
Manish Singh's avatar
Manish Singh committed
467
  gtk_calendar_mark_day (GTK_CALENDAR (calendar), 19);	
468

Manish Singh's avatar
Manish Singh committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
  g_signal_connect (calendar, "month_changed", 
		    G_CALLBACK (calendar_month_changed),
		    &calendar_data);
  g_signal_connect (calendar, "day_selected", 
		    G_CALLBACK (calendar_day_selected),
		    &calendar_data);
  g_signal_connect (calendar, "day_selected_double_click", 
		    G_CALLBACK (calendar_day_selected_double_click),
		    &calendar_data);
  g_signal_connect (calendar, "prev_month", 
		    G_CALLBACK (calendar_prev_month),
		    &calendar_data);
  g_signal_connect (calendar, "next_month", 
		    G_CALLBACK (calendar_next_month),
		    &calendar_data);
  g_signal_connect (calendar, "prev_year", 
		    G_CALLBACK (calendar_prev_year),
		    &calendar_data);
  g_signal_connect (calendar, "next_year", 
		    G_CALLBACK (calendar_next_year),
		    &calendar_data);
490

491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
  rpane = gtk_vbox_new (FALSE, DEF_PAD_SMALL);
  gtk_paned_pack2 (GTK_PANED (hpaned), rpane, FALSE, FALSE);

  /* Build the right font-button */

  vbox = gtk_vbox_new(FALSE, DEF_PAD_SMALL);
  frame = create_frame ("<b>Options</b>", vbox, 1, 0);
  gtk_box_pack_start (GTK_BOX (rpane), frame, FALSE, TRUE, 0);
  size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

  gtk_widget_ensure_style (calendar);
  style = gtk_widget_get_style (calendar);
  font = pango_font_description_to_string (style->font_desc);
  button = gtk_font_button_new_with_font (font);
  g_free (font);

  g_signal_connect (button, "font-set",
                    G_CALLBACK(calendar_select_font),
                    &calendar_data);

  label = gtk_label_new_with_mnemonic ("_Font:");
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_size_group_add_widget (size, label);

  hbox = gtk_hbox_new (FALSE, DEF_PAD_SMALL);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);

  /* Build the width entry */

  button = gtk_spin_button_new_with_range (0, 127, 1);
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (button),
                             gtk_calendar_get_detail_width_chars (GTK_CALENDAR (calendar)));

  g_signal_connect (button, "value-changed",
                    G_CALLBACK (detail_width_changed),
                    &calendar_data);

  label = gtk_label_new_with_mnemonic ("Details W_idth:");
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_size_group_add_widget (size, label);

  hbox = gtk_hbox_new (FALSE, DEF_PAD_SMALL);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);

  /* Build the height entry */

  button = gtk_spin_button_new_with_range (0, 127, 1);
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (button),
                             gtk_calendar_get_detail_height_rows (GTK_CALENDAR (calendar)));
546

547 548 549
  g_signal_connect (button, "value-changed",
                    G_CALLBACK (detail_height_changed),
                    &calendar_data);
550

551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
  label = gtk_label_new_with_mnemonic ("Details H_eight:");
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_size_group_add_widget (size, label);

  hbox = gtk_hbox_new (FALSE, DEF_PAD_SMALL);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);

  /* Build the right details frame */

  vbox = gtk_vbox_new(FALSE, DEF_PAD_SMALL);
  frame = create_frame ("<b>Details</b>", vbox, 1, 1);
  gtk_box_pack_start (GTK_BOX (rpane), frame, FALSE, TRUE, 0);

  details = gtk_text_view_new();
  calendar_data.details_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (details));

  calendar_data.details_changed = g_signal_connect (calendar_data.details_buffer, "changed",
                                                    G_CALLBACK (calendar_details_changed),
                                                    &calendar_data);

  scroller = gtk_scrolled_window_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (scroller), details);

  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroller),
                                       GTK_SHADOW_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);

  gtk_box_pack_start (GTK_BOX (vbox), scroller, FALSE, TRUE, 0);

  hbox = gtk_hbox_new (FALSE, DEF_PAD_SMALL);
  align = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
  gtk_container_add (GTK_CONTAINER (align), hbox);
  gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, TRUE, 0);

  button = gtk_button_new_with_mnemonic ("Demonstrate _Details");

  g_signal_connect_swapped (button,
                            "clicked",
                            G_CALLBACK (demonstrate_details),
                            &calendar_data);

  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);

  button = gtk_button_new_with_mnemonic ("_Reset Details");

  g_signal_connect_swapped (button,
                            "clicked",
                            G_CALLBACK (reset_details),
                            &calendar_data);

  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);

608
  toggle = gtk_check_button_new_with_mnemonic ("_Use Details");
609 610 611 612
  g_signal_connect (toggle, "toggled",
                    G_CALLBACK(calendar_toggle_details),
                    &calendar_data);
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, TRUE, 0);
613 614 615
  
  /* Build the Right frame with the flags in */ 

616
  vbox = gtk_vbox_new(FALSE, 0);
617 618
  frame = create_expander ("<b>Flags</b>", vbox, 1, 0);
  gtk_box_pack_start (GTK_BOX (rpane), frame, TRUE, TRUE, 0);
619

620
  for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
621
    {
622 623 624 625 626 627
      toggle = gtk_check_button_new_with_mnemonic(flags[i].label);
      gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, TRUE, 0);
      calendar_data.flag_checkboxes[i] = toggle;

      g_signal_connect (toggle, "toggled",
                        G_CALLBACK (calendar_toggle_flag),
Manish Singh's avatar
Manish Singh committed
628
			&calendar_data);
629 630

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), flags[i].init);
631 632 633 634 635 636
    }

  /*
   *  Build the Signal-event part.
   */

637 638
  vbox = gtk_vbox_new (TRUE, DEF_PAD_SMALL);
  frame = create_frame ("<b>Signal Events</b>", vbox, 1, 0);
639 640
  
  hbox = gtk_hbox_new (FALSE, 3);
641
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
642 643 644 645 646 647
  label = gtk_label_new ("Signal:");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
  calendar_data.last_sig = gtk_label_new ("");
  gtk_box_pack_start (GTK_BOX (hbox), calendar_data.last_sig, FALSE, TRUE, 0);

  hbox = gtk_hbox_new (FALSE, 3);
648
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
649 650 651 652 653 654
  label = gtk_label_new ("Previous signal:");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
  calendar_data.prev_sig = gtk_label_new ("");
  gtk_box_pack_start (GTK_BOX (hbox), calendar_data.prev_sig, FALSE, TRUE, 0);

  hbox = gtk_hbox_new (FALSE, 3);
655
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
656 657 658 659 660
  label = gtk_label_new ("Second previous signal:");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
  calendar_data.prev2_sig = gtk_label_new ("");
  gtk_box_pack_start (GTK_BOX (hbox), calendar_data.prev2_sig, FALSE, TRUE, 0);

661 662 663 664
  /*
   *  Glue everything together
   */

665 666 667 668
  bbox = gtk_hbutton_box_new ();
  gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);

  button = gtk_button_new_with_label ("Close");
669
  g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
670
  gtk_container_add (GTK_CONTAINER (bbox), button);
671 672 673 674 675 676 677 678 679 680 681

  vbox = gtk_vbox_new (FALSE, DEF_PAD_SMALL);

  gtk_box_pack_start (GTK_BOX (vbox), hpaned,                TRUE,  TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), frame,                 FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), bbox,                  FALSE, TRUE, 0);

  gtk_container_add (GTK_CONTAINER (window), vbox);

682 683 684
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_widget_grab_default (button);

685 686
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 0);
  gtk_widget_show_all (window);
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
}


int main(int   argc,
         char *argv[] )
{
  gtk_init (&argc, &argv);

  create_calendar();

  gtk_main();

  return(0);
}
/* example-end */