/* * Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved. * * This file is part of System Informer. * * Authors: * * dmex 2011-2026 * */ #include "toolstatus.h" BOOLEAN RebarBandInsert( _In_ REBAR_BAND BandID, _In_ HWND ChildWindowHandle, _In_ ULONG ChildMinimumWidth, _In_ ULONG ChildMinimumHeight ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_STYLE | RBBIM_ID | RBBIM_CHILD | RBBIM_CHILDSIZE; rebarBandInfo.wID = BandID; rebarBandInfo.hwndChild = ChildWindowHandle; rebarBandInfo.cxMinChild = ChildMinimumWidth; rebarBandInfo.cyMinChild = ChildMinimumHeight; rebarBandInfo.cyChild = ChildMinimumHeight; if (ToolStatusConfig.ToolBarLocked) rebarBandInfo.fStyle = RBBS_VARIABLEHEIGHT | RBBS_USECHEVRON | RBBS_NOGRIPPER; else rebarBandInfo.fStyle = RBBS_VARIABLEHEIGHT | RBBS_USECHEVRON; // Color the band background so the area not covered by a transparent/auto-sized // child (e.g. the space to the right of the menu bar band, which the rebar // stretches to fill the row) matches the dark theme instead of showing the // default system band color. if (EnableThemeSupport) { const PH_WINDOW_THEME_PALETTE* palette = PhGetWindowThemePalette(); rebarBandInfo.fMask |= RBBIM_COLORS; rebarBandInfo.clrFore = palette->TextColor; rebarBandInfo.clrBack = palette->BackgroundColor; } ULONG index = SearchboxHandle ? RebarBandToIndex(REBAR_BAND_ID_SEARCHBOX) : ULONG_MAX; if (SendMessage(RebarHandle, RB_INSERTBAND, (WPARAM)index, (LPARAM)&rebarBandInfo)) return TRUE; return FALSE; } /** * Refreshes the themed band colors for every rebar band. * * Band colors are cached per band, so a live theme mode switch (which changes * the palette but keeps theme support enabled) must re-push them; enabling or * disabling theme support itself requires a restart. */ VOID RebarUpdateBandColors( VOID ) { ULONG count; if (!RebarHandle) return; if (!RebarGetBandCount(&count)) return; for (ULONG index = 0; index < count; index++) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_COLORS; if (EnableThemeSupport) { const PH_WINDOW_THEME_PALETTE* palette = PhGetWindowThemePalette(); rebarBandInfo.clrFore = palette->TextColor; rebarBandInfo.clrBack = palette->BackgroundColor; } else { rebarBandInfo.clrFore = CLR_DEFAULT; rebarBandInfo.clrBack = CLR_DEFAULT; } SendMessage(RebarHandle, RB_SETBANDINFO, index, (LPARAM)&rebarBandInfo); } InvalidateRect(RebarHandle, NULL, TRUE); } VOID RebarBandRemove( _In_ REBAR_BAND BandID ) { ULONG index = RebarBandToIndex(BandID); if (index == ULONG_MAX) return; SendMessage(RebarHandle, RB_DELETEBAND, (WPARAM)index, 0); } BOOLEAN RebarBandMove( _In_ ULONG OldIndex, _In_ ULONG NewIndex ) { if (SendMessage(RebarHandle, RB_MOVEBAND, OldIndex, NewIndex)) return TRUE; return FALSE; } ULONG RebarBandToIndex( _In_ REBAR_BAND BandID ) { LONG_PTR index = SendMessage(RebarHandle, RB_IDTOINDEX, (WPARAM)BandID, 0); if (index == INT_ERROR) return ULONG_MAX; return (ULONG)index; } _Success_(return) BOOLEAN RebarGetBandCount( _Out_ PULONG Count ) { LONG_PTR count = SendMessage(RebarHandle, RB_GETBANDCOUNT, 0, 0); if (count == INT_ERROR) return FALSE; *Count = (ULONG)count; return TRUE; } LONG RebarGetRowHeight( _In_ REBAR_BAND BandID ) { ULONG index; index = RebarBandToIndex(BandID); if (index == ULONG_MAX) return 0; return (LONG)SendMessage(RebarHandle, RB_GETROWHEIGHT, index, 0); } VOID RebarSetBarInfo( VOID ) { REBARINFO rebarInfo; memset(&rebarInfo, 0, sizeof(REBARINFO)); rebarInfo.cbSize = sizeof(REBARINFO); rebarInfo.himl = NULL; SendMessage(RebarHandle, RB_SETBARINFO, 0, (LPARAM)&rebarInfo); } _Success_(return) BOOLEAN RebarGetBandIndexStyle( _In_ ULONG BandIndex, _Out_ PULONG Style ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_STYLE; if (SendMessage(RebarHandle, RB_GETBANDINFO, BandIndex, (LPARAM)&rebarBandInfo)) { *Style = rebarBandInfo.fStyle; return TRUE; } return FALSE; } BOOLEAN RebarSetBandIndexStyle( _In_ ULONG BandIndex, _In_ ULONG Style ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_STYLE; rebarBandInfo.fStyle = Style; if (SendMessage(RebarHandle, RB_SETBANDINFO, BandIndex, (LPARAM)&rebarBandInfo)) return TRUE; return FALSE; } _Success_(return) BOOLEAN RebarGetBandIndexChildSize( _In_ ULONG BandIndex, _Out_ PBAND_CHILD_SIZE BandSize ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_CHILDSIZE; if (SendMessage(RebarHandle, RB_GETBANDINFO, BandIndex, (LPARAM)&rebarBandInfo)) { memset(BandSize, 0, sizeof(BAND_CHILD_SIZE)); BandSize->InitialChildHeight = rebarBandInfo.cyChild; BandSize->MaximumChildHeight = rebarBandInfo.cyMaxChild; BandSize->MinChildHeight = rebarBandInfo.cyMinChild; BandSize->MinChildWidth = rebarBandInfo.cxMinChild; BandSize->ResizeStepValue = rebarBandInfo.cyIntegral; return TRUE; } return FALSE; } BOOLEAN RebarSetBandIndexChildSize( _In_ ULONG BandIndex, _In_ PBAND_CHILD_SIZE BandSize ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_CHILDSIZE; rebarBandInfo.cyChild = BandSize->InitialChildHeight; rebarBandInfo.cyMaxChild = BandSize->MaximumChildHeight; rebarBandInfo.cyMinChild = BandSize->MinChildHeight; rebarBandInfo.cxMinChild = BandSize->MinChildWidth; rebarBandInfo.cyIntegral = BandSize->ResizeStepValue; if (SendMessage(RebarHandle, RB_SETBANDINFO, BandIndex, (LPARAM)&rebarBandInfo)) return TRUE; return FALSE; } _Success_(return) BOOLEAN RebarGetBandIndexStyleSize( _In_ ULONG BandIndex, _Out_ PBAND_STYLE_SIZE BandStyleSize ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_STYLE | RBBIM_SIZE; if (SendMessage(RebarHandle, RB_GETBANDINFO, BandIndex, (LPARAM)&rebarBandInfo)) { memset(BandStyleSize, 0, sizeof(BAND_STYLE_SIZE)); BandStyleSize->BandStyle = rebarBandInfo.fStyle; BandStyleSize->BandWidth = rebarBandInfo.cx; return TRUE; } return FALSE; } BOOLEAN RebarSetBandIndexStyleSize( _In_ ULONG BandIndex, _In_ PBAND_STYLE_SIZE RebarBandInfo ) { REBARBANDINFO rebarBandInfo; memset(&rebarBandInfo, 0, sizeof(REBARBANDINFO)); rebarBandInfo.cbSize = sizeof(REBARBANDINFO); rebarBandInfo.fMask = RBBIM_STYLE | RBBIM_SIZE; rebarBandInfo.fStyle = RebarBandInfo->BandStyle; rebarBandInfo.cx = RebarBandInfo->BandWidth; if (SendMessage(RebarHandle, RB_SETBANDINFO, BandIndex, (LPARAM)&rebarBandInfo)) return TRUE; return FALSE; }