X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin2_src%2FWM%2Fwm.c;h=b07322359dc71cdb441c6bfe093d32ebcd46d14c;hb=bd2f2872dd2c125d9200a0465cdeddaf8794e31f;hp=cb4fd27ea2228467722dcb601b2d0dc2e197beb9;hpb=117854336280cdf3d07143820e4d82d92c570239;p=tpg%2Facess2.git diff --git a/Usermode/Applications/axwin2_src/WM/wm.c b/Usermode/Applications/axwin2_src/WM/wm.c index cb4fd27e..b0732235 100644 --- a/Usermode/Applications/axwin2_src/WM/wm.c +++ b/Usermode/Applications/axwin2_src/WM/wm.c @@ -14,6 +14,9 @@ extern void Video_GetTextDims(tFont *Font, const char *Text, int *W, int *H); // === PROTOTYPES === +tApplication *AxWin_RegisterClient(tIPC_Type *IPCType, void *Ident, const char *Name); +void AxWin_DeregisterClient(tApplication *App); +tApplication *AxWin_GetClient(tIPC_Type *Method, void *Ident); tElement *AxWin_CreateElement(tElement *Parent, int Type, int Flags, const char *DebugName); void AxWin_DeleteElement(tElement *Element); void AxWin_SetFlags(tElement *Element, int Flags); @@ -25,8 +28,13 @@ void AxWin_SetText(tElement *Element, const char *Text); tElement gWM_RootElement = { .DebugName = "ROOT" }; - +tWindow *gWM_WindowFirst; +tWindow *gWM_WindowLast; tApplication *gWM_Applications; + int giWM_MaxAreaX = 0; + int giWM_MaxAreaY = 0; + int giWM_MaxAreaW = -1; + int giWM_MaxAreaH = -1; // --- Element type flags struct { @@ -43,19 +51,28 @@ struct { const int ciWM_NumWidgetTypes = sizeof(gaWM_WidgetTypes)/sizeof(gaWM_WidgetTypes[0]); // === CODE === -tApplication *AxWin_RegisterClient(int IdentLen, void *Ident, tMessages_Handle_Callback *Cb, const char *Name) +tApplication *AxWin_RegisterClient(tIPC_Type *Method, void *Ident, const char *Name) { - tApplication *ret = calloc( 1, sizeof(tApplication) + 1 + strlen(Name) + 1 + IdentLen ); + int identlen = Method->GetIdentSize(Ident); + // Structure, empty string, Name, Ident + tApplication *ret = calloc( 1, sizeof(tApplication) + 1 + strlen(Name) + 1 + identlen ); + + // DebugName is empty + // Name/Title ret->Name = &ret->MetaElement.DebugName[1]; strcpy(ret->Name, Name); + // Ident ret->Ident = ret->Name + strlen(Name) + 1; - memcpy(ret->Ident, Ident, IdentLen); - ret->SendMessage = Cb; + memcpy(ret->Ident, Ident, identlen); + // IPC Type + ret->IPCType = Method; + // Element index ret->MaxElementIndex = DEFAULT_ELEMENTS_PER_APP; ret->EleIndex = calloc( 1, ret->MaxElementIndex * sizeof(*ret->EleIndex) ); + // Add to global list ret->Next = gWM_Applications; gWM_Applications = ret; @@ -66,8 +83,8 @@ tApplication *AxWin_RegisterClient(int IdentLen, void *Ident, tMessages_Handle_C void AxWin_DeregisterClient(tApplication *App) { + // TODO: Complete implementing DeregisterClient tElement *win, *next; - // TODO: Implement DeregisterClient for( win = App->MetaElement.FirstChild; win; win = next ) { @@ -76,18 +93,66 @@ void AxWin_DeregisterClient(tApplication *App) } // TODO: Inform listeners of deleted application - // TODO: Remove from list + + // Remove from list + { + tApplication *app, *prev = NULL; + for( app = gWM_Applications; app; app = app->Next ) + { + if( app == App ) break; + prev = app; + } + + if( app ) + { + if(prev) + prev->Next = App->Next; + else + gWM_Applications = App->Next; + } + } + free(App); } -tElement *AxWin_CreateWindow(tApplication *App, const char *Name) +/** + * \brief Get an application handle from a client identifier + */ +tApplication *AxWin_GetClient(tIPC_Type *Method, void *Ident) { - tElement *ret; + // TODO: Faster and smarter technique + tApplication *app; + for( app = gWM_Applications; app; app = app->Next ) + { + if( app->IPCType != Method ) continue; + if( Method->CompareIdent( app->Ident, Ident ) != 0 ) continue; + return app; + } + return NULL; +} - // TODO: Implement _CreateTab +tElement *AxWin_CreateAppWindow(tApplication *App, const char *Name) +{ + tElement *ret; + tWindow *win; + + win = calloc(1, sizeof(tWindow) + 1); + if(!win) return NULL; + + ret = &win->RootElement; + ret->Type = ELETYPE_WINDOW; + ret->Data = win; + ret->Parent = &App->MetaElement; + + // Add to parent list + if(ret->Parent->LastChild) + ret->Parent->LastChild->NextSibling = ret; + ret->Parent->LastChild = ret; + if(!ret->Parent->FirstChild) + ret->Parent->FirstChild = ret; - ret = AxWin_CreateElement(&App->MetaElement, ELETYPE_WINDOW, 0, NULL); ret->Text = strdup(Name); + return ret; }