Switched Tab on Mac OS X to use a dedicated container type system. This container type will eventually be the new home of all the sizer stuff. Now to remove the dedicated NSTabView stuff...

This commit is contained in:
Pietro Gagliardi 2014-08-04 17:03:07 -04:00
parent 39a2414cf9
commit 1ba1f475ba
5 changed files with 79 additions and 13 deletions

31
redo/container_darwin.go Normal file
View File

@ -0,0 +1,31 @@
// 4 august 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type container struct {
view C.id
*sizer
}
func newContainer(child Control) *container {
c := &container{
sizer: new(sizer),
}
c.view = C.newContainerView(unsafe.Pointer(c))
c.child = child
c.child.setParent(&controlParent{c.view})
return c
}
//export containerResized
func containerResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
c := (*container)(unsafe.Pointer(data))
c.resize(0, 0, int(width), int(height))
}

33
redo/container_darwin.m Normal file
View File

@ -0,0 +1,33 @@
// 4 august 2014
#include "objc_darwin.h"
#include "_cgo_export.h"
#include <Cocoa/Cocoa.h>
// calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these
// fortunately, in the case of NSTabView, this -[setFrame:] is called when resizing and when changing tabs, so we can indeed use this directly there
@interface goContainerView : NSView {
@public
void *gocontainer;
}
@end
@implementation goContainerView
- (void)setFrame:(NSRect)r
{
[super setFrame:r];
if (self->gocontainer != NULL)
containerResized(self->gocontainer, (intptr_t) r.size.width, (intptr_t) r.size.height);
}
@end
id newContainerView(void *gocontainer)
{
goContainerView *c;
c = [[goContainerView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
c->gocontainer = gocontainer;
return (id) c;
}

View File

@ -55,7 +55,7 @@ extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
/* tab_darwin.m */
extern id newTab(void *);
extern id tabAppend(id, char *);
extern void tabAppend(id, char *, id);
/* table_darwin.m */
extern id newTable(void);
@ -87,4 +87,7 @@ extern struct xsize areaPrefSize(id);
extern struct xalignment alignmentInfo(id, struct xrect);
extern struct xrect frame(id);
/* container_darwin.m */
extern id newContainerView(void *);
#endif

View File

@ -11,7 +11,7 @@ import "C"
type tab struct {
_id C.id
tabs []*sizer
tabs []*container
}
func newTab() Tab {
@ -21,22 +21,20 @@ func newTab() Tab {
}
func (t *tab) Append(name string, control Control) {
s := new(sizer)
t.tabs = append(t.tabs, s)
c := newContainer(control)
t.tabs = append(t.tabs, c)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
tabview := C.tabAppend(t._id, cname)
s.child = control
s.child.setParent(&controlParent{tabview})
C.tabAppend(t._id, cname, c.view)
}
//export tabResized
func tabResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
t := (*tab)(unsafe.Pointer(data))
for _, s := range t.tabs {
// t := (*tab)(unsafe.Pointer(data))
// for _, c := range t.tabs {
// the tab area's coordinate system is localized, so the origin is (0, 0)
s.resize(0, 0, int(width), int(height))
}
// c.resize(0, 0, int(width), int(height))
// }
}
func (t *tab) id() C.id {

View File

@ -5,6 +5,7 @@
#import <Cocoa/Cocoa.h>
#define toNSTabView(x) ((NSTabView *) (x))
#define toNSView(x) ((NSView *) (x))
@interface goTabView : NSTabView {
@public
@ -35,12 +36,12 @@ id newTab(void *gotab)
return (id) t;
}
id tabAppend(id t, char *name)
void tabAppend(id t, char *name, id view)
{
NSTabViewItem *i;
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
[i setLabel:[NSString stringWithUTF8String:name]];
[i setView:toNSView(view)];
[toNSTabView(t) addTabViewItem:i];
return (id) [i view];
}