diff --git a/Chapters/ch02-a-side-toolbox.xml b/Chapters/ch02-a-side-toolbox.xml index 99367b0..0a36d54 100644 --- a/Chapters/ch02-a-side-toolbox.xml +++ b/Chapters/ch02-a-side-toolbox.xml @@ -188,29 +188,29 @@ ENDPROC
The first thing that we need to do is to create an equivalent window state block for the toolbox pane, which we can then update with the necessary values calculated from the main window’s position. Unfortunately we can’t use our usual scratch block of memory pointed to by
pane% = main% + 64
+toolbox% = main% + 64
-!pane% = ToolBoxWindow%
-SYS "Wimp_GetWindowState",,pane%
+!toolbox% = ToolBoxWindow%
+SYS "Wimp_GetWindowState",,toolbox%
Since the pane can’t be resized by the user, we can be fairly confident that its width and height will still be as they were saved in the templates file. These can be used to give us the values for the pane’s width and height, saving us from having to use constants in the code. Before making any changes to the pane window state block’s contents, we therefore calculate the width and height of the pane’s visible area and store the two values for future use.
-width% = pane%!12 - pane%!4 : REM Visible Area Maximum X - Minimum X
-height% = pane%!16 - pane%!8 : REM Visible Area Maximum Y - Minimum Y
+box_width% = toolbox%!12 - toolbox%!4 : REM Visible Area Maximum X - Minimum X
+box_height% = toolbox%!16 - toolbox%!8 : REM Visible Area Maximum Y - Minimum Y
As already noted, we know where the main window should be on screen. We also know the relationship that we want to have between the main window and its pane, as shown in
pane%!16 = main%!16 : REM Visible Area Maximum Y
-pane%!8 = main%!16 - height% : REM Visible Area Minimum Y
+toolbox%!16 = main%!16 : REM Visible Area Maximum Y
+toolbox%!8 = main%!16 - box_height% : REM Visible Area Minimum Y
In a similar way, the right-hand side of the pane (its
pane%!12 = main%!4 : REM Visible Area Maximum X
-pane%!4 = main%!4 - width% : REM Visible Area Minimum X
+toolbox%!12 = main%!4 : REM Visible Area Maximum X
+toolbox%!4 = main%!4 - box_width% : REM Visible Area Minimum X
Keeping the
IF main%!28 <> !pane% THEN pane%!28 = main%!28
+IF main%!28 <> ToolBoxWindow% THEN toolbox%!28 = main%!28
There’s one exception to this, however. If the Wimp is already asking us to open the main window behind the pane, then both the pane and the main window must already be in the correct positions in the window stack. In this case, there’s no point attempting to open the pane behind itself, so we just leave things as they are. The pane is now ready to be opened in its new location, using a call to
SYS "Wimp_OpenWindow",,pane%
+SYS "Wimp_OpenWindow",,toolbox%
With the pane open in the correct place, all that remains to do is to open the main window. This is done using the block from the
main%!28 = !pane%
+main%!28 = ToolBoxWindow%
SYS "Wimp_OpenWindow",,main%
Putting all of the code above together, PROChandle_pane_windows() will look as shown in .
-DEF PROChandle_pane_windows(main%)
-LOCAL pane%, width%, height%
+DEF PROChandle_pane_windows(main%)
+LOCAL toolbox%, box_width%, box_height%
REM Get the Window State block for the pane, using some of the spare
REM space above the data for the state of the main window.
-pane% = main% + 64
+toolbox% = main% + 64
-!pane% = ToolBoxWindow%
-SYS "Wimp_GetWindowState",,pane%
+!toolbox% = ToolBoxWindow%
+SYS "Wimp_GetWindowState",,toolbox%
REM Find the width and height of the pane's visible area.
-width% = pane%!12 - pane%!4 : REM Visible Area Maximum X - Minimum X
-height% = pane%!16 - pane%!8 : REM Visible Area Maximum Y - Minimum Y
+box_width% = toolbox%!12 - toolbox%!4 : REM Visible Area Maximum X - Minimum X
+box_height% = toolbox%!16 - toolbox%!8 : REM Visible Area Maximum Y - Minimum Y
REM Move the pane so that it's in the correct X and Y position
REM relative to where the main window is to go.
-pane%!4 = main%!4 - width% : REM Visible Area Minimum X
-pane%!8 = main%!16 - height% : REM Visible Area Minimum Y
-pane%!12 = main%!4 : REM Visible Area Maximum X
-pane%!16 = main%!16 : REM Visible Area Maximum Y
+toolbox%!4 = main%!4 - box_width% : REM Visible Area Minimum X
+toolbox%!8 = main%!16 - box_height% : REM Visible Area Minimum Y
+toolbox%!12 = main%!4 : REM Visible Area Maximum X
+toolbox%!16 = main%!16 : REM Visible Area Maximum Y
REM Unless the main window is to be opened behind the pane, meaning that the
REM pane must already be in the correct place in the stack, set the pane's
REM Open Behind so that it appears in the stack where the main window is to go.
-IF main%!28 <> !pane% THEN pane%!28 = main%!28
+IF main%!28 <> ToolBoxWindow% THEN toolbox%!28 = main%!28
-SYS "Wimp_OpenWindow",,pane%
+SYS "Wimp_OpenWindow",,toolbox%
REM Set the main window's Open Behind so that it opens behind the pane.
-main%!28 = !pane%
+main%!28 = ToolBoxWindow%
SYS "Wimp_OpenWindow",,main%
ENDPROC
@@ -287,7 +287,7 @@ ENDPROC
The full code can be found in .
-
+
REM Move the pane so that it's in the correct X and Y position
REM relative to where the main window is to go.
-pane%!4 = main%!4 - width% : REM Visible Area Minimum X
-pane%!8 = main%!16 - height% : REM Visible Area Minimum Y
-pane%!12 = main%!4 : REM Visible Area Maximum X
-pane%!16 = main%!16 : REM Visible Area Maximum Y
+toolbox%!4 = main%!4 - box_width% : REM Visible Area Minimum X
+toolbox%!8 = main%!16 - box_height% : REM Visible Area Minimum Y
+toolbox%!12 = main%!4 : REM Visible Area Maximum X
+toolbox%!16 = main%!16 : REM Visible Area Maximum Y
We can replace this by testing the minimum
With this in place, our own pane begins to behave in a more Draw-like way when it reaches the edge of the screen, as seen in
The full code can be found in
An alternative to a toolbox at the side of a window, as we
Just as with the toolbox in the previous chapter, the first thing that we will need to do in order to create a toolbar is to design a suitable window template. This time, we will create a toolbar containing a writable icon, which will span the top of our main window – a bit like the URL bar in a browser. The template has been called “Toolbar”, and can be seen in
Much of the window design, including the window flags, is the same as for the toolbox. The toolbar has no window furniture, has its ‘window is a pane’ flag set and its ‘window is moveable’ flag clear.
+ +Compared to the toolbox, we need to take a little more care over the window dimensions. We want the toolbar to span the width of the main window, so the work area width (
The height of the work area (
We have also adjusted the minimum sizes of the bar, although this is as much to keep WinEd happy: with the minimum
The window contains two action buttons and a writable icon, so that we can easily see how the work area moves around in relation to its parent window. All three icons are 52 OS Units high, to match the standard height for a writable icon, and there is a 4 OS Unit gap around the edges of the work area on all four sides.
+ +Once again, we can add the lines shown in
PROCtemplate_load("Toolbar", b%, buffer_size%, -1)
+SYS "Wimp_CreateWindow",,b% TO ToolBarWindow%
+
+The handle of the toolbar is stored in
In terms of infrastructure to handle our new toolbar, there’s not much to add since most of the hard work was done
DEF PROCclose_window_request(b%)
+IF !b% = MainWindow% THEN
+ !q% = ToolBoxWindow%
+ SYS "Wimp_CloseWindow",,q%
+ !q% = ToolBarWindow%
+ SYS "Wimp_CloseWindow",,q%
+ENDIF
+
+SYS "Wimp_CloseWindow",,b%
+ENDPROC
+
+The code that we need to add to
toolbar% = main% + 128
+
+!toolbar% = ToolBarWindow%
+SYS "Wimp_GetWindowState",,toolbar%
+
+The calculations for the position of the toolbox will remain as they are, after which we will add in a similar set of calculations for the new toolbar. To be able to do this, we’ll need the height of the bar – which we can get from its visible area as before.
+ +box_height% = toolbar%!16 - toolbar%!8 : REM Visible Area Maximum Y - Minimum Y
+
+We don’t need the width of the bar, because that will be tied to the width of the main window’s visible area as shown in
The tops of the two windows (
toolbar%!8 = main%!16 - box_height% : REM Visible Area Minimum Y
+toolbar%!16 = main%!16 : REM Visible Area Maximum Y
+
+The horizontal positioning of the toolbar is even easier: it aligns completely with the visible area of the main window, so
toolbar%!4 = main%!4 : REM Visible Area Minimum X
+toolbar%!12 = main%!12 : REM Visible Area Maximum X
+
+This is why the horizontal extent of the pane has to match that of the main window: if the main window is fully extended, the pane has to be able to follow suit.
+Just as with our previous example, the two panes must appear directly in front of the main window in the window stack. The exact order doesn’t matter to the Wimp, so we will choose to put the toolbar in front of the main window, and the toolbox in front of the toolbar.
+ +As before, we start at the top of the pile of panes and work down towards the main window – so the first thing to open is the toolbox.
+ +IF (main%!28 <> ToolBarWindow%) OR (toolbar%!28 <> ToolBoxWindow%) THEN toolbox%!28 = main%!28
+
+SYS "Wimp_OpenWindow",,toolbox%
+
+We still check to see if the windows are already in their correct places in the stack, but with two panes to consider we must now check both whether the main window is behind the toolbar, and whether the toolbar is behind the toolbox. If either isn’t in the correct place, we will need to re-position the toolbox, as the top window of the pile, and then work down from that.
+ +With the toolbox open, we can open the toolbar behind it...
+ +toolbar%!28 = ToolBoxWindow%
+
+SYS "Wimp_OpenWindow",,toolbar%
+
+...and then, at the bottom of our little pile of windows, comes the main window itself.
+ +main%!28 = ToolBarWindow%
+
+SYS "Wimp_OpenWindow",,main%
+
+Putting all of the new code together with the old, PROChandle_pane_windows() now looks as shown in
DEF PROChandle_pane_windows(main%)
+LOCAL toolbox%, toolbar%, box_width%, box_height%, bar_height%
+
+REM Get the Window State block for the toolbox pane, using some of the
+REM spare space above the data for the state of the main window.
+
+toolbox% = main% + 64
+
+!toolbox% = ToolBoxWindow%
+SYS "Wimp_GetWindowState",,toolbox%
+
+REM Get the Window State block for the toolbar pane, using more of the
+REM spare space above the data for the state of the main window.
+
+toolbar% = main% + 128
+
+!toolbar% = ToolBarWindow%
+SYS "Wimp_GetWindowState",,toolbar%
+
+REM Find the height of the toolbar pane's visible area.
+
+bar_height% = toolbar%!16 - toolbar%!8 : REM Visible Area Maximum Y - Minimum Y
+
+REM Move the toolbar pane so that it's in the correct X and Y position
+REM relative to where the main window is to go.
+
+toolbar%!4 = main%!4 : REM Visible Area Minimum X
+toolbar%!8 = main%!16 - bar_height% : REM Visible Area Minimum Y
+toolbar%!12 = main%!12 : REM Visible Area Maximum X
+toolbar%!16 = main%!16 : REM Visible Area Maximum Y
+
+REM Find the width and height of the toolbox pane's visible area.
+
+box_width%% = toolbox%!12 - toolbox%!4 : REM Visible Area Maximum X - Minimum X
+box_height% = toolbox%!16 - toolbox%!8 : REM Visible Area Maximum Y - Minimum Y
+
+REM Move the toolbox pane so that it's in the correct X and Y position
+REM relative to where the main window is to go.
+
+CASE TRUE OF
+WHEN main%!4 > box_width%%
+ toolbox%!4 = main%!4 - box_width%% : REM Visible Area Minimum X
+ toolbox%!12 = main%!4 : REM Visible Area Maximum X
+WHEN main%!4 > 0
+ toolbox%!4 = 0 : REM Visible Area Minimum X
+ toolbox%!12 = box_width%% : REM Visible Area Maximum X
+OTHERWISE
+ toolbox%!4 = main%!4 : REM Visible Area Minimum X
+ toolbox%!12 = main%!4 + box_width%% : REM Visible Area Maximum X
+ENDCASE
+
+toolbox%!8 = main%!16 - box_height% : REM Visible Area Minimum Y
+toolbox%!16 = main%!16 : REM Visible Area Maximum Y
+
+REM Unless the main window is to be opened behind the toolbar pane, and the
+REM toolbar pane is already behind the toolbox pane, meaning that all three
+REM windows must already be in the correct place in the stack, set the toolbox's
+REM Open Behind so that it appears in the stack where the main window is to go.
+
+IF (main%!28 <> ToolBarWindow%) OR (toolbar%!28 <> ToolBoxWindow%) THEN toolbox%!28 = main%!28
+
+SYS "Wimp_OpenWindow",,toolbox%
+
+REM Set the toolbar window's Open Behind so that it opens behind the toolbox.
+
+toolbar%!28 = ToolBoxWindow%
+
+SYS "Wimp_OpenWindow",,toolbar%
+
+REM Set the main window's Open Behind so that it opens behind the toolbar.
+
+main%!28 = ToolBarWindow%
+
+SYS "Wimp_OpenWindow",,main%
+ENDPROC
+
+Running the upplication application should reveal a new toolbar attached to the top of the main window, as shown in
The full code can be found in