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 tApplication *AxWin_RegisterClient(tIPC_Type *IPCType, void *Ident, const char *Name);
18 void AxWin_DeregisterClient(tApplication *App);
19 tApplication *AxWin_GetClient(tIPC_Type *Method, void *Ident);
20 tElement *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName);
21 void AxWin_DeleteElement(tElement *Element);
22 void AxWin_SetFlags(tElement *Element, int Flags);
23 void AxWin_SetSize(tElement *Element, int Size);
24 void AxWin_SetText(tElement *Element, const char *Text);
27 // - TODO: Handle windows by having multiple root elements
28 tElement gWM_RootElement = {
31 tApplication *gWM_Applications;
33 // --- Element type flags
35 void (*Init)(tElement *This);
36 void (*Delete)(tElement *This);
37 void (*UpdateFlags)(tElement *This);
38 void (*UpdateSize)(tElement *This);
39 void (*UpdateText)(tElement *This);
40 } gaWM_WidgetTypes[MAX_ELETYPES] = {
41 {NULL, NULL, NULL, NULL, NULL}, // NULL
42 {NULL, NULL, NULL, NULL, NULL}, // Window
43 {NULL, NULL, NULL, NULL, NULL} // Box
45 const int ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]);
48 tApplication *AxWin_RegisterClient(tIPC_Type *Method, void *Ident, const char *Name)
50 int identlen = Method->GetIdentSize(Ident);
51 // Structure, empty string, Name, Ident
52 tApplication *ret = calloc( 1, sizeof(tApplication) + 1 + strlen(Name) + 1 + identlen );
57 ret->Name = &ret->MetaElement.DebugName[1];
58 strcpy(ret->Name, Name);
60 ret->Ident = ret->Name + strlen(Name) + 1;
61 memcpy(ret->Ident, Ident, identlen);
63 ret->IPCType = Method;
66 ret->MaxElementIndex = DEFAULT_ELEMENTS_PER_APP;
67 ret->EleIndex = calloc( 1, ret->MaxElementIndex * sizeof(*ret->EleIndex) );
70 ret->Next = gWM_Applications;
71 gWM_Applications = ret;
73 // TODO: Inform listeners of the new application
78 void AxWin_DeregisterClient(tApplication *App)
80 // TODO: Complete implementing DeregisterClient
83 for( win = App->MetaElement.FirstChild; win; win = next )
85 next = win->NextSibling;
86 AxWin_DeleteElement(win);
89 // TODO: Inform listeners of deleted application
93 tApplication *app, *prev = NULL;
94 for( app = gWM_Applications; app; app = app->Next )
96 if( app == App ) break;
103 prev->Next = App->Next;
105 gWM_Applications = App->Next;
113 * \brief Get an application handle from a client identifier
115 tApplication *AxWin_GetClient(tIPC_Type *Method, void *Ident)
117 // TODO: Faster and smarter technique
119 for( app = gWM_Applications; app; app = app->Next )
121 if( app->IPCType != Method ) continue;
122 if( Method->CompareIdent( app->Ident, Ident ) != 0 ) continue;
128 tElement *AxWin_CreateWindow(tApplication *App, const char *Name)
132 // TODO: Implement _CreateTab
134 ret = AxWin_CreateElement(&App->MetaElement, ELETYPE_WINDOW, 0, NULL);
135 ret->Text = strdup(Name);
139 // --- Widget Creation and Control ---
140 tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName)
143 const char *dbgName = DebugName ? DebugName : "";
145 ret = calloc(sizeof(tElement)+strlen(dbgName)+1, 1);
146 if(!ret) return NULL;
150 strcpy(ret->DebugName, dbgName);
151 if(Parent == NULL) Parent = &gWM_RootElement;
152 ret->Parent = Parent;
155 // Append to parent's list
156 if(Parent->LastChild)
157 Parent->LastChild->NextSibling = ret;
158 Parent->LastChild = ret;
159 if(!Parent->FirstChild) Parent->FirstChild = ret;
166 if( Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Type].Init )
167 gaWM_WidgetTypes[Type].Init(ret);
169 WM_UpdateMinDims(ret->Parent);
175 * \brief Delete an element
177 void AxWin_DeleteElement(tElement *Element)
179 tElement *child, *next;
181 for(child = Element->FirstChild; child; child = next)
183 next = child->NextSibling;
184 AxWin_DeleteElement(child);
187 // TODO: Implement AxWin_DeleteElement
188 // TODO: Clean up related data.
189 if( Element->Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Element->Type].Delete )
190 gaWM_WidgetTypes[Element->Type].Delete(Element);
193 Element->Owner->EleIndex[ Element->ApplicationID ] = NULL;
203 * \brief Alter an element's flags
205 void AxWin_SetFlags(tElement *Element, int Flags)
207 // Permissions are handled in the message handler
209 gWM_RootElement.Flags = Flags;
213 Element->Flags = Flags;
218 * \brief Set the fixed lenghthways size of an element
220 void AxWin_SetSize(tElement *Element, int Size)
222 if(!Element) return ;
223 Element->FixedWith = Size;
228 * \brief Set the text field of an element
229 * \note Used for the image path on ELETYPE_IMAGE
231 void AxWin_SetText(tElement *Element, const char *Text)
233 if(!Element) return ;
234 if(Element->Text) free(Element->Text);
235 Element->Text = strdup(Text);
237 switch(Element->Type)
240 if(Element->Data) free(Element->Data);
241 Element->Data = Image_Load( Element->Text );
243 Element->Flags &= ~ELEFLAG_FIXEDSIZE;
247 //Element->Flags |= ELEFLAG_FIXEDSIZE;
248 Element->CachedW = ((tImage*)Element->Data)->Width;
249 Element->CachedH = ((tImage*)Element->Data)->Height;
251 if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
252 Element->MinCross = ((tImage*)Element->Data)->Width;
253 Element->MinWith = ((tImage*)Element->Data)->Height;
256 Element->MinWith = ((tImage*)Element->Data)->Width;
257 Element->MinCross = ((tImage*)Element->Data)->Height;
264 Video_GetTextDims(NULL, Element->Text, &w, &h);
265 if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
266 Element->MinCross = w;
267 Element->MinWith = h;
270 Element->MinWith = w;
271 Element->MinCross = h;
275 default: // Any other, no special case