testcalendar.c 22.2 KB
Newer Older
1 2 3 4 5
/* example-start calendar calendar.c */
/*
 * Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson, Mattias Grnlund
 * Copyright (C) 2000 Tony Gale
 *
Javier Jardón's avatar
Javier Jardón committed
6 7 8
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
9 10
 * (at your option) any later version.
 *
Javier Jardón's avatar
Javier Jardón committed
11
 * This library is distributed in the hope that it will be useful,
12 13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Javier Jardón's avatar
Javier Jardón committed
14
 * GNU Lesser General Public License for more details.
15
 *
Javier Jardón's avatar
Javier Jardón committed
16 17
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program. If not, see <http://www.gnu.org/licenses/>.
18 19
 */

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

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

#define TM_YEAR_BASE 1900

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

  GHashTable    *details_table;
  GtkTextBuffer *details_buffer;
44
  gulong         details_changed;
45 46
} CalendarData;

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

/*
 * GtkCalendar
 */

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

68 69
  gtk_calendar_get_date (GTK_CALENDAR(data->window),
			 &year, &month, &day);
70 71 72 73 74 75 76 77 78 79
  if (g_date_valid_dmy (day, month + 1, year))
    {
      date = g_date_new_dmy (day, month + 1, year);
      g_date_strftime (buffer, buff_len-1, "%x", date);
      g_date_free (date);
    }
  else
    {
      g_snprintf (buffer, buff_len - 1, "%d/%d/%d (invalid)", month + 1, day, year);
    }
80 81
}

82 83 84 85 86 87 88 89 90 91 92
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);
}

93
static gchar*
94 95 96 97 98 99 100 101 102 103 104 105
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);

106
  return (detail ? g_strdup (detail) : NULL);
107 108 109 110 111 112
}

static void
calendar_update_details (CalendarData *data)
{
  guint year, month, day;
113
  gchar *detail;
114 115 116 117 118 119 120

  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);
121 122

  g_free (detail);
123 124 125 126
}

static void
calendar_set_signal_strings (char         *sig_str,
127 128
				  CalendarData *data)
{
Manish Singh's avatar
Manish Singh committed
129
  const gchar *prev_sig;
130

Manish Singh's avatar
Manish Singh committed
131
  prev_sig = gtk_label_get_text (GTK_LABEL (data->prev_sig));
132 133
  gtk_label_set_text (GTK_LABEL (data->prev2_sig), prev_sig);

Manish Singh's avatar
Manish Singh committed
134
  prev_sig = gtk_label_get_text (GTK_LABEL (data->last_sig));
135 136 137 138
  gtk_label_set_text (GTK_LABEL (data->prev_sig), prev_sig);
  gtk_label_set_text (GTK_LABEL (data->last_sig), sig_str);
}

139 140
static void
calendar_month_changed (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
141
                             CalendarData *data)
142 143 144 145 146 147 148
{
  char buffer[256] = "month_changed: ";

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

149 150
static void
calendar_day_selected (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
151
                            CalendarData *data)
152 153 154 155 156
{
  char buffer[256] = "day_selected: ";

  calendar_date_to_string (data, buffer+14, 256-14);
  calendar_set_signal_strings (buffer, data);
157 158

  calendar_update_details (data);
159 160
}

161 162
static void
calendar_day_selected_double_click (GtkWidget    *widget,
Manish Singh's avatar
Manish Singh committed
163
                                         CalendarData *data)
164 165
{
  char buffer[256] = "day_selected_double_click: ";
166
  guint day;
167 168 169

  calendar_date_to_string (data, buffer+27, 256-27);
  calendar_set_signal_strings (buffer, data);
170 171 172 173 174 175 176
  gtk_calendar_get_date (GTK_CALENDAR (data->window),
                         NULL, NULL, &day);

  if (gtk_calendar_get_day_is_marked (GTK_CALENDAR (data->window), day))
    gtk_calendar_unmark_day (GTK_CALENDAR (data->window), day);
  else
    gtk_calendar_mark_day (GTK_CALENDAR (data->window), day);
177 178
}

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

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

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

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

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

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

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

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


220 221
static void
calendar_set_flags (CalendarData *calendar)
222
{
223 224 225
  gint options = 0, i;

  for (i = 0; i < G_N_ELEMENTS (calendar->settings); i++)
226
    if (calendar->settings[i])
227 228
      options=options + (1 << i);

229
  if (calendar->window)
230
    gtk_calendar_set_display_options (GTK_CALENDAR (calendar->window), options);
231 232
}

233 234 235
static void
calendar_toggle_flag (GtkWidget    *toggle,
                      CalendarData *calendar)
236 237
{
  gint i;
238 239

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

  calendar_set_flags(calendar);
  
}

247 248
void calendar_select_font (GtkWidget    *button,
                                 CalendarData *calendar)
249
{
250
  const char *font = NULL;
251 252
  GtkCssProvider *provider;
  gchar *data;
253 254

  if (calendar->window)
255
    {
256 257 258 259 260 261 262
      provider = g_object_get_data (G_OBJECT (calendar->window), "css-provider");
      if (!provider)
        {
          provider = gtk_css_provider_new ();
          gtk_style_context_add_provider (gtk_widget_get_style_context (calendar->window), GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
          g_object_set_data_full (G_OBJECT (calendar->window), "css-provider", provider, g_object_unref);
        }
263
      font = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (button));
264 265 266
      data = g_strdup_printf ("GtkCalendar { font: %s; }", font);
      gtk_css_provider_load_from_data (provider, data, -1, NULL);
      g_free (data);
267
    }
268 269
}

270
static gchar*
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
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;
298 299
    }

300 301
  calendar_set_detail (data, year, month, day, detail);
  gtk_widget_queue_resize (data->calendar_widget);
302 303
}

304 305
static void
demonstrate_details (CalendarData *data)
306
{
307 308
  static char *rainbow[] = { "#900", "#980", "#390", "#095", "#059", "#309", "#908" };
  GtkCalendar *calendar = GTK_CALENDAR (data->calendar_widget);
309 310 311 312 313 314 315 316 317 318 319 320 321
  guint year, month, day;
  gchar *detail;

  gtk_calendar_get_date (calendar,
                         &year, &month, &day);

  for (day = 0; day < 29; ++day)
    {
      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, day, detail);
   }
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

  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);
342
  else
343 344 345 346 347 348 349
    gtk_calendar_set_detail_func (GTK_CALENDAR (data->calendar_widget),
                                  NULL, NULL, NULL);
}

static GtkWidget*
create_expander (const char *caption,
                 GtkWidget  *child,
350 351
                 GtkAlign    halign,
                 GtkAlign    valign)
352 353 354 355
{
  GtkWidget *expander = gtk_expander_new ("");
  GtkWidget *label = gtk_expander_get_label_widget (GTK_EXPANDER (expander));

356 357 358 359 360 361 362 363
  g_object_set (child,
                "margin-top", 6,
                "margin-bottom", 0,
                "margin-start", 18,
                "margin-end", 0,
                "halign", halign,
                "valign", valign,
                NULL);
364 365
  gtk_label_set_markup (GTK_LABEL (label), caption);

366
  gtk_container_add (GTK_CONTAINER (expander), child);
367

368
  return expander;
369 370
}

371 372 373
static GtkWidget*
create_frame (const char *caption,
              GtkWidget  *child,
374 375
              GtkAlign    halign,
              GtkAlign    valign)
376 377 378 379
{
  GtkWidget *frame = gtk_frame_new ("");
  GtkWidget *label = gtk_frame_get_label_widget (GTK_FRAME (frame));

380 381 382 383 384 385 386 387
  g_object_set (child,
                "margin-top", 6,
                "margin-bottom", 0,
                "margin-start", 18,
                "margin-end", 0,
                "halign", halign,
                "valign", valign,
                NULL);
388 389 390
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
  gtk_label_set_markup (GTK_LABEL (label), caption);

391
  gtk_container_add (GTK_CONTAINER (frame), child);
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413

  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

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

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

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

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

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

457
  hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
458

459
  /* Calendar widget */
460

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

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

Manish Singh's avatar
Manish Singh committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
  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);
491

492
  rpane = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
493 494 495 496
  gtk_paned_pack2 (GTK_PANED (hpaned), rpane, FALSE, FALSE);

  /* Build the right font-button */

497
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
498
  frame = create_frame ("<b>Options</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_CENTER);
499 500 501
  gtk_box_pack_start (GTK_BOX (rpane), frame, FALSE, TRUE, 0);
  size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

502
  context = gtk_widget_get_style_context (calendar);
503 504
  gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
			 GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
505
  font = pango_font_description_to_string (font_desc);
506 507
  button = gtk_font_button_new_with_font (font);
  g_free (font);
508
  pango_font_description_free (font_desc);
509 510 511 512 513 514 515

  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);
516 517
  gtk_widget_set_halign (label, GTK_ALIGN_START);
  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
518 519
  gtk_size_group_add_widget (size, label);

520
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
  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);
537 538
  gtk_widget_set_halign (label, GTK_ALIGN_START);
  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
539 540
  gtk_size_group_add_widget (size, label);

541
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
542 543 544 545 546 547 548 549 550
  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)));
551

552 553 554
  g_signal_connect (button, "value-changed",
                    G_CALLBACK (detail_height_changed),
                    &calendar_data);
555

556 557
  label = gtk_label_new_with_mnemonic ("Details H_eight:");
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), button);
558 559
  gtk_widget_set_halign (label, GTK_ALIGN_START);
  gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
560 561
  gtk_size_group_add_widget (size, label);

562
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
563 564 565 566 567 568
  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 */

569
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
570
  frame = create_frame ("<b>Details</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_FILL);
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
  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);

591
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, DEF_PAD_SMALL);
592 593 594
  gtk_widget_set_halign (hbox, GTK_ALIGN_START);
  gtk_widget_set_valign (hbox, GTK_ALIGN_CENTER);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613

  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);

614
  toggle = gtk_check_button_new_with_mnemonic ("_Use Details");
615 616 617 618
  g_signal_connect (toggle, "toggled",
                    G_CALLBACK(calendar_toggle_details),
                    &calendar_data);
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, TRUE, 0);
619 620 621
  
  /* Build the Right frame with the flags in */ 

622
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
623
  frame = create_expander ("<b>Flags</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_CENTER);
624
  gtk_box_pack_start (GTK_BOX (rpane), frame, TRUE, TRUE, 0);
625

626
  for (i = 0; i < G_N_ELEMENTS (calendar_data.settings); i++)
627
    {
628 629 630 631 632 633
      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
634
			&calendar_data);
635 636

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), flags[i].init);
637 638 639 640 641 642
    }

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

643 644
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
  gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
645
  frame = create_frame ("<b>Signal Events</b>", vbox, GTK_ALIGN_FILL, GTK_ALIGN_CENTER);
646
  
647
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
648
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
649 650 651 652 653
  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);

654
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
655
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
656 657 658 659 660
  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);

661
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
662
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
663 664 665 666 667
  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);

668 669 670 671
  /*
   *  Glue everything together
   */

672
  bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
673 674 675
  gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);

  button = gtk_button_new_with_label ("Close");
676
  g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
677
  gtk_container_add (GTK_CONTAINER (bbox), button);
678

679
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, DEF_PAD_SMALL);
680

681 682 683 684 685 686 687 688 689 690
  gtk_box_pack_start (GTK_BOX (vbox), hpaned,
                      TRUE,  TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL),
                      FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), frame,
                      FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL),
                      FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), bbox,
                      FALSE, TRUE, 0);
691 692 693

  gtk_container_add (GTK_CONTAINER (window), vbox);

694
  gtk_widget_set_can_default (button, TRUE);
695 696
  gtk_widget_grab_default (button);

697 698
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 0);
  gtk_widget_show_all (window);
699 700 701 702 703 704 705 706
}


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

707 708 709
  if (g_getenv ("GTK_RTL"))
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

710 711 712 713 714 715 716
  create_calendar();

  gtk_main();

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