CPToolbar renders in the CPBorderlessBridgeWindowMask window only - cappuccino

I tried to add the custom toolbar to my application. To locate it at the bottom of the window I created one more window and added the toolbar to it:
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView],
bounds = [contentView bounds];
[contentView setBackgroundColor:[CPColor colorWithHexString:#"cecece"]];
///second window to place the toolbar at the bottom
var w2 = [[CPPanel alloc] initWithContentRect:CGRectMake(0, CGRectGetHeight(bounds) - _settings.toolbarSize,
CGRectGetWidth(bounds), _settings.toolbarSize)
styleMask: CPBorderlessWindowMask]
var c2 = [w2 contentView]
[c2 setBackgroundColor:[CPColor colorWithHexString:#"ff0000"]];
///a toolbar
toolbar = [[Toolbar alloc] initWithWindow:w2];
///show window
[theWindow orderFront:self];
[w2 orderFront:self];
It worked properly with the Cappuccino 0.8.1 but does not with the latest one. Only if I either set toolbar for theWindow or init w2 with CPBorderlessBridgeWindowMask it renders as needed.
Does anyone have any idea what is the reason of this behavior?

Related

My NSScrollView is not scrolling my NSTextView (document)

So I've been burned by this a few times. I'm trying to create an NSTextView that can be scrolled.
The only way I've gotten it to work is by having a Xib—but right now that stopped working after I added a Stack View in an adjacent Split View for God-knows-what-reason.
So what have I done?
I have code for code copied down the Apple Docs like for Text in Scroll View like so:
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextUILayer/Tasks/TextInScrollView.html
BOOL deviateFromAppleScrollDoc = NO;
_scrollView = [[NSScrollView alloc]
initWithFrame:[[self view] frame]];
// Apple Has
// [[theWindow contentView] frame]];
// but we are in a sub-View-Controller
NSSize contentSize = [_scrollView contentSize];
[_scrollView setBorderType:NSNoBorder];
[_scrollView setHasVerticalScroller:YES];
[_scrollView setHasHorizontalScroller:NO];
[_scrollView setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable];
_editorView = [[EditorView alloc]
initWithFrame:NSMakeRect(
0, 0,
contentSize.width, contentSize.height)];
[_editorView setMinSize:NSMakeSize(0.0, contentSize.height)];
[_editorView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[_editorView setVerticallyResizable:YES];
[_editorView setHorizontallyResizable:NO];
if (deviateFromAppleScrollDoc)
{
[_editorView setAutoresizesSubviews:YES];
[_editorView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
}
else
{
[_editorView setAutoresizingMask:NSViewWidthSizable];
}
[[_editorView textContainer]
setContainerSize:NSMakeSize(contentSize.width, FLT_MAX)];
[[_editorView textContainer] setWidthTracksTextView:YES];
if (deviateFromAppleScrollDoc)
{
[[_editorView textContainer] setHeightTracksTextView:YES];
}
if (deviateFromAppleScrollDoc)
{
NSClipView *clipView = [[NSClipView alloc] init];
[clipView setDocumentView:_editorView];
[_scrollView setContentView:clipView];
}
else
{
[_scrollView setDocumentView:_editorView];
}
[[self view] addSubview:_scrollView];
What does that get me?
As you can tell, there is an NSTextView. It does not fill the Container as I would like it to.
There is also a Scroll View and I can tell it is active. You can pull down and get a rebound effect—but it does not scroll the document as I would like. This text is cut off mid-sentence and when I add to it, the View does not scroll with my typing—and even if I scroll I can't get to it.
The Scroll View is "stuck".
I can make it fill the entire window if I change the Autoresizing mask to inlcude NSViewHeightSizable like so:
[_editorView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
See here:
Unfortunatley, it still does not scroll and the "Scroll View" is still "Stuck".
I don't know what to change.
I have tried to add a "NSClipView" and set the Content View instead like so:
NSClipView *clipView = [[NSClipView alloc] init];
[clipView setDocumentView:_editorView];
[_scrollView setContentView:clipView];
This does not work either.
Moreover it does something funky to the width and some of the letters get cut off. Not acceptable. No solution yet.
What am I missing?
What do I need to try / set / do?
Thank you!
UPDATE:
The Scroll View does scroll the document when I activate the find menu in the NSTextView.
Still mystified.
See here:

NSTabView styled like iTunes for Yosemite

I'm trying to build an NSTabView styled in the same way as it is in this NSPanel/NSWindow in iTunes. this pops up when you edit a track.
When I add NSTabview, it appears with a tinted and bordered rect
I've tried everything I can think of to remove this rect, or set it to transparent. Has any one found a solution to this? Any pointers in the right direction would be extremely helpful.
You can create a tabless NSTabView and then you can add a NSSegmentedControl to select the active tab.
here's a programmatic solution for anyone interested:
- (void)createViews {
// tabview
self.tabView = [NSTabView new];
self.tabView.tabViewType = NSNoTabsNoBorder;
self.tabView.controlSize = NSRegularControlSize;
// tabview items
self.detailsTabItemView = [BPBaseView new];
NSTabViewItem *detailItem = [NSTabViewItem new];
detailItem.view = self.detailsTabItemView;
self.artworkTabItemView = [BPBaseView new];
self.artworkTabItemView.backgroundColor = [NSColor colorWithHex:BPCharcoalLight];
NSTabViewItem *artworkItem = [NSTabViewItem new];
artworkItem.view = self.artworkTabItemView;
[self.tabView addTabViewItem:detailItem];
[self.tabView addTabViewItem:artworkItem];
// segment control
self.segmentControl = [NSSegmentedControl new];
self.segmentControl.segmentCount = 2;
[self.segmentControl setLabel:#"Details" forSegment:0];
[self.segmentControl setLabel:#"Artwork" forSegment:1];
self.segmentControl.action = #selector(segmentControlClicked:);
self.segmentControl.selectedSegment = 0;
[self segmentControlClicked:self.segmentControl]; // force first view to show
// add views
[self.bottomContainerView addSubview:self.segmentControl];
[self.bottomContainerView addSubview:self.tabView];
}
- (void)segmentControlClicked:(id)segmentControl{
NSInteger index = [segmentControl selectedSegment];
[self.tabView selectTabViewItemAtIndex:index];
}

Programmatically add a close button to an NSWindow

I'd like to add a close button to an NSWindow programmatically. I can get the button to display, but there are no mouse-over or mouse-down effects. My "selector" never seems to get called when i click the button. I'm not really sure whats wrong and why this is so annoying.
Here is what I've been messing with:
closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:self.styleMask];
NSView *themeFrame = [[self contentView] superview];
NSRect c = [themeFrame frame]; // c for "container"
NSRect aV = [closeButton frame]; // aV for "accessory view"
NSRect newFrame = NSMakeRect( c.size.width - aV.size.width - 5, // x position c.size.height - aV.size.height - 5, // y position aV.size.width, // width aV.size.height); // height
[closeButton setFrame:newFrame];
[themeFrame addSubview:closeButton];
[closeButton setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
[closeButton setEnabled:YES];
[closeButton setTarget:self];
[closeButton setAction:NSSelectorFromString(#"testClick:") ];
Where "testClick" is just a memeber function of my class and is defined as such:
- (void)testClick:(id)sender
The problem seems to be the call to:
[themeFrame addSubview:closeButton];
where the themeFrame is: [[self contentView] superview] Just adding the button to [self contentView] works, but I'd like it added to the titlebar.
No Interface Builder please...
Potential issue # 1)
The way you're calling "NSSelectorFromString" seems incorrect to me. I don't think you can pass parameters via this way in Objective C.
Try this:
[closeButton setAction: #selector(closeWindow:)];
and create a new "closeWindow:" action that looks like:
- (void) closeWindow: (id) sender;
which closes the window.
Potential issue # 2)
Instead of:
closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:self.styleMask];
NSView *themeFrame = [[self contentView] superview];
Why not use:
NSWindow * parentWindow = [[self contentView] window];
if(parentWindow)
{
closeButton = [parentWindow standardWindowButton:NSWindowCloseButton forStyleMask:self.styleMask];
}

uibutton font subclass

I have the following method in my UIButton class:
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
self.titleLabel.font = [UIFont fontWithName:#"Chalkduster" size:16];
self.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
self.titleLabel.textColor = [UIColor greenColor];
}
return self;
}
Works great except I can't see the border around the button: any ideas why? What do I have to do extra to make the button border show?
Thank you
Do not subclass button do everything in IB it would be more better. This is how You can achieve what you want:
Select button -> go to Attributes Inspector -> Type -> select Rounded Rect. That will give You default button look.
Then select font (Press on T Letter) like this:
Also select text color behind Font.
Result:
EDIT:
Create button programmatically:
//create the button with RoundedRect type
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//set the position of the button
button.frame = CGRectMake(100, 150, 100, 30);
//set the button's title
[button setTitle:#"Click Me!" forState:UIControlStateNormal];
//set the button's font
button.titleLabel.font = [UIFont fontWithName:#"Chalkduster" size:16];
//set the button's line break mode
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
//set the button's text color
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
//button.titleLabel.textColor = [UIColor greenColor]; // don't use this because button's text color after clicking it will be blue (default).
//add the button to the view
[self.view addSubview:button];
Result:
Note: Do not use textColor because Your text color after clicking the button will be default blue.

Changing the titlebar height in an NSPanel

I'm trying to change the titlebar height of an NSPanel. I tried the following but it didn't work as expected:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSRect f = [[[window contentView] superview] frame];
f.size.height += 10;
[[window contentView] superview].frame = f;
}
You can't change the height of a window's title bar. It's fixed by the framework. If you want a window with a custom appearance you'll need to create a window using the NSBorderlessWindowMask style mask and then draw your own title bar and widgets.

Resources