From b974203d0fd9ac76847b8a35a3dc67464a516087 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Sun, 7 Mar 2010 13:01:33 +0000 Subject: [PATCH] Couple of new methods for String. Cleaned up some component code to use SafePointers. --- src/containers/juce_BitArray.cpp | 5 +- src/core/juce_StandardHeader.h | 312 +++++++++--------- src/core/juce_Time.cpp | 19 +- .../layout/juce_ResizableBorderComponent.cpp | 115 +++---- .../layout/juce_ResizableBorderComponent.h | 10 +- .../layout/juce_ResizableCornerComponent.cpp | 35 +- .../layout/juce_ResizableCornerComponent.h | 4 +- src/gui/components/layout/juce_Viewport.cpp | 4 +- src/gui/components/layout/juce_Viewport.h | 2 +- .../mouse/juce_ComponentDragger.cpp | 18 +- src/gui/components/mouse/juce_MouseEvent.cpp | 5 + src/gui/components/mouse/juce_MouseEvent.h | 7 + .../mouse/juce_MouseInputSource.cpp | 2 +- .../components/mouse/juce_MouseInputSource.h | 6 +- .../special/juce_ColourSelector.cpp | 23 +- .../components/windows/juce_AlertWindow.cpp | 8 +- .../components/windows/juce_ComponentPeer.cpp | 14 +- .../components/windows/juce_TooltipWindow.cpp | 2 +- src/native/mac/juce_mac_MainMenu.mm | 2 +- .../mac/juce_mac_NSViewComponentPeer.mm | 5 +- src/text/juce_String.cpp | 44 ++- src/text/juce_String.h | 12 +- 22 files changed, 328 insertions(+), 326 deletions(-) diff --git a/src/containers/juce_BitArray.cpp b/src/containers/juce_BitArray.cpp index 1cad30b639..2e31e48f25 100644 --- a/src/containers/juce_BitArray.cpp +++ b/src/containers/juce_BitArray.cpp @@ -866,10 +866,7 @@ const String BitArray::toString (const int base, const int minimumNumCharacters) return String::empty; } - const int length = s.length(); - - if (length < minimumNumCharacters) - s = String::repeatedString (T("0"), minimumNumCharacters - length) + s; + s = s.paddedLeft ('0', minimumNumCharacters); return isNegative() ? T("-") + s : s; } diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index bc8787dbaf..93edfaf424 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -1,156 +1,156 @@ -/* - ============================================================================== - - This file is part of the JUCE library - "Jules' Utility Class Extensions" - Copyright 2004-9 by Raw Material Software Ltd. - - ------------------------------------------------------------------------------ - - JUCE can be redistributed and/or modified under the terms of the GNU General - Public License (Version 2), as published by the Free Software Foundation. - A copy of the license is included in the JUCE distribution, or can be found - online at www.gnu.org/licenses. - - JUCE 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. - - ------------------------------------------------------------------------------ - - To release a closed-source product which uses JUCE, commercial licenses are - available: visit www.rawmaterialsoftware.com/juce for more information. - - ============================================================================== -*/ - -#ifndef __JUCE_STANDARDHEADER_JUCEHEADER__ -#define __JUCE_STANDARDHEADER_JUCEHEADER__ - -//============================================================================== -/** Current Juce version number. - - See also SystemStats::getJUCEVersion() for a string version. -*/ -#define JUCE_MAJOR_VERSION 1 -#define JUCE_MINOR_VERSION 51 -#define JUCE_BUILDNUMBER 6 - -/** Current Juce version number. - - Bits 16 to 32 = major version. - Bits 8 to 16 = minor version. - Bits 0 to 8 = point release (not currently used). - - See also SystemStats::getJUCEVersion() for a string version. -*/ -#define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8) + JUCE_BUILDNUMBER) - - -//============================================================================== -#include "juce_TargetPlatform.h" // (sets up the various JUCE_WINDOWS, JUCE_MAC, etc flags) - -#include "../../juce_Config.h" - -//============================================================================== -#ifdef JUCE_NAMESPACE - #define BEGIN_JUCE_NAMESPACE namespace JUCE_NAMESPACE { - #define END_JUCE_NAMESPACE } -#else - #define BEGIN_JUCE_NAMESPACE - #define END_JUCE_NAMESPACE -#endif - -//============================================================================== -#include "juce_PlatformDefs.h" - -// Now we'll include any OS headers we need.. (at this point we are outside the Juce namespace). -#if JUCE_MSVC - #if (defined(_MSC_VER) && (_MSC_VER <= 1200)) - #pragma warning (disable: 4284) // (spurious VC6 warning) - #endif - - #pragma warning (push) - #pragma warning (disable: 4514 4245 4100) -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if JUCE_USE_INTRINSICS - #include -#endif - -#if JUCE_MAC || JUCE_IPHONE - #include -#endif - -#if JUCE_LINUX - #include -#endif - -#if JUCE_MSVC && JUCE_DEBUG - #include -#endif - -#if JUCE_MSVC - #include - #pragma warning (pop) - - #if ! JUCE_PUBLIC_INCLUDES - #pragma warning (4: 4511 4512 4100) // (enable some warnings that are turned off in VC8) - #endif -#endif - -//============================================================================== -// DLL building settings on Win32 -#if JUCE_MSVC - #ifdef JUCE_DLL_BUILD - #define JUCE_API __declspec (dllexport) - #pragma warning (disable: 4251) - #elif defined (JUCE_DLL) - #define JUCE_API __declspec (dllimport) - #pragma warning (disable: 4251) - #endif -#elif defined (__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) - #ifdef JUCE_DLL_BUILD - #define JUCE_API __attribute__ ((visibility("default"))) - #endif -#endif - -#ifndef JUCE_API - /** This macro is added to all juce public class declarations. */ - #define JUCE_API -#endif - -/** This macro is added to all juce public function declarations. */ -#define JUCE_PUBLIC_FUNCTION JUCE_API JUCE_CALLTYPE - - -//============================================================================== -// Now include some basics that are needed by most of the Juce classes... -BEGIN_JUCE_NAMESPACE - -extern bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger(); - -#if JUCE_LOG_ASSERTIONS - extern void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw(); -#endif - -#include "juce_Memory.h" -#include "juce_MathsFunctions.h" -#include "juce_ByteOrder.h" -#include "juce_Logger.h" - -END_JUCE_NAMESPACE - - -#endif // __JUCE_STANDARDHEADER_JUCEHEADER__ +/* + ============================================================================== + + This file is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-9 by Raw Material Software Ltd. + + ------------------------------------------------------------------------------ + + JUCE can be redistributed and/or modified under the terms of the GNU General + Public License (Version 2), as published by the Free Software Foundation. + A copy of the license is included in the JUCE distribution, or can be found + online at www.gnu.org/licenses. + + JUCE 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. + + ------------------------------------------------------------------------------ + + To release a closed-source product which uses JUCE, commercial licenses are + available: visit www.rawmaterialsoftware.com/juce for more information. + + ============================================================================== +*/ + +#ifndef __JUCE_STANDARDHEADER_JUCEHEADER__ +#define __JUCE_STANDARDHEADER_JUCEHEADER__ + +//============================================================================== +/** Current Juce version number. + + See also SystemStats::getJUCEVersion() for a string version. +*/ +#define JUCE_MAJOR_VERSION 1 +#define JUCE_MINOR_VERSION 51 +#define JUCE_BUILDNUMBER 7 + +/** Current Juce version number. + + Bits 16 to 32 = major version. + Bits 8 to 16 = minor version. + Bits 0 to 8 = point release (not currently used). + + See also SystemStats::getJUCEVersion() for a string version. +*/ +#define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8) + JUCE_BUILDNUMBER) + + +//============================================================================== +#include "juce_TargetPlatform.h" // (sets up the various JUCE_WINDOWS, JUCE_MAC, etc flags) + +#include "../../juce_Config.h" + +//============================================================================== +#ifdef JUCE_NAMESPACE + #define BEGIN_JUCE_NAMESPACE namespace JUCE_NAMESPACE { + #define END_JUCE_NAMESPACE } +#else + #define BEGIN_JUCE_NAMESPACE + #define END_JUCE_NAMESPACE +#endif + +//============================================================================== +#include "juce_PlatformDefs.h" + +// Now we'll include any OS headers we need.. (at this point we are outside the Juce namespace). +#if JUCE_MSVC + #if (defined(_MSC_VER) && (_MSC_VER <= 1200)) + #pragma warning (disable: 4284) // (spurious VC6 warning) + #endif + + #pragma warning (push) + #pragma warning (disable: 4514 4245 4100) +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if JUCE_USE_INTRINSICS + #include +#endif + +#if JUCE_MAC || JUCE_IPHONE + #include +#endif + +#if JUCE_LINUX + #include +#endif + +#if JUCE_MSVC && JUCE_DEBUG + #include +#endif + +#if JUCE_MSVC + #include + #pragma warning (pop) + + #if ! JUCE_PUBLIC_INCLUDES + #pragma warning (4: 4511 4512 4100) // (enable some warnings that are turned off in VC8) + #endif +#endif + +//============================================================================== +// DLL building settings on Win32 +#if JUCE_MSVC + #ifdef JUCE_DLL_BUILD + #define JUCE_API __declspec (dllexport) + #pragma warning (disable: 4251) + #elif defined (JUCE_DLL) + #define JUCE_API __declspec (dllimport) + #pragma warning (disable: 4251) + #endif +#elif defined (__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) + #ifdef JUCE_DLL_BUILD + #define JUCE_API __attribute__ ((visibility("default"))) + #endif +#endif + +#ifndef JUCE_API + /** This macro is added to all juce public class declarations. */ + #define JUCE_API +#endif + +/** This macro is added to all juce public function declarations. */ +#define JUCE_PUBLIC_FUNCTION JUCE_API JUCE_CALLTYPE + + +//============================================================================== +// Now include some basics that are needed by most of the Juce classes... +BEGIN_JUCE_NAMESPACE + +extern bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger(); + +#if JUCE_LOG_ASSERTIONS + extern void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw(); +#endif + +#include "juce_Memory.h" +#include "juce_MathsFunctions.h" +#include "juce_ByteOrder.h" +#include "juce_Logger.h" + +END_JUCE_NAMESPACE + + +#endif // __JUCE_STANDARDHEADER_JUCEHEADER__ diff --git a/src/core/juce_Time.cpp b/src/core/juce_Time.cpp index 1112027a48..71bd9726a5 100644 --- a/src/core/juce_Time.cpp +++ b/src/core/juce_Time.cpp @@ -310,20 +310,15 @@ const String Time::toString (const bool includeDate, if (includeTime) { + const int mins = getMinutes(); + + result << (use24HourClock ? getHours() : getHoursInAmPmFormat()) + << (mins < 10 ? ":0" : ":") << mins; + if (includeSeconds) { - result += String::formatted (T("%d:%02d:%02d "), - (use24HourClock) ? getHours() - : getHoursInAmPmFormat(), - getMinutes(), - getSeconds()); - } - else - { - result += String::formatted (T("%d.%02d"), - (use24HourClock) ? getHours() - : getHoursInAmPmFormat(), - getMinutes()); + const int secs = getSeconds(); + result << (secs < 10 ? ":0" : ":") << secs; } if (! use24HourClock) diff --git a/src/gui/components/layout/juce_ResizableBorderComponent.cpp b/src/gui/components/layout/juce_ResizableBorderComponent.cpp index de3d982e43..48093333f4 100644 --- a/src/gui/components/layout/juce_ResizableBorderComponent.cpp +++ b/src/gui/components/layout/juce_ResizableBorderComponent.cpp @@ -33,10 +33,13 @@ BEGIN_JUCE_NAMESPACE #include "../../graphics/geometry/juce_Line.h" #include "../lookandfeel/juce_LookAndFeel.h" -const int zoneL = 1; -const int zoneR = 2; -const int zoneT = 4; -const int zoneB = 8; +enum ResizableBorderComponentZones +{ + zoneL = 1, + zoneR = 2, + zoneT = 4, + zoneB = 8 +}; //============================================================================== ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize, @@ -70,67 +73,50 @@ void ResizableBorderComponent::mouseMove (const MouseEvent& e) void ResizableBorderComponent::mouseDown (const MouseEvent& e) { - if (component->isValidComponent()) + if (component == 0) { - updateMouseZone (e); - - originalX = component->getX(); - originalY = component->getY(); - originalW = component->getWidth(); - originalH = component->getHeight(); - - if (constrainer != 0) - constrainer->resizeStart(); - } - else - { - jassertfalse + jassertfalse // You've deleted the component that this resizer was supposed to be using! + return; } + + updateMouseZone (e); + + originalBounds = component->getBounds(); + + if (constrainer != 0) + constrainer->resizeStart(); } void ResizableBorderComponent::mouseDrag (const MouseEvent& e) { - if (! component->isValidComponent()) + if (component == 0) { - jassertfalse + jassertfalse // You've deleted the component that this resizer was supposed to be using! return; } - int x = originalX; - int y = originalY; - int w = originalW; - int h = originalH; - - const int dx = e.getDistanceFromDragStartX(); - const int dy = e.getDistanceFromDragStartY(); + Rectangle bounds (originalBounds); if ((mouseZone & zoneL) != 0) - { - x += dx; - w -= dx; - } + bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX()); if ((mouseZone & zoneT) != 0) - { - y += dy; - h -= dy; - } + bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY()); if ((mouseZone & zoneR) != 0) - w += dx; + bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX()); if ((mouseZone & zoneB) != 0) - h += dy; + bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY()); if (constrainer != 0) - constrainer->setBoundsForComponent (component, - Rectangle (x, y, w, h), + constrainer->setBoundsForComponent (component, bounds, (mouseZone & zoneT) != 0, (mouseZone & zoneL) != 0, (mouseZone & zoneB) != 0, (mouseZone & zoneR) != 0); else - component->setBounds (x, y, w, h); + component->setBounds (bounds); } void ResizableBorderComponent::mouseUp (const MouseEvent&) @@ -147,7 +133,7 @@ bool ResizableBorderComponent::hitTest (int x, int y) || y >= getHeight() - borderSize.getBottom(); } -void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw() +void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) { if (borderSize != newBorderSize) { @@ -156,12 +142,12 @@ void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSi } } -const BorderSize ResizableBorderComponent::getBorderThickness() const throw() +const BorderSize ResizableBorderComponent::getBorderThickness() const { return borderSize; } -void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw() +void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) { int newZone = 0; @@ -194,40 +180,15 @@ void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw() switch (newZone) { - case (zoneL | zoneT): - mc = MouseCursor::TopLeftCornerResizeCursor; - break; - - case zoneT: - mc = MouseCursor::TopEdgeResizeCursor; - break; - - case (zoneR | zoneT): - mc = MouseCursor::TopRightCornerResizeCursor; - break; - - case zoneL: - mc = MouseCursor::LeftEdgeResizeCursor; - break; - - case zoneR: - mc = MouseCursor::RightEdgeResizeCursor; - break; - - case (zoneL | zoneB): - mc = MouseCursor::BottomLeftCornerResizeCursor; - break; - - case zoneB: - mc = MouseCursor::BottomEdgeResizeCursor; - break; - - case (zoneR | zoneB): - mc = MouseCursor::BottomRightCornerResizeCursor; - break; - - default: - break; + case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break; + case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break; + case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break; + case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break; + case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break; + case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break; + case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break; + case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break; + default: break; } setMouseCursor (mc); diff --git a/src/gui/components/layout/juce_ResizableBorderComponent.h b/src/gui/components/layout/juce_ResizableBorderComponent.h index bf60f2f940..d1051836b9 100644 --- a/src/gui/components/layout/juce_ResizableBorderComponent.h +++ b/src/gui/components/layout/juce_ResizableBorderComponent.h @@ -78,13 +78,13 @@ public: @see getBorderThickness */ - void setBorderThickness (const BorderSize& newBorderSize) throw(); + void setBorderThickness (const BorderSize& newBorderSize); /** Returns the number of pixels wide that the draggable edges of this component are. @see setBorderThickness */ - const BorderSize getBorderThickness() const throw(); + const BorderSize getBorderThickness() const; //============================================================================== @@ -107,13 +107,13 @@ protected: bool hitTest (int x, int y); private: - Component* const component; + Component::SafePointer component; ComponentBoundsConstrainer* constrainer; BorderSize borderSize; - int originalX, originalY, originalW, originalH; + Rectangle originalBounds; int mouseZone; - void updateMouseZone (const MouseEvent& e) throw(); + void updateMouseZone (const MouseEvent& e); ResizableBorderComponent (const ResizableBorderComponent&); ResizableBorderComponent& operator= (const ResizableBorderComponent&); diff --git a/src/gui/components/layout/juce_ResizableCornerComponent.cpp b/src/gui/components/layout/juce_ResizableCornerComponent.cpp index d439a4f160..ef2fc1d8f5 100644 --- a/src/gui/components/layout/juce_ResizableCornerComponent.cpp +++ b/src/gui/components/layout/juce_ResizableCornerComponent.cpp @@ -58,40 +58,33 @@ void ResizableCornerComponent::paint (Graphics& g) void ResizableCornerComponent::mouseDown (const MouseEvent&) { - if (component->isValidComponent()) + if (component == 0) { - originalX = component->getX(); - originalY = component->getY(); - originalW = component->getWidth(); - originalH = component->getHeight(); + jassertfalse; // You've deleted the component that this resizer is supposed to be controlling! + return; + } - if (constrainer != 0) - constrainer->resizeStart(); - } - else - { - jassertfalse - } + originalBounds = component->getBounds(); + + if (constrainer != 0) + constrainer->resizeStart(); } void ResizableCornerComponent::mouseDrag (const MouseEvent& e) { - if (! component->isValidComponent()) + if (component == 0) { - jassertfalse + jassertfalse; // You've deleted the component that this resizer is supposed to be controlling! return; } - int x = originalX; - int y = originalY; - int w = originalW + e.getDistanceFromDragStartX(); - int h = originalH + e.getDistanceFromDragStartY(); + Rectangle r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(), + originalBounds.getHeight() + e.getDistanceFromDragStartY())); if (constrainer != 0) - constrainer->setBoundsForComponent (component, Rectangle (x, y, w, h), - false, false, true, true); + constrainer->setBoundsForComponent (component, r, false, false, true, true); else - component->setBounds (x, y, w, h); + component->setBounds (r); } void ResizableCornerComponent::mouseUp (const MouseEvent&) diff --git a/src/gui/components/layout/juce_ResizableCornerComponent.h b/src/gui/components/layout/juce_ResizableCornerComponent.h index e5ea5bb620..f41de52ee3 100644 --- a/src/gui/components/layout/juce_ResizableCornerComponent.h +++ b/src/gui/components/layout/juce_ResizableCornerComponent.h @@ -85,9 +85,9 @@ protected: private: //============================================================================== - Component* const component; + Component::SafePointer component; ComponentBoundsConstrainer* constrainer; - int originalX, originalY, originalW, originalH; + Rectangle originalBounds; ResizableCornerComponent (const ResizableCornerComponent&); ResizableCornerComponent& operator= (const ResizableCornerComponent&); diff --git a/src/gui/components/layout/juce_Viewport.cpp b/src/gui/components/layout/juce_Viewport.cpp index 2dc2595636..a9768b835f 100644 --- a/src/gui/components/layout/juce_Viewport.cpp +++ b/src/gui/components/layout/juce_Viewport.cpp @@ -78,11 +78,9 @@ void Viewport::setViewedComponent (Component* const newViewedComponent) { if (contentComp != newViewedComponent) { - if (contentComp->isValidComponent()) { - Component* const oldComp = contentComp; + ScopedPointer oldCompDeleter (contentComp); contentComp = 0; - delete oldComp; } contentComp = newViewedComponent; diff --git a/src/gui/components/layout/juce_Viewport.h b/src/gui/components/layout/juce_Viewport.h index 12027935db..c919dfdd14 100644 --- a/src/gui/components/layout/juce_Viewport.h +++ b/src/gui/components/layout/juce_Viewport.h @@ -242,7 +242,7 @@ public: bool useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY); private: - Component* contentComp; + Component::SafePointer contentComp; int lastVX, lastVY, lastVW, lastVH; int scrollBarThickness; int singleStepX, singleStepY; diff --git a/src/gui/components/mouse/juce_ComponentDragger.cpp b/src/gui/components/mouse/juce_ComponentDragger.cpp index 87bad690e5..74681b92fc 100644 --- a/src/gui/components/mouse/juce_ComponentDragger.cpp +++ b/src/gui/components/mouse/juce_ComponentDragger.cpp @@ -47,7 +47,7 @@ void ComponentDragger::startDraggingComponent (Component* const componentToDrag, { jassert (componentToDrag->isValidComponent()); - if (componentToDrag->isValidComponent()) + if (componentToDrag != 0) { constrainer = constrainer_; originalPos = componentToDrag->relativePositionToGlobal (Point()); @@ -59,24 +59,20 @@ void ComponentDragger::dragComponent (Component* const componentToDrag, const Mo jassert (componentToDrag->isValidComponent()); jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..) - if (componentToDrag->isValidComponent()) + if (componentToDrag != 0) { - Point pos (originalPos); - int w = componentToDrag->getWidth(); - int h = componentToDrag->getHeight(); + Rectangle bounds (componentToDrag->getBounds().withPosition (originalPos)); const Component* const parentComp = componentToDrag->getParentComponent(); if (parentComp != 0) - pos = parentComp->globalPositionToRelative (pos); + bounds.setPosition (parentComp->globalPositionToRelative (originalPos)); - pos += Point (e.getDistanceFromDragStartX(), - e.getDistanceFromDragStartY()); + bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart()); if (constrainer != 0) - constrainer->setBoundsForComponent (componentToDrag, Rectangle (pos.getX(), pos.getY(), w, h), - false, false, false, false); + constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false); else - componentToDrag->setBounds (pos.getX(), pos.getY(), w, h); + componentToDrag->setBounds (bounds); } } diff --git a/src/gui/components/mouse/juce_MouseEvent.cpp b/src/gui/components/mouse/juce_MouseEvent.cpp index 9777702b3a..d69cfc1926 100644 --- a/src/gui/components/mouse/juce_MouseEvent.cpp +++ b/src/gui/components/mouse/juce_MouseEvent.cpp @@ -117,6 +117,11 @@ int MouseEvent::getDistanceFromDragStart() const throw() return mouseDownPos.getDistanceFrom (getPosition()); } +const Point MouseEvent::getOffsetFromDragStart() const throw() +{ + return getPosition() - mouseDownPos; +} + int MouseEvent::getLengthOfMousePress() const throw() { if (mouseDownTime.toMilliseconds() > 0) diff --git a/src/gui/components/mouse/juce_MouseEvent.h b/src/gui/components/mouse/juce_MouseEvent.h index 399b031dd8..dc93f49786 100644 --- a/src/gui/components/mouse/juce_MouseEvent.h +++ b/src/gui/components/mouse/juce_MouseEvent.h @@ -181,6 +181,13 @@ public: */ int getDistanceFromDragStartY() const throw(); + /** Returns the difference between the mouse's current postion and where it was + when the button was last pressed. + + @see getDistanceFromDragStart + */ + const Point getOffsetFromDragStart() const throw(); + /** Returns true if the mouse has just been clicked. Used in either your mouseUp() or mouseDrag() methods, this will tell you whether diff --git a/src/gui/components/mouse/juce_MouseInputSource.cpp b/src/gui/components/mouse/juce_MouseInputSource.cpp index 9006526767..7c25b96e1c 100644 --- a/src/gui/components/mouse/juce_MouseInputSource.cpp +++ b/src/gui/components/mouse/juce_MouseInputSource.cpp @@ -59,7 +59,7 @@ public: Component* getComponentUnderMouse() const { - return const_cast (static_cast (componentUnderMouse)); + return static_cast (componentUnderMouse); } const ModifierKeys getCurrentModifiers() const diff --git a/src/gui/components/mouse/juce_MouseInputSource.h b/src/gui/components/mouse/juce_MouseInputSource.h index 91e0fdc895..180b41eb7c 100644 --- a/src/gui/components/mouse/juce_MouseInputSource.h +++ b/src/gui/components/mouse/juce_MouseInputSource.h @@ -23,8 +23,8 @@ ============================================================================== */ -#ifndef __JUCE_MOUSEEVENT_JUCEHEADER__x -#define __JUCE_MOUSEEVENT_JUCEHEADER__x +#ifndef __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__ +#define __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__ class Component; class ComponentPeer; @@ -177,4 +177,4 @@ private: }; -#endif // __JUCE_MOUSEEVENT_JUCEHEADER__ +#endif // __JUCE_MOUSEINPUTSOURCE_JUCEHEADER__ diff --git a/src/gui/components/special/juce_ColourSelector.cpp b/src/gui/components/special/juce_ColourSelector.cpp index 859b90552d..e55d19d676 100644 --- a/src/gui/components/special/juce_ColourSelector.cpp +++ b/src/gui/components/special/juce_ColourSelector.cpp @@ -36,6 +36,11 @@ BEGIN_JUCE_NAMESPACE static const int swatchesPerRow = 8; static const int swatchHeight = 22; +static const String colourComponentToHexString (int value) +{ + return String::toHexString (value).toUpperCase().paddedLeft ('0', 2); +} + //============================================================================== class ColourComponentSlider : public Slider { @@ -52,7 +57,7 @@ public: const String getTextFromValue (double value) { - return String::formatted (T("%02X"), (int) value); + return colourComponentToHexString ((int) value); } double getValueFromText (const String& text) @@ -496,15 +501,13 @@ void ColourSelector::paint (Graphics& g) g.setColour (Colours::white.overlaidWith (colour).contrasting()); g.setFont (14.0f, true); g.drawText (((flags & showAlphaChannel) != 0) - ? String::formatted (T("#%02X%02X%02X%02X"), - (int) colour.getAlpha(), - (int) colour.getRed(), - (int) colour.getGreen(), - (int) colour.getBlue()) - : String::formatted (T("#%02X%02X%02X"), - (int) colour.getRed(), - (int) colour.getGreen(), - (int) colour.getBlue()), + ? colourComponentToHexString ((int) colour.getAlpha()) + + colourComponentToHexString ((int) colour.getRed()) + + colourComponentToHexString ((int) colour.getGreen()) + + colourComponentToHexString ((int) colour.getBlue()) + : colourComponentToHexString ((int) colour.getRed()) + + colourComponentToHexString ((int) colour.getGreen()) + + colourComponentToHexString ((int) colour.getBlue()), 0, edgeGap, getWidth(), topSpace - edgeGap * 2, Justification::centred, false); } diff --git a/src/gui/components/windows/juce_AlertWindow.cpp b/src/gui/components/windows/juce_AlertWindow.cpp index 1e172051aa..b046014889 100644 --- a/src/gui/components/windows/juce_AlertWindow.cpp +++ b/src/gui/components/windows/juce_AlertWindow.cpp @@ -616,7 +616,7 @@ struct AlertWindowInfo String title, message, button1, button2, button3; AlertWindow::AlertIconType iconType; int numButtons; - Component* associatedComponent; + Component::SafePointer associatedComponent; int run() const { @@ -627,10 +627,8 @@ struct AlertWindowInfo private: int show() const { - jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted? - - LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel() - : LookAndFeel::getDefaultLookAndFeel(); + LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel() + : LookAndFeel::getDefaultLookAndFeel(); ScopedPointer alertBox (lf.createAlertWindow (title, message, button1, button2, button3, iconType, numButtons, associatedComponent)); diff --git a/src/gui/components/windows/juce_ComponentPeer.cpp b/src/gui/components/windows/juce_ComponentPeer.cpp index 12dcc2c14e..1bfa5eba95 100644 --- a/src/gui/components/windows/juce_ComponentPeer.cpp +++ b/src/gui/components/windows/juce_ComponentPeer.cpp @@ -151,8 +151,8 @@ bool ComponentPeer::handleKeyPress (const int keyCode, { updateCurrentModifiers(); - Component* target = Component::currentlyFocusedComponent->isValidComponent() - ? Component::currentlyFocusedComponent + Component* target = Component::getCurrentlyFocusedComponent() != 0 + ? Component::getCurrentlyFocusedComponent() : component; if (target->isCurrentlyBlockedByAnotherModalComponent()) @@ -210,8 +210,8 @@ bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown) { updateCurrentModifiers(); - Component* target = Component::currentlyFocusedComponent->isValidComponent() - ? Component::currentlyFocusedComponent + Component* target = Component::getCurrentlyFocusedComponent() != 0 + ? Component::getCurrentlyFocusedComponent() : component; if (target->isCurrentlyBlockedByAnotherModalComponent()) @@ -264,7 +264,7 @@ void ComponentPeer::handleModifierKeysChange() if (target == 0) target = component; - if (target->isValidComponent()) + if (target != 0) target->internalModifierKeysChanged(); } @@ -415,7 +415,7 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, const Point (dynamic_cast (static_cast (dragAndDropTargetComponent))); + = dynamic_cast (static_cast (dragAndDropTargetComponent)); FileDragAndDropTarget* newTarget = 0; @@ -470,7 +470,7 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point (dynamic_cast (static_cast (dragAndDropTargetComponent))); + = dynamic_cast (static_cast (dragAndDropTargetComponent)); dragAndDropTargetComponent = 0; lastDragAndDropCompUnderMouse = 0; diff --git a/src/gui/components/windows/juce_TooltipWindow.cpp b/src/gui/components/windows/juce_TooltipWindow.cpp index cd64471cdc..3a388c83b9 100644 --- a/src/gui/components/windows/juce_TooltipWindow.cpp +++ b/src/gui/components/windows/juce_TooltipWindow.cpp @@ -113,7 +113,7 @@ void TooltipWindow::showFor (const String& tip) const String TooltipWindow::getTipFor (Component* const c) { - if (c->isValidComponent() + if (c != 0 && Process::isForegroundProcess() && ! Component::isMouseButtonDownAnywhere()) { diff --git a/src/native/mac/juce_mac_MainMenu.mm b/src/native/mac/juce_mac_MainMenu.mm index c47bdf1da5..e385818e44 100644 --- a/src/native/mac/juce_mac_MainMenu.mm +++ b/src/native/mac/juce_mac_MainMenu.mm @@ -378,7 +378,7 @@ END_JUCE_NAMESPACE NSEvent* e = [NSApp currentEvent]; if ([e type] == NSKeyDown || [e type] == NSKeyUp) { - if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent()) + if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0) { JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer()); diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index 5308795251..6fe58a9991 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -1456,10 +1456,7 @@ BOOL NSViewComponentPeer::sendDragCallback (int type, id sender bool NSViewComponentPeer::isOpaque() { - if (! getComponent()->isValidComponent()) - return true; - - return getComponent()->isOpaque(); + return component == 0 || component->isOpaque(); } void NSViewComponentPeer::drawRect (NSRect r) diff --git a/src/text/juce_String.cpp b/src/text/juce_String.cpp index 517d4bb000..aec8bad7cf 100644 --- a/src/text/juce_String.cpp +++ b/src/text/juce_String.cpp @@ -1157,7 +1157,7 @@ void String::vprintf (const tchar* const pf, va_list& args) throw() //============================================================================== const String String::repeatedString (const tchar* const stringToRepeat, - int numberOfTimesToRepeat) throw() + int numberOfTimesToRepeat) { const int len = CharacterFunctions::length (stringToRepeat); String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0); @@ -1174,6 +1174,48 @@ const String String::repeatedString (const tchar* const stringToRepeat, return result; } +const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const +{ + if (padCharacter == 0) + { + jassertfalse; + return *this; + } + + const int len = length(); + + if (len >= minimumLength) + return *this; + + String result ((int) minimumLength + 1, (int) 0); + + tchar* n = result.text->text; + + minimumLength -= len; + while (--minimumLength >= 0) + *n++ = padCharacter; + + *n = 0; + CharacterFunctions::append (n, text->text); + + return result; +} + +const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const +{ + if (padCharacter == 0) + { + jassertfalse; + return *this; + } + + const int paddingNeeded = minimumLength - length(); + if (paddingNeeded <= 0) + return *this; + + return *this + String::empty.paddedLeft (padCharacter, paddingNeeded); +} + //============================================================================== const String String::replaceSection (int index, int numCharsToReplace, diff --git a/src/text/juce_String.h b/src/text/juce_String.h index 1ef4a08f10..b57a948ff8 100644 --- a/src/text/juce_String.h +++ b/src/text/juce_String.h @@ -750,7 +750,17 @@ public: @param numberOfTimesToRepeat how many times to repeat it */ static const String repeatedString (const tchar* const stringToRepeat, - int numberOfTimesToRepeat) throw(); + int numberOfTimesToRepeat); + + /** Returns a copy of this string with the specified character repeatedly added to its + beginning until the total length is at least the minimum length specified. + */ + const String paddedLeft (const juce_wchar padCharacter, int minimumLength) const; + + /** Returns a copy of this string with the specified character repeatedly added to its + end until the total length is at least the minimum length specified. + */ + const String paddedRight (const juce_wchar padCharacter, int minimumLength) const; /** Creates a string from data in an unknown format.