diff options
| author | Matthias Melcher <git@matthiasm.com> | 2021-12-11 19:43:00 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2021-12-13 18:17:07 +0100 |
| commit | 160832ce04f932fbb3df199aa01d1c93148bb292 (patch) | |
| tree | d1ce303700666997a8608b7a488a25e633f07804 /fluid/Fl_Window_Type.cxx | |
| parent | a802aaeb170e3c233c5d92ae29d8703a0b9c2768 (diff) | |
STR 3442: copy/paste now inserts widget as expected.
Fluid would add pasted widgets as the last child of the
current group, even if they were cut at the beginning
of the group. This patch adds a 'startegy' to adding
widgets to allow merging closer to the 'current' widget.
Also added d'n'd for the widget bin and some other
UI improvements.
STR 3442: some preparation, variable renaming
STR 3442: unifying functions to add widgets.
Adding widgets interactively is merged into one function,
making undo/redo work as expected and removing
unexpected differences between adding by menu or bin.
STR 3442: adding drag'n'drop for windows from bin.
Just drag the window symbol out of the tree and drop it anywhere
on the desktop.
Visual representation of dragged Window.
STR 3442: insert individual nodes after 'current'
STR 3442: adding new widget at expected positions.
The widget bin can finally do drag'n'drop.
Widgets appear in the tree close to the last selection.
Duplicating now ads right below.
Cut and paste inserts after last selection.
Fluid: replaced #define with strict enum type.
Diffstat (limited to 'fluid/Fl_Window_Type.cxx')
| -rw-r--r-- | fluid/Fl_Window_Type.cxx | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/fluid/Fl_Window_Type.cxx b/fluid/Fl_Window_Type.cxx index 8f718ff05..21eefe868 100644 --- a/fluid/Fl_Window_Type.cxx +++ b/fluid/Fl_Window_Type.cxx @@ -27,6 +27,7 @@ #include "file.h" #include "code.h" #include "widget_panel.h" +#include "factory.h" #include <FL/Fl.H> #include <FL/Fl_Overlay_Window.H> @@ -349,7 +350,12 @@ int Overlay_Window::handle(int e) { return ret; } -Fl_Type *Fl_Window_Type::make() { +/** + Make and add a new WIndow node. + \param[in] strategy is kAddAsLastChild or kAddAfterCurrent + \return new node + */ +Fl_Type *Fl_Window_Type::make(Strategy strategy) { Fl_Type *p = Fl_Type::current; while (p && !p->is_code_block()) p = p->parent; if (!p) { @@ -372,7 +378,7 @@ Fl_Type *Fl_Window_Type::make() { Overlay_Window *w = new Overlay_Window(100,100); w->window = myo; myo->o = w; - myo->add(p); + myo->add(p, strategy); myo->modal = 0; myo->non_modal = 0; return myo; @@ -1181,8 +1187,60 @@ int Fl_Window_Type::popupx = 0x7FFFFFFF; // mark as invalid (MAXINT) int Fl_Window_Type::popupy = 0x7FFFFFFF; int Fl_Window_Type::handle(int event) { - static Fl_Type* selection; + static Fl_Type* selection = NULL; switch (event) { + case FL_DND_ENTER: + Fl::belowmouse(o); + case FL_DND_DRAG: + { + // find the innermost item clicked on: + selection = this; + for (Fl_Type* i=next; i && i->level>level; i=i->next) + if (i->is_group()) { + Fl_Widget_Type* myo = (Fl_Widget_Type*)i; + for (Fl_Widget *o1 = myo->o; o1; o1 = o1->parent()) + if (!o1->visible()) goto CONTINUE_DND; + if (Fl::event_inside(myo->o)) { + selection = myo; + if (Fl::event_clicks()==1) + reveal_in_browser(myo); + } + } + CONTINUE_DND: + if (selection && !selection->selected) { + select_only(selection); + ((Overlay_Window *)o)->redraw_overlay(); + } + } + case FL_DND_RELEASE: + return 1; + case FL_PASTE: + { Fl_Type *prototype = typename_to_prototype(Fl::event_text()); + if (prototype==NULL) + return 0; + + in_this_only = this; + popupx = Fl::event_x(); + popupy = Fl::event_y(); + // If the selected widget at dnd start and the drop target are the same, + // or in the same group, add after selection. Otherwise, just add + // at the end of the selected group. + if ( Fl_Type::current_dnd->group() + && selection->group() + && Fl_Type::current_dnd->group()==selection->group()) + { + Fl_Type *cc = Fl_Type::current; + Fl_Type::current = Fl_Type::current_dnd; + add_new_widget_from_user(prototype, kAddAfterCurrent); + Fl_Type::current = cc; + } else { + add_new_widget_from_user(prototype, kAddAsLastChild); + } + popupx = 0x7FFFFFFF; + popupy = 0x7FFFFFFF; // mark as invalid (MAXINT) + in_this_only = NULL; + return 1; + } case FL_PUSH: x1 = mx = Fl::event_x(); y1 = my = Fl::event_y(); @@ -1439,7 +1497,12 @@ int Fl_Window_Type::read_fdesign(const char* propname, const char* value) { Fl_Widget_Class_Type Fl_Widget_Class_type; Fl_Widget_Class_Type *current_widget_class = 0; -Fl_Type *Fl_Widget_Class_Type::make() { +/** + Create and add a new Widget Class node. + \param[in] strategy add after current or as last child + \return new node + */ +Fl_Type *Fl_Widget_Class_Type::make(Strategy strategy) { Fl_Type *p = Fl_Type::current; while (p && (!p->is_decl_block() || (p->is_widget() && p->is_class()))) p = p->parent; Fl_Widget_Class_Type *myo = new Fl_Widget_Class_Type(); @@ -1460,7 +1523,7 @@ Fl_Type *Fl_Widget_Class_Type::make() { Overlay_Window *w = new Overlay_Window(100,100); w->window = myo; myo->o = w; - myo->add(p); + myo->add(p, strategy); myo->modal = 0; myo->non_modal = 0; myo->wc_relative = 0; |
