/* Exported for the windows message loop only */ static void DIB_GrabStaticColors(HWND window) { #ifdef SYSPAL_NOSTATIC HDC hdc; hdc = GetDC(window); SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC256); if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) { SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); } ReleaseDC(window, hdc); #endif }
static BOOL NTAPI GuiSetPalette(IN OUT PFRONTEND This, HPALETTE PaletteHandle, UINT PaletteUsage) { PGUI_CONSOLE_DATA GuiData = This->Context; HPALETTE OldPalette; // if (GetType(GuiData->ActiveBuffer) != GRAPHICS_BUFFER) return FALSE; if (PaletteHandle == NULL) return FALSE; /* Set the new palette for the framebuffer */ OldPalette = SelectPalette(GuiData->hMemDC, PaletteHandle, FALSE); if (OldPalette == NULL) return FALSE; /* Specify the use of the system palette for the framebuffer */ SetSystemPaletteUse(GuiData->hMemDC, PaletteUsage); /* Realize the (logical) palette */ RealizePalette(GuiData->hMemDC); /* Save the original system palette handle */ if (GuiData->hSysPalette == NULL) GuiData->hSysPalette = OldPalette; return TRUE; }
static void DIB_ReleaseStaticColors(HWND window) { #ifdef SYSPAL_NOSTATIC HDC hdc; hdc = GetDC(window); SetSystemPaletteUse(hdc, SYSPAL_STATIC); ReleaseDC(window, hdc); #endif }
/* Called in response to WM_ACTIVATE messages */ void Win_Focus(int on) { HDC hdc; /* Right now, the only thing we care about is palette manipulation */ if(!sys_palette_p) return; hdc = GetDC(Win_Window); if(on) { PALETTEENTRY entries[NUM_COLORS]; /* Save the current system palette */ GetSystemPaletteEntries(hdc, 0, NUM_COLORS, entries); SetPaletteEntries(sys_palette, 0, NUM_COLORS, entries); /* Set our palette as the logical palette */ #ifdef PRIVATE_CMAP /* This is more trouble than it's worth. It fries system colors */ SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); #endif SelectPalette(hdc, our_palette, false); RealizePalette(hdc); InvalidateRect(Win_Window, NULL, 0); } else { /* Set the system palette and reset colors */ SelectPalette(hdc, sys_palette, false); RealizePalette(hdc); #ifdef PRIVATE_CMAP SetSystemPaletteUse(hdc, SYSPAL_STATIC); #endif } ReleaseDC(hdc, Win_Window); }
void AppActivate(BOOL fActive) /**************************************************************************** * * Function: AppActivate * Parameters: fActive - True if app is activating * * Description: If the application is activating, then swap the system * into SYSPAL_NOSTATIC mode so that our palettes will display * correctly. * ****************************************************************************/ { HDC hdc = GetDC(NULL); if (fActive && (GetSystemPaletteUse(hdc) == SYSPAL_STATIC)) { /* Switch to SYSPAL_NOSTATIC */ SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); } else if (!fActive) { /* Always switch back to SYSPAL_STATIC */ SetSystemPaletteUse(hdc, SYSPAL_STATIC); } ReleaseDC(NULL,hdc); }
static VOID NTAPI GuiSetActiveScreenBuffer(IN OUT PFRONTEND This) { PGUI_CONSOLE_DATA GuiData = This->Context; PCONSOLE_SCREEN_BUFFER ActiveBuffer; HPALETTE hPalette; EnterCriticalSection(&GuiData->Lock); GuiData->WindowSizeLock = TRUE; InterlockedExchangePointer((PVOID*)&GuiData->ActiveBuffer, ConDrvGetActiveScreenBuffer(GuiData->Console)); GuiData->WindowSizeLock = FALSE; LeaveCriticalSection(&GuiData->Lock); ActiveBuffer = GuiData->ActiveBuffer; /* Change the current palette */ if (ActiveBuffer->PaletteHandle == NULL) { hPalette = GuiData->hSysPalette; } else { hPalette = ActiveBuffer->PaletteHandle; } DPRINT("GuiSetActiveScreenBuffer using palette 0x%p\n", hPalette); /* Set the new palette for the framebuffer */ SelectPalette(GuiData->hMemDC, hPalette, FALSE); /* Specify the use of the system palette for the framebuffer */ SetSystemPaletteUse(GuiData->hMemDC, ActiveBuffer->PaletteUsage); /* Realize the (logical) palette */ RealizePalette(GuiData->hMemDC); GuiResizeTerminal(This); // ConioDrawConsole(Console); }
Standard_EXPORTEXTERN long InterfaceGraphic_RealizePalette ( HDC hdc, HPALETTE hPal, BOOL fBkg, BOOL fUseStatic ) { int i; long retVal = 0; if ( fUseStatic ) { if ( !s_sysUse ) for ( i = 0; i < NB_STATIC_COLORS; ++i ) s_sysPal[ i ] = GetSysColor ( s_sysPalIdx[ i ] ); SetSystemPaletteUse ( hdc, fBkg ? SYSPAL_STATIC : SYSPAL_NOSTATIC ); if ( UnrealizeObject ( hPal ) && SelectPalette ( hdc, hPal, fBkg ) ) retVal = RealizePalette ( hdc ); if ( fBkg ) { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPal ); s_sysUse = FALSE; } else { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPalBW ); s_sysUse = TRUE; } // end else #pragma warning(push) #pragma warning(disable:4306) /* level 4 warning on cast of int to HWND in HWND_BROADCAST macro */ PostMessage ( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 ); #pragma warning(pop) } else { SelectPalette ( hdc, hPal, FALSE ); retVal = RealizePalette ( hdc ); } // end else return retVal; } // end RealizePaletteNow
__declspec( dllexport ) long InterfaceGraphic_RealizePalette ( HDC hdc, HPALETTE hPal, BOOL fBkg, BOOL fUseStatic ) { int i; long retVal = 0; if ( fUseStatic ) { if ( !s_sysUse ) for ( i = 0; i < NB_STATIC_COLORS; ++i ) s_sysPal[ i ] = GetSysColor ( s_sysPalIdx[ i ] ); SetSystemPaletteUse ( hdc, fBkg ? SYSPAL_STATIC : SYSPAL_NOSTATIC ); if ( UnrealizeObject ( hPal ) && SelectPalette ( hdc, hPal, fBkg ) ) retVal = RealizePalette ( hdc ); if ( fBkg ) { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPal ); s_sysUse = FALSE; } else { SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPalBW ); s_sysUse = TRUE; } // end else PostMessage ( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 ); } else { SelectPalette ( hdc, hPal, FALSE ); retVal = RealizePalette ( hdc ); } // end else return retVal; } // end RealizePaletteNow
BOOL CDIBPal::SetSysPalColors() { BOOL bResult = FALSE; int i, iSysColors, iPalEntries; HPALETTE hpalOld; // Get a screen DC to work with HWND hwndActive = ::GetActiveWindow(); HDC hdcScreen = ::GetDC(hwndActive); ASSERT(hdcScreen); // Make sure we are on a palettized device if (!GetDeviceCaps(hdcScreen, RASTERCAPS) & RC_PALETTE) { TRACE("Not a palettized device"); goto abort; } // Get the number of system colors and the number of palette entries // Note that on a palletized device the number of colors is the // number of guaranteed colors. I.e. the number of reserved system colors iSysColors = GetDeviceCaps(hdcScreen, NUMCOLORS); iPalEntries = GetDeviceCaps(hdcScreen, SIZEPALETTE); // if there are more than 256 colors we are wasting our time if (iSysColors > 256) goto abort; // Now we force the palette manager to reset its tables so that // the next palette to be realized will get its colors in the order they are // in the logical palette. This is done by changing the number of // reserved colors. SetSystemPaletteUse(hdcScreen, SYSPAL_NOSTATIC); SetSystemPaletteUse(hdcScreen, SYSPAL_STATIC); // Select our palette into the screen DC and realize it so that // its colors will be entered into the free slots in the physical palette hpalOld = ::SelectPalette(hdcScreen, (HPALETTE)m_hObject, // our hpal FALSE); ::RealizePalette(hdcScreen); // Now replace the old palette (but don't realize it) ::SelectPalette(hdcScreen, hpalOld, FALSE); // The physical palette now has our colors set in place and its own // reserved colors at either end. We can grab the lot now PALETTEENTRY pe[256]; GetSystemPaletteEntries(hdcScreen, 0, iPalEntries, pe); // Set the PC_NOCOLLAPSE flag for each of our colors so that GDI // won't merge them together. Be careful not to set PC_NOCOLLAPSE for the // sys color entries or we'll get multpile copies of these colors in // the palette when we realize it. for (i = 0; i < iSysColors/2; i++) { pe[i].peFlags = 0; } for (; i < iPalEntries-iSysColors/2; i++) { pe[i].peFlags = PC_NOCOLLAPSE; } for (; i < iPalEntries; i++) { pe[i].peFlags = 0; } // Resize the palette in case it was smaller ResizePalette(iPalEntries); // Update the palette entries with what is now in the physical palette SetPaletteEntries(0, iPalEntries, pe); bResult = TRUE; abort: ::ReleaseDC(hwndActive, hdcScreen); return bResult; }