1. more (minor) wxCaret bug fixes

2. try to enforce wxPaintDC usage only inside EVT_PAINT handler (only in
   debug mode)
3. warnings removed from pnghand.cpp and dibuitls.cpp


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2664 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-06-03 23:17:01 +00:00
parent 2bc07607fc
commit c6eba8f8b2
5 changed files with 99 additions and 56 deletions

View File

@@ -140,12 +140,13 @@ void wxCaret::DoShow()
void wxCaret::DoHide() void wxCaret::DoHide()
{ {
wxASSERT_MSG( m_hasCaret, "cannot hide non existent caret" ); if ( m_hasCaret )
{
if ( !::HideCaret(GetWinHwnd(GetWindow())) ) if ( !::HideCaret(GetWinHwnd(GetWindow())) )
{ {
wxLogLastError("HideCaret"); wxLogLastError("HideCaret");
} }
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -9,36 +9,63 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ===========================================================================
// declarations
// ===========================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "dcclient.h" #pragma implementation "dcclient.h"
#endif #endif
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif
#ifndef WX_PRECOMP
#endif #endif
#include "wx/dcclient.h" #include "wx/dcclient.h"
#include "wx/log.h" #include "wx/log.h"
#include <windows.h> #include "wx/msw/private.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
#endif #endif
/* // ----------------------------------------------------------------------------
* wxWindowDC // global variables
*/ // ----------------------------------------------------------------------------
wxWindowDC::wxWindowDC(void) static PAINTSTRUCT g_paintStruct;
#ifdef __WXDEBUG__
// a global variable which we check to verify that wxPaintDC are only
// created in resopnse to WM_PAINT message - doing this from elsewhere is a
// common programming error among wxWindows programmers and might lead to
// very subtle and difficult to debug refresh/repaint bugs.
extern bool g_isPainting = FALSE;
#endif // __WXDEBUG__
// ===========================================================================
// implementation
// ===========================================================================
// ----------------------------------------------------------------------------
// wxWindowDC
// ----------------------------------------------------------------------------
wxWindowDC::wxWindowDC()
{ {
m_canvas = NULL; m_canvas = NULL;
} }
@@ -46,30 +73,30 @@ wxWindowDC::wxWindowDC(void)
wxWindowDC::wxWindowDC(wxWindow *the_canvas) wxWindowDC::wxWindowDC(wxWindow *the_canvas)
{ {
m_canvas = the_canvas; m_canvas = the_canvas;
// m_hDC = (WXHDC) ::GetDCEx((HWND) the_canvas->GetHWND(), NULL, DCX_WINDOW); m_hDC = (WXHDC) ::GetWindowDC(GetWinHwnd(the_canvas) );
m_hDC = (WXHDC) ::GetWindowDC((HWND) the_canvas->GetHWND() ); m_hDCCount++;
m_hDCCount ++;
SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID)); SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
} }
wxWindowDC::~wxWindowDC(void) wxWindowDC::~wxWindowDC()
{ {
if (m_canvas && m_hDC) if (m_canvas && m_hDC)
{ {
SelectOldObjects(m_hDC); SelectOldObjects(m_hDC);
::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC); ::ReleaseDC(GetWinHwnd(m_canvas), GetHdc());
m_hDC = 0; m_hDC = 0;
} }
m_hDCCount --;
m_hDCCount--;
} }
/* // ----------------------------------------------------------------------------
* wxClientDC // wxClientDC
*/ // ----------------------------------------------------------------------------
wxClientDC::wxClientDC(void) wxClientDC::wxClientDC()
{ {
m_canvas = NULL; m_canvas = NULL;
} }
@@ -77,47 +104,49 @@ wxClientDC::wxClientDC(void)
wxClientDC::wxClientDC(wxWindow *the_canvas) wxClientDC::wxClientDC(wxWindow *the_canvas)
{ {
m_canvas = the_canvas; m_canvas = the_canvas;
// BeginDrawing(); m_hDC = (WXHDC) ::GetDC(GetWinHwnd(the_canvas));
m_hDC = (WXHDC) ::GetDC((HWND) the_canvas->GetHWND());
SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID)); SetBackground(wxBrush(m_canvas->GetBackgroundColour(), wxSOLID));
} }
wxClientDC::~wxClientDC(void) wxClientDC::~wxClientDC()
{ {
// EndDrawing(); if ( m_canvas && GetHdc() )
if (m_canvas && (HDC) m_hDC)
{ {
SelectOldObjects(m_hDC); SelectOldObjects(m_hDC);
::ReleaseDC((HWND) m_canvas->GetHWND(), (HDC) m_hDC); ::ReleaseDC(GetWinHwnd(m_canvas), GetHdc());
m_hDC = 0; m_hDC = 0;
} }
} }
/* // ----------------------------------------------------------------------------
* wxPaintDC // wxPaintDC
*/ // ----------------------------------------------------------------------------
wxPaintDC::wxPaintDC(void) // TODO (VZ) I have still some doubts about this hack and I still think that we
{ // should store pairs of (hwnd, hdc) and not just the DC - what if
m_canvas = NULL; // BeginPaint() was called on other window? It seems to work like
} // this, but to be sure about it we'd need to store hwnd too...
static PAINTSTRUCT g_paintStruct;
// Don't call Begin/EndPaint if it's already been called:
// for example, if calling a base class OnPaint.
WXHDC wxPaintDC::ms_PaintHDC = 0; WXHDC wxPaintDC::ms_PaintHDC = 0;
size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage size_t wxPaintDC::ms_PaintCount = 0; // count of ms_PaintHDC usage
wxPaintDC::wxPaintDC()
{
m_canvas = NULL;
}
wxPaintDC::wxPaintDC(wxWindow *canvas) wxPaintDC::wxPaintDC(wxWindow *canvas)
{ {
wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" ); wxCHECK_RET( canvas, "NULL canvas in wxPaintDC ctor" );
wxCHECK_RET( g_isPainting,
_T("wxPaintDC may be created only in EVT_PAINT handler!") );
m_canvas = canvas; m_canvas = canvas;
// Don't call Begin/EndPaint if it's already been called: for example, if
// calling a base class OnPaint.
if ( ms_PaintCount > 0 ) { if ( ms_PaintCount > 0 ) {
// it means that we've already called BeginPaint and so we must just // it means that we've already called BeginPaint and so we must just
// reuse the same HDC (BeginPaint shouldn't be called more than once) // reuse the same HDC (BeginPaint shouldn't be called more than once)
@@ -145,7 +174,7 @@ wxPaintDC::~wxPaintDC()
m_hDC = (WXHDC) NULL; m_hDC = (WXHDC) NULL;
ms_PaintHDC = (WXHDC) NULL; ms_PaintHDC = (WXHDC) NULL;
} }
else { }//: ms_PaintHDC still in use //else: ms_PaintHDC still in use
} }
} }

View File

@@ -243,7 +243,6 @@ PDIB DibOpenFile(LPSTR szFile)
PDIB DibReadBitmapInfo(HFILE fh) PDIB DibReadBitmapInfo(HFILE fh)
{ {
DWORD off; DWORD off;
HANDLE hbi = NULL;
int size; int size;
int i; int i;
int nNumColors; int nNumColors;

View File

@@ -38,7 +38,7 @@
#include <wx/msw/dibutils.h> #include <wx/msw/dibutils.h>
extern "C" { extern "C" {
#include "png.h" #include "../png/png.h"
} }
extern "C" void png_read_init PNGARG((png_structp png_ptr)); extern "C" void png_read_init PNGARG((png_structp png_ptr));
@@ -130,7 +130,8 @@ wxPNGReader::Create(int width, int height, int depth, int colortype)
} }
RawImage = 0; RawImage = 0;
Palette = 0; Palette = 0;
if (lpbi = DibCreate(Depth, Width, Height)) { lpbi = DibCreate(Depth, Width, Height);
if (lpbi) {
RawImage = (ImagePointerType)DibPtr(lpbi); RawImage = (ImagePointerType)DibPtr(lpbi);
EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4; EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4;
imageOK = TRUE; imageOK = TRUE;
@@ -291,7 +292,7 @@ bool wxPNGReader::InstantiateBitmap(wxBitmap *bitmap)
if ( Palette ) if ( Palette )
{ {
HPALETTE oldPal = ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE); ::SelectPalette(dc, (HPALETTE) Palette->GetHPALETTE(), FALSE);
::RealizePalette(dc); ::RealizePalette(dc);
} }

View File

@@ -117,6 +117,17 @@ wxMenu *wxCurrentPopupMenu = NULL;
extern wxList WXDLLEXPORT wxPendingDelete; extern wxList WXDLLEXPORT wxPendingDelete;
extern char wxCanvasClassName[]; extern char wxCanvasClassName[];
#ifdef __WXDEBUG__
// see comments in dcclient.cpp where g_isPainting is defined
extern bool g_isPainting;
inline static void wxStartPainting() { g_isPainting = TRUE; }
inline static void wxEndPainting() { g_isPainting = FALSE; }
#else // !debug
inline static void wxStartPainting() { }
inline static void wxEndPainting() { }
#endif // debug/!debug
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// private functions // private functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -1674,7 +1685,9 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
break; break;
case WM_PAINT: case WM_PAINT:
wxStartPainting();
processed = HandlePaint(); processed = HandlePaint();
wxEndPainting();
break; break;
case WM_CLOSE: case WM_CLOSE: