changeset 676:9861d264925d

MLE was missing the scrollbar. Fixes for getting and setting the position. However it still currently does not work until the window is shown.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 01 Mar 2011 04:37:11 +0000
parents 48f8efba898f
children 99002595f549
files dw.h mac/dw.m
diffstat 2 files changed, 68 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Mon Feb 28 08:27:53 2011 +0000
+++ b/dw.h	Tue Mar 01 04:37:11 2011 +0000
@@ -304,7 +304,7 @@
    HWND handle;
 } *HPIXMAP;
 
-#define DW_DT_LEFT               0
+#define DW_DT_LEFT               0 /* NSLeftTextAlignment */
 #define DW_DT_QUERYEXTENT        0
 #define DW_DT_UNDERSCORE         0
 #define DW_DT_STRIKEOUT          0
@@ -312,7 +312,7 @@
 #define DW_DT_EXTERNALLEADING    0
 #define DW_DT_CENTER             2 /* NSCenterTextAlignment */
 #define DW_DT_RIGHT              1 /* NSCenterTextAlignment */
-#define DW_DT_TOP                0 /* NSLeftTextAlignment */
+#define DW_DT_TOP                0 
 #define DW_DT_VCENTER            0
 #define DW_DT_BOTTOM             0
 #define DW_DT_HALFTONE           0
--- a/mac/dw.m	Mon Feb 28 08:27:53 2011 +0000
+++ b/mac/dw.m	Tue Mar 01 04:37:11 2011 +0000
@@ -2566,7 +2566,16 @@
 HWND API dw_mle_new(ULONG id)
 {
 	DWMLE *mle = [[DWMLE alloc] init];
-	return mle;
+    NSScrollView *scrollview  = [[NSScrollView alloc] init];    
+    
+    //[mle setScrollview:scrollview];
+    [scrollview setBorderType:NSBezelBorder];
+    [scrollview setHasVerticalScroller:YES];
+    [scrollview setAutohidesScrollers:YES];
+    [scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
+    [scrollview setDocumentView:mle];
+    [mle setAutoresizingMask:NSViewWidthSizable];
+	return scrollview;
 }	
 
 /*
@@ -2578,7 +2587,8 @@
  */
 unsigned int API dw_mle_import(HWND handle, char *buffer, int startpoint)
 {
-	DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
     NSTextStorage *ts = [mle textStorage];
     NSString *nstr = [NSString stringWithUTF8String:buffer];
     NSMutableString *ms = [ts mutableString];
@@ -2596,7 +2606,8 @@
  */
 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length)
 {
-	DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
     NSTextStorage *ts = [mle textStorage];
     NSMutableString *ms = [ts mutableString];
     strncpy(buffer, [ms UTF8String], length);
@@ -2611,7 +2622,8 @@
  */
 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines)
 {
-	DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
     NSTextStorage *ts = [mle textStorage];
     NSMutableString *ms = [ts mutableString];
     
@@ -2628,7 +2640,8 @@
  */
 void API dw_mle_delete(HWND handle, int startpoint, int length)
 {
-	DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
     NSTextStorage *ts = [mle textStorage];
     NSMutableString *ms = [ts mutableString];
     [ms deleteCharactersInRange:NSMakeRange(startpoint+1, length)];
@@ -2641,7 +2654,8 @@
  */
 void API dw_mle_clear(HWND handle)
 {
-	DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
     NSTextStorage *ts = [mle textStorage];
     NSMutableString *ms = [ts mutableString];
     NSUInteger length = [ms length];
@@ -2667,7 +2681,8 @@
  */
 void API dw_mle_set_editable(HWND handle, int state)
 {
-	DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
 	if(state)
 	{
 		[mle setEditable:YES];
@@ -2686,7 +2701,8 @@
  */
 void API dw_mle_set_word_wrap(HWND handle, int state)
 {
-    DWMLE *mle = handle;
+    NSScrollView *sv = handle;
+	DWMLE *mle = [sv documentView];
     if(state)
     {
         [mle setHorizontallyResizable:NO];
@@ -3824,7 +3840,17 @@
 void API dw_splitbar_set(HWND handle, float percent)
 {
 	DWSplitBar *split = handle;
-	[split setPosition:percent ofDividerAtIndex:0];
+    NSRect rect = [split frame];
+    float pos;
+    if([split isVertical])
+    {
+        pos = rect.size.height * (percent / 100.0);
+    }
+    else
+    {
+        pos = rect.size.width * (percent / 100.0);
+    }
+	[split setPosition:pos ofDividerAtIndex:0];
 }
 
 /*
@@ -3834,8 +3860,27 @@
  */
 float API dw_splitbar_get(HWND handle)
 {
-	NSLog(@"dw_splitbar_get() unimplemented\n");
-	return 0.0;
+	DWSplitBar *split = handle;
+    NSRect rect1 = [split frame];
+    NSArray *subviews = [split subviews];
+    NSView *view = [subviews objectAtIndex:0];
+    NSRect rect2 = [view frame];
+    float pos, total, retval = 0.0;
+    if([split isVertical])
+    {
+        total = rect1.size.height;
+        pos = rect2.size.height;
+    }
+    else
+    {
+        total = rect1.size.width;
+        pos = rect2.size.width;
+    }
+    if(total > 0)
+    {
+        retval = pos / total;
+    }
+	return retval;
 }
 
 /*
@@ -5319,6 +5364,11 @@
 void dw_window_set_data(HWND window, char *dataname, void *data)
 {
 	id object = window;
+    if([object isMemberOfClass:[NSScrollView class]])
+    {
+        NSScrollView *sv = window;
+        object = [sv documentView];
+    }
 	WindowData *blah = (WindowData *)[object userdata];
 	
 	if(!blah)
@@ -5351,6 +5401,11 @@
 void *dw_window_get_data(HWND window, char *dataname)
 {
 	id object = window;
+    if([object isMemberOfClass:[NSScrollView class]])
+    {
+        NSScrollView *sv = window;
+        object = [sv documentView];
+    }
 	WindowData *blah = (WindowData *)[object userdata];
 	
 	if(blah && blah->root && dataname)