libyui-gtk  2.44.9
YGLabel.cc
1 /********************************************************************
2  * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
3  ********************************************************************/
4 
5 #define YUILogComponent "gtk"
6 #include "YGUI.h"
7 #include "YGUtils.h"
8 #include "YGWidget.h"
9 #include "YLabel.h"
10 
11 class YGLabel : public YLabel, public YGWidget
12 {
13 public:
14  YGLabel (YWidget *parent, const std::string &text, bool heading, bool outputField)
15  : YLabel (NULL, text, heading, outputField),
16  YGWidget (this, parent, GTK_TYPE_LABEL, NULL)
17  {
18  // gtk_misc_set_alignment (GTK_MISC (getWidget()), 0.0, 0.5);
19  gtk_widget_set_halign (getWidget(), GTK_ALIGN_START);
20  gtk_widget_set_valign (getWidget(), GTK_ALIGN_CENTER);
21 
22  if (outputField) {
23  gtk_label_set_selectable (GTK_LABEL (getWidget()), TRUE);
24  gtk_label_set_single_line_mode (GTK_LABEL (getWidget()), TRUE);
25  YGUtils::setWidgetFont (getWidget(), PANGO_STYLE_ITALIC, PANGO_WEIGHT_NORMAL,
26  PANGO_SCALE_MEDIUM);
27  }
28  if (heading)
29  YGUtils::setWidgetFont (getWidget(), PANGO_STYLE_NORMAL, PANGO_WEIGHT_BOLD,
30  PANGO_SCALE_LARGE);
31  setLabel (text);
32  }
33 
34  virtual void setText (const std::string &label)
35  {
36  YLabel::setText (label);
37  gtk_label_set_label (GTK_LABEL (getWidget()), label.c_str());
38  std::string::size_type i = label.find ('\n', 0);
39  if (isOutputField()) { // must not have a breakline
40  if (i != std::string::npos) {
41  std::string l (label, 0, i);
42  gtk_label_set_label (GTK_LABEL (getWidget()), l.c_str());
43  }
44  }
45  else {
46  bool selectable = i != std::string::npos && i != label.size()-1;
47  gtk_label_set_selectable (GTK_LABEL (getWidget()), selectable);
48  }
49  }
50 
51  YGWIDGET_IMPL_COMMON (YLabel)
52  YGWIDGET_IMPL_USE_BOLD (YLabel)
53 };
54 
55 YLabel *YGWidgetFactory::createLabel (YWidget *parent,
56  const std::string &text, bool heading, bool outputField)
57 { return new YGLabel (parent, text, heading, outputField); }
58 
YGLabel
Definition: YGLabel.cc:11
YGWidget
Definition: YGWidget.h:13