2007-05-22 18:53:17 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-10-02 13:42:19 +04:00
|
|
|
* ede-desktop, desktop and icon manager
|
2007-05-22 18:53:17 +04:00
|
|
|
* Part of Equinox Desktop Environment (EDE).
|
2008-10-02 13:42:19 +04:00
|
|
|
* Copyright (c) 2006-2008 EDE Authors.
|
2007-05-22 18:53:17 +04:00
|
|
|
*
|
|
|
|
* This program is licensed under terms of the
|
|
|
|
* GNU General Public License version 2 or newer.
|
|
|
|
* See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
2008-09-15 15:00:23 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/Fl_Shared_Image.H>
|
|
|
|
#include <FL/Fl_Menu_Button.H>
|
|
|
|
#include <FL/x.H>
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
#include <edelib/Debug.h>
|
|
|
|
#include <edelib/IconTheme.h>
|
2007-09-03 16:26:58 +04:00
|
|
|
#include <edelib/MessageBox.h>
|
2007-07-02 14:28:18 +04:00
|
|
|
#include <edelib/Nls.h>
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-22 13:43:15 +04:00
|
|
|
#ifdef USE_SHAPE
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
#endif
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2008-10-02 13:42:19 +04:00
|
|
|
#include "ede-desktop.h"
|
2008-08-07 18:22:05 +04:00
|
|
|
#include "DesktopIcon.h"
|
|
|
|
#include "IconProperties.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
|
2008-08-10 21:49:38 +04:00
|
|
|
// minimal icon sizes
|
|
|
|
#define ICON_SIZE_MIN_W 48
|
|
|
|
#define ICON_SIZE_MIN_H 48
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
// spaces around box in case of large/small icons
|
|
|
|
#define OFFSET_W 16
|
|
|
|
#define OFFSET_H 16
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// label offset from icon y()+h(), so selection box can be drawn nicely
|
|
|
|
#define LABEL_OFFSET 2
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
static void rename_cb(Fl_Widget*, void* d);
|
|
|
|
static void props_cb(Fl_Widget*, void* d);
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2008-08-10 21:49:38 +04:00
|
|
|
static Fl_Menu_Item icon_menu[] = {
|
2007-07-02 14:28:18 +04:00
|
|
|
{_(" &Open "), 0, 0},
|
|
|
|
{_(" &Rename "), 0, rename_cb, 0},
|
|
|
|
{_(" &Delete "), 0, 0, 0, FL_MENU_DIVIDER},
|
2008-08-07 18:22:05 +04:00
|
|
|
{_(" &Properties "), 0, props_cb, 0},
|
2007-07-02 14:28:18 +04:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2008-08-10 21:49:38 +04:00
|
|
|
static Fl_Menu_Item icon_trash_menu[] = {
|
2007-07-02 14:28:18 +04:00
|
|
|
{_(" &Open "), 0, 0},
|
|
|
|
{_(" &Properties "), 0, 0, 0, FL_MENU_DIVIDER},
|
|
|
|
{_(" &Empty "), 0, 0},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
static void rename_cb(Fl_Widget*, void* d) {
|
2007-07-02 14:28:18 +04:00
|
|
|
DesktopIcon* di = (DesktopIcon*)d;
|
2008-08-07 18:22:05 +04:00
|
|
|
E_ASSERT(di != NULL);
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2007-09-03 16:26:58 +04:00
|
|
|
const char* new_name = edelib::input(_("New name"), di->label());
|
2007-07-02 14:28:18 +04:00
|
|
|
if(!new_name)
|
|
|
|
return;
|
|
|
|
if(new_name[0] == '\0')
|
|
|
|
return;
|
|
|
|
di->rename(new_name);
|
|
|
|
}
|
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
static void props_cb(Fl_Widget*, void* d) {
|
|
|
|
DesktopIcon* di = (DesktopIcon*)d;
|
|
|
|
E_ASSERT(di != NULL);
|
|
|
|
show_icon_properties_dialog(di);
|
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
|
2008-08-10 21:49:38 +04:00
|
|
|
Fl_Widget(is->x, is->y, ICON_SIZE_MIN_W, ICON_SIZE_MIN_H) {
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
E_ASSERT(gs != NULL);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
lwidth = lheight = 0;
|
|
|
|
focus = false;
|
2007-06-18 18:18:35 +04:00
|
|
|
micon = NULL;
|
2008-10-03 15:29:56 +04:00
|
|
|
darker_img = NULL;
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GlobalIconSettings is shared from desktop so we only
|
|
|
|
* reference it. On other hand IconSettings is not shared
|
|
|
|
* and we must construct a copy from given parameter
|
|
|
|
*/
|
2007-06-18 18:18:35 +04:00
|
|
|
globals = gs;
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
settings = new IconSettings;
|
2007-06-18 18:18:35 +04:00
|
|
|
settings->name = is->name;
|
|
|
|
settings->cmd = is->cmd;
|
|
|
|
settings->icon = is->icon;
|
2007-11-28 15:42:52 +03:00
|
|
|
settings->icon2 = is->icon2;
|
2007-06-18 18:18:35 +04:00
|
|
|
settings->type = is->type;
|
|
|
|
settings->key_name= is->key_name;
|
2007-07-02 14:28:18 +04:00
|
|
|
settings->full_path = is->full_path;
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
// x,y are not needed since x(), y() are filled with it
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
// setting fonts is TODO :P
|
|
|
|
#if 0
|
|
|
|
Fl::set_font((Fl_Font)20, "-windows-*-medium-r-*-*-14-*-*-*-*-*-*-*");
|
|
|
|
labelfont((Fl_Font)20);
|
|
|
|
#endif
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
label(settings->name.c_str());
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
imenu = new Fl_Menu_Button(0, 0, 0, 0);
|
|
|
|
if(settings->type == ICON_TRASH)
|
|
|
|
imenu->menu(icon_trash_menu);
|
|
|
|
else
|
|
|
|
imenu->menu(icon_menu);
|
|
|
|
|
2007-11-28 15:42:52 +03:00
|
|
|
load_icon(ICON_FACE_ONE);
|
2007-07-02 14:28:18 +04:00
|
|
|
fix_position(x(), y());
|
2007-06-29 15:22:29 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
//Use desktop color as color for icon background
|
|
|
|
color(bg);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
align(FL_ALIGN_WRAP);
|
2007-05-22 18:53:17 +04:00
|
|
|
update_label_size();
|
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
DesktopIcon::~DesktopIcon() {
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG("DesktopIcon::~DesktopIcon()\n");
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
if(settings)
|
|
|
|
delete settings;
|
2007-05-22 18:53:17 +04:00
|
|
|
if(micon)
|
|
|
|
delete micon;
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2008-10-03 15:29:56 +04:00
|
|
|
delete darker_img;
|
2007-07-02 14:28:18 +04:00
|
|
|
delete imenu;
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
2007-11-28 15:42:52 +03:00
|
|
|
void DesktopIcon::load_icon(int face) {
|
|
|
|
const char* ic = NULL;
|
|
|
|
|
|
|
|
if(face != ICON_FACE_TWO) {
|
|
|
|
if(!settings->icon.empty())
|
|
|
|
ic = settings->icon.c_str();
|
|
|
|
} else {
|
|
|
|
if(!settings->icon2.empty())
|
|
|
|
ic = settings->icon2.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ic)
|
|
|
|
return;
|
|
|
|
|
|
|
|
edelib::String ipath = edelib::IconTheme::get(ic, edelib::ICON_SIZE_HUGE);
|
|
|
|
if(ipath.empty()) {
|
2008-08-07 18:22:05 +04:00
|
|
|
ipath = edelib::IconTheme::get("empty", edelib::ICON_SIZE_HUGE);
|
|
|
|
E_DEBUG(E_STRLOC ": Didn't find '%s' icon, ", ic);
|
2008-08-10 21:49:38 +04:00
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
if(!ipath.empty()) {
|
|
|
|
E_DEBUG("loaded 'empty' instead\n");
|
|
|
|
} else {
|
|
|
|
E_DEBUG("balling out\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-11-28 15:42:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Image* img = Fl_Shared_Image::get(ipath.c_str());
|
|
|
|
if(!img) {
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG(E_STRLOC ": Unable to load %s\n", ipath.c_str());
|
2007-11-28 15:42:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int img_w = img->w();
|
|
|
|
int img_h = img->h();
|
|
|
|
|
|
|
|
// resize box if icon is larger
|
2008-08-10 21:49:38 +04:00
|
|
|
if(img_w > ICON_SIZE_MIN_W || img_h > ICON_SIZE_MIN_H)
|
2007-11-28 15:42:52 +03:00
|
|
|
size(img_w + OFFSET_W, img_h + OFFSET_H);
|
|
|
|
|
|
|
|
image(img);
|
2008-10-03 15:29:56 +04:00
|
|
|
|
|
|
|
// darker icon version for selection
|
|
|
|
delete darker_img;
|
|
|
|
darker_img = image()->copy(image()->w(), image()->h());
|
|
|
|
darker_img->color_average(FL_BLUE, 0.6);
|
2007-11-28 15:42:52 +03:00
|
|
|
}
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
void DesktopIcon::update_label_size(void) {
|
2007-11-06 17:33:19 +03:00
|
|
|
labelsize(globals->label_fontsize);
|
2007-05-22 18:53:17 +04:00
|
|
|
lwidth = globals->label_maxwidth;
|
|
|
|
lheight= 0;
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
/*
|
|
|
|
* make sure current font size/type is set (internaly to fltk)
|
|
|
|
* so fl_measure() can correctly calculate label width and height
|
|
|
|
*/
|
2007-07-02 14:28:18 +04:00
|
|
|
int old = fl_font();
|
|
|
|
int old_sz = fl_size();
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_font(labelfont(), labelsize());
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_measure(label(), lwidth, lheight, align());
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
fl_font(old, old_sz);
|
|
|
|
|
2007-06-28 18:31:14 +04:00
|
|
|
lwidth += 12;
|
|
|
|
lheight += 5;
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
void DesktopIcon::fix_position(int X, int Y) {
|
|
|
|
int dx, dy, dw, dh;
|
|
|
|
Desktop::instance()->area(dx, dy, dw, dh);
|
|
|
|
|
|
|
|
if(X < dx)
|
|
|
|
X = dx;
|
|
|
|
if(Y < dy)
|
|
|
|
Y = dy;
|
|
|
|
if(X + w() > dw)
|
|
|
|
X = (dx + dw) - w();
|
|
|
|
if(Y + h() > dh)
|
|
|
|
Y = (dy + dh) - h();
|
|
|
|
|
|
|
|
position(X, Y);
|
|
|
|
}
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
void DesktopIcon::drag(int x, int y, bool apply) {
|
|
|
|
if(!micon) {
|
|
|
|
micon = new MovableIcon(this);
|
2007-06-22 13:43:15 +04:00
|
|
|
#if USE_SHAPE
|
|
|
|
/*
|
|
|
|
* This is used to calculate correct window startup/ending
|
|
|
|
* position since icon is placed in the middle of the box.
|
|
|
|
*
|
|
|
|
* Opposite, window (shaped) will have small but noticeable 'jump off' and
|
|
|
|
* dropped icon position will not be at the exact place where was dropped.
|
|
|
|
*/
|
|
|
|
int ix, iy;
|
|
|
|
ix = iy = 0;
|
|
|
|
if(image()) {
|
|
|
|
ix = (w()/2) - (image()->w()/2);
|
|
|
|
iy = (h()/2) - (image()->h()/2);
|
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-22 13:43:15 +04:00
|
|
|
micon->position(micon->x() + ix, micon->y() + iy);
|
|
|
|
#endif
|
|
|
|
micon->show();
|
|
|
|
} else {
|
2008-08-07 18:22:05 +04:00
|
|
|
E_ASSERT(micon != NULL);
|
2007-06-22 13:43:15 +04:00
|
|
|
micon->position(x, y);
|
|
|
|
}
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
if(apply) {
|
2007-06-22 13:43:15 +04:00
|
|
|
#if USE_SHAPE
|
|
|
|
int ix, iy;
|
|
|
|
ix = iy = 0;
|
|
|
|
if(image()) {
|
|
|
|
ix = (w()/2) - (image()->w()/2);
|
|
|
|
iy = (h()/2) - (image()->h()/2);
|
|
|
|
}
|
2007-07-02 14:28:18 +04:00
|
|
|
fix_position(micon->x() - ix, micon->y() - iy);
|
2007-06-22 13:43:15 +04:00
|
|
|
#else
|
2007-07-02 14:28:18 +04:00
|
|
|
fix_position(micon->x(), micon->y());
|
2007-06-22 13:43:15 +04:00
|
|
|
#endif
|
2007-05-22 18:53:17 +04:00
|
|
|
delete micon;
|
2007-06-18 18:18:35 +04:00
|
|
|
micon = NULL;
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used only in Desktop::move_selection
|
|
|
|
int DesktopIcon::drag_icon_x(void) {
|
|
|
|
if(!micon)
|
|
|
|
return x();
|
2007-06-18 18:18:35 +04:00
|
|
|
else
|
2007-05-22 18:53:17 +04:00
|
|
|
return micon->x();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used only in Desktop::move_selection
|
|
|
|
int DesktopIcon::drag_icon_y(void) {
|
|
|
|
if(!micon)
|
|
|
|
return y();
|
|
|
|
else
|
|
|
|
return micon->y();
|
|
|
|
}
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
void DesktopIcon::rename(const char* str) {
|
|
|
|
if(!str)
|
|
|
|
return;
|
2008-10-02 16:16:04 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
if(settings->name == str)
|
|
|
|
return;
|
|
|
|
|
|
|
|
settings->name = str;
|
|
|
|
label(settings->name.c_str());
|
|
|
|
update_label_size();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2007-09-03 16:26:58 +04:00
|
|
|
const edelib::String& DesktopIcon::path(void) {
|
|
|
|
return settings->full_path;
|
|
|
|
}
|
|
|
|
|
2007-11-28 15:42:52 +03:00
|
|
|
int DesktopIcon::icon_type(void) {
|
|
|
|
return settings->type;
|
|
|
|
}
|
|
|
|
|
2008-10-03 15:29:56 +04:00
|
|
|
void DesktopIcon::use_icon1(void) {
|
2007-11-28 15:42:52 +03:00
|
|
|
load_icon(ICON_FACE_ONE);
|
|
|
|
fast_redraw();
|
|
|
|
}
|
|
|
|
|
2008-10-03 15:29:56 +04:00
|
|
|
void DesktopIcon::use_icon2(void) {
|
2007-11-28 15:42:52 +03:00
|
|
|
load_icon(ICON_FACE_TWO);
|
|
|
|
fast_redraw();
|
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
void DesktopIcon::fast_redraw(void) {
|
2007-07-02 14:28:18 +04:00
|
|
|
int wsz = w();
|
|
|
|
int xpos = x();
|
|
|
|
|
|
|
|
if(lwidth > w()) {
|
|
|
|
wsz = lwidth + 4;
|
|
|
|
xpos = x() - 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LABEL_OFFSET + 2 include selection box line height too; same for xpos
|
|
|
|
parent()->damage(FL_DAMAGE_ALL, xpos, y(), wsz, h() + lheight + LABEL_OFFSET + 2);
|
2007-06-18 18:18:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopIcon::draw(void) {
|
|
|
|
//draw_box(FL_UP_BOX, FL_BLACK);
|
|
|
|
|
|
|
|
if(image() && (damage() & FL_DAMAGE_ALL)) {
|
|
|
|
Fl_Image* im = image();
|
|
|
|
|
|
|
|
// center image in the box
|
|
|
|
int ix = (w()/2) - (im->w()/2);
|
|
|
|
int iy = (h()/2) - (im->h()/2);
|
|
|
|
ix += x();
|
|
|
|
iy += y();
|
|
|
|
|
2008-10-03 15:29:56 +04:00
|
|
|
// darker_img is always present if image() is present
|
|
|
|
if(is_focused())
|
|
|
|
darker_img->draw(ix, iy);
|
|
|
|
else
|
|
|
|
im->draw(ix, iy);
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
2007-06-26 20:33:25 +04:00
|
|
|
if(globals->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
|
2007-06-18 18:18:35 +04:00
|
|
|
int X = x() + w()-(w()/2)-(lwidth/2);
|
|
|
|
int Y = y() + h() + LABEL_OFFSET;
|
|
|
|
|
|
|
|
Fl_Color old = fl_color();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
if(!globals->label_transparent) {
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_color(globals->label_background);
|
|
|
|
fl_rectf(X, Y, lwidth, lheight);
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
int old_font = fl_font();
|
|
|
|
int old_font_sz = fl_size();
|
|
|
|
|
|
|
|
// draw with icon's font
|
|
|
|
fl_font(labelfont(), labelsize());
|
|
|
|
|
2007-06-28 18:31:14 +04:00
|
|
|
// pseudo-shadow
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_color(globals->label_foreground);
|
|
|
|
fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
// restore old font
|
|
|
|
fl_font(old_font, old_font_sz);
|
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
if(is_focused()) {
|
|
|
|
/*
|
|
|
|
* draw focused box on our way so later
|
|
|
|
* this can be used to draw customised boxes
|
|
|
|
*/
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_color(globals->label_foreground);
|
2007-06-28 18:31:14 +04:00
|
|
|
fl_line_style(FL_DOT);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_push_matrix();
|
|
|
|
fl_begin_loop();
|
|
|
|
fl_vertex(X,Y);
|
|
|
|
fl_vertex(X+lwidth,Y);
|
|
|
|
fl_vertex(X+lwidth,Y+lheight);
|
|
|
|
fl_vertex(X,Y+lheight);
|
|
|
|
fl_vertex(X,Y);
|
|
|
|
fl_end_loop();
|
|
|
|
fl_pop_matrix();
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
// revert to default line style
|
2007-06-18 18:18:35 +04:00
|
|
|
fl_line_style(0);
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
2007-05-23 16:43:50 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
// revert to old color whatever that be
|
|
|
|
fl_color(old);
|
2007-07-02 14:28:18 +04:00
|
|
|
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG(E_STRLOC ": DesktopIcon label redraw\n");
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DesktopIcon::handle(int event) {
|
2007-06-20 14:58:07 +04:00
|
|
|
switch(event) {
|
|
|
|
case FL_FOCUS:
|
|
|
|
case FL_UNFOCUS:
|
|
|
|
case FL_ENTER:
|
|
|
|
case FL_LEAVE:
|
|
|
|
return 1;
|
|
|
|
/*
|
|
|
|
* We have to handle FL_MOVE too, if want to get only once
|
|
|
|
* FL_ENTER when entered or FL_LEAVE when leaved.
|
|
|
|
*/
|
|
|
|
case FL_MOVE:
|
|
|
|
return 1;
|
|
|
|
case FL_PUSH:
|
2007-07-02 14:28:18 +04:00
|
|
|
if(Fl::event_button() == 3) {
|
|
|
|
// Fl_Menu_Item::popup() by default does not call callbacks
|
|
|
|
const Fl_Menu_Item* m = imenu->menu()->popup(Fl::event_x(), Fl::event_y());
|
|
|
|
if(m && m->callback())
|
|
|
|
m->do_callback(0, this);
|
|
|
|
}
|
2007-06-20 14:58:07 +04:00
|
|
|
return 1;
|
|
|
|
case FL_RELEASE:
|
|
|
|
if(Fl::event_clicks() > 0)
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG(E_STRLOC ": EXECUTE: %s\n", settings->cmd.c_str());
|
2007-06-20 14:58:07 +04:00
|
|
|
return 1;
|
2007-07-02 14:28:18 +04:00
|
|
|
|
|
|
|
case FL_DND_ENTER:
|
|
|
|
case FL_DND_DRAG:
|
|
|
|
case FL_DND_LEAVE:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case FL_DND_RELEASE:
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG(E_STRLOC ": FL_DND_RELEASE on icon\n");
|
2007-07-02 14:28:18 +04:00
|
|
|
return 1;
|
|
|
|
case FL_PASTE:
|
2008-08-07 18:22:05 +04:00
|
|
|
E_DEBUG(E_STRLOC ": FL_PASTE on icon with %s\n", Fl::event_text());
|
2007-07-02 14:28:18 +04:00
|
|
|
return 1;
|
2007-06-20 14:58:07 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-02 14:28:18 +04:00
|
|
|
return 0;
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
2007-06-22 13:43:15 +04:00
|
|
|
MovableIcon::MovableIcon(DesktopIcon* ic) : Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0) {
|
2008-08-07 18:22:05 +04:00
|
|
|
E_ASSERT(icon != NULL);
|
2007-05-22 18:53:17 +04:00
|
|
|
|
|
|
|
set_override();
|
2007-06-18 18:18:35 +04:00
|
|
|
color(ic->color());
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
begin();
|
2007-06-20 14:58:07 +04:00
|
|
|
/*
|
|
|
|
* Force box be same width/height as icon so it
|
|
|
|
* can fit inside masked window.
|
|
|
|
*/
|
2007-06-22 13:43:15 +04:00
|
|
|
#ifdef USE_SHAPE
|
|
|
|
Fl_Image* img = ic->icon_image();
|
|
|
|
if(img)
|
|
|
|
icon_box = new Fl_Box(0, 0, img->w(), img->h());
|
|
|
|
else
|
|
|
|
icon_box = new Fl_Box(0, 0, w(), h());
|
2007-06-20 14:58:07 +04:00
|
|
|
#else
|
2007-06-18 18:18:35 +04:00
|
|
|
icon_box = new Fl_Box(0, 0, w(), h());
|
2007-06-20 14:58:07 +04:00
|
|
|
#endif
|
2007-06-18 18:18:35 +04:00
|
|
|
icon_box->image(ic->icon_image());
|
|
|
|
end();
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 18:18:35 +04:00
|
|
|
MovableIcon::~MovableIcon() {
|
2007-06-22 13:43:15 +04:00
|
|
|
if(mask)
|
|
|
|
XFreePixmap(fl_display, mask);
|
2007-06-18 18:18:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovableIcon::show(void) {
|
|
|
|
if(!shown())
|
|
|
|
Fl_X::make_xid(this);
|
2007-06-20 14:58:07 +04:00
|
|
|
|
2007-06-22 13:43:15 +04:00
|
|
|
#ifdef USE_SHAPE
|
|
|
|
if(icon->icon_image()) {
|
|
|
|
mask = create_mask(icon->icon_image());
|
2008-01-15 17:42:44 +03:00
|
|
|
if(mask) {
|
2007-06-22 13:43:15 +04:00
|
|
|
XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0, mask, ShapeSet);
|
2008-01-15 17:42:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now set transparency; composite manager should handle the rest (if running)
|
|
|
|
* TODO: should this be declared as part of the class ?
|
|
|
|
*/
|
|
|
|
Atom opacity_atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False);
|
|
|
|
unsigned int opacity = 0xc0000000;
|
|
|
|
XChangeProperty(fl_display, fl_xid(this), opacity_atom, XA_CARDINAL, 32, PropModeReplace,
|
|
|
|
(unsigned char*)&opacity, 1L);
|
|
|
|
}
|
2007-06-22 13:43:15 +04:00
|
|
|
}
|
2007-06-18 18:18:35 +04:00
|
|
|
#endif
|
2007-05-22 18:53:17 +04:00
|
|
|
}
|