Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2006 John-Mark Bell <jmb@netsurf-browser.org>
  3.  * Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * NetSurf is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; version 2 of the License.
  10.  *
  11.  * NetSurf is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  
  20. /** \file
  21.  * Single/Multi-line UTF-8 text area (interface)
  22.  */
  23.  
  24. #ifndef _NETSURF_DESKTOP_TEXTAREA_H_
  25. #define _NETSURF_DESKTOP_TEXTAREA_H_
  26.  
  27. #include <stdint.h>
  28. #include <stdbool.h>
  29. #include "desktop/browser.h"
  30. #include "desktop/plot_style.h"
  31.  
  32.  
  33. struct textarea;
  34.  
  35. /* Text area flags */
  36. typedef enum {
  37.         TEXTAREA_DEFAULT                = (1 << 0),     /**< Standard input */
  38.         TEXTAREA_MULTILINE              = (1 << 1),     /**< Multiline area */
  39.         TEXTAREA_READONLY               = (1 << 2),     /**< Non-editable */
  40.         TEXTAREA_INTERNAL_CARET         = (1 << 3),     /**< Render own caret */
  41.         TEXTAREA_PASSWORD               = (1 << 4)      /**< Obscured display */
  42. } textarea_flags;
  43.  
  44. typedef enum {
  45.         TEXTAREA_DRAG_NONE,
  46.         TEXTAREA_DRAG_SCROLLBAR,
  47.         TEXTAREA_DRAG_SELECTION
  48. } textarea_drag_type;
  49.  
  50. typedef enum {
  51.         TEXTAREA_MSG_DRAG_REPORT,       /**< Textarea drag start/end report */
  52.         TEXTAREA_MSG_REDRAW_REQUEST,    /**< Textarea redraw request */
  53.         TEXTAREA_MSG_MOVED_CARET        /**< Textarea caret moved */
  54. } textarea_msg_type;
  55.  
  56. struct textarea_msg {
  57.         struct textarea *ta;
  58.  
  59.         textarea_msg_type type;
  60.         union {
  61.                 textarea_drag_type drag;
  62.                 struct rect redraw;
  63.                 struct {
  64.                         bool hidden;
  65.                         int x;
  66.                         int y;
  67.                         int height;
  68.                 } caret;
  69.         } data;
  70. };
  71.  
  72. typedef struct textarea_setup {
  73.         textarea_flags flags;   /**< Setup flags */
  74.  
  75.         int width;              /**< Textarea width */
  76.         int height;             /**< Textarea height */
  77.  
  78.         int pad_top;            /**< Textarea top padding */
  79.         int pad_right;          /**< Textarea right padding */
  80.         int pad_bottom;         /**< Textarea bottom padding */
  81.         int pad_left;           /**< Textarea left padding */
  82.  
  83.         int border_width;       /**< Textarea border width */
  84.         colour border_col;      /**< Textarea border colour */
  85.  
  86.         colour selected_text;   /**< Textarea selected text colour */
  87.         colour selected_bg;     /**< Textarea selection background colour */
  88.         plot_font_style_t text; /**< Textarea background colour and font */
  89.  
  90. } textarea_setup;
  91.  
  92. /**
  93.  * Client callback for the textarea
  94.  *
  95.  * \param data          user data passed at textarea creation
  96.  * \param textarea_msg  textarea message data
  97.  */
  98. typedef void(*textarea_client_callback)(void *data, struct textarea_msg *msg);
  99.  
  100. /**
  101.  * Create a text area
  102.  *
  103.  * \param setup textarea settings and style
  104.  * \param redraw_callback will be called when textarea wants to redraw
  105.  * \param data  user specified data which will be passed to callbacks
  106.  * \return Opaque handle for textarea or 0 on error
  107.  */
  108. struct textarea *textarea_create(const textarea_setup *setup,
  109.                 textarea_client_callback callback, void *data);
  110.  
  111. /**
  112.  * Destroy a text area
  113.  *
  114.  * \param ta Text area to destroy
  115.  */
  116. void textarea_destroy(struct textarea *ta);
  117.  
  118. /**
  119.  * Set the text in a text area, discarding any current text
  120.  *
  121.  * \param ta Text area
  122.  * \param text UTF-8 text to set text area's contents to
  123.  * \return true on success, false on memory exhaustion
  124.  */
  125. bool textarea_set_text(struct textarea *ta, const char *text);
  126.  
  127. /**
  128.  * Extract the text from a text area
  129.  *
  130.  * \param ta Text area
  131.  * \param buf Pointer to buffer to receive data, or NULL
  132.  *            to read length required
  133.  * \param len Length (bytes) of buffer pointed to by buf, or 0 to read length
  134.  * \return Length (bytes) written/required or -1 on error
  135.  */
  136. int textarea_get_text(struct textarea *ta, char *buf, unsigned int len);
  137.  
  138. /**
  139.  * Set the caret's position
  140.  *
  141.  * \param ta            Text area
  142.  * \param caret         0-based character index to place caret at, -1 removes
  143.  *                      the caret
  144.  * \return true on success false otherwise
  145.  */
  146. bool textarea_set_caret(struct textarea *ta, int caret);
  147.  
  148. /**
  149.  * Get the caret's position
  150.  *
  151.  * \param ta Text area
  152.  * \return 0-based character index of caret location, or -1 on error
  153.  */
  154. int textarea_get_caret(struct textarea *ta);
  155.  
  156. /**
  157.  * Handle redraw requests for text areas
  158.  *
  159.  * \param ta    textarea to render
  160.  * \param x     x coordinate of textarea top
  161.  * \param y     y coordinate of textarea left
  162.  * \param bg    background colour under textarea
  163.  * \param clip  clip rectangle
  164.  * \param ctx   current redraw context
  165.  */
  166. void textarea_redraw(struct textarea *ta, int x, int y, colour bg,
  167.                 const struct rect *clip, const struct redraw_context *ctx);
  168.  
  169. /**
  170.  * Key press handling for text areas.
  171.  *
  172.  * \param ta    The text area which got the keypress
  173.  * \param key   The ucs4 character codepoint
  174.  * \return      true if the keypress is dealt with, false otherwise.
  175.  */
  176. bool textarea_keypress(struct textarea *ta, uint32_t key);
  177.  
  178. /**
  179.  * Handles all kinds of mouse action
  180.  *
  181.  * \param ta    Text area
  182.  * \param mouse the mouse state at action moment
  183.  * \param x     X coordinate
  184.  * \param y     Y coordinate
  185.  * \return true if action was handled false otherwise
  186.  */
  187. bool textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse,
  188.                 int x, int y);
  189.  
  190. /**
  191.  * Gets the dimensions of a textarea
  192.  *
  193.  * \param width         if not NULL, gets updated to the width of the textarea
  194.  * \param height        if not NULL, gets updated to the height of the textarea
  195.  */
  196. void textarea_get_dimensions(struct textarea *ta, int *width, int *height);
  197.  
  198. /**
  199.  * Set the dimensions of a textarea, causing a reflow and
  200.  * emitting a redraw request.
  201.  *
  202.  * \param width         the new width of the textarea
  203.  * \param height        the new height of the textarea
  204.  */
  205. void textarea_set_dimensions(struct textarea *ta, int width, int height);
  206. #endif
  207.  
  208.