diff --git a/makefile.lst b/makefile.lst index b2b86fd4c..258dd7a13 100644 --- a/makefile.lst +++ b/makefile.lst @@ -132,6 +132,7 @@ COMMON_SOURCES = \ src/jinete/jbutton.cpp \ src/jinete/jclipboard.cpp \ src/jinete/jcombobox.cpp \ + src/jinete/jcustom_label.cpp \ src/jinete/jdraw.cpp \ src/jinete/jentry.cpp \ src/jinete/jexception.cpp \ @@ -145,6 +146,7 @@ COMMON_SOURCES = \ src/jinete/jinete.cpp \ src/jinete/jintern.cpp \ src/jinete/jlabel.cpp \ + src/jinete/jlink_label.cpp \ src/jinete/jlist.cpp \ src/jinete/jlistbox.cpp \ src/jinete/jmanager.cpp \ diff --git a/src/commands/cmd_about.cpp b/src/commands/cmd_about.cpp index 0f8f5fff6..8a4770a24 100644 --- a/src/commands/cmd_about.cpp +++ b/src/commands/cmd_about.cpp @@ -61,7 +61,7 @@ void AboutCommand::execute(Context* context) separator1 = ji_separator_new(NULL, JI_HORIZONTAL); label3 = new Label(COPYRIGHT); - label4 = new Label(WEBSITE); + label4 = new LinkLabel(WEBSITE); textbox = jtextbox_new("Authors:\n\n" " David Capello\n" " - Project leader and developer\n\n" diff --git a/src/jinete/jcustom_label.cpp b/src/jinete/jcustom_label.cpp new file mode 100644 index 000000000..1446a83dd --- /dev/null +++ b/src/jinete/jcustom_label.cpp @@ -0,0 +1,45 @@ +/* Jinete - a GUI library + * Copyright (C) 2003-2010 David Capello. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "config.h" + +#include "jinete/jcustom_label.h" + +CustomLabel::CustomLabel(const char *text) + : Label(text) +{ +} + +bool CustomLabel::msg_proc(JMessage msg) +{ + return Label::msg_proc(msg); +} diff --git a/src/jinete/jcustom_label.h b/src/jinete/jcustom_label.h new file mode 100644 index 000000000..5908d3a68 --- /dev/null +++ b/src/jinete/jcustom_label.h @@ -0,0 +1,47 @@ +/* Jinete - a GUI library + * Copyright (C) 2003-2010 David Capello. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JINETE_JCUSTOM_LABEL_H_INCLUDED +#define JINETE_JCUSTOM_LABEL_H_INCLUDED + +#include "jinete/jlabel.h" + +class CustomLabel : public Label +{ +public: + CustomLabel(const char *text); + +protected: + virtual bool msg_proc(JMessage msg); + +}; + +#endif diff --git a/src/jinete/jinete.h b/src/jinete/jinete.h index 12451ed6e..1e5e90340 100644 --- a/src/jinete/jinete.h +++ b/src/jinete/jinete.h @@ -39,6 +39,7 @@ #include "jinete/jbutton.h" #include "jinete/jclipboard.h" #include "jinete/jcombobox.h" +#include "jinete/jcustom_label.h" #include "jinete/jdraw.h" #include "jinete/jentry.h" #include "jinete/jexception.h" @@ -49,6 +50,7 @@ #include "jinete/jhook.h" #include "jinete/jimage.h" #include "jinete/jlabel.h" +#include "jinete/jlink_label.h" #include "jinete/jlist.h" #include "jinete/jlistbox.h" #include "jinete/jmanager.h" diff --git a/src/jinete/jlink_label.cpp b/src/jinete/jlink_label.cpp new file mode 100644 index 000000000..e0abb9e36 --- /dev/null +++ b/src/jinete/jlink_label.cpp @@ -0,0 +1,86 @@ +/* Jinete - a GUI library + * Copyright (C) 2003-2010 David Capello. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "config.h" + +#include "jinete/jlink_label.h" +#include "jinete/jmessage.h" +#include "jinete/jtheme.h" +#include "jinete/jsystem.h" +#include "launcher.h" + +LinkLabel::LinkLabel(const char* urlOrText) + : CustomLabel(urlOrText) + , m_url(urlOrText) +{ +} + +LinkLabel::LinkLabel(const char* url, const char* text) + : CustomLabel(text) + , m_url(url) +{ +} + +bool LinkLabel::msg_proc(JMessage msg) +{ + switch (msg->type) { + + case JM_SETCURSOR: + // TODO theme stuff + if (jwidget_is_enabled(this)) { + jmouse_set_cursor(JI_CURSOR_HAND); + return true; + } + break; + + case JM_MOUSEENTER: + case JM_MOUSELEAVE: + // TODO theme stuff + if (jwidget_is_enabled(this)) + jwidget_dirty(this); + break; + + case JM_DRAW: + this->theme->draw_link_label(this, &msg->draw.rect); + return true; + + case JM_BUTTONRELEASED: + if (jwidget_is_enabled(this)) { + if (!m_url.empty()) + Launcher::openUrl(m_url); + Click(); + } + break; + } + + return CustomLabel::msg_proc(msg); +} diff --git a/src/jinete/jlink_label.h b/src/jinete/jlink_label.h new file mode 100644 index 000000000..bd1fd4b4e --- /dev/null +++ b/src/jinete/jlink_label.h @@ -0,0 +1,54 @@ +/* Jinete - a GUI library + * Copyright (C) 2003-2010 David Capello. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the author nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JINETE_JLINK_LABEL_H_INCLUDED +#define JINETE_JLINK_LABEL_H_INCLUDED + +#include "Vaca/Signal.h" +#include "jinete/jcustom_label.h" +#include + +class LinkLabel : public CustomLabel +{ + std::string m_url; + +public: + LinkLabel(const char* urlOrText); + LinkLabel(const char* url, const char* text); + + Vaca::Signal0 Click; + +protected: + virtual bool msg_proc(JMessage msg); + +}; + +#endif diff --git a/src/jinete/jtheme.h b/src/jinete/jtheme.h index 486e370ad..6b10518d2 100644 --- a/src/jinete/jtheme.h +++ b/src/jinete/jtheme.h @@ -72,6 +72,7 @@ public: virtual void draw_entry(JWidget widget, JRect clip) = 0; virtual void draw_grid(JWidget widget, JRect clip) = 0; virtual void draw_label(JWidget widget, JRect clip) = 0; + virtual void draw_link_label(JWidget widget, JRect clip) = 0; virtual void draw_listbox(JWidget widget, JRect clip) = 0; virtual void draw_listitem(JWidget widget, JRect clip) = 0; virtual void draw_menu(JWidget widget, JRect clip) = 0; diff --git a/src/jinete/themes/jstandard_theme.cpp b/src/jinete/themes/jstandard_theme.cpp index 5066de9ed..730cfa521 100644 --- a/src/jinete/themes/jstandard_theme.cpp +++ b/src/jinete/themes/jstandard_theme.cpp @@ -117,6 +117,7 @@ public: void draw_entry(JWidget widget, JRect clip); void draw_grid(JWidget widget, JRect clip); void draw_label(JWidget widget, JRect clip); + void draw_link_label(JWidget widget, JRect clip); void draw_listbox(JWidget widget, JRect clip); void draw_listitem(JWidget widget, JRect clip); void draw_menu(JWidget widget, JRect clip); @@ -724,6 +725,23 @@ void jstandard_theme::draw_label(JWidget widget, JRect clip) draw_textstring(NULL, -1, bg, false, widget, widget->rc, 0); } +void jstandard_theme::draw_link_label(JWidget widget, JRect clip) +{ + int bg = get_bg_color(widget); + + jdraw_rectfill(widget->rc, bg); + + draw_textstring(NULL, makecol(0, 0, 255), bg, false, widget, widget->rc, 0); + + if (widget->hasMouseOver()) { + int w = jwidget_get_text_length(widget); + int h = jwidget_get_text_height(widget); + + hline(ji_screen, + widget->rc->x1, widget->rc->y2-1, widget->rc->x1+w-1, makecol(0, 0, 255)); + } +} + void jstandard_theme::draw_listbox(JWidget widget, JRect clip) { int bg; diff --git a/src/modules/skinneable_theme.cpp b/src/modules/skinneable_theme.cpp index e4ebb6285..803c2d644 100644 --- a/src/modules/skinneable_theme.cpp +++ b/src/modules/skinneable_theme.cpp @@ -829,6 +829,23 @@ void SkinneableTheme::draw_label(JWidget widget, JRect clip) draw_textstring(NULL, -1, bg, false, widget, widget->rc, 0); } +void SkinneableTheme::draw_link_label(JWidget widget, JRect clip) +{ + int bg = BGCOLOR; + + jdraw_rectfill(widget->rc, bg); + + draw_textstring(NULL, makecol(0, 0, 255), bg, false, widget, widget->rc, 0); + + if (widget->hasMouseOver()) { + int w = jwidget_get_text_length(widget); + int h = jwidget_get_text_height(widget); + + hline(ji_screen, + widget->rc->x1, widget->rc->y2-1, widget->rc->x1+w-1, makecol(0, 0, 255)); + } +} + void SkinneableTheme::draw_listbox(JWidget widget, JRect clip) { jdraw_rectfill(widget->rc, COLOR_BACKGROUND); diff --git a/src/modules/skinneable_theme.h b/src/modules/skinneable_theme.h index 5720c2efd..fb173b3bb 100644 --- a/src/modules/skinneable_theme.h +++ b/src/modules/skinneable_theme.h @@ -438,6 +438,7 @@ public: void draw_entry(JWidget widget, JRect clip); void draw_grid(JWidget widget, JRect clip); void draw_label(JWidget widget, JRect clip); + void draw_link_label(JWidget widget, JRect clip); void draw_listbox(JWidget widget, JRect clip); void draw_listitem(JWidget widget, JRect clip); void draw_menu(JWidget widget, JRect clip);