Merged revisions 7764-7977,7979-8058 via svnmerge from

svn://svn.netsurf-browser.org/branches/paulblokus/textinput

........
  r7769 | paulblokus | 2009-06-11 22:26:16 +0100 (Thu, 11 Jun 2009) | 4 lines
  
  replace global history window with an empty window for future tests
  add the necessary files
  first lines ported
........
  r7771 | paulblokus | 2009-06-11 23:51:46 +0100 (Thu, 11 Jun 2009) | 1 line
  
  more functions
........
  r7772 | paulblokus | 2009-06-12 02:07:36 +0100 (Fri, 12 Jun 2009) | 1 line
  
  redraw working
........
  r7777 | paulblokus | 2009-06-12 11:35:45 +0100 (Fri, 12 Jun 2009) | 3 lines
  
  plotter fix
  make use of the provided clipping rectangle
........
  r7781 | paulblokus | 2009-06-12 16:26:51 +0100 (Fri, 12 Jun 2009) | 3 lines
  
  callbacks for taxtarea to request a [caret]redraw
  basic caret handling drawing
........
  r7782 | paulblokus | 2009-06-12 22:36:50 +0100 (Fri, 12 Jun 2009) | 1 line
  
  single character insertion
........
  r7783 | paulblokus | 2009-06-12 22:41:37 +0100 (Fri, 12 Jun 2009) | 1 line
  
  single character insertion
........
  r7784 | paulblokus | 2009-06-12 23:55:40 +0100 (Fri, 12 Jun 2009) | 3 lines
  
  fixed caret clipping
  arrows, delete and backspace
........
  r7812 | paulblokus | 2009-06-16 14:55:41 +0100 (Tue, 16 Jun 2009) | 1 line
  
  remove bug causing NS hang on \n in textarea
........
  r7816 | paulblokus | 2009-06-16 16:29:48 +0100 (Tue, 16 Jun 2009) | 1 line
  
  Enter, Home, End keys
........
  r7817 | paulblokus | 2009-06-16 16:56:16 +0100 (Tue, 16 Jun 2009) | 1 line
  
  Ctrl + Home/End
........
  r7818 | paulblokus | 2009-06-16 17:16:51 +0100 (Tue, 16 Jun 2009) | 1 line
  
  redraw caret only on caret moves
........
  r7821 | paulblokus | 2009-06-16 20:18:30 +0100 (Tue, 16 Jun 2009) | 1 line
  
  line end/start delete
........
  r7822 | paulblokus | 2009-06-16 23:43:42 +0100 (Tue, 16 Jun 2009) | 1 line
  
  selection drawing + select all
........
  r7823 | paulblokus | 2009-06-17 02:31:07 +0100 (Wed, 17 Jun 2009) | 3 lines
  
  auto scrolling on caret moves
  clear selection
........
  r7845 | paulblokus | 2009-06-18 17:35:03 +0100 (Thu, 18 Jun 2009) | 1 line
  
  page up/down
........
  r7846 | paulblokus | 2009-06-18 17:38:45 +0100 (Thu, 18 Jun 2009) | 1 line
  
   remove unnecessary fix
........
  r7847 | paulblokus | 2009-06-18 18:00:16 +0100 (Thu, 18 Jun 2009) | 1 line
  
  clipping fixes
........
  r7849 | paulblokus | 2009-06-18 18:21:02 +0100 (Thu, 18 Jun 2009) | 1 line
  
  scroll fix
........
  r7850 | paulblokus | 2009-06-18 18:45:13 +0100 (Thu, 18 Jun 2009) | 1 line
  
  simplified redraw request logic
........
  r7855 | paulblokus | 2009-06-18 19:56:24 +0100 (Thu, 18 Jun 2009) | 1 line
  
  front end passing mouse events
........
  r7858 | paulblokus | 2009-06-18 22:18:39 +0100 (Thu, 18 Jun 2009) | 3 lines
  
  drag selection
  bug fixes
........
  r7860 | paulblokus | 2009-06-18 23:32:39 +0100 (Thu, 18 Jun 2009) | 3 lines
  
  take selection into account on keypress of different types
  a few bugs fixed
........
  r7876 | paulblokus | 2009-06-19 13:43:07 +0100 (Fri, 19 Jun 2009) | 3 lines
  
  pango nsfont_split fix
  a few textarea fixes
........
  r7879 | paulblokus | 2009-06-19 17:33:10 +0100 (Fri, 19 Jun 2009) | 4 lines
  
  newline handling seems to work this way
  clear selection on mouse click
  more bug fixes
........
  r7880 | paulblokus | 2009-06-19 18:16:27 +0100 (Fri, 19 Jun 2009) | 3 lines
  
  no caret option
  selection follows drag
........
  r7883 | paulblokus | 2009-06-19 19:08:44 +0100 (Fri, 19 Jun 2009) | 3 lines
  
  o width selection bug fix
  caret at correct side of drag selection
........
  r7918 | paulblokus | 2009-06-22 21:01:28 +0100 (Mon, 22 Jun 2009) | 3 lines
  
  fix caret positioning at line end
  CR removal in input methods
........
  r7919 | paulblokus | 2009-06-22 21:34:39 +0100 (Mon, 22 Jun 2009) | 1 line
  
  fix crash on 0 length text
........
  r7926 | paulblokus | 2009-06-23 09:53:56 +0100 (Tue, 23 Jun 2009) | 3 lines
  
  change LF into spaces for single line widget
  text normalisation at one place
........
  r7931 | paulblokus | 2009-06-23 10:51:25 +0100 (Tue, 23 Jun 2009) | 1 line
  
  cleanup
........
  r7933 | paulblokus | 2009-06-23 11:17:22 +0100 (Tue, 23 Jun 2009) | 1 line
  
  fix selection draw
........
  r7935 | paulblokus | 2009-06-23 11:41:30 +0100 (Tue, 23 Jun 2009) | 1 line
  
  guard readonly
........
  r7942 | paulblokus | 2009-06-24 08:19:39 +0100 (Wed, 24 Jun 2009) | 1 line
  
  applied changes suggested by jmb
........
  r7943 | paulblokus | 2009-06-24 09:04:49 +0100 (Wed, 24 Jun 2009) | 1 line
  
  little fixes
........
  r7945 | paulblokus | 2009-06-24 12:50:14 +0100 (Wed, 24 Jun 2009) | 1 line
  
  correct line length and wrapping
........
  r7947 | paulblokus | 2009-06-24 14:32:36 +0100 (Wed, 24 Jun 2009) | 3 lines
  
  fixed page up/down broken in last commit
  changed logic for caret positioning on soft breaks
........
  r7949 | paulblokus | 2009-06-24 16:31:42 +0100 (Wed, 24 Jun 2009) | 1 line
  
  remove temporary/test code
........
  r7975 | paulblokus | 2009-06-25 16:00:46 +0100 (Thu, 25 Jun 2009) | 1 line
  
  changes suggested by jmb
........
  r7976 | paulblokus | 2009-06-25 16:33:23 +0100 (Thu, 25 Jun 2009) | 1 line
  
  added ro_ prefix to RISC OS textarea code
........

svn path=/trunk/netsurf/; revision=8060
This commit is contained in:
John Mark Bell 2009-06-27 13:59:25 +00:00
parent fa99a7a3ce
commit ca96353d9f
14 changed files with 1622 additions and 142 deletions

View File

@ -13,7 +13,7 @@ S_RENDER := box.c box_construct.c box_normalise.c directory.c \
layout.c list.c loosen.c table.c textplain.c
S_UTILS := base64.c filename.c hashtable.c locale.c messages.c talloc.c \
url.c utf8.c utils.c useragent.c
S_DESKTOP := knockout.c options.c print.c tree.c version.c
S_DESKTOP := knockout.c options.c print.c tree.c version.c textarea.c
# S_COMMON are sources common to all builds
S_COMMON := $(addprefix content/,$(S_CONTENT)) \

View File

@ -191,21 +191,24 @@ typedef enum {
* a drag. */
BROWSER_MOUSE_CLICK_1 = 4, /* button 1 clicked. */
BROWSER_MOUSE_CLICK_2 = 8, /* button 2 clicked. */
BROWSER_MOUSE_DOUBLE_CLICK = 16, /* button 1 double clicked */
BROWSER_MOUSE_DRAG_1 = 16, /* start of button 1 drag operation */
BROWSER_MOUSE_DRAG_2 = 32, /* start of button 2 drag operation */
BROWSER_MOUSE_DRAG_1 = 32, /* start of button 1 drag operation */
BROWSER_MOUSE_DRAG_2 = 64, /* start of button 2 drag operation */
BROWSER_MOUSE_DRAG_ON = 64, /* a drag operation was started and
BROWSER_MOUSE_DRAG_ON = 128, /* a drag operation was started and
* a mouse button is still pressed */
BROWSER_MOUSE_HOLDING_1 = 128, /* while button 1 drag is in progress */
BROWSER_MOUSE_HOLDING_2 = 256, /* while button 2 drag is in progress */
BROWSER_MOUSE_HOLDING_1 = 256, /* while button 1 drag is in progress */
BROWSER_MOUSE_HOLDING_2 = 512, /* while button 2 drag is in progress */
BROWSER_MOUSE_MOD_1 = 512, /* primary modifier key pressed
BROWSER_MOUSE_MOD_1 = 1024, /* primary modifier key pressed
* (eg. Shift) */
BROWSER_MOUSE_MOD_2 = 1024 /* secondary modifier key pressed
BROWSER_MOUSE_MOD_2 = 2048, /* secondary modifier key pressed
* (eg. Ctrl) */
BROWSER_MOUSE_MOD_3 = 4096 /* secondary modifier key pressed
* (eg. Alt) */
} browser_mouse_state;

1379
desktop/textarea.c Normal file

File diff suppressed because it is too large Load Diff

58
desktop/textarea.h Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright 2006 John-Mark Bell <jmb@netsurf-browser.org>
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Single/Multi-line UTF-8 text area (interface)
*/
#ifndef _NETSURF_DESKTOP_TEXTAREA_H_
#define _NETSURF_DESKTOP_TEXTAREA_H_
#include <stdint.h>
#include <stdbool.h>
#include "css/css.h"
#include "desktop/browser.h"
/* Text area flags */
#define TEXTAREA_MULTILINE 0x01 /**< Text area is multiline */
#define TEXTAREA_READONLY 0x02 /**< Text area is read only */
struct text_area;
typedef void(*textarea_start_redraw_callback)(void *data);
typedef void(*textarea_end_redraw_callback)(void *data);
struct text_area *textarea_create(int x, int y, int width, int height,
unsigned int flags, const struct css_style *style,
textarea_start_redraw_callback redraw_start_callback,
textarea_end_redraw_callback redraw_end_callback, void *data);
void textarea_destroy(struct text_area *ta);
bool textarea_set_text(struct text_area *ta, const char *text);
int textarea_get_text(struct text_area *ta, char *buf, unsigned int len);
bool textarea_set_caret(struct text_area *ta, int caret);
int textarea_get_caret(struct text_area *ta);
void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1);
bool textarea_keypress(struct text_area *ta, uint32_t key);
bool textarea_mouse_action(struct text_area *ta, browser_mouse_state mouse,
int x, int y);
bool textarea_drag_end(struct text_area *ta, browser_mouse_state mouse,
int x, int y);
#endif

View File

@ -28,6 +28,7 @@
#include <stdbool.h>
struct browser_window;
struct box;

View File

@ -183,6 +183,7 @@ bool nsfont_split(const struct css_style *style,
pango_layout_set_width(layout, x * PANGO_SCALE);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
pango_layout_set_single_paragraph_mode(layout, true);
line = pango_layout_get_line(layout, 1);
if (line)
index = line->start_index - 1;

View File

@ -43,6 +43,7 @@
#include "desktop/netsurf.h"
#include "desktop/options.h"
#include "desktop/save_pdf/pdf_plotters.h"
#include "desktop/textinput.h"
#include "gtk/gtk_gui.h"
#include "gtk/dialogs/gtk_options.h"
#include "gtk/gtk_completion.h"
@ -734,3 +735,72 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data)
}
#endif
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key)
{
/* this function will need to become much more complex to support
* everything that the RISC OS version does. But this will do for
* now. I hope.
*/
switch (key->keyval)
{
case GDK_BackSpace:
if (key->state & GDK_SHIFT_MASK)
return KEY_DELETE_LINE_START;
else
return KEY_DELETE_LEFT;
case GDK_Delete:
if (key->state & GDK_SHIFT_MASK)
return KEY_DELETE_LINE_END;
else
return KEY_DELETE_RIGHT;
case GDK_Linefeed: return 13;
case GDK_Return: return 10;
case GDK_Left: return KEY_LEFT;
case GDK_Right: return KEY_RIGHT;
case GDK_Up: return KEY_UP;
case GDK_Down: return KEY_DOWN;
case GDK_Home:
if (key->state & GDK_CONTROL_MASK)
return KEY_TEXT_START;
else
return KEY_LINE_START;
case GDK_End:
if (key->state & GDK_CONTROL_MASK)
return KEY_TEXT_END;
else
return KEY_LINE_END;
case GDK_Page_Up:
return KEY_PAGE_UP;
case GDK_Page_Down:
return KEY_PAGE_DOWN;
case 'a':
if (key->state & GDK_CONTROL_MASK)
return KEY_SELECT_ALL;
return gdk_keyval_to_unicode(key->keyval);
case 'u':
if (key->state & GDK_CONTROL_MASK)
return KEY_CLEAR_SELECTION;
return gdk_keyval_to_unicode(key->keyval);
case GDK_Escape:
return KEY_ESCAPE;
/* Modifiers - do nothing for now */
case GDK_Shift_L:
case GDK_Shift_R:
case GDK_Control_L:
case GDK_Control_R:
case GDK_Caps_Lock:
case GDK_Shift_Lock:
case GDK_Meta_L:
case GDK_Meta_R:
case GDK_Alt_L:
case GDK_Alt_R:
case GDK_Super_L:
case GDK_Super_R:
case GDK_Hyper_L:
case GDK_Hyper_R: return 0;
default: return gdk_keyval_to_unicode(
key->keyval);
}
}

View File

@ -19,6 +19,7 @@
#ifndef GTK_GUI_H
#define GTK_GUI_H
#include <inttypes.h>
#include <stdbool.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
@ -37,5 +38,7 @@ extern GtkLabel *labelTooltip;
extern GtkDialog *wndOpenFile;
uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *);
#endif /* GTK_GUI_H */

View File

@ -119,7 +119,7 @@ bool nsgtk_plot_rectangle(int x0, int y0, int width, int height,
line_width = 1;
cairo_set_line_width(current_cr, line_width);
cairo_rectangle(current_cr, x0, y0, width, height);
cairo_rectangle(current_cr, x0 + 0.5, y0 + 0.5, width, height);
cairo_stroke(current_cr);
return true;

View File

@ -38,7 +38,7 @@
struct gui_window *window_list = 0; /**< first entry in win list*/
int temp_open_background = -1;
static uint32_t gdkkey_to_nskey(GdkEventKey *);
static void nsgtk_gui_window_attach_child(struct gui_window *parent,
struct gui_window *child);
/* Methods which apply only to a gui_window */
@ -449,50 +449,11 @@ gboolean nsgtk_window_button_release_event(GtkWidget *widget,
return TRUE;
}
uint32_t gdkkey_to_nskey(GdkEventKey *key)
{
/* this function will need to become much more complex to support
* everything that the RISC OS version does. But this will do for
* now. I hope.
*/
switch (key->keyval)
{
case GDK_BackSpace: return KEY_DELETE_LEFT;
case GDK_Delete: return KEY_DELETE_RIGHT;
case GDK_Linefeed: return 13;
case GDK_Return: return 10;
case GDK_Left: return KEY_LEFT;
case GDK_Right: return KEY_RIGHT;
case GDK_Up: return KEY_UP;
case GDK_Down: return KEY_DOWN;
/* Modifiers - do nothing for now */
case GDK_Shift_L:
case GDK_Shift_R:
case GDK_Control_L:
case GDK_Control_R:
case GDK_Caps_Lock:
case GDK_Shift_Lock:
case GDK_Meta_L:
case GDK_Meta_R:
case GDK_Alt_L:
case GDK_Alt_R:
case GDK_Super_L:
case GDK_Super_R:
case GDK_Hyper_L:
case GDK_Hyper_R: return 0;
default: return gdk_keyval_to_unicode(
key->keyval);
}
}
gboolean nsgtk_window_keypress_event(GtkWidget *widget, GdkEventKey *event,
gpointer data)
{
struct gui_window *g = data;
uint32_t nskey = gdkkey_to_nskey(event);
uint32_t nskey = gtk_gui_gdkkey_to_nskey(event);
if (browser_window_key_press(g->bw, nskey))
return TRUE;

View File

@ -338,8 +338,8 @@ void ro_gui_cert_open(struct tree *tree, struct node *node)
return;
}
if (session->issuer)
textarea_destroy(session->issuer);
session->issuer = textarea_create(w, ICON_CERT_ISSUER,
ro_textarea_destroy(session->issuer);
session->issuer = ro_textarea_create(w, ICON_CERT_ISSUER,
TEXTAREA_MULTILINE | TEXTAREA_READONLY,
ro_gui_desktop_font_family, ro_gui_desktop_font_size,
ro_gui_desktop_font_style);
@ -348,28 +348,28 @@ void ro_gui_cert_open(struct tree *tree, struct node *node)
warn_user("NoMemory", 0);
return;
}
if (!textarea_set_text(session->issuer, session->issuer_t)) {
textarea_destroy(session->issuer);
if (!ro_textarea_set_text(session->issuer, session->issuer_t)) {
ro_textarea_destroy(session->issuer);
xwimp_delete_window(w);
warn_user("NoMemory", 0);
return;
}
if (session->subject)
textarea_destroy(session->subject);
session->subject = textarea_create(w, ICON_CERT_SUBJECT,
ro_textarea_destroy(session->subject);
session->subject = ro_textarea_create(w, ICON_CERT_SUBJECT,
TEXTAREA_MULTILINE | TEXTAREA_READONLY,
ro_gui_desktop_font_family, ro_gui_desktop_font_size,
ro_gui_desktop_font_style);
if (!session->subject) {
textarea_destroy(session->issuer);
ro_textarea_destroy(session->issuer);
xwimp_delete_window(w);
warn_user("NoMemory", 0);
return;
}
if (!textarea_set_text(session->subject, session->subject_t)) {
textarea_destroy(session->subject);
textarea_destroy(session->issuer);
if (!ro_textarea_set_text(session->subject, session->subject_t)) {
ro_textarea_destroy(session->subject);
ro_textarea_destroy(session->issuer);
xwimp_delete_window(w);
warn_user("NoMemory", 0);
return;
@ -392,9 +392,9 @@ void ro_gui_cert_close(wimp_w w)
for (i = 0; i < data->num; i++) {
if (data->certs[i].subject)
textarea_destroy(data->certs[i].subject);
ro_textarea_destroy(data->certs[i].subject);
if (data->certs[i].issuer)
textarea_destroy(data->certs[i].issuer);
ro_textarea_destroy(data->certs[i].issuer);
}
free(data->certs);
free(data->url);

View File

@ -110,12 +110,12 @@ static wimp_window text_area_definition = {
{}
};
static void textarea_reflow(struct text_area *ta, unsigned int line);
static bool textarea_mouse_click(wimp_pointer *pointer);
static bool textarea_key_press(wimp_key *key);
static void textarea_redraw(wimp_draw *redraw);
static void textarea_redraw_internal(wimp_draw *redraw, bool update);
static void textarea_open(wimp_open *open);
static void ro_textarea_reflow(struct text_area *ta, unsigned int line);
static bool ro_textarea_mouse_click(wimp_pointer *pointer);
static bool ro_textarea_key_press(wimp_key *key);
static void ro_textarea_redraw(wimp_draw *redraw);
static void ro_textarea_redraw_internal(wimp_draw *redraw, bool update);
static void ro_textarea_open(wimp_open *open);
/**
* Create a text area
@ -128,7 +128,7 @@ static void textarea_open(wimp_open *open);
* \param font_style Font style to use, or 0 for default
* \return Opaque handle for textarea or 0 on error
*/
uintptr_t textarea_create(wimp_w parent, wimp_i icon, unsigned int flags,
uintptr_t ro_textarea_create(wimp_w parent, wimp_i icon, unsigned int flags,
const char *font_family, unsigned int font_size,
rufl_style font_style)
{
@ -189,21 +189,21 @@ uintptr_t textarea_create(wimp_w parent, wimp_i icon, unsigned int flags,
}
/* set the window dimensions */
if (!textarea_update((uintptr_t)ret)) {
textarea_destroy((uintptr_t)ret);
if (!ro_textarea_update((uintptr_t)ret)) {
ro_textarea_destroy((uintptr_t)ret);
return 0;
}
/* and register our event handlers */
ro_gui_wimp_event_set_user_data(ret->window, ret);
ro_gui_wimp_event_register_mouse_click(ret->window,
textarea_mouse_click);
ro_textarea_mouse_click);
ro_gui_wimp_event_register_keypress(ret->window,
textarea_key_press);
ro_textarea_key_press);
ro_gui_wimp_event_register_redraw_window(ret->window,
textarea_redraw);
ro_textarea_redraw);
ro_gui_wimp_event_register_open_window(ret->window,
textarea_open);
ro_textarea_open);
return (uintptr_t)ret;
}
@ -213,7 +213,7 @@ uintptr_t textarea_create(wimp_w parent, wimp_i icon, unsigned int flags,
*
* \param self Text area to update
*/
bool textarea_update(uintptr_t self)
bool ro_textarea_update(uintptr_t self)
{
struct text_area *ta;
wimp_window_state state;
@ -291,7 +291,7 @@ bool textarea_update(uintptr_t self)
}
/* reflow the text */
textarea_reflow(ta, 0);
ro_textarea_reflow(ta, 0);
return true;
}
@ -300,7 +300,7 @@ bool textarea_update(uintptr_t self)
*
* \param self Text area to destroy
*/
void textarea_destroy(uintptr_t self)
void ro_textarea_destroy(uintptr_t self)
{
struct text_area *ta;
os_error *error;
@ -329,7 +329,7 @@ void textarea_destroy(uintptr_t self)
* \param text UTF-8 text to set text area's contents to
* \return true on success, false on memory exhaustion
*/
bool textarea_set_text(uintptr_t self, const char *text)
bool ro_textarea_set_text(uintptr_t self, const char *text)
{
struct text_area *ta;
unsigned int len = strlen(text) + 1;
@ -353,7 +353,7 @@ bool textarea_set_text(uintptr_t self, const char *text)
memcpy(ta->text, text, len);
ta->text_len = len;
textarea_reflow(ta, 0);
ro_textarea_reflow(ta, 0);
return true;
}
@ -367,7 +367,7 @@ bool textarea_set_text(uintptr_t self, const char *text)
* \param len Length (bytes) of buffer pointed to by buf, or 0 to read length
* \return Length (bytes) written/required or -1 on error
*/
int textarea_get_text(uintptr_t self, char *buf, unsigned int len)
int ro_textarea_get_text(uintptr_t self, char *buf, unsigned int len)
{
struct text_area *ta;
@ -399,7 +399,7 @@ int textarea_get_text(uintptr_t self, char *buf, unsigned int len)
* \param index 0-based character index to insert at
* \param text UTF-8 text to insert
*/
void textarea_insert_text(uintptr_t self, unsigned int index,
void ro_textarea_insert_text(uintptr_t self, unsigned int index,
const char *text)
{
struct text_area *ta;
@ -442,7 +442,7 @@ void textarea_insert_text(uintptr_t self, unsigned int index,
ta->text_len += b_len;
/** \todo calculate line to reflow from */
textarea_reflow(ta, 0);
ro_textarea_reflow(ta, 0);
}
/**
@ -453,7 +453,7 @@ void textarea_insert_text(uintptr_t self, unsigned int index,
* \param end End character index of replaced section (exclusive)
* \param text UTF-8 text to insert
*/
void textarea_replace_text(uintptr_t self, unsigned int start,
void ro_textarea_replace_text(uintptr_t self, unsigned int start,
unsigned int end, const char *text)
{
struct text_area *ta;
@ -474,7 +474,7 @@ void textarea_replace_text(uintptr_t self, unsigned int start,
end = c_len;
if (start == end)
return textarea_insert_text(self, start, text);
return ro_textarea_insert_text(self, start, text);
if (start > end) {
int temp = end;
@ -515,7 +515,7 @@ void textarea_replace_text(uintptr_t self, unsigned int start,
ta->text_len += b_len - (b_end - b_start);
/** \todo calculate line to reflow from */
textarea_reflow(ta, 0);
ro_textarea_reflow(ta, 0);
}
/**
@ -524,7 +524,7 @@ void textarea_replace_text(uintptr_t self, unsigned int start,
* \param self Text area
* \param caret 0-based character index to place caret at
*/
void textarea_set_caret(uintptr_t self, unsigned int caret)
void ro_textarea_set_caret(uintptr_t self, unsigned int caret)
{
struct text_area *ta;
size_t c_len, b_off;
@ -566,7 +566,7 @@ void textarea_set_caret(uintptr_t self, unsigned int caret)
/* Finally, redraw the WIMP caret */
index = textarea_get_caret(self);
index = ro_textarea_get_caret(self);
os_line_height.x = 0;
os_line_height.y = (int)((float)(ta->line_height - ta->line_spacing) * 0.62) + 1;
ro_convert_pixels_to_os_units(&os_line_height, (os_mode)-1);
@ -605,7 +605,7 @@ void textarea_set_caret(uintptr_t self, unsigned int caret)
* \param x X position of caret on the screen
* \param y Y position of caret on the screen
*/
void textarea_set_caret_xy(uintptr_t self, int x, int y)
void ro_textarea_set_caret_xy(uintptr_t self, int x, int y)
{
struct text_area *ta;
wimp_window_state state;
@ -665,7 +665,7 @@ void textarea_set_caret_xy(uintptr_t self, int x, int y)
temp = utf8_next(ta->text, ta->text_len, temp))
c_off++;
textarea_set_caret((uintptr_t)ta, c_off);
ro_textarea_set_caret((uintptr_t)ta, c_off);
}
/**
@ -674,7 +674,7 @@ void textarea_set_caret_xy(uintptr_t self, int x, int y)
* \param self Text area
* \return 0-based character index of caret location, or -1 on error
*/
unsigned int textarea_get_caret(uintptr_t self)
unsigned int ro_textarea_get_caret(uintptr_t self)
{
struct text_area *ta;
size_t c_off = 0, b_off;
@ -701,7 +701,7 @@ unsigned int textarea_get_caret(uintptr_t self)
* \param ta Text area to reflow
* \param line Line number to begin reflow on
*/
void textarea_reflow(struct text_area *ta, unsigned int line)
void ro_textarea_reflow(struct text_area *ta, unsigned int line)
{
rufl_code code;
char *text;
@ -846,7 +846,8 @@ void textarea_reflow(struct text_area *ta, unsigned int line)
}
/* Now, attempt to create vertical scrollbar */
ro_gui_wimp_update_window_furniture(ta->window, wimp_WINDOW_VSCROLL,
ro_gui_wimp_update_window_furniture(ta->window,
wimp_WINDOW_VSCROLL,
wimp_WINDOW_VSCROLL);
/* Get new window state */
@ -877,7 +878,7 @@ void textarea_reflow(struct text_area *ta, unsigned int line)
ta->vis_width -= vscroll_width;
/* Now we've done that, we have to reflow the text area */
textarea_reflow(ta, 0);
ro_textarea_reflow(ta, 0);
}
}
@ -887,13 +888,13 @@ void textarea_reflow(struct text_area *ta, unsigned int line)
* \param pointer Mouse click state block
* \return true if click handled, false otherwise
*/
bool textarea_mouse_click(wimp_pointer *pointer)
bool ro_textarea_mouse_click(wimp_pointer *pointer)
{
struct text_area *ta;
ta = (struct text_area *)ro_gui_wimp_event_get_user_data(pointer->w);
textarea_set_caret_xy((uintptr_t)ta, pointer->pos.x, pointer->pos.y);
ro_textarea_set_caret_xy((uintptr_t)ta, pointer->pos.x, pointer->pos.y);
return true;
}
@ -903,7 +904,7 @@ bool textarea_mouse_click(wimp_pointer *pointer)
* \param key Key pressed state block
* \param true if press handled, false otherwise
*/
bool textarea_key_press(wimp_key *key)
bool ro_textarea_key_press(wimp_key *key)
{
uint32_t c = (uint32_t) key->c;
wimp_key keypress;
@ -925,49 +926,49 @@ bool textarea_key_press(wimp_key *key)
utf8_len = utf8_from_ucs4(c, utf8);
utf8[utf8_len] = '\0';
c_pos = textarea_get_caret((uintptr_t)ta);
textarea_insert_text((uintptr_t)ta, c_pos, utf8);
textarea_set_caret((uintptr_t)ta, ++c_pos);
c_pos = ro_textarea_get_caret((uintptr_t)ta);
ro_textarea_insert_text((uintptr_t)ta, c_pos, utf8);
ro_textarea_set_caret((uintptr_t)ta, ++c_pos);
redraw = true;
} else {
/** \todo handle command keys */
switch (c & ~IS_WIMP_KEY) {
case 8: /* Backspace */
c_pos = textarea_get_caret((uintptr_t)ta);
c_pos = ro_textarea_get_caret((uintptr_t)ta);
if (c_pos > 0) {
textarea_replace_text((uintptr_t)ta,
ro_textarea_replace_text((uintptr_t)ta,
c_pos - 1, c_pos, "");
textarea_set_caret((uintptr_t)ta, c_pos - 1);
ro_textarea_set_caret((uintptr_t)ta, c_pos - 1);
redraw = true;
}
break;
case 21: /* Ctrl + U */
textarea_set_text((uintptr_t)ta, "");
textarea_set_caret((uintptr_t)ta, 0);
ro_textarea_set_text((uintptr_t)ta, "");
ro_textarea_set_caret((uintptr_t)ta, 0);
redraw = true;
break;
case wimp_KEY_DELETE:
c_pos = textarea_get_caret((uintptr_t)ta);
c_pos = ro_textarea_get_caret((uintptr_t)ta);
if (os_version < RISCOS5 && c_pos > 0) {
textarea_replace_text((uintptr_t)ta,
ro_textarea_replace_text((uintptr_t)ta,
c_pos - 1, c_pos, "");
textarea_set_caret((uintptr_t)ta, c_pos - 1);
ro_textarea_set_caret((uintptr_t)ta, c_pos - 1);
} else {
textarea_replace_text((uintptr_t)ta, c_pos,
ro_textarea_replace_text((uintptr_t)ta, c_pos,
c_pos + 1, "");
}
redraw = true;
break;
case wimp_KEY_LEFT:
c_pos = textarea_get_caret((uintptr_t)ta);
c_pos = ro_textarea_get_caret((uintptr_t)ta);
if (c_pos > 0)
textarea_set_caret((uintptr_t)ta, c_pos - 1);
ro_textarea_set_caret((uintptr_t)ta, c_pos - 1);
break;
case wimp_KEY_RIGHT:
c_pos = textarea_get_caret((uintptr_t)ta);
textarea_set_caret((uintptr_t)ta, c_pos + 1);
c_pos = ro_textarea_get_caret((uintptr_t)ta);
ro_textarea_set_caret((uintptr_t)ta, c_pos + 1);
break;
case wimp_KEY_UP:
/** \todo Move caret up a line */
@ -984,16 +985,17 @@ bool textarea_key_press(wimp_key *key)
/** \todo line end */
break;
case wimp_KEY_CONTROL | wimp_KEY_UP:
textarea_set_caret((uintptr_t)ta, 0);
ro_textarea_set_caret((uintptr_t)ta, 0);
break;
case wimp_KEY_CONTROL | wimp_KEY_DOWN:
textarea_set_caret((uintptr_t)ta, utf8_length(ta->text));
ro_textarea_set_caret((uintptr_t)ta,
utf8_length(ta->text));
break;
case wimp_KEY_COPY:
if (os_version < RISCOS5) {
c_pos = textarea_get_caret((uintptr_t)ta);
textarea_replace_text((uintptr_t)ta, c_pos,
c_pos = ro_textarea_get_caret((uintptr_t)ta);
ro_textarea_replace_text((uintptr_t)ta, c_pos,
c_pos + 1, "");
} else {
/** \todo line end */
@ -1004,10 +1006,10 @@ bool textarea_key_press(wimp_key *key)
case wimp_KEY_RETURN:
if (ta->flags & TEXTAREA_MULTILINE) {
/* Insert newline */
c_pos = textarea_get_caret((uintptr_t)ta);
textarea_insert_text((uintptr_t)ta, c_pos,
c_pos = ro_textarea_get_caret((uintptr_t)ta);
ro_textarea_insert_text((uintptr_t)ta, c_pos,
"\n");
textarea_set_caret((uintptr_t)ta, ++c_pos);
ro_textarea_set_caret((uintptr_t)ta, ++c_pos);
redraw = true;
@ -1038,7 +1040,7 @@ bool textarea_key_press(wimp_key *key)
update.box.y1 = 0;
update.box.x1 = ta->vis_width;
update.box.y0 = -ta->line_height * (ta->line_count + 1);
textarea_redraw_internal(&update, true);
ro_textarea_redraw_internal(&update, true);
}
return true;
@ -1049,9 +1051,9 @@ bool textarea_key_press(wimp_key *key)
*
* \param redraw Redraw request block
*/
void textarea_redraw(wimp_draw *redraw)
void ro_textarea_redraw(wimp_draw *redraw)
{
textarea_redraw_internal(redraw, false);
ro_textarea_redraw_internal(redraw, false);
}
/**
@ -1060,7 +1062,7 @@ void textarea_redraw(wimp_draw *redraw)
* \param redraw Redraw/update request block
* \param update True if update, false if full redraw
*/
void textarea_redraw_internal(wimp_draw *redraw, bool update)
void ro_textarea_redraw_internal(wimp_draw *redraw, bool update)
{
struct text_area *ta;
int clip_x0, clip_y0, clip_x1, clip_y1;
@ -1170,7 +1172,7 @@ void textarea_redraw_internal(wimp_draw *redraw, bool update)
*
* \param open OpenWindow block
*/
void textarea_open(wimp_open *open)
void ro_textarea_open(wimp_open *open)
{
os_error *error;

View File

@ -31,20 +31,20 @@
#define TEXTAREA_MULTILINE 0x01 /**< Text area is multiline */
#define TEXTAREA_READONLY 0x02 /**< Text area is read only */
uintptr_t textarea_create(wimp_w parent, wimp_i icon, unsigned int flags,
uintptr_t ro_textarea_create(wimp_w parent, wimp_i icon, unsigned int flags,
const char *font_family, unsigned int font_size,
rufl_style font_style);
bool textarea_update(uintptr_t self);
void textarea_destroy(uintptr_t self);
bool textarea_set_text(uintptr_t self, const char *text);
int textarea_get_text(uintptr_t self, char *buf, unsigned int len);
void textarea_insert_text(uintptr_t self, unsigned int index,
bool ro_textarea_update(uintptr_t self);
void ro_textarea_destroy(uintptr_t self);
bool ro_textarea_set_text(uintptr_t self, const char *text);
int ro_textarea_get_text(uintptr_t self, char *buf, unsigned int len);
void ro_textarea_insert_text(uintptr_t self, unsigned int index,
const char *text);
void textarea_replace_text(uintptr_t self, unsigned int start,
void ro_textarea_replace_text(uintptr_t self, unsigned int start,
unsigned int end, const char *text);
void textarea_set_caret(uintptr_t self, unsigned int caret);
void textarea_set_caret_xy(uintptr_t self, int x, int y);
unsigned int textarea_get_caret(uintptr_t self);
void ro_textarea_set_caret(uintptr_t self, unsigned int caret);
void ro_textarea_set_caret_xy(uintptr_t self, int x, int y);
unsigned int ro_textarea_get_caret(uintptr_t self);
#endif

View File

@ -1080,7 +1080,7 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element,
LOG(("xwimp_create_icon: 0x%x: %s",
error->errnum, error->errmess));
tree->textarea_handle = textarea_create((wimp_w)tree->handle,
tree->textarea_handle = ro_textarea_create((wimp_w)tree->handle,
(wimp_i)tree->edit_handle, 0, ro_gui_desktop_font_family,
ro_gui_desktop_font_size,
ro_gui_desktop_font_style);
@ -1088,12 +1088,13 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element,
ro_gui_tree_stop_edit(tree);
return;
}
textarea_set_text(tree->textarea_handle, element->text);
ro_textarea_set_text(tree->textarea_handle, element->text);
if (pointer)
textarea_set_caret_xy(tree->textarea_handle,
ro_textarea_set_caret_xy(tree->textarea_handle,
pointer->pos.x, pointer->pos.y);
else
textarea_set_caret(tree->textarea_handle, strlen(element->text));
ro_textarea_set_caret(tree->textarea_handle,
strlen(element->text));
tree_handle_node_element_changed(tree, element);
ro_gui_tree_scroll_visible(tree, element);
@ -1114,7 +1115,7 @@ void ro_gui_tree_stop_edit(struct tree *tree)
if (!tree->editing) return;
if (tree->textarea_handle) {
textarea_destroy(tree->textarea_handle);
ro_textarea_destroy(tree->textarea_handle);
tree->textarea_handle = 0;
}
error = xwimp_delete_icon((wimp_w)tree->handle, (wimp_i)tree->edit_handle);
@ -1308,7 +1309,8 @@ bool ro_gui_tree_keypress(wimp_key *key)
return true;
case wimp_KEY_RETURN:
if ((tree->editing) && (tree->textarea_handle)) {
strlen = textarea_get_text(tree->textarea_handle,
strlen = ro_textarea_get_text(
tree->textarea_handle,
NULL, 0);
if (strlen == -1) {
ro_gui_tree_stop_edit(tree);
@ -1321,7 +1323,7 @@ bool ro_gui_tree_keypress(wimp_key *key)
warn_user("NoMemory", 0);
return true;
}
textarea_get_text(tree->textarea_handle,
ro_textarea_get_text(tree->textarea_handle,
new_string, strlen);
free((void *)tree->editing->text);
tree->editing->text = new_string;