• R/O
  • SSH
  • HTTPS

alchemusica: 提交


Commit MetaInfo

修订版198 (tree)
时间2021-08-11 15:02:56
作者toshinagata1964

Log Message

In the strip chart view, the popup of the control number was not working correctly. Fixed.

更改概述

差异

--- trunk/Classes/GraphicSplitterView.h (revision 197)
+++ trunk/Classes/GraphicSplitterView.h (revision 198)
@@ -23,6 +23,7 @@
2323 MyPopUpButton *codePopup;
2424 MyPopUpButton *trackPopup;
2525 NSTextField *trackLabelText;
26+ NSMenu *controlSubmenu;
2627 }
2728
2829 - (void)setKindAndCode: (int32_t)kindAndCode;
--- trunk/Classes/GraphicSplitterView.m (revision 197)
+++ trunk/Classes/GraphicSplitterView.m (revision 198)
@@ -20,11 +20,12 @@
2020 #import "MyDocument.h"
2121 #import "MyMIDISequence.h"
2222 #import "NSCursorAdditions.h"
23+#import "NSMenuAdditions.h"
2324 #import "MDObjects.h"
2425
2526 @implementation GraphicSplitterView
2627
27-static NSMenu *sControlSubmenu;
28+// static NSMenu *sControlSubmenu;
2829 // static NSMenu *sKeyPresSubmenu;
2930
3031 static struct sKindMenuItems {
@@ -40,7 +41,7 @@
4041 { kMDEventTempo, @"Tempo" }
4142 };
4243
43-static NSMenuItem *
44+/*static NSMenuItem *
4445 searchMenuItemWithTag(NSMenu *menu, int tag)
4546 {
4647 int i;
@@ -56,7 +57,7 @@
5657 }
5758 }
5859 return nil;
59-}
60+}*/
6061
6162 - (id)initWithFrame:(NSRect)frame {
6263 int i;
@@ -114,6 +115,13 @@
114115 return self;
115116 }
116117
118+- (void)dealloc
119+{
120+ if (controlSubmenu != nil)
121+ [controlSubmenu release];
122+ [super dealloc];
123+}
124+
117125 - (NSMenu *)makeTrackPopup
118126 {
119127 NSMenu *menu;
@@ -154,9 +162,9 @@
154162 id target = [[[self superview] window] windowController];
155163 [kindPopup setTarget: target];
156164 [kindPopup setAction: @selector(kindPopUpPressed:)];
157- if (sControlSubmenu == nil) {
158- sControlSubmenu = [MDMenuWithControlNames(nil, nil, 0) retain];
159- }
165+ if (controlSubmenu == nil) {
166+ controlSubmenu = [MDMenuWithControlNames(self, @selector(codeMenuItemSelected:), 0) retain];
167+ }
160168 [codePopup setTarget: target];
161169 [codePopup setAction: @selector(codeMenuItemSelected:)];
162170 [trackPopup setTarget:target];
@@ -213,6 +221,12 @@
213221 {
214222 }
215223
224+- (IBAction)codeMenuItemSelected:(id)sender
225+{
226+ GraphicWindowController *controller = (GraphicWindowController *)[[self window] windowController];
227+ [controller codeMenuItemSelected:(NSMenuItem *)sender inSplitterView:self];
228+}
229+
216230 - (void)setKindAndCode: (int32_t)kindAndCode
217231 {
218232 int kind, code;
@@ -220,11 +234,11 @@
220234 code = (kindAndCode & 65535);
221235 kind = ((kindAndCode >> 16) & 65535);
222236 if (kind != 65535) {
223- item = searchMenuItemWithTag([kindPopup menu], kind);
237+ item = [[kindPopup menu] searchMenuItemWithTag:kind];
224238 if (item != nil) {
225239 [kindPopup selectItem: item];
226240 if (kind == kMDEventControl) {
227- [codePopup setMenu: sControlSubmenu];
241+ [codePopup setMenu: controlSubmenu];
228242 [codePopup setEnabled: YES];
229243 } else {
230244 [codePopup setMenu: [[[NSMenu allocWithZone: [self zone]] initWithTitle: @""] autorelease]];
@@ -233,7 +247,7 @@
233247 }
234248 }
235249 if (code != 65535) {
236- item = searchMenuItemWithTag([codePopup menu], code);
250+ item = [[codePopup menu] searchMenuItemWithTag:code];
237251 if (item != nil) {
238252 [codePopup selectItem: item];
239253 }
--- trunk/Classes/GraphicWindowController.h (revision 197)
+++ trunk/Classes/GraphicWindowController.h (revision 198)
@@ -203,7 +203,7 @@
203203
204204 - (void)setStripChartAtIndex: (int)index kind: (int)kind code: (int)code;
205205 - (IBAction)kindPopUpPressed: (id)sender;
206-- (IBAction)codeMenuItemSelected: (id)sender;
206+- (void)codeMenuItemSelected: (NSMenuItem *)item inSplitterView: (GraphicSplitterView *)view;
207207 - (IBAction)trackPopUpPressedInSplitterView: (id)sender;
208208
209209 - (IBAction)expandHorizontally: (id)sender;
--- trunk/Classes/GraphicWindowController.m (revision 197)
+++ trunk/Classes/GraphicWindowController.m (revision 198)
@@ -1209,12 +1209,12 @@
12091209 }
12101210 }
12111211
1212-- (IBAction)codeMenuItemSelected: (id)sender
1212+- (void)codeMenuItemSelected: (NSMenuItem *)item inSplitterView: (GraphicSplitterView *)view
12131213 {
12141214 int i, code;
12151215 for (i = 1; i < myClientViewsCount; i++) {
1216- if (records[i].splitter == (GraphicSplitterView *)[sender superview]) {
1217- code = (int)[[sender selectedItem] tag];
1216+ if (records[i].splitter == view) {
1217+ code = (int)[item tag];
12181218 [self setStripChartAtIndex: i kind: -1 code: code];
12191219 break;
12201220 }
--- trunk/Classes/MyPopUpButton.h (revision 197)
+++ trunk/Classes/MyPopUpButton.h (revision 198)
@@ -25,6 +25,7 @@
2525 {
2626 NSColor *textColor;
2727 NSColor *backgroundColor;
28+ NSMenuItem *selectedItem; /* non-nil if an item in the submenu is selected */
2829 }
2930 + (NSImage *)triangleImage;
3031 + (NSImage *)doubleTriangleImage;
--- trunk/Classes/MyPopUpButton.m (revision 197)
+++ trunk/Classes/MyPopUpButton.m (revision 198)
@@ -144,4 +144,28 @@
144144 return backgroundColor;
145145 }
146146
147+// Implement the menu item selection with hierarchical menus
148+- (NSMenuItem *)selectedItem
149+{
150+ NSMenuItem *item = [super selectedItem];
151+ if (item == nil && selectedItem != nil)
152+ return selectedItem;
153+ else return item;
154+}
155+
156+- (void)selectItem:(NSMenuItem *)anItem
157+{
158+ NSMenuItem *item;
159+ if (selectedItem)
160+ [selectedItem setState:NSOffState];
161+ [super selectItem:anItem];
162+ item = [super selectedItem];
163+ if (item == nil) {
164+ // Should be a submenu item
165+ selectedItem = anItem;
166+ [selectedItem setState:NSOnState];
167+ }
168+ else selectedItem = nil;
169+}
170+
147171 @end
--- trunk/Classes/NSMenuAdditions.h (revision 197)
+++ trunk/Classes/NSMenuAdditions.h (revision 198)
@@ -20,4 +20,6 @@
2020
2121 @interface NSMenu (MyMenuAddition)
2222 - (void)changeMenuTitleAttributes:(NSDictionary *)attributes;
23+- (NSMenuItem *)searchMenuItemWithTag:(int)tag;
24+- (NSMenu *)findSubmenuContainingItem:(NSMenuItem *)anItem outIndex:(int *)outIndex;
2325 @end
--- trunk/Classes/NSMenuAdditions.m (revision 197)
+++ trunk/Classes/NSMenuAdditions.m (revision 198)
@@ -36,4 +36,47 @@
3636 }
3737 }
3838
39+static NSMenuItem *
40+searchMenuItemWithTagSub(NSMenu *menu, int tag)
41+{
42+ int i;
43+ NSMenuItem *item;
44+ for (i = (int)[menu numberOfItems] - 1; i >= 0; i--) {
45+ item = (NSMenuItem *)[menu itemAtIndex: i];
46+ if ([item tag] == tag)
47+ return item;
48+ if ([item hasSubmenu]) {
49+ item = searchMenuItemWithTagSub([item submenu], tag);
50+ if (item != nil)
51+ return item;
52+ }
53+ }
54+ return nil;
55+}
56+
57+- (NSMenuItem *)searchMenuItemWithTag:(int)tag
58+{
59+ return searchMenuItemWithTagSub(self, tag);
60+}
61+
62+- (NSMenu *)findSubmenuContainingItem:(NSMenuItem *)anItem outIndex:(int *)outIndex
63+{
64+ int i;
65+ NSMenuItem *item;
66+ for (i = (int)[self numberOfItems] - 1; i >= 0; i--) {
67+ item = (NSMenuItem *)[self itemAtIndex: i];
68+ if (item == anItem) {
69+ if (outIndex != NULL)
70+ *outIndex = i;
71+ return self;
72+ }
73+ if ([item hasSubmenu]) {
74+ NSMenu *menu = [[item submenu] findSubmenuContainingItem:anItem outIndex:outIndex];
75+ if (menu != nil)
76+ return menu;
77+ }
78+ }
79+ return nil;
80+}
81+
3982 @end
Show on old repository browser