~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/register/register-gnome/datecell-gnome.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:25:46 UTC
  • Revision ID: siretart@tauware.de-20080803072546-y6p8xda8zpfi62ys
import gnucash_2.2.4.orig.tar.gz

The original tarball had the md5sum: 27e660297dc5b8ce574515779d05a5a5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************\
 
2
 * datecell-gnome.c -- implement date cell handler in gnome         *
 
3
 *                                                                  *  
 
4
 * This program is free software; you can redistribute it and/or    *
 
5
 * modify it under the terms of the GNU General Public License as   *
 
6
 * published by the Free Software Foundation; either version 2 of   *
 
7
 * the License, or (at your option) any later version.              *
 
8
 *                                                                  *
 
9
 * This program is distributed in the hope that it will be useful,  *
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
 
12
 * GNU General Public License for more details.                     *
 
13
 *                                                                  *
 
14
 * You should have received a copy of the GNU General Public License*
 
15
 * along with this program; if not, contact:                        *
 
16
 *                                                                  *
 
17
 * Free Software Foundation           Voice:  +1-617-542-5942       *
 
18
 * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
 
19
 * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
 
20
 *                                                                  *
 
21
\********************************************************************/
 
22
 
 
23
/*
 
24
 * FILE: datecell-gnome.c
 
25
 *
 
26
 * FUNCTION: Implement gnome portion of datecell widget
 
27
 *           embedded in a table cell.
 
28
 *
 
29
 * HISTORY:
 
30
 * Copyright (c) 2000 Dave Peticolas <dave@krondo.com>
 
31
 */
 
32
 
 
33
#include "config.h"
 
34
 
 
35
#include <gnome.h>
 
36
#include <stdio.h>
 
37
#include <stdlib.h>
 
38
#include <string.h>
 
39
#include <time.h>
 
40
 
 
41
#include "datecell.h"
 
42
#include "dialog-utils.h"
 
43
#include "gnc-ui-util.h"
 
44
#include "gnucash-date-picker.h"
 
45
#include "gnucash-item-edit.h"
 
46
#include "gnucash-sheet.h"
 
47
 
 
48
 
 
49
#define DATE_BUF (MAX_DATE_LENGTH+1)
 
50
 
 
51
typedef struct _PopBox
 
52
{
 
53
  GnucashSheet  *sheet;
 
54
  GncItemEdit      *item_edit;
 
55
  GNCDatePicker *date_picker;
 
56
 
 
57
  gboolean signals_connected; /* date picker signals connected? */
 
58
  gboolean calendar_popped;   /* calendar is popped up? */
 
59
  gboolean in_date_select;
 
60
 
 
61
  struct tm date;
 
62
} PopBox;
 
63
 
 
64
 
 
65
static void block_picker_signals (DateCell *cell);
 
66
static void unblock_picker_signals (DateCell *cell);
 
67
static void gnc_date_cell_realize (BasicCell *bcell, gpointer w);
 
68
static void gnc_date_cell_set_value_internal (BasicCell *bcell,
 
69
                                              const char *value);
 
70
static void gnc_date_cell_move (BasicCell *bcell);
 
71
static void gnc_date_cell_gui_destroy (BasicCell *bcell);
 
72
static void gnc_date_cell_destroy (BasicCell *bcell);
 
73
static void gnc_date_cell_modify_verify (BasicCell *_cell,
 
74
                                         const char *change,
 
75
                                         int change_len,
 
76
                                         const char *newval,
 
77
                                         int newval_len,
 
78
                                         int *cursor_position,
 
79
                                         int *start_selection,
 
80
                                         int *end_selection);
 
81
static gboolean gnc_date_cell_direct_update (BasicCell *bcell,
 
82
                                             int *cursor_position,
 
83
                                             int *start_selection,
 
84
                                             int *end_selection,
 
85
                                             void *gui_data);
 
86
static gboolean gnc_date_cell_enter (BasicCell *bcell,
 
87
                                     int *cursor_position,
 
88
                                     int *start_selection,
 
89
                                     int *end_selection);
 
90
static void gnc_date_cell_leave (BasicCell *bcell);
 
91
 
 
92
 
 
93
static void
 
94
gnc_parse_date (struct tm *parsed, const char * datestr)
 
95
{
 
96
  int day, month, year;
 
97
 
 
98
  if (!parsed) return;
 
99
  if (!datestr) return;
 
100
 
 
101
  qof_scan_date (datestr, &day, &month, &year);
 
102
 
 
103
  parsed->tm_mday = day;
 
104
  parsed->tm_mon  = month - 1;
 
105
  parsed->tm_year = year - 1900;
 
106
 
 
107
  gnc_tm_set_day_start(parsed);
 
108
  if (mktime (parsed) == -1)
 
109
    gnc_tm_get_today_start (parsed);
 
110
  mktime (parsed);
 
111
}
 
112
 
 
113
static void
 
114
gnc_date_cell_print_date (DateCell *cell, char *buff)
 
115
{
 
116
  PopBox *box = cell->cell.gui_private;
 
117
 
 
118
  qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
 
119
             box->date.tm_mday,
 
120
             box->date.tm_mon + 1,
 
121
             box->date.tm_year+1900);
 
122
}
 
123
 
 
124
static void
 
125
gnc_date_cell_init (DateCell *cell)
 
126
{
 
127
  PopBox *box;
 
128
  time_t secs;
 
129
  char buff[DATE_BUF];
 
130
 
 
131
  gnc_basic_cell_init (&(cell->cell));
 
132
 
 
133
  cell->cell.is_popup = TRUE;
 
134
 
 
135
  cell->cell.destroy = gnc_date_cell_destroy;
 
136
 
 
137
  cell->cell.gui_realize = gnc_date_cell_realize;
 
138
  cell->cell.gui_destroy = gnc_date_cell_gui_destroy;
 
139
  cell->cell.modify_verify = gnc_date_cell_modify_verify;
 
140
  cell->cell.direct_update = gnc_date_cell_direct_update;
 
141
  cell->cell.set_value = gnc_date_cell_set_value_internal;
 
142
 
 
143
  box = g_new0 (PopBox, 1);
 
144
 
 
145
  box->sheet = NULL;
 
146
  box->item_edit = NULL;
 
147
  box->date_picker = NULL;
 
148
 
 
149
  box->signals_connected = FALSE;
 
150
  box->calendar_popped = FALSE;
 
151
  box->in_date_select = FALSE;
 
152
 
 
153
  cell->cell.gui_private = box;
 
154
 
 
155
  /* default value is today's date */
 
156
  time (&secs);
 
157
  box->date = *localtime (&secs);
 
158
  gnc_date_cell_print_date (cell, buff);
 
159
 
 
160
  gnc_basic_cell_set_value_internal (&cell->cell, buff);
 
161
}
 
162
 
 
163
BasicCell *
 
164
gnc_date_cell_new (void)
 
165
{
 
166
   DateCell *cell;
 
167
 
 
168
   cell = g_new0 (DateCell, 1);
 
169
 
 
170
   gnc_date_cell_init (cell);
 
171
 
 
172
   return &cell->cell;
 
173
}
 
174
 
 
175
static void
 
176
date_picked_cb (GNCDatePicker *gdp, gpointer data)
 
177
{
 
178
  DateCell *cell = data;
 
179
  PopBox *box = cell->cell.gui_private;
 
180
  guint day, month, year;
 
181
  char buffer[DATE_BUF];
 
182
 
 
183
  gtk_calendar_get_date (gdp->calendar, &year, &month, &day);
 
184
 
 
185
  qof_print_date_dmy_buff (buffer, MAX_DATE_LENGTH, day, month + 1, year);
 
186
 
 
187
  box->in_date_select = TRUE;
 
188
  gnucash_sheet_modify_current_cell (box->sheet, buffer);
 
189
  box->in_date_select = FALSE;
 
190
 
 
191
  gnc_item_edit_hide_popup (box->item_edit);
 
192
  box->calendar_popped = FALSE;
 
193
}
 
194
 
 
195
static void
 
196
date_selected_cb (GNCDatePicker *gdp, gpointer data)
 
197
{
 
198
  DateCell *cell = data;
 
199
  PopBox *box = cell->cell.gui_private;
 
200
  guint day, month, year;
 
201
  char buffer[DATE_BUF];
 
202
 
 
203
  gtk_calendar_get_date (gdp->calendar, &year, &month, &day);
 
204
 
 
205
  qof_print_date_dmy_buff (buffer, MAX_DATE_LENGTH, day, month + 1, year);
 
206
 
 
207
  box->in_date_select = TRUE;
 
208
  gnucash_sheet_modify_current_cell (box->sheet, buffer);
 
209
  box->in_date_select = FALSE;
 
210
}
 
211
 
 
212
static void
 
213
key_press_item_cb (GNCDatePicker *gdp, GdkEventKey *event, gpointer data)
 
214
{
 
215
  DateCell *cell = data;
 
216
  PopBox *box = cell->cell.gui_private;
 
217
 
 
218
  switch(event->keyval)
 
219
  {
 
220
    case GDK_Escape:
 
221
      gnc_item_edit_hide_popup (box->item_edit);
 
222
      box->calendar_popped = FALSE;
 
223
      break;
 
224
 
 
225
    default:
 
226
      gtk_widget_event(GTK_WIDGET (box->sheet), (GdkEvent *) event);
 
227
      break;
 
228
  }
 
229
}
 
230
 
 
231
static void
 
232
date_picker_disconnect_signals (DateCell *cell)
 
233
{
 
234
  PopBox *box = cell->cell.gui_private;
 
235
 
 
236
  if (!box->signals_connected)
 
237
    return;
 
238
 
 
239
  g_signal_handlers_disconnect_matched (box->date_picker, G_SIGNAL_MATCH_DATA,
 
240
                                        0, 0, NULL, NULL, cell);
 
241
 
 
242
  box->signals_connected = FALSE;
 
243
}
 
244
 
 
245
static void
 
246
date_picker_connect_signals (DateCell *cell)
 
247
{
 
248
  PopBox *box = cell->cell.gui_private;
 
249
 
 
250
  if (box->signals_connected)
 
251
    return;
 
252
 
 
253
  g_signal_connect (box->date_picker, "date_selected",
 
254
                    G_CALLBACK(date_selected_cb), cell);
 
255
 
 
256
  g_signal_connect(box->date_picker, "date_picked",
 
257
                   G_CALLBACK(date_picked_cb), cell);
 
258
 
 
259
  g_signal_connect(box->date_picker, "key_press_event",
 
260
                   G_CALLBACK(key_press_item_cb), cell);
 
261
 
 
262
  box->signals_connected = TRUE;
 
263
}
 
264
 
 
265
static void
 
266
block_picker_signals (DateCell *cell)
 
267
{
 
268
  PopBox *box = cell->cell.gui_private;
 
269
 
 
270
  if (!box->signals_connected)
 
271
    return;
 
272
 
 
273
  g_signal_handlers_block_matched (box->date_picker, G_SIGNAL_MATCH_DATA,
 
274
                                   0, 0, NULL, NULL, cell);
 
275
}
 
276
 
 
277
static void
 
278
unblock_picker_signals (DateCell *cell)
 
279
{
 
280
  PopBox *box = cell->cell.gui_private;
 
281
 
 
282
  if (!box->signals_connected)
 
283
    return;
 
284
 
 
285
  g_signal_handlers_unblock_matched (box->date_picker, G_SIGNAL_MATCH_DATA,
 
286
                                     0, 0, NULL, NULL, cell);
 
287
}
 
288
 
 
289
static void
 
290
gnc_date_cell_gui_destroy (BasicCell *bcell)
 
291
{
 
292
  PopBox *box = bcell->gui_private;
 
293
  DateCell *cell = (DateCell *) bcell;
 
294
 
 
295
  if (cell->cell.gui_realize == NULL)
 
296
  {
 
297
    if (box != NULL && box->date_picker != NULL)
 
298
    {
 
299
      date_picker_disconnect_signals (cell);
 
300
      g_object_unref (box->date_picker);
 
301
      box->date_picker = NULL;
 
302
    }
 
303
 
 
304
    /* allow the widget to be shown again */
 
305
    cell->cell.gui_realize = gnc_date_cell_realize;
 
306
    cell->cell.gui_move = NULL;
 
307
    cell->cell.enter_cell = NULL;
 
308
    cell->cell.leave_cell = NULL;
 
309
    cell->cell.gui_destroy = NULL;
 
310
  }
 
311
}
 
312
 
 
313
static void
 
314
gnc_date_cell_destroy (BasicCell *bcell)
 
315
{
 
316
  DateCell *cell = (DateCell *) bcell;
 
317
  PopBox *box = cell->cell.gui_private;
 
318
 
 
319
  gnc_date_cell_gui_destroy (&(cell->cell));
 
320
 
 
321
  g_free (box);
 
322
 
 
323
  cell->cell.gui_private = NULL;
 
324
  cell->cell.gui_realize = NULL;
 
325
}
 
326
 
 
327
void 
 
328
gnc_date_cell_set_value (DateCell *cell, int day, int mon, int year)
 
329
{
 
330
  PopBox *box = cell->cell.gui_private;
 
331
  struct tm dada;
 
332
  char buff[DATE_BUF];
 
333
 
 
334
  dada.tm_mday = day;
 
335
  dada.tm_mon  = mon - 1;
 
336
  dada.tm_year = year - 1900;
 
337
 
 
338
  gnc_tm_set_day_start(&dada);
 
339
  mktime (&dada);
 
340
 
 
341
  box->date.tm_mday = dada.tm_mday;
 
342
  box->date.tm_mon  = dada.tm_mon;
 
343
  box->date.tm_year = dada.tm_year;
 
344
 
 
345
  qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH, dada.tm_mday, dada.tm_mon + 1, dada.tm_year + 1900);
 
346
 
 
347
  gnc_basic_cell_set_value_internal (&cell->cell, buff);
 
348
 
 
349
  if (!box->date_picker)
 
350
    return;
 
351
 
 
352
  block_picker_signals (cell);
 
353
  gnc_date_picker_set_date (box->date_picker, day, mon - 1, year);
 
354
  unblock_picker_signals (cell);
 
355
}
 
356
 
 
357
void 
 
358
gnc_date_cell_set_value_secs (DateCell *cell, time_t secs)
 
359
{
 
360
  PopBox *box = cell->cell.gui_private;
 
361
  char buff[DATE_BUF];
 
362
  struct tm * stm;
 
363
 
 
364
  stm = localtime (&secs);
 
365
  box->date = *stm;
 
366
 
 
367
  qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
 
368
             box->date.tm_mday, 
 
369
             box->date.tm_mon + 1, 
 
370
             box->date.tm_year + 1900);
 
371
 
 
372
  gnc_basic_cell_set_value_internal (&cell->cell, buff);
 
373
 
 
374
  if (!box->date_picker)
 
375
    return;
 
376
 
 
377
  block_picker_signals (cell);
 
378
  gnc_date_picker_set_date (box->date_picker,
 
379
                            box->date.tm_mday,
 
380
                            box->date.tm_mon,
 
381
                            box->date.tm_year + 1900);
 
382
  unblock_picker_signals (cell);
 
383
}
 
384
 
 
385
void
 
386
gnc_date_cell_commit (DateCell *cell)
 
387
{
 
388
  PopBox *box = cell->cell.gui_private;
 
389
  char buff[DATE_BUF];
 
390
 
 
391
  if (!cell)
 
392
    return;
 
393
 
 
394
  gnc_parse_date (&(box->date), cell->cell.value);
 
395
 
 
396
  qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
 
397
             box->date.tm_mday, 
 
398
             box->date.tm_mon + 1,
 
399
             box->date.tm_year + 1900);
 
400
 
 
401
  gnc_basic_cell_set_value_internal (&cell->cell, buff);
 
402
 
 
403
  if (!box->date_picker)
 
404
    return;
 
405
 
 
406
  block_picker_signals (cell);
 
407
  gnc_date_picker_set_date (box->date_picker,
 
408
                            box->date.tm_mday,
 
409
                            box->date.tm_mon,
 
410
                            box->date.tm_year + 1900);
 
411
  unblock_picker_signals (cell);
 
412
}
 
413
 
 
414
static gboolean
 
415
gnc_date_cell_direct_update (BasicCell *bcell,
 
416
                             int *cursor_position,
 
417
                             int *start_selection,
 
418
                             int *end_selection,
 
419
                             void *gui_data)
 
420
{
 
421
  DateCell *cell = (DateCell *) bcell;
 
422
  PopBox *box = cell->cell.gui_private;
 
423
  GdkEventKey *event = gui_data;
 
424
  char buff[DATE_BUF];
 
425
 
 
426
  if (!gnc_handle_date_accelerator (event, &(box->date), bcell->value))
 
427
    return FALSE;
 
428
 
 
429
  qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
 
430
             box->date.tm_mday,
 
431
             box->date.tm_mon + 1,
 
432
             box->date.tm_year + 1900);
 
433
 
 
434
  gnc_basic_cell_set_value_internal (&cell->cell, buff);
 
435
 
 
436
  *start_selection = 0;
 
437
  *end_selection = -1;
 
438
 
 
439
  if (!box->date_picker)
 
440
    return TRUE;
 
441
 
 
442
  block_picker_signals (cell);
 
443
  gnc_date_picker_set_date (box->date_picker,
 
444
                            box->date.tm_mday,
 
445
                            box->date.tm_mon,
 
446
                            box->date.tm_year + 1900);
 
447
  unblock_picker_signals (cell);
 
448
 
 
449
  return TRUE;
 
450
}
 
451
 
 
452
static void
 
453
gnc_date_cell_modify_verify (BasicCell *_cell,
 
454
                             const char *change,
 
455
                             int change_len,
 
456
                             const char *newval,
 
457
                             int newval_len,
 
458
                             int *cursor_position,
 
459
                             int *start_selection,
 
460
                             int *end_selection)
 
461
{
 
462
  DateCell *cell = (DateCell *) _cell;
 
463
  PopBox *box = cell->cell.gui_private;
 
464
  gboolean accept = FALSE;
 
465
 
 
466
  if (box->in_date_select)
 
467
  {
 
468
    gnc_basic_cell_set_value (_cell, newval);
 
469
    return;
 
470
  }
 
471
 
 
472
  /* if user hit backspace, accept the change */
 
473
  if (change == NULL)
 
474
    accept = TRUE;
 
475
  else if (change_len == 0)
 
476
    accept = TRUE;
 
477
  else
 
478
  {
 
479
    int count = 0;
 
480
    unsigned char separator = dateSeparator ();
 
481
    gboolean ok = TRUE;
 
482
    const gchar *c;
 
483
    gunichar uc;
 
484
    
 
485
    /* accept only numbers or a date separator. Note that the
 
486
     * separator of '-' (for DATE_FORMAT_ISO) takes precedence
 
487
     * over the accelerator below! */      
 
488
    c = change;
 
489
    while (*c)
 
490
    {
 
491
      uc = g_utf8_get_char (c);
 
492
        
 
493
      if (!g_unichar_isdigit (uc) && (separator != uc))
 
494
        ok = FALSE;
 
495
 
 
496
      if (separator == uc)
 
497
        count++;
 
498
      
 
499
      c = g_utf8_next_char (c);
 
500
    }      
 
501
    
 
502
    c = _cell->value;
 
503
    while (*c)
 
504
    {
 
505
      uc = g_utf8_get_char (c);
 
506
        
 
507
      if (separator == uc)
 
508
        count++;
 
509
 
 
510
      c = g_utf8_next_char (c);
 
511
    }
 
512
     
 
513
    if (2 < count)
 
514
      ok = FALSE;
 
515
 
 
516
    if (ok)
 
517
      accept = TRUE;
 
518
  }
 
519
 
 
520
  /* keep a copy of the new value */
 
521
  if (accept)
 
522
  {
 
523
 
 
524
    gnc_basic_cell_set_value_internal (&cell->cell, newval);
 
525
    gnc_parse_date (&(box->date), newval);
 
526
 
 
527
    if (!box->date_picker)
 
528
      return;
 
529
 
 
530
    block_picker_signals (cell);
 
531
    gnc_date_picker_set_date (box->date_picker,
 
532
                              box->date.tm_mday,
 
533
                              box->date.tm_mon,
 
534
                              box->date.tm_year + 1900);
 
535
    unblock_picker_signals (cell);
 
536
  }
 
537
}
 
538
 
 
539
static void
 
540
gnc_date_cell_realize (BasicCell *bcell, gpointer data)
 
541
{
 
542
  GnucashSheet *sheet = data;
 
543
  GnomeCanvasItem *item = sheet->item_editor;
 
544
  GncItemEdit *item_edit = GNC_ITEM_EDIT (item);
 
545
  DateCell *cell = (DateCell *) bcell;
 
546
  PopBox *box = cell->cell.gui_private;
 
547
 
 
548
  /* initialize gui-specific, private data */
 
549
  box->sheet = sheet;
 
550
  box->item_edit = item_edit;
 
551
  box->date_picker = gnc_item_edit_new_date_picker (box->item_edit);
 
552
#ifdef HAVE_GTK_2_10
 
553
  g_object_ref_sink(box->date_picker);
 
554
#else
 
555
  g_object_ref (box->date_picker);
 
556
  gtk_object_sink (GTK_OBJECT(box->date_picker));
 
557
#endif
 
558
 
 
559
  /* to mark cell as realized, remove the realize method */
 
560
  cell->cell.gui_realize = NULL;
 
561
  cell->cell.gui_move = gnc_date_cell_move;
 
562
  cell->cell.enter_cell = gnc_date_cell_enter;
 
563
  cell->cell.leave_cell = gnc_date_cell_leave;
 
564
}
 
565
 
 
566
static void
 
567
gnc_date_cell_move (BasicCell *bcell)
 
568
{
 
569
  PopBox *box = bcell->gui_private;
 
570
 
 
571
  date_picker_disconnect_signals ((DateCell *) bcell);
 
572
 
 
573
  gnc_item_edit_set_popup (box->item_edit, NULL, NULL,
 
574
                       NULL, NULL, NULL, NULL, NULL);
 
575
 
 
576
  box->calendar_popped = FALSE;
 
577
}
 
578
 
 
579
static int
 
580
get_popup_height (GnomeCanvasItem *item,
 
581
                  int space_available,
 
582
                  int row_height,
 
583
                  gpointer user_data)
 
584
{
 
585
  GtkWidget *cal = GTK_WIDGET (GNC_DATE_PICKER (item)->calendar);
 
586
  GtkRequisition req;
 
587
 
 
588
  req.height = 0;
 
589
  req.width = 0;
 
590
 
 
591
  gtk_widget_size_request (cal, &req);
 
592
 
 
593
  return req.height;
 
594
}
 
595
 
 
596
static void
 
597
popup_set_focus (GnomeCanvasItem *item,
 
598
                 gpointer user_data)
 
599
{
 
600
  gtk_widget_grab_focus (GTK_WIDGET (GNC_DATE_PICKER (item)->calendar));
 
601
}
 
602
 
 
603
static gboolean
 
604
gnc_date_cell_enter (BasicCell *bcell,
 
605
                     int *cursor_position,
 
606
                     int *start_selection,
 
607
                     int *end_selection)
 
608
{
 
609
  DateCell *cell = (DateCell *) bcell;
 
610
  PopBox *box = bcell->gui_private;
 
611
 
 
612
  gnc_item_edit_set_popup (box->item_edit, GNOME_CANVAS_ITEM (box->date_picker),
 
613
                       get_popup_height, NULL, popup_set_focus,
 
614
                       NULL, NULL, NULL);
 
615
 
 
616
  block_picker_signals (cell);
 
617
  gnc_date_picker_set_date (box->date_picker,
 
618
                            box->date.tm_mday,
 
619
                            box->date.tm_mon,
 
620
                            box->date.tm_year + 1900);
 
621
  unblock_picker_signals (cell);
 
622
 
 
623
  date_picker_connect_signals ((DateCell *) bcell);
 
624
 
 
625
  *start_selection = 0;
 
626
  *end_selection = -1;
 
627
 
 
628
  return TRUE;
 
629
}
 
630
 
 
631
static void
 
632
gnc_date_cell_leave (BasicCell *bcell)
 
633
{
 
634
  Timespec ts;
 
635
  PopBox *box = bcell->gui_private;
 
636
 
 
637
  date_picker_disconnect_signals ((DateCell *) bcell);
 
638
 
 
639
  gnc_item_edit_set_popup (box->item_edit, NULL, NULL,
 
640
                       NULL, NULL, NULL, NULL, NULL);
 
641
 
 
642
  box->calendar_popped = FALSE;
 
643
 
 
644
  /* Refresh the date to expand any shortcuts. */
 
645
  gnc_date_cell_get_date ((DateCell *)bcell, &ts);
 
646
  gnc_date_cell_set_value_secs ((DateCell *)bcell, ts.tv_sec);
 
647
}
 
648
 
 
649
void
 
650
gnc_date_cell_get_date (DateCell *cell, Timespec *ts)
 
651
{
 
652
  PopBox *box = cell->cell.gui_private;
 
653
 
 
654
  if (!cell || !ts)
 
655
    return;
 
656
 
 
657
  gnc_parse_date (&(box->date), cell->cell.value);
 
658
 
 
659
  ts->tv_sec = mktime (&box->date);
 
660
  ts->tv_nsec = 0;
 
661
}
 
662
 
 
663
static void 
 
664
gnc_date_cell_set_value_internal (BasicCell *_cell, const char *str)
 
665
{
 
666
  DateCell *cell = (DateCell *) _cell;
 
667
  PopBox *box = cell->cell.gui_private;
 
668
  char buff[DATE_BUF];
 
669
 
 
670
  gnc_parse_date (&(box->date), str);
 
671
 
 
672
  qof_print_date_dmy_buff (buff, MAX_DATE_LENGTH,
 
673
             box->date.tm_mday, 
 
674
             box->date.tm_mon + 1, 
 
675
             box->date.tm_year + 1900);
 
676
 
 
677
  gnc_basic_cell_set_value_internal (_cell, buff);
 
678
 
 
679
  if (!box->date_picker)
 
680
    return;
 
681
 
 
682
  block_picker_signals (cell);
 
683
  gnc_date_picker_set_date (box->date_picker,
 
684
                            box->date.tm_mday,
 
685
                            box->date.tm_mon,
 
686
                            box->date.tm_year + 1900);
 
687
  unblock_picker_signals (cell);
 
688
}