From 07cf98cb8eb7625eeffc95e407a9fa1ad863b451 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Nov 1999 00:30:45 +0000 Subject: [PATCH] 1. undid my wrong fix to wxWindowBase::Centre 2. corrected fatal bug in wxCheckLstBox (double deletion of items) 3. wxTextCtrl::SetValue() only does it if the new text is different from the old one 4. wxBitmap(const wxIcon&) ctor added 5. compilation fixes for VC++ and generic Win32 implementation of wxGetCurrentTime() in timercmn.cpp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/bitmap.h | 5 ++++ src/common/timercmn.cpp | 38 +++++++++++++++++++++++------- src/common/wincmn.cpp | 5 ++-- src/msw/bitmap.cpp | 52 +++++++++++++++++++++++++++-------------- src/msw/checklst.cpp | 7 +++++- src/msw/font.cpp | 2 -- src/msw/listbox.cpp | 26 +++++++++++++-------- src/msw/ownerdrw.cpp | 13 ++++++++--- src/msw/statbox.cpp | 39 ++++--------------------------- src/msw/textctrl.cpp | 7 ++++-- 10 files changed, 112 insertions(+), 82 deletions(-) diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 4fb10e6877..5d2d28686f 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -140,6 +140,11 @@ public: // If depth is omitted, will create a bitmap compatible with the display wxBitmap(int width, int height, int depth = -1); + + // we must have this, otherwise icons are silently copied into bitmaps using + // the copy ctor but the resulting bitmap is invalid! + wxBitmap(const wxIcon& icon); + ~wxBitmap(); virtual bool Create(int width, int height, int depth = -1); diff --git a/src/common/timercmn.cpp b/src/common/timercmn.cpp index e2ac6496ae..63a4eced88 100644 --- a/src/common/timercmn.cpp +++ b/src/common/timercmn.cpp @@ -40,12 +40,15 @@ // configure might have found it already for us #ifndef HAVE_LOCALTIME #define HAVE_LOCALTIME - - // TODO add test for broken compilers here if needed - #define WX_GMTOFF_IN_TM #endif #endif +// TODO: #define WX_GMTOFF_IN_TM for Windows compilers which have it here + +#if defined(__WIN32__) && !defined(WX_GMTOFF_IN_TM) + #include +#endif + #if defined(HAVE_GETTIMEOFDAY) #include #include @@ -198,11 +201,9 @@ bool wxGetLocalTime(long *timeZone, int *dstObserved) *timeZone = 60*tb.timezone; *dstObserved = tb.dstflag; } -#else - // special hacks for known compilers - I wonder if this is still needed, - // i.e. if there are any of them which don't support localtime()? (VZ) - - #if defined(__BORLANDC__) +#else // no standard function return tz info + // special hacks for known compilers + #if defined(__BORLANDC__) || defined(__VISUALC__) *timeZone = _timezone; *dstObserved = _daylight; #elif defined(__SALFORDC__) @@ -211,10 +212,29 @@ bool wxGetLocalTime(long *timeZone, int *dstObserved) #elif defined(__VISAGECPP__) *timeZone = _timezone; *dstObserved = daylight; + #elif defined(__WIN32__) + TIME_ZONE_INFORMATION tzInfo; + switch ( GetTimeZoneInformation(&tzInfo) ) + { + default: + wxFAIL_MSG(_T("unknown GetTimeZoneInformation return code")); + // fall through + + case TIME_ZONE_ID_UNKNOWN: + case TIME_ZONE_ID_STANDARD: + *dstObserved = FALSE; + break; + + case TIME_ZONE_ID_DAYLIGHT: + *dstObserved = TRUE; + break; + } + + *timeZone = 60*tzInfo.Bias; #else wxFAIL_MSG(_T("wxGetLocalTime() not implemented")); #endif // compiler -#endif +#endif // all ways in the known Universe to get tz info return FALSE; } diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 9cad968ed4..18e1821bfc 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -354,9 +354,8 @@ void wxWindowBase::Centre(int direction) yNew += posParent.y; } - // move the centre of this window to this position (not the upper left - // corner as it was done before) - Move(xNew - width / 2, yNew - height / 2); + // move the centre of this window to this position + Move(xNew, yNew); } // fits the window around the children diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 9498c65e43..24811e80a3 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -99,26 +99,44 @@ wxBitmap::wxBitmap() wxTheBitmapList->AddBitmap(this); } -wxBitmap::wxBitmap(const wxBitmap& bitmap) +wxBitmap::wxBitmap(const wxIcon& icon) { - 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()); + if ( wxTheBitmapList ) + wxTheBitmapList->AddBitmap(this); - ::DeleteDC(hdc); + if ( !icon.Ok() ) + return; - SetHBITMAP((WXHBITMAP)hbitmap); - } - else - { - Ref(bitmap); - } + int width = icon.GetWidth(), + height = icon.GetHeight(); + + HDC hdc = ::CreateCompatibleDC(NULL); // screen DC + HBITMAP hbitmap = ::CreateCompatibleBitmap(hdc, width, height); + HBITMAP hbmpOld = (HBITMAP)::SelectObject(hdc, hbitmap); + + HICON hicon = (HICON) icon.GetHICON(); +#if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__) + ::DrawIconEx(hdc, 0, 0, hicon, width, height, 0, 0, DI_NORMAL); +#else + ::DrawIcon(hdc, 0, 0, hicon); +#endif + + ::SelectObject(hdc, hbmpOld); + ::DeleteDC(hdc); + + m_refData = new wxBitmapRefData; + M_BITMAPDATA->m_width = width; + M_BITMAPDATA->m_height = height; + M_BITMAPDATA->m_depth = wxDisplayDepth(); + M_BITMAPDATA->m_numColors = 0; + + M_BITMAPDATA->m_hBitmap = (WXHBITMAP)hbitmap; + M_BITMAPDATA->m_ok = TRUE; +} + +wxBitmap::wxBitmap(const wxBitmap& bitmap) +{ + Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index 78606eee75..c15c16e0d1 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -314,7 +314,10 @@ void wxCheckListBox::InsertItems(int nItems, const wxString items[], int pos) for ( i = 0; i < nItems; i++ ) { wxOwnerDrawn *pNewItem = CreateItem((size_t)(pos + i)); pNewItem->SetName(items[i]); + pNewItem->SetFont(GetFont()); + m_aItems.Insert(pNewItem, (size_t)(pos + i)); + ListBox_SetItemData((HWND)GetHWND(), i + pos, pNewItem); } } @@ -323,9 +326,11 @@ void wxCheckListBox::InsertItems(int nItems, const wxString items[], int pos) bool wxCheckListBox::SetFont( const wxFont &font ) { size_t i; - for (i=0; i < m_aItems.GetCount(); i++) + for ( i = 0; i < m_aItems.GetCount(); i++ ) m_aItems[i]->SetFont(font); + wxListBox::SetFont(font); + return TRUE; } diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 33c95ced7f..bd43058f11 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -200,8 +200,6 @@ bool wxFont::RealizeResource() { // VZ: the old code returned FALSE in this case, but it doesn't seem // to make sense because the font _was_ created - wxLogDebug(wxT("Calling wxFont::RealizeResource() twice")); - return TRUE; } diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 2168734e01..6e786a20fc 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -256,15 +256,15 @@ void wxListBox::Delete(int N) wxCHECK_RET( N >= 0 && N < m_noItems, wxT("invalid index in wxListBox::Delete") ); -#if wxUSE_OWNER_DRAWN - delete m_aItems[N]; - m_aItems.Remove(N); -#else // !wxUSE_OWNER_DRAWN - if ( HasClientObjectData() ) - { - delete GetClientObject(N); - } -#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN + // for owner drawn objects, the data is used for storing wxOwnerDrawn + // pointers and we shouldn't touch it +#if !wxUSE_OWNER_DRAWN + if ( !(m_windowStyle & wxLB_OWNERDRAW) ) +#endif // !wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + delete GetClientObject(N); + } SendMessage(GetHwnd(), LB_DELETESTRING, N, 0); m_noItems--; @@ -747,13 +747,19 @@ bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item) MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item; + HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0); + wxDC dc; - dc.SetHDC((WXHDC)CreateIC(wxT("DISPLAY"), NULL, NULL, 0)); + dc.SetHDC((WXHDC)hdc); dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_ANSI_VAR_FONT)); pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE; pStruct->itemWidth = dc.GetCharWidth(); + dc.SetHDC(0); + + DeleteDC(hdc); + return TRUE; } diff --git a/src/msw/ownerdrw.cpp b/src/msw/ownerdrw.cpp index 96298bf72e..f8c26c035e 100644 --- a/src/msw/ownerdrw.cpp +++ b/src/msw/ownerdrw.cpp @@ -140,12 +140,14 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODSt // using native API because it reckognizes '&' #ifdef O_DRAW_NATIVE_API int nPrevMode = SetBkMode(hdc, TRANSPARENT); - HBRUSH hbr = CreateSolidBrush(colBack), - hPrevBrush = (HBRUSH) SelectObject(hdc, hbr); + HBRUSH hbr = CreateSolidBrush(colBack), + hPrevBrush = (HBRUSH)SelectObject(hdc, hbr); RECT rectAll = { rc.GetLeft(), rc.GetTop(), rc.GetRight(), rc.GetBottom() }; FillRect(hdc, &rectAll, hbr); + DeleteObject(hbr); + // use default font if no font set HFONT hfont; if ( m_font.Ok() ) { @@ -186,14 +188,19 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODSt // then draw a check mark into it RECT rect = { 0, 0, GetMarginWidth(), m_nHeight }; + if ( m_nHeight > 0 ) + { #ifndef __SC__ - DrawFrameControl(hdcMem, &rect, DFC_MENU, DFCS_MENUCHECK); + DrawFrameControl(hdcMem, &rect, DFC_MENU, DFCS_MENUCHECK); #endif + } // finally copy it to screen DC and clean up BitBlt(hdc, rc.x, rc.y, GetMarginWidth(), m_nHeight, hdcMem, 0, 0, SRCCOPY); + DeleteDC(hdcMem); + DeleteObject(hbmpCheck); #else // #### to do: perhaps using Marlett font (create equiv. font under X) // wxFAIL("not implemented"); diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 2c150f4866..1e70d4c60e 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -114,47 +114,16 @@ WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, ::SetBkColor(hdc, wxColourToRGB(colBack)); ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); - wxBrush *brush= wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID); + wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID); return (WXHBRUSH)brush->GetResourceHandle(); } -// VZ: this is probably the most commented function in wxWindows, but I still -// don't understand what it does and why. Wouldn't it be better to _never_ -// erase the background here? What would we lose if we didn't do it? -// (FIXME) - -// Shouldn't erase the whole window, since the static box must only paint its -// outline. void wxStaticBox::OnEraseBackground(wxEraseEvent& event) { - // If we don't have this (call Default()), we don't paint the background properly. - // If we do have this, we seem to overwrite enclosed controls. - // Is it the WS_CLIPCHILDREN style that's causing the problems? - // Probably - without this style, the background of the window will show through, - // so the control doesn't have to paint it. The window background will always be - // painted before all other controls, therefore there are no problems with - // controls being hidden by the static box. - // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better. - // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel. - // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass - // this information from arbitrary wxWindow derivatives, and it depends on what you wish to - // do with the windows. - // Alternatively, just make sure that wxStaticBox is always at the back! There are probably - // few other circumstances where it matters about child clipping. But what about painting onto - // to panel, inside a groupbox? Doesn't appear, because the box wipes it out. - wxWindow *parent = GetParent(); - if ( parent && parent->GetHWND() && - (::GetWindowLong(GetHwndOf(parent), GWL_STYLE) & WS_CLIPCHILDREN) ) - { - // TODO: May in fact need to generate a paint event for inside this - // control's rectangle, otherwise all controls are going to be clipped - - // ugh. - - // let wxControl::OnEraseBackground() do the job - event.Skip(); - } - //else: do *not* call event.Skip() or wxControl will erase the background + // do nothing - the aim of having this function is to prevent + // wxControl::OnEraseBackground() to paint over the control inside the + // static box } long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 2e6d785284..fc7e926e8c 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -296,9 +296,12 @@ void wxTextCtrl::SetValue(const wxString& value) { wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos); - SetWindowText(GetHwnd(), valueDos); + if ( valueDos != GetValue() ) + { + SetWindowText(GetHwnd(), valueDos); - AdjustSpaceLimit(); + AdjustSpaceLimit(); + } } void wxTextCtrl::WriteText(const wxString& value) -- 2.47.2