libyui-gtk  2.44.8
YGUtils.h
1 /********************************************************************
2  * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
3  ********************************************************************/
4 
5 #ifndef YGUTILS_H
6 #define YGUTILS_H
7 
8 #include <string>
9 #include <list>
10 #include <gtk/gtk.h>
11 
12 /* YGUtils.h/cc have some functionality that is shared between different parts
13  of the code. */
14 
15 namespace YGUtils
16 {
17  /* Replaces Yast's '&' accelerator by Gnome's '_' (and proper escaping). */
18  std::string mapKBAccel (const std::string &src);
19 
20  /* Adds filter support to a GtkEntry. */
21  void setFilter (GtkEntry *entry, const std::string &validChars);
22 
23  /* Replaces every 'mouth' by 'food' in 'str'. */
24  void replace (std::string &str, const char *mouth, int mouth_len, const char *food);
25 
26  /* Truncates the text with "..." past the given length.
27  pos: -1 = start, 0 = middle, 1 = end. Honors utf-8 characters. */
28  std::string truncate (const std::string &str, int length, int pos);
29 
30  /* Escapes markup text (eg. changes '<' by '<'). */
31  std::string escapeMarkup (const std::string &str);
32 
33  /* Check if 'str' ends with 'suffix'. */
34  bool endsWith (const std::string &str, const std::string &suffix);
35 
36  /* Adds functionality to scroll widgets to top or bottom. */
37  void scrollWidget (GtkAdjustment *vadj, bool top);
38 
39  /* Returns the average width of the given number of characters in pixels. */
40  int getCharsWidth (GtkWidget *widget, int chars_nb);
41  int getCharsHeight (GtkWidget *widget, int chars_nb);
42 
43  /* Sets some widget font proprities. */
44  void setWidgetFont (GtkWidget *widget, PangoStyle style, PangoWeight weight, double scale);
45 
46  /* Instead of setting GtkPaned::position in pixels, do so in percents. */
47  void setPaneRelPosition (GtkWidget *paned, gdouble rel);
48 
49  /* Saves some code and standardizes the error. Returns NULL if failed.
50  Don't forget to g_object_unref it! */
51  GdkPixbuf *loadPixbuf (const std::string &fileneme);
52 
53  /* Shifts colors in a GdkPixbuf. */
54  GdkPixbuf *setOpacity (const GdkPixbuf *src, int opacity, bool touchAlpha);
55 
56  /* Gray out some pixbuf. */
57  GdkPixbuf *setGray (const GdkPixbuf *src);
58 
59  /* Tries to make sense out of the string, applying some stock icon to the button. */
60  const char *setStockIcon (GtkWidget *button, const std::string &label,
61  const char *fallbackIcon);
62  const char *mapIconname(const std::string &label);
63 
64 
65  /* For empty model rows, render a separator (can be used for GtkTreeView and GtkComboBox */
66  gboolean empty_row_is_separator_cb (
67  GtkTreeModel *model, GtkTreeIter *iter, gpointer text_col);
68 
69  /* Shrink widget inner-border (thickness) */
70  void shrinkWidget (GtkWidget *widget);
71 };
72 
73 extern "C" {
74  char *ygutils_mapKBAccel (const char *src);
75 
76  void ygutils_setWidgetFont (GtkWidget *widget, PangoStyle style, PangoWeight weight, double scale);
77  void ygutils_setPaneRelPosition (GtkWidget *paned, gdouble rel);
78 
79  void ygutils_setFilter (GtkEntry *entry, const char *validChars);
80 
81  void ygutils_scrollAdj (GtkAdjustment *vadj, gboolean top);
82 
83  const char *ygutils_mapIconname (const std::string &label);
84  const char *ygutils_setStockIcon (GtkWidget *button, const char *label,
85  const char *fallbackIcon);
86 
87  GdkPixbuf *ygutils_setOpacity (const GdkPixbuf *src, int opacity, gboolean useAlpha);
88 
89  gchar *ygutils_headerize_help (const char *help_text, gboolean *cut);
90 
91  // convert liberal html to xhtml
92  gchar *ygutils_convert_to_xhtml (const char *instr);
93 };
94 
95 #endif // YGUTILS_H
96