summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-09 21:34:56 -0400
committerPietro Gagliardi <[email protected]>2014-08-09 21:34:56 -0400
commit62938635a2a6c5d614a890131483c57e1482d1fd (patch)
tree01fd66f1ff5e3506b7300663fb80690cc71b0c59
parentea3dd093f7941cfc74af085fffc8e3f24b2ce0d5 (diff)
Started splitting apart xsizing_darwin.m and rearranging objc_darwin.h.
-rw-r--r--redo/control_darwin.m17
-rw-r--r--redo/objc_darwin.h45
-rw-r--r--redo/tab_darwin.m13
-rw-r--r--redo/xsizing_darwin.m31
4 files changed, 57 insertions, 49 deletions
diff --git a/redo/control_darwin.m b/redo/control_darwin.m
index a939583..f34f3c2 100644
--- a/redo/control_darwin.m
+++ b/redo/control_darwin.m
@@ -3,9 +3,26 @@
#import "objc_darwin.h"
#import <Cocoa/Cocoa.h>
+#define toNSControl(x) ((NSControl *) (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 no borders on Area
id newScrollView(id content)
{
NSScrollView *sv;
diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h
index 79d1e04..f92f7b5 100644
--- a/redo/objc_darwin.h
+++ b/redo/objc_darwin.h
@@ -13,6 +13,29 @@
#include <objc/objc.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 */
extern id getAppDelegate(void); /* used by the other .m files */
extern BOOL uiinit(void);
@@ -58,6 +81,7 @@ extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
/* tab_darwin.m */
extern id newTab(void);
extern void tabAppend(id, char *, id);
+extern struct xsize tabPreferredSize(id);
/* table_darwin.m */
extern id newTable(void);
@@ -66,33 +90,14 @@ extern void tableUpdate(id);
extern void tableMakeDataSource(id, void *);
/* control_darwin.m */
+extern struct xsize controlPreferredSize(id);
extern id newScrollView(id);
/* 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 xrect frame(id);
/* area_darwin.h */
-struct xpoint {
- intptr_t x;
- intptr_t y;
-};
extern Class getAreaClass(void);
extern id newArea(void *);
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
diff --git a/redo/tab_darwin.m b/redo/tab_darwin.m
index 7fef7a0..1c2920a 100644
--- a/redo/tab_darwin.m
+++ b/redo/tab_darwin.m
@@ -25,3 +25,16 @@ void tabAppend(id t, char *name, id view)
[i setView:toNSView(view)];
[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;
+}
diff --git a/redo/xsizing_darwin.m b/redo/xsizing_darwin.m
index 84d83f2..56c55b4 100644
--- a/redo/xsizing_darwin.m
+++ b/redo/xsizing_darwin.m
@@ -8,35 +8,7 @@
#define toNSScrollView(x) ((NSScrollView *) (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...
-
-// 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;
-}
+// TODO figure out where these should go
// 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)
@@ -61,6 +33,7 @@ struct xalignment alignmentInfo(id c, struct xrect newrect)
return a;
}
+// TODO remove?
struct xrect frame(id c)
{
NSRect r;