From 53337dddebd26948ddb4c5b39696090f2897ef9c Mon Sep 17 00:00:00 2001 From: "Christophe Berbizier (dbdl)" Date: Wed, 12 Feb 2014 16:43:02 +0100 Subject: [PATCH] added: LHyperlinkButton --- Source/LHyperlinkButton.cpp | 95 +++++++++++ Source/LHyperlinkButton.h | 59 +++++++ Source/LHyperlinkButton_inh.h | 293 ++++++++++++++++++++++++++++++++++ Source/Main.cpp | 2 + Source/luce.cpp | 1 + Source/luce.h | 1 + 6 files changed, 451 insertions(+) create mode 100644 Source/LHyperlinkButton.cpp create mode 100644 Source/LHyperlinkButton.h create mode 100644 Source/LHyperlinkButton_inh.h diff --git a/Source/LHyperlinkButton.cpp b/Source/LHyperlinkButton.cpp new file mode 100644 index 0000000..79ca87c --- /dev/null +++ b/Source/LHyperlinkButton.cpp @@ -0,0 +1,95 @@ +/************************************************************ + + LHyperlinkButton.cpp + + @author Christophe Berbizier (cberbizier@peersuasive.com) + @license GPLv3 + @copyright + + +(c) 2014, Peersuasive Technologies + +*************************************************************/ + +#include "LHyperlinkButton_inh.h" + +const char LHyperlinkButton::className[] = "LHyperlinkButton"; +const Luna::PropertyType LHyperlinkButton::properties[] = { + {"url", &LHyperlinkButton::getURL, &LHyperlinkButton::setURL}, + {"font", &LBase::writeOnly, &LHyperlinkButton::setFont}, + + {0,0} +}; +const Luna::FunctionType LHyperlinkButton::methods[] = { + method( LHyperlinkButton, getURL ), + method( LHyperlinkButton, setURL ), + method( LHyperlinkButton, setFont ), + method( LHyperlinkButton, changeWidthToFitText ), + {0,0} +}; + +const Luna::StaticType LHyperlinkButton::statics[] = { + {0,0} +}; + +LHyperlinkButton::LHyperlinkButton(lua_State *L) + : LButton(L, this), + HyperlinkButton() +{ + HyperlinkButton::setName(myName()); + HyperlinkButton::addListener(this); + + REGISTER_CLASS(LHyperlinkButton); +} + +LHyperlinkButton::~LHyperlinkButton() {} + +// callbacks +int LHyperlinkButton::addListener(lua_State*) { + HyperlinkButton::addListener(this); + return 0; +} + +int LHyperlinkButton::removeListener(lua_State*) { + HyperlinkButton::removeListener(this); + return 0; +} + +void LHyperlinkButton::paintButton(Graphics& g, bool isMouseOver, bool isButtonDown) { + if(hasCallback("paintButton")) + LButton::lpaintButton(g, isMouseOver, isButtonDown); + else + HyperlinkButton::paintButton(g, isMouseOver, isButtonDown); +} + +void LHyperlinkButton::buttonStateChanged() { + LButton::lbuttonStateChanged(); +} + +void LHyperlinkButton::buttonClicked (Button* buttonThatWasClicked) { + LButton::lbuttonClicked(buttonThatWasClicked); +} + +/////// getters/setters +int LHyperlinkButton::getURL ( lua_State *L ) { + return LUA::returnString( HyperlinkButton::getURL().toString(true) ); +} +int LHyperlinkButton::setURL ( lua_State* ) { + HyperlinkButton::setURL( URL( LUA::getString() ) ); + return 0; +} + +/////// setters +int LHyperlinkButton::setFont ( lua_State* ) { + Font newFont = *LUA::from_luce(2); + bool resizeToMatchComponentHeight = LUA::checkAndGetBoolean(2, false); + Justification justificationType ( + (Justification)LUA::checkAndGetNumber(2, Justification::horizontallyCentred ) ); + HyperlinkButton::setFont( newFont, resizeToMatchComponentHeight, justificationType ); + return 0; +} + +int LHyperlinkButton::changeWidthToFitText ( lua_State* ) { + HyperlinkButton::changeWidthToFitText(); + return 0; +} diff --git a/Source/LHyperlinkButton.h b/Source/LHyperlinkButton.h new file mode 100644 index 0000000..41dacb0 --- /dev/null +++ b/Source/LHyperlinkButton.h @@ -0,0 +1,59 @@ +/************************************************************ + + LHyperlinkButton.h + + @author Christophe Berbizier (cberbizier@peersuasive.com) + @license GPLv3 + @copyright + + +(c) 2014, Peersuasive Technologies + +*************************************************************/ + +#ifndef __LUCE_LHYPERLINKBUTTON_H +#define __LUCE_LHYPERLINKBUTTON_H + +class LHyperlinkButton + : public LButton, + public HyperlinkButton, + public Button::Listener + +{ +public: + LHyperlinkButton(lua_State*); + ~LHyperlinkButton(); + + //============================================================================== + int addListener(lua_State*); + int removeListener(lua_State*); + + //============================================================================== + int setURL(lua_State*); + int getURL(lua_State*); + + //============================================================================== + int setFont(lua_State*); + int changeWidthToFitText(lua_State*); + + //============================================================================== + static const char className[]; + static const Luna::Inheritence inherits[]; + static const Luna::InheritenceF inheritsF[]; + static const Luna::PropertyType properties[]; + static const Luna::FunctionType methods[]; + static const Luna::StaticType statics[]; + static const Luna::Enum enums[]; + +private: + //============================================================================== + // callbacks + virtual void paintButton(Graphics&, bool, bool) override; + virtual void buttonStateChanged() override; + virtual void buttonClicked (Button* buttonThatWasClicked) override; + + //============================================================================== + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LHyperlinkButton) +}; + +#endif // __LUCE_LHYPERLINKBUTTON_H diff --git a/Source/LHyperlinkButton_inh.h b/Source/LHyperlinkButton_inh.h new file mode 100644 index 0000000..d6117c6 --- /dev/null +++ b/Source/LHyperlinkButton_inh.h @@ -0,0 +1,293 @@ + +/* + 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 2 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +(c) 2013-2014, Peersuasive Technologies + +*/ + +// LButton inheritage +const Luna::Inheritence LHyperlinkButton::inherits[] = { + // LComponent + {"size", &LButton::getSize, &LButton::setSize}, // artificial + {"explicitFocusOrder", &LButton::getExplicitFocusOrder, &LButton::setExplicitFocusOrder}, + {"lookAndFeel", &LButton::getLookAndFeel, &LButton::setLookAndFeel}, + {"focusContainer", &LButton::isFocusContainer, &LButton::setFocusContainer}, + {"componentEffect", &LButton::getComponentEffect, &LButton::setComponentEffect}, + {"bounds", &LButton::getBounds, &LButton::setBounds}, + {"opaque", &LButton::isOpaque, &LButton::setOpaque}, + {"positioner", &LButton::getPositioner, &LButton::setPositioner}, + {"transform", &LButton::getTransform, &LButton::setTransform}, + {"componentID", &LButton::getComponentID, &LButton::setComponentID}, + {"enabled", &LButton::isEnabled, &LButton::setEnabled}, + {"alpha", &LButton::getAlpha, &LButton::setAlpha}, + {"alwaysOnTop", &LButton::isAlwaysOnTop, &LButton::setAlwaysOnTop}, + {"mouseCursor", &LButton::getMouseCursor, &LButton::setMouseCursor}, + {"wantsKeyboardFocus", &LButton::getWantsKeyboardFocus, &LButton::setWantsKeyboardFocus}, + {"cachedComponentImage", &LButton::getCachedComponentImage, &LButton::setCachedComponentImage}, + {"visible", &LButton::isVisible, &LButton::setVisible}, + {"broughtToFrontOnMouseClick", &LButton::isBroughtToFrontOnMouseClick, &LButton::setBroughtToFrontOnMouseClick}, + {"mouseClickGrabsKeyboardFocus", &LButton::getMouseClickGrabsKeyboardFocus, &LButton::setMouseClickGrabsKeyboardFocus}, + {"interceptsMouseClicks", &LComponent::getInterceptsMouseClicks, &LComponent::setInterceptsMouseClicks}, + {"name", &LButton::getName, &LButton::setName}, + + // LButton + {"clickingTogglesState", &LButton::getClickingTogglesState, &LButton::setClickingTogglesState}, + {"toggleState", &LButton::getToggleState, &LButton::setToggleState}, + {"radioGroupId", &LButton::getRadioGroupId, &LButton::setRadioGroupId}, + {"tooltip", &LButton::getTooltip, &LButton::setTooltip}, + {"buttonText", &LButton::getButtonText, &LButton::setButtonText}, + + {0,0} +}; + +const Luna::InheritenceF LHyperlinkButton::inheritsF[] = { + // LComponent + method( LComponent, as ), + method( LComponent, startDragging ), + method( LButton, getExplicitFocusOrder ), + method( LButton, setExplicitFocusOrder ), + method( LButton, findColour ), + method( LButton, getRight ), + method( LButton, getProperties ), + method( LButton, isParentOf ), + method( LButton, getLookAndFeel ), + method( LButton, setLookAndFeel ), + method( LButton, createComponentSnapshot ), + method( LButton, getScreenPosition ), + method( LButton, proportionOfHeight ), + method( LButton, isFocusContainer ), + method( LButton, setFocusContainer ), + method( LButton, getX ), + method( LButton, getY ), + method( LButton, getHeight ), + method( LButton, getComponentEffect ), + method( LButton, setComponentEffect ), + method( LButton, getTopLevelComponent ), + method( LButton, isMouseOver ), + method( LButton, getBounds ), + method( LButton, setBounds ), + method( LButton, reallyContains ), + method( LButton, localAreaToGlobal ), + method( LButton, getDesktopScaleFactor ), + method( LButton, getCurrentlyModalComponent ), + method( LButton, isOpaque ), + method( LButton, setOpaque ), + method( LButton, getParentWidth ), + method( LButton, getNumCurrentlyModalComponents ), + method( LButton, hasKeyboardFocus ), + method( LButton, getScreenY ), + method( LButton, findChildWithID ), + method( LButton, hitTest ), + method( LButton, isMouseOverOrDragging ), + method( LButton, getPositioner ), + method( LButton, setPositioner ), + method( LButton, isTransformed ), + method( LButton, getWidth ), + method( LButton, getLocalPoint ), + method( LButton, getTransform ), + method( LButton, setTransform ), + method( LButton, getComponentAt ), + method( LButton, getScreenBounds ), + method( LButton, getMouseXYRelative ), + method( LButton, getComponentID ), + method( LButton, setComponentID ), + method( LButton, keyStateChanged ), + method( LButton, getChildComponent ), + method( LButton, getScreenX ), + method( LButton, getParentMonitorArea ), + method( LButton, getLocalArea ), + method( LButton, isColourSpecified ), + method( LButton, isEnabled ), + method( LButton, setEnabled ), + method( LButton, canModalEventBeSentToComponent ), + method( LButton, isCurrentlyBlockedByAnotherModalComponent ), + method( LButton, findParentComponentOfClass ), + method( LButton, getNumChildComponents ), + method( LButton, isMouseButtonDownAnywhere ), + method( LButton, createFocusTraverser ), + method( LButton, isMouseButtonDown ), + method( LButton, localPointToGlobal ), + method( LButton, getPosition ), + method( LButton, getMarkers ), + method( LButton, getAlpha ), + method( LButton, setAlpha ), + method( LButton, isAlwaysOnTop ), + method( LButton, setAlwaysOnTop ), + method( LButton, getBoundsInParent ), + method( LButton, getParentHeight ), + method( LButton, getMouseCursor ), + method( LButton, setMouseCursor ), + method( LButton, getWantsKeyboardFocus ), + method( LButton, setWantsKeyboardFocus ), + method( LButton, proportionOfWidth ), + method( LButton, getBottom ), + method( LButton, getCachedComponentImage ), + method( LButton, setCachedComponentImage ), + method( LButton, getIndexOfChildComponent ), + method( LButton, contains ), + method( LButton, keyPressed ), + method( LButton, isVisible ), + method( LButton, setVisible ), + method( LButton, getPeer ), + method( LButton, isShowing ), + method( LButton, getLocalBounds ), + method( LButton, getParentComponent ), + method( LButton, isCurrentlyModal ), + method( LButton, isBroughtToFrontOnMouseClick ), + method( LButton, setBroughtToFrontOnMouseClick ), + method( LButton, getMouseClickGrabsKeyboardFocus ), + method( LButton, setMouseClickGrabsKeyboardFocus ), + method( LButton, getName ), + method( LButton, setName ), + method( LButton, getCurrentlyFocusedComponent ), + method( LButton, isOnDesktop ), + method( LButton, enterModalState ), + method( LButton, setBoundsInset ), + method( LButton, setRepaintsOnMouseActivity ), + method( LButton, toFront ), + method( LButton, addKeyListener ), + method( LButton, addAndMakeVisible ), + method( LButton, setTopLeftPosition ), + method( LButton, removeKeyListener ), + method( LButton, sendLookAndFeelChange ), + method( LButton, getWindowHandle ), + method( LButton, moveKeyboardFocusToSibling ), + method( LButton, addChildComponent ), + method( LButton, updateMouseCursor ), + method( LButton, addMouseListener ), + method( LButton, removeComponentListener ), + method( LButton, setPaintingIsUnclipped ), + method( LButton, unfocusAllComponents ), + method( LButton, centreWithSize ), + method( LButton, copyAllExplicitColoursTo ), + method( LButton, exitModalState ), + method( LButton, setInterceptsMouseClicks ), + method( LButton, setTopRightPosition ), + method( LButton, grabKeyboardFocus ), + method( LButton, addToDesktop ), + method( LButton, repaint ), + method( LButton, setBufferedToImage ), + method( LButton, setBoundsToFit ), + method( LButton, addChildAndSetID ), + method( LButton, getInterceptsMouseClicks ), + method( LButton, removeMouseListener ), + method( LButton, beginDragAutoRepeat ), + method( LButton, setColour ), + method( LButton, paintEntireComponent ), + method( LButton, deleteAllChildren ), + method( LButton, removeColour ), + method( LButton, setBoundsRelative ), + method( LButton, setCentrePosition ), + method( LButton, removeFromDesktop ), + method( LButton, getVisibleArea ), + method( LButton, toBehind ), + method( LButton, removeAllChildren ), + method( LButton, postCommandMessage ), + method( LButton, setCentreRelative ), + method( LButton, setSize ), + method( LButton, toBack ), + method( LButton, addComponentListener ), + method( LButton, visibilityChanged ), + method( LButton, userTriedToCloseWindow ), + method( LButton, minimisationStateChanged ), + method( LButton, parentHierarchyChanged ), + method( LButton, childrenChanged ), + method( LButton, lookAndFeelChanged ), + method( LButton, enablementChanged ), + method( LButton, paint ), + method( LButton, paintOverChildren ), + method( LButton, mouseMove ), + method( LButton, mouseEnter ), + method( LButton, mouseExit ), + method( LButton, mouseDown ), + method( LButton, mouseDrag ), + method( LButton, mouseUp ), + method( LButton, mouseDoubleClick ), + method( LButton, mouseWheelMove ), + method( LButton, mouseMagnify ), + method( LButton, modifierKeysChanged ), + method( LButton, focusGained ), + method( LButton, focusLost ), + method( LButton, focusOfChildComponentChanged ), + method( LButton, resized ), + method( LButton, moved ), + method( LButton, childBoundsChanged ), + method( LButton, parentSizeChanged ), + method( LButton, broughtToFront ), + method( LButton, handleCommandMessage ), + method( LButton, inputAttemptWhenModal ), + method( LButton, colourChanged ), + + // LButton + method( LButton, getConnectedEdgeFlags ), + method( LButton, isConnectedOnRight ), + method( LButton, isConnectedOnTop ), + method( LButton, getClickingTogglesState ), + method( LButton, setClickingTogglesState ), + method( LButton, isOver ), + method( LButton, isDown ), + method( LButton, getToggleState ), + method( LButton, setToggleState ), + method( LButton, isConnectedOnLeft ), + method( LButton, isConnectedOnBottom ), + method( LButton, getRadioGroupId ), + method( LButton, setRadioGroupId ), + method( LButton, getTooltip ), + method( LButton, setTooltip ), + method( LButton, isRegisteredForShortcut ), + method( LButton, getMillisecondsSinceButtonDown ), + method( LButton, getButtonText ), + method( LButton, setButtonText ), + method( LButton, getCommandID ), + method( LButton, getToggleStateValue ), + //method( LButton, removeListener ), + method( LButton, setConnectedEdges ), + //method( LButton, addListener ), + method( LButton, addShortcut ), + method( LButton, setState ), + method( LButton, clearShortcuts ), + method( LButton, setCommandToTrigger ), + method( LButton, setTriggeredOnMouseDown ), + method( LButton, setRepeatSpeed ), + method( LButton, triggerClick ), + method( LButton, clicked ), + method( LButton, paintButton ), + method( LButton, buttonStateChanged ), + method( LButton, buttonClicked ), + method( LButton, internalClickCallback ), + + {0,0} +}; + +const Luna::Enum LHyperlinkButton::enums[] = { + { "ConnectedEdgeFlags", { + { "ConnectedOnLeft" , Button::ConnectedOnLeft }, + { "ConnectedOnRight" , Button::ConnectedOnRight }, + { "ConnectedOnTop" , Button::ConnectedOnTop }, + { "ConnectedOnBottom" , Button::ConnectedOnBottom }, + }}, + + { "ButtonState", { + { "buttonNormal" , Button::buttonNormal }, + { "buttonOver" , Button::buttonOver }, + { "buttonDown" , Button::buttonDown }, + }}, + + { "ColourIds", { + { "textColourId" , HyperlinkButton::textColourId }, + }}, + {0} +}; diff --git a/Source/Main.cpp b/Source/Main.cpp index 01405c9..8babe47 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -168,6 +168,7 @@ l_class(MainComponent); l_class(JComponent); l_class(TextButton); l_class(ToggleButton); +l_class(HyperlinkButton); l_class(Label); l_class(TextEditor); l_class(TreeView); @@ -200,6 +201,7 @@ static const luaL_Reg luce_lib [] = { { "Component", l_JComponent }, d(TextButton), d(ToggleButton), + d(HyperlinkButton), d(TextEditor), d(Label), d(TreeView), diff --git a/Source/luce.cpp b/Source/luce.cpp index 07bf426..8852dd2 100644 --- a/Source/luce.cpp +++ b/Source/luce.cpp @@ -36,6 +36,7 @@ namespace luce { #include "LLabel.cpp" #include "LTextButton.cpp" #include "LToggleButton.cpp" +#include "LHyperlinkButton.cpp" #include "LTextEditor.cpp" //#include "LValueTree.cpp" #include "LTreeView.cpp" diff --git a/Source/luce.h b/Source/luce.h index b8155b0..939337a 100644 --- a/Source/luce.h +++ b/Source/luce.h @@ -56,6 +56,7 @@ namespace luce { #include "LLabel.h" #include "LTextButton.h" #include "LToggleButton.h" +#include "LHyperlinkButton.h" #include "LTextEditor.h" //#include "LValueTree.h" #include "LTreeView.h"