Converted Window on Mac OS X to use the new container system. Now I can merge container and sizing...
This commit is contained in:
parent
84297ad7e1
commit
6010665415
|
@ -10,6 +10,7 @@ import (
|
|||
import "C"
|
||||
|
||||
type container struct {
|
||||
// TODO rename to id
|
||||
view C.id
|
||||
*sizer
|
||||
}
|
||||
|
@ -27,5 +28,6 @@ func newContainer(child Control) *container {
|
|||
//export containerResized
|
||||
func containerResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
|
||||
c := (*container)(unsafe.Pointer(data))
|
||||
// the origin of a view's content area is always (0, 0)
|
||||
c.resize(0, 0, int(width), int(height))
|
||||
}
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
#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
|
||||
// fornunately:
|
||||
// - NSWindow resizing calls -[setFrameSize:] (but not -[setFrame:])
|
||||
// - NSTab resizing calls both -[setFrame:] and -[setFrameSIze:] on the current tab
|
||||
// - NSTab switching tabs calls both -[setFrame:] and -[setFrameSize:] on the new tab
|
||||
// so we just override setFrameSize:
|
||||
@interface goContainerView : NSView {
|
||||
@public
|
||||
void *gocontainer;
|
||||
|
@ -14,11 +18,12 @@
|
|||
|
||||
@implementation goContainerView
|
||||
|
||||
- (void)setFrame:(NSRect)r
|
||||
- (void)setFrameSize:(NSSize)s
|
||||
{
|
||||
[super setFrame:r];
|
||||
NSLog(@"setFrameSize %@", NSStringFromSize(s));
|
||||
[super setFrameSize:s];
|
||||
if (self->gocontainer != NULL)
|
||||
containerResized(self->gocontainer, (intptr_t) r.size.width, (intptr_t) r.size.height);
|
||||
containerResized(self->gocontainer, (intptr_t) s.width, (intptr_t) s.height);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -23,6 +23,7 @@ extern void issue(void *);
|
|||
/* window_darwin.m */
|
||||
extern id newWindow(intptr_t, intptr_t);
|
||||
extern void windowSetDelegate(id, void *);
|
||||
extern void windowSetContentView(id, id);
|
||||
extern const char *windowTitle(id);
|
||||
extern void windowSetTitle(id, const char *);
|
||||
extern void windowShow(id);
|
||||
|
|
|
@ -15,7 +15,7 @@ type window struct {
|
|||
|
||||
closing *event
|
||||
|
||||
*sizer
|
||||
*container
|
||||
}
|
||||
|
||||
func newWindow(title string, width int, height int, control Control) *window {
|
||||
|
@ -26,11 +26,10 @@ func newWindow(title string, width int, height int, control Control) *window {
|
|||
w := &window{
|
||||
id: id,
|
||||
closing: newEvent(),
|
||||
sizer: new(sizer),
|
||||
container: newContainer(control),
|
||||
}
|
||||
C.windowSetDelegate(id, unsafe.Pointer(w))
|
||||
w.child = control
|
||||
w.child.setParent(&controlParent{C.windowContentView(w.id)})
|
||||
C.windowSetDelegate(w.id, unsafe.Pointer(w))
|
||||
C.windowSetContentView(w.id, w.container.view)
|
||||
return w
|
||||
}
|
||||
|
||||
|
@ -69,11 +68,3 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
|
|||
}
|
||||
return C.NO
|
||||
}
|
||||
|
||||
//export windowResized
|
||||
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
||||
w := (*window)(unsafe.Pointer(xw))
|
||||
// the origin of the window's content area is always (0, 0)
|
||||
w.resize(0, 0, int(width), int(height))
|
||||
fmt.Printf("new size %d x %d\n", width, height)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#define toNSWindow(x) ((NSWindow *) (x))
|
||||
#define toNSView(x) ((NSView *) (x))
|
||||
|
||||
@interface goWindowDelegate : NSObject <NSWindowDelegate> {
|
||||
@public
|
||||
|
@ -19,11 +20,6 @@
|
|||
return windowClosing(self->gowin);
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)n
|
||||
{
|
||||
[self doWindowResize:[n object]];
|
||||
}
|
||||
|
||||
- (void)doWindowResize:(id)win
|
||||
{
|
||||
NSWindow *w;
|
||||
|
@ -69,6 +65,11 @@ void windowSetDelegate(id win, void *w)
|
|||
[toNSWindow(win) setDelegate:d];
|
||||
}
|
||||
|
||||
void windowSetContentView(id win, id view)
|
||||
{
|
||||
[toNSWindow(win) setContentView:toNSView(view)];
|
||||
}
|
||||
|
||||
const char *windowTitle(id win)
|
||||
{
|
||||
return [[toNSWindow(win) title] UTF8String];
|
||||
|
|
Loading…
Reference in New Issue