Cocoa / Interface Builder: What do I need to subclass to replicate this window? - objective-c

I'm guessing it is using a custom NSWindow, NSTextField, NSSecureTextField, NSButton? I don't necessarily want to replicate it, I would just like to know what would be involved in customizing my app's UI to this level.

The window itself could be a HUD-style panel, which you can get in IB without subclassing anything. It looks like there's a bit of custom background to it, unless it's just faintly showing something behind it; if it is a custom background, a custom view as the content view could do that job.
The separator could be an image view or a custom view.
The static text fields can be done without subclassing. Just change the text color.
The editable text fields, both the regular one and the secure one, you would need to subclass. I have no idea how you would do that.
The follow-link button is a mix of custom drawing and a standard image. Start with the NSImageNameFollowLinkFreestandingTemplate image; draw that, then fill an empty path with white using the source-in blend mode.
The other two buttons are customized, probably using custom cells in order to override the background without overriding the text drawing.

Related

how to set default font and font style in cocoa app?

My app has all different kind of NSViews, including NSTabView, NSButton, NSTextField, NSPopupButton and so on.
I would like to change all display text to a certain font and with certain font style.
is there anyway to set the default font and font style in cocoa app?
I have tried:
How to loop through subviews in order to get the text of NSTextViews
however it doesn't work with NSTabView and NSButton.
I think that there must be an easy to do so, it's just I don't know what it is.
Please advise.
There isn't a built in way to do this (ie. by setting a key in Info.plist). You really do need to go through all the controls in your app, one way or another, and set a custom font for them. There are a few possible approaches. One is to use a custom subclass for all the controls for which you need to use a custom font. The subclass can be really minimal, it just needs to set the correct font upon initialization, possibly preserving other font attributes (size, color, etc.) setup in Interface Builder. Another option is to do as you've suggested and go through each subview in your app, check to see if it responds to -setFont:, and set your custom font if it does. I've used the first approach (subclass) with good success.

How can I add NSTextView and NSMatrix controls in a single scrollable NSScrollView?

I am new to Mac development.
I want to add three controls in a single Scrollable NSScrollView.
1) NSTextView.
2) NSMatrix.
3) NSTextView.
Please note that text in nstextview can be of dynamic height.... and there should be no scroll for textviews.
here is a screenshot of what I am looking for -
how can I add these three views in nsscrollview? Please help!
Update 1 - can I add these controls in a NSView?
I'll assume you've got a project in Xcode 4 started. Select your project's MainMenu.xib file to begin editing your main user interface.
Start with a window. Drag a custom view into it. Add your text view to the custom view, followed by the matrix, followed by another text view, sizing the views as you go. It's at this point that you also can configure your text views not to display scroll bars. Next, select the custom view. Embed it in a scroll view, and there you are.
The window, custom view, text views, and matrix are selected from Xcode 4's Object Library palette. To embed, choose the Embed/Scroll View command from the Editor menu.
As for the dynamic sizing, you'll have to code for changing the heights of the text views, and so the height of the enclosing custom view. (That is an exercise I leave to you.) Your burden can be lessened somewhat by taking advantage of autosizing to maintain the proper spacing between the three UI elements; you can do this either in Xcode 4, or you can do it using NSView's relevant instance methods.
Good luck to you in your endeavors.

Creating custom combination of widget in Cocoa

I have seen that in Cocoa I can create a custom view using drawing primitives which allows me to draw what I like but at a very low level.
Instead I'd like to create custom widgets using a combination of existing controls. For example:
I'd like to create a table with images and combobox in cells
I'd like to create a custom widget wich is a combination of several (for example a list, a button and combobox)
How can I approach this problem ?
Secondly a typical cocoa developer uses external controls? Is there a repository or a list of interesting external custom controls (commercial or free) ?
I'd like to create a table with images and combobox in cells
There already exists NSImageCell and NSComboBoxCell. Are you sure you need to do anything different?
If the problem is that you want an image and a combo box in the same cell, you will have to subclass NSCell. Currently table views can only contain cells, not views, which makes your life harder (as understanding how cell drawing works is more difficult). That will change in Lion, however, so if you can wait until then, this will become easier!
I'd like to create a custom widget wich is a combination of several (for example a list, a button and combobox)
How is your custom widget different to just placing those three things in the same view?
You could write your own NSView subclass. When it's created, it should create a list, a button and a combobox and add them as subviews to itself. Your NSView subclass should handle the logic of keeping them in sync or doing whatever it is you want them to do. Then, to use this combination control in Interface Builder, you place a Custom View and set its class (rightmost tab of the inspector) to your NSView subclass.
BTW, on a tangent, are you sure you mean combobox? Loads of people coming from Windows get this one wrong. A combobox is a combination of a menu and a text field: it allows the user to enter custom text that is not in the menu. If you just want a dropdown menu of choices (and the user can't enter a custom one), you use an NSPopupButton.
Secondly a typical cocoa developer uses external controls?
Yes, sometimes. Things like BWToolkit can be very useful. There's a lot more that are just floating around mailing lists as code snippets, rather than being cleaned up and put in a library. Search for what you need to do!

Looking for a vertical NSToolBar lookalike

I'm looking for an NSToolBar type of object to use in my application. I need it to be vertical and to look nice. The buttons on the object do not need to be repositioned or customizable like the NSToolBar it, but I would like the same look and feel the NSToolBar has, just vertical.
I've tried the google route, but I'm not really sure what to search for when it comes to looking for obj-c objects or examples.
I know seeing as what I want is basically a static set of buttons along the side of my window I could just use a bunch of buttons, but it doesn't have the nice seamless look that the NSToolBar does.
Is there something out there similar to what I'm looking for? Is there a repository of obj-c objects or a nice collection of them on a site that I'm just not finding?
It wouldn't have much in the way of functionality, but if you check the 'Textured' box (under 'Appearance') in Interface Builder of an NSWindow, it will make the whole window look like a toolbar. Dropping a well-placed NSBox (set to 'Custom', and with a fill color of the background of a window-or-so) on top of the window leaving only a strip for what would look like a toolbar, you would have a visual approximation, although without any functionality of an NSToolbar whatsoever. Buttons would all have to be done manually, etc, etc.
However, I must caution you that this sounds like a major violation of the HIG. If you are trying to make something twitterish, I won't dissuade you, but it is a sort of crosroads there's no need to cross until Apple decides which path it is going to take.
The toolbar itself wouldn't be too tricky, but if you wanted to allow customization, that would be tricky. Since you didn't mention customization (or showing/hiding) all you really want is a vertical bar of buttons and a background color that matches the window color.
Make your window a textured window, using NSTexturedWindowMask, then create a subclass of NSView with the dimensions you want, drawing its background to match the window background color.
-(void)drawRect:(NSRect)dirtyRect {
[[[self window] backgroundColor] set];
NSRectFill(dirtyRect);
}
The buttons will just be subviews of this view.
Like I say, customization and showing/hiding make this is much harder task to achieve.

How can I remove the "blur" effect that Cocoa adds to transparent sheets?

By default, Cocoa adds a background blur effect to transparent and semitransparent modal sheets when they are applied to a window. I would like to disable the blur effect. How would I go about doing it?
I have created a custom sheet (a subclass of NSWindow with a transparent background and some controls in it). I am able to display it using the standard beginSheet method as follows:
[NSApp beginSheet:myCustomSheet
modalForWindow:mainWindow
modalDelegate:self
didEndSelector:...];
The sheet displays fine, but everything behind it is blurred.
Note 1: I am writing a completely customized user interface for a touch screen / kiosk type app, so none of the usual Apple user interface guidelines apply.
Note 2: I do want to see what is underneath the sheet. As SirRatty pointed out, it is possible to block out the blurred portion by filling in the background. In my case, I want to have the background show through, just without appearing blurred.
There's a private API call that can be used to set a CI filter on the background of a window:
http://www.mail-archive.com/cocoa-dev#lists.apple.com/msg16280.html
There's also a CGSRemoveWindowFilter:
extern CGError CGSRemoveWindowFilter(CGSConnectionID cid, CGSWindowID wid, CGSWindowFilterRef filter);
Just be aware that the usual private API caveats apply (might go away or change in the future, etc.).
What I've done:
In IB, add a window-sized custom NSView to the window, at the bottom of the content view hierarchy. Set the object's class to MySolidView (or whatever.)
In Xcode, the MySolidView class does just one thing: on -drawRect it will fill the view with a solid color. (e.g. light grey).
You could write your own sheet animation routines that display your own NSWindow and fill the background of the window with a semitransparent colour. I'm not sure whether setAlphaValue: for NSWindow will also affect the child elements' opacity. If it does affect them, you could use setBackgroundColor: and provide the default window background colour but with an alpha component, this should not affect the child elements.
I suppose one of the problems of developing/designing your own user interface is when you have to reimplement the wheel just for a minor customisation. At least, if you write it yourself, you'll have more control over its customisation in the future.