Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / intuition / setmenustrip.c
blobb04c0edf09885f168bb4844572ae013306d8dff1
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include "intuition_intern.h"
8 #include "menus.h"
10 void CalculateDims(struct Window *win, struct Menu *menu);
11 void Characterize(struct Menu *menu);
13 /*****************************************************************************
15 NAME */
16 #include <proto/intuition.h>
17 #include <proto/exec.h>
18 #include <intuition/intuition.h>
20 AROS_LH2(BOOL, SetMenuStrip,
22 /* SYNOPSIS */
23 AROS_LHA(struct Window *, window, A0),
24 AROS_LHA(struct Menu *, menu , A1),
26 /* LOCATION */
27 struct IntuitionBase *, IntuitionBase, 44, Intuition)
29 /* FUNCTION
30 This function adds a MenuStrip to the Window, which can be invoked
31 by the user after this call by pressing the right mouse button.
32 Menus with no MenuItems will not be attached.
34 INPUTS
35 window - The window to add the MenuStrip to
36 menu - The menu to be added to the window above.
38 RESULT
39 TRUE if all menus have at least one menuitem.
41 NOTES
42 This function calculates internal values and is therfore the
43 official way to add a new MenuStrip to Window.
44 Always do a ClearMenuStrip() before closing the Window or adding
45 another MenuStrip to the Window.
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 ResetMenuStrip(), ClearMenuStrip()
54 INTERNALS
56 HISTORY
57 11.06.99 SDuvan implemented function
59 *****************************************************************************/
61 AROS_LIBFUNC_INIT
63 SANITY_CHECKR(window,FALSE)
65 #define HASSUBITEM 0x8000
67 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->MenuLock);
69 /* If a menu is active for this task, we must wait until the
70 user is done. We check the task rather than the window as
71 semaphores is owned by tasks... */
72 /* struct Task *me = FindTask(NULL); */
74 /* This must be before CalculateDims(). */
75 Characterize(menu);
77 /* When entering here, this menustrip is NOT displayed as the user has
78 removed it from the window using ClearMenuStrip() if it was ever
79 attached to a window. */
80 CalculateDims(window, menu);
82 #if 0 /* stegerg: ??? */
85 if(me == GPB(IntuiBase)->ib_ActiveMenuTask)
87 ObtainSemaphore(&GPB(IntuiBase)->ib_MenuWaitLock);
89 AddTail((struct Node *)me, &GPB(IntuiBase)->ib_MenuWaitList);
91 ReleaseSemaphore(&GPB(IntuiBase)->ib_MenuWaitLock);
93 Wait(SIGF_INTUITION);
96 #endif
98 window->MenuStrip = menu;
100 #if 0 /* stegerg: ??? */
101 /* Note that we have to do a similar test in the input handler
102 as well. */
104 /* If we were just one of the tasks in the list... */
106 /* if(me != GPB(IntuitionBase)->ib_ActiveMenuTask)
108 struct Task *sleeper;
110 ObtainSemaphore(&GPB(IntuitionBase)->ib_MenuWaitLock);
111 sleeper = RemHead(&GPB(IntuitionBase)->ib_MenuWaitList);
112 ReleaseSemaphore(&GPB(IntuitionBase)->ib_MenuWaitLock);
114 if(sleeper)
115 Signal(sleeper, SIGF_INTUITION);
118 #endif
120 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->MenuLock);
122 return TRUE;
124 AROS_LIBFUNC_EXIT
125 } /* SetMenuStrip */
127 void CalculateDims(struct Window *win, struct Menu *menu)
129 struct MenuItem *item;
131 while(menu != NULL)
133 item = menu->FirstItem;
135 GetMenuBox(win, item, &menu->JazzX, &menu->JazzY, &menu->BeatX, &menu->BeatY);
137 menu = menu->NextMenu;
141 /* Mark items that has subitems. This is necessary for the input handler
142 code. It's not possible to check item->SubItem within it as we save
143 the layer coordinates there. */
144 void Characterize(struct Menu *menu)
146 while(menu != NULL)
148 struct MenuItem *item;
150 item = menu->FirstItem;
152 while(item != NULL)
154 if(item->SubItem != NULL)
155 item->Flags |= HASSUBITEM;
157 item = item->NextItem;
160 menu = menu->NextMenu;