*/
virtual bool CanInsertContent(wxRichTextParagraphLayoutBox& container, long pos) const;
+ /**
+ Finds a table, either selected or near the cursor
+ */
+ wxRichTextTable* FindTable() const;
+
+ /**
+ Helper for FindTable()
+ */
+ wxRichTextObject* FindCurrentPosition() const;
+
long m_lockId;
bool m_locked;
};
void OnDemoteList(wxCommandEvent& event);
void OnClearList(wxCommandEvent& event);
+ void OnTableAddColumn(wxCommandEvent& event);
+ void OnTableAddRow(wxCommandEvent& event);
+ void OnTableDeleteColumn(wxCommandEvent& event);
+ void OnTableDeleteRow(wxCommandEvent& event);
+ void OnTableFocusedUpdateUI(wxUpdateUIEvent& event);
+ void OnTableHasCellsUpdateUI(wxUpdateUIEvent& event);
+
void OnReload(wxCommandEvent& event);
void OnViewHTML(wxCommandEvent& event);
ID_FORMAT_DEMOTE_LIST,
ID_FORMAT_CLEAR_LIST,
+ ID_TABLE_ADD_COLUMN,
+ ID_TABLE_ADD_ROW,
+ ID_TABLE_DELETE_COLUMN,
+ ID_TABLE_DELETE_ROW,
+
ID_SET_FONT_SCALE,
ID_SET_DIMENSION_SCALE,
EVT_MENU(ID_FORMAT_DEMOTE_LIST, MyFrame::OnDemoteList)
EVT_MENU(ID_FORMAT_CLEAR_LIST, MyFrame::OnClearList)
+ EVT_MENU(ID_TABLE_ADD_COLUMN, MyFrame::OnTableAddColumn)
+ EVT_MENU(ID_TABLE_ADD_ROW, MyFrame::OnTableAddRow)
+ EVT_MENU(ID_TABLE_DELETE_COLUMN, MyFrame::OnTableDeleteColumn)
+ EVT_MENU(ID_TABLE_DELETE_ROW, MyFrame::OnTableDeleteRow)
+ EVT_UPDATE_UI_RANGE(ID_TABLE_ADD_COLUMN, ID_TABLE_ADD_ROW, MyFrame::OnTableFocusedUpdateUI)
+ EVT_UPDATE_UI_RANGE(ID_TABLE_DELETE_COLUMN, ID_TABLE_DELETE_ROW, MyFrame::OnTableHasCellsUpdateUI)
+
EVT_MENU(ID_VIEW_HTML, MyFrame::OnViewHTML)
EVT_MENU(ID_SWITCH_STYLE_SHEETS, MyFrame::OnSwitchStyleSheets)
EVT_MENU(ID_MANAGE_STYLES, MyFrame::OnManageStyles)
listsMenu->Append(ID_FORMAT_DEMOTE_LIST, _("Demote List Items"));
listsMenu->Append(ID_FORMAT_CLEAR_LIST, _("Clear List Formatting"));
+ wxMenu* tableMenu = new wxMenu;
+ tableMenu->Append(ID_TABLE_ADD_COLUMN, _("&Add Column"));
+ tableMenu->Append(ID_TABLE_ADD_ROW, _("Add &Row"));
+ tableMenu->Append(ID_TABLE_DELETE_COLUMN, _("Delete &Column"));
+ tableMenu->Append(ID_TABLE_DELETE_ROW, _("&Delete Row"));
+
wxMenu* insertMenu = new wxMenu;
insertMenu->Append(ID_INSERT_SYMBOL, _("&Symbol...\tCtrl+I"));
insertMenu->Append(ID_INSERT_URL, _("&URL..."));
menuBar->Append(editMenu, wxT("&Edit"));
menuBar->Append(formatMenu, wxT("F&ormat"));
menuBar->Append(listsMenu, wxT("&Lists"));
+ menuBar->Append(tableMenu, wxT("&Tables"));
menuBar->Append(insertMenu, wxT("&Insert"));
menuBar->Append(helpMenu, wxT("&Help"));
r.SetInsertionPointEnd();
}
#endif
+
#if 1
{
// Add a table
r.SetFocusObject(cell);
cell->Clear();
r.WriteText("This cell spans 2 columns and 3 rows");
-
+
r.SetFocusObject(NULL); // Set the focus back to the main buffer
r.SetInsertionPointEnd();
}
}
}
+void MyFrame::OnTableAddColumn(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextTable* table = wxDynamicCast(m_richTextCtrl->FindTable(), wxRichTextTable);
+ if (table)
+ {
+ wxRichTextAttr cellAttr = table->GetCell(0, 0)->GetAttributes();
+ table->AddColumns(table->GetColumnCount(), 1, cellAttr);
+ }
+}
+
+void MyFrame::OnTableAddRow(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextTable* table = wxDynamicCast(m_richTextCtrl->FindTable(), wxRichTextTable);
+ if (table)
+ {
+ wxRichTextAttr cellAttr = table->GetCell(0, 0)->GetAttributes();
+ table->AddRows(table->GetRowCount(), 1, cellAttr);
+ }
+}
+
+void MyFrame::OnTableDeleteColumn(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextTable* table = wxDynamicCast(m_richTextCtrl->FindTable(), wxRichTextTable);
+ if (table)
+ {
+ int col = table->GetFocusedCell().GetCol();
+ if (col == -1)
+ {
+ col = table->GetColumnCount() - 1;
+ }
+
+ table->DeleteColumns(col, 1);
+ }
+}
+
+void MyFrame::OnTableDeleteRow(wxCommandEvent& WXUNUSED(event))
+{
+ wxRichTextTable* table = wxDynamicCast(m_richTextCtrl->FindTable(), wxRichTextTable);
+ if (table)
+ {
+ int row = table->GetFocusedCell().GetRow();
+ if (row == -1)
+ {
+ row = table->GetRowCount() - 1;
+ }
+
+ table->DeleteRows(row, 1);
+ }
+}
+
+void MyFrame::OnTableFocusedUpdateUI(wxUpdateUIEvent& event)
+{
+ event.Enable(m_richTextCtrl->FindTable() != NULL);
+}
+
+void MyFrame::OnTableHasCellsUpdateUI(wxUpdateUIEvent& event)
+{
+ bool enable(false);
+ wxRichTextTable* table = wxDynamicCast(m_richTextCtrl->FindTable(), wxRichTextTable);
+ if (table)
+ {
+ if (event.GetId() == ID_TABLE_DELETE_COLUMN)
+ {
+ enable = table->GetColumnCount() > 1;
+ }
+ else
+ {
+ enable = table->GetRowCount() > 1;
+ }
+ }
+
+ event.Enable(enable);
+}
+
void MyFrame::OnInsertURL(wxCommandEvent& WXUNUSED(event))
{
wxString url = wxGetTextFromUser(_("URL:"), _("Insert URL"));
{
wxRichTextBuffer::AddDrawingHandler(new wxRichTextEnhancedDrawingHandler);
}
+
+wxRichTextObject* MyRichTextCtrl::FindCurrentPosition() const
+{
+ long position = -1;
+
+ if (HasSelection()) // First see if there's a selection
+ {
+ wxRichTextRange range = GetSelectionRange();
+ if (range.ToInternal().GetLength() == 1)
+ {
+ position = range.GetStart();
+ }
+ }
+ if (position == -1) // Failing that, near cursor
+ {
+ position = GetAdjustedCaretPosition(GetCaretPosition());
+ }
+
+
+ wxRichTextObject* obj = GetFocusObject()->GetLeafObjectAtPosition(position);
+
+ return obj;
+}
+
+wxRichTextTable* MyRichTextCtrl::FindTable() const
+{
+ wxRichTextObject* obj = FindCurrentPosition();
+
+ // It could be a table or a cell (or neither)
+ wxRichTextTable* table = wxDynamicCast(obj, wxRichTextTable);
+ if (table)
+ {
+ return table;
+ }
+
+ while (obj)
+ {
+ obj = obj->GetParent();
+ wxRichTextTable* table = wxDynamicCast(obj, wxRichTextTable);
+ if (table)
+ {
+ return table;
+ }
+ }
+
+ return NULL;
+}