Hello Ben!
I've few strings a code (in attached the patch) for fltk2.
If You decide what that's maybe to usefully for fltk2 project - You're inlude
(after formatting/optimization the code) it to project...
PS: sorry for my dirty style of programming...
Regards.
diff -r fltk-2.0.x-r7725_old/fltk/Input.h fltk-2.0.x-r7725_new/fltk/Input.h
61a62,67
> void show_cursor(bool n) {cursor_on_ = n;redraw();}
> void show_cursor() {show_cursor(true);}
> void hide_cursor() {show_cursor(false);}
> bool is_show_cursor(){ return (cursor_on_ == true); }
> const double blink_time(){ return blink_cursor_time_; }
> void blink_cursor(bool blink, const double time_blink = 0.5);
103a110,112
> bool cursor_on_;
> bool blink_cursor_;
> double blink_cursor_time_;
diff -r fltk-2.0.x-r7725_old/src/Input.cxx fltk-2.0.x-r7725_new/src/Input.cxx
2c2
< // "$Id: Input.cxx 7513 2010-04-15 17:19:27Z spitzak $"
---
> // "$Id: Input.cxx 5600 2007-01-13 00:04:55Z spitzak $"
33a34,38
> #include <fltk/run.h>
> #include <fltk/Cursor.h>
> #include <fltk/Group.h>
> #include <fltk/Window.h>
> #include <stdio.h>
44,46c49
< if (i->when() & WHEN_CHANGED) {
< i->do_callback();
< } else if (i->when() & (WHEN_RELEASE|WHEN_ENTER_KEY)) {
---
> if (i->when() & (WHEN_RELEASE|WHEN_ENTER_KEY)) {
50a54,55
> } else {
> if (i->when()) i->do_callback();
63,66c68,69
< The default when() is WHEN_RELEASE. This is fine for a popup
< control panel where nothing happens until the panel is closed.
< But for most other uses of the input field you want to change
< it. Useful values are:
---
> By default the callback() is done each time the text is changed
> by the user. Other values for when():
69,72c72,81
< - fltk::WHEN_CHANGED: The callback is done each time the text is
< changed by the user.
< - fltk::WHEN_ENTER_KEY: Hitting the enter key after changing the
< text will cause the callback.
---
> - fltk::WHEN_CHANGED: The default, if set and no other flags are set the
> callback is done each time the text is changed by the user.
> - fltk::WHEN_ENTER_KEY: If the user types the Enter key, the entire
> text is selected, and if the value has changed, the callback is
> done. The callback will also be done if the value has changed
> and the user clicks on another widget or the focus moves away
> (to another widget or program). If another widget (such as an OK button
> on a panel) has Enter as a shortcut, that widget will take precendence.
> If that widget hides or destroys the Input widget because it is
> dismissing a panel, the callback will be done then.
75,77c84,85
< Also you need to do this if you want both the enter key and
< either WHEN_CHANGED or WHEN_RELEASE, in this case you can tell
< if Enter was typed by testing fltk::event_key()==fltk::EnterKey.
---
> The callback will also be done for other reasons described above,
> test fltk::event_key()==fltk::EnterKey to ignore these.
80,81c88
< focus moves (which can happen due to the window this widget
< is on being closed).
---
> focus moves away. But no special treatment of ENTER.
242,243c249
< Color color = this->color();
< setcolor(color);
---
> setcolor(color());
246,247c252,254
< if (flag(INACTIVE_R)) setcolor(inactive(labelcolor(), color));
< else setcolor(labelcolor());
---
> Color color = labelcolor();
> if (flag(INACTIVE_R)) color = inactive(color);
> setcolor(color);
272c279,280
< drawstyle(style(), this->flags()&~HIGHLIGHT);
---
> Flags flags = this->flags()&~HIGHLIGHT;
> drawstyle(style(), flags);
301c309
<
---
> bool isdc = false;
427a436,495
>
>
> // for (; ypos < r.h();){ ypos += height; }
>
> if(cursor_on_ && blink_cursor_ && !isdc){
> // if((r.h()/height)>=ypos/height)
> if(position() <= mark()){
> setcolor(textcolor);
> if(type() == MULTILINE || type() == WORDWRAP){
> fillrect(xpos+curx-1, r.y()+ypos, 2, height);
> }
> else { fillrect(xpos+curx-1, r.y()+ypos, 2, height); }
> spot_x = xpos+curx;
> spot_y = r.y()+ypos;
> isdc = true;
>
> printf("ypos=%d\n", ypos);
> printf("r.h()=%d\n", r.h());
> printf("height=%d\n", height);
>
> }
> else {
> // count new lines in the text
> const char *my_p = (const char *)text();
> int my_c = 1;
> while((my_p = strchr(my_p, '\n')) != NULL){ my_p++; my_c++; }
> int my_l = ypos/height+1;
> int my_s = 1;
> my_p = (const char *)text();
> for(int _i = 0; _i < position(); _i++){
> if(my_p[_i] == '\n'){ my_s++; }
> }
> my_p = NULL;
> // for(;;){ if(my_c == my_l){ break; } else { my_c--; } }
> if(my_s == my_l){
> setcolor(textcolor);
> if(type() == MULTILINE || type() == WORDWRAP){
> fillrect(xpos+curx-1, r.y()+ypos, 2, height);
> }
> else { fillrect(xpos+curx-1, r.y()+ypos, 2, height); }
> spot_x = xpos+curx;
> spot_y = r.y()+ypos;
> isdc = true;
> }
>
> printf("position()=%d\n", position());
> printf("mark()=%d\n", mark());
> printf("ypos=%d\n", ypos);
> printf("r.h()=%d\n", r.h());
> printf("height=%d\n", height);
> printf("my_c=%d\n", my_c);
> printf("my_l=%d\n", my_l);
> printf("my_s=%d\n", my_s);
>
> // printf("newscroll=%d\n", newscroll);
>
> }
>
> }
>
443,444c511,513
< if ((this==dnd_target || (focused() && selstart == selend)) &&
< cursor_position >= p-text_ && cursor_position <= e-text_) {
---
> if ((this==dnd_target || focused() && selstart == selend) &&
> cursor_position >= p-text_ && cursor_position <= e-text_ &&
> cursor_on_) {
871c940
< if (undowidget != this || !(undocut || undoinsert)) return false;
---
> if (undowidget != this || !undocut && !undoinsert) return false;
923a993,1002
>
> static void function_blink_cursor(void* p){
>
> fltk::Input *input = (fltk::Input *)p;
> input->show_cursor(!(input->is_show_cursor()));
> fltk::repeat_timeout(input->blink_time(), &function_blink_cursor, p);
>
> }
>
>
940a1020,1022
> cursor_on_ = true;
> blink_cursor_ = false;
> blink_cursor_time_ = 0.5;
942a1025,1058
>
>
>
>
> void Input::blink_cursor(bool blink, const double time_blink){
>
> blink_cursor_time_ = time_blink;
>
> if(blink){
>
> if(!blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
>
> }
>
> else {
>
> if(blink_cursor_){
>
> fltk::remove_timeout(&function_blink_cursor, this);
> cursor_on_ = true;
>
> }
>
> }
>
> blink_cursor_ = blink;
>
> }
>
>
>
>
>
>
1066a1183
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
1138d1254
< bool command = event_state(COMMAND);
1141c1257
< bool alt = event_state(OPTION);
---
> bool alt = event_state(ALT|META);
1208c1324
< if (command) {
---
> if (ctrl) {
1262c1378
< if (command || shift) return false;
---
> if (ctrl || shift) return false;
1289c1405
< if (!command && try_shortcut()) return true;
---
> if (!ctrl && try_shortcut()) return true;
1319c1435
< if (!command && try_shortcut()) return true;
---
> if (!ctrl && try_shortcut()) return true;
1329c1445
< if (!command && try_shortcut()) return true;
---
> if (!ctrl && try_shortcut()) return true;
1361,1364d1476
< #if defined(__APPLE__)
< case LeftCmdKey:
< case RightCmdKey:
< #endif
1413a1526
>
1416c1529,1565
< case ENTER:
---
> // case PUSH:{printf("PUSH\n");}
> // case RELEASE:{printf("RELEASE\n");}
> // case ENTER:{printf("ENTER\n");}
> // case LEAVE:{printf("LEAVE\n");}
> // case DRAG:{printf("DRAG\n");}
> // case FOCUS:{printf("FOCUS\n");}
> // case UNFOCUS:{printf("UNFOCUS\n");}
> // case KEY:{printf("KEY\n");}
> // case KEYUP:{printf("KEYUP\n");}
> // case FOCUS_CHANGE:{printf("FOCUS_CHANGE\n");}
> // case MOVE:{printf("MOVE\n");}
> // case DEACTIVATE:{printf("DEACTIVATE\n");}
> // case ACTIVATE:{printf("ACTIVATE\n");}
> // case HIDE:{printf("HIDE\n");}
> // case SHOW:{printf("SHOW\n");}
> // case PASTE:{printf("PASTE\n");}
> // case TIMEOUT:{printf("TIMEOUT\n");}
> // case MOUSEWHEEL:{printf("MOUSEWHEEL\n");}
> // case DND_ENTER:{printf("DND_ENTER\n");}
> // case DND_DRAG:{printf("DND_DRAG\n");}
> // case DND_LEAVE:{printf("DND_LEAVE\n");}
> // case DND_RELEASE:{printf("DND_RELEASE\n");}
> // case TOOLTIP:{printf("TOOLTIP\n");}
>
>
> case FOCUS_CHANGE: {
>
> /// printf("FOCUS_CHANGE\n");
>
> }
>
> case ENTER: {
>
> cursor(fltk::CURSOR_INSERT);
> /// printf("ENTER\n");
>
> }
1421a1571,1573
>
> /// printf("FOCUS\n");
>
1453a1606,1610
>
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> if(blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
>
1456a1614,1615
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
1462a1622,1624
>
> /// printf("UNFOCUS\n");
>
1465a1628,1630
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> /// printf("HIDE\n");
1468a1634,1638
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> if(blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
> /// printf("KEY\n");
> redraw();
1471a1642,1644
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> if(blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
1472a1646,1647
> redraw();
> /// printf("PUSH\n");
1478,1479c1653,1654
< ((newpos >= mark() && newpos < position()) ||
< (newpos >= position() && newpos < mark()))) {
---
> (newpos >= mark() && newpos < position() ||
> newpos >= position() && newpos < mark())) {
1491a1667
> /// printf("TIMEOUT\n");
1502a1679,1683
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> // if(blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
> redraw();
> /// printf("DRAG\n");
1553a1735,1738
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> if(blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
> /// printf("RELEASE\n");
1574a1760
> /// printf("DND_ENTER\n");
1577a1764,1768
>
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
>
> /// printf("DND_DRAG\n");
1597a1789
>
1601a1794
> /// printf("DND_LEAVE\n");
1608a1802,1811
> // cursor(fltk::CURSOR_INSERT);
> if(blink_cursor_){ fltk::remove_timeout(&function_blink_cursor, this); }
> cursor_on_ = true;
> if(blink_cursor_){ fltk::add_timeout(blink_cursor_time_, &function_blink_cursor, this); }
>
> dnd_target->cursor(fltk::CURSOR_INSERT);
> //dnd_target->redraw();
>
> /// printf("DND_RELEASE\n");
>
1610c1813
< if (dnd_target != this) return 0;
---
> if (dnd_target != this){ return 0; }
1652c1855
< // End of "$Id: Input.cxx 7513 2010-04-15 17:19:27Z spitzak $".
---
> // End of "$Id: Input.cxx 5600 2007-01-13 00:04:55Z spitzak $".
diff -r fltk-2.0.x-r7725_old/src/TabGroup.cxx fltk-2.0.x-r7725_new/src/TabGroup.cxx
1c1
< // "$Id: TabGroup.cxx 7513 2010-04-15 17:19:27Z spitzak $"
---
> // "$Id: TabGroup.cxx 5575 2007-01-02 17:31:40Z spitzak $"
247c247
< if ((push_ && !push_->visible()) || (o && !o->visible()))
---
> if (push_ && !push_->visible() || o && !o->visible())
430c430,431
< setcolor(sel ? selection_color() : o->color());
---
> setcolor(sel ? o->selection_color() : o->color());
> textcolor(sel ? o->selection_textcolor() : o->textcolor());
434c435
< addvertex(x1+pager_->slope(), up_pos );
---
> addvertex(x1, up_pos );
436c437
< addvertex(x2+pager_->slope(), H+eat_border_factor);
---
> addvertex(x2, H+eat_border_factor);
439,440c440,441
< drawline(x1, H, x1+pager_->slope(), up_pos );
< drawline(x1+pager_->slope(), up_pos , x2, up_pos );
---
> drawline(x1, H, x1, up_pos );
> drawline(x1, up_pos , x2, up_pos );
443c444
< if (x2+pager_->slope() < w()-1) drawline(x2+pager_->slope(), H, w()-1, H);
---
> if (x2 < w()-1) drawline(x2, H, w()-1, H);
446c447
< drawline(x2, (1-sel)*shrink_factor , x2+pager_->slope(), H);
---
> drawline(x2, (1-sel)*shrink_factor , x2, H);
450c451
< addvertex(x1+pager_->slope(), h()-1-up_pos );
---
> addvertex(x1, h()-1-up_pos );
452c453
< addvertex(x2+pager_->slope(), h()+H-eat_border_factor);
---
> addvertex(x2, h()+H-eat_border_factor);
456c457
< addvertex(x1+pager_->slope(), h()-1-up_pos);
---
> addvertex(x1, h()-1-up_pos);
458c459
< addvertex(x2+pager_->slope(), h()+H-eat_border_factor);
---
> addvertex(x2, h()+H-eat_border_factor);
462c463
< if (x2+pager_->slope() < w()-1) drawline(x2+pager_->slope(), h()+H, w()-1, h()+H);
---
> if (x2 < w()-1) drawline(x2, h()+H, w()-1, h()+H);
465c466
< drawline(x1, h()+H, x1+pager_->slope(), h()-up_pos);
---
> drawline(x1, h()+H, x1, h()-up_pos);
468c469
< Rectangle r((what==TAB_LEFT ? x1 : x2-W)+(pager_->slope()+pager_->extra_space()/2),
---
> Rectangle r((what==TAB_LEFT ? x1 : x2-W)+(pager_->extra_space()/2),
470c471
< W-(pager_->slope()+pager_->extra_space()/2),
---
> W-(pager_->extra_space()/2),
474,475c475,477
< o->draw_label(r, (o->flags() & ~ALIGN_MASK)|ALIGN_CENTER);
< FLAT_BOX->draw_symbol_overlay(r);
---
> o->draw_label(r, ALIGN_CENTER);
> // if (sel && focused()) focusbox()->draw(r);
> FLAT_BOX->draw_symbol_overlay(r);
525c527
< // End of "$Id: TabGroup.cxx 7513 2010-04-15 17:19:27Z spitzak $".
---
> // End of "$Id: TabGroup.cxx 5575 2007-01-02 17:31:40Z spitzak $".
diff -r fltk-2.0.x-r7725_old/test/input.cxx fltk-2.0.x-r7725_new/test/input.cxx
101a102
> input[0]->blink_cursor(true);
106a108
> input[1]->blink_cursor(true);
108a111
> input[2]->blink_cursor(true);
110a114
> input[3]->blink_cursor(true);
112a117
> input[4]->blink_cursor(true);
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev