static LRESULT CALLBACK toolbarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ModernToolbarCtrl* pMTBInfo = (ModernToolbarCtrl*)GetWindowLongPtr(hwnd, 0); switch (msg) { case WM_ERASEBKGND: return (g_CluiData.fDisableSkinEngine) ? sttDrawToolBarBackground(hwnd, (HDC)wParam, NULL, pMTBInfo) : 0; case WM_NCPAINT: case WM_PAINT: { PAINTSTRUCT ps; BOOL bFloat = (GetParent(hwnd) != pcli->hwndContactList); if (g_CluiData.fDisableSkinEngine || !g_CluiData.fLayered || bFloat) { BeginPaint(hwnd, &ps); if ((!g_CluiData.fLayered || bFloat) && !g_CluiData.fDisableSkinEngine) sttDrawNonLayeredSkinedBar(hwnd, ps.hdc); else sttDrawToolBarBackground(hwnd, ps.hdc, &ps.rcPaint, pMTBInfo); EndPaint(hwnd, &ps); } } return DefWindowProc(hwnd, msg, wParam, lParam); case WM_NOTIFY: if (((LPNMHDR)lParam)->code == BUTTONNEEDREDRAW) pcli->pfnInvalidateRect(hwnd, NULL, FALSE); return 0; case MTBM_LAYEREDPAINT: { RECT MyRect = { 0 }; HDC hDC = (HDC)wParam; GetWindowRect(hwnd, &MyRect); RECT rcClient; GetClientRect(hwnd, &rcClient); SkinDrawGlyph(hDC, &rcClient, &rcClient, "Bar,ID=ToolBar,Part=Background"); for (int i = 0; i < pMTBInfo->pButtonList->realCount; i++) { RECT childRect; POINT Offset; TTBCtrlButton* mtbi = (TTBCtrlButton*)pMTBInfo->pButtonList->items[i]; GetWindowRect(mtbi->hWindow, &childRect); Offset.x = childRect.left - MyRect.left; Offset.y = childRect.top - MyRect.top; SendMessage(mtbi->hWindow, BUTTONDRAWINPARENT, (WPARAM)hDC, (LPARAM)&Offset); } } return 0; case WM_DESTROY: xpt_FreeThemeForWindow(hwnd); CallService(MS_SKINENG_REGISTERPAINTSUB, (WPARAM)hwnd, 0); break; } return mir_callNextSubclass(hwnd, toolbarWndProc, msg, wParam, lParam); }
static LRESULT CALLBACK ToolBar_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { static BOOL supressRepos=FALSE; MTBINFO * pMTBInfo=(MTBINFO *)GetWindowLongPtr(hwnd, GWLP_USERDATA); switch (msg) { case WM_CREATE: { HANDLE hFrame=NULL; CLISTFrame Frame={0}; CREATESTRUCT * lpcs = (CREATESTRUCT *) lParam; //create internal info MTBINFO * pMTBInfo = (MTBINFO *) mir_calloc( sizeof(MTBINFO) ); pMTBInfo->cbSize = sizeof(MTBINFO); SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR) pMTBInfo ); pMTBInfo->nButtonWidth = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnWidth", SETTINGS_BARBTNWIDTH_DEFAULT); pMTBInfo->nButtonHeight= ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnHeight", SETTINGS_BARBTNHEIGHT_DEFAULT); pMTBInfo->nButtonSpace = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnSpace", SETTINGS_BARBTNSPACE_DEFAULT); pMTBInfo->fAutoSize = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_Autosize", SETTINGS_BARAUTOSIZE_DEFAULT); pMTBInfo->fSingleLine = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_Multiline", SETTINGS_BARMULTILINE_DEFAULT)==0; //register self frame Frame.cbSize=sizeof(CLISTFrame); Frame.hWnd=hwnd; Frame.align=alTop; Frame.hIcon=LoadSkinnedIcon (SKINICON_OTHER_MIRANDA); Frame.Flags=(ModernGetSettingByte(NULL,"CLUI","ShowButtonBar",SETTINGS_SHOWBUTTONBAR_DEFAULT)?F_VISIBLE:0)|F_LOCKED|F_NOBORDER|F_NO_SUBCONTAINER; Frame.height=ModernGetSettingDword(NULL, "ModernToolBar", "option_Bar0_OldHeight", pMTBInfo->nButtonHeight); pMTBInfo->wLastHeight=Frame.height; pMTBInfo->nLineCount = 1; pMTBInfo->pButtonList=li.List_Create(0,1); Frame.name=(char*) lpcs->lpCreateParams; hFrame=(HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&Frame,(LPARAM)0); CallService(MS_SKINENG_REGISTERPAINTSUB,(WPARAM)Frame.hWnd,(LPARAM)ToolBar_LayeredPaintProc); //$$$$$ register sub for frame pMTBInfo->hFrame = hFrame; pMTBInfo->hWnd = hwnd; //add self to window list WindowList_Add(tbdat.hToolBarWindowList, hwnd, NULL); pMTBInfo->mtbXPTheme=xpt_AddThemeHandle(hwnd,L"TOOLBAR"); ToolBar_DefaultButtonRegistration(); //SetTimer(hwnd,123,1000,NULL); return 0; } case WM_TIMER: { //KillTimer(hwnd,123); //ToolBar_DefaultButtonRegistration(); return 0; } case WM_SHOWWINDOW: { { int res; int ID; ID= Sync( FindFrameID, hwnd ); if (ID) { res=CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS,ID),0); if (res>=0) ModernWriteSettingByte(0,"CLUI","ShowButtonBar",(BYTE)(wParam/*(res&F_VISIBLE)*/?1:0)); if (wParam) SendMessage(hwnd, MTBM_REPOSBUTTONS, 0, 0); } } break; } case MTBM_UPDATEFRAMEVISIBILITY: { BOOL vis=(BOOL)wParam; INT_PTR frameopt; BOOL curvis=IsWindowVisible(hwnd); BOOL bResize=FALSE; int frameID=Sync( FindFrameID, hwnd ); int Height; pMTBInfo->nButtonWidth = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnWidth", SETTINGS_BARBTNWIDTH_DEFAULT); pMTBInfo->nButtonHeight= ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnHeight", SETTINGS_BARBTNHEIGHT_DEFAULT); pMTBInfo->nButtonSpace = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_BtnSpace", SETTINGS_BARBTNSPACE_DEFAULT); pMTBInfo->fAutoSize = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_Autosize", SETTINGS_BARAUTOSIZE_DEFAULT); pMTBInfo->fSingleLine = ModernGetSettingByte(NULL, "ModernToolBar", "option_Bar0_Multiline", SETTINGS_BARMULTILINE_DEFAULT)==0; Height=sttReposButtons( pMTBInfo ); if (pMTBInfo->fAutoSize) { frameopt=CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT,frameID),0); if (Height!=frameopt) { frameopt=Height; CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_HEIGHT,frameID),frameopt); bResize=TRUE; } } if ((curvis!=vis || bResize) && vis !=-1) { frameopt=CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS,frameID),0); frameopt&=~F_VISIBLE; frameopt|=vis ? F_VISIBLE : 0; CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_FLAGS,frameID),frameopt); } break; } case WM_DESTROY: { xpt_FreeThemeForWindow(hwnd); WindowList_Remove( tbdat.hToolBarWindowList, hwnd ); SendMessage(hwnd, MTBM_REMOVE_ALL_BUTTONS, 0, 0 ); li.List_Destroy( pMTBInfo->pButtonList ); mir_free( pMTBInfo->pButtonList ); SetWindowLongPtr( hwnd, GWLP_USERDATA, 0 ); mir_free( pMTBInfo ); return 0; } case WM_COMMAND: { if (HIWORD(wParam)==BN_CLICKED && lParam!=0 ) sttButtonPressed(pMTBInfo, (HWND) lParam ); return TRUE; } case MTBM_ADDBUTTON: { //Adding button MTB_BUTTONINFO * mtbi=(MTB_BUTTONINFO * )wParam; HWND hwndButton = NULL; if (!(mtbi->bSeparator)) hwndButton= CreateWindow(SKINBUTTONCLASS /*MIRANDABUTTONCLASS*/, _T(""), BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP , 0, 0, pMTBInfo->nButtonWidth, pMTBInfo->nButtonHeight, hwnd, (HMENU) NULL, g_hInst, NULL); mtbi->hWindow=hwndButton; mtbi->hwndToolBar=hwnd; li.List_Insert(pMTBInfo->pButtonList, mtbi, pMTBInfo->pButtonList->realCount); //just insert pointer. such object are managed in global tbbutton list if (hwndButton) { char * buttonId=(char *)_malloca(sizeof("ToolBar.")+strlen(mtbi->szButtonID)+2); strcpy(buttonId,"ToolBar."); strcat(buttonId,mtbi->szButtonID); SendMessage(hwndButton, BUTTONSETID, 0 ,(LPARAM) buttonId ); if (pMTBInfo->bFlatButtons) SendMessage(hwndButton, BUTTONSETASFLATBTN, 0, 1 ); SetWindowLongPtr(hwndButton,GWLP_USERDATA,(LONG_PTR)mtbi); SendMessage(hwndButton, MBM_UPDATETRANSPARENTFLAG, 0, 2); } return (LRESULT)hwndButton; } case MTBM_REMOVE_ALL_BUTTONS: { int i; for (i=0; i<pMTBInfo->pButtonList->realCount; i++ ) { MTB_BUTTONINFO * mtbi=(MTB_BUTTONINFO *)pMTBInfo->pButtonList->items[i]; if (mtbi->hWindow && mtbi->hwndToolBar==hwnd) { DestroyWindow(mtbi->hWindow); mtbi->hWindow = NULL; mtbi->hwndToolBar = NULL; } } li.List_Destroy( pMTBInfo->pButtonList ); mir_free( pMTBInfo->pButtonList ); pMTBInfo->pButtonList=li.List_Create(0,1); break; } case WM_SIZE: if (pMTBInfo->wLastHeight!=HIWORD(lParam)) { ModernWriteSettingDword(NULL, "ModernToolBar", "option_Bar0_OldHeight", HIWORD(lParam)); pMTBInfo->wLastHeight=HIWORD(lParam); } if (supressRepos) { supressRepos=FALSE; break; } //fall through case MTBM_REPOSBUTTONS: { if (pMTBInfo && pMTBInfo->hWnd == hwnd) { int Height=sttReposButtons(pMTBInfo); if ( pMTBInfo->fAutoSize) { RECT rcClient; GetClientRect(pMTBInfo->hWnd, &rcClient); if (rcClient.bottom-rcClient.top != Height && Height) { supressRepos=TRUE; PostMessage(pMTBInfo->hWnd,MTBM_UPDATEFRAMEVISIBILITY, -1, 0); } } return 0; } break; } case WM_ERASEBKGND: if (g_CluiData.fDisableSkinEngine) return sttDrawToolBarBackground(hwnd, (HDC)wParam, NULL, pMTBInfo); else return 0; case WM_NCPAINT: case WM_PAINT: { BOOL ret=FALSE; PAINTSTRUCT ps; BOOL bFloat = (GetParent(hwnd)!=pcli->hwndContactList); if (g_CluiData.fDisableSkinEngine|| !g_CluiData.fLayered || bFloat ) { BeginPaint(hwnd,&ps); if ((!g_CluiData.fLayered || bFloat) && !g_CluiData.fDisableSkinEngine) { sttDrawNonLayeredSkinedBar(hwnd, ps.hdc); } else ret=sttDrawToolBarBackground(hwnd, ps.hdc, &ps.rcPaint, pMTBInfo); EndPaint(hwnd,&ps); } return DefWindowProc(hwnd, msg, wParam, lParam); } case WM_NOTIFY: { if (((LPNMHDR) lParam)->code==BUTTONNEEDREDRAW) pcli->pfnInvalidateRect(hwnd, NULL, FALSE); return 0; } case MTBM_LAYEREDPAINT: { int i; RECT MyRect={0}; HDC hDC=(HDC)wParam; GetWindowRect(hwnd,&MyRect); { RECT rcClient; GetClientRect(hwnd, &rcClient); SkinDrawGlyph(hDC,&rcClient,&rcClient,"Bar,ID=ToolBar,Part=Background"); } for (i=0; i<pMTBInfo->pButtonList->realCount; i++) { RECT childRect; POINT Offset; MTB_BUTTONINFO * mtbi=(MTB_BUTTONINFO *)pMTBInfo->pButtonList->items[i]; GetWindowRect(mtbi->hWindow,&childRect); Offset.x=childRect.left-MyRect.left;; Offset.y=childRect.top-MyRect.top; SendMessage(mtbi->hWindow, BUTTONDRAWINPARENT, (WPARAM)hDC,(LPARAM)&Offset); } return 0; } case MTBM_SETBUTTONSTATEBYID: case MTBM_SETBUTTONSTATE: { char * hButtonId=(msg==MTBM_SETBUTTONSTATEBYID) ? (char *) wParam : NULL; void * hButton=(msg==MTBM_SETBUTTONSTATE) ? (void *)wParam : NULL; MTB_BUTTONINFO *mtbi=NULL; int i; for (i=0; i<pMTBInfo->pButtonList->realCount; i++) { mtbi=(MTB_BUTTONINFO*)pMTBInfo->pButtonList->items[i]; if ((hButtonId && !strcmp(mtbi->szButtonID, hButtonId)) || (hButton == mtbi)) { mtbi->bPushButton=(BOOL)lParam; sttUpdateButtonState(mtbi); pcli->pfnInvalidateRect(hwnd, NULL, FALSE); break; } } break; } case MTBM_GETBUTTONSTATEBYID: case MTBM_GETBUTTONSTATE: { int * res= (int*)lParam; if (res==NULL) break; char * hButtonId=(msg==MTBM_GETBUTTONSTATEBYID) ? (char *) wParam : NULL; void * hButton=(msg==MTBM_GETBUTTONSTATE) ? (void *)wParam : NULL; MTB_BUTTONINFO *mtbi=NULL; int i; for (i=0; i<pMTBInfo->pButtonList->realCount; i++) { mtbi=(MTB_BUTTONINFO*)pMTBInfo->pButtonList->items[i]; if ((hButtonId && !strcmp(mtbi->szButtonID, hButtonId)) || (hButton == mtbi)) { *res=0; *res |= mtbi->bPushButton ? TBST_PUSHED : TBST_RELEASED; break; } } break; } case MTBM_REMOVEBUTTON: { MTB_BUTTONINFO *mtbi=NULL; for (int i=0; i<pMTBInfo->pButtonList->realCount; i++) { mtbi=(MTB_BUTTONINFO*)pMTBInfo->pButtonList->items[i]; if (mtbi==(MTB_BUTTONINFO*)wParam) { li.List_Remove(pMTBInfo->pButtonList,i); for (int j=0; j<tbdat.listOfButtons->realCount; j++) if (mtbi==(MTB_BUTTONINFO*)tbdat.listOfButtons->items[j]) { li.List_Remove(tbdat.listOfButtons,j); break; } li.List_RemovePtr(tbdat.listOfButtons,mtbi); delete_MTB_BUTTONINFO((void*)mtbi); mtbi=NULL; pcli->pfnInvalidateRect(hwnd, NULL, FALSE); break; } } break; } default : return DefWindowProc(hwnd, msg, wParam, lParam); } return TRUE; }