2007-06-18 20:46:27 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Eiconman, desktop and icon manager
|
|
|
|
* Part of Equinox Desktop Environment (EDE).
|
|
|
|
* Copyright (c) 2000-2007 EDE Authors.
|
|
|
|
*
|
|
|
|
* This program is licensed under terms of the
|
|
|
|
* GNU General Public License version 2 or newer.
|
|
|
|
* See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NotifyBox.h"
|
|
|
|
#include "eiconman.h"
|
|
|
|
#include <edelib/Debug.h>
|
|
|
|
|
|
|
|
#include <FL/Fl.h>
|
|
|
|
#include <FL/fl_draw.h>
|
|
|
|
#include <FL/Fl_Group.h>
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
#define MAX_LABEL_WIDTH 200
|
2007-06-18 20:46:27 +04:00
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
#define TIMEOUT (1.0f/60.0f)
|
|
|
|
#define TIME_SHOWN 3.0f
|
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
NotifyBox::NotifyBox(int aw, int ah) : Fl_Window(0, 0, 10, 10) {
|
2007-06-19 13:59:15 +04:00
|
|
|
area_w = aw;
|
|
|
|
area_h = ah;
|
2007-06-18 20:46:27 +04:00
|
|
|
lwidth = lheight = 0;
|
|
|
|
is_shown = false;
|
2007-06-19 13:59:15 +04:00
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
clear_border();
|
|
|
|
set_non_modal();
|
|
|
|
|
|
|
|
begin();
|
|
|
|
txt_box = new Fl_Box(0, 0, w(), h());
|
|
|
|
txt_box->box(FL_BORDER_BOX);
|
|
|
|
txt_box->color(FL_WHITE);
|
|
|
|
txt_box->align(FL_ALIGN_WRAP);
|
|
|
|
end();
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NotifyBox::~NotifyBox() {
|
|
|
|
EDEBUG("NotifyBox::~NotifyBox()\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyBox::update_label_size(void) {
|
|
|
|
lwidth = MAX_LABEL_WIDTH;
|
|
|
|
lheight= 0;
|
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
fl_font(txt_box->labelfont(), txt_box->labelsize());
|
|
|
|
fl_measure(txt_box->label(), lwidth, lheight, txt_box->align());
|
2007-06-18 20:46:27 +04:00
|
|
|
|
|
|
|
lwidth += 10;
|
|
|
|
lheight += 10;
|
|
|
|
}
|
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
void NotifyBox::resize_all(void) {
|
2007-06-18 20:46:27 +04:00
|
|
|
update_label_size();
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
// center box
|
|
|
|
int x_pos = (area_w/2) - (lwidth/2);
|
2007-06-28 15:21:24 +04:00
|
|
|
resize(x_pos, 0, lwidth, lheight);
|
|
|
|
txt_box->resize(0, 0, w(), h());
|
|
|
|
}
|
2007-06-18 20:46:27 +04:00
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
void NotifyBox::show(void) {
|
|
|
|
if(shown())
|
|
|
|
return;
|
2007-06-18 20:46:27 +04:00
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
EDEBUG(ESTRLOC ": %i %i\n", x(), y());
|
|
|
|
resize_all();
|
|
|
|
|
|
|
|
Fl_Window::show();
|
|
|
|
is_shown = true;
|
|
|
|
Fl::add_timeout(TIME_SHOWN, visible_timeout_cb, this);
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyBox::hide(void) {
|
2007-06-19 13:59:15 +04:00
|
|
|
if(!shown())
|
|
|
|
return;
|
|
|
|
|
2007-06-28 15:21:24 +04:00
|
|
|
Fl_Window::hide();
|
2007-06-19 13:59:15 +04:00
|
|
|
is_shown = false;
|
2007-06-28 15:21:24 +04:00
|
|
|
Fl::remove_timeout(visible_timeout_cb);
|
|
|
|
Fl::remove_timeout(animate_cb);
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
void NotifyBox::label(const char* l) {
|
2007-06-28 15:21:24 +04:00
|
|
|
txt_box->label(l);
|
|
|
|
resize_all();
|
2007-06-19 13:59:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyBox::copy_label(const char* l) {
|
2007-06-28 15:21:24 +04:00
|
|
|
txt_box->copy_label(l);
|
|
|
|
resize_all();
|
2007-06-19 13:59:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* NotifyBox::label(void) {
|
2007-06-28 15:21:24 +04:00
|
|
|
return txt_box->label();
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
|
2007-06-19 13:59:15 +04:00
|
|
|
void NotifyBox::animate(void) {
|
2007-06-28 15:21:24 +04:00
|
|
|
if(y() > -lheight) {
|
|
|
|
position(x(), y() - 1);
|
|
|
|
Fl::repeat_timeout(TIMEOUT, animate_cb, this);
|
|
|
|
} else
|
|
|
|
hide();
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyBox::visible_timeout(void) {
|
2007-06-28 15:21:24 +04:00
|
|
|
Fl::remove_timeout(visible_timeout_cb);
|
|
|
|
Fl::add_timeout(TIMEOUT, animate_cb, this);
|
2007-06-18 20:46:27 +04:00
|
|
|
}
|