+// Add an item
+bool wxRichTextContextMenuPropertiesInfo::AddItem(const wxString& label, wxRichTextObject* obj)
+{
+ if (GetCount() < 3)
+ {
+ m_labels.Add(label);
+ m_objects.Add(obj);
+ return true;
+ }
+ else
+ return false;
+}
+
+// Returns number of menu items were added.
+int wxRichTextContextMenuPropertiesInfo::AddMenuItems(wxMenu* menu, int startCmd) const
+{
+ wxMenuItem* item = menu->FindItem(startCmd);
+ // If none of the standard properties identifiers are in the menu, assume it's
+ // a custom menu without properties commands, and don't add them.
+ if (item)
+ {
+ // If no items, to add just set the text to something generic
+ if (GetCount() == 0)
+ {
+ menu->SetLabel(startCmd, _("&Properties"));
+
+ // Delete the others if necessary
+ int i;
+ for (i = startCmd+1; i < startCmd+3; i++)
+ {
+ if (menu->FindItem(i))
+ {
+ menu->Delete(i);
+ }
+ }
+ }
+ else
+ {
+ int i;
+ int pos = -1;
+ // Find the position of the first properties item
+ for (i = 0; i < (int) menu->GetMenuItemCount(); i++)
+ {
+ wxMenuItem* item = menu->FindItemByPosition(i);
+ if (item && item->GetId() == startCmd)
+ {
+ pos = i;
+ break;
+ }
+ }
+
+ if (pos != -1)
+ {
+ int insertBefore = pos+1;
+ for (i = startCmd; i < startCmd+GetCount(); i++)
+ {
+ if (menu->FindItem(i))
+ {
+ menu->SetLabel(i, m_labels[i - startCmd]);
+ }
+ else
+ {
+ if (insertBefore >= (int) menu->GetMenuItemCount())
+ menu->Append(i, m_labels[i - startCmd]);
+ else
+ menu->Insert(insertBefore, i, m_labels[i - startCmd]);
+ }
+ insertBefore ++;
+ }
+
+ // Delete any old items still left on the menu
+ for (i = startCmd + GetCount(); i < startCmd+3; i++)
+ {
+ if (menu->FindItem(i))
+ {
+ menu->Delete(i);
+ }
+ }
+ }
+ }
+ }
+
+ return GetCount();
+}
+
+// Add appropriate menu items for the current container and clicked on object
+// (and container's parent, if appropriate).
+int wxRichTextContextMenuPropertiesInfo::AddItems(wxRichTextObject* container, wxRichTextObject* obj)
+{
+ Clear();
+ if (obj && obj->CanEditProperties())
+ AddItem(obj->GetPropertiesMenuLabel(), obj);
+
+ if (container && container != obj && container->CanEditProperties() && m_labels.Index(container->GetPropertiesMenuLabel()) == wxNOT_FOUND)
+ AddItem(container->GetPropertiesMenuLabel(), container);
+
+ if (container && container->GetParent() && container->GetParent()->CanEditProperties() && m_labels.Index(container->GetParent()->GetPropertiesMenuLabel()) == wxNOT_FOUND)
+ AddItem(container->GetParent()->GetPropertiesMenuLabel(), container->GetParent());
+
+ return GetCount();
+}
+