Commit 487c43cb authored by Neil Turton's avatar Neil Turton
Browse files

Import from cleaned 360 CD

parents
s/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
cmhg/** gitlab-language=cmhg linguist-language=cmhg linguist-detectable=true
*,fe1 gitlab-language=make linguist-language=make linguist-detectable=true
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# Makefile for ColourMenu
#
# ***********************************
# *** C h a n g e L i s t ***
# ***********************************
# Date Name Description
# ---- ---- -----------
# 06-Jan-94 AMcC Created
#
#
# Component specific options:
#
COMPONENT = ColourMenu
ROM_MODULE = aof.${COMPONENT}
#
# Export Paths for Messages module
#
RESDIR = <resource$dir>.Resources2.${COMPONENT}
#
# Generic options:
#
MKDIR = cdir
CC = cc
CMHG = cmhg
CP = copy
LD = link
RM = remove
WIPE = -wipe
CPFLAGS = ~cfr~v
WFLAGS = ~c~v
CFLAGS = -c -depend !Depend ${INCLUDES} -zM -ffah -zps1 ${DFLAGS}
DFLAGS = -DROM
INCLUDES = -Itbox:,C:
#
# Libraries
#
ANSILIB = CLib:o.ansilib
CLIB = CLIB:o.stubs
RLIB = RISCOSLIB:o.risc_oslib
ROMCSTUBS = RISCOSLIB:o.romcstubs
ABSSYM = RISC_OSLib:o.abssym
TBOXLIB = tbox:tboxlib
OBJS =\
o.Modhdr_NoD\
o.auxiliary\
o.copy\
o.create\
o.delete\
o.events\
o.getstate\
o.hide\
o.main\
o.miscop\
o.show\
o.task
#
# Rule patterns
#
.c.o:; ${CC} ${CFLAGS} -o $@ $<
.cmhg.o:; ${CMHG} -O $@ $<
#
# Main rules:
#
#
rom: ${ROM_MODULE}
@echo ${COMPONENT}: Module built (ROM)
install_rom: ${ROM_MODULE}
${CP} ${ROM_MODULE} ${INSTDIR}.${COMPONENT} ${CPFLAGS}
@echo ${COMPONENT}: Module installed (ROM)
resources: Messages
${MKDIR} ${RESDIR}
${CP} Messages ${RESDIR}.Messages ${CPFLAGS}
@echo ${COMPONENT}: resource files copied to Messages module
clean:
${WIPE} o.* ${WFLAGS}
${WIPE} aof ${WFLAGS}
${WIPE} linked ${WFLAGS}
${WIPE} map ${WFLAGS}
@echo ${COMPONENT}: cleaned
${ROM_MODULE}: ${OBJS} ${TBOXLIB} ${ROMCSTUBS}
${MKDIR} aof
${LD} -o $@ -aof ${OBJS} ${TBOXLIB} ${ROMCSTUBS}
# final link for ROM Image (using given base address)
rom_link:
${MKDIR} linked
${MKDIR} map
${LD} -o linked.${COMPONENT} -bin -base ${ADDRESS} ${ROM_MODULE} ${ABSSYM} \
-map > map.${COMPONENT}
truncate map.${COMPONENT} linked.${COMPONENT}
${CP} linked.${COMPONENT} ${LINKDIR}.${COMPONENT} ${CPFLAGS}
@echo ${COMPONENT}: rom_link complete
#---------------------------------------------------------------------------
# Dynamic dependencies:
# Project: ColourMenu
# Toolflags:
CCflags = -c -depend !Depend -IC: -throwback -zM -ffah -zps1
C++flags = -c -depend !Depend -throwback -IC:
Pascalflags = -c -depend !Depend -throwback -IP:
Linkflags = -m -o $@
ObjAsmflags = -Throwback -Stamp -NoCache -depend !Depend -CloseExec -Quit
CMHGflags =
LibFileflags = -c -o $@
Squeezeflags = -o $@
AAsmflags = -ThrowBack -Stamp -NoCache -depend !Depend -CloseExec -Quit -To $@ -From
# Final targets:
@.ColourMenu: C:o.stubs @.o.auxiliary @.o.copy @.o.create @.o.delete \
@.o.events @.o.getstate @.o.hide @.o.main @.o.miscop @.o.show @.o.task @.o.Modhdr_NoD \
@.o.messages @.^.common.tboxlib
link $(linkflags) C:o.stubs @.o.auxiliary @.o.copy @.o.create \
@.o.delete @.o.events @.o.getstate @.o.hide @.o.main @.o.miscop @.o.show @.o.task \
@.o.Modhdr_NoD @.o.messages @.^.common.tboxlib
# User-editable dependencies:
@.ColrMenuM: @.messages
modgen @.ColrMenuM ColourMenuM "ColourMenu Messages" 1.00 @.messages Resources.ColourMenu.Messages
@.o.messages: @.Messages
resgen messages_file @.o.messages @.Messages Resources.ColourMenu.Messages
# Static dependencies:
@.o.auxiliary: @.c.auxiliary
cc $(ccflags) -o @.o.auxiliary @.c.auxiliary
@.o.create: @.c.create
cc $(ccflags) -o @.o.create @.c.create
@.o.Modhdr_NoD: @.cmhg.Modhdr_NoD
cmhg @.cmhg.Modhdr_NoD -o @.o.Modhdr_NoD
@.o.main: @.c.main
cc $(ccflags) -o @.o.main @.c.main
@.o.copy: @.c.copy
cc $(ccflags) -o @.o.copy @.c.copy
@.o.delete: @.c.delete
cc $(ccflags) -o @.o.delete @.c.delete
@.o.getstate: @.c.getstate
cc $(ccflags) -o @.o.getstate @.c.getstate
@.o.hide: @.c.hide
cc $(ccflags) -o @.o.hide @.c.hide
@.o.show: @.c.show
cc $(ccflags) -o @.o.show @.c.show
@.o.task: @.c.task
cc $(ccflags) -o @.o.task @.c.task
@.o.miscop: @.c.miscop
cc $(ccflags) -o @.o.miscop @.c.miscop
@.o.events: @.c.events
cc $(ccflags) -o @.o.events @.c.events
# Dynamic dependencies:
# Copyright 1996 Acorn Computers Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile for ColourMenu
#
# ***********************************
# *** C h a n g e L i s t ***
# ***********************************
# Date Name Description
# ---- ---- -----------
# 06-Jan-94 AMcC Created
#
#
# Component specific options:
#
COMPONENT = ColourMenu
ROM_MODULE = aof.${COMPONENT}
#
# Export Paths for Messages module
#
RESDIR = <resource$dir>.Resources2.${COMPONENT}
#
# Generic options:
#
MKDIR = cdir
CC = cc
CMHG = cmhg
CP = copy
LD = link
RM = remove
WIPE = -wipe
CPFLAGS = ~cfr~v
WFLAGS = ~c~v
CFLAGS = -c -depend !Depend ${INCLUDES} -zM -ffah -zps1 ${DFLAGS}
DFLAGS = -DROM
INCLUDES = -Itbox:,C:
#
# Libraries
#
ANSILIB = CLib:o.ansilib
CLIB = CLIB:o.stubs
RLIB = RISCOSLIB:o.risc_oslib
ROMCSTUBS = RISCOSLIB:o.romcstubs
ABSSYM = RISC_OSLib:o.abssym
TBOXLIB = tbox:tboxlib
OBJS =\
o.Modhdr_NoD\
o.auxiliary\
o.copy\
o.create\
o.delete\
o.events\
o.getstate\
o.hide\
o.main\
o.miscop\
o.show\
o.task
#
# Rule patterns
#
.c.o:; ${CC} ${CFLAGS} -o $@ $<
.cmhg.o:; ${CMHG} -O $@ $<
#
# Main rules:
#
#
rom: ${ROM_MODULE}
@echo ${COMPONENT}: Module built (ROM)
install_rom: ${ROM_MODULE}
${CP} ${ROM_MODULE} ${INSTDIR}.${COMPONENT} ${CPFLAGS}
@echo ${COMPONENT}: Module installed (ROM)
resources: Messages
${MKDIR} ${RESDIR}
${CP} Messages ${RESDIR}.Messages ${CPFLAGS}
@echo ${COMPONENT}: resource files copied to Messages module
clean:
${WIPE} o.* ${WFLAGS}
${WIPE} aof ${WFLAGS}
${WIPE} linked ${WFLAGS}
${WIPE} map ${WFLAGS}
@echo ${COMPONENT}: cleaned
${ROM_MODULE}: ${OBJS} ${TBOXLIB} ${ROMCSTUBS}
${MKDIR} aof
${LD} -o $@ -aof ${OBJS} ${TBOXLIB} ${ROMCSTUBS}
# final link for ROM Image (using given base address)
rom_link:
${MKDIR} linked
${MKDIR} map
${LD} -o linked.${COMPONENT} -bin -base ${ADDRESS} ${ROM_MODULE} ${ABSSYM} \
-map > map.${COMPONENT}
truncate map.${COMPONENT} linked.${COMPONENT}
${CP} linked.${COMPONENT} ${LINKDIR}.${COMPONENT} ${CPFLAGS}
@echo ${COMPONENT}: rom_link complete
#---------------------------------------------------------------------------
# Dynamic dependencies:
E00:ColourMenu has active tasks.
E01:Memory allocation failed.
E02:Buffer too short.
E11:Task, %0, does not exist.
E12:Method, %0, not recognised.
E13:MiscOp Method, %0, not recognised.
Title:Colour
Help:Click here to select a colour.
None:None
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: auxiliary.c
* Purpose: support functions for the ColourMenu object class
* Author: TGR
* History: 13-Jan-94: TGR: created
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "twimp.h"
#include "style.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "objects.menu.h"
#include "main.h"
#include "auxiliary.h"
#include "object.h"
#include "task.h"
#define ColourSum(A) (palette.colour[A].red + palette.colour[A].green + palette.colour[A].blue)
int global_menu_state[64] = {0};
char *global_title;
char *global_help_message;
GlobalMenu global_menu =
{0,0,0,NULL,NULL,NULL};
EventInterest messages_of_interest[] =
{{wimp_MHELP_REQUEST , 0},
{wimp_MMENUS_DELETED , 0},
{wimp_MPALETTE_CHANGE, 0},
{-1 , -1}
};
EventInterest events_of_interest[] =
{{wimp_EMENU , 0},
{wimp_ETOOLBOX_EVENT , 0},
{-1 , -1}
};
EventInterest toolbox_events_of_interest[] =
{{ColourMenu_AboutToBeShown, ColourMenu_AboutToBeShown},
{-1 , -1}
};
extern BOOL menu_showing (int *buffer) {
int *ppositiona,
*ppositionb;
ppositiona = buffer;
ppositionb = global_menu_state;
DEBUG debug_output ("a","ColourMenu: looking for menu\n");
if (~global_menu.flags & GLOBAL_MENU_INFO_FLAGS_IS_SHOWING) return FALSE;
while (*ppositionb != -1) {
DEBUG debug_output ("a","ColourMenu: global = %d; recent = %d\n",(int)*ppositionb,(int)*ppositiona);
if (*ppositiona++ != *ppositionb++) return FALSE;
}
if (*ppositiona != -1) {
DEBUG debug_output ("a","ColourMenu: ... found one\n");
return TRUE;
} else
return FALSE;
}
extern _kernel_oserror *palette_update (void) {
_kernel_oserror *e;
_kernel_swi_regs regs;
wimp_PaletteBlock palette;
wimp_MenuEntry *entry;
int fg,light,dark,threshold,i;
if (!global_menu.wimp_menu) return NULL;
regs.r[1] = (int) &palette;
if ((e = _kernel_swi (Wimp_ReadPalette, &regs, &regs)) != NULL)
return e;
light = (ColourSum(0) > ColourSum(7)) ? 0 : 7;
dark = ~light & 0x7;
threshold = (ColourSum(light) - ColourSum(dark))/2;
DEBUG debug_output ("a","ColourMenu: updating palette, threshold is %d, light is %d (%d)\n",threshold,light,ColourSum(light));
for (i=0; i<16; i++) {
entry = wimp_menu_entry (global_menu.wimp_menu, i);
fg = (ColourSum(i) > threshold) ? dark : light;
DEBUG debug_output ("a","ColourMenu: ColourSum(%d) is %d, %d chosen as foregnd\n",i,ColourSum(i),fg);
entry->icon_flags = entry->icon_flags
& (~(wimp_ICONFLAGS_FORECOL * 0xf))
| wimp_ICONFLAGS_FORECOL * fg;
}
return NULL;
}
extern void set_colour (ColourMenuInternal *menu_int, int new_colour) {
if (global_menu.current == menu_int) {
wimp_menu_entry (global_menu.wimp_menu,global_menu.current->colour)->flags &= ~wimp_MENUFLAGS_TICKED;
wimp_menu_entry (global_menu.wimp_menu,new_colour)->flags |= wimp_MENUFLAGS_TICKED;
global_menu.colour = new_colour;
}
menu_int->colour = new_colour;
}
extern _kernel_oserror *hide_menu (ColourMenuInternal *menu_int) {
_kernel_oserror *e;
_kernel_swi_regs regs;
int buffer[64];
if (global_menu.current == menu_int) {
regs.r[0] = 0;
regs.r[1] = (int) buffer;
if ((e = _kernel_swi (Wimp_GetMenuState, &regs, &regs)) != NULL)
return e;
if (menu_showing(buffer)) {
regs.r[1] = -1;
if ((e = _kernel_swi (Wimp_CreateMenu, &regs, &regs)) != NULL)
return e;
return has_been_hidden ();
}
}
return NULL;
}
_kernel_oserror *update_tree (void) {
_kernel_oserror *e;
_kernel_swi_regs regs;
DEBUG debug_output ("a","ColourMenu: updating menu tree\n");
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_IS_SHOWING) {
if ((e = _kernel_swi (Menu_UpdateTree, &regs, &regs)) != NULL)
return e;
/*
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
*/
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL) {
regs.r[1] = (int) global_menu.wimp_menu;
return _kernel_swi (Wimp_CreateMenu, &regs, &regs);
}
}
return NULL;
}
_kernel_oserror *menu_show_actual (void) {
_kernel_swi_regs regs;
_kernel_oserror *e;
regs.r[1] = (int) global_menu.wimp_menu; /* Wimp menu block */
regs.r[2] = global_menu.x;
regs.r[3] = global_menu.y;
DEBUG debug_output ("e","ColourMenu: showing menu, 0x%x\n",global_menu.current->object_id);
e = _kernel_swi (Wimp_CreateMenu, &regs, &regs);
return e;
}
_kernel_oserror *menu_show_submenu_actual (void) {
_kernel_swi_regs regs;
_kernel_oserror *e;
regs.r[1] = (int) global_menu.wimp_menu; /* Wimp menu block */
regs.r[2] = global_menu.x;
regs.r[3] = global_menu.y;
DEBUG debug_output ("e","ColourMenu: showing submenu, object_id = 0x%x; wimp_Menu = 0x%x; vert_gap = %d\n",global_menu.current->object_id,(int)global_menu.wimp_menu, global_menu.wimp_menu->hdr.vert_gap);
/* Routine to dump out the memory in which the menu is stored! ***
{
FILE *fp;
char *ptr = (char *) global_menu.wimp_menu;
int i;
if ((fp = fopen ("$.dump", "w")) != NULL) {
for (i=0;i<0x400;i++)
putc (*ptr++,fp);
fclose (fp);
}
}
*/
e = _kernel_swi (Wimp_CreateSubMenu, &regs, &regs);
DEBUG debug_output ("e","ColourMenu: just after Wimp_CreateSubmenu, e = 0x%x\n",e);
return e;
}
extern _kernel_oserror *has_been_hidden (void) {
_kernel_oserror *e;
_kernel_swi_regs regs;
ToolboxEvent toolbox_event;
if (global_menu.current->flags & ColourMenuInternal_GenerateHideEvent) {
toolbox_event.hdr.size = sizeof (ColourMenu_HasBeenHidden_Event);
toolbox_event.hdr.event_code = ColourMenu_HasBeenHidden;
toolbox_event.hdr.flags = 0;
regs.r[0] = 0;
regs.r[1] = global_menu.current->object_id;
regs.r[2] = -1;
regs.r[3] = (int) &toolbox_event;
if ((e = _kernel_swi (Toolbox_RaiseToolboxEvent, &regs, &regs)) != NULL)
return e;
}
global_menu.current = NULL;
global_menu.flags &= ~GLOBAL_MENU_INFO_FLAGS_IS_SHOWING;
return NULL;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: copy.c
* Purpose: copy a ColourMenu Object
* Author: TGR
* History: 17-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
#include "copy.h"
extern _kernel_oserror *copy_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* request to copy an object
* R0 = 2
* R1 = Object ID
* R2 = internal handle returned when "src" Object was created
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9:
* R0 = flags
* bit 0 set => do not recursively copy the Object
* R1 = source Object ID
*/
/*
* The Toolbox has already checked that this is not just a copy
* call for a shared Object which already exists.
* We create a new Object, and add it to the list of Objects for this
* task.
* We need to remember the ObjectID passed to us by the Toolbox, so
* that we can identify this Object if we are given an ID from the
* client's "id block".
*/
#ifdef COPY_OBJECT
_kernel_oserror *e;
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2],
*menu_intx;
ObjectID object_idx = (ObjectID) r->r[1];
if ((menu_intx = mem_alloc(sizeof(ColourMenuInternal))) == NULL) {
return make_error (ColourMenu_AllocFailed,0);
}
if (menu_int->title) {
if ((menu_intx->title = mem_alloc (strlen(menu_int->title) + 1)) == NULL) {
e = make_error (ColourMenu_AllocFailed,0);
goto clearup1;
}
strcpy(menu_intx->title, menu_int->title);
} else menu_intx->title = NULL;
menu_intx->object_id = object_idx;
menu_intx->flags = menu_int->flags;
menu_intx->colour = menu_int->colour;
menu_intx->title_len = menu_int->title_len;
menu_intx->forward = t->object_list;
menu_intx->backward = t->object_list->backward;
t->object_list->backward->forward = menu_intx;
t->object_list->backward = menu_intx;
r->r[0] = (int) menu_intx;
return NULL;
clearup1:
mem_freek (menu_intx);
return e;
IGNORE(t);
#else
return NULL;
#endif
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: create.c
* Purpose: create a ColourMenu Object
* Author: TGR
* History: 13-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
#include "create.h"
extern _kernel_oserror *create_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* request to create an object
* R0 = 0
* R1 = Object ID
* R2 = 0 (will be internal handle for other SWIs
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9
* R0 = flags
* bit 0 set => create from memory
* R1 -> description block
*/
/*
* The Toolbox has already checked that this is not just a create
* call for a shared Object which already exists.
* We create a new Object, and add it to the list of Objects for this
* task.
* We need to remember the ObjectID passed to us by the Toolbox, so
* that we can identify this Object if we are given an ID from the
* client's "id block".
* Note that if any template names are held in the Object, then we
* create an Object from that template, and store its ID.
* Note also that the Toolbox has changed the client's R1 to point
* at an in-core template, if it wasn't already!
*/
_kernel_swi_regs *user_regs,
regs;
ColourMenuTemplate *menu_temp;
ObjectTemplateHeader *obj_temp_hdr;
ColourMenuInternal *menu_int;
ObjectID object_id;
_kernel_oserror *e;
user_regs = (_kernel_swi_regs *) r->r[4];
obj_temp_hdr = (ObjectTemplateHeader *)user_regs->r[1];
menu_temp = (ColourMenuTemplate *) obj_temp_hdr->body;
object_id = (ObjectID) r->r[1];
DEBUG debug_output ("f","ColourMenu: entering create\n");
if ((menu_int=mem_alloc(sizeof(ColourMenuInternal))) == NULL) {
return make_error(ColourMenu_AllocFailed,0);
}
DEBUG debug_output ("f","ColourMenu: creating object, 0x%x, @0x%x\n",object_id,menu_int);
menu_int->object_id = object_id;
menu_int->flags
= ((menu_temp->flags & ColourMenu_GenerateShowEvent) ? ColourMenuInternal_GenerateShowEvent : 0)
| ((menu_temp->flags & ColourMenu_GenerateHideEvent) ? ColourMenuInternal_GenerateHideEvent : 0)
| ((menu_temp->flags & ColourMenu_NoneEntry) ? ColourMenuInternal_NoneEntry : 0);
if (!menu_temp->title || !menu_temp->max_title) {
menu_int->title = NULL;
} else if ((menu_int->title = mem_alloc (menu_temp->max_title)) == NULL) {
e = make_error(ColourMenu_AllocFailed,0);
goto clearup1;
} else if (!string_copy_chk (menu_int->title, menu_temp->title, menu_temp->max_title)) {
e = make_error (ColourMenu_ShortBuffer,0);
goto clearup2;
}
menu_int->colour = menu_temp->colour;
menu_int->title_len = menu_temp->max_title;
if (t->object_list) { /* If there are already menus attached to the task ... */
menu_int->forward = t->object_list;
menu_int->backward = t->object_list->backward;
t->object_list->backward->forward = menu_int;
t->object_list->backward = menu_int;
} else { /* ... if not ... */
/* register interest in toolbox events */
regs.r[0] = 0;
regs.r[1] = ColourMenu_PostFilter;
regs.r[2] = (int) t;
regs.r[3] = Toolbox_RegisterPostFilter_ToolboxEvent;
regs.r[4] = (int) toolbox_events_of_interest;
if ((e = _kernel_swi (Toolbox_RegisterPostFilter, &regs, &regs)) != NULL) {
goto clearup2;
}
/* register interest in wimp events */
regs.r[0] = 0;
regs.r[1] = ColourMenu_PostFilter;
regs.r[2] = (int) t;
regs.r[3] = Toolbox_RegisterPostFilter_WimpEvent;
regs.r[4] = (int) events_of_interest;
if ((e = _kernel_swi (Toolbox_RegisterPostFilter, &regs, &regs)) != NULL) {
goto clearup2;
}
/* register interest in wimp messages */
regs.r[0] = 0;
regs.r[1] = ColourMenu_PostFilter;
regs.r[2] = (int) t;
regs.r[3] = Toolbox_RegisterPostFilter_WimpMessage;
regs.r[4] = (int) messages_of_interest;
if ((e = _kernel_swi (Toolbox_RegisterPostFilter, &regs, &regs)) != NULL) {
DEBUG debug_output ("f","ColourMenu: handling error from final post-filter register\n");
goto clearup2;
}
/* register interest in pre-filter */
regs.r[0] = 0;
regs.r[1] = ColourMenu_PreFilter;
regs.r[2] = (int) t;
if ((e = _kernel_swi (Toolbox_RegisterPreFilter, &regs, &regs)) != NULL) {
DEBUG debug_output ("f","ColourMenu: handling error from registering pre-filter\n");
goto clearup2;
}
DEBUG debug_output ("f","ColourMenu: object_list should be set here\n");
t->object_list = menu_int;
menu_int->forward = menu_int;
menu_int->backward = menu_int;
}
user_regs->r[0] = r->r[1];
r->r[0] = (int) menu_int;
return NULL;
clearup2:
mem_freek (menu_int->title);
clearup1:
mem_freek (menu_int);
return e;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: delete.c
* Purpose: delete a ColourMenu Object
* Author: TGR
* History: 18-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
#include "delete.h"
extern _kernel_oserror *delete_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* request to delete an object
* R0 = 1
* R1 = Object ID
* R2 = internal handle returned when Object was created
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9
* R0 = flags
* bit 0 set => do not recursively delete the object
* R1 = Object ID
*/
/*
* The Toolbox has already checked that this is not just a delete
* call for a shared Object.
* We delete Object from the list of Objects for this
* task.
* If recursive delete is requested then we also call Toolbox_Delete
* for any Objects "attached" to this Object.
*/
_kernel_swi_regs regs;
_kernel_oserror *e;
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
e = hide_menu(menu_int);
if (menu_int->forward == menu_int) { /* Unlinking from the list is regarded as imperative */
DEBUG debug_output ("d","Menu: about to register disinterest\n");
regs.r[0] = 1; /* No longer interested in events */
regs.r[1] = ColourMenu_PostFilter;
regs.r[2] = (int) t;
regs.r[3] = Toolbox_RegisterPostFilter_ToolboxEvent;
regs.r[4] = (int) toolbox_events_of_interest;
_kernel_swi (Toolbox_RegisterPostFilter, &regs, &regs);
regs.r[0] = 1; /* No longer interested in events */
regs.r[1] = ColourMenu_PostFilter;
regs.r[2] = (int) t;
regs.r[3] = Toolbox_RegisterPostFilter_WimpEvent;
regs.r[4] = (int) events_of_interest;
_kernel_swi (Toolbox_RegisterPostFilter, &regs, &regs);
regs.r[0] = 1; /* No longer interested in events */
regs.r[1] = ColourMenu_PostFilter;
regs.r[2] = (int) t;
regs.r[3] = Toolbox_RegisterPostFilter_WimpMessage;
regs.r[4] = (int) messages_of_interest;
_kernel_swi (Toolbox_RegisterPostFilter, &regs, &regs);
regs.r[0] = 1;
regs.r[1] = ColourMenu_PreFilter;
regs.r[2] = (int) t;
_kernel_swi (Toolbox_RegisterPreFilter, &regs, &regs);
t->object_list = NULL;
} else {
if (t-> object_list == menu_int) {
t->object_list = menu_int->forward;
}
menu_int->forward->backward = menu_int->backward;
menu_int->backward->forward = menu_int->forward;
}
if (menu_int->title) mem_freek (menu_int->title);
mem_freek (menu_int);
return e;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: events.c
* Purpose: filters registered with the Toolbox. Events are delivered here.
* Author: TGR
* History: 26-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "events.h"
_kernel_oserror *event_help_request (wimp_Message message_block, TaskDescriptor *t);
_kernel_oserror *event_menu_warning (wimp_Message message_block, TaskDescriptor *t);
_kernel_oserror *event_menus_deleted (wimp_Message message_block, TaskDescriptor *t);
_kernel_oserror *event_menu_selection (int *menu_tree, TaskDescriptor *t, IDBlock *id_block,_kernel_swi_regs *r);
_kernel_oserror *event_menu_to_show (TaskDescriptor *t, IDBlock *id_block,_kernel_swi_regs *r);
_kernel_oserror *menu_show_actual (void);
_kernel_oserror *menu_show_submenu_actual (void);
extern _kernel_oserror *events_postfilter (_kernel_swi_regs *r)
{
/*
* called from the main Toolbox postfilter, when an event happens which
* this module has expressed an interest in.
* R0 = Wimp event reason code
* R1 ->client's Wimp event block
* R2 = Task Descriptor of task interested in the event
* R3 ->6-word "ID block" as passed to Toolbox_Initialise
*
*/
/*
* This function gets a pointer to the task interested in the event in
* R2 (since this was the value passed to Toolbox_RegisterPostFilter).
* If the event is dealt with by this module (eg ID block gets updated).
* then set R0 to non-null before return.
*/
_kernel_oserror *e;
wimp_PollBlock *block = (wimp_PollBlock *)r->r[1];
IDBlock *id_block = (IDBlock *)r->r[3];
int event_code = r->r[0];
TaskDescriptor *t = (TaskDescriptor *) r->r[2];
DEBUG debug_output ("e","ColourMenu: Postfilter entered, received wimp event code = 0x%x\n",event_code);
r->r[0] = 0;
if (t == NULL)
return NULL;
switch (event_code) {
case wimp_ESEND:
case wimp_ESEND_WANT_ACK:
switch (block->msg.hdr.action) {
case wimp_MMENUS_DELETED:
return event_menus_deleted(block->msg,t);
break;
case wimp_MHELP_REQUEST:
return event_help_request(block->msg,t);
break;
case wimp_MPALETTE_CHANGE:
if ((e = palette_update()) != NULL) {
return e;
}
break;
default:
break;
}
break;
case wimp_EMENU:
return event_menu_selection((int *) r->r[1],t,id_block,r);
/* ... R1 points to a list of menu selections */
break;
case wimp_ETOOLBOX_EVENT:
DEBUG debug_output ("e","ColourMenu: toolbox event\n");
if (block->toolbox_event.hdr.event_code == ColourMenu_AboutToBeShown) {
DEBUG debug_output ("e","ColourMenu: AboutToBeShown event returned\n");
return event_menu_to_show (t,id_block,r);
}
break;
default:
break;
}
return NULL;
}
extern _kernel_oserror *events_prefilter (_kernel_swi_regs *r)
{
/*
* called from the main Toolbox prefilter, when Wimp_Poll is called.
* R0 = mask passed to Wimp_Poll
* R1 ->client's poll block passed to Wimp_Poll
* R2 = Task Descriptor.
*
*/
/*
* This function gets a pointer to the current task in
* R2 (since this was the value passed to Toolbox_RegisterPreFilter).
* This function can enable additional events by zero-ing bits in
* r->r[0]
*/
DEBUG debug_output ("e","ColourMenu: prefilter entered\n");
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT) {
global_menu.flags = (global_menu.flags
| GLOBAL_MENU_INFO_FLAGS_IS_SHOWING)
& ~GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
return ((global_menu.flags & GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL)?menu_show_actual():menu_show_submenu_actual());
}
IGNORE(r);
return NULL;
}
/* Respond to request for help ******************************************************************/
_kernel_oserror *event_help_request (wimp_Message message_block, TaskDescriptor *t) {
_kernel_swi_regs regs;
_kernel_oserror *e;
ColourMenuInternal *menu_int = global_menu.current;
wimp_Message help_reply;
ObjectID object_id = menu_int->object_id;
int buffer[64];
if (!menu_int) return NULL;
object_id = menu_int->object_id;
DEBUG debug_output ("e","ColourMenu: request for help\n");
regs.r[0] = 0;
regs.r[1] = (int) buffer;
if ((e = _kernel_swi (Wimp_GetMenuState, &regs, &regs)) != NULL) {
return e;
}
if (!menu_showing(buffer)) return NULL;
if (global_menu.t == t) {
int str_len;
help_reply.hdr.your_ref = message_block.hdr.my_ref;
help_reply.hdr.action = wimp_MHELP_REPLY;
help_reply.hdr.size = sizeof(wimp_Message);
string_copy_chk (help_reply.data.chars, global_help_message, wimp_MAX_MSG_DATA_SIZE);
str_len = strlen(global_help_message);
if (str_len < wimp_MAX_MSG_DATA_SIZE) {
global_help_message[str_len+1] = '\0';
if (str_len+1 < wimp_MAX_MSG_DATA_SIZE)
global_help_message[str_len+2] = '\0';
}
}
regs.r[0] = wimp_ESEND;
regs.r[1] = (int) &help_reply;
regs.r[2] = message_block.hdr.task_handle;
if ((e = _kernel_swi (Wimp_SendMessage, &regs, &regs)) != NULL) {
return e;
}
return NULL;
}
/* Menu will be deleted. Mark it as not showing *************************************************/
_kernel_oserror *event_menus_deleted (wimp_Message message_block, TaskDescriptor *t){
ColourMenuInternal *menu_int = global_menu.current;
ObjectID object_id;
if (!menu_int) return NULL;
if (global_menu.wimp_menu != (wimp_Menu *) (*message_block.data.words))
return NULL;
object_id = menu_int->object_id;
DEBUG debug_output ("e","ColourMenu: menus deleted, tidying up\n");
IGNORE(t);
IGNORE(message_block);
return has_been_hidden ();
}
/* Respond to a menu selection ******************************************************************/
_kernel_oserror *event_menu_selection (int *menu_tree, TaskDescriptor *t, IDBlock *id_block,_kernel_swi_regs *r) {
_kernel_swi_regs regs;
_kernel_oserror *e;
ColourMenuInternal *menu_int = global_menu.current;
ObjectID object_id;
ToolboxEvent toolbox_event;
ColourMenu_Selection_Event
*selection;
int *pposition = global_menu_state;
wimp_PointerInfo pointer_info;
DEBUG debug_output ("e","ColourMenu: selection entered\n");
if (!menu_int || (*menu_tree == -1)) {
return NULL;
}
if (!(menu_showing(menu_tree))) {
DEBUG debug_output ("e","ColourMenu: menu not found, returning\n");
return NULL;
}
object_id = global_menu.current->object_id;
while (*pposition != -1) {
if (*pposition++ != *menu_tree++) {
return NULL;
}
}
if (*menu_tree == -1) return NULL;
set_colour (global_menu.current, *menu_tree);
DEBUG debug_output ("e","ColourMenu: set new colour\n");
selection = (ColourMenu_Selection_Event *) &toolbox_event;
toolbox_event.hdr.size = sizeof (ColourMenu_Selection_Event);
toolbox_event.hdr.event_code = ColourMenu_Selection;
toolbox_event.hdr.flags = 0;
selection->colour = *menu_tree;
regs.r[0] = 0;
regs.r[1] = (int) object_id;
regs.r[2] = -1;
regs.r[3] = (int) selection;
if ((e = _kernel_swi (Toolbox_RaiseToolboxEvent, &regs, &regs)) != NULL) {
return e;
}
regs.r[1] = (int) &pointer_info;
if ((e = _kernel_swi (Wimp_GetPointerInfo, &regs, &regs)) != NULL) {
return e;
}
if (pointer_info.button_state & wimp_ADJUST_BUTTON) {
DEBUG debug_output ("e","ColourMenu: adjust click\n");
if ((e = update_tree()) != NULL)
return e;
} else if (pointer_info.button_state & (wimp_SELECT_BUTTON|wimp_MENU_BUTTON)) {
has_been_hidden ();
}
r->r[0] = 1;
id_block->self_id = object_id;
IGNORE(r);
IGNORE(t);
return NULL;
}
_kernel_oserror *event_menu_to_show (TaskDescriptor *t, IDBlock *id_block,_kernel_swi_regs *r) {
if (global_menu.t == t) { /* No further checking - assume this is it */
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
/*
id_block->self_id = global_menu.current->object_id;
*/
}
IGNORE (r);
IGNORE (id_block);
return NULL;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: getstate.c
* Purpose: return state for a ColourMenu Object
* Author: TGR
* History: 25-Apr-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
#include "getstate.h"
extern _kernel_oserror *getstate_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* request for info about an object
* R0 = 5
* R1 = Object ID
* R2 = internal handle returned when Object was created
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9
* R0 = flags
* R1 = Object ID
*/
/*
* return state in R0
*
*/
_kernel_swi_regs regs;
_kernel_oserror *e;
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
int buffer[64];
r->r[0] = 0;
if (global_menu.current == menu_int) {
regs.r[0] = 0;
regs.r[1] = (int) buffer;
if ((e = _kernel_swi (Wimp_GetMenuState, &regs, &regs)) != NULL)
return e;
if (menu_showing(buffer)) r->r[0] = Toolbox_GetObjectState_Showing;
}
IGNORE(t);
return NULL;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: hide.c
* Purpose: hide a ColourMenu Object
* Author: TGR
* History: 18-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
#include "hide.h"
extern _kernel_oserror *hide_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* request to hide an object
* R0 = 4
* R1 = Object ID
* R2 = internal handle returned when Object was created
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9
* R0 = flags
* R1 = Object ID
*
*/
/*
* Remove the object from view. For efficiency, we should stop expressing
* interest in any events which can't happen whilst the Object is
* hidden.
*
*/
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
IGNORE(t);
return hide_menu(menu_int);
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: main.c
* Purpose: main module of a ColourMenu Object module
* Author: TGR
* History: 18-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "rmensure.h"
#include "mem.h"
#include "os.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "object.h"
#include "auxiliary.h"
#include "create.h"
#include "delete.h"
#include "copy.h"
#include "show.h"
#include "hide.h"
#include "getstate.h"
#include "miscop.h"
#include "events.h"
#include "task.h"
#include "main.h"
#define MAX_CLASS_SWI_METHODS 7
static _kernel_oserror *(*class_swi_methods [MAX_CLASS_SWI_METHODS])(_kernel_swi_regs *r, TaskDescriptor *t) =
{
create_object,
delete_object,
NULL, /*copy_object,*/
show_object,
hide_object,
getstate_object,
miscop_object
};
/* +++++++++++++++++++++++++++++++++ finalisation code +++++++++++++++++++++++++++++++++ */
#ifdef ROM
static _kernel_oserror *__ROM;
#endif
extern _kernel_oserror *ColourMenu_finalise (int fatal, int podule, void *pw)
{
_kernel_swi_regs regs;
#ifndef ROM
extern int messages_file(void);
#endif
IGNORE(fatal);
IGNORE(podule);
IGNORE(pw);
/*
* refuse to finalise if tasks active
*/
if (task_any_active())
return make_error (ColourMenu_TasksActive, 0);
mem_freek (global_help_message);
mem_freek (global_title);
/*
* close our messages file
*/
messages_file_close ();
#ifndef ROM
/*
* ... and deregister from ResourceFS
*/
regs.r[0] = messages_file();
_kernel_swi (ResourceFS_DeregisterFiles, &regs, &regs);
#endif
/* hide menus before deletion */
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_IS_SHOWING) {
regs.r[1] = -1;
_kernel_swi (Wimp_CreateMenu, &regs, &regs);
}
/* deregister object module */
regs.r[0] = 0;
regs.r[1] = ColourMenu_ObjectClass;
_kernel_swi(Toolbox_DeRegisterObjectModule, &regs, &regs);
/*
* free up memory we may have left allocated
*/
mem_free_all ();
#ifdef ROM
if(!__ROM) _swix(0xa2c41, 0);
#endif
return NULL;
}
/* ++++++++++++++++++++++++++++++++ initialisation code +++++++++++++++++++++++++++++++ */
extern _kernel_oserror *ColourMenu_init(char *cmd_tail, int podule_base, void *pw)
{
char *messages_filename;
_kernel_swi_regs regs;
_kernel_oserror *e;
int buffer_size;
#ifndef ROM
extern int messages_file(void);
#endif
IGNORE(cmd_tail);
IGNORE(podule_base);
IGNORE(pw);
#ifdef ROM
__ROM = _swix(0xa2c43, _IN(0), pw);
#endif
DEBUG debug_set_var_name("ColourMenu$Debug");
if ((e = rmensure ("Menu", "Toolbox.Menu", "0.22")) != NULL) return e;
/*
* register our messages file with Resource FS and MessageTrans
*/
#ifndef ROM
regs.r[0] = messages_file();
if ((e = _kernel_swi (ResourceFS_RegisterFiles, &regs, &regs)) != NULL)
return e;
#endif
if (getenv ("ColourMenu$Path") == NULL)
messages_filename = "Resources:Resources.ColourMenu.Messages";
else
messages_filename = "ColourMenu:Messages";
DEBUG debug_output ("M","ColourMenu: Opening main message file\n");
if ((e = messages_file_open (messages_filename)) != NULL)
return e;
if ((e = messages_file_lookup ("Help", 0, &buffer_size, 0)) != NULL)
return e;
if ((global_help_message = mem_alloc (buffer_size)) == NULL)
return make_error(ColourMenu_AllocFailed,0);
if ((e = messages_file_lookup ("Help", global_help_message, &buffer_size, 0)) !=NULL)
return e;
if ((e = messages_file_lookup ("Title", 0, &buffer_size, 0)) != NULL)
return e;
if ((global_title = mem_alloc (buffer_size)) == NULL)
return make_error(ColourMenu_AllocFailed,0);
if ((e = messages_file_lookup ("Title", global_title, &buffer_size, 0)) !=NULL)
return e;
DEBUG debug_output ("M","ColourMenu: buffer_size is %d (0x%x), title is '%s'\n",buffer_size, (int) &buffer_size, global_title);
/* register with the Toolbox as an Object Module */
regs.r[0] = 0;
regs.r[1] = ColourMenu_ObjectClass;
regs.r[2] = ColourMenu_ClassSWI;
regs.r[3] = 0;
if ((e = _kernel_swi(Toolbox_RegisterObjectModule, &regs, &regs)) != NULL)
return e;
return NULL;
}
/* +++++++++++++++++++++++++++++++++ service handler code ++++++++++++++++++++++++++++++ */
extern void ColourMenu_services(int service_number, _kernel_swi_regs *r, void *pw)
{
_kernel_swi_regs regs;
IGNORE(pw);
switch (service_number)
{
case Service_ToolboxTaskDied:
/*
* task dying - r0 holds task handle
*/
task_remove (r->r[0]);
break;
case Service_ToolboxTaskBorn:
/* Toolbox task has just started R0 == wimp task handle */
/*
* create a new "task descriptor"
*/
task_add (r->r[0]);
break;
case Service_ToolboxStarting:
/*
* register with the Toolbox as an Object Module
*/
regs.r[0] = 0;
regs.r[1] = ColourMenu_ObjectClass;
regs.r[2] = ColourMenu_ClassSWI;
regs.r[3] = 0;
_kernel_swi (Toolbox_RegisterObjectModule, &regs, &regs);
break;
default:
break;
}
}
/* ++++++++++++++++++++++++++++++++++++++ SWI code +++++++++++++++++++++++++++++++++++++ */
extern _kernel_oserror *ColourMenu_SWI_handler(int swi_no, _kernel_swi_regs *r, void *pw)
{
_kernel_oserror *e = NULL;
TaskDescriptor *t;
IGNORE(pw);
DEBUG debug_output ("M","ColourMenu: SWI no. 0x%x\n",swi_no + ColourMenu_SWIChunkBase);
switch (swi_no + ColourMenu_SWIChunkBase)
{
case ColourMenu_ClassSWI:
if (r->r[0] < 0 || r->r[0] >= MAX_CLASS_SWI_METHODS)
{
return make_error_hex(ColourMenu_NoSuchMethod,1,r->r[0]);
}
else
{
t = task_find (r->r[3]);
if (t == NULL)
{
return make_error_hex(ColourMenu_NoSuchTask,1,r->r[3]);
}
DEBUG debug_output ("M","ColourMenu: class SWI method %d\n",r->r[0]);
e = (*class_swi_methods[r->r[0]])(r, t);
}
break;
case ColourMenu_PostFilter:
e = events_postfilter (r);
break;
case ColourMenu_PreFilter:
e = events_prefilter (r);
break;
default:
break;
}
return e;
}
#if debugging
/* ++++++++++++++++++++++++++++++++++++++ star commands ++++++++++++++++++++++++++++++++++++*/
extern _kernel_oserror *ColourMenu_commands(char *arg_string, int argc, int cmd_no, void *pw)
{
IGNORE(argc);
IGNORE(pw);
IGNORE(arg_string);
switch (cmd_no)
{
case 0:
mem_print_list();
break;
default:
break;
}
return NULL;
}
#endif
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: miscop.c
* Purpose: miscellanaous operations on a ColourMenu Object
* Author: TGR
* History: 26-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "main.h"
#include "auxiliary.h"
#include "object.h"
#include "task.h"
#include "miscop.h"
_kernel_oserror *colourmenu_set_colour (_kernel_swi_regs *r, TaskDescriptor *t);
_kernel_oserror *colourmenu_get_colour (_kernel_swi_regs *r, TaskDescriptor *t);
_kernel_oserror *colourmenu_set_none_available (_kernel_swi_regs *r, TaskDescriptor *t);
_kernel_oserror *colourmenu_get_none_available (_kernel_swi_regs *r, TaskDescriptor *t);
_kernel_oserror *colourmenu_set_title (_kernel_swi_regs *r, TaskDescriptor *t);
_kernel_oserror *colourmenu_get_title (_kernel_swi_regs *r, TaskDescriptor *t);
/* Define functions using pointers *****************************************************/
#define MAX_MISCOP_METHODS 6
static _kernel_oserror *(*colourmenu_miscop_methods [MAX_MISCOP_METHODS]) (_kernel_swi_regs *r, TaskDescriptor *t) = {
colourmenu_set_colour,
colourmenu_get_colour,
colourmenu_set_none_available,
colourmenu_get_none_available,
colourmenu_set_title,
colourmenu_get_title
};
extern _kernel_oserror *miscop_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* do a "miscellaneous (ie object-specific) operation on an object
* R0 = 6
* R1 = Object ID
* R2 = internal handle returned when Object was created
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9
* R0 = flags
* R1 = Object ID
* R2 = method code
* R3-R9 method-specific data
*/
/*
* This is the routine which deals with all object-specific operations.
*
*
*/
_kernel_swi_regs *user_regs = (_kernel_swi_regs *) r->r[4];
int method = user_regs->r[2];
DEBUG debug_output ("y","ColourMenu: miscop method = 0x%x\n",method);
if (method < 0 || method >= MAX_MISCOP_METHODS) {
return make_error_hex(ColourMenu_NoSuchMiscOpMethod,1,method);
} else
return (*colourmenu_miscop_methods[method])(r,t);
}
/* set current colour ***************************************************************************/
_kernel_oserror *colourmenu_set_colour (_kernel_swi_regs *r, TaskDescriptor *t) {
_kernel_oserror *e;
_kernel_swi_regs *user_regs = ((_kernel_swi_regs *) r->r[4]);
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
int new_colour = user_regs->r[3],
old_colour = global_menu.colour;
if (global_menu.current == menu_int) {
global_menu.colour = new_colour;
if (old_colour >= 0) /* untick previous colour */
wimp_menu_entry (global_menu.wimp_menu,old_colour)->flags &= ~wimp_MENUFLAGS_TICKED;
if ( new_colour >= 0
&& new_colour <= ((menu_int->flags & ColourMenuInternal_NoneEntry)?16:15)) {
wimp_menu_entry (global_menu.wimp_menu,new_colour)->flags |= wimp_MENUFLAGS_TICKED;
}
/*
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL) {
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
} else {
*/
if ((e = update_tree()) != NULL)
return e;
/*
}
*/
}
menu_int->colour = new_colour;
IGNORE(t);
return NULL;
}
/* read current colour **************************************************************************/
_kernel_oserror *colourmenu_get_colour (_kernel_swi_regs *r, TaskDescriptor *t) {
_kernel_swi_regs *user_regs = ((_kernel_swi_regs *) r->r[4]);
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
user_regs->r[0] = menu_int->colour;
IGNORE(t);
return NULL;
}
/* include/don't include entry "None" ***********************************************************/
_kernel_oserror *colourmenu_set_none_available (_kernel_swi_regs *r, TaskDescriptor *t) {
_kernel_oserror *e;
_kernel_swi_regs *user_regs = ((_kernel_swi_regs *) r->r[4]);
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
if (global_menu.current == menu_int) {
if (user_regs->r[3] & 1) {
wimp_menu_entry (global_menu.wimp_menu, 15)->flags &= ~wimp_MENUFLAGS_LAST_ITEM;
} else {
wimp_menu_entry (global_menu.wimp_menu, 15)->flags |= wimp_MENUFLAGS_LAST_ITEM;
}
/*
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL) {
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
} else {
*/
if ((e = update_tree()) != NULL)
return e;
/*
}
*/
}
if (user_regs->r[3] & 1) {
menu_int->flags |= ColourMenuInternal_NoneEntry;
} else {
menu_int->flags &= ~ColourMenuInternal_NoneEntry;
}
IGNORE(t);
return NULL;
}
/* is entry "None" included in menu? ************************************************************/
_kernel_oserror *colourmenu_get_none_available (_kernel_swi_regs *r, TaskDescriptor *t) {
_kernel_swi_regs *user_regs = ((_kernel_swi_regs *) r->r[4]);
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
user_regs->r[0] = menu_int->flags & ColourMenuInternal_NoneEntry;
IGNORE(t);
return NULL;
}
/* set the title of the colourmenu *************************************************************/
_kernel_oserror *colourmenu_set_title (_kernel_swi_regs *r, TaskDescriptor *t) {
_kernel_swi_regs *user_regs = ((_kernel_swi_regs *) r->r[4]);
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
IGNORE(t);
string_copy_chk(menu_int->title,(char *)user_regs->r[3],menu_int->title_len);
if (global_menu.current == menu_int) {
string_copy_chk(global_menu.wimp_menu->hdr.title.indirect_text.buffer,(char *)user_regs->r[3],global_menu.wimp_menu->hdr.title.indirect_text.buff_len);
return update_tree();
}
/*
if (global_menu.flags & GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL) {
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
} else {
*/
/*
}
*/
return NULL;
}
/* read the title of the colourmenu ************************************************************/
_kernel_oserror *colourmenu_get_title (_kernel_swi_regs *r, TaskDescriptor *t) {
_kernel_swi_regs *user_regs = ((_kernel_swi_regs *) r->r[4]);
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
if (!user_regs->r[3]) {
user_regs->r[4] = strlen (menu_int->title) + 1;
return NULL;
}
if (string_copy_chk ((char *) user_regs->r[3], menu_int->title, user_regs->r[4])) {
user_regs->r[4] = strlen ((char *) user_regs->r[3]) + 1;
}
IGNORE(t);
return NULL;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: show.c
* Purpose: show a ColourMenu Object
* Author: TGR
* History: 18-Jan-94: TGR: created
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "twimp.h"
#include "style.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.ColourMenu.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
#include "show.h"
_kernel_oserror *show_menu_coords (_kernel_swi_regs *user_regs);
extern _kernel_oserror *show_object (_kernel_swi_regs *r, TaskDescriptor *t)
{
/*
* request to show an object
* R0 = 3
* R1 = Object ID
* R2 = internal handle returned when Object was created
* R3 = wimp task handle of caller (use to identify task descriptor)
* R4 -> user regs R0-R9
* R0 = flags
* R1 = Object ID
* R2 = "show type"
* 0 => default place
* 1 => R3 points to buffer with full data for showing
* 2 => R3 points to buffer with coordinates
* R3 = 0
* OR R3 -> buffer giving Object-specific data for showing this
* Object
* R4 = Parent Object ID
* R5 = Parent Component ID
*/
/*
* Function to "display" an Object on the screen. If R2 == 0, then
* display in default place.
* If Object has bit set to say warn before show, then we should just
* send Toolbox Event, and wait for the next call to Wimp_Poll after
* the event is delivered before the Object is actually shown
* (ie catch it in the prefilter).
*
*/
_kernel_oserror *e;
_kernel_swi_regs regs,
*user_regs = (_kernel_swi_regs *) r->r[4];
ToolboxEvent toolbox_event;
ColourMenu_AboutToBeShown_Event
*about_to_be_shown;
ColourMenuInternal *menu_int = (ColourMenuInternal *) r->r[2];
wimp_MenuEntry *entry;
int i,old_colour,title_width;
BOOL none_entry = menu_int->flags & ColourMenuInternal_NoneEntry;
static char *entry_texts[17] = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15",NULL};
int buffer_size;
DEBUG debug_output ("s","ColourMenu: entering show\n");
if (!global_menu.wimp_menu) { /* If we haven't created the menu in memory yet ... */
if ((global_menu.wimp_menu = mem_alloc (sizeof(wimp_MenuHeader) + 17 * sizeof(wimp_MenuEntry))) == NULL) {
return make_error (ColourMenu_AllocFailed, 2, r->r[1], -1);
} else {
wimp_Menu *menu = global_menu.wimp_menu;
if ((e = messages_file_lookup ("None", 0, &buffer_size, 0)) != NULL)
return e;
/* IDJ: 6-Feb-95: bug-fix AQU-01196: memory leak */
if (entry_texts[16] != NULL)
{
mem_freek(entry_texts[16]);
entry_texts[16] = NULL;
}
if ((entry_texts[16] = mem_alloc (buffer_size)) == NULL)
return make_error(ColourMenu_AllocFailed,0);
if ((e = messages_file_lookup ("None", entry_texts[16], &buffer_size, 0)) !=NULL)
return e;
menu->hdr.title.indirect_text.valid_string = NULL;
menu->hdr.title_fgnd = style_MENU_TITLE_FORECOL;
menu->hdr.title_bgnd = style_MENU_TITLE_BACKCOL;
menu->hdr.worka_fgnd = style_MENU_ENTRY_FORECOL;
menu->hdr.worka_bgnd = style_MENU_ENTRY_BACKCOL;
menu->hdr.height = style_MENU_ENTRY_HEIGHT;
menu->hdr.vert_gap = style_MENU_ENTRY_GAP;
for (i=0; i<=16; i++) {
entry = wimp_menu_entry (menu, i);
entry->flags = (i==0) ? wimp_MENUFLAGS_TITLE_INDIRECT : 0;
entry->icon_flags = wimp_ICONFLAGS_TEXT
| ((i<16) ? (wimp_ICONFLAGS_BACKCOL * i) : 0)
| wimp_ICONFLAGS_VCENTRE
| wimp_ICONFLAGS_FILLED
| wimp_ICONFLAGS_INDIRECT
| wimp_ICONFLAGS_NO_CANCEL
| wimp_ICONFLAGS_BUTTON_TYPE * 9
| wimp_ICONFLAGS_ESG * 0;
/* | wimp_ICONFLAGS_RJUSTIFY
All menus have previously been left justify so this flag has been removed for consistency.
*/
entry->submenu = (wimp_Menu *) -1;
entry->icon_data.indirect_text.buffer = entry_texts[i];
entry->icon_data.indirect_text.buff_len = strlen(entry_texts[i])+1;
entry->icon_data.indirect_text.valid_string = NULL;
DEBUG debug_output ("s","ColourMenu: entry %d, '%s'\n",i,entry->icon_data.indirect_text.buffer);
}
entry = wimp_menu_entry (menu, 16);
entry->icon_flags |= (wimp_ICONFLAGS_BACKCOL * style_MENU_ENTRY_BACKCOL)
| (wimp_ICONFLAGS_FORECOL * style_MENU_ENTRY_FORECOL);
}
if ((e = palette_update()) != NULL)
return e;
wimp_menu_entry (global_menu.wimp_menu, 16)->flags |= wimp_MENUFLAGS_LAST_ITEM;
}
/* Set the correct last item */
if (none_entry) { /* Entry no. 16 (the 17th always thinks its the last item!) */
wimp_menu_entry (global_menu.wimp_menu, 15)->flags &= ~wimp_MENUFLAGS_LAST_ITEM;
} else {
wimp_menu_entry (global_menu.wimp_menu, 15)->flags |= wimp_MENUFLAGS_LAST_ITEM;
}
/* tick the correct colour */
old_colour = global_menu.colour;
if (old_colour >= 0) /* untick previous colour */
wimp_menu_entry (global_menu.wimp_menu,old_colour)->flags &= ~wimp_MENUFLAGS_TICKED;
if (menu_int->colour >= 0 && menu_int->colour <= ((none_entry)?16:15)) /* tick current colour */
wimp_menu_entry (global_menu.wimp_menu,menu_int->colour)->flags |= wimp_MENUFLAGS_TICKED;
global_menu.colour = menu_int->colour;
global_menu.current = menu_int;
if ((e = show_menu_coords (user_regs)) != NULL)
return e;
global_menu.t = t;
title_width = (menu_int->title) ? strlen (menu_int->title) : strlen (global_title);
global_menu.wimp_menu->hdr.title.indirect_text.buffer = (menu_int->title) ? menu_int->title : global_title;
DEBUG debug_output ("s","ColourMenu: global_title = '%s'\n",global_title);
global_menu.wimp_menu->hdr.title.indirect_text.buff_len = title_width+1;
global_menu.wimp_menu->hdr.width = ((title_width > 4) ? title_width+1 : 5)<<4;
if (user_regs->r[0] & 2) {
global_menu.flags &= ~GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL;
regs.r[0] = 0;
regs.r[1] = (int) global_menu_state;
if ((e = _kernel_swi (Wimp_GetMenuState, &regs, &regs)) != NULL) {
return e;
}
r->r[0] = (int) global_menu.wimp_menu;
} else {
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL;
*global_menu_state = -1;
}
global_menu.flags &= ~GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT;
/* generate event if necessary */
if (global_menu.current->flags & ColourMenuInternal_GenerateShowEvent) {
regs.r[0] = 0; /* flags*/
regs.r[1] = user_regs->r[1]; /* Object id */
regs.r[2] = -1; /* Component id */
regs.r[3] = (int) &toolbox_event;
toolbox_event.hdr.size = sizeof (ColourMenu_AboutToBeShown_Event);
toolbox_event.hdr.event_code = ColourMenu_AboutToBeShown;
toolbox_event.hdr.flags = user_regs->r[0];
about_to_be_shown = (ColourMenu_AboutToBeShown_Event *) &toolbox_event;
about_to_be_shown->show_type = user_regs->r[2];
about_to_be_shown->x = global_menu.x;
about_to_be_shown->y = global_menu.y;
return _kernel_swi (Toolbox_RaiseToolboxEvent, &regs, &regs);
} else {
global_menu.flags |= GLOBAL_MENU_INFO_FLAGS_IS_SHOWING;
return ((global_menu.flags & GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL)?menu_show_actual():menu_show_submenu_actual());
}
return NULL;
}
_kernel_oserror *show_menu_coords (_kernel_swi_regs *user_regs) {
_kernel_oserror *e = NULL;
_kernel_swi_regs regs;
DisplayInfo *coords = (DisplayInfo *) user_regs->r[3];
wimp_PointerInfo ptr_info;
switch (user_regs->r[2]) {
case 1:
case 2:
global_menu.x = coords->x;
global_menu.y = coords->y;
break;
default:
regs.r[1] = (int) &ptr_info;
if ((e = _kernel_swi (Wimp_GetPointerInfo, &regs, &regs)) != NULL) return e;
global_menu.x = ptr_info.x - 64;
global_menu.y = ptr_info.y;
break;
}
DEBUG debug_output ("s","ColourMenu: global_menu.current @0x%x\n",(int)global_menu.current);
DEBUG debug_output ("s","ColourMenu: show coordinates are (%d,%d)\n",global_menu.x,global_menu.y);
return e;
}
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Title: task.c
* Purpose: task handling for the ColourMenu module
* Author: TGR
* History: 18-Jan-94: TGR: created from IDJ template
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "kernel.h"
#include "swis.h"
#include "const.h"
#include "macros.h"
#include "services.h"
#include "debug.h"
#include "mem.h"
#include "string32.h"
#include "messages.h"
#include "objects.toolbox.h"
#include "objects.colourmenu.h"
#include "main.h"
#include "object.h"
#include "auxiliary.h"
#include "task.h"
/*
* This module has a linked list of client tasks.
* task_add gets called when a Service_ToolboxTaskBorn
* service call goes round.
* The task is removed when the Service_WimpCloseDown is
* received.
* Each task keeps an Object list
*/
static TaskDescriptor *task__list = NULL;
extern BOOL task_any_active(void)
{
return task__list != NULL;
}
extern TaskDescriptor *task_find (int task_handle)
{
/*
* Function to return a TaskDescriptor corresponding to
* a task with a given Wimp handle
*/
TaskDescriptor *t;
t = task__list;
while (t != NULL)
{
if (t->task_handle == task_handle)
break;
t = t->next;
}
return t;
}
extern void task_remove (int task_handle)
{
/*
* Function to remove a task descriptor from the list, given its
* Wimp task handle. Memory is freed, and we also delete any objects
* owned by the exiting task.
*/
TaskDescriptor *t = task__list;
TaskDescriptor *prev_t = NULL, *next = NULL;
ColourMenuInternal *i,*j;
/*
if (t == global_menu.t) {
if (global_menu.wimp_menu) {
mem_freek (global_menu.wimp_menu);
global_menu.wimp_menu = NULL;
}
}
*/
while (t != NULL)
{
next = t->next;
if (t->task_handle == task_handle)
{
/*
* remove this task's object's list
*/
if (t->object_list != NULL) {
i = t->object_list;
do {
j = i->forward;
if (i == global_menu.current) {
global_menu.current = NULL;
global_menu.flags = 0;
}
if (i->title) mem_freek (i->title);
mem_freek (i);
} while ((i=j) != t->object_list);
}
/*
* remove the task descriptor itself
*/
if (t == task__list)
task__list = next;
else
prev_t->next = next;
mem_free (t, "freeing task descriptor (colourmenu)");
break;
}
prev_t = t;
t = next;
}
if (task__list == NULL)
if (global_menu.wimp_menu) {
mem_freek (global_menu.wimp_menu);
global_menu.wimp_menu = NULL;
}
}
extern void task_add (int task_handle)
{
/*
* Function to add a task descriptor to the list of active
* Toolbox tasks.
*/
/*
* extra safety check, we make sure that the task is not already there!
*/
TaskDescriptor *new_t;
if (task_find (task_handle) != NULL)
return;
/*
* add task to list
*/
if ((new_t = mem_allocate (sizeof(TaskDescriptor), "task descriptor(colourmenu)")) == NULL)
{
raise_toolbox_error(ColourMenu_AllocFailed,0,-1,0);
return;
}
new_t->task_handle = task_handle;
new_t->next = task__list;
task__list = new_t;
}
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; Title: cmhg.toolbox
; Purpose: module header for a ColourMenu Object module
; Author: TGR
; History: 18-Jan-94: TGR: version 1.00
; PRODUCT RELEASE
; 6-Feb-95: IDJ: version 0.17 fixes AQU-01196
;
initialisation-code: ColourMenu_init
finalisation-code: ColourMenu_finalise
service-call-handler: ColourMenu_services 0x44ec1, 0x44ec2, 0x44ec3
title-string: ColourMenu
help-string: ColourMenu 0.17
command-keyword-table: ColourMenu_commands
ColourMenu_Memory()
swi-chunk-base-number: 0x82980
swi-handler-code: ColourMenu_SWI_handler
swi-decoding-table: ColourMenu, ClassSWI, PostFilter, PreFilter
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; Title: cmhg.toolbox
; Purpose: module header for a ColourMenu Object module
; Author: TGR
; History: 18-Jan-94: TGR: version 1.00
; PRODUCT RELEASE
; 6-Feb-95: IDJ: version 0.17 fixes AQU-01196
;
initialisation-code: ColourMenu_init
finalisation-code: ColourMenu_finalise
service-call-handler: ColourMenu_services 0x44ec1, 0x44ec2, 0x44ec3
title-string: ColourMenu
help-string: ColourMenu 0.17
swi-chunk-base-number: 0x82980
swi-handler-code: ColourMenu_SWI_handler
swi-decoding-table: ColourMenu, ClassSWI, PostFilter, PreFilter
/* Copyright 1996 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __auxiliary_h
#define __auxiliary_h
#include "kernel.h"
#ifndef __toolbox_h
#include "objects.toolbox.h"
#endif
#ifndef __colourmenu_h
#include "objects.colourmenu.h"
#endif
#ifndef __wimp_h
#include "twimp.h"
#endif
#ifndef __mem_h
#include "mem.h"
#endif
#include "main.h"
#include "object.h"
#include "task.h"
#define mem_freek(A) mem_free(A,"Colour")
#define mem_alloc(A) mem_allocate(A,"Colour")
#define GCharSpaceX 164;
typedef struct _display_info { /* Graphical display information, either coords or size */
int x;
int y;
} DisplayInfo;
/* Globals **************************************************************************************/
extern int global_menu_state[64];
typedef struct {
unsigned int x,y,flags,colour;
ColourMenuInternal *current;
wimp_Menu *wimp_menu;
TaskDescriptor *t;
} GlobalMenu;
extern GlobalMenu global_menu;
extern char *global_title;
extern char *global_help_message;
extern EventInterest messages_of_interest[];
extern EventInterest events_of_interest[];
extern EventInterest toolbox_events_of_interest[];
#define GLOBAL_MENU_INFO_FLAGS_IS_SHOWING 0x00000001
#define GLOBAL_MENU_INFO_FLAGS_SHOW_NEXT 0x00000002
#define GLOBAL_MENU_INFO_FLAGS_TOP_LEVEL 0x00000004
extern BOOL menu_showing (int *buffer);
extern _kernel_oserror *palette_update (void);
extern void set_colour (ColourMenuInternal *menu_int, int new_colour);
extern _kernel_oserror *hide_menu (ColourMenuInternal *menu_int);
extern _kernel_oserror *update_tree (void);
_kernel_oserror *menu_show_actual (void);
_kernel_oserror *menu_show_submenu_actual (void);
extern _kernel_oserror *has_been_hidden (void);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment