Commit ca045eab31cbda4fce190c8207ed7cefee58b86a
1 parent
5b38bdd9
Exists in
master
and in
4 other branches
Implementing toolbar widget.
Showing
2 changed files
with
175 additions
and
0 deletions
Show diff stats
src/widgets/toolbar/core.c
@@ -29,10 +29,18 @@ | @@ -29,10 +29,18 @@ | ||
29 | 29 | ||
30 | #include <config.h> | 30 | #include <config.h> |
31 | #include <pw3270/toolbar.h> | 31 | #include <pw3270/toolbar.h> |
32 | + #include <lib3270/log.h> | ||
33 | + | ||
34 | + static gboolean popup_context_menu(GtkToolbar *toolbar, gint x, gint y, gint button_number); | ||
35 | + static void finalize(GObject *object); | ||
36 | + | ||
32 | 37 | ||
33 | struct _pw3270ToolBar { | 38 | struct _pw3270ToolBar { |
34 | GtkToolbar parent; | 39 | GtkToolbar parent; |
35 | 40 | ||
41 | + /// @brief Popup Menu | ||
42 | + GtkWidget * popup_menu; | ||
43 | + | ||
36 | }; | 44 | }; |
37 | 45 | ||
38 | struct _pw3270ToolBarClass { | 46 | struct _pw3270ToolBarClass { |
@@ -46,10 +54,156 @@ | @@ -46,10 +54,156 @@ | ||
46 | 54 | ||
47 | static void pw3270ToolBar_class_init(pw3270ToolBarClass *klass) { | 55 | static void pw3270ToolBar_class_init(pw3270ToolBarClass *klass) { |
48 | 56 | ||
57 | + GtkToolbarClass * toolbar = GTK_TOOLBAR_CLASS(klass); | ||
58 | + | ||
59 | + toolbar->popup_context_menu = popup_context_menu; | ||
60 | + | ||
61 | + G_OBJECT_CLASS(klass)->finalize = finalize; | ||
62 | + | ||
63 | + } | ||
64 | + | ||
65 | + static void detacher(GtkWidget *attach_widget, GtkMenu *menu) { | ||
66 | + | ||
67 | + pw3270ToolBar * toolbar = PW3270_TOOLBAR(attach_widget); | ||
68 | + toolbar->popup_menu = NULL; | ||
69 | + | ||
70 | + } | ||
71 | + | ||
72 | + static void set_icon_size(GtkMenuItem *menuitem, GtkWidget *toolbar) { | ||
73 | + | ||
74 | + GtkIconSize * icon_size = g_object_get_data(G_OBJECT(menuitem),"icon_size"); | ||
75 | + | ||
76 | + if(icon_size) | ||
77 | + gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar),*icon_size); | ||
78 | + else | ||
79 | + gtk_toolbar_unset_icon_size(GTK_TOOLBAR(toolbar)); | ||
80 | + | ||
81 | + } | ||
82 | + | ||
83 | + static void set_style(GtkMenuItem *menuitem, GtkWidget *toolbar) { | ||
84 | + | ||
85 | + GtkToolbarStyle * style = g_object_get_data(G_OBJECT(menuitem),"toolbar_style"); | ||
86 | + | ||
87 | + if(style) | ||
88 | + gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),*style); | ||
89 | + else | ||
90 | + gtk_toolbar_unset_style(GTK_TOOLBAR(toolbar)); | ||
91 | + | ||
49 | } | 92 | } |
50 | 93 | ||
51 | static void pw3270ToolBar_init(pw3270ToolBar *widget) { | 94 | static void pw3270ToolBar_init(pw3270ToolBar *widget) { |
52 | 95 | ||
96 | + widget->popup_menu = gtk_menu_new(); | ||
97 | + | ||
98 | + // Size options | ||
99 | + { | ||
100 | + static const struct { | ||
101 | + const gchar * label; | ||
102 | + GtkIconSize icon_size; | ||
103 | + } itens[] = { | ||
104 | + | ||
105 | + { | ||
106 | + .label = "Default" | ||
107 | + | ||
108 | + }, | ||
109 | + | ||
110 | + { | ||
111 | + .label = "Small", | ||
112 | + .icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR | ||
113 | + }, | ||
114 | + | ||
115 | + { | ||
116 | + .label = "Large", | ||
117 | + .icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR | ||
118 | + }, | ||
119 | + }; | ||
120 | + | ||
121 | + size_t ix; | ||
122 | + | ||
123 | + GtkWidget * item = gtk_menu_item_new_with_mnemonic("Icon _size"); | ||
124 | + gtk_menu_shell_append(GTK_MENU_SHELL(widget->popup_menu),item); | ||
125 | + | ||
126 | + GtkWidget * submenu = gtk_menu_new(); | ||
127 | + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu); | ||
128 | + | ||
129 | + for(ix = 0; ix < G_N_ELEMENTS(itens); ix++) { | ||
130 | + | ||
131 | + item = gtk_menu_item_new_with_mnemonic(itens[ix].label); | ||
132 | + | ||
133 | + if(ix > 0) | ||
134 | + g_object_set_data(G_OBJECT(item),"icon_size", (gpointer) &itens[ix].icon_size); | ||
135 | + | ||
136 | + g_signal_connect(item, "activate", G_CALLBACK(set_icon_size), widget); | ||
137 | + | ||
138 | + gtk_menu_shell_append(GTK_MENU_SHELL(submenu),item); | ||
139 | + | ||
140 | + } | ||
141 | + | ||
142 | + } | ||
143 | + | ||
144 | + // Style option | ||
145 | + { | ||
146 | + static const struct { | ||
147 | + const gchar * label; | ||
148 | + GtkToolbarStyle style; | ||
149 | + } itens[] = { | ||
150 | + | ||
151 | + { | ||
152 | + .label = "Default" | ||
153 | + }, | ||
154 | + | ||
155 | + { | ||
156 | + .label = "Icons only", | ||
157 | + .style = GTK_TOOLBAR_ICONS | ||
158 | + }, | ||
159 | + | ||
160 | + { | ||
161 | + .label = "Text only", | ||
162 | + .style = GTK_TOOLBAR_TEXT | ||
163 | + }, | ||
164 | + | ||
165 | + { | ||
166 | + .label = "Icons & text", | ||
167 | + .style = GTK_TOOLBAR_BOTH | ||
168 | + }, | ||
169 | + }; | ||
170 | + | ||
171 | + size_t ix; | ||
172 | + | ||
173 | + GtkWidget * item = gtk_menu_item_new_with_mnemonic("S_tyle"); | ||
174 | + gtk_menu_shell_append(GTK_MENU_SHELL(widget->popup_menu),item); | ||
175 | + | ||
176 | + GtkWidget * submenu = gtk_menu_new(); | ||
177 | + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),submenu); | ||
178 | + | ||
179 | + for(ix = 0; ix < G_N_ELEMENTS(itens); ix++) { | ||
180 | + | ||
181 | + item = gtk_menu_item_new_with_mnemonic(itens[ix].label); | ||
182 | + | ||
183 | + if(ix > 0) | ||
184 | + g_object_set_data(G_OBJECT(item),"toolbar_style", (gpointer) &itens[ix].style); | ||
185 | + | ||
186 | + g_signal_connect(item, "activate", G_CALLBACK(set_style), widget); | ||
187 | + | ||
188 | + gtk_menu_shell_append(GTK_MENU_SHELL(submenu),item); | ||
189 | + | ||
190 | + } | ||
191 | + | ||
192 | + } | ||
193 | + | ||
194 | + // gtk_container_set_border_width(GTK_CONTAINER(widget->popup_menu),6); | ||
195 | + gtk_widget_show_all(widget->popup_menu); | ||
196 | + gtk_menu_attach_to_widget(GTK_MENU(widget->popup_menu),GTK_WIDGET(widget),detacher); | ||
197 | + | ||
198 | + } | ||
199 | + | ||
200 | + static void finalize(GObject *object) { | ||
201 | + | ||
202 | +// pw3270ToolBar * toolbar = PW3270_TOOLBAR(object); | ||
203 | + | ||
204 | + | ||
205 | + G_OBJECT_CLASS(pw3270ToolBar_parent_class)->finalize(object); | ||
206 | + | ||
53 | } | 207 | } |
54 | 208 | ||
55 | GtkWidget * pw3270_toolbar_new(void) { | 209 | GtkWidget * pw3270_toolbar_new(void) { |
@@ -75,7 +229,12 @@ | @@ -75,7 +229,12 @@ | ||
75 | return NULL; | 229 | return NULL; |
76 | } | 230 | } |
77 | 231 | ||
232 | + debug("Action: %s icon: %s", action->name, action->icon); | ||
233 | + | ||
78 | GtkToolItem * item = gtk_tool_button_new(gtk_image_new_from_icon_name(action->icon,GTK_ICON_SIZE_LARGE_TOOLBAR),action->label); | 234 | GtkToolItem * item = gtk_tool_button_new(gtk_image_new_from_icon_name(action->icon,GTK_ICON_SIZE_LARGE_TOOLBAR),action->label); |
235 | + gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item),TRUE); | ||
236 | + | ||
237 | + gtk_widget_set_name(GTK_WIDGET(item), action->name); | ||
79 | 238 | ||
80 | if(action->summary) | 239 | if(action->summary) |
81 | gtk_tool_item_set_tooltip_text(item,action->summary); | 240 | gtk_tool_item_set_tooltip_text(item,action->summary); |
@@ -85,3 +244,17 @@ | @@ -85,3 +244,17 @@ | ||
85 | return GTK_WIDGET(item); | 244 | return GTK_WIDGET(item); |
86 | } | 245 | } |
87 | 246 | ||
247 | + gboolean popup_context_menu(GtkToolbar *widget, gint x, gint y, gint button_number) { | ||
248 | + | ||
249 | + pw3270ToolBar * toolbar = PW3270_TOOLBAR(widget); | ||
250 | + | ||
251 | + debug("%s button_number=%d",__FUNCTION__,button_number); | ||
252 | + | ||
253 | + if(toolbar->popup_menu) { | ||
254 | + gtk_menu_popup_at_pointer(GTK_MENU(toolbar->popup_menu),NULL); | ||
255 | + } | ||
256 | + | ||
257 | + | ||
258 | + return TRUE; | ||
259 | + | ||
260 | + } |
src/widgets/toolbar/toolbar.cbp
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | <Option compiler="gcc" /> | 13 | <Option compiler="gcc" /> |
14 | <Compiler> | 14 | <Compiler> |
15 | <Add option="-g" /> | 15 | <Add option="-g" /> |
16 | + <Add option="-DDEBUG=1" /> | ||
16 | </Compiler> | 17 | </Compiler> |
17 | </Target> | 18 | </Target> |
18 | <Target title="Release"> | 19 | <Target title="Release"> |
@@ -22,6 +23,7 @@ | @@ -22,6 +23,7 @@ | ||
22 | <Option compiler="gcc" /> | 23 | <Option compiler="gcc" /> |
23 | <Compiler> | 24 | <Compiler> |
24 | <Add option="-O2" /> | 25 | <Add option="-O2" /> |
26 | + <Add option="-DNDEBUG=1" /> | ||
25 | </Compiler> | 27 | </Compiler> |
26 | <Linker> | 28 | <Linker> |
27 | <Add option="-s" /> | 29 | <Add option="-s" /> |