gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
Labels.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 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(G_OBJECT(eventBox), "button_press_event", G_CALLBACK(nf.func), nf.data);
94  gtk_widget_show(current());
95  gtk_widget_show (label);
96  return *this;
97  }
98 
102  GtkWidget* getWidget(void) {
103 // cout<<"Labels : getWidget "<<current()<<endl;
105  }
106 
121  void pangoMarkup(const char *str) {
122  if (getCount()){
123  string pangoString; pangoString=pangoString+"<span "+str+">%s</span>"; // parse the current text into the markup
124  char *markup = g_markup_printf_escaped (pangoString.c_str(), gtk_label_get_text(GTK_LABEL(current()))); // generate the required markup
125  gtk_label_set_markup(GTK_LABEL(current()), markup);
126  g_free(markup);
127  }
128  }
129 
134  void pangoMarkup(Pango &p) {
135  p.setLabelText(current());
136  }
137 
143  GtkWidget * setAlignment(float xalign, float yalign){
144  if (getCount()){
145  gtk_misc_set_alignment (GTK_MISC(current()), xalign, yalign);
146  return current();
147  }
148  return NULL; // if there are no labels then return NULL
149  }
150 
156  LinkList<GtkWidget *>::add(gtk_label_new(NULL));
157  pangoMarkup(p); // set the markup
158  gtk_widget_show (current());
159  return *this;
160  }
161 
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 
186  void setText(const char*text){
187  if (getCount())
188  gtk_label_set_text(GTK_LABEL(current()), text);
189  }
190 
194  const char* getText(void){
195  if (getCount())
196  return gtk_label_get_text(GTK_LABEL(current()));
197  }
198 
202  Labels &operator=(string text){
203  setText(text.c_str());
204  return *this;
205  }
206 
210  Labels &operator=(const char*text){
211  setText(text);
212  return *this;
213  }
214 
215 #ifdef DEBUG
216  ~Labels(void) {
217  cout<<"Labels::~Labels"<<endl;
218  }
219 #endif
220 };
221 #endif //LABELS_H_
void setLabelsFont(PangoFontDescription *pangoFontDescription)
Definition: Labels.H:169
Labels & operator=(const char *text)
Definition: Labels.H:210
class to create and handle labels.
Definition: Labels.H:58
GtkWidget * getWidget(void)
returns the current GtkWidget* in the list
Definition: Labels.H:102
void pangoMarkup(Pango &p)
Set the pango markup of the currently displayed text. The Pango class is used to setup the label...
Definition: Labels.H:134
void setLabelText(GtkWidget *l)
Definition: Pango.H:185
float p
GtkWidget * setAlignment(float xalign, float yalign)
Definition: Labels.H:143
void setAngle(double angle)
Definition: Labels.H:178
void setText(const char *text)
Definition: Labels.H:186
gpointer data
The data to pass to func when the button it pressed.
Definition: Buttons.H:59
Definition: Pango.H:102
const char * str
The label to show in the button.
Definition: Buttons.H:57
class to pass using operator<< for creating a label button
Definition: Buttons.H:66
void pangoMarkup(const char *str)
Set the pango markup of the currently displayed text. Allows you to set the current text to different...
Definition: Labels.H:121
void(* func)()
The function to call when the button is pressed.
Definition: Buttons.H:58
const char * getText(void)
Definition: Labels.H:194
Labels & operator=(string text)
Definition: Labels.H:202
Labels & operator<<(std::string str)
Definition: Labels.H:65
gtkIOStream: /tmp/gtkiostream/include/Labels.H Source File
GTK+ IOStream  Beta