extern "C" int __declspec(dllexport) CListInitialise(PLUGINLINK * link) { int rc = 0; DBVARIANT dbv; int i; char szProfilePath[MAX_PATH]; pluginLink = link; #ifdef _DEBUG _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif mir_getMMI(&mmi); mir_getLI(&li); mir_getTMI(&tmi); mir_getLP( &pluginInfo ); API::onInit(); LoadCLCButtonModule(); RegisterCLUIFrameClasses(); ZeroMemory((void*) &cfg::dat, sizeof(cfg::dat)); int iCount = CallService(MS_DB_CONTACT_GETCOUNT, 0, 0); iCount += 20; if( iCount < 300 ) iCount = 300; cfg::eCache = reinterpret_cast<TExtraCache *>(malloc(sizeof(TExtraCache) * iCount)); ZeroMemory(cfg::eCache, sizeof(struct TExtraCache) * iCount); cfg::nextCacheEntry = 0; cfg::maxCacheEntry = iCount; cfg::init(); cfg::dat.toolbarVisibility = cfg::getDword("CLUI", "TBVisibility", DEFAULT_TB_VISIBILITY); cfg::dat.hMenuButtons = GetSubMenu(LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_CONTEXT)), 3); cfg::dat.hMenuNotify = CreatePopupMenu(); cfg::dat.wNextMenuID = 1; cfg::dat.sortTimer = cfg::getDword("CLC", "SortTimer", 150); cfg::dat.szNoEvents = TranslateTS(szNoevents); cfg::dat.avatarBorder = (COLORREF)cfg::getDword("CLC", "avatarborder", 0); cfg::dat.avatarRadius = (COLORREF)cfg::getDword("CLC", "avatarradius", 4); cfg::dat.hBrushAvatarBorder = CreateSolidBrush(cfg::dat.avatarBorder); cfg::dat.avatarSize = cfg::getWord("CList", "AvatarSize", 24); cfg::dat.dualRowMode = cfg::getByte("CLC", "DualRowMode", 0); cfg::dat.avatarPadding = cfg::getByte("CList", "AvatarPadding", 0); cfg::dat.isTransparent = cfg::getByte("CList", "Transparent", 0); cfg::dat.alpha = cfg::getByte("CList", "Alpha", SETTING_ALPHA_DEFAULT); cfg::dat.autoalpha = cfg::getByte("CList", "AutoAlpha", SETTING_ALPHA_DEFAULT); cfg::dat.fadeinout = cfg::getByte("CLUI", "FadeInOut", 0); cfg::dat.autosize = cfg::getByte("CLUI", "AutoSize", 0); cfg::dat.dwExtraImageMask = cfg::getDword("CLUI", "ximgmask", 0); cfg::dat.bNoOfflineAvatars = cfg::getByte("CList", "NoOfflineAV", 1); cfg::dat.bFullTransparent = cfg::getByte("CLUI", "fulltransparent", 0); cfg::dat.bDblClkAvatars = cfg::getByte("CLC", "dblclkav", 0); cfg::dat.bEqualSections = cfg::getByte("CLUI", "EqualSections", 0); cfg::dat.bCenterStatusIcons = cfg::getByte("CLC", "si_centered", 1); cfg::dat.boldHideOffline = -1; cfg::dat.bSecIMAvail = ServiceExists("SecureIM/IsContactSecured") ? 1 : 0; cfg::dat.bNoTrayTips = cfg::getByte("CList", "NoTrayTips", 0); cfg::dat.bShowLocalTime = cfg::getByte("CLC", "ShowLocalTime", 1); cfg::dat.bShowLocalTimeSelective = cfg::getByte("CLC", "SelectiveLocalTime", 1); cfg::dat.bDontSeparateOffline = cfg::getByte("CList", "DontSeparateOffline", 0); cfg::dat.bShowXStatusOnSbar = cfg::getByte("CLUI", "xstatus_sbar", 0); cfg::dat.bLayeredHack = cfg::getByte("CLUI", "layeredhack", 1); cfg::dat.bFirstRun = cfg::getByte("CLUI", "firstrun", 1); cfg::dat.langPackCP = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0); cfg::dat.realTimeSaving = cfg::getByte("CLUI", "save_pos_always", 0); DWORD sortOrder = cfg::getDword("CList", "SortOrder", SORTBY_NAME); cfg::dat.sortOrder[0] = LOBYTE(LOWORD(sortOrder)); cfg::dat.sortOrder[1] = HIBYTE(LOWORD(sortOrder)); cfg::dat.sortOrder[2] = LOBYTE(HIWORD(sortOrder)); if(cfg::dat.bFirstRun) cfg::writeByte("CLUI", "firstrun", 0); if(!cfg::getString(NULL, "CLUI", "exIconOrder", &dbv)) { if(lstrlenA(dbv.pszVal) < EXICON_COUNT) { for(i = 1; i <= EXICON_COUNT; i++) cfg::dat.exIconOrder[i - 1] = i; } else { for(i = 0; i < EXICON_COUNT; i++) if(dbv.pszVal[i] < EXICON_COUNT+1 && dbv.pszVal[i] >0) cfg::dat.exIconOrder[i] = dbv.pszVal[i]; else cfg::dat.exIconOrder[i] = i+1; } DBFreeVariant(&dbv); } else { for(i = 1; i <= EXICON_COUNT; i++) cfg::dat.exIconOrder[i - 1] = i; } ReloadThemedOptions(); FLT_ReadOptions(); Reload3dBevelColors(); himlExtraImages = ImageList_Create(16, 16, ILC_MASK | (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16), 30, 2); ImageList_SetIconSize(himlExtraImages, cfg::dat.exIconScale, cfg::dat.exIconScale); cfg::dat.dwFlags = cfg::getDword("CLUI", "Frameflags", CLUI_FRAME_SHOWTOPBUTTONS | CLUI_FRAME_STATUSICONS | CLUI_FRAME_SHOWBOTTOMBUTTONS | CLUI_FRAME_BUTTONSFLAT | CLUI_FRAME_CLISTSUNKEN); cfg::dat.dwFlags |= (cfg::getByte("CLUI", "ShowSBar", 1) ? CLUI_FRAME_SBARSHOW : 0); cfg::dat.soundsOff = cfg::getByte("CLUI", "NoSounds", 0); CallService(MS_DB_GETPROFILEPATH, MAX_PATH, (LPARAM)szProfilePath); #if defined(_UNICODE) MultiByteToWideChar(CP_ACP, 0, szProfilePath, MAX_PATH, cfg::dat.tszProfilePath, MAX_PATH); cfg::dat.tszProfilePath[MAX_PATH - 1] = 0; #else mir_sntprintf(cfg::dat.tszProfilePath, MAX_PATH, "%s", szProfilePath); #endif _tcslwr(cfg::dat.tszProfilePath); if(cfg::getByte("Skin", "UseSound", 0) != cfg::dat.soundsOff) cfg::writeByte("Skin", "UseSound", (BYTE)(cfg::dat.soundsOff ? 0 : 1)); // get the clist interface pcli = ( CLIST_INTERFACE* )CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, (LPARAM)g_hInst); if ( (INT_PTR)pcli == CALLSERVICE_NOTFOUND ) { LBL_Error: MessageBoxA( NULL, "This plugin requires Miranda IM 0.8.0.9 or later", "Fatal error", MB_OK ); return 1; } if ( pcli->version < 6 ) // don't join it with the previous if() goto LBL_Error; pcli->pfnBuildGroupPopupMenu = BuildGroupPopupMenu; pcli->pfnCluiProtocolStatusChanged = CluiProtocolStatusChanged; pcli->pfnCompareContacts = CompareContacts; pcli->pfnCreateClcContact = CreateClcContact; pcli->pfnCreateEvent = fnCreateEvent; pcli->pfnDocking_ProcessWindowMessage = Docking_ProcessWindowMessage; pcli->pfnGetDefaultFontSetting = GetDefaultFontSetting; pcli->pfnGetRowBottomY = RowHeight::getItemBottomY; pcli->pfnGetRowHeight = RowHeight::getHeight; pcli->pfnGetRowTopY = RowHeight::getItemTopY; pcli->pfnGetRowTotalHeight = RowHeight::getTotalHeight; pcli->pfnGetWindowVisibleState = GetWindowVisibleState; pcli->pfnHitTest = HitTest; pcli->pfnLoadContactTree = LoadContactTree; pcli->pfnOnCreateClc = LoadCLUIModule; pcli->pfnPaintClc = PaintClc; pcli->pfnRebuildEntireList = RebuildEntireList; pcli->pfnRowHitTest = RowHeight::hitTest; pcli->pfnScrollTo = ScrollTo; pcli->pfnTrayIconUpdateBase = TrayIconUpdateBase; pcli->pfnSetHideOffline = SetHideOffline; pcli->pfnShowHide = ShowHide; saveAddContactToGroup = pcli->pfnAddContactToGroup; pcli->pfnAddContactToGroup = AddContactToGroup; saveRemoveItemFromGroup = pcli->pfnRemoveItemFromGroup; pcli->pfnRemoveItemFromGroup = RemoveItemFromGroup; saveAddEvent = pcli->pfnAddEvent; pcli->pfnAddEvent = AddEvent; saveRemoveEvent = pcli->pfnRemoveEvent; pcli->pfnRemoveEvent = RemoveEvent; saveAddGroup = pcli->pfnAddGroup; pcli->pfnAddGroup = AddGroup; saveAddInfoItemToGroup = pcli->pfnAddInfoItemToGroup; pcli->pfnAddInfoItemToGroup = AddInfoItemToGroup; saveContactListControlWndProc = pcli->pfnContactListControlWndProc; pcli->pfnContactListControlWndProc = ContactListControlWndProc; saveContactListWndProc = pcli->pfnContactListWndProc; pcli->pfnContactListWndProc = ContactListWndProc; saveIconFromStatusMode = pcli->pfnIconFromStatusMode; pcli->pfnIconFromStatusMode = fnIconFromStatusMode; saveLoadClcOptions = pcli->pfnLoadClcOptions; pcli->pfnLoadClcOptions = LoadClcOptions; saveProcessExternalMessages = pcli->pfnProcessExternalMessages; pcli->pfnProcessExternalMessages = ProcessExternalMessages; saveRecalcScrollBar = pcli->pfnRecalcScrollBar; pcli->pfnRecalcScrollBar = RecalcScrollBar; saveTrayIconProcessMessage = pcli->pfnTrayIconProcessMessage; pcli->pfnTrayIconProcessMessage = TrayIconProcessMessage; rc = LoadContactListModule(); if (rc == 0) rc = LoadCLCModule(); HookEvent(ME_SYSTEM_MODULESLOADED, systemModulesLoaded); return rc; }
static INT_PTR CALLBACK GenMenuOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct OrderData *dat = (struct OrderData*)GetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_USERDATA); LPNMHDR hdr; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); dat=(struct OrderData*)mir_alloc(sizeof(struct OrderData)); SetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_USERDATA,(LONG_PTR)dat); dat->dragging = 0; dat->iInitMenuValue = DBGetContactSettingByte( NULL, "CList", "MoveProtoMenus", FALSE ); MyOldWindowProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_WNDPROC); SetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_WNDPROC,(LONG_PTR)&LBTNDOWNProc); { HIMAGELIST himlCheckBoxes; himlCheckBoxes=ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 2, 2); ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_NOTICK); ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_TICK); TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_MENUOBJECTS),himlCheckBoxes,TVSIL_NORMAL); TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_MENUITEMS),himlCheckBoxes,TVSIL_NORMAL); } CheckDlgButton(hwndDlg, dat->iInitMenuValue ? IDC_RADIO2 : IDC_RADIO1, TRUE ); CheckDlgButton(hwndDlg, IDC_DISABLEMENUICONS, bIconsDisabled ); BuildMenuObjectsTree(hwndDlg); return TRUE; case WM_COMMAND: if ( HIWORD(wParam) == BN_CLICKED || HIWORD( wParam ) == BN_DBLCLK ) { switch ( LOWORD( wParam )) { case IDC_INSERTSEPARATOR: InsertSeparator(hwndDlg); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RESETMENU: ResetMenuItems( hwndDlg ); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; case IDC_DISABLEMENUICONS: case IDC_RADIO1: case IDC_RADIO2: SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; case IDC_GENMENU_DEFAULT: { TVITEM tvi; HTREEITEM hti; MenuItemOptData *iod; hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_MENUITEMS)); if (hti==NULL) break; tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem=hti; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),&tvi); iod = ( MenuItemOptData * )tvi.lParam; if ( iod->name && _tcsstr( iod->name, STR_SEPARATOR )) break; if (iod->name) mir_free(iod->name); iod->name = mir_tstrdup( iod->defname ); SaveTree(hwndDlg); RebuildCurrent(hwndDlg); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); } break; case IDC_GENMENU_SET: { TVITEM tvi; TCHAR buf[256]; MenuItemOptData *iod; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg,IDC_MENUITEMS )); if ( hti == NULL ) break; tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem = hti; SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_GETITEM, 0, (LPARAM)&tvi); iod = ( MenuItemOptData * )tvi.lParam; if ( iod->name && _tcsstr(iod->name, STR_SEPARATOR )) break; ZeroMemory(buf,sizeof( buf )); GetDlgItemText( hwndDlg, IDC_GENMENU_CUSTOMNAME, buf, SIZEOF( buf )); if (iod->name) mir_free(iod->name); iod->name = mir_tstrdup(buf); SaveTree(hwndDlg); RebuildCurrent(hwndDlg); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); } break; } } break; case WM_NOTIFY: hdr = (LPNMHDR)lParam; switch( hdr->idFrom ) { case 0: if (hdr->code == PSN_APPLY ) { bIconsDisabled = IsDlgButtonChecked(hwndDlg, IDC_DISABLEMENUICONS) != 0; DBWriteContactSettingByte(NULL, "CList", "DisableMenuIcons", bIconsDisabled); SaveTree(hwndDlg); int iNewMenuValue = IsDlgButtonChecked(hwndDlg, IDC_RADIO1) ? 0 : 1; if ( iNewMenuValue != dat->iInitMenuValue ) { RebuildProtoMenus( iNewMenuValue ); dat->iInitMenuValue = iNewMenuValue; } RebuildCurrent(hwndDlg); } break; case IDC_MENUOBJECTS: if (hdr->code == TVN_SELCHANGEDA ) RebuildCurrent( hwndDlg ); break; case IDC_MENUITEMS: switch (hdr->code) { case NM_CUSTOMDRAW: { int i= handleCustomDraw(GetDlgItem(hwndDlg,IDC_MENUITEMS),(LPNMTVCUSTOMDRAW) lParam); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, i); return TRUE; } case TVN_BEGINDRAGA: SetCapture(hwndDlg); dat->dragging=1; dat->hDragItem=((LPNMTREEVIEW)lParam)->itemNew.hItem; TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),dat->hDragItem); break; case NM_CLICK: { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(GetMessagePos()); hti.pt.y=(short)HIWORD(GetMessagePos()); ScreenToClient(hdr->hwndFrom,&hti.pt); if (TreeView_HitTest(hdr->hwndFrom,&hti)) { if (hti.flags&TVHT_ONITEMICON) { TVITEM tvi; tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem=hti.hItem; TreeView_GetItem(hdr->hwndFrom,&tvi); tvi.iImage=tvi.iSelectedImage=!tvi.iImage; ((MenuItemOptData *)tvi.lParam)->show=tvi.iImage; TreeView_SetItem(hdr->hwndFrom,&tvi); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); //all changes take effect in runtime //ShowWindow(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREEWARNING),SW_SHOW); } /*--------MultiSelection----------*/ if (hti.flags&TVHT_ONITEMLABEL) { /// LabelClicked Set/unset selection TVITEM tvi; HWND tvw=hdr->hwndFrom; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hti.hItem; TreeView_GetItem(tvw,&tvi); if (GetKeyState(VK_CONTROL)&0x8000) { if (((MenuItemOptData *)tvi.lParam)->isSelected) ((MenuItemOptData *)tvi.lParam)->isSelected=0; else ((MenuItemOptData *)tvi.lParam)->isSelected=1; //current selection order++. TreeView_SetItem(tvw,&tvi); } else if (GetKeyState(VK_SHIFT)&0x8000) { ; // shifted click } else { // reset all selection except current HTREEITEM hit; hit=TreeView_GetRoot(tvw); if (hit) do { TVITEM tvi={0}; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hit; TreeView_GetItem(tvw,&tvi); if (hti.hItem!=hit) ((MenuItemOptData *)tvi.lParam)->isSelected=0; else ((MenuItemOptData *)tvi.lParam)->isSelected=1; TreeView_SetItem(tvw,&tvi); } while (hit=TreeView_GetNextSibling(tvw,hit)); } } } break; } case TVN_SELCHANGING: { LPNMTREEVIEW pn; pn = (LPNMTREEVIEW) lParam; //((MenuItemOptData *)(pn->itemNew.lParam))->isSelected=1; /*if (pn->action==NotKeyPressed) { remove all selection } */ } case TVN_SELCHANGEDA: { TVITEM tvi; HTREEITEM hti; MenuItemOptData *iod; SetDlgItemTextA(hwndDlg,IDC_GENMENU_CUSTOMNAME,""); SetDlgItemTextA(hwndDlg,IDC_GENMENU_SERVICE,""); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_CUSTOMNAME),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_DEFAULT),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_SET),FALSE); hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_MENUITEMS)); if (hti==NULL) break; tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem=hti; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),&tvi); if ( tvi.lParam == 0 ) break; iod = ( MenuItemOptData * )tvi.lParam; if ( iod->name && _tcsstr(iod->name, STR_SEPARATOR)) break; SetDlgItemText(hwndDlg,IDC_GENMENU_CUSTOMNAME,iod->name); if (iod->pimi->submenu.first == NULL && iod->uniqname) SetDlgItemTextA(hwndDlg, IDC_GENMENU_SERVICE, iod->uniqname); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_DEFAULT), lstrcmp(iod->name, iod->defname) != 0); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_SET),TRUE); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_CUSTOMNAME),TRUE); break; } break; } } break; case WM_MOUSEMOVE: if (!dat||!dat->dragging) break; { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(lParam); hti.pt.y=(short)HIWORD(lParam); ClientToScreen(hwndDlg,&hti.pt); ScreenToClient(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti.pt); TreeView_HitTest(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti); if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) { HTREEITEM it = hti.hItem; hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_MENUITEMS))/2; TreeView_HitTest(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti); if (!(hti.flags&TVHT_ABOVE)) TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti.hItem,1); else TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),it,0); } else { if (hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg,IDC_MENUITEMS,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0); if (hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg,IDC_MENUITEMS,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0); TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),NULL,0); } } break; case WM_LBUTTONUP: if (!dat->dragging) break; TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),NULL,0); dat->dragging=0; ReleaseCapture(); { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(lParam); hti.pt.y=(short)HIWORD(lParam); ClientToScreen(hwndDlg,&hti.pt); ScreenToClient(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti.pt); hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_MENUITEMS))/2; TreeView_HitTest(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti); if (hti.flags&TVHT_ABOVE) hti.hItem=TVI_FIRST; if (dat->hDragItem==hti.hItem) break; dat->hDragItem=NULL; if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)||(hti.hItem==TVI_FIRST)) { HWND tvw; HTREEITEM * pSIT; HTREEITEM FirstItem=NULL; UINT uITCnt,uSic ; tvw=GetDlgItem(hwndDlg,IDC_MENUITEMS); uITCnt=TreeView_GetCount(tvw); uSic=0; if (uITCnt) { pSIT=(HTREEITEM *)mir_alloc(sizeof(HTREEITEM)*uITCnt); if (pSIT) { HTREEITEM hit; hit=TreeView_GetRoot(tvw); if (hit) do { TVITEM tvi={0}; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hit; TreeView_GetItem(tvw,&tvi); if (((MenuItemOptData *)tvi.lParam)->isSelected) { pSIT[uSic]=tvi.hItem; uSic++; } }while (hit=TreeView_GetNextSibling(tvw,hit)); // Proceed moving { UINT i; HTREEITEM insertAfter; insertAfter=hti.hItem; for (i=0; i<uSic; i++) { if (insertAfter) insertAfter=MoveItemAbove(tvw,pSIT[i],insertAfter); else break; if (!i) FirstItem=insertAfter; } } // free pointers... mir_free(pSIT); } } if (FirstItem) TreeView_SelectItem(tvw,FirstItem); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); SaveTree(hwndDlg); } } break; case WM_DESTROY: if ( dat ) mir_free( dat ); ImageList_Destroy(TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_MENUOBJECTS),NULL,TVSIL_NORMAL)); FreeTreeData( hwndDlg ); break; } return FALSE; }
static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MButtonCtrl *bct = (MButtonCtrl *) GetWindowLong(hwndDlg, 0); switch (msg) { case WM_NCCREATE: { SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE) | BS_OWNERDRAW); bct = malloc(sizeof(MButtonCtrl)); if (bct == NULL) return FALSE; bct->hwnd = hwndDlg; bct->stateId = PBS_NORMAL; bct->focus = 0; bct->hFont = GetStockObject(DEFAULT_GUI_FONT); bct->arrow = NULL; bct->defbutton = 0; bct->hIcon = bct->hIconPrivate = 0; bct->iIcon = 0; bct->hIml = 0; bct->hBitmap = NULL; bct->pushBtn = 0; bct->pbState = 0; bct->hThemeButton = NULL; bct->hThemeToolbar = NULL; bct->cHot = 0; bct->flatBtn = 0; bct->bThemed = FALSE; bct->bSkinned = bct->bSendOnDown = 0; bct->buttonItem = NULL; LoadTheme(bct); SetWindowLong(hwndDlg, 0, (LONG) bct); if (((CREATESTRUCTA *) lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *) lParam)->lpszName); return TRUE; } case WM_DESTROY: { if (bct) { if (hwndToolTips) { TOOLINFO ti; ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT) bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti); } if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM) &ti) == 0) { DestroyWindow(hwndToolTips); hwndToolTips = NULL; } } if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); DestroyTheme(bct); free(bct); } SetWindowLong(hwndDlg, 0, (LONG) NULL); break; // DONT! fall thru } case WM_SETTEXT: { bct->cHot = 0; if ((char*) lParam) { char *tmp = (char *) lParam; while (*tmp) { if (*tmp == '&' && *(tmp + 1)) { bct->cHot = tolower(*(tmp + 1)); break; } tmp++; } InvalidateRect(bct->hwnd, NULL, TRUE); lstrcpyn(bct->szText, (TCHAR *)lParam, 127); bct->szText[127] = 0; } break; } case WM_SYSKEYUP: if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int) wParam)) { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; InvalidateRect(bct->hwnd, NULL, TRUE); } if(!bct->bSendOnDown) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); return 0; } break; case WM_THEMECHANGED: { // themed changed, reload theme object if (bct->bThemed) LoadTheme(bct); InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it break; } case WM_SETFONT: // remember the font so we can use it later { bct->hFont = (HFONT) wParam; // maybe we should redraw? break; } case WM_NCPAINT: case WM_PAINT: { PAINTSTRUCT ps; HDC hdcPaint; hdcPaint = BeginPaint(hwndDlg, &ps); if (hdcPaint) { PaintWorker(bct, hdcPaint); EndPaint(hwndDlg, &ps); } break; } case BM_GETIMAGE: if(wParam == IMAGE_ICON) return (LRESULT)(bct->hIconPrivate ? bct->hIconPrivate : bct->hIcon); break; case BM_SETIMAGE: if(!lParam) break; bct->hIml = 0; bct->iIcon = 0; if (wParam == IMAGE_ICON) { ICONINFO ii = {0}; BITMAP bm = {0}; if (bct->hIconPrivate) { DestroyIcon(bct->hIconPrivate); bct->hIconPrivate = 0; } GetIconInfo((HICON) lParam, &ii); GetObject(ii.hbmColor, sizeof(bm), &bm); if (bm.bmWidth > g_cxsmIcon || bm.bmHeight > g_cysmIcon) { HIMAGELIST hImageList; hImageList = ImageList_Create(g_cxsmIcon, g_cysmIcon, IsWinVerXPPlus() ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0); ImageList_AddIcon(hImageList, (HICON) lParam); bct->hIconPrivate = ImageList_GetIcon(hImageList, 0, ILD_NORMAL); ImageList_RemoveAll(hImageList); ImageList_Destroy(hImageList); bct->hIcon = 0; } else { bct->hIcon = (HICON) lParam; bct->hIconPrivate = 0; } DeleteObject(ii.hbmMask); DeleteObject(ii.hbmColor); bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == IMAGE_BITMAP) { bct->hBitmap = (HBITMAP) lParam; if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIcon = bct->hIconPrivate = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case BM_SETPRIVATEICON: bct->hIml = 0; bct->iIcon = 0; { if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIconPrivate = DuplicateIcon(g_hInst, (HICON) lParam); bct->hIcon = 0; break; } case BM_SETIMLICON: { if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIml = (HIMAGELIST) wParam; bct->iIcon = (int) lParam; bct->hIcon = bct->hIconPrivate = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case BM_SETSKINNED: bct->bSkinned = (DWORD)lParam; bct->bThemed = bct->bSkinned ? FALSE : bct->bThemed; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_SETBTNITEM: bct->buttonItem = (ButtonItem *)lParam; break; case BM_SETASMENUACTION: bct->bSendOnDown = wParam ? TRUE : FALSE; return 0; case BM_SETCHECK: if (!bct->pushBtn) break; if (wParam == BST_CHECKED) { bct->pbState = 1; bct->stateId = PBS_PRESSED; } else if (wParam == BST_UNCHECKED) { bct->pbState = 0; bct->stateId = PBS_NORMAL; } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_GETCHECK: if (bct->pushBtn) { return bct->pbState ? BST_CHECKED : BST_UNCHECKED; } return 0; case BUTTONSETARROW: // turn arrow on/off if (wParam) { if (!bct->arrow) bct->arrow = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_MINIMIZE), IMAGE_ICON, g_cxsmIcon, g_cysmIcon, 0); } else { if (bct->arrow) { DestroyIcon(bct->arrow); bct->arrow = NULL; } } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETDEFAULT: bct->defbutton = wParam ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASPUSHBTN: bct->pushBtn = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN: bct->flatBtn = lParam == 0 ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN + 10: bct->bThemed = lParam ? TRUE : FALSE; bct->bSkinned = bct->bThemed ? 0 : bct->bSkinned; break; case BUTTONADDTOOLTIP: { TOOLINFO ti; if (!(char*) wParam) break; if (!hwndToolTips) { hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); SetWindowPos(hwndToolTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT) bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM) &ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM) &ti); } ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT) bct->hwnd; ti.lpszText = (TCHAR *) wParam; SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti); break; } case WM_SETFOCUS: // set keybord focus and redraw bct->focus = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_KILLFOCUS: // kill focus and redraw bct->focus = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_WINDOWPOSCHANGED: InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_ENABLE: // windows tells us to enable/disable { bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case WM_MOUSELEAVE: // faked by the WM_TIMER { if (bct->stateId != PBS_DISABLED) { // don't change states if disabled bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; } case WM_LBUTTONDOWN: { if (bct->stateId != PBS_DISABLED && bct->stateId != PBS_PRESSED) { bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); if(bct->bSendOnDown) { SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } } break; } case WM_LBUTTONUP: { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; } if (bct->stateId != PBS_DISABLED) { // don't change states if disabled if (msg == WM_LBUTTONUP) bct->stateId = PBS_HOT; else bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } if(!bct->bSendOnDown) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); break; } case WM_MOUSEMOVE: if (bct->stateId == PBS_NORMAL) { bct->stateId = PBS_HOT; InvalidateRect(bct->hwnd, NULL, TRUE); } // Call timer, used to start cheesy TrackMouseEvent faker SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); break; case WM_NCHITTEST: { LRESULT lr = SendMessage(GetParent(hwndDlg), WM_NCHITTEST, wParam, lParam); if(lr == HTLEFT || lr == HTRIGHT || lr == HTBOTTOM || lr == HTTOP || lr == HTTOPLEFT || lr == HTTOPRIGHT || lr == HTBOTTOMLEFT || lr == HTBOTTOMRIGHT) return HTTRANSPARENT; break; } case WM_TIMER: // use a timer to check if they have did a mouseout { if (wParam == BUTTON_POLLID) { RECT rc; POINT pt; GetWindowRect(hwndDlg, &rc); GetCursorPos(&pt); if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L); KillTimer(hwndDlg, BUTTON_POLLID); } } break; } case WM_ERASEBKGND: return 1; } return DefWindowProc(hwndDlg, msg, wParam, lParam); }
void LoadProtocolIcons() { PROTOCOLDESCRIPTOR **pProtos; int i, j, allProtoNum, k; HICON hIcon; CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM) &allProtoNum, (LPARAM) &pProtos); g_dat->protoNum = 0; for(i = 0; i < allProtoNum; i++) { if (pProtos[i]->type == PROTOTYPE_PROTOCOL) g_dat->protoNum++; } if (g_dat->protoNames != NULL) { for(i = 0; i < g_dat->protoNum; i++) { if (g_dat->protoNames[i] != NULL) { mir_free(g_dat->protoNames[i]); } } mir_free(g_dat->protoNames); } g_dat->protoNames = (char **) mir_alloc(sizeof(char*) * g_dat->protoNum); if (g_dat->hTabIconList == NULL) { g_dat->hTabIconList = ImageList_Create(16, 16, IsWinVerXPPlus() ? ILC_COLOR32 | ILC_MASK : ILC_COLOR8 | ILC_MASK, (g_dat->protoNum + 1) * 12 + 8, 0); ImageList_AddIcon(g_dat->hTabIconList, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); ImageList_AddIcon(g_dat->hTabIconList, g_dat->hIcons[SMF_ICON_TYPING]); for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { ImageList_AddIcon(g_dat->hTabIconList, LoadSkinnedProtoIcon(NULL, i)); } for(i = j = 0; i < allProtoNum; i++) { if (pProtos[i]->type != PROTOTYPE_PROTOCOL) continue; g_dat->protoNames[j] = mir_strdup(pProtos[i]->szName); for (k = ID_STATUS_OFFLINE; k <= ID_STATUS_OUTTOLUNCH; k++) { hIcon = LoadSkinnedProtoIcon(pProtos[i]->szName, k); if (hIcon != NULL) { ImageList_AddIcon(g_dat->hTabIconList, hIcon); } else { ImageList_AddIcon(g_dat->hTabIconList, LoadSkinnedProtoIcon(NULL, ID_STATUS_OFFLINE)); } } j++; } } else { int index = 0; ImageList_ReplaceIcon(g_dat->hTabIconList, index++, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); ImageList_ReplaceIcon(g_dat->hTabIconList, index++, g_dat->hIcons[SMF_ICON_TYPING]); for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { ImageList_ReplaceIcon(g_dat->hTabIconList, index++, LoadSkinnedProtoIcon(NULL, i)); } for(i = j = 0; i < allProtoNum; i++) { if (pProtos[i]->type != PROTOTYPE_PROTOCOL) continue; g_dat->protoNames[j] = mir_strdup(pProtos[i]->szName); for (k = ID_STATUS_OFFLINE; k <= ID_STATUS_OUTTOLUNCH; k++) { hIcon = LoadSkinnedProtoIcon(pProtos[i]->szName, k); if (hIcon != NULL) { ImageList_ReplaceIcon(g_dat->hTabIconList, index++, hIcon); } else { ImageList_ReplaceIcon(g_dat->hTabIconList, index++, LoadSkinnedProtoIcon(NULL, ID_STATUS_OFFLINE)); } } j++; } } }