From 1d535a9a43e65a1fa3e205c42bc106ee0ce6a1a5 Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Tue, 17 Sep 2013 02:10:35 +0200 Subject: Treeview implementation adjusted (still requires changes at several places in the atari frontent) --- atari/gui.c | 3 + atari/hotlist.c | 211 ++++++++++++++++++++++++++++ atari/hotlist.h | 46 +++++++ atari/plot/plot.c | 6 + atari/plot/plot.h | 1 + atari/treeview.c | 406 +++++++++++++++++++++++++++++++++++++++++++++++++----- atari/treeview.h | 31 ++++- 7 files changed, 664 insertions(+), 40 deletions(-) (limited to 'atari') diff --git a/atari/gui.c b/atari/gui.c index 83731b4de..3f056a1bc 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -171,6 +171,8 @@ void gui_poll(bool active) tmp = tmp->next; } + // TODO: reenable treeview redraws +/* if(hl.tv->redraw){ atari_treeview_redraw(hl.tv); } @@ -178,6 +180,7 @@ void gui_poll(bool active) if(gl_history.tv->redraw){ atari_treeview_redraw(gl_history.tv); } +*/ } diff --git a/atari/hotlist.c b/atari/hotlist.c index dfed6d037..e44ce7db3 100644 --- a/atari/hotlist.c +++ b/atari/hotlist.c @@ -15,3 +15,214 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + + +#include +#include +#include +#include +#include +#include + +#include "desktop/browser.h" +#include "content/content.h" +#include "content/hlcache.h" +#include "content/urldb.h" +#include "utils/nsoption.h" +#include "desktop/hotlist.h" +#include "desktop/tree.h" +#include "desktop/gui.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/url.h" +#include "atari/gui.h" +#include "atari/misc.h" +#include "atari/treeview.h" +#include "atari/hotlist.h" +#include "atari/findfile.h" +#include "atari/gemtk/gemtk.h" +#include "atari/res/netsurf.rsh" + +extern GRECT desk_area; + +struct atari_hotlist hl; + +static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) +{ + NSTREEVIEW tv=NULL; + GRECT tb_area; + + if(ev_out->emo_events & MU_MESAG){ + switch (msg[0]) { + + case WM_TOOLBAR: + + tv = (NSTREEVIEW) gemtk_wm_get_user_data(win); + + switch (msg[4]) { + case TOOLBAR_HOTLIST_CREATE_FOLDER: + hotlist_add_folder(NULL, false, 0); + break; + + case TOOLBAR_HOTLIST_ADD: + atari_hotlist_add_page(NULL, NULL); + break; + + case TOOLBAR_HOTLIST_DELETE: + hotlist_keypress(KEY_DELETE_LEFT); + gemtk_wm_exec_redraw(tv->window, NULL); + break; + + case TOOLBAR_HOTLIST_EDIT: + hotlist_edit_selection(); + break; + } + + gemtk_obj_get_tree(TOOLBAR_HOTLIST)[msg[4]].ob_state &= ~OS_SELECTED; + gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_TOOLBAR, &tb_area); + evnt_timer(150); + gemtk_wm_exec_redraw(tv->window, &tb_area); + break; + + case WM_CLOSED: + atari_hotlist_close(); + break; + + default: break; + } + } + + // TODO: implement selectable objects in toolbar API: + // ObjcChange( OC_TOOLBAR, win, buff[4], ~SELECTED, OC_MSG ); +} + + + +void atari_hotlist_init(void) +{ + if (hl.init == false) { + if( strcmp(nsoption_charp(hotlist_file), "") == 0 ){ + atari_find_resource( (char*)&hl.path, "hotlist", "hotlist" ); + } else { + strncpy( (char*)&hl.path, nsoption_charp(hotlist_file), PATH_MAX-1 ); + } + + LOG(("Hotlist: %s", (char*)&hl.path )); + + if( hl.window == NULL ){ + int flags = ATARI_TREEVIEW_WIDGETS; + short handle = -1; + 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); + if( hl.window == NULL ) { + gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT, + "Failed to allocate Hotlist"); + return; + } + wind_set_str(handle, WF_NAME, (char*)messages_get("Hotlist")); + 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 + ); + if (hl.tv == NULL) { + /* handle it properly, clean up previous allocs */ + LOG(("Failed to allocate treeview")); + return; + } + + } else { + + } + } + hl.init = true; +} + + +void atari_hotlist_open(void) +{ + if( hl.init == false ) { + return; + } + + if( hl.open == false ) { + + GRECT pos; + pos.g_x = desk_area.g_w - desk_area.g_w / 4; + pos.g_y = desk_area.g_y; + 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 ); + } else { + wind_set(gemtk_wm_get_handle(hl.window), WF_TOP, 1, 0, 0, 0); + } +} + +void atari_hotlist_close(void) +{ + wind_close(gemtk_wm_get_handle(hl.window)); + hl.open = false; + atari_treeview_close(hl.tv); +} + +void atari_hotlist_destroy(void) +{ + + if( hl.init == false) { + return; + } + if( hl.window != NULL ) { + if (hl.open) + atari_hotlist_close(); + wind_delete(gemtk_wm_get_handle(hl.window)); + gemtk_wm_remove(hl.window); + hl.window = NULL; + atari_treeview_destroy(hl.tv); + hl.init = false; + } + LOG(("done")); +} + +void atari_hotlist_redraw(void) +{ + int i = 01; + atari_treeview_redraw(hl.tv); +} + +struct node; + +void atari_hotlist_add_page( const char * url, const char * title ) +{ + struct node * root; + struct node * selected = NULL; + struct node * folder = NULL; + nsurl *nsurl; + NSTREEVIEW tv = hl.tv; + if(hl.tv == NULL ) + return; + + atari_hotlist_open(); + + if (nsurl_create(url, &nsurl) != NSERROR_OK) + return; + + 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 ); + } + nsurl_unref(nsurl); +} + diff --git a/atari/hotlist.h b/atari/hotlist.h index e69de29bb..c6fc4649a 100644 --- a/atari/hotlist.h +++ b/atari/hotlist.h @@ -0,0 +1,46 @@ +/* + * Copyright 2013 Ole Loots + * + * 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 . + */ + +#ifndef NS_ATARI_HOTLIST_H +#define NS_ATARI_HOTLIST_H +#include +#include "desktop/tree.h" +#include "atari/gemtk/gemtk.h" +#include "atari/treeview.h" +/* The hotlist window, toolbar and treeview data. */ + +struct atari_hotlist { + GUIWIN * window; + NSTREEVIEW tv; /*< The hotlist treeview handle. */ + bool open; + bool init; + char path[PATH_MAX]; +}; + +extern struct atari_hotlist hl; + +void atari_hotlist_init( void ); +void atari_hotlist_open( void ); +void atari_hotlist_close( void ); +void atari_hotlist_destroy( void ); +void atari_hotlist_add_page( const char * url, const char * title ); + +void atari_hotlist_redraw( void ); + + +#endif diff --git a/atari/plot/plot.c b/atari/plot/plot.c index 80eda6949..19c34e257 100755 --- a/atari/plot/plot.c +++ b/atari/plot/plot.c @@ -1953,6 +1953,12 @@ VdiHdl plot_get_vdi_handle(void) return(atari_plot_vdi_handle); } +long plot_get_flags(void) +{ + return(atari_plot_flags); +} + + bool plot_get_clip(struct rect * out) { out->x0 = view.clipping.x0; diff --git a/atari/plot/plot.h b/atari/plot/plot.h index 3c9461d69..d00bbc669 100755 --- a/atari/plot/plot.h +++ b/atari/plot/plot.h @@ -112,6 +112,7 @@ bool plot_get_clip(struct rect * out); void plot_get_clip_grect(GRECT * out); bool plot_clip(const struct rect *clip); VdiHdl plot_get_vdi_handle(void); +long plot_get_flags(void); bool plot_rectangle( int x0, int y0, int x1, int y1,const plot_style_t *style ); bool plot_line( int x0, int y0, int x1, int y1, const plot_style_t *style ); bool plot_blit_bitmap(struct bitmap * bmp, int x, int y, diff --git a/atari/treeview.c b/atari/treeview.c index 7ea039c13..6dd43d3db 100644 --- a/atari/treeview.c +++ b/atari/treeview.c @@ -75,21 +75,370 @@ struct atari_treeview_window { struct atari_treeview_callbacks *io; }; -typedef struct atari_treeview_window *ATARI_TREEVIEW; - +enum treeview_area_e { + TREEVIEW_AREA_WORK = 0, + TREEVIEW_AREA_TOOLBAR, + TREEVIEW_AREA_CONTENT +}; /* native GUI event handlers: */ -static void __CDECL on_mbutton_event(struct atari_treeview_window tvw, +static void __CDECL on_mbutton_event(struct atari_treeview_window *tvw, EVMULT_OUT *ev_out, short msg[8]); -static void __CDECL on_keybd_event(struct atari_treeview_window tvw, +static void __CDECL on_keybd_event(struct atari_treeview_window *tvw, EVMULT_OUT *ev_out, short msg[8]); -static void __CDECL on_redraw_event(struct atari_treeview_window tvw, +static void __CDECL on_redraw_event(struct atari_treeview_window *tvw, EVMULT_OUT *ev_out, short msg[8]); -/* GEMTK event sink: */ + +/** + * Schedule a redraw of the treeview content + * + */ +static void atari_treeview_redraw_grect_request(struct core_window *cw, + GRECT *area) +{ + if (cw != NULL) { + ATARI_TREEVIEW_PTR tv = (ATARI_TREEVIEW_PTR) cw; + if( tv->redraw == false ){ + tv->redraw = true; + tv->rdw_area.g_x = area->g_x; + tv->rdw_area.g_y = area->g_y; + tv->rdw_area.g_w = area->g_w; + tv->rdw_area.g_h = area->g_h; + } else { + /* merge the redraw area to the new area.: */ + int newx1 = area->g_x+area->g_w; + int newy1 = area->g_y+area->g_h; + int oldx1 = tv->rdw_area.g_x + tv->rdw_area.g_w; + int oldy1 = tv->rdw_area.g_y + tv->rdw_area.g_h; + tv->rdw_area.g_x = MIN(tv->rdw_area.g_x, area->g_x); + tv->rdw_area.g_y = MIN(tv->rdw_area.g_y, area->g_y); + tv->rdw_area.g_w = ( oldx1 > newx1 ) ? oldx1 - tv->rdw_area.g_x : newx1 - tv->rdw_area.g_x; + tv->rdw_area.g_h = ( oldy1 > newy1 ) ? oldy1 - tv->rdw_area.g_y : newy1 - tv->rdw_area.g_y; + } + // dbg_grect("atari_treeview_request_redraw", &tv->rdw_area); + } +} + + +static void atari_treeview_get_grect(ATARI_TREEVIEW_PTR tptr, enum treeview_area_e mode, + GRECT *dest) +{ + + struct atari_treeview_window * tv = tptr; + + if (mode == TREEVIEW_AREA_CONTENT) { + gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_CONTENT, dest); + } + else if (mode == TREEVIEW_AREA_TOOLBAR) { + gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_TOOLBAR, dest); + } +} + + +void atari_treeview_redraw(struct atari_treeview_window *tv) +{ + static FONT_PLOTTER vdi_txt_plotter = NULL; + FONT_PLOTTER old_txt_plotter; + + VdiHdl plot_vdi_handle = 0; + long atari_plot_flags = 0; + + /* TODO: do not use the global vdi handle for plot actions! */ + /* TODO: implement getter/setter for the vdi handle */ + + if (tv != NULL) { + if( tv->redraw && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) { + + plot_vdi_handle = plot_get_vdi_handle(); + long atari_plot_flags = plot_get_flags(); + short todo[4]; + GRECT work; + short handle = gemtk_wm_get_handle(tv->window); + struct gemtk_wm_scroll_info_s *slid; + +/* + if (vdi_txt_plotter == NULL) { + int err = 0; + VdiHdl vdih = plot_get_vdi_handle(); + vdi_txt_plotter = new_font_plotter(vdih, (char*)"vdi", PLOT_FLAG_TRANS, + &err); + if(err) { + const char * desc = plot_err_str(err); + die(("Unable to load vdi font plotter %s -> %s", "vdi", desc )); + } + } +*/ + gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_CONTENT, &work); + slid = gemtk_wm_get_scroll_info(tv->window); + + struct redraw_context ctx = { + .interactive = true, + .background_images = true, + .plot = &atari_plotters + }; + plot_set_dimensions(work.g_x, work.g_y, work.g_w, work.g_h); + if (plot_lock() == false) + return; +/* + if(vdi_txt_plotter != NULL){ + old_txt_plotter = plot_get_text_plotter(); + plot_set_text_plotter(vdi_txt_plotter); + } +*/ + if( wind_get(handle, WF_FIRSTXYWH, + &todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) { + while (todo[2] && todo[3]) { + + short pxy[4]; + pxy[0] = todo[0]; + pxy[1] = todo[1]; + pxy[2] = todo[0] + todo[2]-1; + pxy[3] = todo[1] + todo[3]-1; + vs_clip(plot_vdi_handle, 1, (short*)&pxy); + + /* convert screen to treeview coords: */ + todo[0] = todo[0] - work.g_x + slid->x_pos*slid->x_unit_px; + todo[1] = todo[1] - work.g_y + slid->y_pos*slid->y_unit_px; + if( todo[0] < 0 ){ + todo[2] = todo[2] + todo[0]; + todo[0] = 0; + } + if( todo[1] < 0 ){ + todo[3] = todo[3] + todo[1]; + todo[1] = 0; + } + + if (rc_intersect((GRECT *)&tv->rdw_area,(GRECT *)&todo)) { + tv->io->draw(tv, -(slid->x_pos*slid->x_unit_px), + -(slid->y_pos*slid->y_unit_px), + todo[0], todo[1], todo[2], todo[3], &ctx); + } + vs_clip(plot_vdi_handle, 0, (short*)&pxy); + if (wind_get(handle, WF_NEXTXYWH, + &todo[0], &todo[1], &todo[2], &todo[3])==0) { + break; + } + } + } else { + /* + plot_set_text_plotter(old_txt_plotter); + */ + plot_unlock(); + return; + } + /* + plot_set_text_plotter(old_txt_plotter); + */ + plot_unlock(); + tv->redraw = false; + tv->rdw_area.g_x = 65000; + tv->rdw_area.g_y = 65000; + tv->rdw_area.g_w = -1; + tv->rdw_area.g_h = -1; + } else { + /* just copy stuff from the offscreen buffer */ + } + } +} + + +/** + * GEMTK event sink + * +*/ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) { + ATARI_TREEVIEW_PTR tv = (ATARI_TREEVIEW_PTR) gemtk_wm_get_user_data(win); + + if( (ev_out->emo_events & MU_MESAG) != 0 ) { + // handle message + switch (msg[0]) { + + case WM_REDRAW: + on_redraw_event(tv, ev_out, msg); + break; + + default: + break; + } + } + if( (ev_out->emo_events & MU_KEYBD) != 0 ) { + on_keybd_event(tv, ev_out, msg); + } + if( (ev_out->emo_events & MU_BUTTON) != 0 ) { + LOG(("Treeview click at: %d,%d\n", ev_out->emo_mouse.p_x, + ev_out->emo_mouse.p_y)); + on_mbutton_event(tv, ev_out, msg); + } + + if (tv) { + + } +/* + if(tv != NULL && tv->user_func != NULL){ + tv->user_func(win, ev_out, msg); + } +*/ + return(0); +} + + +static void __CDECL on_keybd_event(ATARI_TREEVIEW_PTR tptr, EVMULT_OUT *ev_out, + short msg[8]) +{ + bool r=false; + long kstate = 0; + long kcode = 0; + long ucs4; + long ik; + unsigned short nkc = 0; + unsigned short nks = 0; + unsigned char ascii; + struct atari_treeview_window * tv = tptr; + + kstate = ev_out->emo_kmeta; + kcode = ev_out->emo_kreturn; + nkc= gem_to_norm( (short)kstate, (short)kcode ); + ascii = (nkc & 0xFF); + ik = nkc_to_input_key(nkc, &ucs4); + + if (ik == 0) { + if (ascii >= 9) { + tv->io->keypress(tv, ucs4); + //r = tree_keypress(tv->tree, ucs4); + } + } else { + tv->io->keypress(tv, ik); + } +} + + +static void __CDECL on_redraw_event(ATARI_TREEVIEW_PTR tptr, EVMULT_OUT *ev_out, + short msg[8]) +{ + GRECT work, clip; + struct gemtk_wm_scroll_info_s *slid; + struct atari_treeview_window * tv = tptr; + + if (tv == NULL) + return; + + gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_CONTENT, &work); + slid = gemtk_wm_get_scroll_info(tv->window); + + clip = work; + if ( !rc_intersect( (GRECT*)&msg[4], &clip ) ) return; + clip.g_x -= work.g_x; + clip.g_y -= work.g_y; + if( clip.g_x < 0 ) { + clip.g_w = work.g_w + clip.g_x; + clip.g_x = 0; + } + if( clip.g_y < 0 ) { + clip.g_h = work.g_h + clip.g_y; + clip.g_y = 0; + } + if( clip.g_h > 0 && clip.g_w > 0 ) { + + GRECT rdrw_area; + + rdrw_area.g_x = (slid->x_pos*slid->x_unit_px) + clip.g_x; + rdrw_area.g_y =(slid->y_pos*slid->y_unit_px) + clip.g_y; + rdrw_area.g_w = clip.g_w; + rdrw_area.g_h = clip.g_h; + + atari_treeview_redraw_grect_request(tptr, &rdrw_area); + } +} + +static void __CDECL on_mbutton_event(ATARI_TREEVIEW_PTR tptr, EVMULT_OUT *ev_out, + short msg[8]) +{ + struct atari_treeview_window * tv = tptr; + struct gemtk_wm_scroll_info_s *slid; + GRECT work; + short mx, my; + int bms; + bool ignore=false; + short cur_rel_x, cur_rel_y, dummy, mbut; + + if(tv == NULL) + return; + + gemtk_wm_get_grect(tv->window, GEMTK_WM_AREA_CONTENT, &work); + slid = gemtk_wm_get_scroll_info(tv->window); + mx = ev_out->emo_mouse.p_x; + my = ev_out->emo_mouse.p_y; + + /* mouse click relative origin: */ + + short origin_rel_x = (mx-work.g_x) + + (slid->x_pos*slid->x_unit_px); + short origin_rel_y = (my-work.g_y) + + (slid->y_pos*slid->y_unit_px); + + /* Only pass on events in the content area: */ + if( origin_rel_x >= 0 && origin_rel_y >= 0 + && mx < work.g_x + work.g_w + && my < work.g_y + work.g_h ) + { + if (ev_out->emo_mclicks == 2) { + tv->io->mouse_action(tv, + BROWSER_MOUSE_CLICK_1|BROWSER_MOUSE_DOUBLE_CLICK, + origin_rel_x, origin_rel_y); + return; + } + graf_mkstate(&cur_rel_x, &cur_rel_y, &mbut, &dummy); + /* check for click or hold: */ + if( (mbut&1) == 0 ){ + bms = BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_PRESS_1; + if(ev_out->emo_mclicks == 2 ) { + bms = BROWSER_MOUSE_DOUBLE_CLICK; + } + tv->io->mouse_action(tv, bms, origin_rel_x, origin_rel_y); + } else { + /* button still pressed */ + short prev_x = origin_rel_x; + short prev_y = origin_rel_y; + + cur_rel_x = origin_rel_x; + cur_rel_y = origin_rel_y; + + gem_set_cursor(&gem_cursors.hand); + + tv->startdrag.x = origin_rel_x; + tv->startdrag.y = origin_rel_y; + + tv->io->mouse_action(tv, BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_ON, + cur_rel_x, cur_rel_y); + do{ + if (abs(prev_x-cur_rel_x) > 5 || abs(prev_y-cur_rel_y) > 5) { + tv->io->mouse_action(tv, + BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_ON, + cur_rel_x, cur_rel_y); + prev_x = cur_rel_x; + prev_y = cur_rel_y; + } + + if (tv->redraw) { + // TODO: maybe GUI poll would fit better here? + // ... is gui_poll re-entrance save? + atari_treeview_redraw(tv); + } + + /* sample mouse button state: */ + graf_mkstate(&cur_rel_x, &cur_rel_y, &mbut, &dummy); + cur_rel_x = (cur_rel_x-work.g_x)+(slid->x_pos*slid->x_unit_px); + cur_rel_y = (cur_rel_y-work.g_y)+(slid->y_pos*slid->y_unit_px); + } while( mbut & 1 ); + + /* End drag: */ + tv->io->mouse_action(tv, BROWSER_MOUSE_HOVER, cur_rel_x, cur_rel_y); + gem_set_cursor(&gem_cursors.arrow); + } + } } @@ -97,15 +446,10 @@ struct atari_treeview_window * atari_treeview_create(GUIWIN *win, struct atari_treeview_callbacks * callbacks, uint32_t flags) { -/* - init_func(); - - sslcert_viewer_init(&cw_t, (struct core_window *)tree, - ssl_current_session); -*/ /* allocate the core_window struct: */ struct atari_treeview_window * cw; + struct gemtk_wm_scroll_info_s *slid; cw = calloc(sizeof(struct atari_treeview_window), 1); if (cw == NULL) { @@ -114,9 +458,24 @@ atari_treeview_create(GUIWIN *win, struct atari_treeview_callbacks * callbacks, return NULL; } + /* Store the window ref inside the new treeview: */ cw->window = win; cw->io = callbacks; + // Setup gemtk event handler function: + gemtk_wm_set_event_handler(win, handle_event); + + // bind window user data to treeview ref: + gemtk_wm_set_user_data(win, (void*)cw); + + // Get acces to the gemtk scroll info struct: + slid = gemtk_wm_get_scroll_info(cw->window); + + // Setup line and column height/width of the window, + // each scroll takes the configured steps: + slid->y_unit_px = 16; + slid->x_unit_px = 16; + assert(cw->io); assert(cw->io->init); @@ -145,7 +504,6 @@ void atari_treeview_delete(struct atari_treeview_window * cw) * Core Window Callbacks: */ - /** * Request a redraw of the window * @@ -158,27 +516,7 @@ void atari_treeview_redraw_request(struct core_window *cw, const struct rect *r) RECT_TO_GRECT(r, &area) - if (cw != NULL) { - ATARI_TREEVIEW tv = (ATARI_TREEVIEW) cw; - if( tv->redraw == false ){ - tv->redraw = true; - tv->rdw_area.g_x = area.g_x; - tv->rdw_area.g_y = area.g_y; - tv->rdw_area.g_w = area.g_w; - tv->rdw_area.g_h = area.g_h; - } else { - /* merge the redraw area to the new area.: */ - int newx1 = area.g_x+area.g_w; - int newy1 = area.g_y+area.g_h; - int oldx1 = tv->rdw_area.g_x + tv->rdw_area.g_w; - int oldy1 = tv->rdw_area.g_y + tv->rdw_area.g_h; - tv->rdw_area.g_x = MIN(tv->rdw_area.g_x, area.g_x); - tv->rdw_area.g_y = MIN(tv->rdw_area.g_y, area.g_y); - tv->rdw_area.g_w = ( oldx1 > newx1 ) ? oldx1 - tv->rdw_area.g_x : newx1 - tv->rdw_area.g_x; - tv->rdw_area.g_h = ( oldy1 > newy1 ) ? oldy1 - tv->rdw_area.g_y : newy1 - tv->rdw_area.g_y; - } - // dbg_grect("atari_treeview_request_redraw", &tv->rdw_area); - } + atari_treeview_redraw_grect_request(cw, &area); } /** diff --git a/atari/treeview.h b/atari/treeview.h index f8e4c4264..a6a59acd2 100644 --- a/atari/treeview.h +++ b/atari/treeview.h @@ -19,19 +19,38 @@ #ifndef NSATARI_TREEVIEW_H #define NSATARI_TREEVIEW_H +#include "atari/gui.h" +#include "atari/gemtk/gemtk.h" + +#define ATARI_TREEVIEW_WIDGETS (CLOSER | MOVER | SIZER| NAME | FULLER | \ + SMALLER | VSLIDE | HSLIDE | UPARROW | DNARROW \ + | LFARROW | RTARROW) + + +struct core_window; +struct atari_treeview_window; +typedef struct atari_treeview_window *ATARI_TREEVIEW_PTR; + +typedef void (*atari_treeview_keypress_callback)(struct core_window *cw, + long ucs4); +typedef void (*atari_treeview_mouse_action_callback)(struct core_window *cw, + browser_mouse_state mouse, + int x, int y); +typedef void (*atari_treeview_draw_callback)(struct core_window *cw, int x, + int y, int clip_x, int clip_y, + int clip_width, int clip_height, + const struct redraw_context *ctx); + struct atari_treeview_callbacks { nserror (*init)(struct core_window *cw, struct core_window_callback_table * default_callbacks); void (*fini)(struct core_window *cw); - void (*draw)(struct core_window *cw); - void (*keypress)(struct core_window *cw); - void (*mouse)(struct core_window *cw); + atari_treeview_draw_callback draw; + atari_treeview_keypress_callback keypress; + atari_treeview_mouse_action_callback mouse_action; gemtk_wm_event_handler_f gemtk_user_func; }; -struct atari_treeview_callbacks; -struct atari_treeview_window; - struct atari_treeview_window * atari_treeview_create(GUIWIN *win, struct atari_treeview_callbacks * callbacks, uint32_t flags); -- cgit v1.2.3