changeset 844:5103d132c3cd

Implemented dw_scrollbox_get_range() and dw_scrollbox_get_pos() on the Mac.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 29 Mar 2011 23:25:20 +0000
parents d51e958aad95
children 7331b7c9f1c9
files mac/dw.m
diffstat 1 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Mar 29 23:04:32 2011 +0000
+++ b/mac/dw.m	Tue Mar 29 23:25:20 2011 +0000
@@ -2613,13 +2613,11 @@
     return groupbox;
 }
 
-#ifndef INCOMPLETE
 /*
  * Create a new scrollable Box to be packed.
  * Parameters:
  *       type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
  *       pad: Number of pixels to pad around the box.
- * This works fine under GTK+, but is incomplete on other platforms
  */
 HWND API dw_scrollbox_new( int type, int pad )
 {
@@ -2644,9 +2642,27 @@
  */
 int API dw_scrollbox_get_pos(HWND handle, int orient)
 {
-   int val = -1;
-   NSLog(@"dw_scrollbox_get_pos() unimplemented\n");
-   return val;
+    DWScrollBox *scrollbox = handle;
+    NSView *view = [scrollbox documentView];
+    NSSize contentsize = [scrollbox contentSize];
+    NSScroller *scrollbar;
+    int range = 0;
+    int val = 0;
+    if(orient == DW_VERT)
+    {
+        scrollbar = [scrollbox verticalScroller];
+        range = [view bounds].size.height - contentsize.height;
+    }
+    else
+    {
+        scrollbar = [scrollbox horizontalScroller];
+        range = [view bounds].size.width - contentsize.width;
+    }
+    if(range > 0)
+    {
+        val = [scrollbar floatValue] * range;
+    }
+    return val;
 }
 
 /*
@@ -2657,11 +2673,19 @@
  */
 int API dw_scrollbox_get_range(HWND handle, int orient)
 {
-   int val = -1;
-   NSLog(@"dw_scrollbox_get_range() unimplemented\n");
-   return val;
-}
-#endif
+    DWScrollBox *scrollbox = handle;
+    NSView *view = [scrollbox documentView];
+    int range = 0;
+    if(orient == DW_VERT)
+    {
+        range = [view bounds].size.height;
+    }
+    else
+    {
+        range = [view bounds].size.width;
+    }
+    return range;
+}
 
 /*
  * Pack windows (widgets) into a box from the end (or bottom).