> On 05/16/12 22:59, Greg Ercolano wrote:
> > What's the goal: is it to add up/dn/lt/rt key control
> > to the caret position of the text display widget?
My goals are
0) to (re)/place (fg,bg) color text anywhere in the text display widget (TDW)
1) to grab ALL keys from the TDW
2) to move/show/hide the caret anywhere in the TDW
All above are INDEPENDENT of each other
> >
> > If so, I'd think you'd want to derive a class from
> > Fl_Text_Display to handle() the key events.
>
> This seems to work reliably wrt to displaying the caret,
> and doesn't seem to need the explicit take_focus() call.
CORRECT !
> This is probably because here we're responding to FL_FOCUS/UNFOCUS,
> and I'm calling redraw() on those events to properly show/hide
> the cursor, which is probably why Fl_Text_Display wasn't drawing
> the caret correctly. (Showing the caret in Fl_Text_Display was
> probably never tested during its development)
For what I need I found I didn't even need redraw() see below.
> This example just shows adding caret cursor motion for
> up/dn/lt/right keys. It doesn't show copy selection, etc.
> But hopefully that too is easily added by checking the state keys,
> ie. checking Fl::event_state() for FL_SHIFT, FL_CTRL, etc.
>
> The following should be a good start.
>
> #include <FL/Fl.H>
> #include <FL/Fl_Window.H>
> #include <FL/Fl_Text_Display.H>
> //
> // Add up/dn/lt/rt keynav to Fl_Text_Display caret cursor -erco 5/16/12
> //
> class MyTextDisplay : public Fl_Text_Display {
> public:
> MyTextDisplay(int X,int Y,int W,int H,const char*L=0) :
> Fl_Text_Display(X,Y,W,H,L) {
> show_cursor(); // ENABLE CURSOR
> cursor_color(0xFF000000); // CURSOR RED
> cursor_style(Fl_Text_Display::HEAVY_CURSOR);
> //take_focus(); // UNNEEDED
> }
> int handle(int e) {
> int ret = Fl_Text_Display::handle(e); // let text display handle
> event first
> switch (e) {
> case FL_FOCUS:
> case FL_UNFOCUS:
> case FL_KEYUP:
> redraw(); // show/hide cursor
Both lines above I did without!
> return 1;
> case FL_KEYBOARD: {
> switch (Fl::event_key()) {
> case FL_Up: printf("UP\n"); move_up(); break;
> case FL_Down: printf("DOWN\n"); move_down(); break;
> case FL_Left: printf("LEFT\n"); move_left(); break;
> case FL_Right: printf("RIGHT\n"); move_right(); break;
> }
for my needs I would just steal all keys here deleting above 4 lines
> break;
> }
> }
> return(ret);
> }
> };
> int main() {
> Fl_Window *win = new Fl_Window(640,480,"Display");
> MyTextDisplay *mDisp = new MyTextDisplay(20,20,640-40,480-40);
> Fl_Text_Buffer *mBuff = new Fl_Text_Buffer();
> mDisp->buffer(mBuff);
> mBuff->text("line 0\nline 1\nline 2\nline 3\nline 4\nline 5\n");
> mDisp->insert_position(5);
> win->end();
> win->show();
> return Fl::run();
> }
This Method (at first testing) works CLEANLY.
It WORKS because keys(events) are taken from Fl_Text_Display (NOT Fl_Window)
This is ALL MY FAULT as I just assumed (from examples)
that events HAD to be taken from the Fl_Window. This is clearly wrong.
I do have one follow up question though.
I am currently trying to flesh out a class TextWindow
(obviously simplified)
class MyTextDisplay : public Fl_Text_Display
{
private:
// ... etc
public:
MyTextDisplay(int X,int Y,int W,int H,const char* l)
: Fl_Text_Display(X,Y,W,H,l) {
// ...
}
// ... methods (trap keys, show/hideCursor(pos), replaceText etc)
};
class MyTextWindow: public Fl_Window, MyTextDisplay
{
public:
MyTextWindow(int W, int H,const char* l)
: Fl_Window(W,H,l), MyTextDisplay(20,20,W-40,H-40,NULL)
{
Fl_Window::label(l);
Fl_Window::add(this); // Compile error : ambiguous base class Fl_Widget
// Fl_Window::add(this->MyTextDisplay) ??
// (MyTextDisplay::) ??
// I know what I want to do here but I just don't know C++ well enough
// for the correct syntax
}
// ...
};
If necessary I can work around the above syntax issue,
but if someone knows the correct syntax I would be grateful.
I intend to make this TextWindow a class so it can appear/disappear.
I seem to recall reading a posting that someone wanted a window that can
appear/disappear.
More of that later.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev