From 10fcf31a2cefc6a8224a33038cb255c082669d5f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Aug 1999 22:22:02 +0000 Subject: [PATCH] 1. wxWindow::Centre() hopefully fixed 2. attempts to construct bitmaps from icons properly 3. wxTreeCtrl background is always white git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3232 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 8 ++-- include/wx/msw/bitmap.h | 19 ++++---- src/common/wincmn.cpp | 18 ++++++-- src/msw/bitmap.cpp | 97 ++++++++++++++++++++++++++++++----------- src/msw/dc.cpp | 3 ++ src/msw/treectrl.cpp | 6 ++- 6 files changed, 108 insertions(+), 43 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index cb603db5e9..c842b7f779 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1003,9 +1003,11 @@ enum wxDirection // wxCENTRE = 0x0400 (defined above) -// centering into frame rather than screen -#define wxCENTER_FRAME 0x0004 - +// centering into frame rather than screen (obsolete) +#define wxCENTER_FRAME 0x0000 +// centre on screen rather than parent +#define wxCENTRE_ON_SCREEN 0x0004 +#define wxCENTER_ON_SCREEN wxCENTRE_ON_SCREEN // ---------------------------------------------------------------------------- // Possible SetSize flags diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index a17235451c..4fb10e6877 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -36,7 +36,7 @@ class WXDLLEXPORT wxMask: public wxObject DECLARE_DYNAMIC_CLASS(wxMask) public: - wxMask(void); + wxMask(); // Construct a mask from a bitmap and a colour indicating // the transparent area @@ -49,7 +49,7 @@ public: // Construct a mask from a mono bitmap (copies the bitmap). wxMask(const wxBitmap& bitmap); - ~wxMask(void); + ~wxMask(); bool Create(const wxBitmap& bitmap, const wxColour& colour); bool Create(const wxBitmap& bitmap, int paletteIndex); @@ -68,8 +68,8 @@ class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData friend class WXDLLEXPORT wxIcon; friend class WXDLLEXPORT wxCursor; public: - wxBitmapRefData(void); - ~wxBitmapRefData(void); + wxBitmapRefData(); + ~wxBitmapRefData(); public: int m_width; @@ -121,11 +121,10 @@ class WXDLLEXPORT wxBitmap: public wxGDIObject friend class WXDLLEXPORT wxBitmapHandler; public: - wxBitmap(void); // Platform-specific + wxBitmap(); // Platform-specific // Copy constructors - inline wxBitmap(const wxBitmap& bitmap) - { Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } + wxBitmap(const wxBitmap& bitmap); // Initialize with raw data wxBitmap(const char bits[], int width, int height, int depth = 1); @@ -141,7 +140,7 @@ public: // If depth is omitted, will create a bitmap compatible with the display wxBitmap(int width, int height, int depth = -1); - ~wxBitmap(void); + ~wxBitmap(); virtual bool Create(int width, int height, int depth = -1); virtual bool Create(void *data, long type, int width, int height, int depth = 1); @@ -182,8 +181,8 @@ public: static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType); static wxBitmapHandler *FindHandler(long bitmapType); - static void InitStandardHandlers(void); - static void CleanUpHandlers(void); + static void InitStandardHandlers(); + static void CleanUpHandlers(); protected: static wxList sm_handlers; diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 5052d51dfe..a235318fb0 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -303,15 +303,22 @@ void wxWindowBase::Centre(int direction) int widthParent, heightParent; wxWindow *parent = GetParent(); - if ( (direction & wxCENTER_FRAME) && parent ) + if ( !parent ) { - parent->GetClientSize(&widthParent, &heightParent); + // no other choice + direction |= wxCENTRE_ON_SCREEN; } - else + + if ( direction & wxCENTRE_ON_SCREEN ) { // centre with respect to the whole screen wxDisplaySize(&widthParent, &heightParent); } + else + { + // centre inside the parents rectangle + parent->GetClientSize(&widthParent, &heightParent); + } int width, height; GetSize(&width, &height); @@ -327,8 +334,11 @@ void wxWindowBase::Centre(int direction) // controls are always centered on their parent because it doesn't make // sense to centre them on the screen - if ( (direction & wxCENTER_FRAME) || wxDynamicCast(this, wxControl) ) + if ( !(direction & wxCENTRE_ON_SCREEN) || wxDynamicCast(this, wxControl) ) { + // theo nly chance to get this is to have a wxControl without parent + wxCHECK_RET( parent, _T("a control must have a parent") ); + // adjust to the parents client area origin wxPoint posParent = parent->ClientToScreen(wxPoint(0, 0)); diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index e6194fcef9..29926d61d2 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -9,42 +9,60 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "bitmap.h" + #pragma implementation "bitmap.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include -#include "wx/setup.h" -#include "wx/list.h" -#include "wx/utils.h" -#include "wx/app.h" -#include "wx/palette.h" -#include "wx/dcmemory.h" -#include "wx/bitmap.h" -#include "wx/icon.h" + #include + + #include "wx/list.h" + #include "wx/utils.h" + #include "wx/app.h" + #include "wx/palette.h" + #include "wx/dcmemory.h" + #include "wx/bitmap.h" + #include "wx/icon.h" #endif #include "wx/msw/private.h" #include "wx/log.h" -#include "assert.h" - #include "wx/msw/dib.h" +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + #if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) -IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) + IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) + IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) #endif -wxBitmapRefData::wxBitmapRefData(void) +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxBitmapRefData +// ---------------------------------------------------------------------------- + +wxBitmapRefData::wxBitmapRefData() { m_ok = FALSE; m_width = 0; @@ -57,7 +75,7 @@ wxBitmapRefData::wxBitmapRefData(void) m_bitmapMask = NULL; } -wxBitmapRefData::~wxBitmapRefData(void) +wxBitmapRefData::~wxBitmapRefData() { if (m_selectedInto) { @@ -77,15 +95,44 @@ wxBitmapRefData::~wxBitmapRefData(void) } +// ---------------------------------------------------------------------------- +// wxBitmap +// ---------------------------------------------------------------------------- + wxList wxBitmap::sm_handlers; -wxBitmap::wxBitmap(void) +wxBitmap::wxBitmap() { if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } -wxBitmap::~wxBitmap(void) +wxBitmap::wxBitmap(const wxBitmap& bitmap) +{ + wxIcon *icon = wxDynamicCast(&bitmap, wxIcon); + if ( icon ) + { + HDC hdc = ::CreateCompatibleDC(NULL); // screen DC + HBITMAP hbitmap = ::CreateCompatibleBitmap(hdc, + icon->GetWidth(), + icon->GetHeight()); + ::SelectObject(hdc, hbitmap); + ::DrawIcon(hdc, 0, 0, (HICON)icon->GetHICON()); + + ::DeleteDC(hdc); + + SetHBITMAP((WXHBITMAP)hbitmap); + } + else + { + Ref(bitmap); + } + + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); +} + +wxBitmap::~wxBitmap() { if (wxTheBitmapList) wxTheBitmapList->DeleteObject(this); @@ -435,7 +482,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const * wxMask */ -wxMask::wxMask(void) +wxMask::wxMask() { m_maskBitmap = 0; } @@ -463,7 +510,7 @@ wxMask::wxMask(const wxBitmap& bitmap) Create(bitmap); } -wxMask::~wxMask(void) +wxMask::~wxMask() { if ( m_maskBitmap ) ::DeleteObject((HBITMAP) m_maskBitmap); @@ -601,7 +648,7 @@ class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler { DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler) public: - inline wxBMPResourceHandler(void) + inline wxBMPResourceHandler() { m_name = "Windows bitmap resource"; m_extension = ""; @@ -644,7 +691,7 @@ class WXDLLEXPORT wxBMPFileHandler: public wxBitmapHandler { DECLARE_DYNAMIC_CLASS(wxBMPFileHandler) public: - inline wxBMPFileHandler(void) + inline wxBMPFileHandler() { m_name = "Windows bitmap file"; m_extension = "bmp"; @@ -697,7 +744,7 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int WXUN #endif } -void wxBitmap::CleanUpHandlers(void) +void wxBitmap::CleanUpHandlers() { wxNode *node = sm_handlers.First(); while ( node ) @@ -710,7 +757,7 @@ void wxBitmap::CleanUpHandlers(void) } } -void wxBitmap::InitStandardHandlers(void) +void wxBitmap::InitStandardHandlers() { AddHandler(new wxBMPResourceHandler); AddHandler(new wxBMPFileHandler); diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index d693d7a278..d17e9b1961 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -591,6 +591,9 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) HDC cdc = GetHdc(); HDC memdc = ::CreateCompatibleDC( cdc ); HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( ); + + wxASSERT_MSG( hbitmap, _T("bitmap is ok but HBITMAP is NULL?") ); + ::SelectObject( memdc, hbitmap ); ::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY); ::DeleteDC( memdc ); diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index cd68918437..4118355c1a 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -199,13 +199,17 @@ bool wxTreeCtrl::Create(wxWindow *parent, // we emulate the multiple selection tree controls by using checkboxes: set // up the image list we need for this if we do have multiple selections if ( m_windowStyle & wxTR_MULTIPLE ) - wstyle |= TVS_CHECKBOXES; + wstyle |= TVS_CHECKBOXES; #endif // Create the tree control. if ( !MSWCreateControl(WC_TREEVIEW, wstyle) ) return FALSE; + // the treectrl with any other background looks ugly because the items + // background is white anyhow + SetBackgroundColour(*wxWHITE); + // VZ: this is some experimental code which may be used to get the // TVS_CHECKBOXES style functionality for comctl32.dll < 4.71. // AFAIK, the standard DLL does about the same thing anyhow. -- 2.45.2