summaryrefslogtreecommitdiff
path: root/fluid/widgets/Bin_Button.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-03-07 18:54:03 +0100
committerMatthias Melcher <github@matthiasm.com>2025-03-07 18:54:24 +0100
commitc3571838cb10133aa913efd7523b9543a65459c1 (patch)
tree6820fd1e11ce523d76f4f0580c3fa7d8072dcec8 /fluid/widgets/Bin_Button.cxx
parent89f714cb4eac968c94925ee2e9629649033ef372 (diff)
Fluid: Rebuilding most of the widget directory.
One file per logical unit. Namespaces. Non-static data member initializers to never get an uninitialized field again.
Diffstat (limited to 'fluid/widgets/Bin_Button.cxx')
-rw-r--r--fluid/widgets/Bin_Button.cxx128
1 files changed, 128 insertions, 0 deletions
diff --git a/fluid/widgets/Bin_Button.cxx b/fluid/widgets/Bin_Button.cxx
new file mode 100644
index 000000000..cc351085d
--- /dev/null
+++ b/fluid/widgets/Bin_Button.cxx
@@ -0,0 +1,128 @@
+//
+// Widget Bin Button code for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2025 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// https://www.fltk.org/COPYING.php
+//
+// Please see the following page on how to report bugs and issues:
+//
+// https://www.fltk.org/bugs.php
+//
+
+#include "widgets/Bin_Button.h"
+
+#include "app/fluid.h"
+#include "nodes/factory.h"
+#include "nodes/Fl_Window_Type.h"
+#include "widgets/widget_browser.h"
+
+#include <FL/Fl_Button.H>
+#include <FL/Fl_Window.H>
+
+using namespace fld;
+using namespace fld::widget;
+
+
+/** \class fld::widget::Bin_Button
+ The Bin_Button button is a button that can be used in the widget bin to
+ allow the user to drag and drop widgets into a window or group. This feature
+ makes it easy for the user to position a widget at a specific location within
+ the window or group.
+ */
+
+/**
+ Convert mouse dragging into a drag and drop event.
+ */
+int fld::widget::Bin_Button::handle(int inEvent)
+{
+ int ret = 0;
+ switch (inEvent) {
+ case FL_PUSH:
+ Fl_Button::handle(inEvent);
+ return 1; // make sure that we get drag events
+ case FL_DRAG:
+ ret = Fl_Button::handle(inEvent);
+ if (!user_data())
+ return ret;
+ if (!Fl::event_is_click()) { // make it a dnd event
+ // fake a drag outside of the widget
+ Fl::e_x = x()-1;
+ Fl_Button::handle(inEvent);
+ // fake a button release
+ Fl_Button::handle(FL_RELEASE);
+ // make it into a dnd event
+ const char *type_name = (const char*)user_data();
+ Fl_Type::current_dnd = Fl_Type::current;
+ Fl::copy(type_name, (int)strlen(type_name)+1, 0);
+ Fl::dnd();
+ return 1;
+ }
+ return ret;
+ }
+ return Fl_Button::handle(inEvent);
+}
+
+/** \class fld::widget::Bin_Window_Button
+ The Bin_Window_Button button is used in the widget bin to create new
+ windows by dragging and dropping. When the button is dragged and dropped onto
+ the desktop, a new window will be created at the drop location.
+
+ This does not work in Wayland because Wayland does not allow client
+ applications to control window placement.
+ */
+
+/**
+ Convert mouse dragging into a drag and drop event.
+ */
+int fld::widget::Bin_Window_Button::handle(int inEvent)
+{
+ static Fl_Window *drag_win = NULL;
+ int ret = 0;
+ switch (inEvent) {
+ case FL_PUSH:
+ Fl_Button::handle(inEvent);
+ return 1; // make sure that we get drag events
+ case FL_DRAG:
+ ret = Fl_Button::handle(inEvent);
+ if (!user_data())
+ return ret;
+ if (!Fl::event_is_click()) {
+ if (!drag_win) {
+ drag_win = new Fl_Window(0, 0, 480, 320);
+ drag_win->border(0);
+ drag_win->set_non_modal();
+ }
+ if (drag_win) {
+ drag_win->position(Fl::event_x_root()+1, Fl::event_y_root()+1);
+ drag_win->show();
+ }
+ // Does not work outside window: fl_cursor(FL_CURSOR_HAND);
+ }
+ return ret;
+ case FL_RELEASE:
+ if (drag_win) {
+ Fl::delete_widget(drag_win);
+ drag_win = NULL;
+ // create a new window here
+ Fl_Type *prototype = typename_to_prototype((char*)user_data());
+ if (prototype) {
+ Fl_Type *new_type = add_new_widget_from_user(prototype, Strategy::AFTER_CURRENT);
+ if (new_type && new_type->is_a(ID_Window)) {
+ Fl_Window_Type *new_window = (Fl_Window_Type*)new_type;
+ Fl_Window *w = (Fl_Window *)new_window->o;
+ w->position(Fl::event_x_root(), Fl::event_y_root());
+ }
+ }
+ widget_browser->display(Fl_Type::current);
+ widget_browser->rebuild();
+ }
+ return Fl_Button::handle(inEvent);
+ }
+ return Fl_Button::handle(inEvent);
+}
+