NetSurf
Functions | Variables
corewindow.c File Reference

GTK generic core window interface. More...

#include <assert.h>
#include <string.h>
#include <math.h>
#include <gtk/gtk.h>
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utf8.h"
#include "netsurf/types.h"
#include "netsurf/keypress.h"
#include "netsurf/mouse.h"
#include "gtk/compat.h"
#include "gtk/gui.h"
#include "gtk/plotters.h"
#include "gtk/corewindow.h"
Include dependency graph for corewindow.c:

Go to the source code of this file.

Functions

static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate (GdkEventButton *event)
 Convert GDK mouse event to netsurf mouse state. More...
 
static gboolean nsgtk_cw_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer g)
 gtk event on mouse button press. More...
 
static gboolean nsgtk_cw_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer g)
 gtk event on mouse button release. More...
 
static gboolean nsgtk_cw_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, gpointer g)
 gtk event on mouse movement. More...
 
static nserror nsgtk_cw_key (struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
 Deal with keypress events not handled buy input method or callback. More...
 
static gboolean nsgtk_cw_keypress_event (GtkWidget *widget, GdkEventKey *event, gpointer g)
 gtk event on key press. More...
 
static gboolean nsgtk_cw_keyrelease_event (GtkWidget *widget, GdkEventKey *event, gpointer g)
 gtk event on key release. More...
 
static void nsgtk_cw_input_method_commit (GtkIMContext *ctx, const gchar *str, gpointer g)
 gtk event handler for input method commit. More...
 
static gboolean nsgtk_cw_draw_event (GtkWidget *widget, GdkEventExpose *event, gpointer g)
 handler for gtk draw event on a nsgtk core window for GTK 2 More...
 
static nserror nsgtk_cw_invalidate_area (struct core_window *cw, const struct rect *rect)
 callback from core to request an invalidation of a GTK core window area. More...
 
static nserror nsgtk_cw_update_size (struct core_window *cw, int width, int height)
 update window size core window callback More...
 
static nserror nsgtk_cw_set_scroll (struct core_window *cw, int x, int y)
 scroll window core window callback More...
 
static nserror nsgtk_cw_get_scroll (const struct core_window *cw, int *x, int *y)
 scroll window core window callback More...
 
static nserror nsgtk_cw_get_window_dimensions (const struct core_window *cw, int *width, int *height)
 Callback from the core to obtain the window viewport dimensions. More...
 
static nserror nsgtk_cw_drag_status (struct core_window *cw, core_window_drag_status ds)
 update window drag status core window callback More...
 
nserror nsgtk_corewindow_init (struct nsgtk_corewindow *nsgtk_cw)
 initialise elements of gtk core window. More...
 
nserror nsgtk_corewindow_fini (struct nsgtk_corewindow *nsgtk_cw)
 finalise elements of gtk core window. More...
 

Variables

static struct core_window_table nsgtk_cw_cb_table
 core window callback table for nsgtk More...
 
struct core_window_tablensgtk_core_window_table = &nsgtk_cw_cb_table
 

Detailed Description

GTK generic core window interface.

Provides interface for core renderers to the gtk toolkit drawable area.

Todo:
should the interface really be called coredrawable?

This module is an object that must be encapsulated. Client users should embed a struct nsgtk_corewindow at the beginning of their context for this display surface, fill in relevant data and then call nsgtk_corewindow_init()

The nsgtk core window structure requires the drawing area and scrollable widgets are present and the callback for draw, key and mouse operations.

Definition in file corewindow.c.

Function Documentation

◆ nsgtk_corewindow_fini()

nserror nsgtk_corewindow_fini ( struct nsgtk_corewindow nsgtk_cw)

finalise elements of gtk core window.

Parameters
nsgtk_cwA gtk core window structure to initialise
Returns
NSERROR_OK on successful finalisation otherwise error code.

Definition at line 786 of file corewindow.c.

References nsgtk_corewindow::input_method, and NSERROR_OK.

Referenced by nsgtk_cookies_destroy(), nsgtk_global_history_destroy(), nsgtk_hotlist_destroy(), nsgtk_local_history_destroy(), and nsgtk_pi_delete_event().

Here is the caller graph for this function:

◆ nsgtk_corewindow_init()

nserror nsgtk_corewindow_init ( struct nsgtk_corewindow nsgtk_cw)

initialise elements of gtk core window.

Parameters
nsgtk_cwA gtk core window structure to initialise
Returns
NSERROR_OK on successful initialisation otherwise error code.

Definition at line 733 of file corewindow.c.

References CORE_WINDOW_DRAG_NONE, nsgtk_corewindow::drag_status, nsgtk_corewindow::drawing_area, GTK_STATE_FLAG_NORMAL, nsgtk_corewindow::input_method, NSERROR_OK, nsgtk_connect_draw_event(), nsgtk_cw_button_press_event(), nsgtk_cw_button_release_event(), nsgtk_cw_draw_event(), nsgtk_cw_input_method_commit(), nsgtk_cw_keypress_event(), nsgtk_cw_keyrelease_event(), nsgtk_cw_motion_notify_event(), and nsgtk_widget_override_background_color().

Referenced by nsgtk_cookies_init(), nsgtk_global_history_init(), nsgtk_hotlist_init(), nsgtk_local_history_init(), and nsgtk_page_info().

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

◆ nsgtk_cw_button_press_event()

static gboolean nsgtk_cw_button_press_event ( GtkWidget *  widget,
GdkEventButton *  event,
gpointer  g 
)
static

gtk event on mouse button press.

Service gtk event for a mouse button transition to pressed from released state.

Parameters
widgetThe gtk widget the event occurred for.
eventThe event that occurred.
gThe context pointer passed when the event was registered.

Definition at line 109 of file corewindow.c.

References nsgtk_corewindow::drawing_area, nsgtk_corewindow::input_method, nsgtk_corewindow_mouse::last_x, nsgtk_corewindow_mouse::last_y, nsgtk_corewindow::mouse, nsgtk_corewindow::mouse_state, nsgtk_cw_gdkbutton_to_nsstate(), nsgtk_corewindow_mouse::pressed, nsgtk_corewindow_mouse::pressed_x, nsgtk_corewindow_mouse::pressed_y, and nsgtk_corewindow_mouse::state.

Referenced by nsgtk_corewindow_init().

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

◆ nsgtk_cw_button_release_event()

static gboolean nsgtk_cw_button_release_event ( GtkWidget *  widget,
GdkEventButton *  event,
gpointer  g 
)
static

gtk event on mouse button release.

Service gtk event for a mouse button transition from pressed to released state.

Parameters
widgetThe gtk widget the event occurred for.
eventThe event that occurred.
gThe context pointer passed when the event was registered.

Definition at line 143 of file corewindow.c.

References BROWSER_MOUSE_CLICK_1, BROWSER_MOUSE_CLICK_2, BROWSER_MOUSE_DOUBLE_CLICK, BROWSER_MOUSE_DRAG_ON, BROWSER_MOUSE_HOLDING_1, BROWSER_MOUSE_HOLDING_2, BROWSER_MOUSE_HOVER, BROWSER_MOUSE_MOD_1, BROWSER_MOUSE_MOD_2, BROWSER_MOUSE_MOD_3, BROWSER_MOUSE_PRESS_1, BROWSER_MOUSE_PRESS_2, nsgtk_corewindow::mouse, nsgtk_corewindow::mouse_state, nsgtk_corewindow_mouse::pressed, and nsgtk_corewindow_mouse::state.

Referenced by nsgtk_corewindow_init().

Here is the caller graph for this function:

◆ nsgtk_cw_drag_status()

static nserror nsgtk_cw_drag_status ( struct core_window *  cw,
core_window_drag_status  ds 
)
static

update window drag status core window callback

Parameters
cwcore window handle.
dsThe new drag status.

Definition at line 709 of file corewindow.c.

References nsgtk_corewindow::drag_status, and NSERROR_OK.

◆ nsgtk_cw_draw_event()

static gboolean nsgtk_cw_draw_event ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  g 
)
static

handler for gtk draw event on a nsgtk core window for GTK 2

Parameters
widgetThe GTK widget to redraw.
eventThe GDK expose event
gThe context pointer passed when the event was registered.
Returns
FALSE indicating no error.

Definition at line 534 of file corewindow.c.

References clip(), current_cr, nsgtk_corewindow::draw, and nsgtk_widget_get_window().

Referenced by nsgtk_corewindow_init().

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

◆ nsgtk_cw_gdkbutton_to_nsstate()

static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate ( GdkEventButton *  event)
static

Convert GDK mouse event to netsurf mouse state.

Parameters
eventThe GDK mouse event to convert.
Returns
The netsurf mouse state.

Definition at line 59 of file corewindow.c.

References BROWSER_MOUSE_DOUBLE_CLICK, BROWSER_MOUSE_HOVER, BROWSER_MOUSE_MOD_1, BROWSER_MOUSE_MOD_2, BROWSER_MOUSE_MOD_3, BROWSER_MOUSE_PRESS_1, and BROWSER_MOUSE_PRESS_2.

Referenced by nsgtk_cw_button_press_event().

Here is the caller graph for this function:

◆ nsgtk_cw_get_scroll()

static nserror nsgtk_cw_get_scroll ( const struct core_window *  cw,
int *  x,
int *  y 
)
static

scroll window core window callback

Parameters
cwcore window handle.
rrectangle that needs scrolling.

Definition at line 643 of file corewindow.c.

References NSERROR_OK, and nsgtk_corewindow::scrolled.

◆ nsgtk_cw_get_window_dimensions()

static nserror nsgtk_cw_get_window_dimensions ( const struct core_window *  cw,
int *  width,
int *  height 
)
static

Callback from the core to obtain the window viewport dimensions.

Parameters
[in]cwthe core window object
[out]widthto be set to viewport width in px
[out]heightto be set to viewport height in px

Definition at line 675 of file corewindow.c.

References nsgtk_corewindow::drawing_area, height, NSERROR_OK, nsgtk_corewindow::scrolled, and width.

◆ nsgtk_cw_input_method_commit()

static void nsgtk_cw_input_method_commit ( GtkIMContext *  ctx,
const gchar *  str,
gpointer  g 
)
static

gtk event handler for input method commit.

Service gtk commit for input method commit action.

Parameters
ctxThe gtk input method context the event occurred for.
strThe resulting string from the input method.
gThe context pointer passed when the event was registered.

Definition at line 468 of file corewindow.c.

References nsgtk_corewindow::key, utf8_next(), and utf8_to_ucs4().

Referenced by nsgtk_corewindow_init().

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

◆ nsgtk_cw_invalidate_area()

static nserror nsgtk_cw_invalidate_area ( struct core_window *  cw,
const struct rect rect 
)
static

callback from core to request an invalidation of a GTK core window area.

The specified area of the window should now be considered out of date. If the area is NULL the entire window must be invalidated.

Parameters
[in]cwThe core window to invalidate.
[in]rectarea to redraw or NULL for the entire window area.
Returns
NSERROR_OK on success or appropriate error code.

Definition at line 570 of file corewindow.c.

References nsgtk_corewindow::drawing_area, NSERROR_OK, rect::x0, rect::x1, rect::y0, and rect::y1.

◆ nsgtk_cw_key()

static nserror nsgtk_cw_key ( struct nsgtk_corewindow nsgtk_cw,
uint32_t  nskey 
)
static

Deal with keypress events not handled buy input method or callback.

Parameters
nsgtk_cwnsgtk core window key event happened in.
nskeyThe netsurf keycode of the event.
Returns
NSERROR_OK on success otherwise an error code.

Definition at line 310 of file corewindow.c.

References NS_KEY_DOWN, NS_KEY_LEFT, NS_KEY_PAGE_DOWN, NS_KEY_PAGE_UP, NS_KEY_RIGHT, NS_KEY_TEXT_END, NS_KEY_TEXT_START, NS_KEY_UP, NSERROR_OK, nsgtk_adjustment_get_lower(), nsgtk_adjustment_get_page_increment(), nsgtk_adjustment_get_step_increment(), nsgtk_adjustment_get_upper(), and nsgtk_corewindow::scrolled.

Referenced by nsgtk_cw_keypress_event().

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

◆ nsgtk_cw_keypress_event()

static gboolean nsgtk_cw_keypress_event ( GtkWidget *  widget,
GdkEventKey *  event,
gpointer  g 
)
static

gtk event on key press.

Service gtk key-press-event for key transition on a widget from released to pressed.

Parameters
widgetThe gtk widget the event occurred for.
eventThe event that occurred.
gThe context pointer passed when the event was registered.

Definition at line 406 of file corewindow.c.

References gtk_gui_gdkkey_to_nskey(), nsgtk_corewindow::input_method, nsgtk_corewindow::key, messages_get_errorcode(), NSERROR_NOT_IMPLEMENTED, NSERROR_OK, nsgtk_cw_key(), and NSLOG.

Referenced by nsgtk_corewindow_init().

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

◆ nsgtk_cw_keyrelease_event()

static gboolean nsgtk_cw_keyrelease_event ( GtkWidget *  widget,
GdkEventKey *  event,
gpointer  g 
)
static

gtk event on key release.

Service gtk key-release-event for key transition on a widget from pressed to released.

Parameters
widgetThe gtk widget the event occurred for.
eventThe event that occurred.
gThe context pointer passed when the event was registered.

Definition at line 450 of file corewindow.c.

References nsgtk_corewindow::input_method.

Referenced by nsgtk_corewindow_init().

Here is the caller graph for this function:

◆ nsgtk_cw_motion_notify_event()

static gboolean nsgtk_cw_motion_notify_event ( GtkWidget *  widget,
GdkEventMotion *  event,
gpointer  g 
)
static

gtk event on mouse movement.

Service gtk motion-notify-event for mouse movement above a widget.

Parameters
widgetThe gtk widget the event occurred for.
eventThe motion event that occurred.
gThe context pointer passed when the event was registered.

Definition at line 220 of file corewindow.c.

References BROWSER_MOUSE_DRAG_1, BROWSER_MOUSE_DRAG_2, BROWSER_MOUSE_DRAG_ON, BROWSER_MOUSE_HOLDING_1, BROWSER_MOUSE_HOLDING_2, BROWSER_MOUSE_HOVER, BROWSER_MOUSE_MOD_1, BROWSER_MOUSE_MOD_2, BROWSER_MOUSE_MOD_3, BROWSER_MOUSE_PRESS_1, BROWSER_MOUSE_PRESS_2, nsgtk_corewindow_mouse::last_x, nsgtk_corewindow_mouse::last_y, nsgtk_corewindow::mouse, nsgtk_corewindow::mouse_state, nsgtk_corewindow_mouse::pressed, nsgtk_corewindow_mouse::pressed_x, nsgtk_corewindow_mouse::pressed_y, and nsgtk_corewindow_mouse::state.

Referenced by nsgtk_corewindow_init().

Here is the caller graph for this function:

◆ nsgtk_cw_set_scroll()

static nserror nsgtk_cw_set_scroll ( struct core_window *  cw,
int  x,
int  y 
)
static

scroll window core window callback

Parameters
cwcore window handle.
rrectangle that needs scrolling.

Definition at line 615 of file corewindow.c.

References NSERROR_OK, and nsgtk_corewindow::scrolled.

◆ nsgtk_cw_update_size()

static nserror nsgtk_cw_update_size ( struct core_window *  cw,
int  width,
int  height 
)
static

update window size core window callback

Parameters
cwcore window handle.
widthNew widget width.
heightNew widget height.

Definition at line 597 of file corewindow.c.

References nsgtk_corewindow::drawing_area, height, NSERROR_OK, and width.

Variable Documentation

◆ nsgtk_core_window_table

struct core_window_table* nsgtk_core_window_table = &nsgtk_cw_cb_table

Definition at line 730 of file corewindow.c.

Referenced by main().

◆ nsgtk_cw_cb_table

struct core_window_table nsgtk_cw_cb_table
static
Initial value:
= {
.invalidate = nsgtk_cw_invalidate_area,
.set_extent = nsgtk_cw_update_size,
.set_scroll = nsgtk_cw_set_scroll,
.get_scroll = nsgtk_cw_get_scroll,
.get_dimensions = nsgtk_cw_get_window_dimensions,
.drag_status = nsgtk_cw_drag_status
}
static nserror nsgtk_cw_update_size(struct core_window *cw, int width, int height)
update window size core window callback
Definition: corewindow.c:597
static nserror nsgtk_cw_get_window_dimensions(const struct core_window *cw, int *width, int *height)
Callback from the core to obtain the window viewport dimensions.
Definition: corewindow.c:675
static nserror nsgtk_cw_get_scroll(const struct core_window *cw, int *x, int *y)
scroll window core window callback
Definition: corewindow.c:643
static nserror nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
update window drag status core window callback
Definition: corewindow.c:709
static nserror nsgtk_cw_set_scroll(struct core_window *cw, int x, int y)
scroll window core window callback
Definition: corewindow.c:615
static nserror nsgtk_cw_invalidate_area(struct core_window *cw, const struct rect *rect)
callback from core to request an invalidation of a GTK core window area.
Definition: corewindow.c:570

core window callback table for nsgtk

Definition at line 721 of file corewindow.c.