~ubuntu-branches/ubuntu/quantal/gnome-games/quantal-proposed

« back to all changes in this revision

Viewing changes to gtali/src/games-frame.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell, Jeremy Bicha, Robert Ancell
  • Date: 2012-11-06 10:56:12 UTC
  • mfrom: (170.1.5 quantal)
  • Revision ID: package-import@ubuntu.com-20121106105612-80ig0ec8l36noz2v
Tags: 1:3.6.0.2-0ubuntu1.1
[ Jeremy Bicha ]
* debian/patches/03_add-keywords.patch:
  - Dropped, already applied

[ Robert Ancell ]
* debian/scores/gnome-mahjongg.inst:
 - Fix name of score files (LP: #1074861)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2009 Christian Persch
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
 
 
22
#include <gtk/gtk.h>
 
23
 
 
24
#include "games-frame.h"
 
25
 
 
26
enum {
 
27
  PROP_0,
 
28
  PROP_LABEL
 
29
};
 
30
 
 
31
G_DEFINE_TYPE (GamesFrame, games_frame, GTK_TYPE_BOX);
 
32
 
 
33
struct GamesFramePrivate {
 
34
  GtkWidget *label;
 
35
  GtkWidget *alignment;
 
36
};
 
37
 
 
38
static void
 
39
games_frame_init (GamesFrame * frame)
 
40
{
 
41
  GtkBox *box = GTK_BOX (frame);
 
42
  PangoAttrList *attr_list;
 
43
  PangoAttribute *attr;
 
44
 
 
45
  frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame, GAMES_TYPE_FRAME, GamesFramePrivate);
 
46
 
 
47
  gtk_box_set_spacing (box, 6);
 
48
  gtk_box_set_homogeneous (box, FALSE);
 
49
  gtk_orientable_set_orientation (GTK_ORIENTABLE (frame), GTK_ORIENTATION_VERTICAL);
 
50
 
 
51
  frame->priv->label = gtk_label_new (NULL);
 
52
  gtk_misc_set_alignment (GTK_MISC (frame->priv->label), 0.0, 0.5);
 
53
 
 
54
  attr_list = pango_attr_list_new ();
 
55
  attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
 
56
  attr->start_index = 0;
 
57
  attr->end_index = -1;
 
58
  pango_attr_list_insert (attr_list, attr);
 
59
  gtk_label_set_attributes (GTK_LABEL (frame->priv->label), attr_list);
 
60
  pango_attr_list_unref (attr_list);
 
61
 
 
62
  frame->priv->alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
 
63
  gtk_alignment_set_padding (GTK_ALIGNMENT (frame->priv->alignment), 0, 0, 12, 0);
 
64
 
 
65
  gtk_box_pack_start (box, frame->priv->label, FALSE, FALSE, 0);
 
66
  gtk_box_pack_start (box, frame->priv->alignment, TRUE, TRUE, 0);
 
67
 
 
68
  gtk_widget_set_no_show_all (frame->priv->label, TRUE);
 
69
  gtk_widget_show (frame->priv->alignment);
 
70
}
 
71
 
 
72
static void
 
73
add_atk_relation (GtkWidget *widget, GtkWidget *other, AtkRelationType type)
 
74
{
 
75
  AtkRelationSet *set;
 
76
  AtkRelation *relation;
 
77
  AtkObject *object;
 
78
 
 
79
  object = gtk_widget_get_accessible (other);
 
80
  set = atk_object_ref_relation_set (gtk_widget_get_accessible (widget));
 
81
  relation = atk_relation_new (&object, 1, type);
 
82
  atk_relation_set_add (set, relation);
 
83
  g_object_unref (relation);
 
84
  g_object_unref (set);
 
85
}
 
86
 
 
87
static void
 
88
games_frame_add (GtkContainer *container,
 
89
                 GtkWidget *child)
 
90
{
 
91
  GamesFrame *frame = GAMES_FRAME (container);
 
92
 
 
93
  gtk_container_add (GTK_CONTAINER (frame->priv->alignment), child);
 
94
 
 
95
  add_atk_relation (frame->priv->label, child, ATK_RELATION_LABEL_FOR);
 
96
  add_atk_relation (child, frame->priv->label, ATK_RELATION_LABELLED_BY);
 
97
}
 
98
 
 
99
static void
 
100
games_frame_set_property (GObject *object,
 
101
                          guint prop_id,
 
102
                          const GValue *value,
 
103
                          GParamSpec *pspec)
 
104
{
 
105
  GamesFrame *frame = GAMES_FRAME (object);
 
106
 
 
107
  switch (prop_id) {
 
108
    case PROP_LABEL:
 
109
      games_frame_set_label (frame, g_value_get_string (value));
 
110
      break;
 
111
 
 
112
    default:
 
113
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
114
      break;
 
115
  }
 
116
}
 
117
 
 
118
static void
 
119
games_frame_class_init (GamesFrameClass * klass)
 
120
{
 
121
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
122
  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
123
 
 
124
  object_class->set_property = games_frame_set_property;
 
125
  container_class->add = games_frame_add;
 
126
 
 
127
  g_type_class_add_private (object_class, sizeof (GamesFramePrivate));
 
128
 
 
129
  g_object_class_install_property
 
130
    (object_class,
 
131
     PROP_LABEL,
 
132
     g_param_spec_string ("label", NULL, NULL,
 
133
                          NULL,
 
134
                          G_PARAM_WRITABLE |
 
135
                          G_PARAM_STATIC_NAME |
 
136
                          G_PARAM_STATIC_NICK |
 
137
                          G_PARAM_STATIC_BLURB));
 
138
}
 
139
 
 
140
/**
 
141
 * games_frame_new:
 
142
 * @label: the frame's title, or %NULL
 
143
 *
 
144
 * Returns: a new #GamesFrame
 
145
 **/
 
146
GtkWidget *
 
147
games_frame_new (const char * label)
 
148
{
 
149
  return g_object_new (GAMES_TYPE_FRAME,
 
150
                       "label", label,
 
151
                       NULL);
 
152
}
 
153
 
 
154
/**
 
155
 * games_frame_set_label:
 
156
 * @frame:
 
157
 * @label:
 
158
 *
 
159
 * Sets @frame's title label.
 
160
 */
 
161
void
 
162
games_frame_set_label (GamesFrame *frame,
 
163
                       const char *label)
 
164
{
 
165
  g_return_if_fail (GAMES_IS_FRAME (frame));
 
166
 
 
167
  if (label) {
 
168
    gtk_label_set_text (GTK_LABEL (frame->priv->label), label);
 
169
  } else {
 
170
    gtk_label_set_text (GTK_LABEL (frame->priv->label), "");
 
171
  }
 
172
 
 
173
  g_object_set (frame->priv->label, "visible", label && label[0], NULL);
 
174
 
 
175
  g_object_notify (G_OBJECT (frame), "label");
 
176
}