Usermode/AxWin3 - Added names to widget types
authorJohn Hodge <[email protected]>
Mon, 28 Oct 2013 10:32:55 +0000 (18:32 +0800)
committerJohn Hodge <[email protected]>
Mon, 28 Oct 2013 10:32:55 +0000 (18:32 +0800)
Usermode/Applications/axwin3_src/WM/renderers/widget.c
Usermode/Applications/axwin3_src/WM/renderers/widget/button.c
Usermode/Applications/axwin3_src/WM/renderers/widget/common.h
Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c
Usermode/Applications/axwin3_src/WM/renderers/widget/image.c
Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c
Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c
Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c

index 0261bea..fd757af 100644 (file)
 #define DEFAULT_ELETABLE_SIZE  64
 #define BORDER_EVERYTHING      0
 
+// === IMPORTS ===
+extern tWidgetDef      _widget_typedef_ELETYPE_IMAGE;
+extern tWidgetDef      _widget_typedef_ELETYPE_BUTTON;
+extern tWidgetDef      _widget_typedef_ELETYPE_TEXT;
+extern tWidgetDef      _widget_typedef_ELETYPE_TEXTINPUT;
+extern tWidgetDef      _widget_typedef_ELETYPE_SPACER;
+extern tWidgetDef      _widget_typedef_ELETYPE_SUBWIN;
+
 // === PROTOTYPES ===
  int   Renderer_Widget_Init(void);
 tWindow        *Renderer_Widget_Create(int Flags);
@@ -56,17 +64,23 @@ tWMRenderer gRenderer_Widget = {
 };
        
 // --- Element callbacks
-tWidgetDef     *gaWM_WidgetTypes[NUM_ELETYPES];
+tWidgetDef     *gaWM_WidgetTypes[NUM_ELETYPES] = {
+       [ELETYPE_IMAGE]     = &_widget_typedef_ELETYPE_IMAGE,
+       [ELETYPE_BUTTON]    = &_widget_typedef_ELETYPE_BUTTON,
+       [ELETYPE_TEXT]      = &_widget_typedef_ELETYPE_TEXT,
+       [ELETYPE_TEXTINPUT] = &_widget_typedef_ELETYPE_TEXTINPUT,
+       [ELETYPE_SPACER]    = &_widget_typedef_ELETYPE_SPACER,
+       [ELETYPE_SUBWIN]    = &_widget_typedef_ELETYPE_SUBWIN,
+       };
 const int      ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]);
 tWidgetDef     gWidget_NullWidgetDef;
 
 // === CODE ===
 int Renderer_Widget_Init(void)
 {
-        int    i;
        WM_RegisterRenderer(&gRenderer_Widget); 
 
-       for(i = 0; i < ciWM_NumWidgetTypes; i ++)
+       for(int i = 0; i < ciWM_NumWidgetTypes; i ++)
        {
                if(gaWM_WidgetTypes[i] != NULL) continue;
                
@@ -94,6 +108,7 @@ void Widget_int_SetTypeDef(int Type, tWidgetDef *Ptr)
        }
        
        gaWM_WidgetTypes[Type] = Ptr;
+       _SysDebug("Registered widget type %i '%s'", Type, Ptr->Name);
 }
 
 tWindow        *Renderer_Widget_Create(int Flags)
@@ -289,7 +304,6 @@ void Widget_UpdateDimensions(tElement *Element)
  */
 void Widget_UpdatePosition(tElement *Element)
 {
-       tElement        *child;
         int    x, y;
        
        if( Element->Flags & ELEFLAG_NORENDER ) return ;
@@ -306,7 +320,7 @@ void Widget_UpdatePosition(tElement *Element)
        y = Element->CachedY + Element->PaddingT;
        
        // Update each child
-       for(child = Element->FirstChild; child; child = child->NextSibling)
+       for(tElement *child = Element->FirstChild; child; child = child->NextSibling)
        {
                 int    newX, newY;
                // Ignore elements that will not be rendered
@@ -357,7 +371,6 @@ void Widget_UpdatePosition(tElement *Element)
  */
 void Widget_UpdateMinDims(tElement *Element)
 {
-       tElement        *child;
         int    minW, minH;
         int    nChildren;
        
@@ -367,7 +380,7 @@ void Widget_UpdateMinDims(tElement *Element)
        minH = 0;
        nChildren = 0;
        
-       for(child = Element->FirstChild; child; child = child->NextSibling)
+       for( tElement *child = Element->FirstChild; child; child = child->NextSibling )
        {
                 int    cross;
                
@@ -404,14 +417,13 @@ void Widget_UpdateMinDims(tElement *Element)
 
 tElement *Widget_GetElementByPos(tWidgetWin *Info, int X, int Y)
 {
-       tElement        *ret, *next, *ele;
-       
-       next = &Info->RootElement;
-       do
-       {
+       tElement *ret;
+       tElement *next = &Info->RootElement;
+       // Scan down tree
+       do {
                ret = next;
                next = NULL;
-               for(ele = ret->FirstChild; ele; ele = ele->NextSibling)
+               for(tElement *ele = ret->FirstChild; ele; ele = ele->NextSibling)
                {
                        if(ele->Flags & ELEFLAG_NORENDER)       continue;
                        if(X < ele->CachedX)    continue;
@@ -442,6 +454,12 @@ tElement *Widget_int_Create(tWidgetWin *Info, tElement *Parent, int ID, int Type
 {
        if( Widget_GetElementById(Info, ID) )
                return NULL;
+       if( Type >= NUM_ELETYPES ) {
+               return NULL;
+       }
+       
+       _SysDebug("Widget Create #%i '%s' 0x%x",
+               ID, gaWM_WidgetTypes[Type]->Name, Flags);
 
        // Create new element
        tElement *new = calloc(sizeof(tElement), 1);
@@ -455,7 +473,7 @@ tElement *Widget_int_Create(tWidgetWin *Info, tElement *Parent, int ID, int Type
        new->PaddingL = 2;
        new->PaddingR = 2;
        new->CachedX = -1;
-       
+
        if( gaWM_WidgetTypes[Type]->Init )
                gaWM_WidgetTypes[Type]->Init(new);
        
@@ -621,6 +639,7 @@ int Widget_IPC_SetText(tWindow *Win, size_t Len, const void *Data)
 
        if( gaWM_WidgetTypes[ele->Type]->UpdateText )
        {
+               _SysDebug(" - calling handler");
                gaWM_WidgetTypes[ele->Type]->UpdateText( ele, Msg->Text );
        }
 //     else
index 3de65f0..0ffc2df 100644 (file)
@@ -35,7 +35,7 @@ int Widget_Button_MouseButton(tElement *Element, int X, int Y, int Button, int b
        return 0;       // Handled
 }
 
-DEFWIDGETTYPE(ELETYPE_BUTTON,
+DEFWIDGETTYPE(ELETYPE_BUTTON, "Button",
        0,
        .Render = Widget_Button_Render,
        .MouseButton = Widget_Button_MouseButton
index 172c907..2564716 100644 (file)
@@ -16,6 +16,7 @@ typedef struct sWidgetDef     tWidgetDef;
 
 struct sWidgetDef
 {
+       const char      *Name;
         int    Flags;
        void    (*Init)(tElement *Ele);
        void    (*Delete)(tElement *Ele);
@@ -45,10 +46,10 @@ extern void Widget_int_SetTypeDef(int Type, tWidgetDef *Def);
 extern void    Widget_UpdateMinDims(tElement *Element);
 extern void    Widget_Fire(tElement *Element);
 
-#define DEFWIDGETTYPE(_type, _flags, _attribs...) \
-tWidgetDef     _widget_typedef_##_type = {.Flags=(_flags),_attribs};\
+#define DEFWIDGETTYPE(_type, _name, _flags, _attribs...) \
+tWidgetDef     _widget_typedef_##_type = {.Name=_name,.Flags=(_flags),_attribs};\
 void _widget_set_##_type(void) __attribute__((constructor));\
-void _widget_set_##_type(void) { Widget_int_SetTypeDef(_type, &_widget_typedef_##_type);}
+void _widget_set_##_type(void) { _SysDebug("hai!\n"); Widget_int_SetTypeDef(_type, &_widget_typedef_##_type);}
 
 #endif
 
index d3abdea..0882dc8 100644 (file)
@@ -2,8 +2,8 @@
  * Acess2 Window Manager v3
  * - By John Hodge (thePowersGang)
  * 
- * renderer/widget/button.c
- * - Button Widget Type
+ * renderer/widget/disptext.c
+ * - Label Text
  */
 #include <common.h>
 #include "./common.h"
@@ -39,7 +39,7 @@ void Widget_DispText_UpdateText(tElement *Element, const char *Text)
        Widget_UpdateMinDims(Element->Parent);
 }
 
-DEFWIDGETTYPE(ELETYPE_TEXT,
+DEFWIDGETTYPE(ELETYPE_TEXT, "Text",
        WIDGETTYPE_FLAG_NOCHILDREN,
        .Render = Widget_DispText_Render,
        .UpdateText = Widget_DispText_UpdateText
index a6642c3..692ac5b 100644 (file)
@@ -41,7 +41,7 @@ void Widget_Image_UpdateText(tElement *Element, const char *Text)
        // NOTE: Doesn't update Element->Text because it's not really needed here
 }
 
-DEFWIDGETTYPE(ELETYPE_IMAGE,
+DEFWIDGETTYPE(ELETYPE_IMAGE, "Image",
        WIDGETTYPE_FLAG_NOCHILDREN,
        .Render = Widget_Image_Render,
        .UpdateText = Widget_Image_UpdateText
index 028ed61..bc2dcc4 100644 (file)
@@ -44,7 +44,7 @@ void Widget_Spacer_Init(tElement *Element)
        Element->MinW = SPACER_RULE_SIZE+2;
 }
 
-DEFWIDGETTYPE(ELETYPE_SPACER,
+DEFWIDGETTYPE(ELETYPE_SPACER, "Spacer",
        WIDGETTYPE_FLAG_NOCHILDREN,
        .Render = Widget_Spacer_Render,
        .Init = Widget_Spacer_Init
index fcf196d..8d71191 100644 (file)
@@ -18,7 +18,7 @@ void Widget_SubWin_Render(tWindow *Window, tElement *Element)
        WM_ResizeWindow(Element->Data, Element->CachedW, Element->CachedH);
 }
 
-DEFWIDGETTYPE(ELETYPE_SUBWIN,
+DEFWIDGETTYPE(ELETYPE_SUBWIN, "Subwindow",
        WIDGETTYPE_FLAG_NOCHILDREN,
        .Render = Widget_SubWin_Render
        )
index 831565b..8335241 100644 (file)
@@ -117,6 +117,8 @@ void Widget_TextInput_Init(tElement *Element)
        info = Element->Data = malloc(sizeof(*info));
        info->DrawOfs = 0;
        info->CursorXOfs = 0;
+       info->CursorByteOfs = 0;
+       info->Length = NULL;
 
        // No need to explicitly update parent min dims, as the AddElement routine does that    
 }
@@ -218,7 +220,7 @@ int Widget_TextInput_KeyFire(tElement *Element, int KeySym, int Character)
        return 0;
 }
 
-DEFWIDGETTYPE(ELETYPE_TEXTINPUT,
+DEFWIDGETTYPE(ELETYPE_TEXTINPUT, "TextInput",
        WIDGETTYPE_FLAG_NOCHILDREN,
        .Render = Widget_TextInput_Render,
        .Init = Widget_TextInput_Init,

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