changeset 2822:0adf73d5d8c2

iOS: First steps for implmenting container modes on iOS and eventually Android. Added DW_FEATURE_CONTAINER_MODE with the following possible states on mobile platforms: DW_CONTAINER_MODE_DEFAULT, DW_CONTAINER_MODE_EXTRA and DW_CONTAINER_MODE_MULTI.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 04 Aug 2022 19:12:19 +0000
parents 3731f21dd678
children b1ff739d0dbc
files dw.h ios/dw.m
diffstat 2 files changed, 46 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Tue Aug 02 08:52:13 2022 +0000
+++ b/dw.h	Thu Aug 04 19:12:19 2022 +0000
@@ -1658,6 +1658,12 @@
 #define DW_DARK_MODE_FULL     2
 #define DW_DARK_MODE_FORCED   3
 
+/* Mobile alternate container modes */
+#define DW_CONTAINER_MODE_DEFAULT 0    /* Displays only the main column on mobile platforms */
+#define DW_CONTAINER_MODE_EXTRA   1    /* Displays the main column, and the rest on a second line */
+#define DW_CONTAINER_MODE_MULTI   2    /* Displays every display column on a separate line plus buttons */
+#define DW_CONTAINER_MODE_MAX     3
+
 /* Application ID support lengths */
 #define _DW_APP_ID_SIZE 100
 
@@ -1827,6 +1833,7 @@
     DW_FEATURE_TASK_BAR,                /* Supports icons in the taskbar or similar system widget */
     DW_FEATURE_TREE,                    /* Supports the Tree Widget */
     DW_FEATURE_WINDOW_PLACEMENT,        /* Supports arbitrary window placement */
+    DW_FEATURE_CONTAINER_MODE,          /* Supports alternate container view modes */
     DW_FEATURE_MAX
 } DWFEATURE;
 
--- a/ios/dw.m	Tue Aug 02 08:52:13 2022 +0000
+++ b/ios/dw.m	Thu Aug 04 19:12:19 2022 +0000
@@ -280,6 +280,7 @@
 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED;
+static int _dw_container_mode = DW_CONTAINER_MODE_DEFAULT;
 static CGPoint _dw_event_point = {0};
 static NSMutableArray *_dw_toplevel_windows;
 
@@ -2329,12 +2330,20 @@
 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
 @end
 
- /* TODO: UITableView does not support variable columns...
-  * also OutlineView does not exist in iOS.
-  */
-UITableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text)
-{
-    UITableViewCell *browsercell = [[UITableViewCell alloc] init];
+/* Subclass UITableViewCell so we can support multiple columns...
+ * Enabled via the DW_FEATURE_CONTAINER_MODE feature setting.
+ */
+@interface DWTableViewCell : UITableViewCell {}
+@end
+
+@implementation DWTableViewCell
+-(void)dealloc { [super dealloc]; }
+@end
+
+ /* Create a tableview cell for containers using DW_CONTAINER_MODE_* or listboxes */
+DWTableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text)
+{
+    DWTableViewCell *browsercell = [[DWTableViewCell alloc] init];
     [browsercell setAutoresizesSubviews:YES];
 
     if(icon)
@@ -2408,9 +2417,9 @@
     id celldata = [data objectAtIndex:index];
 
     /* The data is already a NSTableCellView so just return that */
-    if([celldata isMemberOfClass:[UITableViewCell class]])
-    {
-        UITableViewCell *result = celldata;
+    if([celldata isMemberOfClass:[DWTableViewCell class]])
+    {
+        DWTableViewCell *result = celldata;
         
         /* Copy the alignment setting from the column,
          * and set the text color from the container.
@@ -2664,7 +2673,7 @@
 
             for(x=0;x<rowcount;x++)
             {
-                UITableViewCell *cell = [data objectAtIndex:(x*colcount)];
+                DWTableViewCell *cell = [data objectAtIndex:(x*colcount)];
                 int thiswidth = 4, thisheight = 0;
                 
                 if([cell imageView])
@@ -5742,7 +5751,7 @@
         }
         else
         {
-            UITableViewCell *cell = [cont getRow:index and:0];
+            DWTableViewCell *cell = [cont getRow:index and:0];
             NSString *nstr = [[cell textLabel] text];
 
             strncpy(buffer, [nstr UTF8String], length - 1);
@@ -5780,7 +5789,7 @@
         if(index <= count)
         {
             NSString *nstr = [NSString stringWithUTF8String:buffer];
-            UITableViewCell *cell = [cont getRow:index and:0];
+            DWTableViewCell *cell = [cont getRow:index and:0];
 
             [[cell textLabel] setText:nstr];
             [cont reloadData];
@@ -7217,9 +7226,9 @@
     id object = [cont getRow:(row+lastadd) and:column];
     
     /* If it is a cell, change the content of the cell */
-    if([object isMemberOfClass:[UITableViewCell class]])
-    {
-        UITableViewCell *cell = object;
+    if([object isMemberOfClass:[DWTableViewCell class]])
+    {
+        DWTableViewCell *cell = object;
 
         if(icon)
             [[cell imageView] setImage:icon];
@@ -7298,9 +7307,9 @@
     id object = [cont getRow:(row+lastadd) and:0];
     
     /* If it is a cell, change the content of the cell */
-    if([object isMemberOfClass:[UITableViewCell class]])
-    {
-        UITableViewCell *cell = object;
+    if([object isMemberOfClass:[DWTableViewCell class]])
+    {
+        DWTableViewCell *cell = object;
 
         if(icon)
             [[cell imageView] setImage:icon];
@@ -11931,6 +11940,8 @@
         case DW_FEATURE_UTF8_UNICODE:
         case DW_FEATURE_TREE:
             return DW_FEATURE_ENABLED;
+        case DW_FEATURE_CONTAINER_MODE:
+            return _dw_container_mode;
         case DW_FEATURE_DARK_MODE:
         {
             if(DWObj)
@@ -11979,6 +11990,15 @@
         case DW_FEATURE_UTF8_UNICODE:
         case DW_FEATURE_TREE:
             return DW_ERROR_GENERAL;
+        case DW_FEATURE_CONTAINER_MODE:
+        {
+            if(state >= DW_CONTAINER_MODE_DEFAULT && state < DW_CONTAINER_MODE_MAX)
+            {
+                _dw_container_mode = state;
+                return DW_ERROR_NONE;
+            }
+            return DW_ERROR_GENERAL;
+        }
         case DW_FEATURE_DARK_MODE:
         {
             /* Make sure DWObj is initialized */
@@ -11996,6 +12016,7 @@
             }
             else /* Save the requested state for dw_init() */
                 _dw_dark_mode_state = state;
+            return DW_ERROR_NONE;
         }
         default:
             return DW_FEATURE_UNSUPPORTED;