All pastes #149242 Raw Edit

wx spacing

public text v1 · immutable
#149242 ·published 2006-08-25 17:11 UTC
rendered paste body
Index: src/mac/carbon/textctrl.cpp
===================================================================
--- src/mac/carbon/textctrl.cpp	(revision 83)
+++ src/mac/carbon/textctrl.cpp	(working copy)
@@ -1852,8 +1852,9 @@
             options |=
                 kTXNSupportEditCommandProcessing
                 | kTXNSupportEditCommandUpdating
-                | kTXNSupportSpellCheckCommandProcessing
-                | kTXNSupportSpellCheckCommandUpdating
+            // spell checking crashes text fields in the toolbar
+            //    | kTXNSupportSpellCheckCommandProcessing
+            //    | kTXNSupportSpellCheckCommandUpdating
                 | kTXNSupportFontCommandProcessing
                 | kTXNSupportFontCommandUpdating;
 
Index: src/mac/carbon/toolbar.cpp
===================================================================
--- src/mac/carbon/toolbar.cpp	(revision 83)
+++ src/mac/carbon/toolbar.cpp	(working copy)
@@ -50,6 +50,14 @@
 const short kwxMacToolSpacing = 0;
 #endif
 
+#if wxMAC_USE_NATIVE_TOOLBAR
+// separator types
+enum {
+    kSeparatorNormal        = 0,
+    kSeparatorSpace         = 1,
+    kSeparatorFlexibleSpace = 2
+};
+#endif
 
 IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
 
@@ -109,6 +117,17 @@
         m_controlHandle = handle;
     }
 
+    int GetSeparatorType() const
+    {
+        return m_separatorType;
+    }
+
+    void SetSeparatorType(int inType)
+    {
+        wxASSERT(inType == kSeparatorNormal || inType == kSeparatorSpace || inType == kSeparatorFlexibleSpace);
+        m_separatorType = inType;
+    }
+
     void SetPosition( const wxPoint& position );
 
     void ClearControl()
@@ -122,6 +141,7 @@
 
 #if wxMAC_USE_NATIVE_TOOLBAR
         m_toolbarItemRef = NULL;
+        m_separatorType = 0;
 #endif
     }
 
@@ -177,7 +197,9 @@
             if( controlWindow != NULL )
             {
                 if ( m_controlHandle )
+                {
                     HideControl( m_controlHandle );
+                }
             }
 
             CFRetain( inToolbarItemRef );
@@ -222,6 +244,7 @@
 #if wxMAC_USE_NATIVE_TOOLBAR
         m_toolbarItemRef = NULL;
         m_index = -1;
+        m_separatorType = 0;
 #endif
     }
 
@@ -233,6 +256,9 @@
     HIToolbarItemRef m_toolbarItemRef;
     // position in its toolbar, -1 means not inserted
     CFIndex m_index;
+
+    // to handle separator/space/flexibleSpace
+    int m_separatorType;
 #endif
 };
 
@@ -702,7 +728,6 @@
             {
                 HIToolbarItemRef    item = NULL;
                 CFStringRef         identifier = NULL;
-                CFTypeRef           data = NULL;
                 wxToolBarTool *     tool = NULL;
 
                 // workaround for required NULL inUserData (any non-NULL value causes a crash)
@@ -797,7 +822,6 @@
     OSStatus result = eventNotHandledErr;
     wxToolBarTool *tool = NULL;
     HIObjectRef toolbarItem = NULL;
-    CFTypeRef data = NULL;
 
     switch( GetEventClass( inEvent ))
     {
@@ -1307,7 +1331,7 @@
 #if wxMAC_USE_NATIVE_TOOLBAR
 void *wxToolBar::CreateItemFromDrag( void* inDrag )
 {
-    DragRef drag = (DragRef) inDrag;
+    // DragRef drag = (DragRef) inDrag;
     // returns HIToolbarItemRef
     return NULL;
 }
@@ -1565,6 +1589,20 @@
         m_maxRows = nRows;
 }
 
+wxToolBarToolBase * wxToolBar::InsertSpace(size_t pos)
+{
+    wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, wxToolBarBase::InsertSpace(pos) );
+    tool->SetSeparatorType(kSeparatorSpace);
+    return tool;
+}
+
+wxToolBarToolBase * wxToolBar::InsertFlexibleSpace(size_t pos)
+{
+    wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, wxToolBarBase::InsertFlexibleSpace(pos) );
+    tool->SetSeparatorType(kSeparatorFlexibleSpace);
+    return tool;
+}
+
 void wxToolBar::MacSuperChangedPosition()
 {
     wxWindow::MacSuperChangedPosition();
@@ -1651,11 +1689,22 @@
                 // in flat style we need a visual separator
 #if wxMAC_USE_NATIVE_TOOLBAR
                 HIToolbarItemRef item;
-                err = HIToolbarItemCreate(
-                    kHIToolbarSeparatorIdentifier,
+                CFStringRef identifier = NULL;
+                OptionBits options = kHIToolbarItemNoAttributes;
                     // kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
-                    kHIToolbarItemIsSeparator,
-                    &item );
+                switch(tool->GetSeparatorType()) {
+                    case kSeparatorNormal:
+                        identifier = kHIToolbarSeparatorIdentifier;
+                        options = kHIToolbarItemIsSeparator;
+                    break;
+                    case kSeparatorSpace:
+                        identifier = kHIToolbarSpaceIdentifier;
+                    break;
+                    case kSeparatorFlexibleSpace:
+                        identifier = kHIToolbarFlexibleSpaceIdentifier;
+                    break;
+                }
+                err = HIToolbarItemCreate( identifier, options, &item );
                 if (err == noErr)
                     tool->SetToolbarItemRef( item );
 #endif
@@ -1727,7 +1776,6 @@
 
 #if wxMAC_USE_NATIVE_TOOLBAR
             // disable for now since it causes a crash
-            if( false )
             {
                 HIToolbarItemRef item = NULL;
                 OSErr result = noErr;
Index: src/common/tbarbase.cpp
===================================================================
--- src/common/tbarbase.cpp	(revision 83)
+++ src/common/tbarbase.cpp	(working copy)
@@ -271,6 +271,26 @@
     return tool;
 }
 
+wxToolBarToolBase *wxToolBarBase::AddSpace()
+{
+    return InsertSpace(GetToolsCount());
+}
+
+wxToolBarToolBase *wxToolBarBase::InsertSpace(size_t pos)
+{
+	return InsertSeparator(pos);
+}
+
+wxToolBarToolBase *wxToolBarBase::AddFlexibleSpace()
+{
+    return InsertFlexibleSpace(GetToolsCount());
+}
+
+wxToolBarToolBase *wxToolBarBase::InsertFlexibleSpace(size_t pos)
+{
+	return InsertSeparator(pos);
+}
+
 wxToolBarToolBase *wxToolBarBase::RemoveTool(int id)
 {
     size_t pos = 0;
Index: include/wx/mac/carbon/toolbar.h
===================================================================
--- include/wx/mac/carbon/toolbar.h	(revision 83)
+++ include/wx/mac/carbon/toolbar.h	(working copy)
@@ -57,6 +57,10 @@
 
     virtual void SetRows(int nRows);
 
+    virtual wxToolBarToolBase *InsertSpace(size_t pos);
+
+    virtual wxToolBarToolBase *InsertFlexibleSpace(size_t pos);
+
   // Add all the buttons
 
     virtual wxString MacGetToolTipString( wxPoint &where ) ;
Index: include/wx/tbarbase.h
===================================================================
--- include/wx/tbarbase.h	(revision 83)
+++ include/wx/tbarbase.h	(working copy)
@@ -40,7 +40,7 @@
 {
     wxTOOL_STYLE_BUTTON    = 1,
     wxTOOL_STYLE_SEPARATOR = 2,
-    wxTOOL_STYLE_CONTROL
+    wxTOOL_STYLE_CONTROL   = 3
 };
 
 // ----------------------------------------------------------------------------
@@ -331,6 +331,14 @@
     virtual wxToolBarToolBase *AddSeparator();
     virtual wxToolBarToolBase *InsertSeparator(size_t pos);
 
+    // add a blank area to the toolbar
+    virtual wxToolBarToolBase *AddSpace();
+    virtual wxToolBarToolBase *InsertSpace(size_t pos);
+
+    // add a flexible blank area to the toolbar that fills any unused space
+    virtual wxToolBarToolBase *AddFlexibleSpace();
+    virtual wxToolBarToolBase *InsertFlexibleSpace(size_t pos);
+
     // remove the tool from the toolbar: the caller is responsible for actually
     // deleting the pointer
     virtual wxToolBarToolBase *RemoveTool(int toolid);
Index: wxPython/src/_toolbar.i
===================================================================
--- wxPython/src/_toolbar.i	(revision 83)
+++ wxPython/src/_toolbar.i	(working copy)
@@ -314,6 +314,12 @@
     wxToolBarToolBase *AddSeparator();
     wxToolBarToolBase *InsertSeparator(size_t pos);
 
+    wxToolBarToolBase *AddSpace();
+    wxToolBarToolBase *InsertSpace(size_t pos);
+
+    wxToolBarToolBase *AddFlexibleSpace();
+    wxToolBarToolBase *InsertFlexibleSpace(size_t pos);
+
     wxToolBarToolBase *RemoveTool(int id);
 
     bool DeleteToolByPos(size_t pos);