gtklistitem.c 20.9 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Elliot Lee's avatar
Elliot Lee committed
2 3 4
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19

20
/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

27
#include "config.h"
28 29 30

#include <gdk/gdkkeysyms.h>

31 32 33
#undef GTK_DISABLE_DEPRECATED
#define __GTK_LIST_ITEM_C__

34
#include "gtkbindings.h"
Elliot Lee's avatar
Elliot Lee committed
35 36 37
#include "gtklabel.h"
#include "gtklistitem.h"
#include "gtklist.h"
38
#include "gtkmarshalers.h"
39
#include "gtksignal.h"
40
#include "gtkintl.h"
41

42
#include "gtkalias.h"
Elliot Lee's avatar
Elliot Lee committed
43 44


45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
enum
{
  TOGGLE_FOCUS_ROW,
  SELECT_ALL,
  UNSELECT_ALL,
  UNDO_SELECTION,
  START_SELECTION,
  END_SELECTION,
  TOGGLE_ADD_MODE,
  EXTEND_SELECTION,
  SCROLL_VERTICAL,
  SCROLL_HORIZONTAL,
  LAST_SIGNAL
};

static void gtk_list_item_class_init        (GtkListItemClass *klass);
static void gtk_list_item_init              (GtkListItem      *list_item);
static void gtk_list_item_realize           (GtkWidget        *widget);
static void gtk_list_item_size_request      (GtkWidget        *widget,
					     GtkRequisition   *requisition);
static void gtk_list_item_size_allocate     (GtkWidget        *widget,
					     GtkAllocation    *allocation);
67 68
static void gtk_list_item_style_set         (GtkWidget        *widget,
					     GtkStyle         *previous_style);
69 70 71 72 73 74 75 76 77
static gint gtk_list_item_button_press      (GtkWidget        *widget,
					     GdkEventButton   *event);
static gint gtk_list_item_expose            (GtkWidget        *widget,
					     GdkEventExpose   *event);
static void gtk_real_list_item_select       (GtkItem          *item);
static void gtk_real_list_item_deselect     (GtkItem          *item);
static void gtk_real_list_item_toggle       (GtkItem          *item);


Elliot Lee's avatar
Elliot Lee committed
78
static GtkItemClass *parent_class = NULL;
79
static guint list_item_signals[LAST_SIGNAL] = {0};
Elliot Lee's avatar
Elliot Lee committed
80 81


82
GtkType
83
gtk_list_item_get_type (void)
Elliot Lee's avatar
Elliot Lee committed
84
{
85
  static GtkType list_item_type = 0;
Elliot Lee's avatar
Elliot Lee committed
86 87 88

  if (!list_item_type)
    {
89
      static const GtkTypeInfo list_item_info =
Elliot Lee's avatar
Elliot Lee committed
90 91 92 93 94 95
      {
	"GtkListItem",
	sizeof (GtkListItem),
	sizeof (GtkListItemClass),
	(GtkClassInitFunc) gtk_list_item_class_init,
	(GtkObjectInitFunc) gtk_list_item_init,
96 97
	/* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
98
        (GtkClassInitFunc) NULL,
Elliot Lee's avatar
Elliot Lee committed
99 100
      };

101
      I_("GtkListItem");
Elliot Lee's avatar
Elliot Lee committed
102 103 104 105 106 107 108 109 110
      list_item_type = gtk_type_unique (gtk_item_get_type (), &list_item_info);
    }

  return list_item_type;
}

static void
gtk_list_item_class_init (GtkListItemClass *class)
{
111
  GtkObjectClass *object_class;
Elliot Lee's avatar
Elliot Lee committed
112 113
  GtkWidgetClass *widget_class;
  GtkItemClass *item_class;
114
  GtkBindingSet *binding_set;
Elliot Lee's avatar
Elliot Lee committed
115

116
  object_class = (GtkObjectClass*) class;
Elliot Lee's avatar
Elliot Lee committed
117 118 119 120 121
  widget_class = (GtkWidgetClass*) class;
  item_class = (GtkItemClass*) class;

  parent_class = gtk_type_class (gtk_item_get_type ());

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  widget_class->realize = gtk_list_item_realize;
  widget_class->size_request = gtk_list_item_size_request;
  widget_class->size_allocate = gtk_list_item_size_allocate;
  widget_class->style_set = gtk_list_item_style_set;
  widget_class->button_press_event = gtk_list_item_button_press;
  widget_class->expose_event = gtk_list_item_expose;

  item_class->select = gtk_real_list_item_select;
  item_class->deselect = gtk_real_list_item_deselect;
  item_class->toggle = gtk_real_list_item_toggle;

  class->toggle_focus_row = NULL;
  class->select_all = NULL;
  class->unselect_all = NULL;
  class->undo_selection = NULL;
  class->start_selection = NULL;
  class->end_selection = NULL;
  class->extend_selection = NULL;
  class->scroll_horizontal = NULL;
  class->scroll_vertical = NULL;
  class->toggle_add_mode = NULL;

144
  list_item_signals[TOGGLE_FOCUS_ROW] =
145
    gtk_signal_new (I_("toggle-focus-row"),
146
                    GTK_RUN_LAST | GTK_RUN_ACTION,
147
                    GTK_CLASS_TYPE (object_class),
148
                    GTK_SIGNAL_OFFSET (GtkListItemClass, toggle_focus_row),
149
                    _gtk_marshal_VOID__VOID,
150 151
                    GTK_TYPE_NONE, 0);
  list_item_signals[SELECT_ALL] =
152
    gtk_signal_new (I_("select-all"),
153
                    GTK_RUN_LAST | GTK_RUN_ACTION,
154
                    GTK_CLASS_TYPE (object_class),
155
                    GTK_SIGNAL_OFFSET (GtkListItemClass, select_all),
156
                    _gtk_marshal_VOID__VOID,
157 158
                    GTK_TYPE_NONE, 0);
  list_item_signals[UNSELECT_ALL] =
159
    gtk_signal_new (I_("unselect-all"),
160
                    GTK_RUN_LAST | GTK_RUN_ACTION,
161
                    GTK_CLASS_TYPE (object_class),
162
                    GTK_SIGNAL_OFFSET (GtkListItemClass, unselect_all),
163
                    _gtk_marshal_VOID__VOID,
164 165
                    GTK_TYPE_NONE, 0);
  list_item_signals[UNDO_SELECTION] =
166
    gtk_signal_new (I_("undo-selection"),
167
		    GTK_RUN_LAST | GTK_RUN_ACTION,
168
		    GTK_CLASS_TYPE (object_class),
169
		    GTK_SIGNAL_OFFSET (GtkListItemClass, undo_selection),
170
		    _gtk_marshal_VOID__VOID,
171 172
		    GTK_TYPE_NONE, 0);
  list_item_signals[START_SELECTION] =
173
    gtk_signal_new (I_("start-selection"),
174
		    GTK_RUN_LAST | GTK_RUN_ACTION,
175
		    GTK_CLASS_TYPE (object_class),
176
		    GTK_SIGNAL_OFFSET (GtkListItemClass, start_selection),
177
		    _gtk_marshal_VOID__VOID,
178 179
		    GTK_TYPE_NONE, 0);
  list_item_signals[END_SELECTION] =
180
    gtk_signal_new (I_("end-selection"),
181
		    GTK_RUN_LAST | GTK_RUN_ACTION,
182
		    GTK_CLASS_TYPE (object_class),
183
		    GTK_SIGNAL_OFFSET (GtkListItemClass, end_selection),
184
		    _gtk_marshal_VOID__VOID,
185 186
		    GTK_TYPE_NONE, 0);
  list_item_signals[TOGGLE_ADD_MODE] =
187
    gtk_signal_new (I_("toggle-add-mode"),
188
		    GTK_RUN_LAST | GTK_RUN_ACTION,
189
		    GTK_CLASS_TYPE (object_class),
190
		    GTK_SIGNAL_OFFSET (GtkListItemClass, toggle_add_mode),
191
		    _gtk_marshal_VOID__VOID,
192 193
		    GTK_TYPE_NONE, 0);
  list_item_signals[EXTEND_SELECTION] =
194
    gtk_signal_new (I_("extend-selection"),
195
                    GTK_RUN_LAST | GTK_RUN_ACTION,
196
                    GTK_CLASS_TYPE (object_class),
197
                    GTK_SIGNAL_OFFSET (GtkListItemClass, extend_selection),
198
                    _gtk_marshal_VOID__ENUM_FLOAT_BOOLEAN,
199
                    GTK_TYPE_NONE, 3,
200
		    GTK_TYPE_SCROLL_TYPE, GTK_TYPE_FLOAT, GTK_TYPE_BOOL);
201
  list_item_signals[SCROLL_VERTICAL] =
202
    gtk_signal_new (I_("scroll-vertical"),
203
                    GTK_RUN_LAST | GTK_RUN_ACTION,
204
                    GTK_CLASS_TYPE (object_class),
205
                    GTK_SIGNAL_OFFSET (GtkListItemClass, scroll_vertical),
206
                    _gtk_marshal_VOID__ENUM_FLOAT,
207
                    GTK_TYPE_NONE, 2, GTK_TYPE_SCROLL_TYPE, GTK_TYPE_FLOAT);
208
  list_item_signals[SCROLL_HORIZONTAL] =
209
    gtk_signal_new (I_("scroll-horizontal"),
210
                    GTK_RUN_LAST | GTK_RUN_ACTION,
211
                    GTK_CLASS_TYPE (object_class),
212
                    GTK_SIGNAL_OFFSET (GtkListItemClass, scroll_horizontal),
213
                    _gtk_marshal_VOID__ENUM_FLOAT,
214
                    GTK_TYPE_NONE, 2, GTK_TYPE_SCROLL_TYPE, GTK_TYPE_FLOAT);
215

216 217
  binding_set = gtk_binding_set_by_class (class);
  gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
218
				"scroll-vertical", 2,
219 220
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
				GTK_TYPE_FLOAT, 0.0);
221
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, 0,
222
				"scroll-vertical", 2,
223 224
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
				GTK_TYPE_FLOAT, 0.0);
225
  gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
226
				"scroll-vertical", 2,
227 228
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
				GTK_TYPE_FLOAT, 0.0);
229
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, 0,
230
				"scroll-vertical", 2,
231 232
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
				GTK_TYPE_FLOAT, 0.0);
233
  gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
234
				"scroll-vertical", 2,
235 236
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
				GTK_TYPE_FLOAT, 0.0);
237
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, 0,
238
				"scroll-vertical", 2,
239 240
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
				GTK_TYPE_FLOAT, 0.0);
241
  gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
242
				"scroll-vertical", 2,
243 244
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
				GTK_TYPE_FLOAT, 0.0);
245
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, 0,
246
				"scroll-vertical", 2,
247 248
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
				GTK_TYPE_FLOAT, 0.0);
249
  gtk_binding_entry_add_signal (binding_set, GDK_Home, GDK_CONTROL_MASK,
250
				"scroll-vertical", 2,
251 252
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 0.0);
253
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, GDK_CONTROL_MASK,
254
				"scroll-vertical", 2,
255 256
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 0.0);
257
  gtk_binding_entry_add_signal (binding_set, GDK_End, GDK_CONTROL_MASK,
258
				"scroll-vertical", 2,
259 260
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 1.0);
261
  gtk_binding_entry_add_signal (binding_set, GDK_KP_End, GDK_CONTROL_MASK,
262
				"scroll-vertical", 2,
263 264 265
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 1.0);
  
266
  gtk_binding_entry_add_signal (binding_set, GDK_Up, GDK_SHIFT_MASK,
267
				"extend-selection", 3,
268 269
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
270
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, GDK_SHIFT_MASK,
271
				"extend-selection", 3,
272 273 274
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
  
275
  gtk_binding_entry_add_signal (binding_set, GDK_Down, GDK_SHIFT_MASK,
276
				"extend-selection", 3,
277 278
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
279
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, GDK_SHIFT_MASK,
280
				"extend-selection", 3,
281 282
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
283
  gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, GDK_SHIFT_MASK,
284
				"extend-selection", 3,
285 286
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
287
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, GDK_SHIFT_MASK,
288
				"extend-selection", 3,
289 290
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_BACKWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
291
  gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, GDK_SHIFT_MASK,
292
				"extend-selection", 3,
293 294
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
295
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, GDK_SHIFT_MASK,
296
				"extend-selection", 3,
297 298
				GTK_TYPE_ENUM, GTK_SCROLL_PAGE_FORWARD,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
299 300
  gtk_binding_entry_add_signal (binding_set, GDK_Home,
				GDK_SHIFT_MASK | GDK_CONTROL_MASK,
301
				"extend-selection", 3,
302 303
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
304 305
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Home,
				GDK_SHIFT_MASK | GDK_CONTROL_MASK,
306
				"extend-selection", 3,
307 308
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 0.0, GTK_TYPE_BOOL, TRUE);
309 310
  gtk_binding_entry_add_signal (binding_set, GDK_End,
				GDK_SHIFT_MASK | GDK_CONTROL_MASK,
311
				"extend-selection", 3,
312 313
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 1.0, GTK_TYPE_BOOL, TRUE);
314 315
  gtk_binding_entry_add_signal (binding_set, GDK_KP_End,
				GDK_SHIFT_MASK | GDK_CONTROL_MASK,
316
				"extend-selection", 3,
317 318
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 1.0, GTK_TYPE_BOOL, TRUE);
319

320
  
321
  gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
322
				"scroll-horizontal", 2,
323 324
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
				GTK_TYPE_FLOAT, 0.0);
325
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0,
326
				"scroll-horizontal", 2,
327 328
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_BACKWARD,
				GTK_TYPE_FLOAT, 0.0);
329
  gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
330
				"scroll-horizontal", 2,
331 332
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
				GTK_TYPE_FLOAT, 0.0);
333
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0,
334
				"scroll-horizontal", 2,
335 336
				GTK_TYPE_ENUM, GTK_SCROLL_STEP_FORWARD,
				GTK_TYPE_FLOAT, 0.0);
337
  gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
338
				"scroll-horizontal", 2,
339 340
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 0.0);
341
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
342
				"scroll-horizontal", 2,
343 344
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 0.0);
345
  gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
346
				"scroll-horizontal", 2,
347 348
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 1.0);
349
  gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
350
				"scroll-horizontal", 2,
351 352 353
				GTK_TYPE_ENUM, GTK_SCROLL_JUMP,
				GTK_TYPE_FLOAT, 1.0);
  
354
  gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
355
				"undo-selection", 0);
356
  gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
357
				"toggle-focus-row", 0);
358
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
359
				"toggle-focus-row", 0);
360
  gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
361
				"toggle-add-mode", 0);
362
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
363
				"toggle-add-mode", 0);
364
  gtk_binding_entry_add_signal (binding_set, GDK_slash, GDK_CONTROL_MASK,
365
				"select-all", 0);
366
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Divide, GDK_CONTROL_MASK,
367
				"select-all", 0);
368
  gtk_binding_entry_add_signal (binding_set, '\\', GDK_CONTROL_MASK,
369
				"unselect-all", 0);
370 371
  gtk_binding_entry_add_signal (binding_set, GDK_Shift_L,
				GDK_RELEASE_MASK | GDK_SHIFT_MASK,
372
				"end-selection", 0);
373 374
  gtk_binding_entry_add_signal (binding_set, GDK_Shift_R,
				GDK_RELEASE_MASK | GDK_SHIFT_MASK,
375
				"end-selection", 0);
376 377 378
  gtk_binding_entry_add_signal (binding_set, GDK_Shift_R,
				GDK_RELEASE_MASK | GDK_SHIFT_MASK |
				GDK_CONTROL_MASK,
379
				"end-selection", 0);
Elliot Lee's avatar
Elliot Lee committed
380 381 382 383 384 385 386 387 388
}

static void
gtk_list_item_init (GtkListItem *list_item)
{
  GTK_WIDGET_SET_FLAGS (list_item, GTK_CAN_FOCUS);
}

GtkWidget*
389
gtk_list_item_new (void)
Elliot Lee's avatar
Elliot Lee committed
390 391 392 393 394 395 396 397 398 399 400 401 402
{
  return GTK_WIDGET (gtk_type_new (gtk_list_item_get_type ()));
}

GtkWidget*
gtk_list_item_new_with_label (const gchar *label)
{
  GtkWidget *list_item;
  GtkWidget *label_widget;

  list_item = gtk_list_item_new ();
  label_widget = gtk_label_new (label);
  gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5);
403 404
  gtk_misc_set_padding (GTK_MISC (label_widget), 0, 1);
  
Elliot Lee's avatar
Elliot Lee committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
  gtk_container_add (GTK_CONTAINER (list_item), label_widget);
  gtk_widget_show (label_widget);

  return list_item;
}

void
gtk_list_item_select (GtkListItem *list_item)
{
  gtk_item_select (GTK_ITEM (list_item));
}

void
gtk_list_item_deselect (GtkListItem *list_item)
{
  gtk_item_deselect (GTK_ITEM (list_item));
}


static void
gtk_list_item_realize (GtkWidget *widget)
{
427 428 429
  GdkWindowAttr attributes;
  gint attributes_mask;

430
  /*GTK_WIDGET_CLASS (parent_class)->realize (widget);*/
431

Elliot Lee's avatar
Elliot Lee committed
432 433
  g_return_if_fail (GTK_IS_LIST_ITEM (widget));

434 435 436 437 438 439 440 441 442 443 444 445 446 447
  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = (gtk_widget_get_events (widget) |
			   GDK_EXPOSURE_MASK |
			   GDK_BUTTON_PRESS_MASK |
			   GDK_BUTTON_RELEASE_MASK |
448 449
			   GDK_BUTTON1_MOTION_MASK |
			   GDK_POINTER_MOTION_HINT_MASK |
450 451 452 453 454 455 456 457 458 459
			   GDK_KEY_PRESS_MASK |
			   GDK_KEY_RELEASE_MASK |
			   GDK_ENTER_NOTIFY_MASK |
			   GDK_LEAVE_NOTIFY_MASK);

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, widget);

  widget->style = gtk_style_attach (widget->style, widget->window);
460 461
  gdk_window_set_background (widget->window, 
			     &widget->style->base[GTK_STATE_NORMAL]);
Elliot Lee's avatar
Elliot Lee committed
462 463 464 465 466 467 468
}

static void
gtk_list_item_size_request (GtkWidget      *widget,
			    GtkRequisition *requisition)
{
  GtkBin *bin;
469
  GtkRequisition child_requisition;
470 471
  gint focus_width;
  gint focus_pad;
Elliot Lee's avatar
Elliot Lee committed
472 473 474 475 476

  g_return_if_fail (GTK_IS_LIST_ITEM (widget));
  g_return_if_fail (requisition != NULL);

  bin = GTK_BIN (widget);
477 478 479 480
  gtk_widget_style_get (widget,
			"focus-line-width", &focus_width,
			"focus-padding", &focus_pad,
			NULL);
Elliot Lee's avatar
Elliot Lee committed
481

482 483 484 485
  requisition->width = 2 * (GTK_CONTAINER (widget)->border_width +
			    widget->style->xthickness + focus_width + focus_pad - 1);
  requisition->height = 2 * (GTK_CONTAINER (widget)->border_width +
			     focus_width + focus_pad - 1);
Elliot Lee's avatar
Elliot Lee committed
486 487 488

  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
    {
489
      gtk_widget_size_request (bin->child, &child_requisition);
Elliot Lee's avatar
Elliot Lee committed
490

491 492
      requisition->width += child_requisition.width;
      requisition->height += child_requisition.height;
Elliot Lee's avatar
Elliot Lee committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    }
}

static void
gtk_list_item_size_allocate (GtkWidget     *widget,
			     GtkAllocation *allocation)
{
  GtkBin *bin;
  GtkAllocation child_allocation;

  g_return_if_fail (GTK_IS_LIST_ITEM (widget));
  g_return_if_fail (allocation != NULL);

  widget->allocation = *allocation;
  if (GTK_WIDGET_REALIZED (widget))
    gdk_window_move_resize (widget->window,
			    allocation->x, allocation->y,
			    allocation->width, allocation->height);

  bin = GTK_BIN (widget);

  if (bin->child)
    {
      child_allocation.x = (GTK_CONTAINER (widget)->border_width +
517
			    widget->style->xthickness);
Elliot Lee's avatar
Elliot Lee committed
518 519 520 521 522 523 524 525
      child_allocation.y = GTK_CONTAINER (widget)->border_width;
      child_allocation.width = allocation->width - child_allocation.x * 2;
      child_allocation.height = allocation->height - child_allocation.y * 2;

      gtk_widget_size_allocate (bin->child, &child_allocation);
    }
}

526 527 528 529 530 531 532 533 534 535
static void 
gtk_list_item_style_set	(GtkWidget      *widget,
			 GtkStyle       *previous_style)
{
  g_return_if_fail (widget != NULL);

  if (previous_style && GTK_WIDGET_REALIZED (widget))
    gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
}

Elliot Lee's avatar
Elliot Lee committed
536 537 538 539
static gint
gtk_list_item_button_press (GtkWidget      *widget,
			    GdkEventButton *event)
{
540 541
  if (event->type == GDK_BUTTON_PRESS && !GTK_WIDGET_HAS_FOCUS (widget))
    gtk_widget_grab_focus (widget);
Elliot Lee's avatar
Elliot Lee committed
542 543 544 545 546 547 548 549 550 551 552 553

  return FALSE;
}

static gint
gtk_list_item_expose (GtkWidget      *widget,
		      GdkEventExpose *event)
{
  g_return_val_if_fail (widget != NULL, FALSE);

  if (GTK_WIDGET_DRAWABLE (widget))
    {
Havoc Pennington's avatar
Havoc Pennington committed
554 555 556 557 558 559
      if (widget->state == GTK_STATE_NORMAL)
        {
          gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
          gdk_window_clear_area (widget->window, event->area.x, event->area.y,
                                 event->area.width, event->area.height);
        }
Elliot Lee's avatar
Elliot Lee committed
560
      else
Havoc Pennington's avatar
Havoc Pennington committed
561 562 563 564 565 566
        {
          gtk_paint_flat_box (widget->style, widget->window, 
                              widget->state, GTK_SHADOW_ETCHED_OUT,
                              &event->area, widget, "listitem",
                              0, 0, -1, -1);           
        }
Elliot Lee's avatar
Elliot Lee committed
567

568 569
      GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);

Havoc Pennington's avatar
Havoc Pennington committed
570 571 572
      if (GTK_WIDGET_HAS_FOCUS (widget))
        {
          if (GTK_IS_LIST (widget->parent) && GTK_LIST (widget->parent)->add_mode)
573
            gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
Havoc Pennington's avatar
Havoc Pennington committed
574
                             NULL, widget, "add-mode",
575
                             0, 0, widget->allocation.width, widget->allocation.height);
Havoc Pennington's avatar
Havoc Pennington committed
576
          else
577
            gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
Havoc Pennington's avatar
Havoc Pennington committed
578
                             NULL, widget, NULL,
579
                             0, 0, widget->allocation.width, widget->allocation.height);
Havoc Pennington's avatar
Havoc Pennington committed
580
        }
Elliot Lee's avatar
Elliot Lee committed
581 582 583 584 585 586 587 588 589 590
    }

  return FALSE;
}

static void
gtk_real_list_item_select (GtkItem *item)
{
  g_return_if_fail (GTK_IS_LIST_ITEM (item));

591 592 593 594 595 596 597 598 599
  switch (GTK_WIDGET (item)->state)
    {
    case GTK_STATE_SELECTED:
    case GTK_STATE_INSENSITIVE:
      break;
    default:
      gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
      break;
    }
Elliot Lee's avatar
Elliot Lee committed
600 601 602 603 604 605 606
}

static void
gtk_real_list_item_deselect (GtkItem *item)
{
  g_return_if_fail (GTK_IS_LIST_ITEM (item));

607 608
  if (GTK_WIDGET (item)->state == GTK_STATE_SELECTED)
    gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
Elliot Lee's avatar
Elliot Lee committed
609 610 611 612 613 614 615
}

static void
gtk_real_list_item_toggle (GtkItem *item)
{
  g_return_if_fail (GTK_IS_LIST_ITEM (item));
  
616
  switch (GTK_WIDGET (item)->state)
Elliot Lee's avatar
Elliot Lee committed
617
    {
618 619 620 621 622 623 624 625
    case GTK_STATE_SELECTED:
      gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_NORMAL);
      break;
    case GTK_STATE_INSENSITIVE:
      break;
    default:
      gtk_widget_set_state (GTK_WIDGET (item), GTK_STATE_SELECTED);
      break;
Elliot Lee's avatar
Elliot Lee committed
626 627
    }
}
628 629

#include "gtkaliasdef.c"