File: bonobo-ui-toolbar-separator-item.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (138 lines) | stat: -rw-r--r-- 3,317 bytes parent folder | download | duplicates (2)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/**
 * bonobo-ui-toolbar-separator-item.h
 *
 * Author:
 *    Ettore Perazzoli
 *
 * Copyright (C) 2000 Helix Code, Inc.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gnome.h>
#include "bonobo-ui-toolbar-separator-item.h"


#define PARENT_TYPE bonobo_ui_toolbar_item_get_type ()
static BonoboUIToolbarItemClass *parent_class = NULL;


#define BORDER_WIDTH        2

#define SPACE_LINE_DIVISION 10
#define SPACE_LINE_START    3
#define SPACE_LINE_END      7


/* GtkWidget methods.  */

static void
impl_size_request (GtkWidget *widget,
		   GtkRequisition *requisition)
{
	int border_width;

	border_width = GTK_CONTAINER (widget)->border_width;

	requisition->width  = 2 * border_width + widget->style->klass->xthickness;
	requisition->height = 2 * border_width + widget->style->klass->ythickness;
}

static void
impl_draw (GtkWidget *widget,
	   GdkRectangle *area)
{
	BonoboUIToolbarItem *item;
	const GtkAllocation *allocation;
	GtkOrientation orientation;
	int border_width;

	item = BONOBO_UI_TOOLBAR_ITEM (widget);

	allocation = &widget->allocation;
	border_width = GTK_CONTAINER (widget)->border_width;

	orientation = bonobo_ui_toolbar_item_get_orientation (item);

	if (orientation == GTK_ORIENTATION_HORIZONTAL)
		gtk_paint_vline (widget->style, widget->window,
				 GTK_WIDGET_STATE (widget), area, widget,
				 "toolbar",
				 allocation->y + allocation->height * SPACE_LINE_START / SPACE_LINE_DIVISION,
				 allocation->y + allocation->height * SPACE_LINE_END / SPACE_LINE_DIVISION,
				 allocation->x + border_width);
	else
		gtk_paint_hline (widget->style, widget->window,
				 GTK_WIDGET_STATE (widget), area, widget,
				 "toolbar",
				 allocation->x + allocation->width * SPACE_LINE_START / SPACE_LINE_DIVISION,
				 allocation->x + allocation->width * SPACE_LINE_END / SPACE_LINE_DIVISION,
				 allocation->y + border_width);
}

static int
impl_expose_event (GtkWidget *widget,
		   GdkEventExpose *expose)
{
	gtk_widget_draw (widget, &expose->area);

	return FALSE;
}


static void
class_init (BonoboUIToolbarSeparatorItemClass *separator_item_class)
{
	GtkWidgetClass *widget_class;

	widget_class = GTK_WIDGET_CLASS (separator_item_class);
	widget_class->size_request = impl_size_request;
	widget_class->draw         = impl_draw;
	widget_class->expose_event = impl_expose_event;

	parent_class = gtk_type_class (bonobo_ui_toolbar_item_get_type ());
}

static void
init (BonoboUIToolbarSeparatorItem *toolbar_separator_item)
{
	gtk_container_set_border_width (GTK_CONTAINER (toolbar_separator_item), BORDER_WIDTH);
}


GtkType
bonobo_ui_toolbar_separator_item_get_type (void)
{
	static GtkType type = 0;

	if (type == 0) {
		static const GtkTypeInfo info = {
			"BonoboUIToolbarSeparatorItem",
			sizeof (BonoboUIToolbarSeparatorItem),
			sizeof (BonoboUIToolbarSeparatorItemClass),
			(GtkClassInitFunc) class_init,
			(GtkObjectInitFunc) init,
			/* reserved_1 */ NULL,
			/* reserved_2 */ NULL,
			(GtkClassInitFunc) NULL,
		};

		type = gtk_type_unique (PARENT_TYPE, &info);
	}

	return type;
}


GtkWidget *
bonobo_ui_toolbar_separator_item_new (void)
{
	BonoboUIToolbarSeparatorItem *new;

	new = gtk_type_new (bonobo_ui_toolbar_separator_item_get_type ());

	return GTK_WIDGET (new);
}