2 * Acess GUI (AxWin) Version 2
3 * By John Hodge (thePowersGang)
5 * Window Manager and Widget Control
11 #include <acess/sys.h> // _SysDebug
14 extern void Video_GetTextDims(tFont *Font, const char *Text, int *W, int *H);
17 tElement *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName);
18 void AxWin_DeleteElement(tElement *Element);
19 void AxWin_SetFlags(tElement *Element, int Flags);
20 void AxWin_SetSize(tElement *Element, int Size);
21 void AxWin_SetText(tElement *Element, const char *Text);
24 // - TODO: Handle windows by having multiple root elements
25 tElement gWM_RootElement = {
29 tApplication *gWM_Applications;
31 // --- Element type flags
33 void (*Init)(tElement *This);
34 void (*Delete)(tElement *This);
35 void (*UpdateFlags)(tElement *This);
36 void (*UpdateSize)(tElement *This);
37 void (*UpdateText)(tElement *This);
38 } gaWM_WidgetTypes[MAX_ELETYPES] = {
39 {NULL, NULL, NULL, NULL, NULL}, // NULL
40 {NULL, NULL, NULL, NULL, NULL}, // Window
41 {NULL, NULL, NULL, NULL, NULL} // Box
43 const int ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]);
46 tApplication *AxWin_RegisterClient(int IdentLen, void *Ident, tMessages_Handle_Callback *Cb, const char *Name)
48 tApplication *ret = calloc( 1, sizeof(tApplication) + 1 + strlen(Name) + 1 + IdentLen );
50 ret->Name = &ret->MetaElement.DebugName[1];
51 strcpy(ret->Name, Name);
52 ret->Ident = ret->Name + strlen(Name) + 1;
53 memcpy(ret->Ident, Ident, IdentLen);
54 ret->SendMessage = Cb;
56 ret->MaxElementIndex = DEFAULT_ELEMENTS_PER_APP;
57 ret->EleIndex = calloc( 1, ret->MaxElementIndex * sizeof(*ret->EleIndex) );
59 ret->Next = gWM_Applications;
60 gWM_Applications = ret;
62 // TODO: Inform listeners of the new application
67 void AxWin_DeregisterClient(tApplication *App)
70 // TODO: Implement DeregisterClient
72 for( win = App->MetaElement.FirstChild; win; win = next )
74 next = win->NextSibling;
75 AxWin_DeleteElement(win);
78 // TODO: Inform listeners of deleted application
79 // TODO: Remove from list
83 tElement *AxWin_CreateWindow(tApplication *App, const char *Name)
87 // TODO: Implement _CreateTab
89 ret = AxWin_CreateElement(&App->MetaElement, ELETYPE_WINDOW, 0, NULL);
90 ret->Text = strdup(Name);
94 // --- Widget Creation and Control ---
95 tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName)
98 const char *dbgName = DebugName ? DebugName : "";
100 ret = calloc(sizeof(tElement)+strlen(dbgName)+1, 1);
101 if(!ret) return NULL;
105 strcpy(ret->DebugName, dbgName);
106 if(Parent == NULL) Parent = &gWM_RootElement;
107 ret->Parent = Parent;
110 // Append to parent's list
111 if(Parent->LastChild)
112 Parent->LastChild->NextSibling = ret;
113 Parent->LastChild = ret;
114 if(!Parent->FirstChild) Parent->FirstChild = ret;
121 if( Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Type].Init )
122 gaWM_WidgetTypes[Type].Init(ret);
124 WM_UpdateMinDims(ret->Parent);
130 * \brief Delete an element
132 void AxWin_DeleteElement(tElement *Element)
134 tElement *child, *next;
136 for(child = Element->FirstChild; child; child = next)
138 next = child->NextSibling;
139 AxWin_DeleteElement(child);
142 // TODO: Implement AxWin_DeleteElement
143 // TODO: Clean up related data.
144 if( Element->Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Element->Type].Delete )
145 gaWM_WidgetTypes[Element->Type].Delete(Element);
148 Element->Owner->EleIndex[ Element->ApplicationID ] = NULL;
158 * \brief Alter an element's flags
160 void AxWin_SetFlags(tElement *Element, int Flags)
162 // Permissions are handled in the message handler
164 gWM_RootElement.Flags = Flags;
168 Element->Flags = Flags;
173 * \brief Set the fixed lenghthways size of an element
175 void AxWin_SetSize(tElement *Element, int Size)
177 if(!Element) return ;
178 Element->FixedWith = Size;
183 * \brief Set the text field of an element
184 * \note Used for the image path on ELETYPE_IMAGE
186 void AxWin_SetText(tElement *Element, const char *Text)
188 if(!Element) return ;
189 if(Element->Text) free(Element->Text);
190 Element->Text = strdup(Text);
192 switch(Element->Type)
195 if(Element->Data) free(Element->Data);
196 Element->Data = Image_Load( Element->Text );
198 Element->Flags &= ~ELEFLAG_FIXEDSIZE;
202 //Element->Flags |= ELEFLAG_FIXEDSIZE;
203 Element->CachedW = ((tImage*)Element->Data)->Width;
204 Element->CachedH = ((tImage*)Element->Data)->Height;
206 if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
207 Element->MinCross = ((tImage*)Element->Data)->Width;
208 Element->MinWith = ((tImage*)Element->Data)->Height;
211 Element->MinWith = ((tImage*)Element->Data)->Width;
212 Element->MinCross = ((tImage*)Element->Data)->Height;
219 Video_GetTextDims(NULL, Element->Text, &w, &h);
220 if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
221 Element->MinCross = w;
222 Element->MinWith = h;
225 Element->MinWith = w;
226 Element->MinCross = h;
230 default: // Any other, no special case