Implement mouse move event handling

This commit is contained in:
Ole Loots 2012-12-06 00:26:00 +01:00
parent 16812b0522
commit 434befd25b
3 changed files with 136 additions and 60 deletions

View File

@ -87,6 +87,7 @@ void * h_gem_rsrc;
long next_poll;
bool rendering = false;
bool gui_poll_repeat = false;
GRECT desk_area;
/* Comandline / Options: */
@ -102,7 +103,7 @@ const char * option_homepage_url;
char options[PATH_MAX];
EVMULT_IN aes_event_in = {
.emi_flags = MU_MESAG | MU_TIMER | MU_KEYBD | MU_BUTTON,
.emi_flags = MU_MESAG | MU_TIMER | MU_KEYBD | MU_BUTTON | MU_M1,
.emi_bclicks = 258,
.emi_bmask = 3,
.emi_bstate = 0,
@ -120,7 +121,7 @@ short aes_msg_out[8];
void gui_poll(bool active)
{
int flags = MU_MESAG | MU_KEYBD | MU_BUTTON | MU_M1 | MU_MX;
short mx, my, dummy;
unsigned short nkc = 0;
@ -131,25 +132,17 @@ void gui_poll(bool active)
if(active || rendering)
aes_event_in.emi_tlow = 0;
if(aes_event_in.emi_tlow < 0){
aes_event_in.emi_tlow = 10000;
printf("long poll!\n");
}
struct gui_window * g;
if(input_window->root->redraw_slots.areas_used > 0){
window_process_redraws(input_window->root);
}
// for( g = window_list; g != NULL; g=g->next ) {
// if( browser_redraw_required( g ) ) {
// browser_redraw(g);
// }
// if(g->root->toolbar) {
// //if(g->root->toolbar->url.redraw ) {
// // TODO: implement toolbar redraw mechanism
// //tb_url_redraw( g );
// //}
// }
// }
if( !active ) {
if(input_window->root->redraw_slots.areas_used > 0){
window_process_redraws(input_window->root);
}
/* this suits for stuff with lower priority */
/* TBD: really be spare on redraws??? */
hotlist_redraw();
@ -158,39 +151,43 @@ void gui_poll(bool active)
// Handle events until there are no more messages pending or
// until the engine indicates activity:
do {
evnt_multi_fast(&aes_event_in, aes_msg_out, &aes_event_out);
if(!guiwin_dispatch_event(&aes_event_in, &aes_event_out, aes_msg_out)) {
if( (aes_event_out.emo_events & MU_MESAG) != 0 ) {
LOG(("WM: %d\n", aes_msg_out[0]));
switch(aes_msg_out[0]) {
if(!(active || rendering) || (clock() >= next_poll)){
do {
short mx, my, dummy;
case MN_SELECTED:
LOG(("Menu Item: %d\n",aes_msg_out[4]));
deskmenu_dispatch_item(aes_msg_out[3], aes_msg_out[4]);
break;
default:
break;
graf_mkstate(&mx, &my, &dummy, &dummy);
aes_event_in.emi_m1.g_x = mx;
aes_event_in.emi_m1.g_y = my;
evnt_multi_fast(&aes_event_in, aes_msg_out, &aes_event_out);
if(!guiwin_dispatch_event(&aes_event_in, &aes_event_out, aes_msg_out)) {
if( (aes_event_out.emo_events & MU_MESAG) != 0 ) {
LOG(("WM: %d\n", aes_msg_out[0]));
switch(aes_msg_out[0]) {
case MN_SELECTED:
LOG(("Menu Item: %d\n",aes_msg_out[4]));
deskmenu_dispatch_item(aes_msg_out[3], aes_msg_out[4]);
break;
default:
break;
}
}
if((aes_event_out.emo_events & MU_KEYBD) != 0) {
uint16_t nkc = gem_to_norm( (short)aes_event_out.emo_kmeta,
(short)aes_event_out.emo_kreturn);
deskmenu_dispatch_keypress(aes_event_out.emo_kreturn,
aes_event_out.emo_kmeta, nkc);
}
}
if((aes_event_out.emo_events & MU_KEYBD) != 0) {
uint16_t nkc = gem_to_norm( (short)aes_event_out.emo_kmeta,
(short)aes_event_out.emo_kreturn);
deskmenu_dispatch_keypress(aes_event_out.emo_kreturn,
aes_event_out.emo_kmeta, nkc);
}
/*
if((aes_event_out.emo_events & MU_KEYBD|MU_MX) != 0) {
on_m1();
}
*/
} while ( gui_poll_repeat && !(active||rendering));
if(input_window && input_window->root->redraw_slots.areas_used > 0 && !active){
window_process_redraws(input_window->root);
}
} while ( gui_poll_repeat && !(active||rendering));
if(active || rendering)
next_poll = clock() + (CLOCKS_PER_SEC>>3);
}
if(input_window && input_window->root->redraw_slots.areas_used > 0){
window_process_redraws(input_window->root);
}
}
@ -1076,7 +1073,13 @@ static void gui_init(int argc, char** argv)
nkc_init();
plot_init(nsoption_charp(atari_font_driver));
tree_set_icon_dir( nsoption_charp(tree_icons_path) );
tree_set_icon_dir(nsoption_charp(tree_icons_path));
wind_get_grect(0, WF_WORKXYWH, &desk_area);
aes_event_in.emi_m1leave = MO_LEAVE;
aes_event_in.emi_m1.g_w = 1;
aes_event_in.emi_m1.g_h = 1;
}
static char *theapp = (char*)"NetSurf";

View File

@ -68,13 +68,14 @@ struct rootwin_data_s {
};
/* -------------------------------------------------------------------------- */
/* Static module methods */
/* Static module event handlers */
/* -------------------------------------------------------------------------- */
static void on_redraw(ROOTWIN *rootwin, short msg[8]);
static void on_resized(ROOTWIN *rootwin);
static void on_file_dropped(ROOTWIN *rootwin, short msg[8]);
static short on_window_key_input(ROOTWIN * rootwin, unsigned short nkc);
static bool on_content_mouse_click(ROOTWIN *rootwin);
static bool on_content_mouse_move(ROOTWIN *rootwin, GRECT *content_area);
static bool redraw_active = false;
@ -92,8 +93,13 @@ static const struct redraw_context rootwin_rdrw_ctx = {
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
{
short retval = 0;
GRECT content_area;
static bool prev_url = false;
static short prev_x=0;
static short prev_y=0;
struct rootwin_data_s * data = guiwin_get_user_data(win);
if ((ev_out->emo_events & MU_MESAG) != 0) {
// handle message
//printf("root win msg: %d\n", msg[0]);
@ -152,17 +158,43 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
}
if ((ev_out->emo_events & MU_BUTTON) != 0) {
LOG(("Mouse click at: %d,%d\n", ev_out->emo_mouse.p_x,
ev_out->emo_mouse.p_y));
GRECT carea;
guiwin_get_grect(data->rootwin->win, GUIWIN_AREA_CONTENT, &carea);
if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y, carea)) {
guiwin_get_grect(data->rootwin->win, GUIWIN_AREA_CONTENT,
&content_area);
if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y,
content_area)) {
on_content_mouse_click(data->rootwin);
}
}
if ((ev_out->emo_events & (MU_M1 | MU_MX)) != 0) {
printf("mx event at %d,%d\n", ev_out->emo_mouse.p_x,
ev_out->emo_mouse.p_y);
if ((ev_out->emo_events & (MU_M1)) != 0) {
short ghandle = wind_find(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y);
if (guiwin_get_handle(data->rootwin->win)==ghandle) {
// The window found at x,y is an gui_window
// and it's the input window.
window_get_grect(data->rootwin, BROWSER_AREA_CONTENT,
&content_area);
if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y,
content_area)) {
on_content_mouse_move(data->rootwin, &content_area);
} else {
GRECT tb_area;
window_get_grect(data->rootwin, BROWSER_AREA_URL_INPUT, &tb_area);
if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y,
tb_area)) {
gem_set_cursor(&gem_cursors.ibeam);
prev_url = true;
}
else {
if(prev_url) {
struct gui_window *gw;
gw = window_get_active_gui_window(data->rootwin);
gem_set_cursor(gw->cursor);
prev_url = false;
}
}
}
}
}
return(retval);
@ -494,6 +526,20 @@ void window_get_scroll(ROOTWIN *rootwin, int *x, int *y)
*y = slid->y_pos * slid->y_unit_px;
}
void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d)
{
if (which == BROWSER_AREA_TOOLBAR) {
guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, d);
} else if (which == BROWSER_AREA_CONTENT) {
guiwin_get_grect(rootwin->win, GUIWIN_AREA_CONTENT, d);
} else if (which == BROWSER_AREA_URL_INPUT) {
toolbar_get_grect(rootwin->toolbar, TOOLBAR_URL_AREA, d);
} else {
}
}
/**
* Redraw the favicon
@ -682,6 +728,27 @@ void window_process_redraws(ROOTWIN * rootwin)
/* -------------------------------------------------------------------------- */
/* Event Handlers: */
/* -------------------------------------------------------------------------- */
static bool on_content_mouse_move(ROOTWIN *rootwin, GRECT *content_area)
{
int mx, my, sx, sy;
struct guiwin_scroll_info_s *slid;
struct gui_window *gw;
struct browser_window *bw;
// make relative mouse coords:
mx = aes_event_out.emo_mouse.p_x - content_area->g_x;
my = aes_event_out.emo_mouse.p_y - content_area->g_y;
slid = guiwin_get_scroll_info(rootwin->win);
gw = window_get_active_gui_window(rootwin);
bw = gw->browser->bw;
// calculate scroll pos. in pixel:
sx = slid->x_pos * slid->x_unit_px;
sy = slid->y_pos * slid->y_unit_px;
browser_window_mouse_track(bw, 0, mx + sx, my + sy);
}
static bool on_content_mouse_click(ROOTWIN *rootwin)
{
@ -776,8 +843,8 @@ static bool on_content_mouse_click(ROOTWIN *rootwin)
} else {
/* Right button pressed? */
if ((aes_event_out.emo_mbutton & 2 ) ) {
context_popup( gw, aes_event_out.emo_mouse.p_x,
aes_event_out.emo_mouse.p_x);
context_popup(gw, aes_event_out.emo_mouse.p_x,
aes_event_out.emo_mouse.p_y);
} else {
browser_window_mouse_click(gw->browser->bw,
bmstate|BROWSER_MOUSE_PRESS_1,

View File

@ -28,10 +28,15 @@
#define WIDGET_TOOLBAR 0x2
#define WIDGET_SCROLL 0x4
#define WIDGET_RESIZE 0x8
#define WIN_TOP 0x100
enum browser_area_e {
BROWSER_AREA_CONTENT = 1,
BROWSER_AREA_STATUSBAR,
BROWSER_AREA_TOOLBAR,
BROWSER_AREA_URL_INPUT
};
/* WinDom & Custom bindings for gui window */
/* -------------------------------------------------------------------------- */
/* Public module functions: */
@ -70,6 +75,7 @@ void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area);
void window_process_redraws(ROOTWIN * rootwin);
struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin);
void window_get_scroll(ROOTWIN *rootwin, int *x, int *y);
void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d);
void window_redraw_favicon(struct s_gui_win_root * rootwin, GRECT *clip);
void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw);
bool window_key_input(unsigned short kcode, unsigned short kstate,