diff --git a/Chapters/ch08-moving-the-furniture.xml b/Chapters/ch08-moving-the-furniture.xml index 4f96cd5..43ecf9a 100644 --- a/Chapters/ch08-moving-the-furniture.xml +++ b/Chapters/ch08-moving-the-furniture.xml @@ -55,7 +55,7 @@

NetSurf, on the other hand, uses the easy option and takes advantage of what the Nested Wimp calls Furniture Windows. When writing new software which isn’t targetted at the ‘retro’ scene, the simplicity of the Nested Wimp for this task almost certainly makes it the way to go.

-
+
A full-width toolbar

To show how this works, we will take the responsive toolbar that we created in the previous chapter and make it span the full width of the window – just like NetSurf’s URL bar in .

diff --git a/Chapters/ch09-an-embedded-toolbox.xml b/Chapters/ch09-an-embedded-toolbox.xml index ec421c8..44f5616 100644 --- a/Chapters/ch09-an-embedded-toolbox.xml +++ b/Chapters/ch09-an-embedded-toolbox.xml @@ -68,12 +68,57 @@ -

With these changes in place, we can now close the templates and move on to updating the program itself.

+

With these changes in place, we can now close the templates and move on to updating the program itself. We’ll need to update PROCinitialise in order to load the new “Embedded” template instead of the “Toolbar” that we had before – this is simply a change to the name passed to PROCtemplate_load().

+ +PROCtemplate_load("Embedded", b%, buffer_size%, -1) +SYS "Wimp_CreateWindow",,b% TO ToolBoxWindow% + +

We can also simplify the Open_Window_Request event handler in PROCpoll again. We will no longer need to make any adjustments to the contents of the toolbox, so we can delete PROCopen_window_request() completely and just call Wimp_OpenWindow in the CASE statement once again.

+ +CASE reason% OF + WHEN 2 : SYS "Wimp_OpenWindow",,b% + WHEN 3 : SYS "Wimp_CloseWindow",,b% + WHEN 6 : PROCmouse_click(b%) + WHEN 9 : PROCmenu_selection(b%) + WHEN 17, 18 : IF b%!16 = 0 THEN Quit% = TRUE +ENDCASE
Positioning the furniture +

The remaining changes that we need to make reside in PROCopen_main_window, and concern the positioning of the embedded toolbox. As we saw in the previous chapter, making child windows behave as part of their parent’s furniture is simply a case of positioning them appropriately. To embed our toolbox into the horizontal scroll bar, we place it over the bar and leave the Nested Wimp to do the rest.

+ +

The process for laying the toolbox out is very similar to that used in the previous chapter, although we have changed the name of the toolbar% variable to toolbox%, so as to reflect the different type of pane that we’re positioning.

+ +main% = q% +toolbox% = q% + 100 +main_outline% = q% + 200 + +

We will also amend the call to Wimp_GetWindowInfo in the same way.

+ +!toolbox% = ToolBoxWindow% +SYS "Wimp_GetWindowInfo",,toolbox% OR %1 + +

The dimensions of the new toolbox will depend on the height (or thickness) of the horizontal scroll bar that we’re about to embed it in to. This depends on the window tool sprites in use on the system, but we can calculate it as the difference between the Y0 coordinate of the parent window’s visible area and the Y0 coordinate of its outline. Simplistically, this could be calculated as follows:

+ +box_height% = main%!8 - main_outline%!8 + +

However, there’s a problem. Both of the Y0 coordinates that we are using are inclusive values, whilst the height of the toolbox will need to be given in terms of an inclusive Y0 and an exclusive Y1. This means that we must subtract a pixel from the height, but as we saw when we created our simple application, the number of OS Units which represents a pixel will depend on the current screen mode. As a result, we need to read this value from the OS in the form of the vertical eigenfactor.

+ +SYS "OS_ReadModeVariable", -1, 5 TO ,,eigenfactor% + +

Armed with this information, we can then calculate the height of the toolbox.

+ +box_height% = main%!8 - main_outline%!8 - 2 * (2 ^ eigenfactor%) : REM Visible Area Y0 - Outline Y0 + +

As we currently have nothing to go into the toolbox, the width is largely immaterial and so for now we will set it to 200 OS Units.

+ +box_width% = 200 + + + +
diff --git a/Images/Chapter09/embed-tool-anchor.png b/Images/Chapter09/embed-tool-anchor.png new file mode 100644 index 0000000..ec8c6b5 Binary files /dev/null and b/Images/Chapter09/embed-tool-anchor.png differ