From c951b708ce6e8885f4987e1d98524b31b7e057cc Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Sat, 23 Jun 2007 11:31:36 +0000 Subject: [PATCH] DND stuff (unfinished). --- eiconman/DesktopIcon.cpp | 23 +++++++++++--------- eiconman/Wallpaper.cpp | 37 ++++++++++++++++++++++++++++++- eiconman/Wallpaper.h | 1 + eiconman/eiconman.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ eiconman/eiconman.h | 2 ++ 5 files changed, 99 insertions(+), 11 deletions(-) diff --git a/eiconman/DesktopIcon.cpp b/eiconman/DesktopIcon.cpp index 7514f0c..9ec0869 100644 --- a/eiconman/DesktopIcon.cpp +++ b/eiconman/DesktopIcon.cpp @@ -71,18 +71,21 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) : //edelib::String ipath = edelib::IconTheme::get(nn, edelib::ICON_SIZE_MEDIUM); edelib::String ipath = edelib::IconTheme::get(nn, edelib::ICON_SIZE_HUGE); - Fl_Image* img = Fl_Shared_Image::get(ipath.c_str()); - if(img) { - int img_w = img->w(); - int img_h = img->h(); + if(!ipath.empty()) { + Fl_Image* img = Fl_Shared_Image::get(ipath.c_str()); + if(img) { + int img_w = img->w(); + int img_h = img->h(); - // resize box if icon is larger - if(img_w > ICONSIZE || img_h > ICONSIZE) - size(img_w + OFFSET_W, img_h + OFFSET_H); + // resize box if icon is larger + if(img_w > ICONSIZE || img_h > ICONSIZE) + size(img_w + OFFSET_W, img_h + OFFSET_H); - image(img); - } else - EDEBUG(ESTRLOC ": Unable to load %s\n", ipath.c_str()); + image(img); + } else + EDEBUG(ESTRLOC ": Unable to load %s\n", ipath.c_str()); + } else + EDEBUG(ESTRLOC ": Got empty icon name ?!?\n"); } /* EDEBUG(ESTRLOC ": Got label: %s\n", label()); diff --git a/eiconman/Wallpaper.cpp b/eiconman/Wallpaper.cpp index bb37cbb..24441c7 100644 --- a/eiconman/Wallpaper.cpp +++ b/eiconman/Wallpaper.cpp @@ -103,7 +103,7 @@ Pixmap create_xpixmap(Fl_Image* img, XImage* xim, Pixmap pix) { else if(fl_visual->depth > 8) bitmap_pad = 16; else { - EWARNING("Visual %i not supported\n", xim->bits_per_pixel); + EWARNING(ESTRLOC ": Visual %i not supported\n", xim->bits_per_pixel); XDestroyImage(xim); xim = 0; @@ -429,3 +429,38 @@ void Wallpaper::draw(void) { } #endif } + +#include + +int Wallpaper::handle(int event) { + switch(event) { + /* + * Route all DND events to parent (desktop), otherwise + * desktop will not get them if Wallpaper is visible + */ + case FL_DND_ENTER: + case FL_DND_DRAG: + case FL_DND_LEAVE: + case FL_DND_RELEASE: + return parent()->handle(event); + + case FL_PASTE: + /* + * Since some stuff are in fltk unnedededly complicated, like + * DND, this is needed to make it correctly work. After we got + * FL_PASTE event (drag'n drop content released), that content + * is routed to CLIPBOARD buffer of Desktop and in turn will trigger + * FL_PASTE on Desktop. + * + * This is since fltk use XA_PRIMARY as default (or selection clipboard from X11) + * not CLIPBOARD (as rest of normal world). + * + * Also, to make DND workable for Desktop, Wallpaper widget must be + * always visible. + */ + Fl::paste(*parent(), 1); + return 1; + } + + return Fl_Box::handle(event); +} diff --git a/eiconman/Wallpaper.h b/eiconman/Wallpaper.h index f3507fe..7a9c2ec 100644 --- a/eiconman/Wallpaper.h +++ b/eiconman/Wallpaper.h @@ -37,6 +37,7 @@ class Wallpaper : public Fl_Box { bool set(const char* path); bool set_tiled(const char* path); virtual void draw(void); + virtual int handle(int event); }; #endif diff --git a/eiconman/eiconman.cpp b/eiconman/eiconman.cpp index 207ccf6..d1a390b 100644 --- a/eiconman/eiconman.cpp +++ b/eiconman/eiconman.cpp @@ -121,6 +121,8 @@ Desktop::Desktop() : Fl_Window(0, 0, 100, 100, "") { begin(); wallpaper = new Wallpaper(0, 0, w(), h()); wallpaper->set("/home/sanel/wallpapers/katebig.jpg"); + //wallpaper->hide(); + //wallpaper->set("/home/sanelz/walls/katebig.jpg"); //wallpaper->set("/home/sanelz/walls/nin/1024x768-04.jpg"); //wallpaper->set("/home/sanelz/walls/nin/1024x768-02.jpg"); notify = new NotifyBox(w(), h()); @@ -168,6 +170,8 @@ void Desktop::show(void) { Fl_X::make_xid(this); net_make_me_desktop(this); } + + //Fl::dnd_text_ops(1); } /* @@ -307,6 +311,7 @@ void Desktop::load_icons(const char* path, edelib::Config& conf) { } else { // then try to figure out it's mime; if fails, ignore it if(mt.set(full_path.c_str())) { + EDEBUG(ESTRLOC ": Loading icon as mime-type %s\n", mt.icon_name().c_str()); is.icon = mt.icon_name(); // icon label is name of file is.name = name; @@ -572,6 +577,34 @@ void Desktop::notify_desktop_changed(void) { XFreeStringList(names); } +void Desktop::drop_source(const char* src, int x, int y) { + if(!src) + return; + IconSettings is; + is.x = x; + is.y = y; + + // absolute path is (for now) seen as non-url + if(src[0] == '/') + is.cmd_is_url = false; + else + is.cmd_is_url = true; + + is.name = get_basename(src); + is.cmd = "(none)"; + is.type = ICON_NORMAL; + + edelib::MimeType mt; + if(!mt.set(src)) { + EWARNING(ESTRLOC ": MimeType for %s failed, not dropping icon\n", src); + return; + } + + is.icon = mt.icon_name(); + DesktopIcon* dic = new DesktopIcon(&gisett, &is, color()); + add_icon(dic); +} + int Desktop::handle(int event) { switch(event) { case FL_FOCUS: @@ -675,6 +708,20 @@ int Desktop::handle(int event) { moving = false; return 1; + case FL_DND_ENTER: + case FL_DND_DRAG: + case FL_DND_LEAVE: + return 1; + + case FL_DND_RELEASE: + EDEBUG(ESTRLOC ": DND on desktop\n"); + return 1; + + case FL_PASTE: + EDEBUG("================> PASTE: %s\n", Fl::event_text()); + drop_source(Fl::event_text(), Fl::event_x_root(), Fl::event_y_root()); + return 1; + default: break; } diff --git a/eiconman/eiconman.h b/eiconman/eiconman.h index e52c72a..8f33b1c 100644 --- a/eiconman/eiconman.h +++ b/eiconman/eiconman.h @@ -98,6 +98,8 @@ class Desktop : public Fl_Window { bool in_selection(const DesktopIcon* ic); void move_selection(int x, int y, bool apply); + void drop_source(const char* src, int x, int y); + //DesktopIcon* below_mouse(int px, int py); public: