File: extspinbutton.c

package info (click to toggle)
soundtracker 0.3.8-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,884 kB
  • ctags: 2,176
  • sloc: ansic: 19,640; sh: 327; makefile: 266; asm: 156; sed: 93
file content (114 lines) | stat: -rw-r--r-- 3,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

/*
 * The Real SoundTracker - GTK+ Spinbutton extensions
 *
 * Copyright (C) 1999 Michael Krause
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <math.h>

#include "extspinbutton.h"

/* These two defines have been taken from gtkspinbutton.c in gtk+-1.2.1
   Unfortunately there's no cleaner solution */

#define MIN_SPIN_BUTTON_WIDTH              30
#define ARROW_SIZE                         11

static GtkEntryClass *parent_class = NULL;

static int
extspinbutton_find_display_digits (GtkAdjustment *adjustment)
{
    int num_digits;

    num_digits = adjustment->lower < 0 || adjustment->upper < 0;
    num_digits += ceil(log10(MAX(1000, MAX(ABS(adjustment->lower), ABS(adjustment->upper)))));

    return num_digits;
}

static void
extspinbutton_size_request (GtkWidget      *widget,
			    GtkRequisition *requisition)
{
    g_return_if_fail (widget != NULL);
    g_return_if_fail (requisition != NULL);
    g_return_if_fail (GTK_IS_SPIN_BUTTON (widget));

    GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);

    requisition->width = MAX (MIN_SPIN_BUTTON_WIDTH,
			      extspinbutton_find_display_digits(GTK_SPIN_BUTTON(widget)->adjustment)
			      * gdk_string_width(widget->style->font, "X"))
	+ ARROW_SIZE
	+ 2 * widget->style->klass->xthickness;
}


GtkWidget *
extspinbutton_new (GtkAdjustment *adjustment,
		   gfloat climb_rate,
		   guint digits)
{
    ExtSpinButton *s;

    s = gtk_type_new(extspinbutton_get_type());
    gtk_spin_button_configure(GTK_SPIN_BUTTON(s), adjustment, climb_rate, digits);

    return GTK_WIDGET(s);
}

static void
extspinbutton_init (ExtSpinButton *s)
{
}

static void
extspinbutton_class_init (ExtSpinButtonClass *class)
{
    GtkWidgetClass   *widget_class;

    widget_class = (GtkWidgetClass*)class;

    widget_class->size_request = extspinbutton_size_request;

    parent_class = gtk_type_class (GTK_TYPE_ENTRY);
}

guint
extspinbutton_get_type (void)
{
    static guint extspinbutton_type = 0;
    
    if (!extspinbutton_type) {
	GtkTypeInfo extspinbutton_info =
	{
	    "ExtSpinButton",
	    sizeof(ExtSpinButton),
	    sizeof(ExtSpinButtonClass),
	    (GtkClassInitFunc) extspinbutton_class_init,
	    (GtkObjectInitFunc) extspinbutton_init,
	    (GtkArgSetFunc) NULL,
	    (GtkArgGetFunc) NULL,
	};
	
	extspinbutton_type = gtk_type_unique(gtk_spin_button_get_type (), &extspinbutton_info);
    }
    
    return extspinbutton_type;
}