static void Icon2button(TTBButton *but, HANDLE &hIcoLib, HICON &hIcon, bool bIsUp) { HANDLE hSrc = bIsUp ? but->hIconHandleUp : but->hIconHandleDn; if (hSrc == NULL) { hIcoLib = NULL, hIcon = NULL; return; } hIcoLib = IcoLib_IsManaged((HICON)hSrc); if (!hIcoLib) { char buf[256]; mir_snprintf(buf, "toptoolbar_%s%s", but->name, bIsUp ? (but->hIconDn ? "%s_up" : "%s") : "%s_dn"); SKINICONDESC sid = { 0 }; sid.section.a = "Toolbar"; sid.pszName = buf; sid.defaultFile.a = NULL; mir_snprintf(buf, "%s%s", but->name, bIsUp ? "" : " (pressed)"); sid.description.a = buf; sid.hDefaultIcon = bIsUp ? but->hIconUp : but->hIconDn; hIcoLib = IcoLib_AddIcon(&sid); } hIcon = IcoLib_GetIconByHandle(hIcoLib); }
MIR_APP_DLL(void) ProtoConstructor(PROTO_INTERFACE *pThis, LPCSTR pszModuleName, LPCTSTR ptszUserName) { pThis->m_iVersion = 2; pThis->m_iStatus = pThis->m_iDesiredStatus = ID_STATUS_OFFLINE; pThis->m_szModuleName = mir_strdup(pszModuleName); pThis->m_hProtoIcon = IcoLib_IsManaged(Skin_LoadProtoIcon(pszModuleName, ID_STATUS_ONLINE)); pThis->m_tszUserName = mir_tstrdup(ptszUserName); db_set_resident(pThis->m_szModuleName, "Status"); }
MIR_APP_DLL(HGENMENU) Menu_AddItem(int hMenuObject, TMO_MenuItem *pmi, void *pUserData) { if (!bIsGenMenuInited || pmi == NULL) return NULL; mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo == NULL) return NULL; TMO_IntMenuItem* p = (TMO_IntMenuItem*)mir_calloc(sizeof(TMO_IntMenuItem)); p->parent = pmo; p->signature = MENUITEM_SIGNATURE; p->iCommand = GetNextObjectMenuItemId(); p->mi = *pmi; p->iconId = -1; p->originalPosition = pmi->position; p->pUserData = pUserData; if (pmi->flags & CMIF_UNICODE) p->mi.name.t = mir_tstrdup(pmi->name.t); else p->mi.name.t = mir_a2u(pmi->name.a); if (pmi->hIcon != NULL && !bIconsDisabled) { HANDLE hIcolibItem = IcoLib_IsManaged(pmi->hIcon); if (hIcolibItem != NULL) { HICON hIcon = IcoLib_GetIconByHandle(hIcolibItem, false); p->iconId = ImageList_AddIcon(pmo->m_hMenuIcons, hIcon); p->hIcolibItem = hIcolibItem; IcoLib_ReleaseIcon(hIcon); } else p->iconId = ImageList_AddIcon(pmo->m_hMenuIcons, pmi->hIcon); } TMO_IntMenuItem *pRoot = (p->mi.root != NULL) ? MO_GetIntMenuItem(p->mi.root) : NULL; if (pRoot) { p->owner = &pRoot->submenu; if (pRoot->iconId == -1) pRoot->iconId = p->iconId; } else p->owner = &pmo->m_items; if (!p->owner->first) p->owner->first = p; if (p->owner->last) p->owner->last->next = p; p->owner->last = p; return p; }
MIR_APP_DLL(int) Menu_ModifyItem(HGENMENU hMenuItem, const TCHAR *ptszName, HANDLE hIcolib, int iFlags) { if (!bIsGenMenuInited) return -1; mir_cslock lck(csMenuHook); TMO_IntMenuItem *pimi = MO_GetIntMenuItem(hMenuItem); if (pimi == NULL) return -1; if (ptszName != NULL) replaceStrT(pimi->mi.name.t, ptszName); if (iFlags != -1) { // we allow to set only first 3 bits int oldflags = (pimi->mi.flags & 0xFFFFFFF8); pimi->mi.flags = (iFlags & 0x07) | oldflags; } if (hIcolib != INVALID_HANDLE_VALUE && !bIconsDisabled) { HANDLE hIcolibItem = IcoLib_IsManaged((HICON)hIcolib); if (hIcolibItem) { HICON hIcon = IcoLib_GetIconByHandle(hIcolibItem, false); if (hIcon != NULL) { pimi->hIcolibItem = hIcolibItem; pimi->iconId = ImageList_ReplaceIcon(pimi->parent->m_hMenuIcons, pimi->iconId, hIcon); IcoLib_ReleaseIcon(hIcon); } else pimi->iconId = -1, pimi->hIcolibItem = NULL; } else { pimi->mi.hIcon = (HICON)hIcolib; if (hIcolib != NULL) pimi->iconId = ImageList_ReplaceIcon(pimi->parent->m_hMenuIcons, pimi->iconId, (HICON)hIcolib); else pimi->iconId = -1; //fixme, should remove old icon & shuffle all iconIds } if (pimi->hBmp) { DeleteObject(pimi->hBmp); pimi->hBmp = NULL; } } return 0; }
//wparam=MenuObjectHandle //lparam=PMO_MenuItem //return MenuItemHandle PMO_IntMenuItem MO_AddNewMenuItem( HANDLE menuobjecthandle, PMO_MenuItem pmi ) { if ( !bIsGenMenuInited || pmi == NULL || pmi->cbSize != sizeof( TMO_MenuItem )) return NULL; //old mode if ( !( pmi->flags & CMIF_ROOTHANDLE )) return MO_AddOldNewMenuItem( menuobjecthandle, pmi ); EnterCriticalSection( &csMenuHook ); int objidx = GetMenuObjbyId( (int)menuobjecthandle ); if ( objidx == -1 ) { LeaveCriticalSection( &csMenuHook ); return NULL; } TIntMenuObject* pmo = g_menus[objidx]; TMO_IntMenuItem* p = ( TMO_IntMenuItem* )mir_calloc( sizeof( TMO_IntMenuItem )); p->parent = pmo; p->signature = MENUITEM_SIGNATURE; p->iCommand = GetNextObjectMenuItemId(); p->mi = *pmi; p->iconId = -1; p->OverrideShow = TRUE; p->originalPosition = pmi->position; #if defined( _UNICODE ) if ( pmi->flags & CMIF_UNICODE ) p->mi.ptszName = mir_tstrdup(( pmi->flags & CMIF_KEEPUNTRANSLATED ) ? pmi->ptszName : TranslateTS( pmi->ptszName )); else { if ( pmi->flags & CMIF_KEEPUNTRANSLATED ) p->mi.ptszName = mir_a2u(pmi->pszName); else p->mi.ptszName = LangPackPcharToTchar( pmi->pszName ); } #else p->mi.ptszName = mir_strdup(( pmi->flags & CMIF_KEEPUNTRANSLATED ) ? pmi->ptszName : Translate( pmi->ptszName )); #endif if ( pmi->hIcon != NULL && !bIconsDisabled ) { if ( pmi->flags & CMIF_ICONFROMICOLIB ) { HICON hIcon = IcoLib_GetIconByHandle( pmi->hIcolibItem, false ); p->iconId = ImageList_AddIcon( pmo->m_hMenuIcons, hIcon ); p->hIcolibItem = pmi->hIcolibItem; IconLib_ReleaseIcon( hIcon, 0 ); } else { HANDLE hIcolibItem = IcoLib_IsManaged( pmi->hIcon ); if ( hIcolibItem ) { p->iconId = ImageList_AddIcon( pmo->m_hMenuIcons, pmi->hIcon ); p->hIcolibItem = hIcolibItem; } else p->iconId = ImageList_AddIcon( pmo->m_hMenuIcons, pmi->hIcon ); } } if ( p->mi.root == HGENMENU_ROOT ) p->mi.root = NULL; PMO_IntMenuItem pRoot = ( p->mi.root != NULL ) ? MO_GetIntMenuItem( p->mi.root ) : NULL; if ( pRoot ) p->owner = &pRoot->submenu; else p->owner = &pmo->m_items; if ( !p->owner->first ) p->owner->first = p; if ( p->owner->last ) p->owner->last->next = p; p->owner->last = p; LeaveCriticalSection( &csMenuHook ); return p; }