Better resize support.

Body widget is by default hidden and summary is lowered a little bit,
to fill space gap. Also this commit fixes 'position' calls for output
widgets, as this function for these widgets will move cursor at given
position, instead to move widget. Yuck!
This commit is contained in:
Sanel Zukan 2012-05-15 10:28:08 +00:00
parent 2b81f59d45
commit 04b5c9d1f0
2 changed files with 25 additions and 11 deletions

View File

@ -51,14 +51,19 @@ NotifyWindow::NotifyWindow() : Fl_Window(DEFAULT_W, DEFAULT_H) {
/* use flat box so text can be drawn correctly */ /* use flat box so text can be drawn correctly */
summary->box(FL_FLAT_BOX); summary->box(FL_FLAT_BOX);
summary->cursor_color(FL_BACKGROUND2_COLOR); summary->cursor_color(FL_BACKGROUND2_COLOR);
summary->value(0);
body = new Fl_Multiline_Output(65, 35, 185, 25); body = new Fl_Multiline_Output(65, 35, 185, 25);
/* use flat box so text can be drawn correctly */ /* use flat box so text can be drawn correctly */
body->box(FL_FLAT_BOX); body->box(FL_FLAT_BOX);
body->cursor_color(FL_BACKGROUND2_COLOR); body->cursor_color(FL_BACKGROUND2_COLOR);
body->value(0);
end(); end();
/*
* by default body text is hidden and summary is lowered a little bit
* NOTE: I'm using 'resize' as 'position' for Fl_Input/Fl_Output means something different
*/
summary->resize(summary->x(), summary->y() + (summary->h() / 2), summary->w(), summary->h());
body->hide();
border(0); border(0);
} }
@ -69,6 +74,13 @@ void NotifyWindow::set_icon(const char *img) {
IconLoader::set(imgbox, img, ICON_SIZE_MEDIUM); IconLoader::set(imgbox, img, ICON_SIZE_MEDIUM);
} }
void NotifyWindow::set_body(const char *s) {
summary->resize(summary->x(), summary->y() - (summary->h() / 2), summary->w(), summary->h());
body->value(s);
body->show();
}
void NotifyWindow::show(void) { void NotifyWindow::show(void) {
if(exp != 0) { if(exp != 0) {
if(exp == -1) exp = DEFAULT_EXPIRE; if(exp == -1) exp = DEFAULT_EXPIRE;
@ -79,6 +91,8 @@ void NotifyWindow::show(void) {
netwm_window_set_type(fl_xid(this), NETWM_WINDOW_TYPE_NOTIFICATION); netwm_window_set_type(fl_xid(this), NETWM_WINDOW_TYPE_NOTIFICATION);
} }
#define INPUT_VALID(i) ((i)->visible() && (i)->size() > 0)
void NotifyWindow::resize(int X, int Y, int W, int H) { void NotifyWindow::resize(int X, int Y, int W, int H) {
/* /*
* do not call further if window is shown: different strategy is needed as every time * do not call further if window is shown: different strategy is needed as every time
@ -87,20 +101,20 @@ void NotifyWindow::resize(int X, int Y, int W, int H) {
if(shown()) return; if(shown()) return;
/* resize summary if needed */ /* resize summary if needed */
if(summary->value() && summary->size() > 0) { if(summary->size() > 0) {
int fw = 0, fh = 0; int fw = 0, fh = 0;
fl_font(summary->textfont(), summary->textsize()); fl_font(summary->textfont(), summary->textsize());
fl_measure(summary->value(), fw, fh); fl_measure(summary->value(), fw, fh);
if(fw > summary->w()) { if(fw > summary->w()) {
int d = fw - summary->w(); int d = fw - summary->w();
summary->size(fw, summary->h()); summary->resize(summary->x(), summary->y(), fw, summary->h());
/* move X button */ /* move X button */
closeb->position(closeb->x() + d, closeb->y()); closeb->position(closeb->x() + d, closeb->y());
/* resize body too */ /* resize body too */
if(body->visible()) body->size(body->w() + d, body->h()); if(INPUT_VALID(body)) body->resize(body->x(), body->y(), body->w() + d, body->h());
W += d; W += d;
/* this depends on window position */ /* this depends on window position */
@ -109,10 +123,10 @@ void NotifyWindow::resize(int X, int Y, int W, int H) {
if(fh > summary->h()) { if(fh > summary->h()) {
int d = fh - summary->h(); int d = fh - summary->h();
summary->size(summary->w(), fh); summary->resize(summary->x(), summary->y(), summary->w(), fh);
/* move body down */ /* move body down */
if(body->visible()) body->position(body->x(), body->y() + d); if(INPUT_VALID(body)) body->resize(body->x(), body->y() + d, body->w(), body->h());
H += d; H += d;
Y -= d; Y -= d;
@ -120,14 +134,14 @@ void NotifyWindow::resize(int X, int Y, int W, int H) {
} }
/* resize body if needed */ /* resize body if needed */
if(body->value() && body->size() > 0) { if(INPUT_VALID(body)) {
int fw = 0, fh = 0; int fw = 0, fh = 0;
fl_font(body->textfont(), body->textsize()); fl_font(body->textfont(), body->textsize());
fl_measure(body->value(), fw, fh); fl_measure(body->value(), fw, fh);
if(fw > body->w()) { if(fw > body->w()) {
int d = fw - body->w(); int d = fw - body->w();
body->size(fw, body->h()); body->resize(body->x(), body->y(), fw, body->h());
/* move X button again */ /* move X button again */
closeb->position(closeb->x() + d, closeb->y()); closeb->position(closeb->x() + d, closeb->y());
@ -138,7 +152,7 @@ void NotifyWindow::resize(int X, int Y, int W, int H) {
if(fh > body->h()) { if(fh > body->h()) {
int d = fh - body->h(); int d = fh - body->h();
body->size(body->w(), fh); body->resize(body->x(), body->y(), body->w(), fh);
H += d; H += d;
Y -= d; Y -= d;

View File

@ -24,7 +24,7 @@ public:
void set_icon(const char *img); void set_icon(const char *img);
void set_summary(const char *s) { summary->value(s); } void set_summary(const char *s) { summary->value(s); }
void set_body(const char *s) { body->value(s); } void set_body(const char *s);
/* /*
* match to spec: if is -1, then we handle it, if is 0, then window will not be closed and * match to spec: if is -1, then we handle it, if is 0, then window will not be closed and