Commit 5b7cef10 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Some RISC_OSLib rlib enhancements

menu.c/menu.h:
Add a new menu_setcolours() function to allow the fore/background colour bits to be set on a menu entry.
colourmenu.c:
Use the new menu_setcolours() function instead of making assumptions about menu's internal structure layout.
dbox.c/dbox.h:
New functions dbox_hidefield and dbox_unhidefield added to complement the fade/unfade ones.
As dbox_findicon/findiconbefore are only ever used to find writables, rename them as such. Also, make them find writable (type 15) AND writable draggable (type 14) icons.
Allow navigation by tab/shift tab through icons like the Style Guide chapter 16 says we should. In fact it's a little odd that dbox is emulating 'Ktar' validation itself manually when the Wimp has done this since version 2.92, but maintaining it is less effort than going and checking all the templates.
Fix bug when looking for leading capital letter matches to complete a dbox, the previous code was looking at the cached copy of the icon flags in d->window rathe...
parent 20861055
......@@ -14,10 +14,10 @@
Module_MajorVersion SETS "5.83"
Module_Version SETA 583
Module_MinorVersion SETS ""
Module_Date SETS "08 Jul 2014"
Module_ApplicationDate SETS "08-Jul-14"
Module_Date SETS "31 Jul 2014"
Module_ApplicationDate SETS "31-Jul-14"
Module_ComponentName SETS "RISC_OSLib"
Module_ComponentPath SETS "castle/RiscOS/Sources/Lib/RISC_OSLib"
Module_FullVersion SETS "5.83"
Module_HelpVersion SETS "5.83 (08 Jul 2014)"
Module_HelpVersion SETS "5.83 (31 Jul 2014)"
END
......@@ -6,18 +6,18 @@
*/
#define Module_MajorVersion_CMHG 5.83
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 08 Jul 2014
#define Module_Date_CMHG 31 Jul 2014
#define Module_MajorVersion "5.83"
#define Module_Version 583
#define Module_MinorVersion ""
#define Module_Date "08 Jul 2014"
#define Module_Date "31 Jul 2014"
#define Module_ApplicationDate "08-Jul-14"
#define Module_ApplicationDate "31-Jul-14"
#define Module_ComponentName "RISC_OSLib"
#define Module_ComponentPath "castle/RiscOS/Sources/Lib/RISC_OSLib"
#define Module_FullVersion "5.83"
#define Module_HelpVersion "5.83 (08 Jul 2014)"
#define Module_HelpVersion "5.83 (31 Jul 2014)"
#define Module_LibraryVersionInfo "5:83"
......@@ -56,8 +56,6 @@
menu colourmenu_make(char *title, BOOL includeNone)
{
menu m;
wimp_menuhdr *dptr;
wimp_menuitem *iptr; /* Very mode dependent */
wimp_palettestr palette;
int i, white, black, threshold;
......@@ -86,16 +84,11 @@ menu colourmenu_make(char *title, BOOL includeNone)
/* Set threshold to half the white intensity */
threshold = ColourSum(white) / 2;
black *= wimp_IFORECOL;
white *= wimp_IFORECOL;
/* Check each colour against the threshold */
for (dptr = menu_syshandle(m), i = 0; i <= 15; ++i)
for (i = 0; i <= 15; ++i)
{
iptr = ((wimp_menuitem *)(dptr + 1) + i);
iptr->iconflags = (iptr->iconflags & ~(wimp_IFORECOL * 15))
| (i * wimp_IBACKCOL)
| ((ColourSum(i) > threshold) ? black : white);
menu_setcolours(m, i + 1, (ColourSum(i) > threshold) ? black : white, i);
}
return(m);
......
......@@ -163,6 +163,7 @@ static void dbox__dodispose(dbox d)
/* useful icon flag masks, for searching for specific icon types */
#define BUTTON_IFLAGS (15 * wimp_IBTYPE)
#define WRITABLE_IFLAGS (wimp_BWRITABLE * wimp_IBTYPE)
#define WRITABLE2_IFLAGS (wimp_BWRITABLEDRAG * wimp_IBTYPE)
#define CLICK_IFLAGS (wimp_BCLICKDEBOUNCE * wimp_IBTYPE)
#define AUTO_IFLAGS (wimp_BCLICKAUTO * wimp_IBTYPE)
#define RELEASE_IFLAGS (wimp_BSELREL * wimp_IBTYPE)
......@@ -170,43 +171,38 @@ static void dbox__dodispose(dbox d)
#define ONOFF2_IFLAGS (wimp_BCLICKSEL * wimp_IBTYPE)
#define MENU_IFLAGS (wimp_BSELNOTIFY * wimp_IBTYPE)
static int dbox__findicon(dbox d, wimp_iconflags mask, wimp_iconflags settings, wimp_i *j)
/* Rather like SWI WhichIcon, but only finds the first. Returns 0 if not
found. */
static BOOL dbox__findwritable(dbox d, wimp_i *j)
/* Starting at j, find the first writable (possibly j itself). Returns 0 if not found. */
{
for (; (*j)<d->window.nicons; (*j)++) {
wimp_icon *i = ((wimp_icon*) (&d->window + 1)) + *j;
if ((i->flags & mask) == settings) {
wimp_icon *i = ((wimp_icon *) (&d->window + 1)) + *j;
wimp_iconflags setting = i->flags & BUTTON_IFLAGS;
if ((setting == WRITABLE_IFLAGS)||(setting == WRITABLE2_IFLAGS)) {
tracef1("Found icon %i.\n", *j);
return(1);
return TRUE;
}
}
return(0);
return FALSE;
}
static int dbox__findiconbefore(dbox d,
wimp_iconflags mask, wimp_iconflags settings, wimp_i *j)
/* Does not look at the current icon. */
static BOOL dbox__findwritablebefore(dbox d, wimp_i *j)
/* Find the first writable before j (excluding j itself). Returns 0 if not found. */
{
while ((*j) != 0) {
wimp_icon *i = ((wimp_icon*) (&d->window + 1)) + (--(*j));
if ((i->flags & mask) == settings) {
wimp_icon *i = ((wimp_icon *) (&d->window + 1)) + (--(*j));
wimp_iconflags setting = i->flags & BUTTON_IFLAGS;
if ((setting == WRITABLE_IFLAGS)||(setting == WRITABLE2_IFLAGS)) {
tracef1("Found icon %i.\n", *j);
return(1);
return TRUE;
}
}
return(0);
return FALSE;
}
/* -------- Icons and Fields. -------- */
#ifndef UROM
static dbox_field dbox__icontofield(wimp_i i)
{
return(i);
}
#endif
static wimp_i dbox__fieldtoicon(dbox_field f)
{
return(f);
......@@ -224,7 +220,7 @@ static wimp_icon *dbox__fieldtoiconptr(dbox d, dbox_field f)
static wimp_iconflags dbox__ibutflags(wimp_icon *i)
{
return(i->flags & BUTTON_IFLAGS);
return(wimp_iconflags)(i->flags & BUTTON_IFLAGS);
}
static dbox_fieldtype dbox__iconfieldtype(wimp_icon *i)
......@@ -267,7 +263,6 @@ static int dbox__min(int a, int b) {if (a<b) {return(a);} else {return(b);}}
void dbox_fadefield (dbox d, dbox_field f)
{
/* set shaded bit in iconflags */
wimpt_noerr(wimp_set_icon_state (d->w, dbox__fieldtoicon(f),
wimp_INOSELECT, wimp_INOSELECT));
......@@ -275,12 +270,26 @@ void dbox_fadefield (dbox d, dbox_field f)
void dbox_unfadefield (dbox d, dbox_field f)
{
/* unset shaded bit in iconflags */
wimpt_noerr(wimp_set_icon_state(d->w, dbox__fieldtoicon(f),
0, wimp_INOSELECT));
}
#ifndef UROM
void dbox_hidefield (dbox d, dbox_field f)
{
/* set deleted bit in iconflags */
wimpt_noerr(wimp_set_icon_state (d->w, dbox__fieldtoicon(f),
wimp_IDELETED, wimp_IDELETED));
}
void dbox_unhidefield (dbox d, dbox_field f)
{
/* unset deleted bit in iconflags */
wimpt_noerr(wimp_set_icon_state(d->w, dbox__fieldtoicon(f),
0, wimp_IDELETED));
}
#endif
void dbox_setfield(dbox d, dbox_field f, char *value)
{
......@@ -519,9 +528,6 @@ static void dbox__wimp_event_handler(wimp_eventstr *e, void *handle)
{
dbox d = (dbox) handle;
wimp_caretstr c;
wimp_icon *i;
wimp_i j;
char target;
if (d->raweventproc != 0) {
BOOL done;
......@@ -551,6 +557,7 @@ static void dbox__wimp_event_handler(wimp_eventstr *e, void *handle)
/* It will already have been intercepted (by Events) if there's
a menu, otherwise we're not interested anyway. */
} else if (e->data.but.m.i != (wimp_i) -1) {
wimp_icon *i;
/* ignore clicks not on icons. */
i = dbox__iconhandletoptr(d, e->data.but.m.i);
if (dbox__iconfieldtype(i) == dbox_FACTION) {
......@@ -579,11 +586,12 @@ static void dbox__wimp_event_handler(wimp_eventstr *e, void *handle)
break;
case 13: /* return key */
/* Simulate 'Kr' validation */
tracef1("Caret is in icon %i.\n", c.i);
c.i++;
if (c.i >= d->window.nicons ||
c.i < 0 ||
0==dbox__findicon(d, WRITABLE_IFLAGS, WRITABLE_IFLAGS, &c.i)
c.i == 0 ||
!dbox__findwritable(d, &c.i)
/* find a writable button */
)
{
......@@ -599,17 +607,19 @@ static void dbox__wimp_event_handler(wimp_eventstr *e, void *handle)
case 27: /* ESC key */
dbox__buttonclick(d, dbox_CLOSE);
break;
case 398: /* DOWN key */
case akbd_TabK:
case akbd_DownK:
/* Simulate 'Kta' validation */
tracef1("Caret is in icon %i.\n", c.i);
if (c.i == (wimp_i) -1) {
/* do nothing */
} else {
c.i++;
if (c.i >= d->window.nicons ||
! dbox__findicon(d, WRITABLE_IFLAGS, WRITABLE_IFLAGS, &c.i))
!dbox__findwritable(d, &c.i))
{
c.i = 0;
if (dbox__findicon(d, WRITABLE_IFLAGS, WRITABLE_IFLAGS, &c.i)) {
if (dbox__findwritable(d, &c.i)) {
/* bound to find at least the one you started on. */
}
}
......@@ -620,16 +630,16 @@ static void dbox__wimp_event_handler(wimp_eventstr *e, void *handle)
wimpt_noerr(wimp_set_caret_pos(&c));
}
break;
case 399: /* UP key */
case akbd_Sh + akbd_TabK:
case akbd_UpK:
/* Simulate 'Kta' validation */
tracef1("Caret is in icon %i.\n", c.i);
if (c.i == (wimp_i) -1) {
/* do nothing */
} else {
if (!dbox__findiconbefore(d,
WRITABLE_IFLAGS, WRITABLE_IFLAGS, &c.i)) {
if (!dbox__findwritablebefore(d, &c.i)) {
c.i = d->window.nicons;
if (dbox__findiconbefore(d,
WRITABLE_IFLAGS, WRITABLE_IFLAGS, &c.i)) {
if (dbox__findwritablebefore(d, &c.i)) {
/* bound to find at least the one you started on. */
}
}
......@@ -646,23 +656,28 @@ static void dbox__wimp_event_handler(wimp_eventstr *e, void *handle)
if (e->data.key.chcode < 256)
e->data.key.chcode = toupper(e->data.key.chcode);
if (e->data.key.chcode < 256 && isalpha(e->data.key.chcode)) {
wimp_icon i;
wimp_i j;
for (j=0; j<d->window.nicons; j++) {
tracef1("trying icon %i.\n", j);
i = dbox__iconhandletoptr(d, j);
if ((i->flags & wimp_ITEXT) != 0
&& dbox__iconfieldtype(i) == dbox_FACTION) {
/* Need to get the live icon state from the Wimp as there
might have been some hiding/fading going on since dbox_new() called. */
wimpt_noerr(wimp_get_icon_info(d->w, j, &i));
if (((i.flags & (wimp_ITEXT | wimp_IDELETED | wimp_INOSELECT)) == wimp_ITEXT)
&& dbox__iconfieldtype(&i) == dbox_FACTION) {
char *targetptr;
char target;
BOOL found = FALSE;
if ((i->flags & wimp_INDIRECT) != 0) {
targetptr = &i->data.indirecttext.buffer[0];
if (i.flags & wimp_INDIRECT) {
targetptr = i.data.indirecttext.buffer;
} else {
targetptr = &i->data.text[0];
targetptr = i.data.text;
}
while (1) {
target = *targetptr++;
if (target == 0) break;
if (target < ' ') break; /* Ctrl terminated */
if (target == e->data.key.chcode) {
tracef2("clicking on %i, %i.\n", j, target);
dbox__buttonclick(d, j);
......@@ -720,7 +735,7 @@ dbox dbox_new(char *name)
win_register_event_handler(d->w, dbox__wimp_event_handler, d);
tracef0("Template created.\n");
j = 0;
if (dbox__findicon(d, WRITABLE_IFLAGS, WRITABLE_IFLAGS, &j)) {
if (dbox__findwritable(d, &j)) {
/* there is a writable icon to be found. */
tracef1("Set caret in icon %i.\n", j);
/* Default setting, used in FillIn */
......@@ -960,7 +975,7 @@ dbox_field dbox_fillin(dbox d)
{
wimp_i j = 0;
if (dbox__findicon(d, WRITABLE_IFLAGS, WRITABLE_IFLAGS, &j)) {
if (dbox__findwritable(d, &j)) {
tracef1("Set caret in icon %i.\n", j);
d->caretstr.i = j;
d->caretstr.x = 0;
......@@ -981,9 +996,9 @@ dbox_field dbox_fillin_fixedcaret(dbox d)
wimp_caretstr caret;
wimpt_noerr(wimp_get_caret_pos(&caret));
if (dbox__findicon(d, WRITABLE_IFLAGS, WRITABLE_IFLAGS, &j))
if (dbox__findwritable(d, &j))
{
if (caret.w != dbox_syshandle(d))
if (caret.w != d->w)
{
d->caretstr.i = j;
d->caretstr.x = 0;
......
......@@ -117,7 +117,7 @@ BOOL event_attachmenumaker(event_w w, event_menu_maker menumaker, event_menu_pro
static wimp_w event__current_menu_window = 0;
/* 0 if no menu currently visible */
static menu event__current_menu;
static menu event__current_menu = NULL;
static BOOL event__current_destroy_after; /* set if we made the menu */
static int event__menux = 0;
static int event__menuy = 0;
......@@ -186,7 +186,7 @@ static BOOL event__process(wimp_eventstr *e)
return FALSE;
}
}
else if (e->e == wimp_EMENU && event__current_menu != 0)
else if (e->e == wimp_EMENU && event__current_menu != NULL)
{
mstr *p;
p = win_getmenuh(event__current_menu_window);
......@@ -297,6 +297,8 @@ BOOL event_anywindows()
#endif
void event_clear_current_menu(void) {
event__current_menu = NULL;
event__current_menu_window = 0;
wimpt_noerr(wimp_create_menu((wimp_menustr*) -1, 0, 0));
}
......
......@@ -79,7 +79,7 @@ void fileicon(wimp_w w, wimp_i ii, int filetype)
sprintf(i.i.data.indirectsprite.name, "file_xxx");
}
i.i.data.indirectsprite.spritearea = (void*) 1;
i.i.data.indirectsprite.spritearea = wimp_spritearea;
tracef1("sprite name is %s.\n", (int) i.i.data.indirectsprite.name);
wimp_create_icon(&i, &iii); /* will recreate with same number. */
#if TRACE
......
......@@ -42,8 +42,7 @@
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <kernel.h>
#include <swis.h>
#include "swis.h"
#include "os.h"
#include "werr.h"
......@@ -56,7 +55,7 @@
static int flex__initialised = 0;
static BOOL flex__initialised = FALSE;
/* This implementation goes above the original value of GetEnv,
......@@ -73,18 +72,20 @@ typedef struct {
static void flex__fail(int i)
{
werr(TRUE, msgs_lookup(MSGS_flex1));
#if TRACE
i = *(int *)-4 ; /* go bang! */
char buff[16];
sprintf(buff, "flex__fail %i", i);
werr(TRUE, buff);
#else
i = i; /* avoid compiler warning. */
werr(TRUE, msgs_lookup(MSGS_flex1));
#endif
}
static void flex__check(void)
{
if(flex__initialised == 0)
if (!flex__initialised)
werr(TRUE, msgs_lookup(MSGS_flex3));
}
......@@ -203,7 +204,7 @@ BOOL flex_alloc(flex_ptr anchor, int n)
if (n < 0 || ! flex__ensure(sizeof(flex__rec) + roundup(n)))
{
*anchor = 0;
*anchor = NULL;
return FALSE;
}
......@@ -282,7 +283,7 @@ void flex_free(flex_ptr anchor)
flex__give();
*anchor = 0;
*anchor = NULL;
}
int flex_size(flex_ptr anchor)
......@@ -545,7 +546,7 @@ void flex_init(void)
flex__base = flex__freep;
_kernel_register_slotextend(flex__budge);
tracef1("flex__lim = %i.\n", (int) flex__lim);
flex__initialised = 1;
flex__initialised = TRUE;
/* Check that we're in the Wimp environment. */
{
......
......@@ -133,7 +133,6 @@ os_error *font_lose(font f)
}
#ifndef UROM
os_error * font_readdef(font f, font_def *d)
{
......@@ -154,7 +153,7 @@ os_error * font_readdef(font f, font_def *d)
return(e);
}
#endif
os_error *font_readinfo(font f, font_info *i)
{
......
......@@ -590,38 +590,12 @@ extern void fontselect_closewindows( void )
typedef struct my_font_def
{
char name[40];
int xsize, ysize, xres, yres;
int usage, age;
} my_font_def;
#define ReadDefn 0x00040083
os_error *my_font_readdef(font f, my_font_def *d)
{
os_regset r;
os_error *e;
r.r[0] = (int)f;
r.r[1] = (int)&d->name;
e = os_swix(ReadDefn, &r);
d->xsize = r.r[2];
d->ysize = r.r[3];
d->xres = r.r[4];
d->yres = r.r[5];
d->usage = r.r[6];
d->age = r.r[7];
return(e);
}
/* ------------------------------------------------------------- */
/* Unknown event handler for ModeChange message */
/* ------------------------------------------------------------- */
BOOL unknown_processor( wimp_eventstr *e, void *handle )
static BOOL unknown_processor( wimp_eventstr *e, void *handle )
{
my_font_def font_block;
font_def font_block;
wimp_caretstr caret_block;
switch (e->e)
......@@ -633,7 +607,7 @@ BOOL unknown_processor( wimp_eventstr *e, void *handle )
case wimp_MMODECHANGE:
if ( globals->font_handle != -1 )
{
wimpt_noerr( my_font_readdef( globals->font_handle, &font_block ) );
wimpt_noerr( font_readdef( globals->font_handle, &font_block ) );
wimpt_noerr( font_lose( globals->font_handle ) );
wimpt_noerr( font_find( font_block.name, font_block.xsize, font_block.ysize, 0,0,&globals->font_handle) );
wimpt_noerr( wimp_set_icon_state( globals->font_window_handle, font_text_icon,
......
......@@ -470,6 +470,18 @@ void menu_setflags(menu m, int entry, int tick, int fade)
}
}
void menu_setcolours(menu m, int entry, int fore, int back)
{
wimp_menuitem *p;
if (entry == 0) {return;}
if (entry > m->nitems) {return;}
p = menu__itemptr(m, entry-1);
if (p->iconflags & wimp_IFONT) {return;} /* Dual field use */
p->iconflags = (p->iconflags & ~((15 * wimp_IFORECOL) | (15 * wimp_IBACKCOL)))
| (fore * wimp_IFORECOL)
| (back * wimp_IBACKCOL);
}
void menu_make_writeable(menu m, int entry, char *buffer, int bufferlength,
char *validstring)
{
......
......@@ -40,6 +40,7 @@
#include "swis.h"
#include "sprite.h"
#include "res.h"
#include "wimp.h"
#include "werr.h"
#include "msgs.h"
#include "VerIntern/messages.h"
......@@ -48,7 +49,7 @@
#define SPRITES11 /* Support for new Wimps */
static sprite_area *resspr__area = (sprite_area *) 1; /*defaults to using the wimp sprite pool*/
static sprite_area *resspr__area = wimp_spritearea; /*defaults to using the wimp sprite pool*/
/* Having done res_init (argv [0]); the caller should do resspr_init ();
* before dbox_init (); so that the latter can run over the icon defs and
......
......@@ -436,7 +436,7 @@ record. */
void txt1_disposetextbuffer(txt t)
{
flex_free((void**) &t->buf);
flex_free((flex_ptr) &t->buf);
}
static BOOL txt1__extendtextbuffer(txt t, txt1_bufindex newtop)
......
......@@ -327,7 +327,7 @@ typedef enum
} txtedit_SELACTION;
menu txtedit_menumaker(void *a);
static menu txtedit_menumaker(void *a);
/* Forward reference. */
void txtedit_copyselection(txtedit_state *s);
......@@ -382,12 +382,11 @@ if (s == 0) return 0;
s->t = t;
txt_newmarker(t, &s->selpivot);
s->seltype = txtedit_CHARSEL;
s->selectrecent = NULL;
s->selectrecent = FALSE;
s->filename[0] = 0;
s->ty.ex = -1;
s->ty.ld = -1;
txtfile_buildnewtimestamp(s->ty, &s->ty);
s->deletepending = NULL;
s->next = txtedits;
#ifndef SET_MISC_OPTIONS
......@@ -432,10 +431,6 @@ if (txtscrap_selectowner() == s->t)
txt_disposemarker(s->t, &(s->selpivot));
txt_dispose(&(s->t));
#if FALSE
s->deletepending = 1;
#endif
/* remove s from the list of all text editors. */
if (txtedits == s) {
txtedits = s->next;
......@@ -454,7 +449,6 @@ if (txtedits == s) {
};
free(s);
/* the deletepending mechanism is no longer used. */
}
......@@ -753,7 +747,7 @@ static void txtedit__help_handler(void *a, char *hit)
}
}
menu txtedit_menumaker(void *a) {
static menu txtedit_menumaker(void *a) {
txtedit_state *s = (txtedit_state *) a;
/* IDJ: 30-Jul-91: insert current filetype */
......@@ -960,7 +954,7 @@ if (!drag)
tracef1("Mouse selType=%d.\n", s->seltype);
selectwasrecent = s->selectrecent;
s->selectrecent = NULL;
s->selectrecent = FALSE;
if ((mflags & txt_MEXTEND) != 0)
action = txtedit_EXT;
......@@ -995,7 +989,7 @@ else if ((mflags & txt_MSELECT) != 0)
if (s->selectctl)
{
action = txtedit_CTLSEL;
s->selectrecent = NULL;
s->selectrecent = FALSE;
}
txt_movemarker(s->t, &s->selpivot, at);
}
......@@ -1497,6 +1491,7 @@ while (loopflag1)
at = txt_dot(s->t);
{
int count = 0;
int x, y;
char msg[40];
typedef void SignalHandler(int);
SignalHandler *oldeschandler;
......@@ -1504,7 +1499,8 @@ while (loopflag1)
visdelay_begin();
oldeschandler = signal(SIGINT, &eschandler);
escflag = FALSE;
wimpt_noerr(os_cli("fx 229,0"));
x = 0; y = 0;
wimpt_noerr(os_byte(229, &x, &y));
wasat = at;
......@@ -1537,7 +1533,8 @@ while (loopflag1)
if (escflag) break;
};
wimpt_noerr(os_cli("fx 229,1"));
x = 1; y = 0;