Skip to content

Commit d0d27b9

Browse files
committed
auto adjust pos & mouse event
1 parent 5cb53ec commit d0d27b9

19 files changed

+341
-33
lines changed

src/Edit/Interface/edit_complete.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/******************************************************************************
23
* MODULE : edit_complete.cpp
34
* DESCRIPTION: Tab completion
@@ -57,6 +58,7 @@ find_completions (drd_info drd, tree t, hashset<string>& h, string prefix= "") {
5758
static array<string>
5859
find_completions (drd_info drd, tree t, string prefix= "") {
5960
hashset<string> h;
61+
h->insert (string(""));
6062
find_completions (drd, t, h, prefix);
6163
return as_completions (h);
6264
}
@@ -132,34 +134,36 @@ edit_interface_rep::complete_start (string prefix, array<string> compls) {
132134
completion_prefix= prefix;
133135
completions = close_completions (compls);
134136
completion_pos = 0;
135-
bool visible;
136-
SERVER (get_completion_listbox_visible (visible))
137-
if (!visible) {
138-
// TODO: refactor this part to edit_interface_rep::show_completion_listbox
137+
{
138+
// TODO: ?refactor this part to edit_interface_rep::show_completion_listbox
139+
cout << "complete_start: "
140+
<< "completions=" << completions
141+
<< ", prefix=" << completion_prefix
142+
<< ", tp=" << tp
143+
<< ", et=" << et
144+
<< ", eb=" << eb
145+
<< LF;
139146
array<string> full_completions;
140147
for (int i= 0; i < N (completions); ++i) {
148+
cout << "complete_start: completions[" << i << "]=" << completions[i] << LF;
141149
string c= completions[i];
142-
if (c == completion_prefix) continue; // skip the prefix itself
143150
full_completions << (completion_prefix * c);
144151
}
145-
146152
path tp1= tp;
147153
for (int i= 0; i < N (prefix); ++i) {
148154
tp1= previous_valid (et, tp1);
149155
}
150-
151156
cursor cu= eb->find_check_cursor (tp1);
152-
// cout << "Prefix Cursor: " << cu->ox << ", " << cu->oy << LF;
153-
SI pos_x=
154-
((cu->ox - get_scroll_x () - 500) * magf + get_canvas_x ()) / 256;
155-
SI pos_y= -((cu->oy - 5000 - get_scroll_y ()) * magf) / 256;
156-
// TODO: 5000 is a magic number to add space between completion list box
157-
// and the text.
158-
// We need to find a better way to get the position
159-
160-
SERVER (show_completion_listbox (full_completions, pos_x, pos_y));
157+
cout << "show_completion_listbox: "
158+
<< "completions=" << full_completions
159+
<< ", cu->ox=" << cu->ox
160+
<< ", cu->oy=" << cu->oy
161+
<< ", magf=" << magf
162+
<< ", scroll_x=" << get_scroll_x ()
163+
<< ", scroll_y=" << get_scroll_y ()
164+
<< ", canvas_x=" << get_canvas_x () << LF;
165+
show_completion_listbox (tp, full_completions, cu, magf, get_scroll_x(), get_scroll_y(), get_canvas_x());
161166
}
162-
163167
insert_tree (completions[0]);
164168
complete_message ();
165169
beep ();
@@ -199,19 +203,20 @@ edit_interface_rep::complete_keypress (string key) {
199203

200204
if (key == "tab" || key == "down") {
201205
completion_pos++;
202-
SERVER (set_completion_listbox_next (true));
206+
completion_listbox_next (true);
203207
}
204208
else if (key == "S-tab" || key == "up") {
205209
completion_pos--;
206-
SERVER (set_completion_listbox_next (false));
210+
completion_listbox_next (false);
207211
}
208212
if (completion_pos < 0) completion_pos= N (completions) - 1;
209213
if (completion_pos >= N (completions)) completion_pos= 0;
210-
SERVER (set_completion_listbox_visible (true))
211214
string new_s= completions[completion_pos];
212215
remove (path_up (tp) * (end - N (old_s)), N (old_s));
213216
insert (path_up (tp) * (end - N (old_s)), new_s);
214217
complete_message ();
218+
apply_changes(); // sync eb, for calculating the new cursor position
219+
update_completion_listbox_position (et, eb, tp, magf, get_scroll_x(), get_scroll_y(), get_canvas_x(), completion_pos);
215220
return true;
216221
}
217222

@@ -268,6 +273,7 @@ edit_interface_rep::custom_complete (tree r) {
268273
int i, n= N (r);
269274
string prefix;
270275
array<string> compls;
276+
compls << string ("");
271277
for (i= 0; i < n; i++)
272278
if (is_atomic (r[i])) {
273279
string l= r[i]->label;

src/Edit/Interface/edit_interface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,3 +1095,8 @@ void
10951095
edit_interface_rep::handle_set_zoom_factor (double zoom) {
10961096
set_zoom_factor (zoom);
10971097
}
1098+
1099+
void
1100+
edit_interface_rep::handle_set_input_normal () {
1101+
set_input_normal ();
1102+
}

src/Edit/Interface/edit_interface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class edit_interface_rep : virtual public editor_rep {
234234
void handle_set_zoom_factor (double zoomf);
235235
void handle_clear (renderer win, SI x1, SI y1, SI x2, SI y2);
236236
void handle_repaint (renderer win, SI x1, SI y1, SI x2, SI y2);
237+
void handle_set_input_normal();
237238

238239
friend class interactive_command_rep;
239240
friend class tm_window_rep;

src/Edit/Interface/edit_mouse.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,10 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t,
563563
if (type == "move") mouse_message ("move", x, y);
564564

565565
if (type == "leave") set_pointer ("XC_top_left_arrow");
566-
if ((!move_like) && (type != "enter") && (type != "leave"))
566+
if ((!move_like) && (type != "enter") && (type != "leave")) {
567567
set_input_normal ();
568+
SERVER (set_completion_listbox_visible (false));
569+
}
568570
if (!is_nil (popup_win) && (type != "leave")) {
569571
set_visibility (popup_win, false);
570572
destroy_window_widget (popup_win);

src/Graphics/Gui/message.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum slot_id {
5454
SLOT_COMPLETION_LISTBOX_SHOW,
5555
SLOT_COMPLETION_LISTBOX_VISIBLE,
5656
SLOT_COMPLETION_LISTBOX_NEXT,
57+
SLOT_INPUT_MODE_NORMAL,
5758
SLOT_CANVAS,
5859
SLOT_SCROLLABLE,
5960
SLOT_CURSOR,
@@ -526,6 +527,11 @@ set_completion_listbox_next (widget w, bool next) {
526527
send<bool> (w, SLOT_COMPLETION_LISTBOX_NEXT, next);
527528
}
528529

530+
inline void
531+
set_input_mode_normal (widget w) {
532+
send (w, SLOT_INPUT_MODE_NORMAL);
533+
}
534+
529535
inline void
530536
get_scroll_position (widget w, SI& x, SI& y) {
531537
// get scroll position in a canvas

src/Graphics/Gui/widget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ slot_name (const slot s) {
5050
"SLOT_COMPLETION_LISTBOX_SHOW",
5151
"SLOT_COMPLETION_LISTBOX_VISIBLE",
5252
"SLOT_COMPLETION_LISTBOX_NEXT",
53+
"SLOT_INPUT_MODE_NORMAL",
5354
"SLOT_CANVAS",
5455
"SLOT_SCROLLABLE",
5556
"SLOT_CURSOR",

src/Plugins/Qt/QTMScrollView.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ void
187187
QTMScrollView::scrollContentsBy (int dx, int dy) {
188188
if (dx) p_origin.setX (p_origin.x () - dx);
189189
if (dy) p_origin.setY (p_origin.y () - dy);
190+
qDebug () << "QTMScrollView::scrollContentsBy: "
191+
<< "dx=" << dx << ", dy=" << dy
192+
<< ", new origin: " << p_origin.x () << ", " << p_origin.y ();
190193
}
191194

192195
bool

src/Plugins/Qt/QTMTreeModel.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "observer.hpp"
1919
#include "tree.hpp"
2020

21+
#define DETACHED (-5)
22+
2123
class QTMTreeModel;
2224

2325
/*! An observer to keep a tree in sync with a QTMTreeModel (QAbstractItemModel).
@@ -100,7 +102,6 @@ class QTMTreeModel : public QAbstractItemModel {
100102
static const char* bad_tree_data_exception;
101103
static const char* no_observer_exception;
102104

103-
static const int DETACHED= -5;
104105
// NOTE: for some reason using hashmap was resulting in overwritten values.
105106
// The very same code with QHash works ok. ?!?!
106107
// typedef hashmap<tree_label, hashmap <int, int> > roles_t;

src/Plugins/Qt/QTMWidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ QTMWidget::tm_widget () const {
8585

8686
void
8787
QTMWidget::scrollContentsBy (int dx, int dy) {
88+
//tm_widget() -> scroll_completion_listbox_by (dx, dy);
8889
QTMScrollView::scrollContentsBy (dx, dy);
89-
9090
the_gui->force_update ();
91+
tm_widget ()->scroll_completion_listbox_by(dx, dy);
9192
// we force an update of the internal state to be in sync with the moving
9293
// scrollbars
9394
}

0 commit comments

Comments
 (0)