What about this logic:
void CodeCompletion::UpdateToolBar()
{
ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("code_completion"));
bool showScope = cfg->ReadBool(_T("/scope_filter"), true);
int choice_scope_length = cfg->ReadInt(_T("/toolbar_scope_length"), 286);
int choice_function_length = cfg->ReadInt(_T("/toolbar_function_length"), 660);
if (showScope)
{
if(m_Scope)
m_Scope->SetSize(wxSize(choice_scope_length,-1));
else
{
m_Scope = new wxChoice(m_ToolBar, wxNewId(), wxPoint(0, 0), wxSize(choice_scope_length, -1), 0, 0);
m_ToolBar->InsertControl(0, m_Scope);
}
}
else
{
if(m_Scope)
{
m_ToolBar->DeleteTool(m_Scope->GetId());
m_Scope = NULL;
}
}
m_Function->SetSize(wxSize(choice_function_length,-1));
m_ToolBar->Realize();
m_ToolBar->SetInitialSize();
}