-
Notifications
You must be signed in to change notification settings - Fork 0
/
CAnimationMenu.cp
executable file
·203 lines (156 loc) · 5.55 KB
/
CAnimationMenu.cp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// =================================================================================
// CAnimationMenu.cp ©1995-1998 Metrowerks Inc. All rights reserved.
// =================================================================================
// CAnimationMenu.h
#include <LCommander.h>
#include <LWindow.h>
#include <PP_Messages.h>
#include <UDesktop.h>
#include "CAnimationMenu.h"
#include "CModelController.h"
// ---------------------------------------------------------------------------------
// ¥ CAnimationMenu
// ---------------------------------------------------------------------------------
CAnimationMenu::CAnimationMenu()
: mBaseItems( 0 )
{
_controller = nil;
}
// ---------------------------------------------------------------------------------
// ¥ CAnimationMenu
// ---------------------------------------------------------------------------------
CAnimationMenu::CAnimationMenu(
ResIDT inMenuID )
: LMenu( inMenuID ), mBaseItems( 0 )
{
_controller = nil;
}
// ---------------------------------------------------------------------------------
// ¥ CAnimationMenu
// ---------------------------------------------------------------------------------
CAnimationMenu::CAnimationMenu(
SInt16 inMenuID,
Str255 inTitle )
: LMenu( inMenuID, inTitle ), mBaseItems( 0 )
{
_controller = nil;
}
// ---------------------------------------------------------------------------------
// ¥ ~CAnimationMenu
// ---------------------------------------------------------------------------------
CAnimationMenu::~CAnimationMenu()
{
}
void CAnimationMenu::RemoveAll()
{
_controller = nil;
while(::CountMenuItems( GetMacMenuH() )) {
RemoveItem( ::CountMenuItems( GetMacMenuH() ));
}
}
void CAnimationMenu::SetItems(StringList *names, CModelController *inController)
{
int count = 0;
RemoveAll();
_controller = inController;
StringList_iterator e = names->begin();
while (e != names->end()) {
Str255 theTitle;
InsertCommand( "\p ", cmd_UseMenuItem, 21000 );
c2pstrcpy((unsigned char*)theTitle, (const char*)e->c_str());
count++;
::SetMenuItemText( GetMacMenuH(), count, theTitle );
e++;
}
ShowCommands();
}
void CAnimationMenu::ShowCommands()
{
char *keys = "qwertyuiopasdfghjklzxcvbnm";
int numKeys = strlen(keys);
UInt8 inModifiers;
SInt16 menuLength = ::CountMenuItems(mMacMenuH);
for(int count = 0; count < menuLength; count++) {
char theCommand = keys[count % numKeys];
inModifiers = kMenuNoCommandModifier;
if ((count % (26*2)) >= 26)
inModifiers |= kMenuShiftModifier;
if ((count % (26*4)) >= 26*2)
inModifiers |= kMenuControlModifier;
if ((count % (26*8)) >= 26*4)
inModifiers |= kMenuOptionModifier ;
if ((count-1) < 26*8) {
// This doesn't work, it causes lettered menu items to respond
// as if the command key is held down. Unfortunate.
::SetItemCmd( GetMacMenuH(), count+1, theCommand);
::SetMenuItemModifiers (GetMacMenuH(), count+1, inModifiers);
}
}
}
void CAnimationMenu::HideCommands()
{
SInt16 menuLength = ::CountMenuItems(mMacMenuH);
for(int count = 0; count < menuLength; count++) {
::SetItemCmd( GetMacMenuH(), count+1, 0);
::SetMenuItemModifiers (GetMacMenuH(), count+1, kMenuNoCommandModifier);
}
}
// =================================================================================
// CAnimationMenuAttachment
// =================================================================================
// ---------------------------------------------------------------------------------
// ¥ CAnimationMenuAttachment
// ---------------------------------------------------------------------------------
CAnimationMenuAttachment::CAnimationMenuAttachment(
CAnimationMenu *inWindowMenu )
: LAttachment( msg_AnyMessage, true ), mAnimationMenu( inWindowMenu )
{
}
// ---------------------------------------------------------------------------------
// ¥ ~CAnimationMenuAttachment
// ---------------------------------------------------------------------------------
CAnimationMenuAttachment::~CAnimationMenuAttachment()
{
}
// ---------------------------------------------------------------------------------
// ¥ ExecuteSelf
// ---------------------------------------------------------------------------------
void
CAnimationMenuAttachment::ExecuteSelf(
MessageT inMessage,
void *ioParam )
{
// Turn on host execution by default.
mExecuteHost = true;
if ( inMessage == msg_CommandStatus ) {
// Handle commander status just like in FindCommandStatus
// even though this class isn't an LCommander.
ResIDT theMenuID;
SInt16 theMenuItem;
SCommandStatus *theStatus = static_cast<SCommandStatus *> (ioParam);
if ( LCommander::IsSyntheticCommand( theStatus->command, theMenuID,
theMenuItem ) && theMenuID == mAnimationMenu->GetMenuID() ) {
// Since the item corresponds to an entry in the window menu
// we'll handle it's status here. Note: there may be other
// items at the top of window menu that are the responsibility
// of some commander.
mExecuteHost = false;
*theStatus->enabled = false;
*theStatus->usesMark = false;
*theStatus->mark = noMark;
if (mAnimationMenu->_controller && mAnimationMenu->_controller->animationCount())
*theStatus->enabled = true;
}
} else {
// Handle commands similar to ObeyCommand even
// though this class isn't an LCommander.
ResIDT theMenuID;
SInt16 theMenuItem;
if ( LCommander::IsSyntheticCommand( inMessage, theMenuID,
theMenuItem ) && theMenuID == mAnimationMenu->GetMenuID() ) {
if (mAnimationMenu->_controller) {
mAnimationMenu->_controller->StartSequenceAtIndex(theMenuItem-1);
}
}
}
}