[80] | 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 |
|
---|
| 9 | #ifndef TEXT_INPUT_HH
|
---|
| 10 | #define TEXT_INPUT_HH
|
---|
| 11 |
|
---|
| 12 | #include "window/window.hh"
|
---|
| 13 | #include "window/style.hh"
|
---|
| 14 | #include "string/string.hh"
|
---|
| 15 | #include "time/timedev.hh"
|
---|
| 16 |
|
---|
| 17 | class i4_text_change_notify_event : public i4_object_message_event_class
|
---|
| 18 | {
|
---|
| 19 | public:
|
---|
| 20 | i4_str *new_text;
|
---|
| 21 |
|
---|
| 22 | i4_text_change_notify_event(void *object,
|
---|
| 23 | i4_str *str)
|
---|
| 24 | : i4_object_message_event_class(object),
|
---|
| 25 | new_text(new i4_str(*str)) { }
|
---|
| 26 |
|
---|
| 27 | virtual i4_event *copy() { return new i4_text_change_notify_event(object, new_text); }
|
---|
| 28 | virtual dispatch_time when() { return NOW; }
|
---|
| 29 | ~i4_text_change_notify_event() { delete new_text; }
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | class i4_query_text_input_class : public i4_query_message_event_class
|
---|
| 34 | {
|
---|
| 35 | public:
|
---|
| 36 |
|
---|
| 37 | i4_str *copy_of_data;
|
---|
| 38 |
|
---|
| 39 | i4_query_text_input_class() { copy_of_data=0; }
|
---|
| 40 |
|
---|
| 41 | virtual i4_event *copy()
|
---|
| 42 | {
|
---|
| 43 | i4_query_text_input_class *t=new i4_query_text_input_class;
|
---|
| 44 | if (copy_of_data)
|
---|
| 45 | t->copy_of_data=new i4_str(*copy_of_data,copy_of_data->length()+1);
|
---|
| 46 | return t;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | ~i4_query_text_input_class()
|
---|
| 50 | {
|
---|
| 51 | if (copy_of_data)
|
---|
| 52 | delete copy_of_data;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | } ;
|
---|
| 56 |
|
---|
| 57 | class i4_text_input_class : public i4_window_class
|
---|
| 58 | {
|
---|
| 59 | protected:
|
---|
| 60 | i4_event_handler_class *change_notify;
|
---|
| 61 | i4_str *st;
|
---|
| 62 | i4_font_class *font;
|
---|
| 63 | int max_width;
|
---|
| 64 |
|
---|
| 65 | sw32 cursor_x; // position of the cursor
|
---|
| 66 | sw32 left_x; // how many characters to skip in string before drawing at left side
|
---|
| 67 |
|
---|
| 68 | i4_bool need_cancel_blink; // do we have a timer event currently?
|
---|
| 69 | i4_bool cursor_on; // this gets toggled by the timer event
|
---|
| 70 | i4_time_device_class::id blink_timer; // if we have a time ever scheduled
|
---|
| 71 | i4_bool selecting;
|
---|
| 72 | i4_coord last_x,last_y;
|
---|
| 73 | i4_bool changed, sent_change;
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | sw32 hi_x1, hi_x2; // hilight start and end
|
---|
| 77 | i4_graphical_style_class *style;
|
---|
| 78 | i4_bool selected;
|
---|
| 79 |
|
---|
| 80 | // this will find the character the mouse is on, this should work for non-constantly spaced
|
---|
| 81 | // character strings as well
|
---|
| 82 | w32 mouse_to_cursor();
|
---|
| 83 | void request_blink();
|
---|
| 84 | void stop_blink();
|
---|
| 85 | void sustain_cursor();
|
---|
| 86 | void del_selected();
|
---|
| 87 | void move_cursor_right();
|
---|
| 88 | void move_cursor_left();
|
---|
| 89 | void move_cursor_end();
|
---|
| 90 |
|
---|
| 91 | virtual void draw_deco(i4_draw_context_class &context);
|
---|
| 92 | void become_active();
|
---|
| 93 | void become_unactive();
|
---|
| 94 |
|
---|
| 95 | void note_change()
|
---|
| 96 | {
|
---|
| 97 | changed=i4_T;
|
---|
| 98 | sent_change=i4_F;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | public:
|
---|
| 102 | char *name() { return "text_input"; }
|
---|
| 103 |
|
---|
| 104 | void send_to_parent(i4_event *ev) { parent->receive_event(ev); }
|
---|
| 105 |
|
---|
| 106 | i4_text_input_class(i4_graphical_style_class *style,
|
---|
| 107 | const i4_const_str &default_string,
|
---|
| 108 | w32 width, // width in pixels of window
|
---|
| 109 | w32 max_width,
|
---|
| 110 | i4_event_handler_class *change_notify=0,
|
---|
| 111 | i4_font_class *font=0); // uses style->normal_font by default
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | virtual void draw(i4_draw_context_class &context);
|
---|
| 116 | virtual void receive_event(i4_event *ev);
|
---|
| 117 |
|
---|
| 118 | void change_text(const i4_const_str &new_st);
|
---|
| 119 | i4_str *get_edit_string() { return st; } // don't delete this return string!
|
---|
| 120 | sw32 get_number(); // assuming text is a proper numbe
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | ~i4_text_input_class();
|
---|
| 124 | } ;
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | i4_window_class *i4_create_text_input(i4_graphical_style_class *style,
|
---|
| 128 | const i4_const_str &default_string,
|
---|
| 129 | w32 width, // width in pixels of window
|
---|
| 130 | w32 max_width);
|
---|
| 131 |
|
---|
| 132 | #endif
|
---|
| 133 |
|
---|