Started splitting apart xsizing_darwin.m and rearranging objc_darwin.h.

This commit is contained in:
Pietro Gagliardi 2014-08-09 21:34:56 -04:00
parent ea3dd093f7
commit 62938635a2
4 changed files with 57 additions and 49 deletions

View File

@ -3,9 +3,26 @@
#import "objc_darwin.h" #import "objc_darwin.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#define toNSControl(x) ((NSControl *) (x))
#define toNSView(x) ((NSView *) (x)) #define toNSView(x) ((NSView *) (x))
// also good for NSTableView (TODO might not do what we want) and NSProgressIndicator
struct xsize controlPreferredSize(id control)
{
NSControl *c;
NSRect r;
struct xsize s;
c = toNSControl(control);
[c sizeToFit];
r = [c frame];
s.width = (intptr_t) r.size.width;
s.height = (intptr_t) r.size.height;
return s;
}
// TODO verify this when we add more scrolling controls // TODO verify this when we add more scrolling controls
// TODO no borders on Area
id newScrollView(id content) id newScrollView(id content)
{ {
NSScrollView *sv; NSScrollView *sv;

View File

@ -13,6 +13,29 @@
#include <objc/objc.h> #include <objc/objc.h>
#include <objc/runtime.h> #include <objc/runtime.h>
/* Objective-C -> Go types for max safety */
struct xsize {
intptr_t width;
intptr_t height;
};
struct xrect {
intptr_t x;
intptr_t y;
intptr_t width;
intptr_t height;
};
struct xalignment {
struct xrect rect;
intptr_t baseline;
};
struct xpoint {
intptr_t x;
intptr_t y;
};
/* uitask_darwin.m */ /* uitask_darwin.m */
extern id getAppDelegate(void); /* used by the other .m files */ extern id getAppDelegate(void); /* used by the other .m files */
extern BOOL uiinit(void); extern BOOL uiinit(void);
@ -58,6 +81,7 @@ extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
/* tab_darwin.m */ /* tab_darwin.m */
extern id newTab(void); extern id newTab(void);
extern void tabAppend(id, char *, id); extern void tabAppend(id, char *, id);
extern struct xsize tabPreferredSize(id);
/* table_darwin.m */ /* table_darwin.m */
extern id newTable(void); extern id newTable(void);
@ -66,33 +90,14 @@ extern void tableUpdate(id);
extern void tableMakeDataSource(id, void *); extern void tableMakeDataSource(id, void *);
/* control_darwin.m */ /* control_darwin.m */
extern struct xsize controlPreferredSize(id);
extern id newScrollView(id); extern id newScrollView(id);
/* xsizing_darwin.m */ /* xsizing_darwin.m */
struct xsize {
intptr_t width;
intptr_t height;
};
struct xrect {
intptr_t x;
intptr_t y;
intptr_t width;
intptr_t height;
};
struct xalignment {
struct xrect rect;
intptr_t baseline;
};
extern struct xsize controlPreferredSize(id);
extern struct xsize tabPreferredSize(id);
extern struct xalignment alignmentInfo(id, struct xrect); extern struct xalignment alignmentInfo(id, struct xrect);
extern struct xrect frame(id); extern struct xrect frame(id);
/* area_darwin.h */ /* area_darwin.h */
struct xpoint {
intptr_t x;
intptr_t y;
};
extern Class getAreaClass(void); extern Class getAreaClass(void);
extern id newArea(void *); extern id newArea(void *);
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t); extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);

View File

@ -25,3 +25,16 @@ void tabAppend(id t, char *name, id view)
[i setView:toNSView(view)]; [i setView:toNSView(view)];
[toNSTabView(t) addTabViewItem:i]; [toNSTabView(t) addTabViewItem:i];
} }
struct xsize tabPreferredSize(id control)
{
NSTabView *tv;
NSSize s;
struct xsize t;
tv = toNSTabView(control);
s = [tv minimumSize];
t.width = (intptr_t) s.width;
t.height = (intptr_t) s.height;
return t;
}

View File

@ -8,35 +8,7 @@
#define toNSScrollView(x) ((NSScrollView *) (x)) #define toNSScrollView(x) ((NSScrollView *) (x))
#define toNSView(x) ((NSView *) (x)) #define toNSView(x) ((NSView *) (x))
// TODO merge into control_darwin.m or sizing_darwin.m? really need to figure out what to do about the Go-side container struct... // TODO figure out where these should go
// also good for NSTableView (TODO might not do what we want) and NSProgressIndicator
struct xsize controlPreferredSize(id control)
{
NSControl *c;
NSRect r;
struct xsize s;
c = toNSControl(control);
[c sizeToFit];
r = [c frame];
s.width = (intptr_t) r.size.width;
s.height = (intptr_t) r.size.height;
return s;
}
struct xsize tabPreferredSize(id control)
{
NSTabView *tv;
NSSize s;
struct xsize t;
tv = toNSTabView(control);
s = [tv minimumSize];
t.width = (intptr_t) s.width;
t.height = (intptr_t) s.height;
return t;
}
// this function is safe to call on Areas; it'll just return the frame and a baseline of 0 since it uses the default NSView implementations // this function is safe to call on Areas; it'll just return the frame and a baseline of 0 since it uses the default NSView implementations
struct xalignment alignmentInfo(id c, struct xrect newrect) struct xalignment alignmentInfo(id c, struct xrect newrect)
@ -61,6 +33,7 @@ struct xalignment alignmentInfo(id c, struct xrect newrect)
return a; return a;
} }
// TODO remove?
struct xrect frame(id c) struct xrect frame(id c)
{ {
NSRect r; NSRect r;