X-Git-Url: http://git.maemo.org/git/?p=lordsawar;a=blobdiff_plain;f=src%2Fgui%2Fdecorated.cpp;fp=src%2Fgui%2Fdecorated.cpp;h=156bee6a645baa7d5f64725fc8159e69e180655f;hp=0000000000000000000000000000000000000000;hb=9eda00ff73353c55ecef6f82131166d5d4a85e29;hpb=3d34d4aa85a929f912464f71158396a388274f27;ds=sidebyside diff --git a/src/gui/decorated.cpp b/src/gui/decorated.cpp new file mode 100644 index 0000000..156bee6 --- /dev/null +++ b/src/gui/decorated.cpp @@ -0,0 +1,177 @@ +// Copyright (C) 2008 Ben Asselstine +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. + +#include "decorated.h" +#include +#include + +#include "defs.h" +#include "File.h" +#include "Configuration.h" +using namespace Gtk; +using namespace Gdk; +using namespace Glib; +Decorated::Decorated() +{ +} + +Decorated::~Decorated() +{ + maximized = false; +} + +void Decorated::decorate(Gtk::Window *d, std::string filename, int alpha) +{ + window = d; + if (Configuration::s_decorated == false) + return; + Glib::RefPtr copy; + RefPtr back; + RefPtr pixmap; + RefPtr bitmap; + window->set_decorated(true); + Gtk::Widget *focus = window->get_focus(); + Gtk::Widget *child = window->get_child(); + window->remove(); + Gtk::Frame *windowdecoration =manage(new Gtk::Frame()); + window->add(*windowdecoration); + + windowdecoration->property_shadow_type() = Gtk::SHADOW_ETCHED_OUT; + Gtk::HBox *titlebox= new Gtk::HBox(); + Gtk::EventBox *eventbox = manage(new Gtk::EventBox()); + + title = manage(new Gtk::Label(window->get_title())); + Gtk::Alignment *align= manage(new Gtk::Alignment()); + align->set_padding(0, 0, 10, 10); + title->unset_bg(Gtk::STATE_NORMAL); + //align->add(*title); + + eventbox->add(*align); + titlebox->pack_start(*eventbox, true, true, 5); + Gtk::Button *minimize_button = manage(new Gtk::Button()); + minimize_button->set_label("_"); + minimize_button->set_tooltip_text(_("Minimize")); + minimize_button->property_relief() = Gtk::RELIEF_NONE; + minimize_button->property_can_focus() = false; + minimize_button->signal_clicked().connect(sigc::mem_fun(window, &Gtk::Window::iconify)); + if (window->get_type_hint() == Gdk::WINDOW_TYPE_HINT_NORMAL) + { + maximize_button = manage(new Gtk::Button()); + maximize_button->set_label("^"); + maximize_button->set_tooltip_text(_("Maximize")); + maximize_button->property_relief() = Gtk::RELIEF_NONE; + maximize_button->property_can_focus() = false; + maximize_button->signal_clicked().connect(sigc::mem_fun(this, &Decorated::on_maximize)); + } + Gtk::Button *close_button = manage(new Gtk::Button()); + close_button->set_label("x"); + close_button->set_tooltip_text(_("Close")); + close_button->property_relief() = Gtk::RELIEF_NONE; + close_button->property_can_focus() = false; + close_button->signal_clicked().connect(sigc::mem_fun(this, &Decorated::on_hide)); + //titlebox->pack_end(*close_button, false, false, 0); + //if (window->get_type_hint() == Gdk::WINDOW_TYPE_HINT_NORMAL) + //titlebox->pack_end(*maximize_button, false, false, 0); + //titlebox->pack_end(*minimize_button, false, false, 0); + //windowdecoration->set_label_align(Gtk::ALIGN_RIGHT); + //windowdecoration->set_label_widget(*titlebox); + + + windowdecoration->add(*manage(child)); + titlebox->add_events(Gdk::POINTER_MOTION_MASK); + titlebox->signal_motion_notify_event().connect + (sigc::mem_fun(*this, &Decorated::on_mouse_motion_event)); + copy = windowdecoration->get_style()->copy(); + + if (filename == "") + filename = File::getMiscFile("various/background.png"); + back = Pixbuf::create_from_file(filename); + pixmap = Pixmap::create(window->get_window(), back->get_width(), back->get_height()); + copy->set_bg(Gtk::STATE_NORMAL, Gdk::Color("black")); + window->set_style(copy); + back->composite_color(back, 0, 0, back->get_width(), back->get_height(), 0.0, 0.0, 1.0, 1.0, Gdk::INTERP_NEAREST, alpha, 0, 0, 64, 0, 0); + back->render_pixmap_and_mask(pixmap, bitmap, 10); + copy->set_bg_pixmap(Gtk::STATE_NORMAL, pixmap); + windowdecoration->show_all(); + window->set_style(copy); + if (focus) + window->set_focus(*focus); +} + +void Decorated::on_maximize() +{ + maximized = !maximized; + if (maximized) + { + window->maximize(); + maximize_button->set_label("#"); + maximize_button->set_tooltip_text(_("Restore")); + } + else + { + window->unmaximize(); + maximize_button->set_label("^"); + maximize_button->set_tooltip_text(_("Maximize")); + } +} + +bool Decorated::on_mouse_motion_event(GdkEventMotion *e) +{ + int x, y; + window->get_position(x, y); + window->move(x + int(e->x), y + int(e->y)); + return true; +} + + +void Decorated::set_title(std::string text) +{ + if (Configuration::s_decorated) + { + title->set_text(text); + window->set_title(text); + } + else + window->set_title(text); +} + +void Decorated::on_hide() +{ + window_closed.emit(); +} + +void Decorated::decorate_border(Gtk::Viewport *container, int alpha) +{ + if (Configuration::s_decorated == false) + return; + Glib::RefPtr copy; + Glib::RefPtr back; + Glib::RefPtr pixmap; + Glib::RefPtr bitmap; + copy = container->get_style()->copy(); + back = Gdk::Pixbuf::create_from_file + (File::getMiscFile("various/back.bmp")); + pixmap = Gdk::Pixmap::create + (window->get_window(), back->get_width(), back->get_height()); + back->composite_color(back, 0, 0, + back->get_width(), back->get_height(), + 0.0, 0.0, 1.0, 1.0, Gdk::INTERP_NEAREST, alpha, + 0, 0, 64, 0, 0); + back->render_pixmap_and_mask(pixmap, bitmap, 10); + copy->set_bg_pixmap(Gtk::STATE_NORMAL, pixmap); + container->set_style(copy); +}