summaryrefslogtreecommitdiff
path: root/atari/gemtk
diff options
context:
space:
mode:
Diffstat (limited to 'atari/gemtk')
-rw-r--r--atari/gemtk/aestabs.c173
-rw-r--r--atari/gemtk/aestabs.h56
-rwxr-xr-xatari/gemtk/dragdrop.c515
-rwxr-xr-xatari/gemtk/dragdrop.h4
-rw-r--r--atari/gemtk/gemtk.h197
-rw-r--r--atari/gemtk/guiwin.c1076
-rw-r--r--atari/gemtk/guiwin.h4
-rw-r--r--atari/gemtk/msgbox.c84
-rw-r--r--atari/gemtk/msgbox.h5
-rw-r--r--atari/gemtk/objc.c106
-rw-r--r--atari/gemtk/objc.h7
-rw-r--r--atari/gemtk/redrawslots.c123
-rw-r--r--atari/gemtk/redrawslots.h28
-rw-r--r--atari/gemtk/utils.c66
-rw-r--r--atari/gemtk/utils.h5
15 files changed, 2449 insertions, 0 deletions
diff --git a/atari/gemtk/aestabs.c b/atari/gemtk/aestabs.c
new file mode 100644
index 000000000..414d5c290
--- /dev/null
+++ b/atari/gemtk/aestabs.c
@@ -0,0 +1,173 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <gem.h>
+#include <cflib.h>
+#include "aestabs.h"
+
+#ifndef NDEBUG
+# define DEBUG_PRINT(x) printf x
+#else
+# define DEBUG_PRINT(x)
+#endif
+
+
+AES_TABLIST * tablist_declare(OBJECT *tree, aes_tablist_user_func user_func)
+{
+ AES_TABLIST * newlist = malloc(sizeof(AES_TABLIST));
+
+ newlist->first = NULL;
+ newlist->tree = tree;
+ newlist->user_func = user_func;
+ DEBUG_PRINT(("aes_tablist_declare: %p\n", newlist));
+ return(newlist);
+}
+
+
+AES_TAB * tablist_add(AES_TABLIST * tablist, short obj_tab, OBJECT * page_tree,
+ short obj_page)
+{
+ AES_TAB * newtab = malloc(sizeof(AES_TAB));
+
+ assert(newtab);
+ assert(tablist);
+
+ newtab->next = NULL;
+ newtab->prev = NULL;
+ newtab->obj_tab = obj_tab;
+ newtab->obj_page = obj_page;
+ newtab->page_tree = page_tree;
+
+ if(newtab->page_tree == NULL){
+ newtab->page_tree = tablist->tree;
+ }
+
+ if (tablist->first == NULL) {
+ tablist->first = newtab;
+ set_state(tablist->tree, newtab->obj_tab, OS_SELECTED, 0);
+ } else {
+ AES_TAB *tmp = tablist->first;
+ while( tmp->next != NULL ) {
+ tmp = tmp->next;
+ }
+ tmp->next = newtab;
+ newtab->prev = tmp;
+ newtab->next = NULL;
+ set_state(tablist->tree, newtab->obj_tab, OS_SELECTED, 0);
+ }
+
+ // TODO: Set the visible flag on that register?
+
+ DEBUG_PRINT(("tablist_add: Tab=%p\n", newtab));
+
+ return(newtab);
+}
+
+
+short tablist_activate(AES_TABLIST * tablist, short tab, short options)
+{
+ AES_TAB *tmp, *activated=NULL, *deactivated=NULL;
+ struct aes_tab_s *active;
+ short activated_pg = -1;
+ short is_tab = 0;
+
+ assert(tablist);
+ assert(tablist->first);
+
+ active = tablist_get_active(tablist);
+
+ if (active != NULL) {
+ if ((options & AES_TABLIST_OPTION_FORCE_EVENTS) == 0) {
+ if(active->obj_tab == tab)
+ return(0);
+ }
+ }
+
+ tmp = tablist->first;
+ while (tmp != NULL) {
+ if(tmp->obj_tab == tab) {
+ is_tab = 1;
+ }
+ tmp = tmp->next;
+ }
+
+ if(is_tab == 0) {
+ return(0);
+ }
+
+ tmp = tablist->first;
+ while ( tmp != NULL ) {
+ if(tab != tmp->obj_tab) {
+ if (get_state(tablist->tree, tmp->obj_tab, OS_SELECTED) != 0) {
+ deactivated = tmp;
+ set_state(tablist->tree, tmp->obj_tab, OS_SELECTED, 0);
+ }
+ // the tab registers can share the same page, consider that:
+ if (tablist->tree == tmp->page_tree
+ && activated_pg != tmp->obj_page) {
+
+ set_flag(tablist->tree, tmp->obj_page, OF_HIDETREE, 1);
+ }
+ } else {
+ activated = tmp;
+ // this tab must the selected / visible
+ set_state(tablist->tree, tmp->obj_tab, OS_SELECTED, 1);
+ if(tablist->tree == tmp->page_tree)
+ set_flag(tablist->tree, tmp->obj_page, OF_HIDETREE, 0);
+ activated_pg = tmp->obj_page;
+ }
+ tmp = tmp->next;
+ }
+
+ if(tablist->user_func != NULL) {
+ AES_TABLIST_FUNC_ARGS args;
+ if(deactivated){
+ args.event = AES_TABLIST_TAB_DEACTIVATED;
+ args.tab = deactivated;
+ tablist->user_func(tablist, &args);
+ }
+ if(activated){
+ args.event = AES_TABLIST_TAB_ACTIVATED;
+ args.tab = activated;
+ tablist->user_func(tablist, &args);
+ }
+ }
+ return(1);
+}
+
+struct aes_tab_s *tablist_get_active(AES_TABLIST * tablist)
+{
+ AES_TAB *tmp = tablist->first;
+ while( tmp != NULL ) {
+ if(get_state(tablist->tree, tmp->obj_tab, OS_SELECTED) != 0) {
+ // that's the one
+ return(tmp);
+ }
+ tmp = tmp->next;
+ }
+ return(NULL);
+}
+
+AES_TAB * tablist_find(AES_TABLIST * tablist, OBJECT * page, short tab)
+{
+ AES_TAB *tmp = tablist->first;
+ while( tmp != NULL ) {
+ if((tmp->page_tree == page) && (tab == tmp->obj_tab)) {
+ return(tmp);
+ }
+ tmp = tmp->next;
+ }
+ return(NULL);
+}
+
+void tablist_delete(AES_TABLIST *tablist)
+{
+ AES_TAB *tmp = tablist->first, *cur;
+ while ( tmp != NULL ) {
+ cur = tmp;
+ tmp = tmp->next;
+ DEBUG_PRINT(("tablist_delete, Freeing tab: %p\n", cur));
+ free(cur);
+ }
+ DEBUG_PRINT(("tablist_delete, Freeing list: %p\n", tablist));
+ free(tablist);
+}
diff --git a/atari/gemtk/aestabs.h b/atari/gemtk/aestabs.h
new file mode 100644
index 000000000..c72054acc
--- /dev/null
+++ b/atari/gemtk/aestabs.h
@@ -0,0 +1,56 @@
+#ifndef AESTABS_H_INCLUDED
+#define AESTABS_H_INCLUDED
+
+struct aes_tab_s;
+struct aes_tablist_s;
+typedef struct aes_tab_s AES_TAB;
+typedef struct aes_tablist_s AES_TABLIST;
+
+#define AES_TABLIST_TAB_ACTIVATED 0x01
+#define AES_TABLIST_TAB_DEACTIVATED 0x02
+
+#define AES_TABLIST_OPTION_FORCE_EVENTS 0x01 // do not eat events which do
+ // not changed the internal state
+ // this is required for tabs which
+ // require "activate" events
+ // for tabs which are already
+ // selected.
+
+
+struct aes_tablist_user_args_s
+{
+ short event;
+ AES_TAB *tab;
+};
+
+typedef struct aes_tablist_user_args_s AES_TABLIST_FUNC_ARGS;
+
+typedef void (*aes_tablist_user_func)(AES_TABLIST * list,
+ AES_TABLIST_FUNC_ARGS * args);
+
+struct aes_tab_s {
+ short obj_tab;
+ short obj_page;
+ OBJECT * page_tree;
+ AES_TAB * next, *prev;
+};
+
+struct aes_tablist_s {
+ OBJECT *tree;
+ AES_TAB * first;
+ aes_tablist_user_func user_func;
+};
+
+
+
+AES_TABLIST * tablist_declare(OBJECT *tree, aes_tablist_user_func user_func);
+void tablist_delete(AES_TABLIST * tablist);
+AES_TAB * tablist_add(AES_TABLIST * tablist, short tab, OBJECT *page_tree,
+ short page);
+short tablist_activate(AES_TABLIST * tablist, short tab, short option);
+struct aes_tab_s *tablist_get_active(AES_TABLIST * tablist);
+AES_TAB * tablist_find(AES_TABLIST * tablist, OBJECT *page, short tab);
+
+#define AES_TAB_IS_ACTIVE(l, x) (tablist_get_active(l) == x)
+
+#endif // AESTABS_H_INCLUDED
diff --git a/atari/gemtk/dragdrop.c b/atari/gemtk/dragdrop.c
new file mode 100755
index 000000000..e4ae2da4d
--- /dev/null
+++ b/atari/gemtk/dragdrop.c
@@ -0,0 +1,515 @@
+/*
+* Routine pour Drag and drop sous MultiTos
+* source: D&D Atari, demo OEP (Alexander Lorenz)
+*
+* Struktur OEP (oep.apid): AES-ID der Applikation
+*
+* (Tab = 4)
+*/
+
+#ifdef __PUREC__
+#include <tos.h>
+#else
+#include <osbind.h>
+#include <mintbind.h>
+#include <signal.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+
+#include "gemtk.h"
+#include "cflib.h"
+
+#ifndef EACCDN
+#define EACCDN (-36)
+#endif
+
+#ifndef FA_HIDDEN
+#define FA_HIDDEN 0x02
+#endif
+
+static char pipename[] = "U:\\PIPE\\DRAGDROP.AA";
+static long pipesig;
+
+/*
+* Routinen fr den Sender
+*/
+
+/*
+* Erzeugt Pipe fr D&D
+*
+* Eingabeparameter:
+* pipe - Pointer auf 2 Byte Buffer fr Pipeextension
+*
+* Ausgabeparameters:
+* keine
+*
+* Returnwert:
+* >0: Filehandle der Pipe
+* -1: Fehler beim Erzeugen der Pipe
+*/
+
+short ddcreate(short *pipe)
+{
+ long fd = -1;
+
+ pipename[17] = 'A';
+ pipename[18] = 'A' - 1;
+
+ do /* ouvre un pipe inoccup‚ */
+ {
+ pipename[18]++;
+ if (pipename[18] > 'Z')
+ {
+ pipename[17]++;
+ if (pipename[17] > 'Z')
+ break;
+ else
+ pipename[18] = 'A';
+ }
+
+ /* FA_HIDDEN fr Pipe notwendig! */
+
+ fd = Fcreate(pipename, FA_HIDDEN);
+
+ } while (fd == (long) EACCDN);
+
+ if (fd < 0L)
+ return(-1);
+
+ *pipe = (pipename[17] << 8) | pipename[18];
+
+
+ /* Signalhandler konfigurieren */
+
+ ddgetsig(&pipesig);
+
+
+ return((short) fd);
+}
+
+
+
+/*
+* Sendet AP_DRAGDROP an Empf„ngerapplikation
+*
+* Eingabeparameter:
+* apid - AES-ID der Emf„ngerapp.
+* fd - Filehandle der D&D-Pipe
+* winid - Handle des Zielfensters (0 fr Desktopfenster)
+* mx/my - Maus X und Y Koord.
+* (-1/-1 fr einen fake Drag&Drop)
+* kstate - Sondertastenstatus
+* pipename - Extension der D&D-Pipe
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwert:
+* >0: kein Fehler
+* -1: Empf„ngerapp. gibt DD_NAK zurck
+* -2: Empf„ngerapp. antwortet nicht (Timeout)
+* -3: Fehler bei appl_write()
+*/
+
+short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipeid)
+{
+ char c;
+ short i, msg[8];
+ long fd_mask;
+
+
+ /* AES-Message define and post */
+
+ msg[0] = AP_DRAGDROP;
+ msg[1] = _AESapid;
+ msg[2] = 0;
+ msg[3] = winid;
+ msg[4] = mx;
+ msg[5] = my;
+ msg[6] = kstate;
+ msg[7] = pipeid;
+
+ i = appl_write(apid, 16, msg);
+
+ if (i == 0)
+ {
+ ddclose(fd);
+ return(-3);
+ }
+
+
+ /* receiver reaction */
+
+ fd_mask = (1L << fd);
+ i = Fselect(DD_TIMEOUT, &fd_mask, 0L, 0L);
+ if (!i || !fd_mask)
+ {
+ /* Timeout eingetreten */
+
+ ddclose(fd);
+ return(-2);
+ }
+
+
+ /* le recepteur refuse (lecture du pipe) */
+
+ if (Fread(fd, 1L, &c) != 1L)
+ {
+ ddclose(fd);
+ return(-1);
+ }
+
+ if (c != DD_OK)
+ {
+ ddclose(fd);
+ return(-1);
+ }
+
+ return(1);
+}
+
+
+
+/*
+* Liest die 8 "bevorzugten" Extensionen der Empf„ngerapplikation
+*
+* Eingabeparameter:
+* fd - Filehandle der D&D-Pipe
+*
+* Ausgabeparameters:
+* exts - 32 Bytebuffer fr die 8 bevorzugten Extensionen
+* der Zielapp.
+*
+* Returnwert:
+* >0: kein Fehler
+* -1: Fehler beim Lesen aus der Pipe
+*/
+
+short ddrexts(short fd, char *exts)
+{
+ if (Fread(fd, DD_EXTSIZE, exts) != DD_EXTSIZE)
+ {
+ ddclose(fd);
+ return(-1);
+ }
+
+ return(1);
+}
+
+
+
+/*
+* Testet, ob der Empf„nger einen Datentyp akzeptiert
+*
+* Eingabeparameter:
+* fd - Filehandle (von ddcreate())
+* ext - Zeiger auf Datentyp (4 Bytes zB. "ARGS")
+* text - Zeiger auf Datenbeschreibung (optional, zB. "DESKTOP args")
+* name - Zeiger auf Datendateiname (optional, zB. "SAMPLE.TXT")
+* size - Anzahl Bytes der zu sendenden Daten
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwert:
+* DD_OK - Empf„nger akzeptiert Datentyp
+* DD_NAK - Empf„nger brach Drag&Drop ab
+* DD_EXT - Empf„nger lehnt Datentyp ab
+* DD_LEN - Empf„nger kann Datenmenge nicht verarbeiten
+* DD_TRASH - Drop erfolgte auf Mlleimer
+* DD_PRINTER - Drop erfolgte auf Drucker
+* DD_CLIPBOARD - Drop erfolgte auf Clipboard
+*/
+
+short ddstry(short fd, char *ext, char *text, char *name, long size)
+{
+ char c;
+ short hdrlen, i;
+
+ /* 4 Bytes fr "ext", 4 Bytes fr "size",
+ 2 Bytes fr Stringendnullen */
+
+ hdrlen = (short) (4 + 4 + strlen(text)+1 + strlen(name)+1);
+
+
+ /* Header senden */
+
+ if (Fwrite(fd, 2L, &hdrlen) != 2L)
+ return(DD_NAK);
+
+ i = (short) Fwrite(fd, 4L, ext);
+ i += (short) Fwrite(fd, 4L, &size);
+ i += (short) Fwrite(fd, strlen(text)+1, text);
+ i += (short) Fwrite(fd, strlen(name)+1, name);
+
+ if (i != hdrlen)
+ return(DD_NAK);
+
+
+ /* auf die Antwort warten */
+
+ if (Fread(fd, 1L, &c) != 1L)
+ return(DD_NAK);
+
+ return(c);
+}
+
+
+
+/* Routinen fr Sender und Empf„nger */
+
+/*
+* Pipe schliežen (Drag&Drop beenden/abbrechen)
+*/
+
+void ddclose(short fd)
+{
+ /* Signalhandler restaurieren */
+
+ ddsetsig(pipesig);
+
+
+ Fclose(fd);
+}
+
+
+/*
+* Signalhandler fr D&D konfigurieren
+*
+* Eingabeparameter:
+* oldsig - Zeiger auf 4 Byte Puffer fr alten Handlerwert
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwerte:
+* keine
+*/
+
+void ddgetsig(long *oldsig)
+{
+ *oldsig = (long) Psignal(SIGPIPE, (void *) SIG_IGN);
+}
+
+
+/*
+* Signalhandler nach D&D restaurieren
+*
+* Eingabeparameter:
+* oldsig - Alter Handlerwert (von ddgetsig)
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwerte:
+* keine
+*/
+
+void ddsetsig(long oldsig)
+{
+ if (oldsig != -32L)
+ Psignal(SIGPIPE, (void *) oldsig);
+}
+
+
+
+/* Routinen fr Empf„nger */
+
+/*
+* Drag&Drop Pipe ”ffnen
+*
+* Eingabeparameter:
+* ddnam - Extension der Pipe (letztes short von AP_DRAGDROP)
+* ddmsg - DD_OK oder DD_NAK
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwerte:
+* >0 - Filehandle der Drag&Drop pipe
+* -1 - Drag&Drop abgebrochen
+*/
+
+short ddopen(short ddnam, char ddmsg)
+{
+ long fd;
+
+ pipename[17] = (ddnam & 0xff00) >> 8;
+ pipename[18] = ddnam & 0x00ff;
+
+ fd = Fopen(pipename, 2);
+
+ if (fd < 0L)
+ return(-1);
+
+
+ /* Signalhandler konfigurieren */
+
+ ddgetsig(&pipesig);
+
+
+ if (Fwrite((short) fd, 1L, &ddmsg) != 1L)
+ {
+ ddclose((short) fd);
+ return(-1);
+ }
+
+ return((short) fd);
+}
+
+
+
+/*
+* Schreibt die 8 "bevorzugten" Extensionen der Applikation
+*
+* Eingabeparameter:
+* fd - Filehandle der D&D-Pipe
+* exts - Liste aus acht 4 Byte Extensionen die verstanden
+* werden. Diese Liste sollte nach bevorzugten Datentypen
+* sortiert sein. Sollten weniger als DD_NUMEXTS
+* Extensionen untersttzt werden, muž die Liste mit
+* Nullen (0) aufgefllt werden!
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwert:
+* >0: kein Fehler
+* -1: Fehler beim Schreiben in die Pipe
+*/
+
+short ddsexts(short fd, char *exts)
+{
+ if (Fwrite(fd, DD_EXTSIZE, exts) != DD_EXTSIZE)
+ {
+ ddclose(fd);
+ return(-1);
+ }
+
+ return(1);
+}
+
+
+
+/*
+* N„chsten Header vom Sender holen
+*
+* Eingabeparameter:
+* fd - Filehandle der Pipe (von ddopen())
+*
+* Ausgabeparameters:
+* name - Zeiger auf Buffer fr Datenbeschreibung (min. DD_NAMEMAX!)
+* file - Zeiger auf Buffer fr Datendateiname (min. DD_NAMEMAX!)
+* whichext- Zeiger auf Buffer fr Extension (4 Bytes)
+* size - Zeiger auf Buffer fr Datengr”že (4 Bytes)
+*
+* Returnwert:
+* >0: kein Fehler
+* -1: Sender brach Drag&Drop ab
+*
+* On lit dans le pipe qui normalement est constitu‚ de:
+* 1 short: taille du header
+* 4 CHAR: type de donn‚e (extension)
+* 1 long: taille des donn‚es
+* STRING: description des donn‚es
+* STRING: nom du fichiers
+* soit au minimun 11 octets (cas ou les string sont r‚duites … \0)
+* les string sont limit‚ a 128 octets
+*/
+
+short ddrtry(short fd, char *name, char *file, char *whichext, long *size)
+{
+ char buf[DD_NAMEMAX * 2];
+ short hdrlen, i, len;
+
+ if (Fread(fd, 2L, &hdrlen) != 2L)
+ return(-1);
+
+
+ if (hdrlen < 9) /* il reste au minimum 11 - 2 = 9 octets a lire */
+ {
+ /* sollte eigentlich nie passieren */
+
+ return(-1); /* erreur taille incorrecte */
+ }
+
+ if (Fread(fd, 4L, whichext) != 4L) /* lecture de l'extension */
+ return(-1);
+
+ if (Fread(fd, 4L, size) != 4L) /* lecture de la longueurs des donn‚es */
+ return(-1);
+
+ hdrlen -= 8; /* on a lu 8 octets */
+
+ if (hdrlen > DD_NAMEMAX*2)
+ i = DD_NAMEMAX*2;
+ else
+ i = hdrlen;
+
+ len = i;
+
+ if (Fread(fd, (long) i, buf) != (long) i)
+ return(-1);
+
+ hdrlen -= i;
+
+ strncpy(name, buf, DD_NAMEMAX);
+
+ i = (short) strlen(name) + 1;
+
+ if (len - i > 0)
+ strncpy(file, buf + i, DD_NAMEMAX);
+ else
+ file[0] = '\0';
+
+
+ /* weitere Bytes im Header in den Mll */
+
+ while (hdrlen > DD_NAMEMAX*2)
+ {
+ if (Fread(fd, DD_NAMEMAX*2, buf) != DD_NAMEMAX*2)
+ return(-1);
+
+ hdrlen -= DD_NAMEMAX*2;
+ }
+
+ if (hdrlen > 0)
+ {
+ if (Fread(fd, (long) hdrlen, buf) != (long) hdrlen)
+ return(-1);
+ }
+
+ return(1);
+}
+
+
+
+/*
+* Sendet der Senderapplikation eine 1 Byte Antwort
+*
+* Eingabeparameter:
+* fd - Filehandle der Pipe (von ddopen())
+* ack - Byte das gesendet werden soll (zB. DD_OK)
+*
+* Ausgabeparameter:
+* keine
+*
+* Returnwert:
+* >0: kein Fehler
+* -1: Fehler (die Pipe wird automatisch geschlossen!)
+*/
+
+short ddreply(short fd, char ack)
+{
+ if (Fwrite(fd, 1L, &ack) != 1L)
+ {
+ ddclose(fd);
+ return(-1);
+ }
+
+ return(1);
+}
+
+
diff --git a/atari/gemtk/dragdrop.h b/atari/gemtk/dragdrop.h
new file mode 100755
index 000000000..38466137b
--- /dev/null
+++ b/atari/gemtk/dragdrop.h
@@ -0,0 +1,4 @@
+#ifndef DD_H_INCLUDED
+#define DD_H_INCLUDED
+
+#endif
diff --git a/atari/gemtk/gemtk.h b/atari/gemtk/gemtk.h
new file mode 100644
index 000000000..01588dc63
--- /dev/null
+++ b/atari/gemtk/gemtk.h
@@ -0,0 +1,197 @@
+#ifndef GEMTK_H_INCLUDED
+#define GEMTK_H_INCLUDED
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include <mint/osbind.h>
+#include <mint/cookie.h>
+
+#include <gem.h>
+#include <cflib.h>
+
+
+/* -------------------------------------------------------------------------- */
+/* SYSTEM UTILS */
+/* -------------------------------------------------------------------------- */
+
+/* System type detection added by [GS] */
+/* detect the system type, AES + kernel */
+#define SYS_TOS 0x0001
+#define SYS_MAGIC 0x0002
+#define SYS_MINT 0x0004
+#define SYS_GENEVA 0x0010
+#define SYS_NAES 0x0020
+#define SYS_XAAES 0x0040
+#define sys_type() (_systype_v ? _systype_v : _systype())
+#define sys_MAGIC() ((sys_type() & SYS_MAGIC) != 0)
+#define sys_NAES() ((sys_type() & SYS_NAES) != 0)
+#define sys_XAAES() ((sys_type() & SYS_XAAES) != 0)
+
+#define TOS4VER 0x03300 /* this is assumed to be the last single tasking OS */
+
+extern unsigned short _systype_v;
+unsigned short _systype (void);
+
+/*
+* Chech for GRECT intersection without modifiend the src rectangles
+* return true when the GRECT's intersect, fals otherwise.
+*/
+bool rc_intersect_ro(GRECT *a, GRECT *b);
+
+/*
+* Convert keycode returned by evnt_multi to ascii value
+*/
+int keybd2ascii( int keybd, int shift);
+
+
+#ifndef POINT_WITHIN
+# define POINT_WITHIN(_x,_y, r) ((_x >= r.g_x) && (_x <= r.g_x + r.g_w ) \
+ && (_y >= r.g_y) && (_y <= r.g_y + r.g_h))
+#endif
+
+#ifndef RC_WITHIN
+# define RC_WITHIN(a,b) \
+ (((a)->g_x >= (b)->g_x) \
+ && (((a)->g_x + (a)->g_w) <= ((b)->g_x + (b)->g_w))) \
+ && (((a)->g_y >= (b)->g_y) \
+ && (((a)->g_y + (a)->g_h) <= ((b)->g_y + (b)->g_h)))
+#endif
+
+#ifndef MAX
+# define MAX(_a,_b) ((_a>_b) ? _a : _b)
+#endif
+
+#ifndef MIN
+# define MIN(_a,_b) ((_a<_b) ? _a : _b)
+#endif
+
+#ifndef SET_BIT
+# define SET_BIT(field,bit,val) field = (val)?((field)|(bit)):((field) & ~(bit))
+#endif
+
+/* -------------------------------------------------------------------------- */
+/* MultiTOS Drag & Drop */
+/* -------------------------------------------------------------------------- */
+short ddcreate(short *pipe);
+short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipename);
+short ddrexts(short fd, char *exts);
+short ddstry(short fd, char *ext, char *text, char *name, long size);
+void ddclose(short fd);
+void ddgetsig(long *oldsig);
+void ddsetsig(long oldsig);
+short ddopen(short ddnam, char ddmsg);
+short ddsexts(short fd, char *exts);
+short ddrtry(short fd, char *name, char *file, char *whichext, long *size);
+short ddreply(short fd, char ack);
+
+/* -------------------------------------------------------------------------- */
+/* Message Box module */
+/* -------------------------------------------------------------------------- */
+#define MSG_BOX_ALERT 1
+#define MSG_BOX_CONFIRM 2
+
+short msg_box_show(short type, const char * msg);
+
+/* -------------------------------------------------------------------------- */
+/* GUIWIN Module */
+/* -------------------------------------------------------------------------- */
+#define GW_FLAG_PREPROC_WM 0x01 // let guiwin API handle some events
+#define GW_FLAG_RECV_PREPROC_WM 0x02 // get notified even when pre-processed
+#define GW_FLAG_HAS_VTOOLBAR 0x04 // the attached toolbar is vertical
+#define GW_FLAG_CUSTOM_TOOLBAR 0x08 // no internal toolbar handling
+#define GW_FLAG_TOOLBAR_REDRAW 0x10 // enable internal toolbar redraw
+#define GW_FLAG_CUSTOM_SCROLLING 0x20 // no internal scroller handling
+
+#define GW_FLAG_DEFAULTS (GW_FLAG_PREPROC_WM | GW_FLAG_RECV_PREPROC_WM \
+ | GW_FLAG_TOOLBAR_REDRAW)
+
+#define GW_STATUS_ICONIFIED 0x01
+#define GW_STATUS_SHADED 0x02
+
+#define GW_XTYPE_CHECKBOX (101 << 8)
+#define GW_CB_SELECTED (OS_SELECTED | OS_CROSSED)
+
+#define GUIWIN_VSLIDER 0x01
+#define GUIWIN_HSLIDER 0x02
+#define GUIWIN_VH_SLIDER 0x03
+
+/*
+ Message sent to the client application when an AES object is
+ clicked in an window which contains an form.
+
+ Message Parameters:
+ msg[4] = Clicked Object.
+ msg[5] = Number of clicks.
+ msg[6] = Modifier keys.
+*/
+#define GUIWIN_WM_FORM 1001
+
+struct gui_window_s;
+typedef struct gui_window_s GUIWIN;
+typedef short (*guiwin_event_handler_f)(GUIWIN *gw,
+ EVMULT_OUT *ev_out, short msg[8]);
+struct guiwin_scroll_info_s {
+ int x_unit_px;
+ int y_unit_px;
+ int x_pos;
+ int y_pos;
+ int x_units;
+ int y_units;
+};
+
+enum guwin_area_e {
+ GUIWIN_AREA_WORK = 0,
+ GUIWIN_AREA_TOOLBAR,
+ GUIWIN_AREA_CONTENT
+};
+
+short guiwin_init(void);
+void guiwin_exit(void);
+GUIWIN * guiwin_add(short handle, uint32_t flags,
+ guiwin_event_handler_f handler);
+GUIWIN *guiwin_find(short handle);
+short guiwin_remove(GUIWIN *win);
+GUIWIN *guiwin_validate_ptr(GUIWIN *win);
+short guiwin_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out,
+ short msg[8]);
+void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest);
+short guiwin_get_handle(GUIWIN *win);
+uint32_t guiwin_get_state(GUIWIN *win);
+void guiwin_set_toolbar(GUIWIN *win, OBJECT *toolbar, short idx,
+ uint32_t flags);
+void guiwin_set_event_handler(GUIWIN *win,guiwin_event_handler_f cb);
+void guiwin_set_user_data(GUIWIN *win, void *data);
+void *guiwin_get_user_data(GUIWIN *win);
+struct guiwin_scroll_info_s * guiwin_get_scroll_info(GUIWIN *win);
+void guiwin_set_scroll_grid(GUIWIN * win, short x, short y);
+void guiwin_set_content_units(GUIWIN * win, short x, short y);
+void guiwin_set_form(GUIWIN *win, OBJECT *tree, short index);
+bool guiwin_update_slider(GUIWIN *win, short mode);
+void guiwin_scroll(GUIWIN *gw, short orientation, int units, bool refresh);
+void guiwin_send_msg(GUIWIN *win, short msgtype, short a, short b, short c,
+ short d);
+void guiwin_send_redraw(GUIWIN *win, GRECT *area);
+VdiHdl guiwin_get_vdi_handle(GUIWIN *win);
+bool guiwin_has_intersection(GUIWIN *win, GRECT *work);
+void guiwin_toolbar_redraw(GUIWIN *win, GRECT *clip);
+void guiwin_form_redraw(GUIWIN *gw, GRECT *clip);
+void guiwin_clear(GUIWIN *win);
+
+/* -------------------------------------------------------------------------- */
+/* AES SCROLLER MODULE */
+/* -------------------------------------------------------------------------- */
+
+/* -------------------------------------------------------------------------- */
+/* AES TABS MODULE */
+/* -------------------------------------------------------------------------- */
+
+/* -------------------------------------------------------------------------- */
+/* AES OBJECT TREE TOOLS */
+/* -------------------------------------------------------------------------- */
+char *get_text(OBJECT * tree, short idx);
+GRECT * obj_screen_rect(OBJECT * tree, short obj);
+bool obj_is_inside(OBJECT * tree, short obj, GRECT *area);
+OBJECT *get_tree(int idx);
+void obj_mouse_sprite(OBJECT *tree, int index);
+#endif // GEMTK_H_INCLUDED
diff --git a/atari/gemtk/guiwin.c b/atari/gemtk/guiwin.c
new file mode 100644
index 000000000..666200bfc
--- /dev/null
+++ b/atari/gemtk/guiwin.c
@@ -0,0 +1,1076 @@
+/*
+ * 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/>.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <cflib.h>
+
+
+#include <gem.h>
+#include <mt_gem.h>
+#include "gemtk.h"
+
+//#define DEBUG_PRINT(x) printf x
+#define DEBUG_PRINT(x)
+
+struct gui_window_s {
+ short handle;
+ guiwin_event_handler_f handler_func;
+ uint32_t flags;
+ uint32_t state;
+ OBJECT *toolbar;
+ short toolbar_edit_obj;
+ short toolbar_idx;
+ OBJECT *form;
+ short form_edit_obj;
+ short form_focus_obj;
+ short form_idx;
+ struct guiwin_scroll_info_s scroll_info;
+ void *user_data;
+ struct gui_window_s *next, *prev;
+};
+
+static GUIWIN * winlist;
+static VdiHdl v_vdi_h = -1;
+static short work_out[57];
+
+static void move_rect(GUIWIN * win, GRECT *rect, int dx, int dy)
+{
+ INT16 xy[ 8];
+ long dum = 0L;
+ GRECT g;
+
+ VdiHdl vh = guiwin_get_vdi_handle(win);
+
+ while(!wind_update(BEG_UPDATE));
+ 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;
+ vro_cpyfm(vh, S_ONLY, xy, (MFDB *)&dum, (MFDB *)&dum);
+
+ graf_mouse(M_ON, 0L);
+ wind_update(END_UPDATE);
+}
+
+/**
+* Handles common events.
+* returns 0 when the event was not handled, 1 otherwise.
+*/
+static short preproc_wm(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
+{
+ GRECT g, g_ro, g2;
+ short retval = 1;
+ int val = 1, old_val;
+ struct guiwin_scroll_info_s *slid;
+
+ switch(msg[0]) {
+
+ case WM_HSLID:
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ wind_set(gw->handle, WF_HSLIDE, msg[4], 0, 0, 0);
+ slid = guiwin_get_scroll_info(gw);
+ val = (float)(slid->x_units-(g.g_w/slid->x_unit_px))/1000*(float)msg[4];
+ if(val != slid->x_pos) {
+ if (val < slid->x_pos) {
+ val = -(MAX(0, slid->x_pos-val));
+ } else {
+ val = val-slid->x_pos;
+ }
+ guiwin_scroll(gw, GUIWIN_HSLIDER, val, false);
+ }
+ break;
+
+ case WM_VSLID:
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ wind_set(gw->handle, WF_VSLIDE, msg[4], 0, 0, 0);
+ slid = guiwin_get_scroll_info(gw);
+ 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);
+ } else {
+ val = val -slid->y_pos;
+ }
+ guiwin_scroll(gw, GUIWIN_VSLIDER, val, false);
+ }
+ break;
+
+ case WM_ARROWED:
+ if((gw->flags & GW_FLAG_CUSTOM_SCROLLING) == 0) {
+
+ slid = guiwin_get_scroll_info(gw);
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ g_ro = g;
+
+ switch(msg[4]) {
+
+ case WA_UPPAGE:
+ /* scroll page up */
+ guiwin_scroll(gw, GUIWIN_VSLIDER, -(g.g_h/slid->y_unit_px),
+ true);
+ break;
+
+ case WA_UPLINE:
+ /* scroll line up */
+ guiwin_scroll(gw, GUIWIN_VSLIDER, -1, true);
+ break;
+
+ case WA_DNPAGE:
+ /* scroll page down */
+ guiwin_scroll(gw, GUIWIN_VSLIDER, g.g_h/slid->y_unit_px,
+ true);
+ break;
+
+ case WA_DNLINE:
+ /* scroll line down */
+ guiwin_scroll(gw, GUIWIN_VSLIDER, +1, true);
+ break;
+
+ case WA_LFPAGE:
+ /* scroll page left */
+ guiwin_scroll(gw, GUIWIN_HSLIDER, -(g.g_w/slid->x_unit_px),
+ true);
+ break;
+
+ case WA_LFLINE:
+ /* scroll line left */
+ guiwin_scroll(gw, GUIWIN_HSLIDER, -1,
+ true);
+ break;
+
+ case WA_RTPAGE:
+ /* scroll page right */
+ guiwin_scroll(gw, GUIWIN_HSLIDER, (g.g_w/slid->x_unit_px),
+ true);
+ break;
+
+ case WA_RTLINE:
+ /* scroll line right */
+ guiwin_scroll(gw, GUIWIN_HSLIDER, 1,
+ true);
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+
+ 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);
+
+ if (gw->form) {
+
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ slid = guiwin_get_scroll_info(gw);
+
+ 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);
+ }
+
+ break;
+
+ case WM_SIZED:
+ case WM_REPOSED:
+ wind_get_grect(gw->handle, WF_FULLXYWH, &g2);
+ wind_get_grect(gw->handle, WF_CURRXYWH, &g);
+ g.g_w = MIN(msg[6], g2.g_w);
+ g.g_h = MIN(msg[7], g2.g_h);
+ 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);
+ if((gw->flags & GW_FLAG_CUSTOM_SCROLLING) == 0) {
+ if(guiwin_update_slider(gw, GUIWIN_VH_SLIDER)) {
+ guiwin_send_redraw(gw, NULL);
+ }
+ }
+ }
+
+
+ break;
+
+ case WM_FULLED:
+ wind_get_grect(gw->handle, WF_FULLXYWH, &g);
+ wind_get_grect(gw->handle, WF_CURRXYWH, &g2);
+ if(g.g_w == g2.g_w && g.g_h == g2.g_h) {
+ wind_get_grect(gw->handle, WF_PREVXYWH, &g);
+ }
+ wind_set_grect(gw->handle, WF_CURRXYWH, &g);
+ if((gw->flags & GW_FLAG_CUSTOM_SCROLLING) == 0) {
+ if(guiwin_update_slider(gw, GUIWIN_VH_SLIDER)) {
+ guiwin_send_redraw(gw, NULL);
+ }
+ }
+ break;
+
+ case WM_ICONIFY:
+ wind_set(gw->handle, WF_ICONIFY, msg[4], msg[5], msg[6], msg[7]);
+ gw->state |= GW_STATUS_ICONIFIED;
+ break;
+
+ case WM_UNICONIFY:
+ wind_set(gw->handle, WF_UNICONIFY, msg[4], msg[5], msg[6], msg[7]);
+ gw->state &= ~(GW_STATUS_ICONIFIED);
+ break;
+
+ case WM_SHADED:
+ gw->state |= GW_STATUS_SHADED;
+ break;
+
+ case WM_UNSHADED:
+ gw->state &= ~(GW_STATUS_SHADED);
+ break;
+
+ case WM_REDRAW:
+ if ((gw->flags & GW_FLAG_TOOLBAR_REDRAW)
+ && (gw->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0) {
+ g.g_x = msg[4];
+ g.g_y = msg[5];
+ g.g_w = msg[6];
+ g.g_h = msg[7];
+ guiwin_toolbar_redraw(gw, &g);
+ }
+ if (gw->form != NULL) {
+ g.g_x = msg[4];
+ g.g_y = msg[5];
+ g.g_w = msg[6];
+ g.g_h = msg[7];
+ guiwin_form_redraw(gw, &g);
+ }
+ break;
+
+ default:
+ retval = 0;
+ break;
+
+ }
+
+ return(retval);
+}
+
+static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
+{
+ short retval = 0;
+
+ DEBUG_PRINT(("preproc_mu_button\n"));
+
+ // toolbar handling:
+ if ((gw->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0
+ && gw->toolbar != NULL) {
+
+ GRECT tb_area;
+
+ guiwin_get_grect(gw, GUIWIN_AREA_TOOLBAR, &tb_area);
+
+ if (POINT_WITHIN(ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y, tb_area)) {
+ // send WM_TOOLBAR message
+ gw->toolbar[gw->toolbar_idx].ob_x = tb_area.g_x;
+ gw->toolbar[gw->toolbar_idx].ob_y = tb_area.g_y;
+ short obj_idx = objc_find(gw->toolbar,
+ gw->toolbar_idx, 8,
+ ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y);
+
+ DEBUG_PRINT(("Toolbar index: %d\n", obj_idx));
+ if (obj_idx > 0) {
+ if ((gw->toolbar[obj_idx].ob_flags & OF_SELECTABLE)!=0
+ && ((gw->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0)
+ && ((gw->flags & GW_FLAG_TOOLBAR_REDRAW) == 1)) {
+ gw->toolbar[obj_idx].ob_state |= OS_SELECTED;
+ // TODO: optimize redraw by setting the object clip:
+ guiwin_toolbar_redraw(gw, NULL);
+ }
+ }
+
+ short oldevents = ev_out->emo_events;
+ short msg_out[8] = {WM_TOOLBAR, gl_apid,
+ 0, gw->handle,
+ obj_idx, ev_out->emo_mclicks,
+ ev_out->emo_kmeta, 0
+ };
+ 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;
+ }
+ }
+
+ if (gw->form != NULL) {
+
+ GRECT content_area;
+ struct guiwin_scroll_info_s *slid;
+
+ DEBUG_PRINT(("preproc_mu_button: handling form click.\n"));
+
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &content_area);
+
+ if (POINT_WITHIN(ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y, content_area)) {
+
+ slid = guiwin_get_scroll_info(gw);
+
+ 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);
+
+ gw->form_focus_obj = objc_find(gw->form, gw->form_idx, 8,
+ ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y);
+
+ DEBUG_PRINT(("Window Form click, obj: %d\n", gw->form_focus_obj));
+ if (gw->form_focus_obj > -1
+ && (gw->form[gw->form_focus_obj].ob_state & OS_DISABLED)== 0) {
+
+ uint16_t type = (gw->form[gw->form_focus_obj].ob_type & 0xFF);
+ uint16_t xtype = (gw->form[gw->form_focus_obj].ob_type & 0xFF00);
+ uint16_t nextobj, edit_idx;
+
+ DEBUG_PRINT(("type: %d, xtype: %d\n", type, xtype));
+
+ if (type == G_FTEXT || type == G_FBOXTEXT) {
+
+ // report mouse click to the tree:
+ retval = form_button(gw->form, gw->form_focus_obj,
+ ev_out->emo_mclicks, &nextobj);
+
+ // end edit mode for active edit object:
+ if(gw->form_edit_obj != -1) {
+ objc_edit(gw->form, gw->form_edit_obj,
+ ev_out->emo_kreturn, &edit_idx,
+ EDEND);
+ }
+
+ // activate the new edit object:
+ gw->form_edit_obj = gw->form_focus_obj;
+ objc_edit(gw->form, gw->form_edit_obj,
+ ev_out->emo_kreturn, &edit_idx,
+ EDINIT);
+
+ } else {
+
+ // end edit mode for active edit object:
+ if(gw->form_edit_obj != -1) {
+ objc_edit(gw->form, gw->form_edit_obj,
+ ev_out->emo_kreturn, &edit_idx,
+ EDEND);
+ gw->form_edit_obj = -1;
+ }
+
+ if ((xtype & GW_XTYPE_CHECKBOX) != 0) {
+
+ if ((gw->form[gw->form_focus_obj].ob_state & OS_SELECTED) != 0) {
+ gw->form[gw->form_focus_obj].ob_state &= ~(OS_SELECTED|OS_CROSSED);
+ } else {
+ gw->form[gw->form_focus_obj].ob_state |= (OS_SELECTED|OS_CROSSED);
+ }
+ guiwin_form_redraw(gw, obj_screen_rect(gw->form,
+ gw->form_focus_obj));
+ }
+ short oldevents = ev_out->emo_events;
+ short msg_out[8] = {GUIWIN_WM_FORM, gl_apid,
+ 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);
+ }
+ }
+ }
+ }
+
+ return(retval);
+}
+
+static short preproc_mu_keybd(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
+{
+
+ 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;
+
+ r = form_keybd(gw->form, gw->form_edit_obj, next_edit_obj,
+ ev_out->emo_kreturn,
+ &next_edit_obj, &next_char);
+
+ if (next_edit_obj != gw->form_edit_obj) {
+
+ if(gw->form_edit_obj != -1) {
+ objc_edit(gw->form, gw->form_edit_obj,
+ ev_out->emo_kreturn, &edit_idx,
+ EDEND);
+ }
+
+ gw->form_edit_obj = next_edit_obj;
+
+ objc_edit(gw->form, gw->form_edit_obj,
+ ev_out->emo_kreturn, &edit_idx,
+ EDINIT);
+ } else {
+ if(next_char > 13)
+ r = objc_edit(gw->form, gw->form_edit_obj,
+ ev_out->emo_kreturn, &edit_idx,
+ EDCHAR);
+ }
+ }
+}
+
+short guiwin_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out, short msg[8])
+{
+ GUIWIN *dest;
+ short retval = 0;
+ bool handler_called = false;
+
+ if( (ev_out->emo_events & MU_MESAG) != 0 ) {
+ DEBUG_PRINT(("guiwin_handle_event_multi_fast: %d\n", msg[0]));
+ switch (msg[0]) {
+ case WM_REDRAW:
+ 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:
+ dest = guiwin_find(msg[3]);
+ if (dest) {
+ DEBUG_PRINT(("Found WM_ dest: %p (%d), flags: %d, cb: %p\n", dest, dest->handle, dest->flags, dest->handler_func));
+ if (dest->flags&GW_FLAG_PREPROC_WM) {
+ retval = preproc_wm(dest, ev_out, msg);
+ if(((retval == 0)||(dest->flags&GW_FLAG_RECV_PREPROC_WM))) {
+ retval = dest->handler_func(dest, ev_out, msg);
+ handler_called = true;
+ }
+ } else {
+ if (dest->handler_func) {
+ retval = dest->handler_func(dest, ev_out, msg);
+ handler_called = true;
+ }
+ }
+
+ }
+ break;
+ }
+ } else {
+
+ 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)) {
+
+ dest = guiwin_find(h_aes);
+
+ if (dest == NULL || dest->handler_func == NULL)
+ return(0);
+
+ if ((ev_out->emo_events & MU_BUTTON) != 0) {
+
+ 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;
+ }
+ }
+
+ if ((ev_out->emo_events & MU_KEYBD)) {
+ retval = preproc_mu_keybd(dest, ev_out, msg);
+ }
+
+ if (handler_called==false) {
+ dest->handler_func(dest, ev_out, msg);
+ }
+ }
+ }
+
+ return(retval);
+}
+
+short guiwin_init(void)
+{
+ if(v_vdi_h == -1) {
+ short dummy;
+ short work_in[12] = {Getrez()+2,1,1,1,1,1,1,1,1,1,2,1};
+ v_vdi_h=graf_handle(&dummy, &dummy, &dummy, &dummy);
+ v_opnvwk(work_in, &v_vdi_h, work_out);
+ }
+ return(0);
+}
+
+void guiwin_exit(void)
+{
+ v_clsvwk(v_vdi_h);
+}
+
+GUIWIN * guiwin_add(short handle, uint32_t flags, guiwin_event_handler_f cb)
+{
+
+ GUIWIN *win = calloc(sizeof(GUIWIN),1);
+
+ assert(win!=NULL);
+ DEBUG_PRINT(("guiwin_add: %d, %p, cb: %p\n", handle, win, cb));
+
+ win->handle = handle;
+ win->handler_func = cb;
+ win->flags = flags;
+ 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;
+ }
+
+ DEBUG_PRINT(("Added guiwin: %p, tb: %p\n", win, win->toolbar));
+ return(win);
+}
+
+GUIWIN *guiwin_find(short handle)
+{
+ GUIWIN *g;
+ DEBUG_PRINT(("guiwin search handle: %d\n", handle));
+ for( g = winlist; g != NULL; g=g->next ) {
+ if(g->handle == handle) {
+ DEBUG_PRINT(("guiwin found handle: %p\n", g));
+ return(g);
+ }
+ }
+ return(NULL);
+}
+
+GUIWIN *guiwin_validate_ptr(GUIWIN *win)
+{
+ GUIWIN *g;
+ for( g = winlist; g != NULL; g=g->next ) {
+ DEBUG_PRINT(("guiwin guiwin_validate_ptr check: %p\n", g));
+ if(g == win) {
+ DEBUG_PRINT(("guiwin_validate_ptr valid: %p\n", g));
+ return(g);
+ }
+ }
+ return(NULL);
+}
+
+short guiwin_remove(GUIWIN *win)
+{
+ win = guiwin_validate_ptr(win);
+ if (win == NULL)
+ return(-1);
+
+ /* 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;
+ }
+ DEBUG_PRINT(("guiwin free: %p\n", win));
+ free(win);
+ return(0);
+}
+
+void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest)
+{
+
+ assert(win != NULL);
+
+ wind_get_grect(win->handle, WF_WORKXYWH, dest);
+ if (mode == GUIWIN_AREA_CONTENT) {
+ GRECT tb_area;
+ guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &tb_area);
+ if (win->flags & GW_FLAG_HAS_VTOOLBAR) {
+ dest->g_x += tb_area.g_w;
+ dest->g_w -= tb_area.g_w;
+ } else {
+ dest->g_y += tb_area.g_h;
+ dest->g_h -= tb_area.g_h;
+ }
+ } else if (mode == GUIWIN_AREA_TOOLBAR) {
+ if (win->toolbar != NULL) {
+ if (win->flags & GW_FLAG_HAS_VTOOLBAR) {
+ dest->g_w = win->toolbar[win->toolbar_idx].ob_width;
+ } else {
+ dest->g_h = win->toolbar[win->toolbar_idx].ob_height;
+ }
+ } else {
+ dest->g_h = 0;
+ dest->g_w = 0;
+ }
+ }
+}
+
+void guiwin_scroll(GUIWIN *gw, short orientation, int units, bool refresh)
+{
+ struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(gw);
+ int oldpos = 0, newpos = 0, vis_units=0, pix = 0;
+ int abs_pix = 0;
+ GRECT *redraw=NULL, g, g_ro;
+
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ g_ro = g;
+
+ if (orientation == GUIWIN_VSLIDER) {
+ 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));
+ if(newpos < 0) {
+ newpos = slid->y_pos = 0;
+ }
+ if(oldpos == newpos)
+ return;
+
+ if (units>=vis_units || guiwin_has_intersection(gw, &g_ro)) {
+ // send complete redraw
+ redraw = &g_ro;
+ } else {
+ // only adjust ypos when scrolling down:
+ if(pix < 0 ) {
+ // blit screen area:
+ g.g_h -= abs_pix;
+ move_rect(gw, &g, 0, abs_pix);
+ 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;
+ move_rect(gw, &g, 0, -abs_pix);
+ 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));
+
+ if(newpos < 0) {
+ newpos = slid->x_pos = 0;
+ }
+
+ if(oldpos == newpos)
+ return;
+ if (units>=vis_units || guiwin_has_intersection(gw, &g_ro)) {
+ // send complete redraw
+ redraw = &g_ro;
+ } else {
+ // only adjust ypos when scrolling down:
+ if(pix < 0 ) {
+ // blit screen area:
+ g.g_w -= abs_pix;
+ move_rect(gw, &g, abs_pix, 0);
+ 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;
+ move_rect(gw, &g, -abs_pix, 0);
+ g.g_x = g_ro.g_x + g_ro.g_w - abs_pix;
+ g.g_w = abs_pix;
+ redraw = &g;
+ }
+ }
+ }
+
+ if (refresh) {
+ guiwin_update_slider(gw, orientation);
+ }
+
+ if ((redraw != NULL) && (redraw->g_h > 0)) {
+ guiwin_send_redraw(gw, redraw);
+ }
+}
+
+bool guiwin_update_slider(GUIWIN *win, short mode)
+{
+ GRECT viewport;
+ struct guiwin_scroll_info_s * slid;
+ unsigned long size, pos;
+ int old_x, old_y;
+
+ short handle = guiwin_get_handle(win);
+ guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &viewport);
+ slid = guiwin_get_scroll_info(win);
+
+ old_x = slid->x_pos;
+ old_y = slid->y_pos;
+
+ if((mode & GUIWIN_VSLIDER) && (slid->y_unit_px > 0)) {
+ if ( slid->y_units < (long)viewport.g_h/slid->y_unit_px) {
+ size = 1000L;
+ } else
+ size = MAX( 50L, (unsigned long)viewport.g_h*1000L/
+ (unsigned long)(slid->y_unit_px*slid->y_units));
+ wind_set(handle, WF_VSLSIZE, (int)size, 0, 0, 0);
+
+ if (slid->y_units > (long)viewport.g_h/slid->y_unit_px) {
+ pos = (unsigned long)slid->y_pos *1000L/
+ (unsigned long)(slid->y_units-viewport.g_h/slid->y_unit_px);
+ 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);
+ }
+ }
+ if((mode & GUIWIN_HSLIDER) && (slid->x_unit_px > 0)) {
+ if ( slid->x_units < (long)viewport.g_w/slid->x_unit_px)
+ size = 1000L;
+ else
+ size = MAX( 50L, (unsigned long)viewport.g_w*1000L/
+ (unsigned long)(slid->x_unit_px*slid->x_units));
+ wind_set(handle, WF_HSLSIZE, (int)size, 0, 0, 0);
+
+ if( slid->x_units > (long)viewport.g_w/slid->x_unit_px) {
+ pos = (unsigned long)slid->x_pos*1000L/
+ (unsigned long)(slid->x_units-viewport.g_w/slid->x_unit_px);
+ 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);
+ }
+ }
+
+ if(old_x != slid->x_pos || old_y != slid->y_pos) {
+ return(true);
+ }
+ return(false);
+}
+
+short guiwin_get_handle(GUIWIN *win)
+{
+ return(win->handle);
+}
+
+VdiHdl guiwin_get_vdi_handle(GUIWIN *win)
+{
+ return(v_vdi_h);
+}
+
+uint32_t guiwin_get_state(GUIWIN *win)
+{
+ return(win->state);
+}
+
+void guiwin_set_event_handler(GUIWIN *win,guiwin_event_handler_f cb)
+{
+ win->handler_func = cb;
+}
+
+void guiwin_set_toolbar(GUIWIN *win, OBJECT *toolbar, short idx, uint32_t flags)
+{
+ win->toolbar = toolbar;
+ win->toolbar_idx = idx;
+ win->toolbar_edit_obj = -1;
+ if(flags & GW_FLAG_HAS_VTOOLBAR) {
+ win->flags |= GW_FLAG_HAS_VTOOLBAR;
+ }
+}
+
+void guiwin_set_user_data(GUIWIN *win, void *data)
+{
+ win->user_data = data;
+}
+
+void *guiwin_get_user_data(GUIWIN *win)
+{
+ return(win->user_data);
+}
+
+struct guiwin_scroll_info_s *guiwin_get_scroll_info(GUIWIN *win) {
+ return(&win->scroll_info);
+}
+
+void guiwin_set_scroll_grid(GUIWIN * win, short x, short y)
+{
+ struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(win);
+
+ assert(slid != NULL);
+
+ slid->y_unit_px = x;
+ slid->x_unit_px = y;
+}
+
+void guiwin_set_content_units(GUIWIN * win, short x, short y)
+{
+ struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(win);
+
+ assert(slid != NULL);
+
+ slid->x_units = x;
+ slid->y_units = y;
+}
+
+void guiwin_send_msg(GUIWIN *win, short msg_type, short a, short b, short c,
+ short d)
+{
+ short msg[8];
+
+ msg[0] = msg_type;
+ 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);
+}
+
+void guiwin_send_redraw(GUIWIN *win, GRECT *area)
+{
+ short msg[8], retval;
+ GRECT work;
+
+ EVMULT_IN event_in = {
+ .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;
+
+ if (area == NULL) {
+ guiwin_get_grect(win, GUIWIN_AREA_WORK, &work);
+ if (work.g_w < 1 || work.g_h < 1) {
+ if (win->toolbar != NULL) {
+ guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &work);
+ if (work.g_w < 1 || work.g_h < 1) {
+ return;
+ }
+ }
+ }
+ 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;
+
+ event_out.emo_events = MU_MESAG;
+ retval = preproc_wm(win, &event_out, msg);
+ if (retval == 0 || (win->flags & GW_FLAG_PREPROC_WM) != 0){
+ win->handler_func(win, &event_out, msg);
+ }
+
+
+
+ //appl_write(gl_apid, 16, &msg);
+}
+
+void guiwin_set_form(GUIWIN *win, OBJECT *tree, short index)
+{
+ 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;
+}
+
+bool guiwin_has_intersection(GUIWIN *win, GRECT *work)
+{
+ GRECT area, mywork;
+ bool retval = true;
+
+ if (work == NULL) {
+ guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &mywork);
+ 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);
+}
+
+void guiwin_toolbar_redraw(GUIWIN *gw, GRECT *clip)
+{
+ GRECT tb_area, tb_area_ro, g;
+
+ guiwin_get_grect(gw, GUIWIN_AREA_TOOLBAR, &tb_area_ro);
+
+ if(clip == NULL) {
+ clip = &tb_area_ro;
+ }
+
+ tb_area = tb_area_ro;
+
+ if(rc_intersect(clip, &tb_area)) {
+
+ // Update object position:
+ gw->toolbar[gw->toolbar_idx].ob_x = tb_area_ro.g_x;
+ gw->toolbar[gw->toolbar_idx].ob_width = tb_area_ro.g_w;
+ gw->toolbar[gw->toolbar_idx].ob_y = tb_area_ro.g_y;
+ 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);
+ }
+ }
+}
+
+
+void guiwin_form_redraw(GUIWIN *gw, GRECT *clip)
+{
+ GRECT area, area_ro, g;
+ int scroll_px_x, scroll_px_y;
+ struct guiwin_scroll_info_s *slid;
+ //int new_x, new_y, old_x, old_y;
+ short edit_idx;
+
+ DEBUG_PRINT(("guiwin_form_redraw\n"));
+
+ // calculate form coordinates, include scrolling:
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &area_ro);
+ slid = guiwin_get_scroll_info(gw);
+
+ // 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);
+ }
+ }
+}
+
+
+void guiwin_clear(GUIWIN *win)
+{
+ GRECT area, g;
+ short pxy[4];
+ VdiHdl vh;
+
+ vh = guiwin_get_vdi_handle(win);
+
+ if(win->state & GW_STATUS_ICONIFIED) {
+ // also clear the toolbar area when iconified:
+ guiwin_get_grect(win, GUIWIN_AREA_WORK, &area);
+ } else {
+ guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &area);
+ }
+
+ 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);
+ }
+}
diff --git a/atari/gemtk/guiwin.h b/atari/gemtk/guiwin.h
new file mode 100644
index 000000000..6daf16ca9
--- /dev/null
+++ b/atari/gemtk/guiwin.h
@@ -0,0 +1,4 @@
+#ifndef OPKG_GUI_GUIWIN_H
+#define OPKG_GUI_GUIWIN_
+
+#endif /* OPKG_GUIWIN_H */
diff --git a/atari/gemtk/msgbox.c b/atari/gemtk/msgbox.c
new file mode 100644
index 000000000..770e0af15
--- /dev/null
+++ b/atari/gemtk/msgbox.c
@@ -0,0 +1,84 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gem.h>
+#include "gemtk.h"
+
+#ifndef min
+# define min(x,y) ((x<y) ? x : y )
+#endif
+
+short msg_box_show(short type, const char * msg)
+{
+ #define MSG_BOX_STR_SIZE 256
+ short retval=0, i=0, z=0, l=0;
+ char c;
+ int len_msg = strlen(msg);
+
+ // TODO: localize strings
+ const char *str_yes = "Yes";
+ const char *str_no = "No";
+ const char *str_ok = "OK";
+ char msg_box_str[MSG_BOX_STR_SIZE];
+ char *dst = msg_box_str;
+
+ memset(msg_box_str, 0, MSG_BOX_STR_SIZE);
+
+ strncat(msg_box_str, "[1]", MSG_BOX_STR_SIZE);
+ strncat(msg_box_str, "[", MSG_BOX_STR_SIZE);
+
+ dst = msg_box_str + strlen(msg_box_str);
+
+ for (i=0; i<min(len_msg,40*5); i++) {
+
+ c = msg[i];
+
+ if(c==0)
+ break;
+
+ if (z==40) {
+ if(l==4){
+ break;
+ }
+ z = 0;
+ l++;
+ *dst = (char)'|';
+ dst++;
+ }
+
+ if ((c=='\r' || c=='\n') && *dst != '|') {
+ if(l==4){
+ break;
+ }
+ z = 0;
+ l++;
+ *dst = '|';
+ dst++;
+ }
+ else {
+ z++;
+ *dst = c;
+ dst++;
+ }
+ }
+ strncat(msg_box_str, "][", MSG_BOX_STR_SIZE);
+
+ if(type == MSG_BOX_CONFIRM){
+ strncat(msg_box_str, str_yes, MSG_BOX_STR_SIZE);
+ strncat(msg_box_str, "|", MSG_BOX_STR_SIZE);
+ strncat(msg_box_str, str_no, MSG_BOX_STR_SIZE);
+ } else {
+ strncat(msg_box_str, str_ok, MSG_BOX_STR_SIZE);
+ }
+ strncat(msg_box_str, "]", MSG_BOX_STR_SIZE);
+
+ retval = form_alert(type, msg_box_str);
+ if(type == MSG_BOX_CONFIRM){
+ if(retval != 1){
+ retval = 0;
+ }
+ }
+ return(retval);
+
+ #undef MSG_BOX_STR_SIZE
+}
diff --git a/atari/gemtk/msgbox.h b/atari/gemtk/msgbox.h
new file mode 100644
index 000000000..7a46900ef
--- /dev/null
+++ b/atari/gemtk/msgbox.h
@@ -0,0 +1,5 @@
+#ifndef GUIMSG_H_INCLUDED
+#define GUIMSG_H_INCLUDED
+
+
+#endif // GUIMSG_H_INCLUDED
diff --git a/atari/gemtk/objc.c b/atari/gemtk/objc.c
new file mode 100644
index 000000000..3bf8ebbe0
--- /dev/null
+++ b/atari/gemtk/objc.c
@@ -0,0 +1,106 @@
+/*
+ * 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/>.
+ *
+ * Module Description:
+ *
+ * AES Object tree tools.
+ *
+ */
+
+ #include "gemtk.h"
+
+char *get_text(OBJECT * tree, short idx)
+{
+ static char p[]="";
+ USERBLK *user;
+ char *retval;
+
+ switch (tree[idx].ob_type & 0x00FF) {
+ case G_BUTTON:
+ case G_STRING:
+ case G_TITLE:
+ return( tree[idx].ob_spec.free_string);
+ case G_TEXT:
+ case G_BOXTEXT:
+ case G_FTEXT:
+ case G_FBOXTEXT:
+ return (tree[idx].ob_spec.tedinfo->te_ptext);
+ case G_ICON:
+ case G_CICON:
+ return (tree[idx].ob_spec.iconblk->ib_ptext);
+ break;
+
+ default: break;
+ }
+ return (p);
+}
+
+OBJECT *get_tree(int idx)
+{
+
+ OBJECT *tree;
+
+ rsrc_gaddr(R_TREE, idx, &tree);
+
+ return tree;
+}
+
+bool obj_is_inside(OBJECT * tree, short obj, GRECT *area)
+{
+ GRECT obj_screen;
+ bool ret = false;
+
+ objc_offset(tree, obj, &obj_screen.g_x, &obj_screen.g_y);
+ obj_screen.g_w = tree[obj].ob_width;
+ obj_screen.g_h = tree[obj].ob_height;
+
+ ret = RC_WITHIN(&obj_screen, area);
+
+ return(ret);
+}
+
+GRECT * obj_screen_rect(OBJECT * tree, short obj)
+{
+ static GRECT obj_screen;
+
+ get_objframe(tree, obj, &obj_screen);
+
+ return(&obj_screen);
+}
+
+
+void obj_mouse_sprite(OBJECT *tree, int index)
+{
+ MFORM mform;
+ int dum;
+
+ if ((tree[index].ob_type & 0xFF) != G_ICON)
+ return;
+
+ dum = tree[index].ob_spec.iconblk->ib_char;
+ mform . mf_nplanes = 1;
+ mform . mf_fg = (dum>>8)&0x0F;
+ mform . mf_bg = dum>>12;
+ mform . mf_xhot = 0; /* to prevent the mform to "jump" on the */
+ mform . mf_yhot = 0; /* screen (zebulon rules!) */
+
+ for( dum = 0; dum<16; dum ++) {
+ mform . mf_mask[dum] = tree[index].ob_spec.iconblk->ib_pmask[dum];
+ mform . mf_data[dum] = tree[index].ob_spec.iconblk->ib_pdata[dum];
+ }
+ graf_mouse(USER_DEF, &mform);
+}
diff --git a/atari/gemtk/objc.h b/atari/gemtk/objc.h
new file mode 100644
index 000000000..6fa1072b7
--- /dev/null
+++ b/atari/gemtk/objc.h
@@ -0,0 +1,7 @@
+#ifndef GEMTK_OBJC_H
+#define GEMTK_OBJC_H
+
+
+
+#endif // GEMTK_OBJC_H
+
diff --git a/atari/gemtk/redrawslots.c b/atari/gemtk/redrawslots.c
new file mode 100644
index 000000000..ee5627daf
--- /dev/null
+++ b/atari/gemtk/redrawslots.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2011 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/>.
+ */
+
+#include <stdbool.h>
+#define WITH_RECT
+#include "gemtk.h"
+#undef WITH_RECT
+
+void redraw_slots_init(struct s_redrw_slots * slots, short size)
+{
+ // TODO: allocate slots dynamically!
+ slots->size = MIN( MAX_REDRW_SLOTS , size);
+ slots->areas_used = 0;
+}
+
+void redraw_slots_free(struct s_redrw_slots * slots)
+{
+ // TOOD: free areas...
+}
+
+
+static inline bool rect_intersect( struct rect * box1, struct rect * box2 )
+{
+ if (box2->x1 < box1->x0)
+ return false;
+
+ if (box2->y1 < box1->y0)
+ return false;
+
+ if (box2->x0 > box1->x1)
+ return false;
+
+ if (box2->y0 > box1->y1)
+ return false;
+
+ return true;
+}
+
+
+void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area,
+ bool force)
+{
+ redraw_slot_schedule(slots, area->g_x, area->g_y,
+ area->g_x + area->g_w, area->g_y + area->g_h, force);
+}
+
+/*
+ schedule redraw coords.
+*/
+void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0,
+ short x1, short y1, bool force)
+{
+ int i = 0;
+ struct rect area;
+
+ area.x0 = x0;
+ area.y0 = y0;
+ area.x1 = x1;
+ area.y1 = y1;
+
+ if (force == false) {
+ for (i=0; i<slots->areas_used; i++) {
+ if (slots->areas[i].x0 <= x0
+ && slots->areas[i].x1 >= x1
+ && slots->areas[i].y0 <= y0
+ && slots->areas[i].y1 >= y1) {
+ /* the area is already queued for redraw */
+ return;
+ } else {
+ if (rect_intersect(&slots->areas[i], &area )) {
+ slots->areas[i].x0 = MIN(slots->areas[i].x0, x0);
+ slots->areas[i].y0 = MIN(slots->areas[i].y0, y0);
+ slots->areas[i].x1 = MAX(slots->areas[i].x1, x1);
+ slots->areas[i].y1 = MAX(slots->areas[i].y1, y1);
+ return;
+ }
+ }
+ }
+ }
+
+ if (slots->areas_used < slots->size) {
+ slots->areas[slots->areas_used].x0 = x0;
+ slots->areas[slots->areas_used].x1 = x1;
+ slots->areas[slots->areas_used].y0 = y0;
+ slots->areas[slots->areas_used].y1 = y1;
+ slots->areas_used++;
+ } else {
+ /*
+ we are out of available slots, merge box with last slot
+ this is dumb... but also a very rare case.
+ */
+ slots->areas[slots->size-1].x0 = MIN(slots->areas[i].x0, x0);
+ slots->areas[slots->size-1].y0 = MIN(slots->areas[i].y0, y0);
+ slots->areas[slots->size-1].x1 = MAX(slots->areas[i].x1, x1);
+ slots->areas[slots->size-1].y1 = MAX(slots->areas[i].y1, y1);
+ }
+done:
+ return;
+}
+
+void redraw_slots_remove_area(struct s_redrw_slots * slots, int i)
+{
+ int x;
+ for(x = i+1; i<slots->areas_used; x++){
+ slots->areas[x-1] = slots->areas[x];
+ }
+ slots->areas_used--;
+}
diff --git a/atari/gemtk/redrawslots.h b/atari/gemtk/redrawslots.h
new file mode 100644
index 000000000..d045b3965
--- /dev/null
+++ b/atari/gemtk/redrawslots.h
@@ -0,0 +1,28 @@
+/*
+ * 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/>.
+ */
+
+
+#ifndef ATARI_REDRAW_SLOTS_H
+#define ATARI_REDRAW_SLOTS_H
+
+#include <mt_gem.h>
+#include "utils/types.h"
+
+
+
+#endif
diff --git a/atari/gemtk/utils.c b/atari/gemtk/utils.c
new file mode 100644
index 000000000..3fc668a06
--- /dev/null
+++ b/atari/gemtk/utils.c
@@ -0,0 +1,66 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <gem.h>
+#include "gemtk.h"
+
+/* -------------------------------------------------------------------------- */
+/* GEM Utillity functions: */
+/* -------------------------------------------------------------------------- */
+
+unsigned short _systype_v;
+unsigned short _systype (void)
+{
+ int32_t * cptr = NULL;
+ _systype_v = SYS_TOS;
+
+ cptr = (int32_t *)Setexc(0x0168, -1L);
+ if (cptr == NULL ) {
+ return _systype_v; /* stone old TOS without any cookie support */
+ }
+ while (*cptr) {
+ if (*cptr == C_MgMc || *cptr == C_MgMx ) {
+ _systype_v = (_systype_v & ~0xF) | SYS_MAGIC;
+ } else if (*cptr == C_MiNT ) {
+ _systype_v = (_systype_v & ~0xF) | SYS_MINT;
+ } else if (*cptr == C_Gnva /* Gnva */ ) {
+ _systype_v |= SYS_GENEVA;
+ } else if (*cptr == C_nAES /* nAES */ ) {
+ _systype_v |= SYS_NAES;
+ }
+ cptr += 2;
+ }
+ if (_systype_v & SYS_MINT) { /* check for XaAES */
+ short out = 0, u;
+ if (wind_get (0, (((short)'X') <<8)|'A', &out, &u,&u,&u) && out) {
+ _systype_v |= SYS_XAAES;
+ }
+ }
+ return _systype_v;
+}
+
+bool rc_intersect_ro(GRECT *a, GRECT *b)
+{
+ GRECT r1, r2;
+
+ r1 = *a;
+ r2 = *b;
+
+ return((bool)rc_intersect(&r1, &r2));
+}
+
+
+typedef struct {
+ char *unshift;
+ char *shift;
+ char *capslock;
+} MY_KEYTAB;
+
+int keybd2ascii( int keybd, int shift)
+{
+
+ MY_KEYTAB *key;
+ key = (MY_KEYTAB *)Keytbl( (char*)-1, (char*)-1, (char*)-1);
+ return (shift)?key->shift[keybd>>8]:key->unshift[keybd>>8];
+}
+
diff --git a/atari/gemtk/utils.h b/atari/gemtk/utils.h
new file mode 100644
index 000000000..7ebbcf228
--- /dev/null
+++ b/atari/gemtk/utils.h
@@ -0,0 +1,5 @@
+#ifndef UTILS_H_INCLUDED
+#define UTILS_H_INCLUDED
+
+
+#endif // UTILS_H_INCLUDED