AxWin2 - Fiddling, almost ready for testing :)
[tpg/acess2.git] / Usermode / Applications / axwin2_src / WM / wm.c
index e4d45b5..fd0f056 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "wm.h"
+#include <acess/sys.h> // _SysDebug
 
 // === IMPORTS ===
 extern void    Decorator_RenderWidget(tElement *Element);
@@ -26,11 +27,17 @@ void        WM_RenderWidget(tElement *Element);
 void   WM_Update(void);
 
 // === GLOBALS ===
+// - TODO: Handle windows by having multiple root elements
 tElement       gWM_RootElement = {
        .DebugName = "ROOT"
 };
+
+tApplication   *gWM_Applications;
+
+// --- Element type flags
 struct {
        void    (*Init)(tElement *This);
+       void    (*Delete)(tElement *This);
        void    (*UpdateFlags)(tElement *This);
        void    (*UpdateSize)(tElement *This);
        void    (*UpdateText)(tElement *This);
@@ -38,8 +45,54 @@ struct {
        {NULL, NULL, NULL, NULL},       // NULL
        {NULL, NULL, NULL, NULL}        // Box
 };
+const int      ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]);
 
 // === CODE ===
+tApplication *AxWin_RegisterClient(int IdentLen, void *Ident, tMessages_Handle_Callback *Cb, const char *Name)
+{
+       tApplication    *ret = calloc( 1, sizeof(tApplication) + 1 + strlen(Name) + 1 + IdentLen );
+       
+       ret->Name = &ret->MetaElement.DebugName[1];
+       strcpy(ret->Name, Name);
+       ret->Ident = ret->Name + strlen(Name) + 1;
+       memcpy(ret->Ident, Ident, IdentLen);
+       ret->SendMessage = Cb;
+
+       ret->Next = gWM_Applications;
+       gWM_Applications = ret;
+
+       // TODO: Inform listeners of the new application
+
+       return ret;
+}
+
+void AxWin_DeregisterClient(tApplication *App)
+{
+       tElement        *win, *next;
+       // TODO: Implement DeregisterClient
+
+       for( win = App->MetaElement.FirstChild; win; win = next )
+       {
+               next = win->NextSibling;
+               AxWin_DeleteElement(win);
+       }
+
+       // TODO: Inform listeners of deleted application
+       // TODO: Remove from list
+       free(App);
+}
+
+tElement *AxWin_CreateWindow(tApplication *App, const char *Name)
+{
+       tElement        *ret;
+
+       // TODO: Implement _CreateTab
+       
+       ret = AxWin_CreateElement(&App->MetaElement, ELETYPE_WINDOW, 0, NULL);
+       ret->Text = strdup(Name);
+       return ret;
+}
+
 // --- Widget Creation and Control ---
 tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName)
 {
@@ -67,7 +120,7 @@ tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const
        ret->PaddingT = 2;
        ret->PaddingB = 2;
        
-       if( gaWM_WidgetTypes[Type].Init )
+       if( Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Type].Init )
                gaWM_WidgetTypes[Type].Init(ret);
        
        WM_UpdateMinDims(ret->Parent);
@@ -80,7 +133,20 @@ tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const
  */
 void AxWin_DeleteElement(tElement *Element)
 {
+       tElement        *child, *next;
+       
+       for(child = Element->FirstChild; child; child = next)
+       {
+               next = child->NextSibling;
+               AxWin_DeleteElement(child);
+       }
+
        // TODO: Implement AxWin_DeleteElement
+       // TODO: Clean up related data.
+       if( Element->Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Element->Type].Delete )
+               gaWM_WidgetTypes[Element->Type].Delete(Element);
+
+       free(Element);
 }
 
 /**
@@ -153,6 +219,8 @@ void AxWin_SetText(tElement *Element, const char *Text)
                }
                }
                break;
+       default:        // Any other, no special case
+               break ; 
        }
        
        return ;
@@ -166,6 +234,7 @@ void AxWin_SetText(tElement *Element, const char *Text)
  */
 /**
  * \brief Updates the dimensions of an element
+ * \todo What is the \a Pass parameter for
  * 
  * The dimensions of an element are calculated from the parent's
  * cross dimension (the side at right angles to the alignment) sans some
@@ -266,7 +335,7 @@ void WM_UpdateDimensions(tElement *Element, int Pass)
                else
                        child->CachedW = with;
                
-               WM_UpdateDimensions(child, 0);
+               WM_UpdateDimensions(child, Pass);
        }
        
        _SysDebug("%p'%s' Done", Element, Element->DebugName);

UCC git Repository :: git.ucc.asn.au