How to redraw NSTableView(NSScrollView) focusring? - cocoa

What function I need to override to draw custom focus ring around NSTableView(or I need to subclass NSScrollView what contains table)? May be there are some examples of custom focus ring drawing?

Related

Xcode - Visually identify custom views in interface builder / storyboard

If you build a custom UIView, and integrate it inside of a parent view/view controller in interface builder, the graphical element representing your custom view is invisible, if you don't specify a background color (I don't).
Is there any way, solely during development, to identify different custom views? Any hacks/tricks to distinguish them?
The closest I could come up with is setting the background color in IB, then removing the background in the implementation of the custom view.
Bounds Rectangles
You might find bounds rectangles useful. You can turn them on by going to the menu bar and choosing Editor > Canvas > Show Bounds Rectangles.
Here's an example. I have a view (a UICollectionViewCell subclass) laid out in a nib. It has a single-line label, a two-line label, and a custom subview. The custom subview itself contains a smaller custom subview. Here's the nib with bounds rectangles off:
Here's the same nib with bounds rectangles on:
Background Color Override
Here's another technique that builds on the idea of setting the background color. This technique requires your deployment target to be iOS 5.0 or later.
As you described, set the background color to make the view visible in the nib:
Then switch to the Identity Inspector and add backgroundColor in the User Defined Runtime Attributes section. Set it to the background color you want the view to have at runtime. For example, if you want it to be white at runtime:
If you want the background color to be clear, you can set backgroundColor to a color with opacity 0, or you can set it to “Nil” instead of any color:
That approach of setting the background color in Interface Builder, but resetting it in code is a simple, but effective technique. Two refinements:
If you have multiple custom views on a single storyboard scene, you can save yourself from having to programmatically clear the background color for all of them individually by using IBOutletCollection. So, in Interface Builder, give them all background colors and then add all of your custom views for a given scene to a collection. You then can set the background color for all of them in a single statement. So, for example, if you have a dozen controls on one scene all in a single IBOutletCollection is named viewsCollection:
#property (strong, nonatomic) IBOutletCollection(UIView) NSArray *viewsCollection;
you can clear the background color of all of them in a single statement:
[self.viewsCollection setValue:[UIColor clearColor] forKey:#"backgroundColor"];
You can also make the identification of your custom views in Interface Builder a little easier by setting the "Label" in the "Document" properties on the "Identity inspector":
Once you've done that, when you look at the document outline in the left side of the main panel, you'll see your labels show up:
Then, using the document outline makes it easier to identify your individual views in the scene. You can use a random label like I did here, or you could use the name of your custom view class, or whatever.

Implementing NSTextInputClient without NSView

I have an application with custom widgets and custom event handling model (I'm rendering in OpenGL). I would like to implement a text edit view taking advantage of Cocoa text input structures, but I don't know how to generate NSEvent objects to pass to NSTextInputContext. In particular, I'm having problems providing a window number, graphic context and mouse cursor coordinates (since i have to provide them in the window's coordinate system). Probably graphic context isn't needed but mouse coordinates are necessary to handle mouse selection events.
Is there any way I can solve this?

Is it posible to use free form shapes as windows in OSX?

I want to use a free form shape (e.g. A partially transparent image) as a window backgound without the standard close and maximise buttons. Like the widgets do. Is that possible in OSX? I could not find any info on that or an app that uses this.
Thanks
Yes. You can do this by subclassing NSWindow to make it borderless and transparent. You'll also subclass NSView to draw the visible custom shape, then use an instance of this view as the window's content view. The result will be a window whose only visible parts will be the shape your content view draws.
Here's a good article with an example.

buttons in interface buider

has anyone an idea if it is possible to create ellipse or polygon buttons in IB?
Directly, not without a library.
You can, however, create an NSView subclass which performs your shape drawing for you. You will need to implement the mouse events to perform clicks correctly. Drop an NSView on your window, set its class in the inspector to your custom-drawn NSView subclass, and you're set. Check out this tutorial.
You could also create a custom control, derived from NSControl. Check out this documentation.

make NSRect selectable

Is there a simple way to create a selectable NSRect in Cocoa? In need a rectangle that can be selected and stays selected after a mouse click.
Thanks.
NSRect is just a struct with a position and size. It's not an object that can actually do anything or have any properties other than a width and height. It sounds like what you want is to create an NSView that can be selected. (Here's Apple's Guide on the subject.)
Though not as immediate as you would like, you may be interested in the management of tracking rectangles and tracking areas performed by NSView class.
This mechanism allows you to define specific areas of your custom view. Then, an event is generated whenever the cursor enters or leaves the area, or a mouse button is pressed in this area (-mouseEntered:, -mouseExited:, -mouseDown:, -mouseUp:, -mouseDragged:, ... of NSResponder class). This up to you to define what you want your application do in response to these events (set the rectangle as selected and display it accordingly).
For an example implementation of this, take a look at the Sketch example included with the Apple developer tools (look in /Developer/Examples/AppKit). Sketch allows the user to create new graphics (including rectangles, but also ovals, lines, and text), select them, move them around in the document, etc. In particular, you'll probably want to look at the SKTGraphic class, which represents a single graphic object in the document, and the SKTGraphicView class, which is an NSView subclass that perform the actual layout and drawing, handling mouse events for dragging views around, etc.

Resources