~ubuntu-branches/ubuntu/natty/xfce4-panel/natty

« back to all changes in this revision

Viewing changes to plugins/clock/clock-binary.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-04 15:45:53 UTC
  • mfrom: (1.1.25 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204154553-c1k0n2p2j83chld0
Tags: 4.7.5-0ubuntu1
Upload to natty (pkg-xfce svn r4611).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id$ */
2
1
/*
3
 
 * Copyright (c) 2007 Nick Schermer <nick@xfce.org>
 
2
 * Copyright (c) 2007-2009 Nick Schermer <nick@xfce.org>
4
3
 *
5
4
 * This program is free software; you can redistribute it and/or modify it
6
5
 * under the terms of the GNU General Public License as published by the Free
40
39
 
41
40
 
42
41
 
43
 
/* class functions */
44
 
static void      xfce_clock_binary_finalize      (GObject              *object);
45
42
static void      xfce_clock_binary_set_property  (GObject              *object,
46
43
                                                  guint                 prop_id,
47
44
                                                  const GValue         *value,
50
47
                                                  guint                 prop_id,
51
48
                                                  GValue               *value,
52
49
                                                  GParamSpec           *pspec);
53
 
static void      xfce_clock_binary_size_request  (GtkWidget            *widget,
54
 
                                                  GtkRequisition       *requisition);
 
50
static void      xfce_clock_binary_finalize      (GObject              *object);
55
51
static gboolean  xfce_clock_binary_expose_event  (GtkWidget            *widget,
56
52
                                                  GdkEventExpose       *event);
 
53
static gboolean  xfce_clock_binary_update        (gpointer              user_data);
 
54
 
57
55
 
58
56
 
59
57
enum
60
58
{
61
 
    PROP_0,
62
 
    PROP_SHOW_SECONDS,
63
 
    PROP_TRUE_BINARY
 
59
  PROP_0,
 
60
  PROP_SHOW_SECONDS,
 
61
  PROP_TRUE_BINARY,
 
62
  PROP_SHOW_INACTIVE,
 
63
  PROP_SHOW_GRID,
 
64
  PROP_SIZE_RATIO,
 
65
  PROP_ORIENTATION
64
66
};
65
67
 
66
68
struct _XfceClockBinaryClass
67
69
{
68
 
    GtkImageClass __parent__;
 
70
  GtkImageClass __parent__;
69
71
};
70
72
 
71
73
struct _XfceClockBinary
72
74
{
73
 
    GtkImage  __parent__;
74
 
 
75
 
    /* whether we draw seconds */
76
 
    guint     show_seconds : 1;
77
 
 
78
 
    /* if this is a true binary clock */
79
 
    guint     true_binary : 1;
 
75
  GtkImage  __parent__;
 
76
 
 
77
  ClockPluginTimeout *timeout;
 
78
 
 
79
  guint     show_seconds : 1;
 
80
  guint     true_binary : 1;
 
81
  guint     show_inactive : 1;
 
82
  guint     show_grid : 1;
80
83
};
81
84
 
82
85
 
83
86
 
84
 
G_DEFINE_TYPE (XfceClockBinary, xfce_clock_binary, GTK_TYPE_IMAGE);
 
87
XFCE_PANEL_DEFINE_TYPE (XfceClockBinary, xfce_clock_binary, GTK_TYPE_IMAGE)
85
88
 
86
89
 
87
90
 
88
91
static void
89
92
xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
90
93
{
91
 
    GObjectClass   *gobject_class;
92
 
    GtkWidgetClass *gtkwidget_class;
93
 
 
94
 
    gobject_class = G_OBJECT_CLASS (klass);
95
 
    gobject_class->finalize = xfce_clock_binary_finalize;
96
 
    gobject_class->set_property = xfce_clock_binary_set_property;
97
 
    gobject_class->get_property = xfce_clock_binary_get_property;
98
 
 
99
 
    gtkwidget_class = GTK_WIDGET_CLASS (klass);
100
 
    gtkwidget_class->size_request = xfce_clock_binary_size_request;
101
 
    gtkwidget_class->expose_event = xfce_clock_binary_expose_event;
102
 
 
103
 
    /**
104
 
     * Whether we display seconds
105
 
     **/
106
 
    g_object_class_install_property (gobject_class,
107
 
                                     PROP_SHOW_SECONDS,
108
 
                                     g_param_spec_boolean ("show-seconds", "show-seconds", "show-seconds",
109
 
                                                           FALSE, PANEL_PARAM_READWRITE));
110
 
 
111
 
    /**
112
 
     * Whether this is a true binary clock
113
 
     **/
114
 
    g_object_class_install_property (gobject_class,
115
 
                                     PROP_TRUE_BINARY,
116
 
                                     g_param_spec_boolean ("true-binary", "true-binary", "true-binary",
117
 
                                                           FALSE, PANEL_PARAM_READWRITE));
 
94
  GObjectClass   *gobject_class;
 
95
  GtkWidgetClass *gtkwidget_class;
 
96
 
 
97
  gobject_class = G_OBJECT_CLASS (klass);
 
98
  gobject_class->set_property = xfce_clock_binary_set_property;
 
99
  gobject_class->get_property = xfce_clock_binary_get_property;
 
100
  gobject_class->finalize = xfce_clock_binary_finalize;
 
101
 
 
102
  gtkwidget_class = GTK_WIDGET_CLASS (klass);
 
103
  gtkwidget_class->expose_event = xfce_clock_binary_expose_event;
 
104
 
 
105
  g_object_class_install_property (gobject_class,
 
106
                                   PROP_SIZE_RATIO,
 
107
                                   g_param_spec_double ("size-ratio", NULL, NULL,
 
108
                                                        -1, G_MAXDOUBLE, 1.0,
 
109
                                                        G_PARAM_READABLE
 
110
                                                        | G_PARAM_STATIC_STRINGS));
 
111
 
 
112
  g_object_class_install_property (gobject_class,
 
113
                                   PROP_ORIENTATION,
 
114
                                   g_param_spec_enum ("orientation", NULL, NULL,
 
115
                                                      GTK_TYPE_ORIENTATION,
 
116
                                                      GTK_ORIENTATION_HORIZONTAL,
 
117
                                                      G_PARAM_WRITABLE
 
118
                                                      | G_PARAM_STATIC_STRINGS));
 
119
 
 
120
  g_object_class_install_property (gobject_class,
 
121
                                   PROP_SHOW_SECONDS,
 
122
                                   g_param_spec_boolean ("show-seconds", NULL, NULL,
 
123
                                                         FALSE,
 
124
                                                         G_PARAM_READWRITE
 
125
                                                         | G_PARAM_STATIC_STRINGS));
 
126
 
 
127
  g_object_class_install_property (gobject_class,
 
128
                                   PROP_TRUE_BINARY,
 
129
                                   g_param_spec_boolean ("true-binary", NULL, NULL,
 
130
                                                         FALSE,
 
131
                                                         G_PARAM_READWRITE
 
132
                                                         | G_PARAM_STATIC_STRINGS));
 
133
 
 
134
  g_object_class_install_property (gobject_class,
 
135
                                   PROP_SHOW_INACTIVE,
 
136
                                   g_param_spec_boolean ("show-inactive", NULL, NULL,
 
137
                                                         TRUE,
 
138
                                                         G_PARAM_READWRITE
 
139
                                                         | G_PARAM_STATIC_STRINGS));
 
140
 
 
141
  g_object_class_install_property (gobject_class,
 
142
                                   PROP_SHOW_GRID,
 
143
                                   g_param_spec_boolean ("show-grid", NULL, NULL,
 
144
                                                         FALSE,
 
145
                                                         G_PARAM_READWRITE
 
146
                                                         | G_PARAM_STATIC_STRINGS));
118
147
}
119
148
 
120
149
 
122
151
static void
123
152
xfce_clock_binary_init (XfceClockBinary *binary)
124
153
{
125
 
    /* init */
126
 
    binary->show_seconds = FALSE;
127
 
    binary->true_binary = FALSE;
128
 
}
129
 
 
130
 
 
131
 
 
132
 
static void
133
 
xfce_clock_binary_finalize (GObject *object)
134
 
{
135
 
    (*G_OBJECT_CLASS (xfce_clock_binary_parent_class)->finalize) (object);
 
154
  binary->show_seconds = FALSE;
 
155
  binary->true_binary = FALSE;
 
156
  binary->show_inactive = TRUE;
 
157
  binary->show_grid = FALSE;
 
158
 
 
159
  binary->timeout = clock_plugin_timeout_new (CLOCK_INTERVAL_MINUTE,
 
160
                                              xfce_clock_binary_update,
 
161
                                              binary);
136
162
}
137
163
 
138
164
 
143
169
                                const GValue *value,
144
170
                                GParamSpec   *pspec)
145
171
{
146
 
    XfceClockBinary *binary = XFCE_CLOCK_BINARY (object);
 
172
  XfceClockBinary *binary = XFCE_CLOCK_BINARY (object);
147
173
 
148
 
    switch (prop_id)
 
174
  switch (prop_id)
149
175
    {
150
 
        case PROP_SHOW_SECONDS:
151
 
            binary->show_seconds = g_value_get_boolean (value);
152
 
            break;
153
 
 
154
 
        case PROP_TRUE_BINARY:
155
 
            binary->true_binary = g_value_get_boolean (value);
156
 
            break;
157
 
 
158
 
        default:
159
 
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
160
 
            break;
 
176
    case PROP_ORIENTATION:
 
177
      break;
 
178
 
 
179
    case PROP_SHOW_SECONDS:
 
180
      binary->show_seconds = g_value_get_boolean (value);
 
181
      g_object_notify (object, "size-ratio");
 
182
      break;
 
183
 
 
184
    case PROP_TRUE_BINARY:
 
185
      binary->true_binary = g_value_get_boolean (value);
 
186
      g_object_notify (object, "size-ratio");
 
187
      break;
 
188
 
 
189
    case PROP_SHOW_INACTIVE:
 
190
      binary->show_inactive = g_value_get_boolean (value);
 
191
      break;
 
192
 
 
193
    case PROP_SHOW_GRID:
 
194
      binary->show_grid = g_value_get_boolean (value);
 
195
      break;
 
196
 
 
197
    default:
 
198
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
199
      break;
161
200
    }
 
201
 
 
202
  /* reschedule the timeout and resize */
 
203
  clock_plugin_timeout_set_interval (binary->timeout,
 
204
      binary->show_seconds ? CLOCK_INTERVAL_SECOND : CLOCK_INTERVAL_MINUTE);
 
205
  gtk_widget_queue_resize (GTK_WIDGET (binary));
162
206
}
163
207
 
164
208
 
169
213
                                GValue     *value,
170
214
                                GParamSpec *pspec)
171
215
{
172
 
    XfceClockBinary *binary = XFCE_CLOCK_BINARY (object);
173
 
 
174
 
    switch (prop_id)
175
 
    {
176
 
        case PROP_SHOW_SECONDS:
177
 
            g_value_set_boolean (value, binary->show_seconds);
178
 
            break;
179
 
 
180
 
        case PROP_TRUE_BINARY:
181
 
            g_value_set_boolean (value, binary->true_binary);
182
 
            break;
183
 
 
184
 
        default:
185
 
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186
 
            break;
187
 
    }
188
 
}
189
 
 
190
 
 
191
 
 
192
 
static void
193
 
xfce_clock_binary_size_request (GtkWidget      *widget,
194
 
                                GtkRequisition *requisition)
195
 
{
196
 
    gint             width, height;
197
 
    gdouble          ratio;
198
 
    XfceClockBinary *binary = XFCE_CLOCK_BINARY (widget);
199
 
 
200
 
    /* get the current widget size */
201
 
    gtk_widget_get_size_request (widget, &width, &height);
202
 
 
203
 
    /* ratio of the clock */
204
 
    if (binary->true_binary)
205
 
    {
 
216
  XfceClockBinary *binary = XFCE_CLOCK_BINARY (object);
 
217
  gdouble          ratio;
 
218
 
 
219
  switch (prop_id)
 
220
    {
 
221
    case PROP_SHOW_SECONDS:
 
222
      g_value_set_boolean (value, binary->show_seconds);
 
223
      break;
 
224
 
 
225
    case PROP_TRUE_BINARY:
 
226
      g_value_set_boolean (value, binary->true_binary);
 
227
      break;
 
228
 
 
229
    case PROP_SHOW_INACTIVE:
 
230
      g_value_set_boolean (value, binary->show_inactive);
 
231
      break;
 
232
 
 
233
    case PROP_SHOW_GRID:
 
234
      g_value_set_boolean (value, binary->show_grid);
 
235
      break;
 
236
 
 
237
    case PROP_SIZE_RATIO:
 
238
      if (binary->true_binary)
206
239
        ratio = binary->show_seconds ? 2.0 : 3.0;
207
 
    }
208
 
    else
209
 
    {
 
240
      else
210
241
        ratio = binary->show_seconds ? 1.5 : 1.0;
211
 
    }
212
 
 
213
 
    /* set requisition based on the plugin orientation */
214
 
    if (width == -1)
215
 
    {
216
 
        requisition->height = height;
217
 
        requisition->width = height * ratio;
218
 
    }
219
 
    else
220
 
    {
221
 
        requisition->height = width / ratio;
222
 
        requisition->width = width;
 
242
      g_value_set_double (value, ratio);
 
243
      break;
 
244
 
 
245
    default:
 
246
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
247
      break;
 
248
    }
 
249
}
 
250
 
 
251
 
 
252
 
 
253
static void
 
254
xfce_clock_binary_finalize (GObject *object)
 
255
{
 
256
  /* stop the timeout */
 
257
  clock_plugin_timeout_free (XFCE_CLOCK_BINARY (object)->timeout);
 
258
 
 
259
  (*G_OBJECT_CLASS (xfce_clock_binary_parent_class)->finalize) (object);
 
260
}
 
261
 
 
262
 
 
263
 
 
264
static void
 
265
xfce_clock_binary_expose_event_true_binary (XfceClockBinary *binary,
 
266
                                            cairo_t         *cr,
 
267
                                            GtkAllocation   *alloc)
 
268
{
 
269
  GdkColor    *active, *inactive;
 
270
  struct tm    tm;
 
271
  gint         row, rows;
 
272
  static gint  binary_table[] = { 32, 16, 8, 4, 2, 1 };
 
273
  gint         col, cols = G_N_ELEMENTS (binary_table);
 
274
  gint         remain_h, remain_w;
 
275
  gint         offset_x, offset_y;
 
276
  gint         w, h, x;
 
277
  gint         ticks;
 
278
 
 
279
  if (G_UNLIKELY (GTK_WIDGET_STATE (binary) == GTK_STATE_INSENSITIVE))
 
280
    {
 
281
      inactive = &(GTK_WIDGET (binary)->style->mid[GTK_STATE_INSENSITIVE]);
 
282
      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_INSENSITIVE]);
 
283
    }
 
284
  else
 
285
    {
 
286
      inactive = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_NORMAL]);
 
287
      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_SELECTED]);
 
288
    }
 
289
 
 
290
  clock_plugin_get_localtime (&tm);
 
291
 
 
292
  /* init sizes */
 
293
  remain_h = alloc->height;
 
294
  offset_y = alloc->y;
 
295
 
 
296
  rows = binary->show_seconds ? 3 : 2;
 
297
  for (row = 0; row < rows; row++)
 
298
    {
 
299
      /* get the time this row represents */
 
300
      if (row == 0)
 
301
        ticks = tm.tm_hour;
 
302
      else if (row == 1)
 
303
        ticks = tm.tm_min;
 
304
      else
 
305
        ticks = tm.tm_sec;
 
306
 
 
307
      /* reset sizes */
 
308
      remain_w = alloc->width;
 
309
      offset_x = alloc->x;
 
310
      h = remain_h / (rows - row);
 
311
      remain_h -= h;
 
312
 
 
313
      for (col = 0; col < cols; col++)
 
314
        {
 
315
          /* update sizes */
 
316
          w = remain_w / (cols - col);
 
317
          x = offset_x;
 
318
          remain_w -= w;
 
319
          offset_x += w;
 
320
 
 
321
          if (ticks >= binary_table[col])
 
322
            {
 
323
              gdk_cairo_set_source_color (cr, active);
 
324
              ticks -= binary_table[col];
 
325
            }
 
326
          else if (binary->show_inactive)
 
327
            {
 
328
              gdk_cairo_set_source_color (cr, inactive);
 
329
            }
 
330
          else
 
331
            {
 
332
              continue;
 
333
            }
 
334
 
 
335
          /* draw the dot */
 
336
          cairo_rectangle (cr, x, offset_y, w - 1, h - 1);
 
337
          cairo_fill (cr);
 
338
        }
 
339
 
 
340
      /* advance offset */
 
341
      offset_y += h;
 
342
    }
 
343
}
 
344
 
 
345
 
 
346
 
 
347
static void
 
348
xfce_clock_binary_expose_event_binary (XfceClockBinary *binary,
 
349
                                       cairo_t         *cr,
 
350
                                       GtkAllocation   *alloc)
 
351
{
 
352
  GdkColor    *active, *inactive;
 
353
  static gint  binary_table[] = { 80, 40, 20, 10, 8, 4, 2, 1 };
 
354
  struct tm    tm;
 
355
  gint         row, rows = G_N_ELEMENTS (binary_table) / 2;
 
356
  gint         col, cols;
 
357
  gint         digit;
 
358
  gint         remain_h, remain_w;
 
359
  gint         offset_x, offset_y;
 
360
  gint         w, h, y;
 
361
  gint         ticks;
 
362
 
 
363
  if (G_UNLIKELY (GTK_WIDGET_STATE (binary) == GTK_STATE_INSENSITIVE))
 
364
    {
 
365
      inactive = &(GTK_WIDGET (binary)->style->mid[GTK_STATE_INSENSITIVE]);
 
366
      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_INSENSITIVE]);
 
367
    }
 
368
  else
 
369
    {
 
370
      inactive = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_NORMAL]);
 
371
      active = &(GTK_WIDGET (binary)->style->dark[GTK_STATE_SELECTED]);
 
372
    }
 
373
 
 
374
  clock_plugin_get_localtime (&tm);
 
375
 
 
376
  remain_w = alloc->width;
 
377
  offset_x = alloc->x;
 
378
 
 
379
  /* make sure the cols are all equal */
 
380
  cols = binary->show_seconds ? 6 : 4;
 
381
  for (col = 0; col < cols; col++)
 
382
    {
 
383
      /* get the time this row represents */
 
384
      if (col == 0)
 
385
        ticks = tm.tm_hour;
 
386
      else if (col == 2)
 
387
        ticks = tm.tm_min;
 
388
      else if (col == 4)
 
389
        ticks = tm.tm_sec;
 
390
 
 
391
      /* reset sizes */
 
392
      remain_h = alloc->height;
 
393
      offset_y = alloc->y;
 
394
      w = remain_w / (cols - col);
 
395
      remain_w -= w;
 
396
 
 
397
      for (row = 0; row < rows; row++)
 
398
        {
 
399
          /* update sizes */
 
400
          h = remain_h / (rows - row);
 
401
          remain_h -= h;
 
402
          y = offset_y;
 
403
          offset_y += h;
 
404
 
 
405
          digit = row + (4 * (col % 2));
 
406
          if (ticks >= binary_table[digit])
 
407
            {
 
408
              gdk_cairo_set_source_color (cr, active);
 
409
              ticks -= binary_table[digit];
 
410
            }
 
411
          else if (binary->show_inactive)
 
412
            {
 
413
              gdk_cairo_set_source_color (cr, inactive);
 
414
            }
 
415
          else
 
416
            {
 
417
              continue;
 
418
            }
 
419
 
 
420
          /* draw the dot */
 
421
          cairo_rectangle (cr, offset_x, y, w - 1, h - 1);
 
422
          cairo_fill (cr);
 
423
        }
 
424
 
 
425
      /* advance offset */
 
426
      offset_x += w;
223
427
    }
224
428
}
225
429
 
229
433
xfce_clock_binary_expose_event (GtkWidget      *widget,
230
434
                                GdkEventExpose *event)
231
435
{
232
 
    XfceClockBinary *binary = XFCE_CLOCK_BINARY (widget);
233
 
    gdouble          cw, ch, columns;
234
 
    gint             ticks, cells, decimal;
235
 
    gdouble          radius;
236
 
    gdouble          x, y;
237
 
    gint             i, j;
238
 
    gint             decimal_tb[] = {32, 16, 8, 4, 2, 1};
239
 
    gint             decimal_bcd[] = {80, 40, 20, 10, 8, 4, 2, 1};
240
 
    cairo_t         *cr;
241
 
    GdkColor         active, inactive;
242
 
    struct tm        tm;
243
 
 
244
 
    g_return_val_if_fail (XFCE_CLOCK_IS_BINARY (binary), FALSE);
245
 
 
246
 
    /* number of columns and cells */
247
 
    columns = binary->show_seconds ? 3.0 : 2.0;
248
 
    cells = binary->true_binary ? 6 : 8;
249
 
 
250
 
    /* cell width and height */
251
 
    if (binary->true_binary)
252
 
    {
253
 
        cw = widget->allocation.width / 6.0;
254
 
        ch = widget->allocation.height / columns;
255
 
    }
256
 
    else /* bcd clock */
257
 
    {
258
 
        cw = widget->allocation.width / columns / 2.0;
259
 
        ch = widget->allocation.height / 4.0;
260
 
    }
261
 
 
262
 
    /* arc radius */
263
 
    radius = MIN (cw, ch) / 2.0 * 0.7;
264
 
 
265
 
    /* get colors */
266
 
    inactive = widget->style->fg[GTK_STATE_NORMAL];
267
 
    active = widget->style->bg[GTK_STATE_SELECTED];
268
 
 
269
 
    /* get the cairo context */
270
 
    cr = gdk_cairo_create (widget->window);
271
 
 
272
 
    if (G_LIKELY (cr != NULL))
273
 
    {
274
 
        /* clip the drawing area */
275
 
        gdk_cairo_rectangle (cr, &event->area);
276
 
        cairo_clip (cr);
277
 
        
278
 
        /* get the current time */
279
 
        xfce_clock_util_get_localtime (&tm);
280
 
 
281
 
        /* walk the three or two time parts */
282
 
        for (i = 0; i < columns; i++)
 
436
  XfceClockBinary *binary = XFCE_CLOCK_BINARY (widget);
 
437
  cairo_t         *cr;
 
438
  GdkColor        *color;
 
439
  gint             col, cols;
 
440
  gint             row, rows;
 
441
  GtkAllocation    alloc;
 
442
  gdouble          remain_w, x;
 
443
  gdouble          remain_h, y;
 
444
  gint             w, h;
 
445
  gint             pad_x, pad_y;
 
446
  gint             diff;
 
447
 
 
448
  panel_return_val_if_fail (XFCE_CLOCK_IS_BINARY (binary), FALSE);
 
449
  panel_return_val_if_fail (GDK_IS_WINDOW (widget->window), FALSE);
 
450
 
 
451
  cr = gdk_cairo_create (widget->window);
 
452
  if (G_LIKELY (cr != NULL))
 
453
    {
 
454
      /* clip the drawing region */
 
455
      gdk_cairo_rectangle (cr, &event->area);
 
456
      cairo_clip (cr);
 
457
 
 
458
      gtk_misc_get_padding (GTK_MISC (widget), &pad_x, &pad_y);
 
459
 
 
460
      alloc = widget->allocation;
 
461
      alloc.width -= 1 + 2 * pad_x;
 
462
      alloc.height -= 1 + 2 * pad_y;
 
463
      alloc.x += pad_x + 1;
 
464
      alloc.y += pad_y + 1;
 
465
 
 
466
      /* align columns and fix rounding */
 
467
      cols = binary->true_binary ? 6 : (binary->show_seconds ? 6 : 4);
 
468
      diff = alloc.width - (floor ((gdouble) alloc.width / cols) * cols);
 
469
      alloc.width -= diff;
 
470
      alloc.x += diff / 2;
 
471
 
 
472
      /* align rows and fix rounding */
 
473
      rows = binary->true_binary ? (binary->show_seconds ? 3 : 2) : 4;
 
474
      diff = alloc.height - (floor ((gdouble) alloc.height / rows) * rows);
 
475
      alloc.height -= diff;
 
476
      alloc.y += diff / 2;
 
477
 
 
478
      if (binary->show_grid)
283
479
        {
284
 
            /* get the time of this column */
285
 
            if (i == 0)
286
 
                ticks = tm.tm_hour;
287
 
            else if (i == 1)
288
 
                ticks = tm.tm_min;
289
 
            else
290
 
                ticks = tm.tm_sec;
291
 
 
292
 
            /* walk the binary columns */
293
 
            for (j = 0; j < cells; j++)
294
 
            {
295
 
                if (binary->true_binary)
296
 
                {
297
 
                    /* skip the columns we don't draw */
298
 
                    if (i == 0 && j == 0)
299
 
                        continue;
300
 
 
301
 
                    /* decimal representation of this cell */
302
 
                    decimal = decimal_tb[j];
303
 
 
304
 
                    /* center of the arc */
305
 
                    x = cw * (j + 0.5) + widget->allocation.x;
306
 
                    y = ch * (i + 0.5) + widget->allocation.y;
307
 
                }
308
 
                else /* bcd clock */
309
 
                {
310
 
                    /* skip the columns we don't draw */
311
 
                    if ((j == 0) || (i == 0 && j == 1))
312
 
                        continue;
313
 
 
314
 
                    /* decimal representation of this cell */
315
 
                    decimal = decimal_bcd[j];
316
 
 
317
 
                    /* center of the arc */
318
 
                    x = cw * (i * 2 + (j < 4 ? 0 : 1) + 0.5) + widget->allocation.x;
319
 
                    y = ch * ((j >= 4 ? j - 4 : j) + 0.5) + widget->allocation.y;
320
 
                }
321
 
 
322
 
                /* if this binary values 'fits' in the time */
323
 
                if (ticks >= decimal)
324
 
                {
325
 
                    /* extract the decimal value from the time */
326
 
                    ticks -= decimal;
327
 
 
328
 
                    /* set the active color */
329
 
                    gdk_cairo_set_source_color (cr, &active);
330
 
                }
331
 
                else
332
 
                {
333
 
                    /* set the inactive color */
334
 
                    gdk_cairo_set_source_color (cr, &inactive);
335
 
                }
336
 
 
337
 
                /* draw the arc */
338
 
                cairo_move_to (cr, x, y);
339
 
                cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
340
 
                cairo_close_path (cr);
341
 
 
342
 
                /* fill the arc */
343
 
                cairo_fill (cr);
 
480
          color = &(GTK_WIDGET (binary)->style->light[GTK_STATE_SELECTED]);
 
481
          gdk_cairo_set_source_color (cr, color);
 
482
          cairo_set_line_width (cr, 1);
 
483
 
 
484
          remain_w = alloc.width;
 
485
          remain_h = alloc.height;
 
486
          x = alloc.x - 0.5;
 
487
          y = alloc.y - 0.5;
 
488
 
 
489
          cairo_rectangle (cr, x, y, alloc.width, alloc.height);
 
490
          cairo_stroke (cr);
 
491
 
 
492
          for (col = 0; col < cols - 1; col++)
 
493
            {
 
494
              w = remain_w / (cols - col);
 
495
              x += w; remain_w -= w;
 
496
              cairo_move_to (cr, x, alloc.y);
 
497
              cairo_rel_line_to (cr, 0, alloc.height);
 
498
              cairo_stroke (cr);
 
499
            }
 
500
 
 
501
          for (row = 0; row < rows - 1; row++)
 
502
            {
 
503
              h = remain_h / (rows - row);
 
504
              y += h; remain_h -= h;
 
505
              cairo_move_to (cr, alloc.x, y);
 
506
              cairo_rel_line_to (cr, alloc.width, 0);
 
507
              cairo_stroke (cr);
344
508
            }
345
509
        }
346
510
 
347
 
        /* cleanup */
348
 
        cairo_destroy (cr);
 
511
      if (binary->true_binary)
 
512
        xfce_clock_binary_expose_event_true_binary (binary, cr, &alloc);
 
513
      else
 
514
        xfce_clock_binary_expose_event_binary (binary, cr, &alloc);
 
515
 
 
516
      cairo_destroy (cr);
349
517
    }
350
518
 
351
 
    return FALSE;
 
519
  return FALSE;
 
520
}
 
521
 
 
522
 
 
523
 
 
524
static gboolean
 
525
xfce_clock_binary_update (gpointer user_data)
 
526
{
 
527
  GtkWidget *widget = GTK_WIDGET (user_data);
 
528
 
 
529
  panel_return_val_if_fail (XFCE_CLOCK_IS_BINARY (user_data), FALSE);
 
530
 
 
531
  /* update if the widget if visible */
 
532
  if (G_LIKELY (GTK_WIDGET_VISIBLE (widget)))
 
533
    gtk_widget_queue_draw (widget);
 
534
 
 
535
  return TRUE;
352
536
}
353
537
 
354
538
 
356
540
GtkWidget *
357
541
xfce_clock_binary_new (void)
358
542
{
359
 
    return g_object_new (XFCE_CLOCK_TYPE_BINARY, NULL);
360
 
}
361
 
 
362
 
 
363
 
 
364
 
gboolean
365
 
xfce_clock_binary_update (gpointer user_data)
366
 
{
367
 
    GtkWidget *widget = GTK_WIDGET (user_data);
368
 
 
369
 
    /* update if the widget if visible */
370
 
    if (G_LIKELY (GTK_WIDGET_VISIBLE (widget)))
371
 
        gtk_widget_queue_draw (widget);
372
 
 
373
 
    return TRUE;
 
543
  return g_object_new (XFCE_CLOCK_TYPE_BINARY, NULL);
374
544
}