Added a helper DoInsertNewTool() function to avoid code duplication and ensure
that we never forget to delete a new tool if inserting it into the toolbar
failed.
Also explicitly document that the tool passed to the public InsertTool() is
not owned by the toolbar and so must be deleted by the caller if its insertion
failed.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62846
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// make the size of the buttons big enough to fit the largest bitmap size
void AdjustToolBitmapSize();
// make the size of the buttons big enough to fit the largest bitmap size
void AdjustToolBitmapSize();
+ // calls InsertTool() and deletes the tool if inserting it failed
+ wxToolBarToolBase *DoInsertNewTool(size_t pos, wxToolBarToolBase *tool)
+ {
+ if ( !InsertTool(pos, tool) )
+ {
+ delete tool;
+ return NULL;
+ }
+
+ return tool;
+ }
// the list of all our tools
wxToolBarToolsList m_tools;
// the list of all our tools
wxToolBarToolsList m_tools;
You must call Realize() for the change to take place.
@see AddTool(), InsertControl(), InsertSeparator()
You must call Realize() for the change to take place.
@see AddTool(), InsertControl(), InsertSeparator()
+
+ @return The newly inserted tool or @NULL on failure. Notice that with
+ the overload taking @a tool parameter the caller is responsible for
+ deleting the tool in the latter case.
*/
wxToolBarToolBase* InsertTool(size_t pos, int toolId,
const wxBitmap& bitmap1,
*/
wxToolBarToolBase* InsertTool(size_t pos, int toolId,
const wxBitmap& bitmap1,
wxCHECK_MSG( pos <= GetToolsCount(), NULL,
wxT("invalid position in wxToolBar::InsertTool()") );
wxCHECK_MSG( pos <= GetToolsCount(), NULL,
wxT("invalid position in wxToolBar::InsertTool()") );
- wxToolBarToolBase *tool = CreateTool(id, label, bitmap, bmpDisabled, kind,
- clientData, shortHelp, longHelp);
-
- if ( !InsertTool(pos, tool) )
- {
- delete tool;
-
- return NULL;
- }
-
- return tool;
+ return DoInsertNewTool(pos, CreateTool(id, label, bitmap, bmpDisabled, kind,
+ clientData, shortHelp, longHelp));
}
wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool)
}
wxToolBarToolBase *wxToolBarBase::AddTool(wxToolBarToolBase *tool)
wxCHECK_MSG( control->GetParent() == this, NULL,
wxT("control must have toolbar as parent") );
wxCHECK_MSG( control->GetParent() == this, NULL,
wxT("control must have toolbar as parent") );
- wxCHECK_MSG( pos <= GetToolsCount(), NULL,
- wxT("invalid position in wxToolBar::InsertControl()") );
-
- wxToolBarToolBase *tool = CreateTool(control, label);
-
- if ( !InsertTool(pos, tool) )
- {
- delete tool;
-
- return NULL;
- }
-
- return tool;
+ return DoInsertNewTool(pos, CreateTool(control, label));
}
wxControl *wxToolBarBase::FindControl( int id )
}
wxControl *wxToolBarBase::FindControl( int id )
wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos)
{
wxToolBarToolBase *wxToolBarBase::InsertSeparator(size_t pos)
{
- wxCHECK_MSG( pos <= GetToolsCount(), NULL,
- wxT("invalid position in wxToolBar::InsertSeparator()") );
-
- wxToolBarToolBase *tool = CreateTool(wxID_SEPARATOR,
- wxEmptyString,
- wxNullBitmap, wxNullBitmap,
- wxITEM_SEPARATOR, NULL,
- wxEmptyString, wxEmptyString);
-
- if ( !tool || !DoInsertTool(pos, tool) )
- {
- delete tool;
-
- return NULL;
- }
-
- m_tools.Insert(pos, tool);
-
- return tool;
+ return DoInsertNewTool(pos, CreateTool(wxID_SEPARATOR,
+ wxEmptyString,
+ wxNullBitmap, wxNullBitmap,
+ wxITEM_SEPARATOR, NULL,
+ wxEmptyString, wxEmptyString));
}
wxToolBarToolBase *wxToolBarBase::RemoveTool(int id)
}
wxToolBarToolBase *wxToolBarBase::RemoveTool(int id)