home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
programs
/
fonts
/
a_q
/
fontwindow
/
!FntWinDoc
/
FntWinDocs
< prev
next >
Wrap
Text File
|
1993-03-02
|
21KB
|
634 lines
Overview
Introduction
The FontWindow module provides support for maintaining anti-aliased
font icons across screen resolution changes. It also supports the use of
anti-aliased fonts in menus.
The current situation is that if a window is opened at one screen
resolution and the user then changes screen resolution, then fonts are at
the wrong 'size'. This is not acceptable.
Assumptions
To do its' job the FontWindow module must make some assumptions
about each client:
• It is a wimp application (has a task handle)
• The window definitions come from a template file
• All windows are loaded from the template file at the same time
• None of the fonts are closed by the program
• The order of the icons must not change
These are fairly mild restrictions, to say the least. The reason why the
windows must be loaded (although not necessarily created) at the same
time is so that the font handles in all windows all have 'base' values.
Abstract window handle
The FontWindow module uses an abstract window handle, and relies on
the client to map this to an actual (wimp) window handle. In use this
usually means the abstract handle is one of the following:
• the actual wimp window handle
• a pointer to a word containing the wimp window handle
• a pointer to a structure used to hold information about a window
There is built in support for the first two cases.
If the abstract handle is the actual window handle, then windows with
anti-aliased title bar icons can not be handled − the title bar will remain
in the 'wrong' font across a resolution change.
Errors
The following errors may be generated by the FontWindow module:
&110 Unknown FontWindow operation
&465C0 Unknown FontWindow task
&465C1 Unknown FontWindow window
&465C2 Bad version number for FontWindow
&465C3 FontWindow: reserved flags not zero
&465C4 FontWindow is currently active
&465C5 FontWindow: Window manager too old / not present
&465C6 FontWindow: illegal attempt to de/register menu
&465C7 Unknown FontWindow menu
It should be fairly obvious how and when these would be generated.
Menus
From v1.10 it is possible for FontWindow to maintain a group of menus
with an anti-aliased font used for the item text. The font is fixed for all
menus, but can be defined at initialisation. Currently anti-aliased menu
title bars are not supported.
Furthermore, it is possible to only allow the anti-aliased font to be used
in high resolution screen modes (>= 90 dots per inch), using the system
font at lower resolutions.
All the client has to do is register each (sub) menu once, and that's all!
Registered menus are automatically updated at time of registration and
on a screen mode change.
Note that due to a bug in the window manager v3.16, if you use an anti-
aliased font in menus, and some of those menu items are NOT
indirected, then it SOMETIMES will not display that menu item. From
v1.20 FontWindow can be told to automatically indirect such items.
Because anti-aliased fonts are (generally) proportionally spaced, it is
possible that the (anti-aliased) menu may be too wide or, more likely, too
short. From v1.20 FontWindow can be told to compute the width of the
menu.
Revision History
version 1.00 19-Jan-1993
Window support
version 1.10 19-Feb-1993
Support for anti-aliased menus
version 1.20 27-Feb-1993
Extension to anti-aliased menus, to auto-width the menu
and kludge around a window manager v3.16 bug
version 1.21 02-Mar-1993
SWI allocation from Acorn: FontWindow, &465C0
The SWI's
This chapter details the SWI's provided by the FontWindow module.
FontWindow_Initialise
(SWI &465C0)
Register task with FontWindow module.
On entry R0 = task handle
R1 = pointer to routine to allocate memory (see below)
R2 = pointer to routine to de-allocate memory (see below)
R3 = pointer to routine to decode an abstract window handle (see below)
R4 = pointer to routine to recreate a window (see below)
R5 = routines' R12
R6 = pointer to 256-byte font table to use while loading templates
zero to allocate and initialise one inside the RMA
R7 = version number * 100 of FontWindow that client knows about
bit 16 menus are to always have anti-aliased fonts
bit 17 menus are to have anti-aliased fonts only in high
resolution screen modes (>= 90 dots per inch)
bit 18 automatically calculate menu width if anti-aliasing
bit 19 force all menu items to be indirected if anti-aliasing
bits 20-31 are currently reserved and must be zero
R8 = (if flags in R7) pointer to block defining font to use in menus
+0 font x size, in points * 16
+4 font y size, in points * 16
+8 CR-terminated font name (strlen() < 40)
On exit R0 = pointer to 256-byte font table to use while loading templates
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call registers a wimp application with the FontWindow module.
The client supplies the address of routines used to de/allocate memory
and process the abstract window handle. Fortunately there are default
routines supplied for the most common cases.
If R6=0 then a 256-byte font table is allocated for you.
The version supplied in R7 must be >= 100.
If the client wishes to use anti-aliased fonts in menus then set bit 16/17
of R7, ensure that the version >= 110, and point R8 to a block defining
which font to use. If R8=0 then the default font is used − Homer
ton.Medium at 14 points.
Due to a bug in the window manager v3.16 if you mix indirected and
non-indirected menu items with anti-aliased fonts, then the occasional
non-indirected item will not display. To remedy this, setting bit 19 of
R7 (and setting the version to >= 120) will cause FontWindow to force
all items to be indirected. This appears to work.
If you use fonts in menu items then the occasional item may become too
wide for the menu (with a width calculated using the system character
set). Since it is inconvenient to change the text of menu items, FontWin
dow can compute the width of anti-aliased menu items by setting bit 18
of R7 (and setting the version to >= 120).
The routines are all entered in SVC mode, with R12 set as requested, and
R13 pointing to the usual SVC full-descending stack. The routines may
corrupt R0-R3, R10-R12, R14. All PSR flags must be preserved, except
as indicated.
R1 − allocate memory
On entry R0 = byte-aligned size of memory to allocate
On exit R0 = pointer to word-aligned memory
PSR_V clear if ok
PSR_V set and R0 = error block if error
If R1 = 0 then a suitable routine that allocates memory from the RMA is
used. Note that the routine is entered in SVC mode.
This routine is used to allocate memory for each window registered, and
also to allocate a temporary buffer used when recreating a window.
R2 − de-allocate memory
On entry R0 = pointer to previously allocated memory, or zero [do nothing]
On exit -
If R2 = 0 then a suitable routine that de-allocates memory from the RMA
is used.
This is called when a window is deleted, or to delete the temporary
buffer used when recreating a window.
R3 − decode abstract window handle
On entry R0 = abstract window handle
On exit R0 = wimp window handle
If R3 = 0 then a suitable routine that treats the abstract window handle as
the actual window handle is used.
If R3 = 1 then a suitable routine that treats the abstract window handle as
a pointer to the actual window handle is used.
This is called at many different points.
R4 − recreate window
On entry R0 = abstract window handle
R1 = pointer to wimp_winfo block [ie after Wimp_GetWindowInfo]
On exit -
PSR_V clear if ok
PSR_V set and R0 = error block if error
The entry R1 block contains a wimp_openstr for the recreated window
This routine will be called when a windows' title bar is anti-aliased and
needs to be changed to a new font. The only way to do that is to: read
the current window definition, delete the window, change the title bar
icon, and immediately re-create the window.
On entry R1+0 is the wimp window handle and R1+4 is the window
definition, the title bar icon has been altered. This routine should delete
the window, immediately re-create it and then update its' copy of the
wimp window handle. Incase the window was already open, the
FontWindow module may need to re-open it and so the (new) wimp
window handle should be stored at R1+0 before returning.
If R4 = 0 then a suitable routine that treats the abstract window handle as
the actual window handle is used. This means that it is not possible to
recreate the window (since the caller will not know about the new
window handle) and so the routine simply clears PSR_V and returns.
If R4 = 1 then a suitable routine that treats the abstract window handle as
a pointer to the actual window handle is used.
FontWindow_CloseDown
(SWI &465C1)
Remove task from FontWindow module.
On entry R0 = task handle
R1 = non-zero if close all open fonts
R2 = non-zero if should delete window(s) as well
On exit -
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call removes a wimp application, and any registered windows, from
those registered with the FontWindow module. At the time of this call
the task must be active.
If R2 is non-zero then the registered windows are actually
Wimp_DeleteWindow'ed as well. This is usually not necessary.
If R1 is non-zero then the 256-byte font table is used to close all fonts
opened by the application. This is usually quite handy.
FontWindow_ModeChange
(SWI &465C2)
Handle screen mode being changed.
On entry R0 = task handle
On exit -
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This should be called whenever a Message_ModeChange message is
received by the task. If this is not done then the FontWindow module
can not work.
If the screen resolution has changed (unlikely) the fonts used by the
application are closed and then re-opened at the new resolution. If any
registered windows are currently open then they are automatically
updated. This strategy ensures minimum overhead in the most common
case − nothing to be done.
In actual fact the fonts are not closed. This is because of a bug in the
Wimp v3.10 demonstrated by the following sequence. Start application
(load template with writable icon) in a high-resolution mode; go down to
a low-resolution mode; change wimp_createstr block so fonts point to
new font handles for current screen resolution; call
Wimp_CreateWindow; press Reset button.
To get around this FontWindow currently leaves fonts open once at each
resolution used by the application. Not ideal, but it works.
FontWindow_CreateWindow
(SWI &465C3)
Create the window.
On entry R0 = task handle
R1 = pointer to wimp_createstr block
R2 = abstract window handle, or zero
On exit R0 = window handle
R1 = non-zero if window contained anti-aliased font icon(s)
R1 block updated to reflect current resolution
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call may update the windows' icons if necessary, then does a
Wimp_CreateWindow. If the window contains any anti-aliased font
icons then the details of these are cached for later operations on the
window.
This SWI can be called at any time, but the wimp_createstr block must
have come directly from the template file (so all windows passed to this
routine have 'base' font handles).
The special case where R2 = 0 is used for simple applications, and sets
the internal copy of the abstract window handle to the wimp window
handle. In all other cases it is necessary for the caller to store the details
of the window handle as returned.
The return value in R1 can be used to determine if the window did
contain any anti-aliased font icons.
FontWindow_DeleteWindow
(SWI &465C4)
Delete a window that has cached information.
On entry R0 = task handle
R1 = abstract window handle
On exit -
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call removes a previously registered window, and then deletes it
(using Wimp_DeleteWindow).
FontWindow_OpenWindow
(SWI &465C5)
Update a registered windows' anti-aliased icon definitions (if necessary)
and then open the window.
On entry R0 = task handle
R1 = pointer to wimp_openstr block [window handle not filled in]
R2 = abstract window handle
On exit -
R1+0 holds current window handle
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call will update the windows' icons if they contain references to
font handles opened to a different resolution than the current screen
resolution. It then opens the window at the requested position.
This call is almost redundant. Because the FontWindow_CreateWindow
leaves the window ready for the current resolution this SWI is only
necessary if you create your windows in one go and only open them at
some later time.
There is no need (normally) to use this call when the application receives
a Message_OpenWindow, as the window would already be open − and
hence contain the correct font handles.
FontWindow_Update
(SWI &465C6)
Update a registered windows' anti-aliased icon definitions.
On entry R0 = task handle
R1 = abstract window handle
On exit -
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call will update the windows' icons if they contain references to
font handles opened to a different resolution than the current screen
resolution. Consider it as a pre-processor before opening the window.
This call is usually used on dialogue boxes used as a sub-menu.
FontWindow_RegisterMenu
(SWI &465C7)
Register a wimp menu with the FontWindow module.
On entry R0 = task handle
R1 = pointer to wimp menu block
On exit -
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call will allow FontWindow to transparently update the registered
menu's anti-aliased font status in accordance with the flags set by
FontWindow_Initialise.
Note that this call does not register any of the menus' sub-menus. Each
sub-menu must be registered separately.
It is assumed that the menu being registered uses the system font for its'
menu items − which is not unreasonable. After this call the menus' items
may now be anti-aliased, if necessary.
Anti-aliased menu title bars are not currently supported.
Note that if you intend to swap a menu between font/system and the
menu contains items coloured other than black text on a white back
ground, then it is essential that these items be indirected and include a
validation string with an "F<back><fore>" validation. This is particu
larly true for 'colour-selection' menus. If no such validation string is
found then when converting from font to system, FontWindow will
make the item black text on a white background.
Each registered menu uses approximately 28 bytes of (user-supplied)
memory, plus any extra memory required if items are forced to become
indirected (24 bytes each).
FontWindow_DeRegisterMenu
(SWI &465C8)
De-register a wimp menu from the FontWindow module.
On entry R0 = task handle
R1 = pointer to wimp menu block
R2 = non-zero if force menu items to system font
On exit -
Interrupts -
Processor Mode Processor is in SVC mode
Re-entrancy SWI is re-entrant
Use This call pulls the previously registered menu from the list that are
automatically maintained by the FontWindow module.
If the menus' items were anti-aliased at the start of this call, and R2<>0
then the menu will be converted back to using the system font. This uses
any "F<back><fore>" validation string if found, defaulting to black text
on a white background if not found.
All registered menus are automatically de-registered by the call to
FontWindow_CloseDown.
*Commands
This chapter documents the *Commands provided by the FontWindow
module. All two of them.
*FontWindow
This does nothing, it is provided as a *Help command to display a short
description of the purpose of the module.
*Desktop_FontWindow
This command causes the FontWindow module to be entered as the
current application. This starts a wimp application that monitors tasks
dyeing, and takes some actions if the task was initialised for use with the
FontWindow module.
This feature can be used while developing applications that 'crash'
without exiting cleanly. The FontWindow wimp task will quietly close
all fonts opened by the application. This is useful over a long program
ming session or where font handles become scarce.
However, this can only be done if the default memory de/allocation
routines are used and the font-table was auto-allocated.
Since the FontWindow task has no icon bar icon, and informs the wimp
that it is only interested in Message_TaskCloseDown, there should be no
performance degradation in using this debugging aid.
The total memory usage of this feature is <3/4K.
Examples
This chapter shows how you would actually incorporate these routines
into your current wimp (basic/arm) libraries. In practise, ARM programs
are extremely easy to convert to use of FontWindow. Basic programs
less so.
The !Demo application contains Basic source code for two types of
application − simple stuff that never clones template windows, and a
full-blown multi-document application.
!Run files
You wouldn't forget to include something like the following, would you:
Set App$Path <App$Dir>.,System:Modules.
RMEnsure FontWindow 1.21 RMLoad App:FontWindow
RMEnsure FontWindow 1.21 Error FontWindow module too old
Note that you should use v1.21 in the above RMEnsures, as before this
FontWindow used a (user) SWI chunk.
Simple app's
By simple, it is meant an application that never clones any of its'
template windows. It just creates one window from each window in the
template. Also, no window will have anti-aliased title bar icons. The
vast majority of applications fall into this range.
Just after your Wimp_Initialise add the following:
FontWindow_Initialise, <task handle>, 0, 0, 0, 0, <R12>, 0, 100 TO
<font table>
This font table should then be used when you load templates.
Now, just before your Wimp_CloseDown insert:
FontWindow_CloseDown, TRUE, FALSE
which closes all the fonts for you.
Don't forget to add a call to FontWindow_ModeChange if you receive a
Message_ModeChange − this is essential.
Now, instead of calling Wimp_CreateWindow, you would use
FontWindow_CreateWindow. Use the returned window handle as the
'abstract window handle' in all future calls regarding this window.
For dialogue boxes use a call to FontWindow_Update before the call to
Wimp_CreateSubMenu.
If you do open the window later use FontWindow_OpenWindow in
place of Wimp_OpenWindow.
That's all there is to it.
Large app's
These include multi-document applications and ones that contain
windows with anti-aliased title bar icons.
These are the most awkward, as there are both cloned windows and
(constant) dialogue boxes − but everything has to be treated the same in
respect to the FontWindow module.
We use the 'built-in' abstract handle that is a pointer to the real window
handle. Other than that you follow the same steps as for small appli
cations. So, to start up use:
FontWindow_Initialise, <task handle>, 0, 0, 1, 1, <R12>, 0, 100 TO
<font table>
Now for each dialogue-box window you have to reserve a word of
memory to store the actual window handle, and use this pointer as the
abstract window handle. This means all references in the source code to
the window handle now need to be changed to refer to the contents of
this word of memory. Ho hum.
For 'document' windows it is assumed you already store the window
handle as part of a larger structure, and so the use of this is trivial.
Allocate routine
Here's the default memory allocation routine:
MOV R1, lr
MOV R3, R0
MOV R0, #ModHandReason_Claim
SWI "XOS_Module"
MOVvc R0, R2
BICvcS pc, R1, #PSR_V
ORRS pc, R1, #PSR_V
Deallocate routine
Here's the default memory de-allocation routine:
MOV R1, lr
MOVS R2, R0
MOVne R0, #ModHandReason_Free
SWIne "XOS_Module"
MOVS pc, R1
Recreate routine
Here's the default routine used to recreate a window if the abstract
window handle is a pointer to the actual window handle:
MOV R3, R0
MOV R2, lr
SWI "XWimp_DeleteWindow"
ADDvc R1, R1, #4
SWIvc "XWimp_CreateWindow"
STRvc R0, [R3], #0
SUBvc R1, R1, #4
STRvc R0, [R1, #u_handle]
BICvcS pc, R2, #PSR_V
ORRS pc, R2, #PSR_V