GTK+ IOStream  Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Labels.H
Go to the documentation of this file.
1 /* Copyright 2000-2013 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream 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
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #ifndef LABELS_H_
18 #define LABELS_H_
19 
20 #include <iomanip>
21 #include <gtk/gtk.h>
22 #include <mffm/LinkList.H>
23 
24 #include "Buttons.H"
25 #include "Pango.H"
26 
27 #include <string>
28 
58 class Labels : public LinkList<GtkWidget *> {
59 public:
60 
65  Labels& operator <<(std::string str) {
66  return operator<<(str.c_str());
67  }
68 
73  Labels& operator <<(const char *str) {
74  LinkList<GtkWidget *>::add(gtk_label_new(str));
75  setAlignment(0.0, 0.0);
76  gtk_widget_show (current());
77  //cout<<"Labels : "<<current()<<endl;
78  return *this;
79  }
80 
87  GtkWidget * eventBox=gtk_event_box_new(); // construct the event box
88  LinkList<GtkWidget *>::add(eventBox); // add the eventbox to the list of widgets
89  //gtk_event_box_set_above_child(GTK_EVENT_BOX(eventBox), FALSE);
90  GtkWidget *label=gtk_label_new(nf.str); // construct the label
91  gtk_container_add((GtkContainer *)eventBox,label); // add the label to the eventbox
92  if (nf.func)
93  g_signal_connect(GTK_OBJECT(eventBox), "button_press_event", G_CALLBACK(nf.func), nf.data);
94  //gtk_signal_connect(GTK_OBJECT(current()), "button_press_event",GTK_SIGNAL_FUNC(nf.func), nf.data);
95  gtk_widget_show(current());
96  gtk_widget_show (label);
97  return *this;
98  }
99 
103  GtkWidget* getWidget(void) {
104 // cout<<"Labels : getWidget "<<current()<<endl;
106  }
107 
122  void pangoMarkup(const char *str) {
123  if (getCount()){
124  string pangoString; pangoString=pangoString+"<span "+str+">%s</span>"; // parse the current text into the markup
125  char *markup = g_markup_printf_escaped (pangoString.c_str(), gtk_label_get_text(GTK_LABEL(current()))); // generate the required markup
126  gtk_label_set_markup(GTK_LABEL(current()), markup);
127  g_free(markup);
128  }
129  }
130 
135  void pangoMarkup(Pango &p) {
136  p.setLabelText(current());
137  }
138 
144  GtkWidget * setAlignment(float xalign, float yalign){
145  if (getCount()){
146  gtk_misc_set_alignment (GTK_MISC(current()), xalign, yalign);
147  return current();
148  }
149  return NULL; // if there are no labels then return NULL
150  }
151 
157  LinkList<GtkWidget *>::add(gtk_label_new(NULL));
158  pangoMarkup(p); // set the markup
159  gtk_widget_show (current());
160  return *this;
161  }
162 
169  void setLabelsFont(PangoFontDescription *pangoFontDescription){
170  if (pangoFontDescription)
171  gtk_widget_modify_font(current(),pangoFontDescription);
172  }
173 
178  void setAngle(double angle){
179  if (getCount())
180  gtk_label_set_angle(GTK_LABEL(current()), angle);
181  }
182 
183 #ifdef DEBUG
184  ~Labels(void) {
185  cout<<"Labels::~Labels"<<endl;
186  }
187 #endif
188 };
189 #endif //LABELS_H_