rofi  1.6.0
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  const char *placeholder;
58  PangoLayout *layout;
59  int tbft;
60  int markup;
61  int changed;
62 
63  int blink;
65 
66  double yalign;
67  double xalign;
68 
69  PangoFontMetrics *metrics;
70  PangoEllipsizeMode emode;
71  //
72  const char *theme_name;
73 } textbox;
74 
78 typedef enum
79 {
80  TB_AUTOHEIGHT = 1 << 0,
81  TB_AUTOWIDTH = 1 << 1,
82  TB_EDITABLE = 1 << 19,
83  TB_MARKUP = 1 << 20,
84  TB_WRAP = 1 << 21,
85  TB_PASSWORD = 1 << 22,
86  TB_INDICATOR = 1 << 23,
87 } TextboxFlags;
91 typedef enum
92 {
94  NORMAL = 0,
96  URGENT = 1,
98  ACTIVE = 2,
100  SELECTED = 4,
102  MARKUP = 8,
103 
105  ALT = 16,
107  HIGHLIGHT = 32,
111  STATE_MASK = ~( SELECTED | MARKUP | ALT | HIGHLIGHT )
113 
129 textbox* textbox_create ( widget *parent, WidgetType type, const char *name, TextboxFlags flags,
130  TextBoxFontType tbft, const char *text, double xalign, double yalign );
137 void textbox_font ( textbox *tb, TextBoxFontType tbft );
138 
145 void textbox_text ( textbox *tb, const char *text );
146 
155 int textbox_keybinding ( textbox *tb, KeyBindingAction action );
164 gboolean textbox_append_text ( textbox *tb, const char *pad, const int pad_len );
165 
172 void textbox_cursor ( textbox *tb, int pos );
173 
182 void textbox_insert ( textbox *tb, const int char_pos, const char *str, const int slen );
183 
189 void textbox_setup ( void );
190 
194 void textbox_cleanup ( void );
195 
203 int textbox_get_height ( const textbox *tb );
204 
212 int textbox_get_font_height ( const textbox *tb );
213 
221 int textbox_get_font_width ( const textbox *tb );
222 
228 double textbox_get_estimated_char_width ( void );
229 
235 double textbox_get_estimated_ch ( void );
241 double textbox_get_estimated_char_height ( void );
242 
250 void textbox_delete ( textbox *tb, int pos, int dlen );
251 
262 void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
263 
273 int textbox_get_estimated_height ( const textbox *tb, int eh );
280 void textbox_set_pango_context ( const char *font, PangoContext *p );
287 void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
288 
296 PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
297 
303 const char *textbox_get_visible_text ( const textbox *tb );
311 int textbox_get_desired_width ( widget *wid );
312 
318 void textbox_cursor_end ( textbox *tb );
319 
326 void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode );
328 #endif //ROFI_TEXTBOX_H
textbox_font
void textbox_font(textbox *tb, TextBoxFontType tbft)
Definition: textbox.c:234
textbox::flags
unsigned long flags
Definition: textbox.h:53
WidgetType
WidgetType
Definition: widget.h:57
ACTIVE
@ ACTIVE
Definition: textbox.h:98
textbox_get_desired_width
int textbox_get_desired_width(widget *wid)
Definition: textbox.c:919
textbox_get_estimated_ch
double textbox_get_estimated_ch(void)
Definition: textbox.c:905
textbox::emode
PangoEllipsizeMode emode
Definition: textbox.h:70
MARKUP
@ MARKUP
Definition: textbox.h:102
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:314
textbox_cursor_end
void textbox_cursor_end(textbox *tb)
Definition: textbox.c:584
NORMAL
@ NORMAL
Definition: textbox.h:94
TB_PASSWORD
@ TB_PASSWORD
Definition: textbox.h:85
textbox_append_text
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len)
Definition: textbox.c:785
textbox_setup
void textbox_setup(void)
Definition: textbox.c:817
HIGHLIGHT
@ HIGHLIGHT
Definition: textbox.h:107
TB_AUTOHEIGHT
@ TB_AUTOHEIGHT
Definition: textbox.h:80
TB_AUTOWIDTH
@ TB_AUTOWIDTH
Definition: textbox.h:81
textbox::show_placeholder
int show_placeholder
Definition: textbox.h:57
textbox::layout
PangoLayout * layout
Definition: textbox.h:58
textbox_get_font_height
int textbox_get_font_height(const textbox *tb)
Definition: textbox.c:867
textbox_get_estimated_char_width
double textbox_get_estimated_char_width(void)
Definition: textbox.c:894
SELECTED
@ SELECTED
Definition: textbox.h:100
textbox::xalign
double xalign
Definition: textbox.h:67
textbox_keybinding
int textbox_keybinding(textbox *tb, KeyBindingAction action)
Definition: textbox.c:721
flags
MenuFlags flags
Definition: view.c:108
textbox_get_height
int textbox_get_height(const textbox *tb)
Definition: textbox.c:862
textbox_get_visible_text
const char * textbox_get_visible_text(const textbox *tb)
Definition: textbox.c:291
textbox::cursor
short cursor
Definition: textbox.h:54
textbox::text
char * text
Definition: textbox.h:55
widget.h
textbox_insert
void textbox_insert(textbox *tb, const int char_pos, const char *str, const int slen)
Definition: textbox.c:598
keyb.h
textbox_cursor
void textbox_cursor(textbox *tb, int pos)
Definition: textbox.c:481
textbox::blink_timeout
guint blink_timeout
Definition: textbox.h:64
STATE_MASK
@ STATE_MASK
Definition: textbox.h:111
URGENT
@ URGENT
Definition: textbox.h:96
textbox::theme_name
const char * theme_name
Definition: textbox.h:72
TB_MARKUP
@ TB_MARKUP
Definition: textbox.h:83
FMOD_MASK
@ FMOD_MASK
Definition: textbox.h:109
TextboxFlags
TextboxFlags
Definition: textbox.h:79
textbox_cleanup
void textbox_cleanup(void)
Definition: textbox.c:835
textbox_set_ellipsize
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode)
Definition: textbox.c:944
textbox_get_pango_attributes
PangoAttrList * textbox_get_pango_attributes(textbox *tb)
Definition: textbox.c:298
textbox_get_font_width
int textbox_get_font_width(const textbox *tb)
Definition: textbox.c:874
TB_WRAP
@ TB_WRAP
Definition: textbox.h:84
textbox_delete
void textbox_delete(textbox *tb, int pos, int dlen)
Definition: textbox.c:622
TB_INDICATOR
@ TB_INDICATOR
Definition: textbox.h:86
textbox_get_estimated_height
int textbox_get_estimated_height(const textbox *tb, int eh)
Definition: textbox.c:914
widget-internal.h
TextBoxFontType
TextBoxFontType
Definition: textbox.h:92
textbox_set_pango_attributes
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list)
Definition: textbox.c:305
textbox::blink
int blink
Definition: textbox.h:63
ALT
@ ALT
Definition: textbox.h:105
textbox
Definition: textbox.h:51
textbox::tbft
int tbft
Definition: textbox.h:59
textbox_set_pango_context
void textbox_set_pango_context(const char *font, PangoContext *p)
Definition: textbox.c:824
textbox::changed
int changed
Definition: textbox.h:61
textbox_moveresize
void textbox_moveresize(textbox *tb, int x, int y, int w, int h)
Definition: textbox.c:347
textbox::metrics
PangoFontMetrics * metrics
Definition: textbox.h:69
textbox_get_estimated_char_height
double textbox_get_estimated_char_height(void)
Definition: textbox.c:883
textbox::placeholder
const char * placeholder
Definition: textbox.h:56
textbox::yalign
double yalign
Definition: textbox.h:66
TB_EDITABLE
@ TB_EDITABLE
Definition: textbox.h:82
textbox::markup
int markup
Definition: textbox.h:60
_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:164