2007-05-22 18:53:17 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2013-05-30 17:07:49 +04:00
|
|
|
* Copyright (C) 2006-2013 Sanel Zukan
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-05-22 18:53:17 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
#ifndef __DESKTOP_ICON_H__
|
|
|
|
#define __DESKTOP_ICON_H__
|
2007-05-22 18:53:17 +04:00
|
|
|
|
2008-09-15 15:00:23 +04:00
|
|
|
#include <FL/Fl_Widget.H>
|
|
|
|
#include <FL/Fl_Image.H>
|
2009-07-09 17:44:16 +04:00
|
|
|
#include <edelib/MenuButton.h>
|
2013-05-30 17:07:49 +04:00
|
|
|
#include <edelib/String.h>
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DESKTOP_ICON_TYPE_NORMAL,
|
|
|
|
DESKTOP_ICON_TYPE_TRASH,
|
|
|
|
DESKTOP_ICON_TYPE_LINK,
|
|
|
|
DESKTOP_ICON_TYPE_FILE,
|
|
|
|
DESKTOP_ICON_TYPE_FOLDER
|
|
|
|
};
|
|
|
|
|
|
|
|
/* default icon sizes */
|
|
|
|
#define DESKTOP_ICON_SIZE_W 48
|
|
|
|
#define DESKTOP_ICON_SIZE_H 48
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each DesktopIcon shares IconOptions, which is content of [Icons] section
|
|
|
|
* from configuration file. With this, 'Desktop' needs only to update content so all
|
|
|
|
* icons see it.
|
|
|
|
*/
|
|
|
|
struct IconOptions {
|
|
|
|
int label_background;
|
|
|
|
int label_foreground;
|
|
|
|
int label_font;
|
|
|
|
int label_fontsize;
|
|
|
|
int label_maxwidth;
|
|
|
|
int label_transparent;
|
|
|
|
int label_visible;
|
|
|
|
bool one_click_exec;
|
2013-06-06 13:48:01 +04:00
|
|
|
|
|
|
|
IconOptions() {
|
|
|
|
label_background = FL_BLACK;
|
|
|
|
label_foreground = FL_WHITE;
|
|
|
|
label_maxwidth = 75;
|
|
|
|
label_transparent = 1;
|
|
|
|
label_visible = 1;
|
|
|
|
label_font = FL_HELVETICA;
|
|
|
|
label_fontsize = 12;
|
|
|
|
one_click_exec = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* should be called only when values are assigned to fonts */
|
|
|
|
void sanitize_font(void) {
|
|
|
|
if(label_font < 0) label_font = FL_HELVETICA;
|
|
|
|
if(label_fontsize < 8) label_fontsize = 12;
|
|
|
|
if(label_maxwidth < 30) label_maxwidth = 75;
|
|
|
|
}
|
2013-05-30 17:07:49 +04:00
|
|
|
};
|
2008-08-07 18:22:05 +04:00
|
|
|
|
2007-05-22 18:53:17 +04:00
|
|
|
class MovableIcon;
|
|
|
|
|
2007-06-20 14:58:07 +04:00
|
|
|
class DesktopIcon : public Fl_Widget {
|
2009-02-26 14:15:27 +03:00
|
|
|
private:
|
2013-05-30 17:07:49 +04:00
|
|
|
int icon_type;
|
|
|
|
int lwidth, lheight;
|
|
|
|
bool focused;
|
2009-02-26 14:15:27 +03:00
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
Fl_Image *darker_img;
|
|
|
|
IconOptions *opts;
|
|
|
|
MovableIcon *micon;
|
2009-02-26 14:15:27 +03:00
|
|
|
|
2014-02-25 22:16:10 +04:00
|
|
|
/* location of .desktop file */
|
|
|
|
EDELIB_NS_PREPEND(String) path;
|
2013-05-30 17:07:49 +04:00
|
|
|
EDELIB_NS_PREPEND(MenuButton) *imenu;
|
|
|
|
|
2013-10-29 03:42:40 +04:00
|
|
|
#if !((FL_MAJOR_VERSION >= 1) && (FL_MINOR_VERSION >= 3))
|
|
|
|
EDELIB_NS_PREPEND(String) ttip;
|
|
|
|
#endif
|
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
public:
|
|
|
|
DesktopIcon(const char *l, int W = DESKTOP_ICON_SIZE_W, int H = DESKTOP_ICON_SIZE_H);
|
|
|
|
~DesktopIcon();
|
2009-02-26 14:15:27 +03:00
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
void set_icon_type(int c) { icon_type = c; }
|
|
|
|
int get_icon_type(void) { return icon_type;}
|
|
|
|
void set_image(const char *name);
|
2013-10-29 01:51:05 +04:00
|
|
|
void set_tooltip(const char *tip);
|
2009-02-26 14:15:27 +03:00
|
|
|
|
2011-11-09 18:08:11 +04:00
|
|
|
void update_label_font_and_size(void);
|
2009-02-26 14:15:27 +03:00
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
void set_options(IconOptions *o) {
|
|
|
|
opts = o;
|
|
|
|
update_label_font_and_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Here is implemented localy focus schema avoiding messy fltk one. Focus/unfocus is handled from Desktop. */
|
|
|
|
void do_focus(void) { focused = true; }
|
|
|
|
void do_unfocus(void) { focused = false; }
|
|
|
|
bool is_focused(void) { return focused; }
|
|
|
|
|
|
|
|
void set_path(const char *p) { path = p; }
|
|
|
|
const char *get_path(void) { return path.c_str(); }
|
2009-02-26 14:15:27 +03:00
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
void fix_position(int X, int Y);
|
2009-02-26 14:15:27 +03:00
|
|
|
void drag(int x, int y, bool apply);
|
|
|
|
int drag_icon_x(void);
|
|
|
|
int drag_icon_y(void);
|
|
|
|
|
|
|
|
/*
|
2013-05-30 17:07:49 +04:00
|
|
|
* This is 'enhanced' (in some sense) redraw(). Redrawing icon will not fully redraw label nor
|
|
|
|
* focus box, which laid outside icon box. It will use damage() on given region, but called from
|
|
|
|
* parent, so parent can redraw that region on itself (since label does not laid on any box)
|
2009-02-26 14:15:27 +03:00
|
|
|
*
|
2013-05-30 17:07:49 +04:00
|
|
|
* Alternative way would be to redraw the whole parent, but it is pretty unneeded and slow.
|
2009-02-26 14:15:27 +03:00
|
|
|
*/
|
|
|
|
void fast_redraw(void);
|
|
|
|
|
2013-05-30 17:07:49 +04:00
|
|
|
void draw(void);
|
|
|
|
int handle(int event);
|
2007-05-22 18:53:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|