~ubuntu-branches/ubuntu/quantal/gnumeric/quantal

« back to all changes in this revision

Viewing changes to src/cell.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2009-06-07 11:10:47 UTC
  • mfrom: (1.1.19 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090607111047-l3rtbzfjxvmi1kx0
Tags: 1.9.8-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Promoted gnumeric-doc to Recommends in gnumeric package for help to be
    installed automatically
  - gnumeric-gtk is a transitional package
  - gnumeric conflicts with gnumeric-gtk << 1.8.3-3ubuntu1
  - call initltool-update in po*
  - remove psiconv support (psiconv is in universe):
    o debian/control: remove B-D on libpsiconv-dev
    o debian/rules: don't pass --with-psiconv to ./configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * Author:
6
6
 *    Jody Goldberg 2000-2006 (jody@gnome.org)
7
7
 *    Miguel de Icaza 1998, 1999 (miguel@kernel.org)
 
8
 *    Copyright (C) 2000-2009 Morten Welinder (terra@gnome.org)
8
9
 */
9
10
#include <gnumeric-config.h>
10
11
#include "gnumeric.h"
17
18
#include "expr-impl.h"
18
19
#include "rendered-value.h"
19
20
#include "value.h"
20
 
#include "str.h"
21
21
#include "style.h"
22
22
#include "ranges.h"
23
23
#include "gnm-format.h"
348
348
gnm_cell_is_blank (GnmCell const * cell)
349
349
{
350
350
        return gnm_cell_is_empty (cell) ||
351
 
                (VALUE_IS_STRING (cell->value) && *(cell->value->v_str.val->str) == '\0');
 
351
                (VALUE_IS_STRING (cell->value) &&
 
352
                 *value_peek_string (cell->value) == '\0');
352
353
}
353
354
 
354
355
GnmValue *
439
440
gboolean
440
441
gnm_cell_is_nonsingleton_array (GnmCell const *cell)
441
442
{
442
 
        GnmExprArrayCorner const *corner = gnm_cell_is_array_corner (cell);
443
 
 
 
443
        GnmExprArrayCorner const *corner;
 
444
 
 
445
        if ((cell == NULL) || !gnm_cell_has_expr (cell))
 
446
                return FALSE;
 
447
        if (gnm_expr_top_is_array_elem (cell->base.texpr, NULL, NULL))
 
448
                return TRUE;
 
449
 
 
450
        corner  = gnm_expr_top_get_array_corner (cell->base.texpr);             
444
451
        return corner && (corner->cols > 1 || corner->rows > 1);
445
452
}
446
453
 
526
533
char *
527
534
gnm_cell_get_entered_text (GnmCell const *cell)
528
535
{
 
536
        GnmValue const *v;
 
537
        Sheet *sheet;
 
538
 
529
539
        g_return_val_if_fail (cell != NULL, NULL);
530
540
 
 
541
        sheet = cell->base.sheet;
 
542
 
531
543
        if (gnm_cell_has_expr (cell)) {
532
544
                GnmParsePos pp;
533
545
                GnmConventionsOut out;
534
546
 
535
547
                out.accum = g_string_new ("=");
536
548
                out.pp = parse_pos_init_cell (&pp, cell);
537
 
                out.convs = cell->base.sheet->convs;
 
549
                out.convs = sheet->convs;
538
550
 
539
551
                gnm_expr_top_as_gstring (cell->base.texpr, &out);
540
552
                return g_string_free (out.accum, FALSE);
541
553
        }
542
554
 
543
 
        if (cell->value != NULL) {
544
 
                if (VALUE_IS_STRING (cell->value)) {
 
555
        v = cell->value;
 
556
        if (v != NULL) {
 
557
                GODateConventions const *date_conv =
 
558
                        workbook_date_conv (sheet->workbook);
 
559
 
 
560
                if (VALUE_IS_STRING (v)) {
545
561
                        /* Try to be reasonably smart about adding a leading quote */
546
 
                        char const *tmp = cell->value->v_str.val->str;
 
562
                        char const *tmp = value_peek_string (v);
547
563
 
548
564
                        if (tmp[0] != '\'' && !gnm_expr_char_start_p (tmp)) {
549
 
                                GnmValue *val = format_match_number (tmp,
550
 
                                        gnm_cell_get_format     (cell),
551
 
                                        workbook_date_conv (cell->base.sheet->workbook));
 
565
                                GnmValue *val = format_match_number
 
566
                                        (tmp,
 
567
                                         gnm_cell_get_format (cell),
 
568
                                         date_conv);
552
569
                                if (val == NULL)
553
570
                                        return g_strdup (tmp);
554
571
                                value_release (val);
555
572
                        }
556
573
                        return g_strconcat ("\'", tmp, NULL);
 
574
                } else {
 
575
                        GOFormat const *fmt = gnm_cell_get_format (cell);
 
576
                        return format_value (fmt, v, NULL, -1,  date_conv);
557
577
                }
558
 
                return format_value (NULL, cell->value, NULL, -1,
559
 
                        workbook_date_conv (cell->base.sheet->workbook));
560
578
        }
561
579
 
562
580
        g_warning ("A cell with no expression, and no value ??");
624
642
 * Get the display format.  If the assigned format is General,
625
643
 * the format of the value will be used.
626
644
 **/
627
 
GOFormat *
 
645
GOFormat const *
628
646
gnm_cell_get_format (GnmCell const *cell)
629
647
{
630
 
        GOFormat *fmt;
 
648
        GOFormat const *fmt;
631
649
 
632
650
        g_return_val_if_fail (cell != NULL, go_format_general ());
633
651
 
654
672
gnm_cell_set_format (GnmCell *cell, char const *format)
655
673
{
656
674
        GnmRange r;
657
 
        GnmStyle *mstyle = gnm_style_new ();
658
 
 
659
 
        g_return_if_fail (mstyle != NULL);
660
 
 
 
675
        GnmStyle *mstyle;
 
676
 
 
677
        g_return_if_fail (cell != NULL);
 
678
        g_return_if_fail (format != NULL);
 
679
 
 
680
        mstyle = gnm_style_new ();
661
681
        gnm_style_set_format_text (mstyle, format);
662
682
 
663
683
        r.start = r.end = cell->pos;