Tuesday, November 8, 2022

Enhancing the Arrow buttons in the Macintosh HyperCard 2.4.1 Home stack

HyperCard 2.4.1 Home stack changes for enhanced left/right arrow buttons

by Brendan Bellina 11/2022


Benefits of these changes

~~~~~~~~~~~~~~~~~~~~


Unenhanced the Home stack allows 5 Home Card cards to be displayed along the bottom. Additional cards can be created via the New Card menu option and accessed via the arrow buttons, but their names will not be displayed along the bottom of the Home card. When enhanced any added cards will scroll along the bottom when the arrow buttons are used to navigate. This encourages spreading QuickLinks across multiple cards rather than crowding them all onto the five standard Home cards.


Unenhanced the left/right arrow buttons in the Home stack cycle through all cards in the stack, not just the Home Card background. When enhanced the buttons advance only through the Home Cards. The User Preference cards remain accessible via the Home menu.


Holding down the option key while clicking on an enhanced left/right arrow button  will execute their original unenhanced logic.


Known issues

~~~~~~~~~~


The enhanced buttons require Home cards to be uniquely named.


When creating new Home Cards, if a name is not specified for the new card then standard behavior is that it is defaulted to "Untitled Card" which can lead to duplicate card names. For this reason if an "Untitled Card" button is scrolled off the screen and then back onto the screen its name will be changed to its unique card id.


When deleting the last Home card some Home menu options will be incorrectly disabled. To reenable them select Preferences from the Home menu and then return to the Home cards. This is a bug in the unmodified Home stack code that is more noticable since the enhanced left/right arrow buttons make adding more Home cards a more reasonable thing to do than crowding all QuickLinks on the five standard Home cards.


The Home Card title buttons are not defined in a button family, so it is possible for multiple of them to be hilited at the same time or none hilited. While this should not happen, if it does then use the arrow buttons to scroll through the cards and the hiliting will be corrected.


Applying these Enhancements

~~~~~~~~~~~~~~~~~~~~~~~


1. Add the following to the "Home Cards" background script":


---

Message Handlers added to this script by B Bellina 11/2022:

openCard, resetToFirstCard


on openCard -- added by B Bellina 11/2022

  -- required for enhanced "left arrow" "right arrow" buttons

  put ((number of bg btn id 169) - 1) into homeCardBtnCnt

  -- Determine which btn to hilite

  get the short name of this card

  put false into foundIt

  repeat with i = 1 to homeCardBtnCnt

    if short name of bg btn i is it then

      put true into foundIt

      exit repeat

    end if

  end repeat

  if foundIt then

    put i into foundCardNum

    repeat with i = 1 to homeCardBtnCnt

      set hilite of bg btn i to (i = foundCardNum)

    end repeat

  else

    -- failed to find so reset to first card (normally Welcome to...)

    resetToFirstCard

  end if

  pass openCard -- so others can use it

end openCard


on resetToFirstCard -- added by B Bellina 11/2022

  -- required for enhanced "left arrow" "right arrow" buttons

  if short name of this card is not short name of cd 1 then go cd 1

  put ((number of bg btn id 169) - 1) into homeCardBtnCnt

  repeat with i = 1 to homeCardBtnCnt

    set name of bg btn i to short name of cd i

    set hilite of bg btn i to false

  end repeat

  set hilite of bg btn 1 to true

end resetToFirstCard

---


2. Replace the mouseUp handler of the "left arrow" button with the following:


on mouseUp

  -- enhanced "left arrow" button logic

  -- by Brendan Bellina 11/2022

  -- also requires openCard and resetToFirstCard handlers in the

  -- background script

  if the optionKey is down then

    -- original logic for the button

    visual effect wipe right

    go prev card

  else -- enhanced logic

    lock screen

    set cursor to watch

    -- how many buttons along the bottom, typically 5

    put ((number of bg btn id 169) - 1) into homeCardBtnCnt

    -- how many home cards (they are cards 1...n)

    put number of cards of this bg into homeCardCnt

    if homeCardBtnCnt = homeCardCnt then

      go to prev card of this bg

      unlock screen with visual effect wipe right

    else -- more cards than buttons

      -- determine which button is hilited

      put 0 into fromCdBtnNum

      put short name of this cd into thisCd

      repeat with i = 1 to homeCardBtnCnt

        if hilite of bg btn i is true or ¬

        short name of bg btn i is thisCd then

          put i into fromCdBtnNum

          exit repeat

        end if

      end repeat

      if fromCdBtnNum = 0 then -- messed up so do default action

        go to prev card of this bg

        unlock screen with visual effect wipe right

        exit mouseUp

      end if

      if fromCdBtnNum is 1 then

        -- scroll all of the buttons except the rightmost to the right

        repeat with i = (homeCardBtnCnt - 1) down to 1

          set name of bg btn (i + 1) to short name of bg btn i

        end repeat

        put number of prev cd of this bg into prevCdNum

        get short name of cd prevCdNum

        if it is empty or it is "Untitled Card" then -- no dups allowed

          put id of cd prevCdNum into it

          set name of cd prevCdNum to it

        end if

        set name of bg btn 1 to short name of cd prevCdNum

        go to prev cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = 1)

        end repeat

        unlock screen with visual effect wipe right

      else

        go to prev cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = fromCdBtnNum - 1)

        end repeat

        unlock screen with visual effect wipe right

      end if

    end if

  end if

end mouseUp


3. Replace the mouseUp handler of the "right arrow" button with the following:


on mouseUp

  -- enhanced "right arrow" button logic

  -- by Brendan Bellina 11/2022

  -- also requires openCard and resetToFirstCard handlers in the

  -- background script

  if the optionKey is down then

    -- original logic for the button

    visual effect wipe left

    go next card

  else -- enhanced logic

    lock screen

    set cursor to watch

    -- how many buttons along the bottom, typically 5

    put ((number of bg btn id 169) - 1) into homeCardBtnCnt

    -- how many home cards (they are cards 1...n)

    put number of cards of this bg into homeCardCnt

    if homeCardBtnCnt = homeCardCnt then

      go to next card of this bg

      unlock screen with visual effect wipe left

    else -- more cards than buttons

      -- determine which button is hilited

      put 0 into fromCdBtnNum

      put short name of this cd into thisCd

      repeat with i = 1 to homeCardBtnCnt

        if hilite of bg btn i is true or ¬

        short name of bg btn i is thisCd then

          put i into fromCdBtnNum

          exit repeat

        end if

      end repeat

      if fromCdBtnNum = 0 then -- messed up so do default action

        go to next card of this bg

        unlock screen with visual effect wipe left

        exit mouseUp

      end if

      if fromCdBtnNum is homeCardBtnCnt then

        -- scroll all of the buttons except the leftmost to the left

        repeat with i = 2 to homeCardBtnCnt

          set name of bg btn (i - 1) to short name of bg btn i

        end repeat

        put number of next cd of this bg into nextCdNum

        get short name of cd nextCdNum

        if it is empty or it is "Untitled Card" then -- no dups allowed

          put id of cd nextCdNum into it

          set name of cd nextCdNum to it

        end if

        set name of bg btn homeCardBtnCnt to short name of cd nextCdNum

        go to next cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = homeCardBtnCnt)

        end repeat

        unlock screen with visual effect wipe left

      else

        go to next cd of this bg

        repeat with i = 1 to homeCardBtnCnt

          set hilite of bg btn i to (i = fromCdBtnNum + 1)

        end repeat

        unlock screen with visual effect wipe left

      end if

    end if

  end if

end mouseUp



Thursday, November 3, 2022

Enabling Function Keys in HyperCard IIGS stacks



The Home Improvement stack by Brendan Bellina released on Script-Central v7n2 includes 20 ways to enhance the HyperCard IIGS Home stack.

One of these includes adding Function Key preference settings to the Home stack. This allows function keys F1-F4 to perform undo, cut, copy, paste, and F5-F15 to be user defined handlers or HyperTalk commands. These mappings can be defined regardless of whether a keyboard with function keys is attached to the IIGS or not.


Because the IIGS keyboard did not have function keys the ability of HyperCard IIGS to respond to function key presses is generally unused. If an Apple Extended Keyboard II is connected to the IIGS then its functions keys F1-F15 can be used and F1-F4 will perform undo, cut, copy, and paste, but without a stack or the Home stack having a functionkey handler the other function keys will serve no function.

When using a IIGS emulator it may not even be possible to send the function keys from the host computer keyboard through to the emulated IIGS, so the mappings preferences will also have no effect and even F1-F4 will not perform the built-in undo, cut, copy, and paste functions.

If you want to use the function key mappings preferences on a real IIGS that does not have an Apple Extended Keyboard II, or on an emulated IIGS with an emulator that eats the function key presses, then you have to have another way to indicate to HyperCard that a function key has been pressed.

Enter the Fn Key menu.

The Fn Key menu is a menu that can be added to HyperCard IIGS that can be used within any stack to send a function key signal to HyperCard as if a function key had been pressed.

Here are the steps to enable this menu.

1. Make a copy of your Home stack for safe keeping just in case you mess this up and need to revert.

2. You may want to follow the instructions in the Home Improvement stack to install the HC Extras menu. This menu adds significant functionality to HCGS and adds the addMenu and deleteMenu commands to the Home stack that are also required for the Fn Key menu.

3. If you choose not to use HC Extras then you will need to install the AddMenu XFCN and DeleteMenu XCMD from Apple's Scripter's Tools stack into your Home stack. Since you cannot install these into the active Home stack you will need to duplicate your Home stack, install them into the duplicate, and then rename or delete your original Home stack, and finally rename the duplicate to Home.

4. Make the following changes to your Home stack script:

4.1. In the startUp handler AND in the resume handler, after the line getHomeInfo add a new line
DrawHCFkeyMenu

If you have installed HCExtras then put the new line after the line
DrawHCExtrasMenu

4.2. In the quit handler AND in the suspend handler, after the line setHomeInfo add a new line

UnDrawHCFKeyMenu

4.3. Add the following two handlers: DrawHCFKeyMenu and UnDrawHCFKeyMenu

   on DrawHCFKeyMenu -- FKey Menu by BTB 10/31/2022

  global HCFKeyMenu

  if HCFKeyMenu is not empty then

    deleteMenu HCFKeyMenu

    put empty into HCFKeyMenu

  end if

  put return into r

  put empty into FKeyList

  repeat with i = 1 to 15

    put "F" & i after FKeyList

    if i < 5 then put space & item i of "Undo,Cut,Copy,Paste" after FKeyList

    put r after FKeyList

  end repeat

  put addMenu(" Fn Key  ", FKeyList & "-" &r ¬

  & "About the Fn Keys menu..." &r ¬

  & "Refresh the Fn Keys menu...") ¬

  into HCFKeyMenu

  show menubar

end DrawHCFKeyMenu


on UnDrawHCFKeyMenu

  global HCFKeyMenu

  deleteMenu HCFKeyMenu

  put empty into HCFKeyMenu

  show menubar

end UnDrawHCFKeyMenu

4.4. Add the following code to your doMenu handler. Note that these should come before the final "else pass doMenu" in the handler.  If there is no doMenu handler in your Home script then create one with "on doMenu whichItem" and "end doMenu"

  else if whichItem is "About the Fn Keys menu..." then
    answer "           *  *  *     FN KEYS  M E N U ™   *  *  *" & return &¬
    return & "Author:   B. Bellina                 Vsn: 1.0" &¬
    return & return &¬
    "Send function keys without an extended keyboard"
    
  else if whichItem is "Refresh the Fn Keys menu..." then
    UnDrawHCFKeyMenu
    DrawHCFKeyMenu
    
  else if "*" & word 1 of whichItem & "*" is in ¬
  "*F1*F2*F3*F4*F5*F6*F7*F8*F9*F10*F11*F12*F13*F14*F15*" then
    delete char 1 of whichItem
    functionKey (word 1 of whichItem)

5. After these changes then you restart HCGS you should see a new menu "Fn Keys" that you can use to send the F1-F15 keys to HyperCard IIGS.