2015-07-27 04:17:12 -04:00
|
|
|
#ifndef ROFI_TEXTBOX_H
|
|
|
|
#define ROFI_TEXTBOX_H
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2016-02-21 07:10:32 -05:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2014-08-02 14:02:37 -04:00
|
|
|
#include <pango/pango.h>
|
|
|
|
#include <pango/pango-fontmap.h>
|
2015-12-28 05:24:25 -05:00
|
|
|
#include <pango/pangocairo.h>
|
2015-09-26 14:34:34 -04:00
|
|
|
#include <cairo.h>
|
2016-01-09 10:22:09 -05:00
|
|
|
#include "widget.h"
|
2016-02-21 13:27:53 -05:00
|
|
|
#include "x11-helper.h"
|
2016-04-07 09:32:22 -04:00
|
|
|
#include "keyb.h"
|
2014-08-02 14:02:37 -04:00
|
|
|
|
2016-01-07 02:54:24 -05:00
|
|
|
/**
|
|
|
|
* @defgroup Textbox Textbox
|
|
|
|
* @ingroup Widgets
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-09-26 14:34:34 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
2016-01-09 10:22:09 -05:00
|
|
|
Widget widget;
|
2015-09-26 14:34:34 -04: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 14:57:26 -05:00
|
|
|
int blink;
|
|
|
|
guint blink_timeout;
|
2014-01-19 07:57:54 -05:00
|
|
|
} textbox;
|
|
|
|
|
2014-03-22 16:04:19 -04:00
|
|
|
typedef enum
|
|
|
|
{
|
2016-07-14 01:48:28 -04: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,
|
2014-01-19 07:57:54 -05:00
|
|
|
} TextboxFlags;
|
|
|
|
|
2014-05-25 17:32:06 -04:00
|
|
|
typedef enum
|
|
|
|
{
|
2014-11-24 14:35:28 -05:00
|
|
|
// Render font normally
|
2015-04-06 11:13:26 -04:00
|
|
|
NORMAL = 0,
|
|
|
|
URGENT = 1,
|
|
|
|
ACTIVE = 2,
|
2015-11-30 08:05:39 -05:00
|
|
|
SELECTED = 4,
|
|
|
|
MARKUP = 8,
|
2015-04-06 11:13:26 -04:00
|
|
|
|
2015-01-12 13:14:46 -05:00
|
|
|
// Alternating row.
|
2015-11-30 08:05:39 -05:00
|
|
|
ALT = 16,
|
2014-11-24 14:35:28 -05:00
|
|
|
// Render font highlighted (inverted colors.)
|
2015-11-30 08:05:39 -05:00
|
|
|
HIGHLIGHT = 32,
|
2015-04-02 16:23:17 -04:00
|
|
|
|
2015-04-06 11:13:26 -04:00
|
|
|
FMOD_MASK = ( ALT | HIGHLIGHT ),
|
2015-11-30 08:05:39 -05:00
|
|
|
STATE_MASK = ~( SELECTED | MARKUP | ALT | HIGHLIGHT )
|
2014-05-25 17:32:06 -04:00
|
|
|
} TextBoxFontType;
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2015-09-26 14:34:34 -04:00
|
|
|
textbox* textbox_create ( TextboxFlags flags,
|
2014-03-22 16:04:19 -04:00
|
|
|
short x, short y, short w, short h,
|
2014-05-25 17:32:06 -04:00
|
|
|
TextBoxFontType tbft,
|
2015-02-03 02:21:59 -05:00
|
|
|
const char *text );
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Free the textbox and all allocated memory.
|
|
|
|
*/
|
2014-03-22 16:04:19 -04:00
|
|
|
void textbox_free ( textbox *tb );
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param tbft The style of font to render.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* Set the font render style.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-05-25 17:32:06 -04:00
|
|
|
void textbox_font ( textbox *tb, TextBoxFontType tbft );
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2014-11-24 14:35:28 -05: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 02:21:59 -05:00
|
|
|
void textbox_text ( textbox *tb, const char *text );
|
2014-11-24 14:35:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Render the textbox.
|
|
|
|
*/
|
2015-09-26 14:34:34 -04:00
|
|
|
void textbox_draw ( textbox *tb, cairo_t *draw );
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2016-04-07 09:32:22 -04:00
|
|
|
int textbox_keybinding ( textbox *tb, KeyBindingAction action );
|
2016-05-22 13:41:52 -04: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
|
|
|
|
*/
|
|
|
|
gboolean textbox_append_char ( textbox *tb, char *pad, int pad_len );
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2014-11-24 14:35:28 -05:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move the cursor to the end of the string.
|
|
|
|
*/
|
2014-03-22 16:04:19 -04:00
|
|
|
void textbox_cursor_end ( textbox *tb );
|
2014-11-24 14:35:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param pos New cursor position
|
|
|
|
*
|
|
|
|
* Set the cursor position (string index)
|
|
|
|
*/
|
2014-05-27 06:55:47 -04:00
|
|
|
void textbox_cursor ( textbox *tb, int pos );
|
2014-11-24 14:35:28 -05:00
|
|
|
|
|
|
|
/**
|
2015-11-22 14:41:45 -05: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 14:35:28 -05:00
|
|
|
*
|
|
|
|
* Insert the string str at position pos.
|
|
|
|
*/
|
2015-11-22 14:41:45 -05:00
|
|
|
void textbox_insert ( textbox *tb, int pos, char *str, int slen );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
2014-05-27 02:31:59 -04: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 13:42:32 -05:00
|
|
|
void textbox_setup ( void );
|
2014-05-27 02:31:59 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup the allocated colors and fonts by textbox_setup().
|
|
|
|
*/
|
2015-02-18 02:53:38 -05:00
|
|
|
void textbox_cleanup ( void );
|
2014-05-27 02:31:59 -04:00
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* Get the height of the textbox
|
2014-11-24 14:22:44 -05:00
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns the height of the textbox in pixels.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-08-02 14:02:37 -04:00
|
|
|
int textbox_get_height ( textbox *tb );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* Get the width of the textbox
|
2014-11-24 14:22:44 -05:00
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns the width of the textbox in pixels.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-08-02 14:02:37 -04:00
|
|
|
int textbox_get_width ( textbox *tb );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Get the height of the rendered string.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns the height of the string in pixels.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-08-02 14:02:37 -04:00
|
|
|
int textbox_get_font_height ( textbox *tb );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Get the width of the rendered string.
|
|
|
|
*
|
2014-11-24 14:35:28 -05:00
|
|
|
* @returns the width of the string in pixels.
|
2014-11-24 14:22:44 -05:00
|
|
|
*/
|
2014-08-02 14:02:37 -04:00
|
|
|
int textbox_get_font_width ( textbox *tb );
|
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* Estimate the width of a character.
|
|
|
|
*
|
|
|
|
* @returns the width of a character in pixels.
|
|
|
|
*/
|
2015-02-18 02:53:38 -05:00
|
|
|
double textbox_get_estimated_char_width ( void );
|
2014-08-30 14:45:08 -04:00
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Delete character before cursor.
|
|
|
|
*/
|
2014-08-30 14:45:08 -04:00
|
|
|
void textbox_cursor_bkspc ( textbox *tb );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Delete character after cursor.
|
|
|
|
*/
|
2014-08-30 14:45:08 -04:00
|
|
|
void textbox_cursor_del ( textbox *tb );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move cursor one position backward.
|
|
|
|
*/
|
2014-08-30 14:45:08 -04:00
|
|
|
void textbox_cursor_dec ( textbox *tb );
|
2014-11-24 14:22:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move cursor one position forward.
|
|
|
|
*/
|
2014-08-30 14:45:08 -04:00
|
|
|
void textbox_cursor_inc ( textbox *tb );
|
|
|
|
|
2014-11-24 14:35:28 -05: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 14:45:08 -04:00
|
|
|
void textbox_delete ( textbox *tb, int pos, int dlen );
|
|
|
|
|
2015-03-18 15:56:50 -04:00
|
|
|
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
|
2015-03-19 14:58:05 -04:00
|
|
|
int textbox_get_estimated_char_height ( void );
|
2015-12-28 05:24:25 -05:00
|
|
|
void textbox_set_pango_context ( PangoContext *p );
|
2016-05-10 12:02:23 -04:00
|
|
|
void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
|
2016-01-07 02:54:24 -05:00
|
|
|
|
2016-05-10 12:02:23 -04:00
|
|
|
PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
|
|
|
|
|
|
|
|
const char *textbox_get_visible_text ( textbox *tb );
|
2016-01-07 02:54:24 -05:00
|
|
|
/*@}*/
|
2015-07-27 04:17:12 -04:00
|
|
|
#endif //ROFI_TEXTBOX_H
|