[Y-devel] internal "Class methods" patch (less Canvas)

Thomas spiralman at softhome.net
Sat Feb 21 20:10:16 GMT 2004


hello, this is a patch i made at Mark's request so that modules and other 
server side code can access the methods a widget (or other object) exposes to 
the clients through the "Class" interface.  I left out the object_check 
classes, as i believe they are simply debugging classes used for Mark's final 
project.

I also left out the Canvas class because i was not sure how to implement one 
of the methods, which calls parametersAddOutputInteger().  I assume that 
these would be implemented by passing pointers to ints, and then the method 
would change their values, but i wanted to make sure before i spend a lot of 
time working on Canvas (it is probably as much work as all the other classes 
were combined).  

So if Mark or anybody else wants to chime in on how to implement this, please 
do.

anyway, here is the initial patch
Thomas Stephens
spiralman at softhome.net

--- orig/Y/widget/console.c
+++ mod/Y/widget/console.c
@@ -449,6 +449,24 @@
 }
 
 void
+consoleSetRendition (struct Console *self, int bold, int blink, int inverse, 
int underline, int foreground, int background, const char *charset)
+{
+  self -> bold = bold;
+  self -> blink = blink;
+  self -> inverse = inverse;
+  self -> underline = underline;
+  if (foreground >= 1 && foreground <= 8)
+    self -> foreground = foreground - 1;
+  else
+    self -> foreground = -1;
+  if (background >= 1 && background <= 8)
+    self -> background = background - 1;
+  else
+  self -> background = -1;
+  self -> charset = charset[0];
+}
+
+void
 consoleCSetRendition (struct Console *self, struct Parameters *params)
 {
   if (parametersGetInputCount (params) == 7)
@@ -463,35 +481,49 @@
       background = strtol (parametersGetInput (params, 5), NULL, 0);
       charset    = parametersGetInput (params, 6);
 
-      self -> bold = bold;
-      self -> blink = blink;
-      self -> inverse = inverse;
-      self -> underline = underline;
-      if (foreground >= 1 && foreground <= 8)
-        self -> foreground = foreground - 1;
-      else
-        self -> foreground = -1;
-      if (background >= 1 && background <= 8)
-        self -> background = background - 1;
-      else
-        self -> background = -1;
-      self -> charset = charset[0];
+      consoleSetRendition (self, bold, blink, inverse, underline, foreground, 
background, charset);
    }
 }
 
 void
-consoleCSwapVideo (struct Console *self, struct Parameters *params)
+consoleSwapVideo (struct Console *self)
 {
   Y_TRACE ("Swap Video ?");
 }
 
 void
-consoleCRing (struct Console *self, struct Parameters *params)
+consoleCSwapVideo (struct Console *self, struct Parameters *params)
+{
+  consoleSwapVideo (self);
+}
+
+void
+consoleRing (struct Console *self)
 {
   Y_TRACE ("***BEEP***");
 }
 
 void
+consoleCRing (struct Console *self, struct Parameters *params)
+{
+  consoleRing (self);
+}
+
+void
+consoleUpdateCursorPos (struct Console *self, int col, int row)
+{
+if (col != self -> cursorCol || row != self -> cursorRow)
+ {
+    consoleRepaintChars (self, self -> cursorCol, self -> cursorRow,
+                                     self -> cursorCol + 1, self -> cursorRow 
+1);
+    self -> cursorCol = col;
+    self -> cursorRow = row;
+    consoleRepaintChars (self, self -> cursorCol, self -> cursorRow,
+      self -> cursorCol + 1, self -> cursorRow +1);
+  }
+}
+
+void
 consoleCUpdateCursorPos (struct Console *self, struct Parameters *params)
 {
   if (parametersGetInputCount (params) == 2)
@@ -499,19 +531,34 @@
       int col, row;
       col = strtol (parametersGetInput (params, 0), NULL, 0);
       row = strtol (parametersGetInput (params, 1), NULL, 0);
-      if (col != self -> cursorCol || row != self -> cursorRow)
-        {
-          consoleRepaintChars (self, self -> cursorCol, self -> cursorRow,
-                                     self -> cursorCol + 1, self -> cursorRow 
+1);
-          self -> cursorCol = col;
-          self -> cursorRow = row;
-          consoleRepaintChars (self, self -> cursorCol, self -> cursorRow,
-                                     self -> cursorCol + 1, self -> cursorRow 
+1);
-        }
+      consoleUpdateCursorPos (self, col, row);
     } 
 }
 
 void
+consoleScrollView (struct Console *self, int destRow, int srcRow, int 
numLines)
+{
+  if (destRow >= self -> rows)
+    return;
+  if (srcRow >= self -> rows)
+    return;
+  if (destRow + numLines > self -> rows)
+    numLines = self -> rows - destRow;
+  if (srcRow + numLines > self -> rows)
+    numLines = self -> rows - srcRow;
+  memmove (self -> contents + destRow * self -> cols,
+           self -> contents + srcRow * self -> cols,
+           numLines * self -> cols * sizeof (struct ConsoleChar)); 
+  if (destRow < srcRow)
+    consoleClearRect (self, 0, MAX (srcRow, destRow + numLines),
+                      self -> cols, srcRow + numLines);
+  else if (srcRow < destRow)
+    consoleClearRect (self, 0, srcRow, self -> cols,
+                      MIN (numLines, destRow - srcRow));
+  consoleRepaintChars (self, 0, destRow, self -> cols, destRow + numLines);
+}
+
+void
 consoleCScrollView (struct Console *self, struct Parameters *params)
 {
   if (parametersGetInputCount (params) == 3)
@@ -520,24 +567,7 @@
       destRow  = strtol (parametersGetInput (params, 0), NULL, 0);
       srcRow   = strtol (parametersGetInput (params, 1), NULL, 0);
       numLines = strtol (parametersGetInput (params, 2), NULL, 0);
-      if (destRow >= self -> rows)
-        return;
-      if (srcRow >= self -> rows)
-        return;
-      if (destRow + numLines > self -> rows)
-        numLines = self -> rows - destRow;
-      if (srcRow + numLines > self -> rows)
-        numLines = self -> rows - srcRow;
-      memmove (self -> contents + destRow * self -> cols,
-               self -> contents + srcRow * self -> cols,
-               numLines * self -> cols * sizeof (struct ConsoleChar)); 
-      if (destRow < srcRow)
-        consoleClearRect (self, 0, MAX (srcRow, destRow + numLines),
-                          self -> cols, srcRow + numLines);
-      else if (srcRow < destRow)
-        consoleClearRect (self, 0, srcRow, self -> cols,
-                          MIN (numLines, destRow - srcRow));
-      consoleRepaintChars (self, 0, destRow, self -> cols, destRow + 
numLines);
+      consoleScrollView (self, destRow, srcRow, numLines);
     }
 }
 
--- orig/Y/widget/console.h
+++ mod/Y/widget/console.h
@@ -11,6 +11,15 @@
 struct Widget *   consoleToWidget  (struct Console *);
 struct Object *   consoleToObject  (struct Console *);
 
+void consoleClearRect              (struct Console *, int, int, int, int);
+void consoleDrawText               (struct Console *, int, int, wchar_t *, 
int);
+void consoleRing                   (struct Console *);
+void consoleScrollView             (struct Console *, int destRow, int 
srcRow, int numLines);
+void consoleSetRendition           (struct Console *, int, int, int, int, 
int, int, const char *);
+void consoleSwapVideo              (struct Console *);
+void consoleUpdateCursorPos        (struct Console *, int, int);
+
+
 #endif /* Y_WIDGET_CONSOLE_H */
 
 /* arch-tag: 5b0298fc-904b-4647-a238-89127956cbd0
--- orig/Y/widget/gridlayout.c
+++ mod/Y/widget/gridlayout.c
@@ -270,37 +270,50 @@
   listiteratorDestroy (iter);
 }
 
+void
+gridlayoutAddWidget (struct GridLayout *self, int objId, int col, int row, 
int colspan, int rowspan)
+{
+  struct GridItem *item;
+
+  item = ymalloc (sizeof (struct GridItem));    
+  item -> widget = (struct Widget *) objectFind (objId);
+  item -> col     = col;
+  item -> row     = row;
+  item -> colspan = colspan;
+  item -> rowspan = rowspan;
+  
+  listAppend (self -> items, item);
+
+  if (item -> col + item -> colspan > self -> cols ||
+      item -> row + item -> rowspan > self -> rows)
+    {
+       gridlayoutResizeGrid (self, self -> cols, self -> rows);
+    }
+  else
+    {
+       gridlayoutFitChildren (self);
+       widgetRepaint (gridlayoutToWidget (self),
+                      widgetGetRectangle (item -> widget));
+    }
+  widgetReconfigure (gridlayoutToWidget (self));
+  widgetSetContainer (item -> widget, gridlayoutToWidget (self));
+}
+
 static void
 gridlayoutCAddWidget (struct Object *self_o, struct Parameters *params)
 {
   struct GridLayout *self = (struct GridLayout *)self_o;
   if (self != NULL || parametersGetInputCount (params) > 4)
     {
-      struct GridItem *item;
+      int objId, col, row, colspan, rowspan;
 
-      item = ymalloc (sizeof (struct GridItem));    
-      item -> widget = (struct Widget *)
-            objectFind (strtol (parametersGetInput (params, 0), NULL, 0));
-      item -> col     = strtol (parametersGetInput (params, 1), NULL, 0);
-      item -> row     = strtol (parametersGetInput (params, 2), NULL, 0);
-      item -> colspan = strtol (parametersGetInput (params, 3), NULL, 0);
-      item -> rowspan = strtol (parametersGetInput (params, 4), NULL, 0);
+      objId   = strtol (parametersGetInput (params, 0), NULL, 0);
+      col     = strtol (parametersGetInput (params, 1), NULL, 0);
+      row     = strtol (parametersGetInput (params, 2), NULL, 0);
+      colspan = strtol (parametersGetInput (params, 3), NULL, 0);
+      rowspan = strtol (parametersGetInput (params, 4), NULL, 0);
 
-      listAppend (self -> items, item);
-
-      if (item -> col + item -> colspan > self -> cols ||
-          item -> row + item -> rowspan > self -> rows)
-        {
-           gridlayoutResizeGrid (self, self -> cols, self -> rows);
-        }
-      else
-        {
-           gridlayoutFitChildren (self);
-           widgetRepaint (gridlayoutToWidget (self),
-                          widgetGetRectangle (item -> widget));
-        }
-      widgetReconfigure (gridlayoutToWidget (self));
-      widgetSetContainer (item -> widget, gridlayoutToWidget (self));
+      gridlayoutAddWidget (self, objId, col, row, colspan, rowspan);
     }
 }
 
--- orig/Y/widget/gridlayout.h
+++ mod/Y/widget/gridlayout.h
@@ -11,6 +11,8 @@
 struct Widget *      gridlayoutToWidget  (struct GridLayout *);
 struct Object *      gridlayoutToObject  (struct GridLayout *);
 
+void gridlayoutAddWidget (struct GridLayout *, int, int, int, int, int);
+
 #endif /* Y_WIDGET_GRIDLAYOUT_H */
 
 /* arch-tag: 3fbc3e6e-b55d-4ed3-a7bc-12dcc54ea929
--- orig/Y/widget/menu.c
+++ mod/Y/widget/menu.c
@@ -364,6 +364,28 @@
   self -> current = NULL; 
 }  
 
+void menuAddItem (struct Menu *self, int id, const char *text, int submenuId)
+{
+  struct Object *submenu;
+  struct MenuItem *item;
+  
+  if (indexFind (self -> items, &id) != NULL)
+    return;
+
+  submenu = objectFind (submenuId);
+  if (submenu != NULL && !classInherits (objectClass (submenu), "Menu"))
+    return; 
+
+  item = ymalloc (sizeof (struct MenuItem));
+  item -> id = id;
+  item -> text = ystrdup (text);
+  item -> height = 0;
+  item -> submenu = (struct Menu *) submenu;  /* ok, because we checked */ 
+
+  indexAdd (self -> items, item);
+  widgetReconfigure (menuToWidget (self));
+}
+
 void
 menuCAddItem (struct Menu *self, struct Parameters *params)
 {
@@ -371,29 +393,14 @@
    */
   if (parametersGetInputCount (params) == 3)
     {
-      struct MenuItem *item;
       int id, submenuId;
       const char *text;
-      struct Object *submenu;
+      
       id        = strtol (parametersGetInput (params, 0), NULL, 0);
       text      =         parametersGetInput (params, 1);
       submenuId = strtol (parametersGetInput (params, 2), NULL, 0);
 
-      if (indexFind (self -> items, &id) != NULL)
-        return;
-
-      submenu = objectFind (submenuId);
-      if (submenu != NULL && !classInherits (objectClass (submenu), "Menu"))
-        return; 
-
-      item = ymalloc (sizeof (struct MenuItem));
-      item -> id = id;
-      item -> text = ystrdup (text);
-      item -> height = 0;
-      item -> submenu = (struct Menu *) submenu;  /* ok, because we checked 
*/ 
-
-      indexAdd (self -> items, item);
-      widgetReconfigure (menuToWidget (self));
+      menuAddItem (self, id, text, submenuId);
     }
 }
 
--- orig/Y/widget/menu.h
+++ mod/Y/widget/menu.h
@@ -11,6 +11,8 @@
 struct Widget * menuToWidget  (struct Menu *);
 struct Object * menuToObject  (struct Menu *);
 
+void menuAddItem (struct Menu *, int, const char *, int);
+
 #endif /* Y_WIDGET_MENU_H */
 
 /* arch-tag: 5089f3eb-1e75-40c3-b21d-096b2482716c
--- orig/Y/widget/window.c
+++ mod/Y/widget/window.c
@@ -444,44 +444,60 @@
 }
 
 void
+windowSetChild (struct Window *self, int child_id)
+{
+  struct Widget *child;
+  
+  child = (struct Widget *)objectFind (child_id);
+  if (child == NULL)
+    return;
+  self -> child = child;
+  self -> widget.reqWidth = -1;
+  self -> widget.reqHeight = -1;
+  widgetSetContainer (child, windowToWidget (self));
+  widgetRepaint (child, NULL);
+}
+
+void
 windowCSetChild (struct Window *self, struct Parameters *p)
 {
   if (self != NULL)
     {
       int child_id;
-      struct Widget *child;
       if (parametersGetInputCount (p) < 1)
         return;
       child_id = strtol (parametersGetInput (p, 0), NULL, 0);
-      child = (struct Widget *)objectFind (child_id);
-      if (child == NULL)
-        return;
-      self -> child = child;
-      self -> widget.reqWidth = -1;
-      self -> widget.reqHeight = -1;
-      widgetSetContainer (child, windowToWidget (self));
-      widgetRepaint (child, NULL);
+      
+      windowSetChild (self, child_id);
     }
 }
 
 void
+windowSetFocussed (struct Window *self, int focus_id)
+{
+  struct Widget *focus;
+  
+  focus = (struct Widget *)objectFind (focus_id);
+  if (focus == NULL)
+    return;
+  windowSetFocussedWidget (self, focus);
+}
+
+void
 windowCSetFocussed (struct Window *self, struct Parameters *p)
 {
   if (self != NULL)
     {
       int focus_id;
-      struct Widget *focus;
       if (parametersGetInputCount (p) < 1)
         return;
       focus_id = strtol (parametersGetInput (p, 0), NULL, 0);
-      focus = (struct Widget *)objectFind (focus_id);
-      if (focus == NULL)
-        return;
-      windowSetFocussedWidget (self, focus);
+      windowSetFocussed (self, focus_id);
     }
 }
+
 void
-windowCShow (struct Window *self, struct Parameters *p)
+windowShow (struct Window *self)
 {
   if (self != NULL)
     {
@@ -494,6 +510,12 @@
 }
 
 void
+windowCShow (struct Window *self, struct Parameters *p)
+{
+  windowShow (self);
+}
+
+void
 windowRender (struct Widget *self_w, struct Renderer *renderer)
 {
   struct Window *self = castBack (self_w);
--- orig/Y/widget/window.h
+++ mod/Y/widget/window.h
@@ -44,6 +44,10 @@
 void            windowSaveGeometry (struct Window *);
 void            windowRestoreGeometry (struct Window *);
 
+void windowSetChild    (struct Window *, int);
+void windowSetFocussed (struct Window *, int);
+void windowShow        (struct Window *);
+
 #endif /* Y_WIDGET_WINDOW_H */
 
 /* arch-tag: f4f25bca-aa44-4f8e-a586-2c0f0372f91d



More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved