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_CreateAppWindow(tApplication *App, const char *Name)
132 ret = AxWin_CreateElement(&App->MetaElement, ELETYPE_WINDOW, 0, NULL);
133 ret->Text = strdup(Name);
137 // --- Widget Creation and Control ---
138 tAxWin_Element *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName)
141 const char *dbgName = DebugName ? DebugName : "";
143 ret = calloc(sizeof(tElement)+strlen(dbgName)+1, 1);
144 if(!ret) return NULL;
148 strcpy(ret->DebugName, dbgName);
149 if(Parent == NULL) Parent = &gWM_RootElement;
150 ret->Parent = Parent;
153 // Append to parent's list
154 if(Parent->LastChild)
155 Parent->LastChild->NextSibling = ret;
156 Parent->LastChild = ret;
157 if(!Parent->FirstChild) Parent->FirstChild = ret;
164 if( Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Type].Init )
165 gaWM_WidgetTypes[Type].Init(ret);
167 WM_UpdateMinDims(ret->Parent);
173 * \brief Delete an element
175 void AxWin_DeleteElement(tElement *Element)
177 tElement *child, *next;
179 for(child = Element->FirstChild; child; child = next)
181 next = child->NextSibling;
182 AxWin_DeleteElement(child);
185 // TODO: Implement AxWin_DeleteElement
186 // TODO: Clean up related data.
187 if( Element->Type < ciWM_NumWidgetTypes && gaWM_WidgetTypes[Element->Type].Delete )
188 gaWM_WidgetTypes[Element->Type].Delete(Element);
191 Element->Owner->EleIndex[ Element->ApplicationID ] = NULL;
201 * \brief Alter an element's flags
203 void AxWin_SetFlags(tElement *Element, int Flags)
205 // Permissions are handled in the message handler
207 gWM_RootElement.Flags = Flags;
211 Element->Flags = Flags;
216 * \brief Set the fixed lenghthways size of an element
218 void AxWin_SetSize(tElement *Element, int Size)
220 if(!Element) return ;
221 Element->FixedWith = Size;
226 * \brief Set the text field of an element
227 * \note Used for the image path on ELETYPE_IMAGE
229 void AxWin_SetText(tElement *Element, const char *Text)
231 if(!Element) return ;
232 if(Element->Text) free(Element->Text);
233 Element->Text = strdup(Text);
235 switch(Element->Type)
238 if(Element->Data) free(Element->Data);
239 Element->Data = Image_Load( Element->Text );
241 Element->Flags &= ~ELEFLAG_FIXEDSIZE;
245 //Element->Flags |= ELEFLAG_FIXEDSIZE;
246 Element->CachedW = ((tImage*)Element->Data)->Width;
247 Element->CachedH = ((tImage*)Element->Data)->Height;
249 if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
250 Element->MinCross = ((tImage*)Element->Data)->Width;
251 Element->MinWith = ((tImage*)Element->Data)->Height;
254 Element->MinWith = ((tImage*)Element->Data)->Width;
255 Element->MinCross = ((tImage*)Element->Data)->Height;
262 Video_GetTextDims(NULL, Element->Text, &w, &h);
263 if(Element->Parent && Element->Parent->Flags & ELEFLAG_VERTICAL) {
264 Element->MinCross = w;
265 Element->MinWith = h;
268 Element->MinWith = w;
269 Element->MinCross = h;
273 default: // Any other, no special case