static int BuildMenuObjectsTree(HWND hwndDlg) { TVINSERTSTRUCT tvis; HWND hTree = GetDlgItem(hwndDlg,IDC_MENUOBJECTS); int i; tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; TreeView_DeleteAllItems( hTree ); if ( g_menus.getCount() == 0 ) return FALSE; for ( i=0; i < g_menus.getCount(); i++ ) { if ( g_menus[i]->id == (int)hStatusMenuObject || !g_menus[i]->m_bUseUserDefinedItems ) continue; tvis.item.lParam = ( LPARAM )g_menus[i]->id; tvis.item.pszText = LangPackPcharToTchar( g_menus[i]->Name ); tvis.item.iImage = tvis.item.iSelectedImage = TRUE; TreeView_InsertItem( hTree, &tvis ); mir_free( tvis.item.pszText ); } return 1; }
PMO_IntMenuItem MO_AddOldNewMenuItem( HANDLE menuobjecthandle, PMO_MenuItem pmi ) { if ( !bIsGenMenuInited || pmi == NULL ) return NULL; int objidx = GetMenuObjbyId( (int)menuobjecthandle ); if ( objidx == -1 ) return NULL; if ( pmi->cbSize != sizeof( TMO_MenuItem )) return NULL; if ( pmi->flags & CMIF_ROOTHANDLE ) return NULL; //is item with popup or not if ( pmi->root == 0 ) { //yes,this without popup pmi->root = NULL; //first level } else { // no,search for needed root and create it if need TCHAR* tszRoot; #if defined( _UNICODE ) if ( pmi->flags & CMIF_UNICODE ) tszRoot = mir_tstrdup(TranslateTS(( TCHAR* )pmi->root )); else tszRoot = LangPackPcharToTchar(( char* )pmi->root ); #else tszRoot = mir_tstrdup(TranslateTS(( TCHAR* )pmi->root )); #endif PMO_IntMenuItem oldroot = MO_RecursiveWalkMenu( g_menus[objidx]->m_items.first, FindRoot, tszRoot ); mir_free( tszRoot ); if ( oldroot == NULL ) { //not found,creating root TMO_MenuItem tmi = { 0 }; tmi = *pmi; tmi.flags |= CMIF_ROOTHANDLE; tmi.ownerdata = 0; tmi.root = NULL; //copy pszPopupName tmi.ptszName = ( TCHAR* )pmi->root; if (( oldroot = MO_AddNewMenuItem( menuobjecthandle, &tmi )) != NULL ) MO_SetOptionsMenuItem( oldroot, OPT_MENUITEMSETUNIQNAME, (INT_PTR)pmi->root ); } pmi->root = oldroot; //popup will be created in next commands } pmi->flags |= CMIF_ROOTHANDLE; //add popup(root allready exists) return MO_AddNewMenuItem( menuobjecthandle, pmi ); }
static int FindDbProviders(const char*, DATABASELINK * dblink, LPARAM lParam) { HWND hwndDlg = (HWND)lParam; HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS); char szName[64]; if ( dblink->getFriendlyName(szName,SIZEOF(szName),1) == 0 ) { // add to combo box TCHAR* p = LangPackPcharToTchar( szName ); LRESULT index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)p ); mir_free( p ); SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)dblink); } return DBPE_CONT; }
static int AddProfileManagerPage(struct DetailsPageInit * opi, OPTIONSDIALOGPAGE * odp) { if ( odp->cbSize != sizeof( OPTIONSDIALOGPAGE )) return 1; opi->odp = ( OPTIONSDIALOGPAGE* )mir_realloc( opi->odp, sizeof( OPTIONSDIALOGPAGE )*( opi->pageCount+1 )); { OPTIONSDIALOGPAGE* p = opi->odp + opi->pageCount++; p->cbSize = sizeof(OPTIONSDIALOGPAGE); p->hInstance = odp->hInstance; p->pfnDlgProc = odp->pfnDlgProc; p->position = odp->position; p->ptszTitle = LangPackPcharToTchar(odp->pszTitle); p->pszGroup = NULL; p->groupPosition = odp->groupPosition; p->hGroupIcon = odp->hGroupIcon; p->hIcon = odp->hIcon; if (( DWORD_PTR )odp->pszTemplate & 0xFFFF0000 ) p->pszTemplate = mir_strdup( odp->pszTemplate ); else p->pszTemplate = odp->pszTemplate; } 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; }
//wparam MenuItemHandle //lparam PMO_MenuItem int MO_ModifyMenuItem( PMO_IntMenuItem menuHandle, PMO_MenuItem pmi ) { int oldflags; if ( !bIsGenMenuInited || pmi == NULL || pmi->cbSize != sizeof( TMO_MenuItem )) return -1; EnterCriticalSection( &csMenuHook ); PMO_IntMenuItem pimi = MO_GetIntMenuItem(( HGENMENU )menuHandle ); if ( !pimi ) { LeaveCriticalSection( &csMenuHook ); return -1; } if ( pmi->flags & CMIM_NAME ) { FreeAndNil(( void** )&pimi->mi.pszName ); #if defined( _UNICODE ) if ( pmi->flags & CMIF_UNICODE ) pimi->mi.ptszName = mir_tstrdup(( pmi->flags & CMIF_KEEPUNTRANSLATED ) ? pmi->ptszName : TranslateTS( pmi->ptszName )); else { if ( pmi->flags & CMIF_KEEPUNTRANSLATED ) { int len = lstrlenA( pmi->pszName ); pimi->mi.ptszName = ( TCHAR* )mir_alloc( sizeof( TCHAR )*( len+1 )); MultiByteToWideChar( CP_ACP, 0, pmi->pszName, -1, pimi->mi.ptszName, len+1 ); pimi->mi.ptszName[ len ] = 0; } else pimi->mi.ptszName = LangPackPcharToTchar( pmi->pszName ); } #else pimi->mi.ptszName = mir_strdup(( pmi->flags & CMIF_KEEPUNTRANSLATED ) ? pmi->ptszName : Translate( pmi->ptszName )); #endif } if ( pmi->flags & CMIM_FLAGS ) { oldflags = pimi->mi.flags & ( CMIF_ROOTHANDLE | CMIF_ICONFROMICOLIB ); pimi->mi.flags = (pmi->flags & ~CMIM_ALL) | oldflags; } if ( (pmi->flags & CMIM_ICON) && !bIconsDisabled ) { if ( pimi->mi.flags & CMIF_ICONFROMICOLIB ) { HICON hIcon = IcoLib_GetIconByHandle( pmi->hIcolibItem, false ); if ( hIcon != NULL ) { pimi->hIcolibItem = pmi->hIcolibItem; pimi->iconId = ImageList_ReplaceIcon( pimi->parent->m_hMenuIcons, pimi->iconId, hIcon ); IconLib_ReleaseIcon( hIcon, 0 ); } else pimi->iconId = -1, pimi->hIcolibItem = NULL; } else { pimi->mi.hIcon = pmi->hIcon; if ( pmi->hIcon != NULL ) pimi->iconId = ImageList_ReplaceIcon( pimi->parent->m_hMenuIcons, pimi->iconId, pmi->hIcon ); else pimi->iconId = -1; //fixme, should remove old icon & shuffle all iconIds } if (pimi->hBmp) DeleteObject(pimi->hBmp); pimi->hBmp = NULL; } if ( pmi->flags & CMIM_HOTKEY ) pimi->mi.hotKey = pmi->hotKey; LeaveCriticalSection( &csMenuHook ); return 0; }
INT_PTR CALLBACK DlgPluginOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: { HWND hwndList=GetDlgItem(hwndDlg,IDC_PLUGLIST); LVCOLUMN col; HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | (IsWinVerXPPlus()? ILC_COLOR32 : ILC_COLOR16), 4, 0); ImageList_AddIcon_IconLibLoaded( hIml, SKINICON_OTHER_UNICODE ); ImageList_AddIcon_IconLibLoaded( hIml, SKINICON_OTHER_ANSI ); ImageList_AddIcon_IconLibLoaded( hIml, SKINICON_OTHER_LOADED ); ImageList_AddIcon_IconLibLoaded( hIml, SKINICON_OTHER_NOTLOADED ); ListView_SetImageList( hwndList, hIml, LVSIL_SMALL ); TranslateDialogDefault(hwndDlg); col.mask = LVCF_TEXT | LVCF_WIDTH; col.pszText = TranslateT("Plugin"); col.cx = 70;//max = 140; ListView_InsertColumn(hwndList,0,&col); col.pszText=TranslateT("Name"); col.cx = 70;//max = 220; ListView_InsertColumn(hwndList,1,&col); col.pszText=TranslateT("Version"); col.cx=55; ListView_InsertColumn(hwndList,2,&col); col.pszText=_T(""); col.cx=20; ListView_InsertColumn(hwndList,3,&col); //ListView_InsertColumn(hwndList,4,&col); // XXX: Won't work on windows 95 without IE3+ or 4.70 ListView_SetExtendedListViewStyleEx( hwndList, 0, LVS_EX_SUBITEMIMAGES | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT ); // scan the plugin dir for plugins, cos enumPlugins( dialogListPlugins, ( WPARAM )hwndDlg, ( LPARAM )hwndList ); // sort out the headers { int w, max; ListView_SetColumnWidth( hwndList, 0, LVSCW_AUTOSIZE ); // dll name w = ListView_GetColumnWidth( hwndList, 0 ); if (w>140) { ListView_SetColumnWidth( hwndList, 0, 140 ); w = 140; } max = w<140? 220+140-w:220; ListView_SetColumnWidth( hwndList, 1, LVSCW_AUTOSIZE ); // short name w = ListView_GetColumnWidth( hwndList, 1 ); if (w>max) ListView_SetColumnWidth( hwndList, 1, max ); } return TRUE; } case WM_NOTIFY: { NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; if ( hdr && hdr->hdr.code == LVN_ITEMCHANGED && hdr->uOldState != 0 && (hdr->uNewState == 0x1000 || hdr->uNewState == 0x2000 ) && IsWindowVisible(hdr->hdr.hwndFrom) ) { HWND hwndList = GetDlgItem(hwndDlg,IDC_PLUGLIST); PluginListItemData* dat; int iRow; LVITEM it; it.mask=LVIF_PARAM | LVIF_STATE; it.iItem = hdr->iItem; if ( !ListView_GetItem( hwndList, &it )) break; dat = ( PluginListItemData* )it.lParam; if ( dat->flags == DEFMOD_DB ) { ListView_SetItemState(hwndList, hdr->iItem, 0x3000, LVIS_STATEIMAGEMASK); return FALSE; } // if enabling and replaces, find all other replaces and toggle off if ( hdr->uNewState & 0x2000 && dat->flags != 0 ) { for ( iRow=0; iRow != -1; ) { if ( iRow != hdr->iItem ) { LVITEM dt; dt.mask = LVIF_PARAM; dt.iItem = iRow; if ( ListView_GetItem( hwndList, &dt )) { PluginListItemData* dat2 = ( PluginListItemData* )dt.lParam; if ( dat2->flags == dat->flags ) { // the lParam is unset, so when the check is unset the clist block doesnt trigger int lParam = dat2->flags; dat2->flags = 0; ListView_SetItemState(hwndList, iRow, 0x1000, LVIS_STATEIMAGEMASK ); dat2->flags = lParam; } } } iRow = ListView_GetNextItem( hwndList, iRow, LVNI_ALL ); } } ShowWindow( GetDlgItem(hwndDlg, IDC_RESTART ), TRUE ); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; } if ( hdr && hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != -1 ) { TCHAR buf[1024]; int sel = hdr->uNewState & LVIS_SELECTED; HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST); LVITEM lvi = { 0 }; lvi.mask = LVIF_PARAM; lvi.iItem = hdr->iItem; if ( ListView_GetItem( hwndList, &lvi )) { PluginListItemData* dat = ( PluginListItemData* )lvi.lParam; ListView_GetItemText(hwndList, hdr->iItem, 1, buf, SIZEOF(buf)); SetWindowText(GetDlgItem(hwndDlg,IDC_PLUGININFOFRAME),sel ? buf : _T("")); SetWindowTextA(GetDlgItem(hwndDlg,IDC_PLUGINAUTHOR), sel ? dat->author : "" ); SetWindowTextA(GetDlgItem(hwndDlg,IDC_PLUGINEMAIL), sel ? dat->authorEmail : "" ); { TCHAR* p = LangPackPcharToTchar( dat->description ); SetWindowText(GetDlgItem(hwndDlg,IDC_PLUGINLONGINFO), sel ? p : _T("")); mir_free( p ); } SetWindowTextA(GetDlgItem(hwndDlg,IDC_PLUGINCPYR), sel ? dat->copyright : "" ); SetWindowTextA(GetDlgItem(hwndDlg,IDC_PLUGINURL), sel ? dat->homepage : "" ); if(equalUUID(miid_last, dat->uuid)) SetWindowText(GetDlgItem(hwndDlg,IDC_PLUGINPID), sel ? TranslateT("<none>") : _T("")); else { char szUID[128]; uuidToString( dat->uuid, szUID, sizeof(szUID)); SetWindowTextA(GetDlgItem(hwndDlg,IDC_PLUGINPID), sel ? szUID : "" ); } } } if ( hdr && hdr->hdr.code == PSN_APPLY ) { HWND hwndList=GetDlgItem(hwndDlg,IDC_PLUGLIST); int iRow; int iState; TCHAR buf[1024]; for (iRow=0 ; iRow != (-1) ; ) { ListView_GetItemText(hwndList, iRow, 0, buf, SIZEOF(buf)); iState=ListView_GetItemState(hwndList, iRow, LVIS_STATEIMAGEMASK); SetPluginOnWhiteList(buf, iState&0x2000 ? 1 : 0); iRow=ListView_GetNextItem(hwndList, iRow, LVNI_ALL); } } break; } case WM_COMMAND: if ( HIWORD(wParam) == STN_CLICKED ) { switch (LOWORD(wParam)) { case IDC_PLUGINEMAIL: case IDC_PLUGINURL: { char buf[512]; char * p = &buf[7]; lstrcpyA(buf,"mailto:"); if ( GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), p, SIZEOF(buf) - 7) ) { CallService(MS_UTILS_OPENURL,0,(LPARAM) (LOWORD(wParam)==IDC_PLUGINEMAIL ? buf : p) ); } break; } case IDC_GETMOREPLUGINS: { CallService(MS_UTILS_OPENURL,0,(LPARAM) "http://addons.miranda-im.org/index.php?action=display&id=1" ); break; } } } break; case WM_DESTROY: RemoveAllItems( GetDlgItem( hwndDlg, IDC_PLUGLIST )); break; } return FALSE; }
static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MButtonCtrl* bct = (MButtonCtrl *)GetWindowLongPtr(hwndDlg, 0); switch(msg) { case WM_NCCREATE: SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW); bct = ( MButtonCtrl* )mir_calloc(sizeof(MButtonCtrl)); if (bct==NULL) return FALSE; bct->hwnd = hwndDlg; bct->stateId = PBS_NORMAL; bct->hFont = ( HFONT )GetStockObject(DEFAULT_GUI_FONT); LoadTheme(bct); if (SUCCEEDED(CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, IID_IAccPropServices, (void**)&bct->pAccPropServices))) { // Annotating the Role of this object to be PushButton SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON); } else bct->pAccPropServices = NULL; SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct); if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName); return TRUE; case WM_DESTROY: if (bct) { if (bct->pAccPropServices) { bct->pAccPropServices->Release(); bct->pAccPropServices = NULL; } if (bct->hwndToolTips) { TOOLINFO ti = {0}; ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(bct->hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) { SendMessage(bct->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); } if ( SendMessage(bct->hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0 ) { int idx; TTooltips tt; tt.ThreadId = GetCurrentThreadId(); EnterCriticalSection(&csTips); if ( List_GetIndex( &lToolTips, &tt, &idx ) ) { mir_free( lToolTips.items[idx] ); List_Remove( &lToolTips, idx ); DestroyWindow( bct->hwndToolTips ); } LeaveCriticalSection(&csTips); bct->hwndToolTips = NULL; } } if (bct->arrow) IconLib_ReleaseIcon(bct->arrow, 0); DestroyTheme(bct); } break; // DONT! fall thru case WM_NCDESTROY: mir_free(bct); break; case WM_SETTEXT: bct->cHot = 0; if ( lParam != 0 ) { TCHAR *tmp = ( TCHAR* )lParam; while (*tmp) { if (*tmp=='&' && *(tmp+1)) { bct->cHot = _tolower(*(tmp+1)); break; } tmp++; } InvalidateRect(bct->hwnd, NULL, TRUE); } break; case WM_KEYUP: if (bct->stateId!=PBS_DISABLED && wParam == VK_SPACE) { if (bct->pushBtn) { if (bct->pbState) { bct->pbState = 0; bct->stateId = PBS_NORMAL; } else { bct->pbState = 1; bct->stateId = PBS_PRESSED; } InvalidateRect(bct->hwnd, NULL, TRUE); } SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg); return 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; bct->stateId = PBS_NORMAL; } else { bct->pbState = 1; bct->stateId = PBS_PRESSED; } InvalidateRect(bct->hwnd, NULL, TRUE); } SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg); return 0; } break; case WM_THEMECHANGED: // themed changed, reload theme object 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_SETIMAGE: { HGDIOBJ hnd = NULL; if (bct->hIcon) hnd = bct->hIcon; else if (bct->hBitmap) hnd = bct->hBitmap; if (wParam == IMAGE_ICON) { bct->hIcon = (HICON)lParam; bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == IMAGE_BITMAP) { bct->hBitmap = (HBITMAP)lParam; bct->hIcon = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } return (LRESULT)hnd; } case BM_GETIMAGE: if (bct->hIcon) return (LRESULT)bct->hIcon; else if (bct->hBitmap) return (LRESULT)bct->hBitmap; else 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 = LoadSkinIcon(SKINICON_OTHER_DOWNARROW); SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_BUTTONDROPDOWN); } } else { if (bct->arrow) { IconLib_ReleaseIcon(bct->arrow, 0); bct->arrow = NULL; SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON); } } 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 = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONADDTOOLTIP: if ( wParam ) { TOOLINFO ti = {0}; if ( !bct->hwndToolTips ) { int idx; TTooltips tt; tt.ThreadId = GetCurrentThreadId(); EnterCriticalSection(&csTips); if ( List_GetIndex( &lToolTips, &tt, &idx )) { bct->hwndToolTips = ((TTooltips*)lToolTips.items[idx])->hwnd; } else { TTooltips *ptt = ( TTooltips* )mir_alloc( sizeof(TTooltips) ); ptt->ThreadId = tt.ThreadId; ptt->hwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_ALWAYSTIP, 0, 0, 0, 0, NULL, NULL, hMirandaInst, NULL); List_Insert( &lToolTips, ptt, idx ); bct->hwndToolTips = ptt->hwnd; } LeaveCriticalSection(&csTips); } ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(bct->hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) SendMessage(bct->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; ti.uId = (UINT_PTR)bct->hwnd; #if defined( _UNICODE ) if ( lParam & BATF_UNICODE ) ti.lpszText = mir_wstrdup( TranslateW(( WCHAR* )wParam )); else ti.lpszText = LangPackPcharToTchar(( char* )wParam ); #else ti.lpszText = Translate(( char* )wParam ); #endif if (bct->pAccPropServices) { wchar_t *tmpstr = mir_t2u(ti.lpszText); bct->pAccPropServices->SetHwndPropStr(bct->hwnd, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_DESCRIPTION, tmpstr); mir_free(tmpstr); } SendMessage( bct->hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)&ti); #if defined( _UNICODE ) mir_free( ti.lpszText ); #endif } 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) { // don't change states if disabled bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case WM_LBUTTONUP: { int showClick = 0; 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 (bct->stateId==PBS_PRESSED) showClick = 1; if (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT; else bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } if (showClick) // Tell your daddy you got clicked. 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_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); }
static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct DetailsData* dat = ( struct DetailsData* )GetWindowLongPtr( hwndDlg, GWLP_USERDATA ); switch (msg) { case WM_INITDIALOG: { struct DlgProfData * prof = (struct DlgProfData *)lParam; PROPSHEETHEADER *psh = prof->psh; TranslateDialogDefault(hwndDlg); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hMirandaInst, MAKEINTRESOURCE(IDI_USERDETAILS),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0)); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hMirandaInst, MAKEINTRESOURCE(IDI_USERDETAILS),IMAGE_ICON,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0)); dat = (struct DetailsData*)mir_alloc(sizeof(struct DetailsData)); dat->prof = prof; prof->hwndOK = GetDlgItem( hwndDlg, IDOK ); EnableWindow( prof->hwndOK, FALSE ); SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR)dat ); { TCHAR buf[512]; mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s\n%s"), TranslateT("Miranda Profiles from"), prof->pd->szProfileDir, TranslateT("Select or create your Miranda IM user profile")); SetDlgItemText(hwndDlg, IDC_NAME, buf); } { OPTIONSDIALOGPAGE *odp; int i; TCITEM tci; dat->currentPage = 0; dat->pageCount = psh->nPages; dat->opd = ( struct DetailsPageData* )mir_calloc( sizeof( struct DetailsPageData )*dat->pageCount ); odp = ( OPTIONSDIALOGPAGE* )psh->ppsp; tci.mask = TCIF_TEXT; for( i=0; i < dat->pageCount; i++ ) { dat->opd[i].pTemplate = (DLGTEMPLATE *)LockResource(LoadResource(odp[i].hInstance,FindResourceA(odp[i].hInstance,odp[i].pszTemplate,MAKEINTRESOURCEA(5)))); dat->opd[i].dlgProc = odp[i].pfnDlgProc; dat->opd[i].hInst = odp[i].hInstance; dat->opd[i].hwnd = NULL; dat->opd[i].changed = 0; tci.pszText = ( TCHAR* )odp[i].ptszTitle; if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->szProfile)) dat->currentPage = 1; TabCtrl_InsertItem( GetDlgItem(hwndDlg,IDC_TABS), i, &tci ); } } GetWindowRect(GetDlgItem(hwndDlg,IDC_TABS),&dat->rcDisplay); TabCtrl_AdjustRect(GetDlgItem(hwndDlg,IDC_TABS),FALSE,&dat->rcDisplay); { POINT pt = {0,0}; ClientToScreen( hwndDlg, &pt ); OffsetRect( &dat->rcDisplay, -pt.x, -pt.y ); } TabCtrl_SetCurSel( GetDlgItem( hwndDlg, IDC_TABS ), dat->currentPage ); dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst,dat->opd[dat->currentPage].pTemplate,hwndDlg,dat->opd[dat->currentPage].dlgProc,(LPARAM)dat->prof); ThemeDialogBackground( dat->opd[dat->currentPage].hwnd ); SetWindowPos( dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE ); { PSHNOTIFY pshn; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = ( LPARAM )0; SendMessage( dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn ); } // service mode combobox { char **list = GetSeviceModePluginsList(); if ( !list ) { ShowWindow( GetDlgItem(hwndDlg, IDC_SM_LABEL ), FALSE ); ShowWindow( GetDlgItem(hwndDlg, IDC_SM_COMBO ), FALSE ); } else { int i = 0; LRESULT index; HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO ); index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("") ); SendMessage( hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1 ); SendMessage( hwndCombo, CB_SETCURSEL, 0, 0); while ( list[i] ) { TCHAR *str = LangPackPcharToTchar( list[i] ); index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)str ); mir_free(str); SendMessage( hwndCombo, CB_SETITEMDATA, index, (LPARAM)i ); i++; } mir_free(list); } } ShowWindow( dat->opd[dat->currentPage].hwnd, SW_SHOW ); return TRUE; } case WM_CTLCOLORSTATIC: switch ( GetDlgCtrlID(( HWND )lParam )) { case IDC_WHITERECT: SetBkColor(( HDC )wParam, GetSysColor( COLOR_WINDOW )); return ( INT_PTR )GetSysColorBrush( COLOR_WINDOW ); } break; case PSM_CHANGED: dat->opd[dat->currentPage].changed=1; return TRUE; case PSM_FORCECHANGED: { PSHNOTIFY pshn; int i; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)0; for ( i=0; i < dat->pageCount; i++ ) { pshn.hdr.hwndFrom = dat->opd[i].hwnd; if ( dat->opd[i].hwnd != NULL ) SendMessage(dat->opd[i].hwnd,WM_NOTIFY,0,(LPARAM)&pshn); } break; } case WM_NOTIFY: switch(wParam) { case IDC_TABS: switch(((LPNMHDR)lParam)->code) { case TCN_SELCHANGING: { PSHNOTIFY pshn; if ( dat->currentPage == -1 || dat->opd[dat->currentPage].hwnd == NULL ) break; pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = 0; if ( SendMessage( dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn )) { SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, TRUE ); return TRUE; } break; } case TCN_SELCHANGE: if ( dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL ) ShowWindow( dat->opd[ dat->currentPage ].hwnd, SW_HIDE ); dat->currentPage = TabCtrl_GetCurSel(GetDlgItem(hwndDlg,IDC_TABS)); if ( dat->currentPage != -1 ) { if ( dat->opd[dat->currentPage].hwnd == NULL ) { PSHNOTIFY pshn; dat->opd[dat->currentPage].hwnd=CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst,dat->opd[dat->currentPage].pTemplate,hwndDlg,dat->opd[dat->currentPage].dlgProc,(LPARAM)dat->prof); ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); SetWindowPos(dat->opd[dat->currentPage].hwnd,HWND_TOP,dat->rcDisplay.left,dat->rcDisplay.top,0,0,SWP_NOSIZE); pshn.hdr.code=PSN_INFOCHANGED; pshn.hdr.hwndFrom=dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom=0; pshn.lParam=(LPARAM)0; SendMessage(dat->opd[dat->currentPage].hwnd,WM_NOTIFY,0,(LPARAM)&pshn); } ShowWindow(dat->opd[dat->currentPage].hwnd,SW_SHOW); } break; } break; } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: { int i; PSHNOTIFY pshn; pshn.hdr.idFrom=0; pshn.lParam=0; pshn.hdr.code=PSN_RESET; for(i=0;i<dat->pageCount;i++) { if (dat->opd[i].hwnd==NULL || !dat->opd[i].changed) continue; pshn.hdr.hwndFrom=dat->opd[i].hwnd; SendMessage(dat->opd[i].hwnd,WM_NOTIFY,0,(LPARAM)&pshn); } EndDialog(hwndDlg,0); } break; case IDC_REMOVE: if (!dat->prof->pd->noProfiles) { HWND hwndList = GetDlgItem(dat->opd[0].hwnd, IDC_PROFILELIST); DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat->prof); } break; case IDOK: { int i; PSHNOTIFY pshn; pshn.hdr.idFrom=0; pshn.lParam=(LPARAM)0; if ( dat->currentPage != -1 ) { pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; if ( SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn )) break; } pshn.hdr.code=PSN_APPLY; for ( i=0; i < dat->pageCount; i++ ) { if ( dat->opd[i].hwnd == NULL || !dat->opd[i].changed ) continue; pshn.hdr.hwndFrom = dat->opd[i].hwnd; SendMessage( dat->opd[i].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn ); if ( GetWindowLongPtr( dat->opd[i].hwnd, DWLP_MSGRESULT ) == PSNRET_INVALID_NOCHANGEPAGE) { TabCtrl_SetCurSel( GetDlgItem( hwndDlg, IDC_TABS ), i ); if ( dat->currentPage != -1 ) ShowWindow( dat->opd[ dat->currentPage ].hwnd, SW_HIDE ); dat->currentPage = i; ShowWindow( dat->opd[dat->currentPage].hwnd, SW_SHOW ); return 0; } } EndDialog(hwndDlg,1); break; } } break; case WM_DESTROY: { LRESULT curSel = SendDlgItemMessage(hwndDlg,IDC_SM_COMBO,CB_GETCURSEL,0,0); if ( curSel != CB_ERR ) { int idx = SendDlgItemMessage( hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, ( WPARAM )curSel, 0 ); SetServiceModePlugin(idx); } } DestroyIcon(( HICON )SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); DestroyIcon(( HICON )SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); DeleteObject( dat->hBoldFont ); { int i; for ( i=0; i < dat->pageCount; i++ ) if ( dat->opd[i].hwnd != NULL ) DestroyWindow( dat->opd[i].hwnd ); } mir_free( dat->opd ); mir_free( dat ); break; } return FALSE; }