2012-04-19 14:12:49 +04:00
|
|
|
#include "Applet.h"
|
|
|
|
#include "Panel.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <edelib/Nls.h>
|
|
|
|
#include <edelib/Debug.h>
|
|
|
|
|
|
|
|
#include <FL/x.H>
|
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
/* delay in secs */
|
|
|
|
#define PANEL_MOVE_DELAY 0.0015
|
|
|
|
/* how fast we will move X axis */
|
|
|
|
#define PANEL_ANIM_SPEED 50
|
2012-04-19 14:12:49 +04:00
|
|
|
|
|
|
|
static void hide_cb(Fl_Widget*, void *h);
|
|
|
|
|
|
|
|
class Hider : public Fl_Button {
|
|
|
|
private:
|
2012-05-16 15:30:41 +04:00
|
|
|
int old_x, old_y, is_hidden, old_px, stop_x;
|
2012-04-19 14:12:49 +04:00
|
|
|
public:
|
2012-05-16 15:30:41 +04:00
|
|
|
Hider() : Fl_Button(0, 0, 10, 25, "@>"), old_x(0), old_y(0), is_hidden(0), old_px(0), stop_x(0) {
|
2012-04-19 14:12:49 +04:00
|
|
|
labelsize(8);
|
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
tooltip(_("Hide panel"));
|
|
|
|
callback(hide_cb, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
int panel_hidden(void) { return is_hidden; }
|
2012-05-16 15:30:41 +04:00
|
|
|
void panel_hidden(int s) { is_hidden = s; }
|
|
|
|
|
|
|
|
void panel_show(void);
|
|
|
|
void panel_hide(void);
|
|
|
|
void post_show(void);
|
|
|
|
void post_hide(void);
|
|
|
|
void animate(void);
|
2012-04-19 14:12:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void hide_cb(Fl_Widget*, void *h) {
|
|
|
|
Hider *hh = (Hider*)h;
|
|
|
|
if(hh->panel_hidden())
|
|
|
|
hh->panel_show();
|
|
|
|
else
|
|
|
|
hh->panel_hide();
|
|
|
|
}
|
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
static void animate_cb(void *h) {
|
|
|
|
Hider *hh = (Hider*)h;
|
|
|
|
hh->animate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hider::animate(void) {
|
|
|
|
Panel *p = EDE_PANEL_GET_PANEL_OBJECT(this);
|
|
|
|
|
|
|
|
if(!panel_hidden()) {
|
|
|
|
/* hide */
|
|
|
|
if(p->x() < stop_x) {
|
|
|
|
int X = p->x() + PANEL_ANIM_SPEED;
|
|
|
|
p->position(X, p->y());
|
|
|
|
Fl::repeat_timeout(PANEL_MOVE_DELAY, animate_cb, this);
|
|
|
|
} else {
|
|
|
|
post_hide();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* show */
|
|
|
|
if(p->x() > stop_x) {
|
|
|
|
int X = p->x() - PANEL_ANIM_SPEED;
|
|
|
|
p->position(X, p->y());
|
|
|
|
Fl::repeat_timeout(PANEL_MOVE_DELAY, animate_cb, this);
|
|
|
|
} else {
|
|
|
|
post_show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:12:49 +04:00
|
|
|
void Hider::panel_hide(void) {
|
|
|
|
Panel *p = EDE_PANEL_GET_PANEL_OBJECT(this);
|
2012-05-16 15:30:41 +04:00
|
|
|
int X, Y, W, H;
|
2012-04-19 14:12:49 +04:00
|
|
|
|
|
|
|
p->screen_size(X, Y, W, H);
|
2012-05-16 15:30:41 +04:00
|
|
|
stop_x = X + W - w();
|
2012-04-19 14:12:49 +04:00
|
|
|
old_px = p->x();
|
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
Fl::add_timeout(0.1, animate_cb, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hider::post_hide(void) {
|
|
|
|
Panel *p = EDE_PANEL_GET_PANEL_OBJECT(this);
|
2012-04-19 14:12:49 +04:00
|
|
|
|
|
|
|
/* align to bounds */
|
2012-05-16 15:30:41 +04:00
|
|
|
p->position(stop_x, p->y());
|
2012-04-19 14:12:49 +04:00
|
|
|
p->allow_drag(false);
|
|
|
|
p->apply_struts(false);
|
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
/* hide all children on panel except us */
|
2012-04-19 14:12:49 +04:00
|
|
|
for(int i = 0; i < p->children(); i++) {
|
|
|
|
if(p->child(i) != this)
|
|
|
|
p->child(i)->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append us to the beginning */
|
|
|
|
old_x = x();
|
|
|
|
old_y = y();
|
|
|
|
|
|
|
|
position(0 + Fl::box_dx(p->box()), y());
|
|
|
|
label("@<");
|
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
panel_hidden(1);
|
2012-04-19 14:12:49 +04:00
|
|
|
tooltip(_("Show panel"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Hider::panel_show(void) {
|
2012-05-16 15:30:41 +04:00
|
|
|
Fl::add_timeout(0.1, animate_cb, this);
|
|
|
|
}
|
2012-04-19 14:12:49 +04:00
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
void Hider::post_show(void) {
|
|
|
|
Panel *p = EDE_PANEL_GET_PANEL_OBJECT(this);
|
2012-04-19 14:12:49 +04:00
|
|
|
|
|
|
|
/* align to bounds */
|
|
|
|
p->position(old_px, p->y());
|
|
|
|
p->allow_drag(true);
|
|
|
|
p->apply_struts(true);
|
|
|
|
|
|
|
|
/* show all children on panel */
|
|
|
|
for(int i = 0; i < p->children(); i++) {
|
|
|
|
if(p->child(i) != this)
|
|
|
|
p->child(i)->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move ourself to previous position */
|
|
|
|
position(old_x, old_y);
|
|
|
|
label("@>");
|
|
|
|
|
2012-05-16 15:30:41 +04:00
|
|
|
panel_hidden(0);
|
2012-04-19 14:12:49 +04:00
|
|
|
tooltip(_("Hide panel"));
|
|
|
|
}
|
|
|
|
|
|
|
|
EDE_PANEL_APPLET_EXPORT (
|
|
|
|
Hider,
|
|
|
|
EDE_PANEL_APPLET_OPTION_ALIGN_RIGHT,
|
|
|
|
"Hide-panel applet",
|
|
|
|
"0.1",
|
|
|
|
"empty",
|
|
|
|
"Sanel Zukan"
|
|
|
|
)
|