ede/econtrol/econtrol.cpp

173 lines
3.6 KiB
C++
Raw Normal View History

#include "econtrol.h"
2007-05-22 18:51:00 +04:00
#include <edelib/Config.h>
#include <edelib/StrUtil.h>
#include <edelib/Debug.h>
#include <edelib/Nls.h>
2007-06-15 15:05:44 +04:00
#include <FL/Fl.h>
#include <FL/Fl_Shared_Image.h>
#include <FL/fl_draw.h>
using namespace edelib;
2007-06-15 15:05:44 +04:00
ControlButton::ControlButton(Fl_Box* t, String tv, int x, int y, int w, int h, const char* l) :
Fl_Button(x, y, w, h, l) {
2007-05-22 18:51:00 +04:00
tip = t;
tipval = tv;
2007-06-15 15:05:44 +04:00
box(FL_FLAT_BOX);
align(FL_ALIGN_WRAP);
color(FL_WHITE);
2007-05-22 18:51:00 +04:00
}
ControlButton::~ControlButton() {
}
int ControlButton::handle(int event) {
switch(event) {
2007-06-15 15:05:44 +04:00
case FL_ENTER:
2007-05-22 18:51:00 +04:00
tip->label(tipval.c_str());
return 1;
2007-06-15 15:05:44 +04:00
case FL_LEAVE:
2007-05-22 18:51:00 +04:00
tip->label("");
return 1;
2007-06-15 15:05:44 +04:00
case FL_PUSH:
2007-05-22 18:51:00 +04:00
return 1;
2007-06-15 15:05:44 +04:00
case FL_RELEASE:
2007-05-22 18:51:00 +04:00
return 1;
default:
2007-06-15 15:05:44 +04:00
return Fl_Button::handle(event);
2007-05-22 18:51:00 +04:00
}
2007-06-15 15:05:44 +04:00
return Fl_Button::handle(event);
}
2007-06-15 15:05:44 +04:00
void close_cb(Fl_Widget*, void* w) {
2007-05-22 18:51:00 +04:00
ControlWin* cw = (ControlWin*)w;
cw->do_close();
}
2007-06-15 15:05:44 +04:00
ControlWin::ControlWin(const char* title, int w, int h) : Fl_Window(w, h, title) {
2007-05-22 18:51:00 +04:00
IconTheme::init("edeneu");
2007-06-15 15:05:44 +04:00
fl_register_images();
2007-05-22 18:51:00 +04:00
load_icons();
init();
}
2007-05-22 18:51:00 +04:00
ControlWin::~ControlWin() {
IconTheme::shutdown();
}
2007-05-22 18:51:00 +04:00
void ControlWin::load_icons(void) {
Config c;
2007-05-22 18:51:00 +04:00
if(!c.load("econtrol.conf")) {
EWARNING("Can't load config\n");
return;
}
2007-05-22 18:51:00 +04:00
char buff[1024];
if(!c.get("Control Panel", "Items", buff, sizeof(buff))) {
EWARNING("Can't find Items key\n");
return;
}
2007-08-21 16:17:35 +04:00
list<String> spl;
list<String>::iterator it, it_end;
2007-05-22 18:51:00 +04:00
stringtok(spl, buff, ",");
2007-08-21 16:17:35 +04:00
if(spl.empty())
return;
const char* sect;
2007-05-22 18:51:00 +04:00
ControlIcon cicon;
2007-08-21 16:17:35 +04:00
it = spl.begin();
it_end = spl.end();
for(; it != it_end; ++it) {
sect = (*it).c_str();
str_trim((char*)sect);
2007-05-22 18:51:00 +04:00
if(c.get(sect, "Name", buff, sizeof(buff)))
cicon.name = buff;
else {
2007-08-21 16:17:35 +04:00
EWARNING("No %s, skipping...\n", sect);
2007-05-22 18:51:00 +04:00
continue;
}
2007-05-22 18:51:00 +04:00
if(c.get(sect, "Tip", buff, sizeof(buff)))
cicon.tip = buff;
if(c.get(sect, "Exec", buff, sizeof(buff)))
cicon.exec = buff;
if(c.get(sect, "Icon", buff, sizeof(buff))) {
cicon.icon = buff;
2007-08-21 16:17:35 +04:00
EDEBUG("setting icon (%s): %s\n", sect, cicon.icon.c_str());
2007-05-22 18:51:00 +04:00
}
2007-08-21 16:17:35 +04:00
c.get(sect, "IconPathAbsolute", cicon.abspath, false);
c.get(sect, "Position", cicon.abspath, -1);
2007-05-22 18:51:00 +04:00
iconlist.push_back(cicon);
}
}
2007-05-22 18:51:00 +04:00
void ControlWin::init(void) {
begin();
2007-06-15 15:05:44 +04:00
titlegrp = new Fl_Group(0, 0, 455, 50);
titlegrp->box(FL_FLAT_BOX);
titlegrp->color(138);
2007-05-22 18:51:00 +04:00
titlegrp->begin();
2007-06-15 15:05:44 +04:00
title = new Fl_Box(10, 10, 435, 30, label());
title->color(138);
title->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
title->labelcolor(23);
title->labelfont(FL_HELVETICA_BOLD);
2007-05-22 18:51:00 +04:00
title->labelsize(16);
titlegrp->end();
titlegrp->resizable(title);
icons = new ExpandableGroup(10, 60, 435, 225);
2007-06-15 15:05:44 +04:00
icons->box(FL_DOWN_BOX);
icons->color(FL_BACKGROUND2_COLOR);
icons->end();
2007-05-22 18:51:00 +04:00
2007-06-15 15:05:44 +04:00
tipbox = new Fl_Box(10, 295, 240, 25, _("Double click on desired item"));
tipbox->box(FL_FLAT_BOX);
tipbox->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP);
2007-05-22 18:51:00 +04:00
2007-08-21 16:17:35 +04:00
list<ControlIcon>::iterator it, it_end;
it = iconlist.begin();
it_end = iconlist.end();
for(; it != it_end; ++it) {
ControlButton* b = new ControlButton(tipbox, (*it).tip, 0, 0, 80, 100);
String iconpath = IconTheme::get((*it).icon.c_str(), ICON_SIZE_LARGE);
b->label((*it).name.c_str());
2007-05-22 18:51:00 +04:00
if(!iconpath.empty())
2007-06-15 15:05:44 +04:00
b->image(Fl_Shared_Image::get(iconpath.c_str()));
2007-05-22 18:51:00 +04:00
icons->add(b);
}
2007-06-15 15:05:44 +04:00
//options = new Fl_Button(260, 295, 90, 25, _("&Options"));
close = new Fl_Button(355, 295, 90, 25, _("&Close"));
2007-05-22 18:51:00 +04:00
close->callback(close_cb, this);
2006-09-11 16:48:40 +04:00
2007-05-22 18:51:00 +04:00
// resizable invisible box
2007-06-15 15:05:44 +04:00
rbox = new Fl_Box(10, 220, 120, 65);
2007-05-22 18:51:00 +04:00
resizable(rbox);
end();
}
void ControlWin::do_close(void) {
hide();
}
2007-05-22 18:51:00 +04:00
int main() {
ControlWin cw(_("EDE Control Panel"));
cw.show();
2007-06-15 15:05:44 +04:00
return Fl::run();
}