2012-12-21 03:56:50 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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-19 02:22:43 +04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-11-20 03:29:20 +04:00
|
|
|
#include <stdbool.h>
|
2012-11-19 02:22:43 +04:00
|
|
|
#include <assert.h>
|
2012-11-27 05:12:09 +04:00
|
|
|
|
|
|
|
#include <gem.h>
|
2013-01-12 02:53:46 +04:00
|
|
|
#include <gemx.h>
|
|
|
|
#include <cflib.h>
|
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
#include "gemtk.h"
|
|
|
|
|
2013-01-15 04:54:54 +04:00
|
|
|
//#define DEBUG_PRINT(x) printf x
|
|
|
|
#define DEBUG_PRINT(x)
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_window_s {
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** The AES handle of the window */
|
2012-11-20 03:29:20 +04:00
|
|
|
short handle;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** the generic event handler function for events passed to the client */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_event_handler_f handler_func;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** The custom toolbar redraw function, if any */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_redraw_f toolbar_redraw_func;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** window configuration */
|
2012-11-20 03:29:20 +04:00
|
|
|
uint32_t flags;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** window state */
|
2012-11-20 03:29:20 +04:00
|
|
|
uint32_t state;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** AES Tree used as toolbar */
|
2012-12-31 06:37:43 +04:00
|
|
|
OBJECT *toolbar;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Current edit object selected in the toolbar, if any. */
|
2012-12-31 06:37:43 +04:00
|
|
|
short toolbar_edit_obj;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Current selected object in the toolbar, if any. */
|
|
|
|
short toolbar_focus_obj;
|
|
|
|
|
|
|
|
/** Describes the start of the toolbar tree (usually 0) */
|
2012-11-20 03:29:20 +04:00
|
|
|
short toolbar_idx;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
/** depending on the flag GEMTK_WM_FLAG_HAS_VTOOLBAR this defines the toolbar
|
|
|
|
height or the toolbar width (GEMTK_WM_FLAG_HAS_VTOOLBAR means width).
|
2013-01-15 04:31:35 +04:00
|
|
|
*/
|
|
|
|
short toolbar_size;
|
|
|
|
|
|
|
|
/** AES Object tree to be used for windowed dialogs. */
|
2012-12-31 06:37:43 +04:00
|
|
|
OBJECT *form;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Current form edit object, if any. */
|
2012-12-31 06:37:43 +04:00
|
|
|
short form_edit_obj;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Current form focus object, if any */
|
2012-12-31 06:37:43 +04:00
|
|
|
short form_focus_obj;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Describes the start of the form tree */
|
2012-12-31 06:37:43 +04:00
|
|
|
short form_idx;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Scroll state */
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s scroll_info;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** Arbitary data set by the user */
|
2012-11-20 03:29:20 +04:00
|
|
|
void *user_data;
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
/** linked list items */
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_window_s *next, *prev;
|
2012-11-19 02:22:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static GUIWIN * winlist;
|
2012-11-20 03:29:20 +04:00
|
|
|
static VdiHdl v_vdi_h = -1;
|
|
|
|
static short work_out[57];
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-27 05:12:09 +04:00
|
|
|
static void move_rect(GUIWIN * win, GRECT *rect, int dx, int dy)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
|
|
|
INT16 xy[ 8];
|
|
|
|
long dum = 0L;
|
|
|
|
GRECT g;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
VdiHdl vh = gemtk_wm_get_vdi_handle(win);
|
2012-11-27 05:12:09 +04:00
|
|
|
|
|
|
|
while(!wind_update(BEG_UPDATE));
|
2012-11-21 05:14:22 +04:00
|
|
|
graf_mouse(M_OFF, 0L);
|
|
|
|
|
|
|
|
/* get intersection with screen area */
|
|
|
|
wind_get_grect(0, WF_CURRXYWH, &g);
|
|
|
|
rc_intersect(&g, rect);
|
|
|
|
xy[0] = rect->g_x;
|
|
|
|
xy[1] = rect->g_y;
|
|
|
|
xy[2] = xy[0] + rect->g_w-1;
|
|
|
|
xy[3] = xy[1] + rect->g_h-1;
|
|
|
|
xy[4] = xy[0] + dx;
|
|
|
|
xy[5] = xy[1] + dy;
|
|
|
|
xy[6] = xy[2] + dx;
|
|
|
|
xy[7] = xy[3] + dy;
|
2012-11-27 05:12:09 +04:00
|
|
|
vro_cpyfm(vh, S_ONLY, xy, (MFDB *)&dum, (MFDB *)&dum);
|
2012-11-21 05:14:22 +04:00
|
|
|
|
|
|
|
graf_mouse(M_ON, 0L);
|
|
|
|
wind_update(END_UPDATE);
|
2012-11-20 04:41:42 +04:00
|
|
|
}
|
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
/**
|
|
|
|
* Handles common events.
|
|
|
|
* returns 0 when the event was not handled, 1 otherwise.
|
|
|
|
*/
|
2012-11-19 02:22:43 +04:00
|
|
|
static short preproc_wm(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
|
|
|
|
{
|
2012-11-22 03:26:58 +04:00
|
|
|
GRECT g, g_ro, g2;
|
2012-11-19 02:22:43 +04:00
|
|
|
short retval = 1;
|
2012-11-22 03:26:58 +04:00
|
|
|
int val = 1, old_val;
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
|
|
|
switch(msg[0]) {
|
|
|
|
|
2012-11-22 03:26:58 +04:00
|
|
|
case WM_HSLID:
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_CONTENT, &g);
|
2012-11-22 03:26:58 +04:00
|
|
|
wind_set(gw->handle, WF_HSLIDE, msg[4], 0, 0, 0);
|
2013-01-22 05:33:27 +04:00
|
|
|
slid = gemtk_wm_get_scroll_info(gw);
|
2012-11-22 03:26:58 +04:00
|
|
|
val = (float)(slid->x_units-(g.g_w/slid->x_unit_px))/1000*(float)msg[4];
|
2012-11-22 04:30:03 +04:00
|
|
|
if(val != slid->x_pos) {
|
2012-11-22 03:26:58 +04:00
|
|
|
if (val < slid->x_pos) {
|
2012-11-22 04:30:03 +04:00
|
|
|
val = -(MAX(0, slid->x_pos-val));
|
2012-12-31 06:37:43 +04:00
|
|
|
} else {
|
2012-11-22 04:30:03 +04:00
|
|
|
val = val-slid->x_pos;
|
2012-11-22 03:26:58 +04:00
|
|
|
}
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_HSLIDER, val, false);
|
2012-11-22 03:26:58 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_VSLID:
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_CONTENT, &g);
|
2012-11-22 03:26:58 +04:00
|
|
|
wind_set(gw->handle, WF_VSLIDE, msg[4], 0, 0, 0);
|
2013-01-22 05:33:27 +04:00
|
|
|
slid = gemtk_wm_get_scroll_info(gw);
|
2012-11-22 03:26:58 +04:00
|
|
|
val = (float)(slid->y_units-(g.g_h/slid->y_unit_px))/1000*(float)msg[4];
|
|
|
|
if(val != slid->y_pos) {
|
|
|
|
if (val < slid->y_pos) {
|
|
|
|
val = -(slid->y_pos - val);
|
2012-12-31 06:37:43 +04:00
|
|
|
} else {
|
2012-11-22 03:26:58 +04:00
|
|
|
val = val -slid->y_pos;
|
|
|
|
}
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_VSLIDER, val, false);
|
2012-11-22 03:26:58 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-11-20 04:41:42 +04:00
|
|
|
case WM_ARROWED:
|
2013-01-22 05:33:27 +04:00
|
|
|
if((gw->flags & GEMTK_WM_FLAG_CUSTOM_SCROLLING) == 0) {
|
2012-11-20 04:41:42 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
slid = gemtk_wm_get_scroll_info(gw);
|
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_CONTENT, &g);
|
2012-11-20 04:41:42 +04:00
|
|
|
g_ro = g;
|
|
|
|
|
|
|
|
switch(msg[4]) {
|
|
|
|
|
2012-11-22 03:26:58 +04:00
|
|
|
case WA_UPPAGE:
|
|
|
|
/* scroll page up */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_VSLIDER, -(g.g_h/slid->y_unit_px),
|
2012-12-31 06:37:43 +04:00
|
|
|
true);
|
2012-11-22 03:26:58 +04:00
|
|
|
break;
|
2012-11-20 04:41:42 +04:00
|
|
|
|
|
|
|
case WA_UPLINE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll line up */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_VSLIDER, -1, true);
|
2012-11-20 04:41:42 +04:00
|
|
|
break;
|
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
case WA_DNPAGE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll page down */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_VSLIDER, g.g_h/slid->y_unit_px,
|
2012-12-31 06:37:43 +04:00
|
|
|
true);
|
2012-11-20 04:41:42 +04:00
|
|
|
break;
|
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
case WA_DNLINE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll line down */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_VSLIDER, +1, true);
|
2012-11-20 04:41:42 +04:00
|
|
|
break;
|
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
case WA_LFPAGE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll page left */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_HSLIDER, -(g.g_w/slid->x_unit_px),
|
2012-12-31 06:37:43 +04:00
|
|
|
true);
|
2012-11-20 04:41:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WA_LFLINE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll line left */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_HSLIDER, -1,
|
2012-12-31 06:37:43 +04:00
|
|
|
true);
|
2012-11-20 04:41:42 +04:00
|
|
|
break;
|
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
case WA_RTPAGE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll page right */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_HSLIDER, (g.g_w/slid->x_unit_px),
|
2012-12-31 06:37:43 +04:00
|
|
|
true);
|
2012-11-22 03:26:58 +04:00
|
|
|
break;
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2012-11-20 04:41:42 +04:00
|
|
|
case WA_RTLINE:
|
2012-11-22 03:26:58 +04:00
|
|
|
/* scroll line right */
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_scroll(gw, GEMTK_WM_HSLIDER, 1,
|
2012-12-31 06:37:43 +04:00
|
|
|
true);
|
2012-11-20 04:41:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
case WM_TOPPED:
|
|
|
|
wind_set(gw->handle, WF_TOP, 1, 0, 0, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_MOVED:
|
|
|
|
wind_get_grect(gw->handle, WF_CURRXYWH, &g);
|
|
|
|
wind_set(gw->handle, WF_CURRXYWH, msg[4], msg[5], g.g_w, g.g_h);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
if (gw->form) {
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_CONTENT, &g);
|
|
|
|
slid = gemtk_wm_get_scroll_info(gw);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
gw->form[gw->form_idx].ob_x = g.g_x -
|
|
|
|
(slid->x_pos * slid->x_unit_px);
|
|
|
|
|
|
|
|
gw->form[gw->form_idx].ob_y = g.g_y -
|
|
|
|
(slid->y_pos * slid->y_unit_px);
|
|
|
|
}
|
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
break;
|
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_SIZED:
|
2012-11-19 02:22:43 +04:00
|
|
|
case WM_REPOSED:
|
2012-12-31 06:37:43 +04:00
|
|
|
wind_get_grect(gw->handle, WF_FULLXYWH, &g2);
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_get_grect(gw->handle, WF_CURRXYWH, &g);
|
2012-12-21 03:56:50 +04:00
|
|
|
g.g_w = MIN(msg[6], g2.g_w);
|
|
|
|
g.g_h = MIN(msg[7], g2.g_h);
|
2012-12-31 06:37:43 +04:00
|
|
|
if(g2.g_w != g.g_w || g2.g_h != g.g_h) {
|
|
|
|
wind_set(gw->handle, WF_CURRXYWH, g.g_x, g.g_y, g.g_w, g.g_h);
|
2013-01-22 05:33:27 +04:00
|
|
|
if((gw->flags & GEMTK_WM_FLAG_CUSTOM_SCROLLING) == 0) {
|
|
|
|
if(gemtk_wm_update_slider(gw, GEMTK_WM_VH_SLIDER)) {
|
|
|
|
gemtk_wm_send_redraw(gw, NULL);
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
2012-12-21 03:56:50 +04:00
|
|
|
|
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_FULLED:
|
2013-01-10 04:31:36 +04:00
|
|
|
wind_get_grect(DESKTOP_HANDLE, WF_WORKXYWH, &g);
|
2012-11-22 03:26:58 +04:00
|
|
|
wind_get_grect(gw->handle, WF_CURRXYWH, &g2);
|
2012-12-31 06:37:43 +04:00
|
|
|
if(g.g_w == g2.g_w && g.g_h == g2.g_h) {
|
2012-11-22 03:26:58 +04:00
|
|
|
wind_get_grect(gw->handle, WF_PREVXYWH, &g);
|
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_set_grect(gw->handle, WF_CURRXYWH, &g);
|
2013-01-22 05:33:27 +04:00
|
|
|
if((gw->flags & GEMTK_WM_FLAG_CUSTOM_SCROLLING) == 0) {
|
|
|
|
if(gemtk_wm_update_slider(gw, GEMTK_WM_VH_SLIDER)) {
|
|
|
|
gemtk_wm_send_redraw(gw, NULL);
|
2012-11-22 03:26:58 +04:00
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_ICONIFY:
|
|
|
|
wind_set(gw->handle, WF_ICONIFY, msg[4], msg[5], msg[6], msg[7]);
|
2013-01-22 05:33:27 +04:00
|
|
|
gw->state |= GEMTK_WM_STATUS_ICONIFIED;
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_UNICONIFY:
|
|
|
|
wind_set(gw->handle, WF_UNICONIFY, msg[4], msg[5], msg[6], msg[7]);
|
2013-01-22 05:33:27 +04:00
|
|
|
gw->state &= ~(GEMTK_WM_STATUS_ICONIFIED);
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_SHADED:
|
2013-01-22 05:33:27 +04:00
|
|
|
gw->state |= GEMTK_WM_STATUS_SHADED;
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_UNSHADED:
|
2013-01-22 05:33:27 +04:00
|
|
|
gw->state &= ~(GEMTK_WM_STATUS_SHADED);
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
case WM_REDRAW:
|
2013-01-22 05:33:27 +04:00
|
|
|
if ((gw->flags & GEMTK_WM_FLAG_CUSTOM_TOOLBAR) == 0) {
|
2012-11-22 03:26:58 +04:00
|
|
|
g.g_x = msg[4];
|
|
|
|
g.g_y = msg[5];
|
|
|
|
g.g_w = msg[6];
|
|
|
|
g.g_h = msg[7];
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_toolbar_redraw(gw, WM_REDRAW, &g);
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
if (gw->form != NULL) {
|
|
|
|
g.g_x = msg[4];
|
|
|
|
g.g_y = msg[5];
|
|
|
|
g.g_w = msg[6];
|
|
|
|
g.g_h = msg[7];
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_form_redraw(gw, &g);
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
break;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
|
|
|
default:
|
2012-11-20 03:29:20 +04:00
|
|
|
retval = 0;
|
2012-11-19 02:22:43 +04:00
|
|
|
break;
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Preprocess mouse events
|
|
|
|
*/
|
2012-12-31 06:37:43 +04:00
|
|
|
static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
|
|
|
|
{
|
2013-01-15 04:31:35 +04:00
|
|
|
short retval = 0, obj_idx = 0;
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
DEBUG_PRINT(("preproc_mu_button\n"));
|
|
|
|
|
|
|
|
// toolbar handling:
|
2013-01-22 05:33:27 +04:00
|
|
|
if ((gw->flags & GEMTK_WM_FLAG_CUSTOM_TOOLBAR) == 0
|
2012-12-31 06:37:43 +04:00
|
|
|
&& gw->toolbar != NULL) {
|
|
|
|
|
|
|
|
GRECT tb_area;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_TOOLBAR, &tb_area);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
if (POINT_WITHIN(ev_out->emo_mouse.p_x,
|
|
|
|
ev_out->emo_mouse.p_y, tb_area)) {
|
2013-01-15 04:31:35 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
gw->toolbar[gw->toolbar_idx].ob_x = tb_area.g_x;
|
|
|
|
gw->toolbar[gw->toolbar_idx].ob_y = tb_area.g_y;
|
2013-01-15 04:31:35 +04:00
|
|
|
obj_idx = objc_find(gw->toolbar,
|
2012-12-31 06:37:43 +04:00
|
|
|
gw->toolbar_idx, 8,
|
|
|
|
ev_out->emo_mouse.p_x,
|
|
|
|
ev_out->emo_mouse.p_y);
|
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
gw->toolbar_focus_obj = obj_idx;
|
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
DEBUG_PRINT(("Toolbar index: %d\n", obj_idx));
|
2013-01-15 04:31:35 +04:00
|
|
|
if (obj_idx > -1
|
|
|
|
&& (gw->toolbar[obj_idx].ob_state & OS_DISABLED)== 0
|
2013-01-22 05:33:27 +04:00
|
|
|
&& ((gw->flags & GEMTK_WM_FLAG_CUSTOM_TOOLBAR) == 0)) {
|
2013-01-15 04:31:35 +04:00
|
|
|
|
|
|
|
uint16_t type = (gw->toolbar[obj_idx].ob_type & 0xFF);
|
|
|
|
uint16_t nextobj;
|
|
|
|
|
2013-01-17 04:18:27 +04:00
|
|
|
DEBUG_PRINT(("toolbar item type: %d\n", type));
|
2013-01-15 04:31:35 +04:00
|
|
|
// report mouse click to the tree:
|
|
|
|
retval = form_wbutton(gw->toolbar, gw->toolbar_focus_obj,
|
|
|
|
ev_out->emo_mclicks, &nextobj,
|
|
|
|
gw->handle);
|
|
|
|
if (nextobj == obj_idx
|
|
|
|
&& (type == G_FTEXT || type == G_FBOXTEXT)) {
|
|
|
|
gw->toolbar_edit_obj = obj_idx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gw->toolbar_edit_obj = -1;
|
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
// send WM_TOOLBAR message
|
2012-12-31 06:37:43 +04:00
|
|
|
short oldevents = ev_out->emo_events;
|
|
|
|
short msg_out[8] = {WM_TOOLBAR, gl_apid,
|
|
|
|
0, gw->handle,
|
|
|
|
obj_idx, ev_out->emo_mclicks,
|
2013-01-11 00:09:21 +04:00
|
|
|
ev_out->emo_kmeta, ev_out->emo_mbutton
|
2012-12-31 06:37:43 +04:00
|
|
|
};
|
|
|
|
ev_out->emo_events = MU_MESAG;
|
|
|
|
// notify the window about toolbar click:
|
|
|
|
gw->handler_func(gw, ev_out, msg_out);
|
|
|
|
ev_out->emo_events = oldevents;
|
|
|
|
retval = 1;
|
2013-01-16 06:21:35 +04:00
|
|
|
} else {
|
|
|
|
if (gw->toolbar_edit_obj != -1) {
|
|
|
|
gw->toolbar_edit_obj = -1;
|
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gw->form != NULL) {
|
|
|
|
|
|
|
|
GRECT content_area;
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid;
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
DEBUG_PRINT(("preproc_mu_button: handling form click.\n"));
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_CONTENT, &content_area);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
if (POINT_WITHIN(ev_out->emo_mouse.p_x,
|
|
|
|
ev_out->emo_mouse.p_y, content_area)) {
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
slid = gemtk_wm_get_scroll_info(gw);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
// adjust form position (considering window and scroll position):
|
2012-12-31 06:37:43 +04:00
|
|
|
gw->form[gw->form_idx].ob_x = content_area.g_x -
|
|
|
|
(slid->x_pos * slid->x_unit_px);
|
|
|
|
gw->form[gw->form_idx].ob_y = content_area.g_y -
|
|
|
|
(slid->y_pos * slid->y_unit_px);
|
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
obj_idx = objc_find(gw->form, gw->form_idx, 8,
|
2012-12-31 06:37:43 +04:00
|
|
|
ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y);
|
2013-01-15 04:31:35 +04:00
|
|
|
gw->form_focus_obj = obj_idx;
|
2012-12-31 06:37:43 +04:00
|
|
|
DEBUG_PRINT(("Window Form click, obj: %d\n", gw->form_focus_obj));
|
2013-01-15 04:31:35 +04:00
|
|
|
if (obj_idx > -1
|
|
|
|
&& (gw->form[obj_idx].ob_state & OS_DISABLED)== 0) {
|
|
|
|
|
|
|
|
uint16_t type = (gw->form[obj_idx].ob_type & 0xFF);
|
|
|
|
uint16_t nextobj;
|
|
|
|
|
|
|
|
DEBUG_PRINT(("type: %d\n", type));
|
|
|
|
|
|
|
|
retval = form_wbutton(gw->form, gw->form_focus_obj,
|
|
|
|
ev_out->emo_mclicks, &nextobj,
|
|
|
|
gw->handle);
|
|
|
|
|
|
|
|
if (nextobj == obj_idx
|
|
|
|
&& (type == G_FTEXT || type == G_FBOXTEXT)) {
|
|
|
|
gw->form_edit_obj = obj_idx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gw->form_edit_obj = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
short oldevents = ev_out->emo_events;
|
2013-01-31 22:22:35 +04:00
|
|
|
short msg_out[8] = { GEMTK_WM_WM_FORM_CLICK, gl_apid,
|
2013-01-15 04:31:35 +04:00
|
|
|
0, gw->handle,
|
|
|
|
gw->form_focus_obj, ev_out->emo_mclicks,
|
|
|
|
ev_out->emo_kmeta, 0
|
|
|
|
};
|
|
|
|
ev_out->emo_events = MU_MESAG;
|
|
|
|
// notify the window about form click:
|
|
|
|
gw->handler_func(gw, ev_out, msg_out);
|
|
|
|
ev_out->emo_events = oldevents;
|
|
|
|
retval = 1;
|
|
|
|
evnt_timer(150);
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
}
|
2013-01-16 06:21:35 +04:00
|
|
|
else {
|
|
|
|
gw->form_edit_obj = -1;
|
|
|
|
|
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Preprocess keyboard events (for forms/toolbars)
|
|
|
|
*/
|
2012-12-31 06:37:43 +04:00
|
|
|
static short preproc_mu_keybd(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
|
|
|
|
{
|
2013-01-16 06:21:35 +04:00
|
|
|
short retval = 0;
|
|
|
|
|
|
|
|
if((gw->toolbar != NULL) && (gw->toolbar_edit_obj > -1) ) {
|
|
|
|
|
|
|
|
short next_edit_obj = gw->toolbar_edit_obj;
|
|
|
|
short next_char = -1;
|
|
|
|
short edit_idx;
|
|
|
|
short r;
|
|
|
|
|
|
|
|
r = form_wkeybd(gw->toolbar, gw->toolbar_edit_obj, next_edit_obj,
|
|
|
|
ev_out->emo_kreturn,
|
|
|
|
&next_edit_obj, &next_char, gw->handle);
|
|
|
|
|
|
|
|
if (next_edit_obj != gw->toolbar_edit_obj) {
|
|
|
|
|
2013-01-23 01:28:20 +04:00
|
|
|
gemtk_wm_set_toolbar_edit_obj(gw, next_edit_obj,
|
|
|
|
ev_out->emo_kreturn);
|
2013-01-16 06:21:35 +04:00
|
|
|
} else {
|
|
|
|
if(next_char > 13)
|
|
|
|
r = objc_wedit(gw->toolbar, gw->toolbar_edit_obj,
|
|
|
|
ev_out->emo_kreturn, &edit_idx,
|
|
|
|
EDCHAR, gw->handle);
|
|
|
|
}
|
2013-01-31 22:22:35 +04:00
|
|
|
//retval = 1;
|
|
|
|
/*gemtk_wm_send_msg(gw, GEMTK_WM_WM_FORM_KEY, gw->toolbar_edit_obj,
|
|
|
|
ev_out->emo_kreturn, 0, 0);*/
|
2013-01-16 06:21:35 +04:00
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
if((gw->form != NULL) && (gw->form_edit_obj > -1) ) {
|
|
|
|
|
|
|
|
short next_edit_obj = gw->form_edit_obj;
|
|
|
|
short next_char = -1;
|
|
|
|
short edit_idx;
|
|
|
|
short r;
|
|
|
|
|
2013-01-12 02:53:46 +04:00
|
|
|
r = form_wkeybd(gw->form, gw->form_edit_obj, next_edit_obj,
|
2012-12-31 06:37:43 +04:00
|
|
|
ev_out->emo_kreturn,
|
2013-01-12 02:53:46 +04:00
|
|
|
&next_edit_obj, &next_char, gw->handle);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
if (next_edit_obj != gw->form_edit_obj) {
|
|
|
|
|
|
|
|
if(gw->form_edit_obj != -1) {
|
2013-01-12 02:53:46 +04:00
|
|
|
objc_wedit(gw->form, gw->form_edit_obj,
|
2012-12-31 06:37:43 +04:00
|
|
|
ev_out->emo_kreturn, &edit_idx,
|
2013-01-12 02:53:46 +04:00
|
|
|
EDEND, gw->handle);
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gw->form_edit_obj = next_edit_obj;
|
|
|
|
|
2013-01-12 02:53:46 +04:00
|
|
|
objc_wedit(gw->form, gw->form_edit_obj,
|
2012-12-31 06:37:43 +04:00
|
|
|
ev_out->emo_kreturn, &edit_idx,
|
2013-01-12 02:53:46 +04:00
|
|
|
EDINIT, gw->handle);
|
2012-12-31 06:37:43 +04:00
|
|
|
} else {
|
|
|
|
if(next_char > 13)
|
2013-01-12 02:53:46 +04:00
|
|
|
r = objc_wedit(gw->form, gw->form_edit_obj,
|
2012-12-31 06:37:43 +04:00
|
|
|
ev_out->emo_kreturn, &edit_idx,
|
2013-01-12 02:53:46 +04:00
|
|
|
EDCHAR, gw->handle);
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
}
|
2013-01-16 06:21:35 +04:00
|
|
|
return(retval);
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Event Dispatcher function. The guiwin API doesn't own an event loop,
|
|
|
|
* so you have to inform it for every event that you want it to handle.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
short gemtk_wm_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out, short msg[8])
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
|
|
|
GUIWIN *dest;
|
|
|
|
short retval = 0;
|
2012-11-22 04:19:20 +04:00
|
|
|
bool handler_called = false;
|
2012-11-19 02:22:43 +04:00
|
|
|
|
|
|
|
if( (ev_out->emo_events & MU_MESAG) != 0 ) {
|
2013-01-22 05:33:27 +04:00
|
|
|
DEBUG_PRINT(("gemtk_wm_handle_event_multi_fast: %d (%x)\n", msg[0],
|
2013-01-14 04:01:22 +04:00
|
|
|
msg[0]));
|
2012-11-20 03:29:20 +04:00
|
|
|
switch (msg[0]) {
|
|
|
|
case WM_REDRAW:
|
2012-11-19 02:22:43 +04:00
|
|
|
case WM_CLOSED:
|
|
|
|
case WM_TOPPED:
|
|
|
|
case WM_ARROWED:
|
|
|
|
case WM_HSLID:
|
|
|
|
case WM_VSLID:
|
|
|
|
case WM_FULLED:
|
|
|
|
case WM_SIZED:
|
|
|
|
case WM_REPOSED:
|
|
|
|
case WM_MOVED:
|
|
|
|
case WM_NEWTOP:
|
|
|
|
case WM_UNTOPPED:
|
|
|
|
case WM_ONTOP:
|
|
|
|
case WM_BOTTOM:
|
|
|
|
case WM_ICONIFY:
|
|
|
|
case WM_UNICONIFY:
|
|
|
|
case WM_ALLICONIFY:
|
|
|
|
case WM_TOOLBAR:
|
|
|
|
case AP_DRAGDROP:
|
|
|
|
case AP_TERM:
|
|
|
|
case AP_TFAIL:
|
2013-01-22 05:33:27 +04:00
|
|
|
dest = gemtk_wm_find(msg[3]);
|
2012-11-19 02:22:43 +04:00
|
|
|
if (dest) {
|
|
|
|
DEBUG_PRINT(("Found WM_ dest: %p (%d), flags: %d, cb: %p\n", dest, dest->handle, dest->flags, dest->handler_func));
|
2013-01-22 05:33:27 +04:00
|
|
|
if (dest->flags&GEMTK_WM_FLAG_PREPROC_WM) {
|
2012-11-19 02:22:43 +04:00
|
|
|
retval = preproc_wm(dest, ev_out, msg);
|
2013-01-22 05:33:27 +04:00
|
|
|
if(((retval == 0)||(dest->flags&GEMTK_WM_FLAG_RECV_PREPROC_WM))) {
|
2012-11-20 03:29:20 +04:00
|
|
|
retval = dest->handler_func(dest, ev_out, msg);
|
2012-11-22 04:19:20 +04:00
|
|
|
handler_called = true;
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (dest->handler_func) {
|
|
|
|
retval = dest->handler_func(dest, ev_out, msg);
|
2012-11-22 04:19:20 +04:00
|
|
|
handler_called = true;
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
} else {
|
|
|
|
|
2012-12-18 04:10:20 +04:00
|
|
|
short h_aes;
|
|
|
|
h_aes = wind_find(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y);
|
|
|
|
if(h_aes > 0 && (ev_out->emo_events != MU_TIMER)) {
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
dest = gemtk_wm_find(h_aes);
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
if (dest == NULL || dest->handler_func == NULL)
|
2012-11-20 03:29:20 +04:00
|
|
|
return(0);
|
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
if ((ev_out->emo_events & MU_BUTTON) != 0) {
|
2012-11-19 03:47:03 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
DEBUG_PRINT(("Found MU_BUTTON dest: %p (%d), flags: %d, cb: %p\n", dest, dest->handle, dest->flags, dest->handler_func));
|
|
|
|
retval = preproc_mu_button(dest, ev_out, msg);
|
|
|
|
if(retval != 0) {
|
|
|
|
handler_called = true;
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
2012-11-22 04:19:20 +04:00
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
if ((ev_out->emo_events & MU_KEYBD)) {
|
|
|
|
retval = preproc_mu_keybd(dest, ev_out, msg);
|
2013-01-16 06:21:35 +04:00
|
|
|
if(retval != 0) {
|
|
|
|
handler_called = true;
|
|
|
|
}
|
2012-12-31 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2012-11-22 04:19:20 +04:00
|
|
|
if (handler_called==false) {
|
2012-11-20 03:29:20 +04:00
|
|
|
dest->handler_func(dest, ev_out, msg);
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Initialises the guiwin API
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
short gemtk_wm_init(void)
|
2012-11-20 03:29:20 +04:00
|
|
|
{
|
2012-11-20 04:41:42 +04:00
|
|
|
if(v_vdi_h == -1) {
|
|
|
|
short dummy;
|
2013-01-08 02:45:02 +04:00
|
|
|
short work_in[12] = {Getrez()+2,1,1,1,1,1,1,1,1,1,2,1};
|
2012-11-20 04:41:42 +04:00
|
|
|
v_vdi_h=graf_handle(&dummy, &dummy, &dummy, &dummy);
|
|
|
|
v_opnvwk(work_in, &v_vdi_h, work_out);
|
|
|
|
}
|
|
|
|
return(0);
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_exit(void)
|
2012-11-20 03:29:20 +04:00
|
|
|
{
|
2012-11-20 04:41:42 +04:00
|
|
|
v_clsvwk(v_vdi_h);
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Adds and AES handle to the guiwin list and creates and GUIWIN management
|
|
|
|
* structure.
|
|
|
|
*
|
|
|
|
* \param handle The AES handle
|
|
|
|
* \param flags Creation flags, configures how the AES window is handled
|
|
|
|
* \param cb event handler function for that window
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
GUIWIN * gemtk_wm_add(short handle, uint32_t flags, gemtk_wm_event_handler_f cb)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2012-11-19 03:47:03 +04:00
|
|
|
GUIWIN *win = calloc(sizeof(GUIWIN),1);
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
assert(win!=NULL);
|
2013-01-22 05:33:27 +04:00
|
|
|
DEBUG_PRINT(("gemtk_wm_add: %d, %p, cb: %p\n", handle, win, cb));
|
2012-11-19 02:22:43 +04:00
|
|
|
|
|
|
|
win->handle = handle;
|
|
|
|
win->handler_func = cb;
|
|
|
|
win->flags = flags;
|
2013-01-31 22:22:35 +04:00
|
|
|
gemtk_wm_link(win);
|
2012-12-18 04:10:20 +04:00
|
|
|
|
|
|
|
DEBUG_PRINT(("Added guiwin: %p, tb: %p\n", win, win->toolbar));
|
2012-11-19 02:22:43 +04:00
|
|
|
return(win);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Returns an GUIWIN* for AES handle, when that AES window is managed by guiwin
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
GUIWIN *gemtk_wm_find(short handle)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
|
|
|
GUIWIN *g;
|
2012-11-22 04:19:20 +04:00
|
|
|
DEBUG_PRINT(("guiwin search handle: %d\n", handle));
|
2012-11-19 02:22:43 +04:00
|
|
|
for( g = winlist; g != NULL; g=g->next ) {
|
|
|
|
if(g->handle == handle) {
|
2012-11-22 04:19:20 +04:00
|
|
|
DEBUG_PRINT(("guiwin found handle: %p\n", g));
|
2012-11-19 02:22:43 +04:00
|
|
|
return(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Check's if the pointer is managed by the guiwin API.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
GUIWIN *gemtk_wm_validate_ptr(GUIWIN *win)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2012-11-20 03:29:20 +04:00
|
|
|
GUIWIN *g;
|
|
|
|
for( g = winlist; g != NULL; g=g->next ) {
|
2013-01-22 05:33:27 +04:00
|
|
|
DEBUG_PRINT(("guiwin gemtk_wm_validate_ptr check: %p\n", g));
|
2012-11-19 02:22:43 +04:00
|
|
|
if(g == win) {
|
2013-01-22 05:33:27 +04:00
|
|
|
DEBUG_PRINT(("gemtk_wm_validate_ptr valid: %p\n", g));
|
2012-11-19 02:22:43 +04:00
|
|
|
return(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2013-03-30 16:22:55 +04:00
|
|
|
/**
|
|
|
|
* Add the GUIWIN to the list of handled windows.
|
|
|
|
*/
|
2013-01-31 22:22:35 +04:00
|
|
|
GUIWIN *gemtk_wm_link(GUIWIN *win)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2013-01-31 22:22:35 +04:00
|
|
|
/* Make sure the window is not linked: */
|
|
|
|
GUIWIN *win_val = gemtk_wm_validate_ptr(win);
|
|
|
|
if(win_val){
|
|
|
|
DEBUG_PRINT(("GUIWIN %p is already linked!\n", win));
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (winlist == NULL) {
|
|
|
|
winlist = win;
|
|
|
|
win->next = NULL;
|
|
|
|
win->prev = NULL;
|
|
|
|
} else {
|
|
|
|
GUIWIN *tmp = winlist;
|
|
|
|
while( tmp->next != NULL ) {
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
tmp->next = win;
|
|
|
|
win->prev = tmp;
|
|
|
|
win->next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-30 16:22:55 +04:00
|
|
|
/**
|
|
|
|
* Remove the GUIWIN from the list of handled windows.
|
|
|
|
*/
|
2013-01-31 22:22:35 +04:00
|
|
|
GUIWIN *gemtk_wm_unlink(GUIWIN *win)
|
|
|
|
{
|
|
|
|
GUIWIN * win_val;
|
|
|
|
|
|
|
|
/* Make sure the window is linked: */
|
|
|
|
win_val = gemtk_wm_validate_ptr(win);
|
|
|
|
if (win_val == NULL){
|
|
|
|
DEBUG_PRINT(("GUIWIN %p is not linked!\n", win));
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2012-11-19 02:22:43 +04:00
|
|
|
|
|
|
|
/* unlink the window: */
|
|
|
|
if(win->prev != NULL ) {
|
|
|
|
win->prev->next = win->next;
|
|
|
|
} else {
|
|
|
|
winlist = win->next;
|
|
|
|
}
|
|
|
|
if (win->next != NULL) {
|
|
|
|
win->next->prev = win->prev;
|
|
|
|
}
|
2013-01-31 22:22:35 +04:00
|
|
|
return(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an GUIWIN from the list of managed windows and free the GUIWIN.
|
|
|
|
* Call this when the AES window is closed or deleted.
|
|
|
|
*/
|
|
|
|
short gemtk_wm_remove(GUIWIN *win)
|
|
|
|
{
|
|
|
|
gemtk_wm_unlink(win);
|
2012-11-22 04:19:20 +04:00
|
|
|
DEBUG_PRINT(("guiwin free: %p\n", win));
|
2012-11-19 02:22:43 +04:00
|
|
|
free(win);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Calculate & get a well known area within the GUIWIN.
|
|
|
|
* \param win The GUIWIN ptr.
|
|
|
|
* \param mode Specifies the area to retrieve.
|
|
|
|
* \param dest The calculated rectangle.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2012-12-18 04:10:20 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
assert(win != NULL);
|
2012-12-18 04:10:20 +04:00
|
|
|
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_get_grect(win->handle, WF_WORKXYWH, dest);
|
2013-01-14 04:01:22 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
if (mode == GEMTK_WM_AREA_CONTENT) {
|
2012-11-20 03:29:20 +04:00
|
|
|
GRECT tb_area;
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_TOOLBAR, &tb_area);
|
|
|
|
if (win->flags & GEMTK_WM_FLAG_HAS_VTOOLBAR) {
|
2012-11-20 03:29:20 +04:00
|
|
|
dest->g_x += tb_area.g_w;
|
|
|
|
dest->g_w -= tb_area.g_w;
|
2013-01-10 04:27:36 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dest->g_y += tb_area.g_h;
|
2012-11-20 03:29:20 +04:00
|
|
|
dest->g_h -= tb_area.g_h;
|
|
|
|
}
|
2013-01-22 05:33:27 +04:00
|
|
|
} else if (mode == GEMTK_WM_AREA_TOOLBAR) {
|
2013-01-10 04:27:36 +04:00
|
|
|
if (win->toolbar) {
|
2013-01-22 05:33:27 +04:00
|
|
|
if (win->flags & GEMTK_WM_FLAG_HAS_VTOOLBAR) {
|
2013-01-15 04:31:35 +04:00
|
|
|
dest->g_w = win->toolbar_size;
|
2013-01-10 04:27:36 +04:00
|
|
|
} else {
|
2013-01-15 04:31:35 +04:00
|
|
|
dest->g_h = win->toolbar_size;
|
2013-01-10 04:27:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dest->g_w = 0;
|
|
|
|
dest->g_h = 0;
|
|
|
|
}
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
|
|
|
|
/**
|
2013-01-22 05:33:27 +04:00
|
|
|
* Scroll the content area (GEMTK_WM_AREA_CONTENT) in the specified dimension
|
|
|
|
* (GEMTK_WM_VSLIDER, GEMTK_WM_HSLIDER)
|
2013-01-10 04:27:36 +04:00
|
|
|
* \param win The GUIWIN
|
2013-01-22 05:33:27 +04:00
|
|
|
* \param orientation GEMTK_WM_VSLIDER or GEMTK_WM_HSLIDER
|
2013-01-10 04:27:36 +04:00
|
|
|
* \param units the amout to scroll (pass negative values to scroll up)
|
|
|
|
* \param refresh Sliders will be updated when this flag is set
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_scroll(GUIWIN *win, short orientation, int units, bool refresh)
|
2012-12-01 19:18:02 +04:00
|
|
|
{
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid = gemtk_wm_get_scroll_info(win);
|
2012-12-01 19:18:02 +04:00
|
|
|
int oldpos = 0, newpos = 0, vis_units=0, pix = 0;
|
|
|
|
int abs_pix = 0;
|
|
|
|
GRECT *redraw=NULL, g, g_ro;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_CONTENT, &g);
|
2012-12-01 19:18:02 +04:00
|
|
|
g_ro = g;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
if (orientation == GEMTK_WM_VSLIDER) {
|
2012-12-01 19:18:02 +04:00
|
|
|
pix = units*slid->y_unit_px;
|
|
|
|
abs_pix = abs(pix);
|
|
|
|
oldpos = slid->y_pos;
|
|
|
|
vis_units = g.g_h/slid->y_unit_px;
|
|
|
|
newpos = slid->y_pos = MIN(slid->y_units-vis_units,
|
|
|
|
MAX(0, slid->y_pos+units));
|
2012-12-31 06:37:43 +04:00
|
|
|
if(newpos < 0) {
|
|
|
|
newpos = slid->y_pos = 0;
|
|
|
|
}
|
2012-12-01 19:18:02 +04:00
|
|
|
if(oldpos == newpos)
|
|
|
|
return;
|
2012-12-04 04:32:43 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
if (units>=vis_units || gemtk_wm_has_intersection(win, &g_ro)) {
|
2012-12-01 19:18:02 +04:00
|
|
|
// send complete redraw
|
|
|
|
redraw = &g_ro;
|
|
|
|
} else {
|
|
|
|
// only adjust ypos when scrolling down:
|
|
|
|
if(pix < 0 ) {
|
|
|
|
// blit screen area:
|
|
|
|
g.g_h -= abs_pix;
|
2013-01-10 04:27:36 +04:00
|
|
|
move_rect(win, &g, 0, abs_pix);
|
2012-12-01 19:18:02 +04:00
|
|
|
g.g_y = g_ro.g_y;
|
|
|
|
g.g_h = abs_pix;
|
|
|
|
redraw = &g;
|
|
|
|
} else {
|
|
|
|
// blit screen area:
|
|
|
|
g.g_y += abs_pix;
|
|
|
|
g.g_h -= abs_pix;
|
2013-01-10 04:27:36 +04:00
|
|
|
move_rect(win, &g, 0, -abs_pix);
|
2012-12-01 19:18:02 +04:00
|
|
|
g.g_y = g_ro.g_y + g_ro.g_h - abs_pix;
|
|
|
|
g.g_h = abs_pix;
|
|
|
|
redraw = &g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pix = units*slid->x_unit_px;
|
|
|
|
abs_pix = abs(pix);
|
|
|
|
oldpos = slid->x_pos;
|
|
|
|
vis_units = g.g_w/slid->x_unit_px;
|
|
|
|
newpos = slid->x_pos = MIN(slid->x_units-vis_units,
|
|
|
|
MAX(0, slid->x_pos+units));
|
2012-12-04 04:32:43 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
if(newpos < 0) {
|
|
|
|
newpos = slid->x_pos = 0;
|
|
|
|
}
|
2012-12-04 04:32:43 +04:00
|
|
|
|
2012-12-01 19:18:02 +04:00
|
|
|
if(oldpos == newpos)
|
|
|
|
return;
|
2013-01-22 05:33:27 +04:00
|
|
|
if (units>=vis_units || gemtk_wm_has_intersection(win, &g_ro)) {
|
2012-12-01 19:18:02 +04:00
|
|
|
// send complete redraw
|
|
|
|
redraw = &g_ro;
|
|
|
|
} else {
|
|
|
|
// only adjust ypos when scrolling down:
|
|
|
|
if(pix < 0 ) {
|
|
|
|
// blit screen area:
|
|
|
|
g.g_w -= abs_pix;
|
2013-01-10 04:27:36 +04:00
|
|
|
move_rect(win, &g, abs_pix, 0);
|
2012-12-01 19:18:02 +04:00
|
|
|
g.g_x = g_ro.g_x;
|
|
|
|
g.g_w = abs_pix;
|
|
|
|
redraw = &g;
|
|
|
|
} else {
|
|
|
|
// blit screen area:
|
|
|
|
g.g_x += abs_pix;
|
|
|
|
g.g_w -= abs_pix;
|
2013-01-10 04:27:36 +04:00
|
|
|
move_rect(win, &g, -abs_pix, 0);
|
2012-12-01 19:18:02 +04:00
|
|
|
g.g_x = g_ro.g_x + g_ro.g_w - abs_pix;
|
|
|
|
g.g_w = abs_pix;
|
|
|
|
redraw = &g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refresh) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_update_slider(win, orientation);
|
2012-12-01 19:18:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((redraw != NULL) && (redraw->g_h > 0)) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_send_redraw(win, redraw);
|
2012-12-01 19:18:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Refresh the sliders of the window.
|
|
|
|
* \param win the GUIWIN
|
2013-01-22 05:33:27 +04:00
|
|
|
* \param mode bitmask, valid bits: GEMTK_WM_VSLIDER, GEMTK_WM_HSLIDER
|
2013-01-10 04:27:36 +04:00
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
bool gemtk_wm_update_slider(GUIWIN *win, short mode)
|
2012-11-20 03:29:20 +04:00
|
|
|
{
|
|
|
|
GRECT viewport;
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s * slid;
|
2012-11-20 03:29:20 +04:00
|
|
|
unsigned long size, pos;
|
2012-11-21 05:14:22 +04:00
|
|
|
int old_x, old_y;
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
short handle = gemtk_wm_get_handle(win);
|
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_CONTENT, &viewport);
|
|
|
|
slid = gemtk_wm_get_scroll_info(win);
|
2012-11-20 03:29:20 +04:00
|
|
|
|
2012-11-21 05:14:22 +04:00
|
|
|
old_x = slid->x_pos;
|
|
|
|
old_y = slid->y_pos;
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
// TODO: check if the window has sliders of that direction...?
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
if((mode & GEMTK_WM_VSLIDER) && (slid->y_unit_px > 0)) {
|
2012-11-22 03:26:58 +04:00
|
|
|
if ( slid->y_units < (long)viewport.g_h/slid->y_unit_px) {
|
2012-11-20 03:29:20 +04:00
|
|
|
size = 1000L;
|
2012-11-22 03:26:58 +04:00
|
|
|
} else
|
2012-11-21 05:14:22 +04:00
|
|
|
size = MAX( 50L, (unsigned long)viewport.g_h*1000L/
|
2012-11-22 03:26:58 +04:00
|
|
|
(unsigned long)(slid->y_unit_px*slid->y_units));
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_set(handle, WF_VSLSIZE, (int)size, 0, 0, 0);
|
|
|
|
|
2012-11-22 03:26:58 +04:00
|
|
|
if (slid->y_units > (long)viewport.g_h/slid->y_unit_px) {
|
2012-11-21 05:14:22 +04:00
|
|
|
pos = (unsigned long)slid->y_pos *1000L/
|
2012-11-22 03:26:58 +04:00
|
|
|
(unsigned long)(slid->y_units-viewport.g_h/slid->y_unit_px);
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_set(handle, WF_VSLIDE, (int)pos, 0, 0, 0);
|
|
|
|
} else if (slid->y_pos) {
|
|
|
|
slid->y_pos = 0;
|
|
|
|
wind_set(handle, WF_VSLIDE, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 05:33:27 +04:00
|
|
|
if((mode & GEMTK_WM_HSLIDER) && (slid->x_unit_px > 0)) {
|
2012-11-22 03:26:58 +04:00
|
|
|
if ( slid->x_units < (long)viewport.g_w/slid->x_unit_px)
|
2012-11-20 03:29:20 +04:00
|
|
|
size = 1000L;
|
|
|
|
else
|
2012-11-21 05:14:22 +04:00
|
|
|
size = MAX( 50L, (unsigned long)viewport.g_w*1000L/
|
2012-11-22 03:26:58 +04:00
|
|
|
(unsigned long)(slid->x_unit_px*slid->x_units));
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_set(handle, WF_HSLSIZE, (int)size, 0, 0, 0);
|
|
|
|
|
2012-11-22 03:26:58 +04:00
|
|
|
if( slid->x_units > (long)viewport.g_w/slid->x_unit_px) {
|
2012-11-21 05:14:22 +04:00
|
|
|
pos = (unsigned long)slid->x_pos*1000L/
|
2012-11-22 03:26:58 +04:00
|
|
|
(unsigned long)(slid->x_units-viewport.g_w/slid->x_unit_px);
|
2012-11-20 03:29:20 +04:00
|
|
|
wind_set(handle, WF_HSLIDE, (int)pos, 0, 0, 0);
|
|
|
|
} else if (slid->x_pos) {
|
|
|
|
slid->x_pos = 0;
|
|
|
|
wind_set(handle, WF_HSLIDE, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
|
2012-11-22 03:26:58 +04:00
|
|
|
if(old_x != slid->x_pos || old_y != slid->y_pos) {
|
|
|
|
return(true);
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
|
|
|
return(false);
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Return the AES handle for the GUIWIN.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
short gemtk_wm_get_handle(GUIWIN *win)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2012-11-20 03:29:20 +04:00
|
|
|
return(win->handle);
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Return the VDI handle for an GUIWIN.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
VdiHdl gemtk_wm_get_vdi_handle(GUIWIN *win)
|
2012-11-27 05:12:09 +04:00
|
|
|
{
|
|
|
|
return(v_vdi_h);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Returns the state bitmask of the window
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
uint32_t gemtk_wm_get_state(GUIWIN *win)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2012-11-20 03:29:20 +04:00
|
|
|
return(win->state);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set and new event handler function.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_event_handler(GUIWIN *win,gemtk_wm_event_handler_f cb)
|
2012-11-20 03:29:20 +04:00
|
|
|
{
|
|
|
|
win->handler_func = cb;
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Configure the window so that it shows an toolbar or at least reserves
|
|
|
|
* an area to draw an toolbar.
|
|
|
|
* \param win The GUIWIN
|
|
|
|
* \param toolbar the AES form
|
|
|
|
* \param idx index within the toolbar tree (0 in most cases...)
|
|
|
|
* \param flags optional configuration flags
|
|
|
|
*/
|
|
|
|
//TODO: document flags
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_toolbar(GUIWIN *win, OBJECT *toolbar, short idx, uint32_t flags)
|
2012-11-19 02:22:43 +04:00
|
|
|
{
|
2012-11-20 03:29:20 +04:00
|
|
|
win->toolbar = toolbar;
|
|
|
|
win->toolbar_idx = idx;
|
2012-12-31 06:37:43 +04:00
|
|
|
win->toolbar_edit_obj = -1;
|
2013-01-22 05:33:27 +04:00
|
|
|
if (flags & GEMTK_WM_FLAG_HAS_VTOOLBAR) {
|
|
|
|
win->flags |= GEMTK_WM_FLAG_HAS_VTOOLBAR;
|
2013-01-15 04:31:35 +04:00
|
|
|
win->toolbar_size = win->toolbar[idx].ob_width;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
win->toolbar_size = win->toolbar[idx].ob_height;
|
2012-11-20 03:29:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 04:01:22 +04:00
|
|
|
/** Update width/height of the toolbar region
|
|
|
|
* \param win the GUIWIN
|
2013-01-22 05:33:27 +04:00
|
|
|
* \param s depending on the flag GEMTK_WM_FLAG_HAS_VTOOLBAR this is the width or the height
|
2013-01-14 04:01:22 +04:00
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_toolbar_size(GUIWIN *win, uint16_t s)
|
2013-01-14 04:01:22 +04:00
|
|
|
{
|
2013-01-15 04:31:35 +04:00
|
|
|
win->toolbar_size = s;
|
|
|
|
}
|
2013-01-14 04:01:22 +04:00
|
|
|
|
2013-01-31 22:22:35 +04:00
|
|
|
short getm_wm_get_toolbar_edit_obj(GUIWIN *win)
|
|
|
|
{
|
|
|
|
return(win->toolbar_edit_obj);
|
|
|
|
}
|
|
|
|
|
2013-01-23 01:28:20 +04:00
|
|
|
/** Set the current active edit object */
|
|
|
|
void gemtk_wm_set_toolbar_edit_obj(GUIWIN *win, uint16_t obj, short kreturn)
|
|
|
|
{
|
|
|
|
short edit_idx;
|
|
|
|
|
|
|
|
if (obj != win->toolbar_edit_obj) {
|
|
|
|
|
|
|
|
if(win->toolbar_edit_obj != -1) {
|
|
|
|
objc_wedit(win->toolbar, win->toolbar_edit_obj, kreturn, &edit_idx,
|
|
|
|
EDEND, win->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
win->toolbar_edit_obj = obj;
|
|
|
|
|
|
|
|
objc_wedit(win->toolbar, win->toolbar_edit_obj, kreturn, &edit_idx,
|
|
|
|
EDINIT, win->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
/** Set an custom toolbar redraw function which is called instead of
|
|
|
|
* default drawing routine.
|
|
|
|
* \param win the GUIWIN
|
|
|
|
* \param func the custom redraw function
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_toolbar_redraw_func(GUIWIN *win, gemtk_wm_redraw_f func)
|
2013-01-15 04:31:35 +04:00
|
|
|
{
|
|
|
|
win->toolbar_redraw_func = func;
|
2013-01-14 04:01:22 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Attach an arbitary pointer to the GUIWIN
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_user_data(GUIWIN *win, void *data)
|
2012-11-20 03:29:20 +04:00
|
|
|
{
|
|
|
|
win->user_data = data;
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the user_data pointer attached to the GUIWIN.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void *gemtk_wm_get_user_data(GUIWIN *win)
|
2012-11-20 03:29:20 +04:00
|
|
|
{
|
|
|
|
return(win->user_data);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Get the scroll management structure for a GUIWIN
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *gemtk_wm_get_scroll_info(GUIWIN *win) {
|
2012-11-20 04:41:42 +04:00
|
|
|
return(&win->scroll_info);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/**
|
|
|
|
* Get the amount of content dimensions within the window
|
|
|
|
* which is calculated by using the scroll_info attached to the GUIWIN.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_scroll_grid(GUIWIN * win, short x, short y)
|
2012-12-28 07:41:33 +04:00
|
|
|
{
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid = gemtk_wm_get_scroll_info(win);
|
2012-12-28 07:41:33 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
assert(slid != NULL);
|
2012-12-28 07:41:33 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
slid->y_unit_px = x;
|
|
|
|
slid->x_unit_px = y;
|
2012-12-28 07:41:33 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
|
|
|
|
/** Set the size of the content measured in content units
|
|
|
|
* \param win the GUIWIN
|
|
|
|
* \param x horizontal size
|
|
|
|
* \param y vertical size
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_content_units(GUIWIN * win, short x, short y)
|
2012-12-28 07:41:33 +04:00
|
|
|
{
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid = gemtk_wm_get_scroll_info(win);
|
2012-12-28 07:41:33 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
assert(slid != NULL);
|
2012-12-28 07:41:33 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
slid->x_units = x;
|
|
|
|
slid->y_units = y;
|
2012-12-28 07:41:33 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Send an Message to a GUIWIN using AES message pipe
|
|
|
|
* \param win the GUIWIN which shall receive the message
|
|
|
|
* \param msg_type the WM_ message definition
|
|
|
|
* \param a the 4th parameter to appl_write
|
|
|
|
* \param b the 5th parameter to appl_write
|
|
|
|
* \param c the 6th parameter to appl_write
|
|
|
|
* \param d the 7th parameter to appl_write
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_send_msg(GUIWIN *win, short msg_type, short a, short b, short c,
|
2012-12-31 06:37:43 +04:00
|
|
|
short d)
|
2012-12-04 04:32:43 +04:00
|
|
|
{
|
2012-12-31 06:37:43 +04:00
|
|
|
short msg[8];
|
2012-12-04 04:32:43 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
msg[0] = msg_type;
|
2012-12-12 04:51:18 +04:00
|
|
|
msg[1] = gl_apid;
|
|
|
|
msg[2] = 0;
|
|
|
|
msg[3] = win->handle;
|
|
|
|
msg[4] = a;
|
|
|
|
msg[5] = b;
|
|
|
|
msg[6] = c;
|
|
|
|
msg[7] = d;
|
|
|
|
|
|
|
|
appl_write(gl_apid, 16, &msg);
|
2012-12-04 04:32:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
// TODO: rename, document and implement alternative (gemtk_wm_exec_event)
|
|
|
|
void gemtk_wm_send_redraw(GUIWIN *win, GRECT *area)
|
2012-11-20 04:41:42 +04:00
|
|
|
{
|
2012-12-31 06:37:43 +04:00
|
|
|
short msg[8], retval;
|
2012-11-21 05:14:22 +04:00
|
|
|
GRECT work;
|
2012-11-20 04:41:42 +04:00
|
|
|
|
2012-12-04 04:32:43 +04:00
|
|
|
EVMULT_IN event_in = {
|
2012-12-31 06:37:43 +04:00
|
|
|
.emi_flags = MU_MESAG | MU_TIMER | MU_KEYBD | MU_BUTTON,
|
|
|
|
.emi_bclicks = 258,
|
|
|
|
.emi_bmask = 3,
|
|
|
|
.emi_bstate = 0,
|
|
|
|
.emi_m1leave = MO_ENTER,
|
|
|
|
.emi_m1 = {0,0,0,0},
|
|
|
|
.emi_m2leave = 0,
|
|
|
|
.emi_m2 = {0,0,0,0},
|
|
|
|
.emi_tlow = 0,
|
|
|
|
.emi_thigh = 0
|
|
|
|
};
|
|
|
|
EVMULT_OUT event_out;
|
2012-12-04 04:32:43 +04:00
|
|
|
|
2012-12-18 04:10:20 +04:00
|
|
|
if (area == NULL) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_WORK, &work);
|
2012-12-18 04:10:20 +04:00
|
|
|
if (work.g_w < 1 || work.g_h < 1) {
|
2012-12-31 06:37:43 +04:00
|
|
|
if (win->toolbar != NULL) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_TOOLBAR, &work);
|
2012-12-31 06:37:43 +04:00
|
|
|
if (work.g_w < 1 || work.g_h < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 04:10:20 +04:00
|
|
|
}
|
2012-11-21 05:14:22 +04:00
|
|
|
area = &work;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg[0] = WM_REDRAW;
|
|
|
|
msg[1] = gl_apid;
|
|
|
|
msg[2] = 0;
|
|
|
|
msg[3] = win->handle;
|
|
|
|
msg[4] = area->g_x;
|
|
|
|
msg[5] = area->g_y;
|
|
|
|
msg[6] = area->g_w;
|
|
|
|
msg[7] = area->g_h;
|
2012-11-20 04:41:42 +04:00
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
event_out.emo_events = MU_MESAG;
|
|
|
|
retval = preproc_wm(win, &event_out, msg);
|
2013-01-22 05:33:27 +04:00
|
|
|
if (retval == 0 || (win->flags & GEMTK_WM_FLAG_PREPROC_WM) != 0){
|
2012-12-31 06:37:43 +04:00
|
|
|
win->handler_func(win, &event_out, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-04 04:32:43 +04:00
|
|
|
|
|
|
|
//appl_write(gl_apid, 16, &msg);
|
2012-11-21 05:14:22 +04:00
|
|
|
}
|
2012-11-20 04:41:42 +04:00
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Attach an AES FORM to the GUIWIN, similar feature like the toolbar
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_set_form(GUIWIN *win, OBJECT *tree, short index)
|
2012-12-31 06:37:43 +04:00
|
|
|
{
|
|
|
|
DEBUG_PRINT(("Setting form %p (%d) for window %p\n", tree, index, win));
|
|
|
|
win->form = tree;
|
|
|
|
win->form_edit_obj = -1;
|
|
|
|
win->form_focus_obj = -1;
|
|
|
|
win->form_idx = index;
|
|
|
|
}
|
2012-11-22 03:26:58 +04:00
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Checks if a GUIWIN is overlapped by other windows.
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
bool gemtk_wm_has_intersection(GUIWIN *win, GRECT *work)
|
2012-11-21 05:14:22 +04:00
|
|
|
{
|
2012-11-22 03:26:58 +04:00
|
|
|
GRECT area, mywork;
|
|
|
|
bool retval = true;
|
|
|
|
|
|
|
|
if (work == NULL) {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_CONTENT, &mywork);
|
2012-11-22 03:26:58 +04:00
|
|
|
work = &mywork;
|
|
|
|
}
|
|
|
|
|
|
|
|
wind_get_grect(win->handle, WF_FIRSTXYWH, &area);
|
|
|
|
while (area.g_w && area.g_w) {
|
|
|
|
//GRECT * ptr = &area;
|
|
|
|
if (RC_WITHIN(work, &area)) {
|
|
|
|
retval = false;
|
|
|
|
}
|
|
|
|
wind_get_grect(win->handle, WF_NEXTXYWH, &area);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Execute an toolbar redraw
|
2013-01-15 04:31:35 +04:00
|
|
|
* \param msg specifies the AES message which initiated the redraw, or 0 when
|
|
|
|
* the function was called without AES message context.
|
2013-01-10 04:27:36 +04:00
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_toolbar_redraw(GUIWIN *gw, uint16_t msg, GRECT *clip)
|
2012-11-22 03:26:58 +04:00
|
|
|
{
|
|
|
|
GRECT tb_area, tb_area_ro, g;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_TOOLBAR, &tb_area_ro);
|
2012-11-22 03:26:58 +04:00
|
|
|
|
|
|
|
if(clip == NULL) {
|
|
|
|
clip = &tb_area_ro;
|
|
|
|
}
|
|
|
|
|
|
|
|
tb_area = tb_area_ro;
|
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
if (rc_intersect(clip, &tb_area)) {
|
2012-11-27 05:12:09 +04:00
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
if (gw->toolbar_redraw_func != NULL) {
|
2012-11-22 03:26:58 +04:00
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
// customized redraw:
|
|
|
|
gw->toolbar_redraw_func(gw, msg, &tb_area);
|
2012-11-22 03:26:58 +04:00
|
|
|
|
2013-01-15 04:31:35 +04:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Default redraw action
|
|
|
|
|
|
|
|
// Update object position:
|
|
|
|
gw->toolbar[gw->toolbar_idx].ob_x = tb_area_ro.g_x;
|
|
|
|
gw->toolbar[gw->toolbar_idx].ob_y = tb_area_ro.g_y;
|
|
|
|
gw->toolbar[gw->toolbar_idx].ob_width = tb_area_ro.g_w;
|
|
|
|
gw->toolbar[gw->toolbar_idx].ob_height = tb_area_ro.g_h;
|
|
|
|
|
|
|
|
wind_get_grect(gw->handle, WF_FIRSTXYWH, &g);
|
|
|
|
while (g.g_h > 0 || g.g_w > 0) {
|
|
|
|
if(rc_intersect(&tb_area, &g)) {
|
|
|
|
objc_draw(gw->toolbar, gw->toolbar_idx, 8, g.g_x, g.g_y,
|
|
|
|
g.g_w, g.g_h);
|
|
|
|
|
|
|
|
}
|
|
|
|
wind_get_grect(gw->handle, WF_NEXTXYWH, &g);
|
|
|
|
}
|
2012-11-22 03:26:58 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-20 04:41:42 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Execute FORM redraw
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_form_redraw(GUIWIN *gw, GRECT *clip)
|
2012-12-31 06:37:43 +04:00
|
|
|
{
|
|
|
|
GRECT area, area_ro, g;
|
|
|
|
int scroll_px_x, scroll_px_y;
|
2013-01-22 05:33:27 +04:00
|
|
|
struct gemtk_wm_scroll_info_s *slid;
|
2012-12-31 06:37:43 +04:00
|
|
|
//int new_x, new_y, old_x, old_y;
|
|
|
|
short edit_idx;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
DEBUG_PRINT(("gemtk_wm_form_redraw\n"));
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
// calculate form coordinates, include scrolling:
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(gw, GEMTK_WM_AREA_CONTENT, &area_ro);
|
|
|
|
slid = gemtk_wm_get_scroll_info(gw);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
|
|
|
// Update form position:
|
|
|
|
gw->form[gw->form_idx].ob_x = area_ro.g_x - (slid->x_pos * slid->x_unit_px);
|
|
|
|
gw->form[gw->form_idx].ob_y = area_ro.g_y - (slid->y_pos * slid->y_unit_px);
|
|
|
|
|
|
|
|
if(clip == NULL) {
|
|
|
|
clip = &area_ro;
|
|
|
|
}
|
|
|
|
|
|
|
|
area = area_ro;
|
|
|
|
|
|
|
|
/* Walk the AES rectangle list and redraw the visible areas of the window:*/
|
|
|
|
if(rc_intersect(clip, &area)) {
|
|
|
|
|
|
|
|
wind_get_grect(gw->handle, WF_FIRSTXYWH, &g);
|
|
|
|
while (g.g_h > 0 || g.g_w > 0) {
|
|
|
|
if(rc_intersect(&area, &g)) {
|
|
|
|
objc_draw(gw->form, gw->form_idx, 8, g.g_x, g.g_y,
|
|
|
|
g.g_w, g.g_h);
|
|
|
|
|
|
|
|
}
|
|
|
|
wind_get_grect(gw->handle, WF_NEXTXYWH, &g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-10 04:27:36 +04:00
|
|
|
/** Fill the content area with white color
|
|
|
|
*/
|
2013-01-22 05:33:27 +04:00
|
|
|
void gemtk_wm_clear(GUIWIN *win)
|
2012-11-27 05:12:09 +04:00
|
|
|
{
|
|
|
|
GRECT area, g;
|
|
|
|
short pxy[4];
|
|
|
|
VdiHdl vh;
|
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
vh = gemtk_wm_get_vdi_handle(win);
|
2012-11-27 05:12:09 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
if(win->state & GEMTK_WM_STATUS_ICONIFIED) {
|
2012-11-27 05:12:09 +04:00
|
|
|
// also clear the toolbar area when iconified:
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_WORK, &area);
|
2012-11-27 05:12:09 +04:00
|
|
|
} else {
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_wm_get_grect(win, GEMTK_WM_AREA_CONTENT, &area);
|
2012-11-27 05:12:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
vsf_interior(vh, FIS_SOLID);
|
|
|
|
vsf_color(vh, 0);
|
|
|
|
vswr_mode(vh, MD_REPLACE);
|
|
|
|
wind_get_grect(win->handle, WF_FIRSTXYWH, &g);
|
|
|
|
while (g.g_h > 0 || g.g_w > 0) {
|
|
|
|
if(rc_intersect(&area, &g)) {
|
|
|
|
pxy[0] = g.g_x;
|
|
|
|
pxy[1] = g.g_y;
|
|
|
|
pxy[2] = g.g_x+g.g_w-1;
|
|
|
|
pxy[3] = g.g_y+g.g_h-1;
|
|
|
|
v_bar(vh, pxy);
|
|
|
|
}
|
|
|
|
wind_get_grect(win->handle, WF_NEXTXYWH, &g);
|
|
|
|
}
|
2012-11-19 02:22:43 +04:00
|
|
|
}
|