------------------------ AmigaOS 4 project ---------------------------

layout.gadget 50.1 (16.2.2003)

- initial release for OS4.

- slightly enhanced the stack swapping code.

- removing a gadget from a layout should no longer crash the machine
  when the user still plays with the gadget.

-------------------------- AmigaOS 3.2 project -----------------------

layout.gadget 50.2 (18.8.2019)

- Notice that v50.2 reflects only a transitional status between the
  OS4 and 3.2 projects.

- fixed race condition when opening/closing.

- now runs on 68000/68010.

layout.gadget 47.1 (1.9.2019):

- recompiled with data=far and utillib to improve
  the code generation.

layout.gadget 47.2 (2.9.2019):

- Fixed a compiler problem, __SAVEDS was used
  with DATA=FARONLY, which confused the compiler
  a lot.

layout.gadget 47.3 (8.9.2019):

- shortened the code by adding initialization
  code for the BSS segment.

layout.gadget 47.5 (29.9.2019):

- The creation of a layout gadget now also swaps
  the stack as this already costs up to 4600 bytes
  as experiments have shown.

- OM_SET was another stack-thieve, in particular if
  the layout was deeply nested. This function is now
  also using stack swapping.

layout.gadget 47.6 (21.12.2019):

- Experimental removal of the Request() type of GUI
  locking performed by the layout.gadget in Add/Remove_CHILD
  methods. This may cause deadlocks in combination with
  MagicMenu and is not directly needed if the method is called
  through SetGadgetAttrs(), which holds a lock anyhow. Direct
  calling of OM_SET is discouraged anyhow.

layout.gadget 47.7 (21.2.2020):

- Fixed a bug in page.gadget which prevented the private
  LAYOUT_ACTIVATEOBJECT method from working correctly. It was
  always returning 1 whether the object being searched for was
  found or not.

- ActivateLayoutGadget() was not setting GACT_ACTIVEGADGET in its
  target gadget's Activation flags. Now fixed.

layout.gadget 47.8 (24.2.2020):

- In GM_DOMAIN, the width of the widest label is no longer added
  to the minimum width of members having no label, when computing
  the minimum width of a vertical group. That could make certain
  layouts much wider than actually necessary.

layout.gadget 47.9 (26.2.2020):

- Fixed: in fallback mode, labels were drawn in the screen font
  and with insufficient size, overlapping other elements.

layout.gadget 47.10 (26.2.2020):

- Reworked the layout algorithm for weighted groups. Resizable
  elements could snap to their minimum size during the initial
  weight distribution, even when there would have been sufficient
  room for them to get larger. This should fix bug #1343 (and
  hopefully not introduce new ones).

- Now makes sure all the room available for weighted elements
  in a group is actually used for said elements. Previously, a
  rounding error could leave some pixels unaccounted for which
  would result in uneven spacing between group members.

- GM_LAYOUT no longer calls SetAttrs() on non-BOOPSI objects.

layout.gadget 47.11 (9.3.2020):

- Now tooltips are always shown even when there is an active
  gadget.

layout.gadget 47.12 (14.3.2020):

- Fixed: passed CHILD_MinWidth/Height values could be used even
  when they were not large enough.

layout.gadget 47.13 (17.3.2020):
- Fixed: group labels for LAYOUT_BevelStyle of BVS_NONE were
  still being drawn in some circumstances.

layout.gadget 47.15 (27.3.2020):

- Fixed: layouts were sometimes far too large (e.g. IconEdit 44.19,
  ReqToolsPrefs example in OS3.2 NDK, etc.) (in V47.11-47.14
  only).

layout.gadget 47.16 (31.3.2020):

- Fixed: child label sizes were not always calculated correctly.

- LAYOUT_ShrinkWrap no longer leaves empty space at the right/
  bottom of the layout group.

layout.gadget 47.17 (9.4.2020):

- Fixed: spacing was incorrect for BVT_XENTHIN.

layout.gadget 47.18 (13.4.2020):

- Fixed: Backfill was not propagated in all cases.

layout.gadget 47.19 (9.5.2020):

- Changed makefile to work around SAS/C optimizer bugs.

layout.gadget 47.20 (14.5.2020):

- Implement GM_HANDLESCROLL code is a simple adaptation of the V52.

layout.gadget 47.21 (18.5.2020):

- Implement PAGE_NoDispose (taken from V53).

- Fixed a deadlock. Actually, the same as fixed in 47.6 only this time
  in the page gadget

layout.gadget 47.22 (08.6.2020):

- use the new GA_Hidden and GA_ParentHidden to make sure hidden
  gadgets have the chance to not render themselves (it requires
  cooperation from every single gadget, but it is a start)

layout.gadget 47.23 (10.6.2020):

- Fixed: LABEL_Justification in a CHILD_Label had no effect.

layout.gadget 47.24 (27.6.2020):
- Implemented the new GM_QUERYHOVERED method.

layout.gadget 47.25 (06.9.2020):
- LAYOUT_Left/Top/Right/BottomSpacing tags were always ignored, now
  fixed

- LAYOUT_InnerSpacing was ignored, too. Now working for non-beveled
  root layouts.

- Added new LIDF-flags to detect usage of LAYOUT_Spacing-tags.

layout.gadget 47.26 (08.9.2020):

- Implement support for old style tooltips

layout.gadget 47.27 (12.10.2020):

- Fix backfill bug introduced in v47.18 - this scaled back version hopefully
  will fix the bug, and also keep the old bug fixed, too

layout.gadget 47.28 (10.1.2021):

- Now sets the appropriate default alignment of CHILD_Label objects
  via the new private REACTION_Justification tag, depending on the
  value of LAYOUT_LabelColumn (this ensures that labels on the left
  side of members are right-justified, and vice versa).
  Applications can override this default with LABEL_Justification.

layout.gadget 47.29 (11.1.2021):

- Group member labels were being placed too low by one pixel, which
  made their text vertically misaligned with respect to the text of
  their associated gadget; now fixed.

layout.gadget 47.30 (14.1.2021):

- Fixed a stupid bug I introduced in version 47.28: an unterminated
  tag list was making label.image throw hits all over the place.

layout.gadget 47.31 (14.2.2021):

- Pointer ROWRESIZE or COLUMNRESIZE when hovering the weight bars

layout.gadget 47.32 (28.2.2021):

- Fix tab traversal in layouts within layouts

------------------------ AmigaOS 3.2.1 update ------------------------

layout.gadget 47.33 (31.7.2021):

- Ensure we emit WMHI_HelpHit whenever it changes

layout.gadget 47.34 (11.8.2021):

- Any space left unassigned (due to rounding) after the layout of a
  group is now evenly distributed among all of its weighted members,
  rather than being added entirely to the size of the last one. The
  previous method would yield unpleasing results for groups having
  a large number of equally weighted members (bug #2165).

----------------------- AmigaOS 3.2.2 project ------------------------

layout.gadget 47.35 (4.12.2021)

- Some more shuffling of the deckchairs in the probably futile attempt
  to improve the readability of the code. Let's see if this even makes
  a difference :-/

- Cleaned out most of the header files included, they were not needed,
  especially not dos.library and diskfont.library. What's the point of
  including just about everything (excluding the kitchen sink) and
  not using it?

- Dropped the code which tried to save space by zeroing the BSS
  chunk. Which saved 32 bytes.

- Enabled the code optimization. At some point this had been
  disabled. It saved some 2000 bytes of code.

- Enabled generation of utility.library integer math instead of
  reusing the SAS/C runtime library code for that. This had
  been disabled, too, at some point.

- Switched from code=far to code=near which made sense because
  layout.gadget is much smaller than 64 KBytes. It also saves
  about 2000 bytes of code.

- Dropped the inline optimization complexity level of 16. There
  were just two functions which even reached complexity 4. This
  actually saved space (about 300 bytes).

- Cleaned out all the files which layout.gadget does not need
  to build.

- Built proper prototype header files and identified the functions
  which need to be local (i.e. "static"). That resulted in shorter
  code and also proper prototypes, too.

- Squeezed the LayoutLimits() code so that it does not repeat the
  same code four times in a row and instead calls the same
  function four times in a row.

- Made all the local functions which use varargs parameters use
  <stdarg.h> macros instead of making assumptions about how
  the local stack looks like. That's so 1988...

- Simplified the layout.gadget/OM_GET method, saving 200 bytes
  along the way.

- Found an actual memory leak in the layout.gadget/GM_RENDER
  method which could be triggered for smart refresh windows.
  Fixed it, too.

- The memory allocation and free functions are now a bit
  more paranoid than they used to be. They might just save
  you trouble in the future.

- The task stack swapping code in SwapAndCallHookFunction()
  was relying upon exec.library/StackSwap not to change
  register A0, which is guaranteed. However, the function
  being called between the StackSwap() function calls can
  change registers A0 and A1 as needed, which would be a
  bad thing. This is why SwapAndCallHookFunction() now
  passes the StackSwapStruct in register A2 which should
  avoid that little problem...

- Now pays attention to the page.gadget class still being
  in use and will not attempt to free layout.gadget unless
  page.gadget is no longer in use. This also covers the
  strange case of the library getting reopened before it
  had a chance to get expunged. Setup and cleanup of the
  stack memory and the memory pool has moved into the
  init/expunge functions. The expunge code now also tries
  to shut down the classes if the library open count is 0.

- Dropped the unused instance variables.

- keyactive_method() can no longer stumble into a NULL pointer reference.

- Rewrote findobject_method() for better readability.

- init_propagate_tags(), finish_propagate_tags() and add_propagate_tag()
  are now used by the page.gadget class as well.


layout.gadget 47.36 (6.1.2022)

- Renamed the instance variable "mn_NoDispose" to "mn_BlockDispose". The
  tag which corresponds to it still uses the old name, of course.

- Added padding to the instance data structure members for the benefit
  of 68030 systems all around ;-)

- Added local functions to layout.c which perform testing and conversion
  of 'struct IBox' and 'struct Rectangle', replacing code which served the
  same purpose and was copied over and over and over again in both layout.c
  and page.c. Bonus: the original conversion code for IBox<->Rectangle was
  off by one for all dimensions, so this is a bug fix, too.

- Added small optimizations for code which tested Gadget.Flags values and
  did benefit in a small way by first copying the flags value into a local
  variable.

- Added a variant of the Alloc() function called AllocClear() which uses
  memset(address, 0, size) on the allocated memory. This simplifies data
  structure initialization and renders it more consistent.

- Replaced "if (foo != FALSE)" and "if (foo == TRUE)" with "if (foo)", for
  consistency, simplicity and to avoid side effects (there's just a single
  FALSE but considerably more TRUE values after all).

- All BOOPSI messages built on the stack are now set to zero via memset()
  to provide consistent defaults. That initialization happens at the earliest
  possible moment so as to avoid creating a situation such as in LayoutLimits()
  where the data structure initialization began before the memset() could
  be used :-(

- The new_method() functions in both the layout.gadget and page.gadget code
  directly call the respective set_method() functions to process the TagItem
  parameter list for initialization. Which is sort of OK but required that the
  respective set_method() function had to change behaviour in order to
  indicate that the processing was successful. This made the code more complex,
  and, its context-dependent behaviour being undocumented, rendered it hard to
  use even for the OM_SET/OM_UPDATE case. I changed the set_method() implementations
  to work more like they should do in a normal Gadget class and indicate success or
  failure (as needed by the set_method() code) through an additional function
  parameter.

- TagItem processing no longer truncates the ti_Data value to a 16 bit value or
  even a 1 bit value (for bit fields). Truncation could have side effects, turning
  a non-zero ti_Value into a 0. The new code now tests for TagItem->ti_Data != 0 and
  uses that instead.

- All GetRPAttrs()/GetAttr() calls now preset the output parameter's value with 0
  just to make sure that the result will not be a random value in case GetAttr() does
  not do what it's supposed to. Note that the success/failure of GetAttr() calls
  is consistently ignored in the ReAction classes :-(

- Unfolded code such as this, which made use of the "," operator which has its
  uses in "for ()" statements but not in well-behaved other code:

      if (extra)
          tracking++, extra--;

  This became:

      if (extra)
      {
          tracking++;
          extra--;
      }

- Simplified DrawObjectBox() which repeated the same code over and over again.

- FillBackgroundClipped() in both layout.gadget and page.gadget modified the clipping
  region rectangle data prior to using their boundaries in RectFill()/EraseRect(). This
  meant that the operation could not be repeated and there was no good apparent reason for
  trashing the data. Simplified by adding the offset to the RectFill()/EraseRect()
  parameters instead.

- render_method() and cliprect_method() now do their best to check if
  region operations failed and attempts to back out of using the inconsistent region
  data to optimize rendering. This is hard to do, though :-/

- Mouse coordinates in handlescroll_method(), hittest_method(), helptest_method(),
  now use signed mouse coordinate variables instead of unsigned ones. They are
  signed in the source data structure, which is an InputEvent.

- The page.gadget implementation repeated the same code sequence over and over
  again which invoked DoMethod() on all members of the same page. This is now
  a single common function which is called as needed.


layout.gadget 47.37 (9.1.2022)

- layout.gadget/set_method() breaks its TagItem processing into three sections:
  tag->ti_Tag > CHILD_Dummy, tag->ti_Tag > LAYOUT_Dummy and everything else. I
  had moved LAYOUT_PageBackFill out of its "domain" which had the effect of
  having no longer any effect :-(  I moved it back where it came from.

  The three switch..case sections ought to be merged into a single gigantic
  combined lump of code, just so that the compiler can detect and report duplicate
  use of TagIDs. Who knows, we might have them in there already :-(

- layout.gadget/domain_method() is a bit paranoid about the font being NULL it's
  later likely going to use. This still holds, but it doesn't stop the entire
  layout operation now.

- page.gadget/domain_method() did not properly fill in the width/height at
  all. Ouch :-(


layout.gadget 47.38 (10.1.2022)

- Added local debugging and progress output which is now part of
  the default build. To disable, change the "assert.h" file so that
  its DEBUG symbol is no longer defined.
  To enable the debug output, use "setenv layout.gadget/debug 1"
  (or use a higher number) before you use layout.gadget for the
  first time.

- Fixed a preposterous bug in the BoundsToBox() function. "Too many
  parentheses, Mozart".


layout.gadget 47.39 (10.1.2022)

- Further rework to bring the layout.gadget behaviour closer to the
  V47.34 release. Surprisingly, as close as the code is now to the
  V47.34 release the behaviour can still be different :-(


layout.gadget 47.40 (11.1.2022)

- The global attribute change propagation function was inadvertently making
  assumptions about the contents and layout of the layout/page member data
  structure which were essentially undocumented unless you counted the
  #ifdef..#endif section which suggested that there could have been something
  in common.

  The layout.gadget and page.gadget now have separate propagation functions
  and their respective instance and list member data structures are now found
  in different header files instead of "classdata.h". Shared knowledge was
  assumed but not backed up by documentation, which is the point behind
  splitting it up.

  Thanks go to Camilla Boemann who found the problem!

- Changed how the shared memory pool is initialized. It no longer uses
  MEMF_CLEAR which is not useful because each puddle will be allocated
  using this flag and then individual allocations within these puddles
  get cleared again. This makes the MEMF_CLEAR attribute redundant,
  especially because we have separate allocation functions for memory
  to be cleared, and memory which is not assumed to be cleared.


layout.gadget 47.41 (11.1.2022)

- Moved the RastPort which was allocated separately for each
  layout.gadget instance in the instance data itself. This
  in turn allowed for the memory allocation code to be simplified
  further. The memory pool created no longer uses MEMF_CLEAR because
  it does not have to.


layout.gadget 47.42 (20.2.2022)

- Fix crash when removing the active page from page.gadget. It was
  a small mistake from the refactoring in version 47.35


layout.gadget 47.43 (12.4.2022)

- Beginning with 47.35, the default bevel sizes and distance between
  individual group member objects were left uninitialized. This was
  due to a missing call to the function which sets them to default
  values at the time the layout.gadget class is created.

  Thanks go to Mikhail Malyshev for finally confirming where the
  problem originated from!

- In the hope that it helps, the initialization of the bevel
  sizes and the distance values is now wrapped into Forbid()/Permit()
  so as to update all the parameters in a single step. This may
  lessen the risk of the layout code picking up one set of sizes in
  one iteration of the process and another set in the next iteration.

- Retrieving the drawing pen numbers for certain rendering operations
  is now done, if possible, only once instead of for each iteration
  of a loop over the objects to be highlighted.

- Added a bit more code documentation.


layout.gadget 47.44 (20.4.2022)

- No point in processing more than one input even as handleinput is
  only ever given one at a time


layout.gadget 47.45 (27.9.2022)

- Fix bug that would not allow Min values to be reset


layout.gadget 47.46 (3.10.2022)

- Lucky number 13!

- Added validation code to assert.lib which checks if addition,
  multiplication or mere assignment of signed/unsigned variable values
  will yield numbers which are out of range for the respective
  8-, 16- or 32-bit domain. This also includes tests which check if
  the addition or multiplication overflows. These tests are new and
  likely themselves need testing! :-/

  These tests are disabled by default in "assert.h" and uncommenting
  the '/*#define DEBUG*/' definition will enable them.

- The "page.c" code still needs looking over, with the new tests
  to be implemented which are currently limited to "layout.c" alone.

- Changed the build instructions in the GNUmakefile so that the
  layout.gadget class can be built with debugging code. Due to
  the size of the code in the "layout.o" object file it will
  no longer compile unless "code=far" is being used.

- Reworked code in the OM_SET/OM_NEW methods which would store
  numbers in object instance variables which are really boolean
  values. And found one instance variable which was nominally a
  boolean value but turned out to be an integer.

- Fixed a handful of typos in the documentation, including the
  AutoDocs.

- Found a few range checks which tested unsigned integers,
  in case they would contain negative values. Augmented
  the tests by casting them into signed integers for the
  purposes of the tests.

- Any attempt to set GA_TextAttr to NULL is now ignored.

- Changed certain tests for "!= 0" to be "> 0" which make
  better sense in context. For example, if the idea is to
  count down to zero in a loop, you should test for > 0 and
  not for != 0.


layout.gadget 47.47 (5.10.2022)

- Deleted the "startup.h" header file which was not needed by
  anything...

- Added further assertions to assert.c, for the purpose of flagging
  problematic comparisons between signed and unsigned integers.

- Documented the new assertion code and found that some did not
  exactly work as intended. Fixed.

- Changed the ptd_MinWidth and ptd_MinHeight instance variables for
  the page.gadget class to be signed 32-bit integers (used to be
  unsigned) just to see if it reduces the level of accidental
  complexity of this fine class.

- Corrected even more typos.


layout.gadget 47.48 (17.10.2022)

- Expand/collapse glyph should not scale with the node height


layout.gadget 47.49 (25.10.2022)

- Changed the GNUmakefile optimization options to "opttime optimize nooptinlinelocal",
  which used to be "opttime optimize optinlinelocal optdepth=3 optrdepth=3". The
  inlining and depth settings seem to have contributed to stack size issues.

- If the DEBUG option is enabled in "assert.h", the GNUmakefile build options
  have to use "code=far". In all other cases, "code=near" will be the better
  choice because it saves >800 bytes. For ease of debugging, "code=far" currently
  is the default.

- Removed unused #include <..> directives.

- Added (STRPTR) casts to keep the compiler happy when passing string
  constants to functions with function prototypes calling for (CONST_STRPTR).
  Note: The 'const' qualifier is not needed in a cast which thankfully
  improves readability of the cast...

- Added debug information to the stackswap_method() function invocation,
  naming the method (if possible), providing the method ID value and also
  the source code file and line number for the call made. This information
  is only used if the DEBUG option is in effect. Otherwise, NULL parameters
  will be passed to the stackswap_method() function. We need to get rid of
  this as soon as we are able.

- Saved a bit of code by making GM_GOACTIVE and GM_HANDLEINPUT part of the
  same switch case and a fallthrough. Same thing for GM_LAYOUT and
  DTM_PROCLAYOUT, and OM_NOTIFY for the page.gadget code.

- The stack size used by stackswap.c (currently 8192 bytes) is now more
  easily changed because the associated stack size threshold is
  calculated from the stack size rather than being a separate constant.


layout.gadget 47.50 (26.10.2022)

- Moved all the functions out of layout.c into support.c and
  layout_class_init.c, respectively, which were not strictly
  required to reside in layout.c, or which were shared between
  layout.gadget and page.gadget.

  This small change has benefit for code generation of the large
  layout.c file, which produced smaller code and renders it a
  little bit more manageable. Total code size actually shrunk,
  too, in spite of the fact that the same code is now distributed
  over 2-3 files instead of stuck in a single file.

- Replaced the lone structure copy in layout.c with a CopyMem()
  call, thereby saving even more space.

- Another round of cleaning up header files, macros and what counts
  for punctuation and orthography these days.


layout.gadget 47.51 (29.10.2022)

- Rewrote the assert.c code to make it easier to use assert.h for
  the purpose of detecting surprising side effects in multiplication,
  addition, comparison and assignment of scalar values (not necessarily
  constants or expressions, mind you).

  Note that detection now requires all parameters to be initialized
  or the compiler might exercise its rights to optimize away what
  was supposed to be tested because its value is not known.

- The assertion code is now more likely to auto-detect whether parameter
  result values are signed or unsigned, so you won't have to figure it
  out all by yourself (you can always specify it, though).

- Multiplication and addition now perform overflow detection, which means
  that merely truncating the result is not the only problem which can be
  caught early on.

- Otherwise, no functional changes to the gadget code itself, just how
  the assertion/debugging functions are invoked.


layout.gadget 47.52 (30.10.2022)

- The startup.c code as written was unsafe in the library close function.
  The OpenLibraries() function was unsafe to call twice. Fixed.

- Reworked the assert.c code to use "#include <proto/exec.h>" instead of
  compiler-specific header files.

- Added the missing indentation to the assert.c debug output.


layout.gadget 47.53 (29.11.2022)

- Small changes in handleinput_method() to stop walking the object list
  after the active weight bar has been rendered.

- Further small changes to it clearer which ill-named object structure
  members are really pointers and not boolean values.


layout.gadget 47.54 (29.11.2022)

- Removed the walking the list (mentioned above) completely

- Reduced AddChild and AddImage to almost the same code saving 140 bytes

- Introduced a cleanup function when removing children so that 2 weightbars
  can not be next to each other or at the edges.

- Make sure our GACT_RELVERIFY is set when the child has it set


layout.gadget 47.55 (29.1.2023)

- Don't send out LAYOUT_HelpHit unless we are window.calls top layout


layout.gadget 47.56 (11.2.2023)

- Rework the Backfill of several classes. It should now work better. And
  most importantly it fixes a potential crash if you move a gadget from
  one window to another.


layout.gadget 47.57 (6.3.2023)

- Removed accidentally generated memset() call from the swapstack.c code.
  Ouch :-(

----------------------- AmigaOS 3.2.3 project ------------------------

layout.gadget 47.58 (1.2.2024)

- Don't EVER use more space than we have allowed
- Refactor so all sub-gadget activation is done in the same sub function
- That refactor also fixes a tab cycle issue where relverify was lost
- page.gadget - fix missing background when doing a redraw
- Make LAYOUT_ALIGN_BOTTOM work

layout.gadget 47.59 (30.4.2024)

- Fix shortcuts not working

layout.gadget 47.60 (3.5.2024)

- Fixed bad handling of LAYOUT_HorizAlignment and LAYOUT_VertAlignment
  tags.
- Fix LAYOUT_FillPen not having an effect on its own
- Fix label vert alignment when gadgets are centered vertically

layout.gadget 47.61 (9.8.2024)

- Fixed: labels were not being centred in some situations.
