-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCColorPopupMenuItemView.h
80 lines (60 loc) · 3.04 KB
/
BCColorPopupMenuItemView.h
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
//
// BCColorPopupMenuItemView.h
// Xynk
//
// Created by Tom Houpt on 13/3/3.
//
//
/* Set up the custom views in the popup button menu. This method should be called whenever the baseURL changes.
In MainMenu.xib, the menu for the popup button is defined. There is one menu item with a tag of 1000 that is used as the prototype for the custom menu items. Each colorPickerMenuItemView can contain 4 images. So we keep duplicating the prototype menu item until we have enough menu items for each image found in the directory specified by _baseURL. Duplicating the prototype menu allows us to reuse the target action wiring done in IB.
We need to rebuild this menu each time the _baseURL changes. To accomplish this, we set the tag of each dupicated prototype to 1001. This way we can easily find and remove them to start over.
*/
// USAGE:
// in nib, define a NSPopupButton with one menu item with tag 1000
// call SetUpColorPickerMenu(NSPopupButtonMenu) to set up the menu
// set the selected index with SetSelectedColorIndex
// find the selected index with GetSelectedColorIndex
// make sure the NSPopUpButton is 30 x 15
// make sure the "position" is set to "image only"
#import <Cocoa/Cocoa.h>
#define sideMargin 8.0
#define topMargin 8.0
#define numRows 10
#define numColumns 12
#define numColors 119
#define squareSize 16.0
#define paletteSquareSize 25
void SetUpColorPickerMenu(NSPopUpButton *colorPickerPopup);
NSInteger GetSelectedColorIndex(NSPopUpButton *colorPickerPopup);
void SetSelectedColorIndex(NSPopUpButton *colorPickerPopup, NSInteger index);
NSColor *GetSelectedColor(NSPopUpButton *colorPickerPopup);
void SetSelectedColor(NSPopUpButton *colorPickerPopup, NSColor * theColor);
void SetThemePaletteForColorPicker(NSPopUpButton *colorPickerPopup, NSArray * themePalette);
@interface BCColorPopupMenuItemView : NSView {
@private
NSInteger _selectedIndex;
NSInteger _lastSelectedIndex;
NSMutableArray *_trackingAreas;
// BOOL _thumbnailsNeedUpdate; not used
NSTrackingArea *_paletteTrackingArea;
NSArray *svgColors;
}
/* These two properties are used to detemine which images to use and the current selection, if any. They me be set and interrogated manually, but in this sample code, they are bound to an NSDictionary in CustomMenusAppDelegate.m -setupImagesMenu.
*/
@property (nonatomic, retain) NSArray *imageUrls;
@property (nonatomic, retain, readonly) NSURL *selectedImageUrl;
// exposed these 2 properties (originally private)
// so that we can get index instead of imageURL
@property (nonatomic, assign) NSInteger selectedIndex;
@property (nonatomic, assign) NSInteger lastSelectedIndex;
@property (nonatomic,retain) NSColor *unknownColor;
@property (nonatomic,retain) NSArray *themePalette;
// @property (nonatomic,assign) NSPopUpButton *myPopUpButton;
@property (nonatomic,retain) NSPopUpButton *myPopUpButton;
-(NSRect)getIndexSquare:(NSInteger)index;
-(NSColor *)selectedColor;
-(void)setSelectedColor:(NSColor *)theColor;
-(void)updateMenuImage;
-(IBAction)showColorPanel:(id)sender;
-(IBAction)colorFromColorPanel:(id)sender;
@end