Add support for client data to wxAuiToolBar
Store data passed to AddTool() in wxAuiToolBarItem and provide wxToolBar-like functions for setting and getting this pointer. See #23276. Closes #23271.
This commit is contained in:
parent
996f1f5415
commit
9f55d568c2
3 changed files with 87 additions and 4 deletions
|
|
@ -121,6 +121,7 @@ public:
|
|||
m_dropDown = true;
|
||||
m_sticky = true;
|
||||
m_userData = 0;
|
||||
m_clientData = nullptr;
|
||||
m_alignment = wxALIGN_CENTER;
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +145,7 @@ public:
|
|||
m_dropDown = c.m_dropDown;
|
||||
m_sticky = c.m_sticky;
|
||||
m_userData = c.m_userData;
|
||||
m_clientData = c.m_clientData;
|
||||
m_alignment = c.m_alignment;
|
||||
}
|
||||
|
||||
|
|
@ -217,6 +219,9 @@ public:
|
|||
void SetUserData(long l) { m_userData = l; }
|
||||
long GetUserData() const { return m_userData; }
|
||||
|
||||
void SetClientData(wxObject* l) { m_clientData = l; }
|
||||
wxObject* GetClientData() const { return m_clientData; }
|
||||
|
||||
void SetAlignment(int l) { m_alignment = l; }
|
||||
int GetAlignment() const { return m_alignment; }
|
||||
|
||||
|
|
@ -244,7 +249,8 @@ private:
|
|||
bool m_active; // true if the item is currently active
|
||||
bool m_dropDown; // true if the item has a dropdown button
|
||||
bool m_sticky; // overrides button states if true (always active)
|
||||
long m_userData; // user-specified data
|
||||
long m_userData; // number associated with the item
|
||||
wxObject* m_clientData; // pointer to a wxObject associated with the item
|
||||
int m_alignment; // sizer alignment flag, defaults to wxCENTER, may be wxEXPAND or any other
|
||||
};
|
||||
|
||||
|
|
@ -560,6 +566,9 @@ public:
|
|||
void SetMargins(int x, int y) { SetMargins(x, x, y, y); }
|
||||
void SetMargins(int left, int right, int top, int bottom);
|
||||
|
||||
void SetToolClientData (int tool_id, wxObject* client_data);
|
||||
wxObject* GetToolClientData(int tool_id) const;
|
||||
|
||||
void SetToolBitmapSize(const wxSize& size);
|
||||
wxSize GetToolBitmapSize() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -398,14 +398,45 @@ public:
|
|||
bool IsSticky() const;
|
||||
|
||||
/**
|
||||
Associates a number with the item.
|
||||
|
||||
@param userData Number to associate
|
||||
|
||||
@see GetUserData()
|
||||
*/
|
||||
void SetUserData(long l);
|
||||
/**
|
||||
void SetUserData(long userData);
|
||||
|
||||
/**
|
||||
Get number associated with the item.
|
||||
|
||||
@return Associated number
|
||||
|
||||
@see SetUserData()
|
||||
*/
|
||||
long GetUserData() const;
|
||||
|
||||
/**
|
||||
Associates a wxObject with the item.
|
||||
|
||||
@param clientData Pointer to the wxObject
|
||||
|
||||
@see GetClientData()
|
||||
|
||||
@since 3.3.0
|
||||
*/
|
||||
void SetClientData(wxObject* clientData);
|
||||
|
||||
/**
|
||||
Get wxObject associated with the item.
|
||||
|
||||
@return Pointer to the associated wxObject
|
||||
|
||||
@see SetClientData()
|
||||
|
||||
@since 3.3.0
|
||||
*/
|
||||
wxObject* GetClientData() const;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
|
|
@ -816,6 +847,30 @@ public:
|
|||
void SetMargins(int x, int y);
|
||||
void SetMargins(int left, int right, int top, int bottom);
|
||||
|
||||
/**
|
||||
Associates a wxObject with the item identified by id.
|
||||
|
||||
@param toolId Identifier of the desired item
|
||||
@param clientData Pointer to the wxObject
|
||||
|
||||
@see GetToolClientData()
|
||||
|
||||
@since 3.3.0
|
||||
*/
|
||||
void SetToolClientData(int toolId, wxObject* clientData);
|
||||
|
||||
/**
|
||||
Get wxObject associated with the item identified by id.
|
||||
|
||||
@param toolId Identifier of the desired item
|
||||
@return Pointer to the associated wxObject
|
||||
|
||||
@see SetToolClientData()
|
||||
|
||||
@since 3.3.0
|
||||
*/
|
||||
wxObject* GetToolClientData(int toolId) const;
|
||||
|
||||
void SetToolBitmapSize(const wxSize& size);
|
||||
wxSize GetToolBitmapSize() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -985,7 +985,7 @@ wxAuiToolBarItem* wxAuiToolBar::AddTool(int tool_id,
|
|||
wxItemKind kind,
|
||||
const wxString& shortHelpString,
|
||||
const wxString& longHelpString,
|
||||
wxObject* WXUNUSED(client_data))
|
||||
wxObject* client_data)
|
||||
{
|
||||
wxAuiToolBarItem item;
|
||||
item.m_window = nullptr;
|
||||
|
|
@ -1004,6 +1004,7 @@ wxAuiToolBarItem* wxAuiToolBar::AddTool(int tool_id,
|
|||
item.m_sizerItem = nullptr;
|
||||
item.m_minSize = wxDefaultSize;
|
||||
item.m_userData = 0;
|
||||
item.m_clientData = client_data;
|
||||
item.m_sticky = false;
|
||||
|
||||
if (item.m_toolId == wxID_ANY)
|
||||
|
|
@ -1260,6 +1261,24 @@ wxAuiToolBarItem* wxAuiToolBar::FindToolByIndex(int idx) const
|
|||
return &(m_items[idx]);
|
||||
}
|
||||
|
||||
void wxAuiToolBar::SetToolClientData (int tool_id, wxObject *client_data)
|
||||
{
|
||||
wxAuiToolBarItem* item = FindTool(tool_id);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
item->m_clientData = client_data;
|
||||
}
|
||||
|
||||
wxObject* wxAuiToolBar::GetToolClientData(int tool_id) const
|
||||
{
|
||||
wxAuiToolBarItem* item = FindTool(tool_id);
|
||||
if (!item)
|
||||
return nullptr;
|
||||
|
||||
return item->m_clientData;
|
||||
}
|
||||
|
||||
void wxAuiToolBar::SetToolBitmapSize(const wxSize& WXUNUSED(size))
|
||||
{
|
||||
// TODO: wxToolBar compatibility
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue