text_input.hh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #ifndef TEXT_INPUT_HH
  9. #define TEXT_INPUT_HH
  10. #include "window/window.hh"
  11. #include "window/style.hh"
  12. #include "string/string.hh"
  13. #include "time/timedev.hh"
  14. class i4_text_change_notify_event : public i4_object_message_event_class
  15. {
  16. public:
  17. i4_str *new_text;
  18. i4_text_change_notify_event(void *object,
  19. i4_str *str)
  20. : i4_object_message_event_class(object),
  21. new_text(new i4_str(*str)) { }
  22. virtual i4_event *copy() { return new i4_text_change_notify_event(object, new_text); }
  23. virtual dispatch_time when() { return NOW; }
  24. ~i4_text_change_notify_event() { delete new_text; }
  25. };
  26. class i4_query_text_input_class : public i4_query_message_event_class
  27. {
  28. public:
  29. i4_str *copy_of_data;
  30. i4_query_text_input_class() { copy_of_data=0; }
  31. virtual i4_event *copy()
  32. {
  33. i4_query_text_input_class *t=new i4_query_text_input_class;
  34. if (copy_of_data)
  35. t->copy_of_data=new i4_str(*copy_of_data,copy_of_data->length()+1);
  36. return t;
  37. }
  38. ~i4_query_text_input_class()
  39. {
  40. if (copy_of_data)
  41. delete copy_of_data;
  42. }
  43. } ;
  44. class i4_text_input_class : public i4_window_class
  45. {
  46. protected:
  47. i4_event_handler_class *change_notify;
  48. i4_str *st;
  49. i4_font_class *font;
  50. int max_width;
  51. sw32 cursor_x; // position of the cursor
  52. sw32 left_x; // how many characters to skip in string before drawing at left side
  53. i4_bool need_cancel_blink; // do we have a timer event currently?
  54. i4_bool cursor_on; // this gets toggled by the timer event
  55. i4_time_device_class::id blink_timer; // if we have a time ever scheduled
  56. i4_bool selecting;
  57. i4_coord last_x,last_y;
  58. i4_bool changed, sent_change;
  59. sw32 hi_x1, hi_x2; // hilight start and end
  60. i4_graphical_style_class *style;
  61. i4_bool selected;
  62. // this will find the character the mouse is on, this should work for non-constantly spaced
  63. // character strings as well
  64. w32 mouse_to_cursor();
  65. void request_blink();
  66. void stop_blink();
  67. void sustain_cursor();
  68. void del_selected();
  69. void move_cursor_right();
  70. void move_cursor_left();
  71. void move_cursor_end();
  72. virtual void draw_deco(i4_draw_context_class &context);
  73. void become_active();
  74. void become_unactive();
  75. void note_change()
  76. {
  77. changed=i4_T;
  78. sent_change=i4_F;
  79. }
  80. public:
  81. char *name() { return "text_input"; }
  82. void send_to_parent(i4_event *ev) { parent->receive_event(ev); }
  83. i4_text_input_class(i4_graphical_style_class *style,
  84. const i4_const_str &default_string,
  85. w32 width, // width in pixels of window
  86. w32 max_width,
  87. i4_event_handler_class *change_notify=0,
  88. i4_font_class *font=0); // uses style->normal_font by default
  89. virtual void draw(i4_draw_context_class &context);
  90. virtual void receive_event(i4_event *ev);
  91. void change_text(const i4_const_str &new_st);
  92. i4_str *get_edit_string() { return st; } // don't delete this return string!
  93. sw32 get_number(); // assuming text is a proper numbe
  94. ~i4_text_input_class();
  95. } ;
  96. i4_window_class *i4_create_text_input(i4_graphical_style_class *style,
  97. const i4_const_str &default_string,
  98. w32 width, // width in pixels of window
  99. w32 max_width);
  100. #endif