2016-06-08 2 views
0

필자는 내가 작성한 OSX 데스크탑 응용 프로그램에 내 사용자 정의 스타일 (example)을 적용하는 것과 씨름 해 왔으며, 패러다임/숙어가 무엇을하는지 궁금합니다. 이.NSView 서브 클래스 서브 클래 싱하기 (NSTextField, NSButton, NSPopUpButton)

  • 나는 X를 사용하고/빻 윈도우의 구성 요소를 배치하기위한
  • 나는 아웃 - 오브 - 박스 구성 요소의 사용자 지정 하위 클래스 (NSTextField에 구성 요소의 클래스를 설정하고있어, NSButton 그리고 NSPopUpButton 내가 다른 사람의 일부에서 viewWillDraw, init?을 무시하고 그들에게 모든 wantsLayer을하고 그 레이어에 속성을 설정하고있어
  • ) 예를 들어

이것은 extr 보인다 emely 최고로 어색하고, 시각적 인 것들 중 일부는 NSTextField에 패딩을 덧붙여서 이런 식으로 처리 할 수 ​​없습니다. NSTextFieldCell 하위 클래스를 만들고이를 인스턴스화하고이를 셀로 설정해야합니까? 이렇게하면 텍스트 필드가 완전히 끊어집니다. other places은 서브 클래스 NSButtonCell이어야하지만 X/Nib의 버튼 클래스로 할당 할 수는 없습니다. (@Willeke는 컨트롤에서 셀을 선택하는 것이 가능하다는 의견을 알리고 컨트롤을 다시 클릭하여 사용자 정의 셀 클래스를 할당 함)

많은 사람들이 시각적 구성 요소에 특정 변경을 수행하는 방법을 설명합니다 viewDidLoad에있는 구성 요소를 참조하면 버튼/텍스트 필드 스타일이 프로젝트에 모두 적용되면 매우 지루해 보입니다. 서브 클래 싱을 통해 만들었던 모든 시각적 변화가 악몽처럼 보였고 시각적 변경이 다른 구성 요소의 경우 어디에 만들어 졌는지에 대한 패턴이 없습니다. 서브 클래 싱은 코드를 재사용 가능하게 만들고 싶다면 프로젝트의 모든 크기에 대해 가장 좋은 옵션처럼 보이지만 뭔가 빠졌는가? 내가 누락 된 다른 패턴이나 관용구가 있습니까?

+0

* 사용자 정의 스타일 *에 대한 예제가 있습니까? 복제하려는 효과를 확인할 수 있다면 도움을주기가 더 쉽습니다. –

+0

https://www.dropbox.com/s/320chi85n7ec5oj/Screenshot%202016-06-08%2017.04.29.png?dl= 0은 우리가 원하는'NSTextField'와'NSButton'의 예를 보여줍니다.'NSPopUpButton'이 텍스트 필드와 같은 스타일을 가지기를 바랍니다. – jake

+1

컨트롤 클래스를 변경하는 것과 같은 방법으로 XIB에서 셀 클래스를 변경할 수 있습니다. 다시 클릭하여 셀을 선택하거나 더블 클릭하지 마십시오. 상단의 패스 컨트롤을 사용하거나 왼쪽의 문서 개요를 사용하십시오. – Willeke

답변

0
내가 NSTextFieldCell를 서브 클래 싱 결국 한

, 그리고 this answer에서 나는 내가 직면 한 특정 문제에 대해 다음을 도출 예를 들어, customizing focus styles으로 이동하는 것보다 뷰를 커스터마이징하는 것이 훨씬 더 복잡합니다. 그러나 그것은 제가 아직까지 가지고있는 질문입니다. 좋은 대답이야.

0

NSTextFieldCell을 서브 클래 싱하는 것이 가장 좋은 방법이지만 긴 전투입니다. Willeke sez와 마찬가지로 XIB에서 셀 클래스를 변경하십시오.

나는 BGHUDAppKit을 출발점으로 삼아 수년 동안 주요한 개조/업그레이드를했다.

FWIW 여기에 attrStringWithColor와 같은 내 자신의 카테고리 메소드를 사용하는 BGHUDTextFieldCell.mm의 현재 버전이 있지만 일반 아이디어는 명확해야합니다.

포커스 링 애니메이션 처리는 특히 까다로운 작업입니다. 맞춤형 포커스 링을 그릴 수있는 유일한 방법은 기본 NSTextView 포커스 링을 납치 할 수 있도록 NSTextField 및 해당 수퍼 뷰를 비롯한 많은 항목을 서브 클래스로 만드는 것입니다. 그러나 NSTextView 자체를 서브 클래 싱하지 않기를 권장합니다 ... 아래의 setupFieldEditorColors를 참조하십시오.

// BGHUDTextFieldCell.m 
    // BGHUDAppKit 
    // 
    // Created by BinaryGod on 6/2/08. 
    // 
    // Copyright (c) 2008, Tim Davis (BinaryMethod.com, [email protected]) 
    // All rights reserved. 
    // 
    // Redistribution and use in source and binary forms, with or without modification, 
    // are permitted provided that the following conditions are met: 
    // 
    //  Redistributions of source code must retain the above copyright notice, this 
    // list of conditions and the following disclaimer. 
    // 
    //  Redistributions in binary form must reproduce the above copyright notice, 
    // this list of conditions and the following disclaimer in the documentation and/or 
    // other materials provided with the distribution. 
    // 
    //  Neither the name of the BinaryMethod.com nor the names of its contributors 
    // may be used to endorse or promote products derived from this software without 
    // specific prior written permission. 
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND 
    // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
    // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
    // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
    // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
    // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
    // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
    // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
    // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
    // POSSIBILITY OF SUCH DAMAGE. 

    #import "BGHUDTextFieldCell.h" 
    #import "VNSColorCategory.h" 
    #import "BGThemeMbox.h" 
    @interface BGHUDTextFieldCell (Private) 
    - (void)doInit; 
    - (NSRect)_focusRingFrameForFrame:(NSRect)aRect cellFrame:(NSRect)cellFrame; // bug fix 
    @end 
    @implementation BGHUDTextFieldCell 

    @synthesize themeKey; 
    @synthesize LayerKey; 
    @synthesize defaultTextColor; 
    @synthesize isVerticallyCentered; 
    @synthesize fillsBackground; 
    //@synthesize LayerKey; 
    #pragma mark Drawing Functions 

    - (id)initTextCell:(NSString *)aString { 

    self = [super initTextCell: aString]; 

    if(self) { 
     self.themeKey = @"gradientTheme"; 
     [self doInit]; 

    } 

    return self; 
    } 

    - (id)initWithCoder:(NSCoder *) aDecoder { 

    self = [super initWithCoder: aDecoder]; 

    if(self) { 

     if([aDecoder containsValueForKey: @"themeKey"]) { 

      self.themeKey = [aDecoder decodeObjectForKey: @"themeKey"]; 
     } else { 

      self.themeKey = @"gradientTheme"; 
     } 

     [self doInit]; 

    } 

    return self; 
    } 

    - (void)doInit 
    { 
    self.defaultTextColor = [[[BGThemeManager keyedManager] themeForKey: self.themeKey] textColor]; 
    [self setTextColor:self.defaultTextColor]; 

    if([self drawsBackground]) { 
     fillsBackground = YES; 
     ////NSLog(@"t%d BGHUDTextFieldCell initTextCell ignoring nib backgroundColor %@, use fillsBackground", [self tag], [self backgroundColor]); 
    } 
    else // kpk 2010... always draw background? 
    { 
     fillsBackground = NO; 
    } 

    [self setDrawsBackground: NO]; 
    } 


    -(void)encodeWithCoder:(NSCoder *)aCoder { 

    [super encodeWithCoder: aCoder]; 

    [aCoder encodeObject: self.themeKey forKey: @"themeKey"]; 
    } 

    - (NSRect) adjustFrameToVerticallyCenterText: (NSRect) frame 
    { 
    // super would normally draw text at the top of the cell 
    int offset = floor ((NSHeight (frame) - ([ [ self font ] ascender] - [ [ self font ] descender ]))/2); 
    frame = NSInsetRect (frame, 0.0, offset); 
    return frame; 
    } 

    - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj 
    { 
    BGTheme *theTheme = [[BGThemeManager keyedManager] themeForKey: self.themeKey]; 
    //textObj = [super setUpFieldEditorAttributes:textObj]; 
    NSTextView *theTextView = (NSTextView *)textObj; 
    if ([theTextView isKindOfClass:[NSTextView class]]) 
    { 
     //NSLog(@"t%d text view editor %@ bgcolor %@ insert color %@", [self tag], [theTextView description], [theTextView backgroundColor], [theTextView insertionPointColor]); 
     [BGTheme setupFieldEditorColors:theTheme editor:theTextView window:[[self controlView] window] forObject:self]; 
    } 

    return textObj; 
    } 

    -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { 
    waitIfNeeded(self); 
    if (isVerticallyCentered) // kpk 2013 _cFlags.vCentered = 1; 
     cellFrame = [ self adjustFrameToVerticallyCenterText: cellFrame ]; 

    // kpk 2009/2010: get the fieldEditorView (NSTextView) to display properly as well. 
    // Also be careful not to cause continuous redraws by setting text color unnecessarily. 
    NSWindow *theWindow = [controlView window]; 

    NSTextView* fieldEditorView = (NSTextView*)[theWindow fieldEditor: NO forObject: self]; 
    id fieldEditorDelegate = [fieldEditorView delegate]; 
    if ([theWindow firstResponder] == fieldEditorView && fieldEditorDelegate == controlView) 
    {  
     //NSLog(@"t%d fieldEditorView bg color %@ self %@ controlView %@", [self tag], [self backgroundColor], [self description], [controlView description]); 
     BGTheme *theTheme = [[BGThemeManager keyedManager] themeForKey: self.themeKey]; 
     if (fieldEditorView) 
      [BGTheme setupFieldEditorColors:theTheme editor:fieldEditorView window:theWindow forObject:self]; 

     NSRect editFrame = [fieldEditorView frame]; 
     NSRect controlViewFrame = [controlView frame]; 
     if ([controlView isKindOfClass:[NSTextField class]] && NSIntersectsRect(controlViewFrame, editFrame)) 
     { 
      return; 
     } 
    } 
    fieldEditorView = nil; // kpk 2010: we are done with this now 

    //Create Path 
    NSBezierPath *path = [[NSBezierPath new] autorelease]; 

    if([self bezelStyle] == NSTextFieldRoundedBezel) { 

     [path appendBezierPathWithArcWithCenter: NSMakePoint(cellFrame.origin.x + (cellFrame.size.height /2), cellFrame.origin.y + (cellFrame.size.height /2)) 
           radius: cellFrame.size.height /2 
           startAngle: 90 
           endAngle: 270]; 

     [path appendBezierPathWithArcWithCenter: NSMakePoint(cellFrame.origin.x + (cellFrame.size.width - (cellFrame.size.height /2)), cellFrame.origin.y + (cellFrame.size.height /2)) 
           radius: cellFrame.size.height /2 
           startAngle: 270 
           endAngle: 90]; 

     [path closePath]; 
    } else { 

     // kpk 2010: not desireable for table view cells 
     //[path appendBezierPathWithRoundedRect: cellFrame xRadius: 3.0f yRadius: 3.0f]; 
     //[path appendBezierPathWithRect:cellFrame]; 
    } 

    //Draw Background 
    if(fillsBackground) { 
     [[[[BGThemeManager keyedManager] themeForKey: self.themeKey] textFillColor] set]; 
     // kpk 2010: not desireable for table view cells 
     NSRectFill(cellFrame); 
     //[path fill]; 
    } 
    else if ([self isEditable]) 
    { 
     [[[[BGThemeManager keyedManager] themeForKey: self.themeKey] textFillColor] set]; 
     [path fill];  
     // NSRectFill(cellFrame); 
    } 

    if([self isBezeled] || [self isBordered]) { 

     [NSGraphicsContext saveGraphicsState]; 

     if([super showsFirstResponder] && [theWindow isKeyWindow] && 
      ([self focusRingType] == NSFocusRingTypeDefault || 
      [self focusRingType] == NSFocusRingTypeExterior)) { 

      [[[[BGThemeManager keyedManager] themeForKey: self.themeKey] focusRing] set]; 
     } 

     //Check State 
     if([self isEnabled]) { 

      [[[[BGThemeManager keyedManager] themeForKey: self.themeKey] darkStrokeColor] set]; 
     } else { 

      [[[[BGThemeManager keyedManager] themeForKey: self.themeKey] disabledStrokeColor] set]; 
     } 

     [path setLineWidth: 1.0f]; 
     [path stroke]; 

     [NSGraphicsContext restoreGraphicsState]; 
    } 

    // Check to see if the attributed placeholder has been set or not 
    //if(![self placeholderAttributedString]) { 
    if(![self placeholderAttributedString] && [self placeholderString]) { 

     //Nope lets create it 
     NSDictionary *attribs = [[NSDictionary alloc] initWithObjectsAndKeys: 
          [[[BGThemeManager keyedManager] themeForKey: self.themeKey] placeholderTextColor] , NSForegroundColorAttributeName, nil]; 

     //Set it 
     [self setPlaceholderAttributedString: [[[NSAttributedString alloc] initWithString: [self placeholderString] attributes: [attribs autorelease]] autorelease]]; 
    } 

    //Adjust Frame so Text Draws correctly 
    switch ([self controlSize]) { 

     case NSRegularControlSize: 

      if([self bezelStyle] == NSTextFieldRoundedBezel) { // kpk 2010 

       cellFrame.origin.y += 1; 
      } 
      break; 

     case NSSmallControlSize: 

      if([self bezelStyle] == NSTextFieldRoundedBezel) { 

       cellFrame.origin.y += 1; 
      } 
      break; 

     case NSMiniControlSize: 

      if([self bezelStyle] == NSTextFieldRoundedBezel) { 

       cellFrame.origin.x += 1; 
      } 
      break; 

     default: 
      break; 
    } 

    [self drawInteriorWithFrame: cellFrame inView: controlView]; 
    } 

    -(void)drawInteriorWithFrame:(NSRect) cellFrame inView:(NSView *) controlView {  
    if ([controlView conformsToProtocol:@protocol(EditingAlignmentProtocol)]) 
    { 

     if ([controlView isKindOfClass:[NSControl class]] && [(NSControl *)controlView currentEditor]) 
     {  
      // DLog(@"danger: skipping draw to avoid call to validateEditing!"); 
      return; 
     } 

     cellFrame = [(id <EditingAlignmentProtocol>)controlView editingAlignmentRect]; 
     cellFrame = [self titleRectForBounds:cellFrame]; 
     NSAttributedString *str = [self attributedStringValue]; 
     [str drawInRect:cellFrame]; 
     return; 
    } 

    [super drawInteriorWithFrame: cellFrame inView: controlView]; 
    } 

    - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView; 
    { 

    // Corbin Dunn (the apple author) says to return nil here 
    // The proper thing to do: 
    //  
    //  1. Subclass NSCell, NSTextFieldCell, or whatever other cell you want. 
    //  2. Override: 
    //  
    //  - (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView 
    //                  *)controlView 
    //  
    //  and return nil. 
    //  
    //  That is the correct thing to do for Tiger, Leopard, etc. 
    //   
    //   corbin 
    if ([controlView isKindOfClass: [NSTableView class]]) 
     return nil; // [[BGThemeMbox instance] cellHighlightColor]; 
    return [super highlightColorWithFrame:cellFrame inView:controlView]; 
    } 

    // warning mIsEditingOrSelecting is probably not used correctly when call stack is deep, 
    // while switching from one edit field to another 
    - (NSRect)drawingRectForBounds:(NSRect)aRect 
    { 
    id controlView = [self controlView]; 
    NSRect newRect; 
    if ([controlView conformsToProtocol:@protocol(EditingAlignmentProtocol)]) 
     newRect = [(id <EditingAlignmentProtocol>)controlView editingAlignmentRect]; 
    else 
    { 
     newRect = [super drawingRectForBounds:aRect]; 
     if (mIsEditingOrSelecting == NO) 
     { 
      // Get our ideal size for current text 
      NSSize textSize = [self cellSizeForBounds:aRect]; 
      if (textSize.height >= 22 && textSize.height > newRect.size.height) 
      { 
       newRect.origin.y = -(textSize.height - newRect.size.height) + 6; 
       newRect.size.height = textSize.height + (textSize.height - newRect.size.height); 
      }  
     } 
    } 

    return newRect; 
    } 

    // hack alert: undocumented _focusRingFrameForFrame 
    // this fixes a hard to reproduce bug where NSTextView fieldEditor *sometimes* 
    // leaves behind white clutter. 
    // to reproduce, have 10, 11, or 12 items in scene table, then edit xFade type. 
    // scene table will have white clutter. 
    - (NSRect)_focusRingFrameForFrame:(NSRect)aRect cellFrame:(NSRect)cellFrame 
    { 
    id ctl = [self controlView]; 
    if ([ctl conformsToProtocol:@protocol(EditingAlignmentProtocol)]) 
     return [ctl bounds]; 
    else 
     return cellFrame; 
    } 

    // This method is adapted from Red Sweater Software's RSVerticallyCenteredTextField class. 
    // Created by Daniel Jalkut on 6/17/06. 
    // Copyright 2006 Red Sweater Software. All rights reserved. 
    // MIT License 
    - (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength 
    { 
    if (isVerticallyCentered) // kpk 2013 _cFlags.vCentered replacement 
     aRect = [ self adjustFrameToVerticallyCenterText: aRect ]; 
    aRect = [self drawingRectForBounds:aRect]; 
    mIsEditingOrSelecting = YES; 
    [super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; 
    mIsEditingOrSelecting = NO; 
    //NSLog(@"selectWithFrame %@ %@", controlView, textObj); 
    } 

    // This method is adapted from Red Sweater Software's RSVerticallyCenteredTextField class. 
    // Created by Daniel Jalkut on 6/17/06. 
    // Copyright 2006 Red Sweater Software. All rights reserved. 
    // MIT License 
    - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent 
    { 
    if (isVerticallyCentered) // kpk 2013 _cFlags.vCentered replacement 
     aRect = [ self adjustFrameToVerticallyCenterText: aRect ]; 
    //NSLog(@"editWithFrame %@", controlView); 
    aRect = [self drawingRectForBounds:aRect]; 
    mIsEditingOrSelecting = YES; 
    [super editWithFrame:[self drawingRectForBounds:aRect] inView:controlView editor:textObj delegate:anObject event:theEvent]; 
    mIsEditingOrSelecting = NO; 
    } 

    -(void)_drawKeyboardFocusRingWithFrame:(NSRect)fp8 inView:(id)fp24 { 
    //NSLog(@"_drawKeyboardFocusRingWithFrame"); 
    } 

    - (void)drawWithExpansionFrame:(NSRect)cellFrame inView:(NSView *)view 
    { 
    [[[[BGThemeManager keyedManager] themeForKey: @"gradientTheme"] darkStrokeColor] set]; 
    NSRectFill(cellFrame); 
    [self drawInteriorWithFrame:cellFrame inView:view]; 
    } 

    - (void) setAttributedColor: (NSColor *)iColor 
    { 
    NSMutableAttributedString *attrStr = [[self stringValue] attrStringWithColor: iColor]; 
    [attrStr setAlignment: [self alignment] range:[attrStr fullRange]]; 
    [attrStr setFont:[self font]]; 
    [self setAttributedStringValue:attrStr]; 
    if (iColor) 
     [self setTextColor:iColor]; 
    else if ([self isEditable]) 
     [self setTextColor: [NSColor defaultTextColor]]; 
    else 
     [self setTextColor:[NSColor dimTextColor]]; 
    } 

    #pragma mark - 
    #pragma mark Helper Methods 

    -(void)dealloc { 

    [super dealloc]; 
    } 

    #pragma mark - 

    @end 

.H 파일 :

class TGTextFieldCell: NSTextFieldCell { 
    override init(imageCell image: NSImage?) { 
     super.init(imageCell: image) 
    } 

    override init(textCell aString: String) { 
     super.init(textCell: aString) 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    override func drawingRectForBounds(theRect: NSRect) -> NSRect { 
     let rectInset = NSMakeRect(theRect.origin.x + 7, theRect.origin.y + 7, theRect.size.width, theRect.size.height) 
     return super.drawingRectForBounds(rectInset) 
    } 
} 

그것은 여전히 ​​것 같다

 #import <Cocoa/Cocoa.h> 
    #import "BGThemeManager.h" 

    @protocol EditingAlignmentProtocol 
    - (NSRect)editingAlignmentRect; // used to align NSTextView field editor frame 
    - (void)setIsSettingUpFieldEditor:(bool)flag; 
    - (bool)isSettingUpFieldEditor; 
    @end 

    @interface BGHUDTextFieldCell : NSTextFieldCell { 

    BOOL fillsBackground; 
    NSString *themeKey; 
    NSString *LayerKey; 
    NSColor *defaultTextColor; 
    BOOL mIsEditingOrSelecting; 
    BOOL isVerticallyCentered; 
    } 

    @property (retain) NSString *themeKey; 
    @property (retain) NSString *LayerKey; 
    @property (retain) NSColor *defaultTextColor; 
    @property (assign) BOOL isVerticallyCentered; 
    @property (assign) BOOL fillsBackground; 
    - (void)doInit; // if overriden, must call [super doInit]; 
    - (void) setAttributedColor: (NSColor *)iColor; 
    @end 

setupFieldEditor는

+(void)setupFieldEditorColors:(BGTheme *)iTheme editor:(NSTextView *)iFieldEditorView window:(NSWindow *)iWindow forObject:(id)anObject 
{ 
    if (iFieldEditorView == nil) 
     return; 

    if (!iFieldEditorView || ![iFieldEditorView isKindOfClass:[NSTextView class]]) 
     return; 

    // setup attributes such that editing in the field editor will 
    // occur at the exact same position as the title cell was drawn 
    [[iFieldEditorView textContainer] setLineFragmentPadding:2.0]; 
    //[[iFieldEditorView layoutManager] setTypesetterBehavior:NSTypesetterBehavior_10_2_WithCompatibility]; 
    NSRange theSelRange = [iFieldEditorView selectedRange]; 
    @try 
    { 
     if ([anObject respondsToSelector: @selector(themeKey)] || 
      ([anObject respondsToSelector: @selector(cell)] && 
      [[anObject cell] respondsToSelector: @selector(themeKey)])) 
     { 
     //NSLog(@"theSelRange %@", NSStringFromRange(theSelRange)); 
     NSColor *theTextColor = [iTheme textColor]; 
     if ([iFieldEditorView insertionPointColor] != theTextColor) 
      [iFieldEditorView setInsertionPointColor:theTextColor]; 
     //if ([iFieldEditorView textColor] != theTextColor) 
     //{ 
      //NSLog(@"cell editor tc %@\n change to %@", [iFieldEditorView textColor], theTextColor); 
     // [iFieldEditorView setTextColor: theTextColor]; 
     //} 

     //NSLog(@"cell editor createFlag %d", createFlag); 
     //if (![iFieldEditorView isKindOfClass:[BGHUDTextView class]]) 
     // iFieldEditorView = [BGHUDTextView alloc] init 
     NSColor *theBgColor = [iTheme cellEditingFillColor]; 
     if ([iFieldEditorView backgroundColor] != theBgColor) 
     { 
      //NSLog(@"cell editor bg %@\n change to %@", [iFieldEditorView backgroundColor], theBgColor); 
      [iFieldEditorView setBackgroundColor:theBgColor]; 
     } 

     if ([iFieldEditorView drawsBackground] == NO) 
      [iFieldEditorView setDrawsBackground:YES]; 



     NSMutableDictionary *theDict = [[[iFieldEditorView selectedTextAttributes] mutableCopy] autorelease];   
     //NSColor *theSelTextColor = nil; 
     if([iWindow isKeyWindow]) 
     { 
      if ([theDict objectForKey: NSBackgroundColorAttributeName] != [iTheme selectionHighlightActiveColor]) 
      { 
       [theDict setObject: [iTheme selectionHighlightActiveColor] 
         forKey: NSBackgroundColorAttributeName]; 
       //theSelTextColor = [iTheme selectionTextActiveColor]; 
       //kpk why doesn't this work? 
       [theDict setObject: [iTheme selectionTextActiveColor] 
         forKey: NSForegroundColorAttributeName]; 
       [iFieldEditorView setSelectedTextAttributes:theDict]; 
      } 
     } 
     else 
     { 
      if ([theDict objectForKey: NSBackgroundColorAttributeName] != [iTheme selectionHighlightInActiveColor]) 
      { 
       [theDict setObject: [iTheme selectionHighlightInActiveColor] 
          forKey: NSBackgroundColorAttributeName]; 
       //theSelTextColor = [iTheme selectionTextInActiveColor];   
       //kpk why doesn't this work? 
       [theDict setObject: [iTheme selectionTextInActiveColor] 
          forKey: NSForegroundColorAttributeName]; 
       [iFieldEditorView setSelectedTextAttributes:theDict];     
      } 
     } 

/* 
     NSString *theStr = [iFieldEditorView string]; 
     if (!theStr) 
      return; 


     NSUInteger theStrLength = [theStr length]; 
     if (theStrLength > 0) 
      [iFieldEditorView setTextColor: theTextColor 
            range: NSMakeRange(0, theStrLength)]; 

     if(theSelRange.length > 0 && theSelRange.length <= theStrLength || theSelRange.location <= theStrLength && NSMaxRange(theSelRange) <= theStrLength) 
     { 
      [iFieldEditorView setTextColor: theSelTextColor 
            range: [iFieldEditorView selectedRange]]; 
     } 
     else 
     { 

     } 
     */ 


     } 
    } 
    @catch(...) 
    { 
     //VLog::Log(kLogErrorType | kLogNoFlood, @"caught exception in setupFieldEditorColors %@", NSStringFromRange(theSelRange)); 
     NSLog(@"caught exception in setupFieldEditorColors %@", NSStringFromRange(theSelRange)); 
    }  
} 
관련 문제