diff --git a/include/wx/colordlg.h b/include/wx/colordlg.h index 4f32249140..984ce43dc8 100644 --- a/include/wx/colordlg.h +++ b/include/wx/colordlg.h @@ -22,5 +22,9 @@ #define sm_classwxColourDialog sm_classwxGenericColourDialog #endif +// get the colour from user and return it +wxColour WXDLLEXPORT wxGetColourFromUser(wxWindow *parent = (wxWindow *)NULL, + const wxColour& colInit = wxNullColour); + #endif // _WX_COLORDLG_H_BASE_ diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 106c857248..81378145cb 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -111,8 +111,8 @@ public: // Attributes //////////////////////////////////////////////////////////////////////////// - // Sets the background colour (GetBackgroundColour already implicit in - // wxWindow class) + // Set the control colours + bool SetForegroundColour(const wxColour& col); bool SetBackgroundColour(const wxColour& col); // Gets information about this column @@ -331,8 +331,8 @@ protected: // common part of all ctors void Init(); - // free memory taken by all attributes - void FreeAllAttrs(); + // free memory taken by all attributes and recreate the hash table + void FreeAllAttrs(bool dontRecreate = FALSE); wxTextCtrl* m_textCtrl; // The control used for editing a label wxImageList * m_imageListNormal; // The image list for normal icons diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 9af79de329..5a685ccc75 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -59,6 +59,10 @@ #endif #endif +#if wxUSE_GUI + #include "wx/colordlg.h" +#endif // wxUSE_GUI + #include #ifndef __MWERKS__ @@ -908,6 +912,30 @@ wxString wxGetPasswordFromUser(const wxString& message, #endif // wxUSE_TEXTDLG +wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit) +{ + wxColourData data; + data.SetChooseFull(TRUE); + if ( colInit.Ok() ) + { + data.SetColour((wxColour &)colInit); // const_cast + } + + wxColour colRet; + wxColourDialog dialog(parent, &data); + if ( dialog.ShowModal() == wxID_OK ) + { + colRet = dialog.GetColourData().GetColour(); + } + //else: leave it invalid + + return colRet; +} + +// ---------------------------------------------------------------------------- +// missing C RTL functions (FIXME shouldn't be here at all) +// ---------------------------------------------------------------------------- + #ifdef __MWERKS__ char *strdup(const char *s) { diff --git a/src/generic/wizard.cpp b/src/generic/wizard.cpp index 34ef1e7495..fdd9dc7a8c 100644 --- a/src/generic/wizard.cpp +++ b/src/generic/wizard.cpp @@ -185,7 +185,7 @@ wxWizard::wxWizard(wxWindow *parent, if ( pos == wxDefaultPosition ) { - Centre(); + CentreOnScreen(); } } diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 3c1d51c508..c720b36fa3 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -657,7 +657,56 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask int width = bmp.GetWidth(), height = bmp.GetHeight(); - if ( !useMask ) + HBITMAP hbmpMask = 0; + + if ( useMask ) + { + wxMask *mask = bmp.GetMask(); + if ( mask ) + hbmpMask = (HBITMAP)mask->GetMaskBitmap(); + + if ( !hbmpMask ) + { + // don't give assert here because this would break existing + // programs - just silently ignore useMask parameter + useMask = FALSE; + } + } + + if ( useMask ) + { +#ifdef __WIN32__ + HDC hdcMem = ::CreateCompatibleDC(GetHdc()); + ::SelectObject(hdcMem, GetHbitmapOf(bmp)); + + // this will only work if the transparent part of our bitmap is black + // because it is combined with the destination rectangle using OR, so + // it won't be really transparent otherwise - I don't know what to do + // about it, may be use MAKEROP4(SRCCOPY, DSTINVERT) twice? Or create a + // copy of the bitmap with the transparent part replaced with black + // pixels? + bool ok = ::MaskBlt(GetHdc(), x, y, width, height, + hdcMem, 0, 0, + hbmpMask, 0, 0, + MAKEROP4(SRCCOPY, SRCPAINT)) != 0; + ::DeleteDC(hdcMem); + + if ( !ok ) +#endif // Win32 + { + // VZ: this is incorrect, Blit() doesn't (and can't) draw + // transparently, but it's still better than nothing at all + + // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level + wxMemoryDC memDC; + memDC.SelectObject(bmp); + + Blit(x, y, width, height, &memDC, 0, 0, wxCOPY, useMask); + + memDC.SelectObject(wxNullBitmap); + } + } + else // no mask, just use BitBlt() { HDC cdc = GetHdc(); HDC memdc = ::CreateCompatibleDC( cdc ); @@ -683,16 +732,6 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ::SetTextColor(GetHdc(), old_textground); ::SetBkColor(GetHdc(), old_background); } - else - { - // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level - wxMemoryDC memDC; - memDC.SelectObject(bmp); - - Blit(x, y, width, height, &memDC, 0, 0, wxCOPY, useMask); - - memDC.SelectObject(wxNullBitmap); - } } void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) @@ -1304,21 +1343,40 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, if (useMask) { #ifdef __WIN32__ + // prepare the mask bitmap HBITMAP hbmpMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap()); + // select the correct brush: the current one by default, background one + // if none + HBRUSH hbrNew; + if ( m_brush.Ok() ) + { + hbrNew = (HBRUSH)m_brush.GetResourceHandle(); + } + else if ( m_backgroundBrush.Ok() ) + { + hbrNew = (HBRUSH)m_backgroundBrush.GetResourceHandle(); + } + else + { + hbrNew = 0; + } + + HGDIOBJ hbrOld = hbrNew ? ::SelectObject(GetHdc(), hbrNew) : 0; + // we want the part of the image corresponding to the mask to be // transparent, i.e. do PATCOPY there and apply dwRop elsewhere - const wxColour& colBg = m_backgroundBrush.GetColour(); - HBRUSH hbrBg = (HBRUSH)::CreateSolidBrush(wxColourToRGB(colBg)); - HBRUSH hbrOld = (HBRUSH)::SelectObject(GetHdc(), hbrBg); success = ::MaskBlt(GetHdc(), xdest, ydest, width, height, GetHdcOf(*source), xsrc, ysrc, hbmpMask, 0, 0, MAKEROP4(PATCOPY, dwRop)) != 0; - (void)::SelectObject(GetHdc(), hbrOld); - ::DeleteObject(hbrOld); + if ( hbrNew ) + { + (void)::SelectObject(GetHdc(), hbrOld); + } + ::DeleteObject(hbmpMask); if ( !success ) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 029cbe1b31..f38207bed6 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -239,7 +239,7 @@ void wxListCtrl::UpdateStyle() } } -void wxListCtrl::FreeAllAttrs() +void wxListCtrl::FreeAllAttrs(bool dontRecreate) { if ( m_hasAnyAttr ) { @@ -249,6 +249,10 @@ void wxListCtrl::FreeAllAttrs() } m_attrs.Destroy(); + if ( !dontRecreate ) + { + m_attrs.Create(wxKEY_INTEGER, 1000); // just as def ctor + } m_hasAnyAttr = FALSE; } @@ -256,6 +260,8 @@ void wxListCtrl::FreeAllAttrs() wxListCtrl::~wxListCtrl() { + FreeAllAttrs(TRUE /* no need to recreate hash any more */); + if ( m_textCtrl ) { m_textCtrl->UnsubclassWin(); @@ -416,14 +422,28 @@ long wxListCtrl::ConvertToMSWStyle(long& oldStyle, long style) const // accessors // ---------------------------------------------------------------------------- -// Sets the background colour (GetBackgroundColour already implicit in -// wxWindow class) +// Sets the foreground, i.e. text, colour +bool wxListCtrl::SetForegroundColour(const wxColour& col) +{ + if ( !wxWindow::SetForegroundColour(col) ) + return FALSE; + + ListView_SetTextColor(GetHwnd(), wxColourToRGB(col)); + + return TRUE; +} + +// Sets the background colour bool wxListCtrl::SetBackgroundColour(const wxColour& col) { if ( !wxWindow::SetBackgroundColour(col) ) return FALSE; - ListView_SetBkColor(GetHwnd(), PALETTERGB(col.Red(), col.Green(), col.Blue())); + // we set the same colour for both the "empty" background and the items + // background + COLORREF color = wxColourToRGB(col); + ListView_SetBkColor(GetHwnd(), color); + ListView_SetTextBkColor(GetHwnd(), color); return TRUE; }