OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
iconview.c
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include <stdlib.h>
17 #include "mape/iconview.h"
18 
20 {
21  MapeIconView* view;
22  view = malloc(sizeof(MapeIconView) );
23 
24  view->list_store = GTK_TREE_MODEL(
25  gtk_list_store_new(
27  GDK_TYPE_PIXBUF,
28  G_TYPE_STRING
29  )
30  );
31 
32  view->view = gtk_icon_view_new_with_model(view->list_store);
33  g_object_unref(view->list_store);
34 
35  gtk_icon_view_set_item_orientation(
36  GTK_ICON_VIEW(view->view),
37  GTK_ORIENTATION_HORIZONTAL
38  );
39 
40  view->renderer_icon = gtk_cell_renderer_pixbuf_new();
41  gtk_cell_layout_pack_start(
42  GTK_CELL_LAYOUT(view->view),
43  view->renderer_icon,
44  FALSE
45  );
46 
47  gtk_cell_layout_set_attributes(
48  GTK_CELL_LAYOUT(view->view),
49  view->renderer_icon,
51  NULL
52  );
53 
54  view->renderer_name = gtk_cell_renderer_text_new();
55  gtk_cell_layout_pack_start(
56  GTK_CELL_LAYOUT(view->view),
57  view->renderer_name,
58  TRUE
59  );
60 
61  gtk_cell_layout_set_attributes(
62  GTK_CELL_LAYOUT(view->view),
63  view->renderer_name,
65  NULL
66  );
67 
68  gtk_icon_view_set_selection_mode(
69  GTK_ICON_VIEW(view->view),
70  GTK_SELECTION_NONE
71  );
72 
73  gtk_tree_sortable_set_sort_column_id(
74  GTK_TREE_SORTABLE(view->list_store),
76  GTK_SORT_ASCENDING
77  );
78 
79  gtk_widget_show(view->view);
80 
81  view->window = gtk_scrolled_window_new(NULL, NULL);
82  gtk_container_add(
83  GTK_CONTAINER(view->window),
84  view->view
85  );
86 
87  gtk_scrolled_window_set_policy(
88  GTK_SCROLLED_WINDOW(view->window),
89  GTK_POLICY_AUTOMATIC,
90  GTK_POLICY_AUTOMATIC
91  );
92 
93  gtk_scrolled_window_set_shadow_type(
94  GTK_SCROLLED_WINDOW(view->window),
95  GTK_SHADOW_IN
96  );
97 
98  gtk_widget_show(view->window);
99  return view;
100 }
101 
103 {
104  /* TODO: unref cell renderers? */
105  free(view);
106 }
107 
109 {
110  gtk_list_store_clear(GTK_LIST_STORE(view->list_store) );
111 }
112 
114  GdkPixbuf* icon,
115  const char* name)
116 {
117  GtkTreeIter iter;
118 
119  gtk_list_store_append(
120  GTK_LIST_STORE(view->list_store),
121  &iter
122  );
123 
124  gtk_list_store_set(
125  GTK_LIST_STORE(view->list_store),
126  &iter,
128  icon,
130  name,
131  -1
132  );
133 }
134 
void mape_icon_view_clear(MapeIconView *view)
Definition: iconview.c:108
void mape_icon_view_destroy(MapeIconView *view)
Definition: iconview.c:102
GtkWidget * window
Definition: iconview.h:30
GtkCellRenderer * renderer_icon
Definition: iconview.h:35
GtkCellRenderer * renderer_name
Definition: iconview.h:36
MapeIconView * mape_icon_view_new(GError **error)
Definition: iconview.c:19
GtkTreeModel * list_store
Definition: iconview.h:33
GtkWidget * view
Definition: iconview.h:31
void mape_icon_view_add(MapeIconView *view, GdkPixbuf *icon, const char *name)
Definition: iconview.c:113