2013-09-16 04:26:43 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
2012-11-21 05:14:22 +04:00
|
|
|
*/
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <sys/types.h>
|
2012-11-21 05:14:22 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
|
|
|
|
#include "assert.h"
|
|
|
|
#include "cflib.h"
|
|
|
|
|
|
|
|
#include "utils/nsoption.h"
|
2012-11-21 05:14:22 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "desktop/browser.h"
|
|
|
|
#include "desktop/plotters.h"
|
2013-09-16 04:26:43 +04:00
|
|
|
#include "desktop/mouse.h"
|
|
|
|
#include "desktop/treeview.h"
|
2012-11-21 05:14:22 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/plot/plot.h"
|
2012-11-20 03:29:20 +04:00
|
|
|
#include "atari/misc.h"
|
2012-11-21 05:14:22 +04:00
|
|
|
#include "atari/gemtk/gemtk.h"
|
2013-09-16 04:26:43 +04:00
|
|
|
#include "atari/treeview.h"
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
/**
|
|
|
|
* Declare Core Window Callbacks:
|
|
|
|
*/
|
|
|
|
|
|
|
|
void atari_treeview_redraw_request(struct core_window *cw,
|
|
|
|
const struct rect *r);
|
|
|
|
void atari_treeview_update_size(struct core_window *cw, int width, int height);
|
|
|
|
void atari_treeview_scroll_visible(struct core_window *cw,
|
|
|
|
const struct rect *r);
|
|
|
|
void atari_treeview_get_window_dimensions(struct core_window *cw,
|
|
|
|
int *width, int *height);
|
|
|
|
void atari_treeview_drag_status(struct core_window *cw,
|
|
|
|
core_window_drag_status ds);
|
|
|
|
|
|
|
|
|
|
|
|
static struct core_window_callback_table cw_t = {
|
|
|
|
.redraw_request = atari_treeview_redraw_request,
|
|
|
|
.update_size = atari_treeview_update_size,
|
|
|
|
.scroll_visible = atari_treeview_scroll_visible,
|
|
|
|
.get_window_dimensions = atari_treeview_get_window_dimensions,
|
|
|
|
.drag_status = atari_treeview_drag_status
|
2012-11-20 03:29:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
struct atari_treeview_window {
|
|
|
|
GUIWIN * window;
|
|
|
|
bool disposing;
|
|
|
|
bool redraw;
|
2013-09-21 07:29:04 +04:00
|
|
|
bool is_open;
|
2013-09-16 04:26:43 +04:00
|
|
|
GRECT rdw_area;
|
|
|
|
POINT extent;
|
|
|
|
POINT click;
|
|
|
|
POINT startdrag;
|
|
|
|
struct atari_treeview_callbacks *io;
|
|
|
|
};
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
/* native GUI event handlers: */
|
2013-09-21 07:29:04 +04:00
|
|
|
static void on_mbutton_event(struct atari_treeview_window *tvw,
|
2013-09-16 04:26:43 +04:00
|
|
|
EVMULT_OUT *ev_out, short msg[8]);
|
2013-09-21 07:29:04 +04:00
|
|
|
static void on_keybd_event(struct atari_treeview_window *tvw,
|
2013-09-16 04:26:43 +04:00
|
|
|
EVMULT_OUT *ev_out, short msg[8]);
|
2013-09-21 07:29:04 +04:00
|
|
|
static void on_redraw_event(struct atari_treeview_window *tvw,
|
2013-09-16 04:26:43 +04:00
|
|
|
EVMULT_OUT *ev_out, short msg[8]);
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
/* static utils: */
|
|
|
|
static void atari_treeview_dump_info(struct atari_treeview_window *tv, char *s);
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2013-09-21 07:29:04 +04:00
|
|
|
//dbg_grect("atari_treeview_request_redraw_grect", &tv->rdw_area);
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_treeview_get_grect(ATARI_TREEVIEW_PTR tptr, enum treeview_area_e mode,
|
2013-09-17 04:10:35 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
GUIWIN * atari_treeview_get_gemtk_window(struct atari_treeview_window *tv)
|
2013-09-17 04:10:35 +04:00
|
|
|
{
|
2013-09-21 07:29:04 +04:00
|
|
|
return(tv->window);
|
|
|
|
}
|
2013-09-17 04:10:35 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
static void atari_treeview_dump_info(struct atari_treeview_window *tv,
|
|
|
|
char * title)
|
|
|
|
{
|
|
|
|
printf("Treeview Dump (%s)\n", title);
|
|
|
|
printf("=================================\n");
|
|
|
|
gemtk_wm_dump_window_info(atari_treeview_get_gemtk_window(tv));
|
|
|
|
GEMTK_DBG_GRECT("Redraw Area: \n", &tv->rdw_area)
|
|
|
|
dbg_grect("Redraw Area2: \n", &tv->rdw_area);
|
|
|
|
printf("Extent: x: %d, y: %d\n", tv->extent, tv->extent);
|
|
|
|
}
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_treeview_redraw(struct atari_treeview_window *tv)
|
|
|
|
{
|
|
|
|
if (tv != NULL && tv->is_open) {
|
|
|
|
if( tv->redraw && ((plot_get_flags() & PLOT_FLAG_OFFSCREEN) == 0) ) {
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
short todo[4];
|
|
|
|
GRECT work;
|
|
|
|
short handle = gemtk_wm_get_handle(tv->window);
|
|
|
|
struct gemtk_wm_scroll_info_s *slid;
|
|
|
|
|
|
|
|
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;
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
if( wind_get(handle, WF_FIRSTXYWH,
|
|
|
|
&todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
|
|
|
|
while (todo[2] && todo[3]) {
|
|
|
|
|
|
|
|
short pxy[4];
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
if(!rc_intersect(&work, (GRECT*)&todo)){
|
|
|
|
if (wind_get(handle, WF_NEXTXYWH,
|
|
|
|
&todo[0], &todo[1], &todo[2], &todo[3])==0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-17 04:10:35 +04:00
|
|
|
pxy[0] = todo[0];
|
|
|
|
pxy[1] = todo[1];
|
|
|
|
pxy[2] = todo[0] + todo[2]-1;
|
|
|
|
pxy[3] = todo[1] + todo[3]-1;
|
2013-09-21 07:29:04 +04:00
|
|
|
vs_clip(plot_get_vdi_handle(), 1, (short*)&pxy);
|
|
|
|
|
|
|
|
// Debug code: this 3 lines help to inspect the redraw
|
|
|
|
// areas...
|
|
|
|
/*
|
|
|
|
vsf_color(plot_get_vdi_handle(), 3);
|
|
|
|
v_bar(plot_get_vdi_handle(), (short*)&pxy);
|
|
|
|
evnt_timer(500);
|
|
|
|
*/
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
/* convert screen to treeview coords: */
|
2013-09-21 07:29:04 +04:00
|
|
|
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;
|
2013-09-17 04:10:35 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
// TODO: get slider values
|
2013-09-17 04:10:35 +04:00
|
|
|
if (rc_intersect((GRECT *)&tv->rdw_area,(GRECT *)&todo)) {
|
2013-09-21 07:29:04 +04:00
|
|
|
struct rect clip;
|
|
|
|
|
|
|
|
clip.x0 = todo[0]+(slid->x_pos*slid->x_unit_px);
|
|
|
|
clip.y0 = todo[1]+(slid->y_pos*slid->y_unit_px);
|
|
|
|
clip.x1 = clip.x0 + todo[2]+(slid->x_pos*slid->x_unit_px);
|
|
|
|
clip.y1 = clip.y0 + todo[3]+(slid->y_pos*slid->y_unit_px);
|
|
|
|
|
|
|
|
tv->io->draw(tv, -(slid->x_pos*slid->x_unit_px),
|
2013-09-17 04:10:35 +04:00
|
|
|
-(slid->y_pos*slid->y_unit_px),
|
2013-09-21 07:29:04 +04:00
|
|
|
&clip, &ctx);
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
2013-09-21 07:29:04 +04:00
|
|
|
vs_clip(plot_get_vdi_handle(), 0, (short*)&pxy);
|
2013-09-17 04:10:35 +04:00
|
|
|
if (wind_get(handle, WF_NEXTXYWH,
|
|
|
|
&todo[0], &todo[1], &todo[2], &todo[3])==0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
plot_unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
//
|
|
|
|
//// TODO: rename to atari_treeview_draw_content
|
|
|
|
//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;
|
|
|
|
// short pxy[4];
|
|
|
|
// struct rect clip;
|
|
|
|
//
|
|
|
|
// /* TODO: do not use the global vdi handle for plot actions! */
|
|
|
|
// /* TODO: implement getter/setter for the vdi handle */
|
|
|
|
//
|
|
|
|
// if (tv != NULL && tv->is_open) {
|
|
|
|
// if( tv->redraw && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
|
|
|
|
//
|
|
|
|
// atari_treeview_dump_info(tv, "atari_treeview_redraw");
|
|
|
|
//
|
|
|
|
// 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]) {
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// clip.x0 = todo[0];
|
|
|
|
// clip.y0 = todo[1];
|
|
|
|
// clip.x1 = clip.x0 + todo[2];
|
|
|
|
// clip.y1 = clip.y0 + todo[3];
|
|
|
|
//
|
|
|
|
// clip.x0 = todo[0];
|
|
|
|
// clip.y0 = todo[1];
|
|
|
|
// clip.x1 = clip.x0 + todo[2] ;
|
|
|
|
// clip.y1 = clip.y0 + todo[3] ;
|
|
|
|
///*
|
|
|
|
// clip.x0 = 0;
|
|
|
|
// clip.y0 = 0;
|
|
|
|
// clip.x1 = work.g_w;//MAX(tv->extent.x, work.g_w);
|
|
|
|
// clip.y1 = MAX(tv->extent.y, work.g_h)+200;
|
|
|
|
//*/
|
|
|
|
// dbg_rect("treeview redraw clip", &clip);
|
|
|
|
//
|
|
|
|
// 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), &clip,
|
|
|
|
// &ctx);
|
|
|
|
//
|
|
|
|
// /*tv->io->draw(tv, 0,0, &clip,
|
|
|
|
// &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 */
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GEMTK event sink
|
|
|
|
*
|
|
|
|
*/
|
2013-09-16 04:26:43 +04:00
|
|
|
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2013-09-17 04:10:35 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
if(tv != NULL && tv->io->gemtk_user_func != NULL){
|
|
|
|
tv->io->gemtk_user_func(win, ev_out, msg);
|
2013-09-17 04:10:35 +04:00
|
|
|
}
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
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);
|
2013-09-21 07:29:04 +04:00
|
|
|
//dbg_grect("treeview work: ", &work);
|
|
|
|
|
|
|
|
atari_treeview_get_grect(tv, TREEVIEW_AREA_CONTENT, &work);
|
|
|
|
//dbg_grect("treeview work: ", &work);
|
2013-09-17 04:10:35 +04:00
|
|
|
slid = gemtk_wm_get_scroll_info(tv->window);
|
|
|
|
|
|
|
|
clip = work;
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
/* check if the redraw area intersects with the content area: */
|
|
|
|
if ( !rc_intersect( (GRECT*)&msg[4], &clip)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make redraw coords relative to content viewport */
|
2013-09-17 04:10:35 +04:00
|
|
|
clip.g_x -= work.g_x;
|
|
|
|
clip.g_y -= work.g_y;
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
/* normalize the redraw coords: */
|
2013-09-17 04:10:35 +04:00
|
|
|
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;
|
|
|
|
}
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
/* Merge redraw coords: */
|
2013-09-17 04:10:35 +04:00
|
|
|
if( clip.g_h > 0 && clip.g_w > 0 ) {
|
|
|
|
|
|
|
|
GRECT rdrw_area;
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
rdrw_area.g_x = clip.g_x;
|
|
|
|
rdrw_area.g_y = clip.g_y;
|
2013-09-17 04:10:35 +04:00
|
|
|
rdrw_area.g_w = clip.g_w;
|
|
|
|
rdrw_area.g_h = clip.g_h;
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
//dbg_grect("treeview on_redraw_event ", &rdrw_area);
|
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
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;
|
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
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;
|
2013-09-21 07:29:04 +04:00
|
|
|
/* First, report mouse press, to trigger entry selection */
|
|
|
|
tv->io->mouse_action(tv, BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_PRESS_1, cur_rel_x,
|
|
|
|
cur_rel_y);
|
|
|
|
atari_treeview_redraw(tv);
|
2013-09-17 04:10:35 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
2013-09-11 01:52:56 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
struct atari_treeview_window *
|
|
|
|
atari_treeview_create(GUIWIN *win, struct atari_treeview_callbacks * callbacks,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
2013-09-11 01:52:56 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
/* allocate the core_window struct: */
|
|
|
|
struct atari_treeview_window * cw;
|
2013-09-17 04:10:35 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid;
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
cw = calloc(sizeof(struct atari_treeview_window), 1);
|
|
|
|
if (cw == NULL) {
|
|
|
|
LOG(("calloc failed"));
|
|
|
|
warn_user(messages_get_errorcode(NSERROR_NOMEM), 0);
|
2013-09-11 02:10:59 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
/* Store the window ref inside the new treeview: */
|
2013-09-16 04:26:43 +04:00
|
|
|
cw->window = win;
|
|
|
|
cw->io = callbacks;
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-17 04:10:35 +04:00
|
|
|
// 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;
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
assert(cw->io);
|
2013-09-21 07:29:04 +04:00
|
|
|
assert(cw->io->init_phase2);
|
|
|
|
|
|
|
|
/* Now that the window is configured for treeview content, */
|
|
|
|
/* call init_phase2 which must create the treeview */
|
|
|
|
/* descriptor, and at least setup the the default */
|
|
|
|
/* event handlers of the treeview: */
|
|
|
|
/* It would be more simple to not pass around the callbacks */
|
|
|
|
/* but the treeview constructor requires them for initialization... */
|
|
|
|
nserror err = cw->io->init_phase2(cw, &cw_t);
|
2013-09-16 04:26:43 +04:00
|
|
|
if (err != NSERROR_OK) {
|
|
|
|
free(cw);
|
|
|
|
cw = NULL;
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
return(cw);
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
void atari_treeview_delete(struct atari_treeview_window * cw)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2013-09-16 04:26:43 +04:00
|
|
|
assert(cw);
|
2013-09-21 07:29:04 +04:00
|
|
|
assert(cw->io->finish);
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
cw->io->finish(cw);
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
free(cw);
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_treeview_open(struct atari_treeview_window *cw, GRECT *pos)
|
|
|
|
{
|
|
|
|
if (cw->window != NULL) {
|
|
|
|
cw->is_open = true;
|
|
|
|
wind_open_grect(gemtk_wm_get_handle(cw->window), pos);
|
|
|
|
gemtk_wm_link(cw->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool atari_treeview_is_open(struct atari_treeview_window *cw)
|
|
|
|
{
|
|
|
|
return(cw->is_open);
|
|
|
|
}
|
|
|
|
|
|
|
|
void atari_treeview_close(struct atari_treeview_window *cw)
|
|
|
|
{
|
|
|
|
if (cw->window != NULL) {
|
|
|
|
cw->is_open = false;
|
|
|
|
wind_close(gemtk_wm_get_handle(cw->window));
|
|
|
|
gemtk_wm_unlink(cw->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
/**
|
|
|
|
* Core Window Callbacks:
|
|
|
|
*/
|
2012-11-21 05:14:22 +04:00
|
|
|
|
|
|
|
/**
|
2013-09-16 04:26:43 +04:00
|
|
|
* Request a redraw of the window
|
2012-11-21 05:14:22 +04:00
|
|
|
*
|
2013-09-16 04:26:43 +04:00
|
|
|
* \param cw the core window object
|
|
|
|
* \param r rectangle to redraw
|
2012-11-21 05:14:22 +04:00
|
|
|
*/
|
2013-09-16 04:26:43 +04:00
|
|
|
void atari_treeview_redraw_request(struct core_window *cw, const struct rect *r)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2013-09-16 04:26:43 +04:00
|
|
|
GRECT area;
|
2013-09-21 07:29:04 +04:00
|
|
|
struct gemtk_wm_scroll_info_s * slid;
|
|
|
|
struct atari_treeview_window * tv = (cw);
|
2013-09-16 04:26:43 +04:00
|
|
|
|
|
|
|
RECT_TO_GRECT(r, &area)
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
slid = gemtk_wm_get_scroll_info(tv->window);
|
|
|
|
|
|
|
|
//dbg_rect("redraw rect request", r);
|
|
|
|
|
|
|
|
// treeview redraw is always full window width:
|
|
|
|
area.g_x = 0;
|
|
|
|
area.g_w = area.g_w;
|
|
|
|
// but vertical redraw region is clipped:
|
|
|
|
area.g_y = r->y0 - (slid->y_pos*slid->y_unit_px);
|
|
|
|
area.g_h = r->y1 - r->y0;
|
2013-09-17 04:10:35 +04:00
|
|
|
atari_treeview_redraw_grect_request(cw, &area);
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-16 04:26:43 +04:00
|
|
|
* Update the limits of the window
|
2012-11-21 05:14:22 +04:00
|
|
|
*
|
2013-09-16 04:26:43 +04:00
|
|
|
* \param cw the core window object
|
|
|
|
* \param width the width in px, or negative if don't care
|
|
|
|
* \param height the height in px, or negative if don't care
|
2012-11-21 05:14:22 +04:00
|
|
|
*/
|
2013-09-16 04:26:43 +04:00
|
|
|
void atari_treeview_update_size(struct core_window *cw, int width, int height)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2013-09-21 07:29:04 +04:00
|
|
|
GRECT area;
|
|
|
|
struct gemtk_wm_scroll_info_s *slid;
|
|
|
|
struct atari_treeview_window *tv = (struct atari_treeview_window *)cw;
|
2013-09-11 02:10:59 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
if (tv != NULL) {
|
|
|
|
|
|
|
|
if (tv->disposing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get acces to the gemtk window slider settings: */
|
|
|
|
slid = gemtk_wm_get_scroll_info(tv->window);
|
|
|
|
|
|
|
|
/* recalculate and refresh sliders: */
|
|
|
|
atari_treeview_get_grect(tv, TREEVIEW_AREA_CONTENT, &area);
|
|
|
|
if (width > -1) {
|
|
|
|
slid->x_units = (width/slid->x_unit_px);
|
|
|
|
} else {
|
|
|
|
slid->x_units = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height > -1) {
|
|
|
|
slid->y_units = (height/slid->y_unit_px);
|
|
|
|
} else {
|
|
|
|
slid->y_units = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tv->extent.x = width;
|
|
|
|
tv->extent.y = height;
|
|
|
|
|
|
|
|
|
|
|
|
/*printf("units content: %d, units viewport: %d\n", (height/slid->y_unit_px),
|
|
|
|
(area.g_h/slid->y_unit_px));*/
|
|
|
|
gemtk_wm_update_slider(tv->window, GEMTK_WM_VH_SLIDER);
|
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-16 04:26:43 +04:00
|
|
|
* Scroll the window to make area visible
|
2012-11-21 05:14:22 +04:00
|
|
|
*
|
2013-09-16 04:26:43 +04:00
|
|
|
* \param cw the core window object
|
|
|
|
* \param r rectangle to make visible
|
2012-11-21 05:14:22 +04:00
|
|
|
*/
|
2013-09-16 04:26:43 +04:00
|
|
|
void atari_treeview_scroll_visible(struct core_window *cw, const struct rect *r)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2013-09-21 07:29:04 +04:00
|
|
|
/* atari frontend doesn't support dragging outside the treeview */
|
|
|
|
/* so there is no need to implement this? */
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get window viewport dimensions
|
|
|
|
*
|
|
|
|
* \param cw the core window object
|
|
|
|
* \param width to be set to viewport width in px, if non NULL
|
|
|
|
* \param height to be set to viewport height in px, if non NULL
|
|
|
|
*/
|
|
|
|
void atari_treeview_get_window_dimensions(struct core_window *cw,
|
|
|
|
int *width, int *height)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2013-09-21 07:29:04 +04:00
|
|
|
if (cw != NULL && (width != NULL || height != NULL)) {
|
|
|
|
GRECT work;
|
|
|
|
struct atari_treeview_window *tv = (struct atari_treeview_window *)cw;
|
|
|
|
atari_treeview_get_grect(tv, TREEVIEW_AREA_CONTENT, &work);
|
|
|
|
*width = work.g_w;
|
|
|
|
*height = work.g_h;
|
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
|
2013-09-16 04:26:43 +04:00
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
/**
|
2013-09-16 04:26:43 +04:00
|
|
|
* Inform corewindow owner of drag status
|
2012-11-21 05:14:22 +04:00
|
|
|
*
|
2013-09-16 04:26:43 +04:00
|
|
|
* \param cw the core window object
|
|
|
|
* \param ds the current drag status
|
2012-11-21 05:14:22 +04:00
|
|
|
*/
|
2013-09-16 04:26:43 +04:00
|
|
|
void atari_treeview_drag_status(struct core_window *cw,
|
|
|
|
core_window_drag_status ds)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2013-09-16 04:26:43 +04:00
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
2013-09-16 04:26:43 +04:00
|
|
|
|