Began the migration to native Objective-C by moving the NSWindow functions and some of the shared helper routines.
This commit is contained in:
parent
05c71e0d25
commit
f14614c0c7
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
|
||||
// #include "objc_darwin.h"
|
||||
// #include "sysdata_darwin.h"
|
||||
import "C"
|
||||
|
||||
type sysData struct {
|
||||
|
@ -99,16 +100,15 @@ func initWithDummyFrame(self C.id) C.id {
|
|||
}
|
||||
|
||||
func addControl(parentWindow C.id, control C.id) {
|
||||
windowView := C.objc_msgSend_noargs(parentWindow, _contentView)
|
||||
C.objc_msgSend_id(windowView, _addSubview, control)
|
||||
C.addControl(parentWindow, control)
|
||||
}
|
||||
|
||||
func controlShow(what C.id) {
|
||||
C.objc_msgSend_bool(what, _setHidden, C.BOOL(C.NO))
|
||||
C.controlShow(what)
|
||||
}
|
||||
|
||||
func controlHide(what C.id) {
|
||||
C.objc_msgSend_bool(what, _setHidden, C.BOOL(C.YES))
|
||||
C.controlHide(what)
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -122,40 +122,22 @@ const (
|
|||
|
||||
// Button, Checkbox, Combobox, LineEdit, Label, Listbox
|
||||
func applyStandardControlFont(id C.id) {
|
||||
C.objc_setFont(id, _NSRegularControlSize)
|
||||
C.applyStandardControlFont(id)
|
||||
}
|
||||
|
||||
var classTypes = [nctypes]*classData{
|
||||
c_window: &classData{
|
||||
make: func(parentWindow C.id, alternate bool, s *sysData) C.id {
|
||||
const (
|
||||
_NSBorderlessWindowMask = 0
|
||||
_NSTitledWindowMask = 1 << 0
|
||||
_NSClosableWindowMask = 1 << 1
|
||||
_NSMiniaturizableWindowMask = 1 << 2
|
||||
_NSResizableWindowMask = 1 << 3
|
||||
_NSTexturedBackgroundWindowMask = 1 << 8
|
||||
|
||||
_NSBackingStoreBuffered = 2 // the only backing store method that Apple says we should use (the others are legacy)
|
||||
)
|
||||
|
||||
// we have to specify a content rect to start; it will be overridden soon though
|
||||
win := C.objc_msgSend_noargs(_NSWindow, _alloc)
|
||||
win = C.objc_msgSend_rect_uint_uint_bool(win,
|
||||
_initWithContentRect,
|
||||
C.int64_t(0), C.int64_t(0), C.int64_t(100), C.int64_t(100),
|
||||
C.uintptr_t(_NSTitledWindowMask | _NSClosableWindowMask | _NSMiniaturizableWindowMask | _NSResizableWindowMask),
|
||||
C.uintptr_t(_NSBackingStoreBuffered),
|
||||
C.BOOL(C.YES)) // defer creation of device until we show the window
|
||||
win := C.makeWindow()
|
||||
C.objc_msgSend_id(win, _setDelegate, appDelegate)
|
||||
// we do not need setAcceptsMouseMovedEvents: here since we are using a tracking rect in Areas for that
|
||||
return win
|
||||
},
|
||||
show: func(what C.id) {
|
||||
C.objc_msgSend_id(what, _makeKeyAndOrderFront, what)
|
||||
C.windowShow(what)
|
||||
},
|
||||
hide: func(what C.id) {
|
||||
C.objc_msgSend_id(what, _orderOut, what)
|
||||
C.windowHide(what)
|
||||
},
|
||||
settextsel: _setTitle,
|
||||
textsel: _title,
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/* 12 may 2014 */
|
||||
|
||||
//#include "common_darwin.h"
|
||||
|
||||
extern void addControl(id, id);
|
||||
extern void controlShow(id);
|
||||
extern void controlHide(id);
|
||||
extern void applyStandardControlFont(id);
|
||||
extern id makeWindow(void);
|
||||
extern void windowShow(id);
|
||||
extern void windowHide(id);
|
|
@ -0,0 +1,56 @@
|
|||
// 12 may 2014
|
||||
|
||||
//#include "sysdata_darwin.h"
|
||||
#include "objc_darwin.h"
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSCell.h>
|
||||
|
||||
static NSRect dummyRect;// = NSMakeRect(0, 0, 100, 100);
|
||||
|
||||
#define to(T, x) ((T *) x)
|
||||
#define toNSWindow(x) to(NSWindow, x)
|
||||
#define toNSView(x) to(NSView, x)
|
||||
|
||||
void addControl(id parentWindow, id control)
|
||||
{
|
||||
[[toNSWindow(parentWindow) contentView] addSubview:control];
|
||||
}
|
||||
|
||||
void controlShow(id what)
|
||||
{
|
||||
[toNSView(what) setHidden:NO];
|
||||
}
|
||||
|
||||
void controlHide(id what)
|
||||
{
|
||||
[toNSView(what) setHidden:YES];
|
||||
}
|
||||
|
||||
void applyStandardControlFont(id what)
|
||||
{
|
||||
// TODO inline this
|
||||
objc_setFont(what, NSRegularControlSize);
|
||||
}
|
||||
|
||||
id makeWindow(void)
|
||||
{
|
||||
// TODO separate to initilaizer
|
||||
dummyRect = NSMakeRect(0, 0, 100, 100);
|
||||
return [[NSWindow alloc]
|
||||
initWithContentRect:dummyRect
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES]; // defer creation of device until we show the window
|
||||
}
|
||||
|
||||
void windowShow(id window)
|
||||
{
|
||||
[toNSWindow(window) makeKeyAndOrderFront:window];
|
||||
}
|
||||
|
||||
void windowHide(id window)
|
||||
{
|
||||
[toNSWindow(window) orderOut:window];
|
||||
}
|
Loading…
Reference in New Issue