Permalink
Browse files

Added Delegate

  • Loading branch information...
1 parent 92a43bd commit 5bae17b95e68d14cecbdfa06cd921e15ebf74e47 @bfolder committed Jul 30, 2012
View
@@ -7,6 +7,13 @@
#import <Foundation/Foundation.h>
+@class BFPageControl;
+
+@protocol BFPageControlDelegate <NSObject>
+@optional
+-(void)pageControl: (BFPageControl *)pageControl didSelectPageAtIndex: (NSInteger)index;
+@end
+
@interface BFPageControlCell : NSButtonCell
@property (nonatomic)BOOL useHandCursor;
@property (copy)void (^drawingBlock)(NSRect, NSView *, BOOL, BOOL);
@@ -86,4 +93,10 @@
*/
-(void)setDrawingBlock: (void (^)(NSRect frame, NSView *view, BOOL isSelected, BOOL isHiglighted))drawingBlock;
+///---------------------------------------------------------------------------------------
+/// @name Misc Properties
+///---------------------------------------------------------------------------------------
+
+@property (nonatomic, assign)id <BFPageControlDelegate>delegate;
+
@end
View
@@ -70,6 +70,8 @@ @implementation BFPageControl
@synthesize indicatorMargin = _indicatorMargin;
@synthesize useHandCursor = _useHandCursor;
+@synthesize delegate = _delegate;
+
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -157,6 +159,10 @@ -(void)_clickedItem: (id)sender
{
NSUInteger page = [_matrix.cells indexOfObject: _matrix.selectedCell];
_currentPage = page;
+
+ // Call delegate
+ if(_delegate && [_delegate respondsToSelector: @selector(pageControl:didSelectPageAtIndex:)])
+ [_delegate pageControl: self didSelectPageAtIndex: page];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
View
Binary file not shown.
@@ -7,9 +7,12 @@
//
#import <Cocoa/Cocoa.h>
+#import "BFPageControl.h"
-@interface AppDelegate : NSObject <NSApplicationDelegate>
+@interface AppDelegate : NSObject <NSApplicationDelegate, BFPageControlDelegate>
@property (assign) IBOutlet NSWindow *window;
+@property (nonatomic, assign)IBOutlet NSTextField *label;
+
@end
@@ -7,14 +7,22 @@
//
#import "AppDelegate.h"
-#import "BFPageControl.h"
@implementation AppDelegate
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+@synthesize label = _label;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
+ [_label setStringValue: @"Index 5 selected"];
+
+ // Setup page control
NSRect frame = self.window.frame;
BFPageControl *control = [[BFPageControl alloc] init];
+ [control setDelegate: self];
[control setNumberOfPages: 11];
[control setIndicatorDiameterSize: 15];
[control setIndicatorMargin: 5];
@@ -47,4 +55,15 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[control setFrame: CGRectMake(frame.size.width / 2 - control.frame.size.width / 2, 50, 40, 40)];
}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#pragma mark - Delegate
+
+-(void)pageControl: (BFPageControl *)pageControl didSelectPageAtIndex: (NSInteger)index
+{
+ NSLog(@"%@: Selected page at index: %li", pageControl, index);
+ [_label setStringValue: [NSString stringWithFormat: @"Index %li selected", index]];
+}
+
@end
@@ -3,17 +3,19 @@
<data>
<int key="IBDocument.SystemTarget">1080</int>
<string key="IBDocument.SystemVersion">12A269</string>
- <string key="IBDocument.InterfaceBuilderVersion">2809</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2549</string>
<string key="IBDocument.AppKitVersion">1187</string>
<string key="IBDocument.HIToolboxVersion">624.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="NS.object.0">2809</string>
+ <string key="NS.object.0">2549</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>NSCustomObject</string>
<string>NSMenu</string>
<string>NSMenuItem</string>
+ <string>NSTextField</string>
+ <string>NSTextFieldCell</string>
<string>NSView</string>
<string>NSWindowTemplate</string>
</array>
@@ -1301,10 +1303,52 @@
<object class="NSView" key="NSWindowView" id="439893737">
<reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
- <array class="NSMutableArray" key="NSSubviews"/>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="NSTextField" id="400541759">
+ <reference key="NSNextResponder" ref="439893737"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 186}, {446, 26}}</string>
+ <reference key="NSSuperview" ref="439893737"/>
+ <reference key="NSWindow"/>
+ <string key="NSReuseIdentifierKey">_NS:1535</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="213740748">
+ <int key="NSCellFlags">68157504</int>
+ <int key="NSCellFlags2">138413056</int>
+ <string key="NSContents">Label</string>
+ <object class="NSFont" key="NSSupport">
+ <string key="NSName">LucidaGrande</string>
+ <double key="NSSize">15</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ <string key="NSCellIdentifier">_NS:1535</string>
+ <reference key="NSControlView" ref="400541759"/>
+ <object class="NSColor" key="NSBackgroundColor">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">gridColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC41AA</bytes>
+ </object>
+ </object>
+ </object>
+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+ </object>
+ </array>
<string key="NSFrameSize">{480, 360}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="400541759"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
@@ -1999,6 +2043,14 @@
</object>
<int key="connectionID">532</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">label</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="400541759"/>
+ </object>
+ <int key="connectionID">553</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -2523,7 +2575,9 @@
<object class="IBObjectRecord">
<int key="objectID">372</int>
<reference key="object" ref="439893737"/>
- <array class="NSMutableArray" key="children"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="400541759"/>
+ </array>
<reference key="parent" ref="972006081"/>
</object>
<object class="IBObjectRecord">
@@ -2999,6 +3053,19 @@
<reference key="object" ref="738670835"/>
<reference key="parent" ref="963351320"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">550</int>
+ <reference key="object" ref="400541759"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="213740748"/>
+ </array>
+ <reference key="parent" ref="439893737"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">551</int>
+ <reference key="object" ref="213740748"/>
+ <reference key="parent" ref="400541759"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -3142,6 +3209,8 @@
<string key="516.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="517.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="534.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="550.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="551.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="58.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3161,24 +3230,32 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">547</int>
+ <int key="maxID">554</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">AppDelegate</string>
<string key="superclassName">NSObject</string>
- <object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">window</string>
- <string key="NS.object.0">NSWindow</string>
- </object>
- <object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <string key="NS.key.0">window</string>
- <object class="IBToOneOutletInfo" key="NS.object.0">
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="label">NSTextField</string>
+ <string key="testView">TestView</string>
+ <string key="window">NSWindow</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="label">
+ <string key="name">label</string>
+ <string key="candidateClassName">NSTextField</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="testView">
+ <string key="name">testView</string>
+ <string key="candidateClassName">TestView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="window">
<string key="name">window</string>
<string key="candidateClassName">NSWindow</string>
</object>
- </object>
+ </dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/AppDelegate.h</string>
@@ -3225,6 +3302,14 @@
<string key="minorKey">./Classes/NSDocument.h</string>
</object>
</object>
+ <object class="IBPartialClassDescription">
+ <string key="className">TestView</string>
+ <string key="superclassName">NSView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/TestView.h</string>
+ </object>
+ </object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>

0 comments on commit 5bae17b

Please sign in to comment.