rofi  1.5.4
textbox.h
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  */
27 
28 #ifndef ROFI_TEXTBOX_H
29 #define ROFI_TEXTBOX_H
30 
31 #include <xkbcommon/xkbcommon.h>
32 #include <pango/pango.h>
33 #include <pango/pango-fontmap.h>
34 #include <pango/pangocairo.h>
35 #include <cairo.h>
36 #include "widgets/widget.h"
38 #include "keyb.h"
39 
50 typedef struct
51 {
53  unsigned long flags;
54  short cursor;
55  char *text;
56  PangoLayout *layout;
57  int tbft;
58  int markup;
59  int changed;
60 
61  cairo_surface_t *icon; // AA TODO - pass in icons for a textbox line if needed
63 
64  int blink;
66 
67  double yalign;
68  double xalign;
69 
70  PangoFontMetrics *metrics;
71  PangoEllipsizeMode emode;
73  //
74  const char *theme_name;
75 } textbox;
76 
80 typedef enum
81 {
82  TB_AUTOHEIGHT = 1 << 0,
83  TB_AUTOWIDTH = 1 << 1,
84  TB_EDITABLE = 1 << 19,
85  TB_MARKUP = 1 << 20,
86  TB_WRAP = 1 << 21,
87  TB_PASSWORD = 1 << 22,
88  TB_INDICATOR = 1 << 23,
89  TB_ICON = 1 << 24,
90 } TextboxFlags;
94 typedef enum
95 {
97  NORMAL = 0,
99  URGENT = 1,
101  ACTIVE = 2,
103  SELECTED = 4,
105  MARKUP = 8,
106 
108  ALT = 16,
110  HIGHLIGHT = 32,
114  STATE_MASK = ~( SELECTED | MARKUP | ALT | HIGHLIGHT )
116 
132 textbox* textbox_create ( widget *parent, WidgetType type, const char *name, TextboxFlags flags,
133  TextBoxFontType tbft, const char *text, double xalign, double yalign );
140 void textbox_font ( textbox *tb, TextBoxFontType tbft );
141 
148 void textbox_text ( textbox *tb, const char *text );
149 
156 void textbox_icon ( textbox *tb, cairo_surface_t *icon );
157 
166 int textbox_keybinding ( textbox *tb, KeyBindingAction action );
175 gboolean textbox_append_text ( textbox *tb, const char *pad, const int pad_len );
176 
183 void textbox_cursor ( textbox *tb, int pos );
184 
193 void textbox_insert ( textbox *tb, const int char_pos, const char *str, const int slen );
194 
200 void textbox_setup ( void );
201 
205 void textbox_cleanup ( void );
206 
214 int textbox_get_height ( const textbox *tb );
215 
223 int textbox_get_font_height ( const textbox *tb );
224 
232 int textbox_get_font_width ( const textbox *tb );
233 
239 double textbox_get_estimated_char_width ( void );
240 
246 double textbox_get_estimated_ch ( void );
252 double textbox_get_estimated_char_height ( void );
253 
261 void textbox_delete ( textbox *tb, int pos, int dlen );
262 
273 void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
274 
284 int textbox_get_estimated_height ( const textbox *tb, int eh );
291 void textbox_set_pango_context ( const char *font, PangoContext *p );
298 void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
299 
306 void textbox_set_icon_index ( textbox *tb, int index );
307 
315 PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
316 
322 const char *textbox_get_visible_text ( const textbox *tb );
330 int textbox_get_desired_width ( widget *wid );
331 
337 void textbox_cursor_end ( textbox *tb );
338 
345 void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode );
347 #endif //ROFI_TEXTBOX_H
textbox_font
void textbox_font(textbox *tb, TextBoxFontType tbft)
Definition: textbox.c:231
textbox::flags
unsigned long flags
Definition: textbox.h:53
WidgetType
WidgetType
Definition: widget.h:57
ACTIVE
@ ACTIVE
Definition: textbox.h:101
textbox_get_desired_width
int textbox_get_desired_width(widget *wid)
Definition: textbox.c:935
textbox_icon
void textbox_icon(textbox *tb, cairo_surface_t *icon)
Definition: textbox.c:337
textbox_get_estimated_ch
double textbox_get_estimated_ch(void)
Definition: textbox.c:921
textbox::emode
PangoEllipsizeMode emode
Definition: textbox.h:71
MARKUP
@ MARKUP
Definition: textbox.h:105
KeyBindingAction
KeyBindingAction
Definition: keyb.h:59
textbox::widget
widget widget
Definition: textbox.h:52
textbox_text
void textbox_text(textbox *tb, const char *text)
Definition: textbox.c:305
textbox_cursor_end
void textbox_cursor_end(textbox *tb)
Definition: textbox.c:600
NORMAL
@ NORMAL
Definition: textbox.h:97
TB_PASSWORD
@ TB_PASSWORD
Definition: textbox.h:87
textbox_append_text
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len)
Definition: textbox.c:801
textbox_setup
void textbox_setup(void)
Definition: textbox.c:833
HIGHLIGHT
@ HIGHLIGHT
Definition: textbox.h:110
textbox::icon
cairo_surface_t * icon
Definition: textbox.h:61
TB_AUTOHEIGHT
@ TB_AUTOHEIGHT
Definition: textbox.h:82
TB_AUTOWIDTH
@ TB_AUTOWIDTH
Definition: textbox.h:83
_icon
Definition: icon.c:41
textbox::layout
PangoLayout * layout
Definition: textbox.h:56
textbox_get_font_height
int textbox_get_font_height(const textbox *tb)
Definition: textbox.c:883
textbox_get_estimated_char_width
double textbox_get_estimated_char_width(void)
Definition: textbox.c:910
SELECTED
@ SELECTED
Definition: textbox.h:103
textbox::xalign
double xalign
Definition: textbox.h:68
textbox_keybinding
int textbox_keybinding(textbox *tb, KeyBindingAction action)
Definition: textbox.c:737
flags
MenuFlags flags
Definition: view.c:108
textbox_get_height
int textbox_get_height(const textbox *tb)
Definition: textbox.c:878
TB_ICON
@ TB_ICON
Definition: textbox.h:89
textbox_get_visible_text
const char * textbox_get_visible_text(const textbox *tb)
Definition: textbox.c:282
textbox::cursor
short cursor
Definition: textbox.h:54
textbox::text
char * text
Definition: textbox.h:55
textbox::icon_index
int icon_index
Definition: textbox.h:62
widget.h
textbox_insert
void textbox_insert(textbox *tb, const int char_pos, const char *str, const int slen)
Definition: textbox.c:614
keyb.h
textbox_cursor
void textbox_cursor(textbox *tb, int pos)
Definition: textbox.c:497
textbox::blink_timeout
guint blink_timeout
Definition: textbox.h:65
STATE_MASK
@ STATE_MASK
Definition: textbox.h:114
URGENT
@ URGENT
Definition: textbox.h:99
textbox::theme_name
const char * theme_name
Definition: textbox.h:74
TB_MARKUP
@ TB_MARKUP
Definition: textbox.h:85
textbox::left_offset
int left_offset
Definition: textbox.h:72
FMOD_MASK
@ FMOD_MASK
Definition: textbox.h:112
TextboxFlags
TextboxFlags
Definition: textbox.h:81
textbox_cleanup
void textbox_cleanup(void)
Definition: textbox.c:851
textbox_set_ellipsize
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode)
Definition: textbox.c:958
textbox_get_pango_attributes
PangoAttrList * textbox_get_pango_attributes(textbox *tb)
Definition: textbox.c:289
textbox_get_font_width
int textbox_get_font_width(const textbox *tb)
Definition: textbox.c:890
textbox_set_icon_index
void textbox_set_icon_index(textbox *tb, int index)
TB_WRAP
@ TB_WRAP
Definition: textbox.h:86
textbox_delete
void textbox_delete(textbox *tb, int pos, int dlen)
Definition: textbox.c:638
TB_INDICATOR
@ TB_INDICATOR
Definition: textbox.h:88
textbox_get_estimated_height
int textbox_get_estimated_height(const textbox *tb, int eh)
Definition: textbox.c:930
widget-internal.h
TextBoxFontType
TextBoxFontType
Definition: textbox.h:95
textbox_set_pango_attributes
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list)
Definition: textbox.c:296
textbox::blink
int blink
Definition: textbox.h:64
ALT
@ ALT
Definition: textbox.h:108
textbox
Definition: textbox.h:51
textbox::tbft
int tbft
Definition: textbox.h:57
textbox_set_pango_context
void textbox_set_pango_context(const char *font, PangoContext *p)
Definition: textbox.c:840
textbox::changed
int changed
Definition: textbox.h:59
textbox_moveresize
void textbox_moveresize(textbox *tb, int x, int y, int w, int h)
Definition: textbox.c:353
textbox::metrics
PangoFontMetrics * metrics
Definition: textbox.h:70
textbox_get_estimated_char_height
double textbox_get_estimated_char_height(void)
Definition: textbox.c:899
textbox::yalign
double yalign
Definition: textbox.h:67
TB_EDITABLE
@ TB_EDITABLE
Definition: textbox.h:84
textbox::markup
int markup
Definition: textbox.h:58
_widget
Definition: widget-internal.h:36
textbox_create
textbox * textbox_create(widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign)
Definition: textbox.c:166