Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize toolbar on OSX #23614

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
567b632
Implement toolbar customization on OSX - initial commit
oneeyeman1 May 28, 2023
10c87b1
Add parameter to differentiate between visible and available items
oneeyeman1 May 28, 2023
89a8a7f
Implement delegate methods for the toobar customization panel
oneeyeman1 May 29, 2023
779f9c1
Adding control to implementation
oneeyeman1 May 31, 2023
e0060ae
Fix compilation error
oneeyeman1 Jun 1, 2023
57f5df6
Realize does not add anything to the toolbar, so no need to add tools…
oneeyeman1 Jun 1, 2023
a632e68
Merge remote-tracking branch 'upstream/master' into CustomizeToolbar
oneeyeman1 Jun 4, 2023
4fcc972
Fixing GTK implementation and starting implementing the signal
oneeyeman1 Jun 5, 2023
abfab1d
Fix MSW compilation
oneeyeman1 Jun 5, 2023
8be1d3a
Fix trailing whitespaces
oneeyeman1 Jun 5, 2023
92728d8
Fix spelling
oneeyeman1 Jun 5, 2023
ce48129
Fix compilation under OSX
oneeyeman1 Jun 6, 2023
35392ef
Trying to fix iPhone build
oneeyeman1 Jun 6, 2023
029c0c1
Fix documentation
oneeyeman1 Jun 6, 2023
9dc456b
Update toolbar.cpp
oneeyeman1 Jun 6, 2023
24cb97c
Update toolbar.cpp
oneeyeman1 Jun 6, 2023
f18e6b9
Update toolbar.cpp
oneeyeman1 Jun 6, 2023
7543be5
Update buttonbar.cpp
oneeyeman1 Jun 6, 2023
73f1a88
Update toolbar.h
oneeyeman1 Jun 6, 2023
489a21d
Update toolbar.cpp
oneeyeman1 Jun 6, 2023
6e0f893
Update toolbar.cpp
oneeyeman1 Jun 6, 2023
37f9368
Update the documentation and trying to implement the PR suggestion
oneeyeman1 Jun 9, 2023
9883ce5
Merge remote-tracking branch 'upstream/master' into CustomizeToolbar
oneeyeman1 Jun 14, 2023
1a4de0b
Implement PR suggestion
oneeyeman1 Jun 14, 2023
76c1d5d
Fix code checks (white spaces)
oneeyeman1 Jun 14, 2023
f83da65
Revert to the old code
oneeyeman1 Jun 14, 2023
8980a62
Revert changes for UNIVERSAL build
oneeyeman1 Jun 14, 2023
9d7a875
Fix whitespaces
oneeyeman1 Jun 14, 2023
250879e
Reimplement the feature according to PR suggestions
oneeyeman1 Jun 21, 2023
a49443d
Implement customization toolbar on OSX for the regular button
oneeyeman1 Jul 1, 2023
57dd140
Updating the documentation
oneeyeman1 Jul 1, 2023
7606d55
Fix the whitespaces
oneeyeman1 Jul 1, 2023
fe732c7
Fix compilation error
oneeyeman1 Jul 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/wx/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class WXDLLIMPEXP_CORE wxControlBase : public wxWindow

// get the control alignment (left/right/centre, top/bottom/centre)
int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }

void MarkAvailable(bool available) { m_available = available; }
bool IsAvailable() const { return m_available; }
Comment on lines +49 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to add functions that only make sense for toolbar tools to base wxControl class. You will have to change the code to use them in wxToolBatTool only.

// set label with mnemonics
virtual void SetLabel(const wxString& label) override
{
Expand Down Expand Up @@ -193,7 +194,7 @@ class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
// this field contains the label in wx format, i.e. with '&' mnemonics,
// as it was passed to the last SetLabel() call
wxString m_labelOrig;

bool m_available;
wxDECLARE_NO_COPY_CLASS(wxControlBase);
};

Expand Down
2 changes: 2 additions & 0 deletions include/wx/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_RCLICKED, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_DROPDOWN, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOL_ENTER, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TB_CUSTOMIZE, wxCommandEvent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just TB is really not clear enough without any context.

Suggested change
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TB_CUSTOMIZE, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TOOLBAR_CUSTOMIZE, wxCommandEvent);

wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX_DROPDOWN, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMBOBOX_CLOSEUP, wxCommandEvent);

Expand Down Expand Up @@ -4682,6 +4683,7 @@ typedef void (wxEvtHandler::*wxFullScreenEventFunction)(wxFullScreenEvent&);
#define EVT_TOOL_RCLICKED(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_RCLICKED, winid, wxCommandEventHandler(func))
#define EVT_TOOL_RCLICKED_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_TOOL_RCLICKED, id1, id2, wxCommandEventHandler(func))
#define EVT_TOOL_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_TOOL_ENTER, winid, wxCommandEventHandler(func))
#define EVT_TB_CUSTOMIZE(func) wx__DECLARE_EVT1(wxEVT_TB_CUSTOMIZE, wxCommandEventHandler(func))
#define EVT_CHECKLISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_CHECKLISTBOX, winid, wxCommandEventHandler(func))
#define EVT_COMBOBOX_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX_DROPDOWN, winid, wxCommandEventHandler(func))
#define EVT_COMBOBOX_CLOSEUP(winid, func) wx__DECLARE_EVT1(wxEVT_COMBOBOX_CLOSEUP, winid, wxCommandEventHandler(func))
Expand Down
2 changes: 2 additions & 0 deletions include/wx/osx/toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ class WXDLLIMPEXP_CORE wxToolBar: public wxToolBarBase
wxObject *clientData = nullptr,
const wxString& shortHelp = wxEmptyString,
const wxString& longHelp = wxEmptyString) override;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to avoid whitespace-only changes (even if you make them accidentally, nothing prevents you from looking at the diff and removing them afterwards).

virtual wxToolBarToolBase *CreateTool(wxControl *control,
const wxString& label) override;

void *GetMacToolbar() { return m_macToolbar; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prevailing convention is to use OSX prefix, i.e.

Suggested change
void *GetMacToolbar() { return m_macToolbar; };
void *OSXGetToolbar() { return m_macToolbar; };

protected:
// common part of all ctors
void Init();
Expand Down
11 changes: 8 additions & 3 deletions include/wx/tbarbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject
const wxString& longHelpString = wxEmptyString)
: m_label(label),
m_shortHelpString(shortHelpString),
m_longHelpString(longHelpString)
m_longHelpString(longHelpString),
m_available(true)
{
Init
(
Expand All @@ -94,7 +95,8 @@ class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject
wxToolBarToolBase(wxToolBarBase *tbar,
wxControl *control,
const wxString& label)
: m_label(label)
: m_label(label),
m_available(true)
{
Init(tbar, wxTOOL_STYLE_CONTROL, control->GetId(), wxITEM_MAX);

Expand Down Expand Up @@ -144,6 +146,8 @@ class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject
bool IsToggled() const { return m_toggled; }
bool CanBeToggled() const
{ return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
bool IsAvailable() const { return m_available; }
virtual void MarkAvailable(bool available) { m_available = available; }

// attributes
wxBitmapBundle GetNormalBitmapBundle() const { return m_bmpNormal; }
Expand Down Expand Up @@ -266,6 +270,7 @@ class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject
// short and long help strings
wxString m_shortHelpString;
wxString m_longHelpString;
bool m_available;

#if wxUSE_MENUS
wxMenu *m_dropdownMenu;
Expand Down Expand Up @@ -314,7 +319,7 @@ class WXDLLIMPEXP_CORE wxToolBarBase : public wxControl
const wxString& shortHelp = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL)
{
return AddTool(toolid, label, bitmap, wxBitmapBundle(), kind, shortHelp);
return AddTool(toolid, label, bitmap, wxBitmapBundle(), kind, shortHelp, wxEmptyString, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

}

// add a check tool, i.e. a tool which can be toggled
Expand Down
41 changes: 41 additions & 0 deletions interface/wx/toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ class wxToolBarToolBase : public wxObject

void SetDropdownMenu(wxMenu *menu);
wxMenu *GetDropdownMenu() const;

/**
Mark the tool to be not visible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty misleading for a function called like this. You should say it may be used to mark the tool as being not currently visible if @c available is @false or something like that.


By default all tools and controls in the toolbar are visible.
If you want, you can mark the tool/control not visible by default
When you do that user will be able to go to the customization
dialog and add the tool/control at a later time.
When you want that you pass "false" to this function.

@since 3.3.0
*/
void MarkAvailable(bool available);
};


Expand Down Expand Up @@ -271,6 +284,15 @@ class wxToolBarToolBase : public wxObject
Process a @c wxEVT_TOOL_DROPDOWN event. If unhandled,
displays the default dropdown menu set using
wxToolBar::SetDropdownMenu().
@event{EVT_TB_CUSTOMIZE(id)}
Process a @c wxEVT_TB_CUSTOMIZE event. Under MSW and OSX
it will display native customization dialogs. On GTK it will
be generic.
Comment on lines +288 to +290
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be true, there is no implementation at all for MSW and just a stub for GTK. This is not necessarily a problem, but the documentation shouldn't like and you should check that the API you propose is at least in principle implementable under the other platforms.

In order for this event to happen you need to double click the
toolbar on MSW and right click + context menu selection on OSX/GTK
By default all added tools are displayed.

This event is implemented @since 3.3.0
@endEventTable

The toolbar class emits menu commands in the same way that a frame menubar
Expand Down Expand Up @@ -878,6 +900,25 @@ class wxToolBar : public wxControl
@see GetMargins(), wxSize
*/
void SetMargins(const wxSize& size);

/**
Return whether the tool is displayed by default or not
By default all tools are displayed.

@since 3.3
*/
bool IsAvailable() const;

/**
Calling this function with the parameter set to false will not add the tool to the toolbar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Calling this function with the parameter set to false will not add the tool to the toolbar
Calling this function with the parameter set to false prevents the tool from being added to the toolbar.

by default.

@param available
Whether add the tool by default to the toolbar or not.

@since 3.3
*/
void MarkAvailable(bool available);
///@}

/**
Expand Down
5 changes: 4 additions & 1 deletion samples/toolbar/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
combo->Append("combobox with extremely, extremely, extremely, extremely long label");
combo->Append("in a");
combo->Append("toolbar");
combo->MarkAvailable( false );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create another initially unavailable control instead of hiding this one.

toolBar->AddControl(combo, "Combo Label");
}
#endif // USE_CONTROLS_IN_TOOLBAR
Expand Down Expand Up @@ -511,7 +512,9 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
toolBar->AddStretchableSpace();
toolBar->AddTool(wxID_HELP, "Help", toolBarBitmaps[Tool_help], "Help button", wxITEM_CHECK);

toolBar->AddTool(wxID_ABOUT, "About", toolBarBitmaps[Tool_about], "About");
wxToolBarToolBase *tool = new wxToolBarToolBase( toolBar, wxID_ABOUT, "About", toolBarBitmaps[Tool_about], toolBarBitmaps[Tool_about] );
tool->MarkAvailable( false );
toolBar->AddTool( tool );

if ( !m_pathBmp.empty() )
{
Expand Down
1 change: 1 addition & 0 deletions src/common/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ wxDEFINE_EVENT( wxEVT_COMBOBOX, wxCommandEvent );
wxDEFINE_EVENT( wxEVT_TOOL_RCLICKED, wxCommandEvent );
wxDEFINE_EVENT( wxEVT_TOOL_ENTER, wxCommandEvent );
wxDEFINE_EVENT( wxEVT_TOOL_DROPDOWN, wxCommandEvent );
wxDEFINE_EVENT( wxEVT_TB_CUSTOMIZE, wxCommandEvent);
wxDEFINE_EVENT( wxEVT_COMBOBOX_DROPDOWN, wxCommandEvent);
wxDEFINE_EVENT( wxEVT_COMBOBOX_CLOSEUP, wxCommandEvent);

Expand Down
9 changes: 6 additions & 3 deletions src/common/tbarbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,12 @@ void wxToolBarBase::AdjustToolBitmapSize()
i != m_tools.end();
++i )
{
const wxBitmapBundle& bmp = (*i)->GetNormalBitmapBundle();
if ( bmp.IsOk() )
bundles.push_back(bmp);
if( (*i)->IsAvailable() )
{
const wxBitmapBundle& bmp = (*i)->GetNormalBitmapBundle();
if ( bmp.IsOk() )
bundles.push_back(bmp);
}
}

if ( bundles.empty() )
Expand Down
9 changes: 9 additions & 0 deletions src/gtk/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ static void arrow_toggled(GtkToggleButton* button, wxToolBarTool* tool)
}
}

extern "C"
{
static gboolean context_menu(GtkToolbar *WXUNUSED(self), gint WXUNUSED(x), gint WXUNUSED(y), gint WXUNUSED(button), gpointer WXUNUSED(user_data))
{
return TRUE;
}
}

//-----------------------------------------------------------------------------
// "button_press_event" from dropdown menu button
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -462,6 +470,7 @@ bool wxToolBar::Create( wxWindow *parent,
wxGCC_WARNING_RESTORE()
#endif // !__WXGTK4__
g_object_ref(m_widget);
g_signal_connect( m_toolbar, "popup-context-menu", G_CALLBACK( context_menu ), nullptr );
gtk_widget_show(GTK_WIDGET(m_toolbar));

m_parent->DoAddChild( this );
Expand Down
2 changes: 1 addition & 1 deletion src/osx/carbon/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool wxControl::Create( wxWindow *parent,
if (rval)
SetValidator( validator );
#endif

m_available = true;
return rval;
}

Expand Down