cleanups after SciTech commit :-(

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14063 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-02-08 00:18:10 +00:00
parent e0a76d8d8a
commit b95edd4708
7 changed files with 96 additions and 55 deletions

View File

@@ -227,7 +227,7 @@ public:
void DrawCircle(wxCoord x, wxCoord y, wxCoord radius) void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
{ DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); } { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
void DrawCircle(const wxPoint& pt, wxCoord radius) void DrawCircle(const wxPoint& pt, wxCoord radius)
{ DoDrawEllipse(pt.x, pt.y, radius); } { DrawCircle(pt.x, pt.y, radius); }
void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{ DoDrawEllipse(x, y, width, height); } { DoDrawEllipse(x, y, width, height); }
@@ -743,7 +743,7 @@ protected:
#if wxUSE_PALETTE #if wxUSE_PALETTE
wxPalette m_palette; wxPalette m_palette;
bool m_custompalette; bool m_hasCustomPalette;
#endif // wxUSE_PALETTE #endif // wxUSE_PALETTE
private: private:

View File

@@ -102,12 +102,14 @@ public:
virtual void SelectOldObjects(WXHDC dc); virtual void SelectOldObjects(WXHDC dc);
wxWindow *GetWindow() const { return m_canvas; } wxWindow *GetWindow() const { return m_canvas; }
void SetWindow(wxWindow *win) { void SetWindow(wxWindow *win)
{
m_canvas = win; m_canvas = win;
#if wxUSE_PALETTE #if wxUSE_PALETTE
// if we have palettes use the correct one for this window // if we have palettes use the correct one for this window
InitializePalette(); InitializePalette();
#endif #endif // wxUSE_PALETTE
} }
WXHDC GetHDC() const { return m_hDC; } WXHDC GetHDC() const { return m_hDC; }
@@ -195,10 +197,12 @@ protected:
// (tell windows to translate pixel from other palettes to our custom one // (tell windows to translate pixel from other palettes to our custom one
// and vice versa) // and vice versa)
// Realize tells it to also reset the system palette to this one. // Realize tells it to also reset the system palette to this one.
void DoSelectPalette(bool realize = false); void DoSelectPalette(bool realize = FALSE);
// Find out what palette our parent window has, then select it into the dc // Find out what palette our parent window has, then select it into the dc
void InitializePalette(); void InitializePalette();
#endif #endif // wxUSE_PALETTE
// common part of DoDrawText() and DoDrawRotatedText() // common part of DoDrawText() and DoDrawRotatedText()
void DrawAnyText(const wxString& text, wxCoord x, wxCoord y); void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);

View File

@@ -396,7 +396,7 @@ private:
#define GetHfontOf(font) ((HFONT)(font).GetHFONT()) #define GetHfontOf(font) ((HFONT)(font).GetHFONT())
#define GetHpalette() ((HPALETTE)GetHPALETTE()) #define GetHpalette() ((HPALETTE)GetHPALETTE())
#define GetHpaletteOf(pal) ((HPALETTE)(pal)->GetHPALETTE()) #define GetHpaletteOf(pal) ((HPALETTE)(pal).GetHPALETTE())
#define GetHrgn() ((HRGN)GetHRGN()) #define GetHrgn() ((HRGN)GetHRGN())
#define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN()) #define GetHrgnOf(rgn) ((HRGN)(rgn).GetHRGN())

View File

@@ -770,15 +770,16 @@ public:
// Store the palette used by DCs in wxWindow so that the dcs can share // Store the palette used by DCs in wxWindow so that the dcs can share
// a palette. And we can respond to palette messages. // a palette. And we can respond to palette messages.
wxPalette GetPalette() const { return m_palette; } wxPalette GetPalette() const { return m_palette; }
// When palette is changed tell the DC to set the system palette to the // When palette is changed tell the DC to set the system palette to the
// new one. // new one.
void SetPalette(wxPalette &pal) { void SetPalette(const wxPalette& pal);
m_custompalette=true;
m_palette=pal; // return true if we have a specific palette
wxWindowDC d((wxWindow *) this); bool HasCustomPalette() const { return m_hasCustomPalette; }
d.SetPalette(pal);
} // return the first parent window with a custom palette or NULL
bool HasCustomPalette() { return m_custompalette; } wxWindow *GetAncestorWithCustomPalette() const;
#endif // wxUSE_PALETTE #endif // wxUSE_PALETTE
protected: protected:
@@ -866,8 +867,8 @@ protected:
#ifdef wxUSE_PALETTE #ifdef wxUSE_PALETTE
wxPalette m_palette; wxPalette m_palette;
bool m_custompalette; bool m_hasCustomPalette;
#endif #endif // wxUSE_PALETTE
protected: protected:

View File

@@ -168,7 +168,7 @@ void wxWindowBase::InitBase()
#endif // wxUSE_CARET #endif // wxUSE_CARET
#if wxUSE_PALETTE #if wxUSE_PALETTE
m_custompalette = false; m_hasCustomPalette = FALSE;
#endif // wxUSE_PALETTE #endif // wxUSE_PALETTE
// Whether we're using the current theme for this window (wxGTK only for now) // Whether we're using the current theme for this window (wxGTK only for now)
@@ -733,6 +733,31 @@ bool wxWindowBase::SetFont(const wxFont& font)
return TRUE; return TRUE;
} }
#if wxUSE_PALETTE
void wxWindowBase::SetPalette(const wxPalette& pal)
{
m_hasCustomPalette = TRUE;
m_palette = pal;
// VZ: can anyone explain me what do we do here?
wxWindowDC d((wxWindow *) this);
d.SetPalette(pal);
}
wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
{
wxWindow *win = (wxWindow *)this;
while ( win && !win->HasCustomPalette() )
{
win = win->GetParent();
}
return win;
}
#endif // wxUSE_PALETTE
#if wxUSE_CARET #if wxUSE_CARET
void wxWindowBase::SetCaret(wxCaret *caret) void wxWindowBase::SetCaret(wxCaret *caret)
{ {

View File

@@ -940,7 +940,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
wxPalette *pal = bmp.GetPalette(); wxPalette *pal = bmp.GetPalette();
if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 ) if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
{ {
oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(pal), FALSE); oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(*pal), FALSE);
::RealizePalette(hdcMem); ::RealizePalette(hdcMem);
} }
#endif // wxUSE_PALETTE #endif // wxUSE_PALETTE
@@ -995,7 +995,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
wxPalette *pal = bmp.GetPalette(); wxPalette *pal = bmp.GetPalette();
if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 ) if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
{ {
oldPal = ::SelectPalette(memdc, GetHpaletteOf(pal), FALSE); oldPal = ::SelectPalette(memdc, GetHpaletteOf(*pal), FALSE);
::RealizePalette(memdc); ::RealizePalette(memdc);
} }
#endif // wxUSE_PALETTE #endif // wxUSE_PALETTE
@@ -1157,44 +1157,47 @@ void wxDC::DoSelectPalette(bool realize)
m_oldPalette = 0; m_oldPalette = 0;
} }
if (m_palette.Ok() && m_palette.GetHPALETTE()) if ( m_palette.Ok() )
{ {
HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), FALSE); HPALETTE oldPal = ::SelectPalette(GetHdc(),
GetHpaletteOf(m_palette),
FALSE);
if (!m_oldPalette) if (!m_oldPalette)
m_oldPalette = (WXHPALETTE) oldPal; m_oldPalette = (WXHPALETTE) oldPal;
if (realize) if (realize)
::RealizePalette(GetHdc()); ::RealizePalette(GetHdc());
} }
} }
void wxDC::SetPalette(const wxPalette& palette) void wxDC::SetPalette(const wxPalette& palette)
{ {
if (palette.Ok()) { if ( palette.Ok() )
{
m_palette = palette; m_palette = palette;
DoSelectPalette(true); DoSelectPalette(TRUE);
} }
} }
void wxDC::InitializePalette() void wxDC::InitializePalette()
{ {
if (wxDisplayDepth() <= 8) { if ( wxDisplayDepth() <= 8 )
{
// look for any window or parent that has a custom palette. If any has // look for any window or parent that has a custom palette. If any has
// one then we need to use it in drawing operations // one then we need to use it in drawing operations
wxWindow *win = m_canvas; wxWindow *win = m_canvas->GetAncestorWithCustomPalette();
while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
if (win->HasCustomPalette()) { m_hasCustomPalette = win && win->HasCustomPalette();
if ( m_hasCustomPalette )
{
m_palette = win->GetPalette(); m_palette = win->GetPalette();
m_custompalette = true;
// turn on MSW translation for this palette // turn on MSW translation for this palette
DoSelectPalette(); DoSelectPalette();
} }
else
m_custompalette = false;
} }
} }
#endif // wxUSE_PALETTE #endif // wxUSE_PALETTE
void wxDC::SetFont(const wxFont& the_font) void wxDC::SetFont(const wxFont& the_font)

View File

@@ -3350,29 +3350,37 @@ bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
{ {
#if wxUSE_PALETTE #if wxUSE_PALETTE
// same as below except we don't respond to our own messages // same as below except we don't respond to our own messages
if (hWndPalChange != GetHWND()) { if ( hWndPalChange != GetHWND() )
{
// check to see if we our our parents have a custom palette // check to see if we our our parents have a custom palette
wxWindow *win = this; wxWindow *win = this;
while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent(); while ( win && !win->HasCustomPalette() )
if (win->HasCustomPalette()) { {
/* realize the palette to see whether redrawing is needed */ win = win->GetParent();
HDC hdc = GetDC((HWND) hWndPalChange); }
win->m_palette.SetHPALETTE( (WXHPALETTE)
::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), false) ); if ( win && win->HasCustomPalette() )
{
// realize the palette to see whether redrawing is needed
HDC hdc = ::GetDC((HWND) hWndPalChange);
win->m_palette.SetHPALETTE((WXHPALETTE)
::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
int result = ::RealizePalette(hdc); int result = ::RealizePalette(hdc);
/* restore the palette (before releasing the DC) */
win->m_palette.SetHPALETTE( (WXHPALETTE) // restore the palette (before releasing the DC)
::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), true) ); win->m_palette.SetHPALETTE((WXHPALETTE)
RealizePalette(hdc); ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
ReleaseDC((HWND) hWndPalChange, hdc); ::RealizePalette(hdc);
/* now check for the need to redraw */ ::ReleaseDC((HWND) hWndPalChange, hdc);
// now check for the need to redraw
if (result > 0) if (result > 0)
InvalidateRect((HWND) hWndPalChange, NULL, TRUE); InvalidateRect((HWND) hWndPalChange, NULL, TRUE);
} }
} }
#endif #endif // wxUSE_PALETTE
wxPaletteChangedEvent event(GetId()); wxPaletteChangedEvent event(GetId());
event.SetEventObject(this); event.SetEventObject(this);
@@ -3392,19 +3400,19 @@ bool wxWindowMSW::HandleQueryNewPalette()
/* realize the palette to see whether redrawing is needed */ /* realize the palette to see whether redrawing is needed */
HDC hdc = GetDC((HWND) GetHWND()); HDC hdc = GetDC((HWND) GetHWND());
win->m_palette.SetHPALETTE( (WXHPALETTE) win->m_palette.SetHPALETTE( (WXHPALETTE)
::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), false) ); ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) );
int result = ::RealizePalette(hdc); int result = ::RealizePalette(hdc);
/* restore the palette (before releasing the DC) */ /* restore the palette (before releasing the DC) */
win->m_palette.SetHPALETTE( (WXHPALETTE) win->m_palette.SetHPALETTE( (WXHPALETTE)
::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), true) ); ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) );
::RealizePalette(hdc); ::RealizePalette(hdc);
::ReleaseDC((HWND) GetHWND(), hdc); ::ReleaseDC((HWND) GetHWND(), hdc);
/* now check for the need to redraw */ /* now check for the need to redraw */
if (result > 0) if (result > 0)
::InvalidateRect((HWND) GetHWND(), NULL, TRUE); ::InvalidateRect((HWND) GetHWND(), NULL, TRUE);
} }
#endif #endif // wxUSE_PALETTE
wxQueryNewPaletteEvent event(GetId()); wxQueryNewPaletteEvent event(GetId());
event.SetEventObject(this); event.SetEventObject(this);