2014-01-19 12:57:54 +00:00
|
|
|
#ifndef __TEXTBOX_H__
|
|
|
|
#define __TEXTBOX_H__
|
2014-05-27 06:31:59 +00:00
|
|
|
#include <X11/Xft/Xft.h>
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2014-08-02 18:02:37 +00:00
|
|
|
#include <pango/pango.h>
|
|
|
|
#include <pango/pangoxft.h>
|
|
|
|
#include <pango/pango-fontmap.h>
|
|
|
|
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-01-19 12:57:54 +00:00
|
|
|
unsigned long flags;
|
2014-03-22 20:04:19 +00:00
|
|
|
Window window, parent;
|
|
|
|
short x, y, w, h;
|
|
|
|
short cursor;
|
|
|
|
XftColor color_fg, color_bg;
|
2014-05-21 15:33:28 +00:00
|
|
|
char *text;
|
2014-03-22 20:04:19 +00:00
|
|
|
XIM xim;
|
|
|
|
XIC xic;
|
2014-08-02 18:02:37 +00:00
|
|
|
PangoLayout *layout;
|
2014-01-19 12:57:54 +00:00
|
|
|
} textbox;
|
|
|
|
|
|
|
|
|
2014-03-22 20:04:19 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2015-02-19 12:22:10 +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,
|
2014-01-19 12:57:54 +00:00
|
|
|
} TextboxFlags;
|
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
|
2014-05-25 21:32:06 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2014-11-24 19:35:28 +00:00
|
|
|
// Render font normally
|
2014-05-25 21:32:06 +00:00
|
|
|
NORMAL,
|
2015-01-12 18:14:46 +00:00
|
|
|
// Alternating row.
|
|
|
|
ALT,
|
2014-11-24 19:35:28 +00:00
|
|
|
// Render font highlighted (inverted colors.)
|
2014-05-25 21:32:06 +00:00
|
|
|
HIGHLIGHT,
|
|
|
|
} TextBoxFontType;
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2014-03-22 20:04:19 +00:00
|
|
|
textbox* textbox_create ( Window parent,
|
2015-01-21 09:04:15 +00:00
|
|
|
XVisualInfo *vinfo,
|
|
|
|
Colormap map,
|
2014-03-22 20:04:19 +00:00
|
|
|
TextboxFlags flags,
|
|
|
|
short x, short y, short w, short h,
|
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
|
|
|
|
*
|
|
|
|
* Free the textbox and all allocated memory.
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
void textbox_free ( textbox *tb );
|
2014-01-19 12:57:54 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Show the textbox (map window)
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
void textbox_show ( textbox *tb );
|
2014-11-24 19:35:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Render the textbox.
|
|
|
|
*/
|
2015-01-21 09:04:15 +00:00
|
|
|
void textbox_draw ( textbox * tb );
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param ev XEvent key inputs to textbox
|
|
|
|
*
|
|
|
|
* Let the textbox handle the input event.
|
|
|
|
*
|
|
|
|
* @returns if the key was handled (1), unhandled(0) or handled and return was pressed (-1)
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
int textbox_keypress ( textbox *tb, XEvent *ev );
|
2014-01-19 12:57:54 +00:00
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move the cursor to the end of the string.
|
|
|
|
*/
|
2014-03-22 20:04:19 +00:00
|
|
|
void textbox_cursor_end ( textbox *tb );
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param x The new x coordinate to move the window to
|
|
|
|
* @param y The new y coordinate to move the window to
|
|
|
|
*
|
|
|
|
* Move the window to x,y position.
|
|
|
|
*/
|
2014-05-22 08:03:36 +00:00
|
|
|
void textbox_move ( textbox *tb, int x, int y );
|
2014-05-25 21:32:06 +00:00
|
|
|
|
2014-11-24 19:35:28 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
* @param pos The position to insert the string at
|
|
|
|
* @param str The string to insert.
|
|
|
|
*
|
|
|
|
* Insert the string str at position pos.
|
|
|
|
*/
|
2014-05-27 10:55:47 +00:00
|
|
|
void textbox_insert ( textbox *tb, int pos, char *str );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
2014-05-27 06:31:59 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Unmap the textbox window. Effectively hiding it.
|
|
|
|
*/
|
|
|
|
void textbox_hide ( textbox *tb );
|
2014-05-25 21:32:06 +00:00
|
|
|
|
2014-05-27 06:31:59 +00:00
|
|
|
/**
|
2015-01-21 09:04:15 +00:00
|
|
|
* @param visual Information about the visual to target
|
|
|
|
* @param colormap The colormap to set the colors for.
|
2014-05-27 06:31:59 +00:00
|
|
|
* @param bg The background color.
|
2015-01-12 18:14:46 +00:00
|
|
|
* @param bg_alt The background color for alternating row.
|
2014-05-27 06:31:59 +00:00
|
|
|
* @param fg The foreground color.
|
|
|
|
* @param hlbg The background color for a highlighted entry.
|
|
|
|
* @param hlfg The foreground color for a highlighted entry.
|
|
|
|
*
|
|
|
|
* Setup the cached fonts. This is required to do
|
|
|
|
* before any of the textbox_ functions is called.
|
|
|
|
* Clean with textbox_cleanup()
|
|
|
|
*/
|
2015-01-21 09:04:15 +00:00
|
|
|
void textbox_setup ( XVisualInfo *visual, Colormap colormap,
|
|
|
|
const char *bg, const char *bg_alt, const char *fg,
|
|
|
|
const char *hlbg, const char *hlfg
|
|
|
|
);
|
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
|
|
|
*/
|
2014-08-02 18:02:37 +00:00
|
|
|
int textbox_get_height ( textbox *tb );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* Get the width of the textbox
|
2014-11-24 19:22:44 +00:00
|
|
|
*
|
2014-11-24 19:35:28 +00:00
|
|
|
* @returns the width of the textbox in pixels.
|
2014-11-24 19:22:44 +00:00
|
|
|
*/
|
2014-08-02 18:02:37 +00:00
|
|
|
int textbox_get_width ( 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
|
|
|
*/
|
2014-08-02 18:02:37 +00:00
|
|
|
int textbox_get_font_height ( 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
|
|
|
*/
|
2014-08-02 18:02:37 +00:00
|
|
|
int textbox_get_font_width ( textbox *tb );
|
|
|
|
|
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 );
|
2014-08-30 18:45:08 +00:00
|
|
|
|
|
|
|
|
2014-11-24 19:22:44 +00:00
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Delete character before cursor.
|
|
|
|
*/
|
2014-08-30 18:45:08 +00:00
|
|
|
void textbox_cursor_bkspc ( textbox *tb );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Delete character after cursor.
|
|
|
|
*/
|
2014-08-30 18:45:08 +00:00
|
|
|
void textbox_cursor_del ( textbox *tb );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move cursor one position backward.
|
|
|
|
*/
|
2014-08-30 18:45:08 +00:00
|
|
|
void textbox_cursor_dec ( textbox *tb );
|
2014-11-24 19:22:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param tb Handle to the textbox
|
|
|
|
*
|
|
|
|
* Move cursor one position forward.
|
|
|
|
*/
|
2014-08-30 18:45:08 +00:00
|
|
|
void textbox_cursor_inc ( textbox *tb );
|
|
|
|
|
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 );
|
|
|
|
|
2014-01-19 12:57:54 +00:00
|
|
|
#endif //__TEXTBOX_H__
|