realbasic-nug
[Top] [All Lists]

Problem with Carbon Declare Library

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Problem with Carbon Declare Library
From: Harrie Westphal <harriew@frontiernet.net>
Date: Tue, 28 Jul 2009 15:33:46 -0500
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Since installing RB2009R3 I have been going through every bit of code on my machine checking for EditFields and converting to TextFields and TextAreas. So far I have only found one program that must be kept with EditFIelds because of writing the styled text to disk. All others, to date, have worked fine after the proper conversion.

When I got to the Carbon Declare Library program I encountered a problem with the dynamic menu portion of the project and this has nothing to do with the conversion of the one EditField that was used in the project.

The method involved is the SetupDynamicMenu method. This is where three entries at the top of the File menu all have the same shortcut key with different modifier keys. Supposedly, if this works, when the program runs these three items will appear as one line in the menu and the text of that line will change depending on the modifier keys depressed along with the 1 key. (Originally the key was D but I changed it to 2 to see if that made any difference. It didn't and it is still set as 1). Here is the pertinent code in the project. The only thing I have changed from the original is using 1, instead of D for the three menuitems in the File menu.

MenuBar1 has menus in the folllowing ordfer:

  Apple Application File Edit

Under the File menu are the entries

  Dynamic Menu 1  Cmd-1        (Name FileDynamicMenu1 not autoenabled)
  Dynamic Menu 2  Cmd-Shift-1  (Name FileDynamicMenu2 not autoenabled)
  Dynamic Menu 3  Cmd-Option-1 <Name FileDynamicMenu3 not autoenabled)
  Separator
  Quit  Cmd-Q  (Name FileQuit  Autoenabled)

In the App EnableMenuItems event handler is the code:

  FileDynamicMenu1.enable
  // FileDynamicMenu2.enable
  FileDynamicMenu3.enable

Final result doesn't matter if second line is commented out or not.

In the Apps NewDocument method is the code:
  SetupDynamicMenu 2,1,3

The two should be referring to the File menu, the third menu in the menubar going left to right. The 1,3 should be referring to the first three entries in the File menu.

In the CarbonDeclares module is the method being called above:

Sub SetupDynamicMenu(MenuIndex as integer, ItemIndex as Integer, ItemCount as integer)
  // Added 12/18/2002 by Jarvis Badgley

// This method allows for creation of dynamic menu items, meaning that while the menu is open you can press // a modifier key and the menu changes to reflect it. To set this up, all items must be grouped together // in the menu editor. They must also have the same keyboard shortcut, but with different modifier keys.

// MenuIndex -- The 0 based index location of the menu on the menubar. The apple menu is item 0, Application
  //              menu is 1, etc... Submenus count in this
// ItemIndex -- The 1 based index location of the first item in the group on the menu. In REALbasic's file menu // for instance, the New item is 1, Open is 2, Close is 3, etc.
  // ItemCount -- How manu items there are in the group.

  #if TargetMacOS
    #if targetcarbon then
      Dim OSStatus, menu, i As Integer
      Dim first As Boolean

      const kMenuItemAttrDynamic = 8
      const kMenuItemAttrNotPreviousAlternate = 16

Declare Function GetMenuHandle Lib kCarbonLib (menuID As Short) As Integer Declare Function ChangeMenuItemAttributes Lib kCarbonLib (menu As Short, item As Short, setAttrs As Integer, clearAttrs As Integer) As Integer

      menu = GetMenuHandle(MenuIndex)
      If menu <> 0 Then
        For i=ItemIndex To ItemIndex+ItemCount-1
          If NOT first Then
// kMenuItemAttrNotPreviousAlternate keeps dynamic groups
from mixing
            // when they shouldn't
OSStatus = ChangeMenuItemAttributes(menu, i, BitwiseOr(kMenuItemAttrDynamic, kMenuItemAttrNotPreviousAlternate), 0)
            first = True
          Else
OSStatus = ChangeMenuItemAttributes(menu, i, kMenuItemAttrDynamic, 0)
          End If
          If OSStatus <> 0 Then
            Beep
***** MsgBox "SetupDynamicMenu Error: Could not initialize menu item "+Str(i)
          End

        Next
      Else
        Beep
        MsgBox "SetupDynamicMenu Error: Could not find specified menu"
      End If

    #endif
  #endif

End Sub

Now, according to the comment in the Carbon Declare method above I am assuming that when executed the three options in the first three options in the File menu should appear as one item that will switch between the three names depending on which sequence of keys is held down: Cmd-1, Cmd-Shift-1 or Cmd-Option-1. Instead, when it runs the msgbox of the line with the ***** in front of it is executed three times, once for each of the three menuitems referenced by the call to the method from the Apps NewDocument event during program launch.

The messages are:

SetupDynamicMenu error: Could not initialize the menu item 1
SetupDynamicMenu error: Could not initialize the menu item 2
SetupDynamicMenu error: Could not initialize the menu item 3

When following the execution in the debugger the calls to ChangeMenuItemAttributes all give a return code of: - 5623. I tried referring to menu 2 and 4 and neither of those worked. I am lost on this one.

I would sure appreciate it if someone knowlegable in all this Carbon Declase stuff could help me get this working.


=== A Mac addict in Tennessee ===


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>