From 49f4fa0d787c867ed24ac49897feb347939d4ef3 Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Sat, 21 Sep 2013 05:29:04 +0200 Subject: Hotlist and History and Cookies Manager implemented. (The Cookie Manager window is a new one) --- atari/hotlist.c | 138 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 29 deletions(-) (limited to 'atari/hotlist.c') diff --git a/atari/hotlist.c b/atari/hotlist.c index e44ce7db3..016cbc458 100644 --- a/atari/hotlist.c +++ b/atari/hotlist.c @@ -32,6 +32,7 @@ #include "desktop/hotlist.h" #include "desktop/tree.h" #include "desktop/gui.h" +#include "desktop/core_window.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" @@ -48,30 +49,111 @@ extern GRECT desk_area; struct atari_hotlist hl; +/* Setup Atari Treeview Callbacks: */ +static nserror atari_hotlist_init_phase2(struct core_window *cw, + struct core_window_callback_table * default_callbacks); +static void atari_hotlist_finish(struct core_window *cw); +static void atari_hotlist_keypress(struct core_window *cw, + uint32_t ucs4); +static void atari_hotlist_mouse_action(struct core_window *cw, + browser_mouse_state mouse, + int x, int y); +static void atari_hotlist_draw(struct core_window *cw, int x, + int y, struct rect *clip, + const struct redraw_context *ctx); +static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]); + +static struct atari_treeview_callbacks atari_hotlist_treeview_callbacks = { + .init_phase2 = atari_hotlist_init_phase2, + .finish = atari_hotlist_finish, + .draw = atari_hotlist_draw, + .keypress = atari_hotlist_keypress, + .mouse_action = atari_hotlist_mouse_action, + .gemtk_user_func = handle_event +}; + +static nserror atari_hotlist_init_phase2(struct core_window *cw, + struct core_window_callback_table *cb_t) +{ + LOG(("")); + return(hotlist_init(cb_t, cw, hl.path)); +} + +static void atari_hotlist_finish(struct core_window *cw) +{ + LOG(("")); + hotlist_fini(hl.path); +} + +static void atari_hotlist_draw(struct core_window *cw, int x, + int y, struct rect *clip, + const struct redraw_context *ctx) +{ + hotlist_redraw(x, y, clip, ctx); +} + +static void atari_hotlist_keypress(struct core_window *cw, uint32_t ucs4) +{ + LOG(("ucs4: %lu\n", ucs4)); + hotlist_keypress(ucs4); +} + +static void atari_hotlist_mouse_action(struct core_window *cw, + browser_mouse_state mouse, + int x, int y) +{ + LOG(("x: %d, y: %d\n", x, y)); + if((mouse & BROWSER_MOUSE_HOVER) && hotlist_has_selection()){ + hotlist_mouse_action(mouse, x, y); + } else { + hotlist_mouse_action(mouse, x, y); + } + +} + + + static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) { - NSTREEVIEW tv=NULL; + struct atari_treeview_window *tv=NULL; GRECT tb_area; + GUIWIN * gemtk_win; + struct gui_window * gw; + char *cur_url = NULL; + char *cur_title = NULL; + + LOG(("")); if(ev_out->emo_events & MU_MESAG){ switch (msg[0]) { case WM_TOOLBAR: - - tv = (NSTREEVIEW) gemtk_wm_get_user_data(win); - + LOG(("WM_TOOLBAR")); + tv = (struct atari_treeview_window*) gemtk_wm_get_user_data(win); + assert(tv); switch (msg[4]) { case TOOLBAR_HOTLIST_CREATE_FOLDER: - hotlist_add_folder(NULL, false, 0); + hotlist_add_folder(NULL, 0, 0); break; case TOOLBAR_HOTLIST_ADD: - atari_hotlist_add_page(NULL, NULL); + gw = gui_window_get_input_window(); + if(gw && gw->browser){ + cur_url = gui_window_get_url(gw); + cur_title = gui_window_get_title(gw); + // TODO: read language string. + cur_title = (cur_title ? cur_title : "New bookmark"); + } else { + cur_url = "http://www"; + } + atari_hotlist_add_page(cur_url, cur_title); break; case TOOLBAR_HOTLIST_DELETE: hotlist_keypress(KEY_DELETE_LEFT); - gemtk_wm_exec_redraw(tv->window, NULL); + // TODO: check if redraw is really required, + // - implement treeview getter for the gemtk + // handle. break; case TOOLBAR_HOTLIST_EDIT: @@ -79,10 +161,12 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) break; } + gemtk_win = atari_treeview_get_gemtk_window(tv); + assert(gemtk_win); gemtk_obj_get_tree(TOOLBAR_HOTLIST)[msg[4]].ob_state &= ~OS_SELECTED; - gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_TOOLBAR, &tb_area); + atari_treeview_get_grect(tv, TREEVIEW_AREA_TOOLBAR, &tb_area); evnt_timer(150); - gemtk_wm_exec_redraw(tv->window, &tb_area); + gemtk_wm_exec_redraw(gemtk_win, &tb_area); break; case WM_CLOSED: @@ -116,7 +200,6 @@ void atari_hotlist_init(void) GRECT desk; OBJECT * tree = gemtk_obj_get_tree(TOOLBAR_HOTLIST); assert( tree ); - hl.open = false; handle = wind_create(flags, 0, 0, desk_area.g_w, desk_area.g_h); hl.window = gemtk_wm_add(handle, GEMTK_WM_FLAG_DEFAULTS, NULL); @@ -129,11 +212,10 @@ void atari_hotlist_init(void) gemtk_wm_set_toolbar(hl.window, tree, 0, 0); gemtk_wm_unlink(hl.window); tree_hotlist_path = (const char*)&hl.path; - hl.tv = atari_treeview_create( - TREE_HOTLIST, - hl.window, - handle_event - ); + + hl.tv = atari_treeview_create(hl.window, &atari_hotlist_treeview_callbacks, + flags); + if (hl.tv == NULL) { /* handle it properly, clean up previous allocs */ LOG(("Failed to allocate treeview")); @@ -147,14 +229,14 @@ void atari_hotlist_init(void) hl.init = true; } - void atari_hotlist_open(void) { - if( hl.init == false ) { + assert(hl.init); + if (hl.init == false) { return; } - if( hl.open == false ) { + if (atari_treeview_is_open(hl.tv) == false) { GRECT pos; pos.g_x = desk_area.g_w - desk_area.g_w / 4; @@ -162,9 +244,7 @@ void atari_hotlist_open(void) pos.g_w = desk_area.g_w / 4; pos.g_h = desk_area.g_h; - wind_open_grect(gemtk_wm_get_handle(hl.window), &pos); - hl.open = true; - atari_treeview_open( hl.tv ); + atari_treeview_open(hl.tv, &pos); } else { wind_set(gemtk_wm_get_handle(hl.window), WF_TOP, 1, 0, 0, 0); } @@ -172,8 +252,6 @@ void atari_hotlist_open(void) void atari_hotlist_close(void) { - wind_close(gemtk_wm_get_handle(hl.window)); - hl.open = false; atari_treeview_close(hl.tv); } @@ -184,12 +262,12 @@ void atari_hotlist_destroy(void) return; } if( hl.window != NULL ) { - if (hl.open) + if (atari_treeview_is_open(hl.tv)) atari_hotlist_close(); wind_delete(gemtk_wm_get_handle(hl.window)); gemtk_wm_remove(hl.window); hl.window = NULL; - atari_treeview_destroy(hl.tv); + atari_treeview_delete(hl.tv); hl.init = false; } LOG(("done")); @@ -197,7 +275,6 @@ void atari_hotlist_destroy(void) void atari_hotlist_redraw(void) { - int i = 01; atari_treeview_redraw(hl.tv); } @@ -209,7 +286,7 @@ void atari_hotlist_add_page( const char * url, const char * title ) struct node * selected = NULL; struct node * folder = NULL; nsurl *nsurl; - NSTREEVIEW tv = hl.tv; + ATARI_TREEVIEW_PTR tv = hl.tv; if(hl.tv == NULL ) return; @@ -218,11 +295,14 @@ void atari_hotlist_add_page( const char * url, const char * title ) if (nsurl_create(url, &nsurl) != NSERROR_OK) return; + /* doesn't look nice: if( hl.tv->click.x >= 0 && hl.tv->click.y >= 0 ){ hotlist_add_entry( nsurl, title, true, hl.tv->click.y ); } else { - hotlist_add_url( nsurl ); - } + + }*/ + //hotlist_add_url(nsurl); + hotlist_add_entry(nsurl, title, 0, 0); nsurl_unref(nsurl); } -- cgit v1.2.3