diff options
Diffstat (limited to 'cocoa/InfoBar.mm')
-rw-r--r-- | cocoa/InfoBar.mm | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/cocoa/InfoBar.mm b/cocoa/InfoBar.mm index 45093911d..a4bc52731 100644 --- a/cocoa/InfoBar.mm +++ b/cocoa/InfoBar.mm @@ -22,7 +22,7 @@ { // Get the parent's idea of where we should draw NSRect newRect = [super drawingRectForBounds: theRect]; - + // When the text field is being edited or selected, we have to turn off the magic because it // screws up the configuration of the field editor. We sneak around this by intercepting // selectWithFrame and editWithFrame and sneaking a reduced, centered rect in at the last minute. @@ -30,26 +30,26 @@ { // Get our ideal size for current text NSSize textSize = [self cellSizeForBounds: theRect]; - + // Center that in the proposed rect - float heightDelta = newRect.size.height - textSize.height; + float heightDelta = newRect.size.height - textSize.height; if (heightDelta > 0) { newRect.size.height -= heightDelta; newRect.origin.y += ceil(heightDelta / 2); } } - + return newRect; } //-------------------------------------------------------------------------------------------------- -- (void) selectWithFrame: (NSRect) aRect inView: (NSView*) controlView editor: (NSText*) textObj +- (void) selectWithFrame: (NSRect) aRect inView: (NSView*) controlView editor: (NSText*) textObj delegate:(id) anObject start: (NSInteger) selStart length: (NSInteger) selLength { aRect = [self drawingRectForBounds: aRect]; - mIsEditingOrSelecting = YES; + mIsEditingOrSelecting = YES; [super selectWithFrame: aRect inView: controlView editor: textObj @@ -63,7 +63,7 @@ - (void) editWithFrame: (NSRect) aRect inView: (NSView*) controlView editor: (NSText*) textObj delegate: (id) anObject event: (NSEvent*) theEvent -{ +{ aRect = [self drawingRectForBounds: aRect]; mIsEditingOrSelecting = YES; [super editWithFrame: aRect @@ -86,7 +86,7 @@ if (self) { NSBundle* bundle = [NSBundle bundleForClass: [InfoBar class]]; - + NSString* path = [bundle pathForResource: @"info_bar_bg" ofType: @"tiff" inDirectory: nil]; mBackground = [[NSImage alloc] initWithContentsOfFile: path]; if (![mBackground isValid]) @@ -152,14 +152,14 @@ static float BarFontSize = 10.0; { // 1) The zoom popup. unsigned numberOfDefaultItems = sizeof(DefaultScaleMenuLabels) / sizeof(NSString *); - + // Create the popup button. mZoomPopup = [[NSPopUpButton allocWithZone:[self zone]] initWithFrame: NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown: NO]; - + // No border or background please. [[mZoomPopup cell] setBordered: NO]; [[mZoomPopup cell] setArrowPosition: NSPopUpArrowAtBottom]; - + // Fill it. for (unsigned count = 0; count < numberOfDefaultItems; count++) { @@ -169,28 +169,28 @@ static float BarFontSize = 10.0; [currentItem setRepresentedObject: [NSNumber numberWithFloat: DefaultScaleMenuFactors[count]]]; } [mZoomPopup selectItemAtIndex: DefaultScaleMenuSelectedItemIndex]; - + // Hook it up. [mZoomPopup setTarget: self]; [mZoomPopup setAction: @selector(zoomItemAction:)]; - + // Set a suitable font. [mZoomPopup setFont: [NSFont menuBarFontOfSize: BarFontSize]]; - + // Make sure the popup is big enough to fit the cells. [mZoomPopup sizeToFit]; - + // Don't let it become first responder [mZoomPopup setRefusesFirstResponder: YES]; - + // put it in the scrollview. [self addSubview: mZoomPopup]; [mZoomPopup release]; - + // 2) The caret position label. Class oldCellClass = [NSTextField cellClass]; [NSTextField setCellClass: [VerticallyCenteredTextFieldCell class]]; - + mCaretPositionLabel = [[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 50.0, 1.0)]; [mCaretPositionLabel setBezeled: NO]; [mCaretPositionLabel setBordered: NO]; @@ -205,7 +205,7 @@ static float BarFontSize = 10.0; [self addSubview: mCaretPositionLabel]; [mCaretPositionLabel release]; - + // 3) The status text. mStatusTextLabel = [[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 1.0, 1.0)]; [mStatusTextLabel setBezeled: NO]; @@ -220,7 +220,7 @@ static float BarFontSize = 10.0; [self addSubview: mStatusTextLabel]; [mStatusTextLabel release]; - + // Restore original cell class so that everything else doesn't get broken [NSTextField setCellClass: oldCellClass]; } @@ -248,12 +248,12 @@ static float BarFontSize = 10.0; [mBackground drawAtPoint: target fromRect: NSZeroRect operation: NSCompositeCopy fraction: 1]; target.x += mBackground.size.width; } - + // Draw separator lines between items. NSRect verticalLineRect; float component = 190.0 / 255.0; NSColor* lineColor = [NSColor colorWithDeviceRed: component green: component blue: component alpha: 1]; - + if (mDisplayMask & IBShowZoom) { verticalLineRect = [mZoomPopup frame]; @@ -265,7 +265,7 @@ static float BarFontSize = 10.0; NSRectFill(verticalLineRect); } } - + if (mDisplayMask & IBShowCaretPosition) { verticalLineRect = [mCaretPositionLabel frame]; @@ -347,7 +347,7 @@ static float BarFontSize = 10.0; mDisplayMask = display; [self positionSubViews]; [self needsDisplay]; - } + } } //-------------------------------------------------------------------------------------------------- @@ -358,7 +358,7 @@ static float BarFontSize = 10.0; - (void) zoomItemAction: (id) sender { NSNumber* selectedFactorObject = [[sender selectedCell] representedObject]; - + if (selectedFactorObject == nil) { NSLog(@"Scale popup action: setting arbitrary zoom factors is not yet supported."); @@ -369,9 +369,9 @@ static float BarFontSize = 10.0; [self setScaleFactor: [selectedFactorObject floatValue] adjustPopup: NO]; } } - + //-------------------------------------------------------------------------------------------------- - + - (void) setScaleFactor: (float) newScaleFactor adjustPopup: (BOOL) flag { if (mScaleFactor != newScaleFactor) @@ -381,7 +381,7 @@ static float BarFontSize = 10.0; { unsigned count = 0; unsigned numberOfDefaultItems = sizeof(DefaultScaleMenuFactors) / sizeof(float); - + // We only work with some preset zoom values. If the given value does not correspond // to one then show no selection. while (count < numberOfDefaultItems && (fabs(newScaleFactor - DefaultScaleMenuFactors[count]) > 0.07)) @@ -391,7 +391,7 @@ static float BarFontSize = 10.0; else { [mZoomPopup selectItemAtIndex: count]; - + // Set scale factor to found preset value if it comes close. mScaleFactor = DefaultScaleMenuFactors[count]; } @@ -400,7 +400,7 @@ static float BarFontSize = 10.0; { // Internally set. Notify owner. [mCallback notify: IBNZoomChanged message: nil location: NSZeroPoint value: newScaleFactor]; - } + } } } @@ -414,12 +414,12 @@ static float BarFontSize = 10.0; // Make the position one-based. int newX = (int) position.x + 1; int newY = (int) position.y + 1; - + if (mCurrentCaretX != newX || mCurrentCaretY != newY) { mCurrentCaretX = newX; mCurrentCaretY = newY; - + [mCaretPositionLabel setStringValue: [NSString stringWithFormat: @"%d:%d", newX, newY]]; } } @@ -435,13 +435,13 @@ static float BarFontSize = 10.0; frame.size.width = 0; if (mDisplayMask & IBShowZoom) frame.size.width += [mZoomPopup frame].size.width; - + if (mDisplayMask & IBShowCaretPosition) frame.size.width += [mCaretPositionLabel frame].size.width; - + if (mDisplayMask & IBShowStatusText) frame.size.width += [mStatusTextLabel frame].size.width; - + [self setFrame: frame]; } |