diff --git a/CHANGES b/CHANGES index 78d1ea233..be5a82423 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ CHANGES IN FLTK 1.1.7 - Documentation fixes (STR #648, STR #692, STR #730, STR #744, STR #745) + - Fixed a syntax highlighting bug in the editor demo. - Fl_Progress now contrasts the label color with the bar color, so labels will be readable at all times. - fl_read_image() didn't use the right red, green, and diff --git a/fluid/CodeEditor.cxx b/fluid/CodeEditor.cxx index 926f30506..f979ce107 100644 --- a/fluid/CodeEditor.cxx +++ b/fluid/CodeEditor.cxx @@ -138,8 +138,18 @@ void CodeEditor::style_parse(const char *text, char *style, int length) { *bufptr; const char *temp; + // Style letters: + // + // A - Plain + // B - Line comments + // C - Block comments + // D - Strings + // E - Directives + // F - Types + // G - Keywords + for (current = *style, col = 0, last = 0; length > 0; length --, text ++) { - if (current == 'B') current = 'A'; + if (current == 'B' || current == 'F' || current == 'G') current = 'A'; if (current == 'A') { // Check for directives, comments, strings, and keywords... if (col == 0 && *text == '#') { @@ -162,13 +172,13 @@ void CodeEditor::style_parse(const char *text, char *style, int length) { continue; } else if (*text == '\"') { current = 'D'; - } else if (!last && islower(*text)) { + } else if (!last && (islower(*text) || *text == '_')) { // Might be a keyword... for (temp = text, bufptr = buf; - islower(*temp) && bufptr < (buf + sizeof(buf) - 1); + (islower(*temp) || *temp == '_') && bufptr < (buf + sizeof(buf) - 1); *bufptr++ = *temp++); - if (!islower(*temp)) { + if (!islower(*temp) && *temp != '_') { *bufptr = '\0'; bufptr = buf; @@ -237,7 +247,7 @@ void CodeEditor::style_parse(const char *text, char *style, int length) { else *style++ = current; col ++; - last = isalnum(*text) || *text == '.'; + last = isalnum(*text) || *text == '_' || *text == '.'; if (*text == '\n') { // Reset column and possibly reset the style diff --git a/fluid/function_panel.cxx b/fluid/function_panel.cxx index e4d77bb78..01923e069 100644 --- a/fluid/function_panel.cxx +++ b/fluid/function_panel.cxx @@ -99,7 +99,7 @@ Fl_Window* make_function_panel() { Fl_Window *code_panel=(Fl_Window *)0; -Fl_Text_Editor *code_input=(Fl_Text_Editor *)0; +CodeEditor *code_input=(CodeEditor *)0; Fl_Return_Button *code_panel_ok=(Fl_Return_Button *)0; @@ -110,13 +110,19 @@ Fl_Window* make_code_panel() { { Fl_Window* o = code_panel = new Fl_Window(545, 175, "Code Properties"); w = o; o->labelsize(11); - { Fl_Text_Editor* o = code_input = new Fl_Text_Editor(10, 12, 525, 123); + { CodeEditor* o = code_input = new CodeEditor(10, 12, 525, 123); o->box(FL_DOWN_BOX); + o->color(FL_BACKGROUND2_COLOR); + o->selection_color(FL_SELECTION_COLOR); + o->labeltype(FL_NORMAL_LABEL); + o->labelfont(0); o->labelsize(11); + o->labelcolor(FL_BLACK); + o->textfont(4); o->textsize(11); + o->align(FL_ALIGN_TOP); + o->when(FL_WHEN_RELEASE); Fl_Group::current()->resizable(o); - o->buffer(new Fl_Text_Buffer); - o->textfont(FL_COURIER); o->when(FL_WHEN_ENTER_KEY_CHANGED|FL_WHEN_RELEASE); } { Fl_Group* o = new Fl_Group(12, 145, 523, 20); @@ -340,7 +346,7 @@ Fl_Window* make_class_panel() { Fl_Window *comment_panel=(Fl_Window *)0; -Fl_Text_Editor *comment_input=(Fl_Text_Editor *)0; +CodeEditor *comment_input=(CodeEditor *)0; Fl_Return_Button *comment_panel_ok=(Fl_Return_Button *)0; @@ -359,13 +365,19 @@ Fl_Window* make_comment_panel() { { Fl_Window* o = comment_panel = new Fl_Window(545, 285, "Comment Properties"); w = o; o->labelsize(11); - { Fl_Text_Editor* o = comment_input = new Fl_Text_Editor(95, 10, 438, 241); + { CodeEditor* o = comment_input = new CodeEditor(95, 10, 438, 241); o->box(FL_DOWN_BOX); + o->color(FL_BACKGROUND2_COLOR); + o->selection_color(FL_SELECTION_COLOR); + o->labeltype(FL_NORMAL_LABEL); + o->labelfont(0); o->labelsize(11); + o->labelcolor(FL_BLACK); + o->textfont(4); o->textsize(11); + o->align(FL_ALIGN_TOP); + o->when(FL_WHEN_RELEASE); Fl_Group::current()->resizable(o); - o->buffer(new Fl_Text_Buffer); - o->textfont(FL_COURIER); o->when(FL_WHEN_ENTER_KEY_CHANGED|FL_WHEN_RELEASE); } { Fl_Group* o = new Fl_Group(368, 255, 167, 25); @@ -432,7 +444,7 @@ Fl_Window *widgetbin_panel=(Fl_Window *)0; Fl_Window* make_widgetbin() { Fl_Window* w; - { Fl_Window* o = widgetbin_panel = new Fl_Window(490, 100, "Widget Bin"); + { Fl_Window* o = widgetbin_panel = new Fl_Window(485, 100, "Widget Bin"); w = o; { Fl_Group* o = new Fl_Group(3, 3, 74, 74); o->box(FL_THIN_DOWN_BOX); diff --git a/fluid/function_panel.fl b/fluid/function_panel.fl index 900eefd13..ae0275934 100644 --- a/fluid/function_panel.fl +++ b/fluid/function_panel.fl @@ -83,10 +83,10 @@ Function {make_code_panel()} {open xywh {527 128 545 175} type Single labelsize 11 hide resizable modal } { Fl_Text_Editor code_input { - xywh {10 12 525 123} box DOWN_BOX labelsize 11 textsize 11 resizable - code0 {o->buffer(new Fl_Text_Buffer);} - code1 {o->textfont(FL_COURIER);} - code2 {o->when(FL_WHEN_ENTER_KEY_CHANGED|FL_WHEN_RELEASE);} + xywh {10 12 525 123} box DOWN_BOX labelsize 11 textfont 4 textsize 11 resizable + code0 {o->when(FL_WHEN_ENTER_KEY_CHANGED|FL_WHEN_RELEASE);} + code1 {\#include "CodeEditor.h"} + class CodeEditor } Fl_Group {} {open xywh {12 145 523 20} labelsize 11 @@ -218,11 +218,10 @@ Function {make_comment_panel()} {open label {Comment Properties} xywh {328 152 545 285} type Single labelsize 11 hide resizable modal } { - Fl_Text_Editor comment_input { - xywh {95 10 438 241} box DOWN_BOX labelsize 11 textsize 11 resizable - code0 {o->buffer(new Fl_Text_Buffer);} - code1 {o->textfont(FL_COURIER);} - code2 {o->when(FL_WHEN_ENTER_KEY_CHANGED|FL_WHEN_RELEASE);} + Fl_Text_Editor comment_input {selected + xywh {95 10 438 241} box DOWN_BOX labelsize 11 textfont 4 textsize 11 resizable + code0 {o->when(FL_WHEN_ENTER_KEY_CHANGED|FL_WHEN_RELEASE);} + class CodeEditor } Fl_Group {} {open xywh {368 255 167 25} labelsize 11 @@ -283,8 +282,8 @@ Function {make_widgetbin()} {open } { Fl_Window widgetbin_panel { label {Widget Bin} open - xywh {385 53 485 100} type Single - code0 {o->size(o->w(),80);} non_modal visible + xywh {385 53 485 100} type Single hide + code0 {o->size(o->w(),80);} non_modal } { Fl_Group {} {open xywh {3 3 74 74} box THIN_DOWN_BOX @@ -551,7 +550,7 @@ Function {make_widgetbin()} {open } Fl_Button {} { user_data {"Fl_Input_Choice"} - callback type_make_cb selected + callback type_make_cb tooltip {Input Choice} xywh {384 4 24 24} box THIN_UP_BOX code0 {o->image(pixmap[15]);} } diff --git a/fluid/function_panel.h b/fluid/function_panel.h index 2fcb01340..9f3b86277 100644 --- a/fluid/function_panel.h +++ b/fluid/function_panel.h @@ -44,8 +44,8 @@ extern Fl_Return_Button *f_panel_ok; extern Fl_Button *f_panel_cancel; Fl_Window* make_function_panel(); extern Fl_Window *code_panel; -#include -extern Fl_Text_Editor *code_input; +#include "CodeEditor.h" +extern CodeEditor *code_input; #include extern Fl_Return_Button *code_panel_ok; extern Fl_Button *code_panel_cancel; @@ -78,7 +78,7 @@ extern Fl_Return_Button *c_panel_ok; extern Fl_Button *c_panel_cancel; Fl_Window* make_class_panel(); extern Fl_Window *comment_panel; -extern Fl_Text_Editor *comment_input; +extern CodeEditor *comment_input; extern Fl_Return_Button *comment_panel_ok; extern Fl_Button *comment_panel_cancel; extern Fl_Light_Button *comment_in_source; diff --git a/test/editor.cxx b/test/editor.cxx index 56ae9e974..d27b95e70 100644 --- a/test/editor.cxx +++ b/test/editor.cxx @@ -172,8 +172,18 @@ style_parse(const char *text, *bufptr; const char *temp; + // Style letters: + // + // A - Plain + // B - Line comments + // C - Block comments + // D - Strings + // E - Directives + // F - Types + // G - Keywords + for (current = *style, col = 0, last = 0; length > 0; length --, text ++) { - if (current == 'B') current = 'A'; + if (current == 'B' || current == 'F' || current == 'G') current = 'A'; if (current == 'A') { // Check for directives, comments, strings, and keywords... if (col == 0 && *text == '#') { @@ -196,13 +206,13 @@ style_parse(const char *text, continue; } else if (*text == '\"') { current = 'D'; - } else if (!last && islower(*text)) { + } else if (!last && (islower(*text) || *text == '_')) { // Might be a keyword... for (temp = text, bufptr = buf; - islower(*temp) && bufptr < (buf + sizeof(buf) - 1); + (islower(*temp) || *temp == '_') && bufptr < (buf + sizeof(buf) - 1); *bufptr++ = *temp++); - if (!islower(*temp)) { + if (!islower(*temp) && *temp != '_') { *bufptr = '\0'; bufptr = buf; @@ -271,7 +281,7 @@ style_parse(const char *text, else *style++ = current; col ++; - last = isalnum(*text) || *text == '.'; + last = isalnum(*text) || *text == '_' || *text == '.'; if (*text == '\n') { // Reset column and possibly reset the style @@ -357,11 +367,12 @@ style_update(int pos, // I - Position of update stylebuf->select(pos, pos + nInserted - nDeleted); // Re-parse the changed region; we do this by parsing from the - // beginning of the line of the changed region to the end of + // beginning of the previous line of the changed region to the end of // the line of the changed region... Then we check the last // style character and keep updating if we have a multi-line // comment character... start = textbuf->line_start(pos); +// if (start > 0) start = textbuf->line_start(start - 1); end = textbuf->line_end(pos + nInserted); text = textbuf->text_range(start, end); style = stylebuf->text_range(start, end); @@ -453,7 +464,7 @@ int check_save(void) { int r = fl_choice("The current file has not been saved.\n" "Would you like to save it now?", - "Cancel", "Save", "Discard"); + "Cancel", "Save", "Don't Save"); if (r == 1) { save_cb(); // Save the file...