> Thanks, but the text_editor is different to the text_display. The
> text_display example doesn't show a cursor unfortunately,,, Yet the
> Fl_Text_display page in the fltk documentation refers to a cursor /
> cursor style / etc..
Well, that's not strictly correct; the Fl_Text_Editor widget derives directly from Fl_Text_Display, and most of the functionality, including the handling of cursor motion, and cursor display, come from the underlying Fl_Text_Display widget class.
However, the Fl_Text_Display widget has no input capability, and tends to "shrug off" keyboard input by default, so has no cursor *displayed* by default. However, it does *have* a cursor...
> So I'm wondering if there is a visible cursor in the Fl_text_display
> widget for navigating through each character of the text display
> contents?
Yes, you need to turn it on with Fl_Text_Display->show_cursor();
However... that may not be quite what you want, since by default a "pure" Fl_Text_Display will not take keyboard input, so whilst that will *show* the cursor, it likely still will not move in response to keyboard input.
For that, you need to do at least some of what Fl_Text_Editor does to "enable" keyboard handling...
> Here is some code. I'm not having trouble with it because I don't know how
> to make the cursor appear.
> The code compiles fine (but still no cursor).
You have not shown the cursor....
> outs->textcolor(8);
> outs->selection_color(1);
> outs->cursor_color(2);
> outs->cursor_style(5);
Try not to use "magic numbers" like that, it makes the code very hard to read / maintain, try to use the "proper" values instead... e.g.
outs->cursor_style(Fl_Text_Display::HEAVY_CURSOR);
> // I'm just not sure how to make the cursor appear outs->?
outs->show_cursor();
Here's a worked example, that shows a way (albeit a bit of a hack) to catch key events and pass them on to the Fl_Text_Display widget for processing:
++++++++++++++++++++++++++++++
// fltk-config --compile text-display.cxx
//
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Text_Editor.H>
//#include <FL/names.H>
#define EDIT_CLASS Fl_Text_Display
//#define EDIT_CLASS Fl_Text_Editor
#define TS 14 // default editor textsize
static Fl_Text_Buffer *textbuf = 0;
// Editor window functions and class...
class EditorWindow : public Fl_Double_Window {
public:
EditorWindow(int w, int h, const char* t);
~EditorWindow() {};
EDIT_CLASS *editor;
int handle(int ev);
};
EditorWindow::EditorWindow(int w, int h, const char* t) :
Fl_Double_Window(w, h, t),
editor(NULL)
{
// nothing to do here...
} // constructor
int EditorWindow::handle(int ev)
{
int res = Fl_Double_Window::handle(ev);
if (FL_KEYUP == ev)
{
int key = Fl::event_key();
switch (key)
{
case FL_Left:
editor->move_left();
res = 1;
break;
case FL_Right:
editor->move_right();
res = 1;
break;
case FL_Up:
editor->move_up();
res = 1;
break;
case FL_Down:
editor->move_down();
res = 1;
break;
default:
break;
}
}
// printf("handle: ev = %s, res = %d\n", fl_eventnames[ev], res);
// fflush(stdout);
return res;
} // hanlde method
static void close_cb(Fl_Widget*, void* v)
{
EditorWindow* w = (EditorWindow*)v;
w->hide();
}
static Fl_Menu_Item menuitems[] = {
{ "&File", 0, 0, 0, FL_SUBMENU },
{ "&Quit", FL_COMMAND + 'q', (Fl_Callback *)close_cb, 0 },
{ 0 },
{ 0 }
};
static EditorWindow* new_view()
{
EditorWindow* w = new EditorWindow(660, 400, "Format Text");
w->begin();
Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 660, 30);
m->copy(menuitems, w);
w->editor = new EDIT_CLASS(0, 30, 660, 370);
w->editor->textfont(FL_COURIER);
w->editor->textsize(TS);
w->editor->buffer(textbuf);
textbuf->text();
w->end();
w->resizable(w->editor);
w->callback((Fl_Callback *)close_cb, w);
return w;
}
int main(int argc, char **argv)
{
textbuf = new Fl_Text_Buffer;
EditorWindow* window = new_view();
window->show(argc, argv);
window->editor->cursor_style(Fl_Text_Display::NORMAL_CURSOR);
window->editor->cursor_color(FL_RED);
window->editor->show_cursor();
for (int iter = 0; iter < 16; ++iter)
{
window->editor->insert("This is a line of text to display\n");
}
return Fl::run();
}
/* end of file */