[go: up one dir, main page]

File: gtk_menu_title.c

package info (click to toggle)
dillo 0.8.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,168 kB
  • ctags: 3,987
  • sloc: ansic: 32,778; sh: 3,401; makefile: 251; perl: 17
file content (196 lines) | stat: -rw-r--r-- 5,340 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * File: selection.c
 *
 * Copyright 2004 Sebastian Geerken <s.geerken@ping.de>
 *
 * 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 is a widget with a very special purpose, for displaying titles within
 * menues. It is set to inactive (so it cannot be focussed), and the text is
 * centered horizontally.
 *
 * BTW, it is simple to change the look of menu titles, by putting the
 * following into your ~/.gtkrc file:
 *
 *    style "menu-title" = "default" {
 *      font = "-*-helvetica-medium-o-*-*-10-*-*-*-*-*-*-*"
 *    }
 *
 *    widget "*GtkMenuTitle" style "menu-title"
 */
#include "src/gtk_menu_title.h"

#define BORDER_SPACING  3

static void Gtk_menu_title_class_init   (GtkMenuTitleClass *klass);
static void Gtk_menu_title_init         (GtkMenuTitle *menu_title);

static void Gtk_menu_title_destroy      (GtkObject *object);
static void Gtk_menu_title_size_request (GtkWidget *widget,
                                         GtkRequisition *requisition);
static void Gtk_menu_title_draw         (GtkWidget *widget,
                                         GdkRectangle *area);
static gint Gtk_menu_title_expose_event (GtkWidget *widget,
                                         GdkEventExpose *event);

static GtkMenuItemClass *parent_class = NULL;


/*
 * Standard Gtk+ function.
 */
GtkType a_Gtk_menu_title_get_type (void)
{
  static GtkType type = 0;

  if (!type) {
    GtkTypeInfo info = {
      "GtkMenuTitle",
      sizeof (GtkMenuTitle),
      sizeof (GtkMenuTitleClass),
      (GtkClassInitFunc) Gtk_menu_title_class_init,
      (GtkObjectInitFunc) Gtk_menu_title_init,
      (GtkArgSetFunc) NULL,
      (GtkArgGetFunc) NULL,
      (GtkClassInitFunc)NULL
    };

    type = gtk_type_unique (gtk_menu_item_get_type (), &info);
  }

  return type;
}


/*
 * Standard Gtk+ function.
 */
static void Gtk_menu_title_class_init (GtkMenuTitleClass *klass)
{
   GtkWidgetClass *widget_class;
   GtkObjectClass *object_class;

   parent_class = (GtkMenuItemClass*) klass;

   object_class = (GtkObjectClass*) klass;
   object_class->destroy = Gtk_menu_title_destroy;

   widget_class = (GtkWidgetClass*) klass;
   widget_class->size_request = Gtk_menu_title_size_request;
   widget_class->draw = Gtk_menu_title_draw;
   widget_class->expose_event = Gtk_menu_title_expose_event;
}


/*
 * Standard Gtk+ function.
 */
static void Gtk_menu_title_init (GtkMenuTitle *menu_title)
{
   menu_title->label = NULL;
}


/*
 * Return a new GtkMenuTitle.
 */
GtkWidget* a_Gtk_menu_title_new (const char *label)
{
   GtkWidget *widget;

   widget = gtk_type_new (a_Gtk_menu_title_get_type ());
   GTK_MENU_TITLE(widget)->label = label ? g_strdup (label) : NULL;
   gtk_widget_set_sensitive (widget, FALSE);
   return widget;
}


/*
 * Standard Gtk+ function.
 */
static void Gtk_menu_title_destroy (GtkObject *object)
{
   GtkMenuTitle *menu_title;

   menu_title = GTK_MENU_TITLE (object);
   if (menu_title->label)
      g_free (menu_title->label);
}


/*
 * Standard Gtk+ function.
 */
static void Gtk_menu_title_size_request (GtkWidget *widget,
                                         GtkRequisition *requisition)
{
   GtkMenuTitle *menu_title;

   menu_title = GTK_MENU_TITLE (widget);
   requisition->width = 2 * (GTK_CONTAINER (widget)->border_width +
                             widget->style->klass->xthickness +
                             BORDER_SPACING);
   requisition->height = 2 * (GTK_CONTAINER (widget)->border_width +
                              widget->style->klass->ythickness);
   
   if (menu_title->label) {
      requisition->width +=
         gdk_string_width (widget->style->font, GTK_MENU_TITLE(widget)->label);
      requisition->height +=
         widget->style->font->ascent + widget->style->font->descent;
   }
}

/*
 * Standard Gtk+ function.
 */
static void Gtk_menu_title_paint (GtkWidget *widget,
                                  GdkRectangle *area)
{
   GtkMenuTitle *menu_title;
   gint x, y;

   menu_title = GTK_MENU_TITLE (widget);
   if (menu_title->label) {
      x =
         (widget->allocation.width - gdk_string_width (widget->style->font,
                                                       menu_title->label)) / 2;
      y =
         GTK_CONTAINER (widget)->border_width +
         widget->style->klass->ythickness
         + widget->style->font->ascent;

      /* We do not use widget->state, but instead GTK_STATE_NORMAL, since
       * otherwise, the text would be rendered gray. */
      gdk_draw_string (widget->window, widget->style->font,
                       widget->style->fg_gc[GTK_STATE_NORMAL], x, y,
                       menu_title->label);
   }
}

/*
 * Standard Gtk+ function.
 */
static void Gtk_menu_title_draw (GtkWidget *widget,
                                 GdkRectangle *area)
{
   if (GTK_WIDGET_DRAWABLE (widget))
      Gtk_menu_title_paint (widget, area);
}


/*
 * Standard Gtk+ function.
 */
static gint Gtk_menu_title_expose_event (GtkWidget *widget,
                                         GdkEventExpose *event)
{
   if (GTK_WIDGET_DRAWABLE (widget))
      Gtk_menu_title_paint (widget, &event->area);
   return TRUE;
}