• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Separation of TextFieldCell and TextField subclasses
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Separation of TextFieldCell and TextField subclasses


  • Subject: Re: Separation of TextFieldCell and TextField subclasses
  • From: Stéphane Sudre <email@hidden>
  • Date: Fri, 21 Mar 2003 19:13:41 +0100

On Friday, March 21, 2003, at 06:42 PM, Prachi Gauriar wrote:

Hi. I'm working on a subclass of NSTextFieldCell and NSTextField to work like the search text fields in Mail or Safari for academic purposes. I've seen other implementations of these, but I really wanted to write one myself with a proper separation of the cell and control objects. I was thinking of implementing them as follows:

SearchTextFieldCell
Subclasses NSTextFieldCell and implements methods regarding the text editing itself, like -resetCursorRects, -drawInFrame:withView:, etc. I'd like it to be completely independent of SearchTextField.

SearchTextField
Contains SearchTextFieldCell, an NSButtonCell (for the cancel button), and an NSPopupButtonCell (for the magnifying glass and its menu). This is what the programmer would interface with. Also, this object would handle the placement and drawing of the SearchTextFieldCell, NSButtonCell, and NSPopupButtonCell. I think I'll probably have delegate methods that perform the search and/or cancel methods.

I don't understand the reason why you want to subclass NSTextField into SearchTextFieldCell if the SearchTextField control is going to implement the popup and cancel button using other cells. The goal of having a subclass cell would be to have a cell that is doing everything the SearchTextField is doing/displaying. Otherwise, what you're going to do is to rewrote the NSTextFieldCell and adding it no value.

If you're looking for supporting the same look & feel that the Mail.app search text field, what you will have to do is to implement the mouseDown: method and check whether the click is occurring in the textfield cell, the pop-up or the button (to be able to draw the focus) and then call the cell method to handle the click. Looks like implementing the whole thing without the 2 additional cells.

Other issue : the background. How are you going to draw the background in this situation? At first sight, it looks like the background is going to be drawn by the Control (there's another solution but that won't work with the NSButton and the NSPopUpButton background). So the custom cell is no more responsible for drawing the background and so it's not able again to implement one of the drawing of the control.

For the search method, you can just link to the control:textDidChange: method and use the performSelector:withDelay: methods to get the Mail.app behavior.

Does this seem like a good approach? I've never written a UI widget that actually was separated into a cell and an actual object, and I wanted to get it right. Any help would be appreciated.

An implementation with one NSTextField subclass is available here:

http://s.sudre.free.fr/Software/DevPotPourri.html

IIRC it's in the JCKit that there's an implementation like the one you're looking for but the Control is just using one cell.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Separation of TextFieldCell and TextField subclasses (From: Prachi Gauriar <email@hidden>)

  • Prev by Date: Re: object instance names generated on the fly?
  • Next by Date: Re: Proper way to run runloop for DO server?
  • Previous by thread: Separation of TextFieldCell and TextField subclasses
  • Next by thread: Location and Size of Main Menu --- Are They Defined Anywhere
  • Index(es):
    • Date
    • Thread