Again, replacing FLTK menus...

This commit is contained in:
Sanel Zukan 2009-07-09 13:44:16 +00:00
parent 4bc8027cb7
commit e147228f53
2 changed files with 38 additions and 32 deletions

View File

@ -17,7 +17,6 @@
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
#include <FL/Fl_Shared_Image.H> #include <FL/Fl_Shared_Image.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/x.H> #include <FL/x.H>
#include <edelib/Debug.h> #include <edelib/Debug.h>
@ -27,7 +26,7 @@
#include <edelib/Run.h> #include <edelib/Run.h>
#ifdef HAVE_SHAPE #ifdef HAVE_SHAPE
#include <X11/extensions/shape.h> # include <X11/extensions/shape.h>
#endif #endif
#include "ede-desktop.h" #include "ede-desktop.h"
@ -35,46 +34,54 @@
#include "IconProperties.h" #include "IconProperties.h"
#include "Utils.h" #include "Utils.h"
// minimal icon sizes /* minimal icon sizes */
#define ICON_SIZE_MIN_W 48 #define ICON_SIZE_MIN_W 48
#define ICON_SIZE_MIN_H 48 #define ICON_SIZE_MIN_H 48
// spaces around box in case of large/small icons /* spaces around box in case of large/small icons */
#define OFFSET_W 16 #define OFFSET_W 16
#define OFFSET_H 16 #define OFFSET_H 16
// label offset from icon y()+h(), so selection box can be drawn nicely /* label offset from icon y()+h(), so selection box can be drawn nicely */
#define LABEL_OFFSET 2 #define LABEL_OFFSET 2
EDELIB_NS_USING(String)
EDELIB_NS_USING(IconLoader)
EDELIB_NS_USING(MenuItem)
EDELIB_NS_USING(MenuButton)
EDELIB_NS_USING(ICON_SIZE_HUGE)
EDELIB_NS_USING(ICON_SIZE_TINY)
EDELIB_NS_USING(input)
EDELIB_NS_USING(run_async)
static void rename_cb(Fl_Widget*, void* d); static void rename_cb(Fl_Widget*, void* d);
static void props_cb(Fl_Widget*, void* d); static void props_cb(Fl_Widget*, void* d);
static Fl_Menu_Item icon_menu[] = { static MenuItem icon_menu[] = {
{_(" &Open "), 0, 0}, {_("&Open"), 0, 0},
{_(" &Rename "), 0, rename_cb, 0}, {_("&Rename"), 0, rename_cb, 0},
{_(" &Delete "), 0, 0, 0, FL_MENU_DIVIDER}, {_("&Delete"), 0, 0, 0, FL_MENU_DIVIDER},
{_(" &Properties "), 0, props_cb, 0}, {_("&Properties"), 0, props_cb, 0},
{0} {0}
}; };
static Fl_Menu_Item icon_trash_menu[] = { static MenuItem icon_trash_menu[] = {
{_(" &Open "), 0, 0}, {_("&Open"), 0, 0},
{_(" &Properties "), 0, 0, 0, FL_MENU_DIVIDER}, {_("&Properties"), 0, 0, 0, FL_MENU_DIVIDER},
{_(" &Empty "), 0, 0}, {_("&Empty"), 0, 0},
{0} {0}
}; };
static void rename_cb(Fl_Widget*, void* d) { static void rename_cb(Fl_Widget*, void* d) {
DesktopIcon* di = (DesktopIcon*)d; DesktopIcon* di = (DesktopIcon*)d;
E_ASSERT(di != NULL);
const char* new_name = edelib::input(_("New name"), di->label()); const char* new_name = input(_("New name"), di->label());
di->rename(new_name); di->rename(new_name);
} }
static void props_cb(Fl_Widget*, void* d) { static void props_cb(Fl_Widget*, void* d) {
DesktopIcon* di = (DesktopIcon*)d; DesktopIcon* di = (DesktopIcon*)d;
E_ASSERT(di != NULL);
show_icon_properties_dialog(di); show_icon_properties_dialog(di);
} }
@ -99,11 +106,13 @@ DesktopIcon::DesktopIcon(GlobalIconSettings* gs, IconSettings* is, int bg) :
label(settings->name.c_str()); label(settings->name.c_str());
imenu = new Fl_Menu_Button(0, 0, 0, 0); imenu = new MenuButton(0, 0, 0, 0);
if(settings->type == ICON_TRASH) if(settings->type == ICON_TRASH)
imenu->menu(icon_trash_menu); imenu->menu(icon_trash_menu);
else else {
icon_menu[2].image(IconLoader::get("edit-delete", ICON_SIZE_TINY));
imenu->menu(icon_menu); imenu->menu(icon_menu);
}
load_icon(ICON_FACE_ONE); load_icon(ICON_FACE_ONE);
fix_position(x(), y()); fix_position(x(), y());
@ -138,7 +147,7 @@ void DesktopIcon::load_icon(int face) {
if(!ic) if(!ic)
return; return;
if(!edelib::IconLoader::set(this, ic, edelib::ICON_SIZE_HUGE)) { if(!IconLoader::set(this, ic, ICON_SIZE_HUGE)) {
E_DEBUG(E_STRLOC ": Unable to load %s icon\n", ic); E_DEBUG(E_STRLOC ": Unable to load %s icon\n", ic);
return; return;
} }
@ -208,8 +217,7 @@ void DesktopIcon::drag(int x, int y, bool apply) {
* Opposite, window (shaped) will have small but noticeable 'jump off' and * Opposite, window (shaped) will have small but noticeable 'jump off' and
* dropped icon position will not be at the exact place where was dropped. * dropped icon position will not be at the exact place where was dropped.
*/ */
int ix, iy; int ix = 0, iy = 0;
ix = iy = 0;
if(image()) { if(image()) {
ix = (w()/2) - (image()->w()/2); ix = (w()/2) - (image()->w()/2);
iy = (h()/2) - (image()->h()/2); iy = (h()/2) - (image()->h()/2);
@ -225,8 +233,7 @@ void DesktopIcon::drag(int x, int y, bool apply) {
if(apply) { if(apply) {
#if HAVE_SHAPE #if HAVE_SHAPE
int ix, iy; int ix = 0, iy = 0;
ix = iy = 0;
if(image()) { if(image()) {
ix = (w()/2) - (image()->w()/2); ix = (w()/2) - (image()->w()/2);
iy = (h()/2) - (image()->h()/2); iy = (h()/2) - (image()->h()/2);
@ -269,7 +276,7 @@ void DesktopIcon::rename(const char* str) {
redraw(); redraw();
} }
const edelib::String& DesktopIcon::path(void) { const String& DesktopIcon::path(void) {
return settings->full_path; return settings->full_path;
} }
@ -385,8 +392,8 @@ int DesktopIcon::handle(int event) {
return 1; return 1;
case FL_PUSH: case FL_PUSH:
if(Fl::event_button() == 3) { if(Fl::event_button() == 3) {
/* Fl_Menu_Item::popup() by default does not call callbacks */ /* MenuItem::popup() by default does not call callbacks */
const Fl_Menu_Item* m = imenu->menu()->popup(Fl::event_x(), Fl::event_y()); const MenuItem* m = imenu->menu()->popup(Fl::event_x(), Fl::event_y());
if(m && m->callback()) if(m && m->callback())
m->do_callback(0, this); m->do_callback(0, this);
@ -394,7 +401,7 @@ int DesktopIcon::handle(int event) {
return 1; return 1;
case FL_RELEASE: case FL_RELEASE:
if(Fl::event_clicks() > 0) if(Fl::event_clicks() > 0)
edelib::run_async("ede-launch %s", settings->cmd.c_str()); run_async("ede-launch %s", settings->cmd.c_str());
return 1; return 1;
case FL_DND_ENTER: case FL_DND_ENTER:

View File

@ -22,13 +22,12 @@
#include <FL/Fl_Image.H> #include <FL/Fl_Image.H>
#include <edelib/String.h> #include <edelib/String.h>
#include <edelib/MenuButton.h>
class GlobalIconSettings; class GlobalIconSettings;
class IconSettings; class IconSettings;
class MovableIcon; class MovableIcon;
class Fl_Menu_Button;
class DesktopIcon : public Fl_Widget { class DesktopIcon : public Fl_Widget {
private: private:
IconSettings* settings; IconSettings* settings;
@ -40,8 +39,8 @@ private:
MovableIcon* micon; MovableIcon* micon;
Fl_Image* darker_img; Fl_Image* darker_img;
Fl_Menu_Button* imenu; edelib::MenuButton* imenu;
void load_icon(int face); void load_icon(int face);
void update_label_size(void); void update_label_size(void);