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
This commit is contained in:
Vadim Zeitlin
1999-08-01 22:22:02 +00:00
parent 4ee14879f2
commit 10fcf31a2c
6 changed files with 108 additions and 43 deletions

View File

@@ -1003,9 +1003,11 @@ enum wxDirection
// wxCENTRE = 0x0400 (defined above) // wxCENTRE = 0x0400 (defined above)
// centering into frame rather than screen // centering into frame rather than screen (obsolete)
#define wxCENTER_FRAME 0x0004 #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 // Possible SetSize flags

View File

@@ -36,7 +36,7 @@ class WXDLLEXPORT wxMask: public wxObject
DECLARE_DYNAMIC_CLASS(wxMask) DECLARE_DYNAMIC_CLASS(wxMask)
public: public:
wxMask(void); wxMask();
// Construct a mask from a bitmap and a colour indicating // Construct a mask from a bitmap and a colour indicating
// the transparent area // the transparent area
@@ -49,7 +49,7 @@ public:
// Construct a mask from a mono bitmap (copies the bitmap). // Construct a mask from a mono bitmap (copies the bitmap).
wxMask(const wxBitmap& bitmap); wxMask(const wxBitmap& bitmap);
~wxMask(void); ~wxMask();
bool Create(const wxBitmap& bitmap, const wxColour& colour); bool Create(const wxBitmap& bitmap, const wxColour& colour);
bool Create(const wxBitmap& bitmap, int paletteIndex); bool Create(const wxBitmap& bitmap, int paletteIndex);
@@ -68,8 +68,8 @@ class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
friend class WXDLLEXPORT wxIcon; friend class WXDLLEXPORT wxIcon;
friend class WXDLLEXPORT wxCursor; friend class WXDLLEXPORT wxCursor;
public: public:
wxBitmapRefData(void); wxBitmapRefData();
~wxBitmapRefData(void); ~wxBitmapRefData();
public: public:
int m_width; int m_width;
@@ -121,11 +121,10 @@ class WXDLLEXPORT wxBitmap: public wxGDIObject
friend class WXDLLEXPORT wxBitmapHandler; friend class WXDLLEXPORT wxBitmapHandler;
public: public:
wxBitmap(void); // Platform-specific wxBitmap(); // Platform-specific
// Copy constructors // Copy constructors
inline wxBitmap(const wxBitmap& bitmap) wxBitmap(const wxBitmap& bitmap);
{ Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); }
// Initialize with raw data // Initialize with raw data
wxBitmap(const char bits[], int width, int height, int depth = 1); 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 // If depth is omitted, will create a bitmap compatible with the display
wxBitmap(int width, int height, int depth = -1); wxBitmap(int width, int height, int depth = -1);
~wxBitmap(void); ~wxBitmap();
virtual bool Create(int width, int height, int depth = -1); virtual bool Create(int width, int height, int depth = -1);
virtual bool Create(void *data, long type, 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(const wxString& extension, long bitmapType);
static wxBitmapHandler *FindHandler(long bitmapType); static wxBitmapHandler *FindHandler(long bitmapType);
static void InitStandardHandlers(void); static void InitStandardHandlers();
static void CleanUpHandlers(void); static void CleanUpHandlers();
protected: protected:
static wxList sm_handlers; static wxList sm_handlers;

View File

@@ -303,15 +303,22 @@ void wxWindowBase::Centre(int direction)
int widthParent, heightParent; int widthParent, heightParent;
wxWindow *parent = GetParent(); 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 // centre with respect to the whole screen
wxDisplaySize(&widthParent, &heightParent); wxDisplaySize(&widthParent, &heightParent);
} }
else
{
// centre inside the parents rectangle
parent->GetClientSize(&widthParent, &heightParent);
}
int width, height; int width, height;
GetSize(&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 // controls are always centered on their parent because it doesn't make
// sense to centre them on the screen // 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 // adjust to the parents client area origin
wxPoint posParent = parent->ClientToScreen(wxPoint(0, 0)); wxPoint posParent = parent->ClientToScreen(wxPoint(0, 0));

View File

@@ -9,42 +9,60 @@
// Licence: wxWindows license // Licence: wxWindows license
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "bitmap.h" #pragma implementation "bitmap.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 #endif
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include <stdio.h> #include <stdio.h>
#include "wx/setup.h"
#include "wx/list.h" #include "wx/list.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/palette.h" #include "wx/palette.h"
#include "wx/dcmemory.h" #include "wx/dcmemory.h"
#include "wx/bitmap.h" #include "wx/bitmap.h"
#include "wx/icon.h" #include "wx/icon.h"
#endif #endif
#include "wx/msw/private.h" #include "wx/msw/private.h"
#include "wx/log.h" #include "wx/log.h"
#include "assert.h"
#include "wx/msw/dib.h" #include "wx/msw/dib.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARIES #if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
#endif #endif
wxBitmapRefData::wxBitmapRefData(void) // ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxBitmapRefData
// ----------------------------------------------------------------------------
wxBitmapRefData::wxBitmapRefData()
{ {
m_ok = FALSE; m_ok = FALSE;
m_width = 0; m_width = 0;
@@ -57,7 +75,7 @@ wxBitmapRefData::wxBitmapRefData(void)
m_bitmapMask = NULL; m_bitmapMask = NULL;
} }
wxBitmapRefData::~wxBitmapRefData(void) wxBitmapRefData::~wxBitmapRefData()
{ {
if (m_selectedInto) if (m_selectedInto)
{ {
@@ -77,15 +95,44 @@ wxBitmapRefData::~wxBitmapRefData(void)
} }
// ----------------------------------------------------------------------------
// wxBitmap
// ----------------------------------------------------------------------------
wxList wxBitmap::sm_handlers; wxList wxBitmap::sm_handlers;
wxBitmap::wxBitmap(void) wxBitmap::wxBitmap()
{ {
if ( wxTheBitmapList ) if ( wxTheBitmapList )
wxTheBitmapList->AddBitmap(this); 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) if (wxTheBitmapList)
wxTheBitmapList->DeleteObject(this); wxTheBitmapList->DeleteObject(this);
@@ -435,7 +482,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const
* wxMask * wxMask
*/ */
wxMask::wxMask(void) wxMask::wxMask()
{ {
m_maskBitmap = 0; m_maskBitmap = 0;
} }
@@ -463,7 +510,7 @@ wxMask::wxMask(const wxBitmap& bitmap)
Create(bitmap); Create(bitmap);
} }
wxMask::~wxMask(void) wxMask::~wxMask()
{ {
if ( m_maskBitmap ) if ( m_maskBitmap )
::DeleteObject((HBITMAP) m_maskBitmap); ::DeleteObject((HBITMAP) m_maskBitmap);
@@ -601,7 +648,7 @@ class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
{ {
DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler) DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
public: public:
inline wxBMPResourceHandler(void) inline wxBMPResourceHandler()
{ {
m_name = "Windows bitmap resource"; m_name = "Windows bitmap resource";
m_extension = ""; m_extension = "";
@@ -644,7 +691,7 @@ class WXDLLEXPORT wxBMPFileHandler: public wxBitmapHandler
{ {
DECLARE_DYNAMIC_CLASS(wxBMPFileHandler) DECLARE_DYNAMIC_CLASS(wxBMPFileHandler)
public: public:
inline wxBMPFileHandler(void) inline wxBMPFileHandler()
{ {
m_name = "Windows bitmap file"; m_name = "Windows bitmap file";
m_extension = "bmp"; m_extension = "bmp";
@@ -697,7 +744,7 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int WXUN
#endif #endif
} }
void wxBitmap::CleanUpHandlers(void) void wxBitmap::CleanUpHandlers()
{ {
wxNode *node = sm_handlers.First(); wxNode *node = sm_handlers.First();
while ( node ) while ( node )
@@ -710,7 +757,7 @@ void wxBitmap::CleanUpHandlers(void)
} }
} }
void wxBitmap::InitStandardHandlers(void) void wxBitmap::InitStandardHandlers()
{ {
AddHandler(new wxBMPResourceHandler); AddHandler(new wxBMPResourceHandler);
AddHandler(new wxBMPFileHandler); AddHandler(new wxBMPFileHandler);

View File

@@ -591,6 +591,9 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask )
HDC cdc = GetHdc(); HDC cdc = GetHdc();
HDC memdc = ::CreateCompatibleDC( cdc ); HDC memdc = ::CreateCompatibleDC( cdc );
HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( ); HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( );
wxASSERT_MSG( hbitmap, _T("bitmap is ok but HBITMAP is NULL?") );
::SelectObject( memdc, hbitmap ); ::SelectObject( memdc, hbitmap );
::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY); ::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY);
::DeleteDC( memdc ); ::DeleteDC( memdc );

View File

@@ -199,13 +199,17 @@ bool wxTreeCtrl::Create(wxWindow *parent,
// we emulate the multiple selection tree controls by using checkboxes: set // 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 // up the image list we need for this if we do have multiple selections
if ( m_windowStyle & wxTR_MULTIPLE ) if ( m_windowStyle & wxTR_MULTIPLE )
wstyle |= TVS_CHECKBOXES; wstyle |= TVS_CHECKBOXES;
#endif #endif
// Create the tree control. // Create the tree control.
if ( !MSWCreateControl(WC_TREEVIEW, wstyle) ) if ( !MSWCreateControl(WC_TREEVIEW, wstyle) )
return FALSE; 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 // VZ: this is some experimental code which may be used to get the
// TVS_CHECKBOXES style functionality for comctl32.dll < 4.71. // TVS_CHECKBOXES style functionality for comctl32.dll < 4.71.
// AFAIK, the standard DLL does about the same thing anyhow. // AFAIK, the standard DLL does about the same thing anyhow.