RISCOS.com

www.riscos.com Technical Support:
Toolbox

 


Scale Dialogue box class


A Scale Dialogue object is used to present the user with a dialogue box from which he can set the scale factors for a view on a document. This scale is given as a percentage of the original size of the document.

User interface

The Scale class provides a dialogue box from which a scale factor can be chosen:

SCALE-2.GIF

The default Scale dialogue box has the following attributes:

  • a title bar string
  • a writable number range with up/down arrows and a percentage sign to the right of the up/down arrows
  • four 'standard' size action buttons with the values: 33%, 80%, 100%, 120% as their text plus an optional Scale to Fit action button
  • a Cancel action button
  • a Scale action button.

The user can:

  • type an integral value in the writable field between its lower and upper bounds or use the up/down arrows to adjust the value currently in the field
  • use one of the standard size action buttons to set the scale factor. Clicking on these buttons only causes a value to be inserted in the writable field; it does not apply the scale factors
  • click outside the dialogue box (if it is transient) or click on Cancel, to cancel the dialogue
  • click on Scale or press Return to apply the scale factors
  • if there is a Scale to Fit button, then clicking on it will have application-defined behaviour (e.g. Scale to Fit window).

Application Program Interface

When a Scale object is created it has the following components:

  • an optional Scale To Fit button.
  • an alternative title to use instead of the default.
  • alternative bounds and step size for the writable field.
  • an optional list of different standard size action buttons where each gives a percentage value to insert into the Writable Field. These will be positioned appropriately by the Scale module in place of the default standard size buttons. When a Scale object is shown, the client will be delivered a Scale_DialogueAboutToBeShown Toolbox event (if enabled), just before the dialogue box becomes visible on the screen.

When the Scale dialogue is showing, the Scale module deals with all relevant Wimp events and reports user actions back to the client via Toolbox events. If there are any standard size action buttons in the dialogue box, then the Scale module deals with clicks on them, and inserts the correct percentage value into the writable field.

The client is guaranteed to receive a Scale_DialogueCompleted Toolbox event when the dialogue is over (i.e. the user has clicked on Cancel, or clicked outside the dialogue box (if it were transient), or clicked on Scale, or on Scale To Fit).

Attributes

A Scale object has the following attributes which are specified in its object template and can be manipulated at run-time by the client application:

Attributes Description
flags Bit Meaning
0 when set, this bit indicates that a Scale_AboutToBeShown event should be raised when SWI Toolbox_ShowObject is called for this object.
1 when set, this bit indicates that a Scale_DialogueCompleted event should be raised when the Scale object has been removed from the screen.
2 when set, dialogue box has a Scale To Fit button
min val alternative minimum value for the writable field
max val alternative maximum value for the writable field
step size alternative step size for up/down arrows
Scale title alternative title for the dialogue rather than 'Scale View'
(0 means use default)
max title length this gives the maximum length in bytes of title text which will be used for this object
window the name of an alternative window template to use instead of the default one (0 means use default)
std1 value value of first std scale button
std2 value value of second std scale button
std3 value value of third std scale button
std4 value value of fourth std scale button
Manipulating a Scale object
Creating and deleting a Scale object

A Scale object is created using SWI Toolbox_CreateObject.

When this object is created it has no attached objects (see Attached objects).

A Scale object is deleted using SWI Toolbox_DeleteObject.

The setting of the non-recursive delete bit does not have a meaning for Scale objects.

Showing a Scale object

When a Scale object is displayed on the screen using SWI Toolbox_ShowObject it has the following behaviour:

Show type Position
0 (default) the underlying window is shown at the last place shown on the screen, or the coordinates given in its template, if it has not already been shown
1 (full spec) R3 + 0 visible area minimum x coordinate
R3 + 4 visible area minimum y coordinate
R3 + 8 visible area maximum x coordinate
R3 + 12 visible area maximum y coordinate
R3 + 16 scroll x offset relative to work area
R3 + 20 scroll y offset relative to work area
R3 + 24 Wimp window handle of window to open behind
-1 means top of stack
-2 means bottom of stack
-3 means the window behind the Wimp's backwindow
2 (topleft) R3 + 0 visible area minimum x coordinate
R3 + 4 visible area minimum y coordinate
Before the Scale Dialogue box is shown

When SWI Toolbox_ShowObject is called on a Scale object, the Scale Class raises a Scale_AboutToBeShown Toolbox event (if enabled), just before it shows the underlying Window object which implements this dialogue. This will allow the client to set an initial suitable value in the Scale dialogue's Writable Field.

Applying a Scale factor

When the user clicks on the Scale button, or on the Scale To Fit button if it is present, the Scale module delivers a Scale_ApplyFactor to the client, giving the percentage factor to apply. A special value of 0xffffffff is delivered if the Scale To Fit button is clicked.

Cancelling a Scale dialogue

If the user clicks on the Cancel Button (or clicks outside the Scale dialogue box), then the Scale module delivers a Scale_DialogueCompleted Toolbox event to the client application. This allows the client to update any of its data structures and to clean up any state associated with this dialogue.

Completion of a Scale dialogue

When the Scale module has hidden its dialogue box at the end of a dialogue, it delivers a Scale_DialogueCompleted Toolbox event to the client (if enabled), with an indication of whether a scale factor was reported to the client during the dialogue.

Reading and setting the writable field

Normally a client will only need to respond to the Scale_ApplyFactor Toolbox event in order to allow the user to set scale factors. If, however, the client wishes to read the current value in the writable field, or to set it explicitly (to a suitable start value when the dialogue box is first shown), then it can use the Scale_SetValue/Scale_GetValue methods.

Reading and setting the bounds of the writable field and step size

Normally a client will specify the bounds and step size of the writable field in the template description for the Scale object.

These can however be read and set dynamically using the Scale_SetBounds/ Scale_getBounds and Scale_GetStepSize/Scale_SetStepSize methods.

Scale methods

The following methods are all invoked by calling SWI Toolbox_ObjectMiscOp with:

R0 holding a flags word
R1 being a Scale Dialogue object id
R2 being the method code which distinguishes this method
R3-R9 potentially holding method-specific data
Scale_GetWindowID 0
On entry
R0 = flags
R1 = Scale object id
R2 = 0
On exit
R0 = Window object id for this Scale object
Use

This method returns the id of the underlying Window object used to implement this Scale object.

C veneer

extern _kernel_oserror *scale_get_window_id ( unsigned int flags,
                                              ObjectId scale,
                                              ObjectId *window
                                            );

Scale_SetValue 1
On entry
R0 = flags
R1 = Scale object id
R2 = 1
R3 = value
On exit
R1-R9 preserved
Use

This method is used to set the value displayed in the writable field for this Scale object.

C veneer

extern _kernel_oserror *scale_set_value ( unsigned int flags,
                                          ObjectId scale,
                                          int value
                                        );

Scale_GetValue 2
On entry
R0 = flags
R1 = Scale object id
R2 = 2
On exit
R0 = value
Use

This method returns the value in the writable field of this Scale object.

C veneer

extern _kernel_oserror *scale_get_value ( unsigned int flags,
                                          ObjectId scale,
                                          int *value
                                        );

Scale_SetBounds 3
On entry
R0 = flags
bit 0 set means set the lower bound to the given value
bit 1 set means set the upper bound to the given value
bit 2 set means set step size
R1 = Scale object id
R2 = 3
R3 = value of the lower bound
R4 = value of the upper bound
R5 = step size
On exit
R1-R9 preserved
Use

This method sets the lower and upper bounds and step size of the writable field in the Scale object.

C veneer

extern _kernel_oserror *scale_set_bounds ( unsigned int flags,
                                           ObjectId scale,
                                           int lower_bound,
                                           int upper_bound,
                                           int step_size
                                         );

Scale_GetBounds 4
On entry
R0 = flags
bit 0 set means return the lower bound
bit 1 set means return the upper bound
bit 2 set means return step size
R1 = Scale object id
R2 = 4
On exit
R0 = value of the lower bound
R1 = value of the upper bound
R2 = value of the step size
Use

This method returns either the lower and upper bounds and step size of the writable field in the Scale object.

C veneer

extern _kernel_oserror *scale_get_bounds ( unsigned int flags,
                                           ObjectId scale,
                                           int *lower_bound,
                                           int *upper_bound,
                                           int *step_size
                                         );

Scale_SetTitle 5
On entry
R0 = flags
R1 = Scale object id
R2 = 5
R3 = pointer to text string to use
On exit
R1-R9 preserved
Use

This method sets the text which is to be used in the title bar of the given Scale dialogue.

C veneer

extern _kernel_oserror *scale_set_title ( unsigned int flags,
                                          ObjectId scale,
                                          char *title
                                        );

Scale_GetTitle 6
On entry
R0 = flags
R1 = Scale object id
R2 = 6
R3 = pointer to buffer to return the text in (or 0)
R4 = size of buffer
On exit
R4 = size of buffer required to hold the text (if R3 was 0)
else Buffer pointed to by R3 contains title text
R4 holds number of bytes written to buffer
Use

This method returns the text string used in a Scale dialogue's title bar.

C veneer

extern _kernel_oserror *scale_get_title ( unsigned int flags,
                                          ObjectId scale,
                                          char *buffer,
                                          int buff_size,
                                          int *nbytes
                                        );

Scale events

The Scale module generates the following Toolbox events:

Scale_AboutToBeShown (0x82c00)
Block
+ 8 0x82c00
+ 12 flags (as passed in to Toolbox_ShowObject)
+ 16 value which will be passed in R2 to ToolBox_ShowObject
+ 20... block which will be passed in R3 to ToolBox_ShowObject for the
underlying dialogue box
Use

This Toolbox event is raised just before the Scale module is going to show its underlying Window object, to enable the client to set its initial value appropriately.

C data type

typedef struct
{
  ToolboxEventHeader hdr;
  int                show_type;
  union
  {
    TopLeft               pos;
    WindowShowObjectBlock full;
  } info;
} ScaleAboutToBeShownEvent;

Scale_DialogueCompleted (0x82c01)
Block
+ 8 0x82c01
+ 12 flags
Use

This Toolbox event is raised after the Scale object has been hidden, either by a Cancel click, or by a click on Scale or Scale To Fit, or by the user clicking outside the dialogue box (if it is transient). It allows the client to tidy up its own state associated with this dialogue.

Note that if the dialogue was cancelled, a scale factor may still have been applied, for example if the user clicked Adjust on Scale, and then cancelled the dialogue.

C data type

typedef struct
{
  ToolboxEventHeader hdr;
} ScaleDialogueCompletedEvent;

Scale_ApplyFactor (0x82c02)
Block
+ 8 0x82c02
+ 16 unsigned integer scale factor to apply
Use

This Toolbox event is raised when the user clicks on the Scale button or the Scale To Fit button (if present), or presses Return.

The scale factor to apply is a percentage; 0xffffffff means Scale To Fit.

C data type

typedef struct
{
  ToolboxEventHeader hdr;
  unsigned int       factor;
} ScaleApplyFactorEvent;

Scale templates

The layout of a Scale template is shown below. Fields which have types MsgReference and StringReference are those which will require relocation when they are loaded from a resource file. If the template is being constructed in memory, then these fields should be real pointers (i.e. they do not require relocation).

For more details on relocation, see Resource File Formats.

Field Size in bytes Type
flags 4 word
min_val 4 word
max_val 4 word
step_size 4 word
title 4 MsgReference
max_title 4 word
window 4 StringReference
std1_value 4 word
std2_value 4 word
std3_value 4 word
std4_value 4 word
Underlying window template

The Window object used to implement a Scale dialogue, has the following characteristics. These must be reproduced if the Window is replaced by a client-specified alternative Window template:

Title bar must be indirected.

Gadgets

Component ids are derived by adding to 0x82c000.

Component id Details
0 number range (Scale) must have adjuster arrows, and be writable
1-4 action buttons
(standard scale factors)
these should have the text 33%, 80%, 100% and 120%
5 action button (Cancel) this must be marked as a Cancel action button
6 action button (Scale) this must be marked as the default action button
7 label (%)
8 label (Scale)
9 action button (Scale to fit)

Scale Wimp event handling

Wimp event Action
Mouse Click on Scale or Scale to Fit buttons, then deliver a Scale_ApplyFactor Toolbox event

on a standard size button then enter its value into the Writable Field

on Cancel button then hide the dialogue box, and deliver a Scale_DialogueCompleted Toolbox event.

Key Pressed if key is Return then act as if Scale button had been clicked

if key is Escape then act as if Cancel button had been clicked.

User Message
User Message Recorded
Message_MenusDeleted
deliver a Scale_DialogueCompleted Toolbox event.

This edition Copyright © 3QD Developments Ltd 2015
Last Edit: Tue,03 Nov 2015