2017-04-15 06:32:05 -04:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2017 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-07-27 04:17:12 -04:00
|
|
|
#ifndef ROFI_TEXTBOX_H
|
|
|
|
#define ROFI_TEXTBOX_H
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
#include "keyb.h"
|
|
|
|
#include "widgets/widget-internal.h"
|
|
|
|
#include "widgets/widget.h"
|
|
|
|
#include <cairo.h>
|
2014-08-02 14:02:37 -04:00
|
|
|
#include <pango/pango-fontmap.h>
|
2021-08-19 07:34:01 -04:00
|
|
|
#include <pango/pango.h>
|
2015-12-28 05:24:25 -05:00
|
|
|
#include <pango/pangocairo.h>
|
2021-08-19 07:34:01 -04:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2014-08-02 14:02:37 -04:00
|
|
|
|
2016-01-07 02:54:24 -05:00
|
|
|
/**
|
|
|
|
* @defgroup Textbox Textbox
|
2016-10-13 03:22:08 -04:00
|
|
|
* @ingroup widget
|
2016-01-07 02:54:24 -05:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2020-09-13 04:24:59 -04:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
/** Cache to hold font descriptions. This it to avoid having to lookup each
|
|
|
|
* time. */
|
|
|
|
typedef struct TBFontConfig {
|
|
|
|
/** Font description */
|
|
|
|
PangoFontDescription *pfd;
|
|
|
|
/** Font metrics */
|
|
|
|
PangoFontMetrics *metrics;
|
|
|
|
/** height */
|
|
|
|
double height;
|
|
|
|
} TBFontConfig;
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Internal structure of a textbox widget.
|
2016-11-15 15:54:31 -05:00
|
|
|
* TODO make this internal to textbox
|
2016-10-14 10:46:54 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
typedef struct {
|
|
|
|
widget widget;
|
|
|
|
unsigned long flags;
|
|
|
|
short cursor;
|
|
|
|
char *text;
|
|
|
|
const char *placeholder;
|
|
|
|
int show_placeholder;
|
|
|
|
PangoLayout *layout;
|
|
|
|
int tbft;
|
|
|
|
int markup;
|
|
|
|
int changed;
|
2015-09-26 14:34:34 -04:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
int blink;
|
|
|
|
guint blink_timeout;
|
2017-01-24 02:40:37 -05:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
double yalign;
|
|
|
|
double xalign;
|
2017-05-24 13:57:35 -04:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
TBFontConfig *tbfc;
|
2020-09-13 04:24:59 -04:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
PangoEllipsizeMode emode;
|
|
|
|
//
|
|
|
|
const char *theme_name;
|
2014-01-19 07:57:54 -05:00
|
|
|
} textbox;
|
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Flags for configuring textbox behaviour and looks during creation.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
typedef enum {
|
|
|
|
TB_AUTOHEIGHT = 1 << 0,
|
|
|
|
TB_AUTOWIDTH = 1 << 1,
|
|
|
|
TB_EDITABLE = 1 << 19,
|
|
|
|
TB_MARKUP = 1 << 20,
|
|
|
|
TB_WRAP = 1 << 21,
|
|
|
|
TB_PASSWORD = 1 << 22,
|
|
|
|
TB_INDICATOR = 1 << 23,
|
2014-01-19 07:57:54 -05:00
|
|
|
} TextboxFlags;
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Flags indicating current state of the textbox.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
typedef enum {
|
|
|
|
/** Normal */
|
|
|
|
NORMAL = 0,
|
|
|
|
/** Text in box is urgent. */
|
|
|
|
URGENT = 1,
|
|
|
|
/** Text in box is active. */
|
|
|
|
ACTIVE = 2,
|
|
|
|
/** Text in box is selected. */
|
|
|
|
SELECTED = 4,
|
|
|
|
/** Text in box has pango markup. */
|
|
|
|
MARKUP = 8,
|
2015-04-06 11:13:26 -04:00
|
|
|
|
2021-08-19 07:34:01 -04:00
|
|
|
/** Text is on an alternate row */
|
|
|
|
ALT = 16,
|
|
|
|
/** Render font highlighted (inverted colors.) */
|
|
|
|
HIGHLIGHT = 32,
|
|
|
|
/** Mask for alternate and highlighted */
|
|
|
|
FMOD_MASK = (ALT | HIGHLIGHT),
|
|
|
|
/** Mask of bits indicating state */
|
|
|
|
STATE_MASK = ~(SELECTED | MARKUP | ALT | HIGHLIGHT)
|
2014-05-25 17:32:06 -04:00
|
|
|
} TextBoxFontType;
|
2014-01-19 07:57:54 -05:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
2017-09-09 05:25:33 -04:00
|
|
|
* @param parent The widget's parent.
|
2017-05-30 08:15:13 -04:00
|
|
|
* @param type The type of the to be created widget.
|
2017-01-01 12:40:49 -05:00
|
|
|
* @param name The name of the to be created widget.
|
2016-10-14 10:46:54 -04:00
|
|
|
* @param flags #TextboxFlags indicating the type of textbox.
|
|
|
|
* @param tbft #TextBoxFontType current state of textbox.
|
2017-11-23 12:41:52 -05:00
|
|
|
* @param text initial text to display.
|
2017-06-07 14:14:53 -04:00
|
|
|
* @param xalign Set the Xalign value.
|
|
|
|
* @param yalign set the yalign value.
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
|
|
|
* Create a new textbox widget.
|
|
|
|
*
|
|
|
|
* free with #widget_free
|
|
|
|
* @returns a new #textbox
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
textbox *textbox_create(widget *parent, WidgetType type, const char *name,
|
|
|
|
TextboxFlags flags, TextBoxFontType tbft,
|
|
|
|
const char *text, double xalign, double yalign);
|
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
|
|
|
*/
|
2021-08-19 07:34:01 -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)
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_text(textbox *tb, const char *text);
|
2014-11-24 14:35:28 -05:00
|
|
|
|
2016-10-14 10:46:54 -04: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.
|
|
|
|
*/
|
2021-08-19 07:34:01 -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
|
|
|
|
*
|
2021-08-19 07:34:01 -04:00
|
|
|
* The text should be one insert from a keypress.. the first gunichar is
|
|
|
|
* validated to be (or not) control return TRUE if inserted
|
2016-05-22 13:41:52 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
gboolean textbox_append_text(textbox *tb, const char *pad, const 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
|
|
|
|
* @param pos New cursor position
|
|
|
|
*
|
|
|
|
* Set the cursor position (string index)
|
|
|
|
*/
|
2021-08-19 07:34:01 -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
|
2017-04-23 09:17:15 -04:00
|
|
|
* @param char_pos The position to insert the string at
|
2015-11-22 14:41:45 -05:00
|
|
|
* @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.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_insert(textbox *tb, const int char_pos, const char *str,
|
|
|
|
const 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()
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_setup(void);
|
2014-05-27 02:31:59 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup the allocated colors and fonts by textbox_setup().
|
|
|
|
*/
|
2021-08-19 07:34:01 -04: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
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int textbox_get_height(const 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
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int textbox_get_font_height(const 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
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int textbox_get_font_width(const textbox *tb);
|
2014-08-02 14:02:37 -04:00
|
|
|
|
2014-11-24 14:22:44 -05:00
|
|
|
/**
|
|
|
|
* Estimate the width of a character.
|
|
|
|
*
|
|
|
|
* @returns the width of a character in pixels.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
double textbox_get_estimated_char_width(void);
|
2017-01-01 12:08:49 -05:00
|
|
|
|
2017-09-05 07:52:21 -04:00
|
|
|
/**
|
|
|
|
* Estimate the width of a 0.
|
|
|
|
*
|
|
|
|
* @returns the width of a 0 in pixels.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
double textbox_get_estimated_ch(void);
|
2017-01-01 12:08:49 -05:00
|
|
|
/**
|
|
|
|
* Estimate the height of a character.
|
|
|
|
*
|
|
|
|
* @returns the height of a character in pixels.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
double textbox_get_estimated_char_height(void);
|
2014-08-30 14:45:08 -04:00
|
|
|
|
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.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_delete(textbox *tb, int pos, int dlen);
|
2014-08-30 14:45:08 -04:00
|
|
|
|
2016-10-14 10:46:54 -04: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 15:54:31 -05:00
|
|
|
* TODO remove for #widget_resize and #widget_move
|
2016-10-14 10:46:54 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_moveresize(textbox *tb, int x, int y, int w, int h);
|
2016-12-31 17:00:06 -05:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
2016-12-28 07:46:53 -05:00
|
|
|
* @param tb Handle to the textbox
|
2017-01-01 12:40:49 -05:00
|
|
|
* @param eh The number of rows to display
|
|
|
|
*
|
2021-08-19 07:34:01 -04:00
|
|
|
* Get the (estimated) with of a character, can be used to calculate window
|
|
|
|
* width. This includes padding.
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
|
|
|
* @returns the estimated width of a character.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
int textbox_get_estimated_height(const textbox *tb, int eh);
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
2017-01-24 02:40:37 -05:00
|
|
|
* @param font The name of the font used.
|
2016-10-14 10:46:54 -04:00
|
|
|
* @param p The new default PangoContext
|
|
|
|
*
|
|
|
|
* Set the default pango context (with font description) for all textboxes.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_set_pango_context(const char *font, PangoContext *p);
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param list New pango attributes
|
|
|
|
*
|
2016-11-15 15:54:31 -05:00
|
|
|
* Sets list as active pango attributes.
|
2016-10-14 10:46:54 -04:00
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list);
|
2016-01-07 02:54:24 -05:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Get the list of currently active pango attributes.
|
|
|
|
*
|
|
|
|
* @returns the pango attributes
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
PangoAttrList *textbox_get_pango_attributes(textbox *tb);
|
2016-05-10 12:02:23 -04:00
|
|
|
|
2016-08-23 18:39:56 -04:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* @returns the visible text.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
const char *textbox_get_visible_text(const textbox *tb);
|
2018-06-12 06:00:00 -04:00
|
|
|
/**
|
|
|
|
* @param wid The handle to the textbox.
|
2021-09-07 13:40:07 -04:00
|
|
|
* @param height The height we want the desired width for
|
2018-06-12 06:00:00 -04:00
|
|
|
*
|
|
|
|
* TODO: is this deprecated by widget::get_desired_width
|
|
|
|
*
|
|
|
|
* @returns the desired width of the textbox.
|
|
|
|
*/
|
2021-09-07 13:40:07 -04:00
|
|
|
int textbox_get_desired_width(widget *wid, const int height);
|
2017-08-29 04:40:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move the cursor to the end of the string.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_cursor_end(textbox *tb);
|
2019-05-04 05:01:09 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param mode The PangoEllipsizeMode to use displaying the text in the textbox
|
|
|
|
*
|
|
|
|
* Set the ellipsizing mode used on the string.
|
|
|
|
*/
|
2021-08-19 07:34:01 -04:00
|
|
|
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode);
|
2020-10-12 15:39:36 -04:00
|
|
|
/**@}*/
|
2021-08-19 07:34:01 -04:00
|
|
|
#endif // ROFI_TEXTBOX_H
|