From: John Hodge Date: Mon, 28 Oct 2013 10:32:55 +0000 (+0800) Subject: Usermode/AxWin3 - Added names to widget types X-Git-Tag: rel0.15~105 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c658c88d73bcd7750fb7d727dfd9812d3d02c1bb;p=tpg%2Facess2.git Usermode/AxWin3 - Added names to widget types --- diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget.c b/Usermode/Applications/axwin3_src/WM/renderers/widget.c index 0261beab..fd757af7 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget.c @@ -16,6 +16,14 @@ #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 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/button.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/button.c index 3de65f0e..0ffc2dfe 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/button.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/button.c @@ -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 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/common.h b/Usermode/Applications/axwin3_src/WM/renderers/widget/common.h index 172c9071..2564716e 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/common.h +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/common.h @@ -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 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c index d3abdea1..0882dc80 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/disptext.c @@ -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 #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 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c index a6642c33..692ac5b3 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/image.c @@ -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 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c index 028ed61d..bc2dcc4d 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/spacer.c @@ -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 diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c index fcf196d5..8d711914 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/subwin.c @@ -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 ) diff --git a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c index 831565b3..83352417 100644 --- a/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c +++ b/Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c @@ -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,