return NULL;
}
-static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int depth) {
+static void linearize_mdnodes(CxBuffer *buf, CxList *sections, MDNode *n, int depth, MD_BLOCKTYPE parenttype) {
if(depth >= MD_MAX_DEPTH) {
return;
}
MDDocStyleSection sec;
sec.pos = buf->pos;
sec.length = MDDocStyleSection_LIST;
- sec.style = EDITOR_STYLE_LIST0;
+ sec.style = parenttype == MD_BLOCK_UL ? EDITOR_STYLE_LIST0 : EDITOR_STYLE_ORDLIST0;
sec.link = NULL;
sec.num = n->num;
sec.depth = depth;
MDNode *c = n->children_begin;
depth++;
while(c) {
- linearize_mdnodes(buf, sections, c, depth+1);
+ linearize_mdnodes(buf, sections, c, depth+1, MD_BLOCK_LI);
c = c->next;
}
MDNode *c = n->children_begin;
depth++;
while(c) {
- linearize_mdnodes(buf, sections, c, depth+1);
+ linearize_mdnodes(buf, sections, c, depth+1, 0);
c = c->next;
}
MDNode *n = p->content;
while(n) {
- linearize_mdnodes(buf, sections, n, 0);
+ linearize_mdnodes(buf, sections, n, 0, p->type);
n = n->next;
}
cxBufferPut(buf, '\n');
g_object_set(tag, "indent", -40, NULL);
g_object_set_data(G_OBJECT(tag), "set_style", (void*)tagstyle_list0);
gtk_text_tag_table_add(table, tag);
+
+ tag = gtk_text_tag_new(EDITOR_STYLE_ORDLIST0);
+ g_object_set(tag, "indent", -40, NULL);
+ g_object_set_data(G_OBJECT(tag), "set_style", (void*)tagstyle_list0);
+ gtk_text_tag_table_add(table, tag);
}
/*
// TODO: what do we do in this case?
}
} else if(sec->length == MDDocStyleSection_LIST) {
- editor_insert_list_element(editor, &iter, 0);
+ editor_insert_list_element(editor, &iter, sec->style, sec->num);
}
}
int height,
gpointer data)
{
+ ListElmWidget *elm = data;
+
GtkWidget *parent = gtk_widget_get_parent(GTK_WIDGET(area));
PangoContext *context = gtk_widget_get_pango_context(parent);
PangoFontDescription *font = pango_context_get_font_description(context);
PangoLayout *layout = pango_cairo_create_layout(cr);
- pango_layout_set_text (layout, "•", -1);
+ pango_layout_set_text (layout, elm->str, -1);
pango_layout_set_font_description (layout, font);
int textwidth;
cxBufferPutString(out, " - ");
}
-void editor_insert_list_element(NoteEditor *editor, GtkTextIter *iter, int type) {
+static void destroy_listelm(gpointer data) {
+ ListElmWidget *elm = data;
+ free(elm->str);
+ free(elm);
+}
+
+void editor_insert_list_element(NoteEditor *editor, GtkTextIter *iter, const char *style, int num) {
GtkTextView *textview = GTK_TEXT_VIEW(editor->textview);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
int descent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
int height = pango_font_metrics_get_height(metrics) / PANGO_SCALE;
+ ListElmWidget *elm = malloc(sizeof(ListElmWidget));
+ if(!strcmp(style, EDITOR_STYLE_LIST0)) {
+ elm->str = strdup("•");
+ } else {
+ char buf[32];
+ snprintf(buf, 32, "%d", num);
+ elm->str = strdup(buf);
+ }
+
GtkWidget *widget = gtk_drawing_area_new(); // •
- gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), draw_bulletlist, NULL, NULL);
+ gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), draw_bulletlist, elm, destroy_listelm);
gtk_widget_set_size_request(widget, 40, height);
//gtk_widget_add_css_class(widget, "ui_test");
gtk_widget_set_margin_bottom(widget, -descent);
+ g_object_set_data(G_OBJECT(widget), "listelm", elm);
GtkTextMark *start_mark = gtk_text_buffer_create_mark(buffer, NULL, iter, TRUE);
GtkTextIter iter;
gtk_text_buffer_get_iter_at_mark(buffer, &iter, cursor);
- editor_insert_list_element(editor, &iter, 0);
+ const char *style = ordered ? EDITOR_STYLE_ORDLIST0 : EDITOR_STYLE_LIST0;
+ editor_insert_list_element(editor, &iter, style, 0);
}