~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/number-opt-number.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SEEN_NUMBER_OPT_NUMBER_H
 
2
#define SEEN_NUMBER_OPT_NUMBER_H
 
3
 
 
4
/** \file
 
5
 * <number-opt-number> implementation.
 
6
 */
 
7
/*
 
8
 * Authors:
 
9
 *   Hugo Rodrigues <haa.rodrigues@gmail.com>
 
10
 *
 
11
 * Copyright (C) 2006 Hugo Rodrigues
 
12
 *
 
13
 * Released under GNU GPL, read the file 'COPYING' for more information
 
14
 */
 
15
 
 
16
#ifdef HAVE_CONFIG_H
 
17
#include "config.h"
 
18
#endif
 
19
 
 
20
#include <glib.h>
 
21
#include <glib/gprintf.h>
 
22
//todo: use glib instead of stdlib
 
23
#include <stdlib.h>
 
24
#include "svg/stringstream.h"
 
25
 
 
26
 
 
27
gdouble fixed_g_ascii_strtod (const gchar *nptr, gchar **endptr);
 
28
 
 
29
class NumberOptNumber {
 
30
 
 
31
public:
 
32
 
 
33
    gfloat number; 
 
34
 
 
35
    gfloat optNumber;
 
36
 
 
37
    guint _set : 1;
 
38
 
 
39
    guint optNumber_set : 1;
 
40
 
 
41
    NumberOptNumber()
 
42
    {
 
43
        number = 0.0;
 
44
        optNumber = 0.0;
 
45
 
 
46
        _set = FALSE;
 
47
        optNumber_set = FALSE;
 
48
    }
 
49
 
 
50
    gfloat getNumber()
 
51
    {
 
52
        if(_set)
 
53
            return number;
 
54
        return -1;
 
55
    }
 
56
 
 
57
    gfloat getOptNumber()
 
58
    {
 
59
        if(optNumber_set)
 
60
            return optNumber;
 
61
        return -1;
 
62
    }
 
63
 
 
64
    void setOptNumber(gfloat num)
 
65
    {
 
66
        optNumber_set = true;
 
67
        optNumber = num;
 
68
    }
 
69
 
 
70
    void setNumber(gfloat num)
 
71
    {
 
72
        _set = true;
 
73
        number = num;
 
74
    }
 
75
 
 
76
    bool optNumIsSet(){
 
77
        return optNumber_set;
 
78
    }
 
79
 
 
80
    bool numIsSet(){
 
81
        return _set;
 
82
    }
 
83
    
 
84
    gchar *getValueString()
 
85
    {
 
86
        Inkscape::SVGOStringStream os;
 
87
 
 
88
        if( _set )
 
89
        {
 
90
 
 
91
            if( optNumber_set )
 
92
            {
 
93
                os << number << " " << optNumber;
 
94
            }
 
95
            else {
 
96
                os << number;
 
97
            }
 
98
        }
 
99
        return g_strdup(os.str().c_str());
 
100
    }
 
101
 
 
102
    void set(gchar const *str)
 
103
    {
 
104
        if(!str)
 
105
            return;
 
106
 
 
107
        gchar **values = g_strsplit(str, " ", 2);
 
108
 
 
109
        if( values[0] != NULL )
 
110
        {
 
111
            number = g_ascii_strtod(values[0], NULL);
 
112
            _set = TRUE;
 
113
 
 
114
            if( values[1] != NULL )
 
115
            {
 
116
                optNumber = g_ascii_strtod(values[1], NULL);
 
117
                optNumber_set = TRUE;
 
118
            }
 
119
            else
 
120
                optNumber_set = FALSE;
 
121
        }
 
122
        else {
 
123
                _set = FALSE;
 
124
                optNumber_set = FALSE;
 
125
        }
 
126
    }
 
127
 
 
128
};
 
129
 
 
130
#endif /* !SEEN_NUMBER_OPT_NUMBER_H */
 
131
 
 
132
/*
 
133
  Local Variables:
 
134
  mode:c++
 
135
  c-file-style:"stroustrup"
 
136
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
137
  indent-tabs-mode:nil
 
138
  fill-column:99
 
139
  End:
 
140
*/
 
141
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :