+void Edit::OnAnnotationAdd(wxCommandEvent& WXUNUSED(event))
+{
+ const int line = GetCurrentLine();
+
+ wxString ann = AnnotationGetText(line);
+ ann = wxGetTextFromUser
+ (
+ wxString::Format("Enter annotation for the line %d", line),
+ "Edit annotation",
+ ann,
+ this
+ );
+ if ( ann.empty() )
+ return;
+
+ AnnotationSetText(line, ann);
+ AnnotationSetStyle(line, ANNOTATION_STYLE);
+
+ // Scintilla doesn't update the scroll width for annotations, even with
+ // scroll width tracking on, so do it manually.
+ const int width = GetScrollWidth();
+
+ // NB: The following adjustments are only needed when using
+ // wxSTC_ANNOTATION_BOXED annotations style, but we apply them always
+ // in order to make things simpler and not have to redo the width
+ // calculations when the annotations visibility changes. In a real
+ // program you'd either just stick to a fixed annotations visibility or
+ // update the width when it changes.
+
+ // Take into account the fact that the annotation is shown indented, with
+ // the same indent as the line it's attached to.
+ int indent = GetLineIndentation(line);
+
+ // This is just a hack to account for the width of the box, there doesn't
+ // seem to be any way to get it directly from Scintilla.
+ indent += 3;
+
+ const int widthAnn = TextWidth(ANNOTATION_STYLE, ann + wxString(indent, ' '));
+
+ if (widthAnn > width)
+ SetScrollWidth(widthAnn);
+}
+
+void Edit::OnAnnotationRemove(wxCommandEvent& WXUNUSED(event))
+{
+ AnnotationSetText(GetCurrentLine(), wxString());
+}
+
+void Edit::OnAnnotationClear(wxCommandEvent& WXUNUSED(event))
+{
+ AnnotationClearAll();
+}
+
+void Edit::OnAnnotationStyle(wxCommandEvent& event)
+{
+ int style = 0;
+ switch (event.GetId()) {
+ case myID_ANNOTATION_STYLE_HIDDEN:
+ style = wxSTC_ANNOTATION_HIDDEN;
+ break;
+
+ case myID_ANNOTATION_STYLE_STANDARD:
+ style = wxSTC_ANNOTATION_STANDARD;
+ break;
+
+ case myID_ANNOTATION_STYLE_BOXED:
+ style = wxSTC_ANNOTATION_BOXED;
+ break;
+ }
+
+ AnnotationSetVisible(style);
+}
+