]> git.saurik.com Git - wxWidgets.git/commitdiff
1. undid my wrong fix to wxWindowBase::Centre
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 13 Nov 1999 00:30:45 +0000 (00:30 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 13 Nov 1999 00:30:45 +0000 (00:30 +0000)
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
src/common/timercmn.cpp
src/common/wincmn.cpp
src/msw/bitmap.cpp
src/msw/checklst.cpp
src/msw/font.cpp
src/msw/listbox.cpp
src/msw/ownerdrw.cpp
src/msw/statbox.cpp
src/msw/textctrl.cpp

index 4fb10e6877089b84018070dc4dcc5b98284a7f27..5d2d28686f9fceaf68146ca2a7d282835abca797 100644 (file)
@@ -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);
index e2ac6496aed56eb739a7fac24e67936b1a04896f..63a4eced88cb84e9afd39bf8500b6442cc99b452 100644 (file)
     // 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 <winbase.h>
+#endif
+
 #if defined(HAVE_GETTIMEOFDAY)
     #include <sys/time.h>
     #include <unistd.h>
@@ -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;
 }
index 9cad968ed4eb27107557a43ecd39cd2f097ce6d2..18e1821bfc1ae89d2c64a2f2a48d245c432d5cda 100644 (file)
@@ -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
index 9498c65e43f4877c6138649e9472cc060aec96d0..24811e80a3e60b328bff5ef8064383e0dab32358 100644 (file)
@@ -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);
index 78606eee757a97d96df8c7b84584571ef50b3d2e..c15c16e0d17de9083a4029dca2908451bccb257f 100644 (file)
@@ -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;
 }
 
index 33c95ced7f38b1eb5d59a0c3aaec4576158f51de..bd43058f114661992ba83c1eed453e1226ce7560 100644 (file)
@@ -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;
     }
 
index 2168734e0123f4fc4639fa5a378f30a48444cd18..6e786a20fca96040b3a945dd3a5ca89ed62f9d20 100644 (file)
@@ -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;
 }
 
index 96298bf72e574f527c55042c986bfeb1ed9e07db..f8c26c035ede2b8afea7e4601808a14d64d9cb0a 100644 (file)
@@ -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");
index 2c150f48667a2c5e234d18b4758a461a40fe257f..1e70d4c60ed89f4501342c4b8550dd35caf8047b 100644 (file)
@@ -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)
index 2e6d7852841b9cf81880c882bfb96106c5d7505e..fc7e926e8c4bd7f6203dee2d747972302ef729ec 100644 (file)
@@ -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)