NetSurf
Macros | Functions | Variables
textselection.c File Reference

RISC OS text selection implementation. More...

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <oslib/osfile.h>
#include <oslib/wimp.h>
#include "utils/log.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "netsurf/clipboard.h"
#include "netsurf/window.h"
#include "netsurf/browser_window.h"
#include "riscos/gui.h"
#include "riscos/window.h"
#include "riscos/menus.h"
#include "riscos/message.h"
#include "riscos/mouse.h"
#include "riscos/save.h"
#include "riscos/textselection.h"
#include "riscos/ucstables.h"
Include dependency graph for textselection.c:

Go to the source code of this file.

Macros

#define wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX   ((wimp_drag_claim_flags) 0x2u)
 

Functions

static void ro_gui_selection_drag_end (wimp_dragged *drag, void *data)
 End of text selection drag operation. More...
 
static void ro_gui_discard_clipboard_contents (void)
 Discard the current contents of the clipboard, if any, releasing the memory it uses. More...
 
static void ro_gui_dragging_bounced (wimp_message *message)
 Our message_DRAGGING message was bounced, ie. More...
 
void gui_start_selection (struct gui_window *g)
 Start drag-selecting text within a browser window (RO-dependent part) More...
 
static void gui_set_clipboard (const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles)
 Core tells front end to put given text in clipboard. More...
 
static void gui_get_clipboard (char **buffer, size_t *length)
 Core asks front end for clipboard contents. More...
 
static void ro_gui_selection_prepare_paste_complete (void)
 
static void ro_gui_selection_prepare_paste_bounced (wimp_message *message)
 
void ro_gui_selection_prepare_paste (wimp_w w, ro_gui_selection_prepare_paste_cb cb, void *pw)
 Prepare to paste data from another application. More...
 
bool ro_gui_selection_prepare_paste_datasave (wimp_full_message_data_xfer *dataxfer)
 Prepare to paste data from another application (step 2) More...
 
bool ro_gui_selection_prepare_paste_dataload (wimp_full_message_data_xfer *dataxfer)
 Prepare to paste data from another application (step 3) More...
 
void ro_gui_selection_claim_entity (wimp_full_message_claim_entity *claim)
 Responds to CLAIM_ENTITY message notifying us that the caret and selection or clipboard have been claimed by another application. More...
 
void ro_gui_selection_data_request (wimp_full_message_data_request *req)
 Responds to DATA_REQUEST message, returning information about the clipboard contents if we own the clipboard. More...
 
bool ro_gui_save_clipboard (const char *path)
 Save the clipboard contents to a file. More...
 
void ro_gui_selection_dragging (wimp_message *message)
 Handler for Message_Dragging, used to implement auto-scrolling and ghost caret when a drag is in progress. More...
 
void ro_gui_selection_drag_reset (void)
 Reset drag-and-drop state when drag completes (DataSave received) More...
 
void ro_gui_selection_drag_claim (wimp_message *message)
 
void ro_gui_selection_send_dragging (wimp_pointer *pointer)
 

Variables

static bool dragging_claimed = false
 Receive of Dragging message has claimed it. More...
 
static wimp_t dragging_claimant
 
static os_box dragging_box = { -34, -34, 34, 34 }
 
static wimp_drag_claim_flags last_claim_flags = 0
 
static struct gui_windowlast_start_window
 
static bool drag_claimed = false
 
static bool owns_clipboard = false
 
static bool owns_caret_and_selection = false
 
static char * clipboard = NULL
 
static size_t clip_length = 0
 
static ro_gui_selection_prepare_paste_cb paste_cb = NULL
 
static void * paste_cb_pw = NULL
 
static int paste_prev_message = 0
 
static struct gui_clipboard_table clipboard_table
 
struct gui_clipboard_tableriscos_clipboard_table = &clipboard_table
 

Detailed Description

RISC OS text selection implementation.

Definition in file textselection.c.

Macro Definition Documentation

◆ wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX

#define wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX   ((wimp_drag_claim_flags) 0x2u)

Definition at line 49 of file textselection.c.

Function Documentation

◆ gui_get_clipboard()

static void gui_get_clipboard ( char **  buffer,
size_t *  length 
)
static

Core asks front end for clipboard contents.

Parameters
bufferUTF-8 text, allocated by front end, ownership yielded to core
lengthByte length of UTF-8 text in buffer

Definition at line 255 of file textselection.c.

References buffer, clip_length, and clipboard.

◆ gui_set_clipboard()

static void gui_set_clipboard ( const char *  buffer,
size_t  length,
nsclipboard_styles  styles[],
int  n_styles 
)
static

Core tells front end to put given text in clipboard.

Parameters
bufferUTF-8 text, owned by core
lengthByte length of UTF-8 text in buffer
stylesArray of styles given to text runs, owned by core, or NULL
n_stylesNumber of text run styles in array

Definition at line 204 of file textselection.c.

References buffer, clip_length, clipboard, NSLOG, owns_clipboard, and ro_warn_user().

Here is the call graph for this function:

◆ gui_start_selection()

void gui_start_selection ( struct gui_window g)

Start drag-selecting text within a browser window (RO-dependent part)

Parameters
ggui window

Definition at line 87 of file textselection.c.

References last_start_window, NSLOG, owns_caret_and_selection, ro_gui_selection_drag_end(), ro_gui_window_mouse_at(), ro_mouse_drag_start(), ro_warn_user(), gui_window::state, and gui_window::window.

Here is the call graph for this function:

◆ ro_gui_discard_clipboard_contents()

void ro_gui_discard_clipboard_contents ( void  )
static

Discard the current contents of the clipboard, if any, releasing the memory it uses.

Definition at line 276 of file textselection.c.

References clip_length, and clipboard.

Referenced by ro_gui_selection_claim_entity(), and ro_gui_selection_prepare_paste().

Here is the caller graph for this function:

◆ ro_gui_dragging_bounced()

void ro_gui_dragging_bounced ( wimp_message *  message)
static

Our message_DRAGGING message was bounced, ie.

the intended recipient does not support the drag-and-drop protocol or cannot receive the data at the pointer position.

Definition at line 658 of file textselection.c.

References dragging_claimed.

Referenced by ro_gui_selection_send_dragging().

Here is the caller graph for this function:

◆ ro_gui_save_clipboard()

bool ro_gui_save_clipboard ( const char *  path)

Save the clipboard contents to a file.

Parameters
paththe pathname of the file
Returns
true iff success, otherwise reporting the error before returning false

Definition at line 515 of file textselection.c.

References clip_length, clipboard, NSERROR_OK, NSLOG, path(), ro_warn_user(), and utf8_to_local_encoding().

Referenced by ro_gui_save_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_claim_entity()

void ro_gui_selection_claim_entity ( wimp_full_message_claim_entity *  claim)

Responds to CLAIM_ENTITY message notifying us that the caret and selection or clipboard have been claimed by another application.

Parameters
claimCLAIM_ENTITY message

Definition at line 448 of file textselection.c.

References NSLOG, owns_caret_and_selection, owns_clipboard, ro_gui_discard_clipboard_contents(), and task_handle.

Referenced by ro_gui_user_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_data_request()

void ro_gui_selection_data_request ( wimp_full_message_data_request *  req)

Responds to DATA_REQUEST message, returning information about the clipboard contents if we own the clipboard.

Parameters
reqDATA_REQUEST message

Definition at line 474 of file textselection.c.

References clip_length, GUI_SAVE_CLIPBOARD_CONTENTS, owns_clipboard, and ro_gui_send_datasave().

Referenced by ro_gui_user_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_drag_claim()

void ro_gui_selection_drag_claim ( wimp_message *  message)

Definition at line 590 of file textselection.c.

References dragging_claimant, dragging_claimed, GUI_POINTER_DEFAULT, gui_window_set_pointer(), last_claim_flags, last_start_window, ro_gui_drag_box_cancel(), and wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX.

Referenced by gui_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_drag_end()

static void ro_gui_selection_drag_end ( wimp_dragged *  drag,
void *  data 
)
static

End of text selection drag operation.

Parameters
*dragposition of pointer at conclusion of drag
*datagui window pointer.

Definition at line 162 of file textselection.c.

References browser_window_mouse_track(), gui_window::bw, NSLOG, ro_gui_window_to_window_pos(), ro_warn_user(), gui_window::window, and browser_window::x.

Referenced by gui_start_selection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_drag_reset()

void ro_gui_selection_drag_reset ( void  )

Reset drag-and-drop state when drag completes (DataSave received)

Definition at line 580 of file textselection.c.

References drag_claimed.

◆ ro_gui_selection_dragging()

void ro_gui_selection_dragging ( wimp_message *  message)

Handler for Message_Dragging, used to implement auto-scrolling and ghost caret when a drag is in progress.

Definition at line 551 of file textselection.c.

References drag_claimed, ro_gui_window_lookup(), and ro_gui_window_to_window_pos().

Referenced by gui_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_prepare_paste()

void ro_gui_selection_prepare_paste ( wimp_w  w,
ro_gui_selection_prepare_paste_cb  cb,
void *  pw 
)

Prepare to paste data from another application.

Parameters
wWindow being pasted into
cbCallback to call once preparation is complete
pwPrivate data for callback

Definition at line 309 of file textselection.c.

References owns_clipboard, paste_cb, paste_cb_pw, paste_prev_message, ro_gui_discard_clipboard_contents(), ro_gui_selection_prepare_paste_bounced(), and ro_message_send_message().

Referenced by ro_gui_keypress(), and ro_gui_window_menu_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_prepare_paste_bounced()

static void ro_gui_selection_prepare_paste_bounced ( wimp_message *  message)
static

Definition at line 296 of file textselection.c.

References ro_gui_selection_prepare_paste_complete().

Referenced by ro_gui_selection_prepare_paste(), and ro_gui_selection_prepare_paste_datasave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_prepare_paste_complete()

static void ro_gui_selection_prepare_paste_complete ( void  )
static

Definition at line 284 of file textselection.c.

References paste_cb, paste_cb_pw, and paste_prev_message.

Referenced by ro_gui_selection_prepare_paste_bounced(), ro_gui_selection_prepare_paste_dataload(), and ro_gui_selection_prepare_paste_datasave().

Here is the caller graph for this function:

◆ ro_gui_selection_prepare_paste_dataload()

bool ro_gui_selection_prepare_paste_dataload ( wimp_full_message_data_xfer *  dataxfer)

Prepare to paste data from another application (step 3)

Parameters
dataxferDataLoad message
Returns
True if message was handled, false otherwise

Definition at line 395 of file textselection.c.

References clip_length, clipboard, NSERROR_OK, paste_prev_message, ro_gui_selection_prepare_paste_complete(), ro_message_send_message(), and utf8_from_local_encoding().

Referenced by ro_gui_user_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_prepare_paste_datasave()

bool ro_gui_selection_prepare_paste_datasave ( wimp_full_message_data_xfer *  dataxfer)

Prepare to paste data from another application (step 2)

Parameters
dataxferDataSave message
Returns
True if message was handled, false otherwise

Definition at line 354 of file textselection.c.

References paste_prev_message, ro_gui_selection_prepare_paste_bounced(), ro_gui_selection_prepare_paste_complete(), ro_message_send_message(), and SLEN.

Referenced by ro_msg_datasave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_selection_send_dragging()

void ro_gui_selection_send_dragging ( wimp_pointer *  pointer)

Definition at line 615 of file textselection.c.

References dragging_box, dragging_claimant, dragging_claimed, NSLOG, ro_gui_dragging_bounced(), ro_message_send_message(), and ro_message_send_message_to_window().

Here is the call graph for this function:

Variable Documentation

◆ clip_length

size_t clip_length = 0
static

◆ clipboard

char* clipboard = NULL
static

◆ clipboard_table

struct gui_clipboard_table clipboard_table
static
Initial value:
= {
}
static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles)
Core tells front end to put given text in clipboard.
static void gui_get_clipboard(char **buffer, size_t *length)
Core asks front end for clipboard contents.

Definition at line 663 of file textselection.c.

◆ drag_claimed

bool drag_claimed = false
static

Definition at line 60 of file textselection.c.

Referenced by ro_gui_selection_drag_reset(), and ro_gui_selection_dragging().

◆ dragging_box

os_box dragging_box = { -34, -34, 34, 34 }
static

Definition at line 56 of file textselection.c.

Referenced by ro_gui_selection_send_dragging().

◆ dragging_claimant

wimp_t dragging_claimant
static

Definition at line 55 of file textselection.c.

Referenced by ro_gui_selection_drag_claim(), and ro_gui_selection_send_dragging().

◆ dragging_claimed

bool dragging_claimed = false
static

Receive of Dragging message has claimed it.

Definition at line 54 of file textselection.c.

Referenced by ro_gui_dragging_bounced(), ro_gui_selection_drag_claim(), and ro_gui_selection_send_dragging().

◆ last_claim_flags

wimp_drag_claim_flags last_claim_flags = 0
static

Definition at line 57 of file textselection.c.

Referenced by ro_gui_selection_drag_claim().

◆ last_start_window

struct gui_window* last_start_window
static

Definition at line 58 of file textselection.c.

Referenced by gui_start_selection(), and ro_gui_selection_drag_claim().

◆ owns_caret_and_selection

bool owns_caret_and_selection = false
static

Definition at line 63 of file textselection.c.

Referenced by gui_start_selection(), and ro_gui_selection_claim_entity().

◆ owns_clipboard

bool owns_clipboard = false
static

◆ paste_cb

ro_gui_selection_prepare_paste_cb paste_cb = NULL
static

◆ paste_cb_pw

void* paste_cb_pw = NULL
static

◆ paste_prev_message

int paste_prev_message = 0
static

◆ riscos_clipboard_table

struct gui_clipboard_table* riscos_clipboard_table = &clipboard_table

Definition at line 668 of file textselection.c.

Referenced by main().