Dear community,
I am currently combining the editor and fonts test files (test/editor.cxx &
test/fonts.cxx) shipped with FLTK 1.1.10 to allow the user to define a
different font and font size in realtime for the text she/he entered into the
editor. I use Windows XP.
I managed to assign the new values the user chose to the textfont and textsize
properties of the EditorWindow object and also call the redisplay_range and
redraw methods.
However, the font and its size won't change. From similar messages in this
forum and the Net I see that a callback function must be invoked.
The examples show textsize.callback(...) calls in main() only. However, my
editor object is created in a subroutine and calls like
window->editor->textsize...callback() or else won't compile.
Would you please help me ? Below are the respective procedures.
Thank you,
Alexander
/* function to set a new font and size */
void font_cb (Fl_Widget *, void *v) {
EditorWindow *w = (EditorWindow *)v;
int fn = fontobj->value();
if (!fn) return;
fn--;
textobj->font = fn;
sizeobj->clear();
int n = numsizes[fn];
int *s = sizes[fn];
if (!n) {
// no sizes
} else if (s[0] == 0) {
// many sizes;
int j = 1;
for (int i = 1; i<64 || i<s[n-1]; i++) {
char buf[20];
if (j < n && i==s[j]) {sprintf(buf,"@b%d",i); j++;}
else sprintf(buf,"%d",i);
sizeobj->add(buf);
}
sizeobj->value(pickedsize);
} else {
// some sizes
int w = 0;
for (int i = 0; i < n; i++) {
if (s[i]<=pickedsize) w = i;
char buf[20];
sprintf(buf,"@b%d",s[i]);
sizeobj->add(buf);
}
sizeobj->value(w+1);
}
// fprintf(stderr, "%d %d\n", w->editor->textfont(), w->editor->textsize());
w->editor->textfont((Fl_Font)fn);
w->editor->textsize(sizeobj->value());
// fprintf(stderr, "=%d\n", textbuf->length());
w->editor->redisplay_range(0, textbuf->length());
w->editor->show_insert_position();
w->editor->redraw();
// w->editor->show();
//fprintf(stderr, "%d %d\n", w->editor->textfont(), w->editor->textsize());
textobj->redraw();
textobj->show();
Fl::check();
}
/* function that created a new editor instance */
Fl_Window* new_view() {
EditorWindow* w = new EditorWindow(660, 400, title);
w->begin();
Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 660, 30);
m->copy(menuitems, w);
w->editor = new Fl_Text_Editor(0, 30, 660, 370);
w->editor->buffer(textbuf);
w->editor->highlight_data(stylebuf, styletable,
sizeof(styletable) / sizeof(styletable[0]),
'A', style_unfinished_cb, 0);
w->editor->textfont(FL_COURIER);
w->editor->color(FL_WHITE); /* Solaris would otherwise use gray as
backgound colour */
w->end();
w->resizable(w->editor);
w->callback((Fl_Callback *)close_cb, w);
textbuf->add_modify_callback(style_update, w->editor);
textbuf->add_modify_callback(changed_cb, w);
textbuf->call_modify_callbacks();
num_windows++;
return w;
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk