1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Statusbar; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Box; 32 private import gtk.Widget; 33 private import gtkc.gtk; 34 public import gtkc.gtktypes; 35 private import std.algorithm; 36 37 38 /** 39 * A #GtkStatusbar is usually placed along the bottom of an application's 40 * main #GtkWindow. It may provide a regular commentary of the application's 41 * status (as is usually the case in a web browser, for example), or may be 42 * used to simply output a message when the status changes, (when an upload 43 * is complete in an FTP client, for example). 44 * 45 * Status bars in GTK+ maintain a stack of messages. The message at 46 * the top of the each bar’s stack is the one that will currently be displayed. 47 * 48 * Any messages added to a statusbar’s stack must specify a 49 * context id that is used to uniquely identify 50 * the source of a message. This context id can be generated by 51 * gtk_statusbar_get_context_id(), given a message and the statusbar that 52 * it will be added to. Note that messages are stored in a stack, and when 53 * choosing which message to display, the stack structure is adhered to, 54 * regardless of the context identifier of a message. 55 * 56 * One could say that a statusbar maintains one stack of messages for 57 * display purposes, but allows multiple message producers to maintain 58 * sub-stacks of the messages they produced (via context ids). 59 * 60 * Status bars are created using gtk_statusbar_new(). 61 * 62 * Messages are added to the bar’s stack with gtk_statusbar_push(). 63 * 64 * The message at the top of the stack can be removed using 65 * gtk_statusbar_pop(). A message can be removed from anywhere in the 66 * stack if its message id was recorded at the time it was added. This 67 * is done using gtk_statusbar_remove(). 68 * 69 * # CSS node 70 * 71 * GtkStatusbar has a single CSS node with name statusbar. 72 */ 73 public class Statusbar : Box 74 { 75 /** the main Gtk struct */ 76 protected GtkStatusbar* gtkStatusbar; 77 78 /** Get the main Gtk struct */ 79 public GtkStatusbar* getStatusbarStruct() 80 { 81 return gtkStatusbar; 82 } 83 84 /** the main Gtk struct as a void* */ 85 protected override void* getStruct() 86 { 87 return cast(void*)gtkStatusbar; 88 } 89 90 protected override void setStruct(GObject* obj) 91 { 92 gtkStatusbar = cast(GtkStatusbar*)obj; 93 super.setStruct(obj); 94 } 95 96 /** 97 * Sets our main struct and passes it to the parent class. 98 */ 99 public this (GtkStatusbar* gtkStatusbar, bool ownedRef = false) 100 { 101 this.gtkStatusbar = gtkStatusbar; 102 super(cast(GtkBox*)gtkStatusbar, ownedRef); 103 } 104 105 /** 106 * Retrieves the box containing the label widget. 107 * Since 2.20 108 * Returns: a GtkBox. [transfer none] 109 */ 110 public Box getMessageArea() 111 { 112 auto p = gtk_statusbar_get_message_area(gtkStatusbar); 113 if(p is null) 114 { 115 return null; 116 } 117 return new Box(cast(GtkBox*) p); 118 } 119 120 /** 121 */ 122 123 /** */ 124 public static GType getType() 125 { 126 return gtk_statusbar_get_type(); 127 } 128 129 /** 130 * Creates a new #GtkStatusbar ready for messages. 131 * 132 * Returns: the new #GtkStatusbar 133 * 134 * Throws: ConstructionException GTK+ fails to create the object. 135 */ 136 public this() 137 { 138 auto p = gtk_statusbar_new(); 139 140 if(p is null) 141 { 142 throw new ConstructionException("null returned by new"); 143 } 144 145 this(cast(GtkStatusbar*) p); 146 } 147 148 /** 149 * Returns a new context identifier, given a description 150 * of the actual context. Note that the description is 151 * not shown in the UI. 152 * 153 * Params: 154 * contextDescription = textual description of what context 155 * the new message is being used in 156 * 157 * Returns: an integer id 158 */ 159 public uint getContextId(string contextDescription) 160 { 161 return gtk_statusbar_get_context_id(gtkStatusbar, Str.toStringz(contextDescription)); 162 } 163 164 /** 165 * Removes the first message in the #GtkStatusbar’s stack 166 * with the given context id. 167 * 168 * Note that this may not change the displayed message, if 169 * the message at the top of the stack has a different 170 * context id. 171 * 172 * Params: 173 * contextId = a context identifier 174 */ 175 public void pop(uint contextId) 176 { 177 gtk_statusbar_pop(gtkStatusbar, contextId); 178 } 179 180 /** 181 * Pushes a new message onto a statusbar’s stack. 182 * 183 * Params: 184 * contextId = the message’s context id, as returned by 185 * gtk_statusbar_get_context_id() 186 * text = the message to add to the statusbar 187 * 188 * Returns: a message id that can be used with 189 * gtk_statusbar_remove(). 190 */ 191 public uint push(uint contextId, string text) 192 { 193 return gtk_statusbar_push(gtkStatusbar, contextId, Str.toStringz(text)); 194 } 195 196 /** 197 * Forces the removal of a message from a statusbar’s stack. 198 * The exact @context_id and @message_id must be specified. 199 * 200 * Params: 201 * contextId = a context identifier 202 * messageId = a message identifier, as returned by gtk_statusbar_push() 203 */ 204 public void remove(uint contextId, uint messageId) 205 { 206 gtk_statusbar_remove(gtkStatusbar, contextId, messageId); 207 } 208 209 /** 210 * Forces the removal of all messages from a statusbar's 211 * stack with the exact @context_id. 212 * 213 * Params: 214 * contextId = a context identifier 215 * 216 * Since: 2.22 217 */ 218 public void removeAll(uint contextId) 219 { 220 gtk_statusbar_remove_all(gtkStatusbar, contextId); 221 } 222 223 protected class OnTextPoppedDelegateWrapper 224 { 225 static OnTextPoppedDelegateWrapper[] listeners; 226 void delegate(uint, string, Statusbar) dlg; 227 gulong handlerId; 228 229 this(void delegate(uint, string, Statusbar) dlg) 230 { 231 this.dlg = dlg; 232 this.listeners ~= this; 233 } 234 235 void remove(OnTextPoppedDelegateWrapper source) 236 { 237 foreach(index, wrapper; listeners) 238 { 239 if (wrapper.handlerId == source.handlerId) 240 { 241 listeners[index] = null; 242 listeners = std.algorithm.remove(listeners, index); 243 break; 244 } 245 } 246 } 247 } 248 249 /** 250 * Is emitted whenever a new message is popped off a statusbar's stack. 251 * 252 * Params: 253 * contextId = the context id of the relevant message/statusbar 254 * text = the message that was just popped 255 */ 256 gulong addOnTextPopped(void delegate(uint, string, Statusbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 257 { 258 auto wrapper = new OnTextPoppedDelegateWrapper(dlg); 259 wrapper.handlerId = Signals.connectData( 260 this, 261 "text-popped", 262 cast(GCallback)&callBackTextPopped, 263 cast(void*)wrapper, 264 cast(GClosureNotify)&callBackTextPoppedDestroy, 265 connectFlags); 266 return wrapper.handlerId; 267 } 268 269 extern(C) static void callBackTextPopped(GtkStatusbar* statusbarStruct, uint contextId, char* text, OnTextPoppedDelegateWrapper wrapper) 270 { 271 wrapper.dlg(contextId, Str.toString(text), wrapper.outer); 272 } 273 274 extern(C) static void callBackTextPoppedDestroy(OnTextPoppedDelegateWrapper wrapper, GClosure* closure) 275 { 276 wrapper.remove(wrapper); 277 } 278 279 protected class OnTextPushedDelegateWrapper 280 { 281 static OnTextPushedDelegateWrapper[] listeners; 282 void delegate(uint, string, Statusbar) dlg; 283 gulong handlerId; 284 285 this(void delegate(uint, string, Statusbar) dlg) 286 { 287 this.dlg = dlg; 288 this.listeners ~= this; 289 } 290 291 void remove(OnTextPushedDelegateWrapper source) 292 { 293 foreach(index, wrapper; listeners) 294 { 295 if (wrapper.handlerId == source.handlerId) 296 { 297 listeners[index] = null; 298 listeners = std.algorithm.remove(listeners, index); 299 break; 300 } 301 } 302 } 303 } 304 305 /** 306 * Is emitted whenever a new message gets pushed onto a statusbar's stack. 307 * 308 * Params: 309 * contextId = the context id of the relevant message/statusbar 310 * text = the message that was pushed 311 */ 312 gulong addOnTextPushed(void delegate(uint, string, Statusbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 313 { 314 auto wrapper = new OnTextPushedDelegateWrapper(dlg); 315 wrapper.handlerId = Signals.connectData( 316 this, 317 "text-pushed", 318 cast(GCallback)&callBackTextPushed, 319 cast(void*)wrapper, 320 cast(GClosureNotify)&callBackTextPushedDestroy, 321 connectFlags); 322 return wrapper.handlerId; 323 } 324 325 extern(C) static void callBackTextPushed(GtkStatusbar* statusbarStruct, uint contextId, char* text, OnTextPushedDelegateWrapper wrapper) 326 { 327 wrapper.dlg(contextId, Str.toString(text), wrapper.outer); 328 } 329 330 extern(C) static void callBackTextPushedDestroy(OnTextPushedDelegateWrapper wrapper, GClosure* closure) 331 { 332 wrapper.remove(wrapper); 333 } 334 }