2015-07-27 08:17:12 +00:00
|
|
|
#ifndef ROFI_TEXTBOX_H
|
|
|
|
#define ROFI_TEXTBOX_H
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2016-02-21 12:10:32 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2014-08-02 18:02:37 +00:00
|
|
|
#include <pango/pango.h>
|
|
|
|
#include <pango/pango-fontmap.h>
|
2015-12-28 10:24:25 +00:00
|
|
|
#include <pango/pangocairo.h>
|
2015-09-26 18:34:34 +00:00
|
|
|
#include <cairo.h>
|
2016-10-09 08:13:15 +00:00
|
|
|
#include "widgets/widget.h"
|
|
|
|
#include "widgets/widget-internal.h"
|
2016-02-21 18:27:53 +00:00
|
|
|
#include "x11-helper.h"
|
2016-04-07 13:32:22 +00:00
|
|
|
#include "keyb.h"
|
2014-08-02 18:02:37 +00:00
|
|
|
|
2016-01-07 07:54:24 +00:00
|
|
|
/**
|
|
|
|
* @defgroup Textbox Textbox
|
2016-10-13 07:22:08 +00:00
|
|
|
* @ingroup widget
|
2016-01-07 07:54:24 +00:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* Internal structure of a textbox widget.
|
2016-11-15 20:54:31 +00:00
|
|
|
* TODO make this internal to textbox
|
2016-10-14 14:46:54 +00:00
|
|
|
*/
|
2015-09-26 18:34:34 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2016-10-08 16:57:59 +00:00
|
|
|
widget widget;
|
2015-09-26 18:34:34 +00:00
|
|
|
unsigned long flags;
|
|
|
|
short cursor;
|
|
|
|
Color color_fg, color_bg;
|
|
|
|
char *text;
|
|
|
|
PangoLayout *layout;
|
|
|
|
int tbft;
|
|
|
|
int markup;
|
|
|
|
int changed;
|
|
|
|
|
|
|
|
cairo_surface_t *main_surface;
|
|
|
|
cairo_t *main_draw;
|
|
|
|
|
|
|
|
int update;
|
2016-01-20 19:57:26 +00:00
|
|
|
int blink;
|
|
|
|
guint blink_timeout;
|
2016-12-11 16:06:31 +00:00
|
|
|
//
|
2017-01-08 20:36:06 +00:00
|
|
|
const char *theme_name;
|
2014-01-19 12:57:54 +00:00
|
|
|
} textbox;
|
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* Flags for configuring textbox behaviour and looks during creation.
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2017-01-09 21:40:11 +00:00
|
|
|
TB_AUTOHEIGHT = 1 << 0,
|
|
|
|
TB_AUTOWIDTH = 1 << 1,
|
|
|
|
TB_LEFT = 1 << 16,
|
|
|
|
TB_RIGHT = 1 << 17,
|
|
|
|
TB_CENTER = 1 << 18,
|
|
|
|
TB_EDITABLE = 1 << 19,
|
|
|
|
TB_MARKUP = 1 << 20,
|
|
|
|
TB_WRAP = 1 << 21,
|
|
|
|
TB_PASSWORD = 1 << 22,
|
|
|
|
TB_INDICATOR = 1 << 23,
|
2014-01-19 12:57:54 +00:00
|
|
|
} TextboxFlags;
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* Flags indicating current state of the textbox.
|
|
|
|
*/
|
2014-05-25 21:32:06 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Normal */
|
2015-04-06 15:13:26 +00:00
|
|
|
NORMAL = 0,
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Text in box is urgent. */
|
2015-04-06 15:13:26 +00:00
|
|
|
URGENT = 1,
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Text in box is active. */
|
2015-04-06 15:13:26 +00:00
|
|
|
ACTIVE = 2,
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Text in box is selected. */
|
2015-11-30 13:05:39 +00:00
|
|
|
SELECTED = 4,
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Text in box has pango markup. */
|
2015-11-30 13:05:39 +00:00
|
|
|
MARKUP = 8,
|
2015-04-06 15:13:26 +00:00
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Text is on an alternate row */
|
2015-11-30 13:05:39 +00:00
|
|
|
ALT = 16,
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Render font highlighted (inverted colors.) */
|
2015-11-30 13:05:39 +00:00
|
|
|
HIGHLIGHT = 32,
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Mask for alternate and highlighted */
|
2015-04-06 15:13:26 +00:00
|
|
|
FMOD_MASK = ( ALT | HIGHLIGHT ),
|
2016-10-14 14:46:54 +00:00
|
|
|
/** Mask of bits indicating state */
|
2015-11-30 13:05:39 +00:00
|
|
|
STATE_MASK = ~( SELECTED | MARKUP | ALT | HIGHLIGHT )
|
2014-05-25 21:32:06 +00:00
|
|
|
} TextBoxFontType;
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
2017-01-01 17:40:49 +00:00
|
|
|
* @param name The name of the to be created widget.
|
2016-10-14 14:46:54 +00:00
|
|
|
* @param flags #TextboxFlags indicating the type of textbox.
|
|
|
|
* @param tbft #TextBoxFontType current state of textbox.
|
|
|
|
* @param text intial text to display.
|
|
|
|
*
|
|
|
|
* Create a new textbox widget.
|
|
|
|
*
|
|
|
|
* free with #widget_free
|
|
|
|
* @returns a new #textbox
|
|
|
|
*/
|
2016-12-11 16:06:31 +00:00
|
|
|
textbox* textbox_create ( const char *name, TextboxFlags flags,
|
2014-05-25 21:32:06 +00:00
|
|
|
TextBoxFontType tbft,
|
2015-02-03 07:21:59 +00:00
|
|
|
const char *text );
|
2014-11-24 19:22:44 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param tbft The style of font to render.
|
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* Set the font render style.
|
2014-11-24 19:22:44 +00:00
|
|
|
*/
|
2014-05-25 21:32:06 +00:00
|
|
|
void textbox_font ( textbox *tb, TextBoxFontType tbft );
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param text The text to show in the textbox
|
|
|
|
*
|
|
|
|
* Set the text to show. Cursor is moved to end (if visible)
|
|
|
|
*/
|
2015-02-03 07:21:59 +00:00
|
|
|
void textbox_text ( textbox *tb, const char *text );
|
2014-11-24 19:35:28 +00:00
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param action the #KeyBindingAction to execute on textbox
|
|
|
|
*
|
|
|
|
* Execute an action on the textbox.
|
|
|
|
*
|
|
|
|
* @return TRUE if action was taken.
|
|
|
|
*/
|
2016-04-07 13:32:22 +00:00
|
|
|
int textbox_keybinding ( textbox *tb, KeyBindingAction action );
|
2016-05-22 17:41:52 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param pad The text to insert
|
|
|
|
* @param pad_len the length of the text
|
|
|
|
*
|
|
|
|
* The text should be one insert from a keypress.. the first gunichar is validated to be (or not) control
|
|
|
|
* return TRUE if inserted
|
|
|
|
*/
|
2016-08-23 22:39:56 +00:00
|
|
|
gboolean textbox_append_char ( textbox *tb, const char *pad, const int pad_len );
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param pos New cursor position
|
|
|
|
*
|
|
|
|
* Set the cursor position (string index)
|
|
|
|
*/
|
2014-05-27 10:55:47 +00:00
|
|
|
void textbox_cursor ( textbox *tb, int pos );
|
2014-11-24 19:35:28 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-22 19:41:45 +00:00
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param pos The position to insert the string at
|
|
|
|
* @param str The string to insert.
|
|
|
|
* @param slen The length of the string.
|
2014-11-24 19:35:28 +00:00
|
|
|
*
|
|
|
|
* Insert the string str at position pos.
|
|
|
|
*/
|
2016-08-23 22:39:56 +00:00
|
|
|
void textbox_insert ( textbox *tb, const int pos, const char *str, const int slen );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
2014-05-27 06:31:59 +00:00
|
|
|
/**
|
|
|
|
* Setup the cached fonts. This is required to do
|
|
|
|
* before any of the textbox_ functions is called.
|
|
|
|
* Clean with textbox_cleanup()
|
|
|
|
*/
|
2016-02-21 18:42:32 +00:00
|
|
|
void textbox_setup ( void );
|
2014-05-27 06:31:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup the allocated colors and fonts by textbox_setup().
|
|
|
|
*/
|
2015-02-18 07:53:38 +00:00
|
|
|
void textbox_cleanup ( void );
|
2014-05-27 06:31:59 +00:00
|
|
|
|
2014-11-24 19:22:44 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* Get the height of the textbox
|
2014-11-24 19:22:44 +00:00
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* @returns the height of the textbox in pixels.
|
2014-11-24 19:22:44 +00:00
|
|
|
*/
|
2016-08-23 22:39:56 +00:00
|
|
|
int textbox_get_height ( const textbox *tb );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Get the height of the rendered string.
|
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* @returns the height of the string in pixels.
|
2014-11-24 19:22:44 +00:00
|
|
|
*/
|
2016-08-23 22:39:56 +00:00
|
|
|
int textbox_get_font_height ( const textbox *tb );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Get the width of the rendered string.
|
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* @returns the width of the string in pixels.
|
2014-11-24 19:22:44 +00:00
|
|
|
*/
|
2016-08-23 22:39:56 +00:00
|
|
|
int textbox_get_font_width ( const textbox *tb );
|
2014-08-02 18:02:37 +00:00
|
|
|
|
2014-11-24 19:22:44 +00:00
|
|
|
/**
|
|
|
|
* Estimate the width of a character.
|
|
|
|
*
|
|
|
|
* @returns the width of a character in pixels.
|
|
|
|
*/
|
2015-02-18 07:53:38 +00:00
|
|
|
double textbox_get_estimated_char_width ( void );
|
2017-01-01 17:08:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Estimate the height of a character.
|
|
|
|
*
|
|
|
|
* @returns the height of a character in pixels.
|
|
|
|
*/
|
2016-12-31 22:00:06 +00:00
|
|
|
double textbox_get_estimated_char_height ( void );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param pos The start position
|
|
|
|
* @param dlen The length
|
|
|
|
*
|
|
|
|
* Remove dlen bytes from position pos.
|
|
|
|
*/
|
2014-08-30 18:45:08 +00:00
|
|
|
void textbox_delete ( textbox *tb, int pos, int dlen );
|
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param x The new horizontal position to place with textbox
|
|
|
|
* @param y The new vertical position to place with textbox
|
|
|
|
* @param w The new width of the textbox
|
|
|
|
* @param h The new height of the textbox
|
|
|
|
*
|
|
|
|
* Move and resize the textbox.
|
2016-11-15 20:54:31 +00:00
|
|
|
* TODO remove for #widget_resize and #widget_move
|
2016-10-14 14:46:54 +00:00
|
|
|
*/
|
2015-03-18 19:56:50 +00:00
|
|
|
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
|
2016-12-31 22:00:06 +00:00
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
2016-12-28 12:46:53 +00:00
|
|
|
* @param tb Handle to the textbox
|
2017-01-01 17:40:49 +00:00
|
|
|
* @param eh The number of rows to display
|
|
|
|
*
|
2016-10-14 14:46:54 +00:00
|
|
|
* Get the (estimated) with of a character, can be used to calculate window width.
|
2017-01-01 17:40:49 +00:00
|
|
|
* This includes padding.
|
2016-10-14 14:46:54 +00:00
|
|
|
*
|
|
|
|
* @returns the estimated width of a character.
|
|
|
|
*/
|
2016-12-31 22:00:06 +00:00
|
|
|
int textbox_get_estimated_height ( const textbox *tb, int eh );
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* @param p The new default PangoContext
|
|
|
|
*
|
|
|
|
* Set the default pango context (with font description) for all textboxes.
|
|
|
|
*/
|
2015-12-28 10:24:25 +00:00
|
|
|
void textbox_set_pango_context ( PangoContext *p );
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param list New pango attributes
|
|
|
|
*
|
2016-11-15 20:54:31 +00:00
|
|
|
* Sets list as active pango attributes.
|
2016-10-14 14:46:54 +00:00
|
|
|
*/
|
2016-05-10 16:02:23 +00:00
|
|
|
void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
|
2016-01-07 07:54:24 +00:00
|
|
|
|
2016-10-14 14:46:54 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Get the list of currently active pango attributes.
|
|
|
|
*
|
|
|
|
* @returns the pango attributes
|
|
|
|
*/
|
2016-05-10 16:02:23 +00:00
|
|
|
PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
|
|
|
|
|
2016-08-23 22:39:56 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* @returns the visible text.
|
|
|
|
*/
|
|
|
|
const char *textbox_get_visible_text ( const textbox *tb );
|
2016-01-07 07:54:24 +00:00
|
|
|
/*@}*/
|
2015-07-27 08:17:12 +00:00
|
|
|
#endif //ROFI_TEXTBOX_H
|