]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/tbar95.cpp
Added wxDragLink
[wxWidgets.git] / src / msw / tbar95.cpp
index 46ab1c4fe25744aae16976962088527fd54fa044..afa81726ae1e6f8346105be550dcb6e4f442c67f 100644 (file)
 #include "wx/msw/dib.h"
 #include "wx/app.h"         // for GetComCtl32Version
 
+#if defined(__MWERKS__) && defined(__WXMSW__)
+// including <windef.h> for max definition doesn't seem
+// to work using CodeWarrior 6 Windows. So we define it
+// here. (Otherwise we get a undefined identifier 'max'
+// later on in this file.) (Added by dimitri@shortcut.nl)
+#   ifndef max
+#       define max(a,b)            (((a) > (b)) ? (a) : (b))
+#   endif
+
+#endif
+
 // ----------------------------------------------------------------------------
 // conditional compilation
 // ----------------------------------------------------------------------------
@@ -196,6 +207,8 @@ void wxToolBar::Init()
 
     m_defaultWidth = DEFAULTBITMAPX;
     m_defaultHeight = DEFAULTBITMAPY;
+
+    m_pInTool = 0;
 }
 
 bool wxToolBar::Create(wxWindow *parent,
@@ -264,11 +277,8 @@ wxToolBar::~wxToolBar()
 {
     // we must refresh the frame size when the toolbar is deleted but the frame
     // is not - otherwise toolbar leaves a hole in the place it used to occupy
-    //
-    // NB: a frame is being deleted only if it is not any longer in
-    //     wxTopLevelWindows list
     wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
-    if ( frame && wxTopLevelWindows.Find(frame) )
+    if ( frame && !frame->IsBeingDeleted() )
     {
         frame->SendSizeEvent();
     }
@@ -869,20 +879,24 @@ wxSize wxToolBar::GetToolSize() const
     }
 }
 
-static wxToolBarToolBase *GetItemSkippingDummySpacers( const wxToolBarToolsList& tools, size_t index )
+static
+wxToolBarToolBase *GetItemSkippingDummySpacers(const wxToolBarToolsList& tools,
+                                               size_t index )
 {
     wxToolBarToolsList::Node* current = tools.GetFirst();
 
-    for( ; current != 0; current = current->GetNext() )
+    for ( ; current != 0; current = current->GetNext() )
     {
-        if( index == 0 )
+        if ( index == 0 )
             return current->GetData();
-        size_t separators = ((wxToolBarTool*)current->GetData())->GetSeparatorsCount();
-        // if it is a normal button, sepcount == 0, so skip 1
-        // item ( the button )
-        // otherwise, skip as many items as the separator count,
-        // plus the control itself
-        index -= separators ? separators + 1: 1;
+
+        wxToolBarTool *tool = (wxToolBarTool *)current->GetData();
+        size_t separators = tool->GetSeparatorsCount();
+
+        // if it is a normal button, sepcount == 0, so skip 1 item (the button)
+        // otherwise, skip as many items as the separator count, plus the
+        // control itself
+        index -= separators ? separators + 1 : 1;
     }
 
     return 0;
@@ -894,26 +908,25 @@ wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
     pt.x = x;
     pt.y = y;
     int index = (int)::SendMessage(GetHwnd(), TB_HITTEST, 0, (LPARAM)&pt);
-    if ( index < 0 )
+    // MBN: when the point ( x, y ) is close to the toolbar border
+    //      TB_HITTEST returns m_nButtons ( not -1 )
+    if ( index < 0 || (size_t)index >= m_nButtons )
     {
         // it's a separator or there is no tool at all there
         return (wxToolBarToolBase *)NULL;
     }
 
-    // if comctl32 version < 4.71
-    // wxToolBar95 adds dummy spacers
+    // if comctl32 version < 4.71 wxToolBar95 adds dummy spacers
 #if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
     if ( wxTheApp->GetComCtl32Version() >= 471 )
     {
         return m_tools.Item((size_t)index)->GetData();
     }
     else
+#endif
     {
         return GetItemSkippingDummySpacers( m_tools, (size_t) index );
     }
-#else
-    return GetItemSkippingDummySpacers( m_tools, (size_t) index );
-#endif
 }
 
 void wxToolBar::UpdateSize()