The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53442 lines
1.9MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. /*
  24. ==============================================================================
  25. This header contains the entire Juce source tree, and can be #included in
  26. all your source files.
  27. As well as including this in your files, you should also add juce_inline.cpp
  28. to your project (or juce_inline.mm on the Mac).
  29. ==============================================================================
  30. */
  31. #ifndef __JUCE_AMALGAMATED_TEMPLATE_JUCEHEADER__
  32. #define __JUCE_AMALGAMATED_TEMPLATE_JUCEHEADER__
  33. #define DONT_AUTOLINK_TO_JUCE_LIBRARY 1
  34. /********* Start of inlined file: juce.h *********/
  35. #ifndef __JUCE_JUCEHEADER__
  36. #define __JUCE_JUCEHEADER__
  37. /*
  38. This is the main JUCE header file that applications need to include.
  39. */
  40. // (this includes things that need defining outside of the JUCE namespace)
  41. /********* Start of inlined file: juce_StandardHeader.h *********/
  42. #ifndef __JUCE_STANDARDHEADER_JUCEHEADER__
  43. #define __JUCE_STANDARDHEADER_JUCEHEADER__
  44. /** Current Juce version number.
  45. See also SystemStats::getJUCEVersion() for a string version.
  46. */
  47. #define JUCE_MAJOR_VERSION 1
  48. #define JUCE_MINOR_VERSION 46
  49. /** Current Juce version number.
  50. Bits 16 to 32 = major version.
  51. Bits 8 to 16 = minor version.
  52. Bits 0 to 8 = point release (not currently used).
  53. See also SystemStats::getJUCEVersion() for a string version.
  54. */
  55. #define JUCE_VERSION ((JUCE_MAJOR_VERSION << 16) + (JUCE_MINOR_VERSION << 8))
  56. /********* Start of inlined file: juce_Config.h *********/
  57. #ifndef __JUCE_CONFIG_JUCEHEADER__
  58. #define __JUCE_CONFIG_JUCEHEADER__
  59. /*
  60. This file contains macros that enable/disable various JUCE features.
  61. */
  62. /** The name of the namespace that all Juce classes and functions will be
  63. put inside. If this is not defined, no namespace will be used.
  64. */
  65. #ifndef JUCE_NAMESPACE
  66. #define JUCE_NAMESPACE juce
  67. #endif
  68. /** Normally, JUCE_DEBUG is set to 1 or 0 based on compiler and project settings,
  69. but if you define this value, you can override this can force it to be true or
  70. false.
  71. */
  72. #ifndef JUCE_FORCE_DEBUG
  73. //#define JUCE_FORCE_DEBUG 1
  74. #endif
  75. /** If this flag is enabled, the the jassert and jassertfalse macros will
  76. always use Logger::writeToLog() to write a message when an assertion happens.
  77. Enabling it will also leave this turned on in release builds. When it's disabled,
  78. however, the jassert and jassertfalse macros will not be compiled in a
  79. release build.
  80. @see jassert, jassertfalse, Logger
  81. */
  82. #ifndef JUCE_LOG_ASSERTIONS
  83. // #define JUCE_LOG_ASSERTIONS 1
  84. #endif
  85. /** Comment out this macro if you haven't got the Steinberg ASIO SDK, without
  86. which the ASIOAudioIODevice class can't be built. See the comments in the
  87. ASIOAudioIODevice class's header file for more info about this.
  88. (This only affects a Win32 build)
  89. */
  90. #ifndef JUCE_ASIO
  91. #define JUCE_ASIO 1
  92. #endif
  93. /** Comment out this macro to disable building of ALSA device support on Linux.
  94. */
  95. #ifndef JUCE_ALSA
  96. #define JUCE_ALSA 1
  97. #endif
  98. /** Comment out this macro if you don't want to enable QuickTime or if you don't
  99. have the SDK installed.
  100. If this flag is not enabled, the QuickTimeMovieComponent and QuickTimeAudioFormat
  101. classes will be unavailable.
  102. On Windows, if you enable this, you'll need to have the QuickTime SDK
  103. installed, and its header files will need to be on your include path.
  104. */
  105. #if ! (defined (JUCE_QUICKTIME) || defined (LINUX) || (defined (_WIN32) && ! defined (_MSC_VER)))
  106. #define JUCE_QUICKTIME 1
  107. #endif
  108. /** Comment out this macro if you don't want to enable OpenGL or if you don't
  109. have the appropriate headers and libraries available. If it's not enabled, the
  110. OpenGLComponent class will be unavailable.
  111. */
  112. #ifndef JUCE_OPENGL
  113. #define JUCE_OPENGL 1
  114. #endif
  115. /** These flags enable the Ogg-Vorbis and Flac audio formats.
  116. If you're not going to need either of these formats, turn off the flags to
  117. avoid bloating your codebase with them.
  118. */
  119. #ifndef JUCE_USE_FLAC
  120. #define JUCE_USE_FLAC 1
  121. #endif
  122. #ifndef JUCE_USE_OGGVORBIS
  123. #define JUCE_USE_OGGVORBIS 1
  124. #endif
  125. /** This flag lets you enable support for CD-burning. You might want to disable
  126. it to build without the MS SDK under windows.
  127. */
  128. #if (! defined (JUCE_USE_CDBURNER)) && ! (defined (_WIN32) && ! defined (_MSC_VER))
  129. #define JUCE_USE_CDBURNER 1
  130. #endif
  131. /** Enabling this macro means that all regions that get repainted will have a coloured
  132. line drawn around them.
  133. This is handy if you're trying to optimise drawing, because it lets you easily see
  134. when anything is being repainted unnecessarily.
  135. */
  136. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  137. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  138. #endif
  139. /** Enable this under Linux to use Xinerama for multi-monitor support.
  140. */
  141. #ifndef JUCE_USE_XINERAMA
  142. #define JUCE_USE_XINERAMA 1
  143. #endif
  144. /** Enable this under Linux to use XShm for faster shared-memory rendering.
  145. */
  146. #ifndef JUCE_USE_XSHM
  147. #define JUCE_USE_XSHM 1
  148. #endif
  149. /** Enabling this builds support for VST audio plugins.
  150. @see VSTPluginFormat, AudioPluginFormat, AudioPluginFormatManager, JUCE_PLUGINHOST_AU
  151. */
  152. //#define JUCE_PLUGINHOST_VST 1
  153. /** Enabling this builds support for AudioUnit audio plugins.
  154. @see AudioUnitPluginFormat, AudioPluginFormat, AudioPluginFormatManager, JUCE_PLUGINHOST_VST
  155. */
  156. #define JUCE_PLUGINHOST_AU 1
  157. /** Disabling this will avoid linking to any UI code. This is handy for
  158. writing command-line utilities, e.g. on linux boxes which don't have some
  159. of the UI libraries installed.
  160. (On mac and windows, this won't generally make much difference to the build).
  161. */
  162. #ifndef JUCE_BUILD_GUI_CLASSES
  163. #define JUCE_BUILD_GUI_CLASSES 1
  164. #endif
  165. /** Enable this to add extra memory-leak info to the new and delete operators.
  166. (Currently, this only affects Windows builds in debug mode).
  167. */
  168. #ifndef JUCE_CHECK_MEMORY_LEAKS
  169. #define JUCE_CHECK_MEMORY_LEAKS 1
  170. #endif
  171. /** Enable this to turn on juce's internal catching of exceptions.
  172. Turning it off will avoid any exception catching. With it on, all exceptions
  173. are passed to the JUCEApplication::unhandledException() callback for logging.
  174. */
  175. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  176. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  177. #endif
  178. /** If this macro is set, the Juce String class will use unicode as its
  179. internal representation. If it isn't set, it'll use ANSI.
  180. */
  181. #ifndef JUCE_STRINGS_ARE_UNICODE
  182. #define JUCE_STRINGS_ARE_UNICODE 1
  183. #endif
  184. #endif
  185. /********* End of inlined file: juce_Config.h *********/
  186. #ifdef JUCE_NAMESPACE
  187. #define BEGIN_JUCE_NAMESPACE namespace JUCE_NAMESPACE {
  188. #define END_JUCE_NAMESPACE }
  189. #else
  190. #define BEGIN_JUCE_NAMESPACE
  191. #define END_JUCE_NAMESPACE
  192. #endif
  193. // This sets up the JUCE_WIN32, JUCE_MAC, or JUCE_LINUX macros
  194. /********* Start of inlined file: juce_PlatformDefs.h *********/
  195. #ifndef __JUCE_PLATFORMDEFS_JUCEHEADER__
  196. #define __JUCE_PLATFORMDEFS_JUCEHEADER__
  197. /* This file figures out which platform is being built, and defines some macros
  198. that the rest of the code can use for OS-specific compilation.
  199. Macros that will be set here are:
  200. - One of JUCE_WIN32, JUCE_MAC or JUCE_LINUX.
  201. - Either JUCE_32BIT or JUCE_64BIT, depending on the architecture.
  202. - Either JUCE_LITTLE_ENDIAN or JUCE_BIG_ENDIAN.
  203. - Either JUCE_INTEL or JUCE_PPC
  204. - Either JUCE_GCC or JUCE_MSVC
  205. On the Mac, it also defines MACOS_10_2_OR_EARLIER if the build is targeting OSX10.2,
  206. and MACOS_10_3_OR_EARLIER if it is targeting either 10.2 or 10.3
  207. It also includes a set of macros for debug console output and assertions.
  208. */
  209. #if (defined (_WIN32) || defined (_WIN64))
  210. #define JUCE_WIN32 1
  211. #else
  212. #ifdef LINUX
  213. #define JUCE_LINUX 1
  214. #else
  215. #define JUCE_MAC 1
  216. #endif
  217. #endif
  218. #if JUCE_WIN32
  219. #ifdef _MSC_VER
  220. #ifdef _WIN64
  221. #define JUCE_64BIT 1
  222. #else
  223. #define JUCE_32BIT 1
  224. #endif
  225. #endif
  226. #ifdef _DEBUG
  227. #define JUCE_DEBUG 1
  228. #endif
  229. /** If defined, this indicates that the processor is little-endian. */
  230. #define JUCE_LITTLE_ENDIAN 1
  231. #define JUCE_INTEL 1
  232. #endif
  233. #if JUCE_MAC
  234. #include <CoreServices/CoreServices.h>
  235. #ifndef NDEBUG
  236. #define JUCE_DEBUG 1
  237. #endif
  238. #ifdef __LITTLE_ENDIAN__
  239. #define JUCE_LITTLE_ENDIAN 1
  240. #else
  241. #define JUCE_BIG_ENDIAN 1
  242. #endif
  243. #if defined (__ppc__) || defined (__ppc64__)
  244. #define JUCE_PPC 1
  245. #else
  246. #define JUCE_INTEL 1
  247. #endif
  248. #ifdef __LP64__
  249. #define JUCE_64BIT 1
  250. #else
  251. #define JUCE_32BIT 1
  252. #endif
  253. #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3)
  254. #define MACOS_10_2_OR_EARLIER 1
  255. #endif
  256. #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4)
  257. #define MACOS_10_3_OR_EARLIER 1
  258. #endif
  259. #endif
  260. #if JUCE_LINUX
  261. #ifdef _DEBUG
  262. #define JUCE_DEBUG 1
  263. #endif
  264. // Allow override for big-endian Linux platforms
  265. #ifndef JUCE_BIG_ENDIAN
  266. #define JUCE_LITTLE_ENDIAN 1
  267. #endif
  268. #if defined (__LP64__) || defined (_LP64)
  269. #define JUCE_64BIT 1
  270. #else
  271. #define JUCE_32BIT 1
  272. #endif
  273. #define JUCE_INTEL 1
  274. #endif
  275. #ifdef JUCE_FORCE_DEBUG
  276. #undef JUCE_DEBUG
  277. #if JUCE_FORCE_DEBUG
  278. #define JUCE_DEBUG 1
  279. #endif
  280. #endif
  281. // Compiler type macros.
  282. #ifdef __GNUC__
  283. #define JUCE_GCC 1
  284. #elif defined (_MSC_VER)
  285. #define JUCE_MSVC 1
  286. #if _MSC_VER >= 1400
  287. #define JUCE_USE_INTRINSICS 1
  288. #endif
  289. #else
  290. #error unknown compiler
  291. #endif
  292. /** This macro defines the C calling convention used as the standard for Juce calls. */
  293. #if JUCE_MSVC
  294. #define JUCE_CALLTYPE __stdcall
  295. #else
  296. #define JUCE_CALLTYPE
  297. #endif
  298. // Debugging and assertion macros
  299. // (For info about JUCE_LOG_ASSERTIONS, have a look in juce_Config.h)
  300. #if JUCE_LOG_ASSERTIONS
  301. #define juce_LogCurrentAssertion juce_LogAssertion (__FILE__, __LINE__);
  302. #elif defined (JUCE_DEBUG)
  303. #define juce_LogCurrentAssertion fprintf (stderr, "JUCE Assertion failure in %s, line %d\n", __FILE__, __LINE__);
  304. #else
  305. #define juce_LogCurrentAssertion
  306. #endif
  307. #ifdef JUCE_DEBUG
  308. // If debugging is enabled..
  309. /** Writes a string to the standard error stream.
  310. This is only compiled in a debug build.
  311. @see Logger::outputDebugString
  312. */
  313. #define DBG(dbgtext) Logger::outputDebugString (dbgtext);
  314. /** Printf's a string to the standard error stream.
  315. This is only compiled in a debug build.
  316. @see Logger::outputDebugString
  317. */
  318. #define DBG_PRINTF(dbgprintf) Logger::outputDebugPrintf dbgprintf;
  319. // Assertions..
  320. #if JUCE_WIN32 || DOXYGEN
  321. #if JUCE_USE_INTRINSICS
  322. #pragma intrinsic (__debugbreak)
  323. /** This will try to break the debugger if one is currently hosting this app.
  324. @see jassert()
  325. */
  326. #define juce_breakDebugger __debugbreak();
  327. #elif JUCE_GCC
  328. /** This will try to break the debugger if one is currently hosting this app.
  329. @see jassert()
  330. */
  331. #define juce_breakDebugger asm("int $3");
  332. #else
  333. /** This will try to break the debugger if one is currently hosting this app.
  334. @see jassert()
  335. */
  336. #define juce_breakDebugger { __asm int 3 }
  337. #endif
  338. #elif JUCE_MAC
  339. #define juce_breakDebugger Debugger();
  340. #elif JUCE_LINUX
  341. #define juce_breakDebugger kill (0, SIGTRAP);
  342. #endif
  343. /** This will always cause an assertion failure.
  344. It is only compiled in a debug build, (unless JUCE_LOG_ASSERTIONS is enabled
  345. in juce_Config.h).
  346. @see jassert()
  347. */
  348. #define jassertfalse { juce_LogCurrentAssertion; if (JUCE_NAMESPACE::juce_isRunningUnderDebugger()) juce_breakDebugger; }
  349. /** Platform-independent assertion macro.
  350. This gets optimised out when not being built with debugging turned on.
  351. Be careful not to call any functions within its arguments that are vital to
  352. the behaviour of the program, because these won't get called in the release
  353. build.
  354. @see jassertfalse
  355. */
  356. #define jassert(expression) { if (! (expression)) jassertfalse }
  357. #else
  358. // If debugging is disabled, these dummy debug and assertion macros are used..
  359. #define DBG(dbgtext)
  360. #define DBG_PRINTF(dbgprintf)
  361. #define jassertfalse { juce_LogCurrentAssertion }
  362. #if JUCE_LOG_ASSERTIONS
  363. #define jassert(expression) { if (! (expression)) jassertfalse }
  364. #else
  365. #define jassert(a) { }
  366. #endif
  367. #endif
  368. #ifndef DOXYGEN
  369. template <bool b> struct JuceStaticAssert;
  370. template <> struct JuceStaticAssert <true> { static void dummy() {} };
  371. #endif
  372. /** A compile-time assertion macro.
  373. If the expression parameter is false, the macro will cause a compile error.
  374. */
  375. #define static_jassert(expression) JuceStaticAssert<expression>::dummy();
  376. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  377. #define JUCE_TRY try
  378. /** Used in try-catch blocks, this macro will send exceptions to the JUCEApplication
  379. object so they can be logged by the application if it wants to.
  380. */
  381. #define JUCE_CATCH_EXCEPTION \
  382. catch (const std::exception& e) \
  383. { \
  384. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__); \
  385. } \
  386. catch (...) \
  387. { \
  388. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__); \
  389. }
  390. #define JUCE_CATCH_ALL catch (...) {}
  391. #define JUCE_CATCH_ALL_ASSERT catch (...) { jassertfalse }
  392. #else
  393. #define JUCE_TRY
  394. #define JUCE_CATCH_EXCEPTION
  395. #define JUCE_CATCH_ALL
  396. #define JUCE_CATCH_ALL_ASSERT
  397. #endif
  398. // Macros for inlining.
  399. #if JUCE_MSVC
  400. /** A platform-independent way of forcing an inline function.
  401. Use the syntax: @code
  402. forcedinline void myfunction (int x)
  403. @endcode
  404. */
  405. #ifdef JUCE_DEBUG
  406. #define forcedinline __forceinline
  407. #else
  408. #define forcedinline inline
  409. #endif
  410. /** A platform-independent way of stopping the compiler inlining a function.
  411. Use the syntax: @code
  412. juce_noinline void myfunction (int x)
  413. @endcode
  414. */
  415. #define juce_noinline
  416. #else
  417. /** A platform-independent way of forcing an inline function.
  418. Use the syntax: @code
  419. forcedinline void myfunction (int x)
  420. @endcode
  421. */
  422. #ifndef JUCE_DEBUG
  423. #define forcedinline inline __attribute__((always_inline))
  424. #else
  425. #define forcedinline inline
  426. #endif
  427. /** A platform-independent way of stopping the compiler inlining a function.
  428. Use the syntax: @code
  429. juce_noinline void myfunction (int x)
  430. @endcode
  431. */
  432. #define juce_noinline __attribute__((noinline))
  433. #endif
  434. #endif // __JUCE_PLATFORMDEFS_JUCEHEADER__
  435. /********* End of inlined file: juce_PlatformDefs.h *********/
  436. // Now we'll include any OS headers we need.. (at this point we are outside the Juce namespace).
  437. #if JUCE_MSVC
  438. #pragma warning (push)
  439. #pragma warning (disable: 4514 4245 4100)
  440. #endif
  441. #include <cstdlib>
  442. #include <cstdarg>
  443. #include <climits>
  444. #include <cmath>
  445. #include <cwchar>
  446. #include <stdexcept>
  447. #include <typeinfo>
  448. #include <cstring>
  449. #if JUCE_MAC || JUCE_LINUX
  450. #include <pthread.h>
  451. #endif
  452. #if JUCE_USE_INTRINSICS
  453. #include <intrin.h>
  454. #endif
  455. #if JUCE_MAC && ! MACOS_10_3_OR_EARLIER
  456. #include <libkern/OSAtomic.h>
  457. #endif
  458. #if JUCE_LINUX
  459. #include <signal.h>
  460. #endif
  461. #if JUCE_MSVC && JUCE_DEBUG
  462. #include <crtdbg.h>
  463. #endif
  464. #if JUCE_MSVC
  465. #pragma warning (pop)
  466. #endif
  467. // DLL building settings on Win32
  468. #if JUCE_MSVC
  469. #ifdef JUCE_DLL_BUILD
  470. #define JUCE_API __declspec (dllexport)
  471. #pragma warning (disable: 4251)
  472. #elif defined (JUCE_DLL)
  473. #define JUCE_API __declspec (dllimport)
  474. #pragma warning (disable: 4251)
  475. #endif
  476. #endif
  477. #ifndef JUCE_API
  478. /** This macro is added to all juce public class declarations. */
  479. #define JUCE_API
  480. #endif
  481. /** This macro is added to all juce public function declarations. */
  482. #define JUCE_PUBLIC_FUNCTION JUCE_API JUCE_CALLTYPE
  483. // Now include some basics that are needed by most of the Juce classes...
  484. BEGIN_JUCE_NAMESPACE
  485. extern bool JUCE_API JUCE_CALLTYPE juce_isRunningUnderDebugger() throw();
  486. #if JUCE_LOG_ASSERTIONS
  487. extern void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw();
  488. #endif
  489. /********* Start of inlined file: juce_Memory.h *********/
  490. #ifndef __JUCE_MEMORY_JUCEHEADER__
  491. #define __JUCE_MEMORY_JUCEHEADER__
  492. /*
  493. This file defines the various juce_malloc(), juce_free() macros that should be used in
  494. preference to the standard calls.
  495. */
  496. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  497. #ifndef JUCE_DLL
  498. // Win32 debug non-DLL versions..
  499. /** This should be used instead of calling malloc directly. */
  500. #define juce_malloc(numBytes) _malloc_dbg (numBytes, _NORMAL_BLOCK, __FILE__, __LINE__)
  501. /** This should be used instead of calling calloc directly. */
  502. #define juce_calloc(numBytes) _calloc_dbg (1, numBytes, _NORMAL_BLOCK, __FILE__, __LINE__)
  503. /** This should be used instead of calling realloc directly. */
  504. #define juce_realloc(location, numBytes) _realloc_dbg (location, numBytes, _NORMAL_BLOCK, __FILE__, __LINE__)
  505. /** This should be used instead of calling free directly. */
  506. #define juce_free(location) _free_dbg (location, _NORMAL_BLOCK)
  507. #else
  508. // Win32 debug DLL versions..
  509. // For the DLL, we'll define some functions in the DLL that will be used for allocation - that
  510. // way all juce calls in the DLL and in the host API will all use the same allocator.
  511. extern JUCE_API void* juce_DebugMalloc (const int size, const char* file, const int line);
  512. extern JUCE_API void* juce_DebugCalloc (const int size, const char* file, const int line);
  513. extern JUCE_API void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line);
  514. extern JUCE_API void juce_DebugFree (void* const block);
  515. /** This should be used instead of calling malloc directly. */
  516. #define juce_malloc(numBytes) JUCE_NAMESPACE::juce_DebugMalloc (numBytes, __FILE__, __LINE__)
  517. /** This should be used instead of calling calloc directly. */
  518. #define juce_calloc(numBytes) JUCE_NAMESPACE::juce_DebugCalloc (numBytes, __FILE__, __LINE__)
  519. /** This should be used instead of calling realloc directly. */
  520. #define juce_realloc(location, numBytes) JUCE_NAMESPACE::juce_DebugRealloc (location, numBytes, __FILE__, __LINE__)
  521. /** This should be used instead of calling free directly. */
  522. #define juce_free(location) JUCE_NAMESPACE::juce_DebugFree (location)
  523. #endif
  524. #if ! defined (_AFXDLL)
  525. /** This macro can be added to classes to add extra debugging information to the memory
  526. allocated for them, so you can see the type of objects involved when there's a dump
  527. of leaked objects at program shutdown. (Only works on win32 at the moment).
  528. */
  529. #define juce_UseDebuggingNewOperator \
  530. static void* operator new (size_t sz) { void* const p = juce_malloc ((int) sz); return (p != 0) ? p : ::operator new (sz); } \
  531. static void* operator new (size_t sz, void* p) { return ::operator new (sz, p); } \
  532. static void operator delete (void* p) { juce_free (p); }
  533. #endif
  534. #elif defined (JUCE_DLL)
  535. // Win32 DLL (release) versions..
  536. // For the DLL, we'll define some functions in the DLL that will be used for allocation - that
  537. // way all juce calls in the DLL and in the host API will all use the same allocator.
  538. extern JUCE_API void* juce_Malloc (const int size);
  539. extern JUCE_API void* juce_Calloc (const int size);
  540. extern JUCE_API void* juce_Realloc (void* const block, const int size);
  541. extern JUCE_API void juce_Free (void* const block);
  542. /** This should be used instead of calling malloc directly. */
  543. #define juce_malloc(numBytes) JUCE_NAMESPACE::juce_Malloc (numBytes)
  544. /** This should be used instead of calling calloc directly. */
  545. #define juce_calloc(numBytes) JUCE_NAMESPACE::juce_Calloc (numBytes)
  546. /** This should be used instead of calling realloc directly. */
  547. #define juce_realloc(location, numBytes) JUCE_NAMESPACE::juce_Realloc (location, numBytes)
  548. /** This should be used instead of calling free directly. */
  549. #define juce_free(location) JUCE_NAMESPACE::juce_Free (location)
  550. #define juce_UseDebuggingNewOperator \
  551. static void* operator new (size_t sz) { void* const p = juce_malloc ((int) sz); return (p != 0) ? p : ::operator new (sz); } \
  552. static void* operator new (size_t sz, void* p) { return ::operator new (sz, p); } \
  553. static void operator delete (void* p) { juce_free (p); }
  554. #else
  555. // Mac, Linux and Win32 (release) versions..
  556. /** This should be used instead of calling malloc directly. */
  557. #define juce_malloc(numBytes) malloc (numBytes)
  558. /** This should be used instead of calling calloc directly. */
  559. #define juce_calloc(numBytes) calloc (1, numBytes)
  560. /** This should be used instead of calling realloc directly. */
  561. #define juce_realloc(location, numBytes) realloc (location, numBytes)
  562. /** This should be used instead of calling free directly. */
  563. #define juce_free(location) free (location)
  564. #endif
  565. /** This macro can be added to classes to add extra debugging information to the memory
  566. allocated for them, so you can see the type of objects involved when there's a dump
  567. of leaked objects at program shutdown. (Only works on win32 at the moment).
  568. Note that if you create a class that inherits from a class that uses this macro,
  569. your class must also use the macro, otherwise you'll probably get compile errors
  570. because of ambiguous new operators.
  571. Most of the JUCE classes use it, so see these for examples of where it should go.
  572. */
  573. #ifndef juce_UseDebuggingNewOperator
  574. #define juce_UseDebuggingNewOperator
  575. #endif
  576. #if JUCE_MSVC
  577. /** This is a compiler-indenpendent way of declaring a variable as being thread-local.
  578. E.g.
  579. @code
  580. juce_ThreadLocal int myVariable;
  581. @endcode
  582. */
  583. #define juce_ThreadLocal __declspec(thread)
  584. #else
  585. #define juce_ThreadLocal __thread
  586. #endif
  587. /** Clears a block of memory. */
  588. #define zeromem(memory, numBytes) memset (memory, 0, numBytes)
  589. /** Clears a reference to a local structure. */
  590. #define zerostruct(structure) memset (&structure, 0, sizeof (structure))
  591. /** A handy macro that calls delete on a pointer if it's non-zero, and
  592. then sets the pointer to null.
  593. */
  594. #define deleteAndZero(pointer) { delete (pointer); (pointer) = 0; }
  595. #endif // __JUCE_MEMORY_JUCEHEADER__
  596. /********* End of inlined file: juce_Memory.h *********/
  597. /********* Start of inlined file: juce_MathsFunctions.h *********/
  598. #ifndef __JUCE_MATHSFUNCTIONS_JUCEHEADER__
  599. #define __JUCE_MATHSFUNCTIONS_JUCEHEADER__
  600. /*
  601. This file sets up some handy mathematical typdefs and functions.
  602. */
  603. // Definitions for the int8, int16, int32, int64 and pointer_sized_int types.
  604. /** A platform-independent 8-bit signed integer type. */
  605. typedef signed char int8;
  606. /** A platform-independent 8-bit unsigned integer type. */
  607. typedef unsigned char uint8;
  608. /** A platform-independent 16-bit signed integer type. */
  609. typedef signed short int16;
  610. /** A platform-independent 16-bit unsigned integer type. */
  611. typedef unsigned short uint16;
  612. /** A platform-independent 32-bit signed integer type. */
  613. typedef signed int int32;
  614. /** A platform-independent 32-bit unsigned integer type. */
  615. typedef unsigned int uint32;
  616. #if JUCE_MSVC
  617. /** A platform-independent 64-bit integer type. */
  618. typedef __int64 int64;
  619. /** A platform-independent 64-bit unsigned integer type. */
  620. typedef unsigned __int64 uint64;
  621. /** A platform-independent macro for writing 64-bit literals, needed because
  622. different compilers have different syntaxes for this.
  623. E.g. writing literal64bit (0x1000000000) will translate to 0x1000000000LL for
  624. GCC, or 0x1000000000 for MSVC.
  625. */
  626. #define literal64bit(longLiteral) ((__int64) longLiteral)
  627. #else
  628. /** A platform-independent 64-bit integer type. */
  629. typedef long long int64;
  630. /** A platform-independent 64-bit unsigned integer type. */
  631. typedef unsigned long long uint64;
  632. /** A platform-independent macro for writing 64-bit literals, needed because
  633. different compilers have different syntaxes for this.
  634. E.g. writing literal64bit (0x1000000000) will translate to 0x1000000000LL for
  635. GCC, or 0x1000000000 for MSVC.
  636. */
  637. #define literal64bit(longLiteral) (longLiteral##LL)
  638. #endif
  639. #if JUCE_64BIT
  640. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  641. typedef int64 pointer_sized_int;
  642. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  643. typedef uint64 pointer_sized_uint;
  644. #elif _MSC_VER >= 1300
  645. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  646. typedef _W64 int pointer_sized_int;
  647. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  648. typedef _W64 unsigned int pointer_sized_uint;
  649. #else
  650. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  651. typedef int pointer_sized_int;
  652. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  653. typedef unsigned int pointer_sized_uint;
  654. #endif
  655. /** A platform-independent unicode character type. */
  656. typedef wchar_t juce_wchar;
  657. // Some indispensible min/max functions
  658. /** Returns the larger of two values. */
  659. forcedinline int jmax (const int a, const int b) throw() { return (a < b) ? b : a; }
  660. /** Returns the larger of two values. */
  661. forcedinline int64 jmax (const int64 a, const int64 b) throw() { return (a < b) ? b : a; }
  662. /** Returns the larger of two values. */
  663. forcedinline float jmax (const float a, const float b) throw() { return (a < b) ? b : a; }
  664. /** Returns the larger of two values. */
  665. forcedinline double jmax (const double a, const double b) throw() { return (a < b) ? b : a; }
  666. /** Returns the larger of three values. */
  667. inline int jmax (const int a, const int b, const int c) throw() { return (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a); }
  668. /** Returns the larger of three values. */
  669. inline int64 jmax (const int64 a, const int64 b, const int64 c) throw() { return (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a); }
  670. /** Returns the larger of three values. */
  671. inline float jmax (const float a, const float b, const float c) throw() { return (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a); }
  672. /** Returns the larger of three values. */
  673. inline double jmax (const double a, const double b, const double c) throw() { return (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a); }
  674. /** Returns the larger of four values. */
  675. inline int jmax (const int a, const int b, const int c, const int d) throw() { return jmax (a, jmax (b, c, d)); }
  676. /** Returns the larger of four values. */
  677. inline int64 jmax (const int64 a, const int64 b, const int64 c, const int64 d) throw() { return jmax (a, jmax (b, c, d)); }
  678. /** Returns the larger of four values. */
  679. inline float jmax (const float a, const float b, const float c, const float d) throw() { return jmax (a, jmax (b, c, d)); }
  680. /** Returns the larger of four values. */
  681. inline double jmax (const double a, const double b, const double c, const double d) throw() { return jmax (a, jmax (b, c, d)); }
  682. /** Returns the smaller of two values. */
  683. inline int jmin (const int a, const int b) throw() { return (a > b) ? b : a; }
  684. /** Returns the smaller of two values. */
  685. inline int64 jmin (const int64 a, const int64 b) throw() { return (a > b) ? b : a; }
  686. /** Returns the smaller of two values. */
  687. inline float jmin (const float a, const float b) throw() { return (a > b) ? b : a; }
  688. /** Returns the smaller of two values. */
  689. inline double jmin (const double a, const double b) throw() { return (a > b) ? b : a; }
  690. /** Returns the smaller of three values. */
  691. inline int jmin (const int a, const int b, const int c) throw() { return (a > b) ? ((b > c) ? c : b) : ((a > c) ? c : a); }
  692. /** Returns the smaller of three values. */
  693. inline int64 jmin (const int64 a, const int64 b, const int64 c) throw() { return (a > b) ? ((b > c) ? c : b) : ((a > c) ? c : a); }
  694. /** Returns the smaller of three values. */
  695. inline float jmin (const float a, const float b, const float c) throw() { return (a > b) ? ((b > c) ? c : b) : ((a > c) ? c : a); }
  696. /** Returns the smaller of three values. */
  697. inline double jmin (const double a, const double b, const double c) throw() { return (a > b) ? ((b > c) ? c : b) : ((a > c) ? c : a); }
  698. /** Returns the smaller of four values. */
  699. inline int jmin (const int a, const int b, const int c, const int d) throw() { return jmin (a, jmin (b, c, d)); }
  700. /** Returns the smaller of four values. */
  701. inline int64 jmin (const int64 a, const int64 b, const int64 c, const int64 d) throw() { return jmin (a, jmin (b, c, d)); }
  702. /** Returns the smaller of four values. */
  703. inline float jmin (const float a, const float b, const float c, const float d) throw() { return jmin (a, jmin (b, c, d)); }
  704. /** Returns the smaller of four values. */
  705. inline double jmin (const double a, const double b, const double c, const double d) throw() { return jmin (a, jmin (b, c, d)); }
  706. /** Constrains a value to keep it within a given range.
  707. This will check that the specified value lies between the lower and upper bounds
  708. specified, and if not, will return the nearest value that would be in-range. Effectively,
  709. it's like calling jmax (lowerLimit, jmin (upperLimit, value)).
  710. Note that it expects that lowerLimit <= upperLimit. If this isn't true,
  711. the results will be unpredictable.
  712. @param lowerLimit the minimum value to return
  713. @param upperLimit the maximum value to return
  714. @param valueToConstrain the value to try to return
  715. @returns the closest value to valueToConstrain which lies between lowerLimit
  716. and upperLimit (inclusive)
  717. @see jlimit0To, jmin, jmax
  718. */
  719. template <class Type>
  720. inline Type jlimit (const Type lowerLimit,
  721. const Type upperLimit,
  722. const Type valueToConstrain) throw()
  723. {
  724. jassert (lowerLimit <= upperLimit); // if these are in the wrong order, results are unpredictable..
  725. return (valueToConstrain < lowerLimit) ? lowerLimit
  726. : ((valueToConstrain > upperLimit) ? upperLimit
  727. : valueToConstrain);
  728. }
  729. /** Handy function to swap two values over.
  730. */
  731. template <class Type>
  732. inline void swapVariables (Type& variable1, Type& variable2) throw()
  733. {
  734. const Type tempVal = variable1;
  735. variable1 = variable2;
  736. variable2 = tempVal;
  737. }
  738. /** Handy macro for getting the number of elements in a simple const C array.
  739. E.g.
  740. @code
  741. static int myArray[] = { 1, 2, 3 };
  742. int numElements = numElementsInArray (myArray) // returns 3
  743. @endcode
  744. */
  745. #define numElementsInArray(a) ((int) (sizeof (a) / sizeof ((a)[0])))
  746. // Some useful maths functions that aren't always present with all compilers and build settings.
  747. #if JUCE_WIN32 || defined (DOXYGEN)
  748. /** Using juce_hypot and juce_hypotf is easier than dealing with all the different
  749. versions of these functions of various platforms and compilers. */
  750. forcedinline double juce_hypot (double a, double b) { return _hypot (a, b); }
  751. /** Using juce_hypot and juce_hypotf is easier than dealing with all the different
  752. versions of these functions of various platforms and compilers. */
  753. forcedinline float juce_hypotf (float a, float b) { return (float) _hypot (a, b); }
  754. #elif MACOS_10_2_OR_EARLIER
  755. /** Using juce_hypot and juce_hypotf is easier than dealing with all the different
  756. versions of these functions of various platforms and compilers. */
  757. forcedinline double juce_hypot (double a, double b) { return hypot (a, b); }
  758. /** Using juce_hypot and juce_hypotf is easier than dealing with all the different
  759. versions of these functions of various platforms and compilers. */
  760. forcedinline float juce_hypotf (float a, float b) { return (float) hypot (a, b); }
  761. forcedinline float sinf (const float a) { return (float) sin (a); }
  762. forcedinline float cosf (const float a) { return (float) cos (a); }
  763. forcedinline float tanf (const float a) { return (float) tan (a); }
  764. forcedinline float atan2f (const float a, const float b) { return (float) atan2 (a, b); }
  765. forcedinline float sqrtf (const float a) { return (float) sqrt (a); }
  766. forcedinline float logf (const float a) { return (float) log (a); }
  767. forcedinline float powf (const float a, const float b) { return (float) pow (a, b); }
  768. forcedinline float expf (const float a) { return (float) exp (a); }
  769. #else
  770. /** Using juce_hypot and juce_hypotf is easier than dealing with all the different
  771. versions of these functions of various platforms and compilers. */
  772. forcedinline double juce_hypot (double a, double b) { return hypot (a, b); }
  773. /** Using juce_hypot and juce_hypotf is easier than dealing with all the different
  774. versions of these functions of various platforms and compilers. */
  775. forcedinline float juce_hypotf (float a, float b) { return hypotf (a, b); }
  776. #endif
  777. inline int64 abs64 (const int64 n) throw() { return (n >= 0) ? n : -n; }
  778. /** A predefined value for Pi, at double-precision.
  779. @see float_Pi
  780. */
  781. const double double_Pi = 3.1415926535897932384626433832795;
  782. /** A predefined value for Pi, at sngle-precision.
  783. @see double_Pi
  784. */
  785. const float float_Pi = 3.14159265358979323846f;
  786. /** The isfinite() method seems to vary greatly between platforms, so this is a
  787. platform-independent macro for it.
  788. */
  789. #if JUCE_LINUX
  790. #define juce_isfinite(v) std::isfinite(v)
  791. #elif JUCE_MAC
  792. #if MACOS_10_2_OR_EARLIER
  793. #define juce_isfinite(v) __isfinite(v)
  794. #elif MACOS_10_3_OR_EARLIER
  795. #ifdef isfinite
  796. #define juce_isfinite(v) isfinite(v)
  797. #else
  798. // no idea why the isfinite macro is sometimes impossible to include, so just copy the built-in one..
  799. static __inline__ int juce_isfinite (double __x) { return __x == __x && __builtin_fabs (__x) != __builtin_inf(); }
  800. #endif
  801. #else
  802. #define juce_isfinite(v) std::isfinite(v)
  803. #endif
  804. #elif JUCE_WIN32 && ! defined (isfinite)
  805. #define juce_isfinite(v) _finite(v)
  806. #else
  807. #define juce_isfinite(v) isfinite(v)
  808. #endif
  809. #endif // __JUCE_MATHSFUNCTIONS_JUCEHEADER__
  810. /********* End of inlined file: juce_MathsFunctions.h *********/
  811. /********* Start of inlined file: juce_DataConversions.h *********/
  812. #ifndef __JUCE_DATACONVERSIONS_JUCEHEADER__
  813. #define __JUCE_DATACONVERSIONS_JUCEHEADER__
  814. #if JUCE_USE_INTRINSICS
  815. #pragma intrinsic (_byteswap_ulong)
  816. #endif
  817. // Endianness conversions..
  818. /** Swaps the byte-order in an integer from little to big-endianness or vice-versa. */
  819. forcedinline uint32 swapByteOrder (uint32 n) throw()
  820. {
  821. #if JUCE_MAC
  822. // Mac version
  823. return CFSwapInt32 (n);
  824. #elif JUCE_GCC
  825. // Inpenetrable GCC version..
  826. asm("bswap %%eax" : "=a"(n) : "a"(n));
  827. return n;
  828. #elif JUCE_USE_INTRINSICS
  829. // Win32 intrinsics version..
  830. return _byteswap_ulong (n);
  831. #else
  832. // Win32 version..
  833. __asm {
  834. mov eax, n
  835. bswap eax
  836. mov n, eax
  837. }
  838. return n;
  839. #endif
  840. }
  841. /** Swaps the byte-order of a 16-bit short. */
  842. inline uint16 swapByteOrder (const uint16 n) throw()
  843. {
  844. #if JUCE_USE_INTRINSICSxxx // agh - the MS compiler has an internal error when you try to use this intrinsic!
  845. // Win32 intrinsics version..
  846. return (uint16) _byteswap_ushort (n);
  847. #else
  848. return (uint16) ((n << 8) | (n >> 8));
  849. #endif
  850. }
  851. inline uint64 swapByteOrder (const uint64 value) throw()
  852. {
  853. #if JUCE_MAC
  854. return CFSwapInt64 (value);
  855. #elif JUCE_USE_INTRINSICS
  856. return _byteswap_uint64 (value);
  857. #else
  858. return (((int64) swapByteOrder ((uint32) value)) << 32)
  859. | swapByteOrder ((uint32) (value >> 32));
  860. #endif
  861. }
  862. #if JUCE_LITTLE_ENDIAN
  863. /** Swaps the byte order of a 16-bit int if the CPU is big-endian */
  864. inline uint16 swapIfBigEndian (const uint16 v) throw() { return v; }
  865. /** Swaps the byte order of a 32-bit int if the CPU is big-endian */
  866. inline uint32 swapIfBigEndian (const uint32 v) throw() { return v; }
  867. /** Swaps the byte order of a 64-bit int if the CPU is big-endian */
  868. inline uint64 swapIfBigEndian (const uint64 v) throw() { return v; }
  869. /** Swaps the byte order of a 16-bit int if the CPU is little-endian */
  870. inline uint16 swapIfLittleEndian (const uint16 v) throw() { return swapByteOrder (v); }
  871. /** Swaps the byte order of a 32-bit int if the CPU is little-endian */
  872. inline uint32 swapIfLittleEndian (const uint32 v) throw() { return swapByteOrder (v); }
  873. /** Swaps the byte order of a 64-bit int if the CPU is little-endian */
  874. inline uint64 swapIfLittleEndian (const uint64 v) throw() { return swapByteOrder (v); }
  875. /** Turns 4 bytes into a little-endian integer. */
  876. inline uint32 littleEndianInt (const char* const bytes) throw() { return *(uint32*) bytes; }
  877. /** Turns 2 bytes into a little-endian integer. */
  878. inline uint16 littleEndianShort (const char* const bytes) throw() { return *(uint16*) bytes; }
  879. /** Turns 4 bytes into a big-endian integer. */
  880. inline uint32 bigEndianInt (const char* const bytes) throw() { return swapByteOrder (*(uint32*) bytes); }
  881. /** Turns 2 bytes into a big-endian integer. */
  882. inline uint16 bigEndianShort (const char* const bytes) throw() { return swapByteOrder (*(uint16*) bytes); }
  883. #else
  884. /** Swaps the byte order of a 16-bit int if the CPU is big-endian */
  885. inline uint16 swapIfBigEndian (const uint16 v) throw() { return swapByteOrder (v); }
  886. /** Swaps the byte order of a 32-bit int if the CPU is big-endian */
  887. inline uint32 swapIfBigEndian (const uint32 v) throw() { return swapByteOrder (v); }
  888. /** Swaps the byte order of a 64-bit int if the CPU is big-endian */
  889. inline uint64 swapIfBigEndian (const uint64 v) throw() { return swapByteOrder (v); }
  890. /** Swaps the byte order of a 16-bit int if the CPU is little-endian */
  891. inline uint16 swapIfLittleEndian (const uint16 v) throw() { return v; }
  892. /** Swaps the byte order of a 32-bit int if the CPU is little-endian */
  893. inline uint32 swapIfLittleEndian (const uint32 v) throw() { return v; }
  894. /** Swaps the byte order of a 64-bit int if the CPU is little-endian */
  895. inline uint64 swapIfLittleEndian (const uint64 v) throw() { return v; }
  896. /** Turns 4 bytes into a little-endian integer. */
  897. inline uint32 littleEndianInt (const char* const bytes) throw() { return swapByteOrder (*(uint32*) bytes); }
  898. /** Turns 2 bytes into a little-endian integer. */
  899. inline uint16 littleEndianShort (const char* const bytes) throw() { return swapByteOrder (*(uint16*) bytes); }
  900. /** Turns 4 bytes into a big-endian integer. */
  901. inline uint32 bigEndianInt (const char* const bytes) throw() { return *(uint32*) bytes; }
  902. /** Turns 2 bytes into a big-endian integer. */
  903. inline uint16 bigEndianShort (const char* const bytes) throw() { return *(uint16*) bytes; }
  904. #endif
  905. /** Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */
  906. inline int littleEndian24Bit (const char* const bytes) throw() { return (((int) bytes[2]) << 16) | (((uint32) (uint8) bytes[1]) << 8) | ((uint32) (uint8) bytes[0]); }
  907. /** Converts 3 big-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */
  908. inline int bigEndian24Bit (const char* const bytes) throw() { return (((int) bytes[0]) << 16) | (((uint32) (uint8) bytes[1]) << 8) | ((uint32) (uint8) bytes[2]); }
  909. /** Copies a 24-bit number to 3 little-endian bytes. */
  910. inline void littleEndian24BitToChars (const int value, char* const destBytes) throw() { destBytes[0] = (char)(value & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)((value >> 16) & 0xff); }
  911. /** Copies a 24-bit number to 3 big-endian bytes. */
  912. inline void bigEndian24BitToChars (const int value, char* const destBytes) throw() { destBytes[0] = (char)((value >> 16) & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)(value & 0xff); }
  913. /** Fast floating-point-to-integer conversion.
  914. This is faster than using the normal c++ cast to convert a double to an int, and
  915. it will round the value to the nearest integer, rather than rounding it down
  916. like the normal cast does.
  917. Note that this routine gets its speed at the expense of some accuracy, and when
  918. rounding values whose floating point component is exactly 0.5, odd numbers and
  919. even numbers will be rounded up or down differently. For a more accurate conversion,
  920. see roundDoubleToIntAccurate().
  921. */
  922. inline int roundDoubleToInt (const double value) throw()
  923. {
  924. union { int asInt[2]; double asDouble; } n;
  925. n.asDouble = value + 6755399441055744.0;
  926. #if JUCE_BIG_ENDIAN
  927. return n.asInt [1];
  928. #else
  929. return n.asInt [0];
  930. #endif
  931. }
  932. /** Fast floating-point-to-integer conversion.
  933. This is a slightly slower and slightly more accurate version of roundDoubleToInt(). It works
  934. fine for values above zero, but negative numbers are rounded the wrong way.
  935. */
  936. inline int roundDoubleToIntAccurate (const double value) throw()
  937. {
  938. return roundDoubleToInt (value + 1.5e-8);
  939. }
  940. /** Fast floating-point-to-integer conversion.
  941. This is faster than using the normal c++ cast to convert a float to an int, and
  942. it will round the value to the nearest integer, rather than rounding it down
  943. like the normal cast does.
  944. Note that this routine gets its speed at the expense of some accuracy, and when
  945. rounding values whose floating point component is exactly 0.5, odd numbers and
  946. even numbers will be rounded up or down differently.
  947. */
  948. inline int roundFloatToInt (const float value) throw()
  949. {
  950. union { int asInt[2]; double asDouble; } n;
  951. n.asDouble = value + 6755399441055744.0;
  952. #if JUCE_BIG_ENDIAN
  953. return n.asInt [1];
  954. #else
  955. return n.asInt [0];
  956. #endif
  957. }
  958. #endif // __JUCE_DATACONVERSIONS_JUCEHEADER__
  959. /********* End of inlined file: juce_DataConversions.h *********/
  960. /********* Start of inlined file: juce_Logger.h *********/
  961. #ifndef __JUCE_LOGGER_JUCEHEADER__
  962. #define __JUCE_LOGGER_JUCEHEADER__
  963. /********* Start of inlined file: juce_String.h *********/
  964. #ifndef __JUCE_STRING_JUCEHEADER__
  965. #define __JUCE_STRING_JUCEHEADER__
  966. /********* Start of inlined file: juce_CharacterFunctions.h *********/
  967. #ifndef __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__
  968. #define __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__
  969. /* The String class can either use wchar_t unicode characters, or 8-bit characters
  970. (in the default system encoding) as its internal representation.
  971. To use unicode, define the JUCE_STRINGS_ARE_UNICODE macro in juce_Config.h
  972. Be sure to use "tchar" for characters rather than "char", and always wrap string
  973. literals in the T("abcd") macro, so that it all works nicely either way round.
  974. */
  975. #if JUCE_STRINGS_ARE_UNICODE
  976. #define JUCE_T(stringLiteral) (L##stringLiteral)
  977. typedef juce_wchar tchar;
  978. #define juce_tcharToWideChar(c) (c)
  979. #else
  980. #define JUCE_T(stringLiteral) (stringLiteral)
  981. typedef char tchar;
  982. #define juce_tcharToWideChar(c) ((juce_wchar) (unsigned char) (c))
  983. #endif
  984. #if ! JUCE_DONT_DEFINE_MACROS
  985. /** The 'T' macro allows a literal string to be compiled using either 8-bit characters
  986. or unicode.
  987. If you write your string literals in the form T("xyz"), this will either be compiled
  988. as "xyz" for non-unicode builds, or L"xyz" for unicode builds, depending on whether the
  989. JUCE_STRINGS_ARE_UNICODE macro has been set in juce_Config.h
  990. Because the 'T' symbol is occasionally used inside 3rd-party library headers which you
  991. may need to include after juce.h, you can use the juce_withoutMacros.h file (in
  992. the juce/src directory) to avoid defining this macro. See the comments in
  993. juce_withoutMacros.h for more info.
  994. */
  995. #define T(stringLiteral) JUCE_T(stringLiteral)
  996. #endif
  997. /**
  998. A set of methods for manipulating characters and character strings, with
  999. duplicate methods to handle 8-bit and unicode characters.
  1000. These are defined as wrappers around the basic C string handlers, to provide
  1001. a clean, cross-platform layer, (because various platforms differ in the
  1002. range of C library calls that they provide).
  1003. @see String
  1004. */
  1005. class JUCE_API CharacterFunctions
  1006. {
  1007. public:
  1008. static int length (const char* const s) throw();
  1009. static int length (const juce_wchar* const s) throw();
  1010. static void copy (char* dest, const char* src, const int maxBytes) throw();
  1011. static void copy (juce_wchar* dest, const juce_wchar* src, const int maxChars) throw();
  1012. static void copy (juce_wchar* dest, const char* src, const int maxChars) throw();
  1013. static void copy (char* dest, const juce_wchar* src, const int maxBytes) throw();
  1014. static int bytesRequiredForCopy (const juce_wchar* src) throw();
  1015. static void append (char* dest, const char* src) throw();
  1016. static void append (juce_wchar* dest, const juce_wchar* src) throw();
  1017. static int compare (const char* const s1, const char* const s2) throw();
  1018. static int compare (const juce_wchar* s1, const juce_wchar* s2) throw();
  1019. static int compare (const char* const s1, const char* const s2, const int maxChars) throw();
  1020. static int compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw();
  1021. static int compareIgnoreCase (const char* const s1, const char* const s2) throw();
  1022. static int compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw();
  1023. static int compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw();
  1024. static int compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw();
  1025. static const char* find (const char* const haystack, const char* const needle) throw();
  1026. static const juce_wchar* find (const juce_wchar* haystack, const juce_wchar* const needle) throw();
  1027. static int indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw();
  1028. static int indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw();
  1029. static int indexOfCharFast (const char* const haystack, const char needle) throw();
  1030. static int indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw();
  1031. static int getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw();
  1032. static int getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw();
  1033. static int ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw();
  1034. static int ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw();
  1035. static int getIntValue (const char* const s) throw();
  1036. static int getIntValue (const juce_wchar* s) throw();
  1037. static int64 getInt64Value (const char* s) throw();
  1038. static int64 getInt64Value (const juce_wchar* s) throw();
  1039. static double getDoubleValue (const char* const s) throw();
  1040. static double getDoubleValue (const juce_wchar* const s) throw();
  1041. static char toUpperCase (const char character) throw();
  1042. static juce_wchar toUpperCase (const juce_wchar character) throw();
  1043. static void toUpperCase (char* s) throw();
  1044. static void toUpperCase (juce_wchar* s) throw();
  1045. static bool isUpperCase (const char character) throw();
  1046. static bool isUpperCase (const juce_wchar character) throw();
  1047. static char toLowerCase (const char character) throw();
  1048. static juce_wchar toLowerCase (const juce_wchar character) throw();
  1049. static void toLowerCase (char* s) throw();
  1050. static void toLowerCase (juce_wchar* s) throw();
  1051. static bool isLowerCase (const char character) throw();
  1052. static bool isLowerCase (const juce_wchar character) throw();
  1053. static bool isWhitespace (const char character) throw();
  1054. static bool isWhitespace (const juce_wchar character) throw();
  1055. static bool isDigit (const char character) throw();
  1056. static bool isDigit (const juce_wchar character) throw();
  1057. static bool isLetter (const char character) throw();
  1058. static bool isLetter (const juce_wchar character) throw();
  1059. static bool isLetterOrDigit (const char character) throw();
  1060. static bool isLetterOrDigit (const juce_wchar character) throw();
  1061. /** Returns 0 to 16 for '0' to 'F", or -1 for characters that aren't a legel
  1062. hex digit.
  1063. */
  1064. static int getHexDigitValue (const tchar digit) throw();
  1065. static int printf (char* const dest, const int maxLength, const char* const format, ...) throw();
  1066. static int printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw();
  1067. static int vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw();
  1068. static int vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw();
  1069. };
  1070. #endif // __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__
  1071. /********* End of inlined file: juce_CharacterFunctions.h *********/
  1072. /**
  1073. The JUCE String class!
  1074. Using a reference-counted internal representation, these strings are fast
  1075. and efficient, and there are methods to do just about any operation you'll ever
  1076. dream of.
  1077. @see StringArray, StringPairArray
  1078. */
  1079. class JUCE_API String
  1080. {
  1081. public:
  1082. /** Creates an empty string.
  1083. @see empty
  1084. */
  1085. String() throw();
  1086. /** Creates a copy of another string. */
  1087. String (const String& other) throw();
  1088. /** Creates a string from a zero-terminated text string.
  1089. The string is assumed to be stored in the default system encoding.
  1090. */
  1091. String (const char* const text) throw();
  1092. /** Creates a string from an string of characters.
  1093. This will use up the the first maxChars characters of the string (or
  1094. less if the string is actually shorter)
  1095. */
  1096. String (const char* const text,
  1097. const int maxChars) throw();
  1098. /** Creates a string from a zero-terminated unicode text string. */
  1099. String (const juce_wchar* const unicodeText) throw();
  1100. /** Creates a string from a unicode text string.
  1101. This will use up the the first maxChars characters of the string (or
  1102. less if the string is actually shorter)
  1103. */
  1104. String (const juce_wchar* const unicodeText,
  1105. const int maxChars) throw();
  1106. /** Creates a string from a single character. */
  1107. static const String charToString (const tchar character) throw();
  1108. /** Destructor. */
  1109. ~String() throw();
  1110. /** This is an empty string that can be used whenever one is needed.
  1111. It's better to use this than String() because it explains what's going on
  1112. and is more efficient.
  1113. */
  1114. static const String empty;
  1115. /** Generates a probably-unique 32-bit hashcode from this string. */
  1116. int hashCode() const throw();
  1117. /** Generates a probably-unique 64-bit hashcode from this string. */
  1118. int64 hashCode64() const throw();
  1119. /** Returns the number of characters in the string. */
  1120. int length() const throw();
  1121. // Assignment and concatenation operators..
  1122. /** Replaces this string's contents with another string. */
  1123. const String& operator= (const tchar* const other) throw();
  1124. /** Replaces this string's contents with another string. */
  1125. const String& operator= (const String& other) throw();
  1126. /** Appends another string at the end of this one. */
  1127. const String& operator+= (const tchar* const textToAppend) throw();
  1128. /** Appends another string at the end of this one. */
  1129. const String& operator+= (const String& stringToAppend) throw();
  1130. /** Appends a character at the end of this string. */
  1131. const String& operator+= (const char characterToAppend) throw();
  1132. /** Appends a character at the end of this string. */
  1133. const String& operator+= (const juce_wchar characterToAppend) throw();
  1134. /** Appends a string at the end of this one.
  1135. @param textToAppend the string to add
  1136. @param maxCharsToTake the maximum number of characters to take from the string passed in
  1137. */
  1138. void append (const tchar* const textToAppend,
  1139. const int maxCharsToTake) throw();
  1140. /** Appends a string at the end of this one.
  1141. @returns the concatenated string
  1142. */
  1143. const String operator+ (const String& stringToAppend) const throw();
  1144. /** Appends a string at the end of this one.
  1145. @returns the concatenated string
  1146. */
  1147. const String operator+ (const tchar* const textToAppend) const throw();
  1148. /** Appends a character at the end of this one.
  1149. @returns the concatenated string
  1150. */
  1151. const String operator+ (const tchar characterToAppend) const throw();
  1152. /** Appends a character at the end of this string. */
  1153. String& operator<< (const char n) throw();
  1154. /** Appends a character at the end of this string. */
  1155. String& operator<< (const juce_wchar n) throw();
  1156. /** Appends another string at the end of this one. */
  1157. String& operator<< (const char* const text) throw();
  1158. /** Appends another string at the end of this one. */
  1159. String& operator<< (const juce_wchar* const text) throw();
  1160. /** Appends another string at the end of this one. */
  1161. String& operator<< (const String& text) throw();
  1162. /** Appends a decimal number at the end of this string. */
  1163. String& operator<< (const short number) throw();
  1164. /** Appends a decimal number at the end of this string. */
  1165. String& operator<< (const int number) throw();
  1166. /** Appends a decimal number at the end of this string. */
  1167. String& operator<< (const unsigned int number) throw();
  1168. /** Appends a decimal number at the end of this string. */
  1169. String& operator<< (const float number) throw();
  1170. /** Appends a decimal number at the end of this string. */
  1171. String& operator<< (const double number) throw();
  1172. // Comparison methods..
  1173. /** Returns true if the string contains no characters.
  1174. Note that there's also an isNotEmpty() method to help write readable code.
  1175. */
  1176. inline bool isEmpty() const throw() { return text->text[0] == 0; }
  1177. /** Returns true if the string contains at least one character.
  1178. Note that there's also an isEmpty() method to help write readable code.
  1179. */
  1180. inline bool isNotEmpty() const throw() { return text->text[0] != 0; }
  1181. /** Case-sensitive comparison with another string. */
  1182. bool operator== (const String& other) const throw();
  1183. /** Case-sensitive comparison with another string. */
  1184. bool operator== (const tchar* const other) const throw();
  1185. /** Case-sensitive comparison with another string. */
  1186. bool operator!= (const String& other) const throw();
  1187. /** Case-sensitive comparison with another string. */
  1188. bool operator!= (const tchar* const other) const throw();
  1189. /** Case-insensitive comparison with another string. */
  1190. bool equalsIgnoreCase (const String& other) const throw();
  1191. /** Case-insensitive comparison with another string. */
  1192. bool equalsIgnoreCase (const tchar* const other) const throw();
  1193. /** Case-sensitive comparison with another string. */
  1194. bool operator> (const String& other) const throw();
  1195. /** Case-sensitive comparison with another string. */
  1196. bool operator< (const tchar* const other) const throw();
  1197. /** Case-sensitive comparison with another string. */
  1198. bool operator>= (const String& other) const throw();
  1199. /** Case-sensitive comparison with another string. */
  1200. bool operator<= (const tchar* const other) const throw();
  1201. /** Case-sensitive comparison with another string.
  1202. @returns 0 if the two strings are identical; negative if this string
  1203. comes before the other one alphabetically, or positive if it
  1204. comes after it.
  1205. */
  1206. int compare (const tchar* const other) const throw();
  1207. /** Case-insensitive comparison with another string.
  1208. @returns 0 if the two strings are identical; negative if this string
  1209. comes before the other one alphabetically, or positive if it
  1210. comes after it.
  1211. */
  1212. int compareIgnoreCase (const tchar* const other) const throw();
  1213. /** Lexicographic comparison with another string.
  1214. The comparison used here is case-insensitive and ignores leading non-alphanumeric
  1215. characters, making it good for sorting human-readable strings.
  1216. @returns 0 if the two strings are identical; negative if this string
  1217. comes before the other one alphabetically, or positive if it
  1218. comes after it.
  1219. */
  1220. int compareLexicographically (const tchar* const other) const throw();
  1221. /** Tests whether the string begins with another string.
  1222. Uses a case-sensitive comparison.
  1223. */
  1224. bool startsWith (const tchar* const text) const throw();
  1225. /** Tests whether the string begins with a particular character.
  1226. Uses a case-sensitive comparison.
  1227. */
  1228. bool startsWithChar (const tchar character) const throw();
  1229. /** Tests whether the string begins with another string.
  1230. Uses a case-insensitive comparison.
  1231. */
  1232. bool startsWithIgnoreCase (const tchar* const text) const throw();
  1233. /** Tests whether the string ends with another string.
  1234. Uses a case-sensitive comparison.
  1235. */
  1236. bool endsWith (const tchar* const text) const throw();
  1237. /** Tests whether the string ends with a particular character.
  1238. Uses a case-sensitive comparison.
  1239. */
  1240. bool endsWithChar (const tchar character) const throw();
  1241. /** Tests whether the string ends with another string.
  1242. Uses a case-insensitive comparison.
  1243. */
  1244. bool endsWithIgnoreCase (const tchar* const text) const throw();
  1245. /** Tests whether the string contains another substring.
  1246. Uses a case-sensitive comparison.
  1247. */
  1248. bool contains (const tchar* const text) const throw();
  1249. /** Tests whether the string contains a particular character.
  1250. Uses a case-sensitive comparison.
  1251. */
  1252. bool containsChar (const tchar character) const throw();
  1253. /** Tests whether the string contains another substring.
  1254. Uses a case-insensitive comparison.
  1255. */
  1256. bool containsIgnoreCase (const tchar* const text) const throw();
  1257. /** Tests whether the string contains another substring as a distict word.
  1258. @returns true if the string contains this word, surrounded by
  1259. non-alphanumeric characters
  1260. @see indexOfWholeWord, containsWholeWordIgnoreCase
  1261. */
  1262. bool containsWholeWord (const tchar* const wordToLookFor) const throw();
  1263. /** Tests whether the string contains another substring as a distict word.
  1264. @returns true if the string contains this word, surrounded by
  1265. non-alphanumeric characters
  1266. @see indexOfWholeWordIgnoreCase, containsWholeWord
  1267. */
  1268. bool containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw();
  1269. /** Finds an instance of another substring if it exists as a distict word.
  1270. @returns if the string contains this word, surrounded by non-alphanumeric characters,
  1271. then this will return the index of the start of the substring. If it isn't
  1272. found, then it will return -1
  1273. @see indexOfWholeWordIgnoreCase, containsWholeWord
  1274. */
  1275. int indexOfWholeWord (const tchar* const wordToLookFor) const throw();
  1276. /** Finds an instance of another substring if it exists as a distict word.
  1277. @returns if the string contains this word, surrounded by non-alphanumeric characters,
  1278. then this will return the index of the start of the substring. If it isn't
  1279. found, then it will return -1
  1280. @see indexOfWholeWord, containsWholeWordIgnoreCase
  1281. */
  1282. int indexOfWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw();
  1283. /** Looks for any of a set of characters in the string.
  1284. Uses a case-sensitive comparison.
  1285. @returns true if the string contains any of the characters from
  1286. the string that is passed in.
  1287. */
  1288. bool containsAnyOf (const tchar* const charactersItMightContain) const throw();
  1289. /** Looks for a set of characters in the string.
  1290. Uses a case-sensitive comparison.
  1291. @returns true if the all the characters in the string are also found in the
  1292. string that is passed in.
  1293. */
  1294. bool containsOnly (const tchar* const charactersItMightContain) const throw();
  1295. /** Returns true if the string matches this simple wildcard expression.
  1296. So for example String ("abcdef").matchesWildcard ("*DEF", true) would return true.
  1297. This isn't a full-blown regex though! The only wildcard characters supported
  1298. are "*" and "?". It's mainly intended for filename pattern matching.
  1299. */
  1300. bool matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw();
  1301. // Substring location methods..
  1302. /** Searches for a character inside this string.
  1303. Uses a case-sensitive comparison.
  1304. @returns the index of the first occurrence of the character in this
  1305. string, or -1 if it's not found.
  1306. */
  1307. int indexOfChar (const tchar characterToLookFor) const throw();
  1308. /** Searches for a character inside this string.
  1309. Uses a case-sensitive comparison.
  1310. @param startIndex the index from which the search should proceed
  1311. @param characterToLookFor the character to look for
  1312. @returns the index of the first occurrence of the character in this
  1313. string, or -1 if it's not found.
  1314. */
  1315. int indexOfChar (const int startIndex, const tchar characterToLookFor) const throw();
  1316. /** Returns the index of the first character that matches one of the characters
  1317. passed-in to this method.
  1318. This scans the string, beginning from the startIndex supplied, and if it finds
  1319. a character that appears in the string charactersToLookFor, it returns its index.
  1320. If none of these characters are found, it returns -1.
  1321. If ignoreCase is true, the comparison will be case-insensitive.
  1322. @see indexOfChar, lastIndexOfAnyOf
  1323. */
  1324. int indexOfAnyOf (const tchar* const charactersToLookFor,
  1325. const int startIndex = 0,
  1326. const bool ignoreCase = false) const throw();
  1327. /** Searches for a substring within this string.
  1328. Uses a case-sensitive comparison.
  1329. @returns the index of the first occurrence of this substring, or -1 if it's not found.
  1330. */
  1331. int indexOf (const tchar* const text) const throw();
  1332. /** Searches for a substring within this string.
  1333. Uses a case-sensitive comparison.
  1334. @param startIndex the index from which the search should proceed
  1335. @param textToLookFor the string to search for
  1336. @returns the index of the first occurrence of this substring, or -1 if it's not found.
  1337. */
  1338. int indexOf (const int startIndex,
  1339. const tchar* const textToLookFor) const throw();
  1340. /** Searches for a substring within this string.
  1341. Uses a case-insensitive comparison.
  1342. @returns the index of the first occurrence of this substring, or -1 if it's not found.
  1343. */
  1344. int indexOfIgnoreCase (const tchar* const textToLookFor) const throw();
  1345. /** Searches for a substring within this string.
  1346. Uses a case-insensitive comparison.
  1347. @param startIndex the index from which the search should proceed
  1348. @param textToLookFor the string to search for
  1349. @returns the index of the first occurrence of this substring, or -1 if it's not found.
  1350. */
  1351. int indexOfIgnoreCase (const int startIndex,
  1352. const tchar* const textToLookFor) const throw();
  1353. /** Searches for a character inside this string (working backwards from the end of the string).
  1354. Uses a case-sensitive comparison.
  1355. @returns the index of the last occurrence of the character in this
  1356. string, or -1 if it's not found.
  1357. */
  1358. int lastIndexOfChar (const tchar character) const throw();
  1359. /** Searches for a substring inside this string (working backwards from the end of the string).
  1360. Uses a case-sensitive comparison.
  1361. @returns the index of the start of the last occurrence of the
  1362. substring within this string, or -1 if it's not found.
  1363. */
  1364. int lastIndexOf (const tchar* const textToLookFor) const throw();
  1365. /** Searches for a substring inside this string (working backwards from the end of the string).
  1366. Uses a case-insensitive comparison.
  1367. @returns the index of the start of the last occurrence of the
  1368. substring within this string, or -1 if it's not found.
  1369. */
  1370. int lastIndexOfIgnoreCase (const tchar* const textToLookFor) const throw();
  1371. /** Returns the index of the last character in this string that matches one of the
  1372. characters passed-in to this method.
  1373. This scans the string backwards, starting from its end, and if it finds
  1374. a character that appears in the string charactersToLookFor, it returns its index.
  1375. If none of these characters are found, it returns -1.
  1376. If ignoreCase is true, the comparison will be case-insensitive.
  1377. @see lastIndexOf, indexOfAnyOf
  1378. */
  1379. int lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  1380. const bool ignoreCase = false) const throw();
  1381. // Substring extraction and manipulation methods..
  1382. /** Returns the character at this index in the string.
  1383. No checks are made to see if the index is within a valid range, so be careful!
  1384. */
  1385. inline const tchar& operator[] (const int index) const throw() { jassert (((unsigned int) index) <= (unsigned int) length()); return text->text [index]; }
  1386. /** Returns a character from the string such that it can also be altered.
  1387. This can be used as a way of easily changing characters in the string.
  1388. Note that the index passed-in is not checked to see whether it's in-range, so
  1389. be careful when using this.
  1390. */
  1391. tchar& operator[] (const int index) throw();
  1392. /** Returns the final character of the string.
  1393. If the string is empty this will return 0.
  1394. */
  1395. tchar getLastCharacter() const throw();
  1396. /** Returns a subsection of the string.
  1397. If the range specified is beyond the limits of the string, as much as
  1398. possible is returned.
  1399. @param startIndex the index of the start of the substring needed
  1400. @param endIndex all characters from startIndex up to (but not including)
  1401. this index are returned
  1402. @see fromFirstOccurrenceOf, dropLastCharacters, upToFirstOccurrenceOf
  1403. */
  1404. const String substring (int startIndex,
  1405. int endIndex) const throw();
  1406. /** Returns a section of the string, starting from a given position.
  1407. @param startIndex the first character to include. If this is beyond the end
  1408. of the string, an empty string is returned. If it is zero or
  1409. less, the whole string is returned.
  1410. @returns the substring from startIndex up to the end of the string
  1411. @see dropLastCharacters, fromFirstOccurrenceOf, upToFirstOccurrenceOf, fromLastOccurrenceOf
  1412. */
  1413. const String substring (const int startIndex) const throw();
  1414. /** Returns a version of this string with a number of characters removed
  1415. from the end.
  1416. @param numberToDrop the number of characters to drop from the end of the
  1417. string. If this is greater than the length of the string,
  1418. an empty string will be returned. If zero or less, the
  1419. original string will be returned.
  1420. @see substring, fromFirstOccurrenceOf, upToFirstOccurrenceOf, fromLastOccurrenceOf, getLastCharacter
  1421. */
  1422. const String dropLastCharacters (const int numberToDrop) const throw();
  1423. /** Returns a section of the string starting from a given substring.
  1424. This will search for the first occurrence of the given substring, and
  1425. return the section of the string starting from the point where this is
  1426. found (optionally not including the substring itself).
  1427. e.g. for the string "123456", fromFirstOccurrenceOf ("34", true) would return "3456", and
  1428. fromFirstOccurrenceOf ("34", false) would return "56".
  1429. If the substring isn't found, the method will return an empty string.
  1430. If ignoreCase is true, the comparison will be case-insensitive.
  1431. @see upToFirstOccurrenceOf, fromLastOccurrenceOf
  1432. */
  1433. const String fromFirstOccurrenceOf (const tchar* const substringToStartFrom,
  1434. const bool includeSubStringInResult,
  1435. const bool ignoreCase) const throw();
  1436. /** Returns a section of the string starting from the last occurrence of a given substring.
  1437. Similar to fromFirstOccurrenceOf(), but using the last occurrence of the substring, and
  1438. unlike fromFirstOccurrenceOf(), if the substring isn't found, this method will
  1439. return the whole of the original string.
  1440. @see fromFirstOccurrenceOf, upToLastOccurrenceOf
  1441. */
  1442. const String fromLastOccurrenceOf (const tchar* const substringToFind,
  1443. const bool includeSubStringInResult,
  1444. const bool ignoreCase) const throw();
  1445. /** Returns the start of this string, up to the first occurrence of a substring.
  1446. This will search for the first occurrence of a given substring, and then
  1447. return a copy of the string, up to the position of this substring,
  1448. optionally including or excluding the substring itself in the result.
  1449. e.g. for the string "123456", upTo ("34", false) would return "12", and
  1450. upTo ("34", true) would return "1234".
  1451. If the substring isn't found, this will return the whole of the original string.
  1452. @see upToLastOccurrenceOf, fromFirstOccurrenceOf
  1453. */
  1454. const String upToFirstOccurrenceOf (const tchar* const substringToEndWith,
  1455. const bool includeSubStringInResult,
  1456. const bool ignoreCase) const throw();
  1457. /** Returns the start of this string, up to the last occurrence of a substring.
  1458. Similar to upToFirstOccurrenceOf(), but this finds the last occurrence rather than the first.
  1459. @see upToFirstOccurrenceOf, fromFirstOccurrenceOf
  1460. */
  1461. const String upToLastOccurrenceOf (const tchar* substringToFind,
  1462. const bool includeSubStringInResult,
  1463. const bool ignoreCase) const throw();
  1464. /** Returns a copy of this string with any whitespace characters removed from the start and end. */
  1465. const String trim() const throw();
  1466. /** Returns a copy of this string with any whitespace characters removed from the start. */
  1467. const String trimStart() const throw();
  1468. /** Returns a copy of this string with any whitespace characters removed from the end. */
  1469. const String trimEnd() const throw();
  1470. /** Returns an upper-case version of this string. */
  1471. const String toUpperCase() const throw();
  1472. /** Returns an lower-case version of this string. */
  1473. const String toLowerCase() const throw();
  1474. /** Replaces a sub-section of the string with another string.
  1475. This will return a copy of this string, with a set of characters
  1476. from startIndex to startIndex + numCharsToReplace removed, and with
  1477. a new string inserted in their place.
  1478. Note that this is a const method, and won't alter the string itself.
  1479. @param startIndex the first character to remove. If this is beyond the bounds of the string,
  1480. it will be constrained to a valid range.
  1481. @param numCharactersToReplace the number of characters to remove. If zero or less, no
  1482. characters will be taken out.
  1483. @param stringToInsert the new string to insert at startIndex after the characters have been
  1484. removed.
  1485. */
  1486. const String replaceSection (int startIndex,
  1487. int numCharactersToReplace,
  1488. const tchar* const stringToInsert) const throw();
  1489. /** Replaces all occurrences of a substring with another string.
  1490. Returns a copy of this string, with any occurrences of stringToReplace
  1491. swapped for stringToInsertInstead.
  1492. Note that this is a const method, and won't alter the string itself.
  1493. */
  1494. const String replace (const tchar* const stringToReplace,
  1495. const tchar* const stringToInsertInstead,
  1496. const bool ignoreCase = false) const throw();
  1497. /** Returns a string with all occurrences of a character replaced with a different one. */
  1498. const String replaceCharacter (const tchar characterToReplace,
  1499. const tchar characterToInsertInstead) const throw();
  1500. /** Replaces a set of characters with another set.
  1501. Returns a string in which each character from charactersToReplace has been replaced
  1502. by the character at the equivalent position in newCharacters (so the two strings
  1503. passed in must be the same length).
  1504. e.g. translate ("abc", "def") replaces 'a' with 'd', 'b' with 'e', etc.
  1505. Note that this is a const method, and won't affect the string itself.
  1506. */
  1507. const String replaceCharacters (const String& charactersToReplace,
  1508. const tchar* const charactersToInsertInstead) const throw();
  1509. /** Returns a version of this string that only retains a fixed set of characters.
  1510. This will return a copy of this string, omitting any characters which are not
  1511. found in the string passed-in.
  1512. e.g. for "1122334455", retainCharacters ("432") would return "223344"
  1513. Note that this is a const method, and won't alter the string itself.
  1514. */
  1515. const String retainCharacters (const tchar* const charactersToRetain) const throw();
  1516. /** Returns a version of this string with a set of characters removed.
  1517. This will return a copy of this string, omitting any characters which are
  1518. found in the string passed-in.
  1519. e.g. for "1122334455", removeCharacters ("432") would return "1155"
  1520. Note that this is a const method, and won't alter the string itself.
  1521. */
  1522. const String removeCharacters (const tchar* const charactersToRemove) const throw();
  1523. /** Returns a section from the start of the string that only contains a certain set of characters.
  1524. This returns the leftmost section of the string, up to (and not including) the
  1525. first character that doesn't appear in the string passed in.
  1526. */
  1527. const String initialSectionContainingOnly (const tchar* const permittedCharacters) const throw();
  1528. /** Returns a section from the start of the string that only contains a certain set of characters.
  1529. This returns the leftmost section of the string, up to (and not including) the
  1530. first character that occurs in the string passed in.
  1531. */
  1532. const String initialSectionNotContaining (const tchar* const charactersToStopAt) const throw();
  1533. /** Checks whether the string might be in quotation marks.
  1534. @returns true if the string begins with a quote character (either a double or single quote).
  1535. It is also true if there is whitespace before the quote, but it doesn't check the end of the string.
  1536. @see unquoted, quoted
  1537. */
  1538. bool isQuotedString() const throw();
  1539. /** Removes quotation marks from around the string, (if there are any).
  1540. Returns a copy of this string with any quotes removed from its ends. Quotes that aren't
  1541. at the ends of the string are not affected. If there aren't any quotes, the original string
  1542. is returned.
  1543. Note that this is a const method, and won't alter the string itself.
  1544. @see isQuotedString, quoted
  1545. */
  1546. const String unquoted() const throw();
  1547. /** Adds quotation marks around a string.
  1548. This will return a copy of the string with a quote at the start and end, (but won't
  1549. add the quote if there's already one there, so it's safe to call this on strings that
  1550. may already have quotes around them).
  1551. Note that this is a const method, and won't alter the string itself.
  1552. @param quoteCharacter the character to add at the start and end
  1553. @see isQuotedString, unquoted
  1554. */
  1555. const String quoted (const tchar quoteCharacter = JUCE_T('"')) const throw();
  1556. /** Writes text into this string, using printf style-arguments.
  1557. This will replace the contents of the string with the output of this
  1558. formatted printf.
  1559. Note that using the %s token with a juce string is probably a bad idea, as
  1560. this may expect differect encodings on different platforms.
  1561. @see formatted
  1562. */
  1563. void printf (const tchar* const format, ...) throw();
  1564. /** Returns a string, created using arguments in the style of printf.
  1565. This will return a string which is the result of a sprintf using the
  1566. arguments passed-in.
  1567. Note that using the %s token with a juce string is probably a bad idea, as
  1568. this may expect differect encodings on different platforms.
  1569. @see printf, vprintf
  1570. */
  1571. static const String formatted (const tchar* const format, ...) throw();
  1572. /** Writes text into this string, using a printf style, but taking a va_list argument.
  1573. This will replace the contents of the string with the output of this
  1574. formatted printf. Used by other methods, this is public in case it's
  1575. useful for other purposes where you want to pass a va_list through directly.
  1576. Note that using the %s token with a juce string is probably a bad idea, as
  1577. this may expect differect encodings on different platforms.
  1578. @see printf, formatted
  1579. */
  1580. void vprintf (const tchar* const format, va_list& args) throw();
  1581. /** Creates a string which is a version of a string repeated and joined together.
  1582. @param stringToRepeat the string to repeat
  1583. @param numberOfTimesToRepeat how many times to repeat it
  1584. */
  1585. static const String repeatedString (const tchar* const stringToRepeat,
  1586. int numberOfTimesToRepeat) throw();
  1587. /** Creates a string from data in an unknown format.
  1588. This looks at some binary data and tries to guess whether it's Unicode
  1589. or 8-bit characters, then returns a string that represents it correctly.
  1590. Should be able to handle Unicode endianness correctly, by looking at
  1591. the first two bytes.
  1592. */
  1593. static const String createStringFromData (const void* const data,
  1594. const int size) throw();
  1595. // Numeric conversions..
  1596. /** Creates a string containing this signed 32-bit integer as a decimal number.
  1597. @see getIntValue, getFloatValue, getDoubleValue, toHexString
  1598. */
  1599. explicit String (const int decimalInteger) throw();
  1600. /** Creates a string containing this unsigned 32-bit integer as a decimal number.
  1601. @see getIntValue, getFloatValue, getDoubleValue, toHexString
  1602. */
  1603. explicit String (const unsigned int decimalInteger) throw();
  1604. /** Creates a string containing this signed 16-bit integer as a decimal number.
  1605. @see getIntValue, getFloatValue, getDoubleValue, toHexString
  1606. */
  1607. explicit String (const short decimalInteger) throw();
  1608. /** Creates a string containing this unsigned 16-bit integer as a decimal number.
  1609. @see getIntValue, getFloatValue, getDoubleValue, toHexString
  1610. */
  1611. explicit String (const unsigned short decimalInteger) throw();
  1612. /** Creates a string containing this signed 64-bit integer as a decimal number.
  1613. @see getLargeIntValue, getFloatValue, getDoubleValue, toHexString
  1614. */
  1615. explicit String (const int64 largeIntegerValue) throw();
  1616. /** Creates a string containing this unsigned 64-bit integer as a decimal number.
  1617. @see getLargeIntValue, getFloatValue, getDoubleValue, toHexString
  1618. */
  1619. explicit String (const uint64 largeIntegerValue) throw();
  1620. /** Creates a string representing this floating-point number.
  1621. @param floatValue the value to convert to a string
  1622. @param numberOfDecimalPlaces if this is > 0, it will format the number using that many
  1623. decimal places, and will not use exponent notation. If 0 or
  1624. less, it will use exponent notation if necessary.
  1625. @see getDoubleValue, getIntValue
  1626. */
  1627. explicit String (const float floatValue,
  1628. const int numberOfDecimalPlaces = 0) throw();
  1629. /** Creates a string representing this floating-point number.
  1630. @param doubleValue the value to convert to a string
  1631. @param numberOfDecimalPlaces if this is > 0, it will format the number using that many
  1632. decimal places, and will not use exponent notation. If 0 or
  1633. less, it will use exponent notation if necessary.
  1634. @see getFloatValue, getIntValue
  1635. */
  1636. explicit String (const double doubleValue,
  1637. const int numberOfDecimalPlaces = 0) throw();
  1638. /** Parses this string to find its numerical value (up to 32 bits in size).
  1639. @returns the value of the string as a 32 bit signed base-10 integer.
  1640. @see getTrailingIntValue, getHexValue32, getHexValue64
  1641. */
  1642. int getIntValue() const throw();
  1643. /** Parses this string to find its numerical value (up to 64 bits in size).
  1644. @returns the value of the string as a 64 bit signed base-10 integer.
  1645. */
  1646. int64 getLargeIntValue() const throw();
  1647. /** Parses a decimal number from the end of the string.
  1648. This will look for a value at the end of the string.
  1649. e.g. for "321 xyz654" it will return 654; for "2 3 4" it'll return 4.
  1650. Negative numbers are not handled, so "xyz-5" returns 5.
  1651. @see getIntValue
  1652. */
  1653. int getTrailingIntValue() const throw();
  1654. /** Parses this string as a floating point number.
  1655. @returns the value of the string as a 32-bit floating point value.
  1656. @see getDoubleValue
  1657. */
  1658. float getFloatValue() const throw();
  1659. /** Parses this string as a floating point number.
  1660. @returns the value of the string as a 64-bit floating point value.
  1661. @see getFloatValue
  1662. */
  1663. double getDoubleValue() const throw();
  1664. /** Parses the string as a hexadecimal number.
  1665. Non-hexadecimal characters in the string are ignored.
  1666. If the string contains too many characters, then the lowest significant
  1667. digits are returned, e.g. "ffff12345678" would produce 0x12345678.
  1668. @returns a 32-bit number which is the value of the string in hex.
  1669. */
  1670. int getHexValue32() const throw();
  1671. /** Parses the string as a hexadecimal number.
  1672. Non-hexadecimal characters in the string are ignored.
  1673. If the string contains too many characters, then the lowest significant
  1674. digits are returned, e.g. "ffff1234567812345678" would produce 0x1234567812345678.
  1675. @returns a 64-bit number which is the value of the string in hex.
  1676. */
  1677. int64 getHexValue64() const throw();
  1678. /** Creates a string representing this 32-bit value in hexadecimal. */
  1679. static const String toHexString (const int number) throw();
  1680. /** Creates a string representing this 64-bit value in hexadecimal. */
  1681. static const String toHexString (const int64 number) throw();
  1682. /** Creates a string representing this 16-bit value in hexadecimal. */
  1683. static const String toHexString (const short number) throw();
  1684. /** Creates a string containing a hex dump of a block of binary data.
  1685. @param data the binary data to use as input
  1686. @param size how many bytes of data to use
  1687. @param groupSize how many bytes are grouped together before inserting a
  1688. space into the output. e.g. group size 0 has no spaces,
  1689. group size 1 looks like: "be a1 c2 ff", group size 2 looks
  1690. like "bea1 c2ff".
  1691. */
  1692. static const String toHexString (const unsigned char* data,
  1693. const int size,
  1694. const int groupSize = 1) throw();
  1695. // Casting to character arrays..
  1696. #if JUCE_STRINGS_ARE_UNICODE
  1697. /** Returns a version of this string using the default 8-bit system encoding.
  1698. Because it returns a reference to the string's internal data, the pointer
  1699. that is returned must not be stored anywhere, as it can be deleted whenever the
  1700. string changes.
  1701. */
  1702. operator const char*() const throw();
  1703. /** Returns a unicode version of this string.
  1704. Because it returns a reference to the string's internal data, the pointer
  1705. that is returned must not be stored anywhere, as it can be deleted whenever the
  1706. string changes.
  1707. */
  1708. inline operator const juce_wchar*() const throw() { return text->text; }
  1709. #else
  1710. /** Returns a version of this string using the default 8-bit system encoding.
  1711. Because it returns a reference to the string's internal data, the pointer
  1712. that is returned must not be stored anywhere, as it can be deleted whenever the
  1713. string changes.
  1714. */
  1715. inline operator const char*() const throw() { return text->text; }
  1716. /** Returns a unicode version of this string.
  1717. Because it returns a reference to the string's internal data, the pointer
  1718. that is returned must not be stored anywhere, as it can be deleted whenever the
  1719. string changes.
  1720. */
  1721. operator const juce_wchar*() const throw();
  1722. #endif
  1723. /** Copies the string to a buffer.
  1724. @param destBuffer the place to copy it to
  1725. @param maxCharsToCopy the maximum number of characters to copy to the buffer,
  1726. not including the tailing zero, so this shouldn't be
  1727. larger than the size of your destination buffer - 1
  1728. */
  1729. void copyToBuffer (char* const destBuffer,
  1730. const int maxCharsToCopy) const throw();
  1731. /** Copies the string to a unicode buffer.
  1732. @param destBuffer the place to copy it to
  1733. @param maxCharsToCopy the maximum number of characters to copy to the buffer,
  1734. not including the tailing zero, so this shouldn't be
  1735. larger than the size of your destination buffer - 1
  1736. */
  1737. void copyToBuffer (juce_wchar* const destBuffer,
  1738. const int maxCharsToCopy) const throw();
  1739. /** Copies the string to a buffer as UTF-8 characters.
  1740. Returns the number of bytes copied to the buffer, including the terminating null
  1741. character.
  1742. @param destBuffer the place to copy it to; if this is a null pointer,
  1743. the method just returns the number of bytes required
  1744. (including the terminating null character).
  1745. */
  1746. int copyToUTF8 (uint8* const destBuffer) const throw();
  1747. /** Returns a pointer to a UTF-8 version of this string.
  1748. Because it returns a reference to the string's internal data, the pointer
  1749. that is returned must not be stored anywhere, as it can be deleted whenever the
  1750. string changes.
  1751. */
  1752. const char* toUTF8() const throw();
  1753. /** Creates a String from a UTF-8 encoded buffer.
  1754. If the size is < 0, it'll keep reading until it hits a zero.
  1755. */
  1756. static const String fromUTF8 (const uint8* const utf8buffer,
  1757. int bufferSizeBytes = -1) throw();
  1758. /** Increases the string's internally allocated storage.
  1759. Although the string's contents won't be affected by this call, it will
  1760. increase the amount of memory allocated internally for the string to grow into.
  1761. If you're about to make a large number of calls to methods such
  1762. as += or <<, it's more efficient to preallocate enough extra space
  1763. beforehand, so that these methods won't have to keep resizing the string
  1764. to append the extra characters.
  1765. @param numCharsNeeded the number of characters to allocate storage for. If this
  1766. value is less than the currently allocated size, it will
  1767. have no effect.
  1768. */
  1769. void preallocateStorage (const int numCharsNeeded) throw();
  1770. juce_UseDebuggingNewOperator // (adds debugging info to find leaked objects)
  1771. private:
  1772. struct InternalRefCountedStringHolder
  1773. {
  1774. int refCount;
  1775. int allocatedNumChars;
  1776. #if JUCE_STRINGS_ARE_UNICODE
  1777. wchar_t text[1];
  1778. #else
  1779. char text[1];
  1780. #endif
  1781. };
  1782. InternalRefCountedStringHolder* text;
  1783. static InternalRefCountedStringHolder emptyString;
  1784. // internal constructor that preallocates a certain amount of memory
  1785. String (const int numChars, const int dummyVariable) throw();
  1786. void deleteInternal() throw();
  1787. void createInternal (const int numChars) throw();
  1788. void createInternal (const tchar* const text, const tchar* const textEnd) throw();
  1789. void appendInternal (const tchar* const text, const int numExtraChars) throw();
  1790. void doubleToStringWithDecPlaces (double n, int numDecPlaces) throw();
  1791. void dupeInternalIfMultiplyReferenced() throw();
  1792. };
  1793. /** Global operator to allow a String to be appended to a string literal.
  1794. This allows the use of expressions such as "abc" + String (x)
  1795. @see String
  1796. */
  1797. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  1798. const String& string2) throw();
  1799. /** Global operator to allow a String to be appended to a string literal.
  1800. This allows the use of expressions such as "abc" + String (x)
  1801. @see String
  1802. */
  1803. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  1804. const String& string2) throw();
  1805. #endif // __JUCE_STRING_JUCEHEADER__
  1806. /********* End of inlined file: juce_String.h *********/
  1807. /**
  1808. Acts as an application-wide logging class.
  1809. A subclass of Logger can be created and passed into the Logger::setCurrentLogger
  1810. method and this will then be used by all calls to writeToLog.
  1811. The logger class also contains methods for writing messages to the debugger's
  1812. output stream.
  1813. @see FileLogger
  1814. */
  1815. class JUCE_API Logger
  1816. {
  1817. public:
  1818. /** Destructor. */
  1819. virtual ~Logger();
  1820. /** Sets the current logging class to use.
  1821. Note that the object passed in won't be deleted when no longer needed.
  1822. A null pointer can be passed-in to disable any logging.
  1823. If deleteOldLogger is set to true, the existing logger will be
  1824. deleted (if there is one).
  1825. */
  1826. static void JUCE_CALLTYPE setCurrentLogger (Logger* const newLogger,
  1827. const bool deleteOldLogger = false);
  1828. /** Writes a string to the current logger.
  1829. This will pass the string to the logger's logMessage() method if a logger
  1830. has been set.
  1831. @see logMessage
  1832. */
  1833. static void JUCE_CALLTYPE writeToLog (const String& message);
  1834. /** Writes a message to the standard error stream.
  1835. This can be called directly, or by using the DBG() macro in
  1836. juce_PlatformDefs.h (which will avoid calling the method in non-debug builds).
  1837. */
  1838. static void JUCE_CALLTYPE outputDebugString (const String& text) throw();
  1839. /** Writes a message to the standard error stream.
  1840. This can be called directly, or by using the DBG_PRINTF() macro in
  1841. juce_PlatformDefs.h (which will avoid calling the method in non-debug builds).
  1842. */
  1843. static void JUCE_CALLTYPE outputDebugPrintf (const tchar* format, ...) throw();
  1844. protected:
  1845. Logger();
  1846. /** This is overloaded by subclasses to implement custom logging behaviour.
  1847. @see setCurrentLogger
  1848. */
  1849. virtual void logMessage (const String& message) = 0;
  1850. };
  1851. #endif // __JUCE_LOGGER_JUCEHEADER__
  1852. /********* End of inlined file: juce_Logger.h *********/
  1853. END_JUCE_NAMESPACE
  1854. #endif // __JUCE_STANDARDHEADER_JUCEHEADER__
  1855. /********* End of inlined file: juce_StandardHeader.h *********/
  1856. BEGIN_JUCE_NAMESPACE
  1857. #if JUCE_MSVC
  1858. // this is set explicitly in case the app is using a different packing size.
  1859. #pragma pack (push, 8)
  1860. #pragma warning (push)
  1861. #pragma warning (disable: 4786) // (old vc6 warning about long class names)
  1862. #endif
  1863. #if JUCE_MAC
  1864. #pragma align=natural
  1865. #endif
  1866. #define JUCE_PUBLIC_INCLUDES
  1867. // this is where all the class header files get brought in..
  1868. /********* Start of inlined file: juce_core_includes.h *********/
  1869. #ifndef __JUCE_JUCE_CORE_INCLUDES_INCLUDEFILES__
  1870. #define __JUCE_JUCE_CORE_INCLUDES_INCLUDEFILES__
  1871. #ifndef __JUCE_ATOMIC_JUCEHEADER__
  1872. /********* Start of inlined file: juce_Atomic.h *********/
  1873. #ifndef __JUCE_ATOMIC_JUCEHEADER__
  1874. #define __JUCE_ATOMIC_JUCEHEADER__
  1875. // Atomic increment/decrement operations..
  1876. #if JUCE_MAC && ! DOXYGEN
  1877. #if ! MACOS_10_3_OR_EARLIER
  1878. forcedinline void atomicIncrement (int& variable) throw() { OSAtomicIncrement32 ((int32_t*) &variable); }
  1879. forcedinline int atomicIncrementAndReturn (int& variable) throw() { return OSAtomicIncrement32 ((int32_t*) &variable); }
  1880. forcedinline void atomicDecrement (int& variable) throw() { OSAtomicDecrement32 ((int32_t*) &variable); }
  1881. forcedinline int atomicDecrementAndReturn (int& variable) throw() { return OSAtomicDecrement32 ((int32_t*) &variable); }
  1882. #else
  1883. forcedinline void atomicIncrement (int& variable) throw() { OTAtomicAdd32 (1, (SInt32*) &variable); }
  1884. forcedinline int atomicIncrementAndReturn (int& variable) throw() { return OTAtomicAdd32 (1, (SInt32*) &variable); }
  1885. forcedinline void atomicDecrement (int& variable) throw() { OTAtomicAdd32 (-1, (SInt32*) &variable); }
  1886. forcedinline int atomicDecrementAndReturn (int& variable) throw() { return OTAtomicAdd32 (-1, (SInt32*) &variable); }
  1887. #endif
  1888. #elif JUCE_GCC
  1889. #if JUCE_USE_GCC_ATOMIC_INTRINSICS
  1890. forcedinline void atomicIncrement (int& variable) throw() { __sync_add_and_fetch (&variable, 1); }
  1891. forcedinline int atomicIncrementAndReturn (int& variable) throw() { return __sync_add_and_fetch (&variable, 1); }
  1892. forcedinline void atomicDecrement (int& variable) throw() { __sync_add_and_fetch (&variable, -1); }
  1893. forcedinline int atomicDecrementAndReturn (int& variable) throw() { return __sync_add_and_fetch (&variable, -1); }
  1894. #else
  1895. /** Increments an integer in a thread-safe way. */
  1896. forcedinline void atomicIncrement (int& variable) throw()
  1897. {
  1898. __asm__ __volatile__ (
  1899. #if JUCE_64BIT
  1900. "lock incl (%%rax)"
  1901. :
  1902. : "a" (&variable)
  1903. : "cc", "memory");
  1904. #else
  1905. "lock incl %0"
  1906. : "=m" (variable)
  1907. : "m" (variable));
  1908. #endif
  1909. }
  1910. /** Increments an integer in a thread-safe way and returns the incremented value. */
  1911. forcedinline int atomicIncrementAndReturn (int& variable) throw()
  1912. {
  1913. int result;
  1914. __asm__ __volatile__ (
  1915. #if JUCE_64BIT
  1916. "lock xaddl %%ebx, (%%rax) \n\
  1917. incl %%ebx"
  1918. : "=b" (result)
  1919. : "a" (&variable), "b" (1)
  1920. : "cc", "memory");
  1921. #else
  1922. "lock xaddl %%eax, (%%ecx) \n\
  1923. incl %%eax"
  1924. : "=a" (result)
  1925. : "c" (&variable), "a" (1)
  1926. : "memory");
  1927. #endif
  1928. return result;
  1929. }
  1930. /** Decrememts an integer in a thread-safe way. */
  1931. forcedinline void atomicDecrement (int& variable) throw()
  1932. {
  1933. __asm__ __volatile__ (
  1934. #if JUCE_64BIT
  1935. "lock decl (%%rax)"
  1936. :
  1937. : "a" (&variable)
  1938. : "cc", "memory");
  1939. #else
  1940. "lock decl %0"
  1941. : "=m" (variable)
  1942. : "m" (variable));
  1943. #endif
  1944. }
  1945. /** Decrememts an integer in a thread-safe way and returns the incremented value. */
  1946. forcedinline int atomicDecrementAndReturn (int& variable) throw()
  1947. {
  1948. int result;
  1949. __asm__ __volatile__ (
  1950. #if JUCE_64BIT
  1951. "lock xaddl %%ebx, (%%rax) \n\
  1952. decl %%ebx"
  1953. : "=b" (result)
  1954. : "a" (&variable), "b" (-1)
  1955. : "cc", "memory");
  1956. #else
  1957. "lock xaddl %%eax, (%%ecx) \n\
  1958. decl %%eax"
  1959. : "=a" (result)
  1960. : "c" (&variable), "a" (-1)
  1961. : "memory");
  1962. #endif
  1963. return result;
  1964. }
  1965. #endif
  1966. #elif JUCE_USE_INTRINSICS
  1967. #pragma intrinsic (_InterlockedIncrement)
  1968. #pragma intrinsic (_InterlockedDecrement)
  1969. /** Increments an integer in a thread-safe way. */
  1970. forcedinline void __fastcall atomicIncrement (int& variable) throw()
  1971. {
  1972. _InterlockedIncrement (reinterpret_cast <volatile long*> (&variable));
  1973. }
  1974. /** Increments an integer in a thread-safe way and returns the incremented value. */
  1975. forcedinline int __fastcall atomicIncrementAndReturn (int& variable) throw()
  1976. {
  1977. return _InterlockedIncrement (reinterpret_cast <volatile long*> (&variable));
  1978. }
  1979. /** Decrememts an integer in a thread-safe way. */
  1980. forcedinline void __fastcall atomicDecrement (int& variable) throw()
  1981. {
  1982. _InterlockedDecrement (reinterpret_cast <volatile long*> (&variable));
  1983. }
  1984. /** Decrememts an integer in a thread-safe way and returns the incremented value. */
  1985. forcedinline int __fastcall atomicDecrementAndReturn (int& variable) throw()
  1986. {
  1987. return _InterlockedDecrement (reinterpret_cast <volatile long*> (&variable));
  1988. }
  1989. #else
  1990. /** Increments an integer in a thread-safe way. */
  1991. forcedinline void __fastcall atomicIncrement (int& variable) throw()
  1992. {
  1993. __asm {
  1994. mov ecx, dword ptr [variable]
  1995. lock inc dword ptr [ecx]
  1996. }
  1997. }
  1998. /** Increments an integer in a thread-safe way and returns the incremented value. */
  1999. forcedinline int __fastcall atomicIncrementAndReturn (int& variable) throw()
  2000. {
  2001. int result;
  2002. __asm {
  2003. mov ecx, dword ptr [variable]
  2004. mov eax, 1
  2005. lock xadd dword ptr [ecx], eax
  2006. inc eax
  2007. mov result, eax
  2008. }
  2009. return result;
  2010. }
  2011. /** Decrememts an integer in a thread-safe way. */
  2012. forcedinline void __fastcall atomicDecrement (int& variable) throw()
  2013. {
  2014. __asm {
  2015. mov ecx, dword ptr [variable]
  2016. lock dec dword ptr [ecx]
  2017. }
  2018. }
  2019. /** Decrememts an integer in a thread-safe way and returns the incremented value. */
  2020. forcedinline int __fastcall atomicDecrementAndReturn (int& variable) throw()
  2021. {
  2022. int result;
  2023. __asm {
  2024. mov ecx, dword ptr [variable]
  2025. mov eax, -1
  2026. lock xadd dword ptr [ecx], eax
  2027. dec eax
  2028. mov result, eax
  2029. }
  2030. return result;
  2031. }
  2032. #endif
  2033. #endif // __JUCE_ATOMIC_JUCEHEADER__
  2034. /********* End of inlined file: juce_Atomic.h *********/
  2035. #endif
  2036. #ifndef __JUCE_DATACONVERSIONS_JUCEHEADER__
  2037. #endif
  2038. #ifndef __JUCE_FILELOGGER_JUCEHEADER__
  2039. /********* Start of inlined file: juce_FileLogger.h *********/
  2040. #ifndef __JUCE_FILELOGGER_JUCEHEADER__
  2041. #define __JUCE_FILELOGGER_JUCEHEADER__
  2042. /********* Start of inlined file: juce_File.h *********/
  2043. #ifndef __JUCE_FILE_JUCEHEADER__
  2044. #define __JUCE_FILE_JUCEHEADER__
  2045. /********* Start of inlined file: juce_OwnedArray.h *********/
  2046. #ifndef __JUCE_OWNEDARRAY_JUCEHEADER__
  2047. #define __JUCE_OWNEDARRAY_JUCEHEADER__
  2048. /********* Start of inlined file: juce_ArrayAllocationBase.h *********/
  2049. #ifndef __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__
  2050. #define __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__
  2051. /** The default size of chunk in which arrays increase their storage.
  2052. Used by ArrayAllocationBase and its subclasses.
  2053. */
  2054. const int juceDefaultArrayGranularity = 8;
  2055. /**
  2056. Implements some basic array storage allocation functions.
  2057. This class isn't really for public use - it's used by the other
  2058. array classes, but might come in handy for some purposes.
  2059. @see Array, OwnedArray, ReferenceCountedArray
  2060. */
  2061. template <class ElementType>
  2062. class ArrayAllocationBase
  2063. {
  2064. protected:
  2065. /** Creates an empty array.
  2066. @param granularity_ this is the size of increment by which the internal storage
  2067. will be increased.
  2068. */
  2069. ArrayAllocationBase (const int granularity_) throw()
  2070. : elements (0),
  2071. numAllocated (0),
  2072. granularity (granularity_)
  2073. {
  2074. }
  2075. /** Destructor. */
  2076. ~ArrayAllocationBase() throw()
  2077. {
  2078. delete[] elements;
  2079. }
  2080. /** Changes the amount of storage allocated.
  2081. This will retain any data currently held in the array, and either add or
  2082. remove extra space at the end.
  2083. @param numElements the number of elements that are needed
  2084. */
  2085. void setAllocatedSize (const int numElements) throw()
  2086. {
  2087. if (numAllocated != numElements)
  2088. {
  2089. if (numElements > 0)
  2090. {
  2091. ElementType* const newElements = new ElementType [numElements];
  2092. const int itemsToRetain = jmin (numElements, numAllocated);
  2093. for (int i = 0; i < itemsToRetain; ++i)
  2094. newElements[i] = elements[i];
  2095. delete[] elements;
  2096. elements = newElements;
  2097. }
  2098. else if (elements != 0)
  2099. {
  2100. delete[] elements;
  2101. elements = 0;
  2102. }
  2103. numAllocated = numElements;
  2104. }
  2105. }
  2106. /** Increases the amount of storage allocated if it is less than a given amount.
  2107. This will retain any data currently held in the array, but will add
  2108. extra space at the end to make sure there it's at least as big as the size
  2109. passed in. If it's already bigger, no action is taken.
  2110. @param minNumElements the minimum number of elements that are needed
  2111. */
  2112. void ensureAllocatedSize (int minNumElements) throw()
  2113. {
  2114. if (minNumElements > numAllocated)
  2115. {
  2116. // for arrays with small granularity that get big, start
  2117. // increasing the size in bigger jumps
  2118. if (minNumElements > (granularity << 6))
  2119. {
  2120. minNumElements += (minNumElements / granularity);
  2121. if (minNumElements > (granularity << 8))
  2122. minNumElements += granularity << 6;
  2123. else
  2124. minNumElements += granularity << 5;
  2125. }
  2126. setAllocatedSize (granularity * (minNumElements / granularity + 1));
  2127. }
  2128. }
  2129. ElementType* elements;
  2130. int numAllocated, granularity;
  2131. private:
  2132. ArrayAllocationBase (const ArrayAllocationBase&);
  2133. const ArrayAllocationBase& operator= (const ArrayAllocationBase&);
  2134. };
  2135. #endif // __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__
  2136. /********* End of inlined file: juce_ArrayAllocationBase.h *********/
  2137. /********* Start of inlined file: juce_ElementComparator.h *********/
  2138. #ifndef __JUCE_ELEMENTCOMPARATOR_JUCEHEADER__
  2139. #define __JUCE_ELEMENTCOMPARATOR_JUCEHEADER__
  2140. /**
  2141. Sorts a range of elements in an array.
  2142. The comparator object that is passed-in must define a public method with the following
  2143. signature:
  2144. @code
  2145. int compareElements (ElementType first, ElementType second);
  2146. @endcode
  2147. ..and this method must return:
  2148. - a value of < 0 if the first comes before the second
  2149. - a value of 0 if the two objects are equivalent
  2150. - a value of > 0 if the second comes before the first
  2151. To improve performance, the compareElements() method can be declared as static or const.
  2152. @param comparator an object which defines a compareElements() method
  2153. @param array the array to sort
  2154. @param firstElement the index of the first element of the range to be sorted
  2155. @param lastElement the index of the last element in the range that needs
  2156. sorting (this is inclusive)
  2157. @param retainOrderOfEquivalentItems if true, the order of items that the
  2158. comparator deems the same will be maintained - this will be
  2159. a slower algorithm than if they are allowed to be moved around.
  2160. @see sortArrayRetainingOrder
  2161. */
  2162. template <class ElementType, class ElementComparator>
  2163. static void sortArray (ElementComparator& comparator,
  2164. ElementType* const array,
  2165. int firstElement,
  2166. int lastElement,
  2167. const bool retainOrderOfEquivalentItems)
  2168. {
  2169. (void) comparator; // if you pass in an object with a static compareElements() method, this
  2170. // avoids getting warning messages about the parameter being unused
  2171. if (lastElement > firstElement)
  2172. {
  2173. if (retainOrderOfEquivalentItems)
  2174. {
  2175. for (int i = firstElement; i < lastElement; ++i)
  2176. {
  2177. if (comparator.compareElements (array[i], array [i + 1]) > 0)
  2178. {
  2179. const ElementType temp = array [i];
  2180. array [i] = array[i + 1];
  2181. array [i + 1] = temp;
  2182. if (i > firstElement)
  2183. i -= 2;
  2184. }
  2185. }
  2186. }
  2187. else
  2188. {
  2189. int fromStack[30], toStack[30];
  2190. int stackIndex = 0;
  2191. for (;;)
  2192. {
  2193. const int size = (lastElement - firstElement) + 1;
  2194. if (size <= 8)
  2195. {
  2196. int j = lastElement;
  2197. int maxIndex;
  2198. while (j > firstElement)
  2199. {
  2200. maxIndex = firstElement;
  2201. for (int k = firstElement + 1; k <= j; ++k)
  2202. if (comparator.compareElements (array[k], array [maxIndex]) > 0)
  2203. maxIndex = k;
  2204. const ElementType temp = array [maxIndex];
  2205. array [maxIndex] = array[j];
  2206. array [j] = temp;
  2207. --j;
  2208. }
  2209. }
  2210. else
  2211. {
  2212. const int mid = firstElement + (size >> 1);
  2213. ElementType temp = array [mid];
  2214. array [mid] = array [firstElement];
  2215. array [firstElement] = temp;
  2216. int i = firstElement;
  2217. int j = lastElement + 1;
  2218. for (;;)
  2219. {
  2220. while (++i <= lastElement
  2221. && comparator.compareElements (array[i], array [firstElement]) <= 0)
  2222. {}
  2223. while (--j > firstElement
  2224. && comparator.compareElements (array[j], array [firstElement]) >= 0)
  2225. {}
  2226. if (j < i)
  2227. break;
  2228. temp = array[i];
  2229. array[i] = array[j];
  2230. array[j] = temp;
  2231. }
  2232. temp = array [firstElement];
  2233. array [firstElement] = array[j];
  2234. array [j] = temp;
  2235. if (j - 1 - firstElement >= lastElement - i)
  2236. {
  2237. if (firstElement + 1 < j)
  2238. {
  2239. fromStack [stackIndex] = firstElement;
  2240. toStack [stackIndex] = j - 1;
  2241. ++stackIndex;
  2242. }
  2243. if (i < lastElement)
  2244. {
  2245. firstElement = i;
  2246. continue;
  2247. }
  2248. }
  2249. else
  2250. {
  2251. if (i < lastElement)
  2252. {
  2253. fromStack [stackIndex] = i;
  2254. toStack [stackIndex] = lastElement;
  2255. ++stackIndex;
  2256. }
  2257. if (firstElement + 1 < j)
  2258. {
  2259. lastElement = j - 1;
  2260. continue;
  2261. }
  2262. }
  2263. }
  2264. if (--stackIndex < 0)
  2265. break;
  2266. jassert (stackIndex < numElementsInArray (fromStack));
  2267. firstElement = fromStack [stackIndex];
  2268. lastElement = toStack [stackIndex];
  2269. }
  2270. }
  2271. }
  2272. }
  2273. /**
  2274. Searches a sorted array of elements, looking for the index at which a specified value
  2275. should be inserted for it to be in the correct order.
  2276. The comparator object that is passed-in must define a public method with the following
  2277. signature:
  2278. @code
  2279. int compareElements (ElementType first, ElementType second);
  2280. @endcode
  2281. ..and this method must return:
  2282. - a value of < 0 if the first comes before the second
  2283. - a value of 0 if the two objects are equivalent
  2284. - a value of > 0 if the second comes before the first
  2285. To improve performance, the compareElements() method can be declared as static or const.
  2286. @param comparator an object which defines a compareElements() method
  2287. @param array the array to search
  2288. @param newElement the value that is going to be inserted
  2289. @param firstElement the index of the first element to search
  2290. @param lastElement the index of the last element in the range (this is non-inclusive)
  2291. */
  2292. template <class ElementType, class ElementComparator>
  2293. static int findInsertIndexInSortedArray (ElementComparator& comparator,
  2294. ElementType* const array,
  2295. const ElementType newElement,
  2296. int firstElement,
  2297. int lastElement)
  2298. {
  2299. jassert (firstElement <= lastElement);
  2300. (void) comparator; // if you pass in an object with a static compareElements() method, this
  2301. // avoids getting warning messages about the parameter being unused
  2302. while (firstElement < lastElement)
  2303. {
  2304. if (comparator.compareElements (newElement, array [firstElement]) == 0)
  2305. {
  2306. ++firstElement;
  2307. break;
  2308. }
  2309. else
  2310. {
  2311. const int halfway = (firstElement + lastElement) >> 1;
  2312. if (halfway == firstElement)
  2313. {
  2314. if (comparator.compareElements (newElement, array [halfway]) >= 0)
  2315. ++firstElement;
  2316. break;
  2317. }
  2318. else if (comparator.compareElements (newElement, array [halfway]) >= 0)
  2319. {
  2320. firstElement = halfway;
  2321. }
  2322. else
  2323. {
  2324. lastElement = halfway;
  2325. }
  2326. }
  2327. }
  2328. return firstElement;
  2329. }
  2330. /**
  2331. A simple ElementComparator class that can be used to sort an array of
  2332. integer primitive objects.
  2333. Example: @code
  2334. Array <int> myArray;
  2335. IntegerElementComparator<int> sorter;
  2336. myArray.sort (sorter);
  2337. @endcode
  2338. For floating point values, see the FloatElementComparator class instead.
  2339. @see FloatElementComparator, ElementComparator
  2340. */
  2341. template <class ElementType>
  2342. class IntegerElementComparator
  2343. {
  2344. public:
  2345. static int compareElements (const ElementType first,
  2346. const ElementType second) throw()
  2347. {
  2348. return first - second;
  2349. }
  2350. };
  2351. /**
  2352. A simple ElementComparator class that can be used to sort an array of numeric
  2353. double or floating point primitive objects.
  2354. Example: @code
  2355. Array <double> myArray;
  2356. FloatElementComparator<double> sorter;
  2357. myArray.sort (sorter);
  2358. @endcode
  2359. For integer values, see the IntegerElementComparator class instead.
  2360. @see IntegerElementComparator, ElementComparator
  2361. */
  2362. template <class ElementType>
  2363. class FloatElementComparator
  2364. {
  2365. public:
  2366. static int compareElements (const ElementType first,
  2367. const ElementType second) throw()
  2368. {
  2369. return (first < second) ? -1
  2370. : ((first == second) ? 0
  2371. : 1);
  2372. }
  2373. };
  2374. #endif // __JUCE_ELEMENTCOMPARATOR_JUCEHEADER__
  2375. /********* End of inlined file: juce_ElementComparator.h *********/
  2376. /********* Start of inlined file: juce_CriticalSection.h *********/
  2377. #ifndef __JUCE_CRITICALSECTION_JUCEHEADER__
  2378. #define __JUCE_CRITICALSECTION_JUCEHEADER__
  2379. /**
  2380. Prevents multiple threads from accessing shared objects at the same time.
  2381. @see ScopedLock, Thread, InterProcessLock
  2382. */
  2383. class JUCE_API CriticalSection
  2384. {
  2385. public:
  2386. /**
  2387. Creates a CriticalSection object
  2388. */
  2389. CriticalSection() throw();
  2390. /** Destroys a CriticalSection object.
  2391. If the critical section is deleted whilst locked, its subsequent behaviour
  2392. is unpredictable.
  2393. */
  2394. ~CriticalSection() throw();
  2395. /** Locks this critical section.
  2396. If the lock is currently held by another thread, this will wait until it
  2397. becomes free.
  2398. If the lock is already held by the caller thread, the method returns immediately.
  2399. @see exit, ScopedLock
  2400. */
  2401. void enter() const throw();
  2402. /** Attempts to lock this critical section without blocking.
  2403. This method behaves identically to CriticalSection::enter, except that the caller thread
  2404. does not wait if the lock is currently held by another thread but returns false immediately.
  2405. @returns false if the lock is currently held by another thread, true otherwise.
  2406. @see enter
  2407. */
  2408. bool tryEnter() const throw();
  2409. /** Releases the lock.
  2410. If the caller thread hasn't got the lock, this can have unpredictable results.
  2411. If the enter() method has been called multiple times by the thread, each
  2412. call must be matched by a call to exit() before other threads will be allowed
  2413. to take over the lock.
  2414. @see enter, ScopedLock
  2415. */
  2416. void exit() const throw();
  2417. juce_UseDebuggingNewOperator
  2418. private:
  2419. #if JUCE_WIN32
  2420. #if JUCE_64BIT
  2421. // To avoid including windows.h in the public Juce includes, we'll just allocate a
  2422. // block of memory here that's big enough to be used internally as a windows critical
  2423. // section object.
  2424. uint8 internal [44];
  2425. #else
  2426. uint8 internal [24];
  2427. #endif
  2428. #else
  2429. mutable pthread_mutex_t internal;
  2430. #endif
  2431. CriticalSection (const CriticalSection&);
  2432. const CriticalSection& operator= (const CriticalSection&);
  2433. };
  2434. /**
  2435. A class that can be used in place of a real CriticalSection object.
  2436. This is currently used by some templated array classes, and should get
  2437. optimised out by the compiler.
  2438. @see Array, OwnedArray, ReferenceCountedArray
  2439. */
  2440. class JUCE_API DummyCriticalSection
  2441. {
  2442. public:
  2443. forcedinline DummyCriticalSection() throw() {}
  2444. forcedinline ~DummyCriticalSection() throw() {}
  2445. forcedinline void enter() const throw() {}
  2446. forcedinline void exit() const throw() {}
  2447. };
  2448. #endif // __JUCE_CRITICALSECTION_JUCEHEADER__
  2449. /********* End of inlined file: juce_CriticalSection.h *********/
  2450. /** An array designed for holding objects.
  2451. This holds a list of pointers to objects, and will automatically
  2452. delete the objects when they are removed from the array, or when the
  2453. array is itself deleted.
  2454. Declare it in the form: OwnedArray<MyObjectClass>
  2455. ..and then add new objects, e.g. myOwnedArray.add (new MyObjectClass());
  2456. After adding objects, they are 'owned' by the array and will be deleted when
  2457. removed or replaced.
  2458. To make all the array's methods thread-safe, pass in "CriticalSection" as the templated
  2459. TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.
  2460. @see Array, ReferenceCountedArray, StringArray, CriticalSection
  2461. */
  2462. template <class ObjectClass,
  2463. class TypeOfCriticalSectionToUse = DummyCriticalSection>
  2464. class OwnedArray : private ArrayAllocationBase <ObjectClass*>
  2465. {
  2466. public:
  2467. /** Creates an empty array.
  2468. @param granularity this is the size of increment by which the internal storage
  2469. used by the array will grow. Only change it from the default if you know the
  2470. array is going to be very big and needs to be able to grow efficiently.
  2471. @see ArrayAllocationBase
  2472. */
  2473. OwnedArray (const int granularity = juceDefaultArrayGranularity) throw()
  2474. : ArrayAllocationBase <ObjectClass*> (granularity),
  2475. numUsed (0)
  2476. {
  2477. }
  2478. /** Deletes the array and also deletes any objects inside it.
  2479. To get rid of the array without deleting its objects, use its
  2480. clear (false) method before deleting it.
  2481. */
  2482. ~OwnedArray()
  2483. {
  2484. clear (true);
  2485. }
  2486. /** Clears the array, optionally deleting the objects inside it first. */
  2487. void clear (const bool deleteObjects = true)
  2488. {
  2489. lock.enter();
  2490. if (deleteObjects)
  2491. {
  2492. while (numUsed > 0)
  2493. delete this->elements [--numUsed];
  2494. }
  2495. this->setAllocatedSize (0);
  2496. numUsed = 0;
  2497. lock.exit();
  2498. }
  2499. /** Returns the number of items currently in the array.
  2500. @see operator[]
  2501. */
  2502. inline int size() const throw()
  2503. {
  2504. return numUsed;
  2505. }
  2506. /** Returns a pointer to the object at this index in the array.
  2507. If the index is out-of-range, this will return a null pointer, (and
  2508. it could be null anyway, because it's ok for the array to hold null
  2509. pointers as well as objects).
  2510. @see getUnchecked
  2511. */
  2512. inline ObjectClass* operator[] (const int index) const throw()
  2513. {
  2514. lock.enter();
  2515. ObjectClass* const result = (((unsigned int) index) < (unsigned int) numUsed)
  2516. ? this->elements [index]
  2517. : (ObjectClass*) 0;
  2518. lock.exit();
  2519. return result;
  2520. }
  2521. /** Returns a pointer to the object at this index in the array, without checking whether the index is in-range.
  2522. This is a faster and less safe version of operator[] which doesn't check the index passed in, so
  2523. it can be used when you're sure the index if always going to be legal.
  2524. */
  2525. inline ObjectClass* getUnchecked (const int index) const throw()
  2526. {
  2527. lock.enter();
  2528. jassert (((unsigned int) index) < (unsigned int) numUsed);
  2529. ObjectClass* const result = this->elements [index];
  2530. lock.exit();
  2531. return result;
  2532. }
  2533. /** Returns a pointer to the first object in the array.
  2534. This will return a null pointer if the array's empty.
  2535. @see getLast
  2536. */
  2537. inline ObjectClass* getFirst() const throw()
  2538. {
  2539. lock.enter();
  2540. ObjectClass* const result = (numUsed > 0) ? this->elements [0]
  2541. : (ObjectClass*) 0;
  2542. lock.exit();
  2543. return result;
  2544. }
  2545. /** Returns a pointer to the last object in the array.
  2546. This will return a null pointer if the array's empty.
  2547. @see getFirst
  2548. */
  2549. inline ObjectClass* getLast() const throw()
  2550. {
  2551. lock.enter();
  2552. ObjectClass* const result = (numUsed > 0) ? this->elements [numUsed - 1]
  2553. : (ObjectClass*) 0;
  2554. lock.exit();
  2555. return result;
  2556. }
  2557. /** Finds the index of an object which might be in the array.
  2558. @param objectToLookFor the object to look for
  2559. @returns the index at which the object was found, or -1 if it's not found
  2560. */
  2561. int indexOf (const ObjectClass* const objectToLookFor) const throw()
  2562. {
  2563. int result = -1;
  2564. lock.enter();
  2565. ObjectClass* const* e = this->elements;
  2566. for (int i = numUsed; --i >= 0;)
  2567. {
  2568. if (objectToLookFor == *e)
  2569. {
  2570. result = (int) (e - this->elements);
  2571. break;
  2572. }
  2573. ++e;
  2574. }
  2575. lock.exit();
  2576. return result;
  2577. }
  2578. /** Returns true if the array contains a specified object.
  2579. @param objectToLookFor the object to look for
  2580. @returns true if the object is in the array
  2581. */
  2582. bool contains (const ObjectClass* const objectToLookFor) const throw()
  2583. {
  2584. lock.enter();
  2585. ObjectClass* const* e = this->elements;
  2586. int i = numUsed;
  2587. while (i >= 4)
  2588. {
  2589. if (objectToLookFor == *e
  2590. || objectToLookFor == *++e
  2591. || objectToLookFor == *++e
  2592. || objectToLookFor == *++e)
  2593. {
  2594. lock.exit();
  2595. return true;
  2596. }
  2597. i -= 4;
  2598. ++e;
  2599. }
  2600. while (i > 0)
  2601. {
  2602. if (objectToLookFor == *e)
  2603. {
  2604. lock.exit();
  2605. return true;
  2606. }
  2607. --i;
  2608. ++e;
  2609. }
  2610. lock.exit();
  2611. return false;
  2612. }
  2613. /** Appends a new object to the end of the array.
  2614. Note that the this object will be deleted by the OwnedArray when it
  2615. is removed, so be careful not to delete it somewhere else.
  2616. Also be careful not to add the same object to the array more than once,
  2617. as this will obviously cause deletion of dangling pointers.
  2618. @param newObject the new object to add to the array
  2619. @see set, insert, addIfNotAlreadyThere, addSorted
  2620. */
  2621. void add (const ObjectClass* const newObject) throw()
  2622. {
  2623. lock.enter();
  2624. this->ensureAllocatedSize (numUsed + 1);
  2625. this->elements [numUsed++] = const_cast <ObjectClass*> (newObject);
  2626. lock.exit();
  2627. }
  2628. /** Inserts a new object into the array at the given index.
  2629. Note that the this object will be deleted by the OwnedArray when it
  2630. is removed, so be careful not to delete it somewhere else.
  2631. If the index is less than 0 or greater than the size of the array, the
  2632. element will be added to the end of the array.
  2633. Otherwise, it will be inserted into the array, moving all the later elements
  2634. along to make room.
  2635. Be careful not to add the same object to the array more than once,
  2636. as this will obviously cause deletion of dangling pointers.
  2637. @param indexToInsertAt the index at which the new element should be inserted
  2638. @param newObject the new object to add to the array
  2639. @see add, addSorted, addIfNotAlreadyThere, set
  2640. */
  2641. void insert (int indexToInsertAt,
  2642. const ObjectClass* const newObject) throw()
  2643. {
  2644. if (indexToInsertAt >= 0)
  2645. {
  2646. lock.enter();
  2647. if (indexToInsertAt > numUsed)
  2648. indexToInsertAt = numUsed;
  2649. this->ensureAllocatedSize (numUsed + 1);
  2650. ObjectClass** const e = this->elements + indexToInsertAt;
  2651. const int numToMove = numUsed - indexToInsertAt;
  2652. if (numToMove > 0)
  2653. memmove (e + 1, e, numToMove * sizeof (ObjectClass*));
  2654. *e = const_cast <ObjectClass*> (newObject);
  2655. ++numUsed;
  2656. lock.exit();
  2657. }
  2658. else
  2659. {
  2660. add (newObject);
  2661. }
  2662. }
  2663. /** Appends a new object at the end of the array as long as the array doesn't
  2664. already contain it.
  2665. If the array already contains a matching object, nothing will be done.
  2666. @param newObject the new object to add to the array
  2667. */
  2668. void addIfNotAlreadyThere (const ObjectClass* const newObject) throw()
  2669. {
  2670. lock.enter();
  2671. if (! contains (newObject))
  2672. add (newObject);
  2673. lock.exit();
  2674. }
  2675. /** Replaces an object in the array with a different one.
  2676. If the index is less than zero, this method does nothing.
  2677. If the index is beyond the end of the array, the new object is added to the end of the array.
  2678. Be careful not to add the same object to the array more than once,
  2679. as this will obviously cause deletion of dangling pointers.
  2680. @param indexToChange the index whose value you want to change
  2681. @param newObject the new value to set for this index.
  2682. @param deleteOldElement whether to delete the object that's being replaced with the new one
  2683. @see add, insert, remove
  2684. */
  2685. void set (const int indexToChange,
  2686. const ObjectClass* const newObject,
  2687. const bool deleteOldElement = true)
  2688. {
  2689. if (indexToChange >= 0)
  2690. {
  2691. ObjectClass* toDelete = 0;
  2692. lock.enter();
  2693. if (indexToChange < numUsed)
  2694. {
  2695. if (deleteOldElement)
  2696. toDelete = this->elements [indexToChange];
  2697. if (toDelete == newObject)
  2698. toDelete = 0;
  2699. else
  2700. this->elements [indexToChange] = const_cast <ObjectClass*> (newObject);
  2701. }
  2702. else
  2703. {
  2704. this->ensureAllocatedSize (numUsed + 1);
  2705. this->elements [numUsed++] = const_cast <ObjectClass*> (newObject);
  2706. }
  2707. lock.exit();
  2708. delete toDelete;
  2709. }
  2710. }
  2711. /** Inserts a new object into the array assuming that the array is sorted.
  2712. This will use a comparator to find the position at which the new object
  2713. should go. If the array isn't sorted, the behaviour of this
  2714. method will be unpredictable.
  2715. @param comparator the comparator to use to compare the elements - see the sort method
  2716. for details about this object's structure
  2717. @param newObject the new object to insert to the array
  2718. @see add, sort, indexOfSorted
  2719. */
  2720. template <class ElementComparator>
  2721. void addSorted (ElementComparator& comparator,
  2722. ObjectClass* const newObject) throw()
  2723. {
  2724. (void) comparator; // if you pass in an object with a static compareElements() method, this
  2725. // avoids getting warning messages about the parameter being unused
  2726. lock.enter();
  2727. insert (findInsertIndexInSortedArray (comparator, this->elements, newObject, 0, numUsed), newObject);
  2728. lock.exit();
  2729. }
  2730. /** Finds the index of an object in the array, assuming that the array is sorted.
  2731. This will use a comparator to do a binary-chop to find the index of the given
  2732. element, if it exists. If the array isn't sorted, the behaviour of this
  2733. method will be unpredictable.
  2734. @param comparator the comparator to use to compare the elements - see the sort()
  2735. method for details about the form this object should take
  2736. @param objectToLookFor the object to search for
  2737. @returns the index of the element, or -1 if it's not found
  2738. @see addSorted, sort
  2739. */
  2740. template <class ElementComparator>
  2741. int indexOfSorted (ElementComparator& comparator,
  2742. const ObjectClass* const objectToLookFor) const throw()
  2743. {
  2744. (void) comparator; // if you pass in an object with a static compareElements() method, this
  2745. // avoids getting warning messages about the parameter being unused
  2746. lock.enter();
  2747. int start = 0;
  2748. int end = numUsed;
  2749. for (;;)
  2750. {
  2751. if (start >= end)
  2752. {
  2753. lock.exit();
  2754. return -1;
  2755. }
  2756. else if (comparator.compareElements (objectToLookFor, this->elements [start]) == 0)
  2757. {
  2758. lock.exit();
  2759. return start;
  2760. }
  2761. else
  2762. {
  2763. const int halfway = (start + end) >> 1;
  2764. if (halfway == start)
  2765. {
  2766. lock.exit();
  2767. return -1;
  2768. }
  2769. else if (comparator.compareElements (objectToLookFor, this->elements [halfway]) >= 0)
  2770. start = halfway;
  2771. else
  2772. end = halfway;
  2773. }
  2774. }
  2775. }
  2776. /** Removes an object from the array.
  2777. This will remove the object at a given index (optionally also
  2778. deleting it) and move back all the subsequent objects to close the gap.
  2779. If the index passed in is out-of-range, nothing will happen.
  2780. @param indexToRemove the index of the element to remove
  2781. @param deleteObject whether to delete the object that is removed
  2782. @see removeObject, removeRange
  2783. */
  2784. void remove (const int indexToRemove,
  2785. const bool deleteObject = true)
  2786. {
  2787. lock.enter();
  2788. ObjectClass* toDelete = 0;
  2789. if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
  2790. {
  2791. ObjectClass** const e = this->elements + indexToRemove;
  2792. if (deleteObject)
  2793. toDelete = *e;
  2794. --numUsed;
  2795. const int numToShift = numUsed - indexToRemove;
  2796. if (numToShift > 0)
  2797. memmove (e, e + 1, numToShift * sizeof (ObjectClass*));
  2798. if ((numUsed << 1) < this->numAllocated)
  2799. minimiseStorageOverheads();
  2800. }
  2801. lock.exit();
  2802. delete toDelete;
  2803. }
  2804. /** Removes a specified object from the array.
  2805. If the item isn't found, no action is taken.
  2806. @param objectToRemove the object to try to remove
  2807. @param deleteObject whether to delete the object (if it's found)
  2808. @see remove, removeRange
  2809. */
  2810. void removeObject (const ObjectClass* const objectToRemove,
  2811. const bool deleteObject = true)
  2812. {
  2813. lock.enter();
  2814. ObjectClass** e = this->elements;
  2815. for (int i = numUsed; --i >= 0;)
  2816. {
  2817. if (objectToRemove == *e)
  2818. {
  2819. remove ((int) (e - this->elements), deleteObject);
  2820. break;
  2821. }
  2822. ++e;
  2823. }
  2824. lock.exit();
  2825. }
  2826. /** Removes a range of objects from the array.
  2827. This will remove a set of objects, starting from the given index,
  2828. and move any subsequent elements down to close the gap.
  2829. If the range extends beyond the bounds of the array, it will
  2830. be safely clipped to the size of the array.
  2831. @param startIndex the index of the first object to remove
  2832. @param numberToRemove how many objects should be removed
  2833. @param deleteObjects whether to delete the objects that get removed
  2834. @see remove, removeObject
  2835. */
  2836. void removeRange (int startIndex,
  2837. const int numberToRemove,
  2838. const bool deleteObjects = true)
  2839. {
  2840. lock.enter();
  2841. const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove);
  2842. startIndex = jlimit (0, numUsed, startIndex);
  2843. if (endIndex > startIndex)
  2844. {
  2845. if (deleteObjects)
  2846. {
  2847. for (int i = startIndex; i < endIndex; ++i)
  2848. {
  2849. delete this->elements [i];
  2850. this->elements [i] = 0; // (in case one of the destructors accesses this array and hits a dangling pointer)
  2851. }
  2852. }
  2853. const int rangeSize = endIndex - startIndex;
  2854. ObjectClass** e = this->elements + startIndex;
  2855. int numToShift = numUsed - endIndex;
  2856. numUsed -= rangeSize;
  2857. while (--numToShift >= 0)
  2858. {
  2859. *e = e [rangeSize];
  2860. ++e;
  2861. }
  2862. if ((numUsed << 1) < this->numAllocated)
  2863. minimiseStorageOverheads();
  2864. }
  2865. lock.exit();
  2866. }
  2867. /** Removes the last n objects from the array.
  2868. @param howManyToRemove how many objects to remove from the end of the array
  2869. @param deleteObjects whether to also delete the objects that are removed
  2870. @see remove, removeObject, removeRange
  2871. */
  2872. void removeLast (int howManyToRemove = 1,
  2873. const bool deleteObjects = true)
  2874. {
  2875. lock.enter();
  2876. if (howManyToRemove >= numUsed)
  2877. {
  2878. clear (deleteObjects);
  2879. }
  2880. else
  2881. {
  2882. while (--howManyToRemove >= 0)
  2883. remove (numUsed - 1, deleteObjects);
  2884. }
  2885. lock.exit();
  2886. }
  2887. /** Swaps a pair of objects in the array.
  2888. If either of the indexes passed in is out-of-range, nothing will happen,
  2889. otherwise the two objects at these positions will be exchanged.
  2890. */
  2891. void swap (const int index1,
  2892. const int index2) throw()
  2893. {
  2894. lock.enter();
  2895. if (((unsigned int) index1) < (unsigned int) numUsed
  2896. && ((unsigned int) index2) < (unsigned int) numUsed)
  2897. {
  2898. swapVariables (this->elements [index1],
  2899. this->elements [index2]);
  2900. }
  2901. lock.exit();
  2902. }
  2903. /** Moves one of the objects to a different position.
  2904. This will move the object to a specified index, shuffling along
  2905. any intervening elements as required.
  2906. So for example, if you have the array { 0, 1, 2, 3, 4, 5 } then calling
  2907. move (2, 4) would result in { 0, 1, 3, 4, 2, 5 }.
  2908. @param currentIndex the index of the object to be moved. If this isn't a
  2909. valid index, then nothing will be done
  2910. @param newIndex the index at which you'd like this object to end up. If this
  2911. is less than zero, it will be moved to the end of the array
  2912. */
  2913. void move (const int currentIndex,
  2914. int newIndex) throw()
  2915. {
  2916. if (currentIndex != newIndex)
  2917. {
  2918. lock.enter();
  2919. if (((unsigned int) currentIndex) < (unsigned int) numUsed)
  2920. {
  2921. if (((unsigned int) newIndex) >= (unsigned int) numUsed)
  2922. newIndex = numUsed - 1;
  2923. ObjectClass* const value = this->elements [currentIndex];
  2924. if (newIndex > currentIndex)
  2925. {
  2926. memmove (this->elements + currentIndex,
  2927. this->elements + currentIndex + 1,
  2928. (newIndex - currentIndex) * sizeof (ObjectClass*));
  2929. }
  2930. else
  2931. {
  2932. memmove (this->elements + newIndex + 1,
  2933. this->elements + newIndex,
  2934. (currentIndex - newIndex) * sizeof (ObjectClass*));
  2935. }
  2936. this->elements [newIndex] = value;
  2937. }
  2938. lock.exit();
  2939. }
  2940. }
  2941. /** This swaps the contents of this array with those of another array.
  2942. If you need to exchange two arrays, this is vastly quicker than using copy-by-value
  2943. because it just swaps their internal pointers.
  2944. */
  2945. template <class OtherArrayType>
  2946. void swapWithArray (OtherArrayType& otherArray) throw()
  2947. {
  2948. lock.enter();
  2949. otherArray.lock.enter();
  2950. swapVariables <int> (this->numUsed, otherArray.numUsed);
  2951. swapVariables <ObjectClass**> (this->elements, otherArray.elements);
  2952. swapVariables <int> (this->numAllocated, otherArray.numAllocated);
  2953. otherArray.lock.exit();
  2954. lock.exit();
  2955. }
  2956. /** Reduces the amount of storage being used by the array.
  2957. Arrays typically allocate slightly more storage than they need, and after
  2958. removing elements, they may have quite a lot of unused space allocated.
  2959. This method will reduce the amount of allocated storage to a minimum.
  2960. */
  2961. void minimiseStorageOverheads() throw()
  2962. {
  2963. lock.enter();
  2964. if (numUsed == 0)
  2965. {
  2966. this->setAllocatedSize (0);
  2967. }
  2968. else
  2969. {
  2970. const int newAllocation = this->granularity * (numUsed / this->granularity + 1);
  2971. if (newAllocation < this->numAllocated)
  2972. this->setAllocatedSize (newAllocation);
  2973. }
  2974. lock.exit();
  2975. }
  2976. /** Increases the array's internal storage to hold a minimum number of elements.
  2977. Calling this before adding a large known number of elements means that
  2978. the array won't have to keep dynamically resizing itself as the elements
  2979. are added, and it'll therefore be more efficient.
  2980. */
  2981. void ensureStorageAllocated (const int minNumElements) throw()
  2982. {
  2983. this->ensureAllocatedSize (minNumElements);
  2984. }
  2985. /** Sorts the elements in the array.
  2986. This will use a comparator object to sort the elements into order. The object
  2987. passed must have a method of the form:
  2988. @code
  2989. int compareElements (ElementType first, ElementType second);
  2990. @endcode
  2991. ..and this method must return:
  2992. - a value of < 0 if the first comes before the second
  2993. - a value of 0 if the two objects are equivalent
  2994. - a value of > 0 if the second comes before the first
  2995. To improve performance, the compareElements() method can be declared as static or const.
  2996. @param comparator the comparator to use for comparing elements.
  2997. @param retainOrderOfEquivalentItems if this is true, then items
  2998. which the comparator says are equivalent will be
  2999. kept in the order in which they currently appear
  3000. in the array. This is slower to perform, but may
  3001. be important in some cases. If it's false, a faster
  3002. algorithm is used, but equivalent elements may be
  3003. rearranged.
  3004. @see sortArray, indexOfSorted
  3005. */
  3006. template <class ElementComparator>
  3007. void sort (ElementComparator& comparator,
  3008. const bool retainOrderOfEquivalentItems = false) const throw()
  3009. {
  3010. (void) comparator; // if you pass in an object with a static compareElements() method, this
  3011. // avoids getting warning messages about the parameter being unused
  3012. lock.enter();
  3013. sortArray (comparator, this->elements, 0, size() - 1, retainOrderOfEquivalentItems);
  3014. lock.exit();
  3015. }
  3016. /** Locks the array's CriticalSection.
  3017. Of course if the type of section used is a DummyCriticalSection, this won't
  3018. have any effect.
  3019. @see unlockArray
  3020. */
  3021. void lockArray() const throw()
  3022. {
  3023. lock.enter();
  3024. }
  3025. /** Unlocks the array's CriticalSection.
  3026. Of course if the type of section used is a DummyCriticalSection, this won't
  3027. have any effect.
  3028. @see lockArray
  3029. */
  3030. void unlockArray() const throw()
  3031. {
  3032. lock.exit();
  3033. }
  3034. juce_UseDebuggingNewOperator
  3035. private:
  3036. int numUsed;
  3037. TypeOfCriticalSectionToUse lock;
  3038. // disallow copy constructor and assignment
  3039. OwnedArray (const OwnedArray&);
  3040. const OwnedArray& operator= (const OwnedArray&);
  3041. };
  3042. #endif // __JUCE_OWNEDARRAY_JUCEHEADER__
  3043. /********* End of inlined file: juce_OwnedArray.h *********/
  3044. /********* Start of inlined file: juce_Time.h *********/
  3045. #ifndef __JUCE_TIME_JUCEHEADER__
  3046. #define __JUCE_TIME_JUCEHEADER__
  3047. /********* Start of inlined file: juce_RelativeTime.h *********/
  3048. #ifndef __JUCE_RELATIVETIME_JUCEHEADER__
  3049. #define __JUCE_RELATIVETIME_JUCEHEADER__
  3050. /** A relative measure of time.
  3051. The time is stored as a number of seconds, at double-precision floating
  3052. point accuracy, and may be positive or negative.
  3053. If you need an absolute time, (i.e. a date + time), see the Time class.
  3054. */
  3055. class JUCE_API RelativeTime
  3056. {
  3057. public:
  3058. /** Creates a RelativeTime.
  3059. @param seconds the number of seconds, which may be +ve or -ve.
  3060. @see milliseconds, minutes, hours, days, weeks
  3061. */
  3062. explicit RelativeTime (const double seconds = 0.0) throw();
  3063. /** Copies another relative time. */
  3064. RelativeTime (const RelativeTime& other) throw();
  3065. /** Copies another relative time. */
  3066. const RelativeTime& operator= (const RelativeTime& other) throw();
  3067. /** Destructor. */
  3068. ~RelativeTime() throw();
  3069. /** Creates a new RelativeTime object representing a number of milliseconds.
  3070. @see minutes, hours, days, weeks
  3071. */
  3072. static const RelativeTime milliseconds (const int milliseconds) throw();
  3073. /** Creates a new RelativeTime object representing a number of milliseconds.
  3074. @see minutes, hours, days, weeks
  3075. */
  3076. static const RelativeTime milliseconds (const int64 milliseconds) throw();
  3077. /** Creates a new RelativeTime object representing a number of minutes.
  3078. @see milliseconds, hours, days, weeks
  3079. */
  3080. static const RelativeTime minutes (const double numberOfMinutes) throw();
  3081. /** Creates a new RelativeTime object representing a number of hours.
  3082. @see milliseconds, minutes, days, weeks
  3083. */
  3084. static const RelativeTime hours (const double numberOfHours) throw();
  3085. /** Creates a new RelativeTime object representing a number of days.
  3086. @see milliseconds, minutes, hours, weeks
  3087. */
  3088. static const RelativeTime days (const double numberOfDays) throw();
  3089. /** Creates a new RelativeTime object representing a number of weeks.
  3090. @see milliseconds, minutes, hours, days
  3091. */
  3092. static const RelativeTime weeks (const double numberOfWeeks) throw();
  3093. /** Returns the number of milliseconds this time represents.
  3094. @see milliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  3095. */
  3096. int64 inMilliseconds() const throw();
  3097. /** Returns the number of seconds this time represents.
  3098. @see inMilliseconds, inMinutes, inHours, inDays, inWeeks
  3099. */
  3100. double inSeconds() const throw() { return seconds; }
  3101. /** Returns the number of minutes this time represents.
  3102. @see inMilliseconds, inSeconds, inHours, inDays, inWeeks
  3103. */
  3104. double inMinutes() const throw();
  3105. /** Returns the number of hours this time represents.
  3106. @see inMilliseconds, inSeconds, inMinutes, inDays, inWeeks
  3107. */
  3108. double inHours() const throw();
  3109. /** Returns the number of days this time represents.
  3110. @see inMilliseconds, inSeconds, inMinutes, inHours, inWeeks
  3111. */
  3112. double inDays() const throw();
  3113. /** Returns the number of weeks this time represents.
  3114. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays
  3115. */
  3116. double inWeeks() const throw();
  3117. /** Returns a readable textual description of the time.
  3118. The exact format of the string returned will depend on
  3119. the magnitude of the time - e.g.
  3120. "1 min 4 secs", "1 hr 45 mins", "2 weeks 5 days", "140 ms"
  3121. so that only the two most significant units are printed.
  3122. The returnValueForZeroTime value is the result that is returned if the
  3123. length is zero. Depending on your application you might want to use this
  3124. to return something more relevant like "empty" or "0 secs", etc.
  3125. @see inMilliseconds, inSeconds, inMinutes, inHours, inDays, inWeeks
  3126. */
  3127. const String getDescription (const String& returnValueForZeroTime = JUCE_T("0")) const throw();
  3128. /** Compares two RelativeTimes. */
  3129. bool operator== (const RelativeTime& other) const throw();
  3130. /** Compares two RelativeTimes. */
  3131. bool operator!= (const RelativeTime& other) const throw();
  3132. /** Compares two RelativeTimes. */
  3133. bool operator> (const RelativeTime& other) const throw();
  3134. /** Compares two RelativeTimes. */
  3135. bool operator< (const RelativeTime& other) const throw();
  3136. /** Compares two RelativeTimes. */
  3137. bool operator>= (const RelativeTime& other) const throw();
  3138. /** Compares two RelativeTimes. */
  3139. bool operator<= (const RelativeTime& other) const throw();
  3140. /** Adds another RelativeTime to this one and returns the result. */
  3141. const RelativeTime operator+ (const RelativeTime& timeToAdd) const throw();
  3142. /** Subtracts another RelativeTime from this one and returns the result. */
  3143. const RelativeTime operator- (const RelativeTime& timeToSubtract) const throw();
  3144. /** Adds a number of seconds to this RelativeTime and returns the result. */
  3145. const RelativeTime operator+ (const double secondsToAdd) const throw();
  3146. /** Subtracts a number of seconds from this RelativeTime and returns the result. */
  3147. const RelativeTime operator- (const double secondsToSubtract) const throw();
  3148. /** Adds another RelativeTime to this one. */
  3149. const RelativeTime& operator+= (const RelativeTime& timeToAdd) throw();
  3150. /** Subtracts another RelativeTime from this one. */
  3151. const RelativeTime& operator-= (const RelativeTime& timeToSubtract) throw();
  3152. /** Adds a number of seconds to this time. */
  3153. const RelativeTime& operator+= (const double secondsToAdd) throw();
  3154. /** Subtracts a number of seconds from this time. */
  3155. const RelativeTime& operator-= (const double secondsToSubtract) throw();
  3156. juce_UseDebuggingNewOperator
  3157. private:
  3158. double seconds;
  3159. };
  3160. #endif // __JUCE_RELATIVETIME_JUCEHEADER__
  3161. /********* End of inlined file: juce_RelativeTime.h *********/
  3162. /**
  3163. Holds an absolute date and time.
  3164. Internally, the time is stored at millisecond precision.
  3165. @see RelativeTime
  3166. */
  3167. class JUCE_API Time
  3168. {
  3169. public:
  3170. /** Creates a Time object.
  3171. This default constructor creates a time of 1st January 1970, (which is
  3172. represented internally as 0ms).
  3173. To create a time object representing the current time, use getCurrentTime().
  3174. @see getCurrentTime
  3175. */
  3176. Time() throw();
  3177. /** Creates a copy of another Time object. */
  3178. Time (const Time& other) throw();
  3179. /** Creates a time based on a number of milliseconds.
  3180. The internal millisecond count is set to 0 (1st January 1970). To create a
  3181. time object set to the current time, use getCurrentTime().
  3182. @param millisecondsSinceEpoch the number of milliseconds since the unix
  3183. 'epoch' (midnight Jan 1st 1970).
  3184. @see getCurrentTime, currentTimeMillis
  3185. */
  3186. Time (const int64 millisecondsSinceEpoch) throw();
  3187. /** Creates a time from a set of date components.
  3188. The timezone is assumed to be whatever the system is using as its locale.
  3189. @param year the year, in 4-digit format, e.g. 2004
  3190. @param month the month, in the range 0 to 11
  3191. @param day the day of the month, in the range 1 to 31
  3192. @param hours hours in 24-hour clock format, 0 to 23
  3193. @param minutes minutes 0 to 59
  3194. @param seconds seconds 0 to 59
  3195. @param milliseconds milliseconds 0 to 999
  3196. @param useLocalTime if true, encode using the current machine's local time; if
  3197. false, it will always work in GMT.
  3198. */
  3199. Time (const int year,
  3200. const int month,
  3201. const int day,
  3202. const int hours,
  3203. const int minutes,
  3204. const int seconds = 0,
  3205. const int milliseconds = 0,
  3206. const bool useLocalTime = true) throw();
  3207. /** Destructor. */
  3208. ~Time() throw();
  3209. /** Copies this time from another one. */
  3210. const Time& operator= (const Time& other) throw();
  3211. /** Returns a Time object that is set to the current system time.
  3212. @see currentTimeMillis
  3213. */
  3214. static const Time JUCE_CALLTYPE getCurrentTime() throw();
  3215. /** Returns the time as a number of milliseconds.
  3216. @returns the number of milliseconds this Time object represents, since
  3217. midnight jan 1st 1970.
  3218. @see getMilliseconds
  3219. */
  3220. int64 toMilliseconds() const throw() { return millisSinceEpoch; }
  3221. /** Returns the year.
  3222. A 4-digit format is used, e.g. 2004.
  3223. */
  3224. int getYear() const throw();
  3225. /** Returns the number of the month.
  3226. The value returned is in the range 0 to 11.
  3227. @see getMonthName
  3228. */
  3229. int getMonth() const throw();
  3230. /** Returns the name of the month.
  3231. @param threeLetterVersion if true, it'll be a 3-letter abbreviation, e.g. "Jan"; if false
  3232. it'll return the long form, e.g. "January"
  3233. @see getMonth
  3234. */
  3235. const String getMonthName (const bool threeLetterVersion) const throw();
  3236. /** Returns the day of the month.
  3237. The value returned is in the range 1 to 31.
  3238. */
  3239. int getDayOfMonth() const throw();
  3240. /** Returns the number of the day of the week.
  3241. The value returned is in the range 0 to 6 (0 = sunday, 1 = monday, etc).
  3242. */
  3243. int getDayOfWeek() const throw();
  3244. /** Returns the name of the weekday.
  3245. @param threeLetterVersion if true, it'll return a 3-letter abbreviation, e.g. "Tue"; if
  3246. false, it'll return the full version, e.g. "Tuesday".
  3247. */
  3248. const String getWeekdayName (const bool threeLetterVersion) const throw();
  3249. /** Returns the number of hours since midnight.
  3250. This is in 24-hour clock format, in the range 0 to 23.
  3251. @see getHoursInAmPmFormat, isAfternoon
  3252. */
  3253. int getHours() const throw();
  3254. /** Returns true if the time is in the afternoon.
  3255. So it returns true for "PM", false for "AM".
  3256. @see getHoursInAmPmFormat, getHours
  3257. */
  3258. bool isAfternoon() const throw();
  3259. /** Returns the hours in 12-hour clock format.
  3260. This will return a value 1 to 12 - use isAfternoon() to find out
  3261. whether this is in the afternoon or morning.
  3262. @see getHours, isAfternoon
  3263. */
  3264. int getHoursInAmPmFormat() const throw();
  3265. /** Returns the number of minutes, 0 to 59. */
  3266. int getMinutes() const throw();
  3267. /** Returns the number of seconds, 0 to 59. */
  3268. int getSeconds() const throw();
  3269. /** Returns the number of milliseconds, 0 to 999.
  3270. Unlike toMilliseconds(), this just returns the position within the
  3271. current second rather than the total number since the epoch.
  3272. @see toMilliseconds
  3273. */
  3274. int getMilliseconds() const throw();
  3275. /** Returns true if the local timezone uses a daylight saving correction. */
  3276. bool isDaylightSavingTime() const throw();
  3277. /** Returns a 3-character string to indicate the local timezone. */
  3278. const String getTimeZone() const throw();
  3279. /** Quick way of getting a string version of a date and time.
  3280. For a more powerful way of formatting the date and time, see the formatted() method.
  3281. @param includeDate whether to include the date in the string
  3282. @param includeTime whether to include the time in the string
  3283. @param includeSeconds if the time is being included, this provides an option not to include
  3284. the seconds in it
  3285. @param use24HourClock if the time is being included, sets whether to use am/pm or 24
  3286. hour notation.
  3287. @see formatted
  3288. */
  3289. const String toString (const bool includeDate,
  3290. const bool includeTime,
  3291. const bool includeSeconds = true,
  3292. const bool use24HourClock = false) const throw();
  3293. /** Converts this date/time to a string with a user-defined format.
  3294. This uses the C strftime() function to format this time as a string. To save you
  3295. looking it up, these are the escape codes that strftime uses (other codes might
  3296. work on some platforms and not others, but these are the common ones):
  3297. %a is replaced by the locale's abbreviated weekday name.
  3298. %A is replaced by the locale's full weekday name.
  3299. %b is replaced by the locale's abbreviated month name.
  3300. %B is replaced by the locale's full month name.
  3301. %c is replaced by the locale's appropriate date and time representation.
  3302. %d is replaced by the day of the month as a decimal number [01,31].
  3303. %H is replaced by the hour (24-hour clock) as a decimal number [00,23].
  3304. %I is replaced by the hour (12-hour clock) as a decimal number [01,12].
  3305. %j is replaced by the day of the year as a decimal number [001,366].
  3306. %m is replaced by the month as a decimal number [01,12].
  3307. %M is replaced by the minute as a decimal number [00,59].
  3308. %p is replaced by the locale's equivalent of either a.m. or p.m.
  3309. %S is replaced by the second as a decimal number [00,61].
  3310. %U is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
  3311. %w is replaced by the weekday as a decimal number [0,6], with 0 representing Sunday.
  3312. %W is replaced by the week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.
  3313. %x is replaced by the locale's appropriate date representation.
  3314. %X is replaced by the locale's appropriate time representation.
  3315. %y is replaced by the year without century as a decimal number [00,99].
  3316. %Y is replaced by the year with century as a decimal number.
  3317. %Z is replaced by the timezone name or abbreviation, or by no bytes if no timezone information exists.
  3318. %% is replaced by %.
  3319. @see toString
  3320. */
  3321. const String formatted (const tchar* const format) const throw();
  3322. /** Adds a RelativeTime to this time and returns the result. */
  3323. const Time operator+ (const RelativeTime& delta) const throw() { return Time (millisSinceEpoch + delta.inMilliseconds()); }
  3324. /** Subtracts a RelativeTime from this time and returns the result. */
  3325. const Time operator- (const RelativeTime& delta) const throw() { return Time (millisSinceEpoch - delta.inMilliseconds()); }
  3326. /** Returns the relative time difference between this time and another one. */
  3327. const RelativeTime operator- (const Time& other) const throw() { return RelativeTime::milliseconds (millisSinceEpoch - other.millisSinceEpoch); }
  3328. /** Compares two Time objects. */
  3329. bool operator== (const Time& other) const throw() { return millisSinceEpoch == other.millisSinceEpoch; }
  3330. /** Compares two Time objects. */
  3331. bool operator!= (const Time& other) const throw() { return millisSinceEpoch != other.millisSinceEpoch; }
  3332. /** Compares two Time objects. */
  3333. bool operator< (const Time& other) const throw() { return millisSinceEpoch < other.millisSinceEpoch; }
  3334. /** Compares two Time objects. */
  3335. bool operator<= (const Time& other) const throw() { return millisSinceEpoch <= other.millisSinceEpoch; }
  3336. /** Compares two Time objects. */
  3337. bool operator> (const Time& other) const throw() { return millisSinceEpoch > other.millisSinceEpoch; }
  3338. /** Compares two Time objects. */
  3339. bool operator>= (const Time& other) const throw() { return millisSinceEpoch >= other.millisSinceEpoch; }
  3340. /** Tries to set the computer's clock.
  3341. @returns true if this succeeds, although depending on the system, the
  3342. application might not have sufficient privileges to do this.
  3343. */
  3344. bool setSystemTimeToThisTime() const throw();
  3345. /** Returns the name of a day of the week.
  3346. @param dayNumber the day, 0 to 6 (0 = sunday, 1 = monday, etc)
  3347. @param threeLetterVersion if true, it'll return a 3-letter abbreviation, e.g. "Tue"; if
  3348. false, it'll return the full version, e.g. "Tuesday".
  3349. */
  3350. static const String getWeekdayName (int dayNumber,
  3351. const bool threeLetterVersion) throw();
  3352. /** Returns the name of one of the months.
  3353. @param monthNumber the month, 0 to 11
  3354. @param threeLetterVersion if true, it'll be a 3-letter abbreviation, e.g. "Jan"; if false
  3355. it'll return the long form, e.g. "January"
  3356. */
  3357. static const String getMonthName (int monthNumber,
  3358. const bool threeLetterVersion) throw();
  3359. // Static methods for getting system timers directly..
  3360. /** Returns the current system time.
  3361. Returns the number of milliseconds since midnight jan 1st 1970.
  3362. Should be accurate to within a few millisecs, depending on platform,
  3363. hardware, etc.
  3364. */
  3365. static int64 currentTimeMillis() throw();
  3366. /** Returns the number of millisecs since system startup.
  3367. Should be accurate to within a few millisecs, depending on platform,
  3368. hardware, etc.
  3369. @see getApproximateMillisecondCounter
  3370. */
  3371. static uint32 getMillisecondCounter() throw();
  3372. /** Returns the number of millisecs since system startup.
  3373. Same as getMillisecondCounter(), but returns a more accurate value, using
  3374. the high-res timer.
  3375. @see getMillisecondCounter
  3376. */
  3377. static double getMillisecondCounterHiRes() throw();
  3378. /** Waits until the getMillisecondCounter() reaches a given value.
  3379. This will make the thread sleep as efficiently as it can while it's waiting.
  3380. */
  3381. static void waitForMillisecondCounter (const uint32 targetTime) throw();
  3382. /** Less-accurate but faster version of getMillisecondCounter().
  3383. This will return the last value that getMillisecondCounter() returned, so doesn't
  3384. need to make a system call, but is less accurate - it shouldn't be more than
  3385. 100ms away from the correct time, though, so is still accurate enough for a
  3386. lot of purposes.
  3387. @see getMillisecondCounter
  3388. */
  3389. static uint32 getApproximateMillisecondCounter() throw();
  3390. // High-resolution timers..
  3391. /** Returns the current high-resolution counter's tick-count.
  3392. This is a similar idea to getMillisecondCounter(), but with a higher
  3393. resolution.
  3394. @see getHighResolutionTicksPerSecond, highResolutionTicksToSeconds,
  3395. secondsToHighResolutionTicks
  3396. */
  3397. static int64 getHighResolutionTicks() throw();
  3398. /** Returns the resolution of the high-resolution counter in ticks per second.
  3399. @see getHighResolutionTicks, highResolutionTicksToSeconds,
  3400. secondsToHighResolutionTicks
  3401. */
  3402. static int64 getHighResolutionTicksPerSecond() throw();
  3403. /** Converts a number of high-resolution ticks into seconds.
  3404. @see getHighResolutionTicks, getHighResolutionTicksPerSecond,
  3405. secondsToHighResolutionTicks
  3406. */
  3407. static double highResolutionTicksToSeconds (const int64 ticks) throw();
  3408. /** Converts a number seconds into high-resolution ticks.
  3409. @see getHighResolutionTicks, getHighResolutionTicksPerSecond,
  3410. highResolutionTicksToSeconds
  3411. */
  3412. static int64 secondsToHighResolutionTicks (const double seconds) throw();
  3413. private:
  3414. int64 millisSinceEpoch;
  3415. };
  3416. #endif // __JUCE_TIME_JUCEHEADER__
  3417. /********* End of inlined file: juce_Time.h *********/
  3418. /********* Start of inlined file: juce_StringArray.h *********/
  3419. #ifndef __JUCE_STRINGARRAY_JUCEHEADER__
  3420. #define __JUCE_STRINGARRAY_JUCEHEADER__
  3421. /********* Start of inlined file: juce_VoidArray.h *********/
  3422. #ifndef __JUCE_VOIDARRAY_JUCEHEADER__
  3423. #define __JUCE_VOIDARRAY_JUCEHEADER__
  3424. /********* Start of inlined file: juce_Array.h *********/
  3425. #ifndef __JUCE_ARRAY_JUCEHEADER__
  3426. #define __JUCE_ARRAY_JUCEHEADER__
  3427. /**
  3428. Holds a list of primitive objects, such as ints, doubles, or pointers.
  3429. Examples of arrays are: Array<int> or Array<MyClass*>
  3430. Note that when holding pointers to objects, the array doesn't take any ownership
  3431. of the objects - for doing this, see the OwnedArray class or the ReferenceCountedArray class.
  3432. If you're using a class or struct as the element type, it must be
  3433. capable of being copied or moved with a straightforward memcpy, rather than
  3434. needing construction and destruction code.
  3435. For holding lists of strings, use the specialised class StringArray.
  3436. To make all the array's methods thread-safe, pass in "CriticalSection" as the templated
  3437. TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.
  3438. @see OwnedArray, ReferenceCountedArray, StringArray, CriticalSection
  3439. */
  3440. template <class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
  3441. class Array : private ArrayAllocationBase <ElementType>
  3442. {
  3443. public:
  3444. /** Creates an empty array.
  3445. @param granularity this is the size of increment by which the internal storage
  3446. used by the array will grow. Only change it from the default if you know the
  3447. array is going to be very big and needs to be able to grow efficiently.
  3448. @see ArrayAllocationBase
  3449. */
  3450. Array (const int granularity = juceDefaultArrayGranularity) throw()
  3451. : ArrayAllocationBase <ElementType> (granularity),
  3452. numUsed (0)
  3453. {
  3454. }
  3455. /** Creates a copy of another array.
  3456. @param other the array to copy
  3457. */
  3458. Array (const Array<ElementType, TypeOfCriticalSectionToUse>& other) throw()
  3459. : ArrayAllocationBase <ElementType> (other.granularity)
  3460. {
  3461. other.lockArray();
  3462. numUsed = other.numUsed;
  3463. this->setAllocatedSize (other.numUsed);
  3464. memcpy (this->elements, other.elements, numUsed * sizeof (ElementType));
  3465. other.unlockArray();
  3466. }
  3467. /** Initalises from a null-terminated C array of values.
  3468. @param values the array to copy from
  3469. */
  3470. Array (const ElementType* values) throw()
  3471. : ArrayAllocationBase <ElementType> (juceDefaultArrayGranularity),
  3472. numUsed (0)
  3473. {
  3474. while (*values != 0)
  3475. add (*values++);
  3476. }
  3477. /** Initalises from a C array of values.
  3478. @param values the array to copy from
  3479. @param numValues the number of values in the array
  3480. */
  3481. Array (const ElementType* values, int numValues) throw()
  3482. : ArrayAllocationBase <ElementType> (juceDefaultArrayGranularity),
  3483. numUsed (numValues)
  3484. {
  3485. this->setAllocatedSize (numValues);
  3486. memcpy (this->elements, values, numValues * sizeof (ElementType));
  3487. }
  3488. /** Destructor. */
  3489. ~Array() throw()
  3490. {
  3491. }
  3492. /** Copies another array.
  3493. @param other the array to copy
  3494. */
  3495. const Array <ElementType, TypeOfCriticalSectionToUse>& operator= (const Array <ElementType, TypeOfCriticalSectionToUse>& other) throw()
  3496. {
  3497. if (this != &other)
  3498. {
  3499. other.lockArray();
  3500. lock.enter();
  3501. this->granularity = other.granularity;
  3502. this->ensureAllocatedSize (other.size());
  3503. numUsed = other.numUsed;
  3504. memcpy (this->elements, other.elements, this->numUsed * sizeof (ElementType));
  3505. minimiseStorageOverheads();
  3506. lock.exit();
  3507. other.unlockArray();
  3508. }
  3509. return *this;
  3510. }
  3511. /** Compares this array to another one.
  3512. Two arrays are considered equal if they both contain the same set of
  3513. elements, in the same order.
  3514. @param other the other array to compare with
  3515. */
  3516. template <class OtherArrayType>
  3517. bool operator== (const OtherArrayType& other) const throw()
  3518. {
  3519. lock.enter();
  3520. if (this->numUsed != other.numUsed)
  3521. {
  3522. lock.exit();
  3523. return false;
  3524. }
  3525. for (int i = numUsed; --i >= 0;)
  3526. {
  3527. if (this->elements [i] != other.elements [i])
  3528. {
  3529. lock.exit();
  3530. return false;
  3531. }
  3532. }
  3533. lock.exit();
  3534. return true;
  3535. }
  3536. /** Compares this array to another one.
  3537. Two arrays are considered equal if they both contain the same set of
  3538. elements, in the same order.
  3539. @param other the other array to compare with
  3540. */
  3541. template <class OtherArrayType>
  3542. bool operator!= (const OtherArrayType& other) const throw()
  3543. {
  3544. return ! operator== (other);
  3545. }
  3546. /** Removes all elements from the array.
  3547. This will remove all the elements, and free any storage that the array is
  3548. using. To clear the array without freeing the storage, use the clearQuick()
  3549. method instead.
  3550. @see clearQuick
  3551. */
  3552. void clear() throw()
  3553. {
  3554. lock.enter();
  3555. this->setAllocatedSize (0);
  3556. numUsed = 0;
  3557. lock.exit();
  3558. }
  3559. /** Removes all elements from the array without freeing the array's allocated storage.
  3560. @see clear
  3561. */
  3562. void clearQuick() throw()
  3563. {
  3564. lock.enter();
  3565. numUsed = 0;
  3566. lock.exit();
  3567. }
  3568. /** Returns the current number of elements in the array.
  3569. */
  3570. inline int size() const throw()
  3571. {
  3572. return numUsed;
  3573. }
  3574. /** Returns one of the elements in the array.
  3575. If the index passed in is beyond the range of valid elements, this
  3576. will return zero.
  3577. If you're certain that the index will always be a valid element, you
  3578. can call getUnchecked() instead, which is faster.
  3579. @param index the index of the element being requested (0 is the first element in the array)
  3580. @see getUnchecked, getFirst, getLast
  3581. */
  3582. inline ElementType operator[] (const int index) const throw()
  3583. {
  3584. lock.enter();
  3585. const ElementType result = (((unsigned int) index) < (unsigned int) numUsed)
  3586. ? this->elements [index]
  3587. : ElementType();
  3588. lock.exit();
  3589. return result;
  3590. }
  3591. /** Returns one of the elements in the array, without checking the index passed in.
  3592. Unlike the operator[] method, this will try to return an element without
  3593. checking that the index is within the bounds of the array, so should only
  3594. be used when you're confident that it will always be a valid index.
  3595. @param index the index of the element being requested (0 is the first element in the array)
  3596. @see operator[], getFirst, getLast
  3597. */
  3598. inline ElementType getUnchecked (const int index) const throw()
  3599. {
  3600. lock.enter();
  3601. jassert (((unsigned int) index) < (unsigned int) numUsed);
  3602. const ElementType result = this->elements [index];
  3603. lock.exit();
  3604. return result;
  3605. }
  3606. /** Returns a direct reference to one of the elements in the array, without checking the index passed in.
  3607. This is like getUnchecked, but returns a direct reference to the element, so that
  3608. you can alter it directly. Obviously this can be dangerous, so only use it when
  3609. absolutely necessary.
  3610. @param index the index of the element being requested (0 is the first element in the array)
  3611. @see operator[], getFirst, getLast
  3612. */
  3613. inline ElementType& getReference (const int index) const throw()
  3614. {
  3615. lock.enter();
  3616. jassert (((unsigned int) index) < (unsigned int) numUsed);
  3617. ElementType& result = this->elements [index];
  3618. lock.exit();
  3619. return result;
  3620. }
  3621. /** Returns the first element in the array, or 0 if the array is empty.
  3622. @see operator[], getUnchecked, getLast
  3623. */
  3624. inline ElementType getFirst() const throw()
  3625. {
  3626. lock.enter();
  3627. const ElementType result = (numUsed > 0) ? this->elements [0]
  3628. : ElementType();
  3629. lock.exit();
  3630. return result;
  3631. }
  3632. /** Returns the last element in the array, or 0 if the array is empty.
  3633. @see operator[], getUnchecked, getFirst
  3634. */
  3635. inline ElementType getLast() const throw()
  3636. {
  3637. lock.enter();
  3638. const ElementType result = (numUsed > 0) ? this->elements [numUsed - 1]
  3639. : ElementType();
  3640. lock.exit();
  3641. return result;
  3642. }
  3643. /** Finds the index of the first element which matches the value passed in.
  3644. This will search the array for the given object, and return the index
  3645. of its first occurrence. If the object isn't found, the method will return -1.
  3646. @param elementToLookFor the value or object to look for
  3647. @returns the index of the object, or -1 if it's not found
  3648. */
  3649. int indexOf (const ElementType elementToLookFor) const throw()
  3650. {
  3651. int result = -1;
  3652. lock.enter();
  3653. const ElementType* e = this->elements;
  3654. for (int i = numUsed; --i >= 0;)
  3655. {
  3656. if (elementToLookFor == *e)
  3657. {
  3658. result = (int) (e - this->elements);
  3659. break;
  3660. }
  3661. ++e;
  3662. }
  3663. lock.exit();
  3664. return result;
  3665. }
  3666. /** Returns true if the array contains at least one occurrence of an object.
  3667. @param elementToLookFor the value or object to look for
  3668. @returns true if the item is found
  3669. */
  3670. bool contains (const ElementType elementToLookFor) const throw()
  3671. {
  3672. lock.enter();
  3673. const ElementType* e = this->elements;
  3674. int num = numUsed;
  3675. while (num >= 4)
  3676. {
  3677. if (*e == elementToLookFor
  3678. || *++e == elementToLookFor
  3679. || *++e == elementToLookFor
  3680. || *++e == elementToLookFor)
  3681. {
  3682. lock.exit();
  3683. return true;
  3684. }
  3685. num -= 4;
  3686. ++e;
  3687. }
  3688. while (num > 0)
  3689. {
  3690. if (elementToLookFor == *e)
  3691. {
  3692. lock.exit();
  3693. return true;
  3694. }
  3695. --num;
  3696. ++e;
  3697. }
  3698. lock.exit();
  3699. return false;
  3700. }
  3701. /** Appends a new element at the end of the array.
  3702. @param newElement the new object to add to the array
  3703. @see set, insert, addIfNotAlreadyThere, addSorted, addArray
  3704. */
  3705. void add (const ElementType newElement) throw()
  3706. {
  3707. lock.enter();
  3708. this->ensureAllocatedSize (numUsed + 1);
  3709. this->elements [numUsed++] = newElement;
  3710. lock.exit();
  3711. }
  3712. /** Inserts a new element into the array at a given position.
  3713. If the index is less than 0 or greater than the size of the array, the
  3714. element will be added to the end of the array.
  3715. Otherwise, it will be inserted into the array, moving all the later elements
  3716. along to make room.
  3717. @param indexToInsertAt the index at which the new element should be
  3718. inserted (pass in -1 to add it to the end)
  3719. @param newElement the new object to add to the array
  3720. @see add, addSorted, set
  3721. */
  3722. void insert (int indexToInsertAt, const ElementType newElement) throw()
  3723. {
  3724. lock.enter();
  3725. this->ensureAllocatedSize (numUsed + 1);
  3726. if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed)
  3727. {
  3728. ElementType* const insertPos = this->elements + indexToInsertAt;
  3729. const int numberToMove = numUsed - indexToInsertAt;
  3730. if (numberToMove > 0)
  3731. memmove (insertPos + 1, insertPos, numberToMove * sizeof (ElementType));
  3732. *insertPos = newElement;
  3733. ++numUsed;
  3734. }
  3735. else
  3736. {
  3737. this->elements [numUsed++] = newElement;
  3738. }
  3739. lock.exit();
  3740. }
  3741. /** Inserts multiple copies of an element into the array at a given position.
  3742. If the index is less than 0 or greater than the size of the array, the
  3743. element will be added to the end of the array.
  3744. Otherwise, it will be inserted into the array, moving all the later elements
  3745. along to make room.
  3746. @param indexToInsertAt the index at which the new element should be inserted
  3747. @param newElement the new object to add to the array
  3748. @param numberOfTimesToInsertIt how many copies of the value to insert
  3749. @see insert, add, addSorted, set
  3750. */
  3751. void insertMultiple (int indexToInsertAt, const ElementType newElement,
  3752. int numberOfTimesToInsertIt) throw()
  3753. {
  3754. if (numberOfTimesToInsertIt > 0)
  3755. {
  3756. lock.enter();
  3757. this->ensureAllocatedSize (numUsed + numberOfTimesToInsertIt);
  3758. if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed)
  3759. {
  3760. ElementType* insertPos = this->elements + indexToInsertAt;
  3761. const int numberToMove = numUsed - indexToInsertAt;
  3762. memmove (insertPos + numberOfTimesToInsertIt, insertPos, numberToMove * sizeof (ElementType));
  3763. numUsed += numberOfTimesToInsertIt;
  3764. while (--numberOfTimesToInsertIt >= 0)
  3765. *insertPos++ = newElement;
  3766. }
  3767. else
  3768. {
  3769. while (--numberOfTimesToInsertIt >= 0)
  3770. this->elements [numUsed++] = newElement;
  3771. }
  3772. lock.exit();
  3773. }
  3774. }
  3775. /** Inserts an array of values into this array at a given position.
  3776. If the index is less than 0 or greater than the size of the array, the
  3777. new elements will be added to the end of the array.
  3778. Otherwise, they will be inserted into the array, moving all the later elements
  3779. along to make room.
  3780. @param indexToInsertAt the index at which the first new element should be inserted
  3781. @param newElements the new values to add to the array
  3782. @param numberOfElements how many items are in the array
  3783. @see insert, add, addSorted, set
  3784. */
  3785. void insertArray (int indexToInsertAt,
  3786. const ElementType* newElements,
  3787. int numberOfElements) throw()
  3788. {
  3789. if (numberOfElements > 0)
  3790. {
  3791. lock.enter();
  3792. this->ensureAllocatedSize (numUsed + numberOfElements);
  3793. if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed)
  3794. {
  3795. ElementType* insertPos = this->elements + indexToInsertAt;
  3796. const int numberToMove = numUsed - indexToInsertAt;
  3797. memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ElementType));
  3798. numUsed += numberOfElements;
  3799. while (--numberOfElements >= 0)
  3800. *insertPos++ = *newElements++;
  3801. }
  3802. else
  3803. {
  3804. while (--numberOfElements >= 0)
  3805. this->elements [numUsed++] = *newElements++;
  3806. }
  3807. lock.exit();
  3808. }
  3809. }
  3810. /** Appends a new element at the end of the array as long as the array doesn't
  3811. already contain it.
  3812. If the array already contains an element that matches the one passed in, nothing
  3813. will be done.
  3814. @param newElement the new object to add to the array
  3815. */
  3816. void addIfNotAlreadyThere (const ElementType newElement) throw()
  3817. {
  3818. lock.enter();
  3819. if (! contains (newElement))
  3820. add (newElement);
  3821. lock.exit();
  3822. }
  3823. /** Replaces an element with a new value.
  3824. If the index is less than zero, this method does nothing.
  3825. If the index is beyond the end of the array, the item is added to the end of the array.
  3826. @param indexToChange the index whose value you want to change
  3827. @param newValue the new value to set for this index.
  3828. @see add, insert
  3829. */
  3830. void set (const int indexToChange,
  3831. const ElementType newValue) throw()
  3832. {
  3833. jassert (indexToChange >= 0);
  3834. if (indexToChange >= 0)
  3835. {
  3836. lock.enter();
  3837. if (indexToChange < numUsed)
  3838. {
  3839. this->elements [indexToChange] = newValue;
  3840. }
  3841. else
  3842. {
  3843. this->ensureAllocatedSize (numUsed + 1);
  3844. this->elements [numUsed++] = newValue;
  3845. }
  3846. lock.exit();
  3847. }
  3848. }
  3849. /** Replaces an element with a new value without doing any bounds-checking.
  3850. This just sets a value directly in the array's internal storage, so you'd
  3851. better make sure it's in range!
  3852. @param indexToChange the index whose value you want to change
  3853. @param newValue the new value to set for this index.
  3854. @see set, getUnchecked
  3855. */
  3856. void setUnchecked (const int indexToChange,
  3857. const ElementType newValue) throw()
  3858. {
  3859. lock.enter();
  3860. jassert (((unsigned int) indexToChange) < (unsigned int) numUsed);
  3861. this->elements [indexToChange] = newValue;
  3862. lock.exit();
  3863. }
  3864. /** Adds elements from an array to the end of this array.
  3865. @param elementsToAdd the array of elements to add
  3866. @param numElementsToAdd how many elements are in this other array
  3867. @see add
  3868. */
  3869. void addArray (const ElementType* elementsToAdd,
  3870. int numElementsToAdd) throw()
  3871. {
  3872. lock.enter();
  3873. if (numElementsToAdd > 0)
  3874. {
  3875. this->ensureAllocatedSize (numUsed + numElementsToAdd);
  3876. while (--numElementsToAdd >= 0)
  3877. this->elements [numUsed++] = *elementsToAdd++;
  3878. }
  3879. lock.exit();
  3880. }
  3881. /** This swaps the contents of this array with those of another array.
  3882. If you need to exchange two arrays, this is vastly quicker than using copy-by-value
  3883. because it just swaps their internal pointers.
  3884. */
  3885. template <class OtherArrayType>
  3886. void swapWithArray (OtherArrayType& otherArray) throw()
  3887. {
  3888. lock.enter();
  3889. otherArray.lock.enter();
  3890. swapVariables <int> (this->numUsed, otherArray.numUsed);
  3891. swapVariables <ElementType*> (this->elements, otherArray.elements);
  3892. swapVariables <int> (this->numAllocated, otherArray.numAllocated);
  3893. otherArray.lock.exit();
  3894. lock.exit();
  3895. }
  3896. /** Adds elements from another array to the end of this array.
  3897. @param arrayToAddFrom the array from which to copy the elements
  3898. @param startIndex the first element of the other array to start copying from
  3899. @param numElementsToAdd how many elements to add from the other array. If this
  3900. value is negative or greater than the number of available elements,
  3901. all available elements will be copied.
  3902. @see add
  3903. */
  3904. template <class OtherArrayType>
  3905. void addArray (const OtherArrayType& arrayToAddFrom,
  3906. int startIndex = 0,
  3907. int numElementsToAdd = -1) throw()
  3908. {
  3909. arrayToAddFrom.lockArray();
  3910. lock.enter();
  3911. jassert (this != &arrayToAddFrom);
  3912. if (startIndex < 0)
  3913. {
  3914. jassertfalse
  3915. startIndex = 0;
  3916. }
  3917. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size())
  3918. numElementsToAdd = arrayToAddFrom.size() - startIndex;
  3919. this->addArray ((const ElementType*) (arrayToAddFrom.elements + startIndex), numElementsToAdd);
  3920. lock.exit();
  3921. arrayToAddFrom.unlockArray();
  3922. }
  3923. /** Inserts a new element into the array, assuming that the array is sorted.
  3924. This will use a comparator to find the position at which the new element
  3925. should go. If the array isn't sorted, the behaviour of this
  3926. method will be unpredictable.
  3927. @param comparator the comparator to use to compare the elements - see the sort()
  3928. method for details about the form this object should take
  3929. @param newElement the new element to insert to the array
  3930. @see add, sort
  3931. */
  3932. template <class ElementComparator>
  3933. void addSorted (ElementComparator& comparator,
  3934. const ElementType newElement) throw()
  3935. {
  3936. lock.enter();
  3937. insert (findInsertIndexInSortedArray (comparator, this->elements, newElement, 0, numUsed), newElement);
  3938. lock.exit();
  3939. }
  3940. /** Finds the index of an element in the array, assuming that the array is sorted.
  3941. This will use a comparator to do a binary-chop to find the index of the given
  3942. element, if it exists. If the array isn't sorted, the behaviour of this
  3943. method will be unpredictable.
  3944. @param comparator the comparator to use to compare the elements - see the sort()
  3945. method for details about the form this object should take
  3946. @param elementToLookFor the element to search for
  3947. @returns the index of the element, or -1 if it's not found
  3948. @see addSorted, sort
  3949. */
  3950. template <class ElementComparator>
  3951. int indexOfSorted (ElementComparator& comparator,
  3952. const ElementType elementToLookFor) const throw()
  3953. {
  3954. (void) comparator; // if you pass in an object with a static compareElements() method, this
  3955. // avoids getting warning messages about the parameter being unused
  3956. lock.enter();
  3957. int start = 0;
  3958. int end = numUsed;
  3959. for (;;)
  3960. {
  3961. if (start >= end)
  3962. {
  3963. lock.exit();
  3964. return -1;
  3965. }
  3966. else if (comparator.compareElements (elementToLookFor, this->elements [start]) == 0)
  3967. {
  3968. lock.exit();
  3969. return start;
  3970. }
  3971. else
  3972. {
  3973. const int halfway = (start + end) >> 1;
  3974. if (halfway == start)
  3975. {
  3976. lock.exit();
  3977. return -1;
  3978. }
  3979. else if (comparator.compareElements (elementToLookFor, this->elements [halfway]) >= 0)
  3980. start = halfway;
  3981. else
  3982. end = halfway;
  3983. }
  3984. }
  3985. }
  3986. /** Removes an element from the array.
  3987. This will remove the element at a given index, and move back
  3988. all the subsequent elements to close the gap.
  3989. If the index passed in is out-of-range, nothing will happen.
  3990. @param indexToRemove the index of the element to remove
  3991. @returns the element that has been removed
  3992. @see removeValue, removeRange
  3993. */
  3994. ElementType remove (const int indexToRemove) throw()
  3995. {
  3996. lock.enter();
  3997. if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
  3998. {
  3999. --numUsed;
  4000. ElementType* const e = this->elements + indexToRemove;
  4001. ElementType const removed = *e;
  4002. const int numberToShift = numUsed - indexToRemove;
  4003. if (numberToShift > 0)
  4004. memmove (e, e + 1, numberToShift * sizeof (ElementType));
  4005. if ((numUsed << 1) < this->numAllocated)
  4006. minimiseStorageOverheads();
  4007. lock.exit();
  4008. return removed;
  4009. }
  4010. else
  4011. {
  4012. lock.exit();
  4013. return ElementType();
  4014. }
  4015. }
  4016. /** Removes an item from the array.
  4017. This will remove the first occurrence of the given element from the array.
  4018. If the item isn't found, no action is taken.
  4019. @param valueToRemove the object to try to remove
  4020. @see remove, removeRange
  4021. */
  4022. void removeValue (const ElementType valueToRemove) throw()
  4023. {
  4024. lock.enter();
  4025. ElementType* e = this->elements;
  4026. for (int i = numUsed; --i >= 0;)
  4027. {
  4028. if (valueToRemove == *e)
  4029. {
  4030. remove ((int) (e - this->elements));
  4031. break;
  4032. }
  4033. ++e;
  4034. }
  4035. lock.exit();
  4036. }
  4037. /** Removes a range of elements from the array.
  4038. This will remove a set of elements, starting from the given index,
  4039. and move subsequent elements down to close the gap.
  4040. If the range extends beyond the bounds of the array, it will
  4041. be safely clipped to the size of the array.
  4042. @param startIndex the index of the first element to remove
  4043. @param numberToRemove how many elements should be removed
  4044. @see remove, removeValue
  4045. */
  4046. void removeRange (int startIndex,
  4047. const int numberToRemove) throw()
  4048. {
  4049. lock.enter();
  4050. const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove);
  4051. startIndex = jlimit (0, numUsed, startIndex);
  4052. if (endIndex > startIndex)
  4053. {
  4054. const int rangeSize = endIndex - startIndex;
  4055. ElementType* e = this->elements + startIndex;
  4056. int numToShift = numUsed - endIndex;
  4057. numUsed -= rangeSize;
  4058. while (--numToShift >= 0)
  4059. {
  4060. *e = e [rangeSize];
  4061. ++e;
  4062. }
  4063. if ((numUsed << 1) < this->numAllocated)
  4064. minimiseStorageOverheads();
  4065. }
  4066. lock.exit();
  4067. }
  4068. /** Removes the last n elements from the array.
  4069. @param howManyToRemove how many elements to remove from the end of the array
  4070. @see remove, removeValue, removeRange
  4071. */
  4072. void removeLast (const int howManyToRemove = 1) throw()
  4073. {
  4074. lock.enter();
  4075. numUsed = jmax (0, numUsed - howManyToRemove);
  4076. if ((numUsed << 1) < this->numAllocated)
  4077. minimiseStorageOverheads();
  4078. lock.exit();
  4079. }
  4080. /** Removes any elements which are also in another array.
  4081. @param otherArray the other array in which to look for elements to remove
  4082. @see removeValuesNotIn, remove, removeValue, removeRange
  4083. */
  4084. template <class OtherArrayType>
  4085. void removeValuesIn (const OtherArrayType& otherArray) throw()
  4086. {
  4087. otherArray.lockArray();
  4088. lock.enter();
  4089. if (this == &otherArray)
  4090. {
  4091. clear();
  4092. }
  4093. else
  4094. {
  4095. if (otherArray.size() > 0)
  4096. {
  4097. for (int i = numUsed; --i >= 0;)
  4098. if (otherArray.contains (this->elements [i]))
  4099. remove (i);
  4100. }
  4101. }
  4102. lock.exit();
  4103. otherArray.unlockArray();
  4104. }
  4105. /** Removes any elements which are not found in another array.
  4106. Only elements which occur in this other array will be retained.
  4107. @param otherArray the array in which to look for elements NOT to remove
  4108. @see removeValuesIn, remove, removeValue, removeRange
  4109. */
  4110. template <class OtherArrayType>
  4111. void removeValuesNotIn (const OtherArrayType& otherArray) throw()
  4112. {
  4113. otherArray.lockArray();
  4114. lock.enter();
  4115. if (this != &otherArray)
  4116. {
  4117. if (otherArray.size() <= 0)
  4118. {
  4119. clear();
  4120. }
  4121. else
  4122. {
  4123. for (int i = numUsed; --i >= 0;)
  4124. if (! otherArray.contains (this->elements [i]))
  4125. remove (i);
  4126. }
  4127. }
  4128. lock.exit();
  4129. otherArray.unlockArray();
  4130. }
  4131. /** Swaps over two elements in the array.
  4132. This swaps over the elements found at the two indexes passed in.
  4133. If either index is out-of-range, this method will do nothing.
  4134. @param index1 index of one of the elements to swap
  4135. @param index2 index of the other element to swap
  4136. */
  4137. void swap (const int index1,
  4138. const int index2) throw()
  4139. {
  4140. lock.enter();
  4141. if (((unsigned int) index1) < (unsigned int) numUsed
  4142. && ((unsigned int) index2) < (unsigned int) numUsed)
  4143. {
  4144. swapVariables (this->elements [index1],
  4145. this->elements [index2]);
  4146. }
  4147. lock.exit();
  4148. }
  4149. /** Moves one of the values to a different position.
  4150. This will move the value to a specified index, shuffling along
  4151. any intervening elements as required.
  4152. So for example, if you have the array { 0, 1, 2, 3, 4, 5 } then calling
  4153. move (2, 4) would result in { 0, 1, 3, 4, 2, 5 }.
  4154. @param currentIndex the index of the value to be moved. If this isn't a
  4155. valid index, then nothing will be done
  4156. @param newIndex the index at which you'd like this value to end up. If this
  4157. is less than zero, the value will be moved to the end
  4158. of the array
  4159. */
  4160. void move (const int currentIndex,
  4161. int newIndex) throw()
  4162. {
  4163. if (currentIndex != newIndex)
  4164. {
  4165. lock.enter();
  4166. if (((unsigned int) currentIndex) < (unsigned int) numUsed)
  4167. {
  4168. if (((unsigned int) newIndex) >= (unsigned int) numUsed)
  4169. newIndex = numUsed - 1;
  4170. const ElementType value = this->elements [currentIndex];
  4171. if (newIndex > currentIndex)
  4172. {
  4173. memmove (this->elements + currentIndex,
  4174. this->elements + currentIndex + 1,
  4175. (newIndex - currentIndex) * sizeof (ElementType));
  4176. }
  4177. else
  4178. {
  4179. memmove (this->elements + newIndex + 1,
  4180. this->elements + newIndex,
  4181. (currentIndex - newIndex) * sizeof (ElementType));
  4182. }
  4183. this->elements [newIndex] = value;
  4184. }
  4185. lock.exit();
  4186. }
  4187. }
  4188. /** Reduces the amount of storage being used by the array.
  4189. Arrays typically allocate slightly more storage than they need, and after
  4190. removing elements, they may have quite a lot of unused space allocated.
  4191. This method will reduce the amount of allocated storage to a minimum.
  4192. */
  4193. void minimiseStorageOverheads() throw()
  4194. {
  4195. lock.enter();
  4196. if (numUsed == 0)
  4197. {
  4198. this->setAllocatedSize (0);
  4199. }
  4200. else
  4201. {
  4202. const int newAllocation = this->granularity * (numUsed / this->granularity + 1);
  4203. if (newAllocation < this->numAllocated)
  4204. this->setAllocatedSize (newAllocation);
  4205. }
  4206. lock.exit();
  4207. }
  4208. /** Increases the array's internal storage to hold a minimum number of elements.
  4209. Calling this before adding a large known number of elements means that
  4210. the array won't have to keep dynamically resizing itself as the elements
  4211. are added, and it'll therefore be more efficient.
  4212. */
  4213. void ensureStorageAllocated (const int minNumElements) throw()
  4214. {
  4215. this->ensureAllocatedSize (minNumElements);
  4216. }
  4217. /** Sorts the elements in the array.
  4218. This will use a comparator object to sort the elements into order. The object
  4219. passed must have a method of the form:
  4220. @code
  4221. int compareElements (ElementType first, ElementType second);
  4222. @endcode
  4223. ..and this method must return:
  4224. - a value of < 0 if the first comes before the second
  4225. - a value of 0 if the two objects are equivalent
  4226. - a value of > 0 if the second comes before the first
  4227. To improve performance, the compareElements() method can be declared as static or const.
  4228. @param comparator the comparator to use for comparing elements.
  4229. @param retainOrderOfEquivalentItems if this is true, then items
  4230. which the comparator says are equivalent will be
  4231. kept in the order in which they currently appear
  4232. in the array. This is slower to perform, but may
  4233. be important in some cases. If it's false, a faster
  4234. algorithm is used, but equivalent elements may be
  4235. rearranged.
  4236. @see addSorted, indexOfSorted, sortArray
  4237. */
  4238. template <class ElementComparator>
  4239. void sort (ElementComparator& comparator,
  4240. const bool retainOrderOfEquivalentItems = false) const throw()
  4241. {
  4242. (void) comparator; // if you pass in an object with a static compareElements() method, this
  4243. // avoids getting warning messages about the parameter being unused
  4244. lock.enter();
  4245. sortArray (comparator, this->elements, 0, size() - 1, retainOrderOfEquivalentItems);
  4246. lock.exit();
  4247. }
  4248. /** Locks the array's CriticalSection.
  4249. Of course if the type of section used is a DummyCriticalSection, this won't
  4250. have any effect.
  4251. @see unlockArray
  4252. */
  4253. void lockArray() const throw()
  4254. {
  4255. lock.enter();
  4256. }
  4257. /** Unlocks the array's CriticalSection.
  4258. Of course if the type of section used is a DummyCriticalSection, this won't
  4259. have any effect.
  4260. @see lockArray
  4261. */
  4262. void unlockArray() const throw()
  4263. {
  4264. lock.exit();
  4265. }
  4266. juce_UseDebuggingNewOperator
  4267. private:
  4268. int numUsed;
  4269. TypeOfCriticalSectionToUse lock;
  4270. };
  4271. #endif // __JUCE_ARRAY_JUCEHEADER__
  4272. /********* End of inlined file: juce_Array.h *********/
  4273. /**
  4274. A typedef for an Array of void*'s.
  4275. VoidArrays are used in various places throughout the library instead of
  4276. more strongly-typed arrays, to keep code-size low.
  4277. */
  4278. typedef Array <void*> VoidArray;
  4279. #endif // __JUCE_VOIDARRAY_JUCEHEADER__
  4280. /********* End of inlined file: juce_VoidArray.h *********/
  4281. #ifndef DOXYGEN
  4282. // (used in StringArray::appendNumbersToDuplicates)
  4283. static const tchar* const defaultPreNumberString = JUCE_T(" (");
  4284. static const tchar* const defaultPostNumberString = JUCE_T(")");
  4285. #endif
  4286. /**
  4287. A special array for holding a list of strings.
  4288. @see String, StringPairArray
  4289. */
  4290. class JUCE_API StringArray
  4291. {
  4292. public:
  4293. /** Creates an empty string array */
  4294. StringArray() throw();
  4295. /** Creates a copy of another string array */
  4296. StringArray (const StringArray& other) throw();
  4297. /** Creates a copy of an array of string literals.
  4298. @param strings an array of strings to add. Null pointers in the array will be
  4299. treated as empty strings
  4300. @param numberOfStrings how many items there are in the array
  4301. */
  4302. StringArray (const juce_wchar** const strings,
  4303. const int numberOfStrings) throw();
  4304. /** Creates a copy of an array of string literals.
  4305. @param strings an array of strings to add. Null pointers in the array will be
  4306. treated as empty strings
  4307. @param numberOfStrings how many items there are in the array
  4308. */
  4309. StringArray (const char** const strings,
  4310. const int numberOfStrings) throw();
  4311. /** Creates a copy of a null-terminated array of string literals.
  4312. Each item from the array passed-in is added, until it encounters a null pointer,
  4313. at which point it stops.
  4314. */
  4315. StringArray (const juce_wchar** const strings) throw();
  4316. /** Creates a copy of a null-terminated array of string literals.
  4317. Each item from the array passed-in is added, until it encounters a null pointer,
  4318. at which point it stops.
  4319. */
  4320. StringArray (const char** const strings) throw();
  4321. /** Destructor. */
  4322. virtual ~StringArray() throw();
  4323. /** Copies the contents of another string array into this one */
  4324. const StringArray& operator= (const StringArray& other) throw();
  4325. /** Compares two arrays.
  4326. Comparisons are case-sensitive.
  4327. @returns true only if the other array contains exactly the same strings in the same order
  4328. */
  4329. bool operator== (const StringArray& other) const throw();
  4330. /** Compares two arrays.
  4331. Comparisons are case-sensitive.
  4332. @returns false if the other array contains exactly the same strings in the same order
  4333. */
  4334. bool operator!= (const StringArray& other) const throw();
  4335. /** Returns the number of strings in the array */
  4336. inline int size() const throw() { return strings.size(); };
  4337. /** Returns one of the strings from the array.
  4338. If the index is out-of-range, an empty string is returned.
  4339. Obviously the reference returned shouldn't be stored for later use, as the
  4340. string it refers to may disappear when the array changes.
  4341. */
  4342. const String& operator[] (const int index) const throw();
  4343. /** Searches for a string in the array.
  4344. The comparison will be case-insensitive if the ignoreCase parameter is true.
  4345. @returns true if the string is found inside the array
  4346. */
  4347. bool contains (const String& stringToLookFor,
  4348. const bool ignoreCase = false) const throw();
  4349. /** Searches for a string in the array.
  4350. The comparison will be case-insensitive if the ignoreCase parameter is true.
  4351. @param stringToLookFor the string to try to find
  4352. @param ignoreCase whether the comparison should be case-insensitive
  4353. @param startIndex the first index to start searching from
  4354. @returns the index of the first occurrence of the string in this array,
  4355. or -1 if it isn't found.
  4356. */
  4357. int indexOf (const String& stringToLookFor,
  4358. const bool ignoreCase = false,
  4359. int startIndex = 0) const throw();
  4360. /** Appends a string at the end of the array. */
  4361. void add (const String& stringToAdd) throw();
  4362. /** Inserts a string into the array.
  4363. This will insert a string into the array at the given index, moving
  4364. up the other elements to make room for it.
  4365. If the index is less than zero or greater than the size of the array,
  4366. the new string will be added to the end of the array.
  4367. */
  4368. void insert (const int index,
  4369. const String& stringToAdd) throw();
  4370. /** Adds a string to the array as long as it's not already in there.
  4371. The search can optionally be case-insensitive.
  4372. */
  4373. void addIfNotAlreadyThere (const String& stringToAdd,
  4374. const bool ignoreCase = false) throw();
  4375. /** Replaces one of the strings in the array with another one.
  4376. If the index is higher than the array's size, the new string will be
  4377. added to the end of the array; if it's less than zero nothing happens.
  4378. */
  4379. void set (const int index,
  4380. const String& newString) throw();
  4381. /** Appends some strings from another array to the end of this one.
  4382. @param other the array to add
  4383. @param startIndex the first element of the other array to add
  4384. @param numElementsToAdd the maximum number of elements to add (if this is
  4385. less than zero, they are all added)
  4386. */
  4387. void addArray (const StringArray& other,
  4388. int startIndex = 0,
  4389. int numElementsToAdd = -1) throw();
  4390. /** Breaks up a string into tokens and adds them to this array.
  4391. This will tokenise the given string using whitespace characters as the
  4392. token delimiters, and will add these tokens to the end of the array.
  4393. @returns the number of tokens added
  4394. */
  4395. int addTokens (const tchar* const stringToTokenise,
  4396. const bool preserveQuotedStrings) throw();
  4397. /** Breaks up a string into tokens and adds them to this array.
  4398. This will tokenise the given string (using the string passed in to define the
  4399. token delimiters), and will add these tokens to the end of the array.
  4400. @param stringToTokenise the string to tokenise
  4401. @param breakCharacters a string of characters, any of which will be considered
  4402. to be a token delimiter.
  4403. @param quoteCharacters if this string isn't empty, it defines a set of characters
  4404. which are treated as quotes. Any text occurring
  4405. between quotes is not broken up into tokens.
  4406. @returns the number of tokens added
  4407. */
  4408. int addTokens (const tchar* const stringToTokenise,
  4409. const tchar* breakCharacters,
  4410. const tchar* quoteCharacters) throw();
  4411. /** Breaks up a string into lines and adds them to this array.
  4412. This breaks a string down into lines separated by \\n or \\r\\n, and adds each line
  4413. to the array. Line-break characters are omitted from the strings that are added to
  4414. the array.
  4415. */
  4416. int addLines (const tchar* stringToBreakUp) throw();
  4417. /** Removes all elements from the array. */
  4418. void clear() throw();
  4419. /** Removes a string from the array.
  4420. If the index is out-of-range, no action will be taken.
  4421. */
  4422. void remove (const int index) throw();
  4423. /** Finds a string in the array and removes it.
  4424. This will remove the first occurrence of the given string from the array. The
  4425. comparison may be case-insensitive depending on the ignoreCase parameter.
  4426. */
  4427. void removeString (const String& stringToRemove,
  4428. const bool ignoreCase = false) throw();
  4429. /** Removes any duplicated elements from the array.
  4430. If any string appears in the array more than once, only the first occurrence of
  4431. it will be retained.
  4432. @param ignoreCase whether to use a case-insensitive comparison
  4433. */
  4434. void removeDuplicates (const bool ignoreCase) throw();
  4435. /** Removes empty strings from the array.
  4436. @param removeWhitespaceStrings if true, strings that only contain whitespace
  4437. characters will also be removed
  4438. */
  4439. void removeEmptyStrings (const bool removeWhitespaceStrings = true) throw();
  4440. /** Moves one of the strings to a different position.
  4441. This will move the string to a specified index, shuffling along
  4442. any intervening elements as required.
  4443. So for example, if you have the array { 0, 1, 2, 3, 4, 5 } then calling
  4444. move (2, 4) would result in { 0, 1, 3, 4, 2, 5 }.
  4445. @param currentIndex the index of the value to be moved. If this isn't a
  4446. valid index, then nothing will be done
  4447. @param newIndex the index at which you'd like this value to end up. If this
  4448. is less than zero, the value will be moved to the end
  4449. of the array
  4450. */
  4451. void move (const int currentIndex, int newIndex) throw();
  4452. /** Deletes any whitespace characters from the starts and ends of all the strings. */
  4453. void trim() throw();
  4454. /** Adds numbers to the strings in the array, to make each string unique.
  4455. This will add numbers to the ends of groups of similar strings.
  4456. e.g. if there are two "moose" strings, they will become "moose (1)" and "moose (2)"
  4457. @param ignoreCaseWhenComparing whether the comparison used is case-insensitive
  4458. @param appendNumberToFirstInstance whether the first of a group of similar strings
  4459. also has a number appended to it.
  4460. @param preNumberString when adding a number, this string is added before the number
  4461. @param postNumberString this string is appended after any numbers that are added
  4462. */
  4463. void appendNumbersToDuplicates (const bool ignoreCaseWhenComparing,
  4464. const bool appendNumberToFirstInstance,
  4465. const tchar* const preNumberString = defaultPreNumberString,
  4466. const tchar* const postNumberString = defaultPostNumberString) throw();
  4467. /** Joins the strings in the array together into one string.
  4468. This will join a range of elements from the array into a string, separating
  4469. them with a given string.
  4470. e.g. joinIntoString (",") will turn an array of "a" "b" and "c" into "a,b,c".
  4471. @param separatorString the string to insert between all the strings
  4472. @param startIndex the first element to join
  4473. @param numberOfElements how many elements to join together. If this is less
  4474. than zero, all available elements will be used.
  4475. */
  4476. const String joinIntoString (const String& separatorString,
  4477. int startIndex = 0,
  4478. int numberOfElements = -1) const throw();
  4479. /** Sorts the array into alphabetical order.
  4480. @param ignoreCase if true, the comparisons used will be case-sensitive.
  4481. */
  4482. void sort (const bool ignoreCase) throw();
  4483. /** Reduces the amount of storage being used by the array.
  4484. Arrays typically allocate slightly more storage than they need, and after
  4485. removing elements, they may have quite a lot of unused space allocated.
  4486. This method will reduce the amount of allocated storage to a minimum.
  4487. */
  4488. void minimiseStorageOverheads() throw();
  4489. juce_UseDebuggingNewOperator
  4490. private:
  4491. VoidArray strings;
  4492. };
  4493. #endif // __JUCE_STRINGARRAY_JUCEHEADER__
  4494. /********* End of inlined file: juce_StringArray.h *********/
  4495. /********* Start of inlined file: juce_MemoryBlock.h *********/
  4496. #ifndef __JUCE_MEMORYBLOCK_JUCEHEADER__
  4497. #define __JUCE_MEMORYBLOCK_JUCEHEADER__
  4498. /**
  4499. A class to hold a resizable block of raw data.
  4500. */
  4501. class JUCE_API MemoryBlock
  4502. {
  4503. public:
  4504. /** Create an uninitialised block with 0 size. */
  4505. MemoryBlock() throw();
  4506. /** Creates a memory block with a given initial size.
  4507. @param initialSize the size of block to create
  4508. @param initialiseToZero whether to clear the memory or just leave it uninitialised
  4509. */
  4510. MemoryBlock (const int initialSize,
  4511. const bool initialiseToZero = false) throw();
  4512. /** Creates a copy of another memory block. */
  4513. MemoryBlock (const MemoryBlock& other) throw();
  4514. /** Creates a memory block using a copy of a block of data.
  4515. @param dataToInitialiseFrom some data to copy into this block
  4516. @param sizeInBytes how much space to use
  4517. */
  4518. MemoryBlock (const void* const dataToInitialiseFrom,
  4519. const int sizeInBytes) throw();
  4520. /** Destructor. */
  4521. ~MemoryBlock() throw();
  4522. /** Copies another memory block onto this one.
  4523. This block will be resized and copied to exactly match the other one.
  4524. */
  4525. const MemoryBlock& operator= (const MemoryBlock& other) throw();
  4526. /** Compares two memory blocks.
  4527. @returns true only if the two blocks are the same size and have identical contents.
  4528. */
  4529. bool operator== (const MemoryBlock& other) const throw();
  4530. /** Compares two memory blocks.
  4531. @returns true if the two blocks are different sizes or have different contents.
  4532. */
  4533. bool operator!= (const MemoryBlock& other) const throw();
  4534. /** Returns a pointer to the data, casting it to any type of primitive data required.
  4535. Note that the pointer returned will probably become invalid when the
  4536. block is resized.
  4537. */
  4538. template <class DataType>
  4539. operator DataType*() const throw() { return (DataType*) data; }
  4540. /** Returns a void pointer to the data.
  4541. Note that the pointer returned will probably become invalid when the
  4542. block is resized.
  4543. */
  4544. void* getData() const throw() { return data; }
  4545. /** Returns a byte from the memory block.
  4546. This returns a reference, so you can also use it to set a byte.
  4547. */
  4548. char& operator[] (const int offset) const throw() { return data [offset]; }
  4549. /** Returns the block's current allocated size, in bytes. */
  4550. int getSize() const throw() { return size; }
  4551. /** Resizes the memory block.
  4552. This will try to keep as much of the block's current content as it can,
  4553. and can optionally be made to clear any new space that gets allocated at
  4554. the end of the block.
  4555. @param newSize the new desired size for the block
  4556. @param initialiseNewSpaceToZero if the block gets enlarged, this determines
  4557. whether to clear the new section or just leave it
  4558. uninitialised
  4559. @see ensureSize
  4560. */
  4561. void setSize (const int newSize,
  4562. const bool initialiseNewSpaceToZero = false) throw();
  4563. /** Increases the block's size only if it's smaller than a given size.
  4564. @param minimumSize if the block is already bigger than this size, no action
  4565. will be taken; otherwise it will be increased to this size
  4566. @param initialiseNewSpaceToZero if the block gets enlarged, this determines
  4567. whether to clear the new section or just leave it
  4568. uninitialised
  4569. @see setSize
  4570. */
  4571. void ensureSize (const int minimumSize,
  4572. const bool initialiseNewSpaceToZero = false) throw();
  4573. /** Fills the entire memory block with a repeated byte value.
  4574. This is handy for clearing a block of memory to zero.
  4575. */
  4576. void fillWith (const uint8 valueToUse) throw();
  4577. /** Adds another block of data to the end of this one.
  4578. This block's size will be increased accordingly.
  4579. */
  4580. void append (const void* const data,
  4581. const int numBytes) throw();
  4582. /** Copies data into this MemoryBlock from a memory address.
  4583. @param srcData the memory location of the data to copy into this block
  4584. @param destinationOffset the offset in this block at which the data being copied should begin
  4585. @param numBytes how much to copy in (if this goes beyond the size of the memory block,
  4586. it will be clipped so not to do anything nasty)
  4587. */
  4588. void copyFrom (const void* srcData,
  4589. int destinationOffset,
  4590. int numBytes) throw();
  4591. /** Copies data from this MemoryBlock to a memory address.
  4592. @param destData the memory location to write to
  4593. @param sourceOffset the offset within this block from which the copied data will be read
  4594. @param numBytes how much to copy (if this extends beyond the limits of the memory block,
  4595. zeros will be used for that portion of the data)
  4596. */
  4597. void copyTo (void* destData,
  4598. int sourceOffset,
  4599. int numBytes) const throw();
  4600. /** Chops out a section of the block.
  4601. This will remove a section of the memory block and close the gap around it,
  4602. shifting any subsequent data downwards and reducing the size of the block.
  4603. If the range specified goes beyond the size of the block, it will be clipped.
  4604. */
  4605. void removeSection (int startByte, int numBytesToRemove) throw();
  4606. /** Attempts to parse the contents of the block as a zero-terminated string of 8-bit
  4607. characters in the system's default encoding. */
  4608. const String toString() const throw();
  4609. /** Parses a string of hexadecimal numbers and writes this data into the memory block.
  4610. The block will be resized to the number of valid bytes read from the string.
  4611. Non-hex characters in the string will be ignored.
  4612. @see String::toHexString()
  4613. */
  4614. void loadFromHexString (const String& sourceHexString) throw();
  4615. /** Sets a number of bits in the memory block, treating it as a long binary sequence. */
  4616. void setBitRange (int bitRangeStart,
  4617. int numBits,
  4618. int binaryNumberToApply) throw();
  4619. /** Reads a number of bits from the memory block, treating it as one long binary sequence */
  4620. int getBitRange (int bitRangeStart,
  4621. int numBitsToRead) const throw();
  4622. /** Returns a string of characters that represent the binary contents of this block.
  4623. Uses a 64-bit encoding system to allow binary data to be turned into a string
  4624. of simple non-extended characters, e.g. for storage in XML.
  4625. @see fromBase64Encoding
  4626. */
  4627. const String toBase64Encoding() const throw();
  4628. /** Takes a string of encoded characters and turns it into binary data.
  4629. The string passed in must have been created by to64BitEncoding(), and this
  4630. block will be resized to recreate the original data block.
  4631. @see toBase64Encoding
  4632. */
  4633. bool fromBase64Encoding (const String& encodedString) throw();
  4634. juce_UseDebuggingNewOperator
  4635. private:
  4636. char* data;
  4637. int size;
  4638. };
  4639. #endif // __JUCE_MEMORYBLOCK_JUCEHEADER__
  4640. /********* End of inlined file: juce_MemoryBlock.h *********/
  4641. class FileInputStream;
  4642. class FileOutputStream;
  4643. /**
  4644. Represents a local file or directory.
  4645. This class encapsulates the absolute pathname of a file or directory, and
  4646. has methods for finding out about the file and changing its properties.
  4647. To read or write to the file, there are methods for returning an input or
  4648. output stream.
  4649. @see FileInputStream, FileOutputStream
  4650. */
  4651. class JUCE_API File
  4652. {
  4653. public:
  4654. /** Creates an (invalid) file object.
  4655. The file is initially set to an empty path, so getFullPath() will return
  4656. an empty string, and comparing the file to File::nonexistent will return
  4657. true.
  4658. You can use its operator= method to point it at a proper file.
  4659. */
  4660. File() throw() {}
  4661. /** Creates a file from an absolute path.
  4662. If the path supplied is a relative path, it is taken to be relative
  4663. to the current working directory (see File::getCurrentWorkingDirectory()),
  4664. but this isn't a recommended way of creating a file, because you
  4665. never know what the CWD is going to be.
  4666. On the Mac/Linux, the path can include "~" notation for referring to
  4667. user home directories.
  4668. */
  4669. File (const String& path) throw();
  4670. /** Creates a copy of another file object. */
  4671. File (const File& other) throw();
  4672. /** Destructor. */
  4673. ~File() throw() {}
  4674. /** Sets the file based on an absolute pathname.
  4675. If the path supplied is a relative path, it is taken to be relative
  4676. to the current working directory (see File::getCurrentWorkingDirectory()),
  4677. but this isn't a recommended way of creating a file, because you
  4678. never know what the CWD is going to be.
  4679. On the Mac/Linux, the path can include "~" notation for referring to
  4680. user home directories.
  4681. */
  4682. const File& operator= (const String& newFilePath) throw();
  4683. /** Copies from another file object. */
  4684. const File& operator= (const File& otherFile) throw();
  4685. /** This static constant is used for referring to an 'invalid' file. */
  4686. static const File nonexistent;
  4687. /** Checks whether the file actually exists.
  4688. @returns true if the file exists, either as a file or a directory.
  4689. @see existsAsFile, isDirectory
  4690. */
  4691. bool exists() const throw();
  4692. /** Checks whether the file exists and is a file rather than a directory.
  4693. @returns true only if this is a real file, false if it's a directory
  4694. or doesn't exist
  4695. @see exists, isDirectory
  4696. */
  4697. bool existsAsFile() const throw();
  4698. /** Checks whether the file is a directory that exists.
  4699. @returns true only if the file is a directory which actually exists, so
  4700. false if it's a file or doesn't exist at all
  4701. @see exists, existsAsFile
  4702. */
  4703. bool isDirectory() const throw();
  4704. /** Returns the size of the file in bytes.
  4705. @returns the number of bytes in the file, or 0 if it doesn't exist.
  4706. */
  4707. int64 getSize() const throw();
  4708. /** Utility function to convert a file size in bytes to a neat string description.
  4709. So for example 100 would return "100 bytes", 2000 would return "2 KB",
  4710. 2000000 would produce "2 MB", etc.
  4711. */
  4712. static const String descriptionOfSizeInBytes (const int64 bytes);
  4713. /** Returns the complete, absolute path of this file.
  4714. This includes the filename and all its parent folders. On Windows it'll
  4715. also include the drive letter prefix; on Mac or Linux it'll be a complete
  4716. path starting from the root folder.
  4717. If you just want the file's name, you should use getFileName() or
  4718. getFileNameWithoutExtension().
  4719. @see getFileName, getRelativePathFrom
  4720. */
  4721. const String& getFullPathName() const throw() { return fullPath; }
  4722. /** Returns the last section of the pathname.
  4723. Returns just the final part of the path - e.g. if the whole path
  4724. is "/moose/fish/foo.txt" this will return "foo.txt".
  4725. For a directory, it returns the final part of the path - e.g. for the
  4726. directory "/moose/fish" it'll return "fish".
  4727. If the filename begins with a dot, it'll return the whole filename, e.g. for
  4728. "/moose/.fish", it'll return ".fish"
  4729. @see getFullPathName, getFileNameWithoutExtension
  4730. */
  4731. const String getFileName() const throw();
  4732. /** Creates a relative path that refers to a file relatively to a given directory.
  4733. e.g. File ("/moose/foo.txt").getRelativePathFrom ("/moose/fish/haddock")
  4734. would return "../../foo.txt".
  4735. If it's not possible to navigate from one file to the other, an absolute
  4736. path is returned. If the paths are invalid, an empty string may also be
  4737. returned.
  4738. @param directoryToBeRelativeTo the directory which the resultant string will
  4739. be relative to. If this is actually a file rather than
  4740. a directory, its parent directory will be used instead.
  4741. If it doesn't exist, it's assumed to be a directory.
  4742. @see getChildFile, isAbsolutePath
  4743. */
  4744. const String getRelativePathFrom (const File& directoryToBeRelativeTo) const throw();
  4745. /** Returns the file's extension.
  4746. Returns the file extension of this file, also including the dot.
  4747. e.g. "/moose/fish/foo.txt" would return ".txt"
  4748. @see hasFileExtension, withFileExtension, getFileNameWithoutExtension
  4749. */
  4750. const String getFileExtension() const throw();
  4751. /** Checks whether the file has a given extension.
  4752. @param extensionToTest the extension to look for - it doesn't matter whether or
  4753. not this string has a dot at the start, so ".wav" and "wav"
  4754. will have the same effect. The comparison used is
  4755. case-insensitve.
  4756. @see getFileExtension, withFileExtension, getFileNameWithoutExtension
  4757. */
  4758. bool hasFileExtension (const String& extensionToTest) const throw();
  4759. /** Returns a version of this file with a different file extension.
  4760. e.g. File ("/moose/fish/foo.txt").withFileExtension ("html") returns "/moose/fish/foo.html"
  4761. @param newExtension the new extension, either with or without a dot at the start (this
  4762. doesn't make any difference). To get remove a file's extension altogether,
  4763. pass an empty string into this function.
  4764. @see getFileName, getFileExtension, hasFileExtension, getFileNameWithoutExtension
  4765. */
  4766. const File withFileExtension (const String& newExtension) const throw();
  4767. /** Returns the last part of the filename, without its file extension.
  4768. e.g. for "/moose/fish/foo.txt" this will return "foo".
  4769. @see getFileName, getFileExtension, hasFileExtension, withFileExtension
  4770. */
  4771. const String getFileNameWithoutExtension() const throw();
  4772. /** Returns a 32-bit hash-code that identifies this file.
  4773. This is based on the filename. Obviously it's possible, although unlikely, that
  4774. two files will have the same hash-code.
  4775. */
  4776. int hashCode() const throw();
  4777. /** Returns a 64-bit hash-code that identifies this file.
  4778. This is based on the filename. Obviously it's possible, although unlikely, that
  4779. two files will have the same hash-code.
  4780. */
  4781. int64 hashCode64() const throw();
  4782. /** Returns a file based on a relative path.
  4783. This will find a child file or directory of the current object.
  4784. e.g.
  4785. File ("/moose/fish").getChildFile ("foo.txt") will produce "/moose/fish/foo.txt".
  4786. File ("/moose/fish").getChildFile ("../foo.txt") will produce "/moose/foo.txt".
  4787. If the string is actually an absolute path, it will be treated as such, e.g.
  4788. File ("/moose/fish").getChildFile ("/foo.txt") will produce "/foo.txt"
  4789. @see getSiblingFile, getParentDirectory, getRelativePathFrom, isAChildOf
  4790. */
  4791. const File getChildFile (String relativePath) const throw();
  4792. /** Returns a file which is in the same directory as this one.
  4793. This is equivalent to getParentDirectory().getChildFile (name).
  4794. @see getChildFile, getParentDirectory
  4795. */
  4796. const File getSiblingFile (const String& siblingFileName) const throw();
  4797. /** Returns the directory that contains this file or directory.
  4798. e.g. for "/moose/fish/foo.txt" this will return "/moose/fish".
  4799. */
  4800. const File getParentDirectory() const throw();
  4801. /** Checks whether a file is somewhere inside a directory.
  4802. Returns true if this file is somewhere inside a subdirectory of the directory
  4803. that is passed in. Neither file actually has to exist, because the function
  4804. just checks the paths for similarities.
  4805. e.g. File ("/moose/fish/foo.txt").isAChildOf ("/moose") is true.
  4806. File ("/moose/fish/foo.txt").isAChildOf ("/moose/fish") is also true.
  4807. */
  4808. bool isAChildOf (const File& potentialParentDirectory) const throw();
  4809. /** Chooses a filename relative to this one that doesn't already exist.
  4810. If this file is a directory, this will return a child file of this
  4811. directory that doesn't exist, by adding numbers to a prefix and suffix until
  4812. it finds one that isn't already there.
  4813. If the prefix + the suffix doesn't exist, it won't bother adding a number.
  4814. e.g. File ("/moose/fish").getNonexistentChildFile ("foo", ".txt", true) might
  4815. return "/moose/fish/foo(2).txt" if there's already a file called "foo.txt".
  4816. @param prefix the string to use for the filename before the number
  4817. @param suffix the string to add to the filename after the number
  4818. @param putNumbersInBrackets if true, this will create filenames in the
  4819. format "prefix(number)suffix", if false, it will leave the
  4820. brackets out.
  4821. */
  4822. const File getNonexistentChildFile (const String& prefix,
  4823. const String& suffix,
  4824. bool putNumbersInBrackets = true) const throw();
  4825. /** Chooses a filename for a sibling file to this one that doesn't already exist.
  4826. If this file doesn't exist, this will just return itself, otherwise it
  4827. will return an appropriate sibling that doesn't exist, e.g. if a file
  4828. "/moose/fish/foo.txt" exists, this might return "/moose/fish/foo(2).txt".
  4829. @param putNumbersInBrackets whether to add brackets around the numbers that
  4830. get appended to the new filename.
  4831. */
  4832. const File getNonexistentSibling (const bool putNumbersInBrackets = true) const throw();
  4833. /** Compares the pathnames for two files. */
  4834. bool operator== (const File& otherFile) const throw();
  4835. /** Compares the pathnames for two files. */
  4836. bool operator!= (const File& otherFile) const throw();
  4837. /** Checks whether a file can be created or written to.
  4838. @returns true if it's possible to create and write to this file. If the file
  4839. doesn't already exist, this will check its parent directory to
  4840. see if writing is allowed.
  4841. @see setReadOnly
  4842. */
  4843. bool hasWriteAccess() const throw();
  4844. /** Changes the write-permission of a file or directory.
  4845. @param shouldBeReadOnly whether to add or remove write-permission
  4846. @param applyRecursively if the file is a directory and this is true, it will
  4847. recurse through all the subfolders changing the permissions
  4848. of all files
  4849. @returns true if it manages to change the file's permissions.
  4850. @see hasWriteAccess
  4851. */
  4852. bool setReadOnly (const bool shouldBeReadOnly,
  4853. const bool applyRecursively = false) const throw();
  4854. /** Returns true if this file is a hidden or system file.
  4855. The criteria for deciding whether a file is hidden are platform-dependent.
  4856. */
  4857. bool isHidden() const throw();
  4858. /** Returns the last modification time of this file.
  4859. @returns the time, or an invalid time if the file doesn't exist.
  4860. @see setLastModificationTime, getLastAccessTime, getCreationTime
  4861. */
  4862. const Time getLastModificationTime() const throw();
  4863. /** Returns the last time this file was accessed.
  4864. @returns the time, or an invalid time if the file doesn't exist.
  4865. @see setLastAccessTime, getLastModificationTime, getCreationTime
  4866. */
  4867. const Time getLastAccessTime() const throw();
  4868. /** Returns the time that this file was created.
  4869. @returns the time, or an invalid time if the file doesn't exist.
  4870. @see getLastModificationTime, getLastAccessTime
  4871. */
  4872. const Time getCreationTime() const throw();
  4873. /** Changes the modification time for this file.
  4874. @param newTime the time to apply to the file
  4875. @returns true if it manages to change the file's time.
  4876. @see getLastModificationTime, setLastAccessTime, setCreationTime
  4877. */
  4878. bool setLastModificationTime (const Time& newTime) const throw();
  4879. /** Changes the last-access time for this file.
  4880. @param newTime the time to apply to the file
  4881. @returns true if it manages to change the file's time.
  4882. @see getLastAccessTime, setLastModificationTime, setCreationTime
  4883. */
  4884. bool setLastAccessTime (const Time& newTime) const throw();
  4885. /** Changes the creation date for this file.
  4886. @param newTime the time to apply to the file
  4887. @returns true if it manages to change the file's time.
  4888. @see getCreationTime, setLastModificationTime, setLastAccessTime
  4889. */
  4890. bool setCreationTime (const Time& newTime) const throw();
  4891. /** Creates an empty file if it doesn't already exist.
  4892. If the file that this object refers to doesn't exist, this will create a file
  4893. of zero size.
  4894. If it already exists or is a directory, this method will do nothing.
  4895. @returns true if the file has been created (or if it already existed).
  4896. @see createDirectory
  4897. */
  4898. bool create() const throw();
  4899. /** Creates a new directory for this filename.
  4900. This will try to create the file as a directory, and fill also create
  4901. any parent directories it needs in order to complete the operation.
  4902. @returns true if the directory has been created successfully, (or if it
  4903. already existed beforehand).
  4904. @see create
  4905. */
  4906. bool createDirectory() const throw();
  4907. /** Deletes a file.
  4908. If this file is actually a directory, it may not be deleted correctly if it
  4909. contains files. See deleteRecursively() as a better way of deleting directories.
  4910. @returns true if the file has been successfully deleted (or if it didn't exist to
  4911. begin with).
  4912. @see deleteRecursively
  4913. */
  4914. bool deleteFile() const throw();
  4915. /** Deletes a file or directory and all its subdirectories.
  4916. If this file is a directory, this will try to delete it and all its subfolders. If
  4917. it's just a file, it will just try to delete the file.
  4918. @returns true if the file and all its subfolders have been successfully deleted
  4919. (or if it didn't exist to begin with).
  4920. @see deleteFile
  4921. */
  4922. bool deleteRecursively() const throw();
  4923. /** Moves or renames a file.
  4924. Tries to move a file to a different location.
  4925. If the target file already exists, this will attempt to delete it first, and
  4926. will fail if this can't be done.
  4927. Note that the destination file isn't the directory to put it in, it's the actual
  4928. filename that you want the new file to have.
  4929. @returns true if the operation succeeds
  4930. */
  4931. bool moveFileTo (const File& targetLocation) const throw();
  4932. /** Copies a file.
  4933. Tries to copy a file to a different location.
  4934. If the target file already exists, this will attempt to delete it first, and
  4935. will fail if this can't be done.
  4936. @returns true if the operation succeeds
  4937. */
  4938. bool copyFileTo (const File& targetLocation) const throw();
  4939. /** Copies a directory.
  4940. Tries to copy an entire directory, recursively.
  4941. If this file isn't a directory or if any target files can't be created, this
  4942. will return false.
  4943. @param newDirectory the directory that this one should be copied to. Note that this
  4944. is the name of the actual directory to create, not the directory
  4945. into which the new one should be placed, so there must be enough
  4946. write privileges to create it if it doesn't exist. Any files inside
  4947. it will be overwritten by similarly named ones that are copied.
  4948. */
  4949. bool copyDirectoryTo (const File& newDirectory) const throw();
  4950. /** Used in file searching, to specify whether to return files, directories, or both.
  4951. */
  4952. enum TypesOfFileToFind
  4953. {
  4954. findDirectories = 1, /**< Use this flag to indicate that you want to find directories. */
  4955. findFiles = 2, /**< Use this flag to indicate that you want to find files. */
  4956. findFilesAndDirectories = 3, /**< Use this flag to indicate that you want to find both files and directories. */
  4957. ignoreHiddenFiles = 4 /**< Add this flag to avoid returning any hidden files in the results. */
  4958. };
  4959. /** Searches inside a directory for files matching a wildcard pattern.
  4960. Assuming that this file is a directory, this method will search it
  4961. for either files or subdirectories whose names match a filename pattern.
  4962. @param results an array to which File objects will be added for the
  4963. files that the search comes up with
  4964. @param whatToLookFor a value from the TypesOfFileToFind enum, specifying whether to
  4965. return files, directories, or both. If the ignoreHiddenFiles flag
  4966. is also added to this value, hidden files won't be returned
  4967. @param searchRecursively if true, all subdirectories will be recursed into to do
  4968. an exhaustive search
  4969. @param wildCardPattern the filename pattern to search for, e.g. "*.txt"
  4970. @returns the number of results that have been found
  4971. @see getNumberOfChildFiles, DirectoryIterator
  4972. */
  4973. int findChildFiles (OwnedArray<File>& results,
  4974. const int whatToLookFor,
  4975. const bool searchRecursively,
  4976. const String& wildCardPattern = JUCE_T("*")) const throw();
  4977. /** Searches inside a directory and counts how many files match a wildcard pattern.
  4978. Assuming that this file is a directory, this method will search it
  4979. for either files or subdirectories whose names match a filename pattern,
  4980. and will return the number of matches found.
  4981. This isn't a recursive call, and will only search this directory, not
  4982. its children.
  4983. @param whatToLookFor a value from the TypesOfFileToFind enum, specifying whether to
  4984. count files, directories, or both. If the ignoreHiddenFiles flag
  4985. is also added to this value, hidden files won't be counted
  4986. @param wildCardPattern the filename pattern to search for, e.g. "*.txt"
  4987. @returns the number of matches found
  4988. @see findChildFiles, DirectoryIterator
  4989. */
  4990. int getNumberOfChildFiles (const int whatToLookFor,
  4991. const String& wildCardPattern = JUCE_T("*")) const throw();
  4992. /** Creates a stream to read from this file.
  4993. @returns a stream that will read from this file (initially positioned at the
  4994. start of the file), or 0 if the file can't be opened for some reason
  4995. @see createOutputStream, loadFileAsData
  4996. */
  4997. FileInputStream* createInputStream() const throw();
  4998. /** Creates a stream to write to this file.
  4999. If the file exists, the stream that is returned will be positioned ready for
  5000. writing at the end of the file, so you might want to use deleteFile() first
  5001. to write to an empty file.
  5002. @returns a stream that will write to this file (initially positioned at the
  5003. end of the file), or 0 if the file can't be opened for some reason
  5004. @see createInputStream, printf, appendData, appendText
  5005. */
  5006. FileOutputStream* createOutputStream (const int bufferSize = 0x8000) const throw();
  5007. /** Loads a file's contents into memory as a block of binary data.
  5008. Of course, trying to load a very large file into memory will blow up, so
  5009. it's better to check first.
  5010. @param result the data block to which the file's contents should be appended - note
  5011. that if the memory block might already contain some data, you
  5012. might want to clear it first
  5013. @returns true if the file could all be read into memory
  5014. */
  5015. bool loadFileAsData (MemoryBlock& result) const throw();
  5016. /** Reads a file into memory as a string.
  5017. Attempts to load the entire file as a zero-terminated string.
  5018. This makes use of InputStream::readEntireStreamAsString, which should
  5019. automatically cope with unicode/acsii file formats.
  5020. */
  5021. const String loadFileAsString() const throw();
  5022. /** Writes text to the end of the file.
  5023. This will try to do a printf to the file.
  5024. @returns false if it can't write to the file for some reason
  5025. */
  5026. bool printf (const tchar* format, ...) const throw();
  5027. /** Appends a block of binary data to the end of the file.
  5028. This will try to write the given buffer to the end of the file.
  5029. @returns false if it can't write to the file for some reason
  5030. */
  5031. bool appendData (const void* const dataToAppend,
  5032. const int numberOfBytes) const throw();
  5033. /** Replaces this file's contents with a given block of data.
  5034. This will delete the file and replace it with the given data.
  5035. A nice feature of this method is that it's safe - instead of deleting
  5036. the file first and then re-writing it, it creates a new temporary file,
  5037. writes the data to that, and then moves the new file to replace the existing
  5038. file. This means that if the power gets pulled out or something crashes,
  5039. you're a lot less likely to end up with an empty file..
  5040. Returns true if the operation succeeds, or false if it fails.
  5041. @see appendText
  5042. */
  5043. bool replaceWithData (const void* const dataToWrite,
  5044. const int numberOfBytes) const throw();
  5045. /** Appends a string to the end of the file.
  5046. This will try to append a text string to the file, as either 16-bit unicode
  5047. or 8-bit characters in the default system encoding.
  5048. It can also write the 'ff fe' unicode header bytes before the text to indicate
  5049. the endianness of the file.
  5050. Any single \\n characters in the string are replaced with \\r\\n before it is written.
  5051. @see replaceWithText
  5052. */
  5053. bool appendText (const String& textToAppend,
  5054. const bool asUnicode = false,
  5055. const bool writeUnicodeHeaderBytes = false) const throw();
  5056. /** Replaces this file's contents with a given text string.
  5057. This will delete the file and replace it with the given text.
  5058. A nice feature of this method is that it's safe - instead of deleting
  5059. the file first and then re-writing it, it creates a new temporary file,
  5060. writes the text to that, and then moves the new file to replace the existing
  5061. file. This means that if the power gets pulled out or something crashes,
  5062. you're a lot less likely to end up with an empty file..
  5063. For an explanation of the parameters here, see the appendText() method.
  5064. Returns true if the operation succeeds, or false if it fails.
  5065. @see appendText
  5066. */
  5067. bool replaceWithText (const String& textToWrite,
  5068. const bool asUnicode = false,
  5069. const bool writeUnicodeHeaderBytes = false) const throw();
  5070. /** Creates a set of files to represent each file root.
  5071. e.g. on Windows this will create files for "c:\", "d:\" etc according
  5072. to which ones are available. On the Mac/Linux, this will probably
  5073. just add a single entry for "/".
  5074. */
  5075. static void findFileSystemRoots (OwnedArray<File>& results) throw();
  5076. /** Finds the name of the drive on which this file lives.
  5077. @returns the volume label of the drive, or an empty string if this isn't possible
  5078. */
  5079. const String getVolumeLabel() const throw();
  5080. /** Returns the serial number of the volume on which this file lives.
  5081. @returns the serial number, or zero if there's a problem doing this
  5082. */
  5083. int getVolumeSerialNumber() const throw();
  5084. /** Returns the number of bytes free on the drive that this file lives on.
  5085. @returns the number of bytes free, or 0 if there's a problem finding this out
  5086. */
  5087. int64 getBytesFreeOnVolume() const throw();
  5088. /** Returns true if this file is on a CD or DVD drive. */
  5089. bool isOnCDRomDrive() const throw();
  5090. /** Returns true if this file is on a hard disk.
  5091. This will fail if it's a network drive, but will still be true for
  5092. removable hard-disks.
  5093. */
  5094. bool isOnHardDisk() const throw();
  5095. /** Returns true if this file is on a removable disk drive.
  5096. This might be a usb-drive, a CD-rom, or maybe a network drive.
  5097. */
  5098. bool isOnRemovableDrive() const throw();
  5099. /** Launches the file as a process.
  5100. - if the file is executable, this will run it.
  5101. - if it's a document of some kind, it will launch the document with its
  5102. default viewer application.
  5103. - if it's a folder, it will be opened in Explorer, Finder, or equivalent.
  5104. */
  5105. bool startAsProcess (const String& parameters = String::empty) const throw();
  5106. /** A set of types of location that can be passed to the getSpecialLocation() method.
  5107. */
  5108. enum SpecialLocationType
  5109. {
  5110. /** The user's home folder. This is the same as using File ("~"). */
  5111. userHomeDirectory,
  5112. /** The user's default documents folder. On Windows, this might be the user's
  5113. "My Documents" folder. On the Mac it'll be their "Documents" folder. Linux
  5114. doesn't tend to have one of these, so it might just return their home folder.
  5115. */
  5116. userDocumentsDirectory,
  5117. /** The folder that contains the user's desktop objects. */
  5118. userDesktopDirectory,
  5119. /** The folder in which applications store their persistent user-specific settings.
  5120. On Windows, this might be "\Documents and Settings\username\Application Data".
  5121. On the Mac, it might be "~/Library". If you're going to store your settings in here,
  5122. always create your own sub-folder to put them in, to avoid making a mess.
  5123. */
  5124. userApplicationDataDirectory,
  5125. /** An equivalent of the userApplicationDataDirectory folder that is shared by all users
  5126. of the computer, rather than just the current user.
  5127. On the Mac it'll be "/Library", on Windows, it could be something like
  5128. "\Documents and Settings\All Users\Application Data".
  5129. Depending on the setup, this folder may be read-only.
  5130. */
  5131. commonApplicationDataDirectory,
  5132. /** The folder that should be used for temporary files.
  5133. Always delete them when you're finished, to keep the user's computer tidy!
  5134. */
  5135. tempDirectory,
  5136. /** Returns this application's executable file.
  5137. If running as a plug-in or DLL, this will (where possible) be the DLL rather than the
  5138. host app.
  5139. On the mac this will return the unix binary, not the package folder - see
  5140. currentApplicationFile for that.
  5141. */
  5142. currentExecutableFile,
  5143. /** Returns this application's location.
  5144. If running as a plug-in or DLL, this will (where possible) be the DLL rather than the
  5145. host app.
  5146. On the mac this will return the package folder (if it's in one), not the unix binary
  5147. that's inside it - compare with currentExecutableFile.
  5148. */
  5149. currentApplicationFile,
  5150. /** The directory in which applications normally get installed.
  5151. So on windows, this would be something like "c:\program files", on the
  5152. Mac "/Applications", or "/usr" on linux.
  5153. */
  5154. globalApplicationsDirectory,
  5155. /** The most likely place where a user might store their music files.
  5156. */
  5157. userMusicDirectory,
  5158. /** The most likely place where a user might store their movie files.
  5159. */
  5160. userMoviesDirectory,
  5161. };
  5162. /** Finds the location of a special type of file or directory, such as a home folder or
  5163. documents folder.
  5164. @see SpecialLocationType
  5165. */
  5166. static const File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type);
  5167. /** Returns a temporary file in the system's temp directory.
  5168. This will try to return the name of a non-existent temp file.
  5169. To get the temp folder, you can use getSpecialLocation (File::tempDirectory).
  5170. */
  5171. static const File createTempFile (const String& fileNameEnding) throw();
  5172. /** Returns the current working directory.
  5173. @see setAsCurrentWorkingDirectory
  5174. */
  5175. static const File getCurrentWorkingDirectory() throw();
  5176. /** Sets the current working directory to be this file.
  5177. For this to work the file must point to a valid directory.
  5178. @returns true if the current directory has been changed.
  5179. @see getCurrentWorkingDirectory
  5180. */
  5181. bool setAsCurrentWorkingDirectory() const throw();
  5182. /** The system-specific file separator character.
  5183. On Windows, this will be '\', on Mac/Linux, it'll be '/'
  5184. */
  5185. static const tchar separator;
  5186. /** The system-specific file separator character, as a string.
  5187. On Windows, this will be '\', on Mac/Linux, it'll be '/'
  5188. */
  5189. static const tchar* separatorString;
  5190. /** Removes illegal characters from a filename.
  5191. This will return a copy of the given string after removing characters
  5192. that are not allowed in a legal filename, and possibly shortening the
  5193. string if it's too long.
  5194. Because this will remove slashes, don't use it on an absolute pathname.
  5195. @see createLegalPathName
  5196. */
  5197. static const String createLegalFileName (const String& fileNameToFix) throw();
  5198. /** Removes illegal characters from a pathname.
  5199. Similar to createLegalFileName(), but this won't remove slashes, so can
  5200. be used on a complete pathname.
  5201. @see createLegalFileName
  5202. */
  5203. static const String createLegalPathName (const String& pathNameToFix) throw();
  5204. /** Indicates whether filenames are case-sensitive on the current operating system.
  5205. */
  5206. static bool areFileNamesCaseSensitive();
  5207. /** Returns true if the string seems to be a fully-specified absolute path.
  5208. */
  5209. static bool isAbsolutePath (const String& path) throw();
  5210. juce_UseDebuggingNewOperator
  5211. private:
  5212. String fullPath;
  5213. // internal way of contructing a file without checking the path
  5214. friend class DirectoryIterator;
  5215. File (const String&, int) throw();
  5216. const String getPathUpToLastSlash() const throw();
  5217. };
  5218. #endif // __JUCE_FILE_JUCEHEADER__
  5219. /********* End of inlined file: juce_File.h *********/
  5220. /**
  5221. A simple implemenation of a Logger that writes to a file.
  5222. @see Logger
  5223. */
  5224. class JUCE_API FileLogger : public Logger
  5225. {
  5226. public:
  5227. /** Creates a FileLogger for a given file.
  5228. @param fileToWriteTo the file that to use - new messages will be appended
  5229. to the file. If the file doesn't exist, it will be created,
  5230. along with any parent directories that are needed.
  5231. @param welcomeMessage when opened, the logger will write a header to the log, along
  5232. with the current date and time, and this welcome message
  5233. @param maxInitialFileSizeBytes if this is zero or greater, then if the file already exists
  5234. but is larger than this number of bytes, then the start of the
  5235. file will be truncated to keep the size down. This prevents a log
  5236. file getting ridiculously large over time. The file will be truncated
  5237. at a new-line boundary. If this value is less than zero, no size limit
  5238. will be imposed; if it's zero, the file will always be deleted. Note that
  5239. the size is only checked once when this object is created - any logging
  5240. that is done later will be appended without any checking
  5241. */
  5242. FileLogger (const File& fileToWriteTo,
  5243. const String& welcomeMessage,
  5244. const int maxInitialFileSizeBytes = 128 * 1024);
  5245. /** Destructor. */
  5246. ~FileLogger();
  5247. void logMessage (const String& message);
  5248. /** Helper function to create a log file in the correct place for this platform.
  5249. On Windows this will return a logger with a path such as:
  5250. c:\\Documents and Settings\\username\\Application Data\\[logFileSubDirectoryName]\\[logFileName]
  5251. On the Mac it'll create something like:
  5252. ~/Library/Logs/[logFileName]
  5253. The method might return 0 if the file can't be created for some reason.
  5254. @param logFileSubDirectoryName if a subdirectory is needed, this is what it will be called -
  5255. it's best to use the something like the name of your application here.
  5256. @param logFileName the name of the file to create, e.g. "MyAppLog.txt". Don't just
  5257. call it "log.txt" because if it goes in a directory with logs
  5258. from other applications (as it will do on the Mac) then no-one
  5259. will know which one is yours!
  5260. @param welcomeMessage a message that will be written to the log when it's opened.
  5261. @param maxInitialFileSizeBytes (see the FileLogger constructor for more info on this)
  5262. */
  5263. static FileLogger* createDefaultAppLogger (const String& logFileSubDirectoryName,
  5264. const String& logFileName,
  5265. const String& welcomeMessage,
  5266. const int maxInitialFileSizeBytes = 128 * 1024);
  5267. juce_UseDebuggingNewOperator
  5268. private:
  5269. File logFile;
  5270. CriticalSection logLock;
  5271. FileOutputStream* logStream;
  5272. void trimFileSize (int maxFileSizeBytes) const;
  5273. FileLogger (const FileLogger&);
  5274. const FileLogger& operator= (const FileLogger&);
  5275. };
  5276. #endif // __JUCE_FILELOGGER_JUCEHEADER__
  5277. /********* End of inlined file: juce_FileLogger.h *********/
  5278. #endif
  5279. #ifndef __JUCE_INITIALISATION_JUCEHEADER__
  5280. /********* Start of inlined file: juce_Initialisation.h *********/
  5281. #ifndef __JUCE_INITIALISATION_JUCEHEADER__
  5282. #define __JUCE_INITIALISATION_JUCEHEADER__
  5283. /** Initialises Juce's GUI classes.
  5284. If you're embedding Juce into an application that uses its own event-loop rather
  5285. than using the START_JUCE_APPLICATION macro, call this function before making any
  5286. Juce calls, to make sure things are initialised correctly.
  5287. Note that if you're creating a Juce DLL for Windows, you may also need to call the
  5288. PlatformUtilities::setCurrentModuleInstanceHandle() method.
  5289. @see shutdownJuce_GUI(), initialiseJuce_NonGUI()
  5290. */
  5291. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI();
  5292. /** Clears up any static data being used by Juce's GUI classes.
  5293. If you're embedding Juce into an application that uses its own event-loop rather
  5294. than using the START_JUCE_APPLICATION macro, call this function in your shutdown
  5295. code to clean up any juce objects that might be lying around.
  5296. @see initialiseJuce_GUI(), initialiseJuce_NonGUI()
  5297. */
  5298. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI();
  5299. /** Initialises the core parts of Juce.
  5300. If you're embedding Juce into either a command-line program, call this function
  5301. at the start of your main() function to make sure that Juce is initialised correctly.
  5302. Note that if you're creating a Juce DLL for Windows, you may also need to call the
  5303. PlatformUtilities::setCurrentModuleInstanceHandle() method.
  5304. @see shutdownJuce_NonGUI, initialiseJuce_GUI
  5305. */
  5306. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI();
  5307. /** Clears up any static data being used by Juce's non-gui core classes.
  5308. If you're embedding Juce into either a command-line program, call this function
  5309. at the end of your main() function if you want to make sure any Juce objects are
  5310. cleaned up correctly.
  5311. @see initialiseJuce_NonGUI, initialiseJuce_GUI
  5312. */
  5313. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI();
  5314. #endif // __JUCE_INITIALISATION_JUCEHEADER__
  5315. /********* End of inlined file: juce_Initialisation.h *********/
  5316. #endif
  5317. #ifndef __JUCE_LOGGER_JUCEHEADER__
  5318. #endif
  5319. #ifndef __JUCE_MATHSFUNCTIONS_JUCEHEADER__
  5320. #endif
  5321. #ifndef __JUCE_MEMORY_JUCEHEADER__
  5322. #endif
  5323. #ifndef __JUCE_PLATFORMDEFS_JUCEHEADER__
  5324. #endif
  5325. #ifndef __JUCE_RANDOM_JUCEHEADER__
  5326. /********* Start of inlined file: juce_Random.h *********/
  5327. #ifndef __JUCE_RANDOM_JUCEHEADER__
  5328. #define __JUCE_RANDOM_JUCEHEADER__
  5329. /**
  5330. A simple pseudo-random number generator.
  5331. */
  5332. class JUCE_API Random
  5333. {
  5334. public:
  5335. /** Creates a Random object based on a seed value.
  5336. For a given seed value, the subsequent numbers generated by this object
  5337. will be predictable, so a good idea is to set this value based
  5338. on the time, e.g.
  5339. new Random (Time::currentTimeMillis())
  5340. */
  5341. Random (const int64 seedValue) throw();
  5342. /** Destructor. */
  5343. ~Random() throw();
  5344. /** Returns the next random 32 bit integer.
  5345. @returns a random integer from the full range 0x80000000 to 0x7fffffff
  5346. */
  5347. int nextInt() throw();
  5348. /** Returns the next random number, limited to a given range.
  5349. @returns a random integer between 0 (inclusive) and maxValue (exclusive).
  5350. */
  5351. int nextInt (const int maxValue) throw();
  5352. /** Returns the next 64-bit random number.
  5353. @returns a random integer from the full range 0x8000000000000000 to 0x7fffffffffffffff
  5354. */
  5355. int64 nextInt64() throw();
  5356. /** Returns the next random floating-point number.
  5357. @returns a random value in the range 0 to 1.0
  5358. */
  5359. float nextFloat() throw();
  5360. /** Returns the next random floating-point number.
  5361. @returns a random value in the range 0 to 1.0
  5362. */
  5363. double nextDouble() throw();
  5364. /** Returns the next random boolean value.
  5365. */
  5366. bool nextBool() throw();
  5367. /** To avoid the overhead of having to create a new Random object whenever
  5368. you need a number, this is a shared application-wide object that
  5369. can be used.
  5370. It's not thread-safe though, so threads should use their own Random object.
  5371. */
  5372. static Random& getSystemRandom() throw();
  5373. /** Resets this Random object to a given seed value. */
  5374. void setSeed (const int64 newSeed) throw();
  5375. juce_UseDebuggingNewOperator
  5376. private:
  5377. int64 seed;
  5378. };
  5379. #endif // __JUCE_RANDOM_JUCEHEADER__
  5380. /********* End of inlined file: juce_Random.h *********/
  5381. #endif
  5382. #ifndef __JUCE_RELATIVETIME_JUCEHEADER__
  5383. #endif
  5384. #ifndef __JUCE_SINGLETON_JUCEHEADER__
  5385. /********* Start of inlined file: juce_Singleton.h *********/
  5386. #ifndef __JUCE_SINGLETON_JUCEHEADER__
  5387. #define __JUCE_SINGLETON_JUCEHEADER__
  5388. /********* Start of inlined file: juce_ScopedLock.h *********/
  5389. #ifndef __JUCE_SCOPEDLOCK_JUCEHEADER__
  5390. #define __JUCE_SCOPEDLOCK_JUCEHEADER__
  5391. /**
  5392. Automatically locks and unlocks a CriticalSection object.
  5393. Use one of these as a local variable to control access to a CriticalSection.
  5394. e.g. @code
  5395. CriticalSection myCriticalSection;
  5396. for (;;)
  5397. {
  5398. const ScopedLock myScopedLock (myCriticalSection);
  5399. // myCriticalSection is now locked
  5400. ...do some stuff...
  5401. // myCriticalSection gets unlocked here.
  5402. }
  5403. @endcode
  5404. @see CriticalSection, ScopedUnlock
  5405. */
  5406. class JUCE_API ScopedLock
  5407. {
  5408. public:
  5409. /** Creates a ScopedLock.
  5410. As soon as it is created, this will lock the CriticalSection, and
  5411. when the ScopedLock object is deleted, the CriticalSection will
  5412. be unlocked.
  5413. Make sure this object is created and deleted by the same thread,
  5414. otherwise there are no guarantees what will happen! Best just to use it
  5415. as a local stack object, rather than creating one with the new() operator.
  5416. */
  5417. inline ScopedLock (const CriticalSection& lock) throw() : lock_ (lock) { lock.enter(); }
  5418. /** Destructor.
  5419. The CriticalSection will be unlocked when the destructor is called.
  5420. Make sure this object is created and deleted by the same thread,
  5421. otherwise there are no guarantees what will happen!
  5422. */
  5423. inline ~ScopedLock() throw() { lock_.exit(); }
  5424. private:
  5425. const CriticalSection& lock_;
  5426. ScopedLock (const ScopedLock&);
  5427. const ScopedLock& operator= (const ScopedLock&);
  5428. };
  5429. /**
  5430. Automatically unlocks and re-locks a CriticalSection object.
  5431. This is the reverse of a ScopedLock object - instead of locking the critical
  5432. section for the lifetime of this object, it unlocks it.
  5433. Make sure you don't try to unlock critical sections that aren't actually locked!
  5434. e.g. @code
  5435. CriticalSection myCriticalSection;
  5436. for (;;)
  5437. {
  5438. const ScopedLock myScopedLock (myCriticalSection);
  5439. // myCriticalSection is now locked
  5440. ... do some stuff with it locked ..
  5441. while (xyz)
  5442. {
  5443. ... do some stuff with it locked ..
  5444. const ScopedUnlock unlocker (myCriticalSection);
  5445. // myCriticalSection is now unlocked for the remainder of this block,
  5446. // and re-locked at the end.
  5447. ...do some stuff with it unlocked ...
  5448. }
  5449. // myCriticalSection gets unlocked here.
  5450. }
  5451. @endcode
  5452. @see CriticalSection, ScopedLock
  5453. */
  5454. class ScopedUnlock
  5455. {
  5456. public:
  5457. /** Creates a ScopedUnlock.
  5458. As soon as it is created, this will unlock the CriticalSection, and
  5459. when the ScopedLock object is deleted, the CriticalSection will
  5460. be re-locked.
  5461. Make sure this object is created and deleted by the same thread,
  5462. otherwise there are no guarantees what will happen! Best just to use it
  5463. as a local stack object, rather than creating one with the new() operator.
  5464. */
  5465. inline ScopedUnlock (const CriticalSection& lock) throw() : lock_ (lock) { lock.exit(); }
  5466. /** Destructor.
  5467. The CriticalSection will be unlocked when the destructor is called.
  5468. Make sure this object is created and deleted by the same thread,
  5469. otherwise there are no guarantees what will happen!
  5470. */
  5471. inline ~ScopedUnlock() throw() { lock_.enter(); }
  5472. private:
  5473. const CriticalSection& lock_;
  5474. ScopedUnlock (const ScopedLock&);
  5475. const ScopedUnlock& operator= (const ScopedUnlock&);
  5476. };
  5477. #endif // __JUCE_SCOPEDLOCK_JUCEHEADER__
  5478. /********* End of inlined file: juce_ScopedLock.h *********/
  5479. /**
  5480. Macro to declare member variables and methods for a singleton class.
  5481. To use this, add the line juce_DeclareSingleton (MyClass, allowOnlyOneInstance)
  5482. to the class's definition.
  5483. If allowOnlyOneInstance == true, it won't allow the object to be created
  5484. more than once in the process's lifetime.
  5485. Then put a macro juce_ImplementSingleton (MyClass) along with the class's
  5486. implementation code.
  5487. Clients can then call the static MyClass::getInstance() to get a pointer to the
  5488. singleton, or MyClass::getInstanceWithoutCreating() which may return 0 if no instance
  5489. is currently extant
  5490. it's a very good idea to also add the call clearSingletonInstance() to the
  5491. destructor of the class, in case it is deleted by other means than deleteInstance()
  5492. e.g. @code
  5493. class MySingleton
  5494. {
  5495. public:
  5496. MySingleton()
  5497. {
  5498. }
  5499. ~MySingleton()
  5500. {
  5501. // this ensures that no dangling pointers are left when the
  5502. // singleton is deleted.
  5503. clearSingletonInstance();
  5504. }
  5505. juce_DeclareSingleton (MySingleton, false)
  5506. };
  5507. juce_ImplementSingleton (MySingleton)
  5508. // example of usage:
  5509. MySingleton* m = MySingleton::getInstance(); // creates the singleton if there isn't already one.
  5510. ...
  5511. MySingleton::deleteInstance(); // safely deletes the singleton (if it's been created).
  5512. @endcode
  5513. If you know that your object will only be created and deleted by a single thread, you
  5514. can use the slightly more efficient juce_DeclareSingleton_SingleThreaded() macro instead
  5515. of this one.
  5516. @see juce_ImplementSingleton, juce_DeclareSingleton_SingleThreaded
  5517. */
  5518. #define juce_DeclareSingleton(classname, allowOnlyOneInstance) \
  5519. \
  5520. static classname* _singletonInstance; \
  5521. static JUCE_NAMESPACE::CriticalSection _singletonLock; \
  5522. \
  5523. static classname* getInstance() \
  5524. { \
  5525. if (_singletonInstance == 0) \
  5526. {\
  5527. const JUCE_NAMESPACE::ScopedLock sl (_singletonLock); \
  5528. \
  5529. if (_singletonInstance == 0) \
  5530. { \
  5531. static bool alreadyInside = false; \
  5532. static bool createdOnceAlready = false; \
  5533. \
  5534. const bool problem = alreadyInside || ((allowOnlyOneInstance) && createdOnceAlready); \
  5535. jassert (! problem); \
  5536. if (! problem) \
  5537. { \
  5538. createdOnceAlready = true; \
  5539. alreadyInside = true; \
  5540. classname* newObject = new classname(); /* (use a stack variable to avoid setting the newObject value before the class has finished its constructor) */ \
  5541. alreadyInside = false; \
  5542. \
  5543. _singletonInstance = newObject; \
  5544. } \
  5545. } \
  5546. } \
  5547. \
  5548. return _singletonInstance; \
  5549. } \
  5550. \
  5551. static inline classname* getInstanceWithoutCreating() throw() \
  5552. { \
  5553. return _singletonInstance; \
  5554. } \
  5555. \
  5556. static void deleteInstance() \
  5557. { \
  5558. const JUCE_NAMESPACE::ScopedLock sl (_singletonLock); \
  5559. if (_singletonInstance != 0) \
  5560. { \
  5561. classname* const old = _singletonInstance; \
  5562. _singletonInstance = 0; \
  5563. delete old; \
  5564. } \
  5565. } \
  5566. \
  5567. void clearSingletonInstance() throw() \
  5568. { \
  5569. if (_singletonInstance == this) \
  5570. _singletonInstance = 0; \
  5571. }
  5572. /** This is a counterpart to the juce_DeclareSingleton macro.
  5573. After adding the juce_DeclareSingleton to the class definition, this macro has
  5574. to be used in the cpp file.
  5575. */
  5576. #define juce_ImplementSingleton(classname) \
  5577. \
  5578. classname* classname::_singletonInstance = 0; \
  5579. JUCE_NAMESPACE::CriticalSection classname::_singletonLock;
  5580. /**
  5581. Macro to declare member variables and methods for a singleton class.
  5582. This is exactly the same as juce_DeclareSingleton, but doesn't use a critical
  5583. section to make access to it thread-safe. If you know that your object will
  5584. only ever be created or deleted by a single thread, then this is a
  5585. more efficient version to use.
  5586. See the documentation for juce_DeclareSingleton for more information about
  5587. how to use it, the only difference being that you have to use
  5588. juce_ImplementSingleton_SingleThreaded instead of juce_ImplementSingleton.
  5589. @see juce_ImplementSingleton_SingleThreaded, juce_DeclareSingleton, juce_DeclareSingleton_SingleThreaded_Minimal
  5590. */
  5591. #define juce_DeclareSingleton_SingleThreaded(classname, allowOnlyOneInstance) \
  5592. \
  5593. static classname* _singletonInstance; \
  5594. \
  5595. static classname* getInstance() \
  5596. { \
  5597. if (_singletonInstance == 0) \
  5598. { \
  5599. static bool alreadyInside = false; \
  5600. static bool createdOnceAlready = false; \
  5601. \
  5602. const bool problem = alreadyInside || ((allowOnlyOneInstance) && createdOnceAlready); \
  5603. jassert (! problem); \
  5604. if (! problem) \
  5605. { \
  5606. createdOnceAlready = true; \
  5607. alreadyInside = true; \
  5608. classname* newObject = new classname(); /* (use a stack variable to avoid setting the newObject value before the class has finished its constructor) */ \
  5609. alreadyInside = false; \
  5610. \
  5611. _singletonInstance = newObject; \
  5612. } \
  5613. } \
  5614. \
  5615. return _singletonInstance; \
  5616. } \
  5617. \
  5618. static inline classname* getInstanceWithoutCreating() throw() \
  5619. { \
  5620. return _singletonInstance; \
  5621. } \
  5622. \
  5623. static void deleteInstance() \
  5624. { \
  5625. if (_singletonInstance != 0) \
  5626. { \
  5627. classname* const old = _singletonInstance; \
  5628. _singletonInstance = 0; \
  5629. delete old; \
  5630. } \
  5631. } \
  5632. \
  5633. void clearSingletonInstance() throw() \
  5634. { \
  5635. if (_singletonInstance == this) \
  5636. _singletonInstance = 0; \
  5637. }
  5638. /**
  5639. Macro to declare member variables and methods for a singleton class.
  5640. This is like juce_DeclareSingleton_SingleThreaded, but doesn't do any checking
  5641. for recursion or repeated instantiation. It's intended for use as a lightweight
  5642. version of a singleton, where you're using it in very straightforward
  5643. circumstances and don't need the extra checking.
  5644. Juce use the normal juce_ImplementSingleton_SingleThreaded as the counterpart
  5645. to this declaration, as you would with juce_DeclareSingleton_SingleThreaded.
  5646. See the documentation for juce_DeclareSingleton for more information about
  5647. how to use it, the only difference being that you have to use
  5648. juce_ImplementSingleton_SingleThreaded instead of juce_ImplementSingleton.
  5649. @see juce_ImplementSingleton_SingleThreaded, juce_DeclareSingleton
  5650. */
  5651. #define juce_DeclareSingleton_SingleThreaded_Minimal(classname) \
  5652. \
  5653. static classname* _singletonInstance; \
  5654. \
  5655. static classname* getInstance() \
  5656. { \
  5657. if (_singletonInstance == 0) \
  5658. _singletonInstance = new classname(); \
  5659. \
  5660. return _singletonInstance; \
  5661. } \
  5662. \
  5663. static inline classname* getInstanceWithoutCreating() throw() \
  5664. { \
  5665. return _singletonInstance; \
  5666. } \
  5667. \
  5668. static void deleteInstance() \
  5669. { \
  5670. if (_singletonInstance != 0) \
  5671. { \
  5672. classname* const old = _singletonInstance; \
  5673. _singletonInstance = 0; \
  5674. delete old; \
  5675. } \
  5676. } \
  5677. \
  5678. void clearSingletonInstance() throw() \
  5679. { \
  5680. if (_singletonInstance == this) \
  5681. _singletonInstance = 0; \
  5682. }
  5683. /** This is a counterpart to the juce_DeclareSingleton_SingleThreaded macro.
  5684. After adding juce_DeclareSingleton_SingleThreaded or juce_DeclareSingleton_SingleThreaded_Minimal
  5685. to the class definition, this macro has to be used somewhere in the cpp file.
  5686. */
  5687. #define juce_ImplementSingleton_SingleThreaded(classname) \
  5688. \
  5689. classname* classname::_singletonInstance = 0;
  5690. #endif // __JUCE_SINGLETON_JUCEHEADER__
  5691. /********* End of inlined file: juce_Singleton.h *********/
  5692. #endif
  5693. #ifndef __JUCE_STANDARDHEADER_JUCEHEADER__
  5694. #endif
  5695. #ifndef __JUCE_SYSTEMSTATS_JUCEHEADER__
  5696. /********* Start of inlined file: juce_SystemStats.h *********/
  5697. #ifndef __JUCE_SYSTEMSTATS_JUCEHEADER__
  5698. #define __JUCE_SYSTEMSTATS_JUCEHEADER__
  5699. /**
  5700. Contains methods for finding out about the current hardware and OS configuration.
  5701. */
  5702. class JUCE_API SystemStats
  5703. {
  5704. public:
  5705. /** Returns the current version of JUCE,
  5706. (just in case you didn't already know at compile-time.)
  5707. See also the JUCE_VERSION, JUCE_MAJOR_VERSION and JUCE_MINOR_VERSION macros.
  5708. */
  5709. static const String getJUCEVersion() throw();
  5710. /** The set of possible results of the getOperatingSystemType() method.
  5711. */
  5712. enum OperatingSystemType
  5713. {
  5714. UnknownOS = 0,
  5715. MacOSX = 0x1000,
  5716. Linux = 0x2000,
  5717. Win95 = 0x4001,
  5718. Win98 = 0x4002,
  5719. WinNT351 = 0x4103,
  5720. WinNT40 = 0x4104,
  5721. Win2000 = 0x4105,
  5722. WinXP = 0x4106,
  5723. WinVista = 0x4107,
  5724. Windows = 0x4000, /**< To test whether any version of Windows is running,
  5725. you can use the expression ((getOperatingSystemType() & Windows) != 0). */
  5726. WindowsNT = 0x0100, /**< To test whether the platform is Windows NT or later (i.e. not Win95 or 98),
  5727. you can use the expression ((getOperatingSystemType() & WindowsNT) != 0). */
  5728. };
  5729. /** Returns the type of operating system we're running on.
  5730. @returns one of the values from the OperatingSystemType enum.
  5731. @see getOperatingSystemName
  5732. */
  5733. static OperatingSystemType getOperatingSystemType() throw();
  5734. /** Returns the name of the type of operating system we're running on.
  5735. @returns a string describing the OS type.
  5736. @see getOperatingSystemType
  5737. */
  5738. static const String getOperatingSystemName() throw();
  5739. /** Returns true if the OS is 64-bit, or false for a 32-bit OS.
  5740. */
  5741. static bool isOperatingSystem64Bit() throw();
  5742. // CPU and memory information..
  5743. /** Returns the approximate CPU speed.
  5744. @returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on
  5745. what year you're reading this...)
  5746. */
  5747. static int getCpuSpeedInMegaherz() throw();
  5748. /** Returns a string to indicate the CPU vendor.
  5749. Might not be known on some systems.
  5750. */
  5751. static const String getCpuVendor() throw();
  5752. /** Checks whether Intel MMX instructions are available. */
  5753. static bool hasMMX() throw();
  5754. /** Checks whether Intel SSE instructions are available. */
  5755. static bool hasSSE() throw();
  5756. /** Checks whether Intel SSE2 instructions are available. */
  5757. static bool hasSSE2() throw();
  5758. /** Checks whether AMD 3DNOW instructions are available. */
  5759. static bool has3DNow() throw();
  5760. /** Returns the number of CPUs.
  5761. */
  5762. static int getNumCpus() throw();
  5763. /** Returns a clock-cycle tick counter, if available.
  5764. If the machine can do it, this will return a tick-count
  5765. where each tick is one cpu clock cycle - used for profiling
  5766. code.
  5767. @returns the tick count, or zero if not available.
  5768. */
  5769. static int64 getClockCycleCounter() throw();
  5770. /** Finds out how much RAM is in the machine.
  5771. @returns the approximate number of megabytes of memory, or zero if
  5772. something goes wrong when finding out.
  5773. */
  5774. static int getMemorySizeInMegabytes() throw();
  5775. /** Returns the system page-size.
  5776. This is only used by programmers with beards.
  5777. */
  5778. static int getPageSize() throw();
  5779. /** Returns a list of MAC addresses found on this machine.
  5780. @param addresses an array into which the MAC addresses should be copied
  5781. @param maxNum the number of elements in this array
  5782. @param littleEndian the endianness of the numbers to return. Note that
  5783. the default values of this parameter are different on
  5784. Mac/PC to avoid breaking old software that was written
  5785. before this parameter was added (when the two systems
  5786. defaulted to using different endiannesses). In newer
  5787. software you probably want to specify an explicit value
  5788. for this.
  5789. @returns the number of MAC addresses that were found
  5790. */
  5791. static int getMACAddresses (int64* addresses, int maxNum,
  5792. #if JUCE_MAC
  5793. const bool littleEndian = true) throw();
  5794. #else
  5795. const bool littleEndian = false) throw();
  5796. #endif
  5797. // not-for-public-use platform-specific method gets called at startup to initialise things.
  5798. static void initialiseStats() throw();
  5799. };
  5800. #endif // __JUCE_SYSTEMSTATS_JUCEHEADER__
  5801. /********* End of inlined file: juce_SystemStats.h *********/
  5802. #endif
  5803. #ifndef __JUCE_TIME_JUCEHEADER__
  5804. #endif
  5805. #ifndef __JUCE_ARRAY_JUCEHEADER__
  5806. #endif
  5807. #ifndef __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__
  5808. #endif
  5809. #ifndef __JUCE_BITARRAY_JUCEHEADER__
  5810. /********* Start of inlined file: juce_BitArray.h *********/
  5811. #ifndef __JUCE_BITARRAY_JUCEHEADER__
  5812. #define __JUCE_BITARRAY_JUCEHEADER__
  5813. class MemoryBlock;
  5814. /**
  5815. An array of on/off bits, also usable to store large binary integers.
  5816. A BitArray acts like an arbitrarily large integer whose bits can be set or
  5817. cleared, and some basic mathematical operations can be done on the number as
  5818. a whole.
  5819. */
  5820. class JUCE_API BitArray
  5821. {
  5822. public:
  5823. /** Creates an empty BitArray */
  5824. BitArray() throw();
  5825. /** Creates a BitArray containing an integer value in its low bits.
  5826. The low 32 bits of the array are initialised with this value.
  5827. */
  5828. BitArray (const unsigned int value) throw();
  5829. /** Creates a BitArray containing an integer value in its low bits.
  5830. The low 32 bits of the array are initialised with the absolute value
  5831. passed in, and its sign is set to reflect the sign of the number.
  5832. */
  5833. BitArray (const int value) throw();
  5834. /** Creates a BitArray containing an integer value in its low bits.
  5835. The low 64 bits of the array are initialised with the absolute value
  5836. passed in, and its sign is set to reflect the sign of the number.
  5837. */
  5838. BitArray (int64 value) throw();
  5839. /** Creates a copy of another BitArray. */
  5840. BitArray (const BitArray& other) throw();
  5841. /** Destructor. */
  5842. ~BitArray() throw();
  5843. /** Copies another BitArray onto this one. */
  5844. const BitArray& operator= (const BitArray& other) throw();
  5845. /** Two arrays are the same if the same bits are set. */
  5846. bool operator== (const BitArray& other) const throw();
  5847. /** Two arrays are the same if the same bits are set. */
  5848. bool operator!= (const BitArray& other) const throw();
  5849. /** Clears all bits in the BitArray to 0. */
  5850. void clear() throw();
  5851. /** Clears a particular bit in the array. */
  5852. void clearBit (const int bitNumber) throw();
  5853. /** Sets a specified bit to 1.
  5854. If the bit number is high, this will grow the array to accomodate it.
  5855. */
  5856. void setBit (const int bitNumber) throw();
  5857. /** Sets or clears a specified bit. */
  5858. void setBit (const int bitNumber,
  5859. const bool shouldBeSet) throw();
  5860. /** Sets a range of bits to be either on or off.
  5861. @param startBit the first bit to change
  5862. @param numBits the number of bits to change
  5863. @param shouldBeSet whether to turn these bits on or off
  5864. */
  5865. void setRange (int startBit,
  5866. int numBits,
  5867. const bool shouldBeSet) throw();
  5868. /** Inserts a bit an a given position, shifting up any bits above it. */
  5869. void insertBit (const int bitNumber,
  5870. const bool shouldBeSet) throw();
  5871. /** Returns the value of a specified bit in the array.
  5872. If the index is out-of-range, the result will be false.
  5873. */
  5874. bool operator[] (const int bit) const throw();
  5875. /** Returns true if no bits are set. */
  5876. bool isEmpty() const throw();
  5877. /** Returns a range of bits in the array as an integer value.
  5878. e.g. getBitRangeAsInt (0, 32) would return the lowest 32 bits.
  5879. Asking for more than 32 bits isn't allowed (obviously).
  5880. */
  5881. int getBitRangeAsInt (int startBit, int numBits) const throw();
  5882. /** Sets a range of bits in the array based on an integer value.
  5883. Copies the given integer into the array, starting at startBit,
  5884. and only using up to numBits of the available bits.
  5885. */
  5886. void setBitRangeAsInt (int startBit, int numBits,
  5887. unsigned int valueToSet) throw();
  5888. /** Performs a bitwise OR with another BitArray.
  5889. The result ends up in this array.
  5890. */
  5891. void orWith (const BitArray& other) throw();
  5892. /** Performs a bitwise AND with another BitArray.
  5893. The result ends up in this array.
  5894. */
  5895. void andWith (const BitArray& other) throw();
  5896. /** Performs a bitwise XOR with another BitArray.
  5897. The result ends up in this array.
  5898. */
  5899. void xorWith (const BitArray& other) throw();
  5900. /** Adds another BitArray's value to this one.
  5901. Treating the two arrays as large positive integers, this
  5902. adds them up and puts the result in this array.
  5903. */
  5904. void add (const BitArray& other) throw();
  5905. /** Subtracts another BitArray's value from this one.
  5906. Treating the two arrays as large positive integers, this
  5907. subtracts them and puts the result in this array.
  5908. Note that if the result should be negative, this won't be
  5909. handled correctly.
  5910. */
  5911. void subtract (const BitArray& other) throw();
  5912. /** Multiplies another BitArray's value with this one.
  5913. Treating the two arrays as large positive integers, this
  5914. multiplies them and puts the result in this array.
  5915. */
  5916. void multiplyBy (const BitArray& other) throw();
  5917. /** Divides another BitArray's value into this one and also produces a remainder.
  5918. Treating the two arrays as large positive integers, this
  5919. divides this value by the other, leaving the quotient in this
  5920. array, and the remainder is copied into the other BitArray passed in.
  5921. */
  5922. void divideBy (const BitArray& divisor, BitArray& remainder) throw();
  5923. /** Returns the largest value that will divide both this value and the one
  5924. passed-in.
  5925. */
  5926. const BitArray findGreatestCommonDivisor (BitArray other) const throw();
  5927. /** Performs a modulo operation on this value.
  5928. The result is stored in this value.
  5929. */
  5930. void modulo (const BitArray& divisor) throw();
  5931. /** Performs a combined exponent and modulo operation.
  5932. This BitArray's value becomes (this ^ exponent) % modulus.
  5933. */
  5934. void exponentModulo (const BitArray& exponent, const BitArray& modulus) throw();
  5935. /** Performs an inverse modulo on the value.
  5936. i.e. the result is (this ^ -1) mod (modulus).
  5937. */
  5938. void inverseModulo (const BitArray& modulus) throw();
  5939. /** Shifts a section of bits left or right.
  5940. @param howManyBitsLeft how far to move the bits (+ve numbers shift it left, -ve numbers shift it right).
  5941. @param startBit the first bit to affect - if this is > 0, only bits above that index will be affected.
  5942. */
  5943. void shiftBits (int howManyBitsLeft,
  5944. int startBit = 0) throw();
  5945. /** Does a signed comparison of two BitArrays.
  5946. Return values are:
  5947. - 0 if the numbers are the same
  5948. - < 0 if this number is smaller than the other
  5949. - > 0 if this number is bigger than the other
  5950. */
  5951. int compare (const BitArray& other) const throw();
  5952. /** Compares the magnitudes of two BitArrays, ignoring their signs.
  5953. Return values are:
  5954. - 0 if the numbers are the same
  5955. - < 0 if this number is smaller than the other
  5956. - > 0 if this number is bigger than the other
  5957. */
  5958. int compareAbsolute (const BitArray& other) const throw();
  5959. /** Returns true if the value is less than zero.
  5960. @see setNegative, negate
  5961. */
  5962. bool isNegative() const throw();
  5963. /** Changes the sign of the number to be positive or negative.
  5964. @see isNegative, negate
  5965. */
  5966. void setNegative (const bool shouldBeNegative) throw();
  5967. /** Inverts the sign of the number.
  5968. @see isNegative, setNegative
  5969. */
  5970. void negate() throw();
  5971. /** Counts the total number of set bits in the array. */
  5972. int countNumberOfSetBits() const throw();
  5973. /** Looks for the index of the next set bit after a given starting point.
  5974. searches from startIndex (inclusive) upwards for the first set bit,
  5975. and returns its index.
  5976. If no set bits are found, it returns -1.
  5977. */
  5978. int findNextSetBit (int startIndex = 0) const throw();
  5979. /** Looks for the index of the next clear bit after a given starting point.
  5980. searches from startIndex (inclusive) upwards for the first clear bit,
  5981. and returns its index.
  5982. */
  5983. int findNextClearBit (int startIndex = 0) const throw();
  5984. /** Returns the index of the highest set bit in the array.
  5985. If the array is empty, this will return -1.
  5986. */
  5987. int getHighestBit() const throw();
  5988. /** Sets a range of bits to random values. */
  5989. void fillBitsRandomly (int startBit, int numBits) throw();
  5990. /** Turns this value into a random number less than the given value. */
  5991. void createRandomNumber (const BitArray& maximumValue) throw();
  5992. /** Converts the array to a number string.
  5993. Specify a base such as 2 (binary), 8 (octal), 10 (decimal), 16 (hex).
  5994. */
  5995. const String toString (const int base) const throw();
  5996. /** Converts a number string to an array.
  5997. Any non-valid characters will be ignored.
  5998. Specify a base such as 2 (binary), 8 (octal), 10 (decimal), 16 (hex).
  5999. */
  6000. void parseString (const String& text,
  6001. const int base) throw();
  6002. /** Turns the array into a block of binary data.
  6003. The data is arranged as little-endian, so the first byte of data is the low 8 bits
  6004. of the array, and so on.
  6005. @see loadFromMemoryBlock
  6006. */
  6007. const MemoryBlock toMemoryBlock() const throw();
  6008. /** Copies a block of raw data onto this array.
  6009. The data is arranged as little-endian, so the first byte of data is the low 8 bits
  6010. of the array, and so on.
  6011. @see toMemoryBlock
  6012. */
  6013. void loadFromMemoryBlock (const MemoryBlock& data) throw();
  6014. juce_UseDebuggingNewOperator
  6015. private:
  6016. void ensureSize (const int numVals) throw();
  6017. unsigned int* values;
  6018. int numValues, highestBit;
  6019. bool negative;
  6020. };
  6021. #endif // __JUCE_BITARRAY_JUCEHEADER__
  6022. /********* End of inlined file: juce_BitArray.h *********/
  6023. #endif
  6024. #ifndef __JUCE_ELEMENTCOMPARATOR_JUCEHEADER__
  6025. #endif
  6026. #ifndef __JUCE_MEMORYBLOCK_JUCEHEADER__
  6027. #endif
  6028. #ifndef __JUCE_OWNEDARRAY_JUCEHEADER__
  6029. #endif
  6030. #ifndef __JUCE_PROPERTYSET_JUCEHEADER__
  6031. /********* Start of inlined file: juce_PropertySet.h *********/
  6032. #ifndef __JUCE_PROPERTYSET_JUCEHEADER__
  6033. #define __JUCE_PROPERTYSET_JUCEHEADER__
  6034. /********* Start of inlined file: juce_StringPairArray.h *********/
  6035. #ifndef __JUCE_STRINGPAIRARRAY_JUCEHEADER__
  6036. #define __JUCE_STRINGPAIRARRAY_JUCEHEADER__
  6037. /**
  6038. A container for holding a set of strings which are keyed by another string.
  6039. @see StringArray
  6040. */
  6041. class JUCE_API StringPairArray
  6042. {
  6043. public:
  6044. /** Creates an empty array */
  6045. StringPairArray (const bool ignoreCaseWhenComparingKeys = true) throw();
  6046. /** Creates a copy of another array */
  6047. StringPairArray (const StringPairArray& other) throw();
  6048. /** Destructor. */
  6049. ~StringPairArray() throw();
  6050. /** Copies the contents of another string array into this one */
  6051. const StringPairArray& operator= (const StringPairArray& other) throw();
  6052. /** Compares two arrays.
  6053. Comparisons are case-sensitive.
  6054. @returns true only if the other array contains exactly the same strings with the same keys
  6055. */
  6056. bool operator== (const StringPairArray& other) const throw();
  6057. /** Compares two arrays.
  6058. Comparisons are case-sensitive.
  6059. @returns false if the other array contains exactly the same strings with the same keys
  6060. */
  6061. bool operator!= (const StringPairArray& other) const throw();
  6062. /** Finds the value corresponding to a key string.
  6063. If no such key is found, this will just return an empty string. To check whether
  6064. a given key actually exists (because it might actually be paired with an empty string), use
  6065. the getAllKeys() method to obtain a list.
  6066. Obviously the reference returned shouldn't be stored for later use, as the
  6067. string it refers to may disappear when the array changes.
  6068. @see getValue
  6069. */
  6070. const String& operator[] (const String& key) const throw();
  6071. /** Finds the value corresponding to a key string.
  6072. If no such key is found, this will just return the value provided as a default.
  6073. @see operator[]
  6074. */
  6075. const String getValue (const String& key, const String& defaultReturnValue) const;
  6076. /** Returns a list of all keys in the array. */
  6077. const StringArray& getAllKeys() const throw() { return keys; }
  6078. /** Returns a list of all values in the array. */
  6079. const StringArray& getAllValues() const throw() { return values; }
  6080. /** Returns the number of strings in the array */
  6081. inline int size() const throw() { return keys.size(); };
  6082. /** Adds or amends a key/value pair.
  6083. If a value already exists with this key, its value will be overwritten,
  6084. otherwise the key/value pair will be added to the array.
  6085. */
  6086. void set (const String& key,
  6087. const String& value) throw();
  6088. /** Adds the items from another array to this one.
  6089. This is equivalent to using set() to add each of the pairs from the other array.
  6090. */
  6091. void addArray (const StringPairArray& other);
  6092. /** Removes all elements from the array. */
  6093. void clear() throw();
  6094. /** Removes a string from the array based on its key.
  6095. If the key isn't found, nothing will happen.
  6096. */
  6097. void remove (const String& key) throw();
  6098. /** Removes a string from the array based on its index.
  6099. If the index is out-of-range, no action will be taken.
  6100. */
  6101. void remove (const int index) throw();
  6102. /** Reduces the amount of storage being used by the array.
  6103. Arrays typically allocate slightly more storage than they need, and after
  6104. removing elements, they may have quite a lot of unused space allocated.
  6105. This method will reduce the amount of allocated storage to a minimum.
  6106. */
  6107. void minimiseStorageOverheads() throw();
  6108. juce_UseDebuggingNewOperator
  6109. private:
  6110. StringArray keys, values;
  6111. bool ignoreCase;
  6112. };
  6113. #endif // __JUCE_STRINGPAIRARRAY_JUCEHEADER__
  6114. /********* End of inlined file: juce_StringPairArray.h *********/
  6115. /********* Start of inlined file: juce_XmlElement.h *********/
  6116. #ifndef __JUCE_XMLELEMENT_JUCEHEADER__
  6117. #define __JUCE_XMLELEMENT_JUCEHEADER__
  6118. /********* Start of inlined file: juce_OutputStream.h *********/
  6119. #ifndef __JUCE_OUTPUTSTREAM_JUCEHEADER__
  6120. #define __JUCE_OUTPUTSTREAM_JUCEHEADER__
  6121. /********* Start of inlined file: juce_InputStream.h *********/
  6122. #ifndef __JUCE_INPUTSTREAM_JUCEHEADER__
  6123. #define __JUCE_INPUTSTREAM_JUCEHEADER__
  6124. /** The base class for streams that read data.
  6125. Input and output streams are used throughout the library - subclasses can override
  6126. some or all of the virtual functions to implement their behaviour.
  6127. @see OutputStream, MemoryInputStream, BufferedInputStream, FileInputStream
  6128. */
  6129. class JUCE_API InputStream
  6130. {
  6131. public:
  6132. /** Destructor. */
  6133. virtual ~InputStream() {}
  6134. /** Returns the total number of bytes available for reading in this stream.
  6135. Note that this is the number of bytes available from the start of the
  6136. stream, not from the current position.
  6137. If the size of the stream isn't actually known, this may return -1.
  6138. */
  6139. virtual int64 getTotalLength() = 0;
  6140. /** Returns true if the stream has no more data to read. */
  6141. virtual bool isExhausted() = 0;
  6142. /** Reads a set of bytes from the stream into a memory buffer.
  6143. This is the only read method that subclasses actually need to implement, as the
  6144. InputStream base class implements the other read methods in terms of this one (although
  6145. it's often more efficient for subclasses to implement them directly).
  6146. @param destBuffer the destination buffer for the data
  6147. @param maxBytesToRead the maximum number of bytes to read - make sure the
  6148. memory block passed in is big enough to contain this
  6149. many bytes.
  6150. @returns the actual number of bytes that were read, which may be less than
  6151. maxBytesToRead if the stream is exhausted before it gets that far
  6152. */
  6153. virtual int read (void* destBuffer,
  6154. int maxBytesToRead) = 0;
  6155. /** Reads a byte from the stream.
  6156. If the stream is exhausted, this will return zero.
  6157. @see OutputStream::writeByte
  6158. */
  6159. virtual char readByte();
  6160. /** Reads a boolean from the stream.
  6161. The bool is encoded as a single byte - 1 for true, 0 for false.
  6162. If the stream is exhausted, this will return false.
  6163. @see OutputStream::writeBool
  6164. */
  6165. virtual bool readBool();
  6166. /** Reads two bytes from the stream as a little-endian 16-bit value.
  6167. If the next two bytes read are byte1 and byte2, this returns
  6168. (byte1 | (byte2 << 8)).
  6169. If the stream is exhausted partway through reading the bytes, this will return zero.
  6170. @see OutputStream::writeShort, readShortBigEndian
  6171. */
  6172. virtual short readShort();
  6173. /** Reads two bytes from the stream as a little-endian 16-bit value.
  6174. If the next two bytes read are byte1 and byte2, this returns
  6175. (byte2 | (byte1 << 8)).
  6176. If the stream is exhausted partway through reading the bytes, this will return zero.
  6177. @see OutputStream::writeShortBigEndian, readShort
  6178. */
  6179. virtual short readShortBigEndian();
  6180. /** Reads four bytes from the stream as a little-endian 32-bit value.
  6181. If the next four bytes are byte1 to byte4, this returns
  6182. (byte1 | (byte2 << 8) | (byte3 << 16) | (byte4 << 24)).
  6183. If the stream is exhausted partway through reading the bytes, this will return zero.
  6184. @see OutputStream::writeInt, readIntBigEndian
  6185. */
  6186. virtual int readInt();
  6187. /** Reads four bytes from the stream as a big-endian 32-bit value.
  6188. If the next four bytes are byte1 to byte4, this returns
  6189. (byte4 | (byte3 << 8) | (byte2 << 16) | (byte1 << 24)).
  6190. If the stream is exhausted partway through reading the bytes, this will return zero.
  6191. @see OutputStream::writeIntBigEndian, readInt
  6192. */
  6193. virtual int readIntBigEndian();
  6194. /** Reads eight bytes from the stream as a little-endian 64-bit value.
  6195. If the next eight bytes are byte1 to byte8, this returns
  6196. (byte1 | (byte2 << 8) | (byte3 << 16) | (byte4 << 24) | (byte5 << 32) | (byte6 << 40) | (byte7 << 48) | (byte8 << 56)).
  6197. If the stream is exhausted partway through reading the bytes, this will return zero.
  6198. @see OutputStream::writeInt64, readInt64BigEndian
  6199. */
  6200. virtual int64 readInt64();
  6201. /** Reads eight bytes from the stream as a big-endian 64-bit value.
  6202. If the next eight bytes are byte1 to byte8, this returns
  6203. (byte8 | (byte7 << 8) | (byte6 << 16) | (byte5 << 24) | (byte4 << 32) | (byte3 << 40) | (byte2 << 48) | (byte1 << 56)).
  6204. If the stream is exhausted partway through reading the bytes, this will return zero.
  6205. @see OutputStream::writeInt64BigEndian, readInt64
  6206. */
  6207. virtual int64 readInt64BigEndian();
  6208. /** Reads four bytes as a 32-bit floating point value.
  6209. The raw 32-bit encoding of the float is read from the stream as a little-endian int.
  6210. If the stream is exhausted partway through reading the bytes, this will return zero.
  6211. @see OutputStream::writeFloat, readDouble
  6212. */
  6213. virtual float readFloat();
  6214. /** Reads four bytes as a 32-bit floating point value.
  6215. The raw 32-bit encoding of the float is read from the stream as a big-endian int.
  6216. If the stream is exhausted partway through reading the bytes, this will return zero.
  6217. @see OutputStream::writeFloatBigEndian, readDoubleBigEndian
  6218. */
  6219. virtual float readFloatBigEndian();
  6220. /** Reads eight bytes as a 64-bit floating point value.
  6221. The raw 64-bit encoding of the double is read from the stream as a little-endian int64.
  6222. If the stream is exhausted partway through reading the bytes, this will return zero.
  6223. @see OutputStream::writeDouble, readFloat
  6224. */
  6225. virtual double readDouble();
  6226. /** Reads eight bytes as a 64-bit floating point value.
  6227. The raw 64-bit encoding of the double is read from the stream as a big-endian int64.
  6228. If the stream is exhausted partway through reading the bytes, this will return zero.
  6229. @see OutputStream::writeDoubleBigEndian, readFloatBigEndian
  6230. */
  6231. virtual double readDoubleBigEndian();
  6232. /** Reads an encoded 32-bit number from the stream using a space-saving compressed format.
  6233. For small values, this is more space-efficient than using readInt() and OutputStream::writeInt()
  6234. The format used is: number of significant bytes + up to 4 bytes in little-endian order.
  6235. @see OutputStream::writeCompressedInt()
  6236. */
  6237. virtual int readCompressedInt();
  6238. /** Reads a string from the stream, up to the next linefeed or carriage return.
  6239. The stream is treated as 8-bit characters encoded with the system's default encoding,
  6240. and this will read up to the next "\n" or "\r\n" or end-of-stream.
  6241. After this call, the stream's position will be left pointing to the character
  6242. following the line-feed, but the linefeeds aren't included in the string that
  6243. is returned.
  6244. */
  6245. virtual const String readNextLine();
  6246. /** Reads a zero-terminated string from the stream.
  6247. This will read characters from the stream until it hits a zero character or
  6248. end-of-stream.
  6249. @see OutputStream::writeString, readEntireStreamAsString
  6250. */
  6251. virtual const String readString();
  6252. /** Tries to read the whole stream and turn it into a string.
  6253. This will read from the stream's current position until the end-of-stream, and
  6254. will try to make an educated guess about whether it's unicode or an 8-bit encoding.
  6255. */
  6256. virtual const String readEntireStreamAsString();
  6257. /** Reads from the stream and appends the data to a MemoryBlock.
  6258. @param destBlock the block to append the data onto
  6259. @param maxNumBytesToRead if this is a positive value, it sets a limit to the number
  6260. of bytes that will be read - if it's negative, data
  6261. will be read until the stream is exhausted.
  6262. @returns the number of bytes that were added to the memory block
  6263. */
  6264. virtual int readIntoMemoryBlock (MemoryBlock& destBlock,
  6265. int maxNumBytesToRead = -1);
  6266. /** Returns the offset of the next byte that will be read from the stream.
  6267. @see setPosition
  6268. */
  6269. virtual int64 getPosition() = 0;
  6270. /** Tries to move the current read position of the stream.
  6271. The position is an absolute number of bytes from the stream's start.
  6272. Some streams might not be able to do this, in which case they should do
  6273. nothing and return false. Others might be able to manage it by resetting
  6274. themselves and skipping to the correct position, although this is
  6275. obviously a bit slow.
  6276. @returns true if the stream manages to reposition itself correctly
  6277. @see getPosition
  6278. */
  6279. virtual bool setPosition (int64 newPosition) = 0;
  6280. /** Reads and discards a number of bytes from the stream.
  6281. Some input streams might implement this efficiently, but the base
  6282. class will just keep reading data until the requisite number of bytes
  6283. have been done.
  6284. */
  6285. virtual void skipNextBytes (int64 numBytesToSkip);
  6286. juce_UseDebuggingNewOperator
  6287. protected:
  6288. InputStream() throw() {}
  6289. };
  6290. #endif // __JUCE_INPUTSTREAM_JUCEHEADER__
  6291. /********* End of inlined file: juce_InputStream.h *********/
  6292. /**
  6293. The base class for streams that write data to some kind of destination.
  6294. Input and output streams are used throughout the library - subclasses can override
  6295. some or all of the virtual functions to implement their behaviour.
  6296. @see InputStream, MemoryOutputStream, FileOutputStream
  6297. */
  6298. class JUCE_API OutputStream
  6299. {
  6300. public:
  6301. /** Destructor.
  6302. Some subclasses might want to do things like call flush() during their
  6303. destructors.
  6304. */
  6305. virtual ~OutputStream();
  6306. /** If the stream is using a buffer, this will ensure it gets written
  6307. out to the destination. */
  6308. virtual void flush() = 0;
  6309. /** Tries to move the stream's output position.
  6310. Not all streams will be able to seek to a new position - this will return
  6311. false if it fails to work.
  6312. @see getPosition
  6313. */
  6314. virtual bool setPosition (int64 newPosition) = 0;
  6315. /** Returns the stream's current position.
  6316. @see setPosition
  6317. */
  6318. virtual int64 getPosition() = 0;
  6319. /** Writes a block of data to the stream.
  6320. When creating a subclass of OutputStream, this is the only write method
  6321. that needs to be overloaded - the base class has methods for writing other
  6322. types of data which use this to do the work.
  6323. @returns false if the write operation fails for some reason
  6324. */
  6325. virtual bool write (const void* dataToWrite,
  6326. int howManyBytes) = 0;
  6327. /** Writes a single byte to the stream.
  6328. @see InputStream::readByte
  6329. */
  6330. virtual void writeByte (char byte);
  6331. /** Writes a boolean to the stream.
  6332. This is encoded as a byte - either 1 or 0.
  6333. @see InputStream::readBool
  6334. */
  6335. virtual void writeBool (bool boolValue);
  6336. /** Writes a 16-bit integer to the stream in a little-endian byte order.
  6337. This will write two bytes to the stream: (value & 0xff), then (value >> 8).
  6338. @see InputStream::readShort
  6339. */
  6340. virtual void writeShort (short value);
  6341. /** Writes a 16-bit integer to the stream in a big-endian byte order.
  6342. This will write two bytes to the stream: (value >> 8), then (value & 0xff).
  6343. @see InputStream::readShortBigEndian
  6344. */
  6345. virtual void writeShortBigEndian (short value);
  6346. /** Writes a 32-bit integer to the stream in a little-endian byte order.
  6347. @see InputStream::readInt
  6348. */
  6349. virtual void writeInt (int value);
  6350. /** Writes a 32-bit integer to the stream in a big-endian byte order.
  6351. @see InputStream::readIntBigEndian
  6352. */
  6353. virtual void writeIntBigEndian (int value);
  6354. /** Writes a 64-bit integer to the stream in a little-endian byte order.
  6355. @see InputStream::readInt64
  6356. */
  6357. virtual void writeInt64 (int64 value);
  6358. /** Writes a 64-bit integer to the stream in a big-endian byte order.
  6359. @see InputStream::readInt64BigEndian
  6360. */
  6361. virtual void writeInt64BigEndian (int64 value);
  6362. /** Writes a 32-bit floating point value to the stream.
  6363. The binary 32-bit encoding of the float is written as a little-endian int.
  6364. @see InputStream::readFloat
  6365. */
  6366. virtual void writeFloat (float value);
  6367. /** Writes a 32-bit floating point value to the stream.
  6368. The binary 32-bit encoding of the float is written as a big-endian int.
  6369. @see InputStream::readFloatBigEndian
  6370. */
  6371. virtual void writeFloatBigEndian (float value);
  6372. /** Writes a 64-bit floating point value to the stream.
  6373. The eight raw bytes of the double value are written out as a little-endian 64-bit int.
  6374. @see InputStream::readDouble
  6375. */
  6376. virtual void writeDouble (double value);
  6377. /** Writes a 64-bit floating point value to the stream.
  6378. The eight raw bytes of the double value are written out as a big-endian 64-bit int.
  6379. @see InputStream::readDoubleBigEndian
  6380. */
  6381. virtual void writeDoubleBigEndian (double value);
  6382. /** Writes a condensed encoding of a 32-bit integer.
  6383. If you're storing a lot of integers which are unlikely to have very large values,
  6384. this can save a lot of space, because values under 0xff will only take up 2 bytes,
  6385. under 0xffff only 3 bytes, etc.
  6386. The format used is: number of significant bytes + up to 4 bytes in little-endian order.
  6387. @see InputStream::readCompressedInt
  6388. */
  6389. virtual void writeCompressedInt (int value);
  6390. /** Stores a string in the stream.
  6391. This isn't the method to use if you're trying to append text to the end of a
  6392. text-file! It's intended for storing a string for later retrieval
  6393. by InputStream::readString.
  6394. For appending text to a file, instead use writeText, printf, or operator<<
  6395. @see InputStream::readString, writeText, printf, operator<<
  6396. */
  6397. virtual void writeString (const String& text);
  6398. /** Writes a string of text to the stream.
  6399. It can either write it as 8-bit system-encoded characters, or as unicode, and
  6400. can also add unicode header bytes (0xff, 0xfe) to indicate the endianness (this
  6401. should only be done at the start of a file).
  6402. The method also replaces '\\n' characters in the text with '\\r\\n'.
  6403. */
  6404. virtual void writeText (const String& text,
  6405. const bool asUnicode,
  6406. const bool writeUnicodeHeaderBytes);
  6407. /** Writes a string of text to the stream.
  6408. @see writeText
  6409. */
  6410. virtual void printf (const char* format, ...);
  6411. /** Reads data from an input stream and writes it to this stream.
  6412. @param source the stream to read from
  6413. @param maxNumBytesToWrite the number of bytes to read from the stream (if this is
  6414. less than zero, it will keep reading until the input
  6415. is exhausted)
  6416. */
  6417. virtual int writeFromInputStream (InputStream& source,
  6418. int maxNumBytesToWrite);
  6419. /** Writes a number to the stream as 8-bit characters in the default system encoding. */
  6420. virtual OutputStream& operator<< (const int number);
  6421. /** Writes a number to the stream as 8-bit characters in the default system encoding. */
  6422. virtual OutputStream& operator<< (const double number);
  6423. /** Writes a character to the stream. */
  6424. virtual OutputStream& operator<< (const char character);
  6425. /** Writes a null-terminated string to the stream. */
  6426. virtual OutputStream& operator<< (const char* const text);
  6427. /** Writes a null-terminated unicode text string to the stream, converting it
  6428. to 8-bit characters in the default system encoding. */
  6429. virtual OutputStream& operator<< (const juce_wchar* const text);
  6430. /** Writes a string to the stream as 8-bit characters in the default system encoding. */
  6431. virtual OutputStream& operator<< (const String& text);
  6432. juce_UseDebuggingNewOperator
  6433. protected:
  6434. OutputStream() throw();
  6435. };
  6436. #endif // __JUCE_OUTPUTSTREAM_JUCEHEADER__
  6437. /********* End of inlined file: juce_OutputStream.h *********/
  6438. /** A handy macro to make it easy to iterate all the child elements in an XmlElement.
  6439. The parentXmlElement should be a reference to the parent XML, and the childElementVariableName
  6440. will be the name of a pointer to each child element.
  6441. E.g. @code
  6442. XmlElement* myParentXml = createSomeKindOfXmlDocument();
  6443. forEachXmlChildElement (*myParentXml, child)
  6444. {
  6445. if (child->hasTagName ("FOO"))
  6446. doSomethingWithXmlElement (child);
  6447. }
  6448. @endcode
  6449. @see forEachXmlChildElementWithTagName
  6450. */
  6451. #define forEachXmlChildElement(parentXmlElement, childElementVariableName) \
  6452. \
  6453. for (XmlElement* childElementVariableName = (parentXmlElement).getFirstChildElement(); \
  6454. childElementVariableName != 0; \
  6455. childElementVariableName = childElementVariableName->getNextElement())
  6456. /** A macro that makes it easy to iterate all the child elements of an XmlElement
  6457. which have a specified tag.
  6458. This does the same job as the forEachXmlChildElement macro, but only for those
  6459. elements that have a particular tag name.
  6460. The parentXmlElement should be a reference to the parent XML, and the childElementVariableName
  6461. will be the name of a pointer to each child element. The requiredTagName is the
  6462. tag name to match.
  6463. E.g. @code
  6464. XmlElement* myParentXml = createSomeKindOfXmlDocument();
  6465. forEachXmlChildElementWithTagName (*myParentXml, child, T("MYTAG"))
  6466. {
  6467. // the child object is now guaranteed to be a <MYTAG> element..
  6468. doSomethingWithMYTAGElement (child);
  6469. }
  6470. @endcode
  6471. @see forEachXmlChildElement
  6472. */
  6473. #define forEachXmlChildElementWithTagName(parentXmlElement, childElementVariableName, requiredTagName) \
  6474. \
  6475. for (XmlElement* childElementVariableName = (parentXmlElement).getChildByName (requiredTagName); \
  6476. childElementVariableName != 0; \
  6477. childElementVariableName = childElementVariableName->getNextElementWithTagName (requiredTagName))
  6478. /** Used to build a tree of elements representing an XML document.
  6479. An XML document can be parsed into a tree of XmlElements, each of which
  6480. represents an XML tag structure, and which may itself contain other
  6481. nested elements.
  6482. An XmlElement can also be converted back into a text document, and has
  6483. lots of useful methods for manipulating its attributes and sub-elements,
  6484. so XmlElements can actually be used as a handy general-purpose data
  6485. structure.
  6486. Here's an example of parsing some elements: @code
  6487. // check we're looking at the right kind of document..
  6488. if (myElement->hasTagName ("ANIMALS"))
  6489. {
  6490. // now we'll iterate its sub-elements looking for 'giraffe' elements..
  6491. forEachXmlChildElement (*myElement, e)
  6492. {
  6493. if (e->hasTagName ("GIRAFFE"))
  6494. {
  6495. // found a giraffe, so use some of its attributes..
  6496. String giraffeName = e->getStringAttribute ("name");
  6497. int giraffeAge = e->getIntAttribute ("age");
  6498. bool isFriendly = e->getBoolAttribute ("friendly");
  6499. }
  6500. }
  6501. }
  6502. @endcode
  6503. And here's an example of how to create an XML document from scratch: @code
  6504. // create an outer node called "ANIMALS"
  6505. XmlElement animalsList ("ANIMALS");
  6506. for (int i = 0; i < numAnimals; ++i)
  6507. {
  6508. // create an inner element..
  6509. XmlElement* giraffe = new XmlElement ("GIRAFFE");
  6510. giraffe->setAttribute ("name", "nigel");
  6511. giraffe->setAttribute ("age", 10);
  6512. giraffe->setAttribute ("friendly", true);
  6513. // ..and add our new element to the parent node
  6514. animalsList.addChildElement (giraffe);
  6515. }
  6516. // now we can turn the whole thing into a text document..
  6517. String myXmlDoc = animalsList.createDocument (String::empty);
  6518. @endcode
  6519. @see XmlDocument
  6520. */
  6521. class JUCE_API XmlElement
  6522. {
  6523. public:
  6524. /** Creates an XmlElement with this tag name. */
  6525. XmlElement (const String& tagName) throw();
  6526. /** Creates a (deep) copy of another element. */
  6527. XmlElement (const XmlElement& other) throw();
  6528. /** Creates a (deep) copy of another element. */
  6529. const XmlElement& operator= (const XmlElement& other) throw();
  6530. /** Deleting an XmlElement will also delete all its child elements. */
  6531. ~XmlElement() throw();
  6532. /** Compares two XmlElements to see if they contain the same text and attiributes.
  6533. The elements are only considered equivalent if they contain the same attiributes
  6534. with the same values, and have the same sub-nodes.
  6535. @param other the other element to compare to
  6536. @param ignoreOrderOfAttributes if true, this means that two elements with the
  6537. same attributes in a different order will be
  6538. considered the same; if false, the attributes must
  6539. be in the same order as well
  6540. */
  6541. bool isEquivalentTo (const XmlElement* const other,
  6542. const bool ignoreOrderOfAttributes) const throw();
  6543. /** Returns an XML text document that represents this element.
  6544. The string returned can be parsed to recreate the same XmlElement that
  6545. was used to create it.
  6546. @param dtdToUse the DTD to add to the document
  6547. @param allOnOneLine if true, this means that the document will not contain any
  6548. linefeeds, so it'll be smaller but not very easy to read.
  6549. @param includeXmlHeader whether to add the "<?xml version..etc" line at the start of the
  6550. document
  6551. @param encodingType the character encoding format string to put into the xml
  6552. header
  6553. @see writeToFile
  6554. */
  6555. const String createDocument (const String& dtdToUse,
  6556. const bool allOnOneLine = false,
  6557. const bool includeXmlHeader = true,
  6558. const tchar* const encodingType = JUCE_T("UTF-8")) const throw();
  6559. /** Writes the element to a file as an XML document.
  6560. To improve safety in case something goes wrong while writing the file, this
  6561. will actually write the document to a new temporary file in the same
  6562. directory as the destination file, and if this succeeds, it will rename this
  6563. new file as the destination file (overwriting any existing file that was there).
  6564. @param destinationFile the file to write to. If this already exists, it will be
  6565. overwritten.
  6566. @param dtdToUse the DTD to add to the document
  6567. @param encodingType the character encoding format string to put into the xml
  6568. header
  6569. @returns true if the file is written successfully; false if something goes wrong
  6570. in the process
  6571. @see createDocument
  6572. */
  6573. bool writeToFile (const File& destinationFile,
  6574. const String& dtdToUse,
  6575. const tchar* const encodingType = JUCE_T("UTF-8")) const throw();
  6576. /** Returns this element's tag type name.
  6577. E.g. for an element such as \<MOOSE legs="4" antlers="2">, this would return
  6578. "MOOSE".
  6579. @see hasTagName
  6580. */
  6581. inline const String& getTagName() const throw() { return tagName; }
  6582. /** Tests whether this element has a particular tag name.
  6583. @param possibleTagName the tag name you're comparing it with
  6584. @see getTagName
  6585. */
  6586. bool hasTagName (const tchar* const possibleTagName) const throw();
  6587. /** Returns the number of XML attributes this element contains.
  6588. E.g. for an element such as \<MOOSE legs="4" antlers="2">, this would
  6589. return 2.
  6590. */
  6591. int getNumAttributes() const throw();
  6592. /** Returns the name of one of the elements attributes.
  6593. E.g. for an element such as \<MOOSE legs="4" antlers="2">, then
  6594. getAttributeName(1) would return "antlers".
  6595. @see getAttributeValue, getStringAttribute
  6596. */
  6597. const String& getAttributeName (const int attributeIndex) const throw();
  6598. /** Returns the value of one of the elements attributes.
  6599. E.g. for an element such as \<MOOSE legs="4" antlers="2">, then
  6600. getAttributeName(1) would return "2".
  6601. @see getAttributeName, getStringAttribute
  6602. */
  6603. const String& getAttributeValue (const int attributeIndex) const throw();
  6604. // Attribute-handling methods..
  6605. /** Checks whether the element contains an attribute with a certain name. */
  6606. bool hasAttribute (const tchar* const attributeName) const throw();
  6607. /** Returns the value of a named attribute.
  6608. @param attributeName the name of the attribute to look up
  6609. @param defaultReturnValue a value to return if the element doesn't have an attribute
  6610. with this name
  6611. */
  6612. const String getStringAttribute (const tchar* const attributeName,
  6613. const tchar* const defaultReturnValue = 0) const throw();
  6614. /** Compares the value of a named attribute with a value passed-in.
  6615. @param attributeName the name of the attribute to look up
  6616. @param stringToCompareAgainst the value to compare it with
  6617. @param ignoreCase whether the comparison should be case-insensitive
  6618. @returns true if the value of the attribute is the same as the string passed-in;
  6619. false if it's different (or if no such attribute exists)
  6620. */
  6621. bool compareAttribute (const tchar* const attributeName,
  6622. const tchar* const stringToCompareAgainst,
  6623. const bool ignoreCase = false) const throw();
  6624. /** Returns the value of a named attribute as an integer.
  6625. This will try to find the attribute and convert it to an integer (using
  6626. the String::getIntValue() method).
  6627. @param attributeName the name of the attribute to look up
  6628. @param defaultReturnValue a value to return if the element doesn't have an attribute
  6629. with this name
  6630. @see setAttribute (const tchar* const, int)
  6631. */
  6632. int getIntAttribute (const tchar* const attributeName,
  6633. const int defaultReturnValue = 0) const throw();
  6634. /** Returns the value of a named attribute as floating-point.
  6635. This will try to find the attribute and convert it to an integer (using
  6636. the String::getDoubleValue() method).
  6637. @param attributeName the name of the attribute to look up
  6638. @param defaultReturnValue a value to return if the element doesn't have an attribute
  6639. with this name
  6640. @see setAttribute (const tchar* const, double)
  6641. */
  6642. double getDoubleAttribute (const tchar* const attributeName,
  6643. const double defaultReturnValue = 0.0) const throw();
  6644. /** Returns the value of a named attribute as a boolean.
  6645. This will try to find the attribute and interpret it as a boolean. To do this,
  6646. it'll return true if the value is "1", "true", "y", etc, or false for other
  6647. values.
  6648. @param attributeName the name of the attribute to look up
  6649. @param defaultReturnValue a value to return if the element doesn't have an attribute
  6650. with this name
  6651. */
  6652. bool getBoolAttribute (const tchar* const attributeName,
  6653. const bool defaultReturnValue = false) const throw();
  6654. /** Adds a named attribute to the element.
  6655. If the element already contains an attribute with this name, it's value will
  6656. be updated to the new value. If there's no such attribute yet, a new one will
  6657. be added.
  6658. Note that there are other setAttribute() methods that take integers,
  6659. doubles, etc. to make it easy to store numbers.
  6660. @param attributeName the name of the attribute to set
  6661. @param newValue the value to set it to
  6662. @see removeAttribute
  6663. */
  6664. void setAttribute (const tchar* const attributeName,
  6665. const String& newValue) throw();
  6666. /** Adds a named attribute to the element.
  6667. If the element already contains an attribute with this name, it's value will
  6668. be updated to the new value. If there's no such attribute yet, a new one will
  6669. be added.
  6670. Note that there are other setAttribute() methods that take integers,
  6671. doubles, etc. to make it easy to store numbers.
  6672. @param attributeName the name of the attribute to set
  6673. @param newValue the value to set it to
  6674. */
  6675. void setAttribute (const tchar* const attributeName,
  6676. const tchar* const newValue) throw();
  6677. /** Adds a named attribute to the element, setting it to an integer value.
  6678. If the element already contains an attribute with this name, it's value will
  6679. be updated to the new value. If there's no such attribute yet, a new one will
  6680. be added.
  6681. Note that there are other setAttribute() methods that take integers,
  6682. doubles, etc. to make it easy to store numbers.
  6683. @param attributeName the name of the attribute to set
  6684. @param newValue the value to set it to
  6685. */
  6686. void setAttribute (const tchar* const attributeName,
  6687. const int newValue) throw();
  6688. /** Adds a named attribute to the element, setting it to a floating-point value.
  6689. If the element already contains an attribute with this name, it's value will
  6690. be updated to the new value. If there's no such attribute yet, a new one will
  6691. be added.
  6692. Note that there are other setAttribute() methods that take integers,
  6693. doubles, etc. to make it easy to store numbers.
  6694. @param attributeName the name of the attribute to set
  6695. @param newValue the value to set it to
  6696. */
  6697. void setAttribute (const tchar* const attributeName,
  6698. const double newValue) throw();
  6699. /** Removes a named attribute from the element.
  6700. @param attributeName the name of the attribute to remove
  6701. @see removeAllAttributes
  6702. */
  6703. void removeAttribute (const tchar* const attributeName) throw();
  6704. /** Removes all attributes from this element.
  6705. */
  6706. void removeAllAttributes() throw();
  6707. // Child element methods..
  6708. /** Returns the first of this element's sub-elements.
  6709. see getNextElement() for an example of how to iterate the sub-elements.
  6710. @see forEachXmlChildElement
  6711. */
  6712. XmlElement* getFirstChildElement() const throw() { return firstChildElement; }
  6713. /** Returns the next of this element's siblings.
  6714. This can be used for iterating an element's sub-elements, e.g.
  6715. @code
  6716. XmlElement* child = myXmlDocument->getFirstChildElement();
  6717. while (child != 0)
  6718. {
  6719. ...do stuff with this child..
  6720. child = child->getNextElement();
  6721. }
  6722. @endcode
  6723. Note that when iterating the child elements, some of them might be
  6724. text elements as well as XML tags - use isTextElement() to work this
  6725. out.
  6726. Also, it's much easier and neater to use this method indirectly via the
  6727. forEachXmlChildElement macro.
  6728. @returns the sibling element that follows this one, or zero if this is the last
  6729. element in its parent
  6730. @see getNextElement, isTextElement, forEachXmlChildElement
  6731. */
  6732. inline XmlElement* getNextElement() const throw() { return nextElement; }
  6733. /** Returns the next of this element's siblings which has the specified tag
  6734. name.
  6735. This is like getNextElement(), but will scan through the list until it
  6736. finds an element with the given tag name.
  6737. @see getNextElement, forEachXmlChildElementWithTagName
  6738. */
  6739. XmlElement* getNextElementWithTagName (const tchar* const requiredTagName) const;
  6740. /** Returns the number of sub-elements in this element.
  6741. @see getChildElement
  6742. */
  6743. int getNumChildElements() const throw();
  6744. /** Returns the sub-element at a certain index.
  6745. It's not very efficient to iterate the sub-elements by index - see
  6746. getNextElement() for an example of how best to iterate.
  6747. @returns the n'th child of this element, or 0 if the index is out-of-range
  6748. @see getNextElement, isTextElement, getChildByName
  6749. */
  6750. XmlElement* getChildElement (const int index) const throw();
  6751. /** Returns the first sub-element with a given tag-name.
  6752. @param tagNameToLookFor the tag name of the element you want to find
  6753. @returns the first element with this tag name, or 0 if none is found
  6754. @see getNextElement, isTextElement, getChildElement
  6755. */
  6756. XmlElement* getChildByName (const tchar* const tagNameToLookFor) const throw();
  6757. /** Appends an element to this element's list of children.
  6758. Child elements are deleted automatically when their parent is deleted, so
  6759. make sure the object that you pass in will not be deleted by anything else,
  6760. and make sure it's not already the child of another element.
  6761. @see getFirstChildElement, getNextElement, getNumChildElements,
  6762. getChildElement, removeChildElement
  6763. */
  6764. void addChildElement (XmlElement* const newChildElement) throw();
  6765. /** Inserts an element into this element's list of children.
  6766. Child elements are deleted automatically when their parent is deleted, so
  6767. make sure the object that you pass in will not be deleted by anything else,
  6768. and make sure it's not already the child of another element.
  6769. @param newChildNode the element to add
  6770. @param indexToInsertAt the index at which to insert the new element - if this is
  6771. below zero, it will be added to the end of the list
  6772. @see addChildElement, insertChildElement
  6773. */
  6774. void insertChildElement (XmlElement* const newChildNode,
  6775. int indexToInsertAt) throw();
  6776. /** Replaces one of this element's children with another node.
  6777. If the current element passed-in isn't actually a child of this element,
  6778. this will return false and the new one won't be added. Otherwise, the
  6779. existing element will be deleted, replaced with the new one, and it
  6780. will return true.
  6781. */
  6782. bool replaceChildElement (XmlElement* const currentChildElement,
  6783. XmlElement* const newChildNode) throw();
  6784. /** Removes a child element.
  6785. @param childToRemove the child to look for and remove
  6786. @param shouldDeleteTheChild if true, the child will be deleted, if false it'll
  6787. just remove it
  6788. */
  6789. void removeChildElement (XmlElement* const childToRemove,
  6790. const bool shouldDeleteTheChild) throw();
  6791. /** Deletes all the child elements in the element.
  6792. @see removeChildElement, deleteAllChildElementsWithTagName
  6793. */
  6794. void deleteAllChildElements() throw();
  6795. /** Deletes all the child elements with a given tag name.
  6796. @see removeChildElement
  6797. */
  6798. void deleteAllChildElementsWithTagName (const tchar* const tagName) throw();
  6799. /** Returns true if the given element is a child of this one. */
  6800. bool containsChildElement (const XmlElement* const possibleChild) const throw();
  6801. /** Recursively searches all sub-elements to find one that contains the specified
  6802. child element.
  6803. */
  6804. XmlElement* findParentElementOf (const XmlElement* const elementToLookFor) throw();
  6805. /** Sorts the child elements using a comparator.
  6806. This will use a comparator object to sort the elements into order. The object
  6807. passed must have a method of the form:
  6808. @code
  6809. int compareElements (const XmlElement* first, const XmlElement* second);
  6810. @endcode
  6811. ..and this method must return:
  6812. - a value of < 0 if the first comes before the second
  6813. - a value of 0 if the two objects are equivalent
  6814. - a value of > 0 if the second comes before the first
  6815. To improve performance, the compareElements() method can be declared as static or const.
  6816. @param comparator the comparator to use for comparing elements.
  6817. @param retainOrderOfEquivalentItems if this is true, then items
  6818. which the comparator says are equivalent will be
  6819. kept in the order in which they currently appear
  6820. in the array. This is slower to perform, but may
  6821. be important in some cases. If it's false, a faster
  6822. algorithm is used, but equivalent elements may be
  6823. rearranged.
  6824. */
  6825. template <class ElementComparator>
  6826. void sortChildElements (ElementComparator& comparator,
  6827. const bool retainOrderOfEquivalentItems = false) throw()
  6828. {
  6829. const int num = getNumChildElements();
  6830. if (num > 1)
  6831. {
  6832. XmlElement** const elems = getChildElementsAsArray (num);
  6833. sortArray (comparator, elems, 0, num - 1, retainOrderOfEquivalentItems);
  6834. reorderChildElements (elems, num);
  6835. delete[] elems;
  6836. }
  6837. }
  6838. /** Returns true if this element is a section of text.
  6839. Elements can either be an XML tag element or a secton of text, so this
  6840. is used to find out what kind of element this one is.
  6841. @see getAllText, addTextElement, deleteAllTextElements
  6842. */
  6843. bool isTextElement() const throw();
  6844. /** Returns the text for a text element.
  6845. Note that if you have an element like this:
  6846. @code<xyz>hello</xyz>@endcode
  6847. then calling getText on the "xyz" element won't return "hello", because that is
  6848. actually stored in a special text sub-element inside the xyz element. To get the
  6849. "hello" string, you could either call getText on the (unnamed) sub-element, or
  6850. use getAllSubText() to do this automatically.
  6851. @see isTextElement, getAllSubText, getChildElementAllSubText
  6852. */
  6853. const String getText() const throw();
  6854. /** Sets the text in a text element.
  6855. Note that this is only a valid call if this element is a text element. If it's
  6856. not, then no action will be performed.
  6857. */
  6858. void setText (const String& newText) throw();
  6859. /** Returns all the text from this element's child nodes.
  6860. This iterates all the child elements and when it finds text elements,
  6861. it concatenates their text into a big string which it returns.
  6862. E.g. @code<xyz> hello <x></x> there </xyz>@endcode
  6863. if you called getAllSubText on the "xyz" element, it'd return "hello there".
  6864. @see isTextElement, getChildElementAllSubText, getText, addTextElement
  6865. */
  6866. const String getAllSubText() const throw();
  6867. /** Returns all the sub-text of a named child element.
  6868. If there is a child element with the given tag name, this will return
  6869. all of its sub-text (by calling getAllSubText() on it). If there is
  6870. no such child element, this will return the default string passed-in.
  6871. @see getAllSubText
  6872. */
  6873. const String getChildElementAllSubText (const tchar* const childTagName,
  6874. const String& defaultReturnValue) const throw();
  6875. /** Appends a section of text to this element.
  6876. @see isTextElement, getText, getAllSubText
  6877. */
  6878. void addTextElement (const String& text) throw();
  6879. /** Removes all the text elements from this element.
  6880. @see isTextElement, getText, getAllSubText, addTextElement
  6881. */
  6882. void deleteAllTextElements() throw();
  6883. /** Creates a text element that can be added to a parent element.
  6884. */
  6885. static XmlElement* createTextElement (const String& text) throw();
  6886. juce_UseDebuggingNewOperator
  6887. private:
  6888. friend class XmlDocument;
  6889. String tagName;
  6890. XmlElement* firstChildElement;
  6891. XmlElement* nextElement;
  6892. struct XmlAttributeNode
  6893. {
  6894. XmlAttributeNode (const XmlAttributeNode& other) throw();
  6895. XmlAttributeNode (const String& name, const String& value) throw();
  6896. String name, value;
  6897. XmlAttributeNode* next;
  6898. };
  6899. XmlAttributeNode* attributes;
  6900. XmlElement (int) throw(); // for internal use
  6901. XmlElement (const tchar* const tagNameText, const int nameLen) throw();
  6902. void copyChildrenAndAttributesFrom (const XmlElement& other) throw();
  6903. void writeElementAsText (OutputStream& out, const int indentationLevel) const throw();
  6904. XmlElement** getChildElementsAsArray (const int) const throw();
  6905. void reorderChildElements (XmlElement** const, const int) throw();
  6906. };
  6907. #endif // __JUCE_XMLELEMENT_JUCEHEADER__
  6908. /********* End of inlined file: juce_XmlElement.h *********/
  6909. /**
  6910. A set of named property values, which can be strings, integers, floating point, etc.
  6911. Effectively, this just wraps a StringPairArray in an interface that makes it easier
  6912. to load and save types other than strings.
  6913. See the PropertiesFile class for a subclass of this, which automatically broadcasts change
  6914. messages and saves/loads the list from a file.
  6915. */
  6916. class JUCE_API PropertySet
  6917. {
  6918. public:
  6919. /** Creates an empty PropertySet.
  6920. @param ignoreCaseOfKeyNames if true, the names of properties are compared in a
  6921. case-insensitive way
  6922. */
  6923. PropertySet (const bool ignoreCaseOfKeyNames = false) throw();
  6924. /** Creates a copy of another PropertySet.
  6925. */
  6926. PropertySet (const PropertySet& other) throw();
  6927. /** Copies another PropertySet over this one.
  6928. */
  6929. const PropertySet& operator= (const PropertySet& other) throw();
  6930. /** Destructor. */
  6931. virtual ~PropertySet();
  6932. /** Returns one of the properties as a string.
  6933. If the value isn't found in this set, then this will look for it in a fallback
  6934. property set (if you've specified one with the setFallbackPropertySet() method),
  6935. and if it can't find one there, it'll return the default value passed-in.
  6936. @param keyName the name of the property to retrieve
  6937. @param defaultReturnValue a value to return if the named property doesn't actually exist
  6938. */
  6939. const String getValue (const String& keyName,
  6940. const String& defaultReturnValue = String::empty) const throw();
  6941. /** Returns one of the properties as an integer.
  6942. If the value isn't found in this set, then this will look for it in a fallback
  6943. property set (if you've specified one with the setFallbackPropertySet() method),
  6944. and if it can't find one there, it'll return the default value passed-in.
  6945. @param keyName the name of the property to retrieve
  6946. @param defaultReturnValue a value to return if the named property doesn't actually exist
  6947. */
  6948. int getIntValue (const String& keyName,
  6949. const int defaultReturnValue = 0) const throw();
  6950. /** Returns one of the properties as an double.
  6951. If the value isn't found in this set, then this will look for it in a fallback
  6952. property set (if you've specified one with the setFallbackPropertySet() method),
  6953. and if it can't find one there, it'll return the default value passed-in.
  6954. @param keyName the name of the property to retrieve
  6955. @param defaultReturnValue a value to return if the named property doesn't actually exist
  6956. */
  6957. double getDoubleValue (const String& keyName,
  6958. const double defaultReturnValue = 0.0) const throw();
  6959. /** Returns one of the properties as an boolean.
  6960. The result will be true if the string found for this key name can be parsed as a non-zero
  6961. integer.
  6962. If the value isn't found in this set, then this will look for it in a fallback
  6963. property set (if you've specified one with the setFallbackPropertySet() method),
  6964. and if it can't find one there, it'll return the default value passed-in.
  6965. @param keyName the name of the property to retrieve
  6966. @param defaultReturnValue a value to return if the named property doesn't actually exist
  6967. */
  6968. bool getBoolValue (const String& keyName,
  6969. const bool defaultReturnValue = false) const throw();
  6970. /** Returns one of the properties as an XML element.
  6971. The result will a new XMLElement object that the caller must delete. If may return 0 if the
  6972. key isn't found, or if the entry contains an string that isn't valid XML.
  6973. If the value isn't found in this set, then this will look for it in a fallback
  6974. property set (if you've specified one with the setFallbackPropertySet() method),
  6975. and if it can't find one there, it'll return the default value passed-in.
  6976. @param keyName the name of the property to retrieve
  6977. */
  6978. XmlElement* getXmlValue (const String& keyName) const;
  6979. /** Sets a named property as a string.
  6980. @param keyName the name of the property to set. (This mustn't be an empty string)
  6981. @param value the new value to set it to
  6982. */
  6983. void setValue (const String& keyName, const String& value) throw();
  6984. /** Sets a named property as a string.
  6985. @param keyName the name of the property to set. (This mustn't be an empty string)
  6986. @param value the new value to set it to
  6987. */
  6988. void setValue (const String& keyName, const tchar* const value) throw();
  6989. /** Sets a named property to an integer.
  6990. @param keyName the name of the property to set. (This mustn't be an empty string)
  6991. @param value the new value to set it to
  6992. */
  6993. void setValue (const String& keyName, const int value) throw();
  6994. /** Sets a named property to a double.
  6995. @param keyName the name of the property to set. (This mustn't be an empty string)
  6996. @param value the new value to set it to
  6997. */
  6998. void setValue (const String& keyName, const double value) throw();
  6999. /** Sets a named property to a boolean.
  7000. @param keyName the name of the property to set. (This mustn't be an empty string)
  7001. @param value the new value to set it to
  7002. */
  7003. void setValue (const String& keyName, const bool value) throw();
  7004. /** Sets a named property to an XML element.
  7005. @param keyName the name of the property to set. (This mustn't be an empty string)
  7006. @param xml the new element to set it to. If this is zero, the value will be set to
  7007. an empty string
  7008. @see getXmlValue
  7009. */
  7010. void setValue (const String& keyName, const XmlElement* const xml);
  7011. /** Deletes a property.
  7012. @param keyName the name of the property to delete. (This mustn't be an empty string)
  7013. */
  7014. void removeValue (const String& keyName) throw();
  7015. /** Returns true if the properies include the given key. */
  7016. bool containsKey (const String& keyName) const throw();
  7017. /** Removes all values. */
  7018. void clear();
  7019. /** Returns the keys/value pair array containing all the properties. */
  7020. StringPairArray& getAllProperties() throw() { return properties; }
  7021. /** Returns the lock used when reading or writing to this set */
  7022. const CriticalSection& getLock() const throw() { return lock; }
  7023. /** Returns an XML element which encapsulates all the items in this property set.
  7024. The string parameter is the tag name that should be used for the node.
  7025. @see restoreFromXml
  7026. */
  7027. XmlElement* createXml (const String& nodeName) const throw();
  7028. /** Reloads a set of properties that were previously stored as XML.
  7029. The node passed in must have been created by the createXml() method.
  7030. @see createXml
  7031. */
  7032. void restoreFromXml (const XmlElement& xml) throw();
  7033. /** Sets up a second PopertySet that will be used to look up any values that aren't
  7034. set in this one.
  7035. If you set this up to be a pointer to a second property set, then whenever one
  7036. of the getValue() methods fails to find an entry in this set, it will look up that
  7037. value in the fallback set, and if it finds it, it will return that.
  7038. Make sure that you don't delete the fallback set while it's still being used by
  7039. another set! To remove the fallback set, just call this method with a null pointer.
  7040. @see getFallbackPropertySet
  7041. */
  7042. void setFallbackPropertySet (PropertySet* fallbackProperties) throw();
  7043. /** Returns the fallback property set.
  7044. @see setFallbackPropertySet
  7045. */
  7046. PropertySet* getFallbackPropertySet() const throw() { return fallbackProperties; }
  7047. juce_UseDebuggingNewOperator
  7048. protected:
  7049. /** Subclasses can override this to be told when one of the properies has been changed.
  7050. */
  7051. virtual void propertyChanged();
  7052. private:
  7053. StringPairArray properties;
  7054. PropertySet* fallbackProperties;
  7055. CriticalSection lock;
  7056. bool ignoreCaseOfKeys;
  7057. };
  7058. #endif // __JUCE_PROPERTYSET_JUCEHEADER__
  7059. /********* End of inlined file: juce_PropertySet.h *********/
  7060. #endif
  7061. #ifndef __JUCE_REFERENCECOUNTEDARRAY_JUCEHEADER__
  7062. /********* Start of inlined file: juce_ReferenceCountedArray.h *********/
  7063. #ifndef __JUCE_REFERENCECOUNTEDARRAY_JUCEHEADER__
  7064. #define __JUCE_REFERENCECOUNTEDARRAY_JUCEHEADER__
  7065. /********* Start of inlined file: juce_ReferenceCountedObject.h *********/
  7066. #ifndef __JUCE_REFERENCECOUNTEDOBJECT_JUCEHEADER__
  7067. #define __JUCE_REFERENCECOUNTEDOBJECT_JUCEHEADER__
  7068. /**
  7069. Adds reference-counting to an object.
  7070. To add reference-counting to a class, derive it from this class, and
  7071. use the ReferenceCountedObjectPtr class to point to it.
  7072. e.g. @code
  7073. class MyClass : public ReferenceCountedObject
  7074. {
  7075. void foo();
  7076. // This is a neat way of declaring a typedef for a pointer class,
  7077. // rather than typing out the full templated name each time..
  7078. typedef ReferenceCountedObjectPtr<MyClass> Ptr;
  7079. };
  7080. MyClass::Ptr p = new MyClass();
  7081. MyClass::Ptr p2 = p;
  7082. p = 0;
  7083. p2->foo();
  7084. @endcode
  7085. Once a new ReferenceCountedObject has been assigned to a pointer, be
  7086. careful not to delete the object manually.
  7087. @see ReferenceCountedObjectPtr, ReferenceCountedArray
  7088. */
  7089. class JUCE_API ReferenceCountedObject
  7090. {
  7091. public:
  7092. /** Increments the object's reference count.
  7093. This is done automatically by the smart pointer, but is public just
  7094. in case it's needed for nefarious purposes.
  7095. */
  7096. inline void incReferenceCount() throw()
  7097. {
  7098. atomicIncrement (refCounts);
  7099. jassert (refCounts > 0);
  7100. }
  7101. /** Decreases the object's reference count.
  7102. If the count gets to zero, the object will be deleted.
  7103. */
  7104. inline void decReferenceCount() throw()
  7105. {
  7106. jassert (refCounts > 0);
  7107. if (atomicDecrementAndReturn (refCounts) == 0)
  7108. delete this;
  7109. }
  7110. /** Returns the object's current reference count. */
  7111. inline int getReferenceCount() const throw()
  7112. {
  7113. return refCounts;
  7114. }
  7115. protected:
  7116. /** Creates the reference-counted object (with an initial ref count of zero). */
  7117. ReferenceCountedObject()
  7118. : refCounts (0)
  7119. {
  7120. }
  7121. /** Destructor. */
  7122. virtual ~ReferenceCountedObject()
  7123. {
  7124. // it's dangerous to delete an object that's still referenced by something else!
  7125. jassert (refCounts == 0);
  7126. }
  7127. private:
  7128. int refCounts;
  7129. };
  7130. /**
  7131. Used to point to an object of type ReferenceCountedObject.
  7132. It's wise to use a typedef instead of typing out the templated name
  7133. each time - e.g.
  7134. typedef ReferenceCountedObjectPtr<MyClass> MyClassPtr;
  7135. @see ReferenceCountedObject, ReferenceCountedObjectArray
  7136. */
  7137. template <class ReferenceCountedObjectClass>
  7138. class ReferenceCountedObjectPtr
  7139. {
  7140. public:
  7141. /** Creates a pointer to a null object. */
  7142. inline ReferenceCountedObjectPtr() throw()
  7143. : referencedObject (0)
  7144. {
  7145. }
  7146. /** Creates a pointer to an object.
  7147. This will increment the object's reference-count if it is non-null.
  7148. */
  7149. inline ReferenceCountedObjectPtr (ReferenceCountedObjectClass* const refCountedObject) throw()
  7150. : referencedObject (refCountedObject)
  7151. {
  7152. if (refCountedObject != 0)
  7153. refCountedObject->incReferenceCount();
  7154. }
  7155. /** Copies another pointer.
  7156. This will increment the object's reference-count (if it is non-null).
  7157. */
  7158. inline ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& other) throw()
  7159. : referencedObject (other.referencedObject)
  7160. {
  7161. if (referencedObject != 0)
  7162. referencedObject->incReferenceCount();
  7163. }
  7164. /** Changes this pointer to point at a different object.
  7165. The reference count of the old object is decremented, and it might be
  7166. deleted if it hits zero. The new object's count is incremented.
  7167. */
  7168. const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& operator= (const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& other)
  7169. {
  7170. ReferenceCountedObjectClass* const newObject = other.referencedObject;
  7171. if (newObject != referencedObject)
  7172. {
  7173. if (newObject != 0)
  7174. newObject->incReferenceCount();
  7175. ReferenceCountedObjectClass* const oldObject = referencedObject;
  7176. referencedObject = newObject;
  7177. if (oldObject != 0)
  7178. oldObject->decReferenceCount();
  7179. }
  7180. return *this;
  7181. }
  7182. /** Changes this pointer to point at a different object.
  7183. The reference count of the old object is decremented, and it might be
  7184. deleted if it hits zero. The new object's count is incremented.
  7185. */
  7186. const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& operator= (ReferenceCountedObjectClass* const newObject)
  7187. {
  7188. if (referencedObject != newObject)
  7189. {
  7190. if (newObject != 0)
  7191. newObject->incReferenceCount();
  7192. ReferenceCountedObjectClass* const oldObject = referencedObject;
  7193. referencedObject = newObject;
  7194. if (oldObject != 0)
  7195. oldObject->decReferenceCount();
  7196. }
  7197. return *this;
  7198. }
  7199. /** Destructor.
  7200. This will decrement the object's reference-count, and may delete it if it
  7201. gets to zero.
  7202. */
  7203. inline ~ReferenceCountedObjectPtr()
  7204. {
  7205. if (referencedObject != 0)
  7206. referencedObject->decReferenceCount();
  7207. }
  7208. /** Returns the object that this pointer references.
  7209. The pointer returned may be zero, of course.
  7210. */
  7211. inline operator ReferenceCountedObjectClass*() const throw()
  7212. {
  7213. return referencedObject;
  7214. }
  7215. /** Returns true if this pointer refers to the given object. */
  7216. inline bool operator== (ReferenceCountedObjectClass* const object) const throw()
  7217. {
  7218. return referencedObject == object;
  7219. }
  7220. /** Returns true if this pointer doesn't refer to the given object. */
  7221. inline bool operator!= (ReferenceCountedObjectClass* const object) const throw()
  7222. {
  7223. return referencedObject != object;
  7224. }
  7225. // the -> operator is called on the referenced object
  7226. inline ReferenceCountedObjectClass* operator->() const throw()
  7227. {
  7228. return referencedObject;
  7229. }
  7230. private:
  7231. ReferenceCountedObjectClass* referencedObject;
  7232. };
  7233. #endif // __JUCE_REFERENCECOUNTEDOBJECT_JUCEHEADER__
  7234. /********* End of inlined file: juce_ReferenceCountedObject.h *********/
  7235. /**
  7236. Holds a list of objects derived from ReferenceCountedObject.
  7237. A ReferenceCountedArray holds objects derived from ReferenceCountedObject,
  7238. and takes care of incrementing and decrementing their ref counts when they
  7239. are added and removed from the array.
  7240. To make all the array's methods thread-safe, pass in "CriticalSection" as the templated
  7241. TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.
  7242. @see Array, OwnedArray, StringArray
  7243. */
  7244. template <class ObjectClass, class TypeOfCriticalSectionToUse = DummyCriticalSection>
  7245. class ReferenceCountedArray : private ArrayAllocationBase <ObjectClass*>
  7246. {
  7247. public:
  7248. /** Creates an empty array.
  7249. @param granularity this is the size of increment by which the internal storage
  7250. used by the array will grow. Only change it from the default if you know the
  7251. array is going to be very big and needs to be able to grow efficiently.
  7252. @see ReferenceCountedObject, ArrayAllocationBase, Array, OwnedArray
  7253. */
  7254. ReferenceCountedArray (const int granularity = juceDefaultArrayGranularity) throw()
  7255. : ArrayAllocationBase <ObjectClass*> (granularity),
  7256. numUsed (0)
  7257. {
  7258. }
  7259. /** Creates a copy of another array */
  7260. ReferenceCountedArray (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) throw()
  7261. : ArrayAllocationBase <ObjectClass*> (other.granularity),
  7262. numUsed (other.numUsed)
  7263. {
  7264. other.lockArray();
  7265. this->setAllocatedSize (numUsed);
  7266. memcpy (this->elements, other.elements, numUsed * sizeof (ObjectClass*));
  7267. for (int i = numUsed; --i >= 0;)
  7268. if (this->elements[i] != 0)
  7269. this->elements[i]->incReferenceCount();
  7270. other.unlockArray();
  7271. }
  7272. /** Copies another array into this one.
  7273. Any existing objects in this array will first be released.
  7274. */
  7275. const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& operator= (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) throw()
  7276. {
  7277. if (this != &other)
  7278. {
  7279. other.lockArray();
  7280. lock.enter();
  7281. clear();
  7282. this->granularity = other.granularity;
  7283. this->ensureAllocatedSize (other.numUsed);
  7284. numUsed = other.numUsed;
  7285. memcpy (this->elements, other.elements, numUsed * sizeof (ObjectClass*));
  7286. minimiseStorageOverheads();
  7287. for (int i = numUsed; --i >= 0;)
  7288. if (this->elements[i] != 0)
  7289. this->elements[i]->incReferenceCount();
  7290. lock.exit();
  7291. other.unlockArray();
  7292. }
  7293. return *this;
  7294. }
  7295. /** Destructor.
  7296. Any objects in the array will be released, and may be deleted if not referenced from elsewhere.
  7297. */
  7298. ~ReferenceCountedArray()
  7299. {
  7300. clear();
  7301. }
  7302. /** Removes all objects from the array.
  7303. Any objects in the array that are not referenced from elsewhere will be deleted.
  7304. */
  7305. void clear()
  7306. {
  7307. lock.enter();
  7308. while (numUsed > 0)
  7309. if (this->elements [--numUsed] != 0)
  7310. this->elements [numUsed]->decReferenceCount();
  7311. jassert (numUsed == 0);
  7312. this->setAllocatedSize (0);
  7313. lock.exit();
  7314. }
  7315. /** Returns the current number of objects in the array. */
  7316. inline int size() const throw()
  7317. {
  7318. return numUsed;
  7319. }
  7320. /** Returns a pointer to the object at this index in the array.
  7321. If the index is out-of-range, this will return a null pointer, (and
  7322. it could be null anyway, because it's ok for the array to hold null
  7323. pointers as well as objects).
  7324. @see getUnchecked
  7325. */
  7326. inline ObjectClass* operator[] (const int index) const throw()
  7327. {
  7328. lock.enter();
  7329. ObjectClass* const result = (((unsigned int) index) < (unsigned int) numUsed)
  7330. ? this->elements [index]
  7331. : (ObjectClass*) 0;
  7332. lock.exit();
  7333. return result;
  7334. }
  7335. /** Returns a pointer to the object at this index in the array, without checking whether the index is in-range.
  7336. This is a faster and less safe version of operator[] which doesn't check the index passed in, so
  7337. it can be used when you're sure the index if always going to be legal.
  7338. */
  7339. inline ObjectClass* getUnchecked (const int index) const throw()
  7340. {
  7341. lock.enter();
  7342. jassert (((unsigned int) index) < (unsigned int) numUsed);
  7343. ObjectClass* const result = this->elements [index];
  7344. lock.exit();
  7345. return result;
  7346. }
  7347. /** Returns a pointer to the first object in the array.
  7348. This will return a null pointer if the array's empty.
  7349. @see getLast
  7350. */
  7351. inline ObjectClass* getFirst() const throw()
  7352. {
  7353. lock.enter();
  7354. ObjectClass* const result = (numUsed > 0) ? this->elements [0]
  7355. : (ObjectClass*) 0;
  7356. lock.exit();
  7357. return result;
  7358. }
  7359. /** Returns a pointer to the last object in the array.
  7360. This will return a null pointer if the array's empty.
  7361. @see getFirst
  7362. */
  7363. inline ObjectClass* getLast() const throw()
  7364. {
  7365. lock.enter();
  7366. ObjectClass* const result = (numUsed > 0) ? this->elements [numUsed - 1]
  7367. : (ObjectClass*) 0;
  7368. lock.exit();
  7369. return result;
  7370. }
  7371. /** Finds the index of the first occurrence of an object in the array.
  7372. @param objectToLookFor the object to look for
  7373. @returns the index at which the object was found, or -1 if it's not found
  7374. */
  7375. int indexOf (const ObjectClass* const objectToLookFor) const throw()
  7376. {
  7377. int result = -1;
  7378. lock.enter();
  7379. ObjectClass** e = this->elements;
  7380. for (int i = numUsed; --i >= 0;)
  7381. {
  7382. if (objectToLookFor == *e)
  7383. {
  7384. result = (int) (e - this->elements);
  7385. break;
  7386. }
  7387. ++e;
  7388. }
  7389. lock.exit();
  7390. return result;
  7391. }
  7392. /** Returns true if the array contains a specified object.
  7393. @param objectToLookFor the object to look for
  7394. @returns true if the object is in the array
  7395. */
  7396. bool contains (const ObjectClass* const objectToLookFor) const throw()
  7397. {
  7398. lock.enter();
  7399. ObjectClass** e = this->elements;
  7400. for (int i = numUsed; --i >= 0;)
  7401. {
  7402. if (objectToLookFor == *e)
  7403. {
  7404. lock.exit();
  7405. return true;
  7406. }
  7407. ++e;
  7408. }
  7409. lock.exit();
  7410. return false;
  7411. }
  7412. /** Appends a new object to the end of the array.
  7413. This will increase the new object's reference count.
  7414. @param newObject the new object to add to the array
  7415. @see set, insert, addIfNotAlreadyThere, addSorted, addArray
  7416. */
  7417. void add (ObjectClass* const newObject) throw()
  7418. {
  7419. lock.enter();
  7420. this->ensureAllocatedSize (numUsed + 1);
  7421. this->elements [numUsed++] = newObject;
  7422. if (newObject != 0)
  7423. newObject->incReferenceCount();
  7424. lock.exit();
  7425. }
  7426. /** Inserts a new object into the array at the given index.
  7427. If the index is less than 0 or greater than the size of the array, the
  7428. element will be added to the end of the array.
  7429. Otherwise, it will be inserted into the array, moving all the later elements
  7430. along to make room.
  7431. This will increase the new object's reference count.
  7432. @param indexToInsertAt the index at which the new element should be inserted
  7433. @param newObject the new object to add to the array
  7434. @see add, addSorted, addIfNotAlreadyThere, set
  7435. */
  7436. void insert (int indexToInsertAt,
  7437. ObjectClass* const newObject) throw()
  7438. {
  7439. if (indexToInsertAt >= 0)
  7440. {
  7441. lock.enter();
  7442. if (indexToInsertAt > numUsed)
  7443. indexToInsertAt = numUsed;
  7444. this->ensureAllocatedSize (numUsed + 1);
  7445. ObjectClass** const e = this->elements + indexToInsertAt;
  7446. const int numToMove = numUsed - indexToInsertAt;
  7447. if (numToMove > 0)
  7448. memmove (e + 1, e, numToMove * sizeof (ObjectClass*));
  7449. *e = newObject;
  7450. if (newObject != 0)
  7451. newObject->incReferenceCount();
  7452. ++numUsed;
  7453. lock.exit();
  7454. }
  7455. else
  7456. {
  7457. add (newObject);
  7458. }
  7459. }
  7460. /** Appends a new object at the end of the array as long as the array doesn't
  7461. already contain it.
  7462. If the array already contains a matching object, nothing will be done.
  7463. @param newObject the new object to add to the array
  7464. */
  7465. void addIfNotAlreadyThere (ObjectClass* const newObject) throw()
  7466. {
  7467. lock.enter();
  7468. if (! contains (newObject))
  7469. add (newObject);
  7470. lock.exit();
  7471. }
  7472. /** Replaces an object in the array with a different one.
  7473. If the index is less than zero, this method does nothing.
  7474. If the index is beyond the end of the array, the new object is added to the end of the array.
  7475. The object being added has its reference count increased, and if it's replacing
  7476. another object, then that one has its reference count decreased, and may be deleted.
  7477. @param indexToChange the index whose value you want to change
  7478. @param newObject the new value to set for this index.
  7479. @see add, insert, remove
  7480. */
  7481. void set (const int indexToChange,
  7482. ObjectClass* const newObject)
  7483. {
  7484. if (indexToChange >= 0)
  7485. {
  7486. lock.enter();
  7487. if (newObject != 0)
  7488. newObject->incReferenceCount();
  7489. if (indexToChange < numUsed)
  7490. {
  7491. if (this->elements [indexToChange] != 0)
  7492. this->elements [indexToChange]->decReferenceCount();
  7493. this->elements [indexToChange] = newObject;
  7494. }
  7495. else
  7496. {
  7497. this->ensureAllocatedSize (numUsed + 1);
  7498. this->elements [numUsed++] = newObject;
  7499. }
  7500. lock.exit();
  7501. }
  7502. }
  7503. /** Adds elements from another array to the end of this array.
  7504. @param arrayToAddFrom the array from which to copy the elements
  7505. @param startIndex the first element of the other array to start copying from
  7506. @param numElementsToAdd how many elements to add from the other array. If this
  7507. value is negative or greater than the number of available elements,
  7508. all available elements will be copied.
  7509. @see add
  7510. */
  7511. void addArray (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& arrayToAddFrom,
  7512. int startIndex = 0,
  7513. int numElementsToAdd = -1) throw()
  7514. {
  7515. arrayToAddFrom.lockArray();
  7516. lock.enter();
  7517. if (startIndex < 0)
  7518. {
  7519. jassertfalse
  7520. startIndex = 0;
  7521. }
  7522. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size())
  7523. numElementsToAdd = arrayToAddFrom.size() - startIndex;
  7524. if (numElementsToAdd > 0)
  7525. {
  7526. this->ensureAllocatedSize (numUsed + numElementsToAdd);
  7527. while (--numElementsToAdd >= 0)
  7528. add (arrayToAddFrom.getUnchecked (startIndex++));
  7529. }
  7530. lock.exit();
  7531. arrayToAddFrom.unlockArray();
  7532. }
  7533. /** Inserts a new object into the array assuming that the array is sorted.
  7534. This will use a comparator to find the position at which the new object
  7535. should go. If the array isn't sorted, the behaviour of this
  7536. method will be unpredictable.
  7537. @param comparator the comparator object to use to compare the elements - see the
  7538. sort() method for details about this object's form
  7539. @param newObject the new object to insert to the array
  7540. @see add, sort
  7541. */
  7542. template <class ElementComparator>
  7543. void addSorted (ElementComparator& comparator,
  7544. ObjectClass* newObject) throw()
  7545. {
  7546. lock.enter();
  7547. insert (findInsertIndexInSortedArray (comparator, this->elements, newObject, 0, numUsed), newObject);
  7548. lock.exit();
  7549. }
  7550. /** Removes an object from the array.
  7551. This will remove the object at a given index and move back all the
  7552. subsequent objects to close the gap.
  7553. If the index passed in is out-of-range, nothing will happen.
  7554. The object that is removed will have its reference count decreased,
  7555. and may be deleted if not referenced from elsewhere.
  7556. @param indexToRemove the index of the element to remove
  7557. @see removeObject, removeRange
  7558. */
  7559. void remove (const int indexToRemove)
  7560. {
  7561. lock.enter();
  7562. if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
  7563. {
  7564. ObjectClass** const e = this->elements + indexToRemove;
  7565. if (*e != 0)
  7566. (*e)->decReferenceCount();
  7567. --numUsed;
  7568. const int numberToShift = numUsed - indexToRemove;
  7569. if (numberToShift > 0)
  7570. memmove (e, e + 1, numberToShift * sizeof (ObjectClass*));
  7571. if ((numUsed << 1) < this->numAllocated)
  7572. minimiseStorageOverheads();
  7573. }
  7574. lock.exit();
  7575. }
  7576. /** Removes the first occurrence of a specified object from the array.
  7577. If the item isn't found, no action is taken. If it is found, it is
  7578. removed and has its reference count decreased.
  7579. @param objectToRemove the object to try to remove
  7580. @see remove, removeRange
  7581. */
  7582. void removeObject (ObjectClass* const objectToRemove)
  7583. {
  7584. lock.enter();
  7585. remove (indexOf (objectToRemove));
  7586. lock.exit();
  7587. }
  7588. /** Removes a range of objects from the array.
  7589. This will remove a set of objects, starting from the given index,
  7590. and move any subsequent elements down to close the gap.
  7591. If the range extends beyond the bounds of the array, it will
  7592. be safely clipped to the size of the array.
  7593. The objects that are removed will have their reference counts decreased,
  7594. and may be deleted if not referenced from elsewhere.
  7595. @param startIndex the index of the first object to remove
  7596. @param numberToRemove how many objects should be removed
  7597. @see remove, removeObject
  7598. */
  7599. void removeRange (const int startIndex,
  7600. const int numberToRemove)
  7601. {
  7602. lock.enter();
  7603. const int start = jlimit (0, numUsed, startIndex);
  7604. const int end = jlimit (0, numUsed, startIndex + numberToRemove);
  7605. if (end > start)
  7606. {
  7607. int i;
  7608. for (i = start; i < end; ++i)
  7609. {
  7610. if (this->elements[i] != 0)
  7611. {
  7612. this->elements[i]->decReferenceCount();
  7613. this->elements[i] = 0; // (in case one of the destructors accesses this array and hits a dangling pointer)
  7614. }
  7615. }
  7616. const int rangeSize = end - start;
  7617. ObjectClass** e = this->elements + start;
  7618. i = numUsed - end;
  7619. numUsed -= rangeSize;
  7620. while (--i >= 0)
  7621. {
  7622. *e = e [rangeSize];
  7623. ++e;
  7624. }
  7625. if ((numUsed << 1) < this->numAllocated)
  7626. minimiseStorageOverheads();
  7627. }
  7628. lock.exit();
  7629. }
  7630. /** Removes the last n objects from the array.
  7631. The objects that are removed will have their reference counts decreased,
  7632. and may be deleted if not referenced from elsewhere.
  7633. @param howManyToRemove how many objects to remove from the end of the array
  7634. @see remove, removeObject, removeRange
  7635. */
  7636. void removeLast (int howManyToRemove = 1)
  7637. {
  7638. lock.enter();
  7639. if (howManyToRemove > numUsed)
  7640. howManyToRemove = numUsed;
  7641. while (--howManyToRemove >= 0)
  7642. remove (numUsed - 1);
  7643. lock.exit();
  7644. }
  7645. /** Swaps a pair of objects in the array.
  7646. If either of the indexes passed in is out-of-range, nothing will happen,
  7647. otherwise the two objects at these positions will be exchanged.
  7648. */
  7649. void swap (const int index1,
  7650. const int index2) throw()
  7651. {
  7652. lock.enter();
  7653. if (((unsigned int) index1) < (unsigned int) numUsed
  7654. && ((unsigned int) index2) < (unsigned int) numUsed)
  7655. {
  7656. swapVariables (this->elements [index1],
  7657. this->elements [index2]);
  7658. }
  7659. lock.exit();
  7660. }
  7661. /** Moves one of the objects to a different position.
  7662. This will move the object to a specified index, shuffling along
  7663. any intervening elements as required.
  7664. So for example, if you have the array { 0, 1, 2, 3, 4, 5 } then calling
  7665. move (2, 4) would result in { 0, 1, 3, 4, 2, 5 }.
  7666. @param currentIndex the index of the object to be moved. If this isn't a
  7667. valid index, then nothing will be done
  7668. @param newIndex the index at which you'd like this object to end up. If this
  7669. is less than zero, it will be moved to the end of the array
  7670. */
  7671. void move (const int currentIndex,
  7672. int newIndex) throw()
  7673. {
  7674. if (currentIndex != newIndex)
  7675. {
  7676. lock.enter();
  7677. if (((unsigned int) currentIndex) < (unsigned int) numUsed)
  7678. {
  7679. if (((unsigned int) newIndex) >= (unsigned int) numUsed)
  7680. newIndex = numUsed - 1;
  7681. ObjectClass* const value = this->elements [currentIndex];
  7682. if (newIndex > currentIndex)
  7683. {
  7684. memmove (this->elements + currentIndex,
  7685. this->elements + currentIndex + 1,
  7686. (newIndex - currentIndex) * sizeof (ObjectClass*));
  7687. }
  7688. else
  7689. {
  7690. memmove (this->elements + newIndex + 1,
  7691. this->elements + newIndex,
  7692. (currentIndex - newIndex) * sizeof (ObjectClass*));
  7693. }
  7694. this->elements [newIndex] = value;
  7695. }
  7696. lock.exit();
  7697. }
  7698. }
  7699. /** Compares this array to another one.
  7700. @returns true only if the other array contains the same objects in the same order
  7701. */
  7702. bool operator== (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) const throw()
  7703. {
  7704. other.lockArray();
  7705. lock.enter();
  7706. bool result = numUsed == other.numUsed;
  7707. if (result)
  7708. {
  7709. for (int i = numUsed; --i >= 0;)
  7710. {
  7711. if (this->elements [i] != other.elements [i])
  7712. {
  7713. result = false;
  7714. break;
  7715. }
  7716. }
  7717. }
  7718. lock.exit();
  7719. other.unlockArray();
  7720. return result;
  7721. }
  7722. /** Compares this array to another one.
  7723. @see operator==
  7724. */
  7725. bool operator!= (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) const throw()
  7726. {
  7727. return ! operator== (other);
  7728. }
  7729. /** Sorts the elements in the array.
  7730. This will use a comparator object to sort the elements into order. The object
  7731. passed must have a method of the form:
  7732. @code
  7733. int compareElements (ElementType first, ElementType second);
  7734. @endcode
  7735. ..and this method must return:
  7736. - a value of < 0 if the first comes before the second
  7737. - a value of 0 if the two objects are equivalent
  7738. - a value of > 0 if the second comes before the first
  7739. To improve performance, the compareElements() method can be declared as static or const.
  7740. @param comparator the comparator to use for comparing elements.
  7741. @param retainOrderOfEquivalentItems if this is true, then items
  7742. which the comparator says are equivalent will be
  7743. kept in the order in which they currently appear
  7744. in the array. This is slower to perform, but may
  7745. be important in some cases. If it's false, a faster
  7746. algorithm is used, but equivalent elements may be
  7747. rearranged.
  7748. @see sortArray
  7749. */
  7750. template <class ElementComparator>
  7751. void sort (ElementComparator& comparator,
  7752. const bool retainOrderOfEquivalentItems = false) const throw()
  7753. {
  7754. (void) comparator; // if you pass in an object with a static compareElements() method, this
  7755. // avoids getting warning messages about the parameter being unused
  7756. lock.enter();
  7757. sortArray (comparator, this->elements, 0, size() - 1, retainOrderOfEquivalentItems);
  7758. lock.exit();
  7759. }
  7760. /** Reduces the amount of storage being used by the array.
  7761. Arrays typically allocate slightly more storage than they need, and after
  7762. removing elements, they may have quite a lot of unused space allocated.
  7763. This method will reduce the amount of allocated storage to a minimum.
  7764. */
  7765. void minimiseStorageOverheads() throw()
  7766. {
  7767. lock.enter();
  7768. if (numUsed == 0)
  7769. {
  7770. this->setAllocatedSize (0);
  7771. }
  7772. else
  7773. {
  7774. const int newAllocation = this->granularity * (numUsed / this->granularity + 1);
  7775. if (newAllocation < this->numAllocated)
  7776. this->setAllocatedSize (newAllocation);
  7777. }
  7778. lock.exit();
  7779. }
  7780. /** Locks the array's CriticalSection.
  7781. Of course if the type of section used is a DummyCriticalSection, this won't
  7782. have any effect.
  7783. @see unlockArray
  7784. */
  7785. void lockArray() const throw()
  7786. {
  7787. lock.enter();
  7788. }
  7789. /** Unlocks the array's CriticalSection.
  7790. Of course if the type of section used is a DummyCriticalSection, this won't
  7791. have any effect.
  7792. @see lockArray
  7793. */
  7794. void unlockArray() const throw()
  7795. {
  7796. lock.exit();
  7797. }
  7798. juce_UseDebuggingNewOperator
  7799. private:
  7800. int numUsed;
  7801. TypeOfCriticalSectionToUse lock;
  7802. };
  7803. #endif // __JUCE_REFERENCECOUNTEDARRAY_JUCEHEADER__
  7804. /********* End of inlined file: juce_ReferenceCountedArray.h *********/
  7805. #endif
  7806. #ifndef __JUCE_REFERENCECOUNTEDOBJECT_JUCEHEADER__
  7807. #endif
  7808. #ifndef __JUCE_SORTEDSET_JUCEHEADER__
  7809. /********* Start of inlined file: juce_SortedSet.h *********/
  7810. #ifndef __JUCE_SORTEDSET_JUCEHEADER__
  7811. #define __JUCE_SORTEDSET_JUCEHEADER__
  7812. #if JUCE_MSVC
  7813. #pragma warning (push)
  7814. #pragma warning (disable: 4512)
  7815. #endif
  7816. /**
  7817. Holds a set of unique primitive objects, such as ints or doubles.
  7818. A set can only hold one item with a given value, so if for example it's a
  7819. set of integers, attempting to add the same integer twice will do nothing
  7820. the second time.
  7821. Internally, the list of items is kept sorted (which means that whatever
  7822. kind of primitive type is used must support the ==, <, >, <= and >= operators
  7823. to determine the order), and searching the set for known values is very fast
  7824. because it uses a binary-chop method.
  7825. Note that if you're using a class or struct as the element type, it must be
  7826. capable of being copied or moved with a straightforward memcpy, rather than
  7827. needing construction and destruction code.
  7828. To make all the set's methods thread-safe, pass in "CriticalSection" as the templated
  7829. TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.
  7830. @see Array, OwnedArray, ReferenceCountedArray, StringArray, CriticalSection
  7831. */
  7832. template <class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
  7833. class SortedSet : private ArrayAllocationBase <ElementType>
  7834. {
  7835. public:
  7836. /** Creates an empty set.
  7837. @param granularity this is the size of increment by which the internal storage
  7838. used by the array will grow. Only change it from the default if you know the
  7839. array is going to be very big and needs to be able to grow efficiently.
  7840. @see ArrayAllocationBase
  7841. */
  7842. SortedSet (const int granularity = juceDefaultArrayGranularity) throw()
  7843. : ArrayAllocationBase <ElementType> (granularity),
  7844. numUsed (0)
  7845. {
  7846. }
  7847. /** Creates a copy of another set.
  7848. @param other the set to copy
  7849. */
  7850. SortedSet (const SortedSet<ElementType, TypeOfCriticalSectionToUse>& other) throw()
  7851. : ArrayAllocationBase <ElementType> (other.granularity)
  7852. {
  7853. other.lockSet();
  7854. numUsed = other.numUsed;
  7855. setAllocatedSize (other.numUsed);
  7856. memcpy (this->elements, other.elements, numUsed * sizeof (ElementType));
  7857. other.unlockSet();
  7858. }
  7859. /** Destructor. */
  7860. ~SortedSet() throw()
  7861. {
  7862. }
  7863. /** Copies another set over this one.
  7864. @param other the set to copy
  7865. */
  7866. const SortedSet <ElementType, TypeOfCriticalSectionToUse>& operator= (const SortedSet <ElementType, TypeOfCriticalSectionToUse>& other) throw()
  7867. {
  7868. if (this != &other)
  7869. {
  7870. other.lockSet();
  7871. lock.enter();
  7872. this->granularity = other.granularity;
  7873. ensureAllocatedSize (other.size());
  7874. numUsed = other.numUsed;
  7875. memcpy (this->elements, other.elements, numUsed * sizeof (ElementType));
  7876. minimiseStorageOverheads();
  7877. lock.exit();
  7878. other.unlockSet();
  7879. }
  7880. return *this;
  7881. }
  7882. /** Compares this set to another one.
  7883. Two sets are considered equal if they both contain the same set of
  7884. elements.
  7885. @param other the other set to compare with
  7886. */
  7887. bool operator== (const SortedSet<ElementType>& other) const throw()
  7888. {
  7889. lock.enter();
  7890. if (numUsed != other.numUsed)
  7891. {
  7892. lock.exit();
  7893. return false;
  7894. }
  7895. for (int i = numUsed; --i >= 0;)
  7896. {
  7897. if (this->elements [i] != other.elements [i])
  7898. {
  7899. lock.exit();
  7900. return false;
  7901. }
  7902. }
  7903. lock.exit();
  7904. return true;
  7905. }
  7906. /** Compares this set to another one.
  7907. Two sets are considered equal if they both contain the same set of
  7908. elements.
  7909. @param other the other set to compare with
  7910. */
  7911. bool operator!= (const SortedSet<ElementType>& other) const throw()
  7912. {
  7913. return ! operator== (other);
  7914. }
  7915. /** Removes all elements from the set.
  7916. This will remove all the elements, and free any storage that the set is
  7917. using. To clear it without freeing the storage, use the clearQuick()
  7918. method instead.
  7919. @see clearQuick
  7920. */
  7921. void clear() throw()
  7922. {
  7923. lock.enter();
  7924. this->setAllocatedSize (0);
  7925. numUsed = 0;
  7926. lock.exit();
  7927. }
  7928. /** Removes all elements from the set without freeing the array's allocated storage.
  7929. @see clear
  7930. */
  7931. void clearQuick() throw()
  7932. {
  7933. lock.enter();
  7934. numUsed = 0;
  7935. lock.exit();
  7936. }
  7937. /** Returns the current number of elements in the set.
  7938. */
  7939. inline int size() const throw()
  7940. {
  7941. return numUsed;
  7942. }
  7943. /** Returns one of the elements in the set.
  7944. If the index passed in is beyond the range of valid elements, this
  7945. will return zero.
  7946. If you're certain that the index will always be a valid element, you
  7947. can call getUnchecked() instead, which is faster.
  7948. @param index the index of the element being requested (0 is the first element in the set)
  7949. @see getUnchecked, getFirst, getLast
  7950. */
  7951. inline ElementType operator[] (const int index) const throw()
  7952. {
  7953. lock.enter();
  7954. const ElementType result = (((unsigned int) index) < (unsigned int) numUsed)
  7955. ? this->elements [index]
  7956. : (ElementType) 0;
  7957. lock.exit();
  7958. return result;
  7959. }
  7960. /** Returns one of the elements in the set, without checking the index passed in.
  7961. Unlike the operator[] method, this will try to return an element without
  7962. checking that the index is within the bounds of the set, so should only
  7963. be used when you're confident that it will always be a valid index.
  7964. @param index the index of the element being requested (0 is the first element in the set)
  7965. @see operator[], getFirst, getLast
  7966. */
  7967. inline ElementType getUnchecked (const int index) const throw()
  7968. {
  7969. lock.enter();
  7970. jassert (((unsigned int) index) < (unsigned int) numUsed);
  7971. const ElementType result = this->elements [index];
  7972. lock.exit();
  7973. return result;
  7974. }
  7975. /** Returns the first element in the set, or 0 if the set is empty.
  7976. @see operator[], getUnchecked, getLast
  7977. */
  7978. inline ElementType getFirst() const throw()
  7979. {
  7980. lock.enter();
  7981. const ElementType result = (numUsed > 0) ? this->elements [0]
  7982. : (ElementType) 0;
  7983. lock.exit();
  7984. return result;
  7985. }
  7986. /** Returns the last element in the set, or 0 if the set is empty.
  7987. @see operator[], getUnchecked, getFirst
  7988. */
  7989. inline ElementType getLast() const throw()
  7990. {
  7991. lock.enter();
  7992. const ElementType result = (numUsed > 0) ? this->elements [numUsed - 1]
  7993. : (ElementType) 0;
  7994. lock.exit();
  7995. return result;
  7996. }
  7997. /** Finds the index of the first element which matches the value passed in.
  7998. This will search the set for the given object, and return the index
  7999. of its first occurrence. If the object isn't found, the method will return -1.
  8000. @param elementToLookFor the value or object to look for
  8001. @returns the index of the object, or -1 if it's not found
  8002. */
  8003. int indexOf (const ElementType elementToLookFor) const throw()
  8004. {
  8005. lock.enter();
  8006. int start = 0;
  8007. int end = numUsed;
  8008. for (;;)
  8009. {
  8010. if (start >= end)
  8011. {
  8012. lock.exit();
  8013. return -1;
  8014. }
  8015. else if (elementToLookFor == this->elements [start])
  8016. {
  8017. lock.exit();
  8018. return start;
  8019. }
  8020. else
  8021. {
  8022. const int halfway = (start + end) >> 1;
  8023. if (halfway == start)
  8024. {
  8025. lock.exit();
  8026. return -1;
  8027. }
  8028. else if (elementToLookFor >= this->elements [halfway])
  8029. start = halfway;
  8030. else
  8031. end = halfway;
  8032. }
  8033. }
  8034. }
  8035. /** Returns true if the set contains at least one occurrence of an object.
  8036. @param elementToLookFor the value or object to look for
  8037. @returns true if the item is found
  8038. */
  8039. bool contains (const ElementType elementToLookFor) const throw()
  8040. {
  8041. lock.enter();
  8042. int start = 0;
  8043. int end = numUsed;
  8044. for (;;)
  8045. {
  8046. if (start >= end)
  8047. {
  8048. lock.exit();
  8049. return false;
  8050. }
  8051. else if (elementToLookFor == this->elements [start])
  8052. {
  8053. lock.exit();
  8054. return true;
  8055. }
  8056. else
  8057. {
  8058. const int halfway = (start + end) >> 1;
  8059. if (halfway == start)
  8060. {
  8061. lock.exit();
  8062. return false;
  8063. }
  8064. else if (elementToLookFor >= this->elements [halfway])
  8065. start = halfway;
  8066. else
  8067. end = halfway;
  8068. }
  8069. }
  8070. }
  8071. /** Adds a new element to the set, (as long as it's not already in there).
  8072. @param newElement the new object to add to the set
  8073. @see set, insert, addIfNotAlreadyThere, addSorted, addSet, addArray
  8074. */
  8075. void add (const ElementType newElement) throw()
  8076. {
  8077. lock.enter();
  8078. int start = 0;
  8079. int end = numUsed;
  8080. for (;;)
  8081. {
  8082. if (start >= end)
  8083. {
  8084. jassert (start <= end);
  8085. insertInternal (start, newElement);
  8086. break;
  8087. }
  8088. else if (newElement == this->elements [start])
  8089. {
  8090. break;
  8091. }
  8092. else
  8093. {
  8094. const int halfway = (start + end) >> 1;
  8095. if (halfway == start)
  8096. {
  8097. if (newElement >= this->elements [halfway])
  8098. insertInternal (start + 1, newElement);
  8099. else
  8100. insertInternal (start, newElement);
  8101. break;
  8102. }
  8103. else if (newElement >= this->elements [halfway])
  8104. start = halfway;
  8105. else
  8106. end = halfway;
  8107. }
  8108. }
  8109. lock.exit();
  8110. }
  8111. /** Adds elements from an array to this set.
  8112. @param elementsToAdd the array of elements to add
  8113. @param numElementsToAdd how many elements are in this other array
  8114. @see add
  8115. */
  8116. void addArray (const ElementType* elementsToAdd,
  8117. int numElementsToAdd) throw()
  8118. {
  8119. lock.enter();
  8120. while (--numElementsToAdd >= 0)
  8121. add (*elementsToAdd++);
  8122. lock.exit();
  8123. }
  8124. /** Adds elements from another set to this one.
  8125. @param setToAddFrom the set from which to copy the elements
  8126. @param startIndex the first element of the other set to start copying from
  8127. @param numElementsToAdd how many elements to add from the other set. If this
  8128. value is negative or greater than the number of available elements,
  8129. all available elements will be copied.
  8130. @see add
  8131. */
  8132. template <class OtherSetType>
  8133. void addSet (const OtherSetType& setToAddFrom,
  8134. int startIndex = 0,
  8135. int numElementsToAdd = -1) throw()
  8136. {
  8137. setToAddFrom.lockSet();
  8138. lock.enter();
  8139. jassert (this != &setToAddFrom);
  8140. if (this != &setToAddFrom)
  8141. {
  8142. if (startIndex < 0)
  8143. {
  8144. jassertfalse
  8145. startIndex = 0;
  8146. }
  8147. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > setToAddFrom.size())
  8148. numElementsToAdd = setToAddFrom.size() - startIndex;
  8149. addArray (setToAddFrom.elements + startIndex, numElementsToAdd);
  8150. }
  8151. lock.exit();
  8152. setToAddFrom.unlockSet();
  8153. }
  8154. /** Removes an element from the set.
  8155. This will remove the element at a given index.
  8156. If the index passed in is out-of-range, nothing will happen.
  8157. @param indexToRemove the index of the element to remove
  8158. @returns the element that has been removed
  8159. @see removeValue, removeRange
  8160. */
  8161. ElementType remove (const int indexToRemove) throw()
  8162. {
  8163. lock.enter();
  8164. if (((unsigned int) indexToRemove) < (unsigned int) numUsed)
  8165. {
  8166. --numUsed;
  8167. ElementType* const e = this->elements + indexToRemove;
  8168. ElementType const removed = *e;
  8169. const int numberToShift = numUsed - indexToRemove;
  8170. if (numberToShift > 0)
  8171. memmove (e, e + 1, numberToShift * sizeof (ElementType));
  8172. if ((numUsed << 1) < this->numAllocated)
  8173. minimiseStorageOverheads();
  8174. lock.exit();
  8175. return removed;
  8176. }
  8177. else
  8178. {
  8179. lock.exit();
  8180. return 0;
  8181. }
  8182. }
  8183. /** Removes an item from the set.
  8184. This will remove the given element from the set, if it's there.
  8185. @param valueToRemove the object to try to remove
  8186. @see remove, removeRange
  8187. */
  8188. void removeValue (const ElementType valueToRemove) throw()
  8189. {
  8190. lock.enter();
  8191. remove (indexOf (valueToRemove));
  8192. lock.exit();
  8193. }
  8194. /** Removes any elements which are also in another set.
  8195. @param otherSet the other set in which to look for elements to remove
  8196. @see removeValuesNotIn, remove, removeValue, removeRange
  8197. */
  8198. template <class OtherSetType>
  8199. void removeValuesIn (const OtherSetType& otherSet) throw()
  8200. {
  8201. otherSet.lockSet();
  8202. lock.enter();
  8203. if (this == &otherSet)
  8204. {
  8205. clear();
  8206. }
  8207. else
  8208. {
  8209. if (otherSet.size() > 0)
  8210. {
  8211. for (int i = numUsed; --i >= 0;)
  8212. if (otherSet.contains (this->elements [i]))
  8213. remove (i);
  8214. }
  8215. }
  8216. lock.exit();
  8217. otherSet.unlockSet();
  8218. }
  8219. /** Removes any elements which are not found in another set.
  8220. Only elements which occur in this other set will be retained.
  8221. @param otherSet the set in which to look for elements NOT to remove
  8222. @see removeValuesIn, remove, removeValue, removeRange
  8223. */
  8224. template <class OtherSetType>
  8225. void removeValuesNotIn (const OtherSetType& otherSet) throw()
  8226. {
  8227. otherSet.lockSet();
  8228. lock.enter();
  8229. if (this != &otherSet)
  8230. {
  8231. if (otherSet.size() <= 0)
  8232. {
  8233. clear();
  8234. }
  8235. else
  8236. {
  8237. for (int i = numUsed; --i >= 0;)
  8238. if (! otherSet.contains (this->elements [i]))
  8239. remove (i);
  8240. }
  8241. }
  8242. lock.exit();
  8243. otherSet.lockSet();
  8244. }
  8245. /** Reduces the amount of storage being used by the set.
  8246. Sets typically allocate slightly more storage than they need, and after
  8247. removing elements, they may have quite a lot of unused space allocated.
  8248. This method will reduce the amount of allocated storage to a minimum.
  8249. */
  8250. void minimiseStorageOverheads() throw()
  8251. {
  8252. lock.enter();
  8253. if (numUsed == 0)
  8254. {
  8255. this->setAllocatedSize (0);
  8256. }
  8257. else
  8258. {
  8259. const int newAllocation = this->granularity * (numUsed / this->granularity + 1);
  8260. if (newAllocation < this->numAllocated)
  8261. this->setAllocatedSize (newAllocation);
  8262. }
  8263. lock.exit();
  8264. }
  8265. /** Locks the set's CriticalSection.
  8266. Of course if the type of section used is a DummyCriticalSection, this won't
  8267. have any effect.
  8268. @see unlockSet
  8269. */
  8270. void lockSet() const throw()
  8271. {
  8272. lock.enter();
  8273. }
  8274. /** Unlocks the set's CriticalSection.
  8275. Of course if the type of section used is a DummyCriticalSection, this won't
  8276. have any effect.
  8277. @see lockSet
  8278. */
  8279. void unlockSet() const throw()
  8280. {
  8281. lock.exit();
  8282. }
  8283. juce_UseDebuggingNewOperator
  8284. private:
  8285. int numUsed;
  8286. TypeOfCriticalSectionToUse lock;
  8287. void insertInternal (const int indexToInsertAt, const ElementType newElement) throw()
  8288. {
  8289. this->ensureAllocatedSize (numUsed + 1);
  8290. ElementType* const insertPos = this->elements + indexToInsertAt;
  8291. const int numberToMove = numUsed - indexToInsertAt;
  8292. if (numberToMove > 0)
  8293. memmove (insertPos + 1, insertPos, numberToMove * sizeof (ElementType));
  8294. *insertPos = newElement;
  8295. ++numUsed;
  8296. }
  8297. };
  8298. #if JUCE_MSVC
  8299. #pragma warning (pop)
  8300. #endif
  8301. #endif // __JUCE_SORTEDSET_JUCEHEADER__
  8302. /********* End of inlined file: juce_SortedSet.h *********/
  8303. #endif
  8304. #ifndef __JUCE_SPARSESET_JUCEHEADER__
  8305. /********* Start of inlined file: juce_SparseSet.h *********/
  8306. #ifndef __JUCE_SPARSESET_JUCEHEADER__
  8307. #define __JUCE_SPARSESET_JUCEHEADER__
  8308. /**
  8309. Holds a set of primitive values, storing them as a set of ranges.
  8310. This container acts like a simple BitArray, but can efficiently hold large
  8311. continguous ranges of values. It's quite a specialised class, mostly useful
  8312. for things like keeping the set of selected rows in a listbox.
  8313. The type used as a template paramter must be an integer type, such as int, short,
  8314. int64, etc.
  8315. */
  8316. template <class Type>
  8317. class SparseSet
  8318. {
  8319. public:
  8320. /** Creates a new empty set. */
  8321. SparseSet() throw()
  8322. {
  8323. }
  8324. /** Creates a copy of another SparseSet. */
  8325. SparseSet (const SparseSet<Type>& other) throw()
  8326. : values (other.values)
  8327. {
  8328. }
  8329. /** Destructor. */
  8330. ~SparseSet() throw()
  8331. {
  8332. }
  8333. /** Clears the set. */
  8334. void clear() throw()
  8335. {
  8336. values.clear();
  8337. }
  8338. /** Checks whether the set is empty.
  8339. This is much quicker than using (size() == 0).
  8340. */
  8341. bool isEmpty() const throw()
  8342. {
  8343. return values.size() == 0;
  8344. }
  8345. /** Returns the number of values in the set.
  8346. Because of the way the data is stored, this method can take longer if there
  8347. are a lot of items in the set. Use isEmpty() for a quick test of whether there
  8348. are any items.
  8349. */
  8350. Type size() const throw()
  8351. {
  8352. Type num = 0;
  8353. for (int i = 0; i < values.size(); i += 2)
  8354. num += values[i + 1] - values[i];
  8355. return num;
  8356. }
  8357. /** Returns one of the values in the set.
  8358. @param index the index of the value to retrieve, in the range 0 to (size() - 1).
  8359. @returns the value at this index, or 0 if it's out-of-range
  8360. */
  8361. Type operator[] (int index) const throw()
  8362. {
  8363. for (int i = 0; i < values.size(); i += 2)
  8364. {
  8365. const Type s = values.getUnchecked(i);
  8366. const Type e = values.getUnchecked(i + 1);
  8367. if (index < e - s)
  8368. return s + index;
  8369. index -= e - s;
  8370. }
  8371. return (Type) 0;
  8372. }
  8373. /** Checks whether a particular value is in the set. */
  8374. bool contains (const Type valueToLookFor) const throw()
  8375. {
  8376. bool on = false;
  8377. for (int i = 0; i < values.size(); ++i)
  8378. {
  8379. if (values.getUnchecked(i) > valueToLookFor)
  8380. return on;
  8381. on = ! on;
  8382. }
  8383. return false;
  8384. }
  8385. /** Returns the number of contiguous blocks of values.
  8386. @see getRange
  8387. */
  8388. int getNumRanges() const throw()
  8389. {
  8390. return values.size() >> 1;
  8391. }
  8392. /** Returns one of the contiguous ranges of values stored.
  8393. @param rangeIndex the index of the range to look up, between 0
  8394. and (getNumRanges() - 1)
  8395. @param startValue on return, the value at the start of the range
  8396. @param numValues on return, the number of values in the range
  8397. @see getTotalRange
  8398. */
  8399. bool getRange (const int rangeIndex,
  8400. Type& startValue,
  8401. Type& numValues) const throw()
  8402. {
  8403. if (((unsigned int) rangeIndex) < (unsigned int) getNumRanges())
  8404. {
  8405. startValue = values [rangeIndex << 1];
  8406. numValues = values [(rangeIndex << 1) + 1] - startValue;
  8407. return true;
  8408. }
  8409. return false;
  8410. }
  8411. /** Returns the lowest and highest values in the set.
  8412. @see getRange
  8413. */
  8414. bool getTotalRange (Type& lowestValue,
  8415. Type& highestValue) const throw()
  8416. {
  8417. if (values.size() > 0)
  8418. {
  8419. lowestValue = values.getUnchecked (0);
  8420. highestValue = values.getUnchecked (values.size() - 1);
  8421. return true;
  8422. }
  8423. return false;
  8424. }
  8425. /** Adds a range of contiguous values to the set.
  8426. e.g. addRange (10, 4) will add (10, 11, 12, 13) to the set.
  8427. @param firstValue the start of the range of values to add
  8428. @param numValuesToAdd how many values to add
  8429. */
  8430. void addRange (const Type firstValue,
  8431. const Type numValuesToAdd) throw()
  8432. {
  8433. jassert (numValuesToAdd >= 0);
  8434. if (numValuesToAdd > 0)
  8435. {
  8436. removeRange (firstValue, numValuesToAdd);
  8437. IntegerElementComparator<Type> sorter;
  8438. values.addSorted (sorter, firstValue);
  8439. values.addSorted (sorter, firstValue + numValuesToAdd);
  8440. simplify();
  8441. }
  8442. }
  8443. /** Removes a range of values from the set.
  8444. e.g. removeRange (10, 4) will remove (10, 11, 12, 13) from the set.
  8445. @param firstValue the start of the range of values to remove
  8446. @param numValuesToRemove how many values to remove
  8447. */
  8448. void removeRange (const Type firstValue,
  8449. const Type numValuesToRemove) throw()
  8450. {
  8451. jassert (numValuesToRemove >= 0);
  8452. if (numValuesToRemove > 0
  8453. && firstValue < values.getLast())
  8454. {
  8455. const bool onAtStart = contains (firstValue - 1);
  8456. Type lastValue = firstValue + numValuesToRemove;
  8457. if (lastValue < firstValue) // possible if the signed arithmetic wraps around
  8458. lastValue = values.getLast();
  8459. const bool onAtEnd = contains (lastValue);
  8460. for (int i = values.size(); --i >= 0;)
  8461. {
  8462. if (values.getUnchecked(i) >= firstValue
  8463. && values.getUnchecked(i) <= lastValue)
  8464. {
  8465. values.remove (i);
  8466. }
  8467. }
  8468. IntegerElementComparator<Type> sorter;
  8469. if (onAtStart)
  8470. values.addSorted (sorter, firstValue);
  8471. if (onAtEnd)
  8472. values.addSorted (sorter, lastValue);
  8473. simplify();
  8474. }
  8475. }
  8476. /** Does an XOR of the values in a given range. */
  8477. void invertRange (const Type firstValue,
  8478. const Type numValues)
  8479. {
  8480. SparseSet newItems;
  8481. newItems.addRange (firstValue, numValues);
  8482. int i;
  8483. for (i = getNumRanges(); --i >= 0;)
  8484. {
  8485. const int start = values [i << 1];
  8486. const int end = values [(i << 1) + 1];
  8487. newItems.removeRange (start, end);
  8488. }
  8489. removeRange (firstValue, numValues);
  8490. for (i = newItems.getNumRanges(); --i >= 0;)
  8491. {
  8492. const int start = newItems.values [i << 1];
  8493. const int end = newItems.values [(i << 1) + 1];
  8494. addRange (start, end);
  8495. }
  8496. }
  8497. /** Checks whether any part of a given range overlaps any part of this one. */
  8498. bool overlapsRange (const Type firstValue,
  8499. const Type numValues) throw()
  8500. {
  8501. jassert (numValues >= 0);
  8502. if (numValues > 0)
  8503. {
  8504. for (int i = getNumRanges(); --i >= 0;)
  8505. {
  8506. if (firstValue >= values.getUnchecked ((i << 1) + 1))
  8507. return false;
  8508. if (firstValue + numValues > values.getUnchecked (i << 1))
  8509. return true;
  8510. }
  8511. }
  8512. return false;
  8513. }
  8514. /** Checks whether the whole of a given range is contained within this one. */
  8515. bool containsRange (const Type firstValue,
  8516. const Type numValues) throw()
  8517. {
  8518. jassert (numValues >= 0);
  8519. if (numValues > 0)
  8520. {
  8521. for (int i = getNumRanges(); --i >= 0;)
  8522. {
  8523. if (firstValue >= values.getUnchecked ((i << 1) + 1))
  8524. return false;
  8525. if (firstValue >= values.getUnchecked (i << 1)
  8526. && firstValue + numValues <= values.getUnchecked ((i << 1) + 1))
  8527. return true;
  8528. }
  8529. }
  8530. return false;
  8531. }
  8532. bool operator== (const SparseSet<Type>& other) throw()
  8533. {
  8534. return values == other.values;
  8535. }
  8536. bool operator!= (const SparseSet<Type>& other) throw()
  8537. {
  8538. return values != other.values;
  8539. }
  8540. juce_UseDebuggingNewOperator
  8541. private:
  8542. // alternating start/end values of ranges of values that are present.
  8543. Array<Type> values;
  8544. void simplify() throw()
  8545. {
  8546. jassert ((values.size() & 1) == 0);
  8547. for (int i = values.size(); --i > 0;)
  8548. if (values.getUnchecked(i) == values.getUnchecked (i - 1))
  8549. values.removeRange (i - 1, 2);
  8550. }
  8551. };
  8552. #endif // __JUCE_SPARSESET_JUCEHEADER__
  8553. /********* End of inlined file: juce_SparseSet.h *********/
  8554. #endif
  8555. #ifndef __JUCE_VOIDARRAY_JUCEHEADER__
  8556. #endif
  8557. #ifndef __JUCE_INPUTSTREAM_JUCEHEADER__
  8558. #endif
  8559. #ifndef __JUCE_OUTPUTSTREAM_JUCEHEADER__
  8560. #endif
  8561. #ifndef __JUCE_DIRECTORYITERATOR_JUCEHEADER__
  8562. /********* Start of inlined file: juce_DirectoryIterator.h *********/
  8563. #ifndef __JUCE_DIRECTORYITERATOR_JUCEHEADER__
  8564. #define __JUCE_DIRECTORYITERATOR_JUCEHEADER__
  8565. /**
  8566. Searches through a the files in a directory, returning each file that is found.
  8567. A DirectoryIterator will search through a directory and its subdirectories using
  8568. a wildcard filepattern match.
  8569. If you may be finding a large number of files, this is better than
  8570. using File::findChildFiles() because it doesn't block while it finds them
  8571. all, and this is more memory-efficient.
  8572. It can also guess how far it's got using a wildly inaccurate algorithm.
  8573. */
  8574. class JUCE_API DirectoryIterator
  8575. {
  8576. public:
  8577. /** Creates a DirectoryIterator for a given directory.
  8578. After creating one of these, call its next() method to get the
  8579. first file - e.g. @code
  8580. DirectoryIterator iter (File ("/animals/mooses"), true, "*.moose");
  8581. while (iter.next())
  8582. {
  8583. File theFileItFound (iter.getFile());
  8584. ... etc
  8585. }
  8586. @endcode
  8587. @param directory the directory to search in
  8588. @param isRecursive whether all the subdirectories should also be searched
  8589. @param wildCard the file pattern to match
  8590. @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying
  8591. whether to look for files, directories, or both.
  8592. */
  8593. DirectoryIterator (const File& directory,
  8594. bool isRecursive,
  8595. const String& wildCard = JUCE_T("*"),
  8596. const int whatToLookFor = File::findFiles) throw();
  8597. /** Destructor. */
  8598. ~DirectoryIterator() throw();
  8599. /** Call this to move the iterator along to the next file.
  8600. @returns true if a file was found (you can then use getFile() to see what it was) - or
  8601. false if there are no more matching files.
  8602. */
  8603. bool next() throw();
  8604. /** Returns the file that the iterator is currently pointing at.
  8605. The result of this call is only valid after a call to next() has returned true.
  8606. */
  8607. const File getFile() const throw();
  8608. /** Returns a guess of how far through the search the iterator has got.
  8609. @returns a value 0.0 to 1.0 to show the progress, although this won't be
  8610. very accurate.
  8611. */
  8612. float getEstimatedProgress() const throw();
  8613. juce_UseDebuggingNewOperator
  8614. private:
  8615. OwnedArray <File> filesFound;
  8616. OwnedArray <File> dirsFound;
  8617. String wildCard;
  8618. int index;
  8619. const int whatToLookFor;
  8620. DirectoryIterator* subIterator;
  8621. DirectoryIterator (const DirectoryIterator&);
  8622. const DirectoryIterator& operator= (const DirectoryIterator&);
  8623. };
  8624. #endif // __JUCE_DIRECTORYITERATOR_JUCEHEADER__
  8625. /********* End of inlined file: juce_DirectoryIterator.h *********/
  8626. #endif
  8627. #ifndef __JUCE_FILE_JUCEHEADER__
  8628. #endif
  8629. #ifndef __JUCE_FILEINPUTSTREAM_JUCEHEADER__
  8630. /********* Start of inlined file: juce_FileInputStream.h *********/
  8631. #ifndef __JUCE_FILEINPUTSTREAM_JUCEHEADER__
  8632. #define __JUCE_FILEINPUTSTREAM_JUCEHEADER__
  8633. /**
  8634. An input stream that reads from a local file.
  8635. @see InputStream, FileOutputStream, File::createInputStream
  8636. */
  8637. class JUCE_API FileInputStream : public InputStream
  8638. {
  8639. public:
  8640. /** Creates a FileInputStream.
  8641. @param fileToRead the file to read from - if the file can't be accessed for some
  8642. reason, then the stream will just contain no data
  8643. */
  8644. FileInputStream (const File& fileToRead);
  8645. /** Destructor. */
  8646. ~FileInputStream();
  8647. const File& getFile() const throw() { return file; }
  8648. int64 getTotalLength();
  8649. int read (void* destBuffer, int maxBytesToRead);
  8650. bool isExhausted();
  8651. int64 getPosition();
  8652. bool setPosition (int64 pos);
  8653. juce_UseDebuggingNewOperator
  8654. private:
  8655. File file;
  8656. void* fileHandle;
  8657. int64 currentPosition, totalSize;
  8658. bool needToSeek;
  8659. };
  8660. #endif // __JUCE_FILEINPUTSTREAM_JUCEHEADER__
  8661. /********* End of inlined file: juce_FileInputStream.h *********/
  8662. #endif
  8663. #ifndef __JUCE_FILEOUTPUTSTREAM_JUCEHEADER__
  8664. /********* Start of inlined file: juce_FileOutputStream.h *********/
  8665. #ifndef __JUCE_FILEOUTPUTSTREAM_JUCEHEADER__
  8666. #define __JUCE_FILEOUTPUTSTREAM_JUCEHEADER__
  8667. /**
  8668. An output stream that writes into a local file.
  8669. @see OutputStream, FileInputStream, File::createOutputStream
  8670. */
  8671. class JUCE_API FileOutputStream : public OutputStream
  8672. {
  8673. public:
  8674. /** Creates a FileOutputStream.
  8675. If the file doesn't exist, it will first be created. If the file can't be
  8676. created or opened, the failedToOpen() method will return
  8677. true.
  8678. If the file already exists when opened, the stream's write-postion will
  8679. be set to the end of the file. To overwrite an existing file,
  8680. use File::deleteFile() before opening the stream, or use setPosition(0)
  8681. after it's opened (although this won't truncate the file).
  8682. It's better to use File::createOutputStream() to create one of these, rather
  8683. than using the class directly.
  8684. */
  8685. FileOutputStream (const File& fileToWriteTo,
  8686. const int bufferSizeToUse = 16384);
  8687. /** Destructor. */
  8688. ~FileOutputStream();
  8689. /** Returns the file that this stream is writing to.
  8690. */
  8691. const File& getFile() const throw() { return file; }
  8692. /** Returns true if the stream couldn't be opened for some reason.
  8693. */
  8694. bool failedToOpen() const throw() { return fileHandle == 0; }
  8695. void flush();
  8696. int64 getPosition();
  8697. bool setPosition (int64 pos);
  8698. bool write (const void* data, int numBytes);
  8699. juce_UseDebuggingNewOperator
  8700. private:
  8701. File file;
  8702. void* fileHandle;
  8703. int64 currentPosition;
  8704. int bufferSize, bytesInBuffer;
  8705. char* buffer;
  8706. };
  8707. #endif // __JUCE_FILEOUTPUTSTREAM_JUCEHEADER__
  8708. /********* End of inlined file: juce_FileOutputStream.h *********/
  8709. #endif
  8710. #ifndef __JUCE_FILESEARCHPATH_JUCEHEADER__
  8711. /********* Start of inlined file: juce_FileSearchPath.h *********/
  8712. #ifndef __JUCE_FILESEARCHPATH_JUCEHEADER__
  8713. #define __JUCE_FILESEARCHPATH_JUCEHEADER__
  8714. /**
  8715. Encapsulates a set of folders that make up a search path.
  8716. @see File
  8717. */
  8718. class JUCE_API FileSearchPath
  8719. {
  8720. public:
  8721. /** Creates an empty search path. */
  8722. FileSearchPath();
  8723. /** Creates a search path from a string of pathnames.
  8724. The path can be semicolon- or comma-separated, e.g.
  8725. "/foo/bar;/foo/moose;/fish/moose"
  8726. The separate folders are tokenised and added to the search path.
  8727. */
  8728. FileSearchPath (const String& path);
  8729. /** Creates a copy of another search path. */
  8730. FileSearchPath (const FileSearchPath& other);
  8731. /** Destructor. */
  8732. ~FileSearchPath();
  8733. /** Uses a string containing a list of pathnames to re-initialise this list.
  8734. This search path is cleared and the semicolon- or comma-separated folders
  8735. in this string are added instead. e.g. "/foo/bar;/foo/moose;/fish/moose"
  8736. */
  8737. const FileSearchPath& operator= (const String& path);
  8738. /** Returns the number of folders in this search path.
  8739. @see operator[]
  8740. */
  8741. int getNumPaths() const;
  8742. /** Returns one of the folders in this search path.
  8743. The file returned isn't guaranteed to actually be a valid directory.
  8744. @see getNumPaths
  8745. */
  8746. const File operator[] (const int index) const;
  8747. /** Returns the search path as a semicolon-separated list of directories. */
  8748. const String toString() const;
  8749. /** Adds a new directory to the search path.
  8750. The new directory is added to the end of the list if the insertIndex parameter is
  8751. less than zero, otherwise it is inserted at the given index.
  8752. */
  8753. void add (const File& directoryToAdd,
  8754. const int insertIndex = -1);
  8755. /** Adds a new directory to the search path if it's not already in there. */
  8756. void addIfNotAlreadyThere (const File& directoryToAdd);
  8757. /** Removes a directory from the search path. */
  8758. void remove (const int indexToRemove);
  8759. /** Merges another search path into this one.
  8760. This will remove any duplicate directories.
  8761. */
  8762. void addPath (const FileSearchPath& other);
  8763. /** Removes any directories that are actually subdirectories of one of the other directories in the search path.
  8764. If the search is intended to be recursive, there's no point having nested folders in the search
  8765. path, because they'll just get searched twice and you'll get duplicate results.
  8766. e.g. if the path is "c:\abc\de;c:\abc", this method will simplify it to "c:\abc"
  8767. */
  8768. void removeRedundantPaths();
  8769. /** Removes any directories that don't actually exist. */
  8770. void removeNonExistentPaths();
  8771. /** Searches the path for a wildcard.
  8772. This will search all the directories in the search path in order, adding any
  8773. matching files to the results array.
  8774. @param results an array to append the results to
  8775. @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying whether to
  8776. return files, directories, or both.
  8777. @param searchRecursively whether to recursively search the subdirectories too
  8778. @param wildCardPattern a pattern to match against the filenames
  8779. @returns the number of files added to the array
  8780. @see File::findChildFiles
  8781. */
  8782. int findChildFiles (OwnedArray<File>& results,
  8783. const int whatToLookFor,
  8784. const bool searchRecursively,
  8785. const String& wildCardPattern = JUCE_T("*")) const;
  8786. /** Finds out whether a file is inside one of the path's directories.
  8787. This will return true if the specified file is a child of one of the
  8788. directories specified by this path. Note that this doesn't actually do any
  8789. searching or check that the files exist - it just looks at the pathnames
  8790. to work out whether the file would be inside a directory.
  8791. @param fileToCheck the file to look for
  8792. @param checkRecursively if true, then this will return true if the file is inside a
  8793. subfolder of one of the path's directories (at any depth). If false
  8794. it will only return true if the file is actually a direct child
  8795. of one of the directories.
  8796. @see File::isAChildOf
  8797. */
  8798. bool isFileInPath (const File& fileToCheck,
  8799. const bool checkRecursively) const;
  8800. juce_UseDebuggingNewOperator
  8801. private:
  8802. StringArray directories;
  8803. void init (const String& path);
  8804. };
  8805. #endif // __JUCE_FILESEARCHPATH_JUCEHEADER__
  8806. /********* End of inlined file: juce_FileSearchPath.h *********/
  8807. #endif
  8808. #ifndef __JUCE_NAMEDPIPE_JUCEHEADER__
  8809. /********* Start of inlined file: juce_NamedPipe.h *********/
  8810. #ifndef __JUCE_NAMEDPIPE_JUCEHEADER__
  8811. #define __JUCE_NAMEDPIPE_JUCEHEADER__
  8812. /**
  8813. A cross-process pipe that can have data written to and read from it.
  8814. Two or more processes can use these for inter-process communication.
  8815. @see InterprocessConnection
  8816. */
  8817. class JUCE_API NamedPipe
  8818. {
  8819. public:
  8820. /** Creates a NamedPipe. */
  8821. NamedPipe();
  8822. /** Destructor. */
  8823. ~NamedPipe();
  8824. /** Tries to open a pipe that already exists.
  8825. Returns true if it succeeds.
  8826. */
  8827. bool openExisting (const String& pipeName);
  8828. /** Tries to create a new pipe.
  8829. Returns true if it succeeds.
  8830. */
  8831. bool createNewPipe (const String& pipeName);
  8832. /** Closes the pipe, if it's open. */
  8833. void close();
  8834. /** True if the pipe is currently open. */
  8835. bool isOpen() const throw();
  8836. /** Returns the last name that was used to try to open this pipe. */
  8837. const String getName() const throw();
  8838. /** Reads data from the pipe.
  8839. This will block until another thread has written enough data into the pipe to fill
  8840. the number of bytes specified, or until another thread calls the cancelPendingReads()
  8841. method.
  8842. If the operation fails, it returns -1, otherwise, it will return the number of
  8843. bytes read.
  8844. If timeOutMilliseconds is less than zero, it will wait indefinitely, otherwise
  8845. this is a maximum timeout for reading from the pipe.
  8846. */
  8847. int read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds = 5000);
  8848. /** Writes some data to the pipe.
  8849. If the operation fails, it returns -1, otherwise, it will return the number of
  8850. bytes written.
  8851. */
  8852. int write (const void* sourceBuffer, int numBytesToWrite,
  8853. int timeOutMilliseconds = 2000);
  8854. /** If any threads are currently blocked on a read operation, this tells them to abort.
  8855. */
  8856. void cancelPendingReads();
  8857. juce_UseDebuggingNewOperator
  8858. private:
  8859. void* internal;
  8860. String currentPipeName;
  8861. NamedPipe (const NamedPipe&);
  8862. const NamedPipe& operator= (const NamedPipe&);
  8863. bool openInternal (const String& pipeName, const bool createPipe);
  8864. };
  8865. #endif // __JUCE_NAMEDPIPE_JUCEHEADER__
  8866. /********* End of inlined file: juce_NamedPipe.h *********/
  8867. #endif
  8868. #ifndef __JUCE_BLOWFISH_JUCEHEADER__
  8869. /********* Start of inlined file: juce_BlowFish.h *********/
  8870. #ifndef __JUCE_BLOWFISH_JUCEHEADER__
  8871. #define __JUCE_BLOWFISH_JUCEHEADER__
  8872. /**
  8873. BlowFish encryption class.
  8874. */
  8875. class JUCE_API BlowFish
  8876. {
  8877. public:
  8878. /** Creates an object that can encode/decode based on the specified key.
  8879. The key data can be up to 72 bytes long.
  8880. */
  8881. BlowFish (const uint8* keyData, int keyBytes);
  8882. /** Creates a copy of another blowfish object. */
  8883. BlowFish (const BlowFish& other);
  8884. /** Copies another blowfish object. */
  8885. const BlowFish& operator= (const BlowFish& other);
  8886. /** Destructor. */
  8887. ~BlowFish();
  8888. /** Encrypts a pair of 32-bit integers. */
  8889. void encrypt (uint32& data1, uint32& data2) const;
  8890. /** Decrypts a pair of 32-bit integers. */
  8891. void decrypt (uint32& data1, uint32& data2) const;
  8892. juce_UseDebuggingNewOperator
  8893. private:
  8894. uint32 p[18];
  8895. uint32* s[4];
  8896. uint32 F (uint32 x) const;
  8897. };
  8898. #endif // __JUCE_BLOWFISH_JUCEHEADER__
  8899. /********* End of inlined file: juce_BlowFish.h *********/
  8900. #endif
  8901. #ifndef __JUCE_MD5_JUCEHEADER__
  8902. /********* Start of inlined file: juce_MD5.h *********/
  8903. #ifndef __JUCE_MD5_JUCEHEADER__
  8904. #define __JUCE_MD5_JUCEHEADER__
  8905. /**
  8906. MD5 checksum class.
  8907. Create one of these with a block of source data or a string, and it calculates the
  8908. MD5 checksum of that data.
  8909. You can then retrieve this checksum as a 16-byte block, or as a hex string.
  8910. */
  8911. class JUCE_API MD5
  8912. {
  8913. public:
  8914. /** Creates a null MD5 object. */
  8915. MD5();
  8916. /** Creates a copy of another MD5. */
  8917. MD5 (const MD5& other);
  8918. /** Copies another MD5. */
  8919. const MD5& operator= (const MD5& other);
  8920. /** Creates a checksum for a block of binary data. */
  8921. MD5 (const MemoryBlock& data);
  8922. /** Creates a checksum for a block of binary data. */
  8923. MD5 (const char* data, const int numBytes);
  8924. /** Creates a checksum for a string. */
  8925. MD5 (const String& text);
  8926. /** Creates a checksum for the input from a stream.
  8927. This will read up to the given number of bytes from the stream, and produce the
  8928. checksum of that. If the number of bytes to read is negative, it'll read
  8929. until the stream is exhausted.
  8930. */
  8931. MD5 (InputStream& input, int numBytesToRead = -1);
  8932. /** Creates a checksum for a file. */
  8933. MD5 (const File& file);
  8934. /** Destructor. */
  8935. ~MD5();
  8936. /** Returns the checksum as a 16-byte block of data. */
  8937. const MemoryBlock getRawChecksumData() const;
  8938. /** Returns the checksum as a 32-digit hex string. */
  8939. const String toHexString() const;
  8940. /** Compares this to another MD5. */
  8941. bool operator== (const MD5& other) const;
  8942. /** Compares this to another MD5. */
  8943. bool operator!= (const MD5& other) const;
  8944. juce_UseDebuggingNewOperator
  8945. private:
  8946. uint8 result [16];
  8947. struct ProcessContext
  8948. {
  8949. uint8 buffer [64];
  8950. uint32 state [4];
  8951. uint32 count [2];
  8952. ProcessContext();
  8953. void processBlock (const uint8* const data, int dataSize);
  8954. void transform (const uint8* const buffer);
  8955. void finish (uint8* const result);
  8956. };
  8957. void processStream (InputStream& input, int numBytesToRead);
  8958. };
  8959. #endif // __JUCE_MD5_JUCEHEADER__
  8960. /********* End of inlined file: juce_MD5.h *********/
  8961. #endif
  8962. #ifndef __JUCE_PRIMES_JUCEHEADER__
  8963. /********* Start of inlined file: juce_Primes.h *********/
  8964. #ifndef __JUCE_PRIMES_JUCEHEADER__
  8965. #define __JUCE_PRIMES_JUCEHEADER__
  8966. /**
  8967. Prime number creation class.
  8968. This class contains static methods for generating and testing prime numbers.
  8969. @see BitArray
  8970. */
  8971. class JUCE_API Primes
  8972. {
  8973. public:
  8974. /** Creates a random prime number with a given bit-length.
  8975. The certainty parameter specifies how many iterations to use when testing
  8976. for primality. A safe value might be anything over about 20-30.
  8977. */
  8978. static const BitArray createProbablePrime (int bitLength,
  8979. int certainty) throw();
  8980. /** Tests a number to see if it's prime.
  8981. This isn't a bulletproof test, it uses a Miller-Rabin test to determine
  8982. whether the number is prime.
  8983. The certainty parameter specifies how many iterations to use when testing - a
  8984. safe value might be anything over about 20-30.
  8985. */
  8986. static bool isProbablyPrime (const BitArray& number,
  8987. int certainty) throw();
  8988. };
  8989. #endif // __JUCE_PRIMES_JUCEHEADER__
  8990. /********* End of inlined file: juce_Primes.h *********/
  8991. #endif
  8992. #ifndef __JUCE_RSAKEY_JUCEHEADER__
  8993. /********* Start of inlined file: juce_RSAKey.h *********/
  8994. #ifndef __JUCE_RSAKEY_JUCEHEADER__
  8995. #define __JUCE_RSAKEY_JUCEHEADER__
  8996. /**
  8997. RSA public/private key-pair encryption class.
  8998. An object of this type makes up one half of a public/private RSA key pair. Use the
  8999. createKeyPair() method to create a matching pair for encoding/decoding.
  9000. */
  9001. class JUCE_API RSAKey
  9002. {
  9003. public:
  9004. /** Creates a null key object.
  9005. Initialise a pair of objects for use with the createKeyPair() method.
  9006. */
  9007. RSAKey() throw();
  9008. /** Loads a key from an encoded string representation.
  9009. This reloads a key from a string created by the toString() method.
  9010. */
  9011. RSAKey (const String& stringRepresentation) throw();
  9012. /** Destructor. */
  9013. ~RSAKey() throw();
  9014. /** Turns the key into a string representation.
  9015. This can be reloaded using the constructor that takes a string.
  9016. */
  9017. const String toString() const throw();
  9018. /** Encodes or decodes a value.
  9019. Call this on the public key object to encode some data, then use the matching
  9020. private key object to decode it.
  9021. Returns false if the operation failed, e.g. if this object isn't a valid key.
  9022. */
  9023. bool applyToValue (BitArray& value) const throw();
  9024. /** Creates a public/private key-pair.
  9025. Each key will perform one-way encryption that can only be reversed by
  9026. using the other key.
  9027. The numBits parameter specifies the size of key, e.g. 128, 256, 512 bit. Bigger
  9028. sizes are more secure, but this method will take longer to execute.
  9029. */
  9030. static void createKeyPair (RSAKey& publicKey,
  9031. RSAKey& privateKey,
  9032. const int numBits) throw();
  9033. juce_UseDebuggingNewOperator
  9034. protected:
  9035. BitArray part1, part2;
  9036. };
  9037. #endif // __JUCE_RSAKEY_JUCEHEADER__
  9038. /********* End of inlined file: juce_RSAKey.h *********/
  9039. #endif
  9040. #ifndef __JUCE_SOCKET_JUCEHEADER__
  9041. /********* Start of inlined file: juce_Socket.h *********/
  9042. #ifndef __JUCE_SOCKET_JUCEHEADER__
  9043. #define __JUCE_SOCKET_JUCEHEADER__
  9044. /**
  9045. A wrapper for a streaming (TCP) socket.
  9046. This allows low-level use of sockets; for an easier-to-use messaging layer on top of
  9047. sockets, you could also try the InterprocessConnection class.
  9048. @see DatagramSocket, InterprocessConnection, InterprocessConnectionServer
  9049. */
  9050. class JUCE_API StreamingSocket
  9051. {
  9052. public:
  9053. /** Creates an uninitialised socket.
  9054. To connect it, use the connect() method, after which you can read() or write()
  9055. to it.
  9056. To wait for other sockets to connect to this one, the createListener() method
  9057. enters "listener" mode, and can be used to spawn new sockets for each connection
  9058. that comes along.
  9059. */
  9060. StreamingSocket();
  9061. /** Destructor. */
  9062. ~StreamingSocket();
  9063. /** Binds the socket to the specified local port.
  9064. @returns true on success; false may indicate that another socket is already bound
  9065. on the same port
  9066. */
  9067. bool bindToPort (const int localPortNumber);
  9068. /** Tries to connect the socket to hostname:port.
  9069. If timeOutMillisecs is 0, then this method will block until the operating system
  9070. rejects the connection (which could take a long time).
  9071. @returns true if it succeeds.
  9072. @see isConnected
  9073. */
  9074. bool connect (const String& remoteHostname,
  9075. const int remotePortNumber,
  9076. const int timeOutMillisecs = 3000);
  9077. /** True if the socket is currently connected. */
  9078. bool isConnected() const throw() { return connected; }
  9079. /** Closes the connection. */
  9080. void close();
  9081. /** Returns the name of the currently connected host. */
  9082. const String& getHostName() const throw() { return hostName; }
  9083. /** Returns the port number that's currently open. */
  9084. int getPort() const throw() { return portNumber; }
  9085. /** True if the socket is connected to this machine rather than over the network. */
  9086. bool isLocal() const throw();
  9087. /** Waits until the socket is ready for reading or writing.
  9088. If readyForReading is true, it will wait until the socket is ready for
  9089. reading; if false, it will wait until it's ready for writing.
  9090. If the timeout is < 0, it will wait forever, or else will give up after
  9091. the specified time.
  9092. If the socket is ready on return, this returns 1. If it times-out before
  9093. the socket becomes ready, it returns 0. If an error occurs, it returns -1.
  9094. */
  9095. int waitUntilReady (const bool readyForReading,
  9096. const int timeoutMsecs) const;
  9097. /** Reads bytes from the socket (blocking).
  9098. Note that this method will block unless you have checked the socket is ready
  9099. for reading before calling it (see the waitUntilReady() method).
  9100. @returns the number of bytes read, or -1 if there was an error.
  9101. */
  9102. int read (void* destBuffer, const int maxBytesToRead);
  9103. /** Writes bytes to the socket from a buffer.
  9104. Note that this method will block unless you have checked the socket is ready
  9105. for writing before calling it (see the waitUntilReady() method).
  9106. @returns the number of bytes written, or -1 if there was an error.
  9107. */
  9108. int write (const void* sourceBuffer, const int numBytesToWrite);
  9109. /** Puts this socket into "listener" mode.
  9110. When in this mode, your thread can call waitForNextConnection() repeatedly,
  9111. which will spawn new sockets for each new connection, so that these can
  9112. be handled in parallel by other threads.
  9113. This returns true if it manages to open the socket successfully.
  9114. @see waitForNextConnection
  9115. */
  9116. bool createListener (const int portNumber);
  9117. /** When in "listener" mode, this waits for a connection and spawns it as a new
  9118. socket.
  9119. The object that gets returned will be owned by the caller.
  9120. This method can only be called after using createListener().
  9121. @see createListener
  9122. */
  9123. StreamingSocket* waitForNextConnection() const;
  9124. juce_UseDebuggingNewOperator
  9125. private:
  9126. String hostName;
  9127. int volatile portNumber, handle;
  9128. bool connected, isListener;
  9129. StreamingSocket (const String& hostname, const int portNumber, const int handle);
  9130. StreamingSocket (const StreamingSocket&);
  9131. const StreamingSocket& operator= (const StreamingSocket&);
  9132. };
  9133. /**
  9134. A wrapper for a datagram (UDP) socket.
  9135. This allows low-level use of sockets; for an easier-to-use messaging layer on top of
  9136. sockets, you could also try the InterprocessConnection class.
  9137. @see StreamingSocket, InterprocessConnection, InterprocessConnectionServer
  9138. */
  9139. class JUCE_API DatagramSocket
  9140. {
  9141. public:
  9142. /**
  9143. Creates an (uninitialised) datagram socket.
  9144. The localPortNumber is the port on which to bind this socket. If this value is 0,
  9145. the port number is assigned by the operating system.
  9146. To use the socket for sending, call the connect() method. This will not immediately
  9147. make a connection, but will save the destination you've provided. After this, you can
  9148. call read() or write().
  9149. To wait for other sockets to connect to this one, call waitForNextConnection().
  9150. */
  9151. DatagramSocket (const int localPortNumber);
  9152. /** Destructor. */
  9153. ~DatagramSocket();
  9154. /** Binds the socket to the specified local port.
  9155. @returns true on success; false may indicate that another socket is already bound
  9156. on the same port
  9157. */
  9158. bool bindToPort (const int localPortNumber);
  9159. /** Tries to connect the socket to hostname:port.
  9160. If timeOutMillisecs is 0, then this method will block until the operating system
  9161. rejects the connection (which could take a long time).
  9162. @returns true if it succeeds.
  9163. @see isConnected
  9164. */
  9165. bool connect (const String& remoteHostname,
  9166. const int remotePortNumber,
  9167. const int timeOutMillisecs = 3000);
  9168. /** True if the socket is currently connected. */
  9169. bool isConnected() const throw() { return connected; }
  9170. /** Closes the connection. */
  9171. void close();
  9172. /** Returns the name of the currently connected host. */
  9173. const String& getHostName() const throw() { return hostName; }
  9174. /** Returns the port number that's currently open. */
  9175. int getPort() const throw() { return portNumber; }
  9176. /** True if the socket is connected to this machine rather than over the network. */
  9177. bool isLocal() const throw();
  9178. /** Waits until the socket is ready for reading or writing.
  9179. If readyForReading is true, it will wait until the socket is ready for
  9180. reading; if false, it will wait until it's ready for writing.
  9181. If the timeout is < 0, it will wait forever, or else will give up after
  9182. the specified time.
  9183. If the socket is ready on return, this returns 1. If it times-out before
  9184. the socket becomes ready, it returns 0. If an error occurs, it returns -1.
  9185. */
  9186. int waitUntilReady (const bool readyForReading,
  9187. const int timeoutMsecs) const;
  9188. /** Reads bytes from the socket (blocking).
  9189. Note that this method will block unless you have checked the socket is ready
  9190. for reading before calling it (see the waitUntilReady() method).
  9191. @returns the number of bytes read, or -1 if there was an error.
  9192. */
  9193. int read (void* destBuffer, const int maxBytesToRead);
  9194. /** Writes bytes to the socket from a buffer.
  9195. Note that this method will block unless you have checked the socket is ready
  9196. for writing before calling it (see the waitUntilReady() method).
  9197. @returns the number of bytes written, or -1 if there was an error.
  9198. */
  9199. int write (const void* sourceBuffer, const int numBytesToWrite);
  9200. /** This waits for incoming data to be sent, and returns a socket that can be used
  9201. to read it.
  9202. The object that gets returned is owned by the caller, and can't be used for
  9203. sending, but can be used to read the data.
  9204. */
  9205. DatagramSocket* waitForNextConnection() const;
  9206. juce_UseDebuggingNewOperator
  9207. private:
  9208. String hostName;
  9209. int volatile portNumber, handle;
  9210. bool connected;
  9211. void* serverAddress;
  9212. DatagramSocket (const String& hostname, const int portNumber, const int handle, const int localPortNumber);
  9213. DatagramSocket (const DatagramSocket&);
  9214. const DatagramSocket& operator= (const DatagramSocket&);
  9215. };
  9216. #endif // __JUCE_SOCKET_JUCEHEADER__
  9217. /********* End of inlined file: juce_Socket.h *********/
  9218. #endif
  9219. #ifndef __JUCE_URL_JUCEHEADER__
  9220. /********* Start of inlined file: juce_URL.h *********/
  9221. #ifndef __JUCE_URL_JUCEHEADER__
  9222. #define __JUCE_URL_JUCEHEADER__
  9223. /**
  9224. Represents a URL and has a bunch of useful functions to manipulate it.
  9225. This class can be used to launch URLs in browsers, and also to create
  9226. InputStreams that can read from remote http or ftp sources.
  9227. */
  9228. class JUCE_API URL
  9229. {
  9230. public:
  9231. /** Creates an empty URL. */
  9232. URL() throw();
  9233. /** Creates a URL from a string. */
  9234. URL (const String& url);
  9235. /** Creates a copy of another URL. */
  9236. URL (const URL& other);
  9237. /** Destructor. */
  9238. ~URL() throw();
  9239. /** Copies this URL from another one. */
  9240. const URL& operator= (const URL& other);
  9241. /** Returns a string version of the URL.
  9242. If includeGetParameters is true and any parameters have been set with the
  9243. withParameter() method, then the string will have these appended on the
  9244. end and url-encoded.
  9245. */
  9246. const String toString (const bool includeGetParameters) const;
  9247. /** True if it seems to be valid. */
  9248. bool isWellFormed() const;
  9249. /** Returns a copy of this URL, with a GET parameter added to the end.
  9250. Any control characters in the value will be encoded.
  9251. e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com"
  9252. would produce a new url whose toString(true) method would return
  9253. "www.fish.com?amount=some+fish".
  9254. */
  9255. const URL withParameter (const String& parameterName,
  9256. const String& parameterValue) const;
  9257. /** Returns a copy of this URl, with a file-upload type parameter added to it.
  9258. When performing a POST where one of your parameters is a binary file, this
  9259. lets you specify the file.
  9260. Note that the filename is stored, but the file itself won't actually be read
  9261. until this URL is later used to create a network input stream.
  9262. */
  9263. const URL withFileToUpload (const String& parameterName,
  9264. const File& fileToUpload,
  9265. const String& mimeType) const;
  9266. /** Returns a set of all the parameters encoded into the url.
  9267. E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would
  9268. contain two pairs: "type" => "haddock" and "amount" => "some fish".
  9269. The values returned will have been cleaned up to remove any escape characters.
  9270. @see getNamedParameter, withParameter
  9271. */
  9272. const StringPairArray& getParameters() const throw();
  9273. /** Returns the set of files that should be uploaded as part of a POST operation.
  9274. This is the set of files that were added to the URL with the withFileToUpload()
  9275. method.
  9276. */
  9277. const StringPairArray& getFilesToUpload() const throw();
  9278. /** Returns the set of mime types associated with each of the upload files.
  9279. */
  9280. const StringPairArray& getMimeTypesOfUploadFiles() const throw();
  9281. /** Tries to launch the system's default browser to open the URL.
  9282. Returns true if this seems to have worked.
  9283. */
  9284. bool launchInDefaultBrowser() const;
  9285. /** Takes a guess as to whether a string might be a valid website address.
  9286. This isn't foolproof!
  9287. */
  9288. static bool isProbablyAWebsiteURL (const String& possibleURL);
  9289. /** Takes a guess as to whether a string might be a valid email address.
  9290. This isn't foolproof!
  9291. */
  9292. static bool isProbablyAnEmailAddress (const String& possibleEmailAddress);
  9293. /** This callback function can be used by the createInputStream() method.
  9294. It allows your app to receive progress updates during a lengthy POST operation. If you
  9295. want to continue the operation, this should return true, or false to abort.
  9296. */
  9297. typedef bool (OpenStreamProgressCallback) (void* context, int bytesSent, int totalBytes);
  9298. /** Attempts to open a stream that can read from this URL.
  9299. @param usePostCommand if true, it will try to do use a http 'POST' to pass
  9300. the paramters, otherwise it'll encode them into the
  9301. URL and do a 'GET'.
  9302. @param progressCallback if this is non-zero, it lets you supply a callback function
  9303. to keep track of the operation's progress. This can be useful
  9304. for lengthy POST operations, so that you can provide user feedback.
  9305. @param progressCallbackContext if a callback is specified, this value will be passed to
  9306. the function
  9307. @param extraHeaders if not empty, this string is appended onto the headers that
  9308. are used for the request. It must therefore be a valid set of HTML
  9309. header directives, separated by newlines.
  9310. @param connectionTimeOutMs if 0, this will use whatever default setting the OS chooses. If
  9311. a negative number, it will be infinite. Otherwise it specifies a
  9312. time in milliseconds.
  9313. */
  9314. InputStream* createInputStream (const bool usePostCommand,
  9315. OpenStreamProgressCallback* const progressCallback = 0,
  9316. void* const progressCallbackContext = 0,
  9317. const String& extraHeaders = String::empty,
  9318. const int connectionTimeOutMs = 0) const;
  9319. /** Tries to download the entire contents of this URL into a binary data block.
  9320. If it succeeds, this will return true and append the data it read onto the end
  9321. of the memory block.
  9322. @param destData the memory block to append the new data to
  9323. @param usePostCommand whether to use a POST command to get the data (uses
  9324. a GET command if this is false)
  9325. @see readEntireTextStream, readEntireXmlStream
  9326. */
  9327. bool readEntireBinaryStream (MemoryBlock& destData,
  9328. const bool usePostCommand = false) const;
  9329. /** Tries to download the entire contents of this URL as a string.
  9330. If it fails, this will return an empty string, otherwise it will return the
  9331. contents of the downloaded file. If you need to distinguish between a read
  9332. operation that fails and one that returns an empty string, you'll need to use
  9333. a different method, such as readEntireBinaryStream().
  9334. @param usePostCommand whether to use a POST command to get the data (uses
  9335. a GET command if this is false)
  9336. @see readEntireBinaryStream, readEntireXmlStream
  9337. */
  9338. const String readEntireTextStream (const bool usePostCommand = false) const;
  9339. /** Tries to download the entire contents of this URL and parse it as XML.
  9340. If it fails, or if the text that it reads can't be parsed as XML, this will
  9341. return 0.
  9342. When it returns a valid XmlElement object, the caller is responsibile for deleting
  9343. this object when no longer needed.
  9344. @param usePostCommand whether to use a POST command to get the data (uses
  9345. a GET command if this is false)
  9346. @see readEntireBinaryStream, readEntireTextStream
  9347. */
  9348. XmlElement* readEntireXmlStream (const bool usePostCommand = false) const;
  9349. /** Adds escape sequences to a string to encode any characters that aren't
  9350. legal in a URL.
  9351. E.g. any spaces will be replaced with "%20".
  9352. This is the opposite of removeEscapeChars().
  9353. @see removeEscapeChars
  9354. */
  9355. static const String addEscapeChars (const String& stringToAddEscapeCharsTo);
  9356. /** Replaces any escape character sequences in a string with their original
  9357. character codes.
  9358. E.g. any instances of "%20" will be replaced by a space.
  9359. This is the opposite of addEscapeChars().
  9360. @see addEscapeChars
  9361. */
  9362. static const String removeEscapeChars (const String& stringToRemoveEscapeCharsFrom);
  9363. juce_UseDebuggingNewOperator
  9364. private:
  9365. String url;
  9366. StringPairArray parameters, filesToUpload, mimeTypes;
  9367. };
  9368. #endif // __JUCE_URL_JUCEHEADER__
  9369. /********* End of inlined file: juce_URL.h *********/
  9370. #endif
  9371. #ifndef __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__
  9372. /********* Start of inlined file: juce_BufferedInputStream.h *********/
  9373. #ifndef __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__
  9374. #define __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__
  9375. /** Wraps another input stream, and reads from it using an intermediate buffer
  9376. If you're using an input stream such as a file input stream, and making lots of
  9377. small read accesses to it, it's probably sensible to wrap it in one of these,
  9378. so that the source stream gets accessed in larger chunk sizes, meaning less
  9379. work for the underlying stream.
  9380. */
  9381. class JUCE_API BufferedInputStream : public InputStream
  9382. {
  9383. public:
  9384. /** Creates a BufferedInputStream from an input source.
  9385. @param sourceStream the source stream to read from
  9386. @param bufferSize the size of reservoir to use to buffer the source
  9387. @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
  9388. deleted by this object when it is itself deleted.
  9389. */
  9390. BufferedInputStream (InputStream* const sourceStream,
  9391. const int bufferSize,
  9392. const bool deleteSourceWhenDestroyed) throw();
  9393. /** Destructor.
  9394. This may also delete the source stream, if that option was chosen when the
  9395. buffered stream was created.
  9396. */
  9397. ~BufferedInputStream() throw();
  9398. int64 getTotalLength();
  9399. int64 getPosition();
  9400. bool setPosition (int64 newPosition);
  9401. int read (void* destBuffer, int maxBytesToRead);
  9402. const String readString();
  9403. bool isExhausted();
  9404. juce_UseDebuggingNewOperator
  9405. private:
  9406. InputStream* const source;
  9407. const bool deleteSourceWhenDestroyed;
  9408. int bufferSize;
  9409. int64 position, lastReadPos, bufferStart, bufferOverlap;
  9410. char* buffer;
  9411. void ensureBuffered();
  9412. BufferedInputStream (const BufferedInputStream&);
  9413. const BufferedInputStream& operator= (const BufferedInputStream&);
  9414. };
  9415. #endif // __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__
  9416. /********* End of inlined file: juce_BufferedInputStream.h *********/
  9417. #endif
  9418. #ifndef __JUCE_FILEINPUTSOURCE_JUCEHEADER__
  9419. /********* Start of inlined file: juce_FileInputSource.h *********/
  9420. #ifndef __JUCE_FILEINPUTSOURCE_JUCEHEADER__
  9421. #define __JUCE_FILEINPUTSOURCE_JUCEHEADER__
  9422. /********* Start of inlined file: juce_InputSource.h *********/
  9423. #ifndef __JUCE_INPUTSOURCE_JUCEHEADER__
  9424. #define __JUCE_INPUTSOURCE_JUCEHEADER__
  9425. /**
  9426. A lightweight object that can create a stream to read some kind of resource.
  9427. This may be used to refer to a file, or some other kind of source, allowing a
  9428. caller to create an input stream that can read from it when required.
  9429. @see FileInputSource
  9430. */
  9431. class JUCE_API InputSource
  9432. {
  9433. public:
  9434. InputSource() throw() {}
  9435. /** Destructor. */
  9436. virtual ~InputSource() {}
  9437. /** Returns a new InputStream to read this item.
  9438. @returns an inputstream that the caller will delete, or 0 if
  9439. the filename isn't found.
  9440. */
  9441. virtual InputStream* createInputStream() = 0;
  9442. /** Returns a new InputStream to read an item, relative.
  9443. @param relatedItemPath the relative pathname of the resource that is required
  9444. @returns an inputstream that the caller will delete, or 0 if
  9445. the item isn't found.
  9446. */
  9447. virtual InputStream* createInputStreamFor (const String& relatedItemPath) = 0;
  9448. /** Returns a hash code that uniquely represents this item.
  9449. */
  9450. virtual int64 hashCode() const = 0;
  9451. juce_UseDebuggingNewOperator
  9452. };
  9453. #endif // __JUCE_INPUTSOURCE_JUCEHEADER__
  9454. /********* End of inlined file: juce_InputSource.h *********/
  9455. /**
  9456. A type of InputSource that represents a normal file.
  9457. @see InputSource
  9458. */
  9459. class JUCE_API FileInputSource : public InputSource
  9460. {
  9461. public:
  9462. FileInputSource (const File& file) throw();
  9463. ~FileInputSource();
  9464. InputStream* createInputStream();
  9465. InputStream* createInputStreamFor (const String& relatedItemPath);
  9466. int64 hashCode() const;
  9467. juce_UseDebuggingNewOperator
  9468. private:
  9469. const File file;
  9470. FileInputSource (const FileInputSource&);
  9471. const FileInputSource& operator= (const FileInputSource&);
  9472. };
  9473. #endif // __JUCE_FILEINPUTSOURCE_JUCEHEADER__
  9474. /********* End of inlined file: juce_FileInputSource.h *********/
  9475. #endif
  9476. #ifndef __JUCE_GZIPCOMPRESSOROUTPUTSTREAM_JUCEHEADER__
  9477. /********* Start of inlined file: juce_GZIPCompressorOutputStream.h *********/
  9478. #ifndef __JUCE_GZIPCOMPRESSOROUTPUTSTREAM_JUCEHEADER__
  9479. #define __JUCE_GZIPCOMPRESSOROUTPUTSTREAM_JUCEHEADER__
  9480. /**
  9481. A stream which uses zlib to compress the data written into it.
  9482. @see GZIPDecompressorInputStream
  9483. */
  9484. class JUCE_API GZIPCompressorOutputStream : public OutputStream
  9485. {
  9486. public:
  9487. /** Creates a compression stream.
  9488. @param destStream the stream into which the compressed data should
  9489. be written
  9490. @param compressionLevel how much to compress the data, between 1 and 9, where
  9491. 1 is the fastest/lowest compression, and 9 is the
  9492. slowest/highest compression. Any value outside this range
  9493. indicates that a default compression level should be used.
  9494. @param deleteDestStreamWhenDestroyed whether or not to delete the destStream object when
  9495. this stream is destroyed
  9496. @param noWrap this is used internally by the ZipFile class
  9497. and should be ignored by user applications
  9498. */
  9499. GZIPCompressorOutputStream (OutputStream* const destStream,
  9500. int compressionLevel = 0,
  9501. const bool deleteDestStreamWhenDestroyed = false,
  9502. const bool noWrap = false);
  9503. /** Destructor. */
  9504. ~GZIPCompressorOutputStream();
  9505. void flush();
  9506. int64 getPosition();
  9507. bool setPosition (int64 newPosition);
  9508. bool write (const void* destBuffer, int howMany);
  9509. juce_UseDebuggingNewOperator
  9510. private:
  9511. OutputStream* const destStream;
  9512. const bool deleteDestStream;
  9513. uint8* buffer;
  9514. void* helper;
  9515. bool doNextBlock();
  9516. GZIPCompressorOutputStream (const GZIPCompressorOutputStream&);
  9517. const GZIPCompressorOutputStream& operator= (const GZIPCompressorOutputStream&);
  9518. };
  9519. #endif // __JUCE_GZIPCOMPRESSOROUTPUTSTREAM_JUCEHEADER__
  9520. /********* End of inlined file: juce_GZIPCompressorOutputStream.h *********/
  9521. #endif
  9522. #ifndef __JUCE_GZIPDECOMPRESSORINPUTSTREAM_JUCEHEADER__
  9523. /********* Start of inlined file: juce_GZIPDecompressorInputStream.h *********/
  9524. #ifndef __JUCE_GZIPDECOMPRESSORINPUTSTREAM_JUCEHEADER__
  9525. #define __JUCE_GZIPDECOMPRESSORINPUTSTREAM_JUCEHEADER__
  9526. /**
  9527. This stream will decompress a source-stream using zlib.
  9528. Tip: if you're reading lots of small items from one of these streams, you
  9529. can increase the performance enormously by passing it through a
  9530. BufferedInputStream, so that it has to read larger blocks less often.
  9531. @see GZIPCompressorOutputStream
  9532. */
  9533. class JUCE_API GZIPDecompressorInputStream : public InputStream
  9534. {
  9535. public:
  9536. /** Creates a decompressor stream.
  9537. @param sourceStream the stream to read from
  9538. @param deleteSourceWhenDestroyed whether or not to delete the source stream
  9539. when this object is destroyed
  9540. @param noWrap this is used internally by the ZipFile class
  9541. and should be ignored by user applications
  9542. @param uncompressedStreamLength if the creator knows the length that the
  9543. uncompressed stream will be, then it can supply this
  9544. value, which will be returned by getTotalLength()
  9545. */
  9546. GZIPDecompressorInputStream (InputStream* const sourceStream,
  9547. const bool deleteSourceWhenDestroyed,
  9548. const bool noWrap = false,
  9549. const int64 uncompressedStreamLength = -1);
  9550. /** Destructor. */
  9551. ~GZIPDecompressorInputStream();
  9552. int64 getPosition();
  9553. bool setPosition (int64 pos);
  9554. int64 getTotalLength();
  9555. bool isExhausted();
  9556. int read (void* destBuffer, int maxBytesToRead);
  9557. juce_UseDebuggingNewOperator
  9558. private:
  9559. InputStream* const sourceStream;
  9560. const int64 uncompressedStreamLength;
  9561. const bool deleteSourceWhenDestroyed, noWrap;
  9562. bool isEof;
  9563. int activeBufferSize;
  9564. int64 originalSourcePos, currentPos;
  9565. uint8* buffer;
  9566. void* helper;
  9567. GZIPDecompressorInputStream (const GZIPDecompressorInputStream&);
  9568. const GZIPDecompressorInputStream& operator= (const GZIPDecompressorInputStream&);
  9569. };
  9570. #endif // __JUCE_GZIPDECOMPRESSORINPUTSTREAM_JUCEHEADER__
  9571. /********* End of inlined file: juce_GZIPDecompressorInputStream.h *********/
  9572. #endif
  9573. #ifndef __JUCE_INPUTSOURCE_JUCEHEADER__
  9574. #endif
  9575. #ifndef __JUCE_MEMORYINPUTSTREAM_JUCEHEADER__
  9576. /********* Start of inlined file: juce_MemoryInputStream.h *********/
  9577. #ifndef __JUCE_MEMORYINPUTSTREAM_JUCEHEADER__
  9578. #define __JUCE_MEMORYINPUTSTREAM_JUCEHEADER__
  9579. /**
  9580. Allows a block of data and to be accessed as a stream.
  9581. This can either be used to refer to a shared block of memory, or can make its
  9582. own internal copy of the data when the MemoryInputStream is created.
  9583. */
  9584. class JUCE_API MemoryInputStream : public InputStream
  9585. {
  9586. public:
  9587. /** Creates a MemoryInputStream.
  9588. @param sourceData the block of data to use as the stream's source
  9589. @param sourceDataSize the number of bytes in the source data block
  9590. @param keepInternalCopyOfData if false, the stream will just keep a pointer to
  9591. the source data, so this data shouldn't be changed
  9592. for the lifetime of the stream; if this parameter is
  9593. true, the stream will make its own copy of the
  9594. data and use that.
  9595. */
  9596. MemoryInputStream (const void* const sourceData,
  9597. const int sourceDataSize,
  9598. const bool keepInternalCopyOfData) throw();
  9599. /** Destructor. */
  9600. ~MemoryInputStream() throw();
  9601. int64 getPosition();
  9602. bool setPosition (int64 pos);
  9603. int64 getTotalLength();
  9604. bool isExhausted();
  9605. int read (void* destBuffer, int maxBytesToRead);
  9606. juce_UseDebuggingNewOperator
  9607. private:
  9608. const char* data;
  9609. int dataSize, position;
  9610. MemoryBlock internalCopy;
  9611. };
  9612. #endif // __JUCE_MEMORYINPUTSTREAM_JUCEHEADER__
  9613. /********* End of inlined file: juce_MemoryInputStream.h *********/
  9614. #endif
  9615. #ifndef __JUCE_MEMORYOUTPUTSTREAM_JUCEHEADER__
  9616. /********* Start of inlined file: juce_MemoryOutputStream.h *********/
  9617. #ifndef __JUCE_MEMORYOUTPUTSTREAM_JUCEHEADER__
  9618. #define __JUCE_MEMORYOUTPUTSTREAM_JUCEHEADER__
  9619. /** Writes data to an internal memory buffer, which grows as required.
  9620. The data that was written into the stream can then be accessed later as
  9621. a contiguous block of memory.
  9622. */
  9623. class JUCE_API MemoryOutputStream : public OutputStream
  9624. {
  9625. public:
  9626. /** Creates a memory stream ready for writing into.
  9627. @param initialSize the intial amount of space to allocate for writing into
  9628. @param granularity the increments by which the internal storage will be increased
  9629. @param memoryBlockToWriteTo if this is non-zero, then this block will be used as the
  9630. place that the data gets stored. If it's zero, the stream
  9631. will allocate its own storage internally, which you can
  9632. access using getData() and getDataSize()
  9633. */
  9634. MemoryOutputStream (const int initialSize = 256,
  9635. const int granularity = 256,
  9636. MemoryBlock* const memoryBlockToWriteTo = 0) throw();
  9637. /** Destructor.
  9638. This will free any data that was written to it.
  9639. */
  9640. ~MemoryOutputStream() throw();
  9641. /** Returns a pointer to the data that has been written to the stream.
  9642. @see getDataSize
  9643. */
  9644. const char* getData() throw();
  9645. /** Returns the number of bytes of data that have been written to the stream.
  9646. @see getData
  9647. */
  9648. int getDataSize() const throw();
  9649. /** Resets the stream, clearing any data that has been written to it so far. */
  9650. void reset() throw();
  9651. void flush();
  9652. bool write (const void* buffer, int howMany);
  9653. int64 getPosition();
  9654. bool setPosition (int64 newPosition);
  9655. juce_UseDebuggingNewOperator
  9656. private:
  9657. MemoryBlock* data;
  9658. int position, size, blockSize;
  9659. bool ownsMemoryBlock;
  9660. };
  9661. #endif // __JUCE_MEMORYOUTPUTSTREAM_JUCEHEADER__
  9662. /********* End of inlined file: juce_MemoryOutputStream.h *********/
  9663. #endif
  9664. #ifndef __JUCE_SUBREGIONSTREAM_JUCEHEADER__
  9665. /********* Start of inlined file: juce_SubregionStream.h *********/
  9666. #ifndef __JUCE_SUBREGIONSTREAM_JUCEHEADER__
  9667. #define __JUCE_SUBREGIONSTREAM_JUCEHEADER__
  9668. /** Wraps another input stream, and reads from a specific part of it.
  9669. This lets you take a subsection of a stream and present it as an entire
  9670. stream in its own right.
  9671. */
  9672. class JUCE_API SubregionStream : public InputStream
  9673. {
  9674. public:
  9675. /** Creates a SubregionStream from an input source.
  9676. @param sourceStream the source stream to read from
  9677. @param startPositionInSourceStream this is the position in the source stream that
  9678. corresponds to position 0 in this stream
  9679. @param lengthOfSourceStream this specifies the maximum number of bytes
  9680. from the source stream that will be passed through
  9681. by this stream. When the position of this stream
  9682. exceeds lengthOfSourceStream, it will cause an end-of-stream.
  9683. If the length passed in here is greater than the length
  9684. of the source stream (as returned by getTotalLength()),
  9685. then the smaller value will be used.
  9686. Passing a negative value for this parameter means it
  9687. will keep reading until the source's end-of-stream.
  9688. @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
  9689. deleted by this object when it is itself deleted.
  9690. */
  9691. SubregionStream (InputStream* const sourceStream,
  9692. const int64 startPositionInSourceStream,
  9693. const int64 lengthOfSourceStream,
  9694. const bool deleteSourceWhenDestroyed) throw();
  9695. /** Destructor.
  9696. This may also delete the source stream, if that option was chosen when the
  9697. buffered stream was created.
  9698. */
  9699. ~SubregionStream() throw();
  9700. int64 getTotalLength();
  9701. int64 getPosition();
  9702. bool setPosition (int64 newPosition);
  9703. int read (void* destBuffer, int maxBytesToRead);
  9704. bool isExhausted();
  9705. juce_UseDebuggingNewOperator
  9706. private:
  9707. InputStream* const source;
  9708. const bool deleteSourceWhenDestroyed;
  9709. const int64 startPositionInSourceStream, lengthOfSourceStream;
  9710. SubregionStream (const SubregionStream&);
  9711. const SubregionStream& operator= (const SubregionStream&);
  9712. };
  9713. #endif // __JUCE_SUBREGIONSTREAM_JUCEHEADER__
  9714. /********* End of inlined file: juce_SubregionStream.h *********/
  9715. #endif
  9716. #ifndef __JUCE_PERFORMANCECOUNTER_JUCEHEADER__
  9717. /********* Start of inlined file: juce_PerformanceCounter.h *********/
  9718. #ifndef __JUCE_PERFORMANCECOUNTER_JUCEHEADER__
  9719. #define __JUCE_PERFORMANCECOUNTER_JUCEHEADER__
  9720. /** A timer for measuring performance of code and dumping the results to a file.
  9721. e.g. @code
  9722. PerformanceCounter pc ("fish", 50, "/temp/myfishlog.txt");
  9723. for (;;)
  9724. {
  9725. pc.start();
  9726. doSomethingFishy();
  9727. pc.stop();
  9728. }
  9729. @endcode
  9730. In this example, the time of each period between calling start/stop will be
  9731. measured and averaged over 50 runs, and the results printed to a file
  9732. every 50 times round the loop.
  9733. */
  9734. class JUCE_API PerformanceCounter
  9735. {
  9736. public:
  9737. /** Creates a PerformanceCounter object.
  9738. @param counterName the name used when printing out the statistics
  9739. @param runsPerPrintout the number of start/stop iterations before calling
  9740. printStatistics()
  9741. @param loggingFile a file to dump the results to - if this is File::nonexistent,
  9742. the results are just written to the debugger output
  9743. */
  9744. PerformanceCounter (const String& counterName,
  9745. int runsPerPrintout = 100,
  9746. const File& loggingFile = File::nonexistent);
  9747. /** Destructor. */
  9748. ~PerformanceCounter();
  9749. /** Starts timing.
  9750. @see stop
  9751. */
  9752. void start();
  9753. /** Stops timing and prints out the results.
  9754. The number of iterations before doing a printout of the
  9755. results is set in the constructor.
  9756. @see start
  9757. */
  9758. void stop();
  9759. /** Dumps the current metrics to the debugger output and to a file.
  9760. As well as using Logger::outputDebugString to print the results,
  9761. this will write then to the file specified in the constructor (if
  9762. this was valid).
  9763. */
  9764. void printStatistics();
  9765. juce_UseDebuggingNewOperator
  9766. private:
  9767. String name;
  9768. int numRuns, runsPerPrint;
  9769. double totalTime;
  9770. int64 started;
  9771. File outputFile;
  9772. };
  9773. #endif // __JUCE_PERFORMANCECOUNTER_JUCEHEADER__
  9774. /********* End of inlined file: juce_PerformanceCounter.h *********/
  9775. #endif
  9776. #ifndef __JUCE_PLATFORMUTILITIES_JUCEHEADER__
  9777. /********* Start of inlined file: juce_PlatformUtilities.h *********/
  9778. #ifndef __JUCE_PLATFORMUTILITIES_JUCEHEADER__
  9779. #define __JUCE_PLATFORMUTILITIES_JUCEHEADER__
  9780. /**
  9781. A collection of miscellaneous platform-specific utilities.
  9782. */
  9783. class JUCE_API PlatformUtilities
  9784. {
  9785. public:
  9786. /** Plays the operating system's default alert 'beep' sound. */
  9787. static void beep();
  9788. static bool launchEmailWithAttachments (const String& targetEmailAddress,
  9789. const String& emailSubject,
  9790. const String& bodyText,
  9791. const StringArray& filesToAttach);
  9792. #if JUCE_MAC || DOXYGEN
  9793. /** MAC ONLY - Turns a String into a pascal string. */
  9794. static void copyToStr255 (Str255& d, const String& s);
  9795. /** MAC ONLY - Turns a String into a pascal string. */
  9796. static void copyToStr63 (Str63& d, const String& s);
  9797. /** MAC ONLY - Turns a Core CF String into a juce one. */
  9798. static const String cfStringToJuceString (CFStringRef cfString);
  9799. /** MAC ONLY - Turns a juce string into a Core CF one. */
  9800. static CFStringRef juceStringToCFString (const String& s);
  9801. /** MAC ONLY - Converts a UTF16 string to a Juce String. */
  9802. static const String convertUTF16ToString (const UniChar* utf16);
  9803. /** MAC ONLY - Turns a file path into an FSSpec, returning true if it succeeds. */
  9804. static bool makeFSSpecFromPath (FSSpec* destFSSpec, const String& path);
  9805. /** MAC ONLY - Turns a file path into an FSRef, returning true if it succeeds. */
  9806. static bool makeFSRefFromPath (FSRef* destFSRef, const String& path);
  9807. /** MAC ONLY - Turns an FSRef into a juce string path. */
  9808. static const String makePathFromFSRef (FSRef* file);
  9809. /** MAC ONLY - Converts any decomposed unicode characters in a string into
  9810. their precomposed equivalents.
  9811. */
  9812. static const String convertToPrecomposedUnicode (const String& s);
  9813. /** MAC ONLY - Gets the type of a file from the file's resources. */
  9814. static OSType getTypeOfFile (const String& filename);
  9815. /** MAC ONLY - Returns true if this file is actually a bundle. */
  9816. static bool isBundle (const String& filename);
  9817. #endif
  9818. #if JUCE_WIN32 || DOXYGEN
  9819. // Some registry helper functions:
  9820. /** WIN32 ONLY - Returns a string from the registry.
  9821. The path is a string for the entire path of a value in the registry,
  9822. e.g. "HKEY_CURRENT_USER\Software\foo\bar"
  9823. */
  9824. static const String getRegistryValue (const String& regValuePath,
  9825. const String& defaultValue = String::empty);
  9826. /** WIN32 ONLY - Sets a registry value as a string.
  9827. This will take care of creating any groups needed to get to the given
  9828. registry value.
  9829. */
  9830. static void setRegistryValue (const String& regValuePath,
  9831. const String& value);
  9832. /** WIN32 ONLY - Returns true if the given value exists in the registry. */
  9833. static bool registryValueExists (const String& regValuePath);
  9834. /** WIN32 ONLY - Deletes a registry value. */
  9835. static void deleteRegistryValue (const String& regValuePath);
  9836. /** WIN32 ONLY - Deletes a registry key (which is registry-talk for 'folder'). */
  9837. static void deleteRegistryKey (const String& regKeyPath);
  9838. /** WIN32 ONLY - This returns the HINSTANCE of the current module.
  9839. In a normal Juce application this will be set to the module handle
  9840. of the application executable.
  9841. If you're writing a DLL using Juce and plan to use any Juce messaging or
  9842. windows, you'll need to make sure you use the setCurrentModuleInstanceHandle()
  9843. to set the correct module handle in your DllMain() function, because
  9844. the win32 system relies on the correct instance handle when opening windows.
  9845. */
  9846. static void* JUCE_CALLTYPE getCurrentModuleInstanceHandle() throw();
  9847. /** WIN32 ONLY - Sets a new module handle to be used by the library.
  9848. @see getCurrentModuleInstanceHandle()
  9849. */
  9850. static void JUCE_CALLTYPE setCurrentModuleInstanceHandle (void* newHandle) throw();
  9851. /** WIN32 ONLY - Gets the command-line params as a string.
  9852. This is needed to avoid unicode problems with the argc type params.
  9853. */
  9854. static const String JUCE_CALLTYPE getCurrentCommandLineParams() throw();
  9855. #endif
  9856. /** Clears the floating point unit's flags.
  9857. Only has an effect under win32, currently.
  9858. */
  9859. static void fpuReset();
  9860. #if JUCE_LINUX || DOXYGEN
  9861. #endif
  9862. };
  9863. #if JUCE_MAC
  9864. /**
  9865. A wrapper class for picking up events from an Apple IR remote control device.
  9866. To use it, just create a subclass of this class, implementing the buttonPressed()
  9867. callback, then call start() and stop() to start or stop receiving events.
  9868. */
  9869. class JUCE_API AppleRemoteDevice
  9870. {
  9871. public:
  9872. AppleRemoteDevice();
  9873. virtual ~AppleRemoteDevice();
  9874. /** The set of buttons that may be pressed.
  9875. @see buttonPressed
  9876. */
  9877. enum ButtonType
  9878. {
  9879. menuButton = 0, /**< The menu button (if it's held for a short time). */
  9880. playButton, /**< The play button. */
  9881. plusButton, /**< The plus or volume-up button. */
  9882. minusButton, /**< The minus or volume-down button. */
  9883. rightButton, /**< The right button (if it's held for a short time). */
  9884. leftButton, /**< The left button (if it's held for a short time). */
  9885. rightButton_Long, /**< The right button (if it's held for a long time). */
  9886. leftButton_Long, /**< The menu button (if it's held for a long time). */
  9887. menuButton_Long, /**< The menu button (if it's held for a long time). */
  9888. playButtonSleepMode,
  9889. switched
  9890. };
  9891. /** Override this method to receive the callback about a button press.
  9892. The callback will happen on the application's message thread.
  9893. Some buttons trigger matching up and down events, in which the isDown parameter
  9894. will be true and then false. Others only send a single event when the
  9895. button is pressed.
  9896. */
  9897. virtual void buttonPressed (const ButtonType buttonId, const bool isDown) = 0;
  9898. /** Starts the device running and responding to events.
  9899. Returns true if it managed to open the device.
  9900. @param inExclusiveMode if true, the remote will be grabbed exclusively for this app,
  9901. and will not be available to any other part of the system. If
  9902. false, it will be shared with other apps.
  9903. @see stop
  9904. */
  9905. bool start (const bool inExclusiveMode) throw();
  9906. /** Stops the device running.
  9907. @see start
  9908. */
  9909. void stop() throw();
  9910. /** Returns true if the device has been started successfully.
  9911. */
  9912. bool isActive() const throw();
  9913. /** Returns the ID number of the remote, if it has sent one.
  9914. */
  9915. int getRemoteId() const throw() { return remoteId; }
  9916. juce_UseDebuggingNewOperator
  9917. /** @internal */
  9918. void handleCallbackInternal();
  9919. private:
  9920. void* device;
  9921. void* queue;
  9922. int remoteId;
  9923. bool open (const bool openInExclusiveMode) throw();
  9924. };
  9925. #endif
  9926. #endif // __JUCE_PLATFORMUTILITIES_JUCEHEADER__
  9927. /********* End of inlined file: juce_PlatformUtilities.h *********/
  9928. #endif
  9929. #ifndef __JUCE_UUID_JUCEHEADER__
  9930. /********* Start of inlined file: juce_Uuid.h *********/
  9931. #ifndef __JUCE_UUID_JUCEHEADER__
  9932. #define __JUCE_UUID_JUCEHEADER__
  9933. /**
  9934. A universally unique 128-bit identifier.
  9935. This class generates very random unique numbers based on the system time
  9936. and MAC addresses if any are available. It's extremely unlikely that two identical
  9937. UUIDs would ever be created by chance.
  9938. The class includes methods for saving the ID as a string or as raw binary data.
  9939. */
  9940. class JUCE_API Uuid
  9941. {
  9942. public:
  9943. /** Creates a new unique ID. */
  9944. Uuid();
  9945. /** Destructor. */
  9946. ~Uuid() throw();
  9947. /** Creates a copy of another UUID. */
  9948. Uuid (const Uuid& other);
  9949. /** Copies another UUID. */
  9950. Uuid& operator= (const Uuid& other);
  9951. /** Returns true if the ID is zero. */
  9952. bool isNull() const throw();
  9953. /** Compares two UUIDs. */
  9954. bool operator== (const Uuid& other) const;
  9955. /** Compares two UUIDs. */
  9956. bool operator!= (const Uuid& other) const;
  9957. /** Returns a stringified version of this UUID.
  9958. A Uuid object can later be reconstructed from this string using operator= or
  9959. the constructor that takes a string parameter.
  9960. @returns a 32 character hex string.
  9961. */
  9962. const String toString() const;
  9963. /** Creates an ID from an encoded string version.
  9964. @see toString
  9965. */
  9966. Uuid (const String& uuidString);
  9967. /** Copies from a stringified UUID.
  9968. The string passed in should be one that was created with the toString() method.
  9969. */
  9970. Uuid& operator= (const String& uuidString);
  9971. /** Returns a pointer to the internal binary representation of the ID.
  9972. This is an array of 16 bytes. To reconstruct a Uuid from its data, use
  9973. the constructor or operator= method that takes an array of uint8s.
  9974. */
  9975. const uint8* getRawData() const throw() { return value.asBytes; }
  9976. /** Creates a UUID from a 16-byte array.
  9977. @see getRawData
  9978. */
  9979. Uuid (const uint8* const rawData);
  9980. /** Sets this UUID from 16-bytes of raw data. */
  9981. Uuid& operator= (const uint8* const rawData);
  9982. juce_UseDebuggingNewOperator
  9983. private:
  9984. union
  9985. {
  9986. uint8 asBytes [16];
  9987. int asInt[4];
  9988. int64 asInt64[2];
  9989. } value;
  9990. };
  9991. #endif // __JUCE_UUID_JUCEHEADER__
  9992. /********* End of inlined file: juce_Uuid.h *********/
  9993. #endif
  9994. #ifndef __JUCE_ZIPFILE_JUCEHEADER__
  9995. /********* Start of inlined file: juce_ZipFile.h *********/
  9996. #ifndef __JUCE_ZIPFILE_JUCEHEADER__
  9997. #define __JUCE_ZIPFILE_JUCEHEADER__
  9998. /**
  9999. Decodes a ZIP file from a stream.
  10000. This can enumerate the items in a ZIP file and can create suitable stream objects
  10001. to read each one.
  10002. */
  10003. class JUCE_API ZipFile
  10004. {
  10005. public:
  10006. /** Creates a ZipFile for a given stream.
  10007. @param inputStream the stream to read from
  10008. @param deleteStreamWhenDestroyed if set to true, the object passed-in
  10009. will be deleted when this ZipFile object is deleted
  10010. */
  10011. ZipFile (InputStream* const inputStream,
  10012. const bool deleteStreamWhenDestroyed) throw();
  10013. /** Creates a ZipFile based for a file. */
  10014. ZipFile (const File& file);
  10015. /** Creates a ZipFile for an input source.
  10016. The inputSource object will be owned by the zip file, which will delete
  10017. it later when not needed.
  10018. */
  10019. ZipFile (InputSource* const inputSource);
  10020. /** Destructor. */
  10021. ~ZipFile() throw();
  10022. /**
  10023. Contains information about one of the entries in a ZipFile.
  10024. @see ZipFile::getEntry
  10025. */
  10026. struct ZipEntry
  10027. {
  10028. /** The name of the file, which may also include a partial pathname. */
  10029. String filename;
  10030. /** The file's original size. */
  10031. unsigned int uncompressedSize;
  10032. /** The last time the file was modified. */
  10033. Time fileTime;
  10034. };
  10035. /** Returns the number of items in the zip file. */
  10036. int getNumEntries() const throw();
  10037. /** Returns a structure that describes one of the entries in the zip file.
  10038. This may return zero if the index is out of range.
  10039. @see ZipFile::ZipEntry
  10040. */
  10041. const ZipEntry* getEntry (const int index) const throw();
  10042. /** Returns the index of the first entry with a given filename.
  10043. This uses a case-sensitive comparison to look for a filename in the
  10044. list of entries. It might return -1 if no match is found.
  10045. @see ZipFile::ZipEntry
  10046. */
  10047. int getIndexOfFileName (const String& fileName) const throw();
  10048. /** Returns a structure that describes one of the entries in the zip file.
  10049. This uses a case-sensitive comparison to look for a filename in the
  10050. list of entries. It might return 0 if no match is found.
  10051. @see ZipFile::ZipEntry
  10052. */
  10053. const ZipEntry* getEntry (const String& fileName) const throw();
  10054. /** Sorts the list of entries, based on the filename.
  10055. */
  10056. void sortEntriesByFilename();
  10057. /** Creates a stream that can read from one of the zip file's entries.
  10058. The stream that is returned must be deleted by the caller (and
  10059. zero might be returned if a stream can't be opened for some reason).
  10060. The stream must not be used after the ZipFile object that created
  10061. has been deleted.
  10062. */
  10063. InputStream* createStreamForEntry (const int index);
  10064. /** Uncompresses all of the files in the zip file.
  10065. This will expand all the entires into a target directory. The relative
  10066. paths of the entries are used.
  10067. @param targetDirectory the root folder to uncompress to
  10068. @param shouldOverwriteFiles whether to overwrite existing files with similarly-named ones
  10069. */
  10070. void uncompressTo (const File& targetDirectory,
  10071. const bool shouldOverwriteFiles = true);
  10072. juce_UseDebuggingNewOperator
  10073. private:
  10074. VoidArray entries;
  10075. friend class ZipInputStream;
  10076. CriticalSection lock;
  10077. InputStream* inputStream;
  10078. InputSource* inputSource;
  10079. bool deleteStreamWhenDestroyed;
  10080. int numEntries, centralRecStart;
  10081. #ifdef JUCE_DEBUG
  10082. int numOpenStreams;
  10083. #endif
  10084. void init();
  10085. int findEndOfZipEntryTable (InputStream* in);
  10086. ZipFile (const ZipFile&);
  10087. const ZipFile& operator= (const ZipFile&);
  10088. };
  10089. #endif // __JUCE_ZIPFILE_JUCEHEADER__
  10090. /********* End of inlined file: juce_ZipFile.h *********/
  10091. #endif
  10092. #ifndef __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__
  10093. #endif
  10094. #ifndef __JUCE_LOCALISEDSTRINGS_JUCEHEADER__
  10095. /********* Start of inlined file: juce_LocalisedStrings.h *********/
  10096. #ifndef __JUCE_LOCALISEDSTRINGS_JUCEHEADER__
  10097. #define __JUCE_LOCALISEDSTRINGS_JUCEHEADER__
  10098. /** Used in the same way as the T(text) macro, this will attempt to translate a
  10099. string into a localised version using the LocalisedStrings class.
  10100. @see LocalisedStrings
  10101. */
  10102. #define TRANS(stringLiteral) \
  10103. LocalisedStrings::translateWithCurrentMappings (stringLiteral)
  10104. /**
  10105. Used to convert strings to localised foreign-language versions.
  10106. This is basically a look-up table of strings and their translated equivalents.
  10107. It can be loaded from a text file, so that you can supply a set of localised
  10108. versions of strings that you use in your app.
  10109. To use it in your code, simply call the translate() method on each string that
  10110. might have foreign versions, and if none is found, the method will just return
  10111. the original string.
  10112. The translation file should start with some lines specifying a description of
  10113. the language it contains, and also a list of ISO country codes where it might
  10114. be appropriate to use the file. After that, each line of the file should contain
  10115. a pair of quoted strings with an '=' sign.
  10116. E.g. for a french translation, the file might be:
  10117. @code
  10118. language: French
  10119. countries: fr be mc ch lu
  10120. "hello" = "bonjour"
  10121. "goodbye" = "au revoir"
  10122. @endcode
  10123. If the strings need to contain a quote character, they can use '\"' instead, and
  10124. if the first non-whitespace character on a line isn't a quote, then it's ignored,
  10125. (you can use this to add comments).
  10126. Note that this is a singleton class, so don't create or destroy the object directly.
  10127. There's also a TRANS(text) macro defined to make it easy to use the this.
  10128. E.g. @code
  10129. printSomething (TRANS("hello"));
  10130. @endcode
  10131. This macro is used in the Juce classes themselves, so your application has a chance to
  10132. intercept and translate any internal Juce text strings that might be shown. (You can easily
  10133. get a list of all the messages by searching for the TRANS() macro in the Juce source
  10134. code).
  10135. */
  10136. class JUCE_API LocalisedStrings
  10137. {
  10138. public:
  10139. /** Creates a set of translations from the text of a translation file.
  10140. When you create one of these, you can call setCurrentMappings() to make it
  10141. the set of mappings that the system's using.
  10142. */
  10143. LocalisedStrings (const String& fileContents) throw();
  10144. /** Creates a set of translations from a file.
  10145. When you create one of these, you can call setCurrentMappings() to make it
  10146. the set of mappings that the system's using.
  10147. */
  10148. LocalisedStrings (const File& fileToLoad) throw();
  10149. /** Destructor. */
  10150. ~LocalisedStrings() throw();
  10151. /** Selects the current set of mappings to be used by the system.
  10152. The object you pass in will be automatically deleted when no longer needed, so
  10153. don't keep a pointer to it. You can also pass in zero to remove the current
  10154. mappings.
  10155. See also the TRANS() macro, which uses the current set to do its translation.
  10156. @see translateWithCurrentMappings
  10157. */
  10158. static void setCurrentMappings (LocalisedStrings* newTranslations) throw();
  10159. /** Returns the currently selected set of mappings.
  10160. This is the object that was last passed to setCurrentMappings(). It may
  10161. be 0 if none has been created.
  10162. */
  10163. static LocalisedStrings* getCurrentMappings() throw();
  10164. /** Tries to translate a string using the currently selected set of mappings.
  10165. If no mapping has been set, or if the mapping doesn't contain a translation
  10166. for the string, this will just return the original string.
  10167. See also the TRANS() macro, which uses this method to do its translation.
  10168. @see setCurrentMappings, getCurrentMappings
  10169. */
  10170. static const String translateWithCurrentMappings (const String& text) throw();
  10171. /** Tries to translate a string using the currently selected set of mappings.
  10172. If no mapping has been set, or if the mapping doesn't contain a translation
  10173. for the string, this will just return the original string.
  10174. See also the TRANS() macro, which uses this method to do its translation.
  10175. @see setCurrentMappings, getCurrentMappings
  10176. */
  10177. static const String translateWithCurrentMappings (const char* text) throw();
  10178. /** Attempts to look up a string and return its localised version.
  10179. If the string isn't found in the list, the original string will be returned.
  10180. */
  10181. const String translate (const String& text) const throw();
  10182. /** Returns the name of the language specified in the translation file.
  10183. This is specified in the file using a line starting with "language:", e.g.
  10184. @code
  10185. language: german
  10186. @endcode
  10187. */
  10188. const String getLanguageName() const throw() { return languageName; }
  10189. /** Returns the list of suitable country codes listed in the translation file.
  10190. These is specified in the file using a line starting with "countries:", e.g.
  10191. @code
  10192. countries: fr be mc ch lu
  10193. @endcode
  10194. The country codes are supposed to be 2-character ISO complient codes.
  10195. */
  10196. const StringArray getCountryCodes() const throw() { return countryCodes; }
  10197. juce_UseDebuggingNewOperator
  10198. private:
  10199. String languageName;
  10200. StringArray countryCodes;
  10201. StringPairArray translations;
  10202. void loadFromText (const String& fileContents) throw();
  10203. };
  10204. #endif // __JUCE_LOCALISEDSTRINGS_JUCEHEADER__
  10205. /********* End of inlined file: juce_LocalisedStrings.h *********/
  10206. #endif
  10207. #ifndef __JUCE_STRING_JUCEHEADER__
  10208. #endif
  10209. #ifndef __JUCE_STRINGARRAY_JUCEHEADER__
  10210. #endif
  10211. #ifndef __JUCE_STRINGPAIRARRAY_JUCEHEADER__
  10212. #endif
  10213. #ifndef __JUCE_XMLDOCUMENT_JUCEHEADER__
  10214. /********* Start of inlined file: juce_XmlDocument.h *********/
  10215. #ifndef __JUCE_XMLDOCUMENT_JUCEHEADER__
  10216. #define __JUCE_XMLDOCUMENT_JUCEHEADER__
  10217. /**
  10218. Parses a text-based XML document and creates an XmlElement object from it.
  10219. The parser will parse DTDs to load external entities but won't
  10220. check the document for validity against the DTD.
  10221. e.g.
  10222. @code
  10223. XmlDocument myDocument (File ("myfile.xml"));
  10224. XmlElement* mainElement = myDocument.getDocumentElement();
  10225. if (mainElement == 0)
  10226. {
  10227. String error = myDocument.getLastParseError();
  10228. }
  10229. else
  10230. {
  10231. ..use the element
  10232. }
  10233. @endcode
  10234. @see XmlElement
  10235. */
  10236. class JUCE_API XmlDocument
  10237. {
  10238. public:
  10239. /** Creates an XmlDocument from the xml text.
  10240. The text doesn't actually get parsed until the getDocumentElement() method is
  10241. called.
  10242. */
  10243. XmlDocument (const String& documentText) throw();
  10244. /** Creates an XmlDocument from a file.
  10245. The text doesn't actually get parsed until the getDocumentElement() method is
  10246. called.
  10247. */
  10248. XmlDocument (const File& file);
  10249. /** Destructor. */
  10250. ~XmlDocument() throw();
  10251. /** Creates an XmlElement object to represent the main document node.
  10252. This method will do the actual parsing of the text, and if there's a
  10253. parse error, it may returns 0 (and you can find out the error using
  10254. the getLastParseError() method).
  10255. @param onlyReadOuterDocumentElement if true, the parser will only read the
  10256. first section of the file, and will only
  10257. return the outer document element - this
  10258. allows quick checking of large files to
  10259. see if they contain the correct type of
  10260. tag, without having to parse the entire file
  10261. @returns a new XmlElement which the caller will need to delete, or null if
  10262. there was an error.
  10263. @see getLastParseError
  10264. */
  10265. XmlElement* getDocumentElement (const bool onlyReadOuterDocumentElement = false);
  10266. /** Returns the parsing error that occurred the last time getDocumentElement was called.
  10267. @returns the error, or an empty string if there was no error.
  10268. */
  10269. const String& getLastParseError() const throw();
  10270. /** Sets an input source object to use for parsing documents that reference external entities.
  10271. If the document has been created from a file, this probably won't be needed, but
  10272. if you're parsing some text and there might be a DTD that references external
  10273. files, you may need to create a custom input source that can retrieve the
  10274. other files it needs.
  10275. The object that is passed-in will be deleted automatically when no longer needed.
  10276. @see InputSource
  10277. */
  10278. void setInputSource (InputSource* const newSource) throw();
  10279. juce_UseDebuggingNewOperator
  10280. private:
  10281. String originalText;
  10282. const tchar* input;
  10283. bool outOfData, errorOccurred;
  10284. bool identifierLookupTable [128];
  10285. String lastError, dtdText;
  10286. StringArray tokenisedDTD;
  10287. bool needToLoadDTD;
  10288. InputSource* inputSource;
  10289. void setLastError (const String& desc, const bool carryOn) throw();
  10290. void skipHeader() throw();
  10291. void skipNextWhiteSpace() throw();
  10292. tchar readNextChar() throw();
  10293. XmlElement* readNextElement (const bool alsoParseSubElements) throw();
  10294. void readChildElements (XmlElement* parent) throw();
  10295. int findNextTokenLength() throw();
  10296. void readQuotedString (String& result) throw();
  10297. void readEntity (String& result) throw();
  10298. const String getFileContents (const String& filename) const;
  10299. const String expandEntity (const String& entity);
  10300. const String expandExternalEntity (const String& entity);
  10301. const String getParameterEntity (const String& entity);
  10302. };
  10303. #endif // __JUCE_XMLDOCUMENT_JUCEHEADER__
  10304. /********* End of inlined file: juce_XmlDocument.h *********/
  10305. #endif
  10306. #ifndef __JUCE_XMLELEMENT_JUCEHEADER__
  10307. #endif
  10308. #ifndef __JUCE_CRITICALSECTION_JUCEHEADER__
  10309. #endif
  10310. #ifndef __JUCE_INTERPROCESSLOCK_JUCEHEADER__
  10311. /********* Start of inlined file: juce_InterProcessLock.h *********/
  10312. #ifndef __JUCE_INTERPROCESSLOCK_JUCEHEADER__
  10313. #define __JUCE_INTERPROCESSLOCK_JUCEHEADER__
  10314. /**
  10315. Acts as a critical section which processes can use to block each other.
  10316. @see CriticalSection
  10317. */
  10318. class JUCE_API InterProcessLock
  10319. {
  10320. public:
  10321. /** Creates a lock object.
  10322. @param name a name that processes will use to identify this lock object
  10323. */
  10324. InterProcessLock (const String& name) throw();
  10325. /** Destructor.
  10326. This will also release the lock if it's currently held by this process.
  10327. */
  10328. ~InterProcessLock() throw();
  10329. /** Attempts to lock the critical section.
  10330. @param timeOutMillisecs how many milliseconds to wait if the lock
  10331. is already held by another process - a value of
  10332. 0 will return immediately, negative values will wait
  10333. forever
  10334. @returns true if the lock could be gained within the timeout period, or
  10335. false if the timeout expired.
  10336. */
  10337. bool enter (int timeOutMillisecs = -1) throw();
  10338. /** Releases the lock if it's currently held by this process.
  10339. */
  10340. void exit() throw();
  10341. juce_UseDebuggingNewOperator
  10342. private:
  10343. void* internal;
  10344. String name;
  10345. int reentrancyLevel;
  10346. InterProcessLock (const InterProcessLock&);
  10347. const InterProcessLock& operator= (const InterProcessLock&);
  10348. };
  10349. #endif // __JUCE_INTERPROCESSLOCK_JUCEHEADER__
  10350. /********* End of inlined file: juce_InterProcessLock.h *********/
  10351. #endif
  10352. #ifndef __JUCE_PROCESS_JUCEHEADER__
  10353. /********* Start of inlined file: juce_Process.h *********/
  10354. #ifndef __JUCE_PROCESS_JUCEHEADER__
  10355. #define __JUCE_PROCESS_JUCEHEADER__
  10356. /** Represents the current executable's process.
  10357. This contains methods for controlling the current application at the
  10358. process-level.
  10359. @see Thread, JUCEApplication
  10360. */
  10361. class JUCE_API Process
  10362. {
  10363. public:
  10364. enum ProcessPriority
  10365. {
  10366. LowPriority = 0,
  10367. NormalPriority = 1,
  10368. HighPriority = 2,
  10369. RealtimePriority = 3
  10370. };
  10371. /** Changes the current process's priority.
  10372. @param priority the process priority, where
  10373. 0=low, 1=normal, 2=high, 3=realtime
  10374. */
  10375. static void setPriority (const ProcessPriority priority);
  10376. /** Kills the current process immediately.
  10377. This is an emergency process terminator that kills the application
  10378. immediately - it's intended only for use only when something goes
  10379. horribly wrong.
  10380. @see JUCEApplication::quit
  10381. */
  10382. static void terminate();
  10383. /** Returns true if this application process is the one that the user is
  10384. currently using.
  10385. */
  10386. static bool isForegroundProcess() throw();
  10387. /** Raises the current process's privilege level.
  10388. Does nothing if this isn't supported by the current OS, or if process
  10389. privilege level is fixed.
  10390. */
  10391. static void raisePrivilege();
  10392. /** Lowers the current process's privilege level.
  10393. Does nothing if this isn't supported by the current OS, or if process
  10394. privilege level is fixed.
  10395. */
  10396. static void lowerPrivilege();
  10397. /** Returns true if this process is being hosted by a debugger.
  10398. */
  10399. static bool JUCE_CALLTYPE isRunningUnderDebugger() throw();
  10400. /** Loads a dynamically-linked library into the process's address space.
  10401. @param pathOrFilename the platform-dependent name and search path
  10402. @returns a handle which can be used by getProcedureEntryPoint(), or
  10403. zero if it fails.
  10404. @see freeDynamicLibrary, getProcedureEntryPoint
  10405. */
  10406. static void* loadDynamicLibrary (const String& pathOrFilename);
  10407. /** Frees a dynamically-linked library.
  10408. @param libraryHandle a handle created by loadDynamicLibrary
  10409. @see loadDynamicLibrary, getProcedureEntryPoint
  10410. */
  10411. static void freeDynamicLibrary (void* libraryHandle);
  10412. /** Finds a procedure call in a dynamically-linked library.
  10413. @param libraryHandle a library handle returned by loadDynamicLibrary
  10414. @param procedureName the name of the procedure call to try to load
  10415. @returns a pointer to the function if found, or 0 if it fails
  10416. @see loadDynamicLibrary
  10417. */
  10418. static void* getProcedureEntryPoint (void* libraryHandle,
  10419. const String& procedureName);
  10420. };
  10421. #endif // __JUCE_PROCESS_JUCEHEADER__
  10422. /********* End of inlined file: juce_Process.h *********/
  10423. #endif
  10424. #ifndef __JUCE_READWRITELOCK_JUCEHEADER__
  10425. /********* Start of inlined file: juce_ReadWriteLock.h *********/
  10426. #ifndef __JUCE_READWRITELOCK_JUCEHEADER__
  10427. #define __JUCE_READWRITELOCK_JUCEHEADER__
  10428. /********* Start of inlined file: juce_WaitableEvent.h *********/
  10429. #ifndef __JUCE_WAITABLEEVENT_JUCEHEADER__
  10430. #define __JUCE_WAITABLEEVENT_JUCEHEADER__
  10431. /**
  10432. Allows threads to wait for events triggered by other threads.
  10433. A thread can call wait() on a WaitableObject, and this will suspend the
  10434. calling thread until another thread wakes it up by calling the signal()
  10435. method.
  10436. */
  10437. class JUCE_API WaitableEvent
  10438. {
  10439. public:
  10440. /** Creates a WaitableEvent object. */
  10441. WaitableEvent() throw();
  10442. /** Destructor.
  10443. If other threads are waiting on this object when it gets deleted, this
  10444. can cause nasty errors, so be careful!
  10445. */
  10446. ~WaitableEvent() throw();
  10447. /** Suspends the calling thread until the event has been signalled.
  10448. This will wait until the object's signal() method is called by another thread,
  10449. or until the timeout expires.
  10450. After the event has been signalled, this method will return true and reset
  10451. the event.
  10452. @param timeOutMilliseconds the maximum time to wait, in milliseconds. A negative
  10453. value will cause it to wait forever.
  10454. @returns true if the object has been signalled, false if the timeout expires first.
  10455. @see signal, reset
  10456. */
  10457. bool wait (const int timeOutMilliseconds = -1) const throw();
  10458. /** Wakes up any threads that are currently waiting on this object.
  10459. If signal() is called when nothing is waiting, the next thread to call wait()
  10460. will return immediately and reset the signal.
  10461. @see wait, reset
  10462. */
  10463. void signal() const throw();
  10464. /** Resets the event to an unsignalled state.
  10465. If it's not already signalled, this does nothing.
  10466. */
  10467. void reset() const throw();
  10468. juce_UseDebuggingNewOperator
  10469. private:
  10470. void* internal;
  10471. WaitableEvent (const WaitableEvent&);
  10472. const WaitableEvent& operator= (const WaitableEvent&);
  10473. };
  10474. #endif // __JUCE_WAITABLEEVENT_JUCEHEADER__
  10475. /********* End of inlined file: juce_WaitableEvent.h *********/
  10476. /**
  10477. A critical section that allows multiple simultaneous readers.
  10478. Features of this type of lock are:
  10479. - Multiple readers can hold the lock at the same time, but only one writer
  10480. can hold it at once.
  10481. - Writers trying to gain the lock will be blocked until all readers and writers
  10482. have released it
  10483. - Readers trying to gain the lock while a writer is waiting to acquire it will be
  10484. blocked until the writer has obtained and released it
  10485. - If a thread already has a read lock and tries to obtain a write lock, it will succeed if
  10486. there are no other readers
  10487. - If a thread already has the write lock and tries to obtain a read lock, this will succeed.
  10488. - Recursive locking is supported.
  10489. @see ScopedReadLock, ScopedWriteLock, CriticalSection
  10490. */
  10491. class JUCE_API ReadWriteLock
  10492. {
  10493. public:
  10494. /**
  10495. Creates a ReadWriteLock object.
  10496. */
  10497. ReadWriteLock() throw();
  10498. /** Destructor.
  10499. If the object is deleted whilst locked, any subsequent behaviour
  10500. is unpredictable.
  10501. */
  10502. ~ReadWriteLock() throw();
  10503. /** Locks this object for reading.
  10504. Multiple threads can simulaneously lock the object for reading, but if another
  10505. thread has it locked for writing, then this will block until it releases the
  10506. lock.
  10507. @see exitRead, ScopedReadLock
  10508. */
  10509. void enterRead() const throw();
  10510. /** Releases the read-lock.
  10511. If the caller thread hasn't got the lock, this can have unpredictable results.
  10512. If the enterRead() method has been called multiple times by the thread, each
  10513. call must be matched by a call to exitRead() before other threads will be allowed
  10514. to take over the lock.
  10515. @see enterRead, ScopedReadLock
  10516. */
  10517. void exitRead() const throw();
  10518. /** Locks this object for writing.
  10519. This will block until any other threads that have it locked for reading or
  10520. writing have released their lock.
  10521. @see exitWrite, ScopedWriteLock
  10522. */
  10523. void enterWrite() const throw();
  10524. /** Tries to lock this object for writing.
  10525. This is like enterWrite(), but doesn't block - it returns true if it manages
  10526. to obtain the lock.
  10527. @see enterWrite
  10528. */
  10529. bool tryEnterWrite() const throw();
  10530. /** Releases the write-lock.
  10531. If the caller thread hasn't got the lock, this can have unpredictable results.
  10532. If the enterWrite() method has been called multiple times by the thread, each
  10533. call must be matched by a call to exit() before other threads will be allowed
  10534. to take over the lock.
  10535. @see enterWrite, ScopedWriteLock
  10536. */
  10537. void exitWrite() const throw();
  10538. juce_UseDebuggingNewOperator
  10539. private:
  10540. CriticalSection accessLock;
  10541. WaitableEvent waitEvent;
  10542. mutable int numWaitingWriters, numWriters;
  10543. mutable int writerThreadId;
  10544. mutable Array <int> readerThreads;
  10545. ReadWriteLock (const ReadWriteLock&);
  10546. const ReadWriteLock& operator= (const ReadWriteLock&);
  10547. };
  10548. #endif // __JUCE_READWRITELOCK_JUCEHEADER__
  10549. /********* End of inlined file: juce_ReadWriteLock.h *********/
  10550. #endif
  10551. #ifndef __JUCE_SCOPEDLOCK_JUCEHEADER__
  10552. #endif
  10553. #ifndef __JUCE_SCOPEDREADLOCK_JUCEHEADER__
  10554. /********* Start of inlined file: juce_ScopedReadLock.h *********/
  10555. #ifndef __JUCE_SCOPEDREADLOCK_JUCEHEADER__
  10556. #define __JUCE_SCOPEDREADLOCK_JUCEHEADER__
  10557. /**
  10558. Automatically locks and unlocks a ReadWriteLock object.
  10559. Use one of these as a local variable to control access to a ReadWriteLock.
  10560. e.g. @code
  10561. ReadWriteLock myLock;
  10562. for (;;)
  10563. {
  10564. const ScopedReadLock myScopedLock (myLock);
  10565. // myLock is now locked
  10566. ...do some stuff...
  10567. // myLock gets unlocked here.
  10568. }
  10569. @endcode
  10570. @see ReadWriteLock, ScopedWriteLock
  10571. */
  10572. class JUCE_API ScopedReadLock
  10573. {
  10574. public:
  10575. /** Creates a ScopedReadLock.
  10576. As soon as it is created, this will call ReadWriteLock::enterRead(), and
  10577. when the ScopedReadLock object is deleted, the ReadWriteLock will
  10578. be unlocked.
  10579. Make sure this object is created and deleted by the same thread,
  10580. otherwise there are no guarantees what will happen! Best just to use it
  10581. as a local stack object, rather than creating one with the new() operator.
  10582. */
  10583. inline ScopedReadLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterRead(); }
  10584. /** Destructor.
  10585. The ReadWriteLock's exitRead() method will be called when the destructor is called.
  10586. Make sure this object is created and deleted by the same thread,
  10587. otherwise there are no guarantees what will happen!
  10588. */
  10589. inline ~ScopedReadLock() throw() { lock_.exitRead(); }
  10590. private:
  10591. const ReadWriteLock& lock_;
  10592. ScopedReadLock (const ScopedReadLock&);
  10593. const ScopedReadLock& operator= (const ScopedReadLock&);
  10594. };
  10595. #endif // __JUCE_SCOPEDREADLOCK_JUCEHEADER__
  10596. /********* End of inlined file: juce_ScopedReadLock.h *********/
  10597. #endif
  10598. #ifndef __JUCE_SCOPEDTRYLOCK_JUCEHEADER__
  10599. /********* Start of inlined file: juce_ScopedTryLock.h *********/
  10600. #ifndef __JUCE_SCOPEDTRYLOCK_JUCEHEADER__
  10601. #define __JUCE_SCOPEDTRYLOCK_JUCEHEADER__
  10602. /**
  10603. Automatically tries to lock and unlock a CriticalSection object.
  10604. Use one of these as a local variable to control access to a CriticalSection.
  10605. e.g. @code
  10606. CriticalSection myCriticalSection;
  10607. for (;;)
  10608. {
  10609. const ScopedTryLock myScopedTryLock (myCriticalSection);
  10610. // Unlike using a ScopedLock, this may fail to actually get the lock, so you
  10611. // should test this with the isLocked() method before doing your thread-unsafe
  10612. // action..
  10613. if (myScopedTryLock.isLocked())
  10614. {
  10615. ...do some stuff...
  10616. }
  10617. else
  10618. {
  10619. ..our attempt at locking failed because another thread had already locked it..
  10620. }
  10621. // myCriticalSection gets unlocked here (if it was locked)
  10622. }
  10623. @endcode
  10624. @see CriticalSection::tryEnter, ScopedLock, ScopedUnlock, ScopedReadLock
  10625. */
  10626. class JUCE_API ScopedTryLock
  10627. {
  10628. public:
  10629. /** Creates a ScopedTryLock.
  10630. As soon as it is created, this will try to lock the CriticalSection, and
  10631. when the ScopedTryLock object is deleted, the CriticalSection will
  10632. be unlocked if the lock was successful.
  10633. Make sure this object is created and deleted by the same thread,
  10634. otherwise there are no guarantees what will happen! Best just to use it
  10635. as a local stack object, rather than creating one with the new() operator.
  10636. */
  10637. inline ScopedTryLock (const CriticalSection& lock) throw() : lock_ (lock), lockWasSuccessful (lock.tryEnter()) {}
  10638. /** Destructor.
  10639. The CriticalSection will be unlocked (if locked) when the destructor is called.
  10640. Make sure this object is created and deleted by the same thread,
  10641. otherwise there are no guarantees what will happen!
  10642. */
  10643. inline ~ScopedTryLock() throw() { if (lockWasSuccessful) lock_.exit(); }
  10644. /** Lock state
  10645. @return True if the CriticalSection is locked.
  10646. */
  10647. bool isLocked() const throw() { return lockWasSuccessful; }
  10648. private:
  10649. const CriticalSection& lock_;
  10650. const bool lockWasSuccessful;
  10651. ScopedTryLock (const ScopedTryLock&);
  10652. const ScopedTryLock& operator= (const ScopedTryLock&);
  10653. };
  10654. #endif // __JUCE_SCOPEDTRYLOCK_JUCEHEADER__
  10655. /********* End of inlined file: juce_ScopedTryLock.h *********/
  10656. #endif
  10657. #ifndef __JUCE_SCOPEDWRITELOCK_JUCEHEADER__
  10658. /********* Start of inlined file: juce_ScopedWriteLock.h *********/
  10659. #ifndef __JUCE_SCOPEDWRITELOCK_JUCEHEADER__
  10660. #define __JUCE_SCOPEDWRITELOCK_JUCEHEADER__
  10661. /**
  10662. Automatically locks and unlocks a ReadWriteLock object.
  10663. Use one of these as a local variable to control access to a ReadWriteLock.
  10664. e.g. @code
  10665. ReadWriteLock myLock;
  10666. for (;;)
  10667. {
  10668. const ScopedWriteLock myScopedLock (myLock);
  10669. // myLock is now locked
  10670. ...do some stuff...
  10671. // myLock gets unlocked here.
  10672. }
  10673. @endcode
  10674. @see ReadWriteLock, ScopedReadLock
  10675. */
  10676. class JUCE_API ScopedWriteLock
  10677. {
  10678. public:
  10679. /** Creates a ScopedWriteLock.
  10680. As soon as it is created, this will call ReadWriteLock::enterWrite(), and
  10681. when the ScopedWriteLock object is deleted, the ReadWriteLock will
  10682. be unlocked.
  10683. Make sure this object is created and deleted by the same thread,
  10684. otherwise there are no guarantees what will happen! Best just to use it
  10685. as a local stack object, rather than creating one with the new() operator.
  10686. */
  10687. inline ScopedWriteLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterWrite(); }
  10688. /** Destructor.
  10689. The ReadWriteLock's exitWrite() method will be called when the destructor is called.
  10690. Make sure this object is created and deleted by the same thread,
  10691. otherwise there are no guarantees what will happen!
  10692. */
  10693. inline ~ScopedWriteLock() throw() { lock_.exitWrite(); }
  10694. private:
  10695. const ReadWriteLock& lock_;
  10696. ScopedWriteLock (const ScopedWriteLock&);
  10697. const ScopedWriteLock& operator= (const ScopedWriteLock&);
  10698. };
  10699. #endif // __JUCE_SCOPEDWRITELOCK_JUCEHEADER__
  10700. /********* End of inlined file: juce_ScopedWriteLock.h *********/
  10701. #endif
  10702. #ifndef __JUCE_THREAD_JUCEHEADER__
  10703. /********* Start of inlined file: juce_Thread.h *********/
  10704. #ifndef __JUCE_THREAD_JUCEHEADER__
  10705. #define __JUCE_THREAD_JUCEHEADER__
  10706. /**
  10707. Encapsulates a thread.
  10708. Subclasses derive from Thread and implement the run() method, in which they
  10709. do their business. The thread can then be started with the startThread() method
  10710. and controlled with various other methods.
  10711. This class also contains some thread-related static methods, such
  10712. as sleep(), yield(), getCurrentThreadId() etc.
  10713. @see CriticalSection, WaitableEvent, Process, ThreadWithProgressWindow,
  10714. MessageManagerLock
  10715. */
  10716. class JUCE_API Thread
  10717. {
  10718. public:
  10719. /**
  10720. Creates a thread.
  10721. When first created, the thread is not running. Use the startThread()
  10722. method to start it.
  10723. */
  10724. Thread (const String& threadName);
  10725. /** Destructor.
  10726. Deleting a Thread object that is running will only give the thread a
  10727. brief opportunity to stop itself cleanly, so it's recommended that you
  10728. should always call stopThread() with a decent timeout before deleting,
  10729. to avoid the thread being forcibly killed (which is a Bad Thing).
  10730. */
  10731. virtual ~Thread();
  10732. /** Must be implemented to perform the thread's actual code.
  10733. Remember that the thread must regularly check the threadShouldExit()
  10734. method whilst running, and if this returns true it should return from
  10735. the run() method as soon as possible to avoid being forcibly killed.
  10736. @see threadShouldExit, startThread
  10737. */
  10738. virtual void run() = 0;
  10739. // Thread control functions..
  10740. /** Starts the thread running.
  10741. This will start the thread's run() method.
  10742. (if it's already started, startThread() won't do anything).
  10743. @see stopThread
  10744. */
  10745. void startThread() throw();
  10746. /** Starts the thread with a given priority.
  10747. Launches the thread with a given priority, where 0 = lowest, 10 = highest.
  10748. If the thread is already running, its priority will be changed.
  10749. @see startThread, setPriority
  10750. */
  10751. void startThread (const int priority) throw();
  10752. /** Attempts to stop the thread running.
  10753. This method will cause the threadShouldExit() method to return true
  10754. and call notify() in case the thread is currently waiting.
  10755. Hopefully the thread will then respond to this by exiting cleanly, and
  10756. the stopThread method will wait for a given time-period for this to
  10757. happen.
  10758. If the thread is stuck and fails to respond after the time-out, it gets
  10759. forcibly killed, which is a very bad thing to happen, as it could still
  10760. be holding locks, etc. which are needed by other parts of your program.
  10761. @param timeOutMilliseconds The number of milliseconds to wait for the
  10762. thread to finish before killing it by force. A negative
  10763. value in here will wait forever.
  10764. @see signalThreadShouldExit, threadShouldExit, waitForThreadToExit, isThreadRunning
  10765. */
  10766. void stopThread (const int timeOutMilliseconds) throw();
  10767. /** Returns true if the thread is currently active */
  10768. bool isThreadRunning() const throw();
  10769. /** Sets a flag to tell the thread it should stop.
  10770. Calling this means that the threadShouldExit() method will then return true.
  10771. The thread should be regularly checking this to see whether it should exit.
  10772. @see threadShouldExit
  10773. @see waitForThreadToExit
  10774. */
  10775. void signalThreadShouldExit() throw();
  10776. /** Checks whether the thread has been told to stop running.
  10777. Threads need to check this regularly, and if it returns true, they should
  10778. return from their run() method at the first possible opportunity.
  10779. @see signalThreadShouldExit
  10780. */
  10781. inline bool threadShouldExit() const throw() { return threadShouldExit_; }
  10782. /** Waits for the thread to stop.
  10783. This will waits until isThreadRunning() is false or until a timeout expires.
  10784. @param timeOutMilliseconds the time to wait, in milliseconds. If this value
  10785. is less than zero, it will wait forever.
  10786. @returns true if the thread exits, or false if the timeout expires first.
  10787. */
  10788. bool waitForThreadToExit (const int timeOutMilliseconds) const throw();
  10789. /** Changes the thread's priority.
  10790. @param priority the new priority, in the range 0 (lowest) to 10 (highest). A priority
  10791. of 5 is normal.
  10792. */
  10793. void setPriority (const int priority) throw();
  10794. /** Changes the priority of the caller thread.
  10795. Similar to setPriority(), but this static method acts on the caller thread.
  10796. @see setPriority
  10797. */
  10798. static void setCurrentThreadPriority (const int priority) throw();
  10799. /** Sets the affinity mask for the thread.
  10800. This will only have an effect next time the thread is started - i.e. if the
  10801. thread is already running when called, it'll have no effect.
  10802. @see setCurrentThreadAffinityMask
  10803. */
  10804. void setAffinityMask (const uint32 affinityMask) throw();
  10805. /** Changes the affinity mask for the caller thread.
  10806. This will change the affinity mask for the thread that calls this static method.
  10807. @see setAffinityMask
  10808. */
  10809. static void setCurrentThreadAffinityMask (const uint32 affinityMask) throw();
  10810. // this can be called from any thread that needs to pause..
  10811. static void JUCE_CALLTYPE sleep (int milliseconds) throw();
  10812. /** Yields the calling thread's current time-slot. */
  10813. static void JUCE_CALLTYPE yield() throw();
  10814. /** Makes the thread wait for a notification.
  10815. This puts the thread to sleep until either the timeout period expires, or
  10816. another thread calls the notify() method to wake it up.
  10817. @returns true if the event has been signalled, false if the timeout expires.
  10818. */
  10819. bool wait (const int timeOutMilliseconds) const throw();
  10820. /** Wakes up the thread.
  10821. If the thread has called the wait() method, this will wake it up.
  10822. @see wait
  10823. */
  10824. void notify() const throw();
  10825. /** Returns an id that identifies the caller thread.
  10826. To find the ID of a particular thread object, use getThreadId().
  10827. @returns a unique identifier that identifies the calling thread.
  10828. @see getThreadId
  10829. */
  10830. static int getCurrentThreadId() throw();
  10831. /** Finds the thread object that is currently running.
  10832. Note that the main UI thread (or other non-Juce threads) don't have a Thread
  10833. object associated with them, so this will return 0.
  10834. */
  10835. static Thread* getCurrentThread() throw();
  10836. /** Returns the ID of this thread.
  10837. That means the ID of this thread object - not of the thread that's calling the method.
  10838. This can change when the thread is started and stopped, and will be invalid if the
  10839. thread's not actually running.
  10840. @see getCurrentThreadId
  10841. */
  10842. int getThreadId() const throw();
  10843. /** Returns the name of the thread.
  10844. This is the name that gets set in the constructor.
  10845. */
  10846. const String getThreadName() const throw() { return threadName_; }
  10847. /** Returns the number of currently-running threads.
  10848. @returns the number of Thread objects known to be currently running.
  10849. @see stopAllThreads
  10850. */
  10851. static int getNumRunningThreads() throw();
  10852. /** Tries to stop all currently-running threads.
  10853. This will attempt to stop all the threads known to be running at the moment.
  10854. */
  10855. static void stopAllThreads (const int timeoutInMillisecs) throw();
  10856. juce_UseDebuggingNewOperator
  10857. private:
  10858. const String threadName_;
  10859. void* volatile threadHandle_;
  10860. CriticalSection startStopLock;
  10861. WaitableEvent startSuspensionEvent_, defaultEvent_;
  10862. int threadPriority_, threadId_;
  10863. uint32 affinityMask_;
  10864. bool volatile threadShouldExit_;
  10865. friend void JUCE_API juce_threadEntryPoint (void*);
  10866. static void threadEntryPoint (Thread* thread) throw();
  10867. Thread (const Thread&);
  10868. const Thread& operator= (const Thread&);
  10869. };
  10870. #endif // __JUCE_THREAD_JUCEHEADER__
  10871. /********* End of inlined file: juce_Thread.h *********/
  10872. #endif
  10873. #ifndef __JUCE_THREADPOOL_JUCEHEADER__
  10874. /********* Start of inlined file: juce_ThreadPool.h *********/
  10875. #ifndef __JUCE_THREADPOOL_JUCEHEADER__
  10876. #define __JUCE_THREADPOOL_JUCEHEADER__
  10877. class ThreadPool;
  10878. class ThreadPoolThread;
  10879. /**
  10880. A task that is executed by a ThreadPool object.
  10881. A ThreadPool keeps a list of ThreadPoolJob objects which are executed by
  10882. its threads.
  10883. The runJob() method needs to be implemented to do the task, and if the code that
  10884. does the work takes a significant time to run, it must keep checking the shouldExit()
  10885. method to see if something is trying to interrupt the job. If shouldExit() returns
  10886. true, the runJob() method must return immediately.
  10887. @see ThreadPool, Thread
  10888. */
  10889. class JUCE_API ThreadPoolJob
  10890. {
  10891. public:
  10892. /** Creates a thread pool job object.
  10893. After creating your job, add it to a thread pool with ThreadPool::addJob().
  10894. */
  10895. ThreadPoolJob (const String& name);
  10896. /** Destructor. */
  10897. virtual ~ThreadPoolJob();
  10898. /** Returns the name of this job.
  10899. @see setJobName
  10900. */
  10901. const String getJobName() const;
  10902. /** Changes the job's name.
  10903. @see getJobName
  10904. */
  10905. void setJobName (const String& newName);
  10906. /** These are the values that can be returned by the runJob() method.
  10907. */
  10908. enum JobStatus
  10909. {
  10910. jobHasFinished = 0, /**< indicates that the job has finished and can be
  10911. removed from the pool. */
  10912. jobHasFinishedAndShouldBeDeleted, /**< indicates that the job has finished and that it
  10913. should be automatically deleted by the pool. */
  10914. jobNeedsRunningAgain /**< indicates that the job would like to be called
  10915. again when a thread is free. */
  10916. };
  10917. /** Peforms the actual work that this job needs to do.
  10918. Your subclass must implement this method, in which is does its work.
  10919. If the code in this method takes a significant time to run, it must repeatedly check
  10920. the shouldExit() method to see if something is trying to interrupt the job.
  10921. If shouldExit() ever returns true, the runJob() method must return immediately.
  10922. If this method returns jobHasFinished, then the job will be removed from the pool
  10923. immediately. If it returns jobNeedsRunningAgain, then the job will be left in the
  10924. pool and will get a chance to run again as soon as a thread is free.
  10925. @see shouldExit()
  10926. */
  10927. virtual JobStatus runJob() = 0;
  10928. /** Returns true if this job is currently running its runJob() method. */
  10929. bool isRunning() const throw() { return isActive; }
  10930. /** Returns true if something is trying to interrupt this job and make it stop.
  10931. Your runJob() method must call this whenever it gets a chance, and if it ever
  10932. returns true, the runJob() method must return immediately.
  10933. @see signalJobShouldExit()
  10934. */
  10935. bool shouldExit() const throw() { return shouldStop; }
  10936. /** Calling this will cause the shouldExit() method to return true, and the job
  10937. should (if it's been implemented correctly) stop as soon as possible.
  10938. @see shouldExit()
  10939. */
  10940. void signalJobShouldExit();
  10941. juce_UseDebuggingNewOperator
  10942. private:
  10943. friend class ThreadPool;
  10944. friend class ThreadPoolThread;
  10945. String jobName;
  10946. ThreadPool* pool;
  10947. bool shouldStop, isActive, shouldBeDeleted;
  10948. };
  10949. /**
  10950. A set of threads that will run a list of jobs.
  10951. When a ThreadPoolJob object is added to the ThreadPool's list, its run() method
  10952. will be called by the next pooled thread that becomes free.
  10953. @see ThreadPoolJob, Thread
  10954. */
  10955. class JUCE_API ThreadPool
  10956. {
  10957. public:
  10958. /** Creates a thread pool.
  10959. Once you've created a pool, you can give it some things to do with the addJob()
  10960. method.
  10961. @param numberOfThreads the maximum number of actual threads to run.
  10962. @param startThreadsOnlyWhenNeeded if this is true, then no threads will be started
  10963. until there are some jobs to run. If false, then
  10964. all the threads will be fired-up immediately so that
  10965. they're ready for action
  10966. @param stopThreadsWhenNotUsedTimeoutMs if this timeout is > 0, then if any threads have been
  10967. inactive for this length of time, they will automatically
  10968. be stopped until more jobs come along and they're needed
  10969. */
  10970. ThreadPool (const int numberOfThreads,
  10971. const bool startThreadsOnlyWhenNeeded = true,
  10972. const int stopThreadsWhenNotUsedTimeoutMs = 5000);
  10973. /** Destructor.
  10974. This will attempt to remove all the jobs before deleting, but if you want to
  10975. specify a timeout, you should call removeAllJobs() explicitly before deleting
  10976. the pool.
  10977. */
  10978. ~ThreadPool();
  10979. /** Adds a job to the queue.
  10980. Once a job has been added, then the next time a thread is free, it will run
  10981. the job's ThreadPoolJob::runJob() method. Depending on the return value of the
  10982. runJob() method, the pool will either remove the job from the pool or add it to
  10983. the back of the queue to be run again.
  10984. */
  10985. void addJob (ThreadPoolJob* const job);
  10986. /** Tries to remove a job from the pool.
  10987. If the job isn't yet running, this will simply remove it. If it is running, it
  10988. will wait for it to finish.
  10989. If the timeout period expires before the job finishes running, then the job will be
  10990. left in the pool and this will return false. It returns true if the job is sucessfully
  10991. stopped and removed.
  10992. @param job the job to remove
  10993. @param interruptIfRunning if true, then if the job is currently busy, its
  10994. ThreadPoolJob::signalJobShouldExit() method will be called to try
  10995. to interrupt it. If false, then if the job will be allowed to run
  10996. until it stops normally (or the timeout expires)
  10997. @param timeOutMilliseconds the length of time this method should wait for the job to finish
  10998. before giving up and returning false
  10999. */
  11000. bool removeJob (ThreadPoolJob* const job,
  11001. const bool interruptIfRunning,
  11002. const int timeOutMilliseconds);
  11003. /** Tries clear all jobs from the pool.
  11004. @param interruptRunningJobs if true, then all running jobs will have their ThreadPoolJob::signalJobShouldExit()
  11005. methods called to try to interrupt them
  11006. @param timeOutMilliseconds the length of time this method should wait for all the jobs to finish
  11007. before giving up and returning false
  11008. @returns true if all jobs are successfully stopped and removed; false if the timeout period
  11009. expires while waiting for them to stop
  11010. */
  11011. bool removeAllJobs (const bool interruptRunningJobs,
  11012. const int timeOutMilliseconds);
  11013. /** Returns the number of jobs currently running or queued.
  11014. */
  11015. int getNumJobs() const throw();
  11016. /** Returns one of the jobs in the queue.
  11017. Note that this can be a very volatile list as jobs might be continuously getting shifted
  11018. around in the list, and this method may return 0 if the index is currently out-of-range.
  11019. */
  11020. ThreadPoolJob* getJob (const int index) const;
  11021. /** Returns true if the given job is currently queued or running.
  11022. @see isJobRunning()
  11023. */
  11024. bool contains (const ThreadPoolJob* const job) const throw();
  11025. /** Returns true if the given job is currently being run by a thread.
  11026. */
  11027. bool isJobRunning (const ThreadPoolJob* const job) const;
  11028. /** Waits until a job has finished running and has been removed from the pool.
  11029. This will wait until the job is no longer in the pool - i.e. until its
  11030. runJob() method returns ThreadPoolJob::jobHasFinished.
  11031. If the timeout period expires before the job finishes, this will return false;
  11032. it returns true if the job has finished successfully.
  11033. */
  11034. bool waitForJobToFinish (const ThreadPoolJob* const job,
  11035. const int timeOutMilliseconds) const;
  11036. /** Returns a list of the names of all the jobs currently running or queued.
  11037. If onlyReturnActiveJobs is true, only the ones currently running are returned.
  11038. */
  11039. const StringArray getNamesOfAllJobs (const bool onlyReturnActiveJobs) const;
  11040. /** Changes the priority of all the threads.
  11041. This will call Thread::setPriority() for each thread in the pool.
  11042. */
  11043. void setThreadPriorities (const int newPriority);
  11044. juce_UseDebuggingNewOperator
  11045. private:
  11046. const int numThreads, threadStopTimeout;
  11047. int priority;
  11048. Thread** threads;
  11049. VoidArray jobs;
  11050. CriticalSection lock;
  11051. uint32 lastJobEndTime;
  11052. friend class ThreadPoolThread;
  11053. bool runNextJob();
  11054. ThreadPool (const ThreadPool&);
  11055. const ThreadPool& operator= (const ThreadPool&);
  11056. };
  11057. #endif // __JUCE_THREADPOOL_JUCEHEADER__
  11058. /********* End of inlined file: juce_ThreadPool.h *********/
  11059. #endif
  11060. #ifndef __JUCE_TIMESLICETHREAD_JUCEHEADER__
  11061. /********* Start of inlined file: juce_TimeSliceThread.h *********/
  11062. #ifndef __JUCE_TIMESLICETHREAD_JUCEHEADER__
  11063. #define __JUCE_TIMESLICETHREAD_JUCEHEADER__
  11064. /**
  11065. Used by the TimeSliceThread class.
  11066. To register your class with a TimeSliceThread, derive from this class and
  11067. use the TimeSliceThread::addTimeSliceClient() method to add it to the list.
  11068. Make sure you always call TimeSliceThread::removeTimeSliceClient() before
  11069. deleting your client!
  11070. @see TimeSliceThread
  11071. */
  11072. class JUCE_API TimeSliceClient
  11073. {
  11074. public:
  11075. /** Destructor. */
  11076. virtual ~TimeSliceClient() {}
  11077. /** Called back by a TimeSliceThread.
  11078. When you register this class with it, a TimeSliceThread will repeatedly call
  11079. this method.
  11080. The implementation of this method should use its time-slice to do something that's
  11081. quick - never block for longer than absolutely necessary.
  11082. @returns Your method should return true if it needs more time, or false if it's
  11083. not too busy and doesn't need calling back urgently. If all the thread's
  11084. clients indicate that they're not busy, then it'll save CPU by sleeping for
  11085. up to half a second in between callbacks. You can force the TimeSliceThread
  11086. to wake up and poll again immediately by calling its notify() method.
  11087. */
  11088. virtual bool useTimeSlice() = 0;
  11089. };
  11090. /**
  11091. A thread that keeps a list of clients, and calls each one in turn, giving them
  11092. all a chance to run some sort of short task.
  11093. @see TimeSliceClient, Thread
  11094. */
  11095. class JUCE_API TimeSliceThread : public Thread
  11096. {
  11097. public:
  11098. /**
  11099. Creates a TimeSliceThread.
  11100. When first created, the thread is not running. Use the startThread()
  11101. method to start it.
  11102. */
  11103. TimeSliceThread (const String& threadName);
  11104. /** Destructor.
  11105. Deleting a Thread object that is running will only give the thread a
  11106. brief opportunity to stop itself cleanly, so it's recommended that you
  11107. should always call stopThread() with a decent timeout before deleting,
  11108. to avoid the thread being forcibly killed (which is a Bad Thing).
  11109. */
  11110. ~TimeSliceThread();
  11111. /** Adds a client to the list.
  11112. The client's callbacks will start immediately (possibly before the method
  11113. has returned).
  11114. */
  11115. void addTimeSliceClient (TimeSliceClient* const client);
  11116. /** Removes a client from the list.
  11117. This method will make sure that all callbacks to the client have completely
  11118. finished before the method returns.
  11119. */
  11120. void removeTimeSliceClient (TimeSliceClient* const client);
  11121. /** Returns the number of registered clients. */
  11122. int getNumClients() const throw();
  11123. /** Returns one of the registered clients. */
  11124. TimeSliceClient* getClient (const int index) const throw();
  11125. /** @internal */
  11126. void run();
  11127. juce_UseDebuggingNewOperator
  11128. private:
  11129. CriticalSection callbackLock, listLock;
  11130. Array <TimeSliceClient*> clients;
  11131. int index;
  11132. TimeSliceClient* clientBeingCalled;
  11133. bool clientsChanged;
  11134. TimeSliceThread (const TimeSliceThread&);
  11135. const TimeSliceThread& operator= (const TimeSliceThread&);
  11136. };
  11137. #endif // __JUCE_TIMESLICETHREAD_JUCEHEADER__
  11138. /********* End of inlined file: juce_TimeSliceThread.h *********/
  11139. #endif
  11140. #ifndef __JUCE_WAITABLEEVENT_JUCEHEADER__
  11141. #endif
  11142. #endif
  11143. /********* End of inlined file: juce_core_includes.h *********/
  11144. // if you're compiling a command-line app, you might want to just include the core headers,
  11145. // so you can set this macro before including juce.h
  11146. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  11147. /********* Start of inlined file: juce_app_includes.h *********/
  11148. #ifndef __JUCE_JUCE_APP_INCLUDES_INCLUDEFILES__
  11149. #define __JUCE_JUCE_APP_INCLUDES_INCLUDEFILES__
  11150. #ifndef __JUCE_APPLICATION_JUCEHEADER__
  11151. /********* Start of inlined file: juce_Application.h *********/
  11152. #ifndef __JUCE_APPLICATION_JUCEHEADER__
  11153. #define __JUCE_APPLICATION_JUCEHEADER__
  11154. /********* Start of inlined file: juce_ApplicationCommandTarget.h *********/
  11155. #ifndef __JUCE_APPLICATIONCOMMANDTARGET_JUCEHEADER__
  11156. #define __JUCE_APPLICATIONCOMMANDTARGET_JUCEHEADER__
  11157. /********* Start of inlined file: juce_Component.h *********/
  11158. #ifndef __JUCE_COMPONENT_JUCEHEADER__
  11159. #define __JUCE_COMPONENT_JUCEHEADER__
  11160. /********* Start of inlined file: juce_MouseCursor.h *********/
  11161. #ifndef __JUCE_MOUSECURSOR_JUCEHEADER__
  11162. #define __JUCE_MOUSECURSOR_JUCEHEADER__
  11163. class Image;
  11164. class RefCountedMouseCursor;
  11165. class ComponentPeer;
  11166. class Component;
  11167. /**
  11168. Represents a mouse cursor image.
  11169. This object can either be used to represent one of the standard mouse
  11170. cursor shapes, or a custom one generated from an image.
  11171. */
  11172. class JUCE_API MouseCursor
  11173. {
  11174. public:
  11175. /** The set of available standard mouse cursors. */
  11176. enum StandardCursorType
  11177. {
  11178. NoCursor = 0, /**< An invisible cursor. */
  11179. NormalCursor, /**< The stardard arrow cursor. */
  11180. WaitCursor, /**< The normal hourglass or spinning-beachball 'busy' cursor. */
  11181. IBeamCursor, /**< A vertical I-beam for positioning within text. */
  11182. CrosshairCursor, /**< A pair of crosshairs. */
  11183. CopyingCursor, /**< The normal arrow cursor, but with a "+" on it to indicate
  11184. that you're dragging a copy of something. */
  11185. PointingHandCursor, /**< A hand with a pointing finger, for clicking on web-links. */
  11186. DraggingHandCursor, /**< An open flat hand for dragging heavy objects around. */
  11187. LeftRightResizeCursor, /**< An arrow pointing left and right. */
  11188. UpDownResizeCursor, /**< an arrow pointing up and down. */
  11189. UpDownLeftRightResizeCursor, /**< An arrow pointing up, down, left and right. */
  11190. TopEdgeResizeCursor, /**< A platform-specific cursor for resizing the top-edge of a window. */
  11191. BottomEdgeResizeCursor, /**< A platform-specific cursor for resizing the bottom-edge of a window. */
  11192. LeftEdgeResizeCursor, /**< A platform-specific cursor for resizing the left-edge of a window. */
  11193. RightEdgeResizeCursor, /**< A platform-specific cursor for resizing the right-edge of a window. */
  11194. TopLeftCornerResizeCursor, /**< A platform-specific cursor for resizing the top-left-corner of a window. */
  11195. TopRightCornerResizeCursor, /**< A platform-specific cursor for resizing the top-right-corner of a window. */
  11196. BottomLeftCornerResizeCursor, /**< A platform-specific cursor for resizing the bottom-left-corner of a window. */
  11197. BottomRightCornerResizeCursor /**< A platform-specific cursor for resizing the bottom-right-corner of a window. */
  11198. };
  11199. /** Creates the standard arrow cursor. */
  11200. MouseCursor() throw();
  11201. /** Creates one of the standard mouse cursor */
  11202. MouseCursor (const StandardCursorType type) throw();
  11203. /** Creates a custom cursor from an image.
  11204. @param image the image to use for the cursor - if this is bigger than the
  11205. system can manage, it might get scaled down first, and might
  11206. also have to be turned to black-and-white if it can't do colour
  11207. cursors.
  11208. @param hotSpotX the x position of the cursor's hotspot within the image
  11209. @param hotSpotY the y position of the cursor's hotspot within the image
  11210. */
  11211. MouseCursor (Image& image,
  11212. const int hotSpotX,
  11213. const int hotSpotY) throw();
  11214. /** Creates a copy of another cursor object. */
  11215. MouseCursor (const MouseCursor& other) throw();
  11216. /** Copies this cursor from another object. */
  11217. const MouseCursor& operator= (const MouseCursor& other) throw();
  11218. /** Destructor. */
  11219. ~MouseCursor() throw();
  11220. /** Checks whether two mouse cursors are the same.
  11221. For custom cursors, two cursors created from the same image won't be
  11222. recognised as the same, only MouseCursor objects that have been
  11223. copied from the same object.
  11224. */
  11225. bool operator== (const MouseCursor& other) const throw();
  11226. /** Checks whether two mouse cursors are the same.
  11227. For custom cursors, two cursors created from the same image won't be
  11228. recognised as the same, only MouseCursor objects that have been
  11229. copied from the same object.
  11230. */
  11231. bool operator!= (const MouseCursor& other) const throw();
  11232. /** Makes the system show its default 'busy' cursor.
  11233. This will turn the system cursor to an hourglass or spinning beachball
  11234. until the next time the mouse is moved, or hideWaitCursor() is called.
  11235. This is handy if the message loop is about to block for a couple of
  11236. seconds while busy and you want to give the user feedback about this.
  11237. @see MessageManager::setTimeBeforeShowingWaitCursor
  11238. */
  11239. static void showWaitCursor() throw();
  11240. /** If showWaitCursor has been called, this will return the mouse to its
  11241. normal state.
  11242. This will look at what component is under the mouse, and update the
  11243. cursor to be the correct one for that component.
  11244. @see showWaitCursor
  11245. */
  11246. static void hideWaitCursor() throw();
  11247. juce_UseDebuggingNewOperator
  11248. private:
  11249. RefCountedMouseCursor* cursorHandle;
  11250. friend class Component;
  11251. void showInWindow (ComponentPeer* window) const throw();
  11252. void showInAllWindows() const throw();
  11253. void* getHandle() const throw();
  11254. };
  11255. #endif // __JUCE_MOUSECURSOR_JUCEHEADER__
  11256. /********* End of inlined file: juce_MouseCursor.h *********/
  11257. /********* Start of inlined file: juce_MouseListener.h *********/
  11258. #ifndef __JUCE_MOUSELISTENER_JUCEHEADER__
  11259. #define __JUCE_MOUSELISTENER_JUCEHEADER__
  11260. /********* Start of inlined file: juce_MouseEvent.h *********/
  11261. #ifndef __JUCE_MOUSEEVENT_JUCEHEADER__
  11262. #define __JUCE_MOUSEEVENT_JUCEHEADER__
  11263. class Component;
  11264. /********* Start of inlined file: juce_ModifierKeys.h *********/
  11265. #ifndef __JUCE_MODIFIERKEYS_JUCEHEADER__
  11266. #define __JUCE_MODIFIERKEYS_JUCEHEADER__
  11267. /**
  11268. Represents the state of the mouse buttons and modifier keys.
  11269. This is used both by mouse events and by KeyPress objects to describe
  11270. the state of keys such as shift, control, alt, etc.
  11271. @see KeyPress, MouseEvent::mods
  11272. */
  11273. class JUCE_API ModifierKeys
  11274. {
  11275. public:
  11276. /** Creates a ModifierKeys object from a raw set of flags.
  11277. @param flags to represent the keys that are down
  11278. @see shiftModifier, ctrlModifier, altModifier, leftButtonModifier,
  11279. rightButtonModifier, commandModifier, popupMenuClickModifier
  11280. */
  11281. ModifierKeys (const int flags = 0) throw();
  11282. /** Creates a copy of another object. */
  11283. ModifierKeys (const ModifierKeys& other) throw();
  11284. /** Copies this object from another one. */
  11285. const ModifierKeys& operator= (const ModifierKeys& other) throw();
  11286. /** Checks whether the 'command' key flag is set (or 'ctrl' on Windows/Linux).
  11287. This is a platform-agnostic way of checking for the operating system's
  11288. preferred command-key modifier - so on the Mac it tests for the Apple key, on
  11289. Windows/Linux, it's actually checking for the CTRL key.
  11290. */
  11291. inline bool isCommandDown() const throw() { return (flags & commandModifier) != 0; }
  11292. /** Checks whether the user is trying to launch a pop-up menu.
  11293. This checks for platform-specific modifiers that might indicate that the user
  11294. is following the operating system's normal method of showing a pop-up menu.
  11295. So on Windows/Linux, this method is really testing for a right-click.
  11296. On the Mac, it tests for either the CTRL key being down, or a right-click.
  11297. */
  11298. inline bool isPopupMenu() const throw() { return (flags & popupMenuClickModifier) != 0; }
  11299. /** Checks whether the flag is set for the left mouse-button. */
  11300. inline bool isLeftButtonDown() const throw() { return (flags & leftButtonModifier) != 0; }
  11301. /** Checks whether the flag is set for the right mouse-button.
  11302. Note that for detecting popup-menu clicks, you should be using isPopupMenu() instead, as
  11303. this is platform-independent (and makes your code more explanatory too).
  11304. */
  11305. inline bool isRightButtonDown() const throw() { return (flags & rightButtonModifier) != 0; }
  11306. inline bool isMiddleButtonDown() const throw() { return (flags & middleButtonModifier) != 0; }
  11307. /** Tests for any of the mouse-button flags. */
  11308. inline bool isAnyMouseButtonDown() const throw() { return (flags & allMouseButtonModifiers) != 0; }
  11309. /** Tests for any of the modifier key flags. */
  11310. inline bool isAnyModifierKeyDown() const throw() { return (flags & (shiftModifier | ctrlModifier | altModifier | commandModifier)) != 0; }
  11311. /** Checks whether the shift key's flag is set. */
  11312. inline bool isShiftDown() const throw() { return (flags & shiftModifier) != 0; }
  11313. /** Checks whether the CTRL key's flag is set.
  11314. Remember that it's better to use the platform-agnostic routines to test for command-key and
  11315. popup-menu modifiers.
  11316. @see isCommandDown, isPopupMenu
  11317. */
  11318. inline bool isCtrlDown() const throw() { return (flags & ctrlModifier) != 0; }
  11319. /** Checks whether the shift key's flag is set. */
  11320. inline bool isAltDown() const throw() { return (flags & altModifier) != 0; }
  11321. /** Flags that represent the different keys. */
  11322. enum Flags
  11323. {
  11324. /** Shift key flag. */
  11325. shiftModifier = 1,
  11326. /** CTRL key flag. */
  11327. ctrlModifier = 2,
  11328. /** ALT key flag. */
  11329. altModifier = 4,
  11330. /** Left mouse button flag. */
  11331. leftButtonModifier = 16,
  11332. /** Right mouse button flag. */
  11333. rightButtonModifier = 32,
  11334. /** Middle mouse button flag. */
  11335. middleButtonModifier = 64,
  11336. #if JUCE_MAC
  11337. /** Command key flag - on windows this is the same as the CTRL key flag. */
  11338. commandModifier = 8,
  11339. /** Popup menu flag - on windows this is the same as rightButtonModifier, on the
  11340. Mac it's the same as (rightButtonModifier | ctrlModifier). */
  11341. popupMenuClickModifier = rightButtonModifier | ctrlModifier,
  11342. #else
  11343. /** Command key flag - on windows this is the same as the CTRL key flag. */
  11344. commandModifier = ctrlModifier,
  11345. /** Popup menu flag - on windows this is the same as rightButtonModifier, on the
  11346. Mac it's the same as (rightButtonModifier | ctrlModifier). */
  11347. popupMenuClickModifier = rightButtonModifier,
  11348. #endif
  11349. /** Represents a combination of all the shift, alt, ctrl and command key modifiers. */
  11350. allKeyboardModifiers = shiftModifier | ctrlModifier | altModifier | commandModifier,
  11351. /** Represents a combination of all the mouse buttons at once. */
  11352. allMouseButtonModifiers = leftButtonModifier | rightButtonModifier | middleButtonModifier,
  11353. };
  11354. /** Returns the raw flags for direct testing. */
  11355. inline int getRawFlags() const throw() { return flags; }
  11356. /** Tests a combination of flags and returns true if any of them are set. */
  11357. inline bool testFlags (const int flagsToTest) const throw() { return (flags & flagsToTest) != 0; }
  11358. /** Creates a ModifierKeys object to represent the last-known state of the
  11359. keyboard and mouse buttons.
  11360. @see getCurrentModifiersRealtime
  11361. */
  11362. static const ModifierKeys getCurrentModifiers() throw();
  11363. /** Creates a ModifierKeys object to represent the current state of the
  11364. keyboard and mouse buttons.
  11365. This isn't often needed and isn't recommended, but will actively check all the
  11366. mouse and key states rather than just returning their last-known state like
  11367. getCurrentModifiers() does.
  11368. This is only needed in special circumstances for up-to-date modifier information
  11369. at times when the app's event loop isn't running normally.
  11370. */
  11371. static const ModifierKeys getCurrentModifiersRealtime() throw();
  11372. private:
  11373. int flags;
  11374. static int currentModifierFlags;
  11375. friend class ComponentPeer;
  11376. static void updateCurrentModifiers() throw();
  11377. };
  11378. #endif // __JUCE_MODIFIERKEYS_JUCEHEADER__
  11379. /********* End of inlined file: juce_ModifierKeys.h *********/
  11380. /**
  11381. Contains position and status information about a mouse event.
  11382. @see MouseListener, Component::mouseMove, Component::mouseEnter, Component::mouseExit,
  11383. Component::mouseDown, Component::mouseUp, Component::mouseDrag
  11384. */
  11385. class JUCE_API MouseEvent
  11386. {
  11387. public:
  11388. /** Creates a MouseEvent.
  11389. Normally an application will never need to use this.
  11390. @param x the x position of the mouse, relative to the component that is passed-in
  11391. @param y the y position of the mouse, relative to the component that is passed-in
  11392. @param modifiers the key modifiers at the time of the event
  11393. @param originator the component that the mouse event applies to
  11394. @param eventTime the time the event happened
  11395. @param mouseDownX the x position of the corresponding mouse-down event (relative to the component that is passed-in).
  11396. If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be
  11397. the same as the current mouse-x position.
  11398. @param mouseDownY the y position of the corresponding mouse-down event (relative to the component that is passed-in)
  11399. If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be
  11400. the same as the current mouse-y position.
  11401. @param mouseDownTime the time at which the corresponding mouse-down event happened
  11402. If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be
  11403. the same as the current mouse-event time.
  11404. @param numberOfClicks how many clicks, e.g. a double-click event will be 2, a triple-click will be 3, etc
  11405. @param mouseWasDragged whether the mouse has been dragged significantly since the previous mouse-down
  11406. */
  11407. MouseEvent (const int x, const int y,
  11408. const ModifierKeys& modifiers,
  11409. Component* const originator,
  11410. const Time& eventTime,
  11411. const int mouseDownX,
  11412. const int mouseDownY,
  11413. const Time& mouseDownTime,
  11414. const int numberOfClicks,
  11415. const bool mouseWasDragged) throw();
  11416. /** Destructor. */
  11417. ~MouseEvent() throw();
  11418. /** The x-position of the mouse when the event occurred.
  11419. This value is relative to the top-left of the component to which the
  11420. event applies (as indicated by the MouseEvent::eventComponent field).
  11421. */
  11422. int x;
  11423. /** The y-position of the mouse when the event occurred.
  11424. This value is relative to the top-left of the component to which the
  11425. event applies (as indicated by the MouseEvent::eventComponent field).
  11426. */
  11427. int y;
  11428. /** The key modifiers associated with the event.
  11429. This will let you find out which mouse buttons were down, as well as which
  11430. modifier keys were held down.
  11431. When used for mouse-up events, this will indicate the state of the mouse buttons
  11432. just before they were released, so that you can tell which button they let go of.
  11433. */
  11434. ModifierKeys mods;
  11435. /** The component that this event applies to.
  11436. This is usually the component that the mouse was over at the time, but for mouse-drag
  11437. events the mouse could actually be over a different component and the events are
  11438. still sent to the component that the button was originally pressed on.
  11439. The x and y member variables are relative to this component's position.
  11440. If you use getEventRelativeTo() to retarget this object to be relative to a different
  11441. component, this pointer will be updated, but originalComponent remains unchanged.
  11442. @see originalComponent
  11443. */
  11444. Component* eventComponent;
  11445. /** The component that the event first occurred on.
  11446. If you use getEventRelativeTo() to retarget this object to be relative to a different
  11447. component, this value remains unchanged to indicate the first component that received it.
  11448. @see eventComponent
  11449. */
  11450. Component* originalComponent;
  11451. /** The time that this mouse-event occurred.
  11452. */
  11453. Time eventTime;
  11454. /** Returns the x co-ordinate of the last place that a mouse was pressed.
  11455. The co-ordinate is relative to the component specified in MouseEvent::component.
  11456. @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
  11457. */
  11458. int getMouseDownX() const throw();
  11459. /** Returns the y co-ordinate of the last place that a mouse was pressed.
  11460. The co-ordinate is relative to the component specified in MouseEvent::component.
  11461. @see getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
  11462. */
  11463. int getMouseDownY() const throw();
  11464. /** Returns the straight-line distance between where the mouse is now and where it
  11465. was the last time the button was pressed.
  11466. This is quite handy for things like deciding whether the user has moved far enough
  11467. for it to be considered a drag operation.
  11468. @see getDistanceFromDragStartX
  11469. */
  11470. int getDistanceFromDragStart() const throw();
  11471. /** Returns the difference between the mouse's current x postion and where it was
  11472. when the button was last pressed.
  11473. @see getDistanceFromDragStart
  11474. */
  11475. int getDistanceFromDragStartX() const throw();
  11476. /** Returns the difference between the mouse's current y postion and where it was
  11477. when the button was last pressed.
  11478. @see getDistanceFromDragStart
  11479. */
  11480. int getDistanceFromDragStartY() const throw();
  11481. /** Returns true if the mouse has just been clicked.
  11482. Used in either your mouseUp() or mouseDrag() methods, this will tell you whether
  11483. the user has dragged the mouse more than a few pixels from the place where the
  11484. mouse-down occurred.
  11485. Once they have dragged it far enough for this method to return false, it will continue
  11486. to return false until the mouse-up, even if they move the mouse back to the same
  11487. position where they originally pressed it. This means that it's very handy for
  11488. objects that can either be clicked on or dragged, as you can use it in the mouseDrag()
  11489. callback to ignore any small movements they might make while clicking.
  11490. @returns true if the mouse wasn't dragged by more than a few pixels between
  11491. the last time the button was pressed and released.
  11492. */
  11493. bool mouseWasClicked() const throw();
  11494. /** For a click event, the number of times the mouse was clicked in succession.
  11495. So for example a double-click event will return 2, a triple-click 3, etc.
  11496. */
  11497. int getNumberOfClicks() const throw() { return numberOfClicks; }
  11498. /** Returns the time that the mouse button has been held down for.
  11499. If called from a mouseDrag or mouseUp callback, this will return the
  11500. number of milliseconds since the corresponding mouseDown event occurred.
  11501. If called in other contexts, e.g. a mouseMove, then the returned value
  11502. may be 0 or an undefined value.
  11503. */
  11504. int getLengthOfMousePress() const throw();
  11505. /** Returns the mouse x position of this event, in global screen co-ordinates.
  11506. The co-ordinates are relative to the top-left of the main monitor.
  11507. @see getMouseDownScreenX, Desktop::getMousePosition
  11508. */
  11509. int getScreenX() const throw();
  11510. /** Returns the mouse y position of this event, in global screen co-ordinates.
  11511. The co-ordinates are relative to the top-left of the main monitor.
  11512. @see getMouseDownScreenY, Desktop::getMousePosition
  11513. */
  11514. int getScreenY() const throw();
  11515. /** Returns the x co-ordinate at which the mouse button was last pressed.
  11516. The co-ordinates are relative to the top-left of the main monitor.
  11517. @see getScreenX, Desktop::getMousePosition
  11518. */
  11519. int getMouseDownScreenX() const throw();
  11520. /** Returns the y co-ordinate at which the mouse button was last pressed.
  11521. The co-ordinates are relative to the top-left of the main monitor.
  11522. @see getScreenY, Desktop::getMousePosition
  11523. */
  11524. int getMouseDownScreenY() const throw();
  11525. /** Creates a version of this event that is relative to a different component.
  11526. The x and y positions of the event that is returned will have been
  11527. adjusted to be relative to the new component.
  11528. */
  11529. const MouseEvent getEventRelativeTo (Component* const otherComponent) const throw();
  11530. /** Changes the application-wide setting for the double-click time limit.
  11531. This is the maximum length of time between mouse-clicks for it to be
  11532. considered a double-click. It's used by the Component class.
  11533. @see getDoubleClickTimeout, MouseListener::mouseDoubleClick
  11534. */
  11535. static void setDoubleClickTimeout (const int timeOutMilliseconds) throw();
  11536. /** Returns the application-wide setting for the double-click time limit.
  11537. This is the maximum length of time between mouse-clicks for it to be
  11538. considered a double-click. It's used by the Component class.
  11539. @see setDoubleClickTimeout, MouseListener::mouseDoubleClick
  11540. */
  11541. static int getDoubleClickTimeout() throw();
  11542. juce_UseDebuggingNewOperator
  11543. private:
  11544. int mouseDownX, mouseDownY;
  11545. Time mouseDownTime;
  11546. int numberOfClicks;
  11547. bool wasMovedSinceMouseDown;
  11548. };
  11549. #endif // __JUCE_MOUSEEVENT_JUCEHEADER__
  11550. /********* End of inlined file: juce_MouseEvent.h *********/
  11551. /**
  11552. A MouseListener can be registered with a component to receive callbacks
  11553. about mouse events that happen to that component.
  11554. @see Component::addMouseListener, Component::removeMouseListener
  11555. */
  11556. class JUCE_API MouseListener
  11557. {
  11558. public:
  11559. /** Destructor. */
  11560. virtual ~MouseListener() {}
  11561. /** Called when the mouse moves inside a component.
  11562. If the mouse button isn't pressed and the mouse moves over a component,
  11563. this will be called to let the component react to this.
  11564. A component will always get a mouseEnter callback before a mouseMove.
  11565. @param e details about the position and status of the mouse event, including
  11566. the source component in which it occurred
  11567. @see mouseEnter, mouseExit, mouseDrag, contains
  11568. */
  11569. virtual void mouseMove (const MouseEvent& e);
  11570. /** Called when the mouse first enters a component.
  11571. If the mouse button isn't pressed and the mouse moves into a component,
  11572. this will be called to let the component react to this.
  11573. When the mouse button is pressed and held down while being moved in
  11574. or out of a component, no mouseEnter or mouseExit callbacks are made - only
  11575. mouseDrag messages are sent to the component that the mouse was originally
  11576. clicked on, until the button is released.
  11577. @param e details about the position and status of the mouse event, including
  11578. the source component in which it occurred
  11579. @see mouseExit, mouseDrag, mouseMove, contains
  11580. */
  11581. virtual void mouseEnter (const MouseEvent& e);
  11582. /** Called when the mouse moves out of a component.
  11583. This will be called when the mouse moves off the edge of this
  11584. component.
  11585. If the mouse button was pressed, and it was then dragged off the
  11586. edge of the component and released, then this callback will happen
  11587. when the button is released, after the mouseUp callback.
  11588. @param e details about the position and status of the mouse event, including
  11589. the source component in which it occurred
  11590. @see mouseEnter, mouseDrag, mouseMove, contains
  11591. */
  11592. virtual void mouseExit (const MouseEvent& e);
  11593. /** Called when a mouse button is pressed.
  11594. The MouseEvent object passed in contains lots of methods for finding out
  11595. which button was pressed, as well as which modifier keys (e.g. shift, ctrl)
  11596. were held down at the time.
  11597. Once a button is held down, the mouseDrag method will be called when the
  11598. mouse moves, until the button is released.
  11599. @param e details about the position and status of the mouse event, including
  11600. the source component in which it occurred
  11601. @see mouseUp, mouseDrag, mouseDoubleClick, contains
  11602. */
  11603. virtual void mouseDown (const MouseEvent& e);
  11604. /** Called when the mouse is moved while a button is held down.
  11605. When a mouse button is pressed inside a component, that component
  11606. receives mouseDrag callbacks each time the mouse moves, even if the
  11607. mouse strays outside the component's bounds.
  11608. @param e details about the position and status of the mouse event, including
  11609. the source component in which it occurred
  11610. @see mouseDown, mouseUp, mouseMove, contains, setDragRepeatInterval
  11611. */
  11612. virtual void mouseDrag (const MouseEvent& e);
  11613. /** Called when a mouse button is released.
  11614. A mouseUp callback is sent to the component in which a button was pressed
  11615. even if the mouse is actually over a different component when the
  11616. button is released.
  11617. The MouseEvent object passed in contains lots of methods for finding out
  11618. which buttons were down just before they were released.
  11619. @param e details about the position and status of the mouse event, including
  11620. the source component in which it occurred
  11621. @see mouseDown, mouseDrag, mouseDoubleClick, contains
  11622. */
  11623. virtual void mouseUp (const MouseEvent& e);
  11624. /** Called when a mouse button has been double-clicked on a component.
  11625. The MouseEvent object passed in contains lots of methods for finding out
  11626. which button was pressed, as well as which modifier keys (e.g. shift, ctrl)
  11627. were held down at the time.
  11628. @param e details about the position and status of the mouse event, including
  11629. the source component in which it occurred
  11630. @see mouseDown, mouseUp
  11631. */
  11632. virtual void mouseDoubleClick (const MouseEvent& e);
  11633. /** Called when the mouse-wheel is moved.
  11634. This callback is sent to the component that the mouse is over when the
  11635. wheel is moved.
  11636. If not overridden, the component will forward this message to its parent, so
  11637. that parent components can collect mouse-wheel messages that happen to
  11638. child components which aren't interested in them.
  11639. @param e details about the position and status of the mouse event, including
  11640. the source component in which it occurred
  11641. @param wheelIncrementX the speed and direction of the horizontal scroll-wheel - a positive
  11642. value means the wheel has been pushed to the right, negative means it
  11643. was pushed to the left
  11644. @param wheelIncrementY the speed and direction of the vertical scroll-wheel - a positive
  11645. value means the wheel has been pushed upwards, negative means it
  11646. was pushed downwards
  11647. */
  11648. virtual void mouseWheelMove (const MouseEvent& e,
  11649. float wheelIncrementX,
  11650. float wheelIncrementY);
  11651. private:
  11652. // XXX Deprecated! The parameters for this method have changed to accommodate horizonatal scroll-wheels.
  11653. // This line is here to cause a syntax error if you're trying to use the old-style definition, so
  11654. // if that happens, update your code to use the new one above.
  11655. virtual int mouseWheelMove (const MouseEvent&, float) { return 0; }
  11656. };
  11657. #endif // __JUCE_MOUSELISTENER_JUCEHEADER__
  11658. /********* End of inlined file: juce_MouseListener.h *********/
  11659. /********* Start of inlined file: juce_ComponentListener.h *********/
  11660. #ifndef __JUCE_COMPONENTLISTENER_JUCEHEADER__
  11661. #define __JUCE_COMPONENTLISTENER_JUCEHEADER__
  11662. class Component;
  11663. /**
  11664. Gets informed about changes to a component's hierarchy or position.
  11665. To monitor a component for changes, register a subclass of ComponentListener
  11666. with the component using Component::addComponentListener().
  11667. Be sure to deregister listeners before you delete them!
  11668. @see Component::addComponentListener, Component::removeComponentListener
  11669. */
  11670. class JUCE_API ComponentListener
  11671. {
  11672. public:
  11673. /** Destructor. */
  11674. virtual ~ComponentListener() {}
  11675. /** Called when the component's position or size changes.
  11676. @param component the component that was moved or resized
  11677. @param wasMoved true if the component's top-left corner has just moved
  11678. @param wasResized true if the component's width or height has just changed
  11679. @see Component::setBounds, Component::resized, Component::moved
  11680. */
  11681. virtual void componentMovedOrResized (Component& component,
  11682. bool wasMoved,
  11683. bool wasResized);
  11684. /** Called when the component is brought to the top of the z-order.
  11685. @param component the component that was moved
  11686. @see Component::toFront, Component::broughtToFront
  11687. */
  11688. virtual void componentBroughtToFront (Component& component);
  11689. /** Called when the component is made visible or invisible.
  11690. @param component the component that changed
  11691. @see Component::setVisible
  11692. */
  11693. virtual void componentVisibilityChanged (Component& component);
  11694. /** Called when the component has children added or removed.
  11695. @param component the component whose children were changed
  11696. @see Component::childrenChanged, Component::addChildComponent,
  11697. Component::removeChildComponent
  11698. */
  11699. virtual void componentChildrenChanged (Component& component);
  11700. /** Called to indicate that the component's parents have changed.
  11701. When a component is added or removed from its parent, all of its children
  11702. will produce this notification (recursively - so all children of its
  11703. children will also be called as well).
  11704. @param component the component that this listener is registered with
  11705. @see Component::parentHierarchyChanged
  11706. */
  11707. virtual void componentParentHierarchyChanged (Component& component);
  11708. /** Called when the component's name is changed.
  11709. @see Component::setName, Component::getName
  11710. */
  11711. virtual void componentNameChanged (Component& component);
  11712. };
  11713. #endif // __JUCE_COMPONENTLISTENER_JUCEHEADER__
  11714. /********* End of inlined file: juce_ComponentListener.h *********/
  11715. /********* Start of inlined file: juce_KeyListener.h *********/
  11716. #ifndef __JUCE_KEYLISTENER_JUCEHEADER__
  11717. #define __JUCE_KEYLISTENER_JUCEHEADER__
  11718. /********* Start of inlined file: juce_KeyPress.h *********/
  11719. #ifndef __JUCE_KEYPRESS_JUCEHEADER__
  11720. #define __JUCE_KEYPRESS_JUCEHEADER__
  11721. /**
  11722. Represents a key press, including any modifier keys that are needed.
  11723. E.g. a KeyPress might represent CTRL+C, SHIFT+ALT+H, Spacebar, Escape, etc.
  11724. @see Component, KeyListener, Button::addShortcut, KeyPressMappingManager
  11725. */
  11726. class JUCE_API KeyPress
  11727. {
  11728. public:
  11729. /** Creates an (invalid) KeyPress.
  11730. @see isValid
  11731. */
  11732. KeyPress() throw();
  11733. /** Creates a KeyPress for a key and some modifiers.
  11734. e.g.
  11735. CTRL+C would be: KeyPress ('c', ModifierKeys::ctrlModifier)
  11736. SHIFT+Escape would be: KeyPress (KeyPress::escapeKey, ModifierKeys::shiftModifier)
  11737. @param keyCode a code that represents the key - this value must be
  11738. one of special constants listed in this class, or an
  11739. 8-bit character code such as a letter (case is ignored),
  11740. digit or a simple key like "," or ".". Note that this
  11741. isn't the same as the textCharacter parameter, so for example
  11742. a keyCode of 'a' and a shift-key modifier should have a
  11743. textCharacter value of 'A'.
  11744. @param modifiers the modifiers to associate with the keystroke
  11745. @param textCharacter the character that would be printed if someone typed
  11746. this keypress into a text editor. This value may be
  11747. null if the keypress is a non-printing character
  11748. @see getKeyCode, isKeyCode, getModifiers
  11749. */
  11750. KeyPress (const int keyCode,
  11751. const ModifierKeys& modifiers,
  11752. const juce_wchar textCharacter) throw();
  11753. /** Creates a keypress with a keyCode but no modifiers or text character.
  11754. */
  11755. KeyPress (const int keyCode) throw();
  11756. /** Creates a copy of another KeyPress. */
  11757. KeyPress (const KeyPress& other) throw();
  11758. /** Copies this KeyPress from another one. */
  11759. const KeyPress& operator= (const KeyPress& other) throw();
  11760. /** Compares two KeyPress objects. */
  11761. bool operator== (const KeyPress& other) const throw();
  11762. /** Compares two KeyPress objects. */
  11763. bool operator!= (const KeyPress& other) const throw();
  11764. /** Returns true if this is a valid KeyPress.
  11765. A null keypress can be created by the default constructor, in case it's
  11766. needed.
  11767. */
  11768. bool isValid() const throw() { return keyCode != 0; }
  11769. /** Returns the key code itself.
  11770. This will either be one of the special constants defined in this class,
  11771. or an 8-bit character code.
  11772. */
  11773. int getKeyCode() const throw() { return keyCode; }
  11774. /** Returns the key modifiers.
  11775. @see ModifierKeys
  11776. */
  11777. const ModifierKeys getModifiers() const throw() { return mods; }
  11778. /** Returns the character that is associated with this keypress.
  11779. This is the character that you'd expect to see printed if you press this
  11780. keypress in a text editor or similar component.
  11781. */
  11782. juce_wchar getTextCharacter() const throw() { return textCharacter; }
  11783. /** Checks whether the KeyPress's key is the same as the one provided, without checking
  11784. the modifiers.
  11785. The values for key codes can either be one of the special constants defined in
  11786. this class, or an 8-bit character code.
  11787. @see getKeyCode
  11788. */
  11789. bool isKeyCode (const int keyCodeToCompare) const throw() { return keyCode == keyCodeToCompare; }
  11790. /** Converts a textual key description to a KeyPress.
  11791. This attempts to decode a textual version of a keypress, e.g. "CTRL + C" or "SPACE".
  11792. This isn't designed to cope with any kind of input, but should be given the
  11793. strings that are created by the getTextDescription() method.
  11794. If the string can't be parsed, the object returned will be invalid.
  11795. @see getTextDescription
  11796. */
  11797. static const KeyPress createFromDescription (const String& textVersion) throw();
  11798. /** Creates a textual description of the key combination.
  11799. e.g. "CTRL + C" or "DELETE".
  11800. To store a keypress in a file, use this method, along with createFromDescription()
  11801. to retrieve it later.
  11802. */
  11803. const String getTextDescription() const throw();
  11804. /** Checks whether the user is currently holding down the keys that make up this
  11805. KeyPress.
  11806. Note that this will return false if any extra modifier keys are
  11807. down - e.g. if the keypress is CTRL+X and the user is actually holding CTRL+ALT+x
  11808. then it will be false.
  11809. */
  11810. bool isCurrentlyDown() const throw();
  11811. /** Checks whether a particular key is held down, irrespective of modifiers.
  11812. The values for key codes can either be one of the special constants defined in
  11813. this class, or an 8-bit character code.
  11814. */
  11815. static bool isKeyCurrentlyDown (int keyCode) throw();
  11816. // Key codes
  11817. //
  11818. // Note that the actual values of these are platform-specific and may change
  11819. // without warning, so don't store them anywhere as constants. For persisting/retrieving
  11820. // KeyPress objects, use getTextDescription() and createFromDescription() instead.
  11821. //
  11822. static const int spaceKey; /**< key-code for the space bar */
  11823. static const int escapeKey; /**< key-code for the escape key */
  11824. static const int returnKey; /**< key-code for the return key*/
  11825. static const int tabKey; /**< key-code for the tab key*/
  11826. static const int deleteKey; /**< key-code for the delete key (not backspace) */
  11827. static const int backspaceKey; /**< key-code for the backspace key */
  11828. static const int insertKey; /**< key-code for the insert key */
  11829. static const int upKey; /**< key-code for the cursor-up key */
  11830. static const int downKey; /**< key-code for the cursor-down key */
  11831. static const int leftKey; /**< key-code for the cursor-left key */
  11832. static const int rightKey; /**< key-code for the cursor-right key */
  11833. static const int pageUpKey; /**< key-code for the page-up key */
  11834. static const int pageDownKey; /**< key-code for the page-down key */
  11835. static const int homeKey; /**< key-code for the home key */
  11836. static const int endKey; /**< key-code for the end key */
  11837. static const int F1Key; /**< key-code for the F1 key */
  11838. static const int F2Key; /**< key-code for the F2 key */
  11839. static const int F3Key; /**< key-code for the F3 key */
  11840. static const int F4Key; /**< key-code for the F4 key */
  11841. static const int F5Key; /**< key-code for the F5 key */
  11842. static const int F6Key; /**< key-code for the F6 key */
  11843. static const int F7Key; /**< key-code for the F7 key */
  11844. static const int F8Key; /**< key-code for the F8 key */
  11845. static const int F9Key; /**< key-code for the F9 key */
  11846. static const int F10Key; /**< key-code for the F10 key */
  11847. static const int F11Key; /**< key-code for the F11 key */
  11848. static const int F12Key; /**< key-code for the F12 key */
  11849. static const int F13Key; /**< key-code for the F13 key */
  11850. static const int F14Key; /**< key-code for the F14 key */
  11851. static const int F15Key; /**< key-code for the F15 key */
  11852. static const int F16Key; /**< key-code for the F16 key */
  11853. static const int numberPad0; /**< key-code for the 0 on the numeric keypad. */
  11854. static const int numberPad1; /**< key-code for the 1 on the numeric keypad. */
  11855. static const int numberPad2; /**< key-code for the 2 on the numeric keypad. */
  11856. static const int numberPad3; /**< key-code for the 3 on the numeric keypad. */
  11857. static const int numberPad4; /**< key-code for the 4 on the numeric keypad. */
  11858. static const int numberPad5; /**< key-code for the 5 on the numeric keypad. */
  11859. static const int numberPad6; /**< key-code for the 6 on the numeric keypad. */
  11860. static const int numberPad7; /**< key-code for the 7 on the numeric keypad. */
  11861. static const int numberPad8; /**< key-code for the 8 on the numeric keypad. */
  11862. static const int numberPad9; /**< key-code for the 9 on the numeric keypad. */
  11863. static const int numberPadAdd; /**< key-code for the add sign on the numeric keypad. */
  11864. static const int numberPadSubtract; /**< key-code for the subtract sign on the numeric keypad. */
  11865. static const int numberPadMultiply; /**< key-code for the multiply sign on the numeric keypad. */
  11866. static const int numberPadDivide; /**< key-code for the divide sign on the numeric keypad. */
  11867. static const int numberPadSeparator; /**< key-code for the comma on the numeric keypad. */
  11868. static const int numberPadDecimalPoint; /**< key-code for the decimal point sign on the numeric keypad. */
  11869. static const int numberPadEquals; /**< key-code for the equals key on the numeric keypad. */
  11870. static const int numberPadDelete; /**< key-code for the delete key on the numeric keypad. */
  11871. static const int playKey; /**< key-code for a multimedia 'play' key, (not all keyboards will have one) */
  11872. static const int stopKey; /**< key-code for a multimedia 'stop' key, (not all keyboards will have one) */
  11873. static const int fastForwardKey; /**< key-code for a multimedia 'fast-forward' key, (not all keyboards will have one) */
  11874. static const int rewindKey; /**< key-code for a multimedia 'rewind' key, (not all keyboards will have one) */
  11875. juce_UseDebuggingNewOperator
  11876. private:
  11877. int keyCode;
  11878. ModifierKeys mods;
  11879. juce_wchar textCharacter;
  11880. };
  11881. #endif // __JUCE_KEYPRESS_JUCEHEADER__
  11882. /********* End of inlined file: juce_KeyPress.h *********/
  11883. class Component;
  11884. /**
  11885. Receives callbacks when keys are pressed.
  11886. You can add a key listener to a component to be informed when that component
  11887. gets key events. See the Component::addListener method for more details.
  11888. @see KeyPress, Component::addKeyListener, KeyPressMappingManager
  11889. */
  11890. class JUCE_API KeyListener
  11891. {
  11892. public:
  11893. /** Destructor. */
  11894. virtual ~KeyListener() {}
  11895. /** Called to indicate that a key has been pressed.
  11896. If your implementation returns true, then the key event is considered to have
  11897. been consumed, and will not be passed on to any other components. If it returns
  11898. false, then the key will be passed to other components that might want to use it.
  11899. @param key the keystroke, including modifier keys
  11900. @param originatingComponent the component that received the key event
  11901. @see keyStateChanged, Component::keyPressed
  11902. */
  11903. virtual bool keyPressed (const KeyPress& key,
  11904. Component* originatingComponent) = 0;
  11905. /** Called when any key is pressed or released.
  11906. When this is called, classes that might be interested in
  11907. the state of one or more keys can use KeyPress::isKeyCurrentlyDown() to
  11908. check whether their key has changed.
  11909. If your implementation returns true, then the key event is considered to have
  11910. been consumed, and will not be passed on to any other components. If it returns
  11911. false, then the key will be passed to other components that might want to use it.
  11912. @param originatingComponent the component that received the key event
  11913. @see KeyPress, Component::keyStateChanged
  11914. */
  11915. virtual bool keyStateChanged (Component* originatingComponent);
  11916. };
  11917. #endif // __JUCE_KEYLISTENER_JUCEHEADER__
  11918. /********* End of inlined file: juce_KeyListener.h *********/
  11919. /********* Start of inlined file: juce_KeyboardFocusTraverser.h *********/
  11920. #ifndef __JUCE_KEYBOARDFOCUSTRAVERSER_JUCEHEADER__
  11921. #define __JUCE_KEYBOARDFOCUSTRAVERSER_JUCEHEADER__
  11922. class Component;
  11923. /**
  11924. Controls the order in which focus moves between components.
  11925. The default algorithm used by this class to work out the order of traversal
  11926. is as follows:
  11927. - if two components both have an explicit focus order specified, then the
  11928. one with the lowest number comes first (see the Component::setExplicitFocusOrder()
  11929. method).
  11930. - any component with an explicit focus order greater than 0 comes before ones
  11931. that don't have an order specified.
  11932. - any unspecified components are traversed in a left-to-right, then top-to-bottom
  11933. order.
  11934. If you need traversal in a more customised way, you can create a subclass
  11935. of KeyboardFocusTraverser that uses your own algorithm, and use
  11936. Component::createFocusTraverser() to create it.
  11937. @see Component::setExplicitFocusOrder, Component::createFocusTraverser
  11938. */
  11939. class JUCE_API KeyboardFocusTraverser
  11940. {
  11941. public:
  11942. KeyboardFocusTraverser();
  11943. /** Destructor. */
  11944. virtual ~KeyboardFocusTraverser();
  11945. /** Returns the component that should be given focus after the specified one
  11946. when moving "forwards".
  11947. The default implementation will return the next component which is to the
  11948. right of or below this one.
  11949. This may return 0 if there's no suitable candidate.
  11950. */
  11951. virtual Component* getNextComponent (Component* current);
  11952. /** Returns the component that should be given focus after the specified one
  11953. when moving "backwards".
  11954. The default implementation will return the next component which is to the
  11955. left of or above this one.
  11956. This may return 0 if there's no suitable candidate.
  11957. */
  11958. virtual Component* getPreviousComponent (Component* current);
  11959. /** Returns the component that should receive focus be default within the given
  11960. parent component.
  11961. The default implementation will just return the foremost child component that
  11962. wants focus.
  11963. This may return 0 if there's no suitable candidate.
  11964. */
  11965. virtual Component* getDefaultComponent (Component* parentComponent);
  11966. };
  11967. #endif // __JUCE_KEYBOARDFOCUSTRAVERSER_JUCEHEADER__
  11968. /********* End of inlined file: juce_KeyboardFocusTraverser.h *********/
  11969. /********* Start of inlined file: juce_ImageEffectFilter.h *********/
  11970. #ifndef __JUCE_IMAGEEFFECTFILTER_JUCEHEADER__
  11971. #define __JUCE_IMAGEEFFECTFILTER_JUCEHEADER__
  11972. /********* Start of inlined file: juce_Graphics.h *********/
  11973. #ifndef __JUCE_GRAPHICS_JUCEHEADER__
  11974. #define __JUCE_GRAPHICS_JUCEHEADER__
  11975. /********* Start of inlined file: juce_Font.h *********/
  11976. #ifndef __JUCE_FONT_JUCEHEADER__
  11977. #define __JUCE_FONT_JUCEHEADER__
  11978. /********* Start of inlined file: juce_Typeface.h *********/
  11979. #ifndef __JUCE_TYPEFACE_JUCEHEADER__
  11980. #define __JUCE_TYPEFACE_JUCEHEADER__
  11981. /********* Start of inlined file: juce_Path.h *********/
  11982. #ifndef __JUCE_PATH_JUCEHEADER__
  11983. #define __JUCE_PATH_JUCEHEADER__
  11984. /********* Start of inlined file: juce_AffineTransform.h *********/
  11985. #ifndef __JUCE_AFFINETRANSFORM_JUCEHEADER__
  11986. #define __JUCE_AFFINETRANSFORM_JUCEHEADER__
  11987. /**
  11988. Represents a 2D affine-transformation matrix.
  11989. An affine transformation is a transformation such as a rotation, scale, shear,
  11990. resize or translation.
  11991. These are used for various 2D transformation tasks, e.g. with Path objects.
  11992. @see Path, Point, Line
  11993. */
  11994. class JUCE_API AffineTransform
  11995. {
  11996. public:
  11997. /** Creates an identity transform. */
  11998. AffineTransform() throw();
  11999. /** Creates a copy of another transform. */
  12000. AffineTransform (const AffineTransform& other) throw();
  12001. /** Creates a transform from a set of raw matrix values.
  12002. The resulting matrix is:
  12003. (mat00 mat01 mat02)
  12004. (mat10 mat11 mat12)
  12005. ( 0 0 1 )
  12006. */
  12007. AffineTransform (const float mat00, const float mat01, const float mat02,
  12008. const float mat10, const float mat11, const float mat12) throw();
  12009. /** Copies from another AffineTransform object */
  12010. const AffineTransform& operator= (const AffineTransform& other) throw();
  12011. /** Compares two transforms. */
  12012. bool operator== (const AffineTransform& other) const throw();
  12013. /** Compares two transforms. */
  12014. bool operator!= (const AffineTransform& other) const throw();
  12015. /** A ready-to-use identity transform, which you can use to append other
  12016. transformations to.
  12017. e.g. @code
  12018. AffineTransform myTransform = AffineTransform::identity.rotated (.5f)
  12019. .scaled (2.0f);
  12020. @endcode
  12021. */
  12022. static const AffineTransform identity;
  12023. /** Transforms a 2D co-ordinate using this matrix. */
  12024. void transformPoint (float& x,
  12025. float& y) const throw();
  12026. /** Transforms a 2D co-ordinate using this matrix. */
  12027. void transformPoint (double& x,
  12028. double& y) const throw();
  12029. /** Returns a new transform which is the same as this one followed by a translation. */
  12030. const AffineTransform translated (const float deltaX,
  12031. const float deltaY) const throw();
  12032. /** Returns a new transform which is a translation. */
  12033. static const AffineTransform translation (const float deltaX,
  12034. const float deltaY) throw();
  12035. /** Returns a transform which is the same as this one followed by a rotation.
  12036. The rotation is specified by a number of radians to rotate clockwise, centred around
  12037. the origin (0, 0).
  12038. */
  12039. const AffineTransform rotated (const float angleInRadians) const throw();
  12040. /** Returns a transform which is the same as this one followed by a rotation about a given point.
  12041. The rotation is specified by a number of radians to rotate clockwise, centred around
  12042. the co-ordinates passed in.
  12043. */
  12044. const AffineTransform rotated (const float angleInRadians,
  12045. const float pivotX,
  12046. const float pivotY) const throw();
  12047. /** Returns a new transform which is a rotation about (0, 0). */
  12048. static const AffineTransform rotation (const float angleInRadians) throw();
  12049. /** Returns a new transform which is a rotation about a given point. */
  12050. static const AffineTransform rotation (const float angleInRadians,
  12051. const float pivotX,
  12052. const float pivotY) throw();
  12053. /** Returns a transform which is the same as this one followed by a re-scaling.
  12054. The scaling is centred around the origin (0, 0).
  12055. */
  12056. const AffineTransform scaled (const float factorX,
  12057. const float factorY) const throw();
  12058. /** Returns a new transform which is a re-scale about the origin. */
  12059. static const AffineTransform scale (const float factorX,
  12060. const float factorY) throw();
  12061. /** Returns a transform which is the same as this one followed by a shear.
  12062. The shear is centred around the origin (0, 0).
  12063. */
  12064. const AffineTransform sheared (const float shearX,
  12065. const float shearY) const throw();
  12066. /** Returns a matrix which is the inverse operation of this one.
  12067. Some matrices don't have an inverse - in this case, the method will just return
  12068. an identity transform.
  12069. */
  12070. const AffineTransform inverted() const throw();
  12071. /** Returns the result of concatenating another transformation after this one. */
  12072. const AffineTransform followedBy (const AffineTransform& other) const throw();
  12073. /** Returns true if this transform has no effect on points. */
  12074. bool isIdentity() const throw();
  12075. /** Returns true if this transform maps to a singularity - i.e. if it has no inverse. */
  12076. bool isSingularity() const throw();
  12077. juce_UseDebuggingNewOperator
  12078. /* The transform matrix is:
  12079. (mat00 mat01 mat02)
  12080. (mat10 mat11 mat12)
  12081. ( 0 0 1 )
  12082. */
  12083. float mat00, mat01, mat02;
  12084. float mat10, mat11, mat12;
  12085. private:
  12086. const AffineTransform followedBy (const float mat00, const float mat01, const float mat02,
  12087. const float mat10, const float mat11, const float mat12) const throw();
  12088. };
  12089. #endif // __JUCE_AFFINETRANSFORM_JUCEHEADER__
  12090. /********* End of inlined file: juce_AffineTransform.h *********/
  12091. /********* Start of inlined file: juce_Point.h *********/
  12092. #ifndef __JUCE_POINT_JUCEHEADER__
  12093. #define __JUCE_POINT_JUCEHEADER__
  12094. /**
  12095. A pair of (x, y) co-ordinates.
  12096. Uses 32-bit floating point accuracy.
  12097. @see Line, Path, AffineTransform
  12098. */
  12099. class JUCE_API Point
  12100. {
  12101. public:
  12102. /** Creates a point with co-ordinates (0, 0). */
  12103. Point() throw();
  12104. /** Creates a copy of another point. */
  12105. Point (const Point& other) throw();
  12106. /** Creates a point from an (x, y) position. */
  12107. Point (const float x, const float y) throw();
  12108. /** Copies this point from another one.
  12109. @see setXY
  12110. */
  12111. const Point& operator= (const Point& other) throw();
  12112. /** Destructor. */
  12113. ~Point() throw();
  12114. /** Returns the point's x co-ordinate. */
  12115. inline float getX() const throw() { return x; }
  12116. /** Returns the point's y co-ordinate. */
  12117. inline float getY() const throw() { return y; }
  12118. /** Changes the point's x and y co-ordinates. */
  12119. void setXY (const float x,
  12120. const float y) throw();
  12121. /** Uses a transform to change the point's co-ordinates.
  12122. @see AffineTransform::transformPoint
  12123. */
  12124. void applyTransform (const AffineTransform& transform) throw();
  12125. juce_UseDebuggingNewOperator
  12126. private:
  12127. float x, y;
  12128. };
  12129. #endif // __JUCE_POINT_JUCEHEADER__
  12130. /********* End of inlined file: juce_Point.h *********/
  12131. /********* Start of inlined file: juce_Justification.h *********/
  12132. #ifndef __JUCE_JUSTIFICATION_JUCEHEADER__
  12133. #define __JUCE_JUSTIFICATION_JUCEHEADER__
  12134. /**
  12135. Represents a type of justification to be used when positioning graphical items.
  12136. e.g. it indicates whether something should be placed top-left, top-right,
  12137. centred, etc.
  12138. It is used in various places wherever this kind of information is needed.
  12139. */
  12140. class JUCE_API Justification
  12141. {
  12142. public:
  12143. /** Creates a Justification object using a combination of flags. */
  12144. inline Justification (const int flags_) throw() : flags (flags_) {}
  12145. /** Creates a copy of another Justification object. */
  12146. Justification (const Justification& other) throw();
  12147. /** Copies another Justification object. */
  12148. const Justification& operator= (const Justification& other) throw();
  12149. /** Returns the raw flags that are set for this Justification object. */
  12150. inline int getFlags() const throw() { return flags; }
  12151. /** Tests a set of flags for this object.
  12152. @returns true if any of the flags passed in are set on this object.
  12153. */
  12154. inline bool testFlags (const int flagsToTest) const throw() { return (flags & flagsToTest) != 0; }
  12155. /** Returns just the flags from this object that deal with vertical layout. */
  12156. int getOnlyVerticalFlags() const throw();
  12157. /** Returns just the flags from this object that deal with horizontal layout. */
  12158. int getOnlyHorizontalFlags() const throw();
  12159. /** Adjusts the position of a rectangle to fit it into a space.
  12160. The (x, y) position of the rectangle will be updated to position it inside the
  12161. given space according to the justification flags.
  12162. */
  12163. void applyToRectangle (int& x, int& y,
  12164. const int w, const int h,
  12165. const int spaceX, const int spaceY,
  12166. const int spaceW, const int spaceH) const throw();
  12167. /** Flag values that can be combined and used in the constructor. */
  12168. enum
  12169. {
  12170. /** Indicates that the item should be aligned against the left edge of the available space. */
  12171. left = 1,
  12172. /** Indicates that the item should be aligned against the right edge of the available space. */
  12173. right = 2,
  12174. /** Indicates that the item should be placed in the centre between the left and right
  12175. sides of the available space. */
  12176. horizontallyCentred = 4,
  12177. /** Indicates that the item should be aligned against the top edge of the available space. */
  12178. top = 8,
  12179. /** Indicates that the item should be aligned against the bottom edge of the available space. */
  12180. bottom = 16,
  12181. /** Indicates that the item should be placed in the centre between the top and bottom
  12182. sides of the available space. */
  12183. verticallyCentred = 32,
  12184. /** Indicates that lines of text should be spread out to fill the maximum width
  12185. available, so that both margins are aligned vertically.
  12186. */
  12187. horizontallyJustified = 64,
  12188. /** Indicates that the item should be centred vertically and horizontally.
  12189. This is equivalent to (horizontallyCentred | verticallyCentred)
  12190. */
  12191. centred = 36,
  12192. /** Indicates that the item should be centred vertically but placed on the left hand side.
  12193. This is equivalent to (left | verticallyCentred)
  12194. */
  12195. centredLeft = 33,
  12196. /** Indicates that the item should be centred vertically but placed on the right hand side.
  12197. This is equivalent to (right | verticallyCentred)
  12198. */
  12199. centredRight = 34,
  12200. /** Indicates that the item should be centred horizontally and placed at the top.
  12201. This is equivalent to (horizontallyCentred | top)
  12202. */
  12203. centredTop = 12,
  12204. /** Indicates that the item should be centred horizontally and placed at the bottom.
  12205. This is equivalent to (horizontallyCentred | bottom)
  12206. */
  12207. centredBottom = 20,
  12208. /** Indicates that the item should be placed in the top-left corner.
  12209. This is equivalent to (left | top)
  12210. */
  12211. topLeft = 9,
  12212. /** Indicates that the item should be placed in the top-right corner.
  12213. This is equivalent to (right | top)
  12214. */
  12215. topRight = 10,
  12216. /** Indicates that the item should be placed in the bottom-left corner.
  12217. This is equivalent to (left | bottom)
  12218. */
  12219. bottomLeft = 17,
  12220. /** Indicates that the item should be placed in the bottom-left corner.
  12221. This is equivalent to (right | bottom)
  12222. */
  12223. bottomRight = 18
  12224. };
  12225. private:
  12226. int flags;
  12227. };
  12228. #endif // __JUCE_JUSTIFICATION_JUCEHEADER__
  12229. /********* End of inlined file: juce_Justification.h *********/
  12230. /**
  12231. A path is a sequence of lines and curves that may either form a closed shape
  12232. or be open-ended.
  12233. To use a path, you can create an empty one, then add lines and curves to it
  12234. to create shapes, then it can be rendered by a Graphics context or used
  12235. for geometric operations.
  12236. e.g. @code
  12237. Path myPath;
  12238. myPath.startNewSubPath (10.0f, 10.0f); // move the current position to (10, 10)
  12239. myPath.lineTo (100.0f, 200.0f); // draw a line from here to (100, 200)
  12240. myPath.quadraticTo (0.0f, 150.0f, 5.0f, 50.0f); // draw a curve that ends at (5, 50)
  12241. myPath.closeSubPath(); // close the subpath with a line back to (10, 10)
  12242. // add an ellipse as well, which will form a second sub-path within the path..
  12243. myPath.addEllipse (50.0f, 50.0f, 40.0f, 30.0f);
  12244. // double the width of the whole thing..
  12245. myPath.applyTransform (AffineTransform::scale (2.0f, 1.0f));
  12246. // and draw it to a graphics context with a 5-pixel thick outline.
  12247. g.strokePath (myPath, PathStrokeType (5.0f));
  12248. @endcode
  12249. A path object can actually contain multiple sub-paths, which may themselves
  12250. be open or closed.
  12251. @see PathFlatteningIterator, PathStrokeType, Graphics
  12252. */
  12253. class JUCE_API Path : private ArrayAllocationBase <float>
  12254. {
  12255. public:
  12256. /** Creates an empty path. */
  12257. Path() throw();
  12258. /** Creates a copy of another path. */
  12259. Path (const Path& other) throw();
  12260. /** Destructor. */
  12261. ~Path() throw();
  12262. /** Copies this path from another one. */
  12263. const Path& operator= (const Path& other) throw();
  12264. /** Returns true if the path doesn't contain any lines or curves. */
  12265. bool isEmpty() const throw();
  12266. /** Returns the smallest rectangle that contains all points within the path.
  12267. */
  12268. void getBounds (float& x, float& y,
  12269. float& w, float& h) const throw();
  12270. /** Returns the smallest rectangle that contains all points within the path
  12271. after it's been transformed with the given tranasform matrix.
  12272. */
  12273. void getBoundsTransformed (const AffineTransform& transform,
  12274. float& x, float& y,
  12275. float& w, float& h) const throw();
  12276. /** Checks whether a point lies within the path.
  12277. This is only relevent for closed paths (see closeSubPath()), and
  12278. may produce false results if used on a path which has open sub-paths.
  12279. The path's winding rule is taken into account by this method.
  12280. @see closeSubPath, setUsingNonZeroWinding
  12281. */
  12282. bool contains (const float x,
  12283. const float y) const throw();
  12284. /** Checks whether a line crosses the path.
  12285. This will return positive if the line crosses any of the paths constituent
  12286. lines or curves. It doesn't take into account whether the line is inside
  12287. or outside the path, or whether the path is open or closed.
  12288. */
  12289. bool intersectsLine (const float x1, const float y1,
  12290. const float x2, const float y2) throw();
  12291. /** Removes all lines and curves, resetting the path completely. */
  12292. void clear() throw();
  12293. /** Begins a new subpath with a given starting position.
  12294. This will move the path's current position to the co-ordinates passed in and
  12295. make it ready to draw lines or curves starting from this position.
  12296. After adding whatever lines and curves are needed, you can either
  12297. close the current sub-path using closeSubPath() or call startNewSubPath()
  12298. to move to a new sub-path, leaving the old one open-ended.
  12299. @see lineTo, quadraticTo, cubicTo, closeSubPath
  12300. */
  12301. void startNewSubPath (const float startX,
  12302. const float startY) throw();
  12303. /** Closes a the current sub-path with a line back to its start-point.
  12304. When creating a closed shape such as a triangle, don't use 3 lineTo()
  12305. calls - instead use two lineTo() calls, followed by a closeSubPath()
  12306. to join the final point back to the start.
  12307. This ensures that closes shapes are recognised as such, and this is
  12308. important for tasks like drawing strokes, which needs to know whether to
  12309. draw end-caps or not.
  12310. @see startNewSubPath, lineTo, quadraticTo, cubicTo, closeSubPath
  12311. */
  12312. void closeSubPath() throw();
  12313. /** Adds a line from the shape's last position to a new end-point.
  12314. This will connect the end-point of the last line or curve that was added
  12315. to a new point, using a straight line.
  12316. See the class description for an example of how to add lines and curves to a path.
  12317. @see startNewSubPath, quadraticTo, cubicTo, closeSubPath
  12318. */
  12319. void lineTo (const float endX,
  12320. const float endY) throw();
  12321. /** Adds a quadratic bezier curve from the shape's last position to a new position.
  12322. This will connect the end-point of the last line or curve that was added
  12323. to a new point, using a quadratic spline with one control-point.
  12324. See the class description for an example of how to add lines and curves to a path.
  12325. @see startNewSubPath, lineTo, cubicTo, closeSubPath
  12326. */
  12327. void quadraticTo (const float controlPointX,
  12328. const float controlPointY,
  12329. const float endPointX,
  12330. const float endPointY) throw();
  12331. /** Adds a cubic bezier curve from the shape's last position to a new position.
  12332. This will connect the end-point of the last line or curve that was added
  12333. to a new point, using a cubic spline with two control-points.
  12334. See the class description for an example of how to add lines and curves to a path.
  12335. @see startNewSubPath, lineTo, quadraticTo, closeSubPath
  12336. */
  12337. void cubicTo (const float controlPoint1X,
  12338. const float controlPoint1Y,
  12339. const float controlPoint2X,
  12340. const float controlPoint2Y,
  12341. const float endPointX,
  12342. const float endPointY) throw();
  12343. /** Returns the last point that was added to the path by one of the drawing methods.
  12344. */
  12345. const Point getCurrentPosition() const;
  12346. /** Adds a rectangle to the path.
  12347. The rectangle is added as a new sub-path. (Any currently open paths will be
  12348. left open).
  12349. @see addRoundedRectangle, addTriangle
  12350. */
  12351. void addRectangle (const float x, const float y,
  12352. const float w, const float h) throw();
  12353. /** Adds a rectangle with rounded corners to the path.
  12354. The rectangle is added as a new sub-path. (Any currently open paths will be
  12355. left open).
  12356. @see addRectangle, addTriangle
  12357. */
  12358. void addRoundedRectangle (const float x, const float y,
  12359. const float w, const float h,
  12360. float cornerSize) throw();
  12361. /** Adds a rectangle with rounded corners to the path.
  12362. The rectangle is added as a new sub-path. (Any currently open paths will be
  12363. left open).
  12364. @see addRectangle, addTriangle
  12365. */
  12366. void addRoundedRectangle (const float x, const float y,
  12367. const float w, const float h,
  12368. float cornerSizeX,
  12369. float cornerSizeY) throw();
  12370. /** Adds a triangle to the path.
  12371. The triangle is added as a new closed sub-path. (Any currently open paths will be
  12372. left open).
  12373. Note that whether the vertices are specified in clockwise or anticlockwise
  12374. order will affect how the triangle is filled when it overlaps other
  12375. shapes (the winding order setting will affect this of course).
  12376. */
  12377. void addTriangle (const float x1, const float y1,
  12378. const float x2, const float y2,
  12379. const float x3, const float y3) throw();
  12380. /** Adds a quadrilateral to the path.
  12381. The quad is added as a new closed sub-path. (Any currently open paths will be
  12382. left open).
  12383. Note that whether the vertices are specified in clockwise or anticlockwise
  12384. order will affect how the quad is filled when it overlaps other
  12385. shapes (the winding order setting will affect this of course).
  12386. */
  12387. void addQuadrilateral (const float x1, const float y1,
  12388. const float x2, const float y2,
  12389. const float x3, const float y3,
  12390. const float x4, const float y4) throw();
  12391. /** Adds an ellipse to the path.
  12392. The shape is added as a new sub-path. (Any currently open paths will be
  12393. left open).
  12394. @see addArc
  12395. */
  12396. void addEllipse (const float x, const float y,
  12397. const float width, const float height) throw();
  12398. /** Adds an elliptical arc to the current path.
  12399. Note that when specifying the start and end angles, the curve will be drawn either clockwise
  12400. or anti-clockwise according to whether the end angle is greater than the start. This means
  12401. that sometimes you may need to use values greater than 2*Pi for the end angle.
  12402. @param x the left-hand edge of the rectangle in which the elliptical outline fits
  12403. @param y the top edge of the rectangle in which the elliptical outline fits
  12404. @param width the width of the rectangle in which the elliptical outline fits
  12405. @param height the height of the rectangle in which the elliptical outline fits
  12406. @param fromRadians the angle (clockwise) in radians at which to start the arc segment (where 0 is the
  12407. top-centre of the ellipse)
  12408. @param toRadians the angle (clockwise) in radians at which to end the arc segment (where 0 is the
  12409. top-centre of the ellipse). This angle can be greater than 2*Pi, so for example to
  12410. draw a curve clockwise from the 9 o'clock position to the 3 o'clock position via
  12411. 12 o'clock, you'd use 1.5*Pi and 2.5*Pi as the start and finish points.
  12412. @param startAsNewSubPath if true, the arc will begin a new subpath from its starting point; if false,
  12413. it will be added to the current sub-path, continuing from the current postition
  12414. @see addCentredArc, arcTo, addPieSegment, addEllipse
  12415. */
  12416. void addArc (const float x, const float y,
  12417. const float width, const float height,
  12418. const float fromRadians,
  12419. const float toRadians,
  12420. const bool startAsNewSubPath = false) throw();
  12421. /** Adds an arc which is centred at a given point, and can have a rotation specified.
  12422. Note that when specifying the start and end angles, the curve will be drawn either clockwise
  12423. or anti-clockwise according to whether the end angle is greater than the start. This means
  12424. that sometimes you may need to use values greater than 2*Pi for the end angle.
  12425. @param centreX the centre x of the ellipse
  12426. @param centreY the centre y of the ellipse
  12427. @param radiusX the horizontal radius of the ellipse
  12428. @param radiusY the vertical radius of the ellipse
  12429. @param rotationOfEllipse an angle by which the whole ellipse should be rotated about its centre, in radians (clockwise)
  12430. @param fromRadians the angle (clockwise) in radians at which to start the arc segment (where 0 is the
  12431. top-centre of the ellipse)
  12432. @param toRadians the angle (clockwise) in radians at which to end the arc segment (where 0 is the
  12433. top-centre of the ellipse). This angle can be greater than 2*Pi, so for example to
  12434. draw a curve clockwise from the 9 o'clock position to the 3 o'clock position via
  12435. 12 o'clock, you'd use 1.5*Pi and 2.5*Pi as the start and finish points.
  12436. @param startAsNewSubPath if true, the arc will begin a new subpath from its starting point; if false,
  12437. it will be added to the current sub-path, continuing from the current postition
  12438. @see addArc, arcTo
  12439. */
  12440. void addCentredArc (const float centreX, const float centreY,
  12441. const float radiusX, const float radiusY,
  12442. const float rotationOfEllipse,
  12443. const float fromRadians,
  12444. const float toRadians,
  12445. const bool startAsNewSubPath = false) throw();
  12446. /** Adds a "pie-chart" shape to the path.
  12447. The shape is added as a new sub-path. (Any currently open paths will be
  12448. left open).
  12449. Note that when specifying the start and end angles, the curve will be drawn either clockwise
  12450. or anti-clockwise according to whether the end angle is greater than the start. This means
  12451. that sometimes you may need to use values greater than 2*Pi for the end angle.
  12452. @param x the left-hand edge of the rectangle in which the elliptical outline fits
  12453. @param y the top edge of the rectangle in which the elliptical outline fits
  12454. @param width the width of the rectangle in which the elliptical outline fits
  12455. @param height the height of the rectangle in which the elliptical outline fits
  12456. @param fromRadians the angle (clockwise) in radians at which to start the arc segment (where 0 is the
  12457. top-centre of the ellipse)
  12458. @param toRadians the angle (clockwise) in radians at which to end the arc segment (where 0 is the
  12459. top-centre of the ellipse)
  12460. @param innerCircleProportionalSize if this is > 0, then the pie will be drawn as a curved band around a hollow
  12461. ellipse at its centre, where this value indicates the inner ellipse's size with
  12462. respect to the outer one.
  12463. @see addArc
  12464. */
  12465. void addPieSegment (const float x, const float y,
  12466. const float width, const float height,
  12467. const float fromRadians,
  12468. const float toRadians,
  12469. const float innerCircleProportionalSize);
  12470. /** Adds a line with a specified thickness.
  12471. The line is added as a new closed sub-path. (Any currently open paths will be
  12472. left open).
  12473. @see addArrow
  12474. */
  12475. void addLineSegment (const float startX, const float startY,
  12476. const float endX, const float endY,
  12477. float lineThickness) throw();
  12478. /** Adds a line with an arrowhead on the end.
  12479. The arrow is added as a new closed sub-path. (Any currently open paths will be
  12480. left open).
  12481. */
  12482. void addArrow (const float startX, const float startY,
  12483. const float endX, const float endY,
  12484. float lineThickness,
  12485. float arrowheadWidth,
  12486. float arrowheadLength) throw();
  12487. /** Adds a star shape to the path.
  12488. */
  12489. void addStar (const float centreX,
  12490. const float centreY,
  12491. const int numberOfPoints,
  12492. const float innerRadius,
  12493. const float outerRadius,
  12494. const float startAngle = 0.0f);
  12495. /** Adds a speech-bubble shape to the path.
  12496. @param bodyX the left of the main body area of the bubble
  12497. @param bodyY the top of the main body area of the bubble
  12498. @param bodyW the width of the main body area of the bubble
  12499. @param bodyH the height of the main body area of the bubble
  12500. @param cornerSize the amount by which to round off the corners of the main body rectangle
  12501. @param arrowTipX the x position that the tip of the arrow should connect to
  12502. @param arrowTipY the y position that the tip of the arrow should connect to
  12503. @param whichSide the side to connect the arrow to: 0 = top, 1 = left, 2 = bottom, 3 = right
  12504. @param arrowPositionAlongEdgeProportional how far along the edge of the main rectangle the
  12505. arrow's base should be - this is a proportional distance between 0 and 1.0
  12506. @param arrowWidth how wide the base of the arrow should be where it joins the main rectangle
  12507. */
  12508. void addBubble (float bodyX, float bodyY,
  12509. float bodyW, float bodyH,
  12510. float cornerSize,
  12511. float arrowTipX,
  12512. float arrowTipY,
  12513. int whichSide,
  12514. float arrowPositionAlongEdgeProportional,
  12515. float arrowWidth);
  12516. /** Adds another path to this one.
  12517. The new path is added as a new sub-path. (Any currently open paths in this
  12518. path will be left open).
  12519. @param pathToAppend the path to add
  12520. */
  12521. void addPath (const Path& pathToAppend) throw();
  12522. /** Adds another path to this one, transforming it on the way in.
  12523. The new path is added as a new sub-path, its points being transformed by the given
  12524. matrix before being added.
  12525. @param pathToAppend the path to add
  12526. @param transformToApply an optional transform to apply to the incoming vertices
  12527. */
  12528. void addPath (const Path& pathToAppend,
  12529. const AffineTransform& transformToApply) throw();
  12530. /** Swaps the contents of this path with another one.
  12531. The internal data of the two paths is swapped over, so this is much faster than
  12532. copying it to a temp variable and back.
  12533. */
  12534. void swapWithPath (Path& other);
  12535. /** Applies a 2D transform to all the vertices in the path.
  12536. @see AffineTransform, scaleToFit, getTransformToScaleToFit
  12537. */
  12538. void applyTransform (const AffineTransform& transform) throw();
  12539. /** Rescales this path to make it fit neatly into a given space.
  12540. This is effectively a quick way of calling
  12541. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions))
  12542. @param x the x position of the rectangle to fit the path inside
  12543. @param y the y position of the rectangle to fit the path inside
  12544. @param width the width of the rectangle to fit the path inside
  12545. @param height the height of the rectangle to fit the path inside
  12546. @param preserveProportions if true, it will fit the path into the space without altering its
  12547. horizontal/vertical scale ratio; if false, it will distort the
  12548. path to fill the specified ratio both horizontally and vertically
  12549. @see applyTransform, getTransformToScaleToFit
  12550. */
  12551. void scaleToFit (const float x, const float y,
  12552. const float width, const float height,
  12553. const bool preserveProportions) throw();
  12554. /** Returns a transform that can be used to rescale the path to fit into a given space.
  12555. @param x the x position of the rectangle to fit the path inside
  12556. @param y the y position of the rectangle to fit the path inside
  12557. @param width the width of the rectangle to fit the path inside
  12558. @param height the height of the rectangle to fit the path inside
  12559. @param preserveProportions if true, it will fit the path into the space without altering its
  12560. horizontal/vertical scale ratio; if false, it will distort the
  12561. path to fill the specified ratio both horizontally and vertically
  12562. @param justificationType if the proportions are preseved, the resultant path may be smaller
  12563. than the available rectangle, so this describes how it should be
  12564. positioned within the space.
  12565. @returns an appropriate transformation
  12566. @see applyTransform, scaleToFit
  12567. */
  12568. const AffineTransform getTransformToScaleToFit (const float x, const float y,
  12569. const float width, const float height,
  12570. const bool preserveProportions,
  12571. const Justification& justificationType = Justification::centred) const throw();
  12572. /** Creates a version of this path where all sharp corners have been replaced by curves.
  12573. Wherever two lines meet at an angle, this will replace the corner with a curve
  12574. of the given radius.
  12575. */
  12576. const Path createPathWithRoundedCorners (const float cornerRadius) const throw();
  12577. /** Changes the winding-rule to be used when filling the path.
  12578. If set to true (which is the default), then the path uses a non-zero-winding rule
  12579. to determine which points are inside the path. If set to false, it uses an
  12580. alternate-winding rule.
  12581. The winding-rule comes into play when areas of the shape overlap other
  12582. areas, and determines whether the overlapping regions are considered to be
  12583. inside or outside.
  12584. Changing this value just sets a flag - it doesn't affect the contents of the
  12585. path.
  12586. @see isUsingNonZeroWinding
  12587. */
  12588. void setUsingNonZeroWinding (const bool isNonZeroWinding) throw();
  12589. /** Returns the flag that indicates whether the path should use a non-zero winding rule.
  12590. The default for a new path is true.
  12591. @see setUsingNonZeroWinding
  12592. */
  12593. bool isUsingNonZeroWinding() const throw() { return useNonZeroWinding; }
  12594. /** Iterates the lines and curves that a path contains.
  12595. @see Path, PathFlatteningIterator
  12596. */
  12597. class JUCE_API Iterator
  12598. {
  12599. public:
  12600. Iterator (const Path& path);
  12601. ~Iterator();
  12602. /** Moves onto the next element in the path.
  12603. If this returns false, there are no more elements. If it returns true,
  12604. the elementType variable will be set to the type of the current element,
  12605. and some of the x and y variables will be filled in with values.
  12606. */
  12607. bool next();
  12608. enum PathElementType
  12609. {
  12610. startNewSubPath, /**< For this type, x1 and y1 will be set to indicate the first point in the subpath. */
  12611. lineTo, /**< For this type, x1 and y1 indicate the end point of the line. */
  12612. quadraticTo, /**< For this type, x1, y1, x2, y2 indicate the control point and endpoint of a quadratic curve. */
  12613. cubicTo, /**< For this type, x1, y1, x2, y2, x3, y3 indicate the two control points and the endpoint of a cubic curve. */
  12614. closePath /**< Indicates that the sub-path is being closed. None of the x or y values are valid in this case. */
  12615. };
  12616. PathElementType elementType;
  12617. float x1, y1, x2, y2, x3, y3;
  12618. private:
  12619. const Path& path;
  12620. int index;
  12621. Iterator (const Iterator&);
  12622. const Iterator& operator= (const Iterator&);
  12623. };
  12624. /** Loads a stored path from a data stream.
  12625. The data in the stream must have been written using writePathToStream().
  12626. Note that this will append the stored path to whatever is currently in
  12627. this path, so you might need to call clear() beforehand.
  12628. @see loadPathFromData, writePathToStream
  12629. */
  12630. void loadPathFromStream (InputStream& source);
  12631. /** Loads a stored path from a block of data.
  12632. This is similar to loadPathFromStream(), but just reads from a block
  12633. of data. Useful if you're including stored shapes in your code as a
  12634. block of static data.
  12635. @see loadPathFromStream, writePathToStream
  12636. */
  12637. void loadPathFromData (const unsigned char* const data,
  12638. const int numberOfBytes) throw();
  12639. /** Stores the path by writing it out to a stream.
  12640. After writing out a path, you can reload it using loadPathFromStream().
  12641. @see loadPathFromStream, loadPathFromData
  12642. */
  12643. void writePathToStream (OutputStream& destination) const;
  12644. /** Creates a string containing a textual representation of this path.
  12645. @see restoreFromString
  12646. */
  12647. const String toString() const;
  12648. /** Restores this path from a string that was created with the toString() method.
  12649. @see toString()
  12650. */
  12651. void restoreFromString (const String& stringVersion);
  12652. juce_UseDebuggingNewOperator
  12653. private:
  12654. friend class PathFlatteningIterator;
  12655. friend class Path::Iterator;
  12656. int numElements;
  12657. float pathXMin, pathXMax, pathYMin, pathYMax;
  12658. bool useNonZeroWinding;
  12659. static const float lineMarker;
  12660. static const float moveMarker;
  12661. static const float quadMarker;
  12662. static const float cubicMarker;
  12663. static const float closeSubPathMarker;
  12664. };
  12665. #endif // __JUCE_PATH_JUCEHEADER__
  12666. /********* End of inlined file: juce_Path.h *********/
  12667. class Font;
  12668. class Typeface;
  12669. /**
  12670. Stores information about the shape and kerning of one of the glyphs in a Typeface.
  12671. @see Typeface, PositionedGlyph, GlyphArrangement
  12672. */
  12673. class JUCE_API TypefaceGlyphInfo
  12674. {
  12675. public:
  12676. /** Returns the path that describes the glyph's outline.
  12677. This is normalised to a height of 1.0, and its origin is the
  12678. left-hand edge of the glyph's baseline.
  12679. */
  12680. const Path& getPath() const throw() { return path; }
  12681. /** Returns the unicode character that this glyph represents. */
  12682. juce_wchar getCharacter() const throw() { return character; }
  12683. bool isWhitespace() const throw() { return CharacterFunctions::isWhitespace (character); }
  12684. /** Returns the distance to leave between this and a following character.
  12685. The value returned is expressed as a proportion of the font's height.
  12686. */
  12687. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw();
  12688. /** Returns the typeface that this glyph belongs to. */
  12689. Typeface* getTypeface() const throw() { return typeface; }
  12690. private:
  12691. friend class Typeface;
  12692. struct KerningPair
  12693. {
  12694. juce_wchar character2;
  12695. float kerningAmount;
  12696. };
  12697. const juce_wchar character;
  12698. const Path path;
  12699. float width;
  12700. MemoryBlock kerningPairs;
  12701. Typeface* const typeface;
  12702. TypefaceGlyphInfo (const juce_wchar character,
  12703. const Path& shape,
  12704. const float horizontalSeparation,
  12705. Typeface* const typeface) throw();
  12706. ~TypefaceGlyphInfo() throw();
  12707. KerningPair& getKerningPair (const int index) const throw();
  12708. int getNumKerningPairs() const throw();
  12709. void addKerningPair (const juce_wchar subsequentCharacter,
  12710. const float extraKerningAmount) throw();
  12711. const TypefaceGlyphInfo& operator= (const TypefaceGlyphInfo&);
  12712. };
  12713. /**
  12714. Represents a size-independent system font.
  12715. A Font object represents a particular Typeface along with a specific size,
  12716. style, kerning, scale, etc, wheras the Typeface is just a generalised description
  12717. of the shapes of the glyphs and their properties.
  12718. */
  12719. class JUCE_API Typeface : public ReferenceCountedObject
  12720. {
  12721. public:
  12722. /** Tries to load a named system font and to initialise all the glyphs
  12723. appropriately from it.
  12724. @param faceName the name of the typeface, e.g. "Times"
  12725. @param bold whether to try to find a bold version of the font (may not always be available)
  12726. @param italic whether to try to find an italicised version of the font (may not always be available)
  12727. */
  12728. Typeface (const String& faceName,
  12729. const bool bold,
  12730. const bool italic);
  12731. /** Creates a copy of another typeface */
  12732. Typeface (const Typeface& other);
  12733. /** Destructor. */
  12734. ~Typeface();
  12735. /** Copies another typeface over this one. */
  12736. const Typeface& operator= (const Typeface& other) throw();
  12737. /** Returns a unique ID for the typeface.
  12738. This is based on the name and style, so can be used to compare two Typeface objects.
  12739. */
  12740. int hashCode() const throw() { return hash; }
  12741. /** Returns the name of the typeface, e.g. "Times", "Verdana", etc */
  12742. const String& getName() const throw() { return typefaceName; }
  12743. /** Returns the font's ascent as a proportion of its height. */
  12744. float getAscent() const throw() { return ascent; }
  12745. /** Returns true if the font is flagged as being bold. */
  12746. bool isBold() const throw() { return bold; }
  12747. /** Returns true if the typeface's 'italic' flag is set. */
  12748. bool isItalic() const throw() { return italic; }
  12749. /** Finds the Path that describes the outline shape of a character.
  12750. The height of the path is normalised to 1.0 (i.e. a distance of 1.0 is the
  12751. height of the font).
  12752. This may return 0 if the typeface has no characters, but if the character
  12753. that is asked for is not found, it will first try to return a default
  12754. character instead.
  12755. */
  12756. const Path* getOutlineForGlyph (const juce_wchar character) throw();
  12757. /** Tries to find the information describing a glyph for this character.
  12758. If there isn't a glyph specifically for the character it will return
  12759. a default glyph instead; if the typeface is empty, it may return a null
  12760. pointer.
  12761. */
  12762. const TypefaceGlyphInfo* getGlyph (const juce_wchar character) throw();
  12763. /** Deletes all the glyphs and kerning data fom the typeface. */
  12764. void clear() throw();
  12765. /** Adds a glyph to the typeface.
  12766. This is typically only called by the platform-specific code that generates
  12767. the typeface from a system font.
  12768. */
  12769. void addGlyph (const juce_wchar character,
  12770. const Path& path,
  12771. const float horizontalSpacing) throw();
  12772. /** Adds a kerning distance to the typeface.
  12773. The extra amount passed in is expressed as a proportion of the font's
  12774. height, normalised to 1.0.
  12775. This is typically only called by the platform-specific code that generates
  12776. the typeface from a system font.
  12777. */
  12778. void addKerningPair (const juce_wchar firstChar,
  12779. const juce_wchar secondChar,
  12780. const float extraAmount) throw();
  12781. /** Sets the typeface's name.
  12782. This is typically only called by the platform-specific code that generates
  12783. the typeface from a system font. Calling this method won't actually affect
  12784. the underlying font being used.
  12785. */
  12786. void setName (const String& name) throw();
  12787. /** Sets the font's ascent value, as a proportion of the font height.
  12788. This is typically only called by the platform-specific code that generates
  12789. the typeface from a system font.
  12790. */
  12791. void setAscent (const float newAscent) throw();
  12792. /** Sets the typeface's 'bold' flag.
  12793. This is typically only called by the platform-specific code that generates
  12794. the typeface from a system font.
  12795. */
  12796. void setBold (const bool shouldBeBold) throw();
  12797. /** Sets the typeface's 'italic' flag.
  12798. This is typically only called by the platform-specific code that generates
  12799. the typeface from a system font.
  12800. */
  12801. void setItalic (const bool shouldBeItalic) throw();
  12802. /** Changes the character index to use as the default character.
  12803. This is the character that gets returned for characters which don't have a
  12804. glyph set for them.
  12805. */
  12806. void setDefaultCharacter (const juce_wchar newDefaultCharacter) throw();
  12807. /** Creates a typeface from data created using Typeface::serialise().
  12808. This will attempt to load a compressed typeface that was created using
  12809. the Typeface::serialise() method. This is handy if you want to store
  12810. a typeface in your application as a binary blob, and use it without
  12811. having to actually install it on the computer.
  12812. @see Typeface::serialise()
  12813. */
  12814. Typeface (InputStream& serialisedTypefaceStream);
  12815. /** Writes the typeface to a stream (using a proprietary format).
  12816. This lets you save a typeface and reload it using the
  12817. Typeface::Typeface (InputStream&) constructor. The data's saved in
  12818. a compressed format.
  12819. @see Typeface::Typeface (InputStream&)
  12820. */
  12821. void serialise (OutputStream& outputStream);
  12822. /** A handy typedef to make it easy to use ref counted pointers to this class. */
  12823. typedef ReferenceCountedObjectPtr <Typeface> Ptr;
  12824. juce_UseDebuggingNewOperator
  12825. private:
  12826. VoidArray glyphs;
  12827. short lookupTable [128];
  12828. String typefaceName;
  12829. int hash;
  12830. float ascent; // as a proportion of the height
  12831. bool bold, italic, isFullyPopulated;
  12832. juce_wchar defaultCharacter; // the char to use if a matching glyph can't be found.
  12833. Typeface() throw();
  12834. void addGlyphCopy (const TypefaceGlyphInfo* const glyphInfoToCopy) throw();
  12835. friend class Font;
  12836. friend class TypefaceCache;
  12837. friend class FontGlyphAlphaMap;
  12838. static const Ptr getTypefaceFor (const Font& font) throw();
  12839. // this is a platform-dependent method that will look for the given typeface
  12840. // and set up its kerning tables, etc. accordingly.
  12841. // If addAllGlyphsToFont is true, it should also add all the glyphs in the font
  12842. // to the typeface immediately, rather than having to add them later on-demand.
  12843. void initialiseTypefaceCharacteristics (const String& fontName,
  12844. bool bold, bool italic,
  12845. bool addAllGlyphsToFont) throw();
  12846. // platform-specific routine to look up and add a glyph to this typeface
  12847. bool findAndAddSystemGlyph (juce_wchar character) throw();
  12848. void updateHashCode() throw();
  12849. };
  12850. #endif // __JUCE_TYPEFACE_JUCEHEADER__
  12851. /********* End of inlined file: juce_Typeface.h *********/
  12852. /**
  12853. Represents a particular font, including its size, style, etc.
  12854. Apart from the typeface to be used, a Font object also dictates whether
  12855. the font is bold, italic, underlined, how big it is, and its kerning and
  12856. horizontal scale factor.
  12857. @see Typeface
  12858. */
  12859. class JUCE_API Font
  12860. {
  12861. public:
  12862. /** A combination of these values is used by the constructor to specify the
  12863. style of font to use.
  12864. */
  12865. enum FontStyleFlags
  12866. {
  12867. plain = 0, /**< indicates a plain, non-bold, non-italic version of the font. @see setStyleFlags */
  12868. bold = 1, /**< boldens the font. @see setStyleFlags */
  12869. italic = 2, /**< finds an italic version of the font. @see setStyleFlags */
  12870. underlined = 4 /**< underlines the font. @see setStyleFlags */
  12871. };
  12872. /** Creates a sans-serif font in a given size.
  12873. @param fontHeight the height in pixels (can be fractional)
  12874. @param styleFlags the style to use - this can be a combination of the
  12875. Font::bold, Font::italic and Font::underlined, or
  12876. just Font::plain for the normal style.
  12877. @see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName
  12878. */
  12879. Font (const float fontHeight,
  12880. const int styleFlags = plain) throw();
  12881. /** Creates a font with a given typeface and parameters.
  12882. @param typefaceName the name of the typeface to use
  12883. @param fontHeight the height in pixels (can be fractional)
  12884. @param styleFlags the style to use - this can be a combination of the
  12885. Font::bold, Font::italic and Font::underlined, or
  12886. just Font::plain for the normal style.
  12887. @see FontStyleFlags, getDefaultSansSerifFontName, setDefaultSansSerifFontName
  12888. */
  12889. Font (const String& typefaceName,
  12890. const float fontHeight,
  12891. const int styleFlags) throw();
  12892. /** Creates a copy of another Font object. */
  12893. Font (const Font& other) throw();
  12894. /** Creates a font based on a typeface.
  12895. The font object stores its own internal copy of the typeface, so you can safely
  12896. delete the one passed in after calling this.
  12897. */
  12898. Font (const Typeface& typeface) throw();
  12899. /** Creates a basic sans-serif font at a default height.
  12900. You should use one of the other constructors for creating a font that you're planning
  12901. on drawing with - this constructor is here to help initialise objects before changing
  12902. the font's settings later.
  12903. */
  12904. Font() throw();
  12905. /** Copies this font from another one. */
  12906. const Font& operator= (const Font& other) throw();
  12907. bool operator== (const Font& other) const throw();
  12908. bool operator!= (const Font& other) const throw();
  12909. /** Destructor. */
  12910. ~Font() throw();
  12911. /** Changes the name of the typeface family.
  12912. e.g. "Arial", "Courier", etc.
  12913. If a suitable font isn't found on the machine, it'll just use a default instead.
  12914. */
  12915. void setTypefaceName (const String& faceName) throw();
  12916. /** Returns the name of the typeface family that this font uses.
  12917. e.g. "Arial", "Courier", etc.
  12918. */
  12919. const String& getTypefaceName() const throw() { return typefaceName; }
  12920. /** Returns a platform-specific font family that is recommended for sans-serif fonts.
  12921. This is the typeface that will be used when a font is created without
  12922. specifying another name.
  12923. @see setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName,
  12924. setDefaultSansSerifFontName
  12925. */
  12926. static const String getDefaultSansSerifFontName() throw();
  12927. /** Returns a platform-specific font family that is recommended for serif fonts.
  12928. @see setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName
  12929. */
  12930. static const String getDefaultSerifFontName() throw();
  12931. /** Returns a platform-specific font family that is recommended for monospaced fonts.
  12932. @see setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName
  12933. */
  12934. static const String getDefaultMonospacedFontName() throw();
  12935. /** Changes the default sans-serif typeface family name.
  12936. This changes the value that is returned by getDefaultSansSerifFontName(), so
  12937. changing this will change the default system font used.
  12938. @see getDefaultSansSerifFontName
  12939. */
  12940. static void setDefaultSansSerifFontName (const String& name) throw();
  12941. /** Returns the total height of this font.
  12942. This is the maximum height, from the top of the ascent to the bottom of the
  12943. descenders.
  12944. @see setHeight, setHeightWithoutChangingWidth, getAscent
  12945. */
  12946. float getHeight() const throw() { return height; }
  12947. /** Changes the font's height.
  12948. @see getHeight, setHeightWithoutChangingWidth
  12949. */
  12950. void setHeight (float newHeight) throw();
  12951. /** Changes the font's height without changing its width.
  12952. This alters the horizontal scale to compensate for the change in height.
  12953. */
  12954. void setHeightWithoutChangingWidth (float newHeight) throw();
  12955. /** Returns the height of the font above its baseline.
  12956. This is the maximum height from the baseline to the top.
  12957. @see getHeight, getDescent
  12958. */
  12959. float getAscent() const throw();
  12960. /** Returns the amount that the font descends below its baseline.
  12961. This is calculated as (getHeight() - getAscent()).
  12962. @see getAscent, getHeight
  12963. */
  12964. float getDescent() const throw();
  12965. /** Returns the font's style flags.
  12966. This will return a bitwise-or'ed combination of values from the FontStyleFlags
  12967. enum, to describe whether the font is bold, italic, etc.
  12968. @see FontStyleFlags
  12969. */
  12970. int getStyleFlags() const throw() { return styleFlags; }
  12971. /** Changes the font's style.
  12972. @param newFlags a bitwise-or'ed combination of values from the FontStyleFlags
  12973. enum, to set the font's properties
  12974. @see FontStyleFlags
  12975. */
  12976. void setStyleFlags (const int newFlags) throw();
  12977. /** Makes the font bold or non-bold. */
  12978. void setBold (const bool shouldBeBold) throw();
  12979. /** Returns true if the font is bold. */
  12980. bool isBold() const throw();
  12981. /** Makes the font italic or non-italic. */
  12982. void setItalic (const bool shouldBeItalic) throw();
  12983. /** Returns true if the font is italic. */
  12984. bool isItalic() const throw();
  12985. /** Makes the font underlined or non-underlined. */
  12986. void setUnderline (const bool shouldBeUnderlined) throw();
  12987. /** Returns true if the font is underlined. */
  12988. bool isUnderlined() const throw();
  12989. /** Changes the font's horizontal scale factor.
  12990. @param scaleFactor a value of 1.0 is the normal scale, less than this will be
  12991. narrower, greater than 1.0 will be stretched out.
  12992. */
  12993. void setHorizontalScale (const float scaleFactor) throw();
  12994. /** Returns the font's horizontal scale.
  12995. A value of 1.0 is the normal scale, less than this will be narrower, greater
  12996. than 1.0 will be stretched out.
  12997. @see setHorizontalScale
  12998. */
  12999. float getHorizontalScale() const throw() { return horizontalScale; }
  13000. /** Changes the font's kerning.
  13001. @param extraKerning a multiple of the font's height that will be added
  13002. to space between the characters. So a value of zero is
  13003. normal spacing, positive values spread the letters out,
  13004. negative values make them closer together.
  13005. */
  13006. void setExtraKerningFactor (const float extraKerning) throw();
  13007. /** Returns the font's kerning.
  13008. This is the extra space added between adjacent characters, as a proportion
  13009. of the font's height.
  13010. A value of zero is normal spacing, positive values will spread the letters
  13011. out more, and negative values make them closer together.
  13012. */
  13013. float getExtraKerningFactor() const throw() { return kerning; }
  13014. /** Changes all the font's characteristics with one call. */
  13015. void setSizeAndStyle (const float newHeight,
  13016. const int newStyleFlags,
  13017. const float newHorizontalScale,
  13018. const float newKerningAmount) throw();
  13019. /** Resets this font's characteristics.
  13020. This is basically like saying "myFont = Font();", because it resets the
  13021. typeface, size, style, etc to a default state. Not very useful to most
  13022. people, its raison d'etre is to help the Graphics class be more efficient.
  13023. */
  13024. void resetToDefaultState() throw();
  13025. /** Returns the total width of a string as it would be drawn using this font.
  13026. For a more accurate floating-point result, use getStringWidthFloat().
  13027. */
  13028. int getStringWidth (const String& text) const throw();
  13029. /** Returns the total width of a string as it would be drawn using this font.
  13030. @see getStringWidth
  13031. */
  13032. float getStringWidthFloat (const String& text) const throw();
  13033. /** Returns the typeface used by this font.
  13034. Note that the object returned may go out of scope if this font is deleted
  13035. or has its style changed.
  13036. */
  13037. Typeface* getTypeface() const throw();
  13038. /** Creates an array of Font objects to represent all the fonts on the system.
  13039. If you just need the names of the typefaces, you can also use
  13040. findAllTypefaceNames() instead.
  13041. @param results the array to which new Font objects will be added.
  13042. */
  13043. static void findFonts (OwnedArray<Font>& results) throw();
  13044. /** Returns a list of all the available typeface names.
  13045. The names returned can be passed into setTypefaceName().
  13046. You can use this instead of findFonts() if you only need their names, and not
  13047. font objects.
  13048. */
  13049. static const StringArray findAllTypefaceNames() throw();
  13050. /** Returns the name of the typeface to be used for rendering glyphs that aren't found
  13051. in the requested typeface.
  13052. */
  13053. static const String getFallbackFontName() throw();
  13054. /** Sets the (platform-specific) name of the typeface to use to find glyphs that aren't
  13055. available in whatever font you're trying to use.
  13056. */
  13057. static void setFallbackFontName (const String& name) throw();
  13058. juce_UseDebuggingNewOperator
  13059. private:
  13060. friend class FontGlyphAlphaMap;
  13061. friend class TypefaceCache;
  13062. String typefaceName;
  13063. float height, horizontalScale, kerning;
  13064. mutable float ascent;
  13065. int styleFlags;
  13066. mutable Typeface::Ptr typeface;
  13067. // platform-specific calls
  13068. static void getDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw();
  13069. friend void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI();
  13070. static void initialiseDefaultFontNames() throw();
  13071. };
  13072. #endif // __JUCE_FONT_JUCEHEADER__
  13073. /********* End of inlined file: juce_Font.h *********/
  13074. /********* Start of inlined file: juce_Rectangle.h *********/
  13075. #ifndef __JUCE_RECTANGLE_JUCEHEADER__
  13076. #define __JUCE_RECTANGLE_JUCEHEADER__
  13077. /**
  13078. A rectangle, specified using integer co-ordinates.
  13079. @see RectangleList, Path, Line, Point
  13080. */
  13081. class JUCE_API Rectangle
  13082. {
  13083. public:
  13084. /** Creates a rectangle of zero size.
  13085. The default co-ordinates will be (0, 0, 0, 0).
  13086. */
  13087. Rectangle() throw();
  13088. /** Creates a copy of another rectangle. */
  13089. Rectangle (const Rectangle& other) throw();
  13090. /** Creates a rectangle with a given position and size. */
  13091. Rectangle (const int x, const int y,
  13092. const int width, const int height) throw();
  13093. /** Creates a rectangle with a given size, and a position of (0, 0). */
  13094. Rectangle (const int width, const int height) throw();
  13095. /** Destructor. */
  13096. ~Rectangle() throw();
  13097. /** Returns the x co-ordinate of the rectangle's left-hand-side. */
  13098. inline int getX() const throw() { return x; }
  13099. /** Returns the y co-ordinate of the rectangle's top edge. */
  13100. inline int getY() const throw() { return y; }
  13101. /** Returns the width of the rectangle. */
  13102. inline int getWidth() const throw() { return w; }
  13103. /** Returns the height of the rectangle. */
  13104. inline int getHeight() const throw() { return h; }
  13105. /** Returns the x co-ordinate of the rectangle's right-hand-side. */
  13106. inline int getRight() const throw() { return x + w; }
  13107. /** Returns the y co-ordinate of the rectangle's bottom edge. */
  13108. inline int getBottom() const throw() { return y + h; }
  13109. /** Returns the x co-ordinate of the rectangle's centre. */
  13110. inline int getCentreX() const throw() { return x + (w >> 1); }
  13111. /** Returns the y co-ordinate of the rectangle's centre. */
  13112. inline int getCentreY() const throw() { return y + (h >> 1); }
  13113. /** Returns true if the rectangle's width and height are both zero or less */
  13114. bool isEmpty() const throw();
  13115. /** Changes the position of the rectangle's top-left corner (leaving its size unchanged). */
  13116. void setPosition (const int x, const int y) throw();
  13117. /** Changes the rectangle's size, leaving the position of its top-left corner unchanged. */
  13118. void setSize (const int w, const int h) throw();
  13119. /** Changes all the rectangle's co-ordinates. */
  13120. void setBounds (const int newX, const int newY,
  13121. const int newWidth, const int newHeight) throw();
  13122. /** Moves the rectangle's position by adding amount to its x and y co-ordinates. */
  13123. void translate (const int deltaX,
  13124. const int deltaY) throw();
  13125. /** Returns a rectangle which is the same as this one moved by a given amount. */
  13126. const Rectangle translated (const int deltaX,
  13127. const int deltaY) const throw();
  13128. /** Expands the rectangle by a given amount.
  13129. Effectively, its new size is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2).
  13130. @see expanded, reduce, reduced
  13131. */
  13132. void expand (const int deltaX,
  13133. const int deltaY) throw();
  13134. /** Returns a rectangle that is larger than this one by a given amount.
  13135. Effectively, the rectangle returned is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2).
  13136. @see expand, reduce, reduced
  13137. */
  13138. const Rectangle expanded (const int deltaX,
  13139. const int deltaY) const throw();
  13140. /** Shrinks the rectangle by a given amount.
  13141. Effectively, its new size is (x + deltaX, y + deltaY, w - deltaX * 2, h - deltaY * 2).
  13142. @see reduced, expand, expanded
  13143. */
  13144. void reduce (const int deltaX,
  13145. const int deltaY) throw();
  13146. /** Returns a rectangle that is smaller than this one by a given amount.
  13147. Effectively, the rectangle returned is (x + deltaX, y + deltaY, w - deltaX * 2, h - deltaY * 2).
  13148. @see reduce, expand, expanded
  13149. */
  13150. const Rectangle reduced (const int deltaX,
  13151. const int deltaY) const throw();
  13152. /** Returns true if the two rectangles are identical. */
  13153. bool operator== (const Rectangle& other) const throw();
  13154. /** Returns true if the two rectangles are not identical. */
  13155. bool operator!= (const Rectangle& other) const throw();
  13156. /** Returns true if this co-ordinate is inside the rectangle. */
  13157. bool contains (const int x, const int y) const throw();
  13158. /** Returns true if this other rectangle is completely inside this one. */
  13159. bool contains (const Rectangle& other) const throw();
  13160. /** Returns true if any part of another rectangle overlaps this one. */
  13161. bool intersects (const Rectangle& other) const throw();
  13162. /** Returns the region that is the overlap between this and another rectangle.
  13163. If the two rectangles don't overlap, the rectangle returned will be empty.
  13164. */
  13165. const Rectangle getIntersection (const Rectangle& other) const throw();
  13166. /** Clips a rectangle so that it lies only within this one.
  13167. This is a non-static version of intersectRectangles().
  13168. Returns false if the two regions didn't overlap.
  13169. */
  13170. bool intersectRectangle (int& x, int& y, int& w, int& h) const throw();
  13171. /** Returns the smallest rectangle that contains both this one and the one
  13172. passed-in.
  13173. */
  13174. const Rectangle getUnion (const Rectangle& other) const throw();
  13175. /** If this rectangle merged with another one results in a simple rectangle, this
  13176. will set this rectangle to the result, and return true.
  13177. Returns false and does nothing to this rectangle if the two rectangles don't overlap,
  13178. or if they form a complex region.
  13179. */
  13180. bool enlargeIfAdjacent (const Rectangle& other) throw();
  13181. /** If after removing another rectangle from this one the result is a simple rectangle,
  13182. this will set this object's bounds to be the result, and return true.
  13183. Returns false and does nothing to this rectangle if the two rectangles don't overlap,
  13184. or if removing the other one would form a complex region.
  13185. */
  13186. bool reduceIfPartlyContainedIn (const Rectangle& other) throw();
  13187. /** Static utility to intersect two sets of rectangular co-ordinates.
  13188. Returns false if the two regions didn't overlap.
  13189. @see intersectRectangle
  13190. */
  13191. static bool intersectRectangles (int& x1, int& y1, int& w1, int& h1,
  13192. int x2, int y2, int w2, int h2) throw();
  13193. /** Creates a string describing this rectangle.
  13194. The string will be of the form "x y width height", e.g. "100 100 400 200".
  13195. Coupled with the fromString() method, this is very handy for things like
  13196. storing rectangles (particularly component positions) in XML attributes.
  13197. @see fromString
  13198. */
  13199. const String toString() const throw();
  13200. /** Parses a string containing a rectangle's details.
  13201. The string should contain 4 integer tokens, in the form "x y width height". They
  13202. can be comma or whitespace separated.
  13203. This method is intended to go with the toString() method, to form an easy way
  13204. of saving/loading rectangles as strings.
  13205. @see toString
  13206. */
  13207. static const Rectangle fromString (const String& stringVersion);
  13208. juce_UseDebuggingNewOperator
  13209. private:
  13210. friend class RectangleList;
  13211. int x, y, w, h;
  13212. };
  13213. #endif // __JUCE_RECTANGLE_JUCEHEADER__
  13214. /********* End of inlined file: juce_Rectangle.h *********/
  13215. /********* Start of inlined file: juce_PathStrokeType.h *********/
  13216. #ifndef __JUCE_PATHSTROKETYPE_JUCEHEADER__
  13217. #define __JUCE_PATHSTROKETYPE_JUCEHEADER__
  13218. /**
  13219. Describes a type of stroke used to render a solid outline along a path.
  13220. A PathStrokeType object can be used directly to create the shape of an outline
  13221. around a path, and is used by Graphics::strokePath to specify the type of
  13222. stroke to draw.
  13223. @see Path, Graphics::strokePath
  13224. */
  13225. class JUCE_API PathStrokeType
  13226. {
  13227. public:
  13228. /** The type of shape to use for the corners between two adjacent line segments. */
  13229. enum JointStyle
  13230. {
  13231. mitered, /**< Indicates that corners should be drawn with sharp joints.
  13232. Note that for angles that curve back on themselves, drawing a
  13233. mitre could require extending the point too far away from the
  13234. path, so a mitre limit is imposed and any corners that exceed it
  13235. are drawn as bevelled instead. */
  13236. curved, /**< Indicates that corners should be drawn as rounded-off. */
  13237. beveled /**< Indicates that corners should be drawn with a line flattening their
  13238. outside edge. */
  13239. };
  13240. /** The type shape to use for the ends of lines. */
  13241. enum EndCapStyle
  13242. {
  13243. butt, /**< Ends of lines are flat and don't extend beyond the end point. */
  13244. square, /**< Ends of lines are flat, but stick out beyond the end point for half
  13245. the thickness of the stroke. */
  13246. rounded /**< Ends of lines are rounded-off with a circular shape. */
  13247. };
  13248. /** Creates a stroke type.
  13249. @param strokeThickness the width of the line to use
  13250. @param jointStyle the type of joints to use for corners
  13251. @param endStyle the type of end-caps to use for the ends of open paths.
  13252. */
  13253. PathStrokeType (const float strokeThickness,
  13254. const JointStyle jointStyle = mitered,
  13255. const EndCapStyle endStyle = butt) throw();
  13256. /** Createes a copy of another stroke type. */
  13257. PathStrokeType (const PathStrokeType& other) throw();
  13258. /** Copies another stroke onto this one. */
  13259. const PathStrokeType& operator= (const PathStrokeType& other) throw();
  13260. /** Destructor. */
  13261. ~PathStrokeType() throw();
  13262. /** Applies this stroke type to a path and returns the resultant stroke as another Path.
  13263. @param destPath the resultant stroked outline shape will be copied into this path.
  13264. Note that it's ok for the source and destination Paths to be
  13265. the same object, so you can easily turn a path into a stroked version
  13266. of itself.
  13267. @param sourcePath the path to use as the source
  13268. @param transform an optional transform to apply to the points from the source path
  13269. as they are being used
  13270. @param extraAccuracy if this is greater than 1.0, it will subdivide the path to
  13271. a higher resolution, which improved the quality if you'll later want
  13272. to enlarge the stroked path
  13273. @see createDashedStroke
  13274. */
  13275. void createStrokedPath (Path& destPath,
  13276. const Path& sourcePath,
  13277. const AffineTransform& transform = AffineTransform::identity,
  13278. const float extraAccuracy = 1.0f) const throw();
  13279. /** Applies this stroke type to a path, creating a dashed line.
  13280. This is similar to createStrokedPath, but uses the array passed in to
  13281. break the stroke up into a series of dashes.
  13282. @param destPath the resultant stroked outline shape will be copied into this path.
  13283. Note that it's ok for the source and destination Paths to be
  13284. the same object, so you can easily turn a path into a stroked version
  13285. of itself.
  13286. @param sourcePath the path to use as the source
  13287. @param dashLengths An array of alternating on/off lengths. E.g. { 2, 3, 4, 5 } will create
  13288. a line of length 2, then skip a length of 3, then add a line of length 4,
  13289. skip 5, and keep repeating this pattern.
  13290. @param numDashLengths The number of lengths in the dashLengths array. This should really be
  13291. an even number, otherwise the pattern will get out of step as it
  13292. repeats.
  13293. @param transform an optional transform to apply to the points from the source path
  13294. as they are being used
  13295. @param extraAccuracy if this is greater than 1.0, it will subdivide the path to
  13296. a higher resolution, which improved the quality if you'll later want
  13297. to enlarge the stroked path
  13298. */
  13299. void createDashedStroke (Path& destPath,
  13300. const Path& sourcePath,
  13301. const float* dashLengths,
  13302. int numDashLengths,
  13303. const AffineTransform& transform = AffineTransform::identity,
  13304. const float extraAccuracy = 1.0f) const throw();
  13305. /** Returns the stroke thickness. */
  13306. float getStrokeThickness() const throw() { return thickness; }
  13307. /** Returns the joint style. */
  13308. JointStyle getJointStyle() const throw() { return jointStyle; }
  13309. /** Returns the end-cap style. */
  13310. EndCapStyle getEndStyle() const throw() { return endStyle; }
  13311. juce_UseDebuggingNewOperator
  13312. /** Compares the stroke thickness, joint and end styles of two stroke types. */
  13313. bool operator== (const PathStrokeType& other) const throw();
  13314. /** Compares the stroke thickness, joint and end styles of two stroke types. */
  13315. bool operator!= (const PathStrokeType& other) const throw();
  13316. private:
  13317. float thickness;
  13318. JointStyle jointStyle;
  13319. EndCapStyle endStyle;
  13320. };
  13321. #endif // __JUCE_PATHSTROKETYPE_JUCEHEADER__
  13322. /********* End of inlined file: juce_PathStrokeType.h *********/
  13323. /********* Start of inlined file: juce_Line.h *********/
  13324. #ifndef __JUCE_LINE_JUCEHEADER__
  13325. #define __JUCE_LINE_JUCEHEADER__
  13326. /**
  13327. Represents a line, using 32-bit float co-ordinates.
  13328. This class contains a bunch of useful methods for various geometric
  13329. tasks.
  13330. @see Point, Rectangle, Path, Graphics::drawLine
  13331. */
  13332. class JUCE_API Line
  13333. {
  13334. public:
  13335. /** Creates a line, using (0, 0) as its start and end points. */
  13336. Line() throw();
  13337. /** Creates a copy of another line. */
  13338. Line (const Line& other) throw();
  13339. /** Creates a line based on the co-ordinates of its start and end points. */
  13340. Line (const float startX,
  13341. const float startY,
  13342. const float endX,
  13343. const float endY) throw();
  13344. /** Creates a line from its start and end points. */
  13345. Line (const Point& start,
  13346. const Point& end) throw();
  13347. /** Copies a line from another one. */
  13348. const Line& operator= (const Line& other) throw();
  13349. /** Destructor. */
  13350. ~Line() throw();
  13351. /** Returns the x co-ordinate of the line's start point. */
  13352. inline float getStartX() const throw() { return startX; }
  13353. /** Returns the y co-ordinate of the line's start point. */
  13354. inline float getStartY() const throw() { return startY; }
  13355. /** Returns the x co-ordinate of the line's end point. */
  13356. inline float getEndX() const throw() { return endX; }
  13357. /** Returns the y co-ordinate of the line's end point. */
  13358. inline float getEndY() const throw() { return endY; }
  13359. /** Returns the line's start point. */
  13360. const Point getStart() const throw();
  13361. /** Returns the line's end point. */
  13362. const Point getEnd() const throw();
  13363. /** Changes this line's start point */
  13364. void setStart (const float newStartX,
  13365. const float newStartY) throw();
  13366. /** Changes this line's end point */
  13367. void setEnd (const float newEndX,
  13368. const float newEndY) throw();
  13369. /** Changes this line's start point */
  13370. void setStart (const Point& newStart) throw();
  13371. /** Changes this line's end point */
  13372. void setEnd (const Point& newEnd) throw();
  13373. /** Applies an affine transform to the line's start and end points. */
  13374. void applyTransform (const AffineTransform& transform) throw();
  13375. /** Returns the length of the line. */
  13376. float getLength() const throw();
  13377. /** Returns true if the line's start and end x co-ordinates are the same. */
  13378. bool isVertical() const throw();
  13379. /** Returns true if the line's start and end y co-ordinates are the same. */
  13380. bool isHorizontal() const throw();
  13381. /** Returns the line's angle.
  13382. This value is the number of radians clockwise from the 3 o'clock direction,
  13383. where the line's start point is considered to be at the centre.
  13384. */
  13385. float getAngle() const throw();
  13386. /** Compares two lines. */
  13387. bool operator== (const Line& other) const throw();
  13388. /** Compares two lines. */
  13389. bool operator!= (const Line& other) const throw();
  13390. /** Finds the intersection between two lines.
  13391. @param line the other line
  13392. @param intersectionX the x co-ordinate of the point where the lines meet (or
  13393. where they would meet if they were infinitely long)
  13394. the intersection (if the lines intersect). If the lines
  13395. are parallel, this will just be set to the position
  13396. of one of the line's endpoints.
  13397. @param intersectionY the y co-ordinate of the point where the lines meet
  13398. @returns true if the line segments intersect; false if they dont. Even if they
  13399. don't intersect, the intersection co-ordinates returned will still
  13400. be valid
  13401. */
  13402. bool intersects (const Line& line,
  13403. float& intersectionX,
  13404. float& intersectionY) const throw();
  13405. /** Returns the location of the point which is a given distance along this line.
  13406. @param distanceFromStart the distance to move along the line from its
  13407. start point. This value can be negative or longer
  13408. than the line itself
  13409. @see getPointAlongLineProportionally
  13410. */
  13411. const Point getPointAlongLine (const float distanceFromStart) const throw();
  13412. /** Returns a point which is a certain distance along and to the side of this line.
  13413. This effectively moves a given distance along the line, then another distance
  13414. perpendicularly to this, and returns the resulting position.
  13415. @param distanceFromStart the distance to move along the line from its
  13416. start point. This value can be negative or longer
  13417. than the line itself
  13418. @param perpendicularDistance how far to move sideways from the line. If you're
  13419. looking along the line from its start towards its
  13420. end, then a positive value here will move to the
  13421. right, negative value move to the left.
  13422. */
  13423. const Point getPointAlongLine (const float distanceFromStart,
  13424. const float perpendicularDistance) const throw();
  13425. /** Returns the location of the point which is a given distance along this line
  13426. proportional to the line's length.
  13427. @param proportionOfLength the distance to move along the line from its
  13428. start point, in multiples of the line's length.
  13429. So a value of 0.0 will return the line's start point
  13430. and a value of 1.0 will return its end point. (This value
  13431. can be negative or greater than 1.0).
  13432. @see getPointAlongLine
  13433. */
  13434. const Point getPointAlongLineProportionally (const float proportionOfLength) const throw();
  13435. /** Returns the smallest distance between this line segment and a given point.
  13436. So if the point is close to the line, this will return the perpendicular
  13437. distance from the line; if the point is a long way beyond one of the line's
  13438. end-point's, it'll return the straight-line distance to the nearest end-point.
  13439. @param x x position of the point to test
  13440. @param y y position of the point to test
  13441. @returns the point's distance from the line
  13442. @see getPositionAlongLineOfNearestPoint
  13443. */
  13444. float getDistanceFromLine (const float x,
  13445. const float y) const throw();
  13446. /** Finds the point on this line which is nearest to a given point, and
  13447. returns its position as a proportional position along the line.
  13448. @param x x position of the point to test
  13449. @param y y position of the point to test
  13450. @returns a value 0 to 1.0 which is the distance along this line from the
  13451. line's start to the point which is nearest to the point passed-in. To
  13452. turn this number into a position, use getPointAlongLineProportionally().
  13453. @see getDistanceFromLine, getPointAlongLineProportionally
  13454. */
  13455. float findNearestPointTo (const float x,
  13456. const float y) const throw();
  13457. /** Returns true if the given point lies above this line.
  13458. The return value is true if the point's y coordinate is less than the y
  13459. coordinate of this line at the given x (assuming the line extends infinitely
  13460. in both directions).
  13461. */
  13462. bool isPointAbove (const float x, const float y) const throw();
  13463. /** Returns a shortened copy of this line.
  13464. This will chop off part of the start of this line by a certain amount, (leaving the
  13465. end-point the same), and return the new line.
  13466. */
  13467. const Line withShortenedStart (const float distanceToShortenBy) const throw();
  13468. /** Returns a shortened copy of this line.
  13469. This will chop off part of the end of this line by a certain amount, (leaving the
  13470. start-point the same), and return the new line.
  13471. */
  13472. const Line withShortenedEnd (const float distanceToShortenBy) const throw();
  13473. /** Cuts off parts of this line to keep the parts that are either inside or
  13474. outside a path.
  13475. Note that this isn't smart enough to cope with situations where the
  13476. line would need to be cut into multiple pieces to correctly clip against
  13477. a re-entrant shape.
  13478. @param path the path to clip against
  13479. @param keepSectionOutsidePath if true, it's the section outside the path
  13480. that will be kept; if false its the section inside
  13481. the path
  13482. @returns true if the line was changed.
  13483. */
  13484. bool clipToPath (const Path& path,
  13485. const bool keepSectionOutsidePath) throw();
  13486. juce_UseDebuggingNewOperator
  13487. private:
  13488. float startX, startY, endX, endY;
  13489. };
  13490. #endif // __JUCE_LINE_JUCEHEADER__
  13491. /********* End of inlined file: juce_Line.h *********/
  13492. /********* Start of inlined file: juce_Colours.h *********/
  13493. #ifndef __JUCE_COLOURS_JUCEHEADER__
  13494. #define __JUCE_COLOURS_JUCEHEADER__
  13495. /********* Start of inlined file: juce_Colour.h *********/
  13496. #ifndef __JUCE_COLOUR_JUCEHEADER__
  13497. #define __JUCE_COLOUR_JUCEHEADER__
  13498. /********* Start of inlined file: juce_PixelFormats.h *********/
  13499. #ifndef __JUCE_PIXELFORMATS_JUCEHEADER__
  13500. #define __JUCE_PIXELFORMATS_JUCEHEADER__
  13501. #if JUCE_MSVC
  13502. #pragma pack (push, 1)
  13503. #define PACKED
  13504. #elif JUCE_GCC
  13505. #define PACKED __attribute__((packed))
  13506. #else
  13507. #define PACKED
  13508. #endif
  13509. /**
  13510. Represents a 32-bit ARGB pixel with premultiplied alpha, and can perform compositing
  13511. operations with it.
  13512. This is used internally by the imaging classes.
  13513. @see PixelRGB
  13514. */
  13515. class JUCE_API PixelARGB
  13516. {
  13517. public:
  13518. /** Creates a pixel without defining its colour. */
  13519. PixelARGB() throw() {}
  13520. ~PixelARGB() throw() {}
  13521. /** Creates a pixel from a 32-bit argb value.
  13522. */
  13523. PixelARGB (const uint32 argb_) throw()
  13524. : argb (argb_)
  13525. {
  13526. }
  13527. forcedinline uint32 getARGB() const throw() { return argb; }
  13528. forcedinline uint32 getRB() const throw() { return 0x00ff00ff & argb; }
  13529. forcedinline uint32 getAG() const throw() { return 0x00ff00ff & (argb >> 8); }
  13530. forcedinline uint8 getAlpha() const throw() { return components.a; }
  13531. forcedinline uint8 getRed() const throw() { return components.r; }
  13532. forcedinline uint8 getGreen() const throw() { return components.g; }
  13533. forcedinline uint8 getBlue() const throw() { return components.b; }
  13534. /** Blends another pixel onto this one.
  13535. This takes into account the opacity of the pixel being overlaid, and blends
  13536. it accordingly.
  13537. */
  13538. template <class Pixel>
  13539. forcedinline void blend (const Pixel& src) throw()
  13540. {
  13541. uint32 sargb = src.getARGB();
  13542. const uint32 alpha = 0x100 - (sargb >> 24);
  13543. sargb += 0x00ff00ff & ((getRB() * alpha) >> 8);
  13544. sargb += 0xff00ff00 & (getAG() * alpha);
  13545. argb = sargb;
  13546. }
  13547. /** Blends another pixel onto this one, applying an extra multiplier to its opacity.
  13548. The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
  13549. being used, so this can blend semi-transparently from a PixelRGB argument.
  13550. */
  13551. template <class Pixel>
  13552. forcedinline void blend (const Pixel& src, uint32 extraAlpha) throw()
  13553. {
  13554. ++extraAlpha;
  13555. uint32 sargb = ((extraAlpha * src.getAG()) & 0xff00ff00)
  13556. | (((extraAlpha * src.getRB()) >> 8) & 0x00ff00ff);
  13557. const uint32 alpha = 0x100 - (sargb >> 24);
  13558. sargb += 0x00ff00ff & ((getRB() * alpha) >> 8);
  13559. sargb += 0xff00ff00 & (getAG() * alpha);
  13560. argb = sargb;
  13561. }
  13562. /** Blends another pixel with this one, creating a colour that is somewhere
  13563. between the two, as specified by the amount.
  13564. */
  13565. template <class Pixel>
  13566. forcedinline void tween (const Pixel& src, const uint32 amount) throw()
  13567. {
  13568. uint32 drb = getRB();
  13569. drb += (((src.getRB() - drb) * amount) >> 8);
  13570. drb &= 0x00ff00ff;
  13571. uint32 dag = getAG();
  13572. dag += (((src.getAG() - dag) * amount) >> 8);
  13573. dag &= 0x00ff00ff;
  13574. dag <<= 8;
  13575. dag |= drb;
  13576. argb = dag;
  13577. }
  13578. /** Copies another pixel colour over this one.
  13579. This doesn't blend it - this colour is simply replaced by the other one.
  13580. */
  13581. template <class Pixel>
  13582. forcedinline void set (const Pixel& src) throw()
  13583. {
  13584. argb = src.getARGB();
  13585. }
  13586. /** Replaces the colour's alpha value with another one. */
  13587. forcedinline void setAlpha (const uint8 newAlpha) throw()
  13588. {
  13589. components.a = newAlpha;
  13590. }
  13591. /** Multiplies the colour's alpha value with another one. */
  13592. forcedinline void multiplyAlpha (int multiplier) throw()
  13593. {
  13594. ++multiplier;
  13595. argb = ((multiplier * getAG()) & 0xff00ff00)
  13596. | (((multiplier * getRB()) >> 8) & 0x00ff00ff);
  13597. }
  13598. forcedinline void multiplyAlpha (const float multiplier) throw()
  13599. {
  13600. multiplyAlpha ((int) (multiplier * 256.0f));
  13601. }
  13602. /** Sets the pixel's colour from individual components. */
  13603. void setARGB (const uint8 a, const uint8 r, const uint8 g, const uint8 b) throw()
  13604. {
  13605. components.b = b;
  13606. components.g = g;
  13607. components.r = r;
  13608. components.a = a;
  13609. }
  13610. /** Premultiplies the pixel's RGB values by its alpha. */
  13611. forcedinline void premultiply() throw()
  13612. {
  13613. const uint32 alpha = components.a;
  13614. if (alpha < 0xff)
  13615. {
  13616. if (alpha == 0)
  13617. {
  13618. components.b = 0;
  13619. components.g = 0;
  13620. components.r = 0;
  13621. }
  13622. else
  13623. {
  13624. components.b = (uint8) ((components.b * alpha + 0x7f) >> 8);
  13625. components.g = (uint8) ((components.g * alpha + 0x7f) >> 8);
  13626. components.r = (uint8) ((components.r * alpha + 0x7f) >> 8);
  13627. }
  13628. }
  13629. }
  13630. /** Unpremultiplies the pixel's RGB values. */
  13631. forcedinline void unpremultiply() throw()
  13632. {
  13633. const uint32 alpha = components.a;
  13634. if (alpha < 0xff)
  13635. {
  13636. if (alpha == 0)
  13637. {
  13638. components.b = 0;
  13639. components.g = 0;
  13640. components.r = 0;
  13641. }
  13642. else
  13643. {
  13644. components.b = (uint8) jmin (0xff, (components.b * 0xff) / alpha);
  13645. components.g = (uint8) jmin (0xff, (components.g * 0xff) / alpha);
  13646. components.r = (uint8) jmin (0xff, (components.r * 0xff) / alpha);
  13647. }
  13648. }
  13649. }
  13650. forcedinline void desaturate() throw()
  13651. {
  13652. if (components.a < 0xff && components.a > 0)
  13653. {
  13654. const int newUnpremultipliedLevel = (0xff * ((int) components.r + (int) components.g + (int) components.b) / (3 * components.a));
  13655. components.r = components.g = components.b
  13656. = (uint8) ((newUnpremultipliedLevel * components.a + 0x7f) >> 8);
  13657. }
  13658. else
  13659. {
  13660. components.r = components.g = components.b
  13661. = (uint8) (((int) components.r + (int) components.g + (int) components.b) / 3);
  13662. }
  13663. }
  13664. private:
  13665. union
  13666. {
  13667. uint32 argb;
  13668. struct
  13669. {
  13670. #if JUCE_BIG_ENDIAN
  13671. uint8 a : 8, r : 8, g : 8, b : 8;
  13672. #else
  13673. uint8 b, g, r, a;
  13674. #endif
  13675. } PACKED components;
  13676. };
  13677. } PACKED;
  13678. /**
  13679. Represents a 24-bit RGB pixel, and can perform compositing operations on it.
  13680. This is used internally by the imaging classes.
  13681. @see PixelARGB
  13682. */
  13683. class JUCE_API PixelRGB
  13684. {
  13685. public:
  13686. /** Creates a pixel without defining its colour. */
  13687. PixelRGB() throw() {}
  13688. ~PixelRGB() throw() {}
  13689. /** Creates a pixel from a 32-bit argb value.
  13690. (The argb format is that used by PixelARGB)
  13691. */
  13692. PixelRGB (const uint32 argb) throw()
  13693. {
  13694. r = (uint8) (argb >> 16);
  13695. g = (uint8) (argb >> 8);
  13696. b = (uint8) (argb);
  13697. }
  13698. forcedinline uint32 getARGB() const throw() { return 0xff000000 | b | (g << 8) | (r << 16); }
  13699. forcedinline uint32 getRB() const throw() { return b | (uint32) (r << 16); }
  13700. forcedinline uint32 getAG() const throw() { return 0xff0000 | g; }
  13701. forcedinline uint8 getAlpha() const throw() { return 0xff; }
  13702. forcedinline uint8 getRed() const throw() { return r; }
  13703. forcedinline uint8 getGreen() const throw() { return g; }
  13704. forcedinline uint8 getBlue() const throw() { return b; }
  13705. /** Blends another pixel onto this one.
  13706. This takes into account the opacity of the pixel being overlaid, and blends
  13707. it accordingly.
  13708. */
  13709. forcedinline void blend (const PixelARGB& src) throw()
  13710. {
  13711. uint32 sargb = src.getARGB();
  13712. const uint32 alpha = 0x100 - (sargb >> 24);
  13713. sargb += 0x00ff00ff & ((getRB() * alpha) >> 8);
  13714. sargb += 0x0000ff00 & (g * alpha);
  13715. r = (uint8) (sargb >> 16);
  13716. g = (uint8) (sargb >> 8);
  13717. b = (uint8) sargb;
  13718. }
  13719. forcedinline void blend (const PixelRGB& src) throw()
  13720. {
  13721. set (src);
  13722. }
  13723. /** Blends another pixel onto this one, applying an extra multiplier to its opacity.
  13724. The opacity of the pixel being overlaid is scaled by the extraAlpha factor before
  13725. being used, so this can blend semi-transparently from a PixelRGB argument.
  13726. */
  13727. template <class Pixel>
  13728. forcedinline void blend (const Pixel& src, uint32 extraAlpha) throw()
  13729. {
  13730. ++extraAlpha;
  13731. const uint32 srb = (extraAlpha * src.getRB()) >> 8;
  13732. const uint32 sag = extraAlpha * src.getAG();
  13733. uint32 sargb = (sag & 0xff00ff00) | (srb & 0x00ff00ff);
  13734. const uint32 alpha = 0x100 - (sargb >> 24);
  13735. sargb += 0x00ff00ff & ((getRB() * alpha) >> 8);
  13736. sargb += 0x0000ff00 & (g * alpha);
  13737. b = (uint8) sargb;
  13738. g = (uint8) (sargb >> 8);
  13739. r = (uint8) (sargb >> 16);
  13740. }
  13741. /** Blends another pixel with this one, creating a colour that is somewhere
  13742. between the two, as specified by the amount.
  13743. */
  13744. template <class Pixel>
  13745. forcedinline void tween (const Pixel& src, const uint32 amount) throw()
  13746. {
  13747. uint32 drb = getRB();
  13748. drb += (((src.getRB() - drb) * amount) >> 8);
  13749. uint32 dag = getAG();
  13750. dag += (((src.getAG() - dag) * amount) >> 8);
  13751. b = (uint8) drb;
  13752. g = (uint8) dag;
  13753. r = (uint8) (drb >> 16);
  13754. }
  13755. /** Copies another pixel colour over this one.
  13756. This doesn't blend it - this colour is simply replaced by the other one.
  13757. Because PixelRGB has no alpha channel, any alpha value in the source pixel
  13758. is thrown away.
  13759. */
  13760. template <class Pixel>
  13761. forcedinline void set (const Pixel& src) throw()
  13762. {
  13763. b = src.getBlue();
  13764. g = src.getGreen();
  13765. r = src.getRed();
  13766. }
  13767. /** This method is included for compatibility with the PixelARGB class. */
  13768. forcedinline void setAlpha (const uint8) throw() {}
  13769. /** Multiplies the colour's alpha value with another one. */
  13770. forcedinline void multiplyAlpha (int) throw() {}
  13771. /** Sets the pixel's colour from individual components. */
  13772. void setARGB (const uint8, const uint8 r_, const uint8 g_, const uint8 b_) throw()
  13773. {
  13774. r = r_;
  13775. g = g_;
  13776. b = b_;
  13777. }
  13778. /** Premultiplies the pixel's RGB values by its alpha. */
  13779. forcedinline void premultiply() throw() {}
  13780. /** Unpremultiplies the pixel's RGB values. */
  13781. forcedinline void unpremultiply() throw() {}
  13782. forcedinline void desaturate() throw()
  13783. {
  13784. r = g = b = (uint8) (((int) r + (int) g + (int) b) / 3);
  13785. }
  13786. private:
  13787. #if JUCE_MAC
  13788. uint8 r, g, b;
  13789. #else
  13790. uint8 b, g, r;
  13791. #endif
  13792. } PACKED;
  13793. #if JUCE_MSVC
  13794. #pragma pack (pop)
  13795. #endif
  13796. #undef PACKED
  13797. #endif // __JUCE_PIXELFORMATS_JUCEHEADER__
  13798. /********* End of inlined file: juce_PixelFormats.h *********/
  13799. /**
  13800. Represents a colour, also including a transparency value.
  13801. The colour is stored internally as unsigned 8-bit red, green, blue and alpha values.
  13802. */
  13803. class JUCE_API Colour
  13804. {
  13805. public:
  13806. /** Creates a transparent black colour. */
  13807. Colour() throw();
  13808. /** Creates a copy of another Colour object. */
  13809. Colour (const Colour& other) throw();
  13810. /** Creates a colour from a 32-bit ARGB value.
  13811. The format of this number is:
  13812. ((alpha << 24) | (red << 16) | (green << 16) | blue).
  13813. All components in the range 0x00 to 0xff.
  13814. An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.
  13815. @see getPixelARGB
  13816. */
  13817. explicit Colour (const uint32 argb) throw();
  13818. /** Creates an opaque colour using 8-bit red, green and blue values */
  13819. Colour (const uint8 red,
  13820. const uint8 green,
  13821. const uint8 blue) throw();
  13822. /** Creates an opaque colour using 8-bit red, green and blue values */
  13823. static const Colour fromRGB (const uint8 red,
  13824. const uint8 green,
  13825. const uint8 blue) throw();
  13826. /** Creates a colour using 8-bit red, green, blue and alpha values. */
  13827. Colour (const uint8 red,
  13828. const uint8 green,
  13829. const uint8 blue,
  13830. const uint8 alpha) throw();
  13831. /** Creates a colour using 8-bit red, green, blue and alpha values. */
  13832. static const Colour fromRGBA (const uint8 red,
  13833. const uint8 green,
  13834. const uint8 blue,
  13835. const uint8 alpha) throw();
  13836. /** Creates a colour from 8-bit red, green, and blue values, and a floating-point alpha.
  13837. Alpha of 0.0 is transparent, alpha of 1.0f is opaque.
  13838. Values outside the valid range will be clipped.
  13839. */
  13840. Colour (const uint8 red,
  13841. const uint8 green,
  13842. const uint8 blue,
  13843. const float alpha) throw();
  13844. /** Creates a colour using 8-bit red, green, blue and float alpha values. */
  13845. static const Colour fromRGBAFloat (const uint8 red,
  13846. const uint8 green,
  13847. const uint8 blue,
  13848. const float alpha) throw();
  13849. /** Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.
  13850. The floating point values must be between 0.0 and 1.0.
  13851. An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.
  13852. Values outside the valid range will be clipped.
  13853. */
  13854. Colour (const float hue,
  13855. const float saturation,
  13856. const float brightness,
  13857. const uint8 alpha) throw();
  13858. /** Creates a colour using floating point hue, saturation, brightness and alpha values.
  13859. All values must be between 0.0 and 1.0.
  13860. Numbers outside the valid range will be clipped.
  13861. */
  13862. Colour (const float hue,
  13863. const float saturation,
  13864. const float brightness,
  13865. const float alpha) throw();
  13866. /** Creates a colour using floating point hue, saturation and brightness values, and an 8-bit alpha.
  13867. The floating point values must be between 0.0 and 1.0.
  13868. An alpha of 0x00 is completely transparent, alpha of 0xff is opaque.
  13869. Values outside the valid range will be clipped.
  13870. */
  13871. static const Colour fromHSV (const float hue,
  13872. const float saturation,
  13873. const float brightness,
  13874. const float alpha) throw();
  13875. /** Destructor. */
  13876. ~Colour() throw();
  13877. /** Copies another Colour object. */
  13878. const Colour& operator= (const Colour& other) throw();
  13879. /** Compares two colours. */
  13880. bool operator== (const Colour& other) const throw();
  13881. /** Compares two colours. */
  13882. bool operator!= (const Colour& other) const throw();
  13883. /** Returns the red component of this colour.
  13884. @returns a value between 0x00 and 0xff.
  13885. */
  13886. uint8 getRed() const throw() { return argb.getRed(); }
  13887. /** Returns the green component of this colour.
  13888. @returns a value between 0x00 and 0xff.
  13889. */
  13890. uint8 getGreen() const throw() { return argb.getGreen(); }
  13891. /** Returns the blue component of this colour.
  13892. @returns a value between 0x00 and 0xff.
  13893. */
  13894. uint8 getBlue() const throw() { return argb.getBlue(); }
  13895. /** Returns the red component of this colour as a floating point value.
  13896. @returns a value between 0.0 and 1.0
  13897. */
  13898. float getFloatRed() const throw();
  13899. /** Returns the green component of this colour as a floating point value.
  13900. @returns a value between 0.0 and 1.0
  13901. */
  13902. float getFloatGreen() const throw();
  13903. /** Returns the blue component of this colour as a floating point value.
  13904. @returns a value between 0.0 and 1.0
  13905. */
  13906. float getFloatBlue() const throw();
  13907. /** Returns a premultiplied ARGB pixel object that represents this colour.
  13908. */
  13909. const PixelARGB getPixelARGB() const throw();
  13910. /** Returns a 32-bit integer that represents this colour.
  13911. The format of this number is:
  13912. ((alpha << 24) | (red << 16) | (green << 16) | blue).
  13913. */
  13914. uint32 getARGB() const throw();
  13915. /** Returns the colour's alpha (opacity).
  13916. Alpha of 0x00 is completely transparent, 0xff is completely opaque.
  13917. */
  13918. uint8 getAlpha() const throw() { return argb.getAlpha(); }
  13919. /** Returns the colour's alpha (opacity) as a floating point value.
  13920. Alpha of 0.0 is completely transparent, 1.0 is completely opaque.
  13921. */
  13922. float getFloatAlpha() const throw();
  13923. /** Returns true if this colour is completely opaque.
  13924. Equivalent to (getAlpha() == 0xff).
  13925. */
  13926. bool isOpaque() const throw();
  13927. /** Returns true if this colour is completely transparent.
  13928. Equivalent to (getAlpha() == 0x00).
  13929. */
  13930. bool isTransparent() const throw();
  13931. /** Returns a colour that's the same colour as this one, but with a new alpha value. */
  13932. const Colour withAlpha (const uint8 newAlpha) const throw();
  13933. /** Returns a colour that's the same colour as this one, but with a new alpha value. */
  13934. const Colour withAlpha (const float newAlpha) const throw();
  13935. /** Returns a colour that's the same colour as this one, but with a modified alpha value.
  13936. The new colour's alpha will be this object's alpha multiplied by the value passed-in.
  13937. */
  13938. const Colour withMultipliedAlpha (const float alphaMultiplier) const throw();
  13939. /** Returns a colour that is the result of alpha-compositing a new colour over this one.
  13940. If the foreground colour is semi-transparent, it is blended onto this colour
  13941. accordingly.
  13942. */
  13943. const Colour overlaidWith (const Colour& foregroundColour) const throw();
  13944. /** Returns the colour's hue component.
  13945. The value returned is in the range 0.0 to 1.0
  13946. */
  13947. float getHue() const throw();
  13948. /** Returns the colour's saturation component.
  13949. The value returned is in the range 0.0 to 1.0
  13950. */
  13951. float getSaturation() const throw();
  13952. /** Returns the colour's brightness component.
  13953. The value returned is in the range 0.0 to 1.0
  13954. */
  13955. float getBrightness() const throw();
  13956. /** Returns the colour's hue, saturation and brightness components all at once.
  13957. The values returned are in the range 0.0 to 1.0
  13958. */
  13959. void getHSB (float& hue,
  13960. float& saturation,
  13961. float& brightness) const throw();
  13962. /** Returns a copy of this colour with a different hue. */
  13963. const Colour withHue (const float newHue) const throw();
  13964. /** Returns a copy of this colour with a different saturation. */
  13965. const Colour withSaturation (const float newSaturation) const throw();
  13966. /** Returns a copy of this colour with a different brightness.
  13967. @see brighter, darker, withMultipliedBrightness
  13968. */
  13969. const Colour withBrightness (const float newBrightness) const throw();
  13970. /** Returns a copy of this colour with it hue rotated.
  13971. The new colour's hue is ((this->getHue() + amountToRotate) % 1.0)
  13972. @see brighter, darker, withMultipliedBrightness
  13973. */
  13974. const Colour withRotatedHue (const float amountToRotate) const throw();
  13975. /** Returns a copy of this colour with its saturation multiplied by the given value.
  13976. The new colour's saturation is (this->getSaturation() * multiplier)
  13977. (the result is clipped to legal limits).
  13978. */
  13979. const Colour withMultipliedSaturation (const float multiplier) const throw();
  13980. /** Returns a copy of this colour with its brightness multiplied by the given value.
  13981. The new colour's saturation is (this->getBrightness() * multiplier)
  13982. (the result is clipped to legal limits).
  13983. */
  13984. const Colour withMultipliedBrightness (const float amount) const throw();
  13985. /** Returns a brighter version of this colour.
  13986. @param amountBrighter how much brighter to make it - a value from 0 to 1.0 where 0 is
  13987. unchanged, and higher values make it brighter
  13988. @see withMultipliedBrightness
  13989. */
  13990. const Colour brighter (float amountBrighter = 0.4f) const throw();
  13991. /** Returns a darker version of this colour.
  13992. @param amountDarker how much darker to make it - a value from 0 to 1.0 where 0 is
  13993. unchanged, and higher values make it darker
  13994. @see withMultipliedBrightness
  13995. */
  13996. const Colour darker (float amountDarker = 0.4f) const throw();
  13997. /** Returns a colour that will be clearly visible against this colour.
  13998. The amount parameter indicates how contrasting the new colour should
  13999. be, so e.g. Colours::black.contrasting (0.1f) will return a colour
  14000. that's just a little bit lighter; Colours::black.contrasting (1.0f) will
  14001. return white; Colours::white.contrasting (1.0f) will return black, etc.
  14002. */
  14003. const Colour contrasting (const float amount = 1.0f) const throw();
  14004. /** Returns a colour that contrasts against two colours.
  14005. Looks for a colour that contrasts with both of the colours passed-in.
  14006. Handy for things like choosing a highlight colour in text editors, etc.
  14007. */
  14008. static const Colour contrasting (const Colour& colour1,
  14009. const Colour& colour2) throw();
  14010. /** Returns an opaque shade of grey.
  14011. @param brightness the level of grey to return - 0 is black, 1.0 is white
  14012. */
  14013. static const Colour greyLevel (const float brightness) throw();
  14014. /** Returns a stringified version of this colour.
  14015. The string can be turned back into a colour using the fromString() method.
  14016. */
  14017. const String toString() const throw();
  14018. /** Reads the colour from a string that was created with toString().
  14019. */
  14020. static const Colour fromString (const String& encodedColourString);
  14021. juce_UseDebuggingNewOperator
  14022. private:
  14023. PixelARGB argb;
  14024. };
  14025. #endif // __JUCE_COLOUR_JUCEHEADER__
  14026. /********* End of inlined file: juce_Colour.h *********/
  14027. /**
  14028. Contains a set of predefined named colours (mostly standard HTML colours)
  14029. @see Colour, Colours::greyLevel
  14030. */
  14031. class Colours
  14032. {
  14033. public:
  14034. static JUCE_API const Colour
  14035. transparentBlack, /**< ARGB = 0x00000000 */
  14036. transparentWhite, /**< ARGB = 0x00ffffff */
  14037. black, /**< ARGB = 0xff000000 */
  14038. white, /**< ARGB = 0xffffffff */
  14039. blue, /**< ARGB = 0xff0000ff */
  14040. grey, /**< ARGB = 0xff808080 */
  14041. green, /**< ARGB = 0xff008000 */
  14042. red, /**< ARGB = 0xffff0000 */
  14043. yellow, /**< ARGB = 0xffffff00 */
  14044. aliceblue, antiquewhite, aqua, aquamarine,
  14045. azure, beige, bisque, blanchedalmond,
  14046. blueviolet, brown, burlywood, cadetblue,
  14047. chartreuse, chocolate, coral, cornflowerblue,
  14048. cornsilk, crimson, cyan, darkblue,
  14049. darkcyan, darkgoldenrod, darkgrey, darkgreen,
  14050. darkkhaki, darkmagenta, darkolivegreen, darkorange,
  14051. darkorchid, darkred, darksalmon, darkseagreen,
  14052. darkslateblue, darkslategrey, darkturquoise, darkviolet,
  14053. deeppink, deepskyblue, dimgrey, dodgerblue,
  14054. firebrick, floralwhite, forestgreen, fuchsia,
  14055. gainsboro, gold, goldenrod, greenyellow,
  14056. honeydew, hotpink, indianred, indigo,
  14057. ivory, khaki, lavender, lavenderblush,
  14058. lemonchiffon, lightblue, lightcoral, lightcyan,
  14059. lightgoldenrodyellow, lightgreen, lightgrey, lightpink,
  14060. lightsalmon, lightseagreen, lightskyblue, lightslategrey,
  14061. lightsteelblue, lightyellow, lime, limegreen,
  14062. linen, magenta, maroon, mediumaquamarine,
  14063. mediumblue, mediumorchid, mediumpurple, mediumseagreen,
  14064. mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred,
  14065. midnightblue, mintcream, mistyrose, navajowhite,
  14066. navy, oldlace, olive, olivedrab,
  14067. orange, orangered, orchid, palegoldenrod,
  14068. palegreen, paleturquoise, palevioletred, papayawhip,
  14069. peachpuff, peru, pink, plum,
  14070. powderblue, purple, rosybrown, royalblue,
  14071. saddlebrown, salmon, sandybrown, seagreen,
  14072. seashell, sienna, silver, skyblue,
  14073. slateblue, slategrey, snow, springgreen,
  14074. steelblue, tan, teal, thistle,
  14075. tomato, turquoise, violet, wheat,
  14076. whitesmoke, yellowgreen;
  14077. /** Attempts to look up a string in the list of known colour names, and return
  14078. the appropriate colour.
  14079. A non-case-sensitive search is made of the list of predefined colours, and
  14080. if a match is found, that colour is returned. If no match is found, the
  14081. colour passed in as the defaultColour parameter is returned.
  14082. */
  14083. static JUCE_API const Colour findColourForName (const String& colourName,
  14084. const Colour& defaultColour);
  14085. private:
  14086. // this isn't a class you should ever instantiate - it's just here for the
  14087. // static values in it.
  14088. Colours();
  14089. };
  14090. #endif // __JUCE_COLOURS_JUCEHEADER__
  14091. /********* End of inlined file: juce_Colours.h *********/
  14092. /********* Start of inlined file: juce_SolidColourBrush.h *********/
  14093. #ifndef __JUCE_SOLIDCOLOURBRUSH_JUCEHEADER__
  14094. #define __JUCE_SOLIDCOLOURBRUSH_JUCEHEADER__
  14095. /********* Start of inlined file: juce_Brush.h *********/
  14096. #ifndef __JUCE_BRUSH_JUCEHEADER__
  14097. #define __JUCE_BRUSH_JUCEHEADER__
  14098. class Path;
  14099. class AffineTransform;
  14100. class LowLevelGraphicsContext;
  14101. class Image;
  14102. class Graphics;
  14103. /**
  14104. A brush is used to fill areas with colours, patterns, or images.
  14105. The Graphics class has an idea of a current brush which it uses to render
  14106. shapes, rectangles, lines, text, etc.
  14107. This is the base class - there are subclasses for useful types of fill pattern,
  14108. and applications can define their own brushes too.
  14109. @see Graphics::setBrush, SolidColourBrush, GradientBrush, ImageBrush
  14110. */
  14111. class JUCE_API Brush
  14112. {
  14113. protected:
  14114. /** Creates a Brush.
  14115. (Nothing much happens in the base class).
  14116. */
  14117. Brush() throw();
  14118. public:
  14119. /** Destructor. */
  14120. virtual ~Brush() throw();
  14121. /** Creates a copy of whatever class of Brush this is. */
  14122. virtual Brush* createCopy() const throw() = 0;
  14123. /** Does whatever is relevent to transform the geometry of this brush. */
  14124. virtual void applyTransform (const AffineTransform& transform) throw() = 0;
  14125. /** Does whatever is relevent to change the opacity of this brush. */
  14126. virtual void multiplyOpacity (const float multiple) throw() = 0;
  14127. /** Must return true if this brush won't draw any pixels. */
  14128. virtual bool isInvisible() const throw() = 0;
  14129. virtual void paintPath (LowLevelGraphicsContext& context,
  14130. const Path& path, const AffineTransform& transform) throw() = 0;
  14131. virtual void paintRectangle (LowLevelGraphicsContext& context,
  14132. int x, int y, int w, int h) throw() = 0;
  14133. virtual void paintAlphaChannel (LowLevelGraphicsContext& context,
  14134. const Image& alphaChannelImage, int imageX, int imageY,
  14135. int x, int y, int w, int h) throw() = 0;
  14136. virtual void paintVerticalLine (LowLevelGraphicsContext& context,
  14137. int x, float y1, float y2) throw();
  14138. virtual void paintHorizontalLine (LowLevelGraphicsContext& context,
  14139. int y, float x1, float x2) throw();
  14140. virtual void paintLine (LowLevelGraphicsContext& context,
  14141. float x1, float y1, float x2, float y2) throw();
  14142. private:
  14143. Brush (const Brush&);
  14144. const Brush& operator= (const Brush&);
  14145. };
  14146. #endif // __JUCE_BRUSH_JUCEHEADER__
  14147. /********* End of inlined file: juce_Brush.h *********/
  14148. /**
  14149. A Brush that fills its area with a solid (or semi-transparent) colour.
  14150. An application won't normally need to use this class directly, as drawing
  14151. with solid colours is taken care of automatically by the Graphics class
  14152. (it actually uses one of these brushes internally when you set the colour
  14153. with the Graphics::setColour() method).
  14154. @see Brush, Graphics::setBrush, GradientBrush, ImageBrush
  14155. */
  14156. class JUCE_API SolidColourBrush : public Brush
  14157. {
  14158. public:
  14159. /** Creates a SolidColourBrush to draw with the given colour.
  14160. The colour can be changed later with the setColour() method.
  14161. */
  14162. SolidColourBrush (const Colour& colour) throw();
  14163. /** Creates a SolidColourBrush set to black.
  14164. The colour can be changed later with the setColour() method.
  14165. */
  14166. SolidColourBrush() throw();
  14167. /** Destructor. */
  14168. ~SolidColourBrush() throw();
  14169. /** Returns the colour currently being used. */
  14170. const Colour& getColour() const throw() { return colour; }
  14171. /** Sets the colour to use for drawing. */
  14172. void setColour (const Colour& newColour) throw() { colour = newColour; }
  14173. Brush* createCopy() const throw();
  14174. void applyTransform (const AffineTransform& transform) throw();
  14175. bool isInvisible() const throw();
  14176. void multiplyOpacity (const float multiple) throw();
  14177. void paintPath (LowLevelGraphicsContext& context,
  14178. const Path& path, const AffineTransform& transform) throw();
  14179. void paintRectangle (LowLevelGraphicsContext& context,
  14180. int x, int y, int w, int h) throw();
  14181. void paintAlphaChannel (LowLevelGraphicsContext& context,
  14182. const Image& alphaChannelImage, int imageX, int imageY,
  14183. int x, int y, int w, int h) throw();
  14184. void paintVerticalLine (LowLevelGraphicsContext& context,
  14185. int x, float y1, float y2) throw();
  14186. void paintHorizontalLine (LowLevelGraphicsContext& context,
  14187. int y, float x1, float x2) throw();
  14188. void paintLine (LowLevelGraphicsContext& context,
  14189. float x1, float y1, float x2, float y2) throw();
  14190. juce_UseDebuggingNewOperator
  14191. private:
  14192. Colour colour;
  14193. SolidColourBrush (const SolidColourBrush&);
  14194. const SolidColourBrush& operator= (const SolidColourBrush&);
  14195. };
  14196. #endif // __JUCE_SOLIDCOLOURBRUSH_JUCEHEADER__
  14197. /********* End of inlined file: juce_SolidColourBrush.h *********/
  14198. /********* Start of inlined file: juce_RectanglePlacement.h *********/
  14199. #ifndef __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
  14200. #define __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
  14201. /**
  14202. Defines the method used to postion some kind of rectangular object within
  14203. a rectangular viewport.
  14204. Although similar to Justification, this is more specific, and has some extra
  14205. options.
  14206. */
  14207. class JUCE_API RectanglePlacement
  14208. {
  14209. public:
  14210. /** Creates a RectanglePlacement object using a combination of flags. */
  14211. inline RectanglePlacement (const int flags_) throw() : flags (flags_) {}
  14212. /** Creates a copy of another Justification object. */
  14213. RectanglePlacement (const RectanglePlacement& other) throw();
  14214. /** Copies another Justification object. */
  14215. const RectanglePlacement& operator= (const RectanglePlacement& other) throw();
  14216. /** Flag values that can be combined and used in the constructor. */
  14217. enum
  14218. {
  14219. /** Indicates that the source rectangle's left edge should be aligned with the left edge of the target rectangle. */
  14220. xLeft = 1,
  14221. /** Indicates that the source rectangle's right edge should be aligned with the right edge of the target rectangle. */
  14222. xRight = 2,
  14223. /** Indicates that the source should be placed in the centre between the left and right
  14224. sides of the available space. */
  14225. xMid = 4,
  14226. /** Indicates that the source's top edge should be aligned with the top edge of the
  14227. destination rectangle. */
  14228. yTop = 8,
  14229. /** Indicates that the source's bottom edge should be aligned with the bottom edge of the
  14230. destination rectangle. */
  14231. yBottom = 16,
  14232. /** Indicates that the source should be placed in the centre between the top and bottom
  14233. sides of the available space. */
  14234. yMid = 32,
  14235. /** If this flag is set, then the source rectangle will be resized to completely fill
  14236. the destination rectangle, and all other flags are ignored.
  14237. */
  14238. stretchToFit = 64,
  14239. /** If this flag is set, then the source rectangle will be resized so that it is the
  14240. minimum size to completely fill the destination rectangle. This means that some
  14241. of the source rectangle may fall outside the destination.
  14242. If this flag is not set, the source will be given the maximum size at which none
  14243. of it falls outside the destination rectangle.
  14244. */
  14245. fillDestination = 128,
  14246. /** Indicates that the source rectangle can be reduced in size if required, but should
  14247. never be made larger than its original size.
  14248. */
  14249. onlyReduceInSize = 256,
  14250. /** Indicates that the source rectangle can be enlarged if required, but should
  14251. never be made smaller than its original size.
  14252. */
  14253. onlyIncreaseInSize = 512,
  14254. /** Indicates that the source rectangle's size should be left unchanged.
  14255. */
  14256. doNotResize = (onlyIncreaseInSize | onlyReduceInSize),
  14257. /** A shorthand value that is equivalent to (xMid | yMid). */
  14258. centred = 4 + 32
  14259. };
  14260. /** Returns the raw flags that are set for this object. */
  14261. inline int getFlags() const throw() { return flags; }
  14262. /** Tests a set of flags for this object.
  14263. @returns true if any of the flags passed in are set on this object.
  14264. */
  14265. inline bool testFlags (const int flagsToTest) const throw() { return (flags & flagsToTest) != 0; }
  14266. /** Adjusts the position and size of a rectangle to fit it into a space.
  14267. The source rectangle co-ordinates will be adjusted so that they fit into
  14268. the destination rectangle based on this object's flags.
  14269. */
  14270. void applyTo (double& sourceX,
  14271. double& sourceY,
  14272. double& sourceW,
  14273. double& sourceH,
  14274. const double destinationX,
  14275. const double destinationY,
  14276. const double destinationW,
  14277. const double destinationH) const throw();
  14278. /** Returns the transform that should be applied to these source co-ordinates to fit them
  14279. into the destination rectangle using the current flags.
  14280. */
  14281. const AffineTransform getTransformToFit (float sourceX,
  14282. float sourceY,
  14283. float sourceW,
  14284. float sourceH,
  14285. const float destinationX,
  14286. const float destinationY,
  14287. const float destinationW,
  14288. const float destinationH) const throw();
  14289. private:
  14290. int flags;
  14291. };
  14292. #endif // __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
  14293. /********* End of inlined file: juce_RectanglePlacement.h *********/
  14294. class LowLevelGraphicsContext;
  14295. class Image;
  14296. class RectangleList;
  14297. /**
  14298. A graphics context, used for drawing a component or image.
  14299. When a Component needs painting, a Graphics context is passed to its
  14300. Component::paint() method, and this you then call methods within this
  14301. object to actually draw the component's content.
  14302. A Graphics can also be created from an image, to allow drawing directly onto
  14303. that image.
  14304. @see Component::paint
  14305. */
  14306. class JUCE_API Graphics
  14307. {
  14308. public:
  14309. /** Creates a Graphics object to draw directly onto the given image.
  14310. The graphics object that is created will be set up to draw onto the image,
  14311. with the context's clipping area being the entire size of the image, and its
  14312. origin being the image's origin. To draw into a subsection of an image, use the
  14313. reduceClipRegion() and setOrigin() methods.
  14314. Obviously you shouldn't delete the image before this context is deleted.
  14315. */
  14316. Graphics (Image& imageToDrawOnto) throw();
  14317. /** Destructor. */
  14318. ~Graphics() throw();
  14319. /** Changes the current drawing colour.
  14320. This sets the colour that will now be used for drawing operations - it also
  14321. sets the opacity to that of the colour passed-in.
  14322. If a brush is being used when this method is called, the brush will be deselected,
  14323. and any subsequent drawing will be done with a solid colour brush instead.
  14324. @see setOpacity, setBrush, getColour
  14325. */
  14326. void setColour (const Colour& newColour) throw();
  14327. /** Returns the colour that's currently being used.
  14328. This will return the last colour set by setColour(), even if the colour's not
  14329. currently being used for drawing because a brush has been selected instead.
  14330. @see setColour
  14331. */
  14332. const Colour& getCurrentColour() const throw();
  14333. /** Changes the opacity to use with the current colour.
  14334. If a solid colour is being used for drawing, this changes its opacity (and this
  14335. will be reflected by calls to the getColour() method).
  14336. A value of 0.0 is completely transparent, 1.0 is completely opaque.
  14337. */
  14338. void setOpacity (const float newOpacity) throw();
  14339. /** Changes the current brush to use for drawing.
  14340. If a null pointer is passed in, the context will revert to using a solid
  14341. colour for drawing (using the last colour set by setColour()).
  14342. If a brush is passed in, a copy of it will be used for subsequent drawing
  14343. operations until setColour() or setBrush() is called.
  14344. @see SolidColourBrush, GradientBrush, ImageBrush, Brush
  14345. */
  14346. void setBrush (const Brush* const newBrush) throw();
  14347. /** Changes the font to use for subsequent text-drawing functions.
  14348. Note there's also a setFont (float, int) method to quickly change the size and
  14349. style of the current font.
  14350. @see drawSingleLineText, drawMultiLineText, drawTextAsPath, drawText, drawFittedText
  14351. */
  14352. void setFont (const Font& newFont) throw();
  14353. /** Changes the size and style of the currently-selected font.
  14354. This is a convenient shortcut that changes the context's current font to a
  14355. different size or style. The typeface won't be changed.
  14356. @see Font
  14357. */
  14358. void setFont (const float newFontHeight,
  14359. const int fontStyleFlags = Font::plain) throw();
  14360. /** Returns the font that's currently being used for text operations.
  14361. @see setFont
  14362. */
  14363. const Font& getCurrentFont() const throw();
  14364. /** Draws a one-line text string.
  14365. This will use the current colour (or brush) to fill the text. The font is the last
  14366. one specified by setFont().
  14367. @param text the string to draw
  14368. @param startX the position to draw the left-hand edge of the text
  14369. @param baselineY the position of the text's baseline
  14370. @see drawMultiLineText, drawText, drawFittedText, GlyphArrangement::addLineOfText
  14371. */
  14372. void drawSingleLineText (const String& text,
  14373. const int startX,
  14374. const int baselineY) const throw();
  14375. /** Draws text across multiple lines.
  14376. This will break the text onto a new line where there's a new-line or
  14377. carriage-return character, or at a word-boundary when the text becomes wider
  14378. than the size specified by the maximumLineWidth parameter.
  14379. @see setFont, drawSingleLineText, drawFittedText, GlyphArrangement::addJustifiedText
  14380. */
  14381. void drawMultiLineText (const String& text,
  14382. const int startX,
  14383. const int baselineY,
  14384. const int maximumLineWidth) const throw();
  14385. /** Renders a string of text as a vector path.
  14386. This allows a string to be transformed with an arbitrary AffineTransform and
  14387. rendered using the current colour/brush. It's much slower than the normal text methods
  14388. but more accurate.
  14389. @see setFont
  14390. */
  14391. void drawTextAsPath (const String& text,
  14392. const AffineTransform& transform) const throw();
  14393. /** Draws a line of text within a specified rectangle.
  14394. The text will be positioned within the rectangle based on the justification
  14395. flags passed-in. If the string is too long to fit inside the rectangle, it will
  14396. either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig
  14397. flag is true).
  14398. @see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText
  14399. */
  14400. void drawText (const String& text,
  14401. const int x,
  14402. const int y,
  14403. const int width,
  14404. const int height,
  14405. const Justification& justificationType,
  14406. const bool useEllipsesIfTooBig) const throw();
  14407. /** Tries to draw a text string inside a given space.
  14408. This does its best to make the given text readable within the specified rectangle,
  14409. so it useful for labelling things.
  14410. If the text is too big, it'll be squashed horizontally or broken over multiple lines
  14411. if the maximumLinesToUse value allows this. If the text just won't fit into the space,
  14412. it'll cram as much as possible in there, and put some ellipsis at the end to show that
  14413. it's been truncated.
  14414. A Justification parameter lets you specify how the text is laid out within the rectangle,
  14415. both horizontally and vertically.
  14416. The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally
  14417. to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you
  14418. can set this value to 1.0f.
  14419. @see GlyphArrangement::addFittedText
  14420. */
  14421. void drawFittedText (const String& text,
  14422. const int x,
  14423. const int y,
  14424. const int width,
  14425. const int height,
  14426. const Justification& justificationFlags,
  14427. const int maximumNumberOfLines,
  14428. const float minimumHorizontalScale = 0.7f) const throw();
  14429. /** Fills the context's entire clip region with the current colour or brush.
  14430. (See also the fillAll (const Colour&) method which is a quick way of filling
  14431. it with a given colour).
  14432. */
  14433. void fillAll() const throw();
  14434. /** Fills the context's entire clip region with a given colour.
  14435. This leaves the context's current colour and brush unchanged, it just
  14436. uses the specified colour temporarily.
  14437. */
  14438. void fillAll (const Colour& colourToUse) const throw();
  14439. /** Fills a rectangle with the current colour or brush.
  14440. @see drawRect, fillRoundedRectangle
  14441. */
  14442. void fillRect (int x,
  14443. int y,
  14444. int width,
  14445. int height) const throw();
  14446. /** Fills a rectangle with the current colour or brush. */
  14447. void fillRect (const Rectangle& rectangle) const throw();
  14448. /** Fills a rectangle with the current colour or brush.
  14449. This uses sub-pixel positioning so is slower than the fillRect method which
  14450. takes integer co-ordinates.
  14451. */
  14452. void fillRect (const float x,
  14453. const float y,
  14454. const float width,
  14455. const float height) const throw();
  14456. /** Uses the current colour or brush to fill a rectangle with rounded corners.
  14457. @see drawRoundedRectangle, Path::addRoundedRectangle
  14458. */
  14459. void fillRoundedRectangle (const float x,
  14460. const float y,
  14461. const float width,
  14462. const float height,
  14463. const float cornerSize) const throw();
  14464. /** Uses the current colour or brush to fill a rectangle with rounded corners.
  14465. @see drawRoundedRectangle, Path::addRoundedRectangle
  14466. */
  14467. void fillRoundedRectangle (const Rectangle& rectangle,
  14468. const float cornerSize) const throw();
  14469. /** Fills a rectangle with a checkerboard pattern, alternating between two colours.
  14470. */
  14471. void fillCheckerBoard (int x, int y,
  14472. int width, int height,
  14473. const int checkWidth,
  14474. const int checkHeight,
  14475. const Colour& colour1,
  14476. const Colour& colour2) const throw();
  14477. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  14478. The lines are drawn inside the given rectangle, and greater line thicknesses
  14479. extend inwards.
  14480. @see fillRect
  14481. */
  14482. void drawRect (const int x,
  14483. const int y,
  14484. const int width,
  14485. const int height,
  14486. const int lineThickness = 1) const throw();
  14487. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  14488. The lines are drawn inside the given rectangle, and greater line thicknesses
  14489. extend inwards.
  14490. @see fillRect
  14491. */
  14492. void drawRect (const float x,
  14493. const float y,
  14494. const float width,
  14495. const float height,
  14496. const float lineThickness = 1.0f) const throw();
  14497. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  14498. The lines are drawn inside the given rectangle, and greater line thicknesses
  14499. extend inwards.
  14500. @see fillRect
  14501. */
  14502. void drawRect (const Rectangle& rectangle,
  14503. const int lineThickness = 1) const throw();
  14504. /** Uses the current colour or brush to draw the outline of a rectangle with rounded corners.
  14505. @see fillRoundedRectangle, Path::addRoundedRectangle
  14506. */
  14507. void drawRoundedRectangle (const float x,
  14508. const float y,
  14509. const float width,
  14510. const float height,
  14511. const float cornerSize,
  14512. const float lineThickness) const throw();
  14513. /** Uses the current colour or brush to draw the outline of a rectangle with rounded corners.
  14514. @see fillRoundedRectangle, Path::addRoundedRectangle
  14515. */
  14516. void drawRoundedRectangle (const Rectangle& rectangle,
  14517. const float cornerSize,
  14518. const float lineThickness) const throw();
  14519. /** Draws a 3D raised (or indented) bevel using two colours.
  14520. The bevel is drawn inside the given rectangle, and greater bevel thicknesses
  14521. extend inwards.
  14522. The top-left colour is used for the top- and left-hand edges of the
  14523. bevel; the bottom-right colour is used for the bottom- and right-hand
  14524. edges.
  14525. */
  14526. void drawBevel (const int x,
  14527. const int y,
  14528. const int width,
  14529. const int height,
  14530. const int bevelThickness,
  14531. const Colour& topLeftColour = Colours::white,
  14532. const Colour& bottomRightColour = Colours::black,
  14533. const bool useGradient = true) const throw();
  14534. /** Draws a pixel using the current colour or brush.
  14535. */
  14536. void setPixel (int x, int y) const throw();
  14537. /** Fills an ellipse with the current colour or brush.
  14538. The ellipse is drawn to fit inside the given rectangle.
  14539. @see drawEllipse, Path::addEllipse
  14540. */
  14541. void fillEllipse (const float x,
  14542. const float y,
  14543. const float width,
  14544. const float height) const throw();
  14545. /** Draws an elliptical stroke using the current colour or brush.
  14546. @see fillEllipse, Path::addEllipse
  14547. */
  14548. void drawEllipse (const float x,
  14549. const float y,
  14550. const float width,
  14551. const float height,
  14552. const float lineThickness) const throw();
  14553. /** Draws a line between two points.
  14554. The line is 1 pixel wide and drawn with the current colour or brush.
  14555. */
  14556. void drawLine (float startX,
  14557. float startY,
  14558. float endX,
  14559. float endY) const throw();
  14560. /** Draws a line between two points with a given thickness.
  14561. @see Path::addLineSegment
  14562. */
  14563. void drawLine (const float startX,
  14564. const float startY,
  14565. const float endX,
  14566. const float endY,
  14567. const float lineThickness) const throw();
  14568. /** Draws a line between two points.
  14569. The line is 1 pixel wide and drawn with the current colour or brush.
  14570. */
  14571. void drawLine (const Line& line) const throw();
  14572. /** Draws a line between two points with a given thickness.
  14573. @see Path::addLineSegment
  14574. */
  14575. void drawLine (const Line& line,
  14576. const float lineThickness) const throw();
  14577. /** Draws a dashed line using a custom set of dash-lengths.
  14578. @param startX the line's start x co-ordinate
  14579. @param startY the line's start y co-ordinate
  14580. @param endX the line's end x co-ordinate
  14581. @param endY the line's end y co-ordinate
  14582. @param dashLengths a series of lengths to specify the on/off lengths - e.g.
  14583. { 4, 5, 6, 7 } will draw a line of 4 pixels, skip 5 pixels,
  14584. draw 6 pixels, skip 7 pixels, and then repeat.
  14585. @param numDashLengths the number of elements in the array (this must be an even number).
  14586. @param lineThickness the thickness of the line to draw
  14587. @see PathStrokeType::createDashedStroke
  14588. */
  14589. void drawDashedLine (const float startX,
  14590. const float startY,
  14591. const float endX,
  14592. const float endY,
  14593. const float* const dashLengths,
  14594. const int numDashLengths,
  14595. const float lineThickness = 1.0f) const throw();
  14596. /** Draws a vertical line of pixels at a given x position.
  14597. The x position is an integer, but the top and bottom of the line can be sub-pixel
  14598. positions, and these will be anti-aliased if necessary.
  14599. */
  14600. void drawVerticalLine (const int x, float top, float bottom) const throw();
  14601. /** Draws a horizontal line of pixels at a given y position.
  14602. The y position is an integer, but the left and right ends of the line can be sub-pixel
  14603. positions, and these will be anti-aliased if necessary.
  14604. */
  14605. void drawHorizontalLine (const int y, float left, float right) const throw();
  14606. /** Fills a path using the currently selected colour or brush.
  14607. */
  14608. void fillPath (const Path& path,
  14609. const AffineTransform& transform = AffineTransform::identity) const throw();
  14610. /** Draws a path's outline using the currently selected colour or brush.
  14611. */
  14612. void strokePath (const Path& path,
  14613. const PathStrokeType& strokeType,
  14614. const AffineTransform& transform = AffineTransform::identity) const throw();
  14615. /** Draws a line with an arrowhead.
  14616. @param startX the line's start x co-ordinate
  14617. @param startY the line's start y co-ordinate
  14618. @param endX the line's end x co-ordinate (the tip of the arrowhead)
  14619. @param endY the line's end y co-ordinate (the tip of the arrowhead)
  14620. @param lineThickness the thickness of the line
  14621. @param arrowheadWidth the width of the arrow head (perpendicular to the line)
  14622. @param arrowheadLength the length of the arrow head (along the length of the line)
  14623. */
  14624. void drawArrow (const float startX,
  14625. const float startY,
  14626. const float endX,
  14627. const float endY,
  14628. const float lineThickness,
  14629. const float arrowheadWidth,
  14630. const float arrowheadLength) const throw();
  14631. /** Types of rendering quality that can be specified when drawing images.
  14632. @see blendImage, Graphics::setImageResamplingQuality
  14633. */
  14634. enum ResamplingQuality
  14635. {
  14636. lowResamplingQuality = 0, /**< Just uses a nearest-neighbour algorithm for resampling. */
  14637. mediumResamplingQuality = 1, /**< Uses bilinear interpolation for upsampling and area-averaging for downsampling. */
  14638. highResamplingQuality = 2 /**< Uses bicubic interpolation for upsampling and area-averaging for downsampling. */
  14639. };
  14640. /** Changes the quality that will be used when resampling images.
  14641. By default a Graphics object will be set to mediumRenderingQuality.
  14642. @see Graphics::drawImage, Graphics::drawImageTransformed, Graphics::drawImageWithin
  14643. */
  14644. void setImageResamplingQuality (const ResamplingQuality newQuality) throw();
  14645. /** Draws an image.
  14646. This will draw the whole of an image, positioning its top-left corner at the
  14647. given co-ordinates, and keeping its size the same. This is the simplest image
  14648. drawing method - the others give more control over the scaling and clipping
  14649. of the images.
  14650. Images are composited using the context's current opacity, so if you
  14651. don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f)
  14652. (or setColour() with an opaque colour) before drawing images.
  14653. */
  14654. void drawImageAt (const Image* const imageToDraw,
  14655. const int topLeftX,
  14656. const int topLeftY,
  14657. const bool fillAlphaChannelWithCurrentBrush = false) const throw();
  14658. /** Draws part of an image, rescaling it to fit in a given target region.
  14659. The specified area of the source image is rescaled and drawn to fill the
  14660. specifed destination rectangle.
  14661. Images are composited using the context's current opacity, so if you
  14662. don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f)
  14663. (or setColour() with an opaque colour) before drawing images.
  14664. @param imageToDraw the image to overlay
  14665. @param destX the left of the destination rectangle
  14666. @param destY the top of the destination rectangle
  14667. @param destWidth the width of the destination rectangle
  14668. @param destHeight the height of the destination rectangle
  14669. @param sourceX the left of the rectangle to copy from the source image
  14670. @param sourceY the top of the rectangle to copy from the source image
  14671. @param sourceWidth the width of the rectangle to copy from the source image
  14672. @param sourceHeight the height of the rectangle to copy from the source image
  14673. @param fillAlphaChannelWithCurrentBrush if true, then instead of drawing the source image's pixels,
  14674. the source image's alpha channel is used as a mask with
  14675. which to fill the destination using the current colour
  14676. or brush. (If the source is has no alpha channel, then
  14677. it will just fill the target with a solid rectangle)
  14678. @see setImageResamplingQuality, drawImageAt, drawImageWithin, fillAlphaMap
  14679. */
  14680. void drawImage (const Image* const imageToDraw,
  14681. int destX,
  14682. int destY,
  14683. int destWidth,
  14684. int destHeight,
  14685. int sourceX,
  14686. int sourceY,
  14687. int sourceWidth,
  14688. int sourceHeight,
  14689. const bool fillAlphaChannelWithCurrentBrush = false) const throw();
  14690. /** Draws part of an image, having applied an affine transform to it.
  14691. This lets you throw the image around in some wacky ways, rotate it, shear,
  14692. scale it, etc.
  14693. A clipping subregion is specified within the source image and no pixels
  14694. outside this region will be used.
  14695. Images are composited using the context's current opacity, so if you
  14696. don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f)
  14697. (or setColour() with an opaque colour) before drawing images.
  14698. If fillAlphaChannelWithCurrentBrush is set to true, then the image's RGB channels
  14699. are ignored and it is filled with the current brush, masked by its alpha channel.
  14700. @see setImageResamplingQuality, drawImage
  14701. */
  14702. void drawImageTransformed (const Image* const imageToDraw,
  14703. int sourceClipX,
  14704. int sourceClipY,
  14705. int sourceClipWidth,
  14706. int sourceClipHeight,
  14707. const AffineTransform& transform,
  14708. const bool fillAlphaChannelWithCurrentBrush = false) const throw();
  14709. /** Draws an image to fit within a designated rectangle.
  14710. If the image is too big or too small for the space, it will be rescaled
  14711. to fit as nicely as it can do without affecting its aspect ratio. It will
  14712. then be placed within the target rectangle according to the justification flags
  14713. specified.
  14714. @param imageToDraw the source image to draw
  14715. @param destX top-left of the target rectangle to fit it into
  14716. @param destY top-left of the target rectangle to fit it into
  14717. @param destWidth size of the target rectangle to fit the image into
  14718. @param destHeight size of the target rectangle to fit the image into
  14719. @param placementWithinTarget this specifies how the image should be positioned
  14720. within the target rectangle - see the RectanglePlacement
  14721. class for more details about this.
  14722. @param fillAlphaChannelWithCurrentBrush if true, then instead of drawing the image, just its
  14723. alpha channel will be used as a mask with which to
  14724. draw with the current brush or colour. This is
  14725. similar to fillAlphaMap(), and see also drawImage()
  14726. @see setImageResamplingQuality, drawImage, drawImageTransformed, drawImageAt, RectanglePlacement
  14727. */
  14728. void drawImageWithin (const Image* const imageToDraw,
  14729. const int destX,
  14730. const int destY,
  14731. const int destWidth,
  14732. const int destHeight,
  14733. const RectanglePlacement& placementWithinTarget,
  14734. const bool fillAlphaChannelWithCurrentBrush = false) const throw();
  14735. /** Returns the position of the bounding box for the current clipping region.
  14736. @see getClipRegion, clipRegionIntersects
  14737. */
  14738. const Rectangle getClipBounds() const throw();
  14739. /** Checks whether a rectangle overlaps the context's clipping region.
  14740. If this returns false, no part of the given area can be drawn onto, so this
  14741. method can be used to optimise a component's paint() method, by letting it
  14742. avoid drawing complex objects that aren't within the region being repainted.
  14743. */
  14744. bool clipRegionIntersects (const int x, const int y, const int width, const int height) const throw();
  14745. /** Intersects the current clipping region with another region.
  14746. @returns true if the resulting clipping region is non-zero in size
  14747. @see setOrigin, clipRegionIntersects, getClipLeft, getClipRight, getClipWidth, getClipHeight
  14748. */
  14749. bool reduceClipRegion (const int x, const int y,
  14750. const int width, const int height) throw();
  14751. /** Intersects the current clipping region with a rectangle list region.
  14752. @returns true if the resulting clipping region is non-zero in size
  14753. @see setOrigin, clipRegionIntersects, getClipLeft, getClipRight, getClipWidth, getClipHeight
  14754. */
  14755. bool reduceClipRegion (const RectangleList& clipRegion) throw();
  14756. /** Excludes a rectangle to stop it being drawn into. */
  14757. void excludeClipRegion (const int x, const int y,
  14758. const int width, const int height) throw();
  14759. /** Returns true if no drawing can be done because the clip region is zero. */
  14760. bool isClipEmpty() const throw();
  14761. /** Saves the current graphics state on an internal stack.
  14762. To restore the state, use restoreState().
  14763. */
  14764. void saveState() throw();
  14765. /** Restores a graphics state that was previously saved with saveState().
  14766. */
  14767. void restoreState() throw();
  14768. /** Moves the position of the context's origin.
  14769. This changes the position that the context considers to be (0, 0) to
  14770. the specified position.
  14771. So if you call setOrigin (100, 100), then the position that was previously
  14772. referred to as (100, 100) will subsequently be considered to be (0, 0).
  14773. @see reduceClipRegion
  14774. */
  14775. void setOrigin (const int newOriginX,
  14776. const int newOriginY) throw();
  14777. /** Resets the current colour, brush, and font to default settings. */
  14778. void resetToDefaultState() throw();
  14779. /** Returns true if this context is drawing to a vector-based device, such as a printer. */
  14780. bool isVectorDevice() const throw();
  14781. juce_UseDebuggingNewOperator
  14782. /** Create a graphics that uses a given low-level renderer.
  14783. For internal use only.
  14784. NB. The context will NOT be deleted by this object when it is deleted.
  14785. */
  14786. Graphics (LowLevelGraphicsContext* const internalContext) throw();
  14787. /** @internal */
  14788. LowLevelGraphicsContext* getInternalContext() const throw() { return context; }
  14789. private:
  14790. LowLevelGraphicsContext* const context;
  14791. const bool ownsContext;
  14792. struct GraphicsState
  14793. {
  14794. GraphicsState() throw();
  14795. GraphicsState (const GraphicsState&) throw();
  14796. ~GraphicsState() throw();
  14797. Colour colour;
  14798. Brush* brush;
  14799. Font font;
  14800. ResamplingQuality quality;
  14801. };
  14802. GraphicsState* state;
  14803. OwnedArray <GraphicsState> stateStack;
  14804. bool saveStatePending;
  14805. void saveStateIfPending() throw();
  14806. const Graphics& operator= (const Graphics& other);
  14807. Graphics (const Graphics&);
  14808. };
  14809. #endif // __JUCE_GRAPHICS_JUCEHEADER__
  14810. /********* End of inlined file: juce_Graphics.h *********/
  14811. /**
  14812. A graphical effect filter that can be applied to components.
  14813. An ImageEffectFilter can be applied to the image that a component
  14814. paints before it hits the screen.
  14815. This is used for adding effects like shadows, blurs, etc.
  14816. @see Component::setComponentEffect
  14817. */
  14818. class JUCE_API ImageEffectFilter
  14819. {
  14820. public:
  14821. /** Overridden to render the effect.
  14822. The implementation of this method must use the image that is passed in
  14823. as its source, and should render its output to the graphics context passed in.
  14824. @param sourceImage the image that the source component has just rendered with
  14825. its paint() method. The image may or may not have an alpha
  14826. channel, depending on whether the component is opaque.
  14827. @param destContext the graphics context to use to draw the resultant image.
  14828. */
  14829. virtual void applyEffect (Image& sourceImage,
  14830. Graphics& destContext) = 0;
  14831. /** Destructor. */
  14832. virtual ~ImageEffectFilter() {}
  14833. };
  14834. #endif // __JUCE_IMAGEEFFECTFILTER_JUCEHEADER__
  14835. /********* End of inlined file: juce_ImageEffectFilter.h *********/
  14836. /********* Start of inlined file: juce_RectangleList.h *********/
  14837. #ifndef __JUCE_RECTANGLELIST_JUCEHEADER__
  14838. #define __JUCE_RECTANGLELIST_JUCEHEADER__
  14839. /**
  14840. Maintains a set of rectangles as a complex region.
  14841. This class allows a set of rectangles to be treated as a solid shape, and can
  14842. add and remove rectangular sections of it, and simplify overlapping or
  14843. adjacent rectangles.
  14844. @see Rectangle
  14845. */
  14846. class JUCE_API RectangleList
  14847. {
  14848. public:
  14849. /** Creates an empty RectangleList */
  14850. RectangleList() throw();
  14851. /** Creates a copy of another list */
  14852. RectangleList (const RectangleList& other) throw();
  14853. /** Creates a list containing just one rectangle. */
  14854. RectangleList (const Rectangle& rect) throw();
  14855. /** Copies this list from another one. */
  14856. const RectangleList& operator= (const RectangleList& other) throw();
  14857. /** Destructor. */
  14858. ~RectangleList() throw();
  14859. /** Returns true if the region is empty. */
  14860. bool isEmpty() const throw();
  14861. /** Returns the number of rectangles in the list. */
  14862. int getNumRectangles() const throw() { return rects.size(); }
  14863. /** Returns one of the rectangles at a particular index.
  14864. @returns the rectangle at the index, or an empty rectangle if the
  14865. index is out-of-range.
  14866. */
  14867. const Rectangle getRectangle (const int index) const throw();
  14868. /** Removes all rectangles to leave an empty region. */
  14869. void clear() throw();
  14870. /** Merges a new rectangle into the list.
  14871. The rectangle being added will first be clipped to remove any parts of it
  14872. that overlap existing rectangles in the list.
  14873. */
  14874. void add (const int x, const int y,
  14875. const int w, const int h) throw();
  14876. /** Merges a new rectangle into the list.
  14877. The rectangle being added will first be clipped to remove any parts of it
  14878. that overlap existing rectangles in the list, and adjacent rectangles will be
  14879. merged into it.
  14880. */
  14881. void add (const Rectangle& rect) throw();
  14882. /** Dumbly adds a rectangle to the list without checking for overlaps.
  14883. This simply adds the rectangle to the end, it doesn't merge it or remove
  14884. any overlapping bits.
  14885. */
  14886. void addWithoutMerging (const Rectangle& rect) throw();
  14887. /** Merges another rectangle list into this one.
  14888. Any overlaps between the two lists will be clipped, so that the result is
  14889. the union of both lists.
  14890. */
  14891. void add (const RectangleList& other) throw();
  14892. /** Removes a rectangular region from the list.
  14893. Any rectangles in the list which overlap this will be clipped and subdivided
  14894. if necessary.
  14895. */
  14896. void subtract (const Rectangle& rect) throw();
  14897. /** Removes all areas in another RectangleList from this one.
  14898. Any rectangles in the list which overlap this will be clipped and subdivided
  14899. if necessary.
  14900. */
  14901. void subtract (const RectangleList& otherList) throw();
  14902. /** Removes any areas of the region that lie outside a given rectangle.
  14903. Any rectangles in the list which overlap this will be clipped and subdivided
  14904. if necessary.
  14905. Returns true if the resulting region is not empty, false if it is empty.
  14906. @see getIntersectionWith
  14907. */
  14908. bool clipTo (const Rectangle& rect) throw();
  14909. /** Removes any areas of the region that lie outside a given rectangle list.
  14910. Any rectangles in this object which overlap the specified list will be clipped
  14911. and subdivided if necessary.
  14912. Returns true if the resulting region is not empty, false if it is empty.
  14913. @see getIntersectionWith
  14914. */
  14915. bool clipTo (const RectangleList& other) throw();
  14916. /** Creates a region which is the result of clipping this one to a given rectangle.
  14917. Unlike the other clipTo method, this one doesn't affect this object - it puts the
  14918. resulting region into the list whose reference is passed-in.
  14919. Returns true if the resulting region is not empty, false if it is empty.
  14920. @see clipTo
  14921. */
  14922. bool getIntersectionWith (const Rectangle& rect, RectangleList& destRegion) const throw();
  14923. /** Swaps the contents of this and another list.
  14924. This swaps their internal pointers, so is hugely faster than using copy-by-value
  14925. to swap them.
  14926. */
  14927. void swapWith (RectangleList& otherList) throw();
  14928. /** Checks whether the region contains a given point.
  14929. @returns true if the point lies within one of the rectangles in the list
  14930. */
  14931. bool containsPoint (const int x, const int y) const throw();
  14932. /** Checks whether the region contains the whole of a given rectangle.
  14933. @returns true all parts of the rectangle passed in lie within the region
  14934. defined by this object
  14935. @see intersectsRectangle, containsPoint
  14936. */
  14937. bool containsRectangle (const Rectangle& rectangleToCheck) const throw();
  14938. /** Checks whether the region contains any part of a given rectangle.
  14939. @returns true if any part of the rectangle passed in lies within the region
  14940. defined by this object
  14941. @see containsRectangle
  14942. */
  14943. bool intersectsRectangle (const Rectangle& rectangleToCheck) const throw();
  14944. /** Checks whether this region intersects any part of another one.
  14945. @see intersectsRectangle
  14946. */
  14947. bool intersects (const RectangleList& other) const throw();
  14948. /** Returns the smallest rectangle that can enclose the whole of this region. */
  14949. const Rectangle getBounds() const throw();
  14950. /** Optimises the list into a minimum number of constituent rectangles.
  14951. This will try to combine any adjacent rectangles into larger ones where
  14952. possible, to simplify lists that might have been fragmented by repeated
  14953. add/subtract calls.
  14954. */
  14955. void consolidate() throw();
  14956. /** Adds an x and y value to all the co-ordinates. */
  14957. void offsetAll (const int dx, const int dy) throw();
  14958. /** Creates a Path object to represent this region. */
  14959. const Path toPath() const throw();
  14960. /** An iterator for accessing all the rectangles in a RectangleList. */
  14961. class Iterator
  14962. {
  14963. public:
  14964. Iterator (const RectangleList& list) throw();
  14965. ~Iterator() throw();
  14966. /** Advances to the next rectangle, and returns true if it's not finished.
  14967. Call this before using getRectangle() to find the rectangle that was returned.
  14968. */
  14969. bool next() throw();
  14970. /** Returns the current rectangle. */
  14971. const Rectangle* getRectangle() const throw() { return current; }
  14972. juce_UseDebuggingNewOperator
  14973. private:
  14974. const Rectangle* current;
  14975. const RectangleList& owner;
  14976. int index;
  14977. Iterator (const Iterator&);
  14978. const Iterator& operator= (const Iterator&);
  14979. };
  14980. juce_UseDebuggingNewOperator
  14981. private:
  14982. friend class Iterator;
  14983. Array <Rectangle> rects;
  14984. };
  14985. #endif // __JUCE_RECTANGLELIST_JUCEHEADER__
  14986. /********* End of inlined file: juce_RectangleList.h *********/
  14987. /********* Start of inlined file: juce_BorderSize.h *********/
  14988. #ifndef __JUCE_BORDERSIZE_JUCEHEADER__
  14989. #define __JUCE_BORDERSIZE_JUCEHEADER__
  14990. /**
  14991. Specifies a set of gaps to be left around the sides of a rectangle.
  14992. This is basically the size of the spaces at the top, bottom, left and right of
  14993. a rectangle. It's used by various component classes to specify borders.
  14994. @see Rectangle
  14995. */
  14996. class JUCE_API BorderSize
  14997. {
  14998. public:
  14999. /** Creates a null border.
  15000. All sizes are left as 0.
  15001. */
  15002. BorderSize() throw();
  15003. /** Creates a copy of another border. */
  15004. BorderSize (const BorderSize& other) throw();
  15005. /** Creates a border with the given gaps. */
  15006. BorderSize (const int topGap,
  15007. const int leftGap,
  15008. const int bottomGap,
  15009. const int rightGap) throw();
  15010. /** Creates a border with the given gap on all sides. */
  15011. BorderSize (const int allGaps) throw();
  15012. /** Destructor. */
  15013. ~BorderSize() throw();
  15014. /** Returns the gap that should be left at the top of the region. */
  15015. int getTop() const throw() { return top; }
  15016. /** Returns the gap that should be left at the top of the region. */
  15017. int getLeft() const throw() { return left; }
  15018. /** Returns the gap that should be left at the top of the region. */
  15019. int getBottom() const throw() { return bottom; }
  15020. /** Returns the gap that should be left at the top of the region. */
  15021. int getRight() const throw() { return right; }
  15022. /** Returns the sum of the top and bottom gaps. */
  15023. int getTopAndBottom() const throw() { return top + bottom; }
  15024. /** Returns the sum of the left and right gaps. */
  15025. int getLeftAndRight() const throw() { return left + right; }
  15026. /** Changes the top gap. */
  15027. void setTop (const int newTopGap) throw();
  15028. /** Changes the left gap. */
  15029. void setLeft (const int newLeftGap) throw();
  15030. /** Changes the bottom gap. */
  15031. void setBottom (const int newBottomGap) throw();
  15032. /** Changes the right gap. */
  15033. void setRight (const int newRightGap) throw();
  15034. /** Returns a rectangle with these borders removed from it. */
  15035. const Rectangle subtractedFrom (const Rectangle& original) const throw();
  15036. /** Removes this border from a given rectangle. */
  15037. void subtractFrom (Rectangle& rectangle) const throw();
  15038. /** Returns a rectangle with these borders added around it. */
  15039. const Rectangle addedTo (const Rectangle& original) const throw();
  15040. /** Adds this border around a given rectangle. */
  15041. void addTo (Rectangle& original) const throw();
  15042. bool operator== (const BorderSize& other) const throw();
  15043. bool operator!= (const BorderSize& other) const throw();
  15044. juce_UseDebuggingNewOperator
  15045. private:
  15046. int top, left, bottom, right;
  15047. };
  15048. #endif // __JUCE_BORDERSIZE_JUCEHEADER__
  15049. /********* End of inlined file: juce_BorderSize.h *********/
  15050. /********* Start of inlined file: juce_ComponentPeer.h *********/
  15051. #ifndef __JUCE_COMPONENTPEER_JUCEHEADER__
  15052. #define __JUCE_COMPONENTPEER_JUCEHEADER__
  15053. class Component;
  15054. class Graphics;
  15055. /********* Start of inlined file: juce_MessageListener.h *********/
  15056. #ifndef __JUCE_MESSAGELISTENER_JUCEHEADER__
  15057. #define __JUCE_MESSAGELISTENER_JUCEHEADER__
  15058. /********* Start of inlined file: juce_Message.h *********/
  15059. #ifndef __JUCE_MESSAGE_JUCEHEADER__
  15060. #define __JUCE_MESSAGE_JUCEHEADER__
  15061. class MessageListener;
  15062. /** The base class for objects that can be delivered to a MessageListener.
  15063. The simplest Message object contains a few integer and pointer parameters
  15064. that the user can set, and this is enough for a lot of purposes. For passing more
  15065. complex data, subclasses of Message can also be used.
  15066. @see MessageListener, MessageManager, ActionListener, ChangeListener
  15067. */
  15068. class JUCE_API Message
  15069. {
  15070. public:
  15071. /** Creates an uninitialised message.
  15072. The class's variables will also be left uninitialised.
  15073. */
  15074. Message() throw();
  15075. /** Creates a message object, filling in the member variables.
  15076. The corresponding public member variables will be set from the parameters
  15077. passed in.
  15078. */
  15079. Message (const int intParameter1,
  15080. const int intParameter2,
  15081. const int intParameter3,
  15082. void* const pointerParameter) throw();
  15083. /** Destructor. */
  15084. virtual ~Message() throw();
  15085. // These values can be used for carrying simple data that the application needs to
  15086. // pass around. For more complex messages, just create a subclass.
  15087. int intParameter1; /**< user-defined integer value. */
  15088. int intParameter2; /**< user-defined integer value. */
  15089. int intParameter3; /**< user-defined integer value. */
  15090. void* pointerParameter; /**< user-defined pointer value. */
  15091. juce_UseDebuggingNewOperator
  15092. private:
  15093. friend class MessageListener;
  15094. friend class MessageManager;
  15095. MessageListener* messageRecipient;
  15096. Message (const Message&);
  15097. const Message& operator= (const Message&);
  15098. };
  15099. #endif // __JUCE_MESSAGE_JUCEHEADER__
  15100. /********* End of inlined file: juce_Message.h *********/
  15101. /**
  15102. MessageListener subclasses can post and receive Message objects.
  15103. @see Message, MessageManager, ActionListener, ChangeListener
  15104. */
  15105. class JUCE_API MessageListener
  15106. {
  15107. protected:
  15108. /** Creates a MessageListener. */
  15109. MessageListener() throw();
  15110. public:
  15111. /** Destructor.
  15112. When a MessageListener is deleted, it removes itself from a global list
  15113. of registered listeners, so that the isValidMessageListener() method
  15114. will no longer return true.
  15115. */
  15116. virtual ~MessageListener();
  15117. /** This is the callback method that receives incoming messages.
  15118. This is called by the MessageManager from its dispatch loop.
  15119. @see postMessage
  15120. */
  15121. virtual void handleMessage (const Message& message) = 0;
  15122. /** Sends a message to the message queue, for asynchronous delivery to this listener
  15123. later on.
  15124. This method can be called safely by any thread.
  15125. @param message the message object to send - this will be deleted
  15126. automatically by the message queue, so don't keep any
  15127. references to it after calling this method.
  15128. @see handleMessage
  15129. */
  15130. void postMessage (Message* const message) const throw();
  15131. /** Checks whether this MessageListener has been deleted.
  15132. Although not foolproof, this method is safe to call on dangling or null
  15133. pointers. A list of active MessageListeners is kept internally, so this
  15134. checks whether the object is on this list or not.
  15135. Note that it's possible to get a false-positive here, if an object is
  15136. deleted and another is subsequently created that happens to be at the
  15137. exact same memory location, but I can't think of a good way of avoiding
  15138. this.
  15139. */
  15140. bool isValidMessageListener() const throw();
  15141. };
  15142. #endif // __JUCE_MESSAGELISTENER_JUCEHEADER__
  15143. /********* End of inlined file: juce_MessageListener.h *********/
  15144. class ComponentBoundsConstrainer;
  15145. class ComponentDeletionWatcher;
  15146. /**
  15147. The base class for window objects that wrap a component as a real operating
  15148. system object.
  15149. This is an abstract base class - the platform specific code contains default
  15150. implementations of it that create and manage windows.
  15151. @see Component::createNewPeer
  15152. */
  15153. class JUCE_API ComponentPeer : public MessageListener
  15154. {
  15155. public:
  15156. /** A combination of these flags is passed to the ComponentPeer constructor. */
  15157. enum StyleFlags
  15158. {
  15159. windowAppearsOnTaskbar = (1 << 0), /**< Indicates that the window should have a corresponding
  15160. entry on the taskbar (ignored on MacOSX) */
  15161. windowIsTemporary = (1 << 1), /**< Indicates that the window is a temporary popup, like a menu,
  15162. tooltip, etc. */
  15163. windowIgnoresMouseClicks = (1 << 2), /**< Indicates that the window should let mouse clicks pass
  15164. through it (may not be possible on some platforms). */
  15165. windowHasTitleBar = (1 << 3), /**< Indicates that the window should have a normal OS-specific
  15166. title bar and frame\. if not specified, the window will be
  15167. borderless. */
  15168. windowIsResizable = (1 << 4), /**< Indicates that the window should let mouse clicks pass
  15169. through it (may not be possible on some platforms). */
  15170. windowHasMinimiseButton = (1 << 5), /**< Indicates that if the window has a title bar, it should have a
  15171. minimise button on it. */
  15172. windowHasMaximiseButton = (1 << 6), /**< Indicates that if the window has a title bar, it should have a
  15173. maximise button on it. */
  15174. windowHasCloseButton = (1 << 7), /**< Indicates that if the window has a title bar, it should have a
  15175. close button on it. */
  15176. windowHasDropShadow = (1 << 8), /**< Indicates that the window should have a drop-shadow (this may
  15177. not be possible on all platforms). */
  15178. windowRepaintedExplictly = (1 << 9), /**< Not intended for public use - this tells a window not to
  15179. do its own repainting, but only to repaint when the
  15180. performAnyPendingRepaintsNow() method is called. */
  15181. windowIsSemiTransparent = (1 << 31) /**< Not intended for public use - makes a window transparent. */
  15182. };
  15183. /** Creates a peer.
  15184. The component is the one that we intend to represent, and the style flags are
  15185. a combination of the values in the StyleFlags enum
  15186. */
  15187. ComponentPeer (Component* const component,
  15188. const int styleFlags) throw();
  15189. /** Destructor. */
  15190. virtual ~ComponentPeer();
  15191. /** Returns the component being represented by this peer. */
  15192. Component* getComponent() const throw() { return component; }
  15193. /** Returns the set of style flags that were set when the window was created.
  15194. @see Component::addToDesktop
  15195. */
  15196. int getStyleFlags() const throw() { return styleFlags; }
  15197. /** Returns the raw handle to whatever kind of window is being used.
  15198. On windows, this is probably a HWND, on the mac, it's likely to be a WindowRef,
  15199. but rememeber there's no guarantees what you'll get back.
  15200. */
  15201. virtual void* getNativeHandle() const = 0;
  15202. /** Shows or hides the window. */
  15203. virtual void setVisible (bool shouldBeVisible) = 0;
  15204. /** Changes the title of the window. */
  15205. virtual void setTitle (const String& title) = 0;
  15206. /** Moves the window without changing its size.
  15207. If the native window is contained in another window, then the co-ordinates are
  15208. relative to the parent window's origin, not the screen origin.
  15209. This should result in a callback to handleMovedOrResized().
  15210. */
  15211. virtual void setPosition (int x, int y) = 0;
  15212. /** Resizes the window without changing its position.
  15213. This should result in a callback to handleMovedOrResized().
  15214. */
  15215. virtual void setSize (int w, int h) = 0;
  15216. /** Moves and resizes the window.
  15217. If the native window is contained in another window, then the co-ordinates are
  15218. relative to the parent window's origin, not the screen origin.
  15219. This should result in a callback to handleMovedOrResized().
  15220. */
  15221. virtual void setBounds (int x, int y, int w, int h, const bool isNowFullScreen) = 0;
  15222. /** Returns the current position and size of the window.
  15223. If the native window is contained in another window, then the co-ordinates are
  15224. relative to the parent window's origin, not the screen origin.
  15225. */
  15226. virtual void getBounds (int& x, int& y, int& w, int& h) const = 0;
  15227. /** Returns the x-position of this window, relative to the screen's origin. */
  15228. virtual int getScreenX() const = 0;
  15229. /** Returns the y-position of this window, relative to the screen's origin. */
  15230. virtual int getScreenY() const = 0;
  15231. /** Converts a position relative to the top-left of this component to screen co-ordinates. */
  15232. virtual void relativePositionToGlobal (int& x, int& y) = 0;
  15233. /** Converts a screen co-ordinate to a position relative to the top-left of this component. */
  15234. virtual void globalPositionToRelative (int& x, int& y) = 0;
  15235. /** Minimises the window. */
  15236. virtual void setMinimised (bool shouldBeMinimised) = 0;
  15237. /** True if the window is currently minimised. */
  15238. virtual bool isMinimised() const = 0;
  15239. /** Enable/disable fullscreen mode for the window. */
  15240. virtual void setFullScreen (bool shouldBeFullScreen) = 0;
  15241. /** True if the window is currently full-screen. */
  15242. virtual bool isFullScreen() const = 0;
  15243. /** Sets the size to restore to if fullscreen mode is turned off. */
  15244. void setNonFullScreenBounds (const Rectangle& newBounds) throw();
  15245. /** Returns the size to restore to if fullscreen mode is turned off. */
  15246. const Rectangle& getNonFullScreenBounds() const throw();
  15247. /** Attempts to change the icon associated with this window.
  15248. */
  15249. virtual void setIcon (const Image& newIcon) = 0;
  15250. /** Sets a constrainer to use if the peer can resize itself.
  15251. The constrainer won't be deleted by this object, so the caller must manage its lifetime.
  15252. */
  15253. void setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw();
  15254. /** Returns the current constrainer, if one has been set. */
  15255. ComponentBoundsConstrainer* getConstrainer() const throw() { return constrainer; }
  15256. /** Checks if a point is in the window.
  15257. Coordinates are relative to the top-left of this window. If trueIfInAChildWindow
  15258. is false, then this returns false if the point is actually inside a child of this
  15259. window.
  15260. */
  15261. virtual bool contains (int x, int y, bool trueIfInAChildWindow) const = 0;
  15262. /** Returns the size of the window frame that's around this window.
  15263. Whether or not the window has a normal window frame depends on the flags
  15264. that were set when the window was created by Component::addToDesktop()
  15265. */
  15266. virtual const BorderSize getFrameSize() const = 0;
  15267. /** This is called when the window's bounds change.
  15268. A peer implementation must call this when the window is moved and resized, so that
  15269. this method can pass the message on to the component.
  15270. */
  15271. void handleMovedOrResized();
  15272. /** This is called if the screen resolution changes.
  15273. A peer implementation must call this if the monitor arrangement changes or the available
  15274. screen size changes.
  15275. */
  15276. void handleScreenSizeChange();
  15277. /** This is called to repaint the component into the given context. */
  15278. void handlePaint (LowLevelGraphicsContext& contextToPaintTo);
  15279. /** Sets this window to either be always-on-top or normal.
  15280. Some kinds of window might not be able to do this, so should return false.
  15281. */
  15282. virtual bool setAlwaysOnTop (bool alwaysOnTop) = 0;
  15283. /** Brings the window to the top, optionally also giving it focus. */
  15284. virtual void toFront (bool makeActive) = 0;
  15285. /** Moves the window to be just behind another one. */
  15286. virtual void toBehind (ComponentPeer* other) = 0;
  15287. /** Called when the window is brought to the front, either by the OS or by a call
  15288. to toFront().
  15289. */
  15290. void handleBroughtToFront();
  15291. /** True if the window has the keyboard focus. */
  15292. virtual bool isFocused() const = 0;
  15293. /** Tries to give the window keyboard focus. */
  15294. virtual void grabFocus() = 0;
  15295. /** Tells the window that text input may be required at the given position.
  15296. This may cause things like a virtual on-screen keyboard to appear, depending
  15297. on the OS.
  15298. */
  15299. virtual void textInputRequired (int x, int y) = 0;
  15300. /** Called when the window gains keyboard focus. */
  15301. void handleFocusGain();
  15302. /** Called when the window loses keyboard focus. */
  15303. void handleFocusLoss();
  15304. Component* getLastFocusedSubcomponent() const throw();
  15305. /** Called when a key is pressed.
  15306. For keycode info, see the KeyPress class.
  15307. Returns true if the keystroke was used.
  15308. */
  15309. bool handleKeyPress (const int keyCode,
  15310. const juce_wchar textCharacter);
  15311. /** Called whenever a key is pressed or released.
  15312. Returns true if the keystroke was used.
  15313. */
  15314. bool handleKeyUpOrDown();
  15315. /** Called whenever a modifier key is pressed or released. */
  15316. void handleModifierKeysChange();
  15317. /** Invalidates a region of the window to be repainted asynchronously. */
  15318. virtual void repaint (int x, int y, int w, int h) = 0;
  15319. /** This can be called (from the message thread) to cause the immediate redrawing
  15320. of any areas of this window that need repainting.
  15321. You shouldn't ever really need to use this, it's mainly for special purposes
  15322. like supporting audio plugins where the host's event loop is out of our control.
  15323. */
  15324. virtual void performAnyPendingRepaintsNow() = 0;
  15325. void handleMouseEnter (int x, int y, const int64 time);
  15326. void handleMouseMove (int x, int y, const int64 time);
  15327. void handleMouseDown (int x, int y, const int64 time);
  15328. void handleMouseDrag (int x, int y, const int64 time);
  15329. void handleMouseUp (const int oldModifiers, int x, int y, const int64 time);
  15330. void handleMouseExit (int x, int y, const int64 time);
  15331. void handleMouseWheel (const int amountX, const int amountY, const int64 time);
  15332. /** Causes a mouse-move callback to be made asynchronously. */
  15333. void sendFakeMouseMove() throw();
  15334. void handleUserClosingWindow();
  15335. void handleFileDragMove (const StringArray& files, int x, int y);
  15336. void handleFileDragExit (const StringArray& files);
  15337. void handleFileDragDrop (const StringArray& files, int x, int y);
  15338. /** Resets the masking region.
  15339. The subclass should call this every time it's about to call the handlePaint
  15340. method.
  15341. @see addMaskedRegion
  15342. */
  15343. void clearMaskedRegion() throw();
  15344. /** Adds a rectangle to the set of areas not to paint over.
  15345. A component can call this on its peer during its paint() method, to signal
  15346. that the painting code should ignore a given region. The reason
  15347. for this is to stop embedded windows (such as OpenGL) getting painted over.
  15348. The masked region is cleared each time before a paint happens, so a component
  15349. will have to make sure it calls this every time it's painted.
  15350. */
  15351. void addMaskedRegion (int x, int y, int w, int h) throw();
  15352. /** Returns the number of currently-active peers.
  15353. @see getPeer
  15354. */
  15355. static int getNumPeers() throw();
  15356. /** Returns one of the currently-active peers.
  15357. @see getNumPeers
  15358. */
  15359. static ComponentPeer* getPeer (const int index) throw();
  15360. /** Checks if this peer object is valid.
  15361. @see getNumPeers
  15362. */
  15363. static bool isValidPeer (const ComponentPeer* const peer) throw();
  15364. juce_UseDebuggingNewOperator
  15365. protected:
  15366. Component* const component;
  15367. const int styleFlags;
  15368. RectangleList maskedRegion;
  15369. Rectangle lastNonFullscreenBounds;
  15370. uint32 lastPaintTime;
  15371. ComponentBoundsConstrainer* constrainer;
  15372. static void updateCurrentModifiers() throw();
  15373. /** @internal */
  15374. void handleMessage (const Message& message);
  15375. private:
  15376. Component* lastFocusedComponent;
  15377. ComponentDeletionWatcher* dragAndDropTargetComponent;
  15378. Component* lastDragAndDropCompUnderMouse;
  15379. bool fakeMouseMessageSent : 1, isWindowMinimised : 1;
  15380. friend class Component;
  15381. static ComponentPeer* getPeerFor (const Component* const component) throw();
  15382. void setLastDragDropTarget (Component* comp);
  15383. ComponentPeer (const ComponentPeer&);
  15384. const ComponentPeer& operator= (const ComponentPeer&);
  15385. };
  15386. #endif // __JUCE_COMPONENTPEER_JUCEHEADER__
  15387. /********* End of inlined file: juce_ComponentPeer.h *********/
  15388. class LookAndFeel;
  15389. /**
  15390. The base class for all JUCE user-interface objects.
  15391. */
  15392. class JUCE_API Component : public MouseListener,
  15393. protected MessageListener
  15394. {
  15395. public:
  15396. /** Creates a component.
  15397. To get it to actually appear, you'll also need to:
  15398. - Either add it to a parent component or use the addToDesktop() method to
  15399. make it a desktop window
  15400. - Set its size and position to something sensible
  15401. - Use setVisible() to make it visible
  15402. And for it to serve any useful purpose, you'll need to write a
  15403. subclass of Component or use one of the other types of component from
  15404. the library.
  15405. */
  15406. Component() throw();
  15407. /** Destructor.
  15408. Note that when a component is deleted, any child components it might
  15409. contain are NOT deleted unless you explicitly call deleteAllChildren() first.
  15410. */
  15411. virtual ~Component();
  15412. /** Creates a component, setting its name at the same time.
  15413. @see getName, setName
  15414. */
  15415. Component (const String& componentName) throw();
  15416. /** Returns the name of this component.
  15417. @see setName
  15418. */
  15419. const String& getName() const throw() { return componentName_; }
  15420. /** Sets the name of this component.
  15421. When the name changes, all registered ComponentListeners will receive a
  15422. ComponentListener::componentNameChanged() callback.
  15423. @see getName
  15424. */
  15425. virtual void setName (const String& newName);
  15426. /** Checks whether this Component object has been deleted.
  15427. This will check whether this object is still a valid component, or whether
  15428. it's been deleted.
  15429. It's safe to call this on null or dangling pointers, but note that there is a
  15430. small risk if another new (but different) component has been created at the
  15431. same memory address which this one occupied, this methods can return a
  15432. false positive.
  15433. */
  15434. bool isValidComponent() const throw();
  15435. /** Makes the component visible or invisible.
  15436. This method will show or hide the component.
  15437. Note that components default to being non-visible when first created.
  15438. Also note that visible components won't be seen unless all their parent components
  15439. are also visible.
  15440. This method will call visibilityChanged() and also componentVisibilityChanged()
  15441. for any component listeners that are interested in this component.
  15442. @param shouldBeVisible whether to show or hide the component
  15443. @see isVisible, isShowing, visibilityChanged, ComponentListener::componentVisibilityChanged
  15444. */
  15445. virtual void setVisible (bool shouldBeVisible);
  15446. /** Tests whether the component is visible or not.
  15447. this doesn't necessarily tell you whether this comp is actually on the screen
  15448. because this depends on whether all the parent components are also visible - use
  15449. isShowing() to find this out.
  15450. @see isShowing, setVisible
  15451. */
  15452. bool isVisible() const throw() { return flags.visibleFlag; }
  15453. /** Called when this component's visiblility changes.
  15454. @see setVisible, isVisible
  15455. */
  15456. virtual void visibilityChanged();
  15457. /** Tests whether this component and all its parents are visible.
  15458. @returns true only if this component and all its parents are visible.
  15459. @see isVisible
  15460. */
  15461. bool isShowing() const throw();
  15462. /** Makes a component invisible using a groovy fade-out and animated zoom effect.
  15463. To do this, this function will cunningly:
  15464. - take a snapshot of the component as it currently looks
  15465. - call setVisible(false) on the component
  15466. - replace it with a special component that will continue drawing the
  15467. snapshot, animating it and gradually making it more transparent
  15468. - when it's gone, the special component will also be deleted
  15469. As soon as this method returns, the component can be safely removed and deleted
  15470. leaving the proxy to do the fade-out, so it's even ok to call this in a
  15471. component's destructor.
  15472. Passing non-zero x and y values will cause the ghostly component image to
  15473. also whizz off by this distance while fading out. If the scale factor is
  15474. not 1.0, it will also zoom from the component's current size to this new size.
  15475. One thing to be careful about is that the parent component must be able to cope
  15476. with this unknown component type being added to it.
  15477. */
  15478. void fadeOutComponent (const int lengthOfFadeOutInMilliseconds,
  15479. const int deltaXToMove = 0,
  15480. const int deltaYToMove = 0,
  15481. const float scaleFactorAtEnd = 1.0f);
  15482. /** Makes this component appear as a window on the desktop.
  15483. Note that before calling this, you should make sure that the component's opacity is
  15484. set correctly using setOpaque(). If the component is non-opaque, the windowing
  15485. system will try to create a special transparent window for it, which will generally take
  15486. a lot more CPU to operate (and might not even be possible on some platforms).
  15487. If the component is inside a parent component at the time this method is called, it
  15488. will be first be removed from that parent. Likewise if a component on the desktop
  15489. is subsequently added to another component, it'll be removed from the desktop.
  15490. @param windowStyleFlags a combination of the flags specified in the
  15491. ComponentPeer::StyleFlags enum, which define the
  15492. window's characteristics.
  15493. @param nativeWindowToAttachTo this allows an OS object to be passed-in as the window
  15494. in which the juce component should place itself. On Windows,
  15495. this would be a HWND, a HIViewRef on the Mac. Not necessarily
  15496. supported on all platforms, and best left as 0 unless you know
  15497. what you're doing
  15498. @see removeFromDesktop, isOnDesktop, userTriedToCloseWindow,
  15499. getPeer, ComponentPeer::setMinimised, ComponentPeer::StyleFlags,
  15500. ComponentPeer::getStyleFlags, ComponentPeer::setFullScreen
  15501. */
  15502. virtual void addToDesktop (int windowStyleFlags,
  15503. void* nativeWindowToAttachTo = 0);
  15504. /** If the component is currently showing on the desktop, this will hide it.
  15505. You can also use setVisible() to hide a desktop window temporarily, but
  15506. removeFromDesktop() will free any system resources that are being used up.
  15507. @see addToDesktop, isOnDesktop
  15508. */
  15509. void removeFromDesktop();
  15510. /** Returns true if this component is currently showing on the desktop.
  15511. @see addToDesktop, removeFromDesktop
  15512. */
  15513. bool isOnDesktop() const throw();
  15514. /** Returns the heavyweight window that contains this component.
  15515. If this component is itself on the desktop, this will return the window
  15516. object that it is using. Otherwise, it will return the window of
  15517. its top-level parent component.
  15518. This may return 0 if there isn't a desktop component.
  15519. @see addToDesktop, isOnDesktop
  15520. */
  15521. ComponentPeer* getPeer() const throw();
  15522. /** For components on the desktop, this is called if the system wants to close the window.
  15523. This is a signal that either the user or the system wants the window to close. The
  15524. default implementation of this method will trigger an assertion to warn you that your
  15525. component should do something about it, but you can override this to ignore the event
  15526. if you want.
  15527. */
  15528. virtual void userTriedToCloseWindow();
  15529. /** Called for a desktop component which has just been minimised or un-minimised.
  15530. This will only be called for components on the desktop.
  15531. @see getPeer, ComponentPeer::setMinimised, ComponentPeer::isMinimised
  15532. */
  15533. virtual void minimisationStateChanged (bool isNowMinimised);
  15534. /** Brings the component to the front of its siblings.
  15535. If some of the component's siblings have had their 'always-on-top' flag set,
  15536. then they will still be kept in front of this one (unless of course this
  15537. one is also 'always-on-top').
  15538. @param shouldAlsoGainFocus if true, this will also try to assign keyboard focus
  15539. to the component (see grabKeyboardFocus() for more details)
  15540. @see toBack, toBehind, setAlwaysOnTop
  15541. */
  15542. void toFront (const bool shouldAlsoGainFocus);
  15543. /** Changes this component's z-order to be at the back of all its siblings.
  15544. If the component is set to be 'always-on-top', it will only be moved to the
  15545. back of the other other 'always-on-top' components.
  15546. @see toFront, toBehind, setAlwaysOnTop
  15547. */
  15548. void toBack();
  15549. /** Changes this component's z-order so that it's just behind another component.
  15550. @see toFront, toBack
  15551. */
  15552. void toBehind (Component* const other);
  15553. /** Sets whether the component should always be kept at the front of its siblings.
  15554. @see isAlwaysOnTop
  15555. */
  15556. void setAlwaysOnTop (const bool shouldStayOnTop);
  15557. /** Returns true if this component is set to always stay in front of its siblings.
  15558. @see setAlwaysOnTop
  15559. */
  15560. bool isAlwaysOnTop() const throw();
  15561. /** Returns the x co-ordinate of the component's left edge.
  15562. This is a distance in pixels from the left edge of the component's parent.
  15563. @see getScreenX
  15564. */
  15565. inline int getX() const throw() { return bounds_.getX(); }
  15566. /** Returns the y co-ordinate of the top of this component.
  15567. This is a distance in pixels from the top edge of the component's parent.
  15568. @see getScreenY
  15569. */
  15570. inline int getY() const throw() { return bounds_.getY(); }
  15571. /** Returns the component's width in pixels. */
  15572. inline int getWidth() const throw() { return bounds_.getWidth(); }
  15573. /** Returns the component's height in pixels. */
  15574. inline int getHeight() const throw() { return bounds_.getHeight(); }
  15575. /** Returns the x co-ordinate of the component's right-hand edge.
  15576. This is a distance in pixels from the left edge of the component's parent.
  15577. */
  15578. int getRight() const throw() { return bounds_.getRight(); }
  15579. /** Returns the y co-ordinate of the bottom edge of this component.
  15580. This is a distance in pixels from the top edge of the component's parent.
  15581. */
  15582. int getBottom() const throw() { return bounds_.getBottom(); }
  15583. /** Returns this component's bounding box.
  15584. The rectangle returned is relative to the top-left of the component's parent.
  15585. */
  15586. const Rectangle& getBounds() const throw() { return bounds_; }
  15587. /** Returns the region of this component that's not obscured by other, opaque components.
  15588. The RectangleList that is returned represents the area of this component
  15589. which isn't covered by opaque child components.
  15590. If includeSiblings is true, it will also take into account any siblings
  15591. that may be overlapping the component.
  15592. */
  15593. void getVisibleArea (RectangleList& result,
  15594. const bool includeSiblings) const;
  15595. /** Returns this component's x co-ordinate relative the the screen's top-left origin.
  15596. @see getX, relativePositionToGlobal
  15597. */
  15598. int getScreenX() const throw();
  15599. /** Returns this component's y co-ordinate relative the the screen's top-left origin.
  15600. @see getY, relativePositionToGlobal
  15601. */
  15602. int getScreenY() const throw();
  15603. /** Converts a position relative to this component's top-left into a screen co-ordinate.
  15604. @see globalPositionToRelative, relativePositionToOtherComponent
  15605. */
  15606. void relativePositionToGlobal (int& x, int& y) const throw();
  15607. /** Converts a screen co-ordinate into a position relative to this component's top-left.
  15608. @see relativePositionToGlobal, relativePositionToOtherComponent
  15609. */
  15610. void globalPositionToRelative (int& x, int& y) const throw();
  15611. /** Converts a position relative to this component's top-left into a position
  15612. relative to another component's top-left.
  15613. @see relativePositionToGlobal, globalPositionToRelative
  15614. */
  15615. void relativePositionToOtherComponent (const Component* const targetComponent,
  15616. int& x, int& y) const throw();
  15617. /** Moves the component to a new position.
  15618. Changes the component's top-left position (without changing its size).
  15619. The position is relative to the top-left of the component's parent.
  15620. If the component actually moves, this method will make a synchronous call to moved().
  15621. @see setBounds, ComponentListener::componentMovedOrResized
  15622. */
  15623. void setTopLeftPosition (const int x, const int y);
  15624. /** Moves the component to a new position.
  15625. Changes the position of the component's top-right corner (keeping it the same size).
  15626. The position is relative to the top-left of the component's parent.
  15627. If the component actually moves, this method will make a synchronous call to moved().
  15628. */
  15629. void setTopRightPosition (const int x, const int y);
  15630. /** Changes the size of the component.
  15631. A synchronous call to resized() will be occur if the size actually changes.
  15632. */
  15633. void setSize (const int newWidth, const int newHeight);
  15634. /** Changes the component's position and size.
  15635. The co-ordinates are relative to the top-left of the component's parent, or relative
  15636. to the origin of the screen is the component is on the desktop.
  15637. If this method changes the component's top-left position, it will make a synchronous
  15638. call to moved(). If it changes the size, it will also make a call to resized().
  15639. @see setTopLeftPosition, setSize, ComponentListener::componentMovedOrResized
  15640. */
  15641. void setBounds (int x, int y, int width, int height);
  15642. /** Changes the component's position and size.
  15643. @see setBounds
  15644. */
  15645. void setBounds (const Rectangle& newBounds);
  15646. /** Changes the component's position and size in terms of fractions of its parent's size.
  15647. The values are factors of the parent's size, so for example
  15648. setBoundsRelative (0.2f, 0.2f, 0.5f, 0.5f) would give it half the
  15649. width and height of the parent, with its top-left position 20% of
  15650. the way across and down the parent.
  15651. */
  15652. void setBoundsRelative (const float proportionalX, const float proportionalY,
  15653. const float proportionalWidth, const float proportionalHeight);
  15654. /** Changes the component's position and size based on the amount of space to leave around it.
  15655. This will position the component within its parent, leaving the specified number of
  15656. pixels around each edge.
  15657. */
  15658. void setBoundsInset (const BorderSize& borders);
  15659. /** Positions the component within a given rectangle, keeping its proportions
  15660. unchanged.
  15661. If onlyReduceInSize is false, the component will be resized to fill as much of the
  15662. rectangle as possible without changing its aspect ratio (the component's
  15663. current size is used to determine its aspect ratio, so a zero-size component
  15664. won't work here). If onlyReduceInSize is true, it will only be resized if it's
  15665. too big to fit inside the rectangle.
  15666. It will then be positioned within the rectangle according to the justification flags
  15667. specified.
  15668. */
  15669. void setBoundsToFit (int x, int y, int width, int height,
  15670. const Justification& justification,
  15671. const bool onlyReduceInSize);
  15672. /** Changes the position of the component's centre.
  15673. Leaves the component's size unchanged, but sets the position of its centre
  15674. relative to its parent's top-left.
  15675. */
  15676. void setCentrePosition (const int x, const int y);
  15677. /** Changes the position of the component's centre.
  15678. Leaves the position unchanged, but positions its centre relative to its
  15679. parent's size. E.g. setCentreRelative (0.5f, 0.5f) would place it centrally in
  15680. its parent.
  15681. */
  15682. void setCentreRelative (const float x, const float y);
  15683. /** Changes the component's size and centres it within its parent.
  15684. After changing the size, the component will be moved so that it's
  15685. centred within its parent.
  15686. */
  15687. void centreWithSize (const int width, const int height);
  15688. /** Returns a proportion of the component's width.
  15689. This is a handy equivalent of (getWidth() * proportion).
  15690. */
  15691. int proportionOfWidth (const float proportion) const throw();
  15692. /** Returns a proportion of the component's height.
  15693. This is a handy equivalent of (getHeight() * proportion).
  15694. */
  15695. int proportionOfHeight (const float proportion) const throw();
  15696. /** Returns the width of the component's parent.
  15697. If the component has no parent (i.e. if it's on the desktop), this will return
  15698. the width of the screen.
  15699. */
  15700. int getParentWidth() const throw();
  15701. /** Returns the height of the component's parent.
  15702. If the component has no parent (i.e. if it's on the desktop), this will return
  15703. the height of the screen.
  15704. */
  15705. int getParentHeight() const throw();
  15706. /** Returns the screen co-ordinates of the monitor that contains this component.
  15707. If there's only one monitor, this will return its size - if there are multiple
  15708. monitors, it will return the area of the monitor that contains the component's
  15709. centre.
  15710. */
  15711. const Rectangle getParentMonitorArea() const throw();
  15712. /** Returns the number of child components that this component contains.
  15713. @see getChildComponent, getIndexOfChildComponent
  15714. */
  15715. int getNumChildComponents() const throw();
  15716. /** Returns one of this component's child components, by it index.
  15717. The component with index 0 is at the back of the z-order, the one at the
  15718. front will have index (getNumChildComponents() - 1).
  15719. If the index is out-of-range, this will return a null pointer.
  15720. @see getNumChildComponents, getIndexOfChildComponent
  15721. */
  15722. Component* getChildComponent (const int index) const throw();
  15723. /** Returns the index of this component in the list of child components.
  15724. A value of 0 means it is first in the list (i.e. behind all other components). Higher
  15725. values are further towards the front.
  15726. Returns -1 if the component passed-in is not a child of this component.
  15727. @see getNumChildComponents, getChildComponent, addChildComponent, toFront, toBack, toBehind
  15728. */
  15729. int getIndexOfChildComponent (const Component* const child) const throw();
  15730. /** Adds a child component to this one.
  15731. @param child the new component to add. If the component passed-in is already
  15732. the child of another component, it'll first be removed from that.
  15733. @param zOrder The index in the child-list at which this component should be inserted.
  15734. A value of -1 will insert it in front of the others, 0 is the back.
  15735. @see removeChildComponent, addAndMakeVisible, getChild,
  15736. ComponentListener::componentChildrenChanged
  15737. */
  15738. void addChildComponent (Component* const child,
  15739. int zOrder = -1);
  15740. /** Adds a child component to this one, and also makes the child visible if it isn't.
  15741. Quite a useful function, this is just the same as calling addChildComponent()
  15742. followed by setVisible (true) on the child.
  15743. */
  15744. void addAndMakeVisible (Component* const child,
  15745. int zOrder = -1);
  15746. /** Removes one of this component's child-components.
  15747. If the child passed-in isn't actually a child of this component (either because
  15748. it's invalid or is the child of a different parent), then nothing is done.
  15749. Note that removing a child will not delete it!
  15750. @see addChildComponent, ComponentListener::componentChildrenChanged
  15751. */
  15752. void removeChildComponent (Component* const childToRemove);
  15753. /** Removes one of this component's child-components by index.
  15754. This will return a pointer to the component that was removed, or null if
  15755. the index was out-of-range.
  15756. Note that removing a child will not delete it!
  15757. @see addChildComponent, ComponentListener::componentChildrenChanged
  15758. */
  15759. Component* removeChildComponent (const int childIndexToRemove);
  15760. /** Removes all this component's children.
  15761. Note that this won't delete them! To do that, use deleteAllChildren() instead.
  15762. */
  15763. void removeAllChildren();
  15764. /** Removes all this component's children, and deletes them.
  15765. @see removeAllChildren
  15766. */
  15767. void deleteAllChildren();
  15768. /** Returns the component which this component is inside.
  15769. If this is the highest-level component or hasn't yet been added to
  15770. a parent, this will return null.
  15771. */
  15772. Component* getParentComponent() const throw() { return parentComponent_; }
  15773. /** Searches the parent components for a component of a specified class.
  15774. For example findParentComponentOfClass \<MyComp\>() would return the first parent
  15775. component that can be dynamically cast to a MyComp, or will return 0 if none
  15776. of the parents are suitable.
  15777. N.B. The dummy parameter is needed to work around a VC6 compiler bug.
  15778. */
  15779. template <class TargetClass>
  15780. TargetClass* findParentComponentOfClass (TargetClass* const dummyParameter = 0) const
  15781. {
  15782. (void) dummyParameter;
  15783. Component* p = parentComponent_;
  15784. while (p != 0)
  15785. {
  15786. TargetClass* target = dynamic_cast <TargetClass*> (p);
  15787. if (target != 0)
  15788. return target;
  15789. p = p->parentComponent_;
  15790. }
  15791. return 0;
  15792. }
  15793. /** Returns the highest-level component which contains this one or its parents.
  15794. This will search upwards in the parent-hierarchy from this component, until it
  15795. finds the highest one that doesn't have a parent (i.e. is on the desktop or
  15796. not yet added to a parent), and will return that.
  15797. */
  15798. Component* getTopLevelComponent() const throw();
  15799. /** Checks whether a component is anywhere inside this component or its children.
  15800. This will recursively check through this components children to see if the
  15801. given component is anywhere inside.
  15802. */
  15803. bool isParentOf (const Component* possibleChild) const throw();
  15804. /** Called to indicate that the component's parents have changed.
  15805. When a component is added or removed from its parent, this method will
  15806. be called on all of its children (recursively - so all children of its
  15807. children will also be called as well).
  15808. Subclasses can override this if they need to react to this in some way.
  15809. @see getParentComponent, isShowing, ComponentListener::componentParentHierarchyChanged
  15810. */
  15811. virtual void parentHierarchyChanged();
  15812. /** Subclasses can use this callback to be told when children are added or removed.
  15813. @see parentHierarchyChanged
  15814. */
  15815. virtual void childrenChanged();
  15816. /** Tests whether a given point inside the component.
  15817. Overriding this method allows you to create components which only intercept
  15818. mouse-clicks within a user-defined area.
  15819. This is called to find out whether a particular x, y co-ordinate is
  15820. considered to be inside the component or not, and is used by methods such
  15821. as contains() and getComponentAt() to work out which component
  15822. the mouse is clicked on.
  15823. Components with custom shapes will probably want to override it to perform
  15824. some more complex hit-testing.
  15825. The default implementation of this method returns either true or false,
  15826. depending on the value that was set by calling setInterceptsMouseClicks() (true
  15827. is the default return value).
  15828. Note that the hit-test region is not related to the opacity with which
  15829. areas of a component are painted.
  15830. Applications should never call hitTest() directly - instead use the
  15831. contains() method, because this will also test for occlusion by the
  15832. component's parent.
  15833. Note that for components on the desktop, this method will be ignored, because it's
  15834. not always possible to implement this behaviour on all platforms.
  15835. @param x the x co-ordinate to test, relative to the left hand edge of this
  15836. component. This value is guaranteed to be greater than or equal to
  15837. zero, and less than the component's width
  15838. @param y the y co-ordinate to test, relative to the top edge of this
  15839. component. This value is guaranteed to be greater than or equal to
  15840. zero, and less than the component's height
  15841. @returns true if the click is considered to be inside the component
  15842. @see setInterceptsMouseClicks, contains
  15843. */
  15844. virtual bool hitTest (int x, int y);
  15845. /** Changes the default return value for the hitTest() method.
  15846. Setting this to false is an easy way to make a component pass its mouse-clicks
  15847. through to the components behind it.
  15848. When a component is created, the default setting for this is true.
  15849. @param allowClicksOnThisComponent if true, hitTest() will always return true; if false, it will
  15850. return false (or true for child components if allowClicksOnChildComponents
  15851. is true)
  15852. @param allowClicksOnChildComponents if this is true and allowClicksOnThisComponent is false, then child
  15853. components can be clicked on as normal but clicks on this component pass
  15854. straight through; if this is false and allowClicksOnThisComponent
  15855. is false, then neither this component nor any child components can
  15856. be clicked on
  15857. @see hitTest, getInterceptsMouseClicks
  15858. */
  15859. void setInterceptsMouseClicks (const bool allowClicksOnThisComponent,
  15860. const bool allowClicksOnChildComponents) throw();
  15861. /** Retrieves the current state of the mouse-click interception flags.
  15862. On return, the two parameters are set to the state used in the last call to
  15863. setInterceptsMouseClicks().
  15864. @see setInterceptsMouseClicks
  15865. */
  15866. void getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  15867. bool& allowsClicksOnChildComponents) const throw();
  15868. /** Returns true if a given point lies within this component or one of its children.
  15869. Never override this method! Use hitTest to create custom hit regions.
  15870. @param x the x co-ordinate to test, relative to this component's left hand edge.
  15871. @param y the y co-ordinate to test, relative to this component's top edge.
  15872. @returns true if the point is within the component's hit-test area, but only if
  15873. that part of the component isn't clipped by its parent component. Note
  15874. that this won't take into account any overlapping sibling components
  15875. which might be in the way - for that, see reallyContains()
  15876. @see hitTest, reallyContains, getComponentAt
  15877. */
  15878. virtual bool contains (int x, int y);
  15879. /** Returns true if a given point lies in this component, taking any overlapping
  15880. siblings into account.
  15881. @param x the x co-ordinate to test, relative to this component's left hand edge.
  15882. @param y the y co-ordinate to test, relative to this component's top edge.
  15883. @param returnTrueIfWithinAChild if the point actually lies within a child of this
  15884. component, this determines the value that will
  15885. be returned.
  15886. @see contains, getComponentAt
  15887. */
  15888. bool reallyContains (int x, int y,
  15889. const bool returnTrueIfWithinAChild);
  15890. /** Returns the component at a certain point within this one.
  15891. @param x the x co-ordinate to test, relative to this component's left hand edge.
  15892. @param y the y co-ordinate to test, relative to this component's top edge.
  15893. @returns the component that is at this position - which may be 0, this component,
  15894. or one of its children. Note that overlapping siblings that might actually
  15895. be in the way are not taken into account by this method - to account for these,
  15896. instead call getComponentAt on the top-level parent of this component.
  15897. @see hitTest, contains, reallyContains
  15898. */
  15899. Component* getComponentAt (const int x, const int y);
  15900. /** Marks the whole component as needing to be redrawn.
  15901. Calling this will not do any repainting immediately, but will mark the component
  15902. as 'dirty'. At some point in the near future the operating system will send a paint
  15903. message, which will redraw all the dirty regions of all components.
  15904. There's no guarantee about how soon after calling repaint() the redraw will actually
  15905. happen, and other queued events may be delivered before a redraw is done.
  15906. If the setBufferedToImage() method has been used to cause this component
  15907. to use a buffer, the repaint() call will invalidate the component's buffer.
  15908. To redraw just a subsection of the component rather than the whole thing,
  15909. use the repaint (int, int, int, int) method.
  15910. @see paint
  15911. */
  15912. void repaint() throw();
  15913. /** Marks a subsection of this component as needing to be redrawn.
  15914. Calling this will not do any repainting immediately, but will mark the given region
  15915. of the component as 'dirty'. At some point in the near future the operating system
  15916. will send a paint message, which will redraw all the dirty regions of all components.
  15917. There's no guarantee about how soon after calling repaint() the redraw will actually
  15918. happen, and other queued events may be delivered before a redraw is done.
  15919. The region that is passed in will be clipped to keep it within the bounds of this
  15920. component.
  15921. @see repaint()
  15922. */
  15923. void repaint (const int x, const int y,
  15924. const int width, const int height) throw();
  15925. /** Makes the component use an internal buffer to optimise its redrawing.
  15926. Setting this flag to true will cause the component to allocate an
  15927. internal buffer into which it paints itself, so that when asked to
  15928. redraw itself, it can use this buffer rather than actually calling the
  15929. paint() method.
  15930. The buffer is kept until the repaint() method is called directly on
  15931. this component (or until it is resized), when the image is invalidated
  15932. and then redrawn the next time the component is painted.
  15933. Note that only the drawing that happens within the component's paint()
  15934. method is drawn into the buffer, it's child components are not buffered, and
  15935. nor is the paintOverChildren() method.
  15936. @see repaint, paint, createComponentSnapshot
  15937. */
  15938. void setBufferedToImage (const bool shouldBeBuffered) throw();
  15939. /** Generates a snapshot of part of this component.
  15940. This will return a new Image, the size of the rectangle specified,
  15941. containing a snapshot of the specified area of the component and all
  15942. its children.
  15943. The image may or may not have an alpha-channel, depending on whether the
  15944. image is opaque or not.
  15945. If the clipImageToComponentBounds parameter is true and the area is greater than
  15946. the size of the component, it'll be clipped. If clipImageToComponentBounds is false
  15947. then parts of the component beyond its bounds can be drawn.
  15948. The caller is responsible for deleting the image that is returned.
  15949. @see paintEntireComponent
  15950. */
  15951. Image* createComponentSnapshot (const Rectangle& areaToGrab,
  15952. const bool clipImageToComponentBounds = true);
  15953. /** Draws this component and all its subcomponents onto the specified graphics
  15954. context.
  15955. You should very rarely have to use this method, it's simply there in case you need
  15956. to draw a component with a custom graphics context for some reason, e.g. for
  15957. creating a snapshot of the component.
  15958. It calls paint(), paintOverChildren() and recursively calls paintEntireComponent()
  15959. on its children in order to render the entire tree.
  15960. The graphics context may be left in an undefined state after this method returns,
  15961. so you may need to reset it if you're going to use it again.
  15962. */
  15963. void paintEntireComponent (Graphics& context);
  15964. /** Adds an effect filter to alter the component's appearance.
  15965. When a component has an effect filter set, then this is applied to the
  15966. results of its paint() method. There are a few preset effects, such as
  15967. a drop-shadow or glow, but they can be user-defined as well.
  15968. The effect that is passed in will not be deleted by the component - the
  15969. caller must take care of deleting it.
  15970. To remove an effect from a component, pass a null pointer in as the parameter.
  15971. @see ImageEffectFilter, DropShadowEffect, GlowEffect
  15972. */
  15973. void setComponentEffect (ImageEffectFilter* const newEffect);
  15974. /** Returns the current component effect.
  15975. @see setComponentEffect
  15976. */
  15977. ImageEffectFilter* getComponentEffect() const throw() { return effect_; }
  15978. /** Finds the appropriate look-and-feel to use for this component.
  15979. If the component hasn't had a look-and-feel explicitly set, this will
  15980. return the parent's look-and-feel, or just the default one if there's no
  15981. parent.
  15982. @see setLookAndFeel, lookAndFeelChanged
  15983. */
  15984. LookAndFeel& getLookAndFeel() const throw();
  15985. /** Sets the look and feel to use for this component.
  15986. This will also change the look and feel for any child components that haven't
  15987. had their look set explicitly.
  15988. The object passed in will not be deleted by the component, so it's the caller's
  15989. responsibility to manage it. It may be used at any time until this component
  15990. has been deleted.
  15991. Calling this method will also invoke the sendLookAndFeelChange() method.
  15992. @see getLookAndFeel, lookAndFeelChanged
  15993. */
  15994. void setLookAndFeel (LookAndFeel* const newLookAndFeel);
  15995. /** Called to let the component react to a change in the look-and-feel setting.
  15996. When the look-and-feel is changed for a component, this will be called in
  15997. all its child components, recursively.
  15998. It can also be triggered manually by the sendLookAndFeelChange() method, in case
  15999. an application uses a LookAndFeel class that might have changed internally.
  16000. @see sendLookAndFeelChange, getLookAndFeel
  16001. */
  16002. virtual void lookAndFeelChanged();
  16003. /** Calls the lookAndFeelChanged() method in this component and all its children.
  16004. This will recurse through the children and their children, calling lookAndFeelChanged()
  16005. on them all.
  16006. @see lookAndFeelChanged
  16007. */
  16008. void sendLookAndFeelChange();
  16009. /** Indicates whether any parts of the component might be transparent.
  16010. Components that always paint all of their contents with solid colour and
  16011. thus completely cover any components behind them should use this method
  16012. to tell the repaint system that they are opaque.
  16013. This information is used to optimise drawing, because it means that
  16014. objects underneath opaque windows don't need to be painted.
  16015. By default, components are considered transparent, unless this is used to
  16016. make it otherwise.
  16017. @see isOpaque, getVisibleArea
  16018. */
  16019. void setOpaque (const bool shouldBeOpaque) throw();
  16020. /** Returns true if no parts of this component are transparent.
  16021. @returns the value that was set by setOpaque, (the default being false)
  16022. @see setOpaque
  16023. */
  16024. bool isOpaque() const throw();
  16025. /** Indicates whether the component should be brought to the front when clicked.
  16026. Setting this flag to true will cause the component to be brought to the front
  16027. when the mouse is clicked somewhere inside it or its child components.
  16028. Note that a top-level desktop window might still be brought to the front by the
  16029. operating system when it's clicked, depending on how the OS works.
  16030. By default this is set to false.
  16031. @see setMouseClickGrabsKeyboardFocus
  16032. */
  16033. void setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw();
  16034. /** Indicates whether the component should be brought to the front when clicked-on.
  16035. @see setBroughtToFrontOnMouseClick
  16036. */
  16037. bool isBroughtToFrontOnMouseClick() const throw();
  16038. // Keyboard focus methods
  16039. /** Sets a flag to indicate whether this component needs keyboard focus or not.
  16040. By default components aren't actually interested in gaining the
  16041. focus, but this method can be used to turn this on.
  16042. See the grabKeyboardFocus() method for details about the way a component
  16043. is chosen to receive the focus.
  16044. @see grabKeyboardFocus, getWantsKeyboardFocus
  16045. */
  16046. void setWantsKeyboardFocus (const bool wantsFocus) throw();
  16047. /** Returns true if the component is interested in getting keyboard focus.
  16048. This returns the flag set by setWantsKeyboardFocus(). The default
  16049. setting is false.
  16050. @see setWantsKeyboardFocus
  16051. */
  16052. bool getWantsKeyboardFocus() const throw();
  16053. /** Chooses whether a click on this component automatically grabs the focus.
  16054. By default this is set to true, but you might want a component which can
  16055. be focused, but where you don't want the user to be able to affect it directly
  16056. by clicking.
  16057. */
  16058. void setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus);
  16059. /** Returns the last value set with setMouseClickGrabsKeyboardFocus().
  16060. See setMouseClickGrabsKeyboardFocus() for more info.
  16061. */
  16062. bool getMouseClickGrabsKeyboardFocus() const throw();
  16063. /** Tries to give keyboard focus to this component.
  16064. When the user clicks on a component or its grabKeyboardFocus()
  16065. method is called, the following procedure is used to work out which
  16066. component should get it:
  16067. - if the component that was clicked on actually wants focus (as indicated
  16068. by calling getWantsKeyboardFocus), it gets it.
  16069. - if the component itself doesn't want focus, it will try to pass it
  16070. on to whichever of its children is the default component, as determined by
  16071. KeyboardFocusTraverser::getDefaultComponent()
  16072. - if none of its children want focus at all, it will pass it up to its
  16073. parent instead, unless it's a top-level component without a parent,
  16074. in which case it just takes the focus itself.
  16075. @see setWantsKeyboardFocus, getWantsKeyboardFocus, hasKeyboardFocus,
  16076. getCurrentlyFocusedComponent, focusGained, focusLost,
  16077. keyPressed, keyStateChanged
  16078. */
  16079. void grabKeyboardFocus();
  16080. /** Returns true if this component currently has the keyboard focus.
  16081. @param trueIfChildIsFocused if this is true, then the method returns true if
  16082. either this component or any of its children (recursively)
  16083. have the focus. If false, the method only returns true if
  16084. this component has the focus.
  16085. @see grabKeyboardFocus, setWantsKeyboardFocus, getCurrentlyFocusedComponent,
  16086. focusGained, focusLost
  16087. */
  16088. bool hasKeyboardFocus (const bool trueIfChildIsFocused) const throw();
  16089. /** Returns the component that currently has the keyboard focus.
  16090. @returns the focused component, or null if nothing is focused.
  16091. */
  16092. static Component* JUCE_CALLTYPE getCurrentlyFocusedComponent() throw();
  16093. /** Tries to move the keyboard focus to one of this component's siblings.
  16094. This will try to move focus to either the next or previous component. (This
  16095. is the method that is used when shifting focus by pressing the tab key).
  16096. Components for which getWantsKeyboardFocus() returns false are not looked at.
  16097. @param moveToNext if true, the focus will move forwards; if false, it will
  16098. move backwards
  16099. @see grabKeyboardFocus, setFocusContainer, setWantsKeyboardFocus
  16100. */
  16101. void moveKeyboardFocusToSibling (const bool moveToNext);
  16102. /** Creates a KeyboardFocusTraverser object to use to determine the logic by
  16103. which focus should be passed from this component.
  16104. The default implementation of this method will return a default
  16105. KeyboardFocusTraverser if this component is a focus container (as determined
  16106. by the setFocusContainer() method). If the component isn't a focus
  16107. container, then it will recursively ask its parents for a KeyboardFocusTraverser.
  16108. If you overrride this to return a custom KeyboardFocusTraverser, then
  16109. this component and all its sub-components will use the new object to
  16110. make their focusing decisions.
  16111. The method should return a new object, which the caller is required to
  16112. delete when no longer needed.
  16113. */
  16114. virtual KeyboardFocusTraverser* createFocusTraverser();
  16115. /** Returns the focus order of this component, if one has been specified.
  16116. By default components don't have a focus order - in that case, this
  16117. will return 0. Lower numbers indicate that the component will be
  16118. earlier in the focus traversal order.
  16119. To change the order, call setExplicitFocusOrder().
  16120. The focus order may be used by the KeyboardFocusTraverser class as part of
  16121. its algorithm for deciding the order in which components should be traversed.
  16122. See the KeyboardFocusTraverser class for more details on this.
  16123. @see moveKeyboardFocusToSibling, createFocusTraverser, KeyboardFocusTraverser
  16124. */
  16125. int getExplicitFocusOrder() const throw();
  16126. /** Sets the index used in determining the order in which focusable components
  16127. should be traversed.
  16128. A value of 0 or less is taken to mean that no explicit order is wanted, and
  16129. that traversal should use other factors, like the component's position.
  16130. @see getExplicitFocusOrder, moveKeyboardFocusToSibling
  16131. */
  16132. void setExplicitFocusOrder (const int newFocusOrderIndex) throw();
  16133. /** Indicates whether this component is a parent for components that can have
  16134. their focus traversed.
  16135. This flag is used by the default implementation of the createFocusTraverser()
  16136. method, which uses the flag to find the first parent component (of the currently
  16137. focused one) which wants to be a focus container.
  16138. So using this method to set the flag to 'true' causes this component to
  16139. act as the top level within which focus is passed around.
  16140. @see isFocusContainer, createFocusTraverser, moveKeyboardFocusToSibling
  16141. */
  16142. void setFocusContainer (const bool isFocusContainer) throw();
  16143. /** Returns true if this component has been marked as a focus container.
  16144. See setFocusContainer() for more details.
  16145. @see setFocusContainer, moveKeyboardFocusToSibling, createFocusTraverser
  16146. */
  16147. bool isFocusContainer() const throw();
  16148. /** Returns true if the component (and all its parents) are enabled.
  16149. Components are enabled by default, and can be disabled with setEnabled(). Exactly
  16150. what difference this makes to the component depends on the type. E.g. buttons
  16151. and sliders will choose to draw themselves differently, etc.
  16152. Note that if one of this component's parents is disabled, this will always
  16153. return false, even if this component itself is enabled.
  16154. @see setEnabled, enablementChanged
  16155. */
  16156. bool isEnabled() const throw();
  16157. /** Enables or disables this component.
  16158. Disabling a component will also cause all of its child components to become
  16159. disabled.
  16160. Similarly, enabling a component which is inside a disabled parent
  16161. component won't make any difference until the parent is re-enabled.
  16162. @see isEnabled, enablementChanged
  16163. */
  16164. void setEnabled (const bool shouldBeEnabled);
  16165. /** Callback to indicate that this component has been enabled or disabled.
  16166. This can be triggered by one of the component's parent components
  16167. being enabled or disabled, as well as changes to the component itself.
  16168. The default implementation of this method does nothing; your class may
  16169. wish to repaint itself or something when this happens.
  16170. @see setEnabled, isEnabled
  16171. */
  16172. virtual void enablementChanged();
  16173. /** Changes the mouse cursor shape to use when the mouse is over this component.
  16174. Note that the cursor set by this method can be overridden by the getMouseCursor
  16175. method.
  16176. @see MouseCursor
  16177. */
  16178. void setMouseCursor (const MouseCursor& cursorType) throw();
  16179. /** Returns the mouse cursor shape to use when the mouse is over this component.
  16180. The default implementation will return the cursor that was set by setCursor()
  16181. but can be overridden for more specialised purposes, e.g. returning different
  16182. cursors depending on the mouse position.
  16183. @see MouseCursor
  16184. */
  16185. virtual const MouseCursor getMouseCursor();
  16186. /** Forces the current mouse cursor to be updated.
  16187. If you're overriding the getMouseCursor() method to control which cursor is
  16188. displayed, then this will only be checked each time the user moves the mouse. So
  16189. if you want to force the system to check that the cursor being displayed is
  16190. up-to-date (even if the mouse is just sitting there), call this method.
  16191. This isn't needed if you're only using setMouseCursor().
  16192. */
  16193. void updateMouseCursor() const throw();
  16194. /** Components can override this method to draw their content.
  16195. The paint() method gets called when a region of a component needs redrawing,
  16196. either because the component's repaint() method has been called, or because
  16197. something has happened on the screen that means a section of a window needs
  16198. to be redrawn.
  16199. Any child components will draw themselves over whatever this method draws. If
  16200. you need to paint over the top of your child components, you can also implement
  16201. the paintOverChildren() method to do this.
  16202. If you want to cause a component to redraw itself, this is done asynchronously -
  16203. calling the repaint() method marks a region of the component as "dirty", and the
  16204. paint() method will automatically be called sometime later, by the message thread,
  16205. to paint any bits that need refreshing. In Juce (and almost all modern UI frameworks),
  16206. you never redraw something synchronously.
  16207. You should never need to call this method directly - to take a snapshot of the
  16208. component you could use createComponentSnapshot() or paintEntireComponent().
  16209. @param g the graphics context that must be used to do the drawing operations.
  16210. @see repaint, paintOverChildren, Graphics
  16211. */
  16212. virtual void paint (Graphics& g);
  16213. /** Components can override this method to draw over the top of their children.
  16214. For most drawing operations, it's better to use the normal paint() method,
  16215. but if you need to overlay something on top of the children, this can be
  16216. used.
  16217. @see paint, Graphics
  16218. */
  16219. virtual void paintOverChildren (Graphics& g);
  16220. /** Called when the mouse moves inside this component.
  16221. If the mouse button isn't pressed and the mouse moves over a component,
  16222. this will be called to let the component react to this.
  16223. A component will always get a mouseEnter callback before a mouseMove.
  16224. @param e details about the position and status of the mouse event
  16225. @see mouseEnter, mouseExit, mouseDrag, contains
  16226. */
  16227. virtual void mouseMove (const MouseEvent& e);
  16228. /** Called when the mouse first enters this component.
  16229. If the mouse button isn't pressed and the mouse moves into a component,
  16230. this will be called to let the component react to this.
  16231. When the mouse button is pressed and held down while being moved in
  16232. or out of a component, no mouseEnter or mouseExit callbacks are made - only
  16233. mouseDrag messages are sent to the component that the mouse was originally
  16234. clicked on, until the button is released.
  16235. If you're writing a component that needs to repaint itself when the mouse
  16236. enters and exits, it might be quicker to use the setRepaintsOnMouseActivity()
  16237. method.
  16238. @param e details about the position and status of the mouse event
  16239. @see mouseExit, mouseDrag, mouseMove, contains
  16240. */
  16241. virtual void mouseEnter (const MouseEvent& e);
  16242. /** Called when the mouse moves out of this component.
  16243. This will be called when the mouse moves off the edge of this
  16244. component.
  16245. If the mouse button was pressed, and it was then dragged off the
  16246. edge of the component and released, then this callback will happen
  16247. when the button is released, after the mouseUp callback.
  16248. If you're writing a component that needs to repaint itself when the mouse
  16249. enters and exits, it might be quicker to use the setRepaintsOnMouseActivity()
  16250. method.
  16251. @param e details about the position and status of the mouse event
  16252. @see mouseEnter, mouseDrag, mouseMove, contains
  16253. */
  16254. virtual void mouseExit (const MouseEvent& e);
  16255. /** Called when a mouse button is pressed while it's over this component.
  16256. The MouseEvent object passed in contains lots of methods for finding out
  16257. which button was pressed, as well as which modifier keys (e.g. shift, ctrl)
  16258. were held down at the time.
  16259. Once a button is held down, the mouseDrag method will be called when the
  16260. mouse moves, until the button is released.
  16261. @param e details about the position and status of the mouse event
  16262. @see mouseUp, mouseDrag, mouseDoubleClick, contains
  16263. */
  16264. virtual void mouseDown (const MouseEvent& e);
  16265. /** Called when the mouse is moved while a button is held down.
  16266. When a mouse button is pressed inside a component, that component
  16267. receives mouseDrag callbacks each time the mouse moves, even if the
  16268. mouse strays outside the component's bounds.
  16269. If you want to be able to drag things off the edge of a component
  16270. and have the component scroll when you get to the edges, the
  16271. beginDragAutoRepeat() method might be useful.
  16272. @param e details about the position and status of the mouse event
  16273. @see mouseDown, mouseUp, mouseMove, contains, beginDragAutoRepeat
  16274. */
  16275. virtual void mouseDrag (const MouseEvent& e);
  16276. /** Called when a mouse button is released.
  16277. A mouseUp callback is sent to the component in which a button was pressed
  16278. even if the mouse is actually over a different component when the
  16279. button is released.
  16280. The MouseEvent object passed in contains lots of methods for finding out
  16281. which buttons were down just before they were released.
  16282. @param e details about the position and status of the mouse event
  16283. @see mouseDown, mouseDrag, mouseDoubleClick, contains
  16284. */
  16285. virtual void mouseUp (const MouseEvent& e);
  16286. /** Called when a mouse button has been double-clicked in this component.
  16287. The MouseEvent object passed in contains lots of methods for finding out
  16288. which button was pressed, as well as which modifier keys (e.g. shift, ctrl)
  16289. were held down at the time.
  16290. For altering the time limit used to detect double-clicks,
  16291. see MouseEvent::setDoubleClickTimeout.
  16292. @param e details about the position and status of the mouse event
  16293. @see mouseDown, mouseUp, MouseEvent::setDoubleClickTimeout,
  16294. MouseEvent::getDoubleClickTimeout
  16295. */
  16296. virtual void mouseDoubleClick (const MouseEvent& e);
  16297. /** Called when the mouse-wheel is moved.
  16298. This callback is sent to the component that the mouse is over when the
  16299. wheel is moved.
  16300. If not overridden, the component will forward this message to its parent, so
  16301. that parent components can collect mouse-wheel messages that happen to
  16302. child components which aren't interested in them.
  16303. @param e details about the position and status of the mouse event
  16304. @param wheelIncrementX the speed and direction of the horizontal scroll-wheel - a positive
  16305. value means the wheel has been pushed to the right, negative means it
  16306. was pushed to the left
  16307. @param wheelIncrementY the speed and direction of the vertical scroll-wheel - a positive
  16308. value means the wheel has been pushed upwards, negative means it
  16309. was pushed downwards
  16310. */
  16311. virtual void mouseWheelMove (const MouseEvent& e,
  16312. float wheelIncrementX,
  16313. float wheelIncrementY);
  16314. /** Ensures that a non-stop stream of mouse-drag events will be sent during the
  16315. next mouse-drag operation.
  16316. This allows you to make sure that mouseDrag() events sent continuously, even
  16317. when the mouse isn't moving. This can be useful for things like auto-scrolling
  16318. components when the mouse is near an edge.
  16319. Call this method during a mouseDown() or mouseDrag() callback, specifying the
  16320. minimum interval between consecutive mouse drag callbacks. The callbacks
  16321. will continue until the mouse is released, and then the interval will be reset,
  16322. so you need to make sure it's called every time you begin a drag event. If it
  16323. is called when the mouse isn't actually being pressed, it will apply to the next
  16324. mouse-drag operation that happens.
  16325. Passing an interval of 0 or less will cancel the auto-repeat.
  16326. @see mouseDrag
  16327. */
  16328. static void beginDragAutoRepeat (const int millisecondIntervalBetweenCallbacks);
  16329. /** Causes automatic repaints when the mouse enters or exits this component.
  16330. If turned on, then when the mouse enters/exits, or when the button is pressed/released
  16331. on the component, it will trigger a repaint.
  16332. This is handy for things like buttons that need to draw themselves differently when
  16333. the mouse moves over them, and it avoids having to override all the different mouse
  16334. callbacks and call repaint().
  16335. @see mouseEnter, mouseExit, mouseDown, mouseUp
  16336. */
  16337. void setRepaintsOnMouseActivity (const bool shouldRepaint) throw();
  16338. /** Registers a listener to be told when mouse events occur in this component.
  16339. If you need to get informed about mouse events in a component but can't or
  16340. don't want to override its methods, you can attach any number of listeners
  16341. to the component, and these will get told about the events in addition to
  16342. the component's own callbacks being called.
  16343. Note that a MouseListener can also be attached to more than one component.
  16344. @param newListener the listener to register
  16345. @param wantsEventsForAllNestedChildComponents if true, the listener will receive callbacks
  16346. for events that happen to any child component
  16347. within this component, including deeply-nested
  16348. child components. If false, it will only be
  16349. told about events that this component handles.
  16350. @see MouseListener, removeMouseListener
  16351. */
  16352. void addMouseListener (MouseListener* const newListener,
  16353. const bool wantsEventsForAllNestedChildComponents) throw();
  16354. /** Deregisters a mouse listener.
  16355. @see addMouseListener, MouseListener
  16356. */
  16357. void removeMouseListener (MouseListener* const listenerToRemove) throw();
  16358. /** Adds a listener that wants to hear about keypresses that this component receives.
  16359. The listeners that are registered with a component are called by its keyPressed() or
  16360. keyStateChanged() methods (assuming these haven't been overridden to do something else).
  16361. If you add an object as a key listener, be careful to remove it when the object
  16362. is deleted, or the component will be left with a dangling pointer.
  16363. @see keyPressed, keyStateChanged, removeKeyListener
  16364. */
  16365. void addKeyListener (KeyListener* const newListener) throw();
  16366. /** Removes a previously-registered key listener.
  16367. @see addKeyListener
  16368. */
  16369. void removeKeyListener (KeyListener* const listenerToRemove) throw();
  16370. /** Called when a key is pressed.
  16371. When a key is pressed, the component that has the keyboard focus will have this
  16372. method called. Remember that a component will only be given the focus if its
  16373. setWantsKeyboardFocus() method has been used to enable this.
  16374. If your implementation returns true, the event will be consumed and not passed
  16375. on to any other listeners. If it returns false, the key will be passed to any
  16376. KeyListeners that have been registered with this component. As soon as one of these
  16377. returns true, the process will stop, but if they all return false, the event will
  16378. be passed upwards to this component's parent, and so on.
  16379. The default implementation of this method does nothing and returns false.
  16380. @see keyStateChanged, getCurrentlyFocusedComponent, addKeyListener
  16381. */
  16382. virtual bool keyPressed (const KeyPress& key);
  16383. /** Called when a key is pressed or released.
  16384. Whenever a key on the keyboard is pressed or released (including modifier keys
  16385. like shift and ctrl), this method will be called on the component that currently
  16386. has the keyboard focus. Remember that a component will only be given the focus if
  16387. its setWantsKeyboardFocus() method has been used to enable this.
  16388. If your implementation returns true, the event will be consumed and not passed
  16389. on to any other listeners. If it returns false, then any KeyListeners that have
  16390. been registered with this component will have their keyStateChanged methods called.
  16391. As soon as one of these returns true, the process will stop, but if they all return
  16392. false, the event will be passed upwards to this component's parent, and so on.
  16393. The default implementation of this method does nothing and returns false.
  16394. To find out which keys are up or down at any time, see the KeyPress::isKeyCurrentlyDown()
  16395. method.
  16396. @see keyPressed, KeyPress, getCurrentlyFocusedComponent, addKeyListener
  16397. */
  16398. virtual bool keyStateChanged();
  16399. /** Called when a modifier key is pressed or released.
  16400. Whenever the shift, control, alt or command keys are pressed or released,
  16401. this method will be called on the component that currently has the keyboard focus.
  16402. Remember that a component will only be given the focus if its setWantsKeyboardFocus()
  16403. method has been used to enable this.
  16404. The default implementation of this method actually calls its parent's modifierKeysChanged
  16405. method, so that focused components which aren't interested in this will give their
  16406. parents a chance to act on the event instead.
  16407. @see keyStateChanged, ModifierKeys
  16408. */
  16409. virtual void modifierKeysChanged (const ModifierKeys& modifiers);
  16410. /** Enumeration used by the focusChanged() and focusLost() methods. */
  16411. enum FocusChangeType
  16412. {
  16413. focusChangedByMouseClick, /**< Means that the user clicked the mouse to change focus. */
  16414. focusChangedByTabKey, /**< Means that the user pressed the tab key to move the focus. */
  16415. focusChangedDirectly /**< Means that the focus was changed by a call to grabKeyboardFocus(). */
  16416. };
  16417. /** Called to indicate that this component has just acquired the keyboard focus.
  16418. @see focusLost, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
  16419. */
  16420. virtual void focusGained (FocusChangeType cause);
  16421. /** Called to indicate that this component has just lost the keyboard focus.
  16422. @see focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
  16423. */
  16424. virtual void focusLost (FocusChangeType cause);
  16425. /** Called to indicate that one of this component's children has been focused or unfocused.
  16426. Essentially this means that the return value of a call to hasKeyboardFocus (true) has
  16427. changed. It happens when focus moves from one of this component's children (at any depth)
  16428. to a component that isn't contained in this one, (or vice-versa).
  16429. @see focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
  16430. */
  16431. virtual void focusOfChildComponentChanged (FocusChangeType cause);
  16432. /** Returns true if the mouse is currently over this component.
  16433. If the mouse isn't over the component, this will return false, even if the
  16434. mouse is currently being dragged - so you can use this in your mouseDrag
  16435. method to find out whether it's really over the component or not.
  16436. Note that when the mouse button is being held down, then the only component
  16437. for which this method will return true is the one that was originally
  16438. clicked on.
  16439. @see isMouseButtonDown. isMouseOverOrDragging, mouseDrag
  16440. */
  16441. bool isMouseOver() const throw();
  16442. /** Returns true if the mouse button is currently held down in this component.
  16443. Note that this is a test to see whether the mouse is being pressed in this
  16444. component, so it'll return false if called on component A when the mouse
  16445. is actually being dragged in component B.
  16446. @see isMouseButtonDownAnywhere, isMouseOver, isMouseOverOrDragging
  16447. */
  16448. bool isMouseButtonDown() const throw();
  16449. /** True if the mouse is over this component, or if it's being dragged in this component.
  16450. This is a handy equivalent to (isMouseOver() || isMouseButtonDown()).
  16451. @see isMouseOver, isMouseButtonDown, isMouseButtonDownAnywhere
  16452. */
  16453. bool isMouseOverOrDragging() const throw();
  16454. /** Returns true if a mouse button is currently down.
  16455. Unlike isMouseButtonDown, this will test the current state of the
  16456. buttons without regard to which component (if any) it has been
  16457. pressed in.
  16458. @see isMouseButtonDown, ModifierKeys
  16459. */
  16460. static bool JUCE_CALLTYPE isMouseButtonDownAnywhere() throw();
  16461. /** Returns the mouse's current position, relative to this component.
  16462. The co-ordinates are relative to the component's top-left corner.
  16463. */
  16464. void getMouseXYRelative (int& x, int& y) const throw();
  16465. /** Returns the component that's currently underneath the mouse.
  16466. @returns the component or 0 if there isn't one.
  16467. @see contains, getComponentAt
  16468. */
  16469. static Component* JUCE_CALLTYPE getComponentUnderMouse() throw();
  16470. /** Allows the mouse to move beyond the edges of the screen.
  16471. Calling this method when the mouse button is currently pressed inside this component
  16472. will remove the cursor from the screen and allow the mouse to (seem to) move beyond
  16473. the edges of the screen.
  16474. This means that the co-ordinates returned to mouseDrag() will be unbounded, and this
  16475. can be used for things like custom slider controls or dragging objects around, where
  16476. movement would be otherwise be limited by the mouse hitting the edges of the screen.
  16477. The unbounded mode is automatically turned off when the mouse button is released, or
  16478. it can be turned off explicitly by calling this method again.
  16479. @param shouldUnboundedMovementBeEnabled whether to turn this mode on or off
  16480. @param keepCursorVisibleUntilOffscreen if set to false, the cursor will immediately be
  16481. hidden; if true, it will only be hidden when it
  16482. is moved beyond the edge of the screen
  16483. */
  16484. void enableUnboundedMouseMovement (bool shouldUnboundedMovementBeEnabled,
  16485. bool keepCursorVisibleUntilOffscreen = false) throw();
  16486. /** Called when this component's size has been changed.
  16487. A component can implement this method to do things such as laying out its
  16488. child components when its width or height changes.
  16489. The method is called synchronously as a result of the setBounds or setSize
  16490. methods, so repeatedly changing a components size will repeatedly call its
  16491. resized method (unlike things like repainting, where multiple calls to repaint
  16492. are coalesced together).
  16493. If the component is a top-level window on the desktop, its size could also
  16494. be changed by operating-system factors beyond the application's control.
  16495. @see moved, setSize
  16496. */
  16497. virtual void resized();
  16498. /** Called when this component's position has been changed.
  16499. This is called when the position relative to its parent changes, not when
  16500. its absolute position on the screen changes (so it won't be called for
  16501. all child components when a parent component is moved).
  16502. The method is called synchronously as a result of the setBounds, setTopLeftPosition
  16503. or any of the other repositioning methods, and like resized(), it will be
  16504. called each time those methods are called.
  16505. If the component is a top-level window on the desktop, its position could also
  16506. be changed by operating-system factors beyond the application's control.
  16507. @see resized, setBounds
  16508. */
  16509. virtual void moved();
  16510. /** Called when one of this component's children is moved or resized.
  16511. If the parent wants to know about changes to its immediate children (not
  16512. to children of its children), this is the method to override.
  16513. @see moved, resized, parentSizeChanged
  16514. */
  16515. virtual void childBoundsChanged (Component* child);
  16516. /** Called when this component's immediate parent has been resized.
  16517. If the component is a top-level window, this indicates that the screen size
  16518. has changed.
  16519. @see childBoundsChanged, moved, resized
  16520. */
  16521. virtual void parentSizeChanged();
  16522. /** Called when this component has been moved to the front of its siblings.
  16523. The component may have been brought to the front by the toFront() method, or
  16524. by the operating system if it's a top-level window.
  16525. @see toFront
  16526. */
  16527. virtual void broughtToFront();
  16528. /** Adds a listener to be told about changes to the component hierarchy or position.
  16529. Component listeners get called when this component's size, position or children
  16530. change - see the ComponentListener class for more details.
  16531. @param newListener the listener to register - if this is already registered, it
  16532. will be ignored.
  16533. @see ComponentListener, removeComponentListener
  16534. */
  16535. void addComponentListener (ComponentListener* const newListener) throw();
  16536. /** Removes a component listener.
  16537. @see addComponentListener
  16538. */
  16539. void removeComponentListener (ComponentListener* const listenerToRemove) throw();
  16540. /** Dispatches a numbered message to this component.
  16541. This is a quick and cheap way of allowing simple asynchronous messages to
  16542. be sent to components. It's also safe, because if the component that you
  16543. send the message to is a null or dangling pointer, this won't cause an error.
  16544. The command ID is later delivered to the component's handleCommandMessage() method by
  16545. the application's message queue.
  16546. @see handleCommandMessage
  16547. */
  16548. void postCommandMessage (const int commandId) throw();
  16549. /** Called to handle a command that was sent by postCommandMessage().
  16550. This is called by the message thread when a command message arrives, and
  16551. the component can override this method to process it in any way it needs to.
  16552. @see postCommandMessage
  16553. */
  16554. virtual void handleCommandMessage (int commandId);
  16555. /** Runs a component modally, waiting until the loop terminates.
  16556. This method first makes the component visible, brings it to the front and
  16557. gives it the keyboard focus.
  16558. It then runs a loop, dispatching messages from the system message queue, but
  16559. blocking all mouse or keyboard messages from reaching any components other
  16560. than this one and its children.
  16561. This loop continues until the component's exitModalState() method is called (or
  16562. the component is deleted), and then this method returns, returning the value
  16563. passed into exitModalState().
  16564. @see enterModalState, exitModalState, isCurrentlyModal, getCurrentlyModalComponent,
  16565. isCurrentlyBlockedByAnotherModalComponent, MessageManager::dispatchNextMessage
  16566. */
  16567. int runModalLoop();
  16568. /** Puts the component into a modal state.
  16569. This makes the component modal, so that messages are blocked from reaching
  16570. any components other than this one and its children, but unlike runModalLoop(),
  16571. this method returns immediately.
  16572. If takeKeyboardFocus is true, the component will use grabKeyboardFocus() to
  16573. get the focus, which is usually what you'll want it to do. If not, it will leave
  16574. the focus unchanged.
  16575. @see exitModalState, runModalLoop
  16576. */
  16577. void enterModalState (const bool takeKeyboardFocus = true);
  16578. /** Ends a component's modal state.
  16579. If this component is currently modal, this will turn of its modalness, and return
  16580. a value to the runModalLoop() method that might have be running its modal loop.
  16581. @see runModalLoop, enterModalState, isCurrentlyModal
  16582. */
  16583. void exitModalState (const int returnValue);
  16584. /** Returns true if this component is the modal one.
  16585. It's possible to have nested modal components, e.g. a pop-up dialog box
  16586. that launches another pop-up, but this will only return true for
  16587. the one at the top of the stack.
  16588. @see getCurrentlyModalComponent
  16589. */
  16590. bool isCurrentlyModal() const throw();
  16591. /** Returns the component that is currently modal.
  16592. @returns the modal component, or null if no components are modal
  16593. @see runModalLoop, isCurrentlyModal
  16594. */
  16595. static Component* JUCE_CALLTYPE getCurrentlyModalComponent() throw();
  16596. /** Checks whether there's a modal component somewhere that's stopping this one
  16597. from receiving messages.
  16598. If there is a modal component, its canModalEventBeSentToComponent() method
  16599. will be called to see if it will still allow this component to receive events.
  16600. @see runModalLoop, getCurrentlyModalComponent
  16601. */
  16602. bool isCurrentlyBlockedByAnotherModalComponent() const throw();
  16603. /** When a component is modal, this callback allows it to choose which other
  16604. components can still receive events.
  16605. When a modal component is active and the user clicks on a non-modal component,
  16606. this method is called on the modal component, and if it returns true, the
  16607. event is allowed to reach its target. If it returns false, the event is blocked
  16608. and the inputAttemptWhenModal() callback is made.
  16609. It called by the isCurrentlyBlockedByAnotherModalComponent() method. The default
  16610. implementation just returns false in all cases.
  16611. */
  16612. virtual bool canModalEventBeSentToComponent (const Component* targetComponent);
  16613. /** Called when the user tries to click on a component that is blocked by another
  16614. modal component.
  16615. When a component is modal and the user clicks on one of the other components,
  16616. the modal component will receive this callback.
  16617. The default implementation of this method will play a beep, and bring the currently
  16618. modal component to the front, but it can be overridden to do other tasks.
  16619. @see isCurrentlyBlockedByAnotherModalComponent, canModalEventBeSentToComponent
  16620. */
  16621. virtual void inputAttemptWhenModal();
  16622. /** Returns one of the component's properties as a string.
  16623. @param keyName the name of the property to retrieve
  16624. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  16625. properties, then it will check whether the parent component has
  16626. the key.
  16627. @param defaultReturnValue a value to return if the named property doesn't actually exist
  16628. */
  16629. const String getComponentProperty (const String& keyName,
  16630. const bool useParentComponentIfNotFound,
  16631. const String& defaultReturnValue = String::empty) const throw();
  16632. /** Returns one of the properties as an integer.
  16633. @param keyName the name of the property to retrieve
  16634. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  16635. properties, then it will check whether the parent component has
  16636. the key.
  16637. @param defaultReturnValue a value to return if the named property doesn't actually exist
  16638. */
  16639. int getComponentPropertyInt (const String& keyName,
  16640. const bool useParentComponentIfNotFound,
  16641. const int defaultReturnValue = 0) const throw();
  16642. /** Returns one of the properties as an double.
  16643. @param keyName the name of the property to retrieve
  16644. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  16645. properties, then it will check whether the parent component has
  16646. the key.
  16647. @param defaultReturnValue a value to return if the named property doesn't actually exist
  16648. */
  16649. double getComponentPropertyDouble (const String& keyName,
  16650. const bool useParentComponentIfNotFound,
  16651. const double defaultReturnValue = 0.0) const throw();
  16652. /** Returns one of the properties as an boolean.
  16653. The result will be true if the string found for this key name can be parsed as a non-zero
  16654. integer.
  16655. @param keyName the name of the property to retrieve
  16656. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  16657. properties, then it will check whether the parent component has
  16658. the key.
  16659. @param defaultReturnValue a value to return if the named property doesn't actually exist
  16660. */
  16661. bool getComponentPropertyBool (const String& keyName,
  16662. const bool useParentComponentIfNotFound,
  16663. const bool defaultReturnValue = false) const throw();
  16664. /** Returns one of the properties as an colour.
  16665. @param keyName the name of the property to retrieve
  16666. @param useParentComponentIfNotFound if this is true and the key isn't present in this component's
  16667. properties, then it will check whether the parent component has
  16668. the key.
  16669. @param defaultReturnValue a colour to return if the named property doesn't actually exist
  16670. */
  16671. const Colour getComponentPropertyColour (const String& keyName,
  16672. const bool useParentComponentIfNotFound,
  16673. const Colour& defaultReturnValue = Colours::black) const throw();
  16674. /** Sets a named property as a string.
  16675. @param keyName the name of the property to set. (This mustn't be an empty string)
  16676. @param value the new value to set it to
  16677. @see removeComponentProperty
  16678. */
  16679. void setComponentProperty (const String& keyName, const String& value) throw();
  16680. /** Sets a named property to an integer.
  16681. @param keyName the name of the property to set. (This mustn't be an empty string)
  16682. @param value the new value to set it to
  16683. @see removeComponentProperty
  16684. */
  16685. void setComponentProperty (const String& keyName, const int value) throw();
  16686. /** Sets a named property to a double.
  16687. @param keyName the name of the property to set. (This mustn't be an empty string)
  16688. @param value the new value to set it to
  16689. @see removeComponentProperty
  16690. */
  16691. void setComponentProperty (const String& keyName, const double value) throw();
  16692. /** Sets a named property to a boolean.
  16693. @param keyName the name of the property to set. (This mustn't be an empty string)
  16694. @param value the new value to set it to
  16695. @see removeComponentProperty
  16696. */
  16697. void setComponentProperty (const String& keyName, const bool value) throw();
  16698. /** Sets a named property to a colour.
  16699. @param keyName the name of the property to set. (This mustn't be an empty string)
  16700. @param newColour the new colour to set it to
  16701. @see removeComponentProperty
  16702. */
  16703. void setComponentProperty (const String& keyName, const Colour& newColour) throw();
  16704. /** Deletes a named component property.
  16705. @param keyName the name of the property to delete. (This mustn't be an empty string)
  16706. @see setComponentProperty, getComponentProperty
  16707. */
  16708. void removeComponentProperty (const String& keyName) throw();
  16709. /** Returns the complete set of properties that have been set for this component.
  16710. If no properties have been set, this will return a null pointer.
  16711. @see getComponentProperty, setComponentProperty
  16712. */
  16713. PropertySet* getComponentProperties() const throw() { return propertySet_; }
  16714. /** Looks for a colour that has been registered with the given colour ID number.
  16715. If a colour has been set for this ID number using setColour(), then it is
  16716. returned. If none has been set, the method will try calling the component's
  16717. LookAndFeel class's findColour() method. If none has been registered with the
  16718. look-and-feel either, it will just return black.
  16719. The colour IDs for various purposes are stored as enums in the components that
  16720. they are relevent to - for an example, see Slider::ColourIds,
  16721. Label::ColourIds, TextEditor::ColourIds, TreeView::ColourIds, etc.
  16722. @see setColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour
  16723. */
  16724. const Colour findColour (const int colourId, const bool inheritFromParent = false) const throw();
  16725. /** Registers a colour to be used for a particular purpose.
  16726. Changing a colour will cause a synchronous callback to the colourChanged()
  16727. method, which your component can override if it needs to do something when
  16728. colours are altered.
  16729. For more details about colour IDs, see the comments for findColour().
  16730. @see findColour, isColourSpecified, colourChanged, LookAndFeel::findColour, LookAndFeel::setColour
  16731. */
  16732. void setColour (const int colourId, const Colour& colour);
  16733. /** If a colour has been set with setColour(), this will remove it.
  16734. This allows you to make a colour revert to its default state.
  16735. */
  16736. void removeColour (const int colourId);
  16737. /** Returns true if the specified colour ID has been explicitly set for this
  16738. component using the setColour() method.
  16739. */
  16740. bool isColourSpecified (const int colourId) const throw();
  16741. /** This looks for any colours that have been specified for this component,
  16742. and copies them to the specified target component.
  16743. */
  16744. void copyAllExplicitColoursTo (Component& target) const throw();
  16745. /** This method is called when a colour is changed by the setColour() method.
  16746. @see setColour, findColour
  16747. */
  16748. virtual void colourChanged();
  16749. /** Returns the underlying native window handle for this component.
  16750. This is platform-dependent and strictly for power-users only!
  16751. */
  16752. void* getWindowHandle() const throw();
  16753. /** When created, each component is given a number to uniquely identify it.
  16754. The number is incremented each time a new component is created, so it's a more
  16755. unique way of identifying a component than using its memory location (which
  16756. may be reused after the component is deleted, of course).
  16757. */
  16758. uint32 getComponentUID() const throw() { return componentUID; }
  16759. juce_UseDebuggingNewOperator
  16760. private:
  16761. friend class ComponentPeer;
  16762. friend class InternalDragRepeater;
  16763. static Component* currentlyFocusedComponent;
  16764. static Component* componentUnderMouse;
  16765. String componentName_;
  16766. Component* parentComponent_;
  16767. uint32 componentUID;
  16768. Rectangle bounds_;
  16769. unsigned short numDeepMouseListeners;
  16770. Array <Component*> childComponentList_;
  16771. LookAndFeel* lookAndFeel_;
  16772. MouseCursor cursor_;
  16773. ImageEffectFilter* effect_;
  16774. Image* bufferedImage_;
  16775. VoidArray* mouseListeners_;
  16776. VoidArray* keyListeners_;
  16777. VoidArray* componentListeners_;
  16778. PropertySet* propertySet_;
  16779. struct ComponentFlags
  16780. {
  16781. bool hasHeavyweightPeerFlag : 1;
  16782. bool visibleFlag : 1;
  16783. bool opaqueFlag : 1;
  16784. bool ignoresMouseClicksFlag : 1;
  16785. bool allowChildMouseClicksFlag : 1;
  16786. bool wantsFocusFlag : 1;
  16787. bool isFocusContainerFlag : 1;
  16788. bool dontFocusOnMouseClickFlag : 1;
  16789. bool alwaysOnTopFlag : 1;
  16790. bool bufferToImageFlag : 1;
  16791. bool bringToFrontOnClickFlag : 1;
  16792. bool repaintOnMouseActivityFlag : 1;
  16793. bool draggingFlag : 1;
  16794. bool mouseOverFlag : 1;
  16795. bool mouseInsideFlag : 1;
  16796. bool currentlyModalFlag : 1;
  16797. bool isDisabledFlag : 1;
  16798. bool childCompFocusedFlag : 1;
  16799. #ifdef JUCE_DEBUG
  16800. bool isInsidePaintCall : 1;
  16801. #endif
  16802. };
  16803. union
  16804. {
  16805. uint32 componentFlags_;
  16806. ComponentFlags flags;
  16807. };
  16808. void internalMouseEnter (int x, int y, const int64 time);
  16809. void internalMouseExit (int x, int y, const int64 time);
  16810. void internalMouseDown (int x, int y);
  16811. void internalMouseUp (const int oldModifiers, int x, int y, const int64 time);
  16812. void internalMouseDrag (int x, int y, const int64 time);
  16813. void internalMouseMove (int x, int y, const int64 time);
  16814. void internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time);
  16815. void internalBroughtToFront();
  16816. void internalFocusGain (const FocusChangeType cause);
  16817. void internalFocusLoss (const FocusChangeType cause);
  16818. void internalChildFocusChange (FocusChangeType cause);
  16819. void internalModalInputAttempt();
  16820. void internalModifierKeysChanged();
  16821. void internalChildrenChanged();
  16822. void internalHierarchyChanged();
  16823. void internalUpdateMouseCursor (const bool forcedUpdate) throw();
  16824. void sendMovedResizedMessages (const bool wasMoved, const bool wasResized);
  16825. void repaintParent() throw();
  16826. void sendFakeMouseMove() const;
  16827. void takeKeyboardFocus (const FocusChangeType cause);
  16828. void grabFocusInternal (const FocusChangeType cause, const bool canTryParent = true);
  16829. static void giveAwayFocus();
  16830. void sendEnablementChangeMessage();
  16831. static void* runModalLoopCallback (void*);
  16832. void subtractObscuredRegions (RectangleList& result,
  16833. const int deltaX, const int deltaY,
  16834. const Rectangle& clipRect,
  16835. const Component* const compToAvoid) const throw();
  16836. void clipObscuredRegions (Graphics& g, const Rectangle& clipRect,
  16837. const int deltaX, const int deltaY) const throw();
  16838. // how much of the component is not off the edges of its parents
  16839. const Rectangle getUnclippedArea() const;
  16840. void sendVisibilityChangeMessage();
  16841. // This is included here just to cause a compile error if your code is still handling
  16842. // drag-and-drop with this method. If so, just update it to use the new FileDragAndDropTarget
  16843. // class, which is easy (just make your class inherit from FileDragAndDropTarget, and
  16844. // implement its methods instead of this Component method).
  16845. virtual void filesDropped (const StringArray&, int, int) {}
  16846. // components aren't allowed to have copy constructors, as this would mess up parent
  16847. // hierarchies. You might need to give your subclasses a private dummy constructor like
  16848. // this one to avoid compiler warnings.
  16849. Component (const Component&);
  16850. const Component& operator= (const Component&);
  16851. protected:
  16852. /** @internal */
  16853. virtual void internalRepaint (int x, int y, int w, int h);
  16854. virtual ComponentPeer* createNewPeer (int styleFlags, void* nativeWindowToAttachTo);
  16855. /** Overridden from the MessageListener parent class.
  16856. You can override this if you really need to, but be sure to pass your unwanted messages up
  16857. to this base class implementation, as the Component class needs to send itself messages
  16858. to work properly.
  16859. */
  16860. void handleMessage (const Message&);
  16861. };
  16862. #endif // __JUCE_COMPONENT_JUCEHEADER__
  16863. /********* End of inlined file: juce_Component.h *********/
  16864. /********* Start of inlined file: juce_ApplicationCommandInfo.h *********/
  16865. #ifndef __JUCE_APPLICATIONCOMMANDINFO_JUCEHEADER__
  16866. #define __JUCE_APPLICATIONCOMMANDINFO_JUCEHEADER__
  16867. /********* Start of inlined file: juce_ApplicationCommandID.h *********/
  16868. #ifndef __JUCE_APPLICATIONCOMMANDID_JUCEHEADER__
  16869. #define __JUCE_APPLICATIONCOMMANDID_JUCEHEADER__
  16870. /** A type used to hold the unique ID for an application command.
  16871. This is a numeric type, so it can be stored as an integer.
  16872. @see ApplicationCommandInfo, ApplicationCommandManager,
  16873. ApplicationCommandTarget, KeyPressMappingSet
  16874. */
  16875. typedef int CommandID;
  16876. /** A set of general-purpose application command IDs.
  16877. Because these commands are likely to be used in most apps, they're defined
  16878. here to help different apps to use the same numeric values for them.
  16879. Of course you don't have to use these, but some of them are used internally by
  16880. Juce - e.g. the quit ID is recognised as a command by the JUCEApplication class.
  16881. @see ApplicationCommandInfo, ApplicationCommandManager,
  16882. ApplicationCommandTarget, KeyPressMappingSet
  16883. */
  16884. namespace StandardApplicationCommandIDs
  16885. {
  16886. /** This command ID should be used to send a "Quit the App" command.
  16887. This command is recognised by the JUCEApplication class, so if it is invoked
  16888. and no other ApplicationCommandTarget handles the event first, the JUCEApplication
  16889. object will catch it and call JUCEApplication::systemRequestedQuit().
  16890. */
  16891. static const CommandID quit = 0x1001;
  16892. /** The command ID that should be used to send a "Delete" command. */
  16893. static const CommandID del = 0x1002;
  16894. /** The command ID that should be used to send a "Cut" command. */
  16895. static const CommandID cut = 0x1003;
  16896. /** The command ID that should be used to send a "Copy to clipboard" command. */
  16897. static const CommandID copy = 0x1004;
  16898. /** The command ID that should be used to send a "Paste from clipboard" command. */
  16899. static const CommandID paste = 0x1005;
  16900. /** The command ID that should be used to send a "Select all" command. */
  16901. static const CommandID selectAll = 0x1006;
  16902. /** The command ID that should be used to send a "Deselect all" command. */
  16903. static const CommandID deselectAll = 0x1007;
  16904. }
  16905. #endif // __JUCE_APPLICATIONCOMMANDID_JUCEHEADER__
  16906. /********* End of inlined file: juce_ApplicationCommandID.h *********/
  16907. /**
  16908. Holds information describing an application command.
  16909. This object is used to pass information about a particular command, such as its
  16910. name, description and other usage flags.
  16911. When an ApplicationCommandTarget is asked to provide information about the commands
  16912. it can perform, this is the structure gets filled-in to describe each one.
  16913. @see ApplicationCommandTarget, ApplicationCommandTarget::getCommandInfo(),
  16914. ApplicationCommandManager
  16915. */
  16916. struct JUCE_API ApplicationCommandInfo
  16917. {
  16918. ApplicationCommandInfo (const CommandID commandID) throw();
  16919. /** Sets a number of the structures values at once.
  16920. The meanings of each of the parameters is described below, in the appropriate
  16921. member variable's description.
  16922. */
  16923. void setInfo (const String& shortName,
  16924. const String& description,
  16925. const String& categoryName,
  16926. const int flags) throw();
  16927. /** An easy way to set or remove the isDisabled bit in the structure's flags field.
  16928. If isActive is true, the flags member has the isDisabled bit cleared; if isActive
  16929. is false, the bit is set.
  16930. */
  16931. void setActive (const bool isActive) throw();
  16932. /** An easy way to set or remove the isTicked bit in the structure's flags field.
  16933. */
  16934. void setTicked (const bool isTicked) throw();
  16935. /** Handy method for adding a keypress to the defaultKeypresses array.
  16936. This is just so you can write things like:
  16937. @code
  16938. myinfo.addDefaultKeypress (T('s'), ModifierKeys::commandModifier);
  16939. @endcode
  16940. instead of
  16941. @code
  16942. myinfo.defaultKeypresses.add (KeyPress (T('s'), ModifierKeys::commandModifier));
  16943. @endcode
  16944. */
  16945. void addDefaultKeypress (const int keyCode,
  16946. const ModifierKeys& modifiers) throw();
  16947. /** The command's unique ID number.
  16948. */
  16949. CommandID commandID;
  16950. /** A short name to describe the command.
  16951. This should be suitable for use in menus, on buttons that trigger the command, etc.
  16952. You can use the setInfo() method to quickly set this and some of the command's
  16953. other properties.
  16954. */
  16955. String shortName;
  16956. /** A longer description of the command.
  16957. This should be suitable for use in contexts such as a KeyMappingEditorComponent or
  16958. pop-up tooltip describing what the command does.
  16959. You can use the setInfo() method to quickly set this and some of the command's
  16960. other properties.
  16961. */
  16962. String description;
  16963. /** A named category that the command fits into.
  16964. You can give your commands any category you like, and these will be displayed in
  16965. contexts such as the KeyMappingEditorComponent, where the category is used to group
  16966. commands together.
  16967. You can use the setInfo() method to quickly set this and some of the command's
  16968. other properties.
  16969. */
  16970. String categoryName;
  16971. /** A list of zero or more keypresses that should be used as the default keys for
  16972. this command.
  16973. Methods such as KeyPressMappingSet::resetToDefaultMappings() will use the keypresses in
  16974. this list to initialise the default set of key-to-command mappings.
  16975. @see addDefaultKeypress
  16976. */
  16977. Array <KeyPress> defaultKeypresses;
  16978. /** Flags describing the ways in which this command should be used.
  16979. A bitwise-OR of these values is stored in the ApplicationCommandInfo::flags
  16980. variable.
  16981. */
  16982. enum CommandFlags
  16983. {
  16984. /** Indicates that the command can't currently be performed.
  16985. The ApplicationCommandTarget::getCommandInfo() method must set this flag if it's
  16986. not currently permissable to perform the command. If the flag is set, then
  16987. components that trigger the command, e.g. PopupMenu, may choose to grey-out the
  16988. command or show themselves as not being enabled.
  16989. @see ApplicationCommandInfo::setActive
  16990. */
  16991. isDisabled = 1 << 0,
  16992. /** Indicates that the command should have a tick next to it on a menu.
  16993. If your command is shown on a menu and this is set, it'll show a tick next to
  16994. it. Other components such as buttons may also use this flag to indicate that it
  16995. is a value that can be toggled, and is currently in the 'on' state.
  16996. @see ApplicationCommandInfo::setTicked
  16997. */
  16998. isTicked = 1 << 1,
  16999. /** If this flag is present, then when a KeyPressMappingSet invokes the command,
  17000. it will call the command twice, once on key-down and again on key-up.
  17001. @see ApplicationCommandTarget::InvocationInfo
  17002. */
  17003. wantsKeyUpDownCallbacks = 1 << 2,
  17004. /** If this flag is present, then a KeyMappingEditorComponent will not display the
  17005. command in its list.
  17006. */
  17007. hiddenFromKeyEditor = 1 << 3,
  17008. /** If this flag is present, then a KeyMappingEditorComponent will display the
  17009. command in its list, but won't allow the assigned keypress to be changed.
  17010. */
  17011. readOnlyInKeyEditor = 1 << 4,
  17012. /** If this flag is present and the command is invoked from a keypress, then any
  17013. buttons or menus that are also connected to the command will not flash to
  17014. indicate that they've been triggered.
  17015. */
  17016. dontTriggerVisualFeedback = 1 << 5
  17017. };
  17018. /** A bitwise-OR of the values specified in the CommandFlags enum.
  17019. You can use the setInfo() method to quickly set this and some of the command's
  17020. other properties.
  17021. */
  17022. int flags;
  17023. };
  17024. #endif // __JUCE_APPLICATIONCOMMANDINFO_JUCEHEADER__
  17025. /********* End of inlined file: juce_ApplicationCommandInfo.h *********/
  17026. /**
  17027. A command target publishes a list of command IDs that it can perform.
  17028. An ApplicationCommandManager despatches commands to targets, which must be
  17029. able to provide information about what commands they can handle.
  17030. To create a target, you'll need to inherit from this class, implementing all of
  17031. its pure virtual methods.
  17032. For info about how a target is chosen to receive a command, see
  17033. ApplicationCommandManager::getFirstCommandTarget().
  17034. @see ApplicationCommandManager, ApplicationCommandInfo
  17035. */
  17036. class JUCE_API ApplicationCommandTarget
  17037. {
  17038. public:
  17039. /** Creates a command target. */
  17040. ApplicationCommandTarget();
  17041. /** Destructor. */
  17042. virtual ~ApplicationCommandTarget();
  17043. /**
  17044. */
  17045. struct JUCE_API InvocationInfo
  17046. {
  17047. InvocationInfo (const CommandID commandID) throw();
  17048. /** The UID of the command that should be performed. */
  17049. CommandID commandID;
  17050. /** The command's flags.
  17051. See ApplicationCommandInfo for a description of these flag values.
  17052. */
  17053. int commandFlags;
  17054. /** The types of context in which the command might be called. */
  17055. enum InvocationMethod
  17056. {
  17057. direct = 0, /**< The command is being invoked directly by a piece of code. */
  17058. fromKeyPress, /**< The command is being invoked by a key-press. */
  17059. fromMenu, /**< The command is being invoked by a menu selection. */
  17060. fromButton /**< The command is being invoked by a button click. */
  17061. };
  17062. /** The type of event that triggered this command. */
  17063. InvocationMethod invocationMethod;
  17064. /** If triggered by a keypress or menu, this will be the component that had the
  17065. keyboard focus at the time.
  17066. If triggered by a button, it may be set to that component, or it may be null.
  17067. */
  17068. Component* originatingComponent;
  17069. /** The keypress that was used to invoke it.
  17070. Note that this will be an invalid keypress if the command was invoked
  17071. by some other means than a keyboard shortcut.
  17072. */
  17073. KeyPress keyPress;
  17074. /** True if the callback is being invoked when the key is pressed,
  17075. false if the key is being released.
  17076. @see KeyPressMappingSet::addCommand()
  17077. */
  17078. bool isKeyDown;
  17079. /** If the key is being released, this indicates how long it had been held
  17080. down for.
  17081. (Only relevant if isKeyDown is false.)
  17082. */
  17083. int millisecsSinceKeyPressed;
  17084. };
  17085. /** This must return the next target to try after this one.
  17086. When a command is being sent, and the first target can't handle
  17087. that command, this method is used to determine the next target that should
  17088. be tried.
  17089. It may return 0 if it doesn't know of another target.
  17090. If your target is a Component, you would usually use the findFirstTargetParentComponent()
  17091. method to return a parent component that might want to handle it.
  17092. @see invoke
  17093. */
  17094. virtual ApplicationCommandTarget* getNextCommandTarget() = 0;
  17095. /** This must return a complete list of commands that this target can handle.
  17096. Your target should add all the command IDs that it handles to the array that is
  17097. passed-in.
  17098. */
  17099. virtual void getAllCommands (Array <CommandID>& commands) = 0;
  17100. /** This must provide details about one of the commands that this target can perform.
  17101. This will be called with one of the command IDs that the target provided in its
  17102. getAllCommands() methods.
  17103. It should fill-in all appropriate fields of the ApplicationCommandInfo structure with
  17104. suitable information about the command. (The commandID field will already have been filled-in
  17105. by the caller).
  17106. The easiest way to set the info is using the ApplicationCommandInfo::setInfo() method to
  17107. set all the fields at once.
  17108. If the command is currently inactive for some reason, this method must use
  17109. ApplicationCommandInfo::setActive() to make that clear, (or it should set the isDisabled
  17110. bit of the ApplicationCommandInfo::flags field).
  17111. Any default key-presses for the command should be appended to the
  17112. ApplicationCommandInfo::defaultKeypresses field.
  17113. Note that if you change something that affects the status of the commands
  17114. that would be returned by this method (e.g. something that makes some commands
  17115. active or inactive), you should call ApplicationCommandManager::commandStatusChanged()
  17116. to cause the manager to refresh its status.
  17117. */
  17118. virtual void getCommandInfo (const CommandID commandID,
  17119. ApplicationCommandInfo& result) = 0;
  17120. /** This must actually perform the specified command.
  17121. If this target is able to perform the command specified by the commandID field of the
  17122. InvocationInfo structure, then it should do so, and must return true.
  17123. If it can't handle this command, it should return false, which tells the caller to pass
  17124. the command on to the next target in line.
  17125. @see invoke, ApplicationCommandManager::invoke
  17126. */
  17127. virtual bool perform (const InvocationInfo& info) = 0;
  17128. /** Makes this target invoke a command.
  17129. Your code can call this method to invoke a command on this target, but normally
  17130. you'd call it indirectly via ApplicationCommandManager::invoke() or
  17131. ApplicationCommandManager::invokeDirectly().
  17132. If this target can perform the given command, it will call its perform() method to
  17133. do so. If not, then getNextCommandTarget() will be used to determine the next target
  17134. to try, and the command will be passed along to it.
  17135. @param invocationInfo this must be correctly filled-in, describing the context for
  17136. the invocation.
  17137. @param asynchronously if false, the command will be performed before this method returns.
  17138. If true, a message will be posted so that the command will be performed
  17139. later on the message thread, and this method will return immediately.
  17140. @see perform, ApplicationCommandManager::invoke
  17141. */
  17142. bool invoke (const InvocationInfo& invocationInfo,
  17143. const bool asynchronously);
  17144. /** Invokes a given command directly on this target.
  17145. This is just an easy way to call invoke() without having to fill out the InvocationInfo
  17146. structure.
  17147. */
  17148. bool invokeDirectly (const CommandID commandID,
  17149. const bool asynchronously);
  17150. /** Searches this target and all subsequent ones for the first one that can handle
  17151. the specified command.
  17152. This will use getNextCommandTarget() to determine the chain of targets to try
  17153. after this one.
  17154. */
  17155. ApplicationCommandTarget* getTargetForCommand (const CommandID commandID);
  17156. /** Checks whether this command can currently be performed by this target.
  17157. This will return true only if a call to getCommandInfo() doesn't set the
  17158. isDisabled flag to indicate that the command is inactive.
  17159. */
  17160. bool isCommandActive (const CommandID commandID);
  17161. /** If this object is a Component, this method will seach upwards in its current
  17162. UI hierarchy for the next parent component that implements the
  17163. ApplicationCommandTarget class.
  17164. If your target is a Component, this is a very handy method to use in your
  17165. getNextCommandTarget() implementation.
  17166. */
  17167. ApplicationCommandTarget* findFirstTargetParentComponent();
  17168. juce_UseDebuggingNewOperator
  17169. private:
  17170. // (for async invocation of commands)
  17171. class CommandTargetMessageInvoker : public MessageListener
  17172. {
  17173. public:
  17174. CommandTargetMessageInvoker (ApplicationCommandTarget* const owner);
  17175. ~CommandTargetMessageInvoker();
  17176. void handleMessage (const Message& message);
  17177. private:
  17178. ApplicationCommandTarget* const owner;
  17179. CommandTargetMessageInvoker (const CommandTargetMessageInvoker&);
  17180. const CommandTargetMessageInvoker& operator= (const CommandTargetMessageInvoker&);
  17181. };
  17182. CommandTargetMessageInvoker* messageInvoker;
  17183. friend class CommandTargetMessageInvoker;
  17184. bool tryToInvoke (const InvocationInfo& info, const bool async);
  17185. };
  17186. #endif // __JUCE_APPLICATIONCOMMANDTARGET_JUCEHEADER__
  17187. /********* End of inlined file: juce_ApplicationCommandTarget.h *********/
  17188. /********* Start of inlined file: juce_ActionListener.h *********/
  17189. #ifndef __JUCE_ACTIONLISTENER_JUCEHEADER__
  17190. #define __JUCE_ACTIONLISTENER_JUCEHEADER__
  17191. /**
  17192. Receives callbacks to indicate that some kind of event has occurred.
  17193. Used by various classes, e.g. buttons when they are pressed, to tell listeners
  17194. about something that's happened.
  17195. @see ActionListenerList, ActionBroadcaster, ChangeListener
  17196. */
  17197. class JUCE_API ActionListener
  17198. {
  17199. public:
  17200. /** Destructor. */
  17201. virtual ~ActionListener() {}
  17202. /** Overridden by your subclass to receive the callback.
  17203. @param message the string that was specified when the event was triggered
  17204. by a call to ActionListenerList::sendActionMessage()
  17205. */
  17206. virtual void actionListenerCallback (const String& message) = 0;
  17207. };
  17208. #endif // __JUCE_ACTIONLISTENER_JUCEHEADER__
  17209. /********* End of inlined file: juce_ActionListener.h *********/
  17210. /**
  17211. An instance of this class is used to specify initialisation and shutdown
  17212. code for the application.
  17213. An application that wants to run in the JUCE framework needs to declare a
  17214. subclass of JUCEApplication and implement its various pure virtual methods.
  17215. It then needs to use the START_JUCE_APPLICATION macro somewhere in a cpp file
  17216. to declare an instance of this class and generate a suitable platform-specific
  17217. main() function.
  17218. e.g. @code
  17219. class MyJUCEApp : public JUCEApplication
  17220. {
  17221. // NEVER put objects inside a JUCEApplication class - only use pointers to
  17222. // objects, which you must create in the initialise() method.
  17223. MyApplicationWindow* myMainWindow;
  17224. public:
  17225. MyJUCEApp()
  17226. : myMainWindow (0)
  17227. {
  17228. // never create any Juce objects in the constructor - do all your initialisation
  17229. // in the initialise() method.
  17230. }
  17231. ~MyJUCEApp()
  17232. {
  17233. // all your shutdown code must have already been done in the shutdown() method -
  17234. // nothing should happen in this destructor.
  17235. }
  17236. void initialise (const String& commandLine)
  17237. {
  17238. myMainWindow = new MyApplicationWindow();
  17239. myMainWindow->setBounds (100, 100, 400, 500);
  17240. myMainWindow->setVisible (true);
  17241. }
  17242. void shutdown()
  17243. {
  17244. delete myMainWindow;
  17245. }
  17246. const String getApplicationName()
  17247. {
  17248. return T("Super JUCE-o-matic");
  17249. }
  17250. const String getApplicationVersion()
  17251. {
  17252. return T("1.0");
  17253. }
  17254. };
  17255. // this creates wrapper code to actually launch the app properly.
  17256. START_JUCE_APPLICATION (MyJUCEApp)
  17257. @endcode
  17258. Because this object will be created before Juce has properly initialised, you must
  17259. NEVER add any member variable objects that will be automatically constructed. Likewise
  17260. don't put ANY code in the constructor that could call Juce functions. Any objects that
  17261. you want to add to the class must be pointers, which you should instantiate during the
  17262. initialise() method, and delete in the shutdown() method.
  17263. @see MessageManager, DeletedAtShutdown
  17264. */
  17265. class JUCE_API JUCEApplication : public ApplicationCommandTarget,
  17266. private ActionListener
  17267. {
  17268. protected:
  17269. /** Constructs a JUCE app object.
  17270. If subclasses implement a constructor or destructor, they shouldn't call any
  17271. JUCE code in there - put your startup/shutdown code in initialise() and
  17272. shutdown() instead.
  17273. */
  17274. JUCEApplication();
  17275. public:
  17276. /** Destructor.
  17277. If subclasses implement a constructor or destructor, they shouldn't call any
  17278. JUCE code in there - put your startup/shutdown code in initialise() and
  17279. shutdown() instead.
  17280. */
  17281. virtual ~JUCEApplication();
  17282. /** Returns the global instance of the application object being run. */
  17283. static JUCEApplication* getInstance() throw();
  17284. /** Called when the application starts.
  17285. This will be called once to let the application do whatever initialisation
  17286. it needs, create its windows, etc.
  17287. After the method returns, the normal event-dispatch loop will be run,
  17288. until the quit() method is called, at which point the shutdown()
  17289. method will be called to let the application clear up anything it needs
  17290. to delete.
  17291. If during the initialise() method, the application decides not to start-up
  17292. after all, it can just call the quit() method and the event loop won't be run.
  17293. @param commandLineParameters the line passed in does not include the
  17294. name of the executable, just the parameter list.
  17295. @see shutdown, quit
  17296. */
  17297. virtual void initialise (const String& commandLineParameters) = 0;
  17298. /** Returns true if the application hasn't yet completed its initialise() method
  17299. and entered the main event loop.
  17300. This is handy for things like splash screens to know when the app's up-and-running
  17301. properly.
  17302. */
  17303. bool isInitialising() const throw();
  17304. /* Called to allow the application to clear up before exiting.
  17305. After JUCEApplication::quit() has been called, the event-dispatch loop will
  17306. terminate, and this method will get called to allow the app to sort itself
  17307. out.
  17308. Be careful that nothing happens in this method that might rely on messages
  17309. being sent, or any kind of window activity, because the message loop is no
  17310. longer running at this point.
  17311. @see DeletedAtShutdown
  17312. */
  17313. virtual void shutdown() = 0;
  17314. /** Returns the application's name.
  17315. An application must implement this to name itself.
  17316. */
  17317. virtual const String getApplicationName() = 0;
  17318. /** Returns the application's version number.
  17319. An application can implement this to give itself a version.
  17320. (The default implementation of this just returns an empty string).
  17321. */
  17322. virtual const String getApplicationVersion();
  17323. /** Checks whether multiple instances of the app are allowed.
  17324. If you application class returns true for this, more than one instance is
  17325. permitted to run (except on the Mac where this isn't possible).
  17326. If it's false, the second instance won't start, but it you will still get a
  17327. callback to anotherInstanceStarted() to tell you about this - which
  17328. gives you a chance to react to what the user was trying to do.
  17329. */
  17330. virtual bool moreThanOneInstanceAllowed();
  17331. /** Indicates that the user has tried to start up another instance of the app.
  17332. This will get called even if moreThanOneInstanceAllowed() is false.
  17333. */
  17334. virtual void anotherInstanceStarted (const String& commandLine);
  17335. /** Called when the operating system is trying to close the application.
  17336. The default implementation of this method is to call quit(), but it may
  17337. be overloaded to ignore the request or do some other special behaviour
  17338. instead. For example, you might want to offer the user the chance to save
  17339. their changes before quitting, and give them the chance to cancel.
  17340. If you want to send a quit signal to your app, this is the correct method
  17341. to call, because it means that requests that come from the system get handled
  17342. in the same way as those from your own application code. So e.g. you'd
  17343. call this method from a "quit" item on a menu bar.
  17344. */
  17345. virtual void systemRequestedQuit();
  17346. /** If any unhandled exceptions make it through to the message dispatch loop, this
  17347. callback will be triggered, in case you want to log them or do some other
  17348. type of error-handling.
  17349. If the type of exception is derived from the std::exception class, the pointer
  17350. passed-in will be valid. If the exception is of unknown type, this pointer
  17351. will be null.
  17352. */
  17353. virtual void unhandledException (const std::exception* e,
  17354. const String& sourceFilename,
  17355. const int lineNumber);
  17356. /** Signals that the main message loop should stop and the application should terminate.
  17357. This isn't synchronous, it just posts a quit message to the main queue, and
  17358. when this message arrives, the message loop will stop, the shutdown() method
  17359. will be called, and the app will exit.
  17360. Note that this will cause an unconditional quit to happen, so if you need an
  17361. extra level before this, e.g. to give the user the chance to save their work
  17362. and maybe cancel the quit, you'll need to handle this in the systemRequestedQuit()
  17363. method - see that method's help for more info.
  17364. @param useMaximumForce if this is true, the process will be forcibly killed
  17365. before leaving the WinMain or main() function, which can
  17366. be useful if threads might have got stuck somehow.
  17367. @see MessageManager, DeletedAtShutdown
  17368. */
  17369. static void quit (const bool useMaximumForce = false);
  17370. /** Sets the value that should be returned as the application's exit code when the
  17371. app quits.
  17372. This is the value that's returned by the main() function. Normally you'd leave this
  17373. as 0 unless you want to indicate an error code.
  17374. @see getApplicationReturnValue
  17375. */
  17376. void setApplicationReturnValue (const int newReturnValue) throw();
  17377. /** Returns the value that has been set as the application's exit code.
  17378. @see setApplicationReturnValue
  17379. */
  17380. int getApplicationReturnValue() const throw() { return appReturnValue; }
  17381. // These are used by the START_JUCE_APPLICATION() macro and aren't for public use.
  17382. /** @internal */
  17383. static int main (String& commandLine, JUCEApplication* const newApp);
  17384. /** @internal */
  17385. static int main (int argc, char* argv[], JUCEApplication* const newApp);
  17386. /** @internal */
  17387. static void sendUnhandledException (const std::exception* const e,
  17388. const char* const sourceFile,
  17389. const int lineNumber);
  17390. /** @internal */
  17391. ApplicationCommandTarget* getNextCommandTarget();
  17392. /** @internal */
  17393. void getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result);
  17394. /** @internal */
  17395. void getAllCommands (Array <CommandID>& commands);
  17396. /** @internal */
  17397. bool perform (const InvocationInfo& info);
  17398. /** @internal */
  17399. void actionListenerCallback (const String& message);
  17400. private:
  17401. int appReturnValue;
  17402. bool stillInitialising;
  17403. static int shutdownAppAndClearUp (const bool useMaximumForce);
  17404. };
  17405. #endif // __JUCE_APPLICATION_JUCEHEADER__
  17406. /********* End of inlined file: juce_Application.h *********/
  17407. #endif
  17408. #ifndef __JUCE_APPLICATIONCOMMANDID_JUCEHEADER__
  17409. #endif
  17410. #ifndef __JUCE_APPLICATIONCOMMANDINFO_JUCEHEADER__
  17411. #endif
  17412. #ifndef __JUCE_APPLICATIONCOMMANDMANAGER_JUCEHEADER__
  17413. /********* Start of inlined file: juce_ApplicationCommandManager.h *********/
  17414. #ifndef __JUCE_APPLICATIONCOMMANDMANAGER_JUCEHEADER__
  17415. #define __JUCE_APPLICATIONCOMMANDMANAGER_JUCEHEADER__
  17416. /********* Start of inlined file: juce_AsyncUpdater.h *********/
  17417. #ifndef __JUCE_ASYNCUPDATER_JUCEHEADER__
  17418. #define __JUCE_ASYNCUPDATER_JUCEHEADER__
  17419. /**
  17420. Has a callback method that is triggered asynchronously.
  17421. This object allows an asynchronous callback function to be triggered, for
  17422. tasks such as coalescing multiple updates into a single callback later on.
  17423. Basically, one or more calls to the triggerAsyncUpdate() will result in the
  17424. message thread calling handleAsyncUpdate() as soon as it can.
  17425. */
  17426. class JUCE_API AsyncUpdater
  17427. {
  17428. public:
  17429. /** Creates an AsyncUpdater object. */
  17430. AsyncUpdater() throw();
  17431. /** Destructor.
  17432. If there are any pending callbacks when the object is deleted, these are lost.
  17433. */
  17434. virtual ~AsyncUpdater();
  17435. /** Causes the callback to be triggered at a later time.
  17436. This method returns immediately, having made sure that a callback
  17437. to the handleAsyncUpdate() method will occur as soon as possible.
  17438. If an update callback is already pending but hasn't happened yet, calls
  17439. to this method will be ignored.
  17440. It's thread-safe to call this method from any number of threads without
  17441. needing to worry about locking.
  17442. */
  17443. void triggerAsyncUpdate() throw();
  17444. /** This will stop any pending updates from happening.
  17445. If called after triggerAsyncUpdate() and before the handleAsyncUpdate()
  17446. callback happens, this will cancel the handleAsyncUpdate() callback.
  17447. */
  17448. void cancelPendingUpdate() throw();
  17449. /** If an update has been triggered and is pending, this will invoke it
  17450. synchronously.
  17451. Use this as a kind of "flush" operation - if an update is pending, the
  17452. handleAsyncUpdate() method will be called immediately; if no update is
  17453. pending, then nothing will be done.
  17454. */
  17455. void handleUpdateNowIfNeeded();
  17456. /** Called back to do whatever your class needs to do.
  17457. This method is called by the message thread at the next convenient time
  17458. after the triggerAsyncUpdate() method has been called.
  17459. */
  17460. virtual void handleAsyncUpdate() = 0;
  17461. private:
  17462. class AsyncUpdaterInternal : public MessageListener
  17463. {
  17464. public:
  17465. AsyncUpdaterInternal() throw() {}
  17466. ~AsyncUpdaterInternal() {}
  17467. void handleMessage (const Message&);
  17468. AsyncUpdater* owner;
  17469. private:
  17470. AsyncUpdaterInternal (const AsyncUpdaterInternal&);
  17471. const AsyncUpdaterInternal& operator= (const AsyncUpdaterInternal&);
  17472. };
  17473. AsyncUpdaterInternal internalAsyncHandler;
  17474. bool asyncMessagePending;
  17475. };
  17476. #endif // __JUCE_ASYNCUPDATER_JUCEHEADER__
  17477. /********* End of inlined file: juce_AsyncUpdater.h *********/
  17478. /********* Start of inlined file: juce_Desktop.h *********/
  17479. #ifndef __JUCE_DESKTOP_JUCEHEADER__
  17480. #define __JUCE_DESKTOP_JUCEHEADER__
  17481. /********* Start of inlined file: juce_DeletedAtShutdown.h *********/
  17482. #ifndef __JUCE_DELETEDATSHUTDOWN_JUCEHEADER__
  17483. #define __JUCE_DELETEDATSHUTDOWN_JUCEHEADER__
  17484. /**
  17485. Classes derived from this will be automatically deleted when the application exits.
  17486. After JUCEApplication::shutdown() has been called, any objects derived from
  17487. DeletedAtShutdown which are still in existence will be deleted in the reverse
  17488. order to that in which they were created.
  17489. So if you've got a singleton and don't want to have to explicitly delete it, just
  17490. inherit from this and it'll be taken care of.
  17491. */
  17492. class JUCE_API DeletedAtShutdown
  17493. {
  17494. protected:
  17495. /** Creates a DeletedAtShutdown object. */
  17496. DeletedAtShutdown() throw();
  17497. /** Destructor.
  17498. It's ok to delete these objects explicitly - it's only the ones left
  17499. dangling at the end that will be deleted automatically.
  17500. */
  17501. virtual ~DeletedAtShutdown();
  17502. public:
  17503. /** Deletes all extant objects.
  17504. This shouldn't be used by applications, as it's called automatically
  17505. in the shutdown code of the JUCEApplication class.
  17506. */
  17507. static void deleteAll();
  17508. private:
  17509. DeletedAtShutdown (const DeletedAtShutdown&);
  17510. const DeletedAtShutdown& operator= (const DeletedAtShutdown&);
  17511. };
  17512. #endif // __JUCE_DELETEDATSHUTDOWN_JUCEHEADER__
  17513. /********* End of inlined file: juce_DeletedAtShutdown.h *********/
  17514. /********* Start of inlined file: juce_Timer.h *********/
  17515. #ifndef __JUCE_TIMER_JUCEHEADER__
  17516. #define __JUCE_TIMER_JUCEHEADER__
  17517. class InternalTimerThread;
  17518. /**
  17519. Repeatedly calls a user-defined method at a specified time interval.
  17520. A Timer's timerCallback() method will be repeatedly called at a given
  17521. interval. Initially when a Timer object is created, they will do nothing
  17522. until the startTimer() method is called, then the message thread will
  17523. start calling it back until stopTimer() is called.
  17524. The time interval isn't guaranteed to be precise to any more than maybe
  17525. 10-20ms, and the intervals may end up being much longer than requested if the
  17526. system is busy. Because it's the message thread that is doing the callbacks,
  17527. any messages that take a significant amount of time to process will block
  17528. all the timers for that period.
  17529. If you need to have a single callback that is shared by multiple timers with
  17530. different frequencies, then the MultiTimer class allows you to do that - its
  17531. structure is very similar to the Timer class, but contains multiple timers
  17532. internally, each one identified by an ID number.
  17533. @see MultiTimer
  17534. */
  17535. class JUCE_API Timer
  17536. {
  17537. protected:
  17538. /** Creates a Timer.
  17539. When created, the timer is stopped, so use startTimer() to get it going.
  17540. */
  17541. Timer() throw();
  17542. /** Creates a copy of another timer.
  17543. Note that this timer won't be started, even if the one you're copying
  17544. is running.
  17545. */
  17546. Timer (const Timer& other) throw();
  17547. public:
  17548. /** Destructor. */
  17549. virtual ~Timer();
  17550. /** The user-defined callback routine that actually gets called periodically.
  17551. It's perfectly ok to call startTimer() or stopTimer() from within this
  17552. callback to change the subsequent intervals.
  17553. */
  17554. virtual void timerCallback() = 0;
  17555. /** Starts the timer and sets the length of interval required.
  17556. If the timer is already started, this will reset it, so the
  17557. time between calling this method and the next timer callback
  17558. will not be less than the interval length passed in.
  17559. @param intervalInMilliseconds the interval to use (any values less than 1 will be
  17560. rounded up to 1)
  17561. */
  17562. void startTimer (const int intervalInMilliseconds) throw();
  17563. /** Stops the timer.
  17564. No more callbacks will be made after this method returns.
  17565. If this is called from a different thread, any callbacks that may
  17566. be currently executing may be allowed to finish before the method
  17567. returns.
  17568. */
  17569. void stopTimer() throw();
  17570. /** Checks if the timer has been started.
  17571. @returns true if the timer is running.
  17572. */
  17573. bool isTimerRunning() const throw() { return periodMs > 0; }
  17574. /** Returns the timer's interval.
  17575. @returns the timer's interval in milliseconds if it's running, or 0 if it's not.
  17576. */
  17577. int getTimerInterval() const throw() { return periodMs; }
  17578. private:
  17579. friend class InternalTimerThread;
  17580. int countdownMs, periodMs;
  17581. Timer* previous;
  17582. Timer* next;
  17583. const Timer& operator= (const Timer&);
  17584. };
  17585. #endif // __JUCE_TIMER_JUCEHEADER__
  17586. /********* End of inlined file: juce_Timer.h *********/
  17587. /**
  17588. Classes can implement this interface and register themselves with the Desktop class
  17589. to receive callbacks when the currently focused component changes.
  17590. @see Desktop::addFocusChangeListener, Desktop::removeFocusChangeListener
  17591. */
  17592. class JUCE_API FocusChangeListener
  17593. {
  17594. public:
  17595. /** Destructor. */
  17596. virtual ~FocusChangeListener() {}
  17597. /** Callback to indicate that the currently focused component has changed. */
  17598. virtual void globalFocusChanged (Component* focusedComponent) = 0;
  17599. };
  17600. /**
  17601. Describes and controls aspects of the computer's desktop.
  17602. */
  17603. class JUCE_API Desktop : private DeletedAtShutdown,
  17604. private Timer,
  17605. private AsyncUpdater
  17606. {
  17607. public:
  17608. /** There's only one dektop object, and this method will return it.
  17609. */
  17610. static Desktop& JUCE_CALLTYPE getInstance() throw();
  17611. /** Returns a list of the positions of all the monitors available.
  17612. The first rectangle in the list will be the main monitor area.
  17613. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  17614. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  17615. */
  17616. const RectangleList getAllMonitorDisplayAreas (const bool clippedToWorkArea = true) const throw();
  17617. /** Returns the position and size of the main monitor.
  17618. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  17619. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  17620. */
  17621. const Rectangle getMainMonitorArea (const bool clippedToWorkArea = true) const throw();
  17622. /** Returns the position and size of the monitor which contains this co-ordinate.
  17623. If none of the monitors contains the point, this will just return the
  17624. main monitor.
  17625. If clippedToWorkArea is true, it will exclude any areas like the taskbar on Windows,
  17626. or the menu bar on Mac. If clippedToWorkArea is false, the entire monitor area is returned.
  17627. */
  17628. const Rectangle getMonitorAreaContaining (int x, int y, const bool clippedToWorkArea = true) const throw();
  17629. /** Returns the mouse position.
  17630. The co-ordinates are relative to the top-left of the main monitor.
  17631. */
  17632. static void getMousePosition (int& x, int& y) throw();
  17633. /** Makes the mouse pointer jump to a given location.
  17634. The co-ordinates are relative to the top-left of the main monitor.
  17635. */
  17636. static void setMousePosition (int x, int y) throw();
  17637. /** Returns the last position at which a mouse button was pressed.
  17638. */
  17639. static void getLastMouseDownPosition (int& x, int& y) throw();
  17640. /** Returns the number of times the mouse button has been clicked since the
  17641. app started.
  17642. Each mouse-down event increments this number by 1.
  17643. */
  17644. static int getMouseButtonClickCounter() throw();
  17645. /** This lets you prevent the screensaver from becoming active.
  17646. Handy if you're running some sort of presentation app where having a screensaver
  17647. appear would be annoying.
  17648. Pass false to disable the screensaver, and true to re-enable it. (Note that this
  17649. won't enable a screensaver unless the user has actually set one up).
  17650. The disablement will only happen while the Juce application is the foreground
  17651. process - if another task is running in front of it, then the screensaver will
  17652. be unaffected.
  17653. @see isScreenSaverEnabled
  17654. */
  17655. static void setScreenSaverEnabled (const bool isEnabled) throw();
  17656. /** Returns true if the screensaver has not been turned off.
  17657. This will return the last value passed into setScreenSaverEnabled(). Note that
  17658. it won't tell you whether the user is actually using a screen saver, just
  17659. whether this app is deliberately preventing one from running.
  17660. @see setScreenSaverEnabled
  17661. */
  17662. static bool isScreenSaverEnabled() throw();
  17663. /** Registers a MouseListener that will receive all mouse events that occur on
  17664. any component.
  17665. @see removeGlobalMouseListener
  17666. */
  17667. void addGlobalMouseListener (MouseListener* const listener) throw();
  17668. /** Unregisters a MouseListener that was added with the addGlobalMouseListener()
  17669. method.
  17670. @see addGlobalMouseListener
  17671. */
  17672. void removeGlobalMouseListener (MouseListener* const listener) throw();
  17673. /** Registers a MouseListener that will receive a callback whenever the focused
  17674. component changes.
  17675. */
  17676. void addFocusChangeListener (FocusChangeListener* const listener) throw();
  17677. /** Unregisters a listener that was added with addFocusChangeListener(). */
  17678. void removeFocusChangeListener (FocusChangeListener* const listener) throw();
  17679. /** Returns the number of components that are currently active as top-level
  17680. desktop windows.
  17681. @see getComponent, Component::addToDesktop
  17682. */
  17683. int getNumComponents() const throw();
  17684. /** Returns one of the top-level desktop window components.
  17685. The index is from 0 to getNumComponents() - 1. This could return 0 if the
  17686. index is out-of-range.
  17687. @see getNumComponents, Component::addToDesktop
  17688. */
  17689. Component* getComponent (const int index) const throw();
  17690. /** Finds the component at a given screen location.
  17691. This will drill down into top-level windows to find the child component at
  17692. the given position.
  17693. Returns 0 if the co-ordinates are inside a non-Juce window.
  17694. */
  17695. Component* findComponentAt (const int screenX,
  17696. const int screenY) const;
  17697. juce_UseDebuggingNewOperator
  17698. /** Tells this object to refresh its idea of what the screen resolution is.
  17699. (Called internally by the native code).
  17700. */
  17701. void refreshMonitorSizes() throw();
  17702. /** True if the OS supports semitransparent windows */
  17703. static bool canUseSemiTransparentWindows() throw();
  17704. private:
  17705. friend class Component;
  17706. friend class ComponentPeer;
  17707. SortedSet <void*> mouseListeners, focusListeners;
  17708. VoidArray desktopComponents;
  17709. friend class DeletedAtShutdown;
  17710. friend class TopLevelWindowManager;
  17711. Desktop() throw();
  17712. ~Desktop() throw();
  17713. Array <Rectangle> monitorCoordsClipped, monitorCoordsUnclipped;
  17714. int lastMouseX, lastMouseY;
  17715. void timerCallback();
  17716. void sendMouseMove();
  17717. void resetTimer() throw();
  17718. int getNumDisplayMonitors() const throw();
  17719. const Rectangle getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw();
  17720. void addDesktopComponent (Component* const c) throw();
  17721. void removeDesktopComponent (Component* const c) throw();
  17722. void componentBroughtToFront (Component* const c) throw();
  17723. void triggerFocusCallback() throw();
  17724. void handleAsyncUpdate();
  17725. Desktop (const Desktop&);
  17726. const Desktop& operator= (const Desktop&);
  17727. };
  17728. #endif // __JUCE_DESKTOP_JUCEHEADER__
  17729. /********* End of inlined file: juce_Desktop.h *********/
  17730. class KeyPressMappingSet;
  17731. class ApplicationCommandManagerListener;
  17732. /**
  17733. One of these objects holds a list of all the commands your app can perform,
  17734. and despatches these commands when needed.
  17735. Application commands are a good way to trigger actions in your app, e.g. "Quit",
  17736. "Copy", "Paste", etc. Menus, buttons and keypresses can all be given commands
  17737. to invoke automatically, which means you don't have to handle the result of a menu
  17738. or button click manually. Commands are despatched to ApplicationCommandTarget objects
  17739. which can choose which events they want to handle.
  17740. This architecture also allows for nested ApplicationCommandTargets, so that for example
  17741. you could have two different objects, one inside the other, both of which can respond to
  17742. a "delete" command. Depending on which one has focus, the command will be sent to the
  17743. appropriate place, regardless of whether it was triggered by a menu, keypress or some other
  17744. method.
  17745. To set up your app to use commands, you'll need to do the following:
  17746. - Create a global ApplicationCommandManager to hold the list of all possible
  17747. commands. (This will also manage a set of key-mappings for them).
  17748. - Make some of your UI components (or other objects) inherit from ApplicationCommandTarget.
  17749. This allows the object to provide a list of commands that it can perform, and
  17750. to handle them.
  17751. - Register each type of command using ApplicationCommandManager::registerAllCommandsForTarget(),
  17752. or ApplicationCommandManager::registerCommand().
  17753. - If you want key-presses to trigger your commands, use the ApplicationCommandManager::getKeyMappings()
  17754. method to access the key-mapper object, which you will need to register as a key-listener
  17755. in whatever top-level component you're using. See the KeyPressMappingSet class for more help
  17756. about setting this up.
  17757. - Use methods such as PopupMenu::addCommandItem() or Button::setCommandToTrigger() to
  17758. cause these commands to be invoked automatically.
  17759. - Commands can be invoked directly by your code using ApplicationCommandManager::invokeDirectly().
  17760. When a command is invoked, the ApplicationCommandManager will try to choose the best
  17761. ApplicationCommandTarget to receive the specified command. To do this it will use the
  17762. current keyboard focus to see which component might be interested, and will search the
  17763. component hierarchy for those that also implement the ApplicationCommandTarget interface.
  17764. If an ApplicationCommandTarget isn't interested in the command that is being invoked, then
  17765. the next one in line will be tried (see the ApplicationCommandTarget::getNextCommandTarget()
  17766. method), and so on until ApplicationCommandTarget::getNextCommandTarget() returns 0. At this
  17767. point if the command still hasn't been performed, it will be passed to the current
  17768. JUCEApplication object (which is itself an ApplicationCommandTarget).
  17769. To exert some custom control over which ApplicationCommandTarget is chosen to invoke a command,
  17770. you can override the ApplicationCommandManager::getFirstCommandTarget() method and choose
  17771. the object yourself.
  17772. @see ApplicationCommandTarget, ApplicationCommandInfo
  17773. */
  17774. class JUCE_API ApplicationCommandManager : private AsyncUpdater,
  17775. private FocusChangeListener
  17776. {
  17777. public:
  17778. /** Creates an ApplicationCommandManager.
  17779. Once created, you'll need to register all your app's commands with it, using
  17780. ApplicationCommandManager::registerAllCommandsForTarget() or
  17781. ApplicationCommandManager::registerCommand().
  17782. */
  17783. ApplicationCommandManager();
  17784. /** Destructor.
  17785. Make sure that you don't delete this if pointers to it are still being used by
  17786. objects such as PopupMenus or Buttons.
  17787. */
  17788. virtual ~ApplicationCommandManager();
  17789. /** Clears the current list of all commands.
  17790. Note that this will also clear the contents of the KeyPressMappingSet.
  17791. */
  17792. void clearCommands();
  17793. /** Adds a command to the list of registered commands.
  17794. @see registerAllCommandsForTarget
  17795. */
  17796. void registerCommand (const ApplicationCommandInfo& newCommand);
  17797. /** Adds all the commands that this target publishes to the manager's list.
  17798. This will use ApplicationCommandTarget::getAllCommands() and ApplicationCommandTarget::getCommandInfo()
  17799. to get details about all the commands that this target can do, and will call
  17800. registerCommand() to add each one to the manger's list.
  17801. @see registerCommand
  17802. */
  17803. void registerAllCommandsForTarget (ApplicationCommandTarget* target);
  17804. /** Removes the command with a specified ID.
  17805. Note that this will also remove any key mappings that are mapped to the command.
  17806. */
  17807. void removeCommand (const CommandID commandID);
  17808. /** This should be called to tell the manager that one of its registered commands may have changed
  17809. its active status.
  17810. Because the command manager only finds out whether a command is active or inactive by querying
  17811. the current ApplicationCommandTarget, this is used to tell it that things may have changed. It
  17812. allows things like buttons to update their enablement, etc.
  17813. This method will cause an asynchronous call to ApplicationCommandManagerListener::applicationCommandListChanged()
  17814. for any registered listeners.
  17815. */
  17816. void commandStatusChanged();
  17817. /** Returns the number of commands that have been registered.
  17818. @see registerCommand
  17819. */
  17820. int getNumCommands() const throw() { return commands.size(); }
  17821. /** Returns the details about one of the registered commands.
  17822. The index is between 0 and (getNumCommands() - 1).
  17823. */
  17824. const ApplicationCommandInfo* getCommandForIndex (const int index) const throw() { return commands [index]; }
  17825. /** Returns the details about a given command ID.
  17826. This will search the list of registered commands for one with the given command
  17827. ID number, and return its associated info. If no matching command is found, this
  17828. will return 0.
  17829. */
  17830. const ApplicationCommandInfo* getCommandForID (const CommandID commandID) const throw();
  17831. /** Returns the name field for a command.
  17832. An empty string is returned if no command with this ID has been registered.
  17833. @see getDescriptionOfCommand
  17834. */
  17835. const String getNameOfCommand (const CommandID commandID) const throw();
  17836. /** Returns the description field for a command.
  17837. An empty string is returned if no command with this ID has been registered. If the
  17838. command has no description, this will return its short name field instead.
  17839. @see getNameOfCommand
  17840. */
  17841. const String getDescriptionOfCommand (const CommandID commandID) const throw();
  17842. /** Returns the list of categories.
  17843. This will go through all registered commands, and return a list of all the distict
  17844. categoryName values from their ApplicationCommandInfo structure.
  17845. @see getCommandsInCategory()
  17846. */
  17847. const StringArray getCommandCategories() const throw();
  17848. /** Returns a list of all the command UIDs in a particular category.
  17849. @see getCommandCategories()
  17850. */
  17851. const Array <CommandID> getCommandsInCategory (const String& categoryName) const throw();
  17852. /** Returns the manager's internal set of key mappings.
  17853. This object can be used to edit the keypresses. To actually link this object up
  17854. to invoke commands when a key is pressed, see the comments for the KeyPressMappingSet
  17855. class.
  17856. @see KeyPressMappingSet
  17857. */
  17858. KeyPressMappingSet* getKeyMappings() const throw() { return keyMappings; }
  17859. /** Invokes the given command directly, sending it to the default target.
  17860. This is just an easy way to call invoke() without having to fill out the InvocationInfo
  17861. structure.
  17862. */
  17863. bool invokeDirectly (const CommandID commandID,
  17864. const bool asynchronously);
  17865. /** Sends a command to the default target.
  17866. This will choose a target using getFirstCommandTarget(), and send the specified command
  17867. to it using the ApplicationCommandTarget::invoke() method. This means that if the
  17868. first target can't handle the command, it will be passed on to targets further down the
  17869. chain (see ApplicationCommandTarget::invoke() for more info).
  17870. @param invocationInfo this must be correctly filled-in, describing the context for
  17871. the invocation.
  17872. @param asynchronously if false, the command will be performed before this method returns.
  17873. If true, a message will be posted so that the command will be performed
  17874. later on the message thread, and this method will return immediately.
  17875. @see ApplicationCommandTarget::invoke
  17876. */
  17877. bool invoke (const ApplicationCommandTarget::InvocationInfo& invocationInfo,
  17878. const bool asynchronously);
  17879. /** Chooses the ApplicationCommandTarget to which a command should be sent.
  17880. Whenever the manager needs to know which target a command should be sent to, it calls
  17881. this method to determine the first one to try.
  17882. By default, this method will return the target that was set by calling setFirstCommandTarget().
  17883. If no target is set, it will return the result of findDefaultComponentTarget().
  17884. If you need to make sure all commands go via your own custom target, then you can
  17885. either use setFirstCommandTarget() to specify a single target, or override this method
  17886. if you need more complex logic to choose one.
  17887. It may return 0 if no targets are available.
  17888. @see getTargetForCommand, invoke, invokeDirectly
  17889. */
  17890. virtual ApplicationCommandTarget* getFirstCommandTarget (const CommandID commandID);
  17891. /** Sets a target to be returned by getFirstCommandTarget().
  17892. If this is set to 0, then getFirstCommandTarget() will by default return the
  17893. result of findDefaultComponentTarget().
  17894. If you use this to set a target, make sure you call setFirstCommandTarget (0) before
  17895. deleting the target object.
  17896. */
  17897. void setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw();
  17898. /** Tries to find the best target to use to perform a given command.
  17899. This will call getFirstCommandTarget() to find the preferred target, and will
  17900. check whether that target can handle the given command. If it can't, then it'll use
  17901. ApplicationCommandTarget::getNextCommandTarget() to find the next one to try, and
  17902. so on until no more are available.
  17903. If no targets are found that can perform the command, this method will return 0.
  17904. If a target is found, then it will get the target to fill-in the upToDateInfo
  17905. structure with the latest info about that command, so that the caller can see
  17906. whether the command is disabled, ticked, etc.
  17907. */
  17908. ApplicationCommandTarget* getTargetForCommand (const CommandID commandID,
  17909. ApplicationCommandInfo& upToDateInfo);
  17910. /** Registers a listener that will be called when various events occur. */
  17911. void addListener (ApplicationCommandManagerListener* const listener) throw();
  17912. /** Deregisters a previously-added listener. */
  17913. void removeListener (ApplicationCommandManagerListener* const listener) throw();
  17914. /** Looks for a suitable command target based on which Components have the keyboard focus.
  17915. This is used by the default implementation of ApplicationCommandTarget::getFirstCommandTarget(),
  17916. but is exposed here in case it's useful.
  17917. It tries to pick the best ApplicationCommandTarget by looking at focused components, top level
  17918. windows, etc., and using the findTargetForComponent() method.
  17919. */
  17920. static ApplicationCommandTarget* findDefaultComponentTarget();
  17921. /** Examines this component and all its parents in turn, looking for the first one
  17922. which is a ApplicationCommandTarget.
  17923. Returns the first ApplicationCommandTarget that it finds, or 0 if none of them implement
  17924. that class.
  17925. */
  17926. static ApplicationCommandTarget* findTargetForComponent (Component* component);
  17927. juce_UseDebuggingNewOperator
  17928. private:
  17929. OwnedArray <ApplicationCommandInfo> commands;
  17930. SortedSet <void*> listeners;
  17931. KeyPressMappingSet* keyMappings;
  17932. ApplicationCommandTarget* firstTarget;
  17933. void sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const;
  17934. void handleAsyncUpdate();
  17935. void globalFocusChanged (Component*);
  17936. // xxx this is just here to cause a compile error in old code that hasn't been changed to use the new
  17937. // version of this method.
  17938. virtual short getFirstCommandTarget() { return 0; }
  17939. };
  17940. /**
  17941. A listener that receives callbacks from an ApplicationCommandManager when
  17942. commands are invoked or the command list is changed.
  17943. @see ApplicationCommandManager::addListener, ApplicationCommandManager::removeListener
  17944. */
  17945. class JUCE_API ApplicationCommandManagerListener
  17946. {
  17947. public:
  17948. /** Destructor. */
  17949. virtual ~ApplicationCommandManagerListener() {}
  17950. /** Called when an app command is about to be invoked. */
  17951. virtual void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info) = 0;
  17952. /** Called when commands are registered or deregistered from the
  17953. command manager, or when commands are made active or inactive.
  17954. Note that if you're using this to watch for changes to whether a command is disabled,
  17955. you'll need to make sure that ApplicationCommandManager::commandStatusChanged() is called
  17956. whenever the status of your command might have changed.
  17957. */
  17958. virtual void applicationCommandListChanged() = 0;
  17959. };
  17960. #endif // __JUCE_APPLICATIONCOMMANDMANAGER_JUCEHEADER__
  17961. /********* End of inlined file: juce_ApplicationCommandManager.h *********/
  17962. #endif
  17963. #ifndef __JUCE_APPLICATIONCOMMANDTARGET_JUCEHEADER__
  17964. #endif
  17965. #ifndef __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__
  17966. /********* Start of inlined file: juce_ApplicationProperties.h *********/
  17967. #ifndef __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__
  17968. #define __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__
  17969. /********* Start of inlined file: juce_PropertiesFile.h *********/
  17970. #ifndef __JUCE_PROPERTIESFILE_JUCEHEADER__
  17971. #define __JUCE_PROPERTIESFILE_JUCEHEADER__
  17972. /********* Start of inlined file: juce_ChangeBroadcaster.h *********/
  17973. #ifndef __JUCE_CHANGEBROADCASTER_JUCEHEADER__
  17974. #define __JUCE_CHANGEBROADCASTER_JUCEHEADER__
  17975. /********* Start of inlined file: juce_ChangeListenerList.h *********/
  17976. #ifndef __JUCE_CHANGELISTENERLIST_JUCEHEADER__
  17977. #define __JUCE_CHANGELISTENERLIST_JUCEHEADER__
  17978. /********* Start of inlined file: juce_ChangeListener.h *********/
  17979. #ifndef __JUCE_CHANGELISTENER_JUCEHEADER__
  17980. #define __JUCE_CHANGELISTENER_JUCEHEADER__
  17981. /**
  17982. Receives callbacks about changes to some kind of object.
  17983. Many objects use a ChangeListenerList to keep a set of listeners which they
  17984. will inform when something changes. A subclass of ChangeListener
  17985. is used to receive these callbacks.
  17986. Note that the major difference between an ActionListener and a ChangeListener
  17987. is that for a ChangeListener, multiple changes will be coalesced into fewer
  17988. callbacks, but ActionListeners perform one callback for every event posted.
  17989. @see ChangeListenerList, ChangeBroadcaster, ActionListener
  17990. */
  17991. class JUCE_API ChangeListener
  17992. {
  17993. public:
  17994. /** Destructor. */
  17995. virtual ~ChangeListener() {}
  17996. /** Overridden by your subclass to receive the callback.
  17997. @param objectThatHasChanged the value that was passed to the
  17998. ChangeListenerList::sendChangeMessage() method
  17999. */
  18000. virtual void changeListenerCallback (void* objectThatHasChanged) = 0;
  18001. };
  18002. #endif // __JUCE_CHANGELISTENER_JUCEHEADER__
  18003. /********* End of inlined file: juce_ChangeListener.h *********/
  18004. /**
  18005. A set of ChangeListeners.
  18006. Listeners can be added and removed from the list, and change messages can be
  18007. broadcast to all the listeners.
  18008. @see ChangeListener, ChangeBroadcaster
  18009. */
  18010. class JUCE_API ChangeListenerList : public MessageListener
  18011. {
  18012. public:
  18013. /** Creates an empty list. */
  18014. ChangeListenerList() throw();
  18015. /** Destructor. */
  18016. ~ChangeListenerList() throw();
  18017. /** Adds a listener to the list.
  18018. (Trying to add a listener that's already on the list will have no effect).
  18019. */
  18020. void addChangeListener (ChangeListener* const listener) throw();
  18021. /** Removes a listener from the list.
  18022. If the listener isn't on the list, this won't have any effect.
  18023. */
  18024. void removeChangeListener (ChangeListener* const listener) throw();
  18025. /** Removes all listeners from the list. */
  18026. void removeAllChangeListeners() throw();
  18027. /** Posts an asynchronous change message to all the listeners.
  18028. If a message has already been sent and hasn't yet been delivered, this
  18029. method won't send another - in this way it coalesces multiple frequent
  18030. changes into fewer actual callbacks to the ChangeListeners. Contrast this
  18031. with the ActionListener, which posts a new event for every call to its
  18032. sendActionMessage() method.
  18033. Only listeners which are on the list when the change event is delivered
  18034. will receive the event - and this may include listeners that weren't on
  18035. the list when the change message was sent.
  18036. @param objectThatHasChanged this pointer is passed to the
  18037. ChangeListener::changeListenerCallback() method,
  18038. and can be any value the application needs
  18039. @see sendSynchronousChangeMessage
  18040. */
  18041. void sendChangeMessage (void* objectThatHasChanged) throw();
  18042. /** This will synchronously callback all the ChangeListeners.
  18043. Use this if you need to synchronously force a call to all the
  18044. listeners' ChangeListener::changeListenerCallback() methods.
  18045. */
  18046. void sendSynchronousChangeMessage (void* objectThatHasChanged);
  18047. /** If a change message has been sent but not yet dispatched, this will
  18048. use sendSynchronousChangeMessage() to make the callback immediately.
  18049. */
  18050. void dispatchPendingMessages();
  18051. /** @internal */
  18052. void handleMessage (const Message&);
  18053. juce_UseDebuggingNewOperator
  18054. private:
  18055. SortedSet <void*> listeners;
  18056. CriticalSection lock;
  18057. void* lastChangedObject;
  18058. bool messagePending;
  18059. ChangeListenerList (const ChangeListenerList&);
  18060. const ChangeListenerList& operator= (const ChangeListenerList&);
  18061. };
  18062. #endif // __JUCE_CHANGELISTENERLIST_JUCEHEADER__
  18063. /********* End of inlined file: juce_ChangeListenerList.h *********/
  18064. /** Manages a list of ChangeListeners, and can send them messages.
  18065. To quickly add methods to your class that can add/remove change
  18066. listeners and broadcast to them, you can derive from this.
  18067. @see ChangeListenerList, ChangeListener
  18068. */
  18069. class JUCE_API ChangeBroadcaster
  18070. {
  18071. public:
  18072. /** Creates an ChangeBroadcaster. */
  18073. ChangeBroadcaster() throw();
  18074. /** Destructor. */
  18075. virtual ~ChangeBroadcaster();
  18076. /** Adds a listener to the list.
  18077. (Trying to add a listener that's already on the list will have no effect).
  18078. */
  18079. void addChangeListener (ChangeListener* const listener) throw();
  18080. /** Removes a listener from the list.
  18081. If the listener isn't on the list, this won't have any effect.
  18082. */
  18083. void removeChangeListener (ChangeListener* const listener) throw();
  18084. /** Removes all listeners from the list. */
  18085. void removeAllChangeListeners() throw();
  18086. /** Broadcasts a change message to all the registered listeners.
  18087. The message will be delivered asynchronously by the event thread, so this
  18088. method will not directly call any of the listeners. For a synchronous
  18089. message, use sendSynchronousChangeMessage().
  18090. @see ChangeListenerList::sendActionMessage
  18091. */
  18092. void sendChangeMessage (void* objectThatHasChanged) throw();
  18093. /** Sends a synchronous change message to all the registered listeners.
  18094. @see ChangeListenerList::sendSynchronousChangeMessage
  18095. */
  18096. void sendSynchronousChangeMessage (void* objectThatHasChanged);
  18097. /** If a change message has been sent but not yet dispatched, this will
  18098. use sendSynchronousChangeMessage() to make the callback immediately.
  18099. */
  18100. void dispatchPendingMessages();
  18101. private:
  18102. ChangeListenerList changeListenerList;
  18103. ChangeBroadcaster (const ChangeBroadcaster&);
  18104. const ChangeBroadcaster& operator= (const ChangeBroadcaster&);
  18105. };
  18106. #endif // __JUCE_CHANGEBROADCASTER_JUCEHEADER__
  18107. /********* End of inlined file: juce_ChangeBroadcaster.h *********/
  18108. /** Wrapper on a file that stores a list of key/value data pairs.
  18109. Useful for storing application settings, etc. See the PropertySet class for
  18110. the interfaces that read and write values.
  18111. Not designed for very large amounts of data, as it keeps all the values in
  18112. memory and writes them out to disk lazily when they are changed.
  18113. Because this class derives from ChangeBroadcaster, ChangeListeners can be registered
  18114. with it, and these will be signalled when a value changes.
  18115. @see PropertySet
  18116. */
  18117. class JUCE_API PropertiesFile : public PropertySet,
  18118. public ChangeBroadcaster,
  18119. private Timer
  18120. {
  18121. public:
  18122. enum FileFormatOptions
  18123. {
  18124. ignoreCaseOfKeyNames = 1,
  18125. storeAsBinary = 2,
  18126. storeAsCompressedBinary = 4,
  18127. storeAsXML = 8
  18128. };
  18129. /**
  18130. Creates a PropertiesFile object.
  18131. @param file the file to use
  18132. @param millisecondsBeforeSaving if this is zero or greater, then after a value
  18133. is changed, the object will wait for this amount
  18134. of time and then save the file. If zero, the file
  18135. will be written to disk immediately on being changed
  18136. (which might be slow, as it'll re-write synchronously
  18137. each time a value-change method is called). If it is
  18138. less than zero, the file won't be saved until
  18139. save() or saveIfNeeded() are explicitly called.
  18140. @param options a combination of the flags in the FileFormatOptions
  18141. enum, which specify the type of file to save, and other
  18142. options.
  18143. */
  18144. PropertiesFile (const File& file,
  18145. const int millisecondsBeforeSaving,
  18146. const int options) throw();
  18147. /** Destructor.
  18148. When deleted, the file will first call saveIfNeeded() to flush any changes to disk.
  18149. */
  18150. ~PropertiesFile();
  18151. /** This will flush all the values to disk if they've changed since the last
  18152. time they were saved.
  18153. Returns false if it fails to write to the file for some reason (maybe because
  18154. it's read-only or the directory doesn't exist or something).
  18155. @see save
  18156. */
  18157. bool saveIfNeeded();
  18158. /** This will force a write-to-disk of the current values, regardless of whether
  18159. anything has changed since the last save.
  18160. Returns false if it fails to write to the file for some reason (maybe because
  18161. it's read-only or the directory doesn't exist or something).
  18162. @see saveIfNeeded
  18163. */
  18164. bool save();
  18165. /** Returns true if the properties have been altered since the last time they were
  18166. saved.
  18167. */
  18168. bool needsToBeSaved() const throw();
  18169. /** Returns the file that's being used. */
  18170. const File getFile() const throw();
  18171. /** Handy utility to create a properties file in whatever the standard OS-specific
  18172. location is for these things.
  18173. This uses getDefaultAppSettingsFile() to decide what file to create, then
  18174. creates a PropertiesFile object with the specified properties. See
  18175. getDefaultAppSettingsFile() and the class's constructor for descriptions of
  18176. what the parameters do.
  18177. @see getDefaultAppSettingsFile
  18178. */
  18179. static PropertiesFile* createDefaultAppPropertiesFile (const String& applicationName,
  18180. const String& fileNameSuffix,
  18181. const String& folderName,
  18182. const bool commonToAllUsers,
  18183. const int millisecondsBeforeSaving,
  18184. const int propertiesFileOptions);
  18185. /** Handy utility to choose a file in the standard OS-dependent location for application
  18186. settings files.
  18187. So on a Mac, this will return a file called:
  18188. ~/Library/Preferences/[folderName]/[applicationName].[fileNameSuffix]
  18189. On Windows it'll return something like:
  18190. C:\\Documents and Settings\\username\\Application Data\\[folderName]\\[applicationName].[fileNameSuffix]
  18191. On Linux it'll return
  18192. ~/.[folderName]/[applicationName].[fileNameSuffix]
  18193. If you pass an empty string as the folder name, it'll use the app name for this (or
  18194. omit the folder name on the Mac).
  18195. If commonToAllUsers is true, then this will return the same file for all users of the
  18196. computer, regardless of the current user. If it is false, the file will be specific to
  18197. only the current user. Use this to choose whether you're saving settings that are common
  18198. or user-specific.
  18199. */
  18200. static const File getDefaultAppSettingsFile (const String& applicationName,
  18201. const String& fileNameSuffix,
  18202. const String& folderName,
  18203. const bool commonToAllUsers);
  18204. juce_UseDebuggingNewOperator
  18205. protected:
  18206. virtual void propertyChanged();
  18207. private:
  18208. File file;
  18209. int timerInterval;
  18210. const int options;
  18211. bool needsWriting;
  18212. void timerCallback();
  18213. PropertiesFile (const PropertiesFile&);
  18214. const PropertiesFile& operator= (const PropertiesFile&);
  18215. };
  18216. #endif // __JUCE_PROPERTIESFILE_JUCEHEADER__
  18217. /********* End of inlined file: juce_PropertiesFile.h *********/
  18218. /**
  18219. Manages a collection of properties.
  18220. This is a slightly higher-level wrapper for PropertiesFile, which can be used
  18221. as a singleton.
  18222. It holds two different PropertiesFile objects internally, one for user-specific
  18223. settings (stored in your user directory), and one for settings that are common to
  18224. all users (stored in a folder accessible to all users).
  18225. The class manages the creation of these files on-demand, allowing access via the
  18226. getUserSettings() and getCommonSettings() methods. It also has a few handy
  18227. methods like testWriteAccess() to check that the files can be saved.
  18228. If you're using one of these as a singleton, then your app's start-up code should
  18229. first of all call setStorageParameters() to tell it the parameters to use to create
  18230. the properties files.
  18231. @see PropertiesFile
  18232. */
  18233. class JUCE_API ApplicationProperties : public DeletedAtShutdown
  18234. {
  18235. public:
  18236. /**
  18237. Creates an ApplicationProperties object.
  18238. Before using it, you must call setStorageParameters() to give it the info
  18239. it needs to create the property files.
  18240. */
  18241. ApplicationProperties() throw();
  18242. /** Destructor.
  18243. */
  18244. ~ApplicationProperties();
  18245. juce_DeclareSingleton (ApplicationProperties, false)
  18246. /** Gives the object the information it needs to create the appropriate properties files.
  18247. See the comments for PropertiesFile::createDefaultAppPropertiesFile() for more
  18248. info about how these parameters are used.
  18249. */
  18250. void setStorageParameters (const String& applicationName,
  18251. const String& fileNameSuffix,
  18252. const String& folderName,
  18253. const int millisecondsBeforeSaving,
  18254. const int propertiesFileOptions) throw();
  18255. /** Tests whether the files can be successfully written to, and can show
  18256. an error message if not.
  18257. Returns true if none of the tests fail.
  18258. @param testUserSettings if true, the user settings file will be tested
  18259. @param testCommonSettings if true, the common settings file will be tested
  18260. @param showWarningDialogOnFailure if true, the method will show a helpful error
  18261. message box if either of the tests fail
  18262. */
  18263. bool testWriteAccess (const bool testUserSettings,
  18264. const bool testCommonSettings,
  18265. const bool showWarningDialogOnFailure);
  18266. /** Returns the user settings file.
  18267. The first time this is called, it will create and load the properties file.
  18268. Note that when you search the user PropertiesFile for a value that it doesn't contain,
  18269. the common settings are used as a second-chance place to look. This is done via the
  18270. PropertySet::setFallbackPropertySet() method - by default the common settings are set
  18271. to the fallback for the user settings.
  18272. @see getCommonSettings
  18273. */
  18274. PropertiesFile* getUserSettings() throw();
  18275. /** Returns the common settings file.
  18276. The first time this is called, it will create and load the properties file.
  18277. @param returnUserPropsIfReadOnly if this is true, and the common properties file is
  18278. read-only (e.g. because the user doesn't have permission to write
  18279. to shared files), then this will return the user settings instead,
  18280. (like getUserSettings() would do). This is handy if you'd like to
  18281. write a value to the common settings, but if that's no possible,
  18282. then you'd rather write to the user settings than none at all.
  18283. If returnUserPropsIfReadOnly is false, this method will always return
  18284. the common settings, even if any changes to them can't be saved.
  18285. @see getUserSettings
  18286. */
  18287. PropertiesFile* getCommonSettings (const bool returnUserPropsIfReadOnly) throw();
  18288. /** Saves both files if they need to be saved.
  18289. @see PropertiesFile::saveIfNeeded
  18290. */
  18291. bool saveIfNeeded();
  18292. /** Flushes and closes both files if they are open.
  18293. This flushes any pending changes to disk with PropertiesFile::saveIfNeeded()
  18294. and closes both files. They will then be re-opened the next time getUserSettings()
  18295. or getCommonSettings() is called.
  18296. */
  18297. void closeFiles();
  18298. juce_UseDebuggingNewOperator
  18299. private:
  18300. PropertiesFile* userProps;
  18301. PropertiesFile* commonProps;
  18302. String appName, fileSuffix, folderName;
  18303. int msBeforeSaving, options;
  18304. int commonSettingsAreReadOnly;
  18305. ApplicationProperties (const ApplicationProperties&);
  18306. const ApplicationProperties& operator= (const ApplicationProperties&);
  18307. void openFiles() throw();
  18308. };
  18309. #endif // __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__
  18310. /********* End of inlined file: juce_ApplicationProperties.h *********/
  18311. #endif
  18312. #ifndef __JUCE_DELETEDATSHUTDOWN_JUCEHEADER__
  18313. #endif
  18314. #ifndef __JUCE_PROPERTIESFILE_JUCEHEADER__
  18315. #endif
  18316. #ifndef __JUCE_SYSTEMCLIPBOARD_JUCEHEADER__
  18317. /********* Start of inlined file: juce_SystemClipboard.h *********/
  18318. #ifndef __JUCE_SYSTEMCLIPBOARD_JUCEHEADER__
  18319. #define __JUCE_SYSTEMCLIPBOARD_JUCEHEADER__
  18320. /**
  18321. Handles reading/writing to the system's clipboard.
  18322. */
  18323. class JUCE_API SystemClipboard
  18324. {
  18325. public:
  18326. /** Copies a string of text onto the clipboard */
  18327. static void copyTextToClipboard (const String& text) throw();
  18328. /** Gets the current clipboard's contents.
  18329. Obviously this might have come from another app, so could contain
  18330. anything..
  18331. */
  18332. static const String getTextFromClipboard() throw();
  18333. };
  18334. #endif // __JUCE_SYSTEMCLIPBOARD_JUCEHEADER__
  18335. /********* End of inlined file: juce_SystemClipboard.h *********/
  18336. #endif
  18337. #ifndef __JUCE_MIDIBUFFER_JUCEHEADER__
  18338. /********* Start of inlined file: juce_MidiBuffer.h *********/
  18339. #ifndef __JUCE_MIDIBUFFER_JUCEHEADER__
  18340. #define __JUCE_MIDIBUFFER_JUCEHEADER__
  18341. /********* Start of inlined file: juce_MidiMessage.h *********/
  18342. #ifndef __JUCE_MIDIMESSAGE_JUCEHEADER__
  18343. #define __JUCE_MIDIMESSAGE_JUCEHEADER__
  18344. /**
  18345. Encapsulates a MIDI message.
  18346. @see MidiMessageSequence, MidiOutput, MidiInput
  18347. */
  18348. class JUCE_API MidiMessage
  18349. {
  18350. public:
  18351. /** Creates a 3-byte short midi message.
  18352. @param byte1 message byte 1
  18353. @param byte2 message byte 2
  18354. @param byte3 message byte 3
  18355. @param timeStamp the time to give the midi message - this value doesn't
  18356. use any particular units, so will be application-specific
  18357. */
  18358. MidiMessage (const int byte1,
  18359. const int byte2,
  18360. const int byte3,
  18361. const double timeStamp = 0) throw();
  18362. /** Creates a 2-byte short midi message.
  18363. @param byte1 message byte 1
  18364. @param byte2 message byte 2
  18365. @param timeStamp the time to give the midi message - this value doesn't
  18366. use any particular units, so will be application-specific
  18367. */
  18368. MidiMessage (const int byte1,
  18369. const int byte2,
  18370. const double timeStamp = 0) throw();
  18371. /** Creates a 1-byte short midi message.
  18372. @param byte1 message byte 1
  18373. @param timeStamp the time to give the midi message - this value doesn't
  18374. use any particular units, so will be application-specific
  18375. */
  18376. MidiMessage (const int byte1,
  18377. const double timeStamp = 0) throw();
  18378. /** Creates a midi message from a block of data. */
  18379. MidiMessage (const uint8* const data,
  18380. const int dataSize,
  18381. const double timeStamp = 0) throw();
  18382. /** Reads the next midi message from some data.
  18383. This will read as many bytes from a data stream as it needs to make a
  18384. complete message, and will return the number of bytes it used. This lets
  18385. you read a sequence of midi messages from a file or stream.
  18386. @param data the data to read from
  18387. @param size the maximum number of bytes it's allowed to read
  18388. @param numBytesUsed returns the number of bytes that were actually needed
  18389. @param lastStatusByte in a sequence of midi messages, the initial byte
  18390. can be dropped from a message if it's the same as the
  18391. first byte of the previous message, so this lets you
  18392. supply the byte to use if the first byte of the message
  18393. has in fact been dropped.
  18394. @param timeStamp the time to give the midi message - this value doesn't
  18395. use any particular units, so will be application-specific
  18396. */
  18397. MidiMessage (const uint8* data,
  18398. int size,
  18399. int& numBytesUsed,
  18400. uint8 lastStatusByte,
  18401. double timeStamp = 0) throw();
  18402. /** Creates a copy of another midi message. */
  18403. MidiMessage (const MidiMessage& other) throw();
  18404. /** Creates a copy of another midi message, with a different timestamp. */
  18405. MidiMessage (const MidiMessage& other,
  18406. const double newTimeStamp) throw();
  18407. /** Destructor. */
  18408. ~MidiMessage() throw();
  18409. /** Copies this message from another one. */
  18410. const MidiMessage& operator= (const MidiMessage& other) throw();
  18411. /** Returns a pointer to the raw midi data.
  18412. @see getRawDataSize
  18413. */
  18414. uint8* getRawData() const throw() { return data; }
  18415. /** Returns the number of bytes of data in the message.
  18416. @see getRawData
  18417. */
  18418. int getRawDataSize() const throw() { return size; }
  18419. /** Returns the timestamp associated with this message.
  18420. The units for the timestamp will be application-specific.
  18421. @see setTimeStamp, addToTimeStamp
  18422. */
  18423. double getTimeStamp() const throw() { return timeStamp; }
  18424. /** Changes the message's associated timestamp.
  18425. The units for the timestamp will be application-specific.
  18426. @see addToTimeStamp, getTimeStamp
  18427. */
  18428. void setTimeStamp (const double newTimestamp) throw() { timeStamp = newTimestamp; }
  18429. /** Adds a value to the message's timestamp.
  18430. The units for the timestamp will be application-specific.
  18431. */
  18432. void addToTimeStamp (const double delta) throw() { timeStamp += delta; }
  18433. /** Returns the midi channel associated with the message.
  18434. @returns a value 1 to 16 if the message has a channel, or 0 if it hasn't (e.g.
  18435. if it's a sysex)
  18436. @see isForChannel, setChannel
  18437. */
  18438. int getChannel() const throw();
  18439. /** Returns true if the message applies to the given midi channel.
  18440. @param channelNumber the channel number to look for, in the range 1 to 16
  18441. @see getChannel, setChannel
  18442. */
  18443. bool isForChannel (const int channelNumber) const throw();
  18444. /** Changes the message's midi channel.
  18445. This won't do anything for non-channel messages like sysexes.
  18446. @param newChannelNumber the channel number to change it to, in the range 1 to 16
  18447. */
  18448. void setChannel (const int newChannelNumber) throw();
  18449. /** Returns true if this is a system-exclusive message.
  18450. */
  18451. bool isSysEx() const throw();
  18452. /** Returns a pointer to the sysex data inside the message.
  18453. If this event isn't a sysex event, it'll return 0.
  18454. @see getSysExDataSize
  18455. */
  18456. const uint8* getSysExData() const throw();
  18457. /** Returns the size of the sysex data.
  18458. This value excludes the 0xf0 header byte and the 0xf7 at the end.
  18459. @see getSysExData
  18460. */
  18461. int getSysExDataSize() const throw();
  18462. /** Returns true if this message is a 'key-down' event.
  18463. This will return false for a note-on event with a velocity of 0.
  18464. @see isNoteOff, getNoteNumber, getVelocity, noteOn
  18465. */
  18466. bool isNoteOn() const throw();
  18467. /** Creates a key-down message (using a floating-point velocity).
  18468. @param channel the midi channel, in the range 1 to 16
  18469. @param noteNumber the key number, 0 to 127
  18470. @param velocity in the range 0 to 1.0
  18471. @see isNoteOn
  18472. */
  18473. static const MidiMessage noteOn (const int channel,
  18474. const int noteNumber,
  18475. const float velocity) throw();
  18476. /** Creates a key-down message (using an integer velocity).
  18477. @param channel the midi channel, in the range 1 to 16
  18478. @param noteNumber the key number, 0 to 127
  18479. @param velocity in the range 0 to 127
  18480. @see isNoteOn
  18481. */
  18482. static const MidiMessage noteOn (const int channel,
  18483. const int noteNumber,
  18484. const uint8 velocity) throw();
  18485. /** Returns true if this message is a 'key-up' event.
  18486. This will also return true for a note-on event with a velocity of 0.
  18487. @see isNoteOn, getNoteNumber, getVelocity, noteOff
  18488. */
  18489. bool isNoteOff() const throw();
  18490. /** Creates a key-up message.
  18491. @param channel the midi channel, in the range 1 to 16
  18492. @param noteNumber the key number, 0 to 127
  18493. @see isNoteOff
  18494. */
  18495. static const MidiMessage noteOff (const int channel,
  18496. const int noteNumber) throw();
  18497. /** Returns true if this message is a 'key-down' or 'key-up' event.
  18498. @see isNoteOn, isNoteOff
  18499. */
  18500. bool isNoteOnOrOff() const throw();
  18501. /** Returns the midi note number for note-on and note-off messages.
  18502. If the message isn't a note-on or off, the value returned will be
  18503. meaningless.
  18504. @see isNoteOff, getMidiNoteName, getMidiNoteInHertz, setNoteNumber
  18505. */
  18506. int getNoteNumber() const throw();
  18507. /** Changes the midi note number of a note-on or note-off message.
  18508. If the message isn't a note on or off, this will do nothing.
  18509. */
  18510. void setNoteNumber (const int newNoteNumber) throw();
  18511. /** Returns the velocity of a note-on or note-off message.
  18512. The value returned will be in the range 0 to 127.
  18513. If the message isn't a note-on or off event, it will return 0.
  18514. @see getFloatVelocity
  18515. */
  18516. uint8 getVelocity() const throw();
  18517. /** Returns the velocity of a note-on or note-off message.
  18518. The value returned will be in the range 0 to 1.0
  18519. If the message isn't a note-on or off event, it will return 0.
  18520. @see getVelocity, setVelocity
  18521. */
  18522. float getFloatVelocity() const throw();
  18523. /** Changes the velocity of a note-on or note-off message.
  18524. If the message isn't a note on or off, this will do nothing.
  18525. @param newVelocity the new velocity, in the range 0 to 1.0
  18526. @see getFloatVelocity, multiplyVelocity
  18527. */
  18528. void setVelocity (const float newVelocity) throw();
  18529. /** Multiplies the velocity of a note-on or note-off message by a given amount.
  18530. If the message isn't a note on or off, this will do nothing.
  18531. @param scaleFactor the value by which to multiply the velocity
  18532. @see setVelocity
  18533. */
  18534. void multiplyVelocity (const float scaleFactor) throw();
  18535. /** Returns true if the message is a program (patch) change message.
  18536. @see getProgramChangeNumber, getGMInstrumentName
  18537. */
  18538. bool isProgramChange() const throw();
  18539. /** Returns the new program number of a program change message.
  18540. If the message isn't a program change, the value returned will be
  18541. nonsense.
  18542. @see isProgramChange, getGMInstrumentName
  18543. */
  18544. int getProgramChangeNumber() const throw();
  18545. /** Creates a program-change message.
  18546. @param channel the midi channel, in the range 1 to 16
  18547. @param programNumber the midi program number, 0 to 127
  18548. @see isProgramChange, getGMInstrumentName
  18549. */
  18550. static const MidiMessage programChange (const int channel,
  18551. const int programNumber) throw();
  18552. /** Returns true if the message is a pitch-wheel move.
  18553. @see getPitchWheelValue, pitchWheel
  18554. */
  18555. bool isPitchWheel() const throw();
  18556. /** Returns the pitch wheel position from a pitch-wheel move message.
  18557. The value returned is a 14-bit number from 0 to 0x3fff, indicating the wheel position.
  18558. If called for messages which aren't pitch wheel events, the number returned will be
  18559. nonsense.
  18560. @see isPitchWheel
  18561. */
  18562. int getPitchWheelValue() const throw();
  18563. /** Creates a pitch-wheel move message.
  18564. @param channel the midi channel, in the range 1 to 16
  18565. @param position the wheel position, in the range 0 to 16383
  18566. @see isPitchWheel
  18567. */
  18568. static const MidiMessage pitchWheel (const int channel,
  18569. const int position) throw();
  18570. /** Returns true if the message is an aftertouch event.
  18571. For aftertouch events, use the getNoteNumber() method to find out the key
  18572. that it applies to, and getAftertouchValue() to find out the amount. Use
  18573. getChannel() to find out the channel.
  18574. @see getAftertouchValue, getNoteNumber
  18575. */
  18576. bool isAftertouch() const throw();
  18577. /** Returns the amount of aftertouch from an aftertouch messages.
  18578. The value returned is in the range 0 to 127, and will be nonsense for messages
  18579. other than aftertouch messages.
  18580. @see isAftertouch
  18581. */
  18582. int getAfterTouchValue() const throw();
  18583. /** Creates an aftertouch message.
  18584. @param channel the midi channel, in the range 1 to 16
  18585. @param noteNumber the key number, 0 to 127
  18586. @param aftertouchAmount the amount of aftertouch, 0 to 127
  18587. @see isAftertouch
  18588. */
  18589. static const MidiMessage aftertouchChange (const int channel,
  18590. const int noteNumber,
  18591. const int aftertouchAmount) throw();
  18592. /** Returns true if the message is a channel-pressure change event.
  18593. This is like aftertouch, but common to the whole channel rather than a specific
  18594. note. Use getChannelPressureValue() to find out the pressure, and getChannel()
  18595. to find out the channel.
  18596. @see channelPressureChange
  18597. */
  18598. bool isChannelPressure() const throw();
  18599. /** Returns the pressure from a channel pressure change message.
  18600. @returns the pressure, in the range 0 to 127
  18601. @see isChannelPressure, channelPressureChange
  18602. */
  18603. int getChannelPressureValue() const throw();
  18604. /** Creates a channel-pressure change event.
  18605. @param channel the midi channel: 1 to 16
  18606. @param pressure the pressure, 0 to 127
  18607. @see isChannelPressure
  18608. */
  18609. static const MidiMessage channelPressureChange (const int channel,
  18610. const int pressure) throw();
  18611. /** Returns true if this is a midi controller message.
  18612. @see getControllerNumber, getControllerValue, controllerEvent
  18613. */
  18614. bool isController() const throw();
  18615. /** Returns the controller number of a controller message.
  18616. The name of the controller can be looked up using the getControllerName() method.
  18617. Note that the value returned is invalid for messages that aren't controller changes.
  18618. @see isController, getControllerName, getControllerValue
  18619. */
  18620. int getControllerNumber() const throw();
  18621. /** Returns the controller value from a controller message.
  18622. A value 0 to 127 is returned to indicate the new controller position.
  18623. Note that the value returned is invalid for messages that aren't controller changes.
  18624. @see isController, getControllerNumber
  18625. */
  18626. int getControllerValue() const throw();
  18627. /** Creates a controller message.
  18628. @param channel the midi channel, in the range 1 to 16
  18629. @param controllerType the type of controller
  18630. @param value the controller value
  18631. @see isController
  18632. */
  18633. static const MidiMessage controllerEvent (const int channel,
  18634. const int controllerType,
  18635. const int value) throw();
  18636. /** Checks whether this message is an all-notes-off message.
  18637. @see allNotesOff
  18638. */
  18639. bool isAllNotesOff() const throw();
  18640. /** Checks whether this message is an all-sound-off message.
  18641. @see allSoundOff
  18642. */
  18643. bool isAllSoundOff() const throw();
  18644. /** Creates an all-notes-off message.
  18645. @param channel the midi channel, in the range 1 to 16
  18646. @see isAllNotesOff
  18647. */
  18648. static const MidiMessage allNotesOff (const int channel) throw();
  18649. /** Creates an all-sound-off message.
  18650. @param channel the midi channel, in the range 1 to 16
  18651. @see isAllSoundOff
  18652. */
  18653. static const MidiMessage allSoundOff (const int channel) throw();
  18654. /** Creates an all-controllers-off message.
  18655. @param channel the midi channel, in the range 1 to 16
  18656. */
  18657. static const MidiMessage allControllersOff (const int channel) throw();
  18658. /** Returns true if this event is a meta-event.
  18659. Meta-events are things like tempo changes, track names, etc.
  18660. @see getMetaEventType, isTrackMetaEvent, isEndOfTrackMetaEvent,
  18661. isTextMetaEvent, isTrackNameEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
  18662. isKeySignatureMetaEvent, isMidiChannelMetaEvent
  18663. */
  18664. bool isMetaEvent() const throw();
  18665. /** Returns a meta-event's type number.
  18666. If the message isn't a meta-event, this will return -1.
  18667. @see isMetaEvent, isTrackMetaEvent, isEndOfTrackMetaEvent,
  18668. isTextMetaEvent, isTrackNameEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
  18669. isKeySignatureMetaEvent, isMidiChannelMetaEvent
  18670. */
  18671. int getMetaEventType() const throw();
  18672. /** Returns a pointer to the data in a meta-event.
  18673. @see isMetaEvent, getMetaEventLength
  18674. */
  18675. const uint8* getMetaEventData() const throw();
  18676. /** Returns the length of the data for a meta-event.
  18677. @see isMetaEvent, getMetaEventData
  18678. */
  18679. int getMetaEventLength() const throw();
  18680. /** Returns true if this is a 'track' meta-event. */
  18681. bool isTrackMetaEvent() const throw();
  18682. /** Returns true if this is an 'end-of-track' meta-event. */
  18683. bool isEndOfTrackMetaEvent() const throw();
  18684. /** Creates an end-of-track meta-event.
  18685. @see isEndOfTrackMetaEvent
  18686. */
  18687. static const MidiMessage endOfTrack() throw();
  18688. /** Returns true if this is an 'track name' meta-event.
  18689. You can use the getTextFromTextMetaEvent() method to get the track's name.
  18690. */
  18691. bool isTrackNameEvent() const throw();
  18692. /** Returns true if this is a 'text' meta-event.
  18693. @see getTextFromTextMetaEvent
  18694. */
  18695. bool isTextMetaEvent() const throw();
  18696. /** Returns the text from a text meta-event.
  18697. @see isTextMetaEvent
  18698. */
  18699. const String getTextFromTextMetaEvent() const throw();
  18700. /** Returns true if this is a 'tempo' meta-event.
  18701. @see getTempoMetaEventTickLength, getTempoSecondsPerQuarterNote
  18702. */
  18703. bool isTempoMetaEvent() const throw();
  18704. /** Returns the tick length from a tempo meta-event.
  18705. @param timeFormat the 16-bit time format value from the midi file's header.
  18706. @returns the tick length (in seconds).
  18707. @see isTempoMetaEvent
  18708. */
  18709. double getTempoMetaEventTickLength (const short timeFormat) const throw();
  18710. /** Calculates the seconds-per-quarter-note from a tempo meta-event.
  18711. @see isTempoMetaEvent, getTempoMetaEventTickLength
  18712. */
  18713. double getTempoSecondsPerQuarterNote() const throw();
  18714. /** Creates a tempo meta-event.
  18715. @see isTempoMetaEvent
  18716. */
  18717. static const MidiMessage tempoMetaEvent (const int microsecondsPerQuarterNote) throw();
  18718. /** Returns true if this is a 'time-signature' meta-event.
  18719. @see getTimeSignatureInfo
  18720. */
  18721. bool isTimeSignatureMetaEvent() const throw();
  18722. /** Returns the time-signature values from a time-signature meta-event.
  18723. @see isTimeSignatureMetaEvent
  18724. */
  18725. void getTimeSignatureInfo (int& numerator,
  18726. int& denominator) const throw();
  18727. /** Creates a time-signature meta-event.
  18728. @see isTimeSignatureMetaEvent
  18729. */
  18730. static const MidiMessage timeSignatureMetaEvent (const int numerator,
  18731. const int denominator) throw();
  18732. /** Returns true if this is a 'key-signature' meta-event.
  18733. @see getKeySignatureNumberOfSharpsOrFlats
  18734. */
  18735. bool isKeySignatureMetaEvent() const throw();
  18736. /** Returns the key from a key-signature meta-event.
  18737. @see isKeySignatureMetaEvent
  18738. */
  18739. int getKeySignatureNumberOfSharpsOrFlats() const throw();
  18740. /** Returns true if this is a 'channel' meta-event.
  18741. A channel meta-event specifies the midi channel that should be used
  18742. for subsequent meta-events.
  18743. @see getMidiChannelMetaEventChannel
  18744. */
  18745. bool isMidiChannelMetaEvent() const throw();
  18746. /** Returns the channel number from a channel meta-event.
  18747. @returns the channel, in the range 1 to 16.
  18748. @see isMidiChannelMetaEvent
  18749. */
  18750. int getMidiChannelMetaEventChannel() const throw();
  18751. /** Creates a midi channel meta-event.
  18752. @param channel the midi channel, in the range 1 to 16
  18753. @see isMidiChannelMetaEvent
  18754. */
  18755. static const MidiMessage midiChannelMetaEvent (const int channel) throw();
  18756. /** Returns true if this is an active-sense message. */
  18757. bool isActiveSense() const throw();
  18758. /** Returns true if this is a midi start event.
  18759. @see midiStart
  18760. */
  18761. bool isMidiStart() const throw();
  18762. /** Creates a midi start event. */
  18763. static const MidiMessage midiStart() throw();
  18764. /** Returns true if this is a midi continue event.
  18765. @see midiContinue
  18766. */
  18767. bool isMidiContinue() const throw();
  18768. /** Creates a midi continue event. */
  18769. static const MidiMessage midiContinue() throw();
  18770. /** Returns true if this is a midi stop event.
  18771. @see midiStop
  18772. */
  18773. bool isMidiStop() const throw();
  18774. /** Creates a midi stop event. */
  18775. static const MidiMessage midiStop() throw();
  18776. /** Returns true if this is a midi clock event.
  18777. @see midiClock, songPositionPointer
  18778. */
  18779. bool isMidiClock() const throw();
  18780. /** Creates a midi clock event. */
  18781. static const MidiMessage midiClock() throw();
  18782. /** Returns true if this is a song-position-pointer message.
  18783. @see getSongPositionPointerMidiBeat, songPositionPointer
  18784. */
  18785. bool isSongPositionPointer() const throw();
  18786. /** Returns the midi beat-number of a song-position-pointer message.
  18787. @see isSongPositionPointer, songPositionPointer
  18788. */
  18789. int getSongPositionPointerMidiBeat() const throw();
  18790. /** Creates a song-position-pointer message.
  18791. The position is a number of midi beats from the start of the song, where 1 midi
  18792. beat is 6 midi clocks, and there are 24 midi clocks in a quarter-note. So there
  18793. are 4 midi beats in a quarter-note.
  18794. @see isSongPositionPointer, getSongPositionPointerMidiBeat
  18795. */
  18796. static const MidiMessage songPositionPointer (const int positionInMidiBeats) throw();
  18797. /** Returns true if this is a quarter-frame midi timecode message.
  18798. @see quarterFrame, getQuarterFrameSequenceNumber, getQuarterFrameValue
  18799. */
  18800. bool isQuarterFrame() const throw();
  18801. /** Returns the sequence number of a quarter-frame midi timecode message.
  18802. This will be a value between 0 and 7.
  18803. @see isQuarterFrame, getQuarterFrameValue, quarterFrame
  18804. */
  18805. int getQuarterFrameSequenceNumber() const throw();
  18806. /** Returns the value from a quarter-frame message.
  18807. This will be the lower nybble of the message's data-byte, a value
  18808. between 0 and 15
  18809. */
  18810. int getQuarterFrameValue() const throw();
  18811. /** Creates a quarter-frame MTC message.
  18812. @param sequenceNumber a value 0 to 7 for the upper nybble of the message's data byte
  18813. @param value a value 0 to 15 for the lower nybble of the message's data byte
  18814. */
  18815. static const MidiMessage quarterFrame (const int sequenceNumber,
  18816. const int value) throw();
  18817. /** SMPTE timecode types.
  18818. Used by the getFullFrameParameters() and fullFrame() methods.
  18819. */
  18820. enum SmpteTimecodeType
  18821. {
  18822. fps24 = 0,
  18823. fps25 = 1,
  18824. fps30drop = 2,
  18825. fps30 = 3
  18826. };
  18827. /** Returns true if this is a full-frame midi timecode message.
  18828. */
  18829. bool isFullFrame() const throw();
  18830. /** Extracts the timecode information from a full-frame midi timecode message.
  18831. You should only call this on messages where you've used isFullFrame() to
  18832. check that they're the right kind.
  18833. */
  18834. void getFullFrameParameters (int& hours,
  18835. int& minutes,
  18836. int& seconds,
  18837. int& frames,
  18838. SmpteTimecodeType& timecodeType) const throw();
  18839. /** Creates a full-frame MTC message.
  18840. */
  18841. static const MidiMessage fullFrame (const int hours,
  18842. const int minutes,
  18843. const int seconds,
  18844. const int frames,
  18845. SmpteTimecodeType timecodeType);
  18846. /** Types of MMC command.
  18847. @see isMidiMachineControlMessage, getMidiMachineControlCommand, midiMachineControlCommand
  18848. */
  18849. enum MidiMachineControlCommand
  18850. {
  18851. mmc_stop = 1,
  18852. mmc_play = 2,
  18853. mmc_deferredplay = 3,
  18854. mmc_fastforward = 4,
  18855. mmc_rewind = 5,
  18856. mmc_recordStart = 6,
  18857. mmc_recordStop = 7,
  18858. mmc_pause = 9
  18859. };
  18860. /** Checks whether this is an MMC message.
  18861. If it is, you can use the getMidiMachineControlCommand() to find out its type.
  18862. */
  18863. bool isMidiMachineControlMessage() const throw();
  18864. /** For an MMC message, this returns its type.
  18865. Make sure it's actually an MMC message with isMidiMachineControlMessage() before
  18866. calling this method.
  18867. */
  18868. MidiMachineControlCommand getMidiMachineControlCommand() const throw();
  18869. /** Creates an MMC message.
  18870. */
  18871. static const MidiMessage midiMachineControlCommand (MidiMachineControlCommand command);
  18872. /** Checks whether this is an MMC "goto" message.
  18873. If it is, the parameters passed-in are set to the time that the message contains.
  18874. @see midiMachineControlGoto
  18875. */
  18876. bool isMidiMachineControlGoto (int& hours,
  18877. int& minutes,
  18878. int& seconds,
  18879. int& frames) const throw();
  18880. /** Creates an MMC "goto" message.
  18881. This messages tells the device to go to a specific frame.
  18882. @see isMidiMachineControlGoto
  18883. */
  18884. static const MidiMessage midiMachineControlGoto (int hours,
  18885. int minutes,
  18886. int seconds,
  18887. int frames);
  18888. /** Creates a master-volume change message.
  18889. @param volume the volume, 0 to 1.0
  18890. */
  18891. static const MidiMessage masterVolume (const float volume) throw();
  18892. /** Creates a system-exclusive message.
  18893. The data passed in is wrapped with header and tail bytes of 0xf0 and 0xf7.
  18894. */
  18895. static const MidiMessage createSysExMessage (const uint8* sysexData,
  18896. const int dataSize) throw();
  18897. /** Reads a midi variable-length integer.
  18898. @param data the data to read the number from
  18899. @param numBytesUsed on return, this will be set to the number of bytes that were read
  18900. */
  18901. static int readVariableLengthVal (const uint8* data,
  18902. int& numBytesUsed) throw();
  18903. /** Based on the first byte of a short midi message, this uses a lookup table
  18904. to return the message length (either 1, 2, or 3 bytes).
  18905. The value passed in must be 0x80 or higher.
  18906. */
  18907. static int getMessageLengthFromFirstByte (const uint8 firstByte) throw();
  18908. /** Returns the name of a midi note number.
  18909. E.g "C", "D#", etc.
  18910. @param noteNumber the midi note number, 0 to 127
  18911. @param useSharps if true, sharpened notes are used, e.g. "C#", otherwise
  18912. they'll be flattened, e.g. "Db"
  18913. @param includeOctaveNumber if true, the octave number will be appended to the string,
  18914. e.g. "C#4"
  18915. @param octaveNumForMiddleC if an octave number is being appended, this indicates the
  18916. number that will be used for middle C's octave
  18917. @see getMidiNoteInHertz
  18918. */
  18919. static const String getMidiNoteName (int noteNumber,
  18920. bool useSharps,
  18921. bool includeOctaveNumber,
  18922. int octaveNumForMiddleC) throw();
  18923. /** Returns the frequency of a midi note number.
  18924. @see getMidiNoteName
  18925. */
  18926. static const double getMidiNoteInHertz (int noteNumber) throw();
  18927. /** Returns the standard name of a GM instrument.
  18928. @param midiInstrumentNumber the program number 0 to 127
  18929. @see getProgramChangeNumber
  18930. */
  18931. static const String getGMInstrumentName (int midiInstrumentNumber) throw();
  18932. /** Returns the name of a bank of GM instruments.
  18933. @param midiBankNumber the bank, 0 to 15
  18934. */
  18935. static const String getGMInstrumentBankName (int midiBankNumber) throw();
  18936. /** Returns the standard name of a channel 10 percussion sound.
  18937. @param midiNoteNumber the key number, 35 to 81
  18938. */
  18939. static const String getRhythmInstrumentName (int midiNoteNumber) throw();
  18940. /** Returns the name of a controller type number.
  18941. @see getControllerNumber
  18942. */
  18943. static const String getControllerName (int controllerNumber) throw();
  18944. juce_UseDebuggingNewOperator
  18945. private:
  18946. double timeStamp;
  18947. uint8* data;
  18948. int message, size;
  18949. };
  18950. #endif // __JUCE_MIDIMESSAGE_JUCEHEADER__
  18951. /********* End of inlined file: juce_MidiMessage.h *********/
  18952. /**
  18953. Holds a sequence of time-stamped midi events.
  18954. Analogous to the AudioSampleBuffer, this holds a set of midi events with
  18955. integer time-stamps. The buffer is kept sorted in order of the time-stamps.
  18956. @see MidiMessage
  18957. */
  18958. class JUCE_API MidiBuffer : private ArrayAllocationBase <uint8>
  18959. {
  18960. public:
  18961. /** Creates an empty MidiBuffer. */
  18962. MidiBuffer() throw();
  18963. /** Creates a copy of another MidiBuffer. */
  18964. MidiBuffer (const MidiBuffer& other) throw();
  18965. /** Makes a copy of another MidiBuffer. */
  18966. const MidiBuffer& operator= (const MidiBuffer& other) throw();
  18967. /** Destructor */
  18968. ~MidiBuffer() throw();
  18969. /** Removes all events from the buffer. */
  18970. void clear() throw();
  18971. /** Removes all events between two times from the buffer.
  18972. All events for which (start <= event position < start + numSamples) will
  18973. be removed.
  18974. */
  18975. void clear (const int start,
  18976. const int numSamples) throw();
  18977. /** Returns true if the buffer is empty.
  18978. To actually retrieve the events, use a MidiBuffer::Iterator object
  18979. */
  18980. bool isEmpty() const throw();
  18981. /** Counts the number of events in the buffer.
  18982. This is actually quite a slow operation, as it has to iterate through all
  18983. the events, so you might prefer to call isEmpty() if that's all you need
  18984. to know.
  18985. */
  18986. int getNumEvents() const throw();
  18987. /** Adds an event to the buffer.
  18988. The sample number will be used to determine the position of the event in
  18989. the buffer, which is always kept sorted. The MidiMessage's timestamp is
  18990. ignored.
  18991. If an event is added whose sample position is the same as one or more events
  18992. already in the buffer, the new event will be placed after the existing ones.
  18993. To retrieve events, use a MidiBuffer::Iterator object
  18994. */
  18995. void addEvent (const MidiMessage& midiMessage,
  18996. const int sampleNumber) throw();
  18997. /** Adds an event to the buffer from raw midi data.
  18998. The sample number will be used to determine the position of the event in
  18999. the buffer, which is always kept sorted.
  19000. If an event is added whose sample position is the same as one or more events
  19001. already in the buffer, the new event will be placed after the existing ones.
  19002. The event data will be inspected to calculate the number of bytes in length that
  19003. the midi event really takes up, so maxBytesOfMidiData may be longer than the data
  19004. that actually gets stored. E.g. if you pass in a note-on and a length of 4 bytes,
  19005. it'll actually only store 3 bytes. If the midi data is invalid, it might not
  19006. add an event at all.
  19007. To retrieve events, use a MidiBuffer::Iterator object
  19008. */
  19009. void addEvent (const uint8* const rawMidiData,
  19010. const int maxBytesOfMidiData,
  19011. const int sampleNumber) throw();
  19012. /** Adds some events from another buffer to this one.
  19013. @param otherBuffer the buffer containing the events you want to add
  19014. @param startSample the lowest sample number in the source buffer for which
  19015. events should be added. Any source events whose timestamp is
  19016. less than this will be ignored
  19017. @param numSamples the valid range of samples from the source buffer for which
  19018. events should be added - i.e. events in the source buffer whose
  19019. timestamp is greater than or equal to (startSample + numSamples)
  19020. will be ignored. If this value is less than 0, all events after
  19021. startSample will be taken.
  19022. @param sampleDeltaToAdd a value which will be added to the source timestamps of the events
  19023. that are added to this buffer
  19024. */
  19025. void addEvents (const MidiBuffer& otherBuffer,
  19026. const int startSample,
  19027. const int numSamples,
  19028. const int sampleDeltaToAdd) throw();
  19029. /** Returns the sample number of the first event in the buffer.
  19030. If the buffer's empty, this will just return 0.
  19031. */
  19032. int getFirstEventTime() const throw();
  19033. /** Returns the sample number of the last event in the buffer.
  19034. If the buffer's empty, this will just return 0.
  19035. */
  19036. int getLastEventTime() const throw();
  19037. /**
  19038. Used to iterate through the events in a MidiBuffer.
  19039. Note that altering the buffer while an iterator is using it isn't a
  19040. safe operation.
  19041. @see MidiBuffer
  19042. */
  19043. class Iterator
  19044. {
  19045. public:
  19046. /** Creates an Iterator for this MidiBuffer. */
  19047. Iterator (const MidiBuffer& buffer) throw();
  19048. /** Destructor. */
  19049. ~Iterator() throw();
  19050. /** Repositions the iterator so that the next event retrieved will be the first
  19051. one whose sample position is at greater than or equal to the given position.
  19052. */
  19053. void setNextSamplePosition (const int samplePosition) throw();
  19054. /** Retrieves a copy of the next event from the buffer.
  19055. @param result on return, this will be the message (the MidiMessage's timestamp
  19056. is not set)
  19057. @param samplePosition on return, this will be the position of the event
  19058. @returns true if an event was found, or false if the iterator has reached
  19059. the end of the buffer
  19060. */
  19061. bool getNextEvent (MidiMessage& result,
  19062. int& samplePosition) throw();
  19063. /** Retrieves the next event from the buffer.
  19064. @param midiData on return, this pointer will be set to a block of data containing
  19065. the midi message. Note that to make it fast, this is a pointer
  19066. directly into the MidiBuffer's internal data, so is only valid
  19067. temporarily until the MidiBuffer is altered.
  19068. @param numBytesOfMidiData on return, this is the number of bytes of data used by the
  19069. midi message
  19070. @param samplePosition on return, this will be the position of the event
  19071. @returns true if an event was found, or false if the iterator has reached
  19072. the end of the buffer
  19073. */
  19074. bool getNextEvent (const uint8* &midiData,
  19075. int& numBytesOfMidiData,
  19076. int& samplePosition) throw();
  19077. juce_UseDebuggingNewOperator
  19078. private:
  19079. const MidiBuffer& buffer;
  19080. const uint8* data;
  19081. Iterator (const Iterator&);
  19082. const Iterator& operator= (const Iterator&);
  19083. };
  19084. juce_UseDebuggingNewOperator
  19085. private:
  19086. friend class MidiBuffer::Iterator;
  19087. int bytesUsed;
  19088. uint8* findEventAfter (uint8* d, const int samplePosition) const throw();
  19089. };
  19090. #endif // __JUCE_MIDIBUFFER_JUCEHEADER__
  19091. /********* End of inlined file: juce_MidiBuffer.h *********/
  19092. #endif
  19093. #ifndef __JUCE_MIDIFILE_JUCEHEADER__
  19094. /********* Start of inlined file: juce_MidiFile.h *********/
  19095. #ifndef __JUCE_MIDIFILE_JUCEHEADER__
  19096. #define __JUCE_MIDIFILE_JUCEHEADER__
  19097. /********* Start of inlined file: juce_MidiMessageSequence.h *********/
  19098. #ifndef __JUCE_MIDIMESSAGESEQUENCE_JUCEHEADER__
  19099. #define __JUCE_MIDIMESSAGESEQUENCE_JUCEHEADER__
  19100. /**
  19101. A sequence of timestamped midi messages.
  19102. This allows the sequence to be manipulated, and also to be read from and
  19103. written to a standard midi file.
  19104. @see MidiMessage, MidiFile
  19105. */
  19106. class JUCE_API MidiMessageSequence
  19107. {
  19108. public:
  19109. /** Creates an empty midi sequence object. */
  19110. MidiMessageSequence();
  19111. /** Creates a copy of another sequence. */
  19112. MidiMessageSequence (const MidiMessageSequence& other);
  19113. /** Replaces this sequence with another one. */
  19114. const MidiMessageSequence& operator= (const MidiMessageSequence& other);
  19115. /** Destructor. */
  19116. ~MidiMessageSequence();
  19117. /** Structure used to hold midi events in the sequence.
  19118. These structures act as 'handles' on the events as they are moved about in
  19119. the list, and make it quick to find the matching note-offs for note-on events.
  19120. @see MidiMessageSequence::getEventPointer
  19121. */
  19122. class MidiEventHolder
  19123. {
  19124. public:
  19125. /** Destructor. */
  19126. ~MidiEventHolder();
  19127. /** The message itself, whose timestamp is used to specify the event's time.
  19128. */
  19129. MidiMessage message;
  19130. /** The matching note-off event (if this is a note-on event).
  19131. If this isn't a note-on, this pointer will be null.
  19132. Use the MidiMessageSequence::updateMatchedPairs() method to keep these
  19133. note-offs up-to-date after events have been moved around in the sequence
  19134. or deleted.
  19135. */
  19136. MidiEventHolder* noteOffObject;
  19137. juce_UseDebuggingNewOperator
  19138. private:
  19139. friend class MidiMessageSequence;
  19140. MidiEventHolder (const MidiMessage& message);
  19141. };
  19142. /** Clears the sequence. */
  19143. void clear();
  19144. /** Returns the number of events in the sequence. */
  19145. int getNumEvents() const;
  19146. /** Returns a pointer to one of the events. */
  19147. MidiEventHolder* getEventPointer (const int index) const;
  19148. /** Returns the time of the note-up that matches the note-on at this index.
  19149. If the event at this index isn't a note-on, it'll just return 0.
  19150. @see MidiMessageSequence::MidiEventHolder::noteOffObject
  19151. */
  19152. double getTimeOfMatchingKeyUp (const int index) const;
  19153. /** Returns the index of the note-up that matches the note-on at this index.
  19154. If the event at this index isn't a note-on, it'll just return -1.
  19155. @see MidiMessageSequence::MidiEventHolder::noteOffObject
  19156. */
  19157. int getIndexOfMatchingKeyUp (const int index) const;
  19158. /** Returns the index of an event. */
  19159. int getIndexOf (MidiEventHolder* const event) const;
  19160. /** Returns the index of the first event on or after the given timestamp.
  19161. If the time is beyond the end of the sequence, this will return the
  19162. number of events.
  19163. */
  19164. int getNextIndexAtTime (const double timeStamp) const;
  19165. /** Returns the timestamp of the first event in the sequence.
  19166. @see getEndTime
  19167. */
  19168. double getStartTime() const;
  19169. /** Returns the timestamp of the last event in the sequence.
  19170. @see getStartTime
  19171. */
  19172. double getEndTime() const;
  19173. /** Returns the timestamp of the event at a given index.
  19174. If the index is out-of-range, this will return 0.0
  19175. */
  19176. double getEventTime (const int index) const;
  19177. /** Inserts a midi message into the sequence.
  19178. The index at which the new message gets inserted will depend on its timestamp,
  19179. because the sequence is kept sorted.
  19180. Remember to call updateMatchedPairs() after adding note-on events.
  19181. @param newMessage the new message to add (an internal copy will be made)
  19182. @param timeAdjustment an optional value to add to the timestamp of the message
  19183. that will be inserted
  19184. @see updateMatchedPairs
  19185. */
  19186. void addEvent (const MidiMessage& newMessage,
  19187. double timeAdjustment = 0);
  19188. /** Deletes one of the events in the sequence.
  19189. Remember to call updateMatchedPairs() after removing events.
  19190. @param index the index of the event to delete
  19191. @param deleteMatchingNoteUp whether to also remove the matching note-off
  19192. if the event you're removing is a note-on
  19193. */
  19194. void deleteEvent (const int index,
  19195. const bool deleteMatchingNoteUp);
  19196. /** Merges another sequence into this one.
  19197. Remember to call updateMatchedPairs() after using this method.
  19198. @param other the sequence to add from
  19199. @param timeAdjustmentDelta an amount to add to the timestamps of the midi events
  19200. as they are read from the other sequence
  19201. @param firstAllowableDestTime events will not be added if their time is earlier
  19202. than this time. (This is after their time has been adjusted
  19203. by the timeAdjustmentDelta)
  19204. @param endOfAllowableDestTimes events will not be added if their time is equal to
  19205. or greater than this time. (This is after their time has
  19206. been adjusted by the timeAdjustmentDelta)
  19207. */
  19208. void addSequence (const MidiMessageSequence& other,
  19209. double timeAdjustmentDelta,
  19210. double firstAllowableDestTime,
  19211. double endOfAllowableDestTimes);
  19212. /** Makes sure all the note-on and note-off pairs are up-to-date.
  19213. Call this after moving messages about or deleting/adding messages, and it
  19214. will scan the list and make sure all the note-offs in the MidiEventHolder
  19215. structures are pointing at the correct ones.
  19216. */
  19217. void updateMatchedPairs();
  19218. /** Copies all the messages for a particular midi channel to another sequence.
  19219. @param channelNumberToExtract the midi channel to look for, in the range 1 to 16
  19220. @param destSequence the sequence that the chosen events should be copied to
  19221. @param alsoIncludeMetaEvents if true, any meta-events (which don't apply to a specific
  19222. channel) will also be copied across.
  19223. @see extractSysExMessages
  19224. */
  19225. void extractMidiChannelMessages (const int channelNumberToExtract,
  19226. MidiMessageSequence& destSequence,
  19227. const bool alsoIncludeMetaEvents) const;
  19228. /** Copies all midi sys-ex messages to another sequence.
  19229. @param destSequence this is the sequence to which any sys-exes in this sequence
  19230. will be added
  19231. @see extractMidiChannelMessages
  19232. */
  19233. void extractSysExMessages (MidiMessageSequence& destSequence) const;
  19234. /** Removes any messages in this sequence that have a specific midi channel.
  19235. @param channelNumberToRemove the midi channel to look for, in the range 1 to 16
  19236. */
  19237. void deleteMidiChannelMessages (const int channelNumberToRemove);
  19238. /** Removes any sys-ex messages from this sequence.
  19239. */
  19240. void deleteSysExMessages();
  19241. /** Adds an offset to the timestamps of all events in the sequence.
  19242. @param deltaTime the amount to add to each timestamp.
  19243. */
  19244. void addTimeToMessages (const double deltaTime);
  19245. /** Scans through the sequence to determine the state of any midi controllers at
  19246. a given time.
  19247. This will create a sequence of midi controller changes that can be
  19248. used to set all midi controllers to the state they would be in at the
  19249. specified time within this sequence.
  19250. As well as controllers, it will also recreate the midi program number
  19251. and pitch bend position.
  19252. @param channelNumber the midi channel to look for, in the range 1 to 16. Controllers
  19253. for other channels will be ignored.
  19254. @param time the time at which you want to find out the state - there are
  19255. no explicit units for this time measurement, it's the same units
  19256. as used for the timestamps of the messages
  19257. @param resultMessages an array to which midi controller-change messages will be added. This
  19258. will be the minimum number of controller changes to recreate the
  19259. state at the required time.
  19260. */
  19261. void createControllerUpdatesForTime (const int channelNumber,
  19262. const double time,
  19263. OwnedArray<MidiMessage>& resultMessages);
  19264. juce_UseDebuggingNewOperator
  19265. /** @internal */
  19266. static int compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  19267. const MidiMessageSequence::MidiEventHolder* const second) throw();
  19268. private:
  19269. friend class MidiComparator;
  19270. friend class MidiFile;
  19271. OwnedArray <MidiEventHolder> list;
  19272. void sort();
  19273. };
  19274. #endif // __JUCE_MIDIMESSAGESEQUENCE_JUCEHEADER__
  19275. /********* End of inlined file: juce_MidiMessageSequence.h *********/
  19276. /**
  19277. Reads/writes standard midi format files.
  19278. To read a midi file, create a MidiFile object and call its readFrom() method. You
  19279. can then get the individual midi tracks from it using the getTrack() method.
  19280. To write a file, create a MidiFile object, add some MidiMessageSequence objects
  19281. to it using the addTrack() method, and then call its writeTo() method to stream
  19282. it out.
  19283. @see MidiMessageSequence
  19284. */
  19285. class JUCE_API MidiFile
  19286. {
  19287. public:
  19288. /** Creates an empty MidiFile object.
  19289. */
  19290. MidiFile() throw();
  19291. /** Destructor. */
  19292. ~MidiFile() throw();
  19293. /** Returns the number of tracks in the file.
  19294. @see getTrack, addTrack
  19295. */
  19296. int getNumTracks() const throw();
  19297. /** Returns a pointer to one of the tracks in the file.
  19298. @returns a pointer to the track, or 0 if the index is out-of-range
  19299. @see getNumTracks, addTrack
  19300. */
  19301. const MidiMessageSequence* getTrack (const int index) const throw();
  19302. /** Adds a midi track to the file.
  19303. This will make its own internal copy of the sequence that is passed-in.
  19304. @see getNumTracks, getTrack
  19305. */
  19306. void addTrack (const MidiMessageSequence& trackSequence) throw();
  19307. /** Removes all midi tracks from the file.
  19308. @see getNumTracks
  19309. */
  19310. void clear() throw();
  19311. /** Returns the raw time format code that will be written to a stream.
  19312. After reading a midi file, this method will return the time-format that
  19313. was read from the file's header. It can be changed using the setTicksPerQuarterNote()
  19314. or setSmpteTimeFormat() methods.
  19315. If the value returned is positive, it indicates the number of midi ticks
  19316. per quarter-note - see setTicksPerQuarterNote().
  19317. It it's negative, the upper byte indicates the frames-per-second (but negative), and
  19318. the lower byte is the number of ticks per frame - see setSmpteTimeFormat().
  19319. */
  19320. short getTimeFormat() const throw();
  19321. /** Sets the time format to use when this file is written to a stream.
  19322. If this is called, the file will be written as bars/beats using the
  19323. specified resolution, rather than SMPTE absolute times, as would be
  19324. used if setSmpteTimeFormat() had been called instead.
  19325. @param ticksPerQuarterNote e.g. 96, 960
  19326. @see setSmpteTimeFormat
  19327. */
  19328. void setTicksPerQuarterNote (const int ticksPerQuarterNote) throw();
  19329. /** Sets the time format to use when this file is written to a stream.
  19330. If this is called, the file will be written using absolute times, rather
  19331. than bars/beats as would be the case if setTicksPerBeat() had been called
  19332. instead.
  19333. @param framesPerSecond must be 24, 25, 29 or 30
  19334. @param subframeResolution the sub-second resolution, e.g. 4 (midi time code),
  19335. 8, 10, 80 (SMPTE bit resolution), or 100. For millisecond
  19336. timing, setSmpteTimeFormat (25, 40)
  19337. @see setTicksPerBeat
  19338. */
  19339. void setSmpteTimeFormat (const int framesPerSecond,
  19340. const int subframeResolution) throw();
  19341. /** Makes a list of all the tempo-change meta-events from all tracks in the midi file.
  19342. Useful for finding the positions of all the tempo changes in a file.
  19343. @param tempoChangeEvents a list to which all the events will be added
  19344. */
  19345. void findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const;
  19346. /** Makes a list of all the time-signature meta-events from all tracks in the midi file.
  19347. Useful for finding the positions of all the tempo changes in a file.
  19348. @param timeSigEvents a list to which all the events will be added
  19349. */
  19350. void findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const;
  19351. /** Returns the latest timestamp in any of the tracks.
  19352. (Useful for finding the length of the file).
  19353. */
  19354. double getLastTimestamp() const;
  19355. /** Reads a midi file format stream.
  19356. After calling this, you can get the tracks that were read from the file by using the
  19357. getNumTracks() and getTrack() methods.
  19358. The timestamps of the midi events in the tracks will represent their positions in
  19359. terms of midi ticks. To convert them to seconds, use the convertTimestampTicksToSeconds()
  19360. method.
  19361. @returns true if the stream was read successfully
  19362. */
  19363. bool readFrom (InputStream& sourceStream);
  19364. /** Writes the midi tracks as a standard midi file.
  19365. @returns true if the operation succeeded.
  19366. */
  19367. bool writeTo (OutputStream& destStream);
  19368. /** Converts the timestamp of all the midi events from midi ticks to seconds.
  19369. This will use the midi time format and tempo/time signature info in the
  19370. tracks to convert all the timestamps to absolute values in seconds.
  19371. */
  19372. void convertTimestampTicksToSeconds();
  19373. juce_UseDebuggingNewOperator
  19374. /** @internal */
  19375. static int compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  19376. const MidiMessageSequence::MidiEventHolder* const second) throw();
  19377. private:
  19378. MidiMessageSequence* tracks [128];
  19379. short numTracks, timeFormat;
  19380. MidiFile (const MidiFile&);
  19381. const MidiFile& operator= (const MidiFile&);
  19382. void readNextTrack (const char* data, int size);
  19383. void writeTrack (OutputStream& mainOut, const int trackNum);
  19384. };
  19385. #endif // __JUCE_MIDIFILE_JUCEHEADER__
  19386. /********* End of inlined file: juce_MidiFile.h *********/
  19387. #endif
  19388. #ifndef __JUCE_MIDIKEYBOARDSTATE_JUCEHEADER__
  19389. /********* Start of inlined file: juce_MidiKeyboardState.h *********/
  19390. #ifndef __JUCE_MIDIKEYBOARDSTATE_JUCEHEADER__
  19391. #define __JUCE_MIDIKEYBOARDSTATE_JUCEHEADER__
  19392. class MidiKeyboardState;
  19393. /**
  19394. Receives events from a MidiKeyboardState object.
  19395. @see MidiKeyboardState
  19396. */
  19397. class JUCE_API MidiKeyboardStateListener
  19398. {
  19399. public:
  19400. MidiKeyboardStateListener() throw() {}
  19401. virtual ~MidiKeyboardStateListener() {}
  19402. /** Called when one of the MidiKeyboardState's keys is pressed.
  19403. This will be called synchronously when the state is either processing a
  19404. buffer in its MidiKeyboardState::processNextMidiBuffer() method, or
  19405. when a note is being played with its MidiKeyboardState::noteOn() method.
  19406. Note that this callback could happen from an audio callback thread, so be
  19407. careful not to block, and avoid any UI activity in the callback.
  19408. */
  19409. virtual void handleNoteOn (MidiKeyboardState* source,
  19410. int midiChannel, int midiNoteNumber, float velocity) = 0;
  19411. /** Called when one of the MidiKeyboardState's keys is released.
  19412. This will be called synchronously when the state is either processing a
  19413. buffer in its MidiKeyboardState::processNextMidiBuffer() method, or
  19414. when a note is being played with its MidiKeyboardState::noteOff() method.
  19415. Note that this callback could happen from an audio callback thread, so be
  19416. careful not to block, and avoid any UI activity in the callback.
  19417. */
  19418. virtual void handleNoteOff (MidiKeyboardState* source,
  19419. int midiChannel, int midiNoteNumber) = 0;
  19420. };
  19421. /**
  19422. Represents a piano keyboard, keeping track of which keys are currently pressed.
  19423. This object can parse a stream of midi events, using them to update its idea
  19424. of which keys are pressed for each individiual midi channel.
  19425. When keys go up or down, it can broadcast these events to listener objects.
  19426. It also allows key up/down events to be triggered with its noteOn() and noteOff()
  19427. methods, and midi messages for these events will be merged into the
  19428. midi stream that gets processed by processNextMidiBuffer().
  19429. */
  19430. class JUCE_API MidiKeyboardState
  19431. {
  19432. public:
  19433. MidiKeyboardState();
  19434. ~MidiKeyboardState();
  19435. /** Resets the state of the object.
  19436. All internal data for all the channels is reset, but no events are sent as a
  19437. result.
  19438. If you want to release any keys that are currently down, and to send out note-up
  19439. midi messages for this, use the allNotesOff() method instead.
  19440. */
  19441. void reset();
  19442. /** Returns true if the given midi key is currently held down for the given midi channel.
  19443. The channel number must be between 1 and 16. If you want to see if any notes are
  19444. on for a range of channels, use the isNoteOnForChannels() method.
  19445. */
  19446. bool isNoteOn (const int midiChannel, const int midiNoteNumber) const throw();
  19447. /** Returns true if the given midi key is currently held down on any of a set of midi channels.
  19448. The channel mask has a bit set for each midi channel you want to test for - bit
  19449. 0 = midi channel 1, bit 1 = midi channel 2, etc.
  19450. If a note is on for at least one of the specified channels, this returns true.
  19451. */
  19452. bool isNoteOnForChannels (const int midiChannelMask, const int midiNoteNumber) const throw();
  19453. /** Turns a specified note on.
  19454. This will cause a suitable midi note-on event to be injected into the midi buffer during the
  19455. next call to processNextMidiBuffer().
  19456. It will also trigger a synchronous callback to the listeners to tell them that the key has
  19457. gone down.
  19458. */
  19459. void noteOn (const int midiChannel, const int midiNoteNumber, const float velocity);
  19460. /** Turns a specified note off.
  19461. This will cause a suitable midi note-off event to be injected into the midi buffer during the
  19462. next call to processNextMidiBuffer().
  19463. It will also trigger a synchronous callback to the listeners to tell them that the key has
  19464. gone up.
  19465. But if the note isn't acutally down for the given channel, this method will in fact do nothing.
  19466. */
  19467. void noteOff (const int midiChannel, const int midiNoteNumber);
  19468. /** This will turn off any currently-down notes for the given midi channel.
  19469. If you pass 0 for the midi channel, it will in fact turn off all notes on all channels.
  19470. Calling this method will make calls to noteOff(), so can trigger synchronous callbacks
  19471. and events being added to the midi stream.
  19472. */
  19473. void allNotesOff (const int midiChannel);
  19474. /** Looks at a key-up/down event and uses it to update the state of this object.
  19475. To process a buffer full of midi messages, use the processNextMidiBuffer() method
  19476. instead.
  19477. */
  19478. void processNextMidiEvent (const MidiMessage& message);
  19479. /** Scans a midi stream for up/down events and adds its own events to it.
  19480. This will look for any up/down events and use them to update the internal state,
  19481. synchronously making suitable callbacks to the listeners.
  19482. If injectIndirectEvents is true, then midi events to produce the recent noteOn()
  19483. and noteOff() calls will be added into the buffer.
  19484. Only the section of the buffer whose timestamps are between startSample and
  19485. (startSample + numSamples) will be affected, and any events added will be placed
  19486. between these times.
  19487. If you're going to use this method, you'll need to keep calling it regularly for
  19488. it to work satisfactorily.
  19489. To process a single midi event at a time, use the processNextMidiEvent() method
  19490. instead.
  19491. */
  19492. void processNextMidiBuffer (MidiBuffer& buffer,
  19493. const int startSample,
  19494. const int numSamples,
  19495. const bool injectIndirectEvents);
  19496. /** Registers a listener for callbacks when keys go up or down.
  19497. @see removeListener
  19498. */
  19499. void addListener (MidiKeyboardStateListener* const listener) throw();
  19500. /** Deregisters a listener.
  19501. @see addListener
  19502. */
  19503. void removeListener (MidiKeyboardStateListener* const listener) throw();
  19504. juce_UseDebuggingNewOperator
  19505. private:
  19506. CriticalSection lock;
  19507. uint16 noteStates [128];
  19508. MidiBuffer eventsToAdd;
  19509. VoidArray listeners;
  19510. void noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity);
  19511. void noteOffInternal (const int midiChannel, const int midiNoteNumber);
  19512. MidiKeyboardState (const MidiKeyboardState&);
  19513. const MidiKeyboardState& operator= (const MidiKeyboardState&);
  19514. };
  19515. #endif // __JUCE_MIDIKEYBOARDSTATE_JUCEHEADER__
  19516. /********* End of inlined file: juce_MidiKeyboardState.h *********/
  19517. #endif
  19518. #ifndef __JUCE_MIDIMESSAGE_JUCEHEADER__
  19519. #endif
  19520. #ifndef __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__
  19521. /********* Start of inlined file: juce_MidiMessageCollector.h *********/
  19522. #ifndef __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__
  19523. #define __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__
  19524. /********* Start of inlined file: juce_MidiInput.h *********/
  19525. #ifndef __JUCE_MIDIINPUT_JUCEHEADER__
  19526. #define __JUCE_MIDIINPUT_JUCEHEADER__
  19527. class MidiInput;
  19528. /**
  19529. Receives midi messages from a midi input device.
  19530. This class is overridden to handle incoming midi messages. See the MidiInput
  19531. class for more details.
  19532. @see MidiInput
  19533. */
  19534. class JUCE_API MidiInputCallback
  19535. {
  19536. public:
  19537. /** Destructor. */
  19538. virtual ~MidiInputCallback() {}
  19539. /** Receives an incoming message.
  19540. A MidiInput object will call this method when a midi event arrives. It'll be
  19541. called on a high-priority system thread, so avoid doing anything time-consuming
  19542. in here, and avoid making any UI calls. You might find the MidiBuffer class helpful
  19543. for queueing incoming messages for use later.
  19544. @param source the MidiInput object that generated the message
  19545. @param message the incoming message. The message's timestamp is set to a value
  19546. equivalent to (Time::getMillisecondCounter() / 1000.0) to specify the
  19547. time when the message arrived.
  19548. */
  19549. virtual void handleIncomingMidiMessage (MidiInput* source,
  19550. const MidiMessage& message) = 0;
  19551. /** Notification sent each time a packet of a multi-packet sysex message arrives.
  19552. If a long sysex message is broken up into multiple packets, this callback is made
  19553. for each packet that arrives until the message is finished, at which point
  19554. the normal handleIncomingMidiMessage() callback will be made with the entire
  19555. message.
  19556. The message passed in will contain the start of a sysex, but won't be finished
  19557. with the terminating 0xf7 byte.
  19558. */
  19559. virtual void handlePartialSysexMessage (MidiInput* source,
  19560. const uint8* messageData,
  19561. const int numBytesSoFar,
  19562. const double timestamp)
  19563. {
  19564. // (this bit is just to avoid compiler warnings about unused variables)
  19565. (void) source; (void) messageData; (void) numBytesSoFar; (void) timestamp;
  19566. }
  19567. };
  19568. /**
  19569. Represents a midi input device.
  19570. To create one of these, use the static getDevices() method to find out what inputs are
  19571. available, and then use the openDevice() method to try to open one.
  19572. @see MidiOutput
  19573. */
  19574. class JUCE_API MidiInput
  19575. {
  19576. public:
  19577. /** Returns a list of the available midi input devices.
  19578. You can open one of the devices by passing its index into the
  19579. openDevice() method.
  19580. @see getDefaultDeviceIndex, openDevice
  19581. */
  19582. static const StringArray getDevices();
  19583. /** Returns the index of the default midi input device to use.
  19584. This refers to the index in the list returned by getDevices().
  19585. */
  19586. static int getDefaultDeviceIndex();
  19587. /** Tries to open one of the midi input devices.
  19588. This will return a MidiInput object if it manages to open it. You can then
  19589. call start() and stop() on this device, and delete it when no longer needed.
  19590. If the device can't be opened, this will return a null pointer.
  19591. @param deviceIndex the index of a device from the list returned by getDevices()
  19592. @param callback the object that will receive the midi messages from this device.
  19593. @see MidiInputCallback, getDevices
  19594. */
  19595. static MidiInput* openDevice (int deviceIndex,
  19596. MidiInputCallback* callback);
  19597. #if JUCE_LINUX || DOXYGEN
  19598. /** LINUX ONLY - This will try to create a new midi input device.
  19599. This will attempt to create a new midi input device with the specified name,
  19600. for other apps to connect to.
  19601. Returns 0 if a device can't be created.
  19602. @param deviceName the name to use for the new device
  19603. @param callback the object that will receive the midi messages from this device.
  19604. */
  19605. static MidiInput* createNewDevice (const String& deviceName,
  19606. MidiInputCallback* callback);
  19607. #endif
  19608. /** Destructor. */
  19609. ~MidiInput();
  19610. /** Returns the name of this device.
  19611. */
  19612. const String getName() const throw() { return name; }
  19613. /** Allows you to set a custom name for the device, in case you don't like the name
  19614. it was given when created.
  19615. */
  19616. void setName (const String& newName) throw() { name = newName; }
  19617. /** Starts the device running.
  19618. After calling this, the device will start sending midi messages to the
  19619. MidiInputCallback object that was specified when the openDevice() method
  19620. was called.
  19621. @see stop
  19622. */
  19623. void start();
  19624. /** Stops the device running.
  19625. @see start
  19626. */
  19627. void stop();
  19628. juce_UseDebuggingNewOperator
  19629. private:
  19630. String name;
  19631. void* internal;
  19632. MidiInput (const String& name);
  19633. MidiInput (const MidiInput&);
  19634. };
  19635. #endif // __JUCE_MIDIINPUT_JUCEHEADER__
  19636. /********* End of inlined file: juce_MidiInput.h *********/
  19637. /**
  19638. Collects incoming realtime MIDI messages and turns them into blocks suitable for
  19639. processing by a block-based audio callback.
  19640. The class can also be used as either a MidiKeyboardStateListener or a MidiInputCallback
  19641. so it can easily use a midi input or keyboard component as its source.
  19642. @see MidiMessage, MidiInput
  19643. */
  19644. class JUCE_API MidiMessageCollector : public MidiKeyboardStateListener,
  19645. public MidiInputCallback
  19646. {
  19647. public:
  19648. /** Creates a MidiMessageCollector. */
  19649. MidiMessageCollector();
  19650. /** Destructor. */
  19651. ~MidiMessageCollector();
  19652. /** Clears any messages from the queue.
  19653. You need to call this method before starting to use the collector, so that
  19654. it knows the correct sample rate to use.
  19655. */
  19656. void reset (const double sampleRate);
  19657. /** Takes an incoming real-time message and adds it to the queue.
  19658. The message's timestamp is taken, and it will be ready for retrieval as part
  19659. of the block returned by the next call to removeNextBlockOfMessages().
  19660. This method is fully thread-safe when overlapping calls are made with
  19661. removeNextBlockOfMessages().
  19662. */
  19663. void addMessageToQueue (const MidiMessage& message);
  19664. /** Removes all the pending messages from the queue as a buffer.
  19665. This will also correct the messages' timestamps to make sure they're in
  19666. the range 0 to numSamples - 1.
  19667. This call should be made regularly by something like an audio processing
  19668. callback, because the time that it happens is used in calculating the
  19669. midi event positions.
  19670. This method is fully thread-safe when overlapping calls are made with
  19671. addMessageToQueue().
  19672. */
  19673. void removeNextBlockOfMessages (MidiBuffer& destBuffer,
  19674. const int numSamples);
  19675. /** @internal */
  19676. void handleNoteOn (MidiKeyboardState* source, int midiChannel, int midiNoteNumber, float velocity);
  19677. /** @internal */
  19678. void handleNoteOff (MidiKeyboardState* source, int midiChannel, int midiNoteNumber);
  19679. /** @internal */
  19680. void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
  19681. juce_UseDebuggingNewOperator
  19682. private:
  19683. double lastCallbackTime;
  19684. CriticalSection midiCallbackLock;
  19685. MidiBuffer incomingMessages;
  19686. double sampleRate;
  19687. MidiMessageCollector (const MidiMessageCollector&);
  19688. const MidiMessageCollector& operator= (const MidiMessageCollector&);
  19689. };
  19690. #endif // __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__
  19691. /********* End of inlined file: juce_MidiMessageCollector.h *********/
  19692. #endif
  19693. #ifndef __JUCE_MIDIMESSAGESEQUENCE_JUCEHEADER__
  19694. #endif
  19695. #ifndef __JUCE_AUDIODATACONVERTERS_JUCEHEADER__
  19696. /********* Start of inlined file: juce_AudioDataConverters.h *********/
  19697. #ifndef __JUCE_AUDIODATACONVERTERS_JUCEHEADER__
  19698. #define __JUCE_AUDIODATACONVERTERS_JUCEHEADER__
  19699. /**
  19700. A set of routines to convert buffers of 32-bit floating point data to and from
  19701. various integer formats.
  19702. */
  19703. class JUCE_API AudioDataConverters
  19704. {
  19705. public:
  19706. static void convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 2);
  19707. static void convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 2);
  19708. static void convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 3);
  19709. static void convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 3);
  19710. static void convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 4);
  19711. static void convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 4);
  19712. static void convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 4);
  19713. static void convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample = 4);
  19714. static void convertInt16LEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 2);
  19715. static void convertInt16BEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 2);
  19716. static void convertInt24LEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 3);
  19717. static void convertInt24BEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 3);
  19718. static void convertInt32LEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 4);
  19719. static void convertInt32BEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 4);
  19720. static void convertFloat32LEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 4);
  19721. static void convertFloat32BEToFloat (const void* source, float* dest, int numSamples, const int srcBytesPerSample = 4);
  19722. enum DataFormat
  19723. {
  19724. int16LE,
  19725. int16BE,
  19726. int24LE,
  19727. int24BE,
  19728. int32LE,
  19729. int32BE,
  19730. float32LE,
  19731. float32BE,
  19732. };
  19733. static void convertFloatToFormat (const DataFormat destFormat,
  19734. const float* source, void* dest, int numSamples);
  19735. static void convertFormatToFloat (const DataFormat sourceFormat,
  19736. const void* source, float* dest, int numSamples);
  19737. static void interleaveSamples (const float** source, float* dest,
  19738. const int numSamples, const int numChannels);
  19739. static void deinterleaveSamples (const float* source, float** dest,
  19740. const int numSamples, const int numChannels);
  19741. };
  19742. #endif // __JUCE_AUDIODATACONVERTERS_JUCEHEADER__
  19743. /********* End of inlined file: juce_AudioDataConverters.h *********/
  19744. #endif
  19745. #ifndef __JUCE_AUDIOSAMPLEBUFFER_JUCEHEADER__
  19746. /********* Start of inlined file: juce_AudioSampleBuffer.h *********/
  19747. #ifndef __JUCE_AUDIOSAMPLEBUFFER_JUCEHEADER__
  19748. #define __JUCE_AUDIOSAMPLEBUFFER_JUCEHEADER__
  19749. class AudioFormatReader;
  19750. class AudioFormatWriter;
  19751. const int maxNumAudioSampleBufferChannels = 32;
  19752. /**
  19753. A multi-channel buffer of 32-bit floating point audio samples.
  19754. */
  19755. class JUCE_API AudioSampleBuffer
  19756. {
  19757. public:
  19758. /** Creates a buffer with a specified number of channels and samples.
  19759. The contents of the buffer will initially be undefined, so use clear() to
  19760. set all the samples to zero.
  19761. The buffer will allocate its memory internally, and this will be released
  19762. when the buffer is deleted.
  19763. */
  19764. AudioSampleBuffer (const int numChannels,
  19765. const int numSamples) throw();
  19766. /** Creates a buffer using a pre-allocated block of memory.
  19767. Note that if the buffer is resized or its number of channels is changed, it
  19768. will re-allocate memory internally and copy the existing data to this new area,
  19769. so it will then stop directly addressing this memory.
  19770. @param dataToReferTo a pre-allocated array containing pointers to the data
  19771. for each channel that should be used by this buffer. The
  19772. buffer will only refer to this memory, it won't try to delete
  19773. it when the buffer is deleted or resized.
  19774. @param numChannels the number of channels to use - this must correspond to the
  19775. number of elements in the array passed in
  19776. @param numSamples the number of samples to use - this must correspond to the
  19777. size of the arrays passed in
  19778. */
  19779. AudioSampleBuffer (float** dataToReferTo,
  19780. const int numChannels,
  19781. const int numSamples) throw();
  19782. /** Copies another buffer.
  19783. This buffer will make its own copy of the other's data, unless the buffer was created
  19784. using an external data buffer, in which case boths buffers will just point to the same
  19785. shared block of data.
  19786. */
  19787. AudioSampleBuffer (const AudioSampleBuffer& other) throw();
  19788. /** Copies another buffer onto this one.
  19789. This buffer's size will be changed to that of the other buffer.
  19790. */
  19791. const AudioSampleBuffer& operator= (const AudioSampleBuffer& other) throw();
  19792. /** Destructor.
  19793. This will free any memory allocated by the buffer.
  19794. */
  19795. virtual ~AudioSampleBuffer() throw();
  19796. /** Returns the number of channels of audio data that this buffer contains.
  19797. @see getSampleData
  19798. */
  19799. int getNumChannels() const throw() { return numChannels; }
  19800. /** Returns the number of samples allocated in each of the buffer's channels.
  19801. @see getSampleData
  19802. */
  19803. int getNumSamples() const throw() { return size; }
  19804. /** Returns a pointer to a sample in one of the buffer's channels.
  19805. For speed, this doesn't check whether the channel and sample number
  19806. are legal, so be careful when using it!
  19807. */
  19808. float* getSampleData (const int channelNumber,
  19809. const int sampleOffset = 0) const throw();
  19810. /** Chages the buffer's size or number of channels.
  19811. This can expand or contract the buffer's length, and add or remove channels.
  19812. If keepExistingContent is true, it will try to preserve as much of the
  19813. old data as it can in the new buffer.
  19814. If clearExtraSpace is true, then any extra channels or space that is
  19815. allocated will be also be cleared. If false, then this space is left
  19816. uninitialised.
  19817. If avoidReallocating is true, then changing the buffer's size won't reduce the
  19818. amount of memory that is currently allocated (but it will still increase it if
  19819. the new size is bigger than the amount it currently has). If this is false, then
  19820. a new allocation will be done so that the buffer uses takes up the minimum amount
  19821. of memory that it needs.
  19822. */
  19823. void setSize (const int newNumChannels,
  19824. const int newNumSamples,
  19825. const bool keepExistingContent = false,
  19826. const bool clearExtraSpace = false,
  19827. const bool avoidReallocating = false) throw();
  19828. /** Makes this buffer point to a pre-allocated set of channel data arrays.
  19829. There's also a constructor that lets you specify arrays like this, but this
  19830. lets you change the channels dynamically.
  19831. Note that if the buffer is resized or its number of channels is changed, it
  19832. will re-allocate memory internally and copy the existing data to this new area,
  19833. so it will then stop directly addressing this memory.
  19834. @param dataToReferTo a pre-allocated array containing pointers to the data
  19835. for each channel that should be used by this buffer. The
  19836. buffer will only refer to this memory, it won't try to delete
  19837. it when the buffer is deleted or resized.
  19838. @param numChannels the number of channels to use - this must correspond to the
  19839. number of elements in the array passed in
  19840. @param numSamples the number of samples to use - this must correspond to the
  19841. size of the arrays passed in
  19842. */
  19843. void setDataToReferTo (float** dataToReferTo,
  19844. const int numChannels,
  19845. const int numSamples) throw();
  19846. /** Clears all the samples in all channels. */
  19847. void clear() throw();
  19848. /** Clears a specified region of all the channels.
  19849. For speed, this doesn't check whether the channel and sample number
  19850. are in-range, so be careful!
  19851. */
  19852. void clear (const int startSample,
  19853. const int numSamples) throw();
  19854. /** Clears a specified region of just one channel.
  19855. For speed, this doesn't check whether the channel and sample number
  19856. are in-range, so be careful!
  19857. */
  19858. void clear (const int channel,
  19859. const int startSample,
  19860. const int numSamples) throw();
  19861. /** Applies a gain multiple to a region of one channel.
  19862. For speed, this doesn't check whether the channel and sample number
  19863. are in-range, so be careful!
  19864. */
  19865. void applyGain (const int channel,
  19866. const int startSample,
  19867. int numSamples,
  19868. const float gain) throw();
  19869. /** Applies a gain multiple to a region of all the channels.
  19870. For speed, this doesn't check whether the sample numbers
  19871. are in-range, so be careful!
  19872. */
  19873. void applyGain (const int startSample,
  19874. const int numSamples,
  19875. const float gain) throw();
  19876. /** Applies a range of gains to a region of a channel.
  19877. The gain that is applied to each sample will vary from
  19878. startGain on the first sample to endGain on the last Sample,
  19879. so it can be used to do basic fades.
  19880. For speed, this doesn't check whether the sample numbers
  19881. are in-range, so be careful!
  19882. */
  19883. void applyGainRamp (const int channel,
  19884. const int startSample,
  19885. int numSamples,
  19886. float startGain,
  19887. float endGain) throw();
  19888. /** Adds samples from another buffer to this one.
  19889. @param destChannel the channel within this buffer to add the samples to
  19890. @param destStartSample the start sample within this buffer's channel
  19891. @param source the source buffer to add from
  19892. @param sourceChannel the channel within the source buffer to read from
  19893. @param sourceStartSample the offset within the source buffer's channel to start reading samples from
  19894. @param numSamples the number of samples to process
  19895. @param gainToApplyToSource an optional gain to apply to the source samples before they are
  19896. added to this buffer's samples
  19897. @see copyFrom
  19898. */
  19899. void addFrom (const int destChannel,
  19900. const int destStartSample,
  19901. const AudioSampleBuffer& source,
  19902. const int sourceChannel,
  19903. const int sourceStartSample,
  19904. int numSamples,
  19905. const float gainToApplyToSource = 1.0f) throw();
  19906. /** Adds samples from an array of floats to one of the channels.
  19907. @param destChannel the channel within this buffer to add the samples to
  19908. @param destStartSample the start sample within this buffer's channel
  19909. @param source the source data to use
  19910. @param numSamples the number of samples to process
  19911. @param gainToApplyToSource an optional gain to apply to the source samples before they are
  19912. added to this buffer's samples
  19913. @see copyFrom
  19914. */
  19915. void addFrom (const int destChannel,
  19916. const int destStartSample,
  19917. const float* source,
  19918. int numSamples,
  19919. const float gainToApplyToSource = 1.0f) throw();
  19920. /** Adds samples from an array of floats, applying a gain ramp to them.
  19921. @param destChannel the channel within this buffer to add the samples to
  19922. @param destStartSample the start sample within this buffer's channel
  19923. @param source the source data to use
  19924. @param numSamples the number of samples to process
  19925. @param startGain the gain to apply to the first sample (this is multiplied with
  19926. the source samples before they are added to this buffer)
  19927. @param endGain the gain to apply to the final sample. The gain is linearly
  19928. interpolated between the first and last samples.
  19929. */
  19930. void addFromWithRamp (const int destChannel,
  19931. const int destStartSample,
  19932. const float* source,
  19933. int numSamples,
  19934. float startGain,
  19935. float endGain) throw();
  19936. /** Copies samples from another buffer to this one.
  19937. @param destChannel the channel within this buffer to copy the samples to
  19938. @param destStartSample the start sample within this buffer's channel
  19939. @param source the source buffer to read from
  19940. @param sourceChannel the channel within the source buffer to read from
  19941. @param sourceStartSample the offset within the source buffer's channel to start reading samples from
  19942. @param numSamples the number of samples to process
  19943. @see addFrom
  19944. */
  19945. void copyFrom (const int destChannel,
  19946. const int destStartSample,
  19947. const AudioSampleBuffer& source,
  19948. const int sourceChannel,
  19949. const int sourceStartSample,
  19950. int numSamples) throw();
  19951. /** Copies samples from an array of floats into one of the channels.
  19952. @param destChannel the channel within this buffer to copy the samples to
  19953. @param destStartSample the start sample within this buffer's channel
  19954. @param source the source buffer to read from
  19955. @param numSamples the number of samples to process
  19956. @see addFrom
  19957. */
  19958. void copyFrom (const int destChannel,
  19959. const int destStartSample,
  19960. const float* source,
  19961. int numSamples) throw();
  19962. /** Finds the highest and lowest sample values in a given range.
  19963. @param channel the channel to read from
  19964. @param startSample the start sample within the channel
  19965. @param numSamples the number of samples to check
  19966. @param minVal on return, the lowest value that was found
  19967. @param maxVal on return, the highest value that was found
  19968. */
  19969. void findMinMax (const int channel,
  19970. const int startSample,
  19971. int numSamples,
  19972. float& minVal,
  19973. float& maxVal) const throw();
  19974. /** Finds the highest absolute sample value within a region of a channel.
  19975. */
  19976. float getMagnitude (const int channel,
  19977. const int startSample,
  19978. const int numSamples) const throw();
  19979. /** Finds the highest absolute sample value within a region on all channels.
  19980. */
  19981. float getMagnitude (const int startSample,
  19982. const int numSamples) const throw();
  19983. /** Returns the root mean squared level for a region of a channel.
  19984. */
  19985. float getRMSLevel (const int channel,
  19986. const int startSample,
  19987. const int numSamples) const throw();
  19988. /** Fills a section of the buffer using an AudioReader as its source.
  19989. This will convert the reader's fixed- or floating-point data to
  19990. the buffer's floating-point format, and will try to intelligently
  19991. cope with mismatches between the number of channels in the reader
  19992. and the buffer.
  19993. @see writeToAudioWriter
  19994. */
  19995. void readFromAudioReader (AudioFormatReader* reader,
  19996. const int startSample,
  19997. const int numSamples,
  19998. const int readerStartSample,
  19999. const bool useReaderLeftChan,
  20000. const bool useReaderRightChan) throw();
  20001. /** Writes a section of this buffer to an audio writer.
  20002. This saves you having to mess about with channels or floating/fixed
  20003. point conversion.
  20004. @see readFromAudioReader
  20005. */
  20006. void writeToAudioWriter (AudioFormatWriter* writer,
  20007. const int startSample,
  20008. const int numSamples) const throw();
  20009. juce_UseDebuggingNewOperator
  20010. private:
  20011. int numChannels, size, allocatedBytes;
  20012. float* channels [maxNumAudioSampleBufferChannels + 1];
  20013. float* allocatedData;
  20014. };
  20015. #endif // __JUCE_AUDIOSAMPLEBUFFER_JUCEHEADER__
  20016. /********* End of inlined file: juce_AudioSampleBuffer.h *********/
  20017. #endif
  20018. #ifndef __JUCE_IIRFILTER_JUCEHEADER__
  20019. /********* Start of inlined file: juce_IIRFilter.h *********/
  20020. #ifndef __JUCE_IIRFILTER_JUCEHEADER__
  20021. #define __JUCE_IIRFILTER_JUCEHEADER__
  20022. /**
  20023. An IIR filter that can perform low, high, or band-pass filtering on an
  20024. audio signal.
  20025. @see IIRFilterAudioSource
  20026. */
  20027. class JUCE_API IIRFilter
  20028. {
  20029. public:
  20030. /** Creates a filter.
  20031. Initially the filter is inactive, so will have no effect on samples that
  20032. you process with it. Use the appropriate method to turn it into the type
  20033. of filter needed.
  20034. */
  20035. IIRFilter() throw();
  20036. /** Creates a copy of another filter. */
  20037. IIRFilter (const IIRFilter& other) throw();
  20038. /** Destructor. */
  20039. ~IIRFilter() throw();
  20040. /** Resets the filter's processing pipeline, ready to start a new stream of data.
  20041. Note that this clears the processing state, but the type of filter and
  20042. its coefficients aren't changed. To put a filter into an inactive state, use
  20043. the makeInactive() method.
  20044. */
  20045. void reset() throw();
  20046. /** Performs the filter operation on the given set of samples.
  20047. */
  20048. void processSamples (float* const samples,
  20049. const int numSamples) throw();
  20050. /** Sets the filter up to act as a low-pass filter.
  20051. */
  20052. void makeLowPass (const double sampleRate,
  20053. const double frequency) throw();
  20054. /** Sets the filter up to act as a high-pass filter.
  20055. */
  20056. void makeHighPass (const double sampleRate,
  20057. const double frequency) throw();
  20058. /** Sets the filter up to act as a low-pass shelf filter with variable Q and gain.
  20059. The gain is a scale factor that the low frequencies are multiplied by, so values
  20060. greater than 1.0 will boost the low frequencies, values less than 1.0 will
  20061. attenuate them.
  20062. */
  20063. void makeLowShelf (const double sampleRate,
  20064. const double cutOffFrequency,
  20065. const double Q,
  20066. const float gainFactor) throw();
  20067. /** Sets the filter up to act as a high-pass shelf filter with variable Q and gain.
  20068. The gain is a scale factor that the high frequencies are multiplied by, so values
  20069. greater than 1.0 will boost the high frequencies, values less than 1.0 will
  20070. attenuate them.
  20071. */
  20072. void makeHighShelf (const double sampleRate,
  20073. const double cutOffFrequency,
  20074. const double Q,
  20075. const float gainFactor) throw();
  20076. /** Sets the filter up to act as a band pass filter centred around a
  20077. frequency, with a variable Q and gain.
  20078. The gain is a scale factor that the centre frequencies are multiplied by, so
  20079. values greater than 1.0 will boost the centre frequencies, values less than
  20080. 1.0 will attenuate them.
  20081. */
  20082. void makeBandPass (const double sampleRate,
  20083. const double centreFrequency,
  20084. const double Q,
  20085. const float gainFactor) throw();
  20086. /** Clears the filter's coefficients so that it becomes inactive.
  20087. */
  20088. void makeInactive() throw();
  20089. /** Makes this filter duplicate the set-up of another one.
  20090. */
  20091. void copyCoefficientsFrom (const IIRFilter& other) throw();
  20092. juce_UseDebuggingNewOperator
  20093. protected:
  20094. CriticalSection processLock;
  20095. void setCoefficients (double c1, double c2, double c3,
  20096. double c4, double c5, double c6) throw();
  20097. bool active;
  20098. float coefficients[6];
  20099. float x1, x2, y1, y2;
  20100. // (use the copyCoefficientsFrom() method instead of this operator)
  20101. const IIRFilter& operator= (const IIRFilter&);
  20102. };
  20103. #endif // __JUCE_IIRFILTER_JUCEHEADER__
  20104. /********* End of inlined file: juce_IIRFilter.h *********/
  20105. #endif
  20106. #ifndef __JUCE_AUDIOPLAYHEAD_JUCEHEADER__
  20107. /********* Start of inlined file: juce_AudioPlayHead.h *********/
  20108. #ifndef __JUCE_AUDIOPLAYHEAD_JUCEHEADER__
  20109. #define __JUCE_AUDIOPLAYHEAD_JUCEHEADER__
  20110. /**
  20111. A subclass of AudioPlayHead can supply information about the position and
  20112. status of a moving play head during audio playback.
  20113. One of these can be supplied to an AudioProcessor object so that it can find
  20114. out about the position of the audio that it is rendering.
  20115. @see AudioProcessor::setPlayHead, AudioProcessor::getPlayHead
  20116. */
  20117. class JUCE_API AudioPlayHead
  20118. {
  20119. protected:
  20120. AudioPlayHead() {}
  20121. public:
  20122. virtual ~AudioPlayHead() {}
  20123. /** Frame rate types. */
  20124. enum FrameRateType
  20125. {
  20126. fps24 = 0,
  20127. fps25 = 1,
  20128. fps2997 = 2,
  20129. fps30 = 3,
  20130. fps2997drop = 4,
  20131. fps30drop = 5,
  20132. fpsUnknown = 99
  20133. };
  20134. /** This structure is filled-in by the AudioPlayHead::getCurrentPosition() method.
  20135. */
  20136. struct CurrentPositionInfo
  20137. {
  20138. /** The tempo in BPM */
  20139. double bpm;
  20140. /** Time signature numerator, e.g. the 3 of a 3/4 time sig */
  20141. int timeSigNumerator;
  20142. /** Time signature denominator, e.g. the 4 of a 3/4 time sig */
  20143. int timeSigDenominator;
  20144. /** The current play position, in seconds from the start of the edit. */
  20145. double timeInSeconds;
  20146. /** For timecode, the position of the start of the edit, in seconds from 00:00:00:00. */
  20147. double editOriginTime;
  20148. /** The current play position in pulses-per-quarter-note.
  20149. This is the number of quarter notes since the edit start.
  20150. */
  20151. double ppqPosition;
  20152. /** The position of the start of the last bar, in pulses-per-quarter-note.
  20153. This is the number of quarter notes from the start of the edit to the
  20154. start of the current bar.
  20155. Note - this value may be unavailable on some hosts, e.g. Pro-Tools. If
  20156. it's not available, the value will be 0.
  20157. */
  20158. double ppqPositionOfLastBarStart;
  20159. /** The video frame rate, if applicable. */
  20160. FrameRateType frameRate;
  20161. /** True if the transport is currently playing. */
  20162. bool isPlaying;
  20163. /** True if the transport is currently recording.
  20164. (When isRecording is true, then isPlaying will also be true).
  20165. */
  20166. bool isRecording;
  20167. };
  20168. /** Fills-in the given structure with details about the transport's
  20169. position at the start of the current processing block.
  20170. */
  20171. virtual bool getCurrentPosition (CurrentPositionInfo& result) = 0;
  20172. };
  20173. #endif // __JUCE_AUDIOPLAYHEAD_JUCEHEADER__
  20174. /********* End of inlined file: juce_AudioPlayHead.h *********/
  20175. #endif
  20176. #ifndef __JUCE_AUDIOPROCESSOR_JUCEHEADER__
  20177. /********* Start of inlined file: juce_AudioProcessor.h *********/
  20178. #ifndef __JUCE_AUDIOPROCESSOR_JUCEHEADER__
  20179. #define __JUCE_AUDIOPROCESSOR_JUCEHEADER__
  20180. /********* Start of inlined file: juce_AudioProcessorEditor.h *********/
  20181. #ifndef __JUCE_AUDIOPROCESSOREDITOR_JUCEHEADER__
  20182. #define __JUCE_AUDIOPROCESSOREDITOR_JUCEHEADER__
  20183. class AudioProcessor;
  20184. /**
  20185. Base class for the component that acts as the GUI for an AudioProcessor.
  20186. Derive your editor component from this class, and create an instance of it
  20187. by overriding the AudioProcessor::createEditor() method.
  20188. @see AudioProcessor, GenericAudioProcessorEditor
  20189. */
  20190. class JUCE_API AudioProcessorEditor : public Component
  20191. {
  20192. protected:
  20193. /** Creates an editor for the specified processor.
  20194. */
  20195. AudioProcessorEditor (AudioProcessor* const owner);
  20196. public:
  20197. /** Destructor. */
  20198. ~AudioProcessorEditor();
  20199. /** Returns a pointer to the processor that this editor represents. */
  20200. AudioProcessor* getAudioProcessor() const throw() { return owner; }
  20201. private:
  20202. AudioProcessor* const owner;
  20203. };
  20204. #endif // __JUCE_AUDIOPROCESSOREDITOR_JUCEHEADER__
  20205. /********* End of inlined file: juce_AudioProcessorEditor.h *********/
  20206. /********* Start of inlined file: juce_AudioProcessorListener.h *********/
  20207. #ifndef __JUCE_AUDIOPROCESSORLISTENER_JUCEHEADER__
  20208. #define __JUCE_AUDIOPROCESSORLISTENER_JUCEHEADER__
  20209. class AudioProcessor;
  20210. /**
  20211. Base class for listeners that want to know about changes to an AudioProcessor.
  20212. Use AudioProcessor::addListener() to register your listener with an AudioProcessor.
  20213. @see AudioProcessor
  20214. */
  20215. class JUCE_API AudioProcessorListener
  20216. {
  20217. public:
  20218. /** Destructor. */
  20219. virtual ~AudioProcessorListener() {}
  20220. /** Receives a callback when a parameter is changed.
  20221. IMPORTANT NOTE: this will be called synchronously when a parameter changes, and
  20222. many audio processors will change their parameter during their audio callback.
  20223. This means that not only has your handler code got to be completely thread-safe,
  20224. but it's also got to be VERY fast, and avoid blocking. If you need to handle
  20225. this event on your message thread, use this callback to trigger an AsyncUpdater
  20226. or ChangeBroadcaster which you can respond to on the message thread.
  20227. */
  20228. virtual void audioProcessorParameterChanged (AudioProcessor* processor,
  20229. int parameterIndex,
  20230. float newValue) = 0;
  20231. /** Called to indicate that something else in the plugin has changed, like its
  20232. program, number of parameters, etc.
  20233. IMPORTANT NOTE: this will be called synchronously, and many audio processors will
  20234. call it during their audio callback. This means that not only has your handler code
  20235. got to be completely thread-safe, but it's also got to be VERY fast, and avoid
  20236. blocking. If you need to handle this event on your message thread, use this callback
  20237. to trigger an AsyncUpdater or ChangeBroadcaster which you can respond to later on the
  20238. message thread.
  20239. */
  20240. virtual void audioProcessorChanged (AudioProcessor* processor) = 0;
  20241. /** Indicates that a parameter change gesture has started.
  20242. E.g. if the user is dragging a slider, this would be called when they first
  20243. press the mouse button, and audioProcessorParameterChangeGestureEnd would be
  20244. called when they release it.
  20245. IMPORTANT NOTE: this will be called synchronously, and many audio processors will
  20246. call it during their audio callback. This means that not only has your handler code
  20247. got to be completely thread-safe, but it's also got to be VERY fast, and avoid
  20248. blocking. If you need to handle this event on your message thread, use this callback
  20249. to trigger an AsyncUpdater or ChangeBroadcaster which you can respond to later on the
  20250. message thread.
  20251. @see audioProcessorParameterChangeGestureEnd
  20252. */
  20253. virtual void audioProcessorParameterChangeGestureBegin (AudioProcessor* processor,
  20254. int parameterIndex);
  20255. /** Indicates that a parameter change gesture has finished.
  20256. E.g. if the user is dragging a slider, this would be called when they release
  20257. the mouse button.
  20258. IMPORTANT NOTE: this will be called synchronously, and many audio processors will
  20259. call it during their audio callback. This means that not only has your handler code
  20260. got to be completely thread-safe, but it's also got to be VERY fast, and avoid
  20261. blocking. If you need to handle this event on your message thread, use this callback
  20262. to trigger an AsyncUpdater or ChangeBroadcaster which you can respond to later on the
  20263. message thread.
  20264. @see audioPluginParameterChangeGestureStart
  20265. */
  20266. virtual void audioProcessorParameterChangeGestureEnd (AudioProcessor* processor,
  20267. int parameterIndex);
  20268. };
  20269. #endif // __JUCE_AUDIOPROCESSORLISTENER_JUCEHEADER__
  20270. /********* End of inlined file: juce_AudioProcessorListener.h *********/
  20271. /**
  20272. Base class for audio processing filters or plugins.
  20273. This is intended to act as a base class of audio filter that is general enough to
  20274. be wrapped as a VST, AU, RTAS, etc, or used internally.
  20275. It is also used by the plugin hosting code as the wrapper around an instance
  20276. of a loaded plugin.
  20277. Derive your filter class from this base class, and if you're building a plugin,
  20278. you should implement a global function called createPluginFilter() which creates
  20279. and returns a new instance of your subclass.
  20280. */
  20281. class JUCE_API AudioProcessor
  20282. {
  20283. protected:
  20284. /** Constructor.
  20285. You can also do your initialisation tasks in the initialiseFilterInfo()
  20286. call, which will be made after this object has been created.
  20287. */
  20288. AudioProcessor();
  20289. public:
  20290. /** Destructor. */
  20291. virtual ~AudioProcessor();
  20292. /** Returns the name of this processor.
  20293. */
  20294. virtual const String getName() const = 0;
  20295. /** Called before playback starts, to let the filter prepare itself.
  20296. The sample rate is the target sample rate, and will remain constant until
  20297. playback stops.
  20298. The estimatedSamplesPerBlock value is a HINT about the typical number of
  20299. samples that will be processed for each callback, but isn't any kind
  20300. of guarantee. The actual block sizes that the host uses may be different
  20301. each time the callback happens, and may be more or less than this value.
  20302. */
  20303. virtual void prepareToPlay (double sampleRate,
  20304. int estimatedSamplesPerBlock) = 0;
  20305. /** Called after playback has stopped, to let the filter free up any resources it
  20306. no longer needs.
  20307. */
  20308. virtual void releaseResources() = 0;
  20309. /** Renders the next block.
  20310. When this method is called, the buffer contains a number of channels which is
  20311. at least as great as the maximum number of input and output channels that
  20312. this filter is using. It will be filled with the filter's input data and
  20313. should be replaced with the filter's output.
  20314. So for example if your filter has 2 input channels and 4 output channels, then
  20315. the buffer will contain 4 channels, the first two being filled with the
  20316. input data. Your filter should read these, do its processing, and replace
  20317. the contents of all 4 channels with its output.
  20318. Or if your filter has 5 inputs and 2 outputs, the buffer will have 5 channels,
  20319. all filled with data, and your filter should overwrite the first 2 of these
  20320. with its output. But be VERY careful not to write anything to the last 3
  20321. channels, as these might be mapped to memory that the host assumes is read-only!
  20322. Note that if you have more outputs than inputs, then only those channels that
  20323. correspond to an input channel are guaranteed to contain sensible data - e.g.
  20324. in the case of 2 inputs and 4 outputs, the first two channels contain the input,
  20325. but the last two channels may contain garbage, so you should be careful not to
  20326. let this pass through without being overwritten or cleared.
  20327. Also note that the buffer may have more channels than are strictly necessary,
  20328. but your should only read/write from the ones that your filter is supposed to
  20329. be using.
  20330. The number of samples in these buffers is NOT guaranteed to be the same for every
  20331. callback, and may be more or less than the estimated value given to prepareToPlay().
  20332. Your code must be able to cope with variable-sized blocks, or you're going to get
  20333. clicks and crashes!
  20334. If the filter is receiving a midi input, then the midiMessages array will be filled
  20335. with the midi messages for this block. Each message's timestamp will indicate the
  20336. message's time, as a number of samples from the start of the block.
  20337. Any messages left in the midi buffer when this method has finished are assumed to
  20338. be the filter's midi output. This means that your filter should be careful to
  20339. clear any incoming messages from the array if it doesn't want them to be passed-on.
  20340. Be very careful about what you do in this callback - it's going to be called by
  20341. the audio thread, so any kind of interaction with the UI is absolutely
  20342. out of the question. If you change a parameter in here and need to tell your UI to
  20343. update itself, the best way is probably to inherit from a ChangeBroadcaster, let
  20344. the UI components register as listeners, and then call sendChangeMessage() inside the
  20345. processBlock() method to send out an asynchronous message. You could also use
  20346. the AsyncUpdater class in a similar way.
  20347. */
  20348. virtual void processBlock (AudioSampleBuffer& buffer,
  20349. MidiBuffer& midiMessages) = 0;
  20350. /** Returns the current AudioPlayHead object that should be used to find
  20351. out the state and position of the playhead.
  20352. You can call this from your processBlock() method, and use the AudioPlayHead
  20353. object to get the details about the time of the start of the block currently
  20354. being processed.
  20355. If the host hasn't supplied a playhead object, this will return 0.
  20356. */
  20357. AudioPlayHead* getPlayHead() const throw() { return playHead; }
  20358. /** Returns the current sample rate.
  20359. This can be called from your processBlock() method - it's not guaranteed
  20360. to be valid at any other time, and may return 0 if it's unknown.
  20361. */
  20362. double getSampleRate() const throw() { return sampleRate; }
  20363. /** Returns the current typical block size that is being used.
  20364. This can be called from your processBlock() method - it's not guaranteed
  20365. to be valid at any other time.
  20366. Remember it's not the ONLY block size that may be used when calling
  20367. processBlock, it's just the normal one. The actual block sizes used may be
  20368. larger or smaller than this, and will vary between successive calls.
  20369. */
  20370. int getBlockSize() const throw() { return blockSize; }
  20371. /** Returns the number of input channels that the host will be sending the filter.
  20372. If writing a plugin, your JucePluginCharacteristics.h file should specify the
  20373. number of channels that your filter would prefer to have, and this method lets
  20374. you know how many the host is actually using.
  20375. Note that this method is only valid during or after the prepareToPlay()
  20376. method call. Until that point, the number of channels will be unknown.
  20377. */
  20378. int getNumInputChannels() const throw() { return numInputChannels; }
  20379. /** Returns the number of output channels that the host will be sending the filter.
  20380. If writing a plugin, your JucePluginCharacteristics.h file should specify the
  20381. number of channels that your filter would prefer to have, and this method lets
  20382. you know how many the host is actually using.
  20383. Note that this method is only valid during or after the prepareToPlay()
  20384. method call. Until that point, the number of channels will be unknown.
  20385. */
  20386. int getNumOutputChannels() const throw() { return numOutputChannels; }
  20387. /** Returns the name of one of the input channels, as returned by the host.
  20388. The host might not supply very useful names for channels, and this might be
  20389. something like "1", "2", "left", "right", etc.
  20390. */
  20391. virtual const String getInputChannelName (const int channelIndex) const = 0;
  20392. /** Returns the name of one of the output channels, as returned by the host.
  20393. The host might not supply very useful names for channels, and this might be
  20394. something like "1", "2", "left", "right", etc.
  20395. */
  20396. virtual const String getOutputChannelName (const int channelIndex) const = 0;
  20397. /** Returns true if the specified channel is part of a stereo pair with its neighbour. */
  20398. virtual bool isInputChannelStereoPair (int index) const = 0;
  20399. /** Returns true if the specified channel is part of a stereo pair with its neighbour. */
  20400. virtual bool isOutputChannelStereoPair (int index) const = 0;
  20401. /** This returns the number of samples delay that the filter imposes on the audio
  20402. passing through it.
  20403. The host will call this to find the latency - the filter itself should set this value
  20404. by calling setLatencySamples() as soon as it can during its initialisation.
  20405. */
  20406. int getLatencySamples() const throw() { return latencySamples; }
  20407. /** The filter should call this to set the number of samples delay that it introduces.
  20408. The filter should call this as soon as it can during initialisation, and can call it
  20409. later if the value changes.
  20410. */
  20411. void setLatencySamples (const int newLatency);
  20412. /** Returns true if the processor wants midi messages. */
  20413. virtual bool acceptsMidi() const = 0;
  20414. /** Returns true if the processor produces midi messages. */
  20415. virtual bool producesMidi() const = 0;
  20416. /** This returns a critical section that will automatically be locked while the host
  20417. is calling the processBlock() method.
  20418. Use it from your UI or other threads to lock access to variables that are used
  20419. by the process callback, but obviously be careful not to keep it locked for
  20420. too long, because that could cause stuttering playback. If you need to do something
  20421. that'll take a long time and need the processing to stop while it happens, use the
  20422. suspendProcessing() method instead.
  20423. @see suspendProcessing
  20424. */
  20425. const CriticalSection& getCallbackLock() const throw() { return callbackLock; }
  20426. /** Enables and disables the processing callback.
  20427. If you need to do something time-consuming on a thread and would like to make sure
  20428. the audio processing callback doesn't happen until you've finished, use this
  20429. to disable the callback and re-enable it again afterwards.
  20430. E.g.
  20431. @code
  20432. void loadNewPatch()
  20433. {
  20434. suspendProcessing (true);
  20435. ..do something that takes ages..
  20436. suspendProcessing (false);
  20437. }
  20438. @endcode
  20439. If the host tries to make an audio callback while processing is suspended, the
  20440. filter will return an empty buffer, but won't block the audio thread like it would
  20441. do if you use the getCallbackLock() critical section to synchronise access.
  20442. @see getCallbackLock
  20443. */
  20444. void suspendProcessing (const bool shouldBeSuspended);
  20445. /** Returns true if processing is currently suspended.
  20446. @see suspendProcessing
  20447. */
  20448. bool isSuspended() const throw() { return suspended; }
  20449. /** Returns true if the processor is being run in an offline mode for rendering.
  20450. If the processor is being run live on realtime signals, this returns false.
  20451. If the mode is unknown, this will assume it's realtime and return false.
  20452. This value may be unreliable until the prepareToPlay() method has been called,
  20453. and could change each time prepareToPlay() is called.
  20454. @see setNonRealtime()
  20455. */
  20456. bool isNonRealtime() const throw() { return nonRealtime; }
  20457. /** Called by the host to tell this processor whether it's being used in a non-realime
  20458. capacity for offline rendering or bouncing.
  20459. Whatever value is passed-in will be
  20460. */
  20461. void setNonRealtime (const bool isNonRealtime) throw();
  20462. /** Creates the filter's UI.
  20463. This can return 0 if you want a UI-less filter, in which case the host may create
  20464. a generic UI that lets the user twiddle the parameters directly.
  20465. If you do want to pass back a component, the component should be created and set to
  20466. the correct size before returning it.
  20467. Remember not to do anything silly like allowing your filter to keep a pointer to
  20468. the component that gets created - it could be deleted later without any warning, which
  20469. would make your pointer into a dangler. Use the getActiveEditor() method instead.
  20470. The correct way to handle the connection between an editor component and its
  20471. filter is to use something like a ChangeBroadcaster so that the editor can
  20472. register itself as a listener, and be told when a change occurs. This lets them
  20473. safely unregister themselves when they are deleted.
  20474. Here are a few things to bear in mind when writing an editor:
  20475. - Initially there won't be an editor, until the user opens one, or they might
  20476. not open one at all. Your filter mustn't rely on it being there.
  20477. - An editor object may be deleted and a replacement one created again at any time.
  20478. - It's safe to assume that an editor will be deleted before its filter.
  20479. */
  20480. virtual AudioProcessorEditor* createEditor() = 0;
  20481. /** Returns the active editor, if there is one.
  20482. Bear in mind this can return 0, even if an editor has previously been
  20483. opened.
  20484. */
  20485. AudioProcessorEditor* getActiveEditor() const throw() { return activeEditor; }
  20486. /** Returns the active editor, or if there isn't one, it will create one.
  20487. This may call createEditor() internally to create the component.
  20488. */
  20489. AudioProcessorEditor* createEditorIfNeeded();
  20490. /** This must return the correct value immediately after the object has been
  20491. created, and mustn't change the number of parameters later.
  20492. */
  20493. virtual int getNumParameters() = 0;
  20494. /** Returns the name of a particular parameter. */
  20495. virtual const String getParameterName (int parameterIndex) = 0;
  20496. /** Called by the host to find out the value of one of the filter's parameters.
  20497. The host will expect the value returned to be between 0 and 1.0.
  20498. This could be called quite frequently, so try to make your code efficient.
  20499. It's also likely to be called by non-UI threads, so the code in here should
  20500. be thread-aware.
  20501. */
  20502. virtual float getParameter (int parameterIndex) = 0;
  20503. /** Returns the value of a parameter as a text string. */
  20504. virtual const String getParameterText (int parameterIndex) = 0;
  20505. /** The host will call this method to change the value of one of the filter's parameters.
  20506. The host may call this at any time, including during the audio processing
  20507. callback, so the filter has to process this very fast and avoid blocking.
  20508. If you want to set the value of a parameter internally, e.g. from your
  20509. editor component, then don't call this directly - instead, use the
  20510. setParameterNotifyingHost() method, which will also send a message to
  20511. the host telling it about the change. If the message isn't sent, the host
  20512. won't be able to automate your parameters properly.
  20513. The value passed will be between 0 and 1.0.
  20514. */
  20515. virtual void setParameter (int parameterIndex,
  20516. float newValue) = 0;
  20517. /** Your filter can call this when it needs to change one of its parameters.
  20518. This could happen when the editor or some other internal operation changes
  20519. a parameter. This method will call the setParameter() method to change the
  20520. value, and will then send a message to the host telling it about the change.
  20521. Note that to make sure the host correctly handles automation, you should call
  20522. the beginParameterChangeGesture() and endParameterChangeGesture() methods to
  20523. tell the host when the user has started and stopped changing the parameter.
  20524. */
  20525. void setParameterNotifyingHost (int parameterIndex,
  20526. float newValue);
  20527. /** Returns true if the host can automate this parameter.
  20528. By default, this returns true for all parameters.
  20529. */
  20530. virtual bool isParameterAutomatable (int parameterIndex) const;
  20531. /** Sends a signal to the host to tell it that the user is about to start changing this
  20532. parameter.
  20533. This allows the host to know when a parameter is actively being held by the user, and
  20534. it may use this information to help it record automation.
  20535. If you call this, it must be matched by a later call to endParameterChangeGesture().
  20536. */
  20537. void beginParameterChangeGesture (int parameterIndex);
  20538. /** Tells the host that the user has finished changing this parameter.
  20539. This allows the host to know when a parameter is actively being held by the user, and
  20540. it may use this information to help it record automation.
  20541. A call to this method must follow a call to beginParameterChangeGesture().
  20542. */
  20543. void endParameterChangeGesture (int parameterIndex);
  20544. /** The filter can call this when something (apart from a parameter value) has changed.
  20545. It sends a hint to the host that something like the program, number of parameters,
  20546. etc, has changed, and that it should update itself.
  20547. */
  20548. void updateHostDisplay();
  20549. /** Returns the number of preset programs the filter supports.
  20550. The value returned must be valid as soon as this object is created, and
  20551. must not change over its lifetime.
  20552. This value shouldn't be less than 1.
  20553. */
  20554. virtual int getNumPrograms() = 0;
  20555. /** Returns the number of the currently active program.
  20556. */
  20557. virtual int getCurrentProgram() = 0;
  20558. /** Called by the host to change the current program.
  20559. */
  20560. virtual void setCurrentProgram (int index) = 0;
  20561. /** Must return the name of a given program. */
  20562. virtual const String getProgramName (int index) = 0;
  20563. /** Called by the host to rename a program.
  20564. */
  20565. virtual void changeProgramName (int index, const String& newName) = 0;
  20566. /** The host will call this method when it wants to save the filter's internal state.
  20567. This must copy any info about the filter's state into the block of memory provided,
  20568. so that the host can store this and later restore it using setStateInformation().
  20569. Note that there's also a getCurrentProgramStateInformation() method, which only
  20570. stores the current program, not the state of the entire filter.
  20571. See also the helper function copyXmlToBinary() for storing settings as XML.
  20572. @see getCurrentProgramStateInformation
  20573. */
  20574. virtual void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData) = 0;
  20575. /** The host will call this method if it wants to save the state of just the filter's
  20576. current program.
  20577. Unlike getStateInformation, this should only return the current program's state.
  20578. Not all hosts support this, and if you don't implement it, the base class
  20579. method just calls getStateInformation() instead. If you do implement it, be
  20580. sure to also implement getCurrentProgramStateInformation.
  20581. @see getStateInformation, setCurrentProgramStateInformation
  20582. */
  20583. virtual void getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
  20584. /** This must restore the filter's state from a block of data previously created
  20585. using getStateInformation().
  20586. Note that there's also a setCurrentProgramStateInformation() method, which tries
  20587. to restore just the current program, not the state of the entire filter.
  20588. See also the helper function getXmlFromBinary() for loading settings as XML.
  20589. @see setCurrentProgramStateInformation
  20590. */
  20591. virtual void setStateInformation (const void* data, int sizeInBytes) = 0;
  20592. /** The host will call this method if it wants to restore the state of just the filter's
  20593. current program.
  20594. Not all hosts support this, and if you don't implement it, the base class
  20595. method just calls setStateInformation() instead. If you do implement it, be
  20596. sure to also implement getCurrentProgramStateInformation.
  20597. @see setStateInformation, getCurrentProgramStateInformation
  20598. */
  20599. virtual void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  20600. /** Adds a listener that will be called when an aspect of this processor changes. */
  20601. void addListener (AudioProcessorListener* const newListener) throw();
  20602. /** Removes a previously added listener. */
  20603. void removeListener (AudioProcessorListener* const listenerToRemove) throw();
  20604. /** Not for public use - this is called before deleting an editor component. */
  20605. void editorBeingDeleted (AudioProcessorEditor* const editor) throw();
  20606. /** Not for public use - this is called to initialise the processor. */
  20607. void setPlayHead (AudioPlayHead* const newPlayHead) throw();
  20608. /** Not for public use - this is called to initialise the processor before playing. */
  20609. void setPlayConfigDetails (const int numIns, const int numOuts,
  20610. const double sampleRate,
  20611. const int blockSize) throw();
  20612. juce_UseDebuggingNewOperator
  20613. protected:
  20614. /** Helper function that just converts an xml element into a binary blob.
  20615. Use this in your filter's getStateInformation() method if you want to
  20616. store its state as xml.
  20617. Then use getXmlFromBinary() to reverse this operation and retrieve the XML
  20618. from a binary blob.
  20619. */
  20620. static void copyXmlToBinary (const XmlElement& xml,
  20621. JUCE_NAMESPACE::MemoryBlock& destData);
  20622. /** Retrieves an XML element that was stored as binary with the copyXmlToBinary() method.
  20623. This might return 0 if the data's unsuitable or corrupted. Otherwise it will return
  20624. an XmlElement object that the caller must delete when no longer needed.
  20625. */
  20626. static XmlElement* getXmlFromBinary (const void* data,
  20627. const int sizeInBytes);
  20628. /** @internal */
  20629. AudioPlayHead* playHead;
  20630. /** @internal */
  20631. void sendParamChangeMessageToListeners (const int parameterIndex, const float newValue);
  20632. private:
  20633. VoidArray listeners;
  20634. AudioProcessorEditor* activeEditor;
  20635. double sampleRate;
  20636. int blockSize, numInputChannels, numOutputChannels, latencySamples;
  20637. bool suspended, nonRealtime;
  20638. CriticalSection callbackLock, listenerLock;
  20639. #ifdef JUCE_DEBUG
  20640. BitArray changingParams;
  20641. #endif
  20642. AudioProcessor (const AudioProcessor&);
  20643. const AudioProcessor& operator= (const AudioProcessor&);
  20644. };
  20645. #endif // __JUCE_AUDIOPROCESSOR_JUCEHEADER__
  20646. /********* End of inlined file: juce_AudioProcessor.h *********/
  20647. #endif
  20648. #ifndef __JUCE_AUDIOPROCESSOREDITOR_JUCEHEADER__
  20649. #endif
  20650. #ifndef __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
  20651. /********* Start of inlined file: juce_AudioProcessorGraph.h *********/
  20652. #ifndef __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
  20653. #define __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
  20654. /********* Start of inlined file: juce_AudioPluginFormatManager.h *********/
  20655. #ifndef __JUCE_AUDIOPLUGINFORMATMANAGER_JUCEHEADER__
  20656. #define __JUCE_AUDIOPLUGINFORMATMANAGER_JUCEHEADER__
  20657. /********* Start of inlined file: juce_AudioPluginFormat.h *********/
  20658. #ifndef __JUCE_AUDIOPLUGINFORMAT_JUCEHEADER__
  20659. #define __JUCE_AUDIOPLUGINFORMAT_JUCEHEADER__
  20660. /********* Start of inlined file: juce_AudioPluginInstance.h *********/
  20661. #ifndef __JUCE_AUDIOPLUGININSTANCE_JUCEHEADER__
  20662. #define __JUCE_AUDIOPLUGININSTANCE_JUCEHEADER__
  20663. /********* Start of inlined file: juce_PluginDescription.h *********/
  20664. #ifndef __JUCE_PLUGINDESCRIPTION_JUCEHEADER__
  20665. #define __JUCE_PLUGINDESCRIPTION_JUCEHEADER__
  20666. /**
  20667. A small class to represent some facts about a particular type of plugin.
  20668. This class is for storing and managing the details about a plugin without
  20669. actually having to load an instance of it.
  20670. A KnownPluginList contains a list of PluginDescription objects.
  20671. @see KnownPluginList
  20672. */
  20673. class JUCE_API PluginDescription
  20674. {
  20675. public:
  20676. PluginDescription() throw();
  20677. PluginDescription (const PluginDescription& other) throw();
  20678. const PluginDescription& operator= (const PluginDescription& other) throw();
  20679. ~PluginDescription() throw();
  20680. /** The name of the plugin. */
  20681. String name;
  20682. /** The plugin format, e.g. "VST", "AudioUnit", etc.
  20683. */
  20684. String pluginFormatName;
  20685. /** A category, such as "Dynamics", "Reverbs", etc.
  20686. */
  20687. String category;
  20688. /** The manufacturer. */
  20689. String manufacturerName;
  20690. /** The version. This string doesn't have any particular format. */
  20691. String version;
  20692. /** The binary module file containing the plugin. */
  20693. File file;
  20694. /** The last time the plugin file was changed.
  20695. This is handy when scanning for new or changed plugins.
  20696. */
  20697. Time lastFileModTime;
  20698. /** A unique ID for the plugin.
  20699. Note that this might not be unique between formats, e.g. a VST and some
  20700. other format might actually have the same id.
  20701. @see createIdentifierString
  20702. */
  20703. int uid;
  20704. /** True if the plugin identifies itself as a synthesiser. */
  20705. bool isInstrument;
  20706. /** The number of inputs. */
  20707. int numInputChannels;
  20708. /** The number of outputs. */
  20709. int numOutputChannels;
  20710. /** Returns true if the two descriptions refer the the same plugin.
  20711. This isn't quite as simple as them just having the same file (because of
  20712. shell plugins).
  20713. */
  20714. bool isDuplicateOf (const PluginDescription& other) const;
  20715. /** Returns a string that can be saved and used to uniquely identify the
  20716. plugin again.
  20717. This contains less info than the XML encoding, and is independent of the
  20718. plugin's file location, so can be used to store a plugin ID for use
  20719. across different machines.
  20720. */
  20721. const String createIdentifierString() const throw();
  20722. /** Creates an XML object containing these details.
  20723. @see loadFromXml
  20724. */
  20725. XmlElement* createXml() const;
  20726. /** Reloads the info in this structure from an XML record that was previously
  20727. saved with createXML().
  20728. Returns true if the XML was a valid plugin description.
  20729. */
  20730. bool loadFromXml (const XmlElement& xml);
  20731. juce_UseDebuggingNewOperator
  20732. };
  20733. #endif // __JUCE_PLUGINDESCRIPTION_JUCEHEADER__
  20734. /********* End of inlined file: juce_PluginDescription.h *********/
  20735. /**
  20736. Base class for an active instance of a plugin.
  20737. This derives from the AudioProcessor class, and adds some extra functionality
  20738. that helps when wrapping dynamically loaded plugins.
  20739. @see AudioProcessor, AudioPluginFormat
  20740. */
  20741. class JUCE_API AudioPluginInstance : public AudioProcessor
  20742. {
  20743. public:
  20744. /** Destructor.
  20745. Make sure that you delete any UI components that belong to this plugin before
  20746. deleting the plugin.
  20747. */
  20748. virtual ~AudioPluginInstance();
  20749. /** Fills-in the appropriate parts of this plugin description object.
  20750. */
  20751. virtual void fillInPluginDescription (PluginDescription& description) const = 0;
  20752. juce_UseDebuggingNewOperator
  20753. protected:
  20754. AudioPluginInstance();
  20755. AudioPluginInstance (const AudioPluginInstance&);
  20756. const AudioPluginInstance& operator= (const AudioPluginInstance&);
  20757. };
  20758. #endif // __JUCE_AUDIOPLUGININSTANCE_JUCEHEADER__
  20759. /********* End of inlined file: juce_AudioPluginInstance.h *********/
  20760. class PluginDescription;
  20761. /**
  20762. The base class for a type of plugin format, such as VST, AudioUnit, LADSPA, etc.
  20763. Use the static getNumFormats() and getFormat() calls to find the types
  20764. of format that are available.
  20765. */
  20766. class JUCE_API AudioPluginFormat
  20767. {
  20768. public:
  20769. /** Destructor. */
  20770. virtual ~AudioPluginFormat();
  20771. /** Returns the format name.
  20772. E.g. "VST", "AudioUnit", etc.
  20773. */
  20774. virtual const String getName() const = 0;
  20775. /** This tries to create descriptions for all the plugin types available in
  20776. a binary module file.
  20777. The file will be some kind of DLL or bundle.
  20778. Normally there will only be one type returned, but some plugins
  20779. (e.g. VST shells) can use a single DLL to create a set of different plugin
  20780. subtypes, so in that case, each subtype is returned as a separate object.
  20781. */
  20782. virtual void findAllTypesForFile (OwnedArray <PluginDescription>& results,
  20783. const File& file) = 0;
  20784. /** Tries to recreate a type from a previously generated PluginDescription.
  20785. @see PluginDescription::createInstance
  20786. */
  20787. virtual AudioPluginInstance* createInstanceFromDescription (const PluginDescription& desc) = 0;
  20788. /** Should do a quick check to see if this file or directory might be a plugin of
  20789. this format.
  20790. This is for searching for potential files, so it shouldn't actually try to
  20791. load the plugin or do anything time-consuming.
  20792. */
  20793. virtual bool fileMightContainThisPluginType (const File& file) = 0;
  20794. /** Returns the typical places to look for this kind of plugin.
  20795. Note that if this returns no paths, it means that the format can't be scanned-for
  20796. (i.e. it's an internal format that doesn't live in files)
  20797. */
  20798. virtual const FileSearchPath getDefaultLocationsToSearch() = 0;
  20799. juce_UseDebuggingNewOperator
  20800. protected:
  20801. AudioPluginFormat() throw();
  20802. AudioPluginFormat (const AudioPluginFormat&);
  20803. const AudioPluginFormat& operator= (const AudioPluginFormat&);
  20804. };
  20805. #endif // __JUCE_AUDIOPLUGINFORMAT_JUCEHEADER__
  20806. /********* End of inlined file: juce_AudioPluginFormat.h *********/
  20807. /**
  20808. This maintains a list of known AudioPluginFormats.
  20809. @see AudioPluginFormat
  20810. */
  20811. class JUCE_API AudioPluginFormatManager : public DeletedAtShutdown
  20812. {
  20813. public:
  20814. AudioPluginFormatManager() throw();
  20815. /** Destructor. */
  20816. ~AudioPluginFormatManager() throw();
  20817. juce_DeclareSingleton_SingleThreaded (AudioPluginFormatManager, false);
  20818. /** Adds any formats that it knows about, e.g. VST.
  20819. */
  20820. void addDefaultFormats();
  20821. /** Returns the number of types of format that are available.
  20822. Use getFormat() to get one of them.
  20823. */
  20824. int getNumFormats() throw();
  20825. /** Returns one of the available formats.
  20826. @see getNumFormats
  20827. */
  20828. AudioPluginFormat* getFormat (const int index) throw();
  20829. /** Adds a format to the list.
  20830. The object passed in will be owned and deleted by the manager.
  20831. */
  20832. void addFormat (AudioPluginFormat* const format) throw();
  20833. /** Tries to load the type for this description, by trying all the formats
  20834. that this manager knows about.
  20835. The caller is responsible for deleting the object that is returned.
  20836. If it can't load the plugin, it returns 0 and leaves a message in the
  20837. errorMessage string.
  20838. */
  20839. AudioPluginInstance* createPluginInstance (const PluginDescription& description,
  20840. String& errorMessage) const;
  20841. juce_UseDebuggingNewOperator
  20842. private:
  20843. OwnedArray <AudioPluginFormat> formats;
  20844. AudioPluginFormatManager (const AudioPluginFormatManager&);
  20845. const AudioPluginFormatManager& operator= (const AudioPluginFormatManager&);
  20846. };
  20847. #endif // __JUCE_AUDIOPLUGINFORMATMANAGER_JUCEHEADER__
  20848. /********* End of inlined file: juce_AudioPluginFormatManager.h *********/
  20849. /********* Start of inlined file: juce_KnownPluginList.h *********/
  20850. #ifndef __JUCE_KNOWNPLUGINLIST_JUCEHEADER__
  20851. #define __JUCE_KNOWNPLUGINLIST_JUCEHEADER__
  20852. /********* Start of inlined file: juce_PopupMenu.h *********/
  20853. #ifndef __JUCE_POPUPMENU_JUCEHEADER__
  20854. #define __JUCE_POPUPMENU_JUCEHEADER__
  20855. /********* Start of inlined file: juce_PopupMenuCustomComponent.h *********/
  20856. #ifndef __JUCE_POPUPMENUCUSTOMCOMPONENT_JUCEHEADER__
  20857. #define __JUCE_POPUPMENUCUSTOMCOMPONENT_JUCEHEADER__
  20858. /** A user-defined copmonent that can appear inside one of the rows of a popup menu.
  20859. @see PopupMenu::addCustomItem
  20860. */
  20861. class JUCE_API PopupMenuCustomComponent : public Component
  20862. {
  20863. public:
  20864. /** Destructor. */
  20865. ~PopupMenuCustomComponent();
  20866. /** Chooses the size that this component would like to have.
  20867. Note that the size which this method returns isn't necessarily the one that
  20868. the menu will give it, as it will be stretched to fit the other items in
  20869. the menu.
  20870. */
  20871. virtual void getIdealSize (int& idealWidth,
  20872. int& idealHeight) = 0;
  20873. /** Dismisses the menu indicating that this item has been chosen.
  20874. This will cause the menu to exit from its modal state, returning
  20875. this item's id as the result.
  20876. */
  20877. void triggerMenuItem();
  20878. /** Returns true if this item should be highlighted because the mouse is
  20879. over it.
  20880. You can call this method in your paint() method to find out whether
  20881. to draw a highlight.
  20882. */
  20883. bool isItemHighlighted() const throw() { return isHighlighted; }
  20884. protected:
  20885. /** Constructor.
  20886. If isTriggeredAutomatically is true, then the menu will automatically detect
  20887. a click on this component and use that to trigger it. If it's false, then it's
  20888. up to your class to manually trigger the item if it wants to.
  20889. */
  20890. PopupMenuCustomComponent (const bool isTriggeredAutomatically = true);
  20891. private:
  20892. friend class MenuItemInfo;
  20893. friend class MenuItemComponent;
  20894. friend class PopupMenuWindow;
  20895. int refCount_;
  20896. bool isHighlighted, isTriggeredAutomatically;
  20897. PopupMenuCustomComponent (const PopupMenuCustomComponent&);
  20898. const PopupMenuCustomComponent& operator= (const PopupMenuCustomComponent&);
  20899. };
  20900. #endif // __JUCE_POPUPMENUCUSTOMCOMPONENT_JUCEHEADER__
  20901. /********* End of inlined file: juce_PopupMenuCustomComponent.h *********/
  20902. /** Creates and displays a popup-menu.
  20903. To show a popup-menu, you create one of these, add some items to it, then
  20904. call its show() method, which returns the id of the item the user selects.
  20905. E.g. @code
  20906. void MyWidget::mouseDown (const MouseEvent& e)
  20907. {
  20908. PopupMenu m;
  20909. m.addItem (1, "item 1");
  20910. m.addItem (2, "item 2");
  20911. const int result = m.show();
  20912. if (result == 0)
  20913. {
  20914. // user dismissed the menu without picking anything
  20915. }
  20916. else if (result == 1)
  20917. {
  20918. // user picked item 1
  20919. }
  20920. else if (result == 2)
  20921. {
  20922. // user picked item 2
  20923. }
  20924. }
  20925. @endcode
  20926. Submenus are easy too: @code
  20927. void MyWidget::mouseDown (const MouseEvent& e)
  20928. {
  20929. PopupMenu subMenu;
  20930. subMenu.addItem (1, "item 1");
  20931. subMenu.addItem (2, "item 2");
  20932. PopupMenu mainMenu;
  20933. mainMenu.addItem (3, "item 3");
  20934. mainMenu.addSubMenu ("other choices", subMenu);
  20935. const int result = m.show();
  20936. ...etc
  20937. }
  20938. @endcode
  20939. */
  20940. class JUCE_API PopupMenu
  20941. {
  20942. public:
  20943. /** Creates an empty popup menu. */
  20944. PopupMenu() throw();
  20945. /** Creates a copy of another menu. */
  20946. PopupMenu (const PopupMenu& other) throw();
  20947. /** Destructor. */
  20948. ~PopupMenu() throw();
  20949. /** Copies this menu from another one. */
  20950. const PopupMenu& operator= (const PopupMenu& other) throw();
  20951. /** Resets the menu, removing all its items. */
  20952. void clear() throw();
  20953. /** Appends a new text item for this menu to show.
  20954. @param itemResultId the number that will be returned from the show() method
  20955. if the user picks this item. The value should never be
  20956. zero, because that's used to indicate that the user didn't
  20957. select anything.
  20958. @param itemText the text to show.
  20959. @param isActive if false, the item will be shown 'greyed-out' and can't be
  20960. picked
  20961. @param isTicked if true, the item will be shown with a tick next to it
  20962. @param iconToUse if this is non-zero, it should be an image that will be
  20963. displayed to the left of the item. This method will take its
  20964. own copy of the image passed-in, so there's no need to keep
  20965. it hanging around.
  20966. @see addSeparator, addColouredItem, addCustomItem, addSubMenu
  20967. */
  20968. void addItem (const int itemResultId,
  20969. const String& itemText,
  20970. const bool isActive = true,
  20971. const bool isTicked = false,
  20972. const Image* const iconToUse = 0) throw();
  20973. /** Adds an item that represents one of the commands in a command manager object.
  20974. @param commandManager the manager to use to trigger the command and get information
  20975. about it
  20976. @param commandID the ID of the command
  20977. @param displayName if this is non-empty, then this string will be used instead of
  20978. the command's registered name
  20979. */
  20980. void addCommandItem (ApplicationCommandManager* commandManager,
  20981. const int commandID,
  20982. const String& displayName = String::empty) throw();
  20983. /** Appends a text item with a special colour.
  20984. This is the same as addItem(), but specifies a colour to use for the
  20985. text, which will override the default colours that are used by the
  20986. current look-and-feel. See addItem() for a description of the parameters.
  20987. */
  20988. void addColouredItem (const int itemResultId,
  20989. const String& itemText,
  20990. const Colour& itemTextColour,
  20991. const bool isActive = true,
  20992. const bool isTicked = false,
  20993. const Image* const iconToUse = 0) throw();
  20994. /** Appends a custom menu item.
  20995. This will add a user-defined component to use as a menu item. The component
  20996. passed in will be deleted by this menu when it's no longer needed.
  20997. @see PopupMenuCustomComponent
  20998. */
  20999. void addCustomItem (const int itemResultId,
  21000. PopupMenuCustomComponent* const customComponent) throw();
  21001. /** Appends a custom menu item that can't be used to trigger a result.
  21002. This will add a user-defined component to use as a menu item. Unlike the
  21003. addCustomItem() method that takes a PopupMenuCustomComponent, this version
  21004. can't trigger a result from it, so doesn't take a menu ID. It also doesn't
  21005. delete the component when it's finished, so it's the caller's responsibility
  21006. to manage the component that is passed-in.
  21007. if triggerMenuItemAutomaticallyWhenClicked is true, the menu itself will handle
  21008. detection of a mouse-click on your component, and use that to trigger the
  21009. menu ID specified in itemResultId. If this is false, the menu item can't
  21010. be triggered, so itemResultId is not used.
  21011. @see PopupMenuCustomComponent
  21012. */
  21013. void addCustomItem (const int itemResultId,
  21014. Component* customComponent,
  21015. int idealWidth, int idealHeight,
  21016. const bool triggerMenuItemAutomaticallyWhenClicked) throw();
  21017. /** Appends a sub-menu.
  21018. If the menu that's passed in is empty, it will appear as an inactive item.
  21019. */
  21020. void addSubMenu (const String& subMenuName,
  21021. const PopupMenu& subMenu,
  21022. const bool isActive = true,
  21023. Image* const iconToUse = 0) throw();
  21024. /** Appends a separator to the menu, to help break it up into sections.
  21025. The menu class is smart enough not to display separators at the top or bottom
  21026. of the menu, and it will replace mutliple adjacent separators with a single
  21027. one, so your code can be quite free and easy about adding these, and it'll
  21028. always look ok.
  21029. */
  21030. void addSeparator() throw();
  21031. /** Adds a non-clickable text item to the menu.
  21032. This is a bold-font items which can be used as a header to separate the items
  21033. into named groups.
  21034. */
  21035. void addSectionHeader (const String& title) throw();
  21036. /** Returns the number of items that the menu currently contains.
  21037. (This doesn't count separators).
  21038. */
  21039. int getNumItems() const throw();
  21040. /** Returns true if the menu contains a command item that triggers the given command. */
  21041. bool containsCommandItem (const int commandID) const throw();
  21042. /** Returns true if the menu contains any items that can be used. */
  21043. bool containsAnyActiveItems() const throw();
  21044. /** Displays the menu and waits for the user to pick something.
  21045. This will display the menu modally, and return the ID of the item that the
  21046. user picks. If they click somewhere off the menu to get rid of it without
  21047. choosing anything, this will return 0.
  21048. The current location of the mouse will be used as the position to show the
  21049. menu - to explicitly set the menu's position, use showAt() instead. Depending
  21050. on where this point is on the screen, the menu will appear above, below or
  21051. to the side of the point.
  21052. @param itemIdThatMustBeVisible if you set this to the ID of one of the menu items,
  21053. then when the menu first appears, it will make sure
  21054. that this item is visible. So if the menu has too many
  21055. items to fit on the screen, it will be scrolled to a
  21056. position where this item is visible.
  21057. @param minimumWidth a minimum width for the menu, in pixels. It may be wider
  21058. than this if some items are too long to fit.
  21059. @param maximumNumColumns if there are too many items to fit on-screen in a single
  21060. vertical column, the menu may be laid out as a series of
  21061. columns - this is the maximum number allowed. To use the
  21062. default value for this (probably about 7), you can pass
  21063. in zero.
  21064. @param standardItemHeight if this is non-zero, it will be used as the standard
  21065. height for menu items (apart from custom items)
  21066. @see showAt
  21067. */
  21068. int show (const int itemIdThatMustBeVisible = 0,
  21069. const int minimumWidth = 0,
  21070. const int maximumNumColumns = 0,
  21071. const int standardItemHeight = 0);
  21072. /** Displays the menu at a specific location.
  21073. This is the same as show(), but uses a specific location (in global screen
  21074. co-ordinates) rather than the current mouse position.
  21075. Note that the co-ordinates don't specify the top-left of the menu - they
  21076. indicate a point of interest, and the menu will position itself nearby to
  21077. this point, trying to keep it fully on-screen.
  21078. @see show()
  21079. */
  21080. int showAt (const int screenX,
  21081. const int screenY,
  21082. const int itemIdThatMustBeVisible = 0,
  21083. const int minimumWidth = 0,
  21084. const int maximumNumColumns = 0,
  21085. const int standardItemHeight = 0);
  21086. /** Displays the menu as if it's attached to a component such as a button.
  21087. This is similar to showAt(), but will position it next to the given component, e.g.
  21088. so that the menu's edge is aligned with that of the component. This is intended for
  21089. things like buttons that trigger a pop-up menu.
  21090. */
  21091. int showAt (Component* componentToAttachTo,
  21092. const int itemIdThatMustBeVisible = 0,
  21093. const int minimumWidth = 0,
  21094. const int maximumNumColumns = 0,
  21095. const int standardItemHeight = 0);
  21096. /** Closes any menus that are currently open.
  21097. This might be useful if you have a situation where your window is being closed
  21098. by some means other than a user action, and you'd like to make sure that menus
  21099. aren't left hanging around.
  21100. */
  21101. static void JUCE_CALLTYPE dismissAllActiveMenus() throw();
  21102. /** Specifies a look-and-feel for the menu and any sub-menus that it has.
  21103. This can be called before show() if you need a customised menu. Be careful
  21104. not to delete the LookAndFeel object before the menu has been deleted.
  21105. */
  21106. void setLookAndFeel (LookAndFeel* const newLookAndFeel) throw();
  21107. /** A set of colour IDs to use to change the colour of various aspects of the menu.
  21108. These constants can be used either via the LookAndFeel::setColour()
  21109. method for the look and feel that is set for this menu with setLookAndFeel()
  21110. @see setLookAndFeel, LookAndFeel::setColour, LookAndFeel::findColour
  21111. */
  21112. enum ColourIds
  21113. {
  21114. backgroundColourId = 0x1000700, /**< The colour to fill the menu's background with. */
  21115. textColourId = 0x1000600, /**< The colour for normal menu item text, (unless the
  21116. colour is specified when the item is added). */
  21117. headerTextColourId = 0x1000601, /**< The colour for section header item text (see the
  21118. addSectionHeader() method). */
  21119. highlightedBackgroundColourId = 0x1000900, /**< The colour to fill the background of the currently
  21120. highlighted menu item. */
  21121. highlightedTextColourId = 0x1000800, /**< The colour to use for the text of the currently
  21122. highlighted item. */
  21123. };
  21124. /**
  21125. Allows you to iterate through the items in a pop-up menu, and examine
  21126. their properties.
  21127. To use this, just create one and repeatedly call its next() method. When this
  21128. returns true, all the member variables of the iterator are filled-out with
  21129. information describing the menu item. When it returns false, the end of the
  21130. list has been reached.
  21131. */
  21132. class JUCE_API MenuItemIterator
  21133. {
  21134. public:
  21135. /** Creates an iterator that will scan through the items in the specified
  21136. menu.
  21137. Be careful not to add any items to a menu while it is being iterated,
  21138. or things could get out of step.
  21139. */
  21140. MenuItemIterator (const PopupMenu& menu) throw();
  21141. /** Destructor. */
  21142. ~MenuItemIterator() throw();
  21143. /** Returns true if there is another item, and sets up all this object's
  21144. member variables to reflect that item's properties.
  21145. */
  21146. bool next() throw();
  21147. String itemName;
  21148. const PopupMenu* subMenu;
  21149. int itemId;
  21150. bool isSeparator;
  21151. bool isTicked;
  21152. bool isEnabled;
  21153. bool isCustomComponent;
  21154. bool isSectionHeader;
  21155. const Colour* customColour;
  21156. const Image* customImage;
  21157. ApplicationCommandManager* commandManager;
  21158. juce_UseDebuggingNewOperator
  21159. private:
  21160. const PopupMenu& menu;
  21161. int index;
  21162. MenuItemIterator (const MenuItemIterator&);
  21163. const MenuItemIterator& operator= (const MenuItemIterator&);
  21164. };
  21165. juce_UseDebuggingNewOperator
  21166. private:
  21167. friend class PopupMenuWindow;
  21168. friend class MenuItemIterator;
  21169. VoidArray items;
  21170. LookAndFeel* lookAndFeel;
  21171. bool separatorPending;
  21172. void addSeparatorIfPending();
  21173. int showMenu (const int x, const int y, const int w, const int h,
  21174. const int itemIdThatMustBeVisible,
  21175. const int minimumWidth,
  21176. const int maximumNumColumns,
  21177. const int standardItemHeight,
  21178. const bool alignToRectangle,
  21179. Component* const componentAttachedTo) throw();
  21180. friend class MenuBarComponent;
  21181. Component* createMenuComponent (const int x, const int y, const int w, const int h,
  21182. const int itemIdThatMustBeVisible,
  21183. const int minimumWidth,
  21184. const int maximumNumColumns,
  21185. const int standardItemHeight,
  21186. const bool alignToRectangle,
  21187. Component* menuBarComponent,
  21188. ApplicationCommandManager** managerOfChosenCommand,
  21189. Component* const componentAttachedTo) throw();
  21190. };
  21191. #endif // __JUCE_POPUPMENU_JUCEHEADER__
  21192. /********* End of inlined file: juce_PopupMenu.h *********/
  21193. /**
  21194. Manages a list of plugin types.
  21195. This can be easily edited, saved and loaded, and used to create instances of
  21196. the plugin types in it.
  21197. @see PluginListComponent
  21198. */
  21199. class JUCE_API KnownPluginList : public ChangeBroadcaster
  21200. {
  21201. public:
  21202. /** Creates an empty list.
  21203. */
  21204. KnownPluginList();
  21205. /** Destructor. */
  21206. ~KnownPluginList();
  21207. /** Clears the list. */
  21208. void clear();
  21209. /** Returns the number of types currently in the list.
  21210. @see getType
  21211. */
  21212. int getNumTypes() const throw() { return types.size(); }
  21213. /** Returns one of the types.
  21214. @see getNumTypes
  21215. */
  21216. PluginDescription* getType (const int index) const throw() { return types [index]; }
  21217. /** Looks for a type in the list which comes from this file.
  21218. */
  21219. PluginDescription* getTypeForFile (const File& file) const throw();
  21220. /** Looks for a type in the list which matches a plugin type ID.
  21221. The identifierString parameter must have been created by
  21222. PluginDescription::createIdentifierString().
  21223. */
  21224. PluginDescription* getTypeForIdentifierString (const String& identifierString) const throw();
  21225. /** Adds a type manually from its description. */
  21226. bool addType (const PluginDescription& type);
  21227. /** Removes a type. */
  21228. void removeType (const int index) throw();
  21229. /** Looks for all types that can be loaded from a given file, and adds them
  21230. to the list.
  21231. If dontRescanIfAlreadyInList is true, then the file will only be loaded and
  21232. re-tested if it's not already in the list, or if the file's modification
  21233. time has changed since the list was created. If dontRescanIfAlreadyInList is
  21234. false, the file will always be reloaded and tested.
  21235. Returns true if any new types were added, and all the types found in this
  21236. file (even if it was already known and hasn't been re-scanned) get returned
  21237. in the array.
  21238. */
  21239. bool scanAndAddFile (const File& possiblePluginFile,
  21240. const bool dontRescanIfAlreadyInList,
  21241. OwnedArray <PluginDescription>& typesFound);
  21242. /** Returns true if the specified file is already known about and if it
  21243. hasn't been modified since our entry was created.
  21244. */
  21245. bool isListingUpToDate (const File& possiblePluginFile) const throw();
  21246. /** Scans and adds a bunch of files that might have been dragged-and-dropped.
  21247. If any types are found in the files, their descriptions are returned in the array.
  21248. */
  21249. void scanAndAddDragAndDroppedFiles (const StringArray& filenames,
  21250. OwnedArray <PluginDescription>& typesFound);
  21251. /** Sort methods used to change the order of the plugins in the list.
  21252. */
  21253. enum SortMethod
  21254. {
  21255. defaultOrder = 0,
  21256. sortAlphabetically,
  21257. sortByCategory,
  21258. sortByManufacturer,
  21259. sortByFileSystemLocation
  21260. };
  21261. /** Adds all the plugin types to a popup menu so that the user can select one.
  21262. Depending on the sort method, it may add sub-menus for categories,
  21263. manufacturers, etc.
  21264. Use getIndexChosenByMenu() to find out the type that was chosen.
  21265. */
  21266. void addToMenu (PopupMenu& menu,
  21267. const SortMethod sortMethod) const;
  21268. /** Converts a menu item index that has been chosen into its index in this list.
  21269. Returns -1 if it's not an ID that was used.
  21270. @see addToMenu
  21271. */
  21272. int getIndexChosenByMenu (const int menuResultCode) const;
  21273. /** Sorts the list. */
  21274. void sort (const SortMethod method);
  21275. /** Creates some XML that can be used to store the state of this list.
  21276. */
  21277. XmlElement* createXml() const;
  21278. /** Recreates the state of this list from its stored XML format.
  21279. */
  21280. void recreateFromXml (const XmlElement& xml);
  21281. juce_UseDebuggingNewOperator
  21282. private:
  21283. OwnedArray <PluginDescription> types;
  21284. KnownPluginList (const KnownPluginList&);
  21285. const KnownPluginList& operator= (const KnownPluginList&);
  21286. };
  21287. #endif // __JUCE_KNOWNPLUGINLIST_JUCEHEADER__
  21288. /********* End of inlined file: juce_KnownPluginList.h *********/
  21289. /**
  21290. A type of AudioProcessor which plays back a graph of other AudioProcessors.
  21291. Use one of these objects if you want to wire-up a set of AudioProcessors
  21292. and play back the result.
  21293. Processors can be added to the graph as "nodes" using addNode(), and once
  21294. added, you can connect any of their input or output channels to other
  21295. nodes using addConnection().
  21296. To play back a graph through an audio device, you might want to use an
  21297. AudioProcessorPlayer object.
  21298. */
  21299. class JUCE_API AudioProcessorGraph : public AudioProcessor,
  21300. public AsyncUpdater
  21301. {
  21302. public:
  21303. /** Creates an empty graph.
  21304. */
  21305. AudioProcessorGraph();
  21306. /** Destructor.
  21307. Any processor objects that have been added to the graph will also be deleted.
  21308. */
  21309. ~AudioProcessorGraph();
  21310. /** Represents one of the nodes, or processors, in an AudioProcessorGraph.
  21311. To create a node, call AudioProcessorGraph::addNode().
  21312. */
  21313. class Node : public ReferenceCountedObject
  21314. {
  21315. public:
  21316. /** Destructor.
  21317. */
  21318. ~Node();
  21319. /** The ID number assigned to this node.
  21320. This is assigned by the graph that owns it, and can't be changed.
  21321. */
  21322. const uint32 id;
  21323. /** The actual processor object that this node represents.
  21324. */
  21325. AudioProcessor* const processor;
  21326. /** A set of user-definable properties that are associated with this node.
  21327. This can be used to attach values to the node for whatever purpose seems
  21328. useful. For example, you might store an x and y position if your application
  21329. is displaying the nodes on-screen.
  21330. */
  21331. PropertySet properties;
  21332. /** A convenient typedef for referring to a pointer to a node object.
  21333. */
  21334. typedef ReferenceCountedObjectPtr <Node> Ptr;
  21335. juce_UseDebuggingNewOperator
  21336. private:
  21337. friend class AudioProcessorGraph;
  21338. bool isPrepared;
  21339. Node (const uint32 id, AudioProcessor* const processor) throw();
  21340. void prepare (const double sampleRate, const int blockSize, AudioProcessorGraph* const graph);
  21341. void unprepare();
  21342. Node (const Node&);
  21343. const Node& operator= (const Node&);
  21344. };
  21345. /** Represents a connection between two channels of two nodes in an AudioProcessorGraph.
  21346. To create a connection, use AudioProcessorGraph::addConnection().
  21347. */
  21348. struct Connection
  21349. {
  21350. public:
  21351. /** The ID number of the node which is the input source for this connection.
  21352. @see AudioProcessorGraph::getNodeForId
  21353. */
  21354. uint32 sourceNodeId;
  21355. /** The index of the output channel of the source node from which this
  21356. connection takes its data.
  21357. If this value is the special number AudioProcessorGraph::midiChannelIndex, then
  21358. it is referring to the source node's midi output. Otherwise, it is the zero-based
  21359. index of an audio output channel in the source node.
  21360. */
  21361. int sourceChannelIndex;
  21362. /** The ID number of the node which is the destination for this connection.
  21363. @see AudioProcessorGraph::getNodeForId
  21364. */
  21365. uint32 destNodeId;
  21366. /** The index of the input channel of the destination node to which this
  21367. connection delivers its data.
  21368. If this value is the special number AudioProcessorGraph::midiChannelIndex, then
  21369. it is referring to the destination node's midi input. Otherwise, it is the zero-based
  21370. index of an audio input channel in the destination node.
  21371. */
  21372. int destChannelIndex;
  21373. juce_UseDebuggingNewOperator
  21374. private:
  21375. };
  21376. /** Deletes all nodes and connections from this graph.
  21377. Any processor objects in the graph will be deleted.
  21378. */
  21379. void clear();
  21380. /** Returns the number of nodes in the graph. */
  21381. int getNumNodes() const throw() { return nodes.size(); }
  21382. /** Returns a pointer to one of the nodes in the graph.
  21383. This will return 0 if the index is out of range.
  21384. @see getNodeForId
  21385. */
  21386. Node* getNode (const int index) const throw() { return nodes [index]; }
  21387. /** Searches the graph for a node with the given ID number and returns it.
  21388. If no such node was found, this returns 0.
  21389. @see getNode
  21390. */
  21391. Node* getNodeForId (const uint32 nodeId) const throw();
  21392. /** Adds a node to the graph.
  21393. This creates a new node in the graph, for the specified processor. Once you have
  21394. added a processor to the graph, the graph owns it and will delete it later when
  21395. it is no longer needed.
  21396. The optional nodeId parameter lets you specify an ID to use for the node, but
  21397. if the value is already in use, this new node will overwrite the old one.
  21398. If this succeeds, it returns a pointer to the newly-created node.
  21399. */
  21400. Node* addNode (AudioProcessor* const newProcessor,
  21401. uint32 nodeId = 0);
  21402. /** Deletes a node within the graph which has the specified ID.
  21403. This will also delete any connections that are attached to this node.
  21404. */
  21405. bool removeNode (const uint32 nodeId);
  21406. /** Returns the number of connections in the graph. */
  21407. int getNumConnections() const throw() { return connections.size(); }
  21408. /** Returns a pointer to one of the connections in the graph. */
  21409. const Connection* getConnection (const int index) const throw() { return connections [index]; }
  21410. /** Searches for a connection between some specified channels.
  21411. If no such connection is found, this returns 0.
  21412. */
  21413. const Connection* getConnectionBetween (const uint32 sourceNodeId,
  21414. const int sourceChannelIndex,
  21415. const uint32 destNodeId,
  21416. const int destChannelIndex) const throw();
  21417. /** Returns true if there is a connection between any of the channels of
  21418. two specified nodes.
  21419. */
  21420. bool isConnected (const uint32 possibleSourceNodeId,
  21421. const uint32 possibleDestNodeId) const throw();
  21422. /** Returns true if it would be legal to connect the specified points.
  21423. */
  21424. bool canConnect (const uint32 sourceNodeId, const int sourceChannelIndex,
  21425. const uint32 destNodeId, const int destChannelIndex) const throw();
  21426. /** Attempts to connect two specified channels of two nodes.
  21427. If this isn't allowed (e.g. because you're trying to connect a midi channel
  21428. to an audio one or other such nonsense), then it'll return false.
  21429. */
  21430. bool addConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  21431. const uint32 destNodeId, const int destChannelIndex);
  21432. /** Deletes the connection with the specified index.
  21433. Returns true if a connection was actually deleted.
  21434. */
  21435. void removeConnection (const int index);
  21436. /** Deletes any connection between two specified points.
  21437. Returns true if a connection was actually deleted.
  21438. */
  21439. bool removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  21440. const uint32 destNodeId, const int destChannelIndex);
  21441. /** Removes all connections from the specified node.
  21442. */
  21443. bool disconnectNode (const uint32 nodeId);
  21444. /** Performs a sanity checks of all the connections.
  21445. This might be useful if some of the processors are doing things like changing
  21446. their channel counts, which could render some connections obsolete.
  21447. */
  21448. bool removeIllegalConnections();
  21449. /** A special number that represents the midi channel of a node.
  21450. This is used as a channel index value if you want to refer to the midi input
  21451. or output instead of an audio channel.
  21452. */
  21453. static const int midiChannelIndex;
  21454. /** A special type of AudioProcessor that can live inside an AudioProcessorGraph
  21455. in order to use the audio that comes into and out of the graph itself.
  21456. If you create an AudioGraphIOProcessor in "input" mode, it will act as a
  21457. node in the graph which delivers the audio that is coming into the parent
  21458. graph. This allows you to stream the data to other nodes and process the
  21459. incoming audio.
  21460. Likewise, one of these in "output" mode can be sent data which it will add to
  21461. the sum of data being sent to the graph's output.
  21462. @see AudioProcessorGraph
  21463. */
  21464. class AudioGraphIOProcessor : public AudioPluginInstance
  21465. {
  21466. public:
  21467. /** Specifies the mode in which this processor will operate.
  21468. */
  21469. enum IODeviceType
  21470. {
  21471. audioInputNode, /**< In this mode, the processor has output channels
  21472. representing all the audio input channels that are
  21473. coming into its parent audio graph. */
  21474. audioOutputNode, /**< In this mode, the processor has input channels
  21475. representing all the audio output channels that are
  21476. going out of its parent audio graph. */
  21477. midiInputNode, /**< In this mode, the processor has a midi output which
  21478. delivers the same midi data that is arriving at its
  21479. parent graph. */
  21480. midiOutputNode /**< In this mode, the processor has a midi input and
  21481. any data sent to it will be passed out of the parent
  21482. graph. */
  21483. };
  21484. /** Returns the mode of this processor. */
  21485. IODeviceType getType() const throw() { return type; }
  21486. /** Returns the parent graph to which this processor belongs, or 0 if it
  21487. hasn't yet been added to one. */
  21488. AudioProcessorGraph* getParentGraph() const throw() { return graph; }
  21489. /** True if this is an audio or midi input. */
  21490. bool isInput() const throw();
  21491. /** True if this is an audio or midi output. */
  21492. bool isOutput() const throw();
  21493. AudioGraphIOProcessor (const IODeviceType type);
  21494. ~AudioGraphIOProcessor();
  21495. const String getName() const;
  21496. void fillInPluginDescription (PluginDescription& d) const;
  21497. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  21498. void releaseResources();
  21499. void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
  21500. const String getInputChannelName (const int channelIndex) const;
  21501. const String getOutputChannelName (const int channelIndex) const;
  21502. bool isInputChannelStereoPair (int index) const;
  21503. bool isOutputChannelStereoPair (int index) const;
  21504. bool acceptsMidi() const;
  21505. bool producesMidi() const;
  21506. AudioProcessorEditor* createEditor();
  21507. int getNumParameters();
  21508. const String getParameterName (int);
  21509. float getParameter (int);
  21510. const String getParameterText (int);
  21511. void setParameter (int, float);
  21512. int getNumPrograms();
  21513. int getCurrentProgram();
  21514. void setCurrentProgram (int);
  21515. const String getProgramName (int);
  21516. void changeProgramName (int, const String&);
  21517. void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
  21518. void setStateInformation (const void* data, int sizeInBytes);
  21519. /** @internal */
  21520. void setParentGraph (AudioProcessorGraph* const graph) throw();
  21521. juce_UseDebuggingNewOperator
  21522. private:
  21523. const IODeviceType type;
  21524. AudioProcessorGraph* graph;
  21525. AudioGraphIOProcessor (const AudioGraphIOProcessor&);
  21526. const AudioGraphIOProcessor& operator= (const AudioGraphIOProcessor&);
  21527. };
  21528. // AudioProcessor methods:
  21529. const String getName() const;
  21530. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  21531. void releaseResources();
  21532. void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
  21533. const String getInputChannelName (const int channelIndex) const;
  21534. const String getOutputChannelName (const int channelIndex) const;
  21535. bool isInputChannelStereoPair (int index) const;
  21536. bool isOutputChannelStereoPair (int index) const;
  21537. bool acceptsMidi() const;
  21538. bool producesMidi() const;
  21539. AudioProcessorEditor* createEditor() { return 0; }
  21540. int getNumParameters() { return 0; }
  21541. const String getParameterName (int) { return String::empty; }
  21542. float getParameter (int) { return 0; }
  21543. const String getParameterText (int) { return String::empty; }
  21544. void setParameter (int, float) { }
  21545. int getNumPrograms() { return 0; }
  21546. int getCurrentProgram() { return 0; }
  21547. void setCurrentProgram (int) { }
  21548. const String getProgramName (int) { return String::empty; }
  21549. void changeProgramName (int, const String&) { }
  21550. void getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData);
  21551. void setStateInformation (const void* data, int sizeInBytes);
  21552. /** @internal */
  21553. void handleAsyncUpdate();
  21554. juce_UseDebuggingNewOperator
  21555. private:
  21556. ReferenceCountedArray <Node> nodes;
  21557. OwnedArray <Connection> connections;
  21558. int lastNodeId;
  21559. AudioSampleBuffer renderingBuffers;
  21560. OwnedArray <MidiBuffer> midiBuffers;
  21561. CriticalSection renderLock;
  21562. VoidArray renderingOps;
  21563. friend class AudioGraphIOProcessor;
  21564. AudioSampleBuffer* currentAudioInputBuffer;
  21565. AudioSampleBuffer currentAudioOutputBuffer;
  21566. MidiBuffer* currentMidiInputBuffer;
  21567. MidiBuffer currentMidiOutputBuffer;
  21568. void clearRenderingSequence();
  21569. void buildRenderingSequence();
  21570. bool isAnInputTo (const uint32 possibleInputId,
  21571. const uint32 possibleDestinationId,
  21572. const int recursionCheck) const throw();
  21573. AudioProcessorGraph (const AudioProcessorGraph&);
  21574. const AudioProcessorGraph& operator= (const AudioProcessorGraph&);
  21575. };
  21576. #endif // __JUCE_AUDIOPROCESSORGRAPH_JUCEHEADER__
  21577. /********* End of inlined file: juce_AudioProcessorGraph.h *********/
  21578. #endif
  21579. #ifndef __JUCE_AUDIOPROCESSORLISTENER_JUCEHEADER__
  21580. #endif
  21581. #ifndef __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
  21582. /********* Start of inlined file: juce_AudioProcessorPlayer.h *********/
  21583. #ifndef __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
  21584. #define __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
  21585. /********* Start of inlined file: juce_AudioIODevice.h *********/
  21586. #ifndef __JUCE_AUDIOIODEVICE_JUCEHEADER__
  21587. #define __JUCE_AUDIOIODEVICE_JUCEHEADER__
  21588. class AudioIODevice;
  21589. /**
  21590. One of these is passed to an AudioIODevice object to stream the audio data
  21591. in and out.
  21592. The AudioIODevice will repeatedly call this class's audioDeviceIOCallback()
  21593. method on its own high-priority audio thread, when it needs to send or receive
  21594. the next block of data.
  21595. @see AudioIODevice, AudioDeviceManager
  21596. */
  21597. class JUCE_API AudioIODeviceCallback
  21598. {
  21599. public:
  21600. /** Destructor. */
  21601. virtual ~AudioIODeviceCallback() {}
  21602. /** Processes a block of incoming and outgoing audio data.
  21603. The subclass's implementation should use the incoming audio for whatever
  21604. purposes it needs to, and must fill all the output channels with the next
  21605. block of output data before returning.
  21606. The channel data is arranged with the same array indices as the channel name
  21607. array returned by AudioIODevice::getOutputChannelNames(), but those channels
  21608. that aren't specified in AudioIODevice::open() will have a null pointer for their
  21609. associated channel, so remember to check for this.
  21610. @param inputChannelData a set of arrays containing the audio data for each
  21611. incoming channel - this data is valid until the function
  21612. returns. There will be one channel of data for each input
  21613. channel that was enabled when the audio device was opened
  21614. (see AudioIODevice::open())
  21615. @param numInputChannels the number of pointers to channel data in the
  21616. inputChannelData array.
  21617. @param outputChannelData a set of arrays which need to be filled with the data
  21618. that should be sent to each outgoing channel of the device.
  21619. There will be one channel of data for each output channel
  21620. that was enabled when the audio device was opened (see
  21621. AudioIODevice::open())
  21622. The initial contents of the array is undefined, so the
  21623. callback function must fill all the channels with zeros if
  21624. its output is silence. Failing to do this could cause quite
  21625. an unpleasant noise!
  21626. @param numOutputChannels the number of pointers to channel data in the
  21627. outputChannelData array.
  21628. @param numSamples the number of samples in each channel of the input and
  21629. output arrays. The number of samples will depend on the
  21630. audio device's buffer size and will usually remain constant,
  21631. although this isn't guaranteed, so make sure your code can
  21632. cope with reasonable changes in the buffer size from one
  21633. callback to the next.
  21634. */
  21635. virtual void audioDeviceIOCallback (const float** inputChannelData,
  21636. int numInputChannels,
  21637. float** outputChannelData,
  21638. int numOutputChannels,
  21639. int numSamples) = 0;
  21640. /** Called to indicate that the device is about to start calling back.
  21641. This will be called just before the audio callbacks begin, either when this
  21642. callback has just been added to an audio device, or after the device has been
  21643. restarted because of a sample-rate or block-size change.
  21644. You can use this opportunity to find out the sample rate and block size
  21645. that the device is going to use by calling the AudioIODevice::getCurrentSampleRate()
  21646. and AudioIODevice::getCurrentBufferSizeSamples() on the supplied pointer.
  21647. @param device the audio IO device that will be used to drive the callback.
  21648. Note that if you're going to store this this pointer, it is
  21649. only valid until the next time that audioDeviceStopped is called.
  21650. */
  21651. virtual void audioDeviceAboutToStart (AudioIODevice* device) = 0;
  21652. /** Called to indicate that the device has stopped.
  21653. */
  21654. virtual void audioDeviceStopped() = 0;
  21655. };
  21656. /**
  21657. Base class for an audio device with synchronised input and output channels.
  21658. Subclasses of this are used to implement different protocols such as DirectSound,
  21659. ASIO, CoreAudio, etc.
  21660. To create one of these, you'll need to use the AudioIODeviceType class - see the
  21661. documentation for that class for more info.
  21662. For an easier way of managing audio devices and their settings, have a look at the
  21663. AudioDeviceManager class.
  21664. @see AudioIODeviceType, AudioDeviceManager
  21665. */
  21666. class JUCE_API AudioIODevice
  21667. {
  21668. public:
  21669. /** Destructor. */
  21670. virtual ~AudioIODevice();
  21671. /** Returns the device's name, (as set in the constructor). */
  21672. const String& getName() const throw() { return name; }
  21673. /** Returns the type of the device.
  21674. E.g. "CoreAudio", "ASIO", etc. - this comes from the AudioIODeviceType that created it.
  21675. */
  21676. const String& getTypeName() const throw() { return typeName; }
  21677. /** Returns the names of all the available output channels on this device.
  21678. To find out which of these are currently in use, call getActiveOutputChannels().
  21679. */
  21680. virtual const StringArray getOutputChannelNames() = 0;
  21681. /** Returns the names of all the available input channels on this device.
  21682. To find out which of these are currently in use, call getActiveInputChannels().
  21683. */
  21684. virtual const StringArray getInputChannelNames() = 0;
  21685. /** Returns the number of sample-rates this device supports.
  21686. To find out which rates are available on this device, use this method to
  21687. find out how many there are, and getSampleRate() to get the rates.
  21688. @see getSampleRate
  21689. */
  21690. virtual int getNumSampleRates() = 0;
  21691. /** Returns one of the sample-rates this device supports.
  21692. To find out which rates are available on this device, use getNumSampleRates() to
  21693. find out how many there are, and getSampleRate() to get the individual rates.
  21694. The sample rate is set by the open() method.
  21695. (Note that for DirectSound some rates might not work, depending on combinations
  21696. of i/o channels that are being opened).
  21697. @see getNumSampleRates
  21698. */
  21699. virtual double getSampleRate (int index) = 0;
  21700. /** Returns the number of sizes of buffer that are available.
  21701. @see getBufferSizeSamples, getDefaultBufferSize
  21702. */
  21703. virtual int getNumBufferSizesAvailable() = 0;
  21704. /** Returns one of the possible buffer-sizes.
  21705. @param index the index of the buffer-size to use, from 0 to getNumBufferSizesAvailable() - 1
  21706. @returns a number of samples
  21707. @see getNumBufferSizesAvailable, getDefaultBufferSize
  21708. */
  21709. virtual int getBufferSizeSamples (int index) = 0;
  21710. /** Returns the default buffer-size to use.
  21711. @returns a number of samples
  21712. @see getNumBufferSizesAvailable, getBufferSizeSamples
  21713. */
  21714. virtual int getDefaultBufferSize() = 0;
  21715. /** Tries to open the device ready to play.
  21716. @param inputChannels a BitArray in which a set bit indicates that the corresponding
  21717. input channel should be enabled
  21718. @param outputChannels a BitArray in which a set bit indicates that the corresponding
  21719. output channel should be enabled
  21720. @param sampleRate the sample rate to try to use - to find out which rates are
  21721. available, see getNumSampleRates() and getSampleRate()
  21722. @param bufferSizeSamples the size of i/o buffer to use - to find out the available buffer
  21723. sizes, see getNumBufferSizesAvailable() and getBufferSizeSamples()
  21724. @returns an error description if there's a problem, or an empty string if it succeeds in
  21725. opening the device
  21726. @see close
  21727. */
  21728. virtual const String open (const BitArray& inputChannels,
  21729. const BitArray& outputChannels,
  21730. double sampleRate,
  21731. int bufferSizeSamples) = 0;
  21732. /** Closes and releases the device if it's open. */
  21733. virtual void close() = 0;
  21734. /** Returns true if the device is still open.
  21735. A device might spontaneously close itself if something goes wrong, so this checks if
  21736. it's still open.
  21737. */
  21738. virtual bool isOpen() = 0;
  21739. /** Starts the device actually playing.
  21740. This must be called after the device has been opened.
  21741. @param callback the callback to use for streaming the data.
  21742. @see AudioIODeviceCallback, open
  21743. */
  21744. virtual void start (AudioIODeviceCallback* callback) = 0;
  21745. /** Stops the device playing.
  21746. Once a device has been started, this will stop it. Any pending calls to the
  21747. callback class will be flushed before this method returns.
  21748. */
  21749. virtual void stop() = 0;
  21750. /** Returns true if the device is still calling back.
  21751. The device might mysteriously stop, so this checks whether it's
  21752. still playing.
  21753. */
  21754. virtual bool isPlaying() = 0;
  21755. /** Returns the last error that happened if anything went wrong. */
  21756. virtual const String getLastError() = 0;
  21757. /** Returns the buffer size that the device is currently using.
  21758. If the device isn't actually open, this value doesn't really mean much.
  21759. */
  21760. virtual int getCurrentBufferSizeSamples() = 0;
  21761. /** Returns the sample rate that the device is currently using.
  21762. If the device isn't actually open, this value doesn't really mean much.
  21763. */
  21764. virtual double getCurrentSampleRate() = 0;
  21765. /** Returns the device's current physical bit-depth.
  21766. If the device isn't actually open, this value doesn't really mean much.
  21767. */
  21768. virtual int getCurrentBitDepth() = 0;
  21769. /** Returns a mask showing which of the available output channels are currently
  21770. enabled.
  21771. @see getOutputChannelNames
  21772. */
  21773. virtual const BitArray getActiveOutputChannels() const = 0;
  21774. /** Returns a mask showing which of the available input channels are currently
  21775. enabled.
  21776. @see getInputChannelNames
  21777. */
  21778. virtual const BitArray getActiveInputChannels() const = 0;
  21779. /** Returns the device's output latency.
  21780. This is the delay in samples between a callback getting a block of data, and
  21781. that data actually getting played.
  21782. */
  21783. virtual int getOutputLatencyInSamples() = 0;
  21784. /** Returns the device's input latency.
  21785. This is the delay in samples between some audio actually arriving at the soundcard,
  21786. and the callback getting passed this block of data.
  21787. */
  21788. virtual int getInputLatencyInSamples() = 0;
  21789. /** True if this device can show a pop-up control panel for editing its settings.
  21790. This is generally just true of ASIO devices. If true, you can call showControlPanel()
  21791. to display it.
  21792. */
  21793. virtual bool hasControlPanel() const;
  21794. /** Shows a device-specific control panel if there is one.
  21795. This should only be called for devices which return true from hasControlPanel().
  21796. */
  21797. virtual bool showControlPanel();
  21798. protected:
  21799. /** Creates a device, setting its name and type member variables. */
  21800. AudioIODevice (const String& deviceName,
  21801. const String& typeName);
  21802. /** @internal */
  21803. String name, typeName;
  21804. };
  21805. #endif // __JUCE_AUDIOIODEVICE_JUCEHEADER__
  21806. /********* End of inlined file: juce_AudioIODevice.h *********/
  21807. /**
  21808. An AudioIODeviceCallback object which streams audio through an AudioProcessor.
  21809. To use one of these, just make it the callback used by your AudioIODevice, and
  21810. give it a processor to use by calling setProcessor().
  21811. It's also a MidiInputCallback, so you can connect it to both an audio and midi
  21812. input to send both streams through the processor.
  21813. @see AudioProcessor, AudioProcessorGraph
  21814. */
  21815. class JUCE_API AudioProcessorPlayer : public AudioIODeviceCallback,
  21816. public MidiInputCallback
  21817. {
  21818. public:
  21819. /**
  21820. */
  21821. AudioProcessorPlayer();
  21822. /** Destructor. */
  21823. virtual ~AudioProcessorPlayer();
  21824. /** Sets the processor that should be played.
  21825. The processor that is passed in will not be deleted or owned by this object.
  21826. To stop anything playing, pass in 0 to this method.
  21827. */
  21828. void setProcessor (AudioProcessor* const processorToPlay);
  21829. /** Returns the current audio processor that is being played.
  21830. */
  21831. AudioProcessor* getCurrentProcessor() const throw() { return processor; }
  21832. /** Returns a midi message collector that you can pass midi messages to if you
  21833. want them to be injected into the midi stream that is being sent to the
  21834. processor.
  21835. */
  21836. MidiMessageCollector& getMidiMessageCollector() throw() { return messageCollector; }
  21837. /** @internal */
  21838. void audioDeviceIOCallback (const float** inputChannelData,
  21839. int totalNumInputChannels,
  21840. float** outputChannelData,
  21841. int totalNumOutputChannels,
  21842. int numSamples);
  21843. /** @internal */
  21844. void audioDeviceAboutToStart (AudioIODevice* device);
  21845. /** @internal */
  21846. void audioDeviceStopped();
  21847. /** @internal */
  21848. void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
  21849. juce_UseDebuggingNewOperator
  21850. private:
  21851. AudioProcessor* processor;
  21852. CriticalSection lock;
  21853. double sampleRate;
  21854. int blockSize;
  21855. bool isPrepared;
  21856. int numInputChans, numOutputChans;
  21857. float* channels [128];
  21858. AudioSampleBuffer tempBuffer;
  21859. MidiBuffer incomingMidi;
  21860. MidiMessageCollector messageCollector;
  21861. AudioProcessorPlayer (const AudioProcessorPlayer&);
  21862. const AudioProcessorPlayer& operator= (const AudioProcessorPlayer&);
  21863. };
  21864. #endif // __JUCE_AUDIOPROCESSORPLAYER_JUCEHEADER__
  21865. /********* End of inlined file: juce_AudioProcessorPlayer.h *********/
  21866. #endif
  21867. #ifndef __JUCE_GENERICAUDIOPROCESSOREDITOR_JUCEHEADER__
  21868. /********* Start of inlined file: juce_GenericAudioProcessorEditor.h *********/
  21869. #ifndef __JUCE_GENERICAUDIOPROCESSOREDITOR_JUCEHEADER__
  21870. #define __JUCE_GENERICAUDIOPROCESSOREDITOR_JUCEHEADER__
  21871. /********* Start of inlined file: juce_PropertyPanel.h *********/
  21872. #ifndef __JUCE_PROPERTYPANEL_JUCEHEADER__
  21873. #define __JUCE_PROPERTYPANEL_JUCEHEADER__
  21874. /********* Start of inlined file: juce_PropertyComponent.h *********/
  21875. #ifndef __JUCE_PROPERTYCOMPONENT_JUCEHEADER__
  21876. #define __JUCE_PROPERTYCOMPONENT_JUCEHEADER__
  21877. class EditableProperty;
  21878. /**
  21879. A base class for a component that goes in a PropertyPanel and displays one of
  21880. an item's properties.
  21881. Subclasses of this are used to display a property in various forms, e.g. a
  21882. ChoicePropertyComponent shows its value as a combo box; a SliderPropertyComponent
  21883. shows its value as a slider; a TextPropertyComponent as a text box, etc.
  21884. A subclass must implement the refresh() method which will be called to tell the
  21885. component to update itself, and is also responsible for calling this it when the
  21886. item that it refers to is changed.
  21887. @see PropertyPanel, TextPropertyComponent, SliderPropertyComponent,
  21888. ChoicePropertyComponent, ButtonPropertyComponent, BooleanPropertyComponent
  21889. */
  21890. class JUCE_API PropertyComponent : public Component
  21891. {
  21892. public:
  21893. /** Creates a PropertyComponent.
  21894. @param propertyName the name is stored as this component's name, and is
  21895. used as the name displayed next to this component in
  21896. a property panel
  21897. @param preferredHeight the height that the component should be given - some
  21898. items may need to be larger than a normal row height.
  21899. This value can also be set if a subclass changes the
  21900. preferredHeight member variable.
  21901. */
  21902. PropertyComponent (const String& propertyName,
  21903. const int preferredHeight = 25);
  21904. /** Destructor. */
  21905. ~PropertyComponent();
  21906. /** Returns this item's preferred height.
  21907. This value is specified either in the constructor or by a subclass changing the
  21908. preferredHeight member variable.
  21909. */
  21910. int getPreferredHeight() const throw() { return preferredHeight; }
  21911. /** Updates the property component if the item it refers to has changed.
  21912. A subclass must implement this method, and other objects may call it to
  21913. force it to refresh itself.
  21914. The subclass should be economical in the amount of work is done, so for
  21915. example it should check whether it really needs to do a repaint rather than
  21916. just doing one every time this method is called, as it may be called when
  21917. the value being displayed hasn't actually changed.
  21918. */
  21919. virtual void refresh() = 0;
  21920. /** The default paint method fills the background and draws a label for the
  21921. item's name.
  21922. @see LookAndFeel::drawPropertyComponentBackground(), LookAndFeel::drawPropertyComponentLabel()
  21923. */
  21924. void paint (Graphics& g);
  21925. /** The default resize method positions any child component to the right of this
  21926. one, based on the look and feel's default label size.
  21927. */
  21928. void resized();
  21929. /** By default, this just repaints the component. */
  21930. void enablementChanged();
  21931. juce_UseDebuggingNewOperator
  21932. protected:
  21933. /** Used by the PropertyPanel to determine how high this component needs to be.
  21934. A subclass can update this value in its constructor but shouldn't alter it later
  21935. as changes won't necessarily be picked up.
  21936. */
  21937. int preferredHeight;
  21938. };
  21939. #endif // __JUCE_PROPERTYCOMPONENT_JUCEHEADER__
  21940. /********* End of inlined file: juce_PropertyComponent.h *********/
  21941. /********* Start of inlined file: juce_Viewport.h *********/
  21942. #ifndef __JUCE_VIEWPORT_JUCEHEADER__
  21943. #define __JUCE_VIEWPORT_JUCEHEADER__
  21944. /********* Start of inlined file: juce_ScrollBar.h *********/
  21945. #ifndef __JUCE_SCROLLBAR_JUCEHEADER__
  21946. #define __JUCE_SCROLLBAR_JUCEHEADER__
  21947. /********* Start of inlined file: juce_Button.h *********/
  21948. #ifndef __JUCE_BUTTON_JUCEHEADER__
  21949. #define __JUCE_BUTTON_JUCEHEADER__
  21950. /********* Start of inlined file: juce_TooltipWindow.h *********/
  21951. #ifndef __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  21952. #define __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  21953. /********* Start of inlined file: juce_TooltipClient.h *********/
  21954. #ifndef __JUCE_TOOLTIPCLIENT_JUCEHEADER__
  21955. #define __JUCE_TOOLTIPCLIENT_JUCEHEADER__
  21956. /**
  21957. Components that want to use pop-up tooltips should implement this interface.
  21958. A TooltipWindow will wait for the mouse to hover over a component that
  21959. implements the TooltipClient interface, and when it finds one, it will display
  21960. the tooltip returned by its getTooltip() method.
  21961. @see TooltipWindow, SettableTooltipClient
  21962. */
  21963. class JUCE_API TooltipClient
  21964. {
  21965. public:
  21966. /** Destructor. */
  21967. virtual ~TooltipClient() {}
  21968. /** Returns the string that this object wants to show as its tooltip. */
  21969. virtual const String getTooltip() = 0;
  21970. };
  21971. /**
  21972. An implementation of TooltipClient that stores the tooltip string and a method
  21973. for changing it.
  21974. This makes it easy to add a tooltip to a custom component, by simply adding this
  21975. as a base class and calling setTooltip().
  21976. Many of the Juce widgets already use this as a base class to implement their
  21977. tooltips.
  21978. @see TooltipClient, TooltipWindow
  21979. */
  21980. class JUCE_API SettableTooltipClient : public TooltipClient
  21981. {
  21982. public:
  21983. /** Destructor. */
  21984. virtual ~SettableTooltipClient() {}
  21985. virtual void setTooltip (const String& newTooltip) { tooltipString = newTooltip; }
  21986. virtual const String getTooltip() { return tooltipString; }
  21987. juce_UseDebuggingNewOperator
  21988. protected:
  21989. String tooltipString;
  21990. };
  21991. #endif // __JUCE_TOOLTIPCLIENT_JUCEHEADER__
  21992. /********* End of inlined file: juce_TooltipClient.h *********/
  21993. /**
  21994. A window that displays a pop-up tooltip when the mouse hovers over another component.
  21995. To enable tooltips in your app, just create a single instance of a TooltipWindow
  21996. object.
  21997. The TooltipWindow object will then stay invisible, waiting until the mouse
  21998. hovers for the specified length of time - it will then see if it's currently
  21999. over a component which implements the TooltipClient interface, and if so,
  22000. it will make itself visible to show the tooltip in the appropriate place.
  22001. @see TooltipClient, SettableTooltipClient
  22002. */
  22003. class JUCE_API TooltipWindow : public Component,
  22004. private Timer
  22005. {
  22006. public:
  22007. /** Creates a tooltip window.
  22008. Make sure your app only creates one instance of this class, otherwise you'll
  22009. get multiple overlaid tooltips appearing. The window will initially be invisible
  22010. and will make itself visible when it needs to display a tip.
  22011. To change the style of tooltips, see the LookAndFeel class for its tooltip
  22012. methods.
  22013. @param parentComponent if set to 0, the TooltipWindow will appear on the desktop,
  22014. otherwise the tooltip will be added to the given parent
  22015. component.
  22016. @param millisecondsBeforeTipAppears the time for which the mouse has to stay still
  22017. before a tooltip will be shown
  22018. @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize
  22019. */
  22020. TooltipWindow (Component* parentComponent = 0,
  22021. const int millisecondsBeforeTipAppears = 700);
  22022. /** Destructor. */
  22023. ~TooltipWindow();
  22024. /** A set of colour IDs to use to change the colour of various aspects of the tooltip.
  22025. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  22026. methods.
  22027. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  22028. */
  22029. enum ColourIds
  22030. {
  22031. backgroundColourId = 0x1001b00, /**< The colour to fill the background with. */
  22032. textColourId = 0x1001c00, /**< The colour to use for the text. */
  22033. outlineColourId = 0x1001c10 /**< The colour to use to draw an outline around the tooltip. */
  22034. };
  22035. juce_UseDebuggingNewOperator
  22036. private:
  22037. const int millisecondsBeforeTipAppears;
  22038. int mouseX, mouseY, mouseClicks;
  22039. unsigned int lastMouseMoveTime, lastHideTime;
  22040. Component* lastComponentUnderMouse;
  22041. bool changedCompsSinceShown;
  22042. String tip;
  22043. void paint (Graphics& g);
  22044. void mouseEnter (const MouseEvent& e);
  22045. void timerCallback();
  22046. void showFor (Component* const c);
  22047. TooltipWindow (const TooltipWindow&);
  22048. const TooltipWindow& operator= (const TooltipWindow&);
  22049. };
  22050. #endif // __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  22051. /********* End of inlined file: juce_TooltipWindow.h *********/
  22052. class Button;
  22053. /**
  22054. Used to receive callbacks when a button is clicked.
  22055. @see Button::addButtonListener, Button::removeButtonListener
  22056. */
  22057. class JUCE_API ButtonListener
  22058. {
  22059. public:
  22060. /** Destructor. */
  22061. virtual ~ButtonListener() {}
  22062. /** Called when the button is clicked. */
  22063. virtual void buttonClicked (Button* button) = 0;
  22064. /** Called when the button's state changes. */
  22065. virtual void buttonStateChanged (Button*) {}
  22066. };
  22067. /**
  22068. A base class for buttons.
  22069. This contains all the logic for button behaviours such as enabling/disabling,
  22070. responding to shortcut keystrokes, auto-repeating when held down, toggle-buttons
  22071. and radio groups, etc.
  22072. @see TextButton, DrawableButton, ToggleButton
  22073. */
  22074. class JUCE_API Button : public Component,
  22075. public SettableTooltipClient,
  22076. public ApplicationCommandManagerListener,
  22077. private KeyListener
  22078. {
  22079. protected:
  22080. /** Creates a button.
  22081. @param buttonName the text to put in the button (the component's name is also
  22082. initially set to this string, but these can be changed later
  22083. using the setName() and setButtonText() methods)
  22084. */
  22085. Button (const String& buttonName);
  22086. public:
  22087. /** Destructor. */
  22088. virtual ~Button();
  22089. /** Changes the button's text.
  22090. @see getButtonText
  22091. */
  22092. void setButtonText (const String& newText) throw();
  22093. /** Returns the text displayed in the button.
  22094. @see setButtonText
  22095. */
  22096. const String getButtonText() const throw() { return text; }
  22097. /** Returns true if the button is currently being held down by the mouse.
  22098. @see isOver
  22099. */
  22100. bool isDown() const throw();
  22101. /** Returns true if the mouse is currently over the button.
  22102. This will be also be true if the mouse is being held down.
  22103. @see isDown
  22104. */
  22105. bool isOver() const throw();
  22106. /** A button has an on/off state associated with it, and this changes that.
  22107. By default buttons are 'off' and for simple buttons that you click to perform
  22108. an action you won't change this. Toggle buttons, however will want to
  22109. change their state when turned on or off.
  22110. @param shouldBeOn whether to set the button's toggle state to be on or
  22111. off. If it's a member of a button group, this will
  22112. always try to turn it on, and to turn off any other
  22113. buttons in the group
  22114. @param sendChangeNotification if true, a callback will be made to clicked(); if false
  22115. the button will be repainted but no notification will
  22116. be sent
  22117. @see getToggleState, setRadioGroupId
  22118. */
  22119. void setToggleState (const bool shouldBeOn,
  22120. const bool sendChangeNotification);
  22121. /** Returns true if the button in 'on'.
  22122. By default buttons are 'off' and for simple buttons that you click to perform
  22123. an action you won't change this. Toggle buttons, however will want to
  22124. change their state when turned on or off.
  22125. @see setToggleState
  22126. */
  22127. bool getToggleState() const throw() { return isOn; }
  22128. /** This tells the button to automatically flip the toggle state when
  22129. the button is clicked.
  22130. If set to true, then before the clicked() callback occurs, the toggle-state
  22131. of the button is flipped.
  22132. */
  22133. void setClickingTogglesState (const bool shouldToggle) throw();
  22134. /** Returns true if this button is set to be an automatic toggle-button.
  22135. This returns the last value that was passed to setClickingTogglesState().
  22136. */
  22137. bool getClickingTogglesState() const throw();
  22138. /** Enables the button to act as a member of a mutually-exclusive group
  22139. of 'radio buttons'.
  22140. If the group ID is set to a non-zero number, then this button will
  22141. act as part of a group of buttons with the same ID, only one of
  22142. which can be 'on' at the same time. Note that when it's part of
  22143. a group, clicking a toggle-button that's 'on' won't turn it off.
  22144. To find other buttons with the same ID, this button will search through
  22145. its sibling components for ToggleButtons, so all the buttons for a
  22146. particular group must be placed inside the same parent component.
  22147. Set the group ID back to zero if you want it to act as a normal toggle
  22148. button again.
  22149. @see getRadioGroupId
  22150. */
  22151. void setRadioGroupId (const int newGroupId);
  22152. /** Returns the ID of the group to which this button belongs.
  22153. (See setRadioGroupId() for an explanation of this).
  22154. */
  22155. int getRadioGroupId() const throw() { return radioGroupId; }
  22156. /** Registers a listener to receive events when this button's state changes.
  22157. If the listener is already registered, this will not register it again.
  22158. @see removeButtonListener
  22159. */
  22160. void addButtonListener (ButtonListener* const newListener) throw();
  22161. /** Removes a previously-registered button listener
  22162. @see addButtonListener
  22163. */
  22164. void removeButtonListener (ButtonListener* const listener) throw();
  22165. /** Causes the button to act as if it's been clicked.
  22166. This will asynchronously make the button draw itself going down and up, and
  22167. will then call back the clicked() method as if mouse was clicked on it.
  22168. @see clicked
  22169. */
  22170. virtual void triggerClick();
  22171. /** Sets a command ID for this button to automatically invoke when it's clicked.
  22172. When the button is pressed, it will use the given manager to trigger the
  22173. command ID.
  22174. Obviously be careful that the ApplicationCommandManager doesn't get deleted
  22175. before this button is. To disable the command triggering, call this method and
  22176. pass 0 for the parameters.
  22177. If generateTooltip is true, then the button's tooltip will be automatically
  22178. generated based on the name of this command and its current shortcut key.
  22179. @see addShortcut, getCommandID
  22180. */
  22181. void setCommandToTrigger (ApplicationCommandManager* commandManagerToUse,
  22182. const int commandID,
  22183. const bool generateTooltip);
  22184. /** Returns the command ID that was set by setCommandToTrigger().
  22185. */
  22186. int getCommandID() const throw() { return commandID; }
  22187. /** Assigns a shortcut key to trigger the button.
  22188. The button registers itself with its top-level parent component for keypresses.
  22189. Note that a different way of linking buttons to keypresses is by using the
  22190. setKeyPressToTrigger() method to invoke a command - the difference being that
  22191. setting a shortcut allows the button to be temporarily linked to a keypress
  22192. only while it's on-screen.
  22193. @see clearShortcuts
  22194. */
  22195. void addShortcut (const KeyPress& key);
  22196. /** Removes all key shortcuts that had been set for this button.
  22197. @see addShortcut
  22198. */
  22199. void clearShortcuts();
  22200. /** Returns true if the given keypress is a shortcut for this button.
  22201. @see addShortcut
  22202. */
  22203. bool isRegisteredForShortcut (const KeyPress& key) const throw();
  22204. /** Sets an auto-repeat speed for the button when it is held down.
  22205. (Auto-repeat is disabled by default).
  22206. @param initialDelayInMillisecs how long to wait after the mouse is pressed before
  22207. triggering the next click. If this is zero, auto-repeat
  22208. is disabled
  22209. @param repeatDelayInMillisecs the frequently subsequent repeated clicks should be
  22210. triggered
  22211. @param minimumDelayInMillisecs if this is greater than 0, the auto-repeat speed will
  22212. get faster, the longer the button is held down, up to the
  22213. minimum interval specified here
  22214. */
  22215. void setRepeatSpeed (const int initialDelayInMillisecs,
  22216. const int repeatDelayInMillisecs,
  22217. const int minimumDelayInMillisecs = -1) throw();
  22218. /** Sets whether the button click should happen when the mouse is pressed or released.
  22219. By default the button is only considered to have been clicked when the mouse is
  22220. released, but setting this to true will make it call the clicked() method as soon
  22221. as the button is pressed.
  22222. This is useful if the button is being used to show a pop-up menu, as it allows
  22223. the click to be used as a drag onto the menu.
  22224. */
  22225. void setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw();
  22226. /** Returns the number of milliseconds since the last time the button
  22227. went into the 'down' state.
  22228. */
  22229. uint32 getMillisecondsSinceButtonDown() const throw();
  22230. /** (overridden from Component to do special stuff). */
  22231. void setVisible (bool shouldBeVisible);
  22232. /** Sets the tooltip for this button.
  22233. @see TooltipClient, TooltipWindow
  22234. */
  22235. void setTooltip (const String& newTooltip);
  22236. // (implementation of the TooltipClient method)
  22237. const String getTooltip();
  22238. /** A combination of these flags are used by setConnectedEdges().
  22239. */
  22240. enum ConnectedEdgeFlags
  22241. {
  22242. ConnectedOnLeft = 1,
  22243. ConnectedOnRight = 2,
  22244. ConnectedOnTop = 4,
  22245. ConnectedOnBottom = 8
  22246. };
  22247. /** Hints about which edges of the button might be connected to adjoining buttons.
  22248. The value passed in is a bitwise combination of any of the values in the
  22249. ConnectedEdgeFlags enum.
  22250. E.g. if you are placing two buttons adjacent to each other, you could use this to
  22251. indicate which edges are touching, and the LookAndFeel might choose to drawn them
  22252. without rounded corners on the edges that connect. It's only a hint, so the
  22253. LookAndFeel can choose to ignore it if it's not relevent for this type of
  22254. button.
  22255. */
  22256. void setConnectedEdges (const int connectedEdgeFlags) throw();
  22257. /** Returns the set of flags passed into setConnectedEdges(). */
  22258. int getConnectedEdgeFlags() const throw() { return connectedEdgeFlags; }
  22259. /** Indicates whether the button adjoins another one on its left edge.
  22260. @see setConnectedEdges
  22261. */
  22262. bool isConnectedOnLeft() const throw() { return (connectedEdgeFlags & ConnectedOnLeft) != 0; }
  22263. /** Indicates whether the button adjoins another one on its right edge.
  22264. @see setConnectedEdges
  22265. */
  22266. bool isConnectedOnRight() const throw() { return (connectedEdgeFlags & ConnectedOnRight) != 0; }
  22267. /** Indicates whether the button adjoins another one on its top edge.
  22268. @see setConnectedEdges
  22269. */
  22270. bool isConnectedOnTop() const throw() { return (connectedEdgeFlags & ConnectedOnTop) != 0; }
  22271. /** Indicates whether the button adjoins another one on its bottom edge.
  22272. @see setConnectedEdges
  22273. */
  22274. bool isConnectedOnBottom() const throw() { return (connectedEdgeFlags & ConnectedOnBottom) != 0; }
  22275. /** Used by setState(). */
  22276. enum ButtonState
  22277. {
  22278. buttonNormal,
  22279. buttonOver,
  22280. buttonDown
  22281. };
  22282. /** Can be used to force the button into a particular state.
  22283. This only changes the button's appearance, it won't trigger a click, or stop any mouse-clicks
  22284. from happening.
  22285. The state that you set here will only last until it is automatically changed when the mouse
  22286. enters or exits the button, or the mouse-button is pressed or released.
  22287. */
  22288. void setState (const ButtonState newState);
  22289. juce_UseDebuggingNewOperator
  22290. protected:
  22291. /** This method is called when the button has been clicked.
  22292. Subclasses can override this to perform whatever they actions they need
  22293. to do.
  22294. Alternatively, a ButtonListener can be added to the button, and these listeners
  22295. will be called when the click occurs.
  22296. @see triggerClick
  22297. */
  22298. virtual void clicked();
  22299. /** This method is called when the button has been clicked.
  22300. By default it just calls clicked(), but you might want to override it to handle
  22301. things like clicking when a modifier key is pressed, etc.
  22302. @see ModifierKeys
  22303. */
  22304. virtual void clicked (const ModifierKeys& modifiers);
  22305. /** Subclasses should override this to actually paint the button's contents.
  22306. It's better to use this than the paint method, because it gives you information
  22307. about the over/down state of the button.
  22308. @param g the graphics context to use
  22309. @param isMouseOverButton true if the button is either in the 'over' or
  22310. 'down' state
  22311. @param isButtonDown true if the button should be drawn in the 'down' position
  22312. */
  22313. virtual void paintButton (Graphics& g,
  22314. bool isMouseOverButton,
  22315. bool isButtonDown) = 0;
  22316. /** Called when the button's up/down/over state changes.
  22317. Subclasses can override this if they need to do something special when the button
  22318. goes up or down.
  22319. @see isDown, isOver
  22320. */
  22321. virtual void buttonStateChanged();
  22322. /** @internal */
  22323. virtual void internalClickCallback (const ModifierKeys& modifiers);
  22324. /** @internal */
  22325. void handleCommandMessage (int commandId);
  22326. /** @internal */
  22327. void mouseEnter (const MouseEvent& e);
  22328. /** @internal */
  22329. void mouseExit (const MouseEvent& e);
  22330. /** @internal */
  22331. void mouseDown (const MouseEvent& e);
  22332. /** @internal */
  22333. void mouseDrag (const MouseEvent& e);
  22334. /** @internal */
  22335. void mouseUp (const MouseEvent& e);
  22336. /** @internal */
  22337. bool keyPressed (const KeyPress& key);
  22338. /** @internal */
  22339. bool keyPressed (const KeyPress& key, Component* originatingComponent);
  22340. /** @internal */
  22341. bool keyStateChanged (Component* originatingComponent);
  22342. /** @internal */
  22343. void paint (Graphics& g);
  22344. /** @internal */
  22345. void parentHierarchyChanged();
  22346. /** @internal */
  22347. void focusGained (FocusChangeType cause);
  22348. /** @internal */
  22349. void focusLost (FocusChangeType cause);
  22350. /** @internal */
  22351. void enablementChanged();
  22352. /** @internal */
  22353. void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo&);
  22354. /** @internal */
  22355. void applicationCommandListChanged();
  22356. private:
  22357. Array <KeyPress> shortcuts;
  22358. Component* keySource;
  22359. String text;
  22360. SortedSet <void*> buttonListeners;
  22361. friend class InternalButtonRepeatTimer;
  22362. Timer* repeatTimer;
  22363. uint32 buttonPressTime, lastTimeCallbackTime;
  22364. ApplicationCommandManager* commandManagerToUse;
  22365. int autoRepeatDelay, autoRepeatSpeed, autoRepeatMinimumDelay;
  22366. int radioGroupId, commandID, connectedEdgeFlags;
  22367. ButtonState buttonState;
  22368. bool isOn : 1;
  22369. bool clickTogglesState : 1;
  22370. bool needsToRelease : 1;
  22371. bool needsRepainting : 1;
  22372. bool isKeyDown : 1;
  22373. bool triggerOnMouseDown : 1;
  22374. bool generateTooltip : 1;
  22375. void repeatTimerCallback() throw();
  22376. Timer& getRepeatTimer() throw();
  22377. ButtonState updateState (const MouseEvent* const e) throw();
  22378. bool isShortcutPressed() const throw();
  22379. void turnOffOtherButtonsInGroup (const bool sendChangeNotification);
  22380. void flashButtonState() throw();
  22381. void sendClickMessage (const ModifierKeys& modifiers);
  22382. void sendStateMessage();
  22383. Button (const Button&);
  22384. const Button& operator= (const Button&);
  22385. };
  22386. #endif // __JUCE_BUTTON_JUCEHEADER__
  22387. /********* End of inlined file: juce_Button.h *********/
  22388. class ScrollBar;
  22389. /**
  22390. A class for receiving events from a ScrollBar.
  22391. You can register a ScrollBarListener with a ScrollBar using the ScrollBar::addListener()
  22392. method, and it will be called when the bar's position changes.
  22393. @see ScrollBar::addListener, ScrollBar::removeListener
  22394. */
  22395. class JUCE_API ScrollBarListener
  22396. {
  22397. public:
  22398. /** Destructor. */
  22399. virtual ~ScrollBarListener() {}
  22400. /** Called when a ScrollBar is moved.
  22401. @param scrollBarThatHasMoved the bar that has moved
  22402. @param newRangeStart the new range start of this bar
  22403. */
  22404. virtual void scrollBarMoved (ScrollBar* scrollBarThatHasMoved,
  22405. const double newRangeStart) = 0;
  22406. };
  22407. /**
  22408. A scrollbar component.
  22409. To use a scrollbar, set up its total range using the setRangeLimits() method - this
  22410. sets the range of values it can represent. Then you can use setCurrentRange() to
  22411. change the position and size of the scrollbar's 'thumb'.
  22412. Registering a ScrollBarListener with the scrollbar will allow you to find out when
  22413. the user moves it, and you can use the getCurrentRangeStart() to find out where
  22414. they moved it to.
  22415. The scrollbar will adjust its own visibility according to whether its thumb size
  22416. allows it to actually be scrolled.
  22417. For most purposes, it's probably easier to use a ViewportContainer or ListBox
  22418. instead of handling a scrollbar directly.
  22419. @see ScrollBarListener
  22420. */
  22421. class JUCE_API ScrollBar : public Component,
  22422. public AsyncUpdater,
  22423. private Timer
  22424. {
  22425. public:
  22426. /** Creates a Scrollbar.
  22427. @param isVertical whether it should be a vertical or horizontal bar
  22428. @param buttonsAreVisible whether to show the up/down or left/right buttons
  22429. */
  22430. ScrollBar (const bool isVertical,
  22431. const bool buttonsAreVisible = true);
  22432. /** Destructor. */
  22433. ~ScrollBar();
  22434. /** Returns true if the scrollbar is vertical, false if it's horizontal. */
  22435. bool isVertical() const throw() { return vertical; }
  22436. /** Changes the scrollbar's direction.
  22437. You'll also need to resize the bar appropriately - this just changes its internal
  22438. layout.
  22439. @param shouldBeVertical true makes it vertical; false makes it horizontal.
  22440. */
  22441. void setOrientation (const bool shouldBeVertical) throw();
  22442. /** Shows or hides the scrollbar's buttons. */
  22443. void setButtonVisibility (const bool buttonsAreVisible);
  22444. /** Tells the scrollbar whether to make itself invisible when not needed.
  22445. The default behaviour is for a scrollbar to become invisible when the thumb
  22446. fills the whole of its range (i.e. when it can't be moved). Setting this
  22447. value to false forces the bar to always be visible.
  22448. */
  22449. void setAutoHide (const bool shouldHideWhenFullRange);
  22450. /** Sets the minimum and maximum values that the bar will move between.
  22451. The bar's thumb will always be constrained so that the top of the thumb
  22452. will be >= minimum, and the bottom of the thumb <= maximum.
  22453. @see setCurrentRange
  22454. */
  22455. void setRangeLimits (const double minimum,
  22456. const double maximum) throw();
  22457. /** Returns the lower value that the thumb can be set to.
  22458. This is the value set by setRangeLimits().
  22459. */
  22460. double getMinimumRangeLimit() const throw() { return minimum; }
  22461. /** Returns the upper value that the thumb can be set to.
  22462. This is the value set by setRangeLimits().
  22463. */
  22464. double getMaximumRangeLimit() const throw() { return maximum; }
  22465. /** Changes the position of the scrollbar's 'thumb'.
  22466. This sets both the position and size of the thumb - to just set the position without
  22467. changing the size, you can use setCurrentRangeStart().
  22468. If this method call actually changes the scrollbar's position, it will trigger an
  22469. asynchronous call to ScrollBarListener::scrollBarMoved() for all the listeners that
  22470. are registered.
  22471. @param newStart the top (or left) of the thumb, in the range
  22472. getMinimumRangeLimit() <= newStart <= getMaximumRangeLimit(). If the
  22473. value is beyond these limits, it will be clipped.
  22474. @param newSize the size of the thumb, such that
  22475. getMinimumRangeLimit() <= newStart + newSize <= getMaximumRangeLimit(). If the
  22476. size is beyond these limits, it will be clipped.
  22477. @see setCurrentRangeStart, getCurrentRangeStart, getCurrentRangeSize
  22478. */
  22479. void setCurrentRange (double newStart,
  22480. double newSize) throw();
  22481. /** Moves the bar's thumb position.
  22482. This will move the thumb position without changing the thumb size. Note
  22483. that the maximum thumb start position is (getMaximumRangeLimit() - getCurrentRangeSize()).
  22484. If this method call actually changes the scrollbar's position, it will trigger an
  22485. asynchronous call to ScrollBarListener::scrollBarMoved() for all the listeners that
  22486. are registered.
  22487. @see setCurrentRange
  22488. */
  22489. void setCurrentRangeStart (double newStart) throw();
  22490. /** Returns the position of the top of the thumb.
  22491. @see setCurrentRangeStart
  22492. */
  22493. double getCurrentRangeStart() const throw() { return rangeStart; }
  22494. /** Returns the current size of the thumb.
  22495. @see setCurrentRange
  22496. */
  22497. double getCurrentRangeSize() const throw() { return rangeSize; }
  22498. /** Sets the amount by which the up and down buttons will move the bar.
  22499. The value here is in terms of the total range, and is added or subtracted
  22500. from the thumb position when the user clicks an up/down (or left/right) button.
  22501. */
  22502. void setSingleStepSize (const double newSingleStepSize) throw();
  22503. /** Moves the scrollbar by a number of single-steps.
  22504. This will move the bar by a multiple of its single-step interval (as
  22505. specified using the setSingleStepSize() method).
  22506. A positive value here will move the bar down or to the right, a negative
  22507. value moves it up or to the left.
  22508. */
  22509. void moveScrollbarInSteps (const int howManySteps) throw();
  22510. /** Moves the scroll bar up or down in pages.
  22511. This will move the bar by a multiple of its current thumb size, effectively
  22512. doing a page-up or down.
  22513. A positive value here will move the bar down or to the right, a negative
  22514. value moves it up or to the left.
  22515. */
  22516. void moveScrollbarInPages (const int howManyPages) throw();
  22517. /** Scrolls to the top (or left).
  22518. This is the same as calling setCurrentRangeStart (getMinimumRangeLimit());
  22519. */
  22520. void scrollToTop() throw();
  22521. /** Scrolls to the bottom (or right).
  22522. This is the same as calling setCurrentRangeStart (getMaximumRangeLimit() - getCurrentRangeSize());
  22523. */
  22524. void scrollToBottom() throw();
  22525. /** Changes the delay before the up and down buttons autorepeat when they are held
  22526. down.
  22527. For an explanation of what the parameters are for, see Button::setRepeatSpeed().
  22528. @see Button::setRepeatSpeed
  22529. */
  22530. void setButtonRepeatSpeed (const int initialDelayInMillisecs,
  22531. const int repeatDelayInMillisecs,
  22532. const int minimumDelayInMillisecs = -1) throw();
  22533. /** A set of colour IDs to use to change the colour of various aspects of the component.
  22534. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  22535. methods.
  22536. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  22537. */
  22538. enum ColourIds
  22539. {
  22540. backgroundColourId = 0x1000300, /**< The background colour of the scrollbar. */
  22541. thumbColourId = 0x1000400, /**< A base colour to use for the thumb. The look and feel will probably use variations on this colour. */
  22542. trackColourId = 0x1000401 /**< A base colour to use for the slot area of the bar. The look and feel will probably use variations on this colour. */
  22543. };
  22544. /** Registers a listener that will be called when the scrollbar is moved. */
  22545. void addListener (ScrollBarListener* const listener) throw();
  22546. /** Deregisters a previously-registered listener. */
  22547. void removeListener (ScrollBarListener* const listener) throw();
  22548. /** @internal */
  22549. bool keyPressed (const KeyPress& key);
  22550. /** @internal */
  22551. void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  22552. /** @internal */
  22553. void lookAndFeelChanged();
  22554. /** @internal */
  22555. void handleAsyncUpdate();
  22556. /** @internal */
  22557. void mouseDown (const MouseEvent& e);
  22558. /** @internal */
  22559. void mouseDrag (const MouseEvent& e);
  22560. /** @internal */
  22561. void mouseUp (const MouseEvent& e);
  22562. /** @internal */
  22563. void paint (Graphics& g);
  22564. /** @internal */
  22565. void resized();
  22566. juce_UseDebuggingNewOperator
  22567. private:
  22568. double minimum, maximum;
  22569. double rangeStart, rangeSize;
  22570. double singleStepSize, dragStartRange;
  22571. int thumbAreaStart, thumbAreaSize, thumbStart, thumbSize;
  22572. int dragStartMousePos, lastMousePos;
  22573. int initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs;
  22574. bool vertical, isDraggingThumb, alwaysVisible;
  22575. Button* upButton;
  22576. Button* downButton;
  22577. SortedSet <void*> listeners;
  22578. void updateThumbPosition() throw();
  22579. void timerCallback();
  22580. ScrollBar (const ScrollBar&);
  22581. const ScrollBar& operator= (const ScrollBar&);
  22582. };
  22583. #endif // __JUCE_SCROLLBAR_JUCEHEADER__
  22584. /********* End of inlined file: juce_ScrollBar.h *********/
  22585. /**
  22586. A Viewport is used to contain a larger child component, and allows the child
  22587. to be automatically scrolled around.
  22588. To use a Viewport, just create one and set the component that goes inside it
  22589. using the setViewedComponent() method. When the child component changes size,
  22590. the Viewport will adjust its scrollbars accordingly.
  22591. A subclass of the viewport can be created which will receive calls to its
  22592. visibleAreaChanged() method when the subcomponent changes position or size.
  22593. */
  22594. class JUCE_API Viewport : public Component,
  22595. private ComponentListener,
  22596. private ScrollBarListener
  22597. {
  22598. public:
  22599. /** Creates a Viewport.
  22600. The viewport is initially empty - use the setViewedComponent() method to
  22601. add a child component for it to manage.
  22602. */
  22603. Viewport (const String& componentName = String::empty);
  22604. /** Destructor. */
  22605. ~Viewport();
  22606. /** Sets the component that this viewport will contain and scroll around.
  22607. This will add the given component to this Viewport and position it at
  22608. (0, 0).
  22609. (Don't add or remove any child components directly using the normal
  22610. Component::addChildComponent() methods).
  22611. @param newViewedComponent the component to add to this viewport (this pointer
  22612. may be null). The component passed in will be deleted
  22613. by the Viewport when it's no longer needed
  22614. @see getViewedComponent
  22615. */
  22616. void setViewedComponent (Component* const newViewedComponent);
  22617. /** Returns the component that's currently being used inside the Viewport.
  22618. @see setViewedComponent
  22619. */
  22620. Component* getViewedComponent() const throw() { return contentComp; }
  22621. /** Changes the position of the viewed component.
  22622. The inner component will be moved so that the pixel at the top left of
  22623. the viewport will be the pixel at position (xPixelsOffset, yPixelsOffset)
  22624. within the inner component.
  22625. This will update the scrollbars and might cause a call to visibleAreaChanged().
  22626. @see getViewPositionX, getViewPositionY, setViewPositionProportionately
  22627. */
  22628. void setViewPosition (const int xPixelsOffset,
  22629. const int yPixelsOffset);
  22630. /** Changes the view position as a proportion of the distance it can move.
  22631. The values here are from 0.0 to 1.0 - where (0, 0) would put the
  22632. visible area in the top-left, and (1, 1) would put it as far down and
  22633. to the right as it's possible to go whilst keeping the child component
  22634. on-screen.
  22635. */
  22636. void setViewPositionProportionately (const double proportionX,
  22637. const double proportionY);
  22638. /** Returns the position within the child component of the top-left of its visible area.
  22639. @see getViewWidth, setViewPosition
  22640. */
  22641. int getViewPositionX() const throw() { return lastVX; }
  22642. /** Returns the position within the child component of the top-left of its visible area.
  22643. @see getViewHeight, setViewPosition
  22644. */
  22645. int getViewPositionY() const throw() { return lastVY; }
  22646. /** Returns the width of the visible area of the child component.
  22647. This may be less than the width of this Viewport if there's a vertical scrollbar
  22648. or if the child component is itself smaller.
  22649. */
  22650. int getViewWidth() const throw() { return lastVW; }
  22651. /** Returns the height of the visible area of the child component.
  22652. This may be less than the height of this Viewport if there's a horizontal scrollbar
  22653. or if the child component is itself smaller.
  22654. */
  22655. int getViewHeight() const throw() { return lastVH; }
  22656. /** Returns the width available within this component for the contents.
  22657. This will be the width of the viewport component minus the width of a
  22658. vertical scrollbar (if visible).
  22659. */
  22660. int getMaximumVisibleWidth() const throw();
  22661. /** Returns the height available within this component for the contents.
  22662. This will be the height of the viewport component minus the space taken up
  22663. by a horizontal scrollbar (if visible).
  22664. */
  22665. int getMaximumVisibleHeight() const throw();
  22666. /** Callback method that is called when the visible area changes.
  22667. This will be called when the visible area is moved either be scrolling or
  22668. by calls to setViewPosition(), etc.
  22669. */
  22670. virtual void visibleAreaChanged (int visibleX, int visibleY,
  22671. int visibleW, int visibleH);
  22672. /** Turns scrollbars on or off.
  22673. If set to false, the scrollbars won't ever appear. When true (the default)
  22674. they will appear only when needed.
  22675. */
  22676. void setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  22677. const bool showHorizontalScrollbarIfNeeded);
  22678. /** True if the vertical scrollbar is enabled.
  22679. @see setScrollBarsShown
  22680. */
  22681. bool isVerticalScrollBarShown() const throw() { return showVScrollbar; }
  22682. /** True if the horizontal scrollbar is enabled.
  22683. @see setScrollBarsShown
  22684. */
  22685. bool isHorizontalScrollBarShown() const throw() { return showHScrollbar; }
  22686. /** Changes the width of the scrollbars.
  22687. If this isn't specified, the default width from the LookAndFeel class will be used.
  22688. @see LookAndFeel::getDefaultScrollbarWidth
  22689. */
  22690. void setScrollBarThickness (const int thickness);
  22691. /** Returns the thickness of the scrollbars.
  22692. @see setScrollBarThickness
  22693. */
  22694. int getScrollBarThickness() const throw();
  22695. /** Changes the distance that a single-step click on a scrollbar button
  22696. will move the viewport.
  22697. */
  22698. void setSingleStepSizes (const int stepX, const int stepY);
  22699. /** Shows or hides the buttons on any scrollbars that are used.
  22700. @see ScrollBar::setButtonVisibility
  22701. */
  22702. void setScrollBarButtonVisibility (const bool buttonsVisible);
  22703. /** Returns a pointer to the scrollbar component being used.
  22704. Handy if you need to customise the bar somehow.
  22705. */
  22706. ScrollBar* getVerticalScrollBar() const throw() { return verticalScrollBar; }
  22707. /** Returns a pointer to the scrollbar component being used.
  22708. Handy if you need to customise the bar somehow.
  22709. */
  22710. ScrollBar* getHorizontalScrollBar() const throw() { return horizontalScrollBar; }
  22711. juce_UseDebuggingNewOperator
  22712. /** @internal */
  22713. void resized();
  22714. /** @internal */
  22715. void scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart);
  22716. /** @internal */
  22717. void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  22718. /** @internal */
  22719. bool keyPressed (const KeyPress& key);
  22720. /** @internal */
  22721. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  22722. /** @internal */
  22723. bool useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  22724. private:
  22725. Component* contentComp;
  22726. int lastVX, lastVY, lastVW, lastVH;
  22727. int scrollBarThickness;
  22728. int singleStepX, singleStepY;
  22729. bool showHScrollbar, showVScrollbar;
  22730. Component* contentHolder;
  22731. ScrollBar* verticalScrollBar;
  22732. ScrollBar* horizontalScrollBar;
  22733. void updateVisibleRegion();
  22734. Viewport (const Viewport&);
  22735. const Viewport& operator= (const Viewport&);
  22736. };
  22737. #endif // __JUCE_VIEWPORT_JUCEHEADER__
  22738. /********* End of inlined file: juce_Viewport.h *********/
  22739. /**
  22740. A panel that holds a list of PropertyComponent objects.
  22741. This panel displays a list of PropertyComponents, and allows them to be organised
  22742. into collapsible sections.
  22743. To use, simply create one of these and add your properties to it with addProperties()
  22744. or addSection().
  22745. @see PropertyComponent
  22746. */
  22747. class JUCE_API PropertyPanel : public Component
  22748. {
  22749. public:
  22750. /** Creates an empty property panel. */
  22751. PropertyPanel();
  22752. /** Destructor. */
  22753. ~PropertyPanel();
  22754. /** Deletes all property components from the panel.
  22755. */
  22756. void clear();
  22757. /** Adds a set of properties to the panel.
  22758. The components in the list will be owned by this object and will be automatically
  22759. deleted later on when no longer needed.
  22760. These properties are added without them being inside a named section. If you
  22761. want them to be kept together in a collapsible section, use addSection() instead.
  22762. */
  22763. void addProperties (const Array <PropertyComponent*>& newPropertyComponents);
  22764. /** Adds a set of properties to the panel.
  22765. These properties are added at the bottom of the list, under a section heading with
  22766. a plus/minus button that allows it to be opened and closed.
  22767. The components in the list will be owned by this object and will be automatically
  22768. deleted later on when no longer needed.
  22769. To add properies without them being in a section, use addProperties().
  22770. */
  22771. void addSection (const String& sectionTitle,
  22772. const Array <PropertyComponent*>& newPropertyComponents,
  22773. const bool shouldSectionInitiallyBeOpen = true);
  22774. /** Calls the refresh() method of all PropertyComponents in the panel */
  22775. void refreshAll() const;
  22776. /** Returns a list of all the names of sections in the panel.
  22777. These are the sections that have been added with addSection().
  22778. */
  22779. const StringArray getSectionNames() const;
  22780. /** Returns true if the section at this index is currently open.
  22781. The index is from 0 up to the number of items returned by getSectionNames().
  22782. */
  22783. bool isSectionOpen (const int sectionIndex) const;
  22784. /** Opens or closes one of the sections.
  22785. The index is from 0 up to the number of items returned by getSectionNames().
  22786. */
  22787. void setSectionOpen (const int sectionIndex, const bool shouldBeOpen);
  22788. /** Saves the current state of open/closed sections so it can be restored later.
  22789. The caller is responsible for deleting the object that is returned.
  22790. To restore this state, use restoreOpennessState().
  22791. @see restoreOpennessState
  22792. */
  22793. XmlElement* getOpennessState() const;
  22794. /** Restores a previously saved arrangement of open/closed sections.
  22795. This will try to restore a snapshot of the panel's state that was created by
  22796. the getOpennessState() method. If any of the sections named in the original
  22797. XML aren't present, they will be ignored.
  22798. @see getOpennessState
  22799. */
  22800. void restoreOpennessState (const XmlElement& newState);
  22801. /** Sets a message to be displayed when there are no properties in the panel.
  22802. The default message is "nothing selected".
  22803. */
  22804. void setMessageWhenEmpty (const String& newMessage);
  22805. /** Returns the message that is displayed when there are no properties.
  22806. @see setMessageWhenEmpty
  22807. */
  22808. const String& getMessageWhenEmpty() const throw();
  22809. /** @internal */
  22810. void paint (Graphics& g);
  22811. /** @internal */
  22812. void resized();
  22813. juce_UseDebuggingNewOperator
  22814. private:
  22815. Viewport* viewport;
  22816. Component* propertyHolderComponent;
  22817. String messageWhenEmpty;
  22818. void updatePropHolderLayout() const;
  22819. void updatePropHolderLayout (const int width) const;
  22820. };
  22821. #endif // __JUCE_PROPERTYPANEL_JUCEHEADER__
  22822. /********* End of inlined file: juce_PropertyPanel.h *********/
  22823. /**
  22824. A type of UI component that displays the parameters of an AudioProcessor as
  22825. a simple list of sliders.
  22826. This can be used for showing an editor for a processor that doesn't supply
  22827. its own custom editor.
  22828. @see AudioProcessor
  22829. */
  22830. class JUCE_API GenericAudioProcessorEditor : public AudioProcessorEditor
  22831. {
  22832. public:
  22833. GenericAudioProcessorEditor (AudioProcessor* const owner);
  22834. ~GenericAudioProcessorEditor();
  22835. void paint (Graphics& g);
  22836. void resized();
  22837. juce_UseDebuggingNewOperator
  22838. private:
  22839. PropertyPanel* panel;
  22840. };
  22841. #endif // __JUCE_GENERICAUDIOPROCESSOREDITOR_JUCEHEADER__
  22842. /********* End of inlined file: juce_GenericAudioProcessorEditor.h *********/
  22843. #endif
  22844. #ifndef __JUCE_AUDIOFORMATREADERSOURCE_JUCEHEADER__
  22845. /********* Start of inlined file: juce_AudioFormatReaderSource.h *********/
  22846. #ifndef __JUCE_AUDIOFORMATREADERSOURCE_JUCEHEADER__
  22847. #define __JUCE_AUDIOFORMATREADERSOURCE_JUCEHEADER__
  22848. /********* Start of inlined file: juce_PositionableAudioSource.h *********/
  22849. #ifndef __JUCE_POSITIONABLEAUDIOSOURCE_JUCEHEADER__
  22850. #define __JUCE_POSITIONABLEAUDIOSOURCE_JUCEHEADER__
  22851. /********* Start of inlined file: juce_AudioSource.h *********/
  22852. #ifndef __JUCE_AUDIOSOURCE_JUCEHEADER__
  22853. #define __JUCE_AUDIOSOURCE_JUCEHEADER__
  22854. /**
  22855. Used by AudioSource::getNextAudioBlock().
  22856. */
  22857. struct JUCE_API AudioSourceChannelInfo
  22858. {
  22859. /** The destination buffer to fill with audio data.
  22860. When the AudioSource::getNextAudioBlock() method is called, the active section
  22861. of this buffer should be filled with whatever output the source produces.
  22862. Only the samples specified by the startSample and numSamples members of this structure
  22863. should be affected by the call.
  22864. The contents of the buffer when it is passed to the the AudioSource::getNextAudioBlock()
  22865. method can be treated as the input if the source is performing some kind of filter operation,
  22866. but should be cleared if this is not the case - the clearActiveBufferRegion() is
  22867. a handy way of doing this.
  22868. The number of channels in the buffer could be anything, so the AudioSource
  22869. must cope with this in whatever way is appropriate for its function.
  22870. */
  22871. AudioSampleBuffer* buffer;
  22872. /** The first sample in the buffer from which the callback is expected
  22873. to write data. */
  22874. int startSample;
  22875. /** The number of samples in the buffer which the callback is expected to
  22876. fill with data. */
  22877. int numSamples;
  22878. /** Convenient method to clear the buffer if the source is not producing any data. */
  22879. void clearActiveBufferRegion() const
  22880. {
  22881. if (buffer != 0)
  22882. buffer->clear (startSample, numSamples);
  22883. }
  22884. };
  22885. /**
  22886. Base class for objects that can produce a continuous stream of audio.
  22887. @see AudioFormatReaderSource, ResamplingAudioSource
  22888. */
  22889. class JUCE_API AudioSource
  22890. {
  22891. protected:
  22892. /** Creates an AudioSource. */
  22893. AudioSource() throw() {}
  22894. public:
  22895. /** Destructor. */
  22896. virtual ~AudioSource() {}
  22897. /** Tells the source to prepare for playing.
  22898. The source can use this opportunity to initialise anything it needs to.
  22899. Note that this method could be called more than once in succession without
  22900. a matching call to releaseResources(), so make sure your code is robust and
  22901. can handle that kind of situation.
  22902. @param samplesPerBlockExpected the number of samples that the source
  22903. will be expected to supply each time its
  22904. getNextAudioBlock() method is called. This
  22905. number may vary slightly, because it will be dependent
  22906. on audio hardware callbacks, and these aren't
  22907. guaranteed to always use a constant block size, so
  22908. the source should be able to cope with small variations.
  22909. @param sampleRate the sample rate that the output will be used at - this
  22910. is needed by sources such as tone generators.
  22911. @see releaseResources, getNextAudioBlock
  22912. */
  22913. virtual void prepareToPlay (int samplesPerBlockExpected,
  22914. double sampleRate) = 0;
  22915. /** Allows the source to release anything it no longer needs after playback has stopped.
  22916. This will be called when the source is no longer going to have its getNextAudioBlock()
  22917. method called, so it should release any spare memory, etc. that it might have
  22918. allocated during the prepareToPlay() call.
  22919. Note that there's no guarantee that prepareToPlay() will actually have been called before
  22920. releaseResources(), and it may be called more than once in succession, so make sure your
  22921. code is robust and doesn't make any assumptions about when it will be called.
  22922. @see prepareToPlay, getNextAudioBlock
  22923. */
  22924. virtual void releaseResources() = 0;
  22925. /** Called repeatedly to fetch subsequent blocks of audio data.
  22926. After calling the prepareToPlay() method, this callback will be made each
  22927. time the audio playback hardware (or whatever other destination the audio
  22928. data is going to) needs another block of data.
  22929. It will generally be called on a high-priority system thread, or possibly even
  22930. an interrupt, so be careful not to do too much work here, as that will cause
  22931. audio glitches!
  22932. @see AudioSourceChannelInfo, prepareToPlay, releaseResources
  22933. */
  22934. virtual void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) = 0;
  22935. };
  22936. #endif // __JUCE_AUDIOSOURCE_JUCEHEADER__
  22937. /********* End of inlined file: juce_AudioSource.h *********/
  22938. /**
  22939. A type of AudioSource which can be repositioned.
  22940. The basic AudioSource just streams continuously with no idea of a current
  22941. time or length, so the PositionableAudioSource is used for a finite stream
  22942. that has a current read position.
  22943. @see AudioSource, AudioTransportSource
  22944. */
  22945. class JUCE_API PositionableAudioSource : public AudioSource
  22946. {
  22947. protected:
  22948. /** Creates the PositionableAudioSource. */
  22949. PositionableAudioSource() throw() {}
  22950. public:
  22951. /** Destructor */
  22952. ~PositionableAudioSource() {}
  22953. /** Tells the stream to move to a new position.
  22954. Calling this indicates that the next call to AudioSource::getNextAudioBlock()
  22955. should return samples from this position.
  22956. Note that this may be called on a different thread to getNextAudioBlock(),
  22957. so the subclass should make sure it's synchronised.
  22958. */
  22959. virtual void setNextReadPosition (int newPosition) = 0;
  22960. /** Returns the position from which the next block will be returned.
  22961. @see setNextReadPosition
  22962. */
  22963. virtual int getNextReadPosition() const = 0;
  22964. /** Returns the total length of the stream (in samples). */
  22965. virtual int getTotalLength() const = 0;
  22966. /** Returns true if this source is actually playing in a loop. */
  22967. virtual bool isLooping() const = 0;
  22968. };
  22969. #endif // __JUCE_POSITIONABLEAUDIOSOURCE_JUCEHEADER__
  22970. /********* End of inlined file: juce_PositionableAudioSource.h *********/
  22971. /********* Start of inlined file: juce_AudioFormatReader.h *********/
  22972. #ifndef __JUCE_AUDIOFORMATREADER_JUCEHEADER__
  22973. #define __JUCE_AUDIOFORMATREADER_JUCEHEADER__
  22974. class AudioFormat;
  22975. /**
  22976. Reads samples from an audio file stream.
  22977. A subclass that reads a specific type of audio format will be created by
  22978. an AudioFormat object.
  22979. @see AudioFormat, AudioFormatWriter
  22980. */
  22981. class JUCE_API AudioFormatReader
  22982. {
  22983. protected:
  22984. /** Creates an AudioFormatReader object.
  22985. @param sourceStream the stream to read from - this will be deleted
  22986. by this object when it is no longer needed. (Some
  22987. specialised readers might not use this parameter and
  22988. can leave it as 0).
  22989. @param formatName the description that will be returned by the getFormatName()
  22990. method
  22991. */
  22992. AudioFormatReader (InputStream* const sourceStream,
  22993. const String& formatName);
  22994. public:
  22995. /** Destructor. */
  22996. virtual ~AudioFormatReader();
  22997. /** Returns a description of what type of format this is.
  22998. E.g. "AIFF"
  22999. */
  23000. const String getFormatName() const throw() { return formatName; }
  23001. /** Reads samples from the stream.
  23002. @param destSamples an array of buffers into which the sample data for each
  23003. channel will be written.
  23004. If the format is fixed-point, each channel will be written
  23005. as an array of 32-bit signed integers using the full
  23006. range -0x80000000 to 0x7fffffff, regardless of the source's
  23007. bit-depth. If it is a floating-point format, you should cast
  23008. the resulting array to a (float**) to get the values (in the
  23009. range -1.0 to 1.0 or beyond)
  23010. If the format is stereo, then destSamples[0] is the left channel
  23011. data, and destSamples[1] is the right channel.
  23012. The array passed in should be zero-terminated, and it's ok to
  23013. pass in an array with a different number of channels than
  23014. the number in the stream, so if you pass in an array with only
  23015. one channel and the stream is stereo, the reader will
  23016. put a merged sum of the stereo channels into the single
  23017. destination channel.
  23018. @param startSample the offset into the audio stream from which the samples
  23019. should be read, as a number of samples from the start of the
  23020. stream. It's ok for this to be beyond the start or end of the
  23021. available data - any samples that can't be read will be padded
  23022. with zeros.
  23023. @param numSamples the number of samples to read. If this is greater than the
  23024. number of samples available, the result will be padded with
  23025. zeros
  23026. @returns true if the operation succeeded, false if there was an error. Note
  23027. that reading sections of data beyond the extent of the stream isn't an
  23028. error - the reader should just return zeros for these regions
  23029. @see readMaxLevels
  23030. */
  23031. virtual bool read (int** destSamples,
  23032. int64 startSample,
  23033. int numSamples) = 0;
  23034. /** Finds the highest and lowest sample levels from a section of the audio stream.
  23035. This will read a block of samples from the stream, and measure the
  23036. highest and lowest sample levels from the channels in that section, returning
  23037. these as normalised floating-point levels.
  23038. @param startSample the offset into the audio stream to start reading from. It's
  23039. ok for this to be beyond the start or end of the stream.
  23040. @param numSamples how many samples to read
  23041. @param lowestLeft on return, this is the lowest absolute sample from the left channel
  23042. @param highestLeft on return, this is the highest absolute sample from the left channel
  23043. @param lowestRight on return, this is the lowest absolute sample from the right
  23044. channel (if there is one)
  23045. @param highestRight on return, this is the highest absolute sample from the right
  23046. channel (if there is one)
  23047. @see read
  23048. */
  23049. virtual void readMaxLevels (int64 startSample,
  23050. int64 numSamples,
  23051. float& lowestLeft,
  23052. float& highestLeft,
  23053. float& lowestRight,
  23054. float& highestRight);
  23055. /** Scans the source looking for a sample whose magnitude is in a specified range.
  23056. This will read from the source, either forwards or backwards between two sample
  23057. positions, until it finds a sample whose magnitude lies between two specified levels.
  23058. If it finds a suitable sample, it returns its position; if not, it will return -1.
  23059. There's also a minimumConsecutiveSamples setting to help avoid spikes or zero-crossing
  23060. points when you're searching for a continuous range of samples
  23061. @param startSample the first sample to look at
  23062. @param numSamplesToSearch the number of samples to scan. If this value is negative,
  23063. the search will go backwards
  23064. @param magnitudeRangeMinimum the lowest magnitude (inclusive) that is considered a hit, from 0 to 1.0
  23065. @param magnitudeRangeMaximum the highest magnitude (inclusive) that is considered a hit, from 0 to 1.0
  23066. @param minimumConsecutiveSamples if this is > 0, the method will only look for a sequence
  23067. of this many consecutive samples, all of which lie
  23068. within the target range. When it finds such a sequence,
  23069. it returns the position of the first in-range sample
  23070. it found (i.e. the earliest one if scanning forwards, the
  23071. latest one if scanning backwards)
  23072. */
  23073. int64 searchForLevel (int64 startSample,
  23074. int64 numSamplesToSearch,
  23075. const double magnitudeRangeMinimum,
  23076. const double magnitudeRangeMaximum,
  23077. const int minimumConsecutiveSamples);
  23078. /** The sample-rate of the stream. */
  23079. double sampleRate;
  23080. /** The number of bits per sample, e.g. 16, 24, 32. */
  23081. unsigned int bitsPerSample;
  23082. /** The total number of samples in the audio stream. */
  23083. int64 lengthInSamples;
  23084. /** The total number of channels in the audio stream. */
  23085. unsigned int numChannels;
  23086. /** Indicates whether the data is floating-point or fixed. */
  23087. bool usesFloatingPointData;
  23088. /** A set of metadata values that the reader has pulled out of the stream.
  23089. Exactly what these values are depends on the format, so you can
  23090. check out the format implementation code to see what kind of stuff
  23091. they understand.
  23092. */
  23093. StringPairArray metadataValues;
  23094. /** The input stream, for use by subclasses. */
  23095. InputStream* input;
  23096. juce_UseDebuggingNewOperator
  23097. private:
  23098. String formatName;
  23099. AudioFormatReader (const AudioFormatReader&);
  23100. const AudioFormatReader& operator= (const AudioFormatReader&);
  23101. };
  23102. #endif // __JUCE_AUDIOFORMATREADER_JUCEHEADER__
  23103. /********* End of inlined file: juce_AudioFormatReader.h *********/
  23104. /**
  23105. A type of AudioSource that will read from an AudioFormatReader.
  23106. @see PositionableAudioSource, AudioTransportSource, BufferingAudioSource
  23107. */
  23108. class JUCE_API AudioFormatReaderSource : public PositionableAudioSource
  23109. {
  23110. public:
  23111. /** Creates an AudioFormatReaderSource for a given reader.
  23112. @param sourceReader the reader to use as the data source
  23113. @param deleteReaderWhenThisIsDeleted if true, the reader passed-in will be deleted
  23114. when this object is deleted; if false it will be
  23115. left up to the caller to manage its lifetime
  23116. */
  23117. AudioFormatReaderSource (AudioFormatReader* const sourceReader,
  23118. const bool deleteReaderWhenThisIsDeleted);
  23119. /** Destructor. */
  23120. ~AudioFormatReaderSource();
  23121. /** Toggles loop-mode.
  23122. If set to true, it will continuously loop the input source. If false,
  23123. it will just emit silence after the source has finished.
  23124. @see isLooping
  23125. */
  23126. void setLooping (const bool shouldLoop) throw();
  23127. /** Returns whether loop-mode is turned on or not. */
  23128. bool isLooping() const { return looping; }
  23129. /** Returns the reader that's being used. */
  23130. AudioFormatReader* getAudioFormatReader() const throw() { return reader; }
  23131. /** Implementation of the AudioSource method. */
  23132. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23133. /** Implementation of the AudioSource method. */
  23134. void releaseResources();
  23135. /** Implementation of the AudioSource method. */
  23136. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23137. /** Implements the PositionableAudioSource method. */
  23138. void setNextReadPosition (int newPosition);
  23139. /** Implements the PositionableAudioSource method. */
  23140. int getNextReadPosition() const;
  23141. /** Implements the PositionableAudioSource method. */
  23142. int getTotalLength() const;
  23143. juce_UseDebuggingNewOperator
  23144. private:
  23145. AudioFormatReader* reader;
  23146. bool deleteReader;
  23147. int volatile nextPlayPos;
  23148. bool volatile looping;
  23149. void readBufferSection (int start, int length, AudioSampleBuffer& buffer, int startSample);
  23150. AudioFormatReaderSource (const AudioFormatReaderSource&);
  23151. const AudioFormatReaderSource& operator= (const AudioFormatReaderSource&);
  23152. };
  23153. #endif // __JUCE_AUDIOFORMATREADERSOURCE_JUCEHEADER__
  23154. /********* End of inlined file: juce_AudioFormatReaderSource.h *********/
  23155. #endif
  23156. #ifndef __JUCE_AUDIOSOURCE_JUCEHEADER__
  23157. #endif
  23158. #ifndef __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__
  23159. /********* Start of inlined file: juce_AudioSourcePlayer.h *********/
  23160. #ifndef __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__
  23161. #define __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__
  23162. /**
  23163. Wrapper class to continuously stream audio from an audio source to an
  23164. AudioIODevice.
  23165. This object acts as an AudioIODeviceCallback, so can be attached to an
  23166. output device, and will stream audio from an AudioSource.
  23167. */
  23168. class JUCE_API AudioSourcePlayer : public AudioIODeviceCallback
  23169. {
  23170. public:
  23171. /** Creates an empty AudioSourcePlayer. */
  23172. AudioSourcePlayer();
  23173. /** Destructor.
  23174. Make sure this object isn't still being used by an AudioIODevice before
  23175. deleting it!
  23176. */
  23177. virtual ~AudioSourcePlayer();
  23178. /** Changes the current audio source to play from.
  23179. If the source passed in is already being used, this method will do nothing.
  23180. If the source is not null, its prepareToPlay() method will be called
  23181. before it starts being used for playback.
  23182. If there's another source currently playing, its releaseResources() method
  23183. will be called after it has been swapped for the new one.
  23184. @param newSource the new source to use - this will NOT be deleted
  23185. by this object when no longer needed, so it's the
  23186. caller's responsibility to manage it.
  23187. */
  23188. void setSource (AudioSource* newSource);
  23189. /** Returns the source that's playing.
  23190. May return 0 if there's no source.
  23191. */
  23192. AudioSource* getCurrentSource() const throw() { return source; }
  23193. /** Sets a gain to apply to the audio data. */
  23194. void setGain (const float newGain) throw();
  23195. /** Implementation of the AudioIODeviceCallback method. */
  23196. void audioDeviceIOCallback (const float** inputChannelData,
  23197. int totalNumInputChannels,
  23198. float** outputChannelData,
  23199. int totalNumOutputChannels,
  23200. int numSamples);
  23201. /** Implementation of the AudioIODeviceCallback method. */
  23202. void audioDeviceAboutToStart (AudioIODevice* device);
  23203. /** Implementation of the AudioIODeviceCallback method. */
  23204. void audioDeviceStopped();
  23205. juce_UseDebuggingNewOperator
  23206. private:
  23207. CriticalSection readLock;
  23208. AudioSource* source;
  23209. double sampleRate;
  23210. int bufferSize;
  23211. float* channels [128];
  23212. float* outputChans [128];
  23213. const float* inputChans [128];
  23214. AudioSampleBuffer tempBuffer;
  23215. float lastGain, gain;
  23216. AudioSourcePlayer (const AudioSourcePlayer&);
  23217. const AudioSourcePlayer& operator= (const AudioSourcePlayer&);
  23218. };
  23219. #endif // __JUCE_AUDIOSOURCEPLAYER_JUCEHEADER__
  23220. /********* End of inlined file: juce_AudioSourcePlayer.h *********/
  23221. #endif
  23222. #ifndef __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__
  23223. /********* Start of inlined file: juce_AudioTransportSource.h *********/
  23224. #ifndef __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__
  23225. #define __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__
  23226. /********* Start of inlined file: juce_BufferingAudioSource.h *********/
  23227. #ifndef __JUCE_BUFFERINGAUDIOSOURCE_JUCEHEADER__
  23228. #define __JUCE_BUFFERINGAUDIOSOURCE_JUCEHEADER__
  23229. /**
  23230. An AudioSource which takes another source as input, and buffers it using a thread.
  23231. Create this as a wrapper around another thread, and it will read-ahead with
  23232. a background thread to smooth out playback. You can either create one of these
  23233. directly, or use it indirectly using an AudioTransportSource.
  23234. @see PositionableAudioSource, AudioTransportSource
  23235. */
  23236. class JUCE_API BufferingAudioSource : public PositionableAudioSource
  23237. {
  23238. public:
  23239. /** Creates a BufferingAudioSource.
  23240. @param source the input source to read from
  23241. @param deleteSourceWhenDeleted if true, then the input source object will
  23242. be deleted when this object is deleted
  23243. @param numberOfSamplesToBuffer the size of buffer to use for reading ahead
  23244. */
  23245. BufferingAudioSource (PositionableAudioSource* source,
  23246. const bool deleteSourceWhenDeleted,
  23247. int numberOfSamplesToBuffer);
  23248. /** Destructor.
  23249. The input source may be deleted depending on whether the deleteSourceWhenDeleted
  23250. flag was set in the constructor.
  23251. */
  23252. ~BufferingAudioSource();
  23253. /** Implementation of the AudioSource method. */
  23254. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23255. /** Implementation of the AudioSource method. */
  23256. void releaseResources();
  23257. /** Implementation of the AudioSource method. */
  23258. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23259. /** Implements the PositionableAudioSource method. */
  23260. void setNextReadPosition (int newPosition);
  23261. /** Implements the PositionableAudioSource method. */
  23262. int getNextReadPosition() const;
  23263. /** Implements the PositionableAudioSource method. */
  23264. int getTotalLength() const { return source->getTotalLength(); }
  23265. /** Implements the PositionableAudioSource method. */
  23266. bool isLooping() const { return source->isLooping(); }
  23267. juce_UseDebuggingNewOperator
  23268. private:
  23269. PositionableAudioSource* source;
  23270. bool deleteSourceWhenDeleted;
  23271. int numberOfSamplesToBuffer;
  23272. AudioSampleBuffer buffer;
  23273. CriticalSection bufferStartPosLock;
  23274. int volatile bufferValidStart, bufferValidEnd, nextPlayPos;
  23275. bool wasSourceLooping;
  23276. double volatile sampleRate;
  23277. friend class SharedBufferingAudioSourceThread;
  23278. bool readNextBufferChunk();
  23279. void readBufferSection (int start, int length, int bufferOffset);
  23280. BufferingAudioSource (const BufferingAudioSource&);
  23281. const BufferingAudioSource& operator= (const BufferingAudioSource&);
  23282. };
  23283. #endif // __JUCE_BUFFERINGAUDIOSOURCE_JUCEHEADER__
  23284. /********* End of inlined file: juce_BufferingAudioSource.h *********/
  23285. /********* Start of inlined file: juce_ResamplingAudioSource.h *********/
  23286. #ifndef __JUCE_RESAMPLINGAUDIOSOURCE_JUCEHEADER__
  23287. #define __JUCE_RESAMPLINGAUDIOSOURCE_JUCEHEADER__
  23288. /**
  23289. A type of AudioSource that takes an input source and changes its sample rate.
  23290. @see AudioSource
  23291. */
  23292. class JUCE_API ResamplingAudioSource : public AudioSource
  23293. {
  23294. public:
  23295. /** Creates a ResamplingAudioSource for a given input source.
  23296. @param inputSource the input source to read from
  23297. @param deleteInputWhenDeleted if true, the input source will be deleted when
  23298. this object is deleted
  23299. */
  23300. ResamplingAudioSource (AudioSource* const inputSource,
  23301. const bool deleteInputWhenDeleted);
  23302. /** Destructor. */
  23303. ~ResamplingAudioSource();
  23304. /** Changes the resampling ratio.
  23305. (This value can be changed at any time, even while the source is running).
  23306. @param samplesInPerOutputSample if set to 1.0, the input is passed through; higher
  23307. values will speed it up; lower values will slow it
  23308. down. The ratio must be greater than 0
  23309. */
  23310. void setResamplingRatio (const double samplesInPerOutputSample);
  23311. /** Returns the current resampling ratio.
  23312. This is the value that was set by setResamplingRatio().
  23313. */
  23314. double getResamplingRatio() const throw() { return ratio; }
  23315. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23316. void releaseResources();
  23317. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23318. juce_UseDebuggingNewOperator
  23319. private:
  23320. AudioSource* const input;
  23321. const bool deleteInputWhenDeleted;
  23322. double ratio, lastRatio;
  23323. AudioSampleBuffer buffer;
  23324. int bufferPos, sampsInBuffer;
  23325. double subSampleOffset;
  23326. double coefficients[6];
  23327. CriticalSection ratioLock;
  23328. void setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6);
  23329. void createLowPass (const double proportionalRate);
  23330. struct FilterState
  23331. {
  23332. double x1, x2, y1, y2;
  23333. };
  23334. FilterState filterStates[2];
  23335. void resetFilters();
  23336. void applyFilter (float* samples, int num, FilterState& fs);
  23337. ResamplingAudioSource (const ResamplingAudioSource&);
  23338. const ResamplingAudioSource& operator= (const ResamplingAudioSource&);
  23339. };
  23340. #endif // __JUCE_RESAMPLINGAUDIOSOURCE_JUCEHEADER__
  23341. /********* End of inlined file: juce_ResamplingAudioSource.h *********/
  23342. /**
  23343. An AudioSource that takes a PositionableAudioSource and allows it to be
  23344. played, stopped, started, etc.
  23345. This can also be told use a buffer and background thread to read ahead, and
  23346. if can correct for different sample-rates.
  23347. You may want to use one of these along with an AudioSourcePlayer and AudioIODevice
  23348. to control playback of an audio file.
  23349. @see AudioSource, AudioSourcePlayer
  23350. */
  23351. class JUCE_API AudioTransportSource : public PositionableAudioSource,
  23352. public ChangeBroadcaster
  23353. {
  23354. public:
  23355. /** Creates an AudioTransportSource.
  23356. After creating one of these, use the setSource() method to select an input source.
  23357. */
  23358. AudioTransportSource();
  23359. /** Destructor. */
  23360. ~AudioTransportSource();
  23361. /** Sets the reader that is being used as the input source.
  23362. This will stop playback, reset the position to 0 and change to the new reader.
  23363. The source passed in will not be deleted by this object, so must be managed by
  23364. the caller.
  23365. @param newSource the new input source to use. This may be zero
  23366. @param readAheadBufferSize a size of buffer to use for reading ahead. If this
  23367. is zero, no reading ahead will be done; if it's
  23368. greater than zero, a BufferingAudioSource will be used
  23369. to do the reading-ahead
  23370. @param sourceSampleRateToCorrectFor if this is non-zero, it specifies the sample
  23371. rate of the source, and playback will be sample-rate
  23372. adjusted to maintain playback at the correct pitch. If
  23373. this is 0, no sample-rate adjustment will be performed
  23374. */
  23375. void setSource (PositionableAudioSource* const newSource,
  23376. int readAheadBufferSize = 0,
  23377. double sourceSampleRateToCorrectFor = 0.0);
  23378. /** Changes the current playback position in the source stream.
  23379. The next time the getNextAudioBlock() method is called, this
  23380. is the time from which it'll read data.
  23381. @see getPosition
  23382. */
  23383. void setPosition (double newPosition);
  23384. /** Returns the position that the next data block will be read from
  23385. This is a time in seconds.
  23386. */
  23387. double getCurrentPosition() const;
  23388. /** Returns true if the player has stopped because its input stream ran out of data.
  23389. */
  23390. bool hasStreamFinished() const throw() { return inputStreamEOF; }
  23391. /** Starts playing (if a source has been selected).
  23392. If it starts playing, this will send a message to any ChangeListeners
  23393. that are registered with this object.
  23394. */
  23395. void start();
  23396. /** Stops playing.
  23397. If it's actually playing, this will send a message to any ChangeListeners
  23398. that are registered with this object.
  23399. */
  23400. void stop();
  23401. /** Returns true if it's currently playing. */
  23402. bool isPlaying() const throw() { return playing; }
  23403. /** Changes the gain to apply to the output.
  23404. @param newGain a factor by which to multiply the outgoing samples,
  23405. so 1.0 = 0dB, 0.5 = -6dB, 2.0 = 6dB, etc.
  23406. */
  23407. void setGain (const float newGain) throw();
  23408. /** Returns the current gain setting.
  23409. @see setGain
  23410. */
  23411. float getGain() const throw() { return gain; }
  23412. /** Implementation of the AudioSource method. */
  23413. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23414. /** Implementation of the AudioSource method. */
  23415. void releaseResources();
  23416. /** Implementation of the AudioSource method. */
  23417. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23418. /** Implements the PositionableAudioSource method. */
  23419. void setNextReadPosition (int newPosition);
  23420. /** Implements the PositionableAudioSource method. */
  23421. int getNextReadPosition() const;
  23422. /** Implements the PositionableAudioSource method. */
  23423. int getTotalLength() const;
  23424. /** Implements the PositionableAudioSource method. */
  23425. bool isLooping() const;
  23426. juce_UseDebuggingNewOperator
  23427. private:
  23428. PositionableAudioSource* source;
  23429. ResamplingAudioSource* resamplerSource;
  23430. BufferingAudioSource* bufferingSource;
  23431. PositionableAudioSource* positionableSource;
  23432. AudioSource* masterSource;
  23433. CriticalSection callbackLock;
  23434. float volatile gain, lastGain;
  23435. bool volatile playing, stopped;
  23436. double sampleRate, sourceSampleRate;
  23437. int blockSize, readAheadBufferSize;
  23438. bool isPrepared, inputStreamEOF;
  23439. AudioTransportSource (const AudioTransportSource&);
  23440. const AudioTransportSource& operator= (const AudioTransportSource&);
  23441. };
  23442. #endif // __JUCE_AUDIOTRANSPORTSOURCE_JUCEHEADER__
  23443. /********* End of inlined file: juce_AudioTransportSource.h *********/
  23444. #endif
  23445. #ifndef __JUCE_BUFFERINGAUDIOSOURCE_JUCEHEADER__
  23446. #endif
  23447. #ifndef __JUCE_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__
  23448. /********* Start of inlined file: juce_ChannelRemappingAudioSource.h *********/
  23449. #ifndef __JUCE_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__
  23450. #define __JUCE_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__
  23451. /**
  23452. An AudioSource that takes the audio from another source, and re-maps its
  23453. input and output channels to a different arrangement.
  23454. You can use this to increase or decrease the number of channels that an
  23455. audio source uses, or to re-order those channels.
  23456. Call the reset() method before using it to set up a default mapping, and then
  23457. the setInputChannelMapping() and setOutputChannelMapping() methods to
  23458. create an appropriate mapping, otherwise no channels will be connected and
  23459. it'll produce silence.
  23460. @see AudioSource
  23461. */
  23462. class ChannelRemappingAudioSource : public AudioSource
  23463. {
  23464. public:
  23465. /** Creates a remapping source that will pass on audio from the given input.
  23466. @param source the input source to use. Make sure that this doesn't
  23467. get deleted before the ChannelRemappingAudioSource object
  23468. @param deleteSourceWhenDeleted if true, the input source will be deleted
  23469. when this object is deleted, if false, the caller is
  23470. responsible for its deletion
  23471. */
  23472. ChannelRemappingAudioSource (AudioSource* const source,
  23473. const bool deleteSourceWhenDeleted);
  23474. /** Destructor. */
  23475. ~ChannelRemappingAudioSource();
  23476. /** Specifies a number of channels that this audio source must produce from its
  23477. getNextAudioBlock() callback.
  23478. */
  23479. void setNumberOfChannelsToProduce (const int requiredNumberOfChannels) throw();
  23480. /** Clears any mapped channels.
  23481. After this, no channels are mapped, so this object will produce silence. Create
  23482. some mappings with setInputChannelMapping() and setOutputChannelMapping().
  23483. */
  23484. void clearAllMappings() throw();
  23485. /** Creates an input channel mapping.
  23486. When the getNextAudioBlock() method is called, the data in channel sourceChannelIndex of the incoming
  23487. data will be sent to destChannelIndex of our input source.
  23488. @param destChannelIndex the index of an input channel in our input audio source (i.e. the
  23489. source specified when this object was created).
  23490. @param sourceChannelIndex the index of the input channel in the incoming audio data buffer
  23491. during our getNextAudioBlock() callback
  23492. */
  23493. void setInputChannelMapping (const int destChannelIndex,
  23494. const int sourceChannelIndex) throw();
  23495. /** Creates an output channel mapping.
  23496. When the getNextAudioBlock() method is called, the data returned in channel sourceChannelIndex by
  23497. our input audio source will be copied to channel destChannelIndex of the final buffer.
  23498. @param sourceChannelIndex the index of an output channel coming from our input audio source
  23499. (i.e. the source specified when this object was created).
  23500. @param destChannelIndex the index of the output channel in the incoming audio data buffer
  23501. during our getNextAudioBlock() callback
  23502. */
  23503. void setOutputChannelMapping (const int sourceChannelIndex,
  23504. const int destChannelIndex) throw();
  23505. /** Returns the channel from our input that will be sent to channel inputChannelIndex of
  23506. our input audio source.
  23507. */
  23508. int getRemappedInputChannel (const int inputChannelIndex) const throw();
  23509. /** Returns the output channel to which channel outputChannelIndex of our input audio
  23510. source will be sent to.
  23511. */
  23512. int getRemappedOutputChannel (const int outputChannelIndex) const throw();
  23513. /** Returns an XML object to encapsulate the state of the mappings.
  23514. @see restoreFromXml
  23515. */
  23516. XmlElement* createXml() const throw();
  23517. /** Restores the mappings from an XML object created by createXML().
  23518. @see createXml
  23519. */
  23520. void restoreFromXml (const XmlElement& e) throw();
  23521. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23522. void releaseResources();
  23523. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23524. juce_UseDebuggingNewOperator
  23525. private:
  23526. int requiredNumberOfChannels;
  23527. Array <int> remappedInputs, remappedOutputs;
  23528. AudioSource* const source;
  23529. const bool deleteSourceWhenDeleted;
  23530. AudioSampleBuffer buffer;
  23531. AudioSourceChannelInfo remappedInfo;
  23532. CriticalSection lock;
  23533. ChannelRemappingAudioSource (const ChannelRemappingAudioSource&);
  23534. const ChannelRemappingAudioSource& operator= (const ChannelRemappingAudioSource&);
  23535. };
  23536. #endif // __JUCE_CHANNELREMAPPINGAUDIOSOURCE_JUCEHEADER__
  23537. /********* End of inlined file: juce_ChannelRemappingAudioSource.h *********/
  23538. #endif
  23539. #ifndef __JUCE_IIRFILTERAUDIOSOURCE_JUCEHEADER__
  23540. /********* Start of inlined file: juce_IIRFilterAudioSource.h *********/
  23541. #ifndef __JUCE_IIRFILTERAUDIOSOURCE_JUCEHEADER__
  23542. #define __JUCE_IIRFILTERAUDIOSOURCE_JUCEHEADER__
  23543. /**
  23544. An AudioSource that performs an IIR filter on another source.
  23545. */
  23546. class JUCE_API IIRFilterAudioSource : public AudioSource
  23547. {
  23548. public:
  23549. /** Creates a IIRFilterAudioSource for a given input source.
  23550. @param inputSource the input source to read from
  23551. @param deleteInputWhenDeleted if true, the input source will be deleted when
  23552. this object is deleted
  23553. */
  23554. IIRFilterAudioSource (AudioSource* const inputSource,
  23555. const bool deleteInputWhenDeleted);
  23556. /** Destructor. */
  23557. ~IIRFilterAudioSource();
  23558. /** Changes the filter to use the same parameters as the one being passed in.
  23559. */
  23560. void setFilterParameters (const IIRFilter& newSettings);
  23561. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23562. void releaseResources();
  23563. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23564. juce_UseDebuggingNewOperator
  23565. private:
  23566. AudioSource* const input;
  23567. const bool deleteInputWhenDeleted;
  23568. OwnedArray <IIRFilter> iirFilters;
  23569. IIRFilterAudioSource (const IIRFilterAudioSource&);
  23570. const IIRFilterAudioSource& operator= (const IIRFilterAudioSource&);
  23571. };
  23572. #endif // __JUCE_IIRFILTERAUDIOSOURCE_JUCEHEADER__
  23573. /********* End of inlined file: juce_IIRFilterAudioSource.h *********/
  23574. #endif
  23575. #ifndef __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__
  23576. /********* Start of inlined file: juce_MixerAudioSource.h *********/
  23577. #ifndef __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__
  23578. #define __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__
  23579. /**
  23580. An AudioSource that mixes together the output of a set of other AudioSources.
  23581. Input sources can be added and removed while the mixer is running as long as their
  23582. prepareToPlay() and releaseResources() methods are called before and after adding
  23583. them to the mixer.
  23584. */
  23585. class JUCE_API MixerAudioSource : public AudioSource
  23586. {
  23587. public:
  23588. /** Creates a MixerAudioSource.
  23589. */
  23590. MixerAudioSource();
  23591. /** Destructor. */
  23592. ~MixerAudioSource();
  23593. /** Adds an input source to the mixer.
  23594. If the mixer is running you'll need to make sure that the input source
  23595. is ready to play by calling its prepareToPlay() method before adding it.
  23596. If the mixer is stopped, then its input sources will be automatically
  23597. prepared when the mixer's prepareToPlay() method is called.
  23598. @param newInput the source to add to the mixer
  23599. @param deleteWhenRemoved if true, then this source will be deleted when
  23600. the mixer is deleted or when removeAllInputs() is
  23601. called (unless the source is previously removed
  23602. with the removeInputSource method)
  23603. */
  23604. void addInputSource (AudioSource* newInput,
  23605. const bool deleteWhenRemoved);
  23606. /** Removes an input source.
  23607. If the mixer is running, this will remove the source but not call its
  23608. releaseResources() method, so the caller might want to do this manually.
  23609. @param input the source to remove
  23610. @param deleteSource whether to delete this source after it's been removed
  23611. */
  23612. void removeInputSource (AudioSource* input,
  23613. const bool deleteSource);
  23614. /** Removes all the input sources.
  23615. If the mixer is running, this will remove the sources but not call their
  23616. releaseResources() method, so the caller might want to do this manually.
  23617. Any sources which were added with the deleteWhenRemoved flag set will be
  23618. deleted by this method.
  23619. */
  23620. void removeAllInputs();
  23621. /** Implementation of the AudioSource method.
  23622. This will call prepareToPlay() on all its input sources.
  23623. */
  23624. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23625. /** Implementation of the AudioSource method.
  23626. This will call releaseResources() on all its input sources.
  23627. */
  23628. void releaseResources();
  23629. /** Implementation of the AudioSource method. */
  23630. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23631. juce_UseDebuggingNewOperator
  23632. private:
  23633. VoidArray inputs;
  23634. BitArray inputsToDelete;
  23635. CriticalSection lock;
  23636. AudioSampleBuffer tempBuffer;
  23637. double currentSampleRate;
  23638. int bufferSizeExpected;
  23639. MixerAudioSource (const MixerAudioSource&);
  23640. const MixerAudioSource& operator= (const MixerAudioSource&);
  23641. };
  23642. #endif // __JUCE_MIXERAUDIOSOURCE_JUCEHEADER__
  23643. /********* End of inlined file: juce_MixerAudioSource.h *********/
  23644. #endif
  23645. #ifndef __JUCE_POSITIONABLEAUDIOSOURCE_JUCEHEADER__
  23646. #endif
  23647. #ifndef __JUCE_RESAMPLINGAUDIOSOURCE_JUCEHEADER__
  23648. #endif
  23649. #ifndef __JUCE_TONEGENERATORAUDIOSOURCE_JUCEHEADER__
  23650. /********* Start of inlined file: juce_ToneGeneratorAudioSource.h *********/
  23651. #ifndef __JUCE_TONEGENERATORAUDIOSOURCE_JUCEHEADER__
  23652. #define __JUCE_TONEGENERATORAUDIOSOURCE_JUCEHEADER__
  23653. /**
  23654. A simple AudioSource that generates a sine wave.
  23655. */
  23656. class JUCE_API ToneGeneratorAudioSource : public AudioSource
  23657. {
  23658. public:
  23659. /** Creates a ToneGeneratorAudioSource. */
  23660. ToneGeneratorAudioSource();
  23661. /** Destructor. */
  23662. ~ToneGeneratorAudioSource();
  23663. /** Sets the signal's amplitude. */
  23664. void setAmplitude (const float newAmplitude);
  23665. /** Sets the signal's frequency. */
  23666. void setFrequency (const double newFrequencyHz);
  23667. /** Implementation of the AudioSource method. */
  23668. void prepareToPlay (int samplesPerBlockExpected, double sampleRate);
  23669. /** Implementation of the AudioSource method. */
  23670. void releaseResources();
  23671. /** Implementation of the AudioSource method. */
  23672. void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill);
  23673. juce_UseDebuggingNewOperator
  23674. private:
  23675. double frequency, sampleRate;
  23676. double currentPhase, phasePerSample;
  23677. float amplitude;
  23678. ToneGeneratorAudioSource (const ToneGeneratorAudioSource&);
  23679. const ToneGeneratorAudioSource& operator= (const ToneGeneratorAudioSource&);
  23680. };
  23681. #endif // __JUCE_TONEGENERATORAUDIOSOURCE_JUCEHEADER__
  23682. /********* End of inlined file: juce_ToneGeneratorAudioSource.h *********/
  23683. #endif
  23684. #ifndef __JUCE_AUDIODEVICEMANAGER_JUCEHEADER__
  23685. /********* Start of inlined file: juce_AudioDeviceManager.h *********/
  23686. #ifndef __JUCE_AUDIODEVICEMANAGER_JUCEHEADER__
  23687. #define __JUCE_AUDIODEVICEMANAGER_JUCEHEADER__
  23688. /********* Start of inlined file: juce_AudioIODeviceType.h *********/
  23689. #ifndef __JUCE_AUDIOIODEVICETYPE_JUCEHEADER__
  23690. #define __JUCE_AUDIOIODEVICETYPE_JUCEHEADER__
  23691. class AudioDeviceManager;
  23692. class Component;
  23693. /**
  23694. Represents a type of audio driver, such as DirectSound, ASIO, CoreAudio, etc.
  23695. To get a list of available audio driver types, use the createDeviceTypes()
  23696. method. Each of the objects returned can then be used to list the available
  23697. devices of that type. E.g.
  23698. @code
  23699. OwnedArray <AudioIODeviceType> types;
  23700. AudioIODeviceType::createDeviceTypes (types);
  23701. for (int i = 0; i < types.size(); ++i)
  23702. {
  23703. String typeName (types[i]->getTypeName()); // This will be things like "DirectSound", "CoreAudio", etc.
  23704. types[i]->scanForDevices(); // This must be called before getting the list of devices
  23705. String deviceNames (types[i]->getDeviceNames()); // This will now return a list of available devices of this type
  23706. for (int j = 0; j < deviceNames.size(); ++j)
  23707. {
  23708. AudioIODevice* device = types[i]->createDevice (deviceNames [j]);
  23709. ...
  23710. }
  23711. }
  23712. @endcode
  23713. For an easier way of managing audio devices and their settings, have a look at the
  23714. AudioDeviceManager class.
  23715. @see AudioIODevice, AudioDeviceManager
  23716. */
  23717. class JUCE_API AudioIODeviceType
  23718. {
  23719. public:
  23720. /** Returns the name of this type of driver that this object manages.
  23721. This will be something like "DirectSound", "ASIO", "CoreAudio", "ALSA", etc.
  23722. */
  23723. const String& getTypeName() const throw() { return typeName; }
  23724. /** Refreshes the object's cached list of known devices.
  23725. This must be called at least once before calling getDeviceNames() or any of
  23726. the other device creation methods.
  23727. */
  23728. virtual void scanForDevices() = 0;
  23729. /** Returns the list of available devices of this type.
  23730. The scanForDevices() method must have been called to create this list.
  23731. @param wantInputNames only really used by DirectSound where devices are split up
  23732. into inputs and outputs, this indicates whether to use
  23733. the input or output name to refer to a pair of devices.
  23734. */
  23735. virtual const StringArray getDeviceNames (const bool wantInputNames = false) const = 0;
  23736. /** Returns the name of the default device.
  23737. This will be one of the names from the getDeviceNames() list.
  23738. @param forInput if true, this means that a default input device should be
  23739. returned; if false, it should return the default output
  23740. */
  23741. virtual int getDefaultDeviceIndex (const bool forInput) const = 0;
  23742. /** Returns the index of a given device in the list of device names.
  23743. If asInput is true, it shows the index in the inputs list, otherwise it
  23744. looks for it in the outputs list.
  23745. */
  23746. virtual int getIndexOfDevice (AudioIODevice* device, const bool asInput) const = 0;
  23747. /** Returns true if two different devices can be used for the input and output.
  23748. */
  23749. virtual bool hasSeparateInputsAndOutputs() const = 0;
  23750. /** Creates one of the devices of this type.
  23751. The deviceName must be one of the strings returned by getDeviceNames(), and
  23752. scanForDevices() must have been called before this method is used.
  23753. */
  23754. virtual AudioIODevice* createDevice (const String& outputDeviceName,
  23755. const String& inputDeviceName) = 0;
  23756. struct DeviceSetupDetails
  23757. {
  23758. AudioDeviceManager* manager;
  23759. int minNumInputChannels, maxNumInputChannels;
  23760. int minNumOutputChannels, maxNumOutputChannels;
  23761. bool useStereoPairs;
  23762. };
  23763. /** Destructor. */
  23764. virtual ~AudioIODeviceType();
  23765. protected:
  23766. AudioIODeviceType (const tchar* const typeName);
  23767. private:
  23768. String typeName;
  23769. AudioIODeviceType (const AudioIODeviceType&);
  23770. const AudioIODeviceType& operator= (const AudioIODeviceType&);
  23771. };
  23772. #endif // __JUCE_AUDIOIODEVICETYPE_JUCEHEADER__
  23773. /********* End of inlined file: juce_AudioIODeviceType.h *********/
  23774. /********* Start of inlined file: juce_MidiOutput.h *********/
  23775. #ifndef __JUCE_MIDIOUTPUT_JUCEHEADER__
  23776. #define __JUCE_MIDIOUTPUT_JUCEHEADER__
  23777. /**
  23778. Represents a midi output device.
  23779. To create one of these, use the static getDevices() method to find out what
  23780. outputs are available, then use the openDevice() method to try to open one.
  23781. @see MidiInput
  23782. */
  23783. class JUCE_API MidiOutput : private Thread
  23784. {
  23785. public:
  23786. /** Returns a list of the available midi output devices.
  23787. You can open one of the devices by passing its index into the
  23788. openDevice() method.
  23789. @see getDefaultDeviceIndex, openDevice
  23790. */
  23791. static const StringArray getDevices();
  23792. /** Returns the index of the default midi output device to use.
  23793. This refers to the index in the list returned by getDevices().
  23794. */
  23795. static int getDefaultDeviceIndex();
  23796. /** Tries to open one of the midi output devices.
  23797. This will return a MidiOutput object if it manages to open it. You can then
  23798. send messages to this device, and delete it when no longer needed.
  23799. If the device can't be opened, this will return a null pointer.
  23800. @param deviceIndex the index of a device from the list returned by getDevices()
  23801. @see getDevices
  23802. */
  23803. static MidiOutput* openDevice (int deviceIndex);
  23804. #if JUCE_LINUX || DOXYGEN
  23805. /** LINUX ONLY - This will try to create a new midi output device.
  23806. This will attempt to create a new midi output device that other apps can connect
  23807. to and use as their midi input.
  23808. Returns 0 if a device can't be created.
  23809. @param deviceName the name to use for the new device
  23810. */
  23811. static MidiOutput* createNewDevice (const String& deviceName);
  23812. #endif
  23813. /** Destructor. */
  23814. ~MidiOutput();
  23815. /** Makes this device output a midi message.
  23816. @see MidiMessage
  23817. */
  23818. void sendMessageNow (const MidiMessage& message);
  23819. /** Sends a midi reset to the device. */
  23820. void reset();
  23821. /** Returns the current volume setting for this device. */
  23822. bool getVolume (float& leftVol,
  23823. float& rightVol);
  23824. /** Changes the overall volume for this device. */
  23825. void setVolume (float leftVol,
  23826. float rightVol);
  23827. /** This lets you supply a block of messages that will be sent out at some point
  23828. in the future.
  23829. The MidiOutput class has an internal thread that can send out timestamped
  23830. messages - this appends a set of messages to its internal buffer, ready for
  23831. sending.
  23832. This will only work if you've already started the thread with startBackgroundThread().
  23833. A time is supplied, at which the block of messages should be sent. This time uses
  23834. the same time base as Time::getMillisecondCounter(), and must be in the future.
  23835. The samplesPerSecondForBuffer parameter indicates the number of samples per second
  23836. used by the MidiBuffer. Each event in a MidiBuffer has a sample position, and the
  23837. samplesPerSecondForBuffer value is needed to convert this sample position to a
  23838. real time.
  23839. */
  23840. void sendBlockOfMessages (const MidiBuffer& buffer,
  23841. const double millisecondCounterToStartAt,
  23842. double samplesPerSecondForBuffer) throw();
  23843. /** Gets rid of any midi messages that had been added by sendBlockOfMessages().
  23844. */
  23845. void clearAllPendingMessages() throw();
  23846. /** Starts up a background thread so that the device can send blocks of data.
  23847. Call this to get the device ready, before using sendBlockOfMessages().
  23848. */
  23849. void startBackgroundThread() throw();
  23850. /** Stops the background thread, and clears any pending midi events.
  23851. @see startBackgroundThread
  23852. */
  23853. void stopBackgroundThread() throw();
  23854. juce_UseDebuggingNewOperator
  23855. private:
  23856. void* internal;
  23857. struct PendingMessage
  23858. {
  23859. PendingMessage (const uint8* const data, const int len, const double sampleNumber) throw();
  23860. MidiMessage message;
  23861. PendingMessage* next;
  23862. juce_UseDebuggingNewOperator
  23863. };
  23864. CriticalSection lock;
  23865. PendingMessage* firstMessage;
  23866. MidiOutput() throw();
  23867. MidiOutput (const MidiOutput&);
  23868. void run();
  23869. };
  23870. #endif // __JUCE_MIDIOUTPUT_JUCEHEADER__
  23871. /********* End of inlined file: juce_MidiOutput.h *********/
  23872. /********* Start of inlined file: juce_ComboBox.h *********/
  23873. #ifndef __JUCE_COMBOBOX_JUCEHEADER__
  23874. #define __JUCE_COMBOBOX_JUCEHEADER__
  23875. /********* Start of inlined file: juce_Label.h *********/
  23876. #ifndef __JUCE_LABEL_JUCEHEADER__
  23877. #define __JUCE_LABEL_JUCEHEADER__
  23878. /********* Start of inlined file: juce_ComponentDeletionWatcher.h *********/
  23879. #ifndef __JUCE_COMPONENTDELETIONWATCHER_JUCEHEADER__
  23880. #define __JUCE_COMPONENTDELETIONWATCHER_JUCEHEADER__
  23881. /**
  23882. Object for monitoring a component, and later testing whether it's still valid.
  23883. Slightly obscure, this one, but it's used internally for making sure that
  23884. after some callbacks, a component hasn't been deleted. It's more reliable than
  23885. just using isValidComponent(), which can provide false-positives if a new
  23886. component is created at the same memory location as an old one.
  23887. */
  23888. class JUCE_API ComponentDeletionWatcher
  23889. {
  23890. public:
  23891. /** Creates a watcher for a given component.
  23892. The component must be valid at the time it's passed in.
  23893. */
  23894. ComponentDeletionWatcher (const Component* const componentToWatch) throw();
  23895. /** Destructor. */
  23896. ~ComponentDeletionWatcher() throw();
  23897. /** Returns true if the component has been deleted since the time that this
  23898. object was created.
  23899. */
  23900. bool hasBeenDeleted() const throw();
  23901. /** Returns the component that's being watched, or null if it has been deleted. */
  23902. const Component* getComponent() const throw();
  23903. juce_UseDebuggingNewOperator
  23904. private:
  23905. const Component* const componentToWatch;
  23906. const uint32 componentUID;
  23907. ComponentDeletionWatcher (const ComponentDeletionWatcher&);
  23908. const ComponentDeletionWatcher& operator= (const ComponentDeletionWatcher&);
  23909. };
  23910. #endif // __JUCE_COMPONENTDELETIONWATCHER_JUCEHEADER__
  23911. /********* End of inlined file: juce_ComponentDeletionWatcher.h *********/
  23912. /********* Start of inlined file: juce_TextEditor.h *********/
  23913. #ifndef __JUCE_TEXTEDITOR_JUCEHEADER__
  23914. #define __JUCE_TEXTEDITOR_JUCEHEADER__
  23915. /********* Start of inlined file: juce_UndoManager.h *********/
  23916. #ifndef __JUCE_UNDOMANAGER_JUCEHEADER__
  23917. #define __JUCE_UNDOMANAGER_JUCEHEADER__
  23918. /********* Start of inlined file: juce_UndoableAction.h *********/
  23919. #ifndef __JUCE_UNDOABLEACTION_JUCEHEADER__
  23920. #define __JUCE_UNDOABLEACTION_JUCEHEADER__
  23921. /**
  23922. Used by the UndoManager class to store an action which can be done
  23923. and undone.
  23924. @see UndoManager
  23925. */
  23926. class JUCE_API UndoableAction
  23927. {
  23928. protected:
  23929. /** Creates an action. */
  23930. UndoableAction() throw() {}
  23931. public:
  23932. /** Destructor. */
  23933. virtual ~UndoableAction() {}
  23934. /** Overridden by a subclass to perform the action.
  23935. This method is called by the UndoManager, and shouldn't be used directly by
  23936. applications.
  23937. Be careful not to make any calls in a perform() method that could call
  23938. recursively back into the UndoManager::perform() method
  23939. @returns true if the action could be performed.
  23940. @see UndoManager::perform
  23941. */
  23942. virtual bool perform() = 0;
  23943. /** Overridden by a subclass to undo the action.
  23944. This method is called by the UndoManager, and shouldn't be used directly by
  23945. applications.
  23946. Be careful not to make any calls in an undo() method that could call
  23947. recursively back into the UndoManager::perform() method
  23948. @returns true if the action could be undone without any errors.
  23949. @see UndoManager::perform
  23950. */
  23951. virtual bool undo() = 0;
  23952. /** Returns a value to indicate how much memory this object takes up.
  23953. Because the UndoManager keeps a list of UndoableActions, this is used
  23954. to work out how much space each one will take up, so that the UndoManager
  23955. can work out how many to keep.
  23956. The default value returned here is 10 - units are arbitrary and
  23957. don't have to be accurate.
  23958. @see UndoManager::getNumberOfUnitsTakenUpByStoredCommands,
  23959. UndoManager::setMaxNumberOfStoredUnits
  23960. */
  23961. virtual int getSizeInUnits() { return 10; }
  23962. };
  23963. #endif // __JUCE_UNDOABLEACTION_JUCEHEADER__
  23964. /********* End of inlined file: juce_UndoableAction.h *********/
  23965. /**
  23966. Manages a list of undo/redo commands.
  23967. An UndoManager object keeps a list of past actions and can use these actions
  23968. to move backwards and forwards through an undo history.
  23969. To use it, create subclasses of UndoableAction which perform all the
  23970. actions you need, then when you need to actually perform an action, create one
  23971. and pass it to the UndoManager's perform() method.
  23972. The manager also uses the concept of 'transactions' to group the actions
  23973. together - all actions performed between calls to beginNewTransaction() are
  23974. grouped together and are all undone/redone as a group.
  23975. The UndoManager is a ChangeBroadcaster, so listeners can register to be told
  23976. when actions are performed or undone.
  23977. @see UndoableAction
  23978. */
  23979. class JUCE_API UndoManager : public ChangeBroadcaster
  23980. {
  23981. public:
  23982. /** Creates an UndoManager.
  23983. @param maxNumberOfUnitsToKeep each UndoableAction object returns a value
  23984. to indicate how much storage it takes up
  23985. (UndoableAction::getSizeInUnits()), so this
  23986. lets you specify the maximum total number of
  23987. units that the undomanager is allowed to
  23988. keep in memory before letting the older actions
  23989. drop off the end of the list.
  23990. @param minimumTransactionsToKeep this specifies the minimum number of transactions
  23991. that will be kept, even if this involves exceeding
  23992. the amount of space specified in maxNumberOfUnitsToKeep
  23993. */
  23994. UndoManager (const int maxNumberOfUnitsToKeep = 30000,
  23995. const int minimumTransactionsToKeep = 30);
  23996. /** Destructor. */
  23997. ~UndoManager();
  23998. /** Deletes all stored actions in the list. */
  23999. void clearUndoHistory();
  24000. /** Returns the current amount of space to use for storing UndoableAction objects.
  24001. @see setMaxNumberOfStoredUnits
  24002. */
  24003. int getNumberOfUnitsTakenUpByStoredCommands() const;
  24004. /** Sets the amount of space that can be used for storing UndoableAction objects.
  24005. @param maxNumberOfUnitsToKeep each UndoableAction object returns a value
  24006. to indicate how much storage it takes up
  24007. (UndoableAction::getSizeInUnits()), so this
  24008. lets you specify the maximum total number of
  24009. units that the undomanager is allowed to
  24010. keep in memory before letting the older actions
  24011. drop off the end of the list.
  24012. @param minimumTransactionsToKeep this specifies the minimum number of transactions
  24013. that will be kept, even if this involves exceeding
  24014. the amount of space specified in maxNumberOfUnitsToKeep
  24015. @see getNumberOfUnitsTakenUpByStoredCommands
  24016. */
  24017. void setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  24018. const int minimumTransactionsToKeep);
  24019. /** Performs an action and adds it to the undo history list.
  24020. @param action the action to perform - this will be deleted by the UndoManager
  24021. when no longer needed
  24022. @param actionName if this string is non-empty, the current transaction will be
  24023. given this name; if it's empty, the current transaction name will
  24024. be left unchanged. See setCurrentTransactionName()
  24025. @returns true if the command succeeds - see UndoableAction::perform
  24026. @see beginNewTransaction
  24027. */
  24028. bool perform (UndoableAction* const action,
  24029. const String& actionName = String::empty);
  24030. /** Starts a new group of actions that together will be treated as a single transaction.
  24031. All actions that are passed to the perform() method between calls to this
  24032. method are grouped together and undone/redone together by a single call to
  24033. undo() or redo().
  24034. @param actionName a description of the transaction that is about to be
  24035. performed
  24036. */
  24037. void beginNewTransaction (const String& actionName = String::empty);
  24038. /** Changes the name stored for the current transaction.
  24039. Each transaction is given a name when the beginNewTransaction() method is
  24040. called, but this can be used to change that name without starting a new
  24041. transaction.
  24042. */
  24043. void setCurrentTransactionName (const String& newName);
  24044. /** Returns true if there's at least one action in the list to undo.
  24045. @see getUndoDescription, undo, canRedo
  24046. */
  24047. bool canUndo() const;
  24048. /** Returns the description of the transaction that would be next to get undone.
  24049. The description returned is the one that was passed into beginNewTransaction
  24050. before the set of actions was performed.
  24051. @see undo
  24052. */
  24053. const String getUndoDescription() const;
  24054. /** Tries to roll-back the last transaction.
  24055. @returns true if the transaction can be undone, and false if it fails, or
  24056. if there aren't any transactions to undo
  24057. */
  24058. bool undo();
  24059. /** Tries to roll-back any actions that were added to the current transaction.
  24060. This will perform an undo() only if there are some actions in the undo list
  24061. that were added after the last call to beginNewTransaction().
  24062. This is useful because it lets you call beginNewTransaction(), then
  24063. perform an operation which may or may not actually perform some actions, and
  24064. then call this method to get rid of any actions that might have been done
  24065. without it rolling back the previous transaction if nothing was actually
  24066. done.
  24067. @returns true if any actions were undone.
  24068. */
  24069. bool undoCurrentTransactionOnly();
  24070. /** Returns a list of the UndoableAction objects that have been performed during the
  24071. transaction that is currently open.
  24072. Effectively, this is the list of actions that would be undone if undoCurrentTransactionOnly()
  24073. were to be called now.
  24074. The first item in the list is the earliest action performed.
  24075. */
  24076. void getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const;
  24077. /** Returns true if there's at least one action in the list to redo.
  24078. @see getRedoDescription, redo, canUndo
  24079. */
  24080. bool canRedo() const;
  24081. /** Returns the description of the transaction that would be next to get redone.
  24082. The description returned is the one that was passed into beginNewTransaction
  24083. before the set of actions was performed.
  24084. @see redo
  24085. */
  24086. const String getRedoDescription() const;
  24087. /** Tries to redo the last transaction that was undone.
  24088. @returns true if the transaction can be redone, and false if it fails, or
  24089. if there aren't any transactions to redo
  24090. */
  24091. bool redo();
  24092. juce_UseDebuggingNewOperator
  24093. private:
  24094. OwnedArray <OwnedArray <UndoableAction> > transactions;
  24095. StringArray transactionNames;
  24096. String currentTransactionName;
  24097. int totalUnitsStored, maxNumUnitsToKeep, minimumTransactionsToKeep, nextIndex;
  24098. bool newTransaction, reentrancyCheck;
  24099. // disallow copy constructor
  24100. UndoManager (const UndoManager&);
  24101. const UndoManager& operator= (const UndoManager&);
  24102. };
  24103. #endif // __JUCE_UNDOMANAGER_JUCEHEADER__
  24104. /********* End of inlined file: juce_UndoManager.h *********/
  24105. class TextEditor;
  24106. class TextHolderComponent;
  24107. /**
  24108. Receives callbacks from a TextEditor component when it changes.
  24109. @see TextEditor::addListener
  24110. */
  24111. class JUCE_API TextEditorListener
  24112. {
  24113. public:
  24114. /** Destructor. */
  24115. virtual ~TextEditorListener() {}
  24116. /** Called when the user changes the text in some way. */
  24117. virtual void textEditorTextChanged (TextEditor& editor) = 0;
  24118. /** Called when the user presses the return key. */
  24119. virtual void textEditorReturnKeyPressed (TextEditor& editor) = 0;
  24120. /** Called when the user presses the escape key. */
  24121. virtual void textEditorEscapeKeyPressed (TextEditor& editor) = 0;
  24122. /** Called when the text editor loses focus. */
  24123. virtual void textEditorFocusLost (TextEditor& editor) = 0;
  24124. };
  24125. /**
  24126. A component containing text that can be edited.
  24127. A TextEditor can either be in single- or multi-line mode, and supports mixed
  24128. fonts and colours.
  24129. @see TextEditorListener, Label
  24130. */
  24131. class JUCE_API TextEditor : public Component,
  24132. public SettableTooltipClient
  24133. {
  24134. public:
  24135. /** Creates a new, empty text editor.
  24136. @param componentName the name to pass to the component for it to use as its name
  24137. @param passwordCharacter if this is not zero, this character will be used as a replacement
  24138. for all characters that are drawn on screen - e.g. to create
  24139. a password-style textbox containing circular blobs instead of text,
  24140. you could set this value to 0x25cf, which is the unicode character
  24141. for a black splodge (not all fonts include this, though), or 0x2022,
  24142. which is a bullet (probably the best choice for linux).
  24143. */
  24144. TextEditor (const String& componentName = String::empty,
  24145. const tchar passwordCharacter = 0);
  24146. /** Destructor. */
  24147. virtual ~TextEditor();
  24148. /** Puts the editor into either multi- or single-line mode.
  24149. By default, the editor will be in single-line mode, so use this if you need a multi-line
  24150. editor.
  24151. See also the setReturnKeyStartsNewLine() method, which will also need to be turned
  24152. on if you want a multi-line editor with line-breaks.
  24153. @see isMultiLine, setReturnKeyStartsNewLine
  24154. */
  24155. void setMultiLine (const bool shouldBeMultiLine,
  24156. const bool shouldWordWrap = true);
  24157. /** Returns true if the editor is in multi-line mode.
  24158. */
  24159. bool isMultiLine() const throw();
  24160. /** Changes the behaviour of the return key.
  24161. If set to true, the return key will insert a new-line into the text; if false
  24162. it will trigger a call to the TextEditorListener::textEditorReturnKeyPressed()
  24163. method. By default this is set to false, and when true it will only insert
  24164. new-lines when in multi-line mode (see setMultiLine()).
  24165. */
  24166. void setReturnKeyStartsNewLine (const bool shouldStartNewLine);
  24167. /** Returns the value set by setReturnKeyStartsNewLine().
  24168. See setReturnKeyStartsNewLine() for more info.
  24169. */
  24170. bool getReturnKeyStartsNewLine() const throw() { return returnKeyStartsNewLine; }
  24171. /** Indicates whether the tab key should be accepted and used to input a tab character,
  24172. or whether it gets ignored.
  24173. By default the tab key is ignored, so that it can be used to switch keyboard focus
  24174. between components.
  24175. */
  24176. void setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed) throw();
  24177. /** Returns true if the tab key is being used for input.
  24178. @see setTabKeyUsedAsCharacter
  24179. */
  24180. bool isTabKeyUsedAsCharacter() const throw() { return tabKeyUsed; }
  24181. /** Changes the editor to read-only mode.
  24182. By default, the text editor is not read-only. If you're making it read-only, you
  24183. might also want to call setCaretVisible (false) to get rid of the caret.
  24184. The text can still be highlighted and copied when in read-only mode.
  24185. @see isReadOnly, setCaretVisible
  24186. */
  24187. void setReadOnly (const bool shouldBeReadOnly);
  24188. /** Returns true if the editor is in read-only mode.
  24189. */
  24190. bool isReadOnly() const throw();
  24191. /** Makes the caret visible or invisible.
  24192. By default the caret is visible.
  24193. @see setCaretColour, setCaretPosition
  24194. */
  24195. void setCaretVisible (const bool shouldBeVisible) throw();
  24196. /** Returns true if the caret is enabled.
  24197. @see setCaretVisible
  24198. */
  24199. bool isCaretVisible() const throw() { return caretVisible; }
  24200. /** Enables/disables a vertical scrollbar.
  24201. (This only applies when in multi-line mode). When the text gets too long to fit
  24202. in the component, a scrollbar can appear to allow it to be scrolled. Even when
  24203. this is enabled, the scrollbar will be hidden unless it's needed.
  24204. By default the scrollbar is enabled.
  24205. */
  24206. void setScrollbarsShown (bool shouldBeEnabled) throw();
  24207. /** Returns true if scrollbars are enabled.
  24208. @see setScrollbarsShown
  24209. */
  24210. bool areScrollbarsShown() const throw() { return scrollbarVisible; }
  24211. /** Changes the password character used to disguise the text.
  24212. @param passwordCharacter if this is not zero, this character will be used as a replacement
  24213. for all characters that are drawn on screen - e.g. to create
  24214. a password-style textbox containing circular blobs instead of text,
  24215. you could set this value to 0x25cf, which is the unicode character
  24216. for a black splodge (not all fonts include this, though), or 0x2022,
  24217. which is a bullet (probably the best choice for linux).
  24218. */
  24219. void setPasswordCharacter (const tchar passwordCharacter) throw();
  24220. /** Returns the current password character.
  24221. @see setPasswordCharacter
  24222. l */
  24223. tchar getPasswordCharacter() const throw() { return passwordCharacter; }
  24224. /** Allows a right-click menu to appear for the editor.
  24225. (This defaults to being enabled).
  24226. If enabled, right-clicking (or command-clicking on the Mac) will pop up a menu
  24227. of options such as cut/copy/paste, undo/redo, etc.
  24228. */
  24229. void setPopupMenuEnabled (const bool menuEnabled) throw();
  24230. /** Returns true if the right-click menu is enabled.
  24231. @see setPopupMenuEnabled
  24232. */
  24233. bool isPopupMenuEnabled() const throw() { return popupMenuEnabled; }
  24234. /** Returns true if a popup-menu is currently being displayed.
  24235. */
  24236. bool isPopupMenuCurrentlyActive() const throw() { return menuActive; }
  24237. /** A set of colour IDs to use to change the colour of various aspects of the editor.
  24238. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  24239. methods.
  24240. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  24241. */
  24242. enum ColourIds
  24243. {
  24244. backgroundColourId = 0x1000200, /**< The colour to use for the text component's background - this can be
  24245. transparent if necessary. */
  24246. textColourId = 0x1000201, /**< The colour that will be used when text is added to the editor. Note
  24247. that because the editor can contain multiple colours, calling this
  24248. method won't change the colour of existing text - to do that, call
  24249. applyFontToAllText() after calling this method.*/
  24250. highlightColourId = 0x1000202, /**< The colour with which to fill the background of highlighted sections of
  24251. the text - this can be transparent if you don't want to show any
  24252. highlighting.*/
  24253. highlightedTextColourId = 0x1000203, /**< The colour with which to draw the text in highlighted sections. */
  24254. caretColourId = 0x1000204, /**< The colour with which to draw the caret. */
  24255. outlineColourId = 0x1000205, /**< If this is non-transparent, it will be used to draw a box around
  24256. the edge of the component. */
  24257. focusedOutlineColourId = 0x1000206, /**< If this is non-transparent, it will be used to draw a box around
  24258. the edge of the component when it has focus. */
  24259. shadowColourId = 0x1000207, /**< If this is non-transparent, it'll be used to draw an inner shadow
  24260. around the edge of the editor. */
  24261. };
  24262. /** Sets the font to use for newly added text.
  24263. This will change the font that will be used next time any text is added or entered
  24264. into the editor. It won't change the font of any existing text - to do that, use
  24265. applyFontToAllText() instead.
  24266. @see applyFontToAllText
  24267. */
  24268. void setFont (const Font& newFont) throw();
  24269. /** Applies a font to all the text in the editor.
  24270. This will also set the current font to use for any new text that's added.
  24271. @see setFont
  24272. */
  24273. void applyFontToAllText (const Font& newFont);
  24274. /** Returns the font that's currently being used for new text.
  24275. @see setFont
  24276. */
  24277. const Font getFont() const throw();
  24278. /** If set to true, focusing on the editor will highlight all its text.
  24279. (Set to false by default).
  24280. This is useful for boxes where you expect the user to re-enter all the
  24281. text when they focus on the component, rather than editing what's already there.
  24282. */
  24283. void setSelectAllWhenFocused (const bool b) throw();
  24284. /** Sets limits on the characters that can be entered.
  24285. @param maxTextLength if this is > 0, it sets a maximum length limit; if 0, no
  24286. limit is set
  24287. @param allowedCharacters if this is non-empty, then only characters that occur in
  24288. this string are allowed to be entered into the editor.
  24289. */
  24290. void setInputRestrictions (const int maxTextLength,
  24291. const String& allowedCharacters = String::empty) throw();
  24292. /** When the text editor is empty, it can be set to display a message.
  24293. This is handy for things like telling the user what to type in the box - the
  24294. string is only displayed, it's not taken to actually be the contents of
  24295. the editor.
  24296. */
  24297. void setTextToShowWhenEmpty (const String& text, const Colour& colourToUse) throw();
  24298. /** Changes the size of the scrollbars that are used.
  24299. Handy if you need smaller scrollbars for a small text box.
  24300. */
  24301. void setScrollBarThickness (const int newThicknessPixels);
  24302. /** Shows or hides the buttons on any scrollbars that are used.
  24303. @see ScrollBar::setButtonVisibility
  24304. */
  24305. void setScrollBarButtonVisibility (const bool buttonsVisible);
  24306. /** Registers a listener to be told when things happen to the text.
  24307. @see removeListener
  24308. */
  24309. void addListener (TextEditorListener* const newListener) throw();
  24310. /** Deregisters a listener.
  24311. @see addListener
  24312. */
  24313. void removeListener (TextEditorListener* const listenerToRemove) throw();
  24314. /** Returns the entire contents of the editor. */
  24315. const String getText() const throw();
  24316. /** Returns a section of the contents of the editor. */
  24317. const String getTextSubstring (const int startCharacter, const int endCharacter) const throw();
  24318. /** Returns true if there are no characters in the editor.
  24319. This is more efficient than calling getText().isEmpty().
  24320. */
  24321. bool isEmpty() const throw();
  24322. /** Sets the entire content of the editor.
  24323. This will clear the editor and insert the given text (using the current text colour
  24324. and font). You can set the current text colour using
  24325. @code setColour (TextEditor::textColourId, ...);
  24326. @endcode
  24327. @param newText the text to add
  24328. @param sendTextChangeMessage if true, this will cause a change message to
  24329. be sent to all the listeners.
  24330. @see insertText
  24331. */
  24332. void setText (const String& newText,
  24333. const bool sendTextChangeMessage = true);
  24334. /** Inserts some text at the current cursor position.
  24335. If a section of the text is highlighted, it will be replaced by
  24336. this string, otherwise it will be inserted.
  24337. To delete a section of text, you can use setHighlightedRegion() to
  24338. highlight it, and call insertTextAtCursor (String::empty).
  24339. @see setCaretPosition, getCaretPosition, setHighlightedRegion
  24340. */
  24341. void insertTextAtCursor (String textToInsert);
  24342. /** Deletes all the text from the editor. */
  24343. void clear();
  24344. /** Deletes the currently selected region, and puts it on the clipboard.
  24345. @see copy, paste, SystemClipboard
  24346. */
  24347. void cut();
  24348. /** Copies any currently selected region to the clipboard.
  24349. @see cut, paste, SystemClipboard
  24350. */
  24351. void copy();
  24352. /** Pastes the contents of the clipboard into the editor at the cursor position.
  24353. @see cut, copy, SystemClipboard
  24354. */
  24355. void paste();
  24356. /** Moves the caret to be in front of a given character.
  24357. @see getCaretPosition
  24358. */
  24359. void setCaretPosition (const int newIndex) throw();
  24360. /** Returns the current index of the caret.
  24361. @see setCaretPosition
  24362. */
  24363. int getCaretPosition() const throw();
  24364. /** Selects a section of the text.
  24365. */
  24366. void setHighlightedRegion (int startIndex,
  24367. int numberOfCharactersToHighlight) throw();
  24368. /** Returns the first character that is selected.
  24369. If nothing is selected, this will still return a character index, but getHighlightedRegionLength()
  24370. will return 0.
  24371. @see setHighlightedRegion, getHighlightedRegionLength
  24372. */
  24373. int getHighlightedRegionStart() const throw() { return selectionStart; }
  24374. /** Returns the number of characters that are selected.
  24375. @see setHighlightedRegion, getHighlightedRegionStart
  24376. */
  24377. int getHighlightedRegionLength() const throw() { return jmax (0, selectionEnd - selectionStart); }
  24378. /** Returns the section of text that is currently selected. */
  24379. const String getHighlightedText() const throw();
  24380. /** Finds the index of the character at a given position.
  24381. The co-ordinates are relative to the component's top-left.
  24382. */
  24383. int getTextIndexAt (const int x, const int y) throw();
  24384. /** Returns the total width of the text, as it is currently laid-out.
  24385. This may be larger than the size of the TextEditor, and can change when
  24386. the TextEditor is resized or the text changes.
  24387. */
  24388. int getTextWidth() const throw();
  24389. /** Returns the maximum height of the text, as it is currently laid-out.
  24390. This may be larger than the size of the TextEditor, and can change when
  24391. the TextEditor is resized or the text changes.
  24392. */
  24393. int getTextHeight() const throw();
  24394. /** Changes the size of the gap at the top and left-edge of the editor.
  24395. By default there's a gap of 4 pixels.
  24396. */
  24397. void setIndents (const int newLeftIndent, const int newTopIndent) throw();
  24398. /** Changes the size of border left around the edge of the component.
  24399. @see getBorder
  24400. */
  24401. void setBorder (const BorderSize& border) throw();
  24402. /** Returns the size of border around the edge of the component.
  24403. @see setBorder
  24404. */
  24405. const BorderSize getBorder() const throw();
  24406. /** Used to disable the auto-scrolling which keeps the cursor visible.
  24407. If true (the default), the editor will scroll when the cursor moves offscreen. If
  24408. set to false, it won't.
  24409. */
  24410. void setScrollToShowCursor (const bool shouldScrollToShowCursor) throw();
  24411. /** @internal */
  24412. void paint (Graphics& g);
  24413. /** @internal */
  24414. void paintOverChildren (Graphics& g);
  24415. /** @internal */
  24416. void mouseDown (const MouseEvent& e);
  24417. /** @internal */
  24418. void mouseUp (const MouseEvent& e);
  24419. /** @internal */
  24420. void mouseDrag (const MouseEvent& e);
  24421. /** @internal */
  24422. void mouseDoubleClick (const MouseEvent& e);
  24423. /** @internal */
  24424. void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  24425. /** @internal */
  24426. bool keyPressed (const KeyPress& key);
  24427. /** @internal */
  24428. bool keyStateChanged();
  24429. /** @internal */
  24430. void focusGained (FocusChangeType cause);
  24431. /** @internal */
  24432. void focusLost (FocusChangeType cause);
  24433. /** @internal */
  24434. void resized();
  24435. /** @internal */
  24436. void enablementChanged();
  24437. /** @internal */
  24438. void colourChanged();
  24439. juce_UseDebuggingNewOperator
  24440. protected:
  24441. /** This adds the items to the popup menu.
  24442. By default it adds the cut/copy/paste items, but you can override this if
  24443. you need to replace these with your own items.
  24444. If you want to add your own items to the existing ones, you can override this,
  24445. call the base class's addPopupMenuItems() method, then append your own items.
  24446. When the menu has been shown, performPopupMenuAction() will be called to
  24447. perform the item that the user has chosen.
  24448. The default menu items will be added using item IDs in the range
  24449. 0x7fff0000 - 0x7fff1000, so you should avoid those values for your own
  24450. menu IDs.
  24451. If this was triggered by a mouse-click, the mouseClickEvent parameter will be
  24452. a pointer to the info about it, or may be null if the menu is being triggered
  24453. by some other means.
  24454. @see performPopupMenuAction, setPopupMenuEnabled, isPopupMenuEnabled
  24455. */
  24456. virtual void addPopupMenuItems (PopupMenu& menuToAddTo,
  24457. const MouseEvent* mouseClickEvent);
  24458. /** This is called to perform one of the items that was shown on the popup menu.
  24459. If you've overridden addPopupMenuItems(), you should also override this
  24460. to perform the actions that you've added.
  24461. If you've overridden addPopupMenuItems() but have still left the default items
  24462. on the menu, remember to call the superclass's performPopupMenuAction()
  24463. so that it can perform the default actions if that's what the user clicked on.
  24464. @see addPopupMenuItems, setPopupMenuEnabled, isPopupMenuEnabled
  24465. */
  24466. virtual void performPopupMenuAction (const int menuItemID);
  24467. /** Scrolls the minimum distance needed to get the caret into view. */
  24468. void scrollToMakeSureCursorIsVisible() throw();
  24469. /** @internal */
  24470. void moveCaret (int newCaretPos) throw();
  24471. /** @internal */
  24472. void moveCursorTo (const int newPosition, const bool isSelecting) throw();
  24473. /** Used internally to dispatch a text-change message. */
  24474. void textChanged() throw();
  24475. /** Counts the number of characters in the text.
  24476. This is quicker than getting the text as a string if you just need to know
  24477. the length.
  24478. */
  24479. int getTotalNumChars() throw();
  24480. /** Begins a new transaction in the UndoManager.
  24481. */
  24482. void newTransaction() throw();
  24483. /** Used internally to trigger an undo or redo. */
  24484. void doUndoRedo (const bool isRedo);
  24485. /** Can be overridden to intercept return key presses directly */
  24486. virtual void returnPressed();
  24487. /** Can be overridden to intercept escape key presses directly */
  24488. virtual void escapePressed();
  24489. /** @internal */
  24490. void handleCommandMessage (int commandId);
  24491. private:
  24492. Viewport* viewport;
  24493. TextHolderComponent* textHolder;
  24494. BorderSize borderSize;
  24495. bool readOnly : 1;
  24496. bool multiline : 1;
  24497. bool wordWrap : 1;
  24498. bool returnKeyStartsNewLine : 1;
  24499. bool caretVisible : 1;
  24500. bool popupMenuEnabled : 1;
  24501. bool selectAllTextWhenFocused : 1;
  24502. bool scrollbarVisible : 1;
  24503. bool wasFocused : 1;
  24504. bool caretFlashState : 1;
  24505. bool keepCursorOnScreen : 1;
  24506. bool tabKeyUsed : 1;
  24507. bool menuActive : 1;
  24508. UndoManager undoManager;
  24509. float cursorX, cursorY, cursorHeight;
  24510. int maxTextLength;
  24511. int selectionStart, selectionEnd;
  24512. int leftIndent, topIndent;
  24513. unsigned int lastTransactionTime;
  24514. Font currentFont;
  24515. int totalNumChars, caretPosition;
  24516. VoidArray sections;
  24517. String textToShowWhenEmpty;
  24518. Colour colourForTextWhenEmpty;
  24519. tchar passwordCharacter;
  24520. enum
  24521. {
  24522. notDragging,
  24523. draggingSelectionStart,
  24524. draggingSelectionEnd
  24525. } dragType;
  24526. String allowedCharacters;
  24527. SortedSet <void*> listeners;
  24528. friend class TextEditorInsertAction;
  24529. friend class TextEditorRemoveAction;
  24530. void coalesceSimilarSections() throw();
  24531. void splitSection (const int sectionIndex, const int charToSplitAt) throw();
  24532. void clearInternal (UndoManager* const um) throw();
  24533. void insert (const String& text,
  24534. const int insertIndex,
  24535. const Font& font,
  24536. const Colour& colour,
  24537. UndoManager* const um,
  24538. const int caretPositionToMoveTo) throw();
  24539. void reinsert (const int insertIndex,
  24540. const VoidArray& sections) throw();
  24541. void remove (const int startIndex,
  24542. int endIndex,
  24543. UndoManager* const um,
  24544. const int caretPositionToMoveTo) throw();
  24545. void getCharPosition (const int index,
  24546. float& x, float& y,
  24547. float& lineHeight) const throw();
  24548. int indexAtPosition (const float x,
  24549. const float y) throw();
  24550. int findWordBreakAfter (const int position) const throw();
  24551. int findWordBreakBefore (const int position) const throw();
  24552. friend class TextHolderComponent;
  24553. friend class TextEditorViewport;
  24554. void drawContent (Graphics& g);
  24555. void updateTextHolderSize() throw();
  24556. float getWordWrapWidth() const throw();
  24557. void timerCallbackInt();
  24558. void repaintCaret();
  24559. void repaintText (int textStartIndex, int textEndIndex);
  24560. TextEditor (const TextEditor&);
  24561. const TextEditor& operator= (const TextEditor&);
  24562. };
  24563. #endif // __JUCE_TEXTEDITOR_JUCEHEADER__
  24564. /********* End of inlined file: juce_TextEditor.h *********/
  24565. class Label;
  24566. /**
  24567. A class for receiving events from a Label.
  24568. You can register a LabelListener with a Label using the Label::addListener()
  24569. method, and it will be called when the text of the label changes, either because
  24570. of a call to Label::setText() or by the user editing the text (if the label is
  24571. editable).
  24572. @see Label::addListener, Label::removeListener
  24573. */
  24574. class JUCE_API LabelListener
  24575. {
  24576. public:
  24577. /** Destructor. */
  24578. virtual ~LabelListener() {}
  24579. /** Called when a Label's text has changed.
  24580. */
  24581. virtual void labelTextChanged (Label* labelThatHasChanged) = 0;
  24582. };
  24583. /**
  24584. A component that displays a text string, and can optionally become a text
  24585. editor when clicked.
  24586. */
  24587. class JUCE_API Label : public Component,
  24588. public SettableTooltipClient,
  24589. protected TextEditorListener,
  24590. private ComponentListener,
  24591. private AsyncUpdater
  24592. {
  24593. public:
  24594. /** Creates a Label.
  24595. @param componentName the name to give the component
  24596. @param labelText the text to show in the label
  24597. */
  24598. Label (const String& componentName,
  24599. const String& labelText);
  24600. /** Destructor. */
  24601. ~Label();
  24602. /** Changes the label text.
  24603. If broadcastChangeMessage is true and the new text is different to the current
  24604. text, then the class will broadcast a change message to any LabelListeners that
  24605. are registered.
  24606. */
  24607. void setText (const String& newText,
  24608. const bool broadcastChangeMessage);
  24609. /** Returns the label's current text.
  24610. @param returnActiveEditorContents if this is true and the label is currently
  24611. being edited, then this method will return the
  24612. text as it's being shown in the editor. If false,
  24613. then the value returned here won't be updated until
  24614. the user has finished typing and pressed the return
  24615. key.
  24616. */
  24617. const String getText (const bool returnActiveEditorContents = false) const throw();
  24618. /** Changes the font to use to draw the text.
  24619. @see getFont
  24620. */
  24621. void setFont (const Font& newFont) throw();
  24622. /** Returns the font currently being used.
  24623. @see setFont
  24624. */
  24625. const Font& getFont() const throw();
  24626. /** A set of colour IDs to use to change the colour of various aspects of the label.
  24627. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  24628. methods.
  24629. Note that you can also use the constants from TextEditor::ColourIds to change the
  24630. colour of the text editor that is opened when a label is editable.
  24631. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  24632. */
  24633. enum ColourIds
  24634. {
  24635. backgroundColourId = 0x1000280, /**< The background colour to fill the label with. */
  24636. textColourId = 0x1000281, /**< The colour for the text. */
  24637. outlineColourId = 0x1000282 /**< An optional colour to use to draw a border around the label.
  24638. Leave this transparent to not have an outline. */
  24639. };
  24640. /** Sets the style of justification to be used for positioning the text.
  24641. (The default is Justification::centredLeft)
  24642. */
  24643. void setJustificationType (const Justification& justification) throw();
  24644. /** Returns the type of justification, as set in setJustificationType(). */
  24645. const Justification getJustificationType() const throw() { return justification; }
  24646. /** Makes this label "stick to" another component.
  24647. This will cause the label to follow another component around, staying
  24648. either to its left or above it.
  24649. @param owner the component to follow
  24650. @param onLeft if true, the label will stay on the left of its component; if
  24651. false, it will stay above it.
  24652. */
  24653. void attachToComponent (Component* owner,
  24654. const bool onLeft);
  24655. /** If this label has been attached to another component using attachToComponent, this
  24656. returns the other component.
  24657. Returns 0 if the label is not attached.
  24658. */
  24659. Component* getAttachedComponent() const throw() { return ownerComponent; }
  24660. /** If the label is attached to the left of another component, this returns true.
  24661. Returns false if the label is above the other component. This is only relevent if
  24662. attachToComponent() has been called.
  24663. */
  24664. bool isAttachedOnLeft() const throw() { return leftOfOwnerComp; }
  24665. /** Registers a listener that will be called when the label's text changes. */
  24666. void addListener (LabelListener* const listener) throw();
  24667. /** Deregisters a previously-registered listener. */
  24668. void removeListener (LabelListener* const listener) throw();
  24669. /** Makes the label turn into a TextEditor when clicked.
  24670. By default this is turned off.
  24671. If turned on, then single- or double-clicking will turn the label into
  24672. an editor. If the user then changes the text, then the ChangeBroadcaster
  24673. base class will be used to send change messages to any listeners that
  24674. have registered.
  24675. If the user changes the text, the textWasEdited() method will be called
  24676. afterwards, and subclasses can override this if they need to do anything
  24677. special.
  24678. @param editOnSingleClick if true, just clicking once on the label will start editing the text
  24679. @param editOnDoubleClick if true, a double-click is needed to start editing
  24680. @param lossOfFocusDiscardsChanges if true, clicking somewhere else while the text is being
  24681. edited will discard any changes; if false, then this will
  24682. commit the changes.
  24683. @see showEditor, setEditorColours, TextEditor
  24684. */
  24685. void setEditable (const bool editOnSingleClick,
  24686. const bool editOnDoubleClick = false,
  24687. const bool lossOfFocusDiscardsChanges = false) throw();
  24688. /** Returns true if this option was set using setEditable(). */
  24689. bool isEditableOnSingleClick() const throw() { return editSingleClick; }
  24690. /** Returns true if this option was set using setEditable(). */
  24691. bool isEditableOnDoubleClick() const throw() { return editDoubleClick; }
  24692. /** Returns true if this option has been set in a call to setEditable(). */
  24693. bool doesLossOfFocusDiscardChanges() const throw() { return lossOfFocusDiscardsChanges; }
  24694. /** Returns true if the user can edit this label's text. */
  24695. bool isEditable() const throw() { return editSingleClick || editDoubleClick; }
  24696. /** Makes the editor appear as if the label had been clicked by the user.
  24697. @see textWasEdited, setEditable
  24698. */
  24699. void showEditor();
  24700. /** Hides the editor if it was being shown.
  24701. @param discardCurrentEditorContents if true, the label's text will be
  24702. reset to whatever it was before the editor
  24703. was shown; if false, the current contents of the
  24704. editor will be used to set the label's text
  24705. before it is hidden.
  24706. */
  24707. void hideEditor (const bool discardCurrentEditorContents);
  24708. /** Returns true if the editor is currently focused and active. */
  24709. bool isBeingEdited() const throw();
  24710. juce_UseDebuggingNewOperator
  24711. protected:
  24712. /** @internal */
  24713. void paint (Graphics& g);
  24714. /** @internal */
  24715. void resized();
  24716. /** @internal */
  24717. void mouseUp (const MouseEvent& e);
  24718. /** @internal */
  24719. void mouseDoubleClick (const MouseEvent& e);
  24720. /** @internal */
  24721. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  24722. /** @internal */
  24723. void componentParentHierarchyChanged (Component& component);
  24724. /** @internal */
  24725. void componentVisibilityChanged (Component& component);
  24726. /** @internal */
  24727. void inputAttemptWhenModal();
  24728. /** @internal */
  24729. void focusGained (FocusChangeType);
  24730. /** @internal */
  24731. void enablementChanged();
  24732. /** @internal */
  24733. KeyboardFocusTraverser* createFocusTraverser();
  24734. /** @internal */
  24735. void textEditorTextChanged (TextEditor& editor);
  24736. /** @internal */
  24737. void textEditorReturnKeyPressed (TextEditor& editor);
  24738. /** @internal */
  24739. void textEditorEscapeKeyPressed (TextEditor& editor);
  24740. /** @internal */
  24741. void textEditorFocusLost (TextEditor& editor);
  24742. /** @internal */
  24743. void handleAsyncUpdate();
  24744. /** @internal */
  24745. void colourChanged();
  24746. /** Creates the TextEditor component that will be used when the user has clicked on the label.
  24747. Subclasses can override this if they need to customise this component in some way.
  24748. */
  24749. virtual TextEditor* createEditorComponent();
  24750. /** Called after the user changes the text.
  24751. */
  24752. virtual void textWasEdited();
  24753. private:
  24754. String text;
  24755. Font font;
  24756. Justification justification;
  24757. TextEditor* editor;
  24758. SortedSet <void*> listeners;
  24759. Component* ownerComponent;
  24760. ComponentDeletionWatcher* deletionWatcher;
  24761. bool editSingleClick : 1;
  24762. bool editDoubleClick : 1;
  24763. bool lossOfFocusDiscardsChanges : 1;
  24764. bool leftOfOwnerComp : 1;
  24765. bool updateFromTextEditorContents();
  24766. Label (const Label&);
  24767. const Label& operator= (const Label&);
  24768. };
  24769. #endif // __JUCE_LABEL_JUCEHEADER__
  24770. /********* End of inlined file: juce_Label.h *********/
  24771. class ComboBox;
  24772. /**
  24773. A class for receiving events from a ComboBox.
  24774. You can register a ComboBoxListener with a ComboBox using the ComboBox::addListener()
  24775. method, and it will be called when the selected item in the box changes.
  24776. @see ComboBox::addListener, ComboBox::removeListener
  24777. */
  24778. class JUCE_API ComboBoxListener
  24779. {
  24780. public:
  24781. /** Destructor. */
  24782. virtual ~ComboBoxListener() {}
  24783. /** Called when a ComboBox has its selected item changed.
  24784. */
  24785. virtual void comboBoxChanged (ComboBox* comboBoxThatHasChanged) = 0;
  24786. };
  24787. /**
  24788. A component that lets the user choose from a drop-down list of choices.
  24789. The combo-box has a list of text strings, each with an associated id number,
  24790. that will be shown in the drop-down list when the user clicks on the component.
  24791. The currently selected choice is displayed in the combo-box, and this can
  24792. either be read-only text, or editable.
  24793. To find out when the user selects a different item or edits the text, you
  24794. can register a ComboBoxListener to receive callbacks.
  24795. @see ComboBoxListener
  24796. */
  24797. class JUCE_API ComboBox : public Component,
  24798. public SettableTooltipClient,
  24799. private LabelListener,
  24800. private AsyncUpdater
  24801. {
  24802. public:
  24803. /** Creates a combo-box.
  24804. On construction, the text field will be empty, so you should call the
  24805. setSelectedId() or setText() method to choose the initial value before
  24806. displaying it.
  24807. @param componentName the name to set for the component (see Component::setName())
  24808. */
  24809. ComboBox (const String& componentName);
  24810. /** Destructor. */
  24811. ~ComboBox();
  24812. /** Sets whether the test in the combo-box is editable.
  24813. The default state for a new ComboBox is non-editable, and can only be changed
  24814. by choosing from the drop-down list.
  24815. */
  24816. void setEditableText (const bool isEditable);
  24817. /** Returns true if the text is directly editable.
  24818. @see setEditableText
  24819. */
  24820. bool isTextEditable() const throw();
  24821. /** Sets the style of justification to be used for positioning the text.
  24822. The default is Justification::centredLeft. The text is displayed using a
  24823. Label component inside the ComboBox.
  24824. */
  24825. void setJustificationType (const Justification& justification) throw();
  24826. /** Returns the current justification for the text box.
  24827. @see setJustificationType
  24828. */
  24829. const Justification getJustificationType() const throw();
  24830. /** Adds an item to be shown in the drop-down list.
  24831. @param newItemText the text of the item to show in the list
  24832. @param newItemId an associated ID number that can be set or retrieved - see
  24833. getSelectedId() and setSelectedId()
  24834. @see setItemEnabled, addSeparator, addSectionHeading, removeItem, getNumItems, getItemText, getItemId
  24835. */
  24836. void addItem (const String& newItemText,
  24837. const int newItemId) throw();
  24838. /** Adds a separator line to the drop-down list.
  24839. This is like adding a separator to a popup menu. See PopupMenu::addSeparator().
  24840. */
  24841. void addSeparator() throw();
  24842. /** Adds a heading to the drop-down list, so that you can group the items into
  24843. different sections.
  24844. The headings are indented slightly differently to set them apart from the
  24845. items on the list, and obviously can't be selected. You might want to add
  24846. separators between your sections too.
  24847. @see addItem, addSeparator
  24848. */
  24849. void addSectionHeading (const String& headingName) throw();
  24850. /** This allows items in the drop-down list to be selectively disabled.
  24851. When you add an item, it's enabled by default, but you can call this
  24852. method to change its status.
  24853. If you disable an item which is already selected, this won't change the
  24854. current selection - it just stops the user choosing that item from the list.
  24855. */
  24856. void setItemEnabled (const int itemId,
  24857. const bool isEnabled) throw();
  24858. /** Changes the text for an existing item.
  24859. */
  24860. void changeItemText (const int itemId,
  24861. const String& newText) throw();
  24862. /** Removes all the items from the drop-down list.
  24863. If this call causes the content to be cleared, then a change-message
  24864. will be broadcast unless dontSendChangeMessage is true.
  24865. @see addItem, removeItem, getNumItems
  24866. */
  24867. void clear (const bool dontSendChangeMessage = false);
  24868. /** Returns the number of items that have been added to the list.
  24869. Note that this doesn't include headers or separators.
  24870. */
  24871. int getNumItems() const throw();
  24872. /** Returns the text for one of the items in the list.
  24873. Note that this doesn't include headers or separators.
  24874. @param index the item's index from 0 to (getNumItems() - 1)
  24875. */
  24876. const String getItemText (const int index) const throw();
  24877. /** Returns the ID for one of the items in the list.
  24878. Note that this doesn't include headers or separators.
  24879. @param index the item's index from 0 to (getNumItems() - 1)
  24880. */
  24881. int getItemId (const int index) const throw();
  24882. /** Returns the ID of the item that's currently shown in the box.
  24883. If no item is selected, or if the text is editable and the user
  24884. has entered something which isn't one of the items in the list, then
  24885. this will return 0.
  24886. @see setSelectedId, getSelectedItemIndex, getText
  24887. */
  24888. int getSelectedId() const throw();
  24889. /** Sets one of the items to be the current selection.
  24890. This will set the ComboBox's text to that of the item that matches
  24891. this ID.
  24892. @param newItemId the new item to select
  24893. @param dontSendChangeMessage if set to true, this method won't trigger a
  24894. change notification
  24895. @see getSelectedId, setSelectedItemIndex, setText
  24896. */
  24897. void setSelectedId (const int newItemId,
  24898. const bool dontSendChangeMessage = false) throw();
  24899. /** Returns the index of the item that's currently shown in the box.
  24900. If no item is selected, or if the text is editable and the user
  24901. has entered something which isn't one of the items in the list, then
  24902. this will return -1.
  24903. @see setSelectedItemIndex, getSelectedId, getText
  24904. */
  24905. int getSelectedItemIndex() const throw();
  24906. /** Sets one of the items to be the current selection.
  24907. This will set the ComboBox's text to that of the item at the given
  24908. index in the list.
  24909. @param newItemIndex the new item to select
  24910. @param dontSendChangeMessage if set to true, this method won't trigger a
  24911. change notification
  24912. @see getSelectedItemIndex, setSelectedId, setText
  24913. */
  24914. void setSelectedItemIndex (const int newItemIndex,
  24915. const bool dontSendChangeMessage = false) throw();
  24916. /** Returns the text that is currently shown in the combo-box's text field.
  24917. If the ComboBox has editable text, then this text may have been edited
  24918. by the user; otherwise it will be one of the items from the list, or
  24919. possibly an empty string if nothing was selected.
  24920. @see setText, getSelectedId, getSelectedItemIndex
  24921. */
  24922. const String getText() const throw();
  24923. /** Sets the contents of the combo-box's text field.
  24924. The text passed-in will be set as the current text regardless of whether
  24925. it is one of the items in the list. If the current text isn't one of the
  24926. items, then getSelectedId() will return -1, otherwise it wil return
  24927. the approriate ID.
  24928. @param newText the text to select
  24929. @param dontSendChangeMessage if set to true, this method won't trigger a
  24930. change notification
  24931. @see getText
  24932. */
  24933. void setText (const String& newText,
  24934. const bool dontSendChangeMessage = false) throw();
  24935. /** Programmatically opens the text editor to allow the user to edit the current item.
  24936. This is the same effect as when the box is clicked-on.
  24937. @see Label::showEditor();
  24938. */
  24939. void showEditor();
  24940. /** Registers a listener that will be called when the box's content changes. */
  24941. void addListener (ComboBoxListener* const listener) throw();
  24942. /** Deregisters a previously-registered listener. */
  24943. void removeListener (ComboBoxListener* const listener) throw();
  24944. /** Sets a message to display when there is no item currently selected.
  24945. @see getTextWhenNothingSelected
  24946. */
  24947. void setTextWhenNothingSelected (const String& newMessage) throw();
  24948. /** Returns the text that is shown when no item is selected.
  24949. @see setTextWhenNothingSelected
  24950. */
  24951. const String getTextWhenNothingSelected() const throw();
  24952. /** Sets the message to show when there are no items in the list, and the user clicks
  24953. on the drop-down box.
  24954. By default it just says "no choices", but this lets you change it to something more
  24955. meaningful.
  24956. */
  24957. void setTextWhenNoChoicesAvailable (const String& newMessage) throw();
  24958. /** Returns the text shown when no items have been added to the list.
  24959. @see setTextWhenNoChoicesAvailable
  24960. */
  24961. const String getTextWhenNoChoicesAvailable() const throw();
  24962. /** Gives the ComboBox a tooltip. */
  24963. void setTooltip (const String& newTooltip);
  24964. /** A set of colour IDs to use to change the colour of various aspects of the combo box.
  24965. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  24966. methods.
  24967. To change the colours of the menu that pops up
  24968. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  24969. */
  24970. enum ColourIds
  24971. {
  24972. backgroundColourId = 0x1000b00, /**< The background colour to fill the box with. */
  24973. textColourId = 0x1000a00, /**< The colour for the text in the box. */
  24974. outlineColourId = 0x1000c00, /**< The colour for an outline around the box. */
  24975. buttonColourId = 0x1000d00, /**< The base colour for the button (a LookAndFeel class will probably use variations on this). */
  24976. arrowColourId = 0x1000e00, /**< The colour for the arrow shape that pops up the menu */
  24977. };
  24978. /** @internal */
  24979. void labelTextChanged (Label*);
  24980. /** @internal */
  24981. void enablementChanged();
  24982. /** @internal */
  24983. void colourChanged();
  24984. /** @internal */
  24985. void focusGained (Component::FocusChangeType cause);
  24986. /** @internal */
  24987. void focusLost (Component::FocusChangeType cause);
  24988. /** @internal */
  24989. void handleAsyncUpdate();
  24990. /** @internal */
  24991. const String getTooltip() { return label->getTooltip(); }
  24992. /** @internal */
  24993. void mouseDown (const MouseEvent&);
  24994. /** @internal */
  24995. void mouseDrag (const MouseEvent&);
  24996. /** @internal */
  24997. void mouseUp (const MouseEvent&);
  24998. /** @internal */
  24999. void lookAndFeelChanged();
  25000. /** @internal */
  25001. void paint (Graphics&);
  25002. /** @internal */
  25003. void resized();
  25004. /** @internal */
  25005. bool keyStateChanged();
  25006. /** @internal */
  25007. bool keyPressed (const KeyPress&);
  25008. juce_UseDebuggingNewOperator
  25009. private:
  25010. struct ItemInfo
  25011. {
  25012. String name;
  25013. int itemId;
  25014. bool isEnabled : 1, isHeading : 1;
  25015. bool isSeparator() const throw();
  25016. bool isRealItem() const throw();
  25017. };
  25018. OwnedArray <ItemInfo> items;
  25019. int currentIndex;
  25020. bool isButtonDown;
  25021. bool separatorPending;
  25022. bool menuActive;
  25023. SortedSet <void*> listeners;
  25024. Label* label;
  25025. String textWhenNothingSelected, noChoicesMessage;
  25026. void showPopup();
  25027. ItemInfo* getItemForId (const int itemId) const throw();
  25028. ItemInfo* getItemForIndex (const int index) const throw();
  25029. ComboBox (const ComboBox&);
  25030. const ComboBox& operator= (const ComboBox&);
  25031. };
  25032. #endif // __JUCE_COMBOBOX_JUCEHEADER__
  25033. /********* End of inlined file: juce_ComboBox.h *********/
  25034. /**
  25035. Manages the state of some audio and midi i/o devices.
  25036. This class keeps tracks of a currently-selected audio device, through
  25037. with which it continuously streams data from an audio callback, as well as
  25038. one or more midi inputs.
  25039. The idea is that your application will create one global instance of this object,
  25040. and let it take care of creating and deleting specific types of audio devices
  25041. internally. So when the device is changed, your callbacks will just keep running
  25042. without having to worry about this.
  25043. The manager can save and reload all of its device settings as XML, which
  25044. makes it very easy for you to save and reload the audio setup of your
  25045. application.
  25046. And to make it easy to let the user change its settings, there's a component
  25047. to do just that - the AudioDeviceSelectorComponent class, which contains a set of
  25048. device selection/sample-rate/latency controls.
  25049. To use an AudioDeviceManager, create one, and use initialise() to set it up. Then
  25050. call setAudioCallback() to register your audio callback with it, and use that to process
  25051. your audio data.
  25052. The manager also acts as a handy hub for incoming midi messages, allowing a
  25053. listener to register for messages from either a specific midi device, or from whatever
  25054. the current default midi input device is. The listener then doesn't have to worry about
  25055. re-registering with different midi devices if they are changed or deleted.
  25056. And yet another neat trick is that amount of CPU time being used is measured and
  25057. available with the getCpuUsage() method.
  25058. The AudioDeviceManager is a ChangeBroadcaster, and will send a change message to
  25059. listeners whenever one of its settings is changed.
  25060. @see AudioDeviceSelectorComponent, AudioIODevice, AudioIODeviceType
  25061. */
  25062. class JUCE_API AudioDeviceManager : public ChangeBroadcaster
  25063. {
  25064. public:
  25065. /** Creates a default AudioDeviceManager.
  25066. Initially no audio device will be selected. You should call the initialise() method
  25067. and register an audio callback with setAudioCallback() before it'll be able to
  25068. actually make any noise.
  25069. */
  25070. AudioDeviceManager();
  25071. /** Destructor. */
  25072. ~AudioDeviceManager();
  25073. /** Opens a set of audio devices ready for use.
  25074. This will attempt to open either a default audio device, or one that was
  25075. previously saved as XML.
  25076. @param numInputChannelsNeeded a minimum number of input channels needed
  25077. by your app.
  25078. @param numOutputChannelsNeeded a minimum number of output channels to open
  25079. @param savedState either a previously-saved state that was produced
  25080. by createStateXml(), or 0 if you want the manager
  25081. to choose the best device to open.
  25082. @param selectDefaultDeviceOnFailure if true, then if the device specified in the XML
  25083. fails to open, then a default device will be used
  25084. instead. If false, then on failure, no device is
  25085. opened.
  25086. @param preferredDefaultDeviceName if this is not empty, and there's a device with this
  25087. name, then that will be used as the default device
  25088. (assuming that there wasn't one specified in the XML).
  25089. The string can actually be a simple wildcard, containing "*"
  25090. and "?" characters
  25091. @returns an error message if anything went wrong, or an empty string if it worked ok.
  25092. */
  25093. const String initialise (const int numInputChannelsNeeded,
  25094. const int numOutputChannelsNeeded,
  25095. const XmlElement* const savedState,
  25096. const bool selectDefaultDeviceOnFailure,
  25097. const String& preferredDefaultDeviceName = String::empty);
  25098. /** Returns some XML representing the current state of the manager.
  25099. This stores the current device, its samplerate, block size, etc, and
  25100. can be restored later with initialise().
  25101. */
  25102. XmlElement* createStateXml() const;
  25103. /**
  25104. */
  25105. struct AudioDeviceSetup
  25106. {
  25107. AudioDeviceSetup();
  25108. bool operator== (const AudioDeviceSetup& other) const;
  25109. /**
  25110. */
  25111. String outputDeviceName;
  25112. /**
  25113. */
  25114. String inputDeviceName;
  25115. /**
  25116. */
  25117. double sampleRate;
  25118. /**
  25119. */
  25120. int bufferSize;
  25121. /**
  25122. */
  25123. BitArray inputChannels;
  25124. bool useDefaultInputChannels;
  25125. /**
  25126. */
  25127. BitArray outputChannels;
  25128. bool useDefaultOutputChannels;
  25129. };
  25130. /**
  25131. */
  25132. void getAudioDeviceSetup (AudioDeviceSetup& setup);
  25133. /**
  25134. @param treatAsChosenDevice if this is true and if the device opens correctly, these new
  25135. settings will be taken as having been explicitly chosen by the
  25136. user, and the next time createStateXml() is called, these settings
  25137. will be returned. If it's false, then the device is treated as a
  25138. temporary or default device, and a call to createStateXml() will
  25139. return either the last settings that were made with treatAsChosenDevice
  25140. as true, or the last XML settings that were passed into initialise().
  25141. @returns an error message if anything went wrong, or an empty string if it worked ok.
  25142. */
  25143. const String setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  25144. const bool treatAsChosenDevice);
  25145. /** Returns the currently-active audio device. */
  25146. AudioIODevice* getCurrentAudioDevice() const throw() { return currentAudioDevice; }
  25147. const String getCurrentAudioDeviceType() const throw() { return currentDeviceType; }
  25148. void setCurrentAudioDeviceType (const String& type,
  25149. const bool treatAsChosenDevice);
  25150. /** Closes the currently-open device.
  25151. You can call restartLastAudioDevice() later to reopen it in the same state
  25152. that it was just in.
  25153. */
  25154. void closeAudioDevice();
  25155. /** Tries to reload the last audio device that was running.
  25156. Note that this only reloads the last device that was running before
  25157. closeAudioDevice() was called - it doesn't reload any kind of saved-state,
  25158. and can only be called after a device has been opened with SetAudioDevice().
  25159. If a device is already open, this call will do nothing.
  25160. */
  25161. void restartLastAudioDevice();
  25162. /** Gives the manager an audio callback to use.
  25163. The manager will redirect callbacks from whatever audio device is currently
  25164. in use to this callback object.
  25165. You can pass 0 in here to stop callbacks being made.
  25166. */
  25167. void setAudioCallback (AudioIODeviceCallback* newCallback);
  25168. /** Returns the average proportion of available CPU being spent inside the audio callbacks.
  25169. Returns a value between 0 and 1.0
  25170. */
  25171. double getCpuUsage() const;
  25172. /** Enables or disables a midi input device.
  25173. The list of devices can be obtained with the MidiInput::getDevices() method.
  25174. Any incoming messages from enabled input devices will be forwarded on to all the
  25175. listeners that have been registered with the addMidiInputCallback() method. They
  25176. can either register for messages from a particular device, or from just the
  25177. "default" midi input.
  25178. Routing the midi input via an AudioDeviceManager means that when a listener
  25179. registers for the default midi input, this default device can be changed by the
  25180. manager without the listeners having to know about it or re-register.
  25181. It also means that a listener can stay registered for a midi input that is disabled
  25182. or not present, so that when the input is re-enabled, the listener will start
  25183. receiving messages again.
  25184. @see addMidiInputCallback, isMidiInputEnabled
  25185. */
  25186. void setMidiInputEnabled (const String& midiInputDeviceName,
  25187. const bool enabled);
  25188. /** Returns true if a given midi input device is being used.
  25189. @see setMidiInputEnabled
  25190. */
  25191. bool isMidiInputEnabled (const String& midiInputDeviceName) const;
  25192. /** Registers a listener for callbacks when midi events arrive from a midi input.
  25193. The device name can be empty to indicate that it wants events from whatever the
  25194. current "default" device is. Or it can be the name of one of the midi input devices
  25195. (see MidiInput::getDevices() for the names).
  25196. Only devices which are enabled (see the setMidiInputEnabled() method) will have their
  25197. events forwarded on to listeners.
  25198. */
  25199. void addMidiInputCallback (const String& midiInputDeviceName,
  25200. MidiInputCallback* callback);
  25201. /** Removes a listener that was previously registered with addMidiInputCallback().
  25202. */
  25203. void removeMidiInputCallback (const String& midiInputDeviceName,
  25204. MidiInputCallback* callback);
  25205. /** Sets a midi output device to use as the default.
  25206. The list of devices can be obtained with the MidiOutput::getDevices() method.
  25207. The specified device will be opened automatically and can be retrieved with the
  25208. getDefaultMidiOutput() method.
  25209. Pass in an empty string to deselect all devices. For the default device, you
  25210. can use MidiOutput::getDevices() [MidiOutput::getDefaultDeviceIndex()].
  25211. @see getDefaultMidiOutput, getDefaultMidiOutputName
  25212. */
  25213. void setDefaultMidiOutput (const String& deviceName);
  25214. /** Returns the name of the default midi output.
  25215. @see setDefaultMidiOutput, getDefaultMidiOutput
  25216. */
  25217. const String getDefaultMidiOutputName() const throw() { return defaultMidiOutputName; }
  25218. /** Returns the current default midi output device.
  25219. If no device has been selected, or the device can't be opened, this will
  25220. return 0.
  25221. @see getDefaultMidiOutputName
  25222. */
  25223. MidiOutput* getDefaultMidiOutput() const throw() { return defaultMidiOutput; }
  25224. /**
  25225. */
  25226. const OwnedArray <AudioIODeviceType>& getAvailableDeviceTypes();
  25227. /** Creates a list of available types.
  25228. This will add a set of new AudioIODeviceType objects to the specified list, to
  25229. represent each available types of device.
  25230. You can override this if your app needs to do something specific, like avoid
  25231. using DirectSound devices, etc.
  25232. */
  25233. virtual void createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& types);
  25234. /** Plays a beep through the current audio device.
  25235. This is here to allow the audio setup UI panels to easily include a "test"
  25236. button so that the user can check where the audio is coming from.
  25237. */
  25238. void playTestSound();
  25239. /** Turns on level-measuring.
  25240. When enabled, the device manager will measure the peak input level
  25241. across all channels, and you can get this level by calling getCurrentInputLevel().
  25242. This is mainly intended for audio setup UI panels to use to create a mic
  25243. level display, so that the user can check that they've selected the right
  25244. device.
  25245. A simple filter is used to make the level decay smoothly, but this is
  25246. only intended for giving rough feedback, and not for any kind of accurate
  25247. measurement.
  25248. */
  25249. void enableInputLevelMeasurement (const bool enableMeasurement);
  25250. /** Returns the current input level.
  25251. To use this, you must first enable it by calling enableInputLevelMeasurement().
  25252. See enableInputLevelMeasurement() for more info.
  25253. */
  25254. double getCurrentInputLevel() const;
  25255. juce_UseDebuggingNewOperator
  25256. private:
  25257. OwnedArray <AudioIODeviceType> availableDeviceTypes;
  25258. OwnedArray <AudioDeviceSetup> lastDeviceTypeConfigs;
  25259. AudioDeviceSetup currentSetup;
  25260. AudioIODevice* currentAudioDevice;
  25261. AudioIODeviceCallback* currentCallback;
  25262. int numInputChansNeeded, numOutputChansNeeded;
  25263. String currentDeviceType;
  25264. BitArray inputChannels, outputChannels;
  25265. XmlElement* lastExplicitSettings;
  25266. mutable bool listNeedsScanning;
  25267. bool useInputNames, inputLevelMeasurementEnabled;
  25268. double inputLevel;
  25269. AudioSampleBuffer* testSound;
  25270. int testSoundPosition;
  25271. StringArray midiInsFromXml;
  25272. OwnedArray <MidiInput> enabledMidiInputs;
  25273. Array <MidiInputCallback*> midiCallbacks;
  25274. Array <MidiInput*> midiCallbackDevices;
  25275. String defaultMidiOutputName;
  25276. MidiOutput* defaultMidiOutput;
  25277. CriticalSection audioCallbackLock, midiCallbackLock;
  25278. double cpuUsageMs, timeToCpuScale;
  25279. class CallbackHandler : public AudioIODeviceCallback,
  25280. public MidiInputCallback
  25281. {
  25282. public:
  25283. AudioDeviceManager* owner;
  25284. void audioDeviceIOCallback (const float** inputChannelData,
  25285. int totalNumInputChannels,
  25286. float** outputChannelData,
  25287. int totalNumOutputChannels,
  25288. int numSamples);
  25289. void audioDeviceAboutToStart (AudioIODevice*);
  25290. void audioDeviceStopped();
  25291. void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
  25292. };
  25293. CallbackHandler callbackHandler;
  25294. friend class CallbackHandler;
  25295. void audioDeviceIOCallbackInt (const float** inputChannelData,
  25296. int totalNumInputChannels,
  25297. float** outputChannelData,
  25298. int totalNumOutputChannels,
  25299. int numSamples);
  25300. void audioDeviceAboutToStartInt (AudioIODevice* const device);
  25301. void audioDeviceStoppedInt();
  25302. void handleIncomingMidiMessageInt (MidiInput* source, const MidiMessage& message);
  25303. const String restartDevice (int blockSizeToUse, double sampleRateToUse,
  25304. const BitArray& ins, const BitArray& outs);
  25305. void stopDevice();
  25306. void updateXml();
  25307. void createDeviceTypesIfNeeded();
  25308. void scanDevicesIfNeeded();
  25309. void deleteCurrentDevice();
  25310. double chooseBestSampleRate (double preferred) const;
  25311. AudioIODeviceType* getCurrentDeviceTypeObject() const;
  25312. void insertDefaultDeviceNames (AudioDeviceSetup& setup) const;
  25313. AudioIODeviceType* findType (const String& inputName, const String& outputName);
  25314. AudioDeviceManager (const AudioDeviceManager&);
  25315. const AudioDeviceManager& operator= (const AudioDeviceManager&);
  25316. };
  25317. #endif // __JUCE_AUDIODEVICEMANAGER_JUCEHEADER__
  25318. /********* End of inlined file: juce_AudioDeviceManager.h *********/
  25319. #endif
  25320. #ifndef __JUCE_AUDIOIODEVICE_JUCEHEADER__
  25321. #endif
  25322. #ifndef __JUCE_AUDIOIODEVICETYPE_JUCEHEADER__
  25323. #endif
  25324. #ifndef __JUCE_MIDIINPUT_JUCEHEADER__
  25325. #endif
  25326. #ifndef __JUCE_MIDIOUTPUT_JUCEHEADER__
  25327. #endif
  25328. #ifndef __JUCE_SAMPLER_JUCEHEADER__
  25329. /********* Start of inlined file: juce_Sampler.h *********/
  25330. #ifndef __JUCE_SAMPLER_JUCEHEADER__
  25331. #define __JUCE_SAMPLER_JUCEHEADER__
  25332. /********* Start of inlined file: juce_Synthesiser.h *********/
  25333. #ifndef __JUCE_SYNTHESISER_JUCEHEADER__
  25334. #define __JUCE_SYNTHESISER_JUCEHEADER__
  25335. /**
  25336. Describes one of the sounds that a Synthesiser can play.
  25337. A synthesiser can contain one or more sounds, and a sound can choose which
  25338. midi notes and channels can trigger it.
  25339. The SynthesiserSound is a passive class that just describes what the sound is -
  25340. the actual audio rendering for a sound is done by a SynthesiserVoice. This allows
  25341. more than one SynthesiserVoice to play the same sound at the same time.
  25342. @see Synthesiser, SynthesiserVoice
  25343. */
  25344. class JUCE_API SynthesiserSound : public ReferenceCountedObject
  25345. {
  25346. protected:
  25347. SynthesiserSound();
  25348. public:
  25349. /** Destructor. */
  25350. virtual ~SynthesiserSound();
  25351. /** Returns true if this sound should be played when a given midi note is pressed.
  25352. The Synthesiser will use this information when deciding which sounds to trigger
  25353. for a given note.
  25354. */
  25355. virtual bool appliesToNote (const int midiNoteNumber) = 0;
  25356. /** Returns true if the sound should be triggered by midi events on a given channel.
  25357. The Synthesiser will use this information when deciding which sounds to trigger
  25358. for a given note.
  25359. */
  25360. virtual bool appliesToChannel (const int midiChannel) = 0;
  25361. /**
  25362. */
  25363. typedef ReferenceCountedObjectPtr <SynthesiserSound> Ptr;
  25364. juce_UseDebuggingNewOperator
  25365. };
  25366. /**
  25367. Represents a voice that a Synthesiser can use to play a SynthesiserSound.
  25368. A voice plays a single sound at a time, and a synthesiser holds an array of
  25369. voices so that it can play polyphonically.
  25370. @see Synthesiser, SynthesiserSound
  25371. */
  25372. class JUCE_API SynthesiserVoice
  25373. {
  25374. public:
  25375. /** Creates a voice. */
  25376. SynthesiserVoice();
  25377. /** Destructor. */
  25378. virtual ~SynthesiserVoice();
  25379. /** Returns the midi note that this voice is currently playing.
  25380. Returns a value less than 0 if no note is playing.
  25381. */
  25382. int getCurrentlyPlayingNote() const throw() { return currentlyPlayingNote; }
  25383. /** Returns the sound that this voice is currently playing.
  25384. Returns 0 if it's not playing.
  25385. */
  25386. const SynthesiserSound::Ptr getCurrentlyPlayingSound() const throw() { return currentlyPlayingSound; }
  25387. /** Must return true if this voice object is capable of playing the given sound.
  25388. If there are different classes of sound, and different classes of voice, a voice can
  25389. choose which ones it wants to take on.
  25390. A typical implementation of this method may just return true if there's only one type
  25391. of voice and sound, or it might check the type of the sound object passed-in and
  25392. see if it's one that it understands.
  25393. */
  25394. virtual bool canPlaySound (SynthesiserSound* sound) = 0;
  25395. /** Called to start a new note.
  25396. This will be called during the rendering callback, so must be fast and thread-safe.
  25397. */
  25398. virtual void startNote (const int midiNoteNumber,
  25399. const float velocity,
  25400. SynthesiserSound* sound,
  25401. const int currentPitchWheelPosition) = 0;
  25402. /** Called to stop a note.
  25403. This will be called during the rendering callback, so must be fast and thread-safe.
  25404. If allowTailOff is false or the voice doesn't want to tail-off, then it must stop all
  25405. sound immediately, and must call clearCurrentNote() to reset the state of this voice
  25406. and allow the synth to reassign it another sound.
  25407. If allowTailOff is true and the voice decides to do a tail-off, then it's allowed to
  25408. begin fading out its sound, and it can stop playing until it's finished. As soon as it
  25409. finishes playing (during the rendering callback), it must make sure that it calls
  25410. clearCurrentNote().
  25411. */
  25412. virtual void stopNote (const bool allowTailOff) = 0;
  25413. /** Called to let the voice know that the pitch wheel has been moved.
  25414. This will be called during the rendering callback, so must be fast and thread-safe.
  25415. */
  25416. virtual void pitchWheelMoved (const int newValue) = 0;
  25417. /** Called to let the voice know that a midi controller has been moved.
  25418. This will be called during the rendering callback, so must be fast and thread-safe.
  25419. */
  25420. virtual void controllerMoved (const int controllerNumber,
  25421. const int newValue) = 0;
  25422. /** Renders the next block of data for this voice.
  25423. The output audio data must be added to the current contents of the buffer provided.
  25424. Only the region of the buffer between startSample and (startSample + numSamples)
  25425. should be altered by this method.
  25426. If the voice is currently silent, it should just return without doing anything.
  25427. If the sound that the voice is playing finishes during the course of this rendered
  25428. block, it must call clearCurrentNote(), to tell the synthesiser that it has finished.
  25429. The size of the blocks that are rendered can change each time it is called, and may
  25430. involve rendering as little as 1 sample at a time. In between rendering callbacks,
  25431. the voice's methods will be called to tell it about note and controller events.
  25432. */
  25433. virtual void renderNextBlock (AudioSampleBuffer& outputBuffer,
  25434. int startSample,
  25435. int numSamples) = 0;
  25436. /** Returns true if the voice is currently playing a sound which is mapped to the given
  25437. midi channel.
  25438. If it's not currently playing, this will return false.
  25439. */
  25440. bool isPlayingChannel (const int midiChannel) const;
  25441. /** Changes the voice's reference sample rate.
  25442. The rate is set so that subclasses know the output rate and can set their pitch
  25443. accordingly.
  25444. This method is called by the synth, and subclasses can access the current rate with
  25445. the currentSampleRate member.
  25446. */
  25447. void setCurrentPlaybackSampleRate (const double newRate);
  25448. juce_UseDebuggingNewOperator
  25449. protected:
  25450. /** Returns the current target sample rate at which rendering is being done.
  25451. This is available for subclasses so they can pitch things correctly.
  25452. */
  25453. double getSampleRate() const throw() { return currentSampleRate; }
  25454. /** Resets the state of this voice after a sound has finished playing.
  25455. The subclass must call this when it finishes playing a note and becomes available
  25456. to play new ones.
  25457. It must either call it in the stopNote() method, or if the voice is tailing off,
  25458. then it should call it later during the renderNextBlock method, as soon as it
  25459. finishes its tail-off.
  25460. It can also be called at any time during the render callback if the sound happens
  25461. to have finished, e.g. if it's playing a sample and the sample finishes.
  25462. */
  25463. void clearCurrentNote();
  25464. private:
  25465. friend class Synthesiser;
  25466. double currentSampleRate;
  25467. int currentlyPlayingNote;
  25468. uint32 noteOnTime;
  25469. SynthesiserSound::Ptr currentlyPlayingSound;
  25470. };
  25471. /**
  25472. Base class for a musical device that can play sounds.
  25473. To create a synthesiser, you'll need to create a subclass of SynthesiserSound
  25474. to describe each sound available to your synth, and a subclass of SynthesiserVoice
  25475. which can play back one of these sounds.
  25476. Then you can use the addVoice() and addSound() methods to give the synthesiser a
  25477. set of sounds, and a set of voices it can use to play them. If you only give it
  25478. one voice it will be monophonic - the more voices it has, the more polyphony it'll
  25479. have available.
  25480. Then repeatedly call the renderNextBlock() method to produce the audio. Any midi
  25481. events that go in will be scanned for note on/off messages, and these are used to
  25482. start and stop the voices playing the appropriate sounds.
  25483. While it's playing, you can also cause notes to be triggered by calling the noteOn(),
  25484. noteOff() and other controller methods.
  25485. Before rendering, be sure to call the setCurrentPlaybackSampleRate() to tell it
  25486. what the target playback rate is. This value is passed on to the voices so that
  25487. they can pitch their output correctly.
  25488. */
  25489. class JUCE_API Synthesiser
  25490. {
  25491. public:
  25492. /** Creates a new synthesiser.
  25493. You'll need to add some sounds and voices before it'll make any sound..
  25494. */
  25495. Synthesiser();
  25496. /** Destructor. */
  25497. virtual ~Synthesiser();
  25498. /** Deletes all voices. */
  25499. void clearVoices();
  25500. /** Returns the number of voices that have been added. */
  25501. int getNumVoices() const throw() { return voices.size(); }
  25502. /** Returns one of the voices that have been added. */
  25503. SynthesiserVoice* getVoice (const int index) const throw();
  25504. /** Adds a new voice to the synth.
  25505. All the voices should be the same class of object and are treated equally.
  25506. The object passed in will be managed by the synthesiser, which will delete
  25507. it later on when no longer needed. The caller should not retain a pointer to the
  25508. voice.
  25509. */
  25510. void addVoice (SynthesiserVoice* const newVoice);
  25511. /** Deletes one of the voices. */
  25512. void removeVoice (const int index);
  25513. /** Deletes all sounds. */
  25514. void clearSounds();
  25515. /** Returns the number of sounds that have been added to the synth. */
  25516. int getNumSounds() const throw() { return sounds.size(); }
  25517. /** Returns one of the sounds. */
  25518. SynthesiserSound* getSound (const int index) const throw() { return sounds [index]; }
  25519. /** Adds a new sound to the synthesiser.
  25520. The object passed in is reference counted, so will be deleted when it is removed
  25521. from the synthesiser, and when no voices are still using it.
  25522. */
  25523. void addSound (const SynthesiserSound::Ptr& newSound);
  25524. /** Removes and deletes one of the sounds. */
  25525. void removeSound (const int index);
  25526. /** If set to true, then the synth will try to take over an existing voice if
  25527. it runs out and needs to play another note.
  25528. The value of this boolean is passed into findFreeVoice(), so the result will
  25529. depend on the implementation of this method.
  25530. */
  25531. void setNoteStealingEnabled (const bool shouldStealNotes);
  25532. /** Returns true if note-stealing is enabled.
  25533. @see setNoteStealingEnabled
  25534. */
  25535. bool isNoteStealingEnabled() const throw() { return shouldStealNotes; }
  25536. /** Triggers a note-on event.
  25537. The default method here will find all the sounds that want to be triggered by
  25538. this note/channel. For each sound, it'll try to find a free voice, and use the
  25539. voice to start playing the sound.
  25540. Subclasses might want to override this if they need a more complex algorithm.
  25541. This method will be called automatically according to the midi data passed into
  25542. renderNextBlock(), but may be called explicitly too.
  25543. */
  25544. virtual void noteOn (const int midiChannel,
  25545. const int midiNoteNumber,
  25546. const float velocity);
  25547. /** Triggers a note-off event.
  25548. This will turn off any voices that are playing a sound for the given note/channel.
  25549. If allowTailOff is true, the voices will be allowed to fade out the notes gracefully
  25550. (if they can do). If this is false, the notes will all be cut off immediately.
  25551. This method will be called automatically according to the midi data passed into
  25552. renderNextBlock(), but may be called explicitly too.
  25553. */
  25554. virtual void noteOff (const int midiChannel,
  25555. const int midiNoteNumber,
  25556. const bool allowTailOff);
  25557. /** Turns off all notes.
  25558. This will turn off any voices that are playing a sound on the given midi channel.
  25559. If midiChannel is 0 or less, then all voices will be turned off, regardless of
  25560. which channel they're playing.
  25561. If allowTailOff is true, the voices will be allowed to fade out the notes gracefully
  25562. (if they can do). If this is false, the notes will all be cut off immediately.
  25563. This method will be called automatically according to the midi data passed into
  25564. renderNextBlock(), but may be called explicitly too.
  25565. */
  25566. virtual void allNotesOff (const int midiChannel,
  25567. const bool allowTailOff);
  25568. /** Sends a pitch-wheel message.
  25569. This will send a pitch-wheel message to any voices that are playing sounds on
  25570. the given midi channel.
  25571. This method will be called automatically according to the midi data passed into
  25572. renderNextBlock(), but may be called explicitly too.
  25573. @param midiChannel the midi channel for the event
  25574. @param wheelValue the wheel position, from 0 to 0x3fff, as returned by MidiMessage::getPitchWheelValue()
  25575. */
  25576. virtual void handlePitchWheel (const int midiChannel,
  25577. const int wheelValue);
  25578. /** Sends a midi controller message.
  25579. This will send a midi controller message to any voices that are playing sounds on
  25580. the given midi channel.
  25581. This method will be called automatically according to the midi data passed into
  25582. renderNextBlock(), but may be called explicitly too.
  25583. @param midiChannel the midi channel for the event
  25584. @param controllerNumber the midi controller type, as returned by MidiMessage::getControllerNumber()
  25585. @param controllerValue the midi controller value, between 0 and 127, as returned by MidiMessage::getControllerValue()
  25586. */
  25587. virtual void handleController (const int midiChannel,
  25588. const int controllerNumber,
  25589. const int controllerValue);
  25590. /** Tells the synthesiser what the sample rate is for the audio it's being used to
  25591. render.
  25592. This value is propagated to the voices so that they can use it to render the correct
  25593. pitches.
  25594. */
  25595. void setCurrentPlaybackSampleRate (const double sampleRate);
  25596. /** Creates the next block of audio output.
  25597. This will process the next numSamples of data from all the voices, and add that output
  25598. to the audio block supplied, starting from the offset specified. Note that the
  25599. data will be added to the current contents of the buffer, so you should clear it
  25600. before calling this method if necessary.
  25601. The midi events in the inputMidi buffer are parsed for note and controller events,
  25602. and these are used to trigger the voices. Note that the startSample offset applies
  25603. both to the audio output buffer and the midi input buffer, so any midi events
  25604. with timestamps outside the specified region will be ignored.
  25605. */
  25606. void renderNextBlock (AudioSampleBuffer& outputAudio,
  25607. const MidiBuffer& inputMidi,
  25608. int startSample,
  25609. int numSamples);
  25610. juce_UseDebuggingNewOperator
  25611. protected:
  25612. /** This is used to control access to the rendering callback and the note trigger methods. */
  25613. CriticalSection lock;
  25614. OwnedArray <SynthesiserVoice> voices;
  25615. ReferenceCountedArray <SynthesiserSound> sounds;
  25616. /** The last pitch-wheel values for each midi channel. */
  25617. int lastPitchWheelValues [16];
  25618. /** Searches through the voices to find one that's not currently playing, and which
  25619. can play the given sound.
  25620. Returns 0 if all voices are busy and stealing isn't enabled.
  25621. This can be overridden to implement custom voice-stealing algorithms.
  25622. */
  25623. virtual SynthesiserVoice* findFreeVoice (SynthesiserSound* soundToPlay,
  25624. const bool stealIfNoneAvailable) const;
  25625. /** Starts a specified voice playing a particular sound.
  25626. You'll probably never need to call this, it's used internally by noteOn(), but
  25627. may be needed by subclasses for custom behaviours.
  25628. */
  25629. void startVoice (SynthesiserVoice* const voice,
  25630. SynthesiserSound* const sound,
  25631. const int midiChannel,
  25632. const int midiNoteNumber,
  25633. const float velocity);
  25634. /** xxx Temporary method here to cause a compiler error - note the new parameters for this method. */
  25635. int findFreeVoice (const bool) const { return 0; }
  25636. private:
  25637. double sampleRate;
  25638. uint32 lastNoteOnCounter;
  25639. bool shouldStealNotes;
  25640. Synthesiser (const Synthesiser&);
  25641. const Synthesiser& operator= (const Synthesiser&);
  25642. };
  25643. #endif // __JUCE_SYNTHESISER_JUCEHEADER__
  25644. /********* End of inlined file: juce_Synthesiser.h *********/
  25645. /**
  25646. A subclass of SynthesiserSound that represents a sampled audio clip.
  25647. This is a pretty basic sampler, and just attempts to load the whole audio stream
  25648. into memory.
  25649. To use it, create a Synthesiser, add some SamplerVoice objects to it, then
  25650. give it some SampledSound objects to play.
  25651. @see SamplerVoice, Synthesiser, SynthesiserSound
  25652. */
  25653. class JUCE_API SamplerSound : public SynthesiserSound
  25654. {
  25655. public:
  25656. /** Creates a sampled sound from an audio reader.
  25657. This will attempt to load the audio from the source into memory and store
  25658. it in this object.
  25659. @param name a name for the sample
  25660. @param source the audio to load. This object can be safely deleted by the
  25661. caller after this constructor returns
  25662. @param midiNotes the set of midi keys that this sound should be played on. This
  25663. is used by the SynthesiserSound::appliesToNote() method
  25664. @param midiNoteForNormalPitch the midi note at which the sample should be played
  25665. with its natural rate. All other notes will be pitched
  25666. up or down relative to this one
  25667. @param attackTimeSecs the attack (fade-in) time, in seconds
  25668. @param releaseTimeSecs the decay (fade-out) time, in seconds
  25669. @param maxSampleLengthSeconds a maximum length of audio to read from the audio
  25670. source, in seconds
  25671. */
  25672. SamplerSound (const String& name,
  25673. AudioFormatReader& source,
  25674. const BitArray& midiNotes,
  25675. const int midiNoteForNormalPitch,
  25676. const double attackTimeSecs,
  25677. const double releaseTimeSecs,
  25678. const double maxSampleLengthSeconds);
  25679. /** Destructor. */
  25680. ~SamplerSound();
  25681. /** Returns the sample's name */
  25682. const String& getName() const throw() { return name; }
  25683. /** Returns the audio sample data.
  25684. This could be 0 if there was a problem loading it.
  25685. */
  25686. AudioSampleBuffer* getAudioData() const throw() { return data; }
  25687. bool appliesToNote (const int midiNoteNumber);
  25688. bool appliesToChannel (const int midiChannel);
  25689. juce_UseDebuggingNewOperator
  25690. private:
  25691. friend class SamplerVoice;
  25692. String name;
  25693. AudioSampleBuffer* data;
  25694. double sourceSampleRate;
  25695. BitArray midiNotes;
  25696. int length, attackSamples, releaseSamples;
  25697. int midiRootNote;
  25698. };
  25699. /**
  25700. A subclass of SynthesiserVoice that can play a SamplerSound.
  25701. To use it, create a Synthesiser, add some SamplerVoice objects to it, then
  25702. give it some SampledSound objects to play.
  25703. @see SamplerSound, Synthesiser, SynthesiserVoice
  25704. */
  25705. class JUCE_API SamplerVoice : public SynthesiserVoice
  25706. {
  25707. public:
  25708. /** Creates a SamplerVoice.
  25709. */
  25710. SamplerVoice();
  25711. /** Destructor. */
  25712. ~SamplerVoice();
  25713. bool canPlaySound (SynthesiserSound* sound);
  25714. void startNote (const int midiNoteNumber,
  25715. const float velocity,
  25716. SynthesiserSound* sound,
  25717. const int currentPitchWheelPosition);
  25718. void stopNote (const bool allowTailOff);
  25719. void pitchWheelMoved (const int newValue);
  25720. void controllerMoved (const int controllerNumber,
  25721. const int newValue);
  25722. void renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples);
  25723. juce_UseDebuggingNewOperator
  25724. private:
  25725. double pitchRatio;
  25726. double sourceSamplePosition;
  25727. float lgain, rgain, attackReleaseLevel, attackDelta, releaseDelta;
  25728. bool isInAttack, isInRelease;
  25729. };
  25730. #endif // __JUCE_SAMPLER_JUCEHEADER__
  25731. /********* End of inlined file: juce_Sampler.h *********/
  25732. #endif
  25733. #ifndef __JUCE_SYNTHESISER_JUCEHEADER__
  25734. #endif
  25735. #ifndef __JUCE_AUDIOUNITPLUGINFORMAT_JUCEHEADER__
  25736. /********* Start of inlined file: juce_AudioUnitPluginFormat.h *********/
  25737. #ifndef __JUCE_AUDIOUNITPLUGINFORMAT_JUCEHEADER__
  25738. #define __JUCE_AUDIOUNITPLUGINFORMAT_JUCEHEADER__
  25739. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  25740. /**
  25741. Implements a plugin format manager for AudioUnits.
  25742. */
  25743. class JUCE_API AudioUnitPluginFormat : public AudioPluginFormat
  25744. {
  25745. public:
  25746. AudioUnitPluginFormat();
  25747. ~AudioUnitPluginFormat();
  25748. const String getName() const { return "AudioUnit"; }
  25749. void findAllTypesForFile (OwnedArray <PluginDescription>& results, const File& file);
  25750. AudioPluginInstance* createInstanceFromDescription (const PluginDescription& desc);
  25751. bool fileMightContainThisPluginType (const File& file);
  25752. const FileSearchPath getDefaultLocationsToSearch();
  25753. juce_UseDebuggingNewOperator
  25754. private:
  25755. AudioUnitPluginFormat (const AudioUnitPluginFormat&);
  25756. const AudioUnitPluginFormat& operator= (const AudioUnitPluginFormat&);
  25757. };
  25758. #endif
  25759. #endif // __JUCE_AUDIOUNITPLUGINFORMAT_JUCEHEADER__
  25760. /********* End of inlined file: juce_AudioUnitPluginFormat.h *********/
  25761. #endif
  25762. #ifndef __JUCE_DIRECTXPLUGINFORMAT_JUCEHEADER__
  25763. /********* Start of inlined file: juce_DirectXPluginFormat.h *********/
  25764. #ifndef __JUCE_DIRECTXPLUGINFORMAT_JUCEHEADER__
  25765. #define __JUCE_DIRECTXPLUGINFORMAT_JUCEHEADER__
  25766. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  25767. // Sorry, this file is just a placeholder at the moment!...
  25768. /**
  25769. Implements a plugin format manager for DirectX plugins.
  25770. */
  25771. class JUCE_API DirectXPluginFormat : public AudioPluginFormat
  25772. {
  25773. public:
  25774. DirectXPluginFormat();
  25775. ~DirectXPluginFormat();
  25776. const String getName() const { return "DirectX"; }
  25777. void findAllTypesForFile (OwnedArray <PluginDescription>& results, const File& file);
  25778. AudioPluginInstance* createInstanceFromDescription (const PluginDescription& desc);
  25779. bool fileMightContainThisPluginType (const File& file);
  25780. const FileSearchPath getDefaultLocationsToSearch();
  25781. juce_UseDebuggingNewOperator
  25782. private:
  25783. DirectXPluginFormat (const DirectXPluginFormat&);
  25784. const DirectXPluginFormat& operator= (const DirectXPluginFormat&);
  25785. };
  25786. #endif
  25787. #endif // __JUCE_DIRECTXPLUGINFORMAT_JUCEHEADER__
  25788. /********* End of inlined file: juce_DirectXPluginFormat.h *********/
  25789. #endif
  25790. #ifndef __JUCE_LADSPAPLUGINFORMAT_JUCEHEADER__
  25791. /********* Start of inlined file: juce_LADSPAPluginFormat.h *********/
  25792. #ifndef __JUCE_LADSPAPLUGINFORMAT_JUCEHEADER__
  25793. #define __JUCE_LADSPAPLUGINFORMAT_JUCEHEADER__
  25794. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  25795. // Sorry, this file is just a placeholder at the moment!...
  25796. /**
  25797. Implements a plugin format manager for DirectX plugins.
  25798. */
  25799. class JUCE_API LADSPAPluginFormat : public AudioPluginFormat
  25800. {
  25801. public:
  25802. LADSPAPluginFormat();
  25803. ~LADSPAPluginFormat();
  25804. const String getName() const { return "LADSPA"; }
  25805. void findAllTypesForFile (OwnedArray <PluginDescription>& results, const File& file);
  25806. AudioPluginInstance* createInstanceFromDescription (const PluginDescription& desc);
  25807. bool fileMightContainThisPluginType (const File& file);
  25808. const FileSearchPath getDefaultLocationsToSearch();
  25809. juce_UseDebuggingNewOperator
  25810. private:
  25811. LADSPAPluginFormat (const LADSPAPluginFormat&);
  25812. const LADSPAPluginFormat& operator= (const LADSPAPluginFormat&);
  25813. };
  25814. #endif
  25815. #endif // __JUCE_LADSPAPLUGINFORMAT_JUCEHEADER__
  25816. /********* End of inlined file: juce_LADSPAPluginFormat.h *********/
  25817. #endif
  25818. #ifndef __JUCE_VSTPLUGINFORMAT_JUCEHEADER__
  25819. /********* Start of inlined file: juce_VSTPluginFormat.h *********/
  25820. #ifndef __JUCE_VSTPLUGINFORMAT_JUCEHEADER__
  25821. #define __JUCE_VSTPLUGINFORMAT_JUCEHEADER__
  25822. #if JUCE_PLUGINHOST_VST
  25823. /**
  25824. Implements a plugin format manager for VSTs.
  25825. */
  25826. class JUCE_API VSTPluginFormat : public AudioPluginFormat
  25827. {
  25828. public:
  25829. VSTPluginFormat();
  25830. ~VSTPluginFormat();
  25831. const String getName() const { return "VST"; }
  25832. void findAllTypesForFile (OwnedArray <PluginDescription>& results, const File& file);
  25833. AudioPluginInstance* createInstanceFromDescription (const PluginDescription& desc);
  25834. bool fileMightContainThisPluginType (const File& file);
  25835. const FileSearchPath getDefaultLocationsToSearch();
  25836. juce_UseDebuggingNewOperator
  25837. private:
  25838. VSTPluginFormat (const VSTPluginFormat&);
  25839. const VSTPluginFormat& operator= (const VSTPluginFormat&);
  25840. };
  25841. #endif
  25842. #endif // __JUCE_VSTPLUGINFORMAT_JUCEHEADER__
  25843. /********* End of inlined file: juce_VSTPluginFormat.h *********/
  25844. #endif
  25845. #ifndef __JUCE_AUDIOPLUGINFORMAT_JUCEHEADER__
  25846. #endif
  25847. #ifndef __JUCE_AUDIOPLUGINFORMATMANAGER_JUCEHEADER__
  25848. #endif
  25849. #ifndef __JUCE_AUDIOPLUGININSTANCE_JUCEHEADER__
  25850. #endif
  25851. #ifndef __JUCE_KNOWNPLUGINLIST_JUCEHEADER__
  25852. #endif
  25853. #ifndef __JUCE_PLUGINDESCRIPTION_JUCEHEADER__
  25854. #endif
  25855. #ifndef __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__
  25856. /********* Start of inlined file: juce_PluginDirectoryScanner.h *********/
  25857. #ifndef __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__
  25858. #define __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__
  25859. /**
  25860. Scans a directory for plugins, and adds them to a KnownPluginList.
  25861. To use one of these, create it and call scanNextFile() repeatedly, until
  25862. it returns false.
  25863. */
  25864. class JUCE_API PluginDirectoryScanner
  25865. {
  25866. public:
  25867. /**
  25868. Creates a scanner.
  25869. @param listToAddResultsTo this will get the new types added to it.
  25870. @param formatToLookFor this is the type of format that you want to look for
  25871. @param directoriesToSearch the path to search
  25872. @param searchRecursively true to search recursively
  25873. @param deadMansPedalFile if this isn't File::nonexistent, then it will
  25874. be used as a file to store the names of any plugins
  25875. that crash during initialisation. If there are
  25876. any plugins listed in it, then these will always
  25877. be scanned after all other possible files have
  25878. been tried - in this way, even if there's a few
  25879. dodgy plugins in your path, then a couple of rescans
  25880. will still manage to find all the proper plugins.
  25881. It's probably best to choose a file in the user's
  25882. application data directory (alongside your app's
  25883. settings file) for this. The file format it uses
  25884. is just a list of filenames of the modules that
  25885. failed.
  25886. */
  25887. PluginDirectoryScanner (KnownPluginList& listToAddResultsTo,
  25888. AudioPluginFormat& formatToLookFor,
  25889. FileSearchPath directoriesToSearch,
  25890. const bool searchRecursively,
  25891. const File& deadMansPedalFile);
  25892. /** Destructor. */
  25893. ~PluginDirectoryScanner();
  25894. /** Tries the next likely-looking file.
  25895. If dontRescanIfAlreadyInList is true, then the file will only be loaded and
  25896. re-tested if it's not already in the list, or if the file's modification
  25897. time has changed since the list was created. If dontRescanIfAlreadyInList is
  25898. false, the file will always be reloaded and tested.
  25899. Returns false when there are no more files to try.
  25900. */
  25901. bool scanNextFile (const bool dontRescanIfAlreadyInList);
  25902. /** Returns the file that will be scanned during the next call to scanNextFile().
  25903. This is handy if you want to show the user which file is currently getting
  25904. scanned.
  25905. */
  25906. const File getNextPluginFileThatWillBeScanned() const throw();
  25907. /** Returns the estimated progress, between 0 and 1.
  25908. */
  25909. float getProgress() const { return progress; }
  25910. /** This returns a list of all the filenames of things that looked like being
  25911. a plugin file, but which failed to open for some reason.
  25912. */
  25913. const StringArray& getFailedFiles() const throw() { return failedFiles; }
  25914. juce_UseDebuggingNewOperator
  25915. private:
  25916. KnownPluginList& list;
  25917. AudioPluginFormat& format;
  25918. OwnedArray <File> filesToScan;
  25919. File deadMansPedalFile;
  25920. StringArray failedFiles;
  25921. int nextIndex;
  25922. float progress;
  25923. void recursiveFileSearch (const File& dir, const bool recursive);
  25924. const StringArray getDeadMansPedalFile() throw();
  25925. void setDeadMansPedalFile (const StringArray& newContents) throw();
  25926. PluginDirectoryScanner (const PluginDirectoryScanner&);
  25927. const PluginDirectoryScanner& operator= (const PluginDirectoryScanner&);
  25928. };
  25929. #endif // __JUCE_PLUGINDIRECTORYSCANNER_JUCEHEADER__
  25930. /********* End of inlined file: juce_PluginDirectoryScanner.h *********/
  25931. #endif
  25932. #ifndef __JUCE_PLUGINLISTCOMPONENT_JUCEHEADER__
  25933. /********* Start of inlined file: juce_PluginListComponent.h *********/
  25934. #ifndef __JUCE_PLUGINLISTCOMPONENT_JUCEHEADER__
  25935. #define __JUCE_PLUGINLISTCOMPONENT_JUCEHEADER__
  25936. /********* Start of inlined file: juce_ListBox.h *********/
  25937. #ifndef __JUCE_LISTBOX_JUCEHEADER__
  25938. #define __JUCE_LISTBOX_JUCEHEADER__
  25939. class ListViewport;
  25940. /**
  25941. A subclass of this is used to drive a ListBox.
  25942. @see ListBox
  25943. */
  25944. class JUCE_API ListBoxModel
  25945. {
  25946. public:
  25947. /** Destructor. */
  25948. virtual ~ListBoxModel() {}
  25949. /** This has to return the number of items in the list.
  25950. @see ListBox::getNumRows()
  25951. */
  25952. virtual int getNumRows() = 0;
  25953. /** This method must be implemented to draw a row of the list.
  25954. */
  25955. virtual void paintListBoxItem (int rowNumber,
  25956. Graphics& g,
  25957. int width, int height,
  25958. bool rowIsSelected) = 0;
  25959. /** This is used to create or update a custom component to go in a row of the list.
  25960. Any row may contain a custom component, or can just be drawn with the paintListBoxItem() method
  25961. and handle mouse clicks with listBoxItemClicked().
  25962. This method will be called whenever a custom component might need to be updated - e.g.
  25963. when the table is changed, or TableListBox::updateContent() is called.
  25964. If you don't need a custom component for the specified row, then return 0.
  25965. If you do want a custom component, and the existingComponentToUpdate is null, then
  25966. this method must create a suitable new component and return it.
  25967. If the existingComponentToUpdate is non-null, it will be a pointer to a component previously created
  25968. by this method. In this case, the method must either update it to make sure it's correctly representing
  25969. the given row (which may be different from the one that the component was created for), or it can
  25970. delete this component and return a new one.
  25971. The component that your method returns will be deleted by the ListBox when it is no longer needed.
  25972. */
  25973. virtual Component* refreshComponentForRow (int rowNumber, bool isRowSelected,
  25974. Component* existingComponentToUpdate);
  25975. /** This can be overridden to react to the user clicking on a row.
  25976. @see listBoxItemDoubleClicked
  25977. */
  25978. virtual void listBoxItemClicked (int row, const MouseEvent& e);
  25979. /** This can be overridden to react to the user double-clicking on a row.
  25980. @see listBoxItemClicked
  25981. */
  25982. virtual void listBoxItemDoubleClicked (int row, const MouseEvent& e);
  25983. /** This can be overridden to react to the user double-clicking on a part of the list where
  25984. there are no rows.
  25985. @see listBoxItemClicked
  25986. */
  25987. virtual void backgroundClicked();
  25988. /** Override this to be informed when rows are selected or deselected.
  25989. This will be called whenever a row is selected or deselected. If a range of
  25990. rows is selected all at once, this will just be called once for that event.
  25991. @param lastRowSelected the last row that the user selected. If no
  25992. rows are currently selected, this may be -1.
  25993. */
  25994. virtual void selectedRowsChanged (int lastRowSelected);
  25995. /** Override this to be informed when the delete key is pressed.
  25996. If no rows are selected when they press the key, this won't be called.
  25997. @param lastRowSelected the last row that had been selected when they pressed the
  25998. key - if there are multiple selections, this might not be
  25999. very useful
  26000. */
  26001. virtual void deleteKeyPressed (int lastRowSelected);
  26002. /** Override this to be informed when the return key is pressed.
  26003. If no rows are selected when they press the key, this won't be called.
  26004. @param lastRowSelected the last row that had been selected when they pressed the
  26005. key - if there are multiple selections, this might not be
  26006. very useful
  26007. */
  26008. virtual void returnKeyPressed (int lastRowSelected);
  26009. /** Override this to be informed when the list is scrolled.
  26010. This might be caused by the user moving the scrollbar, or by programmatic changes
  26011. to the list position.
  26012. */
  26013. virtual void listWasScrolled();
  26014. /** To allow rows from your list to be dragged-and-dropped, implement this method.
  26015. If this returns a non-empty name then when the user drags a row, the listbox will
  26016. try to find a DragAndDropContainer in its parent hierarchy, and will use it to trigger
  26017. a drag-and-drop operation, using this string as the source description, with the listbox
  26018. itself as the source component.
  26019. @see DragAndDropContainer::startDragging
  26020. */
  26021. virtual const String getDragSourceDescription (const SparseSet<int>& currentlySelectedRows);
  26022. };
  26023. /**
  26024. A list of items that can be scrolled vertically.
  26025. To create a list, you'll need to create a subclass of ListBoxModel. This can
  26026. either paint each row of the list and respond to events via callbacks, or for
  26027. more specialised tasks, it can supply a custom component to fill each row.
  26028. @see ComboBox, TableListBox
  26029. */
  26030. class JUCE_API ListBox : public Component,
  26031. public SettableTooltipClient
  26032. {
  26033. public:
  26034. /** Creates a ListBox.
  26035. The model pointer passed-in can be null, in which case you can set it later
  26036. with setModel().
  26037. */
  26038. ListBox (const String& componentName,
  26039. ListBoxModel* const model);
  26040. /** Destructor. */
  26041. ~ListBox();
  26042. /** Changes the current data model to display. */
  26043. void setModel (ListBoxModel* const newModel);
  26044. /** Returns the current list model. */
  26045. ListBoxModel* getModel() const throw() { return model; }
  26046. /** Causes the list to refresh its content.
  26047. Call this when the number of rows in the list changes, or if you want it
  26048. to call refreshComponentForRow() on all the row components.
  26049. Be careful not to call it from a different thread, though, as it's not
  26050. thread-safe.
  26051. */
  26052. void updateContent();
  26053. /** Turns on multiple-selection of rows.
  26054. By default this is disabled.
  26055. When your row component gets clicked you'll need to call the
  26056. selectRowsBasedOnModifierKeys() method to tell the list that it's been
  26057. clicked and to get it to do the appropriate selection based on whether
  26058. the ctrl/shift keys are held down.
  26059. */
  26060. void setMultipleSelectionEnabled (bool shouldBeEnabled);
  26061. /** Makes the list react to mouse moves by selecting the row that the mouse if over.
  26062. This function is here primarily for the ComboBox class to use, but might be
  26063. useful for some other purpose too.
  26064. */
  26065. void setMouseMoveSelectsRows (bool shouldSelect);
  26066. /** Selects a row.
  26067. If the row is already selected, this won't do anything.
  26068. @param rowNumber the row to select
  26069. @param dontScrollToShowThisRow if true, the list's position won't change; if false and
  26070. the selected row is off-screen, it'll scroll to make
  26071. sure that row is on-screen
  26072. @param deselectOthersFirst if true and there are multiple selections, these will
  26073. first be deselected before this item is selected
  26074. @see isRowSelected, selectRowsBasedOnModifierKeys, flipRowSelection, deselectRow,
  26075. deselectAllRows, selectRangeOfRows
  26076. */
  26077. void selectRow (const int rowNumber,
  26078. bool dontScrollToShowThisRow = false,
  26079. bool deselectOthersFirst = true);
  26080. /** Selects a set of rows.
  26081. This will add these rows to the current selection, so you might need to
  26082. clear the current selection first with deselectAllRows()
  26083. @param firstRow the first row to select (inclusive)
  26084. @param lastRow the last row to select (inclusive)
  26085. */
  26086. void selectRangeOfRows (int firstRow,
  26087. int lastRow);
  26088. /** Deselects a row.
  26089. If it's not currently selected, this will do nothing.
  26090. @see selectRow, deselectAllRows
  26091. */
  26092. void deselectRow (const int rowNumber);
  26093. /** Deselects any currently selected rows.
  26094. @see deselectRow
  26095. */
  26096. void deselectAllRows();
  26097. /** Selects or deselects a row.
  26098. If the row's currently selected, this deselects it, and vice-versa.
  26099. */
  26100. void flipRowSelection (const int rowNumber);
  26101. /** Returns a sparse set indicating the rows that are currently selected.
  26102. @see setSelectedRows
  26103. */
  26104. const SparseSet<int> getSelectedRows() const;
  26105. /** Sets the rows that should be selected, based on an explicit set of ranges.
  26106. If sendNotificationEventToModel is true, the ListBoxModel::selectedRowsChanged()
  26107. method will be called. If it's false, no notification will be sent to the model.
  26108. @see getSelectedRows
  26109. */
  26110. void setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  26111. const bool sendNotificationEventToModel = true);
  26112. /** Checks whether a row is selected.
  26113. */
  26114. bool isRowSelected (const int rowNumber) const;
  26115. /** Returns the number of rows that are currently selected.
  26116. @see getSelectedRow, isRowSelected, getLastRowSelected
  26117. */
  26118. int getNumSelectedRows() const;
  26119. /** Returns the row number of a selected row.
  26120. This will return the row number of the Nth selected row. The row numbers returned will
  26121. be sorted in order from low to high.
  26122. @param index the index of the selected row to return, (from 0 to getNumSelectedRows() - 1)
  26123. @returns the row number, or -1 if the index was out of range or if there aren't any rows
  26124. selected
  26125. @see getNumSelectedRows, isRowSelected, getLastRowSelected
  26126. */
  26127. int getSelectedRow (const int index = 0) const;
  26128. /** Returns the last row that the user selected.
  26129. This isn't the same as the highest row number that is currently selected - if the user
  26130. had multiply-selected rows 10, 5 and then 6 in that order, this would return 6.
  26131. If nothing is selected, it will return -1.
  26132. */
  26133. int getLastRowSelected() const;
  26134. /** Multiply-selects rows based on the modifier keys.
  26135. If no modifier keys are down, this will select the given row and
  26136. deselect any others.
  26137. If the ctrl (or command on the Mac) key is down, it'll flip the
  26138. state of the selected row.
  26139. If the shift key is down, it'll select up to the given row from the
  26140. last row selected.
  26141. @see selectRow
  26142. */
  26143. void selectRowsBasedOnModifierKeys (const int rowThatWasClickedOn,
  26144. const ModifierKeys& modifiers);
  26145. /** Scrolls the list to a particular position.
  26146. The proportion is between 0 and 1.0, so 0 scrolls to the top of the list,
  26147. 1.0 scrolls to the bottom.
  26148. If the total number of rows all fit onto the screen at once, then this
  26149. method won't do anything.
  26150. @see getVerticalPosition
  26151. */
  26152. void setVerticalPosition (const double newProportion);
  26153. /** Returns the current vertical position as a proportion of the total.
  26154. This can be used in conjunction with setVerticalPosition() to save and restore
  26155. the list's position. It returns a value in the range 0 to 1.
  26156. @see setVerticalPosition
  26157. */
  26158. double getVerticalPosition() const;
  26159. /** Scrolls if necessary to make sure that a particular row is visible.
  26160. */
  26161. void scrollToEnsureRowIsOnscreen (const int row);
  26162. /** Returns a pointer to the scrollbar.
  26163. (Unlikely to be useful for most people).
  26164. */
  26165. ScrollBar* getVerticalScrollBar() const throw();
  26166. /** Returns a pointer to the scrollbar.
  26167. (Unlikely to be useful for most people).
  26168. */
  26169. ScrollBar* getHorizontalScrollBar() const throw();
  26170. /** Finds the row index that contains a given x,y position.
  26171. The position is relative to the ListBox's top-left.
  26172. If no row exists at this position, the method will return -1.
  26173. @see getComponentForRowNumber
  26174. */
  26175. int getRowContainingPosition (const int x, const int y) const throw();
  26176. /** Finds a row index that would be the most suitable place to insert a new
  26177. item for a given position.
  26178. This is useful when the user is e.g. dragging and dropping onto the listbox,
  26179. because it lets you easily choose the best position to insert the item that
  26180. they drop, based on where they drop it.
  26181. If the position is out of range, this will return -1. If the position is
  26182. beyond the end of the list, it will return getNumRows() to indicate the end
  26183. of the list.
  26184. @see getComponentForRowNumber
  26185. */
  26186. int getInsertionIndexForPosition (const int x, const int y) const throw();
  26187. /** Returns the position of one of the rows, relative to the top-left of
  26188. the listbox.
  26189. This may be off-screen, and the range of the row number that is passed-in is
  26190. not checked to see if it's a valid row.
  26191. */
  26192. const Rectangle getRowPosition (const int rowNumber,
  26193. const bool relativeToComponentTopLeft) const throw();
  26194. /** Finds the row component for a given row in the list.
  26195. The component returned will have been created using createRowComponent().
  26196. If the component for this row is off-screen or if the row is out-of-range,
  26197. this will return 0.
  26198. @see getRowContainingPosition
  26199. */
  26200. Component* getComponentForRowNumber (const int rowNumber) const throw();
  26201. /** Returns the row number that the given component represents.
  26202. If the component isn't one of the list's rows, this will return -1.
  26203. */
  26204. int getRowNumberOfComponent (Component* const rowComponent) const throw();
  26205. /** Returns the width of a row (which may be less than the width of this component
  26206. if there's a scrollbar).
  26207. */
  26208. int getVisibleRowWidth() const throw();
  26209. /** Sets the height of each row in the list.
  26210. The default height is 22 pixels.
  26211. @see getRowHeight
  26212. */
  26213. void setRowHeight (const int newHeight);
  26214. /** Returns the height of a row in the list.
  26215. @see setRowHeight
  26216. */
  26217. int getRowHeight() const throw() { return rowHeight; }
  26218. /** Returns the number of rows actually visible.
  26219. This is the number of whole rows which will fit on-screen, so the value might
  26220. be more than the actual number of rows in the list.
  26221. */
  26222. int getNumRowsOnScreen() const throw();
  26223. /** A set of colour IDs to use to change the colour of various aspects of the label.
  26224. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  26225. methods.
  26226. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  26227. */
  26228. enum ColourIds
  26229. {
  26230. backgroundColourId = 0x1002800, /**< The background colour to fill the list with.
  26231. Make this transparent if you don't want the background to be filled. */
  26232. outlineColourId = 0x1002810, /**< An optional colour to use to draw a border around the list.
  26233. Make this transparent to not have an outline. */
  26234. textColourId = 0x1002820 /**< The preferred colour to use for drawing text in the listbox. */
  26235. };
  26236. /** Sets the thickness of a border that will be drawn around the box.
  26237. To set the colour of the outline, use @code setColour (ListBox::outlineColourId, colourXYZ); @endcode
  26238. @see outlineColourId
  26239. */
  26240. void setOutlineThickness (const int outlineThickness);
  26241. /** Returns the thickness of outline that will be drawn around the listbox.
  26242. @see setOutlineColour
  26243. */
  26244. int getOutlineThickness() const throw() { return outlineThickness; }
  26245. /** Sets a component that the list should use as a header.
  26246. This will position the given component at the top of the list, maintaining the
  26247. height of the component passed-in, but rescaling it horizontally to match the
  26248. width of the items in the listbox.
  26249. The component will be deleted when setHeaderComponent() is called with a
  26250. different component, or when the listbox is deleted.
  26251. */
  26252. void setHeaderComponent (Component* const newHeaderComponent);
  26253. /** Changes the width of the rows in the list.
  26254. This can be used to make the list's row components wider than the list itself - the
  26255. width of the rows will be either the width of the list or this value, whichever is
  26256. greater, and if the rows become wider than the list, a horizontal scrollbar will
  26257. appear.
  26258. The default value for this is 0, which means that the rows will always
  26259. be the same width as the list.
  26260. */
  26261. void setMinimumContentWidth (const int newMinimumWidth);
  26262. /** Returns the space currently available for the row items, taking into account
  26263. borders, scrollbars, etc.
  26264. */
  26265. int getVisibleContentWidth() const throw();
  26266. /** Repaints one of the rows.
  26267. This is a lightweight alternative to calling updateContent, and just causes a
  26268. repaint of the row's area.
  26269. */
  26270. void repaintRow (const int rowNumber) throw();
  26271. /** This fairly obscure method creates an image that just shows the currently
  26272. selected row components.
  26273. It's a handy method for doing drag-and-drop, as it can be passed to the
  26274. DragAndDropContainer for use as the drag image.
  26275. Note that it will make the row components temporarily invisible, so if you're
  26276. using custom components this could affect them if they're sensitive to that
  26277. sort of thing.
  26278. @see Component::createComponentSnapshot
  26279. */
  26280. Image* createSnapshotOfSelectedRows();
  26281. /** Returns the viewport that this ListBox uses.
  26282. You may need to use this to change parameters such as whether scrollbars
  26283. are shown, etc.
  26284. */
  26285. Viewport* getViewport() const throw();
  26286. /** @internal */
  26287. bool keyPressed (const KeyPress& key);
  26288. /** @internal */
  26289. bool keyStateChanged();
  26290. /** @internal */
  26291. void paint (Graphics& g);
  26292. /** @internal */
  26293. void paintOverChildren (Graphics& g);
  26294. /** @internal */
  26295. void resized();
  26296. /** @internal */
  26297. void visibilityChanged();
  26298. /** @internal */
  26299. void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  26300. /** @internal */
  26301. void mouseMove (const MouseEvent&);
  26302. /** @internal */
  26303. void mouseExit (const MouseEvent&);
  26304. /** @internal */
  26305. void mouseUp (const MouseEvent&);
  26306. /** @internal */
  26307. void colourChanged();
  26308. juce_UseDebuggingNewOperator
  26309. private:
  26310. friend class ListViewport;
  26311. friend class TableListBox;
  26312. ListBoxModel* model;
  26313. ListViewport* viewport;
  26314. Component* headerComponent;
  26315. int totalItems, rowHeight, minimumRowWidth;
  26316. int outlineThickness;
  26317. int lastMouseX, lastMouseY, lastRowSelected;
  26318. bool mouseMoveSelects, multipleSelection, hasDoneInitialUpdate;
  26319. SparseSet <int> selected;
  26320. void selectRowInternal (const int rowNumber,
  26321. bool dontScrollToShowThisRow,
  26322. bool deselectOthersFirst,
  26323. bool isMouseClick);
  26324. ListBox (const ListBox&);
  26325. const ListBox& operator= (const ListBox&);
  26326. };
  26327. #endif // __JUCE_LISTBOX_JUCEHEADER__
  26328. /********* End of inlined file: juce_ListBox.h *********/
  26329. /********* Start of inlined file: juce_TextButton.h *********/
  26330. #ifndef __JUCE_TEXTBUTTON_JUCEHEADER__
  26331. #define __JUCE_TEXTBUTTON_JUCEHEADER__
  26332. /**
  26333. A button that uses the standard lozenge-shaped background with a line of
  26334. text on it.
  26335. @see Button, DrawableButton
  26336. */
  26337. class JUCE_API TextButton : public Button
  26338. {
  26339. public:
  26340. /** Creates a TextButton.
  26341. @param buttonName the text to put in the button (the component's name is also
  26342. initially set to this string, but these can be changed later
  26343. using the setName() and setButtonText() methods)
  26344. @param toolTip an optional string to use as a toolip
  26345. @see Button
  26346. */
  26347. TextButton (const String& buttonName,
  26348. const String& toolTip = String::empty);
  26349. /** Destructor. */
  26350. ~TextButton();
  26351. /** A set of colour IDs to use to change the colour of various aspects of the button.
  26352. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  26353. methods.
  26354. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  26355. */
  26356. enum ColourIds
  26357. {
  26358. buttonColourId = 0x1000100, /**< The colour used to fill the button shape (when the button is toggled
  26359. 'off'). The look-and-feel class might re-interpret this to add
  26360. effects, etc. */
  26361. buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled
  26362. 'on'). The look-and-feel class might re-interpret this to add
  26363. effects, etc. */
  26364. textColourId = 0x1000102 /**< The colour to use for the button's text. */
  26365. };
  26366. /** Resizes the button to fit neatly around its current text.
  26367. If newHeight is >= 0, the button's height will be changed to this
  26368. value. If it's less than zero, its height will be unaffected.
  26369. */
  26370. void changeWidthToFitText (const int newHeight = -1);
  26371. /** This can be overridden to use different fonts than the default one.
  26372. Note that you'll need to set the font's size appropriately, too.
  26373. */
  26374. virtual const Font getFont();
  26375. juce_UseDebuggingNewOperator
  26376. protected:
  26377. /** @internal */
  26378. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown);
  26379. /** @internal */
  26380. void colourChanged();
  26381. private:
  26382. TextButton (const TextButton&);
  26383. const TextButton& operator= (const TextButton&);
  26384. };
  26385. #endif // __JUCE_TEXTBUTTON_JUCEHEADER__
  26386. /********* End of inlined file: juce_TextButton.h *********/
  26387. /**
  26388. A component displaying a list of plugins, with options to scan for them,
  26389. add, remove and sort them.
  26390. */
  26391. class JUCE_API PluginListComponent : public Component,
  26392. public ListBoxModel,
  26393. public ChangeListener,
  26394. public ButtonListener,
  26395. public Timer
  26396. {
  26397. public:
  26398. /**
  26399. Creates the list component.
  26400. For info about the deadMansPedalFile, see the PluginDirectoryScanner constructor.
  26401. The properties file, if supplied, is used to store the user's last search paths.
  26402. */
  26403. PluginListComponent (KnownPluginList& listToRepresent,
  26404. const File& deadMansPedalFile,
  26405. PropertiesFile* const propertiesToUse);
  26406. /** Destructor. */
  26407. ~PluginListComponent();
  26408. /** @internal */
  26409. void resized();
  26410. /** @internal */
  26411. bool isInterestedInFileDrag (const StringArray& files);
  26412. /** @internal */
  26413. void filesDropped (const StringArray& files, int, int);
  26414. /** @internal */
  26415. int getNumRows();
  26416. /** @internal */
  26417. void paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected);
  26418. /** @internal */
  26419. void deleteKeyPressed (int lastRowSelected);
  26420. /** @internal */
  26421. void buttonClicked (Button* b);
  26422. /** @internal */
  26423. void changeListenerCallback (void*);
  26424. /** @internal */
  26425. void timerCallback();
  26426. juce_UseDebuggingNewOperator
  26427. private:
  26428. KnownPluginList& list;
  26429. File deadMansPedalFile;
  26430. ListBox* listBox;
  26431. TextButton* optionsButton;
  26432. PropertiesFile* propertiesToUse;
  26433. int typeToScan;
  26434. void scanFor (AudioPluginFormat* format);
  26435. PluginListComponent (const PluginListComponent&);
  26436. const PluginListComponent& operator= (const PluginListComponent&);
  26437. };
  26438. #endif // __JUCE_PLUGINLISTCOMPONENT_JUCEHEADER__
  26439. /********* End of inlined file: juce_PluginListComponent.h *********/
  26440. #endif
  26441. #ifndef __JUCE_AIFFAUDIOFORMAT_JUCEHEADER__
  26442. /********* Start of inlined file: juce_AiffAudioFormat.h *********/
  26443. #ifndef __JUCE_AIFFAUDIOFORMAT_JUCEHEADER__
  26444. #define __JUCE_AIFFAUDIOFORMAT_JUCEHEADER__
  26445. /********* Start of inlined file: juce_AudioFormat.h *********/
  26446. #ifndef __JUCE_AUDIOFORMAT_JUCEHEADER__
  26447. #define __JUCE_AUDIOFORMAT_JUCEHEADER__
  26448. /********* Start of inlined file: juce_AudioFormatWriter.h *********/
  26449. #ifndef __JUCE_AUDIOFORMATWRITER_JUCEHEADER__
  26450. #define __JUCE_AUDIOFORMATWRITER_JUCEHEADER__
  26451. /**
  26452. Writes samples to an audio file stream.
  26453. A subclass that writes a specific type of audio format will be created by
  26454. an AudioFormat object.
  26455. After creating one of these with the AudioFormat::createWriterFor() method
  26456. you can call its write() method to store the samples, and then delete it.
  26457. @see AudioFormat, AudioFormatReader
  26458. */
  26459. class JUCE_API AudioFormatWriter
  26460. {
  26461. protected:
  26462. /** Creates an AudioFormatWriter object.
  26463. @param destStream the stream to write to - this will be deleted
  26464. by this object when it is no longer needed
  26465. @param formatName the description that will be returned by the getFormatName()
  26466. method
  26467. @param sampleRate the sample rate to use - the base class just stores
  26468. this value, it doesn't do anything with it
  26469. @param numberOfChannels the number of channels to write - the base class just stores
  26470. this value, it doesn't do anything with it
  26471. @param bitsPerSample the bit depth of the stream - the base class just stores
  26472. this value, it doesn't do anything with it
  26473. */
  26474. AudioFormatWriter (OutputStream* const destStream,
  26475. const String& formatName,
  26476. const double sampleRate,
  26477. const unsigned int numberOfChannels,
  26478. const unsigned int bitsPerSample);
  26479. public:
  26480. /** Destructor. */
  26481. virtual ~AudioFormatWriter();
  26482. /** Returns a description of what type of format this is.
  26483. E.g. "AIFF file"
  26484. */
  26485. const String getFormatName() const throw() { return formatName; }
  26486. /** Writes a set of samples to the audio stream.
  26487. Note that if you're trying to write the contents of an AudioSampleBuffer, you
  26488. can use AudioSampleBuffer::writeToAudioWriter().
  26489. @param samplesToWrite an array of arrays containing the sample data for
  26490. each channel to write. This is a zero-terminated
  26491. array of arrays, and can contain a different number
  26492. of channels than the actual stream uses, and the
  26493. writer should do its best to cope with this.
  26494. If the format is fixed-point, each channel will be formatted
  26495. as an array of signed integers using the full 32-bit
  26496. range -0x80000000 to 0x7fffffff, regardless of the source's
  26497. bit-depth. If it is a floating-point format, you should treat
  26498. the arrays as arrays of floats, and just cast it to an (int**)
  26499. to pass it into the method.
  26500. @param numSamples the number of samples to write
  26501. */
  26502. virtual bool write (const int** samplesToWrite,
  26503. int numSamples) = 0;
  26504. /** Reads a section of samples from an AudioFormatReader, and writes these to
  26505. the output.
  26506. This will take care of any floating-point conversion that's required to convert
  26507. between the two formats. It won't deal with sample-rate conversion, though.
  26508. @returns false if it can't read or write properly during the operation
  26509. */
  26510. bool writeFromAudioReader (AudioFormatReader& reader,
  26511. int64 startSample,
  26512. int numSamplesToRead);
  26513. /** Reads some samples from an AudioSource, and writes these to the output.
  26514. The source must already have been initialised with the AudioSource::prepareToPlay() method
  26515. @param source the source to read from
  26516. @param numSamplesToRead total number of samples to read and write
  26517. @param samplesPerBlock the maximum number of samples to fetch from the source
  26518. @returns false if it can't read or write properly during the operation
  26519. */
  26520. bool writeFromAudioSource (AudioSource& source,
  26521. int numSamplesToRead,
  26522. const int samplesPerBlock = 2048);
  26523. /** Returns the sample rate being used. */
  26524. double getSampleRate() const throw() { return sampleRate; }
  26525. /** Returns the number of channels being written. */
  26526. int getNumChannels() const throw() { return numChannels; }
  26527. /** Returns the bit-depth of the data being written. */
  26528. int getBitsPerSample() const throw() { return bitsPerSample; }
  26529. /** Returns true if it's a floating-point format, false if it's fixed-point. */
  26530. bool isFloatingPoint() const throw() { return usesFloatingPointData; }
  26531. juce_UseDebuggingNewOperator
  26532. protected:
  26533. /** The sample rate of the stream. */
  26534. double sampleRate;
  26535. /** The number of channels being written to the stream. */
  26536. unsigned int numChannels;
  26537. /** The bit depth of the file. */
  26538. unsigned int bitsPerSample;
  26539. /** True if it's a floating-point format, false if it's fixed-point. */
  26540. bool usesFloatingPointData;
  26541. /** The output stream for Use by subclasses. */
  26542. OutputStream* output;
  26543. private:
  26544. String formatName;
  26545. };
  26546. #endif // __JUCE_AUDIOFORMATWRITER_JUCEHEADER__
  26547. /********* End of inlined file: juce_AudioFormatWriter.h *********/
  26548. /**
  26549. Subclasses of AudioFormat are used to read and write different audio
  26550. file formats.
  26551. @see AudioFormatReader, AudioFormatWriter, WavAudioFormat, AiffAudioFormat
  26552. */
  26553. class JUCE_API AudioFormat
  26554. {
  26555. public:
  26556. /** Destructor. */
  26557. virtual ~AudioFormat();
  26558. /** Returns the name of this format.
  26559. e.g. "WAV file" or "AIFF file"
  26560. */
  26561. const String& getFormatName() const;
  26562. /** Returns all the file extensions that might apply to a file of this format.
  26563. The first item will be the one that's preferred when creating a new file.
  26564. So for a wav file this might just return ".wav"; for an AIFF file it might
  26565. return two items, ".aif" and ".aiff"
  26566. */
  26567. const StringArray& getFileExtensions() const;
  26568. /** Returns true if this the given file can be read by this format.
  26569. Subclasses shouldn't do too much work here, just check the extension or
  26570. file type. The base class implementation just checks the file's extension
  26571. against one of the ones that was registered in the constructor.
  26572. */
  26573. virtual bool canHandleFile (const File& fileToTest);
  26574. /** Returns a set of sample rates that the format can read and write. */
  26575. virtual const Array <int> getPossibleSampleRates() = 0;
  26576. /** Returns a set of bit depths that the format can read and write. */
  26577. virtual const Array <int> getPossibleBitDepths() = 0;
  26578. /** Returns true if the format can do 2-channel audio. */
  26579. virtual bool canDoStereo() = 0;
  26580. /** Returns true if the format can do 1-channel audio. */
  26581. virtual bool canDoMono() = 0;
  26582. /** Returns true if the format uses compressed data. */
  26583. virtual bool isCompressed();
  26584. /** Returns a list of different qualities that can be used when writing.
  26585. Non-compressed formats will just return an empty array, but for something
  26586. like Ogg-Vorbis or MP3, it might return a list of bit-rates, etc.
  26587. When calling createWriterFor(), an index from this array is passed in to
  26588. tell the format which option is required.
  26589. */
  26590. virtual const StringArray getQualityOptions();
  26591. /** Tries to create an object that can read from a stream containing audio
  26592. data in this format.
  26593. The reader object that is returned can be used to read from the stream, and
  26594. should then be deleted by the caller.
  26595. @param sourceStream the stream to read from - the AudioFormatReader object
  26596. that is returned will delete this stream when it no longer
  26597. needs it.
  26598. @param deleteStreamIfOpeningFails if no reader can be created, this determines whether this method
  26599. should delete the stream object that was passed-in. (If a valid
  26600. reader is returned, it will always be in charge of deleting the
  26601. stream, so this parameter is ignored)
  26602. @see AudioFormatReader
  26603. */
  26604. virtual AudioFormatReader* createReaderFor (InputStream* sourceStream,
  26605. const bool deleteStreamIfOpeningFails) = 0;
  26606. /** Tries to create an object that can write to a stream with this audio format.
  26607. The writer object that is returned can be used to write to the stream, and
  26608. should then be deleted by the caller.
  26609. If the stream can't be created for some reason (e.g. the parameters passed in
  26610. here aren't suitable), this will return 0.
  26611. @param streamToWriteTo the stream that the data will go to - this will be
  26612. deleted by the AudioFormatWriter object when it's no longer
  26613. needed. If no AudioFormatWriter can be created by this method,
  26614. the stream will NOT be deleted, so that the caller can re-use it
  26615. to try to open a different format, etc
  26616. @param sampleRateToUse the sample rate for the file, which must be one of the ones
  26617. returned by getPossibleSampleRates()
  26618. @param numberOfChannels the number of channels - this must be either 1 or 2, and
  26619. the choice will depend on the results of canDoMono() and
  26620. canDoStereo()
  26621. @param bitsPerSample the bits per sample to use - this must be one of the values
  26622. returned by getPossibleBitDepths()
  26623. @param metadataValues a set of metadata values that the writer should try to write
  26624. to the stream. Exactly what these are depends on the format,
  26625. and the subclass doesn't actually have to do anything with
  26626. them if it doesn't want to. Have a look at the specific format
  26627. implementation classes to see possible values that can be
  26628. used
  26629. @param qualityOptionIndex the index of one of compression qualities returned by the
  26630. getQualityOptions() method. If there aren't any quality options
  26631. for this format, just pass 0 in this parameter, as it'll be
  26632. ignored
  26633. @see AudioFormatWriter
  26634. */
  26635. virtual AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  26636. double sampleRateToUse,
  26637. unsigned int numberOfChannels,
  26638. int bitsPerSample,
  26639. const StringPairArray& metadataValues,
  26640. int qualityOptionIndex) = 0;
  26641. protected:
  26642. /** Creates an AudioFormat object.
  26643. @param formatName this sets the value that will be returned by getFormatName()
  26644. @param fileExtensions a zero-terminated list of file extensions - this is what will
  26645. be returned by getFileExtension()
  26646. */
  26647. AudioFormat (const String& formatName,
  26648. const tchar** const fileExtensions);
  26649. private:
  26650. String formatName;
  26651. StringArray fileExtensions;
  26652. };
  26653. #endif // __JUCE_AUDIOFORMAT_JUCEHEADER__
  26654. /********* End of inlined file: juce_AudioFormat.h *********/
  26655. /**
  26656. Reads and Writes AIFF format audio files.
  26657. @see AudioFormat
  26658. */
  26659. class JUCE_API AiffAudioFormat : public AudioFormat
  26660. {
  26661. public:
  26662. /** Creates an format object. */
  26663. AiffAudioFormat();
  26664. /** Destructor. */
  26665. ~AiffAudioFormat();
  26666. const Array <int> getPossibleSampleRates();
  26667. const Array <int> getPossibleBitDepths();
  26668. bool canDoStereo();
  26669. bool canDoMono();
  26670. #if JUCE_MAC
  26671. bool canHandleFile (const File& fileToTest);
  26672. #endif
  26673. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  26674. const bool deleteStreamIfOpeningFails);
  26675. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  26676. double sampleRateToUse,
  26677. unsigned int numberOfChannels,
  26678. int bitsPerSample,
  26679. const StringPairArray& metadataValues,
  26680. int qualityOptionIndex);
  26681. juce_UseDebuggingNewOperator
  26682. };
  26683. #endif // __JUCE_AIFFAUDIOFORMAT_JUCEHEADER__
  26684. /********* End of inlined file: juce_AiffAudioFormat.h *********/
  26685. #endif
  26686. #ifndef __JUCE_AUDIOCDBURNER_JUCEHEADER__
  26687. /********* Start of inlined file: juce_AudioCDBurner.h *********/
  26688. #ifndef __JUCE_AUDIOCDBURNER_JUCEHEADER__
  26689. #define __JUCE_AUDIOCDBURNER_JUCEHEADER__
  26690. /**
  26691. */
  26692. class AudioCDBurner
  26693. {
  26694. public:
  26695. /** Returns a list of available optical drives.
  26696. Use openDevice() to open one of the items from this list.
  26697. */
  26698. static const StringArray findAvailableDevices();
  26699. /** Tries to open one of the optical drives.
  26700. The deviceIndex is an index into the array returned by findAvailableDevices().
  26701. */
  26702. static AudioCDBurner* openDevice (const int deviceIndex);
  26703. /** Destructor. */
  26704. ~AudioCDBurner();
  26705. /** Returns true if there's a writable disk in the drive.
  26706. */
  26707. bool isDiskPresent() const;
  26708. /** Returns the number of free blocks on the disk.
  26709. There are 75 blocks per second, at 44100Hz.
  26710. */
  26711. int getNumAvailableAudioBlocks() const;
  26712. /** Adds a track to be written.
  26713. The source passed-in here will be kept by this object, and it will
  26714. be used and deleted at some point in the future, either during the
  26715. burn() method or when this AudioCDBurner object is deleted. Your caller
  26716. method shouldn't keep a reference to it or use it again after passing
  26717. it in here.
  26718. */
  26719. bool addAudioTrack (AudioSource* source, int numSamples);
  26720. /**
  26721. Return true to cancel the current burn operation
  26722. */
  26723. class BurnProgressListener
  26724. {
  26725. public:
  26726. BurnProgressListener() throw() {}
  26727. virtual ~BurnProgressListener() {}
  26728. /** Called at intervals to report on the progress of the AudioCDBurner.
  26729. To cancel the burn, return true from this.
  26730. */
  26731. virtual bool audioCDBurnProgress (float proportionComplete) = 0;
  26732. };
  26733. const String burn (BurnProgressListener* listener,
  26734. const bool ejectDiscAfterwards,
  26735. const bool peformFakeBurnForTesting);
  26736. juce_UseDebuggingNewOperator
  26737. private:
  26738. AudioCDBurner (const int deviceIndex);
  26739. void* internal;
  26740. };
  26741. #endif // __JUCE_AUDIOCDBURNER_JUCEHEADER__
  26742. /********* End of inlined file: juce_AudioCDBurner.h *********/
  26743. #endif
  26744. #ifndef __JUCE_AUDIOCDREADER_JUCEHEADER__
  26745. /********* Start of inlined file: juce_AudioCDReader.h *********/
  26746. #ifndef __JUCE_AUDIOCDREADER_JUCEHEADER__
  26747. #define __JUCE_AUDIOCDREADER_JUCEHEADER__
  26748. #if JUCE_MAC
  26749. #endif
  26750. /**
  26751. A type of AudioFormatReader that reads from an audio CD.
  26752. One of these can be used to read a CD as if it's one big audio stream. Use the
  26753. getPositionOfTrackStart() method to find where the individual tracks are
  26754. within the stream.
  26755. @see AudioFormatReader
  26756. */
  26757. class JUCE_API AudioCDReader : public AudioFormatReader
  26758. {
  26759. public:
  26760. /** Returns a list of names of Audio CDs currently available for reading.
  26761. If there's a CD drive but no CD in it, this might return an empty list, or
  26762. possibly a device that can be opened but which has no tracks, depending
  26763. on the platform.
  26764. @see createReaderForCD
  26765. */
  26766. static const StringArray getAvailableCDNames();
  26767. /** Tries to create an AudioFormatReader that can read from an Audio CD.
  26768. @param index the index of one of the available CDs - use getAvailableCDNames()
  26769. to find out how many there are.
  26770. @returns a new AudioCDReader object, or 0 if it couldn't be created. The
  26771. caller will be responsible for deleting the object returned.
  26772. */
  26773. static AudioCDReader* createReaderForCD (const int index);
  26774. /** Destructor. */
  26775. ~AudioCDReader();
  26776. /** Implementation of the AudioFormatReader method. */
  26777. bool read (int** destSamples,
  26778. int64 startSampleInFile,
  26779. int numSamples);
  26780. /** Checks whether the CD has been removed from the drive.
  26781. */
  26782. bool isCDStillPresent() const;
  26783. /** Returns the total number of tracks (audio + data).
  26784. */
  26785. int getNumTracks() const;
  26786. /** Finds the sample offset of the start of a track.
  26787. @param trackNum the track number, where 0 is the first track.
  26788. */
  26789. int getPositionOfTrackStart (int trackNum) const;
  26790. /** Returns true if a given track is an audio track.
  26791. @param trackNum the track number, where 0 is the first track.
  26792. */
  26793. bool isTrackAudio (int trackNum) const;
  26794. /** Refreshes the object's table of contents.
  26795. If the disc has been ejected and a different one put in since this
  26796. object was created, this will cause it to update its idea of how many tracks
  26797. there are, etc.
  26798. */
  26799. void refreshTrackLengths();
  26800. /** Enables scanning for indexes within tracks.
  26801. @see getLastIndex
  26802. */
  26803. void enableIndexScanning (bool enabled);
  26804. /** Returns the index number found during the last read() call.
  26805. Index scanning is turned off by default - turn it on with enableIndexScanning().
  26806. Then when the read() method is called, if it comes across an index within that
  26807. block, the index number is stored and returned by this method.
  26808. Some devices might not support indexes, of course.
  26809. (If you don't know what CD indexes are, it's unlikely you'll ever need them).
  26810. @see enableIndexScanning
  26811. */
  26812. int getLastIndex() const;
  26813. /** Scans a track to find the position of any indexes within it.
  26814. @param trackNumber the track to look in, where 0 is the first track on the disc
  26815. @returns an array of sample positions of any index points found (not including
  26816. the index that marks the start of the track)
  26817. */
  26818. const Array <int> findIndexesInTrack (const int trackNumber);
  26819. /** Returns the CDDB id number for the CD.
  26820. It's not a great way of identifying a disc, but it's traditional.
  26821. */
  26822. int getCDDBId();
  26823. /** Tries to eject the disk.
  26824. Of course this might not be possible, if some other process is using it.
  26825. */
  26826. void ejectDisk();
  26827. juce_UseDebuggingNewOperator
  26828. private:
  26829. #if JUCE_MAC
  26830. File volumeDir;
  26831. OwnedArray<File> tracks;
  26832. Array <int> trackStartSamples;
  26833. int currentReaderTrack;
  26834. AudioFormatReader* reader;
  26835. AudioCDReader (const File& volume);
  26836. public:
  26837. static int compareElements (const File* const, const File* const) throw();
  26838. private:
  26839. #elif JUCE_WIN32
  26840. int numTracks;
  26841. int trackStarts[100];
  26842. bool audioTracks [100];
  26843. void* handle;
  26844. bool indexingEnabled;
  26845. int lastIndex, firstFrameInBuffer, samplesInBuffer;
  26846. MemoryBlock buffer;
  26847. AudioCDReader (void* handle);
  26848. int getIndexAt (int samplePos);
  26849. #elif JUCE_LINUX
  26850. AudioCDReader();
  26851. #endif
  26852. AudioCDReader (const AudioCDReader&);
  26853. const AudioCDReader& operator= (const AudioCDReader&);
  26854. };
  26855. #endif // __JUCE_AUDIOCDREADER_JUCEHEADER__
  26856. /********* End of inlined file: juce_AudioCDReader.h *********/
  26857. #endif
  26858. #ifndef __JUCE_AUDIOFORMAT_JUCEHEADER__
  26859. #endif
  26860. #ifndef __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__
  26861. /********* Start of inlined file: juce_AudioFormatManager.h *********/
  26862. #ifndef __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__
  26863. #define __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__
  26864. /**
  26865. A class for keeping a list of available audio formats, and for deciding which
  26866. one to use to open a given file.
  26867. You can either use this class as a singleton object, or create instances of it
  26868. yourself. Once created, use its registerFormat() method to tell it which
  26869. formats it should use.
  26870. @see AudioFormat
  26871. */
  26872. class JUCE_API AudioFormatManager
  26873. {
  26874. public:
  26875. /** Creates an empty format manager.
  26876. Before it'll be any use, you'll need to call registerFormat() with all the
  26877. formats you want it to be able to recognise.
  26878. */
  26879. AudioFormatManager();
  26880. /** Destructor. */
  26881. ~AudioFormatManager();
  26882. juce_DeclareSingleton (AudioFormatManager, false);
  26883. /** Adds a format to the manager's list of available file types.
  26884. The object passed-in will be deleted by this object, so don't keep a pointer
  26885. to it!
  26886. If makeThisTheDefaultFormat is true, then the getDefaultFormat() method will
  26887. return this one when called.
  26888. */
  26889. void registerFormat (AudioFormat* newFormat,
  26890. const bool makeThisTheDefaultFormat);
  26891. /** Handy method to make it easy to register the formats that come with Juce.
  26892. Currently, this will add WAV and AIFF to the list.
  26893. */
  26894. void registerBasicFormats();
  26895. /** Clears the list of known formats. */
  26896. void clearFormats();
  26897. /** Returns the number of currently registered file formats. */
  26898. int getNumKnownFormats() const;
  26899. /** Returns one of the registered file formats. */
  26900. AudioFormat* getKnownFormat (const int index) const;
  26901. /** Looks for which of the known formats is listed as being for a given file
  26902. extension.
  26903. The extension may have a dot before it, so e.g. ".wav" or "wav" are both ok.
  26904. */
  26905. AudioFormat* findFormatForFileExtension (const String& fileExtension) const;
  26906. /** Returns the format which has been set as the default one.
  26907. You can set a format as being the default when it is registered. It's useful
  26908. when you want to write to a file, because the best format may change between
  26909. platforms, e.g. AIFF is preferred on the Mac, WAV on Windows.
  26910. If none has been set as the default, this method will just return the first
  26911. one in the list.
  26912. */
  26913. AudioFormat* getDefaultFormat() const;
  26914. /** Returns a set of wildcards for file-matching that contains the extensions for
  26915. all known formats.
  26916. E.g. if might return "*.wav;*.aiff" if it just knows about wavs and aiffs.
  26917. */
  26918. const String getWildcardForAllFormats() const;
  26919. /** Searches through the known formats to try to create a suitable reader for
  26920. this file.
  26921. If none of the registered formats can open the file, it'll return 0. If it
  26922. returns a reader, it's the caller's responsibility to delete the reader.
  26923. */
  26924. AudioFormatReader* createReaderFor (const File& audioFile);
  26925. /** Searches through the known formats to try to create a suitable reader for
  26926. this stream.
  26927. The stream object that is passed-in will be deleted by this method or by the
  26928. reader that is returned, so the caller should not keep any references to it.
  26929. The stream that is passed-in must be capable of being repositioned so
  26930. that all the formats can have a go at opening it.
  26931. If none of the registered formats can open the stream, it'll return 0. If it
  26932. returns a reader, it's the caller's responsibility to delete the reader.
  26933. */
  26934. AudioFormatReader* createReaderFor (InputStream* audioFileStream);
  26935. juce_UseDebuggingNewOperator
  26936. private:
  26937. VoidArray knownFormats;
  26938. int defaultFormatIndex;
  26939. };
  26940. #endif // __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__
  26941. /********* End of inlined file: juce_AudioFormatManager.h *********/
  26942. #endif
  26943. #ifndef __JUCE_AUDIOFORMATREADER_JUCEHEADER__
  26944. #endif
  26945. #ifndef __JUCE_AUDIOFORMATWRITER_JUCEHEADER__
  26946. #endif
  26947. #ifndef __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  26948. /********* Start of inlined file: juce_AudioSubsectionReader.h *********/
  26949. #ifndef __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  26950. #define __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  26951. /**
  26952. This class is used to wrap an AudioFormatReader and only read from a
  26953. subsection of the file.
  26954. So if you have a reader which can read a 1000 sample file, you could wrap it
  26955. in one of these to only access, e.g. samples 100 to 200, and any samples
  26956. outside that will come back as 0. Accessing sample 0 from this reader will
  26957. actually read the first sample from the other's subsection, which might
  26958. be at a non-zero position.
  26959. @see AudioFormatReader
  26960. */
  26961. class JUCE_API AudioSubsectionReader : public AudioFormatReader
  26962. {
  26963. public:
  26964. /** Creates a AudioSubsectionReader for a given data source.
  26965. @param sourceReader the source reader from which we'll be taking data
  26966. @param subsectionStartSample the sample within the source reader which will be
  26967. mapped onto sample 0 for this reader.
  26968. @param subsectionLength the number of samples from the source that will
  26969. make up the subsection. If this reader is asked for
  26970. any samples beyond this region, it will return zero.
  26971. @param deleteSourceWhenDeleted if true, the sourceReader object will be deleted when
  26972. this object is deleted.
  26973. */
  26974. AudioSubsectionReader (AudioFormatReader* const sourceReader,
  26975. const int64 subsectionStartSample,
  26976. const int64 subsectionLength,
  26977. const bool deleteSourceWhenDeleted);
  26978. /** Destructor. */
  26979. ~AudioSubsectionReader();
  26980. bool read (int** destSamples,
  26981. int64 startSample,
  26982. int numSamples);
  26983. void readMaxLevels (int64 startSample,
  26984. int64 numSamples,
  26985. float& lowestLeft,
  26986. float& highestLeft,
  26987. float& lowestRight,
  26988. float& highestRight);
  26989. juce_UseDebuggingNewOperator
  26990. private:
  26991. AudioFormatReader* const source;
  26992. int64 startSample, length;
  26993. const bool deleteSourceWhenDeleted;
  26994. AudioSubsectionReader (const AudioSubsectionReader&);
  26995. const AudioSubsectionReader& operator= (const AudioSubsectionReader&);
  26996. };
  26997. #endif // __JUCE_AUDIOSUBSECTIONREADER_JUCEHEADER__
  26998. /********* End of inlined file: juce_AudioSubsectionReader.h *********/
  26999. #endif
  27000. #ifndef __JUCE_AUDIOTHUMBNAIL_JUCEHEADER__
  27001. /********* Start of inlined file: juce_AudioThumbnail.h *********/
  27002. #ifndef __JUCE_AUDIOTHUMBNAIL_JUCEHEADER__
  27003. #define __JUCE_AUDIOTHUMBNAIL_JUCEHEADER__
  27004. class AudioThumbnailCache;
  27005. /**
  27006. Makes it easy to quickly draw scaled views of the waveform shape of an
  27007. audio file.
  27008. To use this class, just create an AudioThumbNail class for the file you want
  27009. to draw, call setSource to tell it which file or resource to use, then call
  27010. drawChannel() to draw it.
  27011. The class will asynchronously scan the wavefile to create its scaled-down view,
  27012. so you should make your UI repaint itself as this data comes in. To do this, the
  27013. AudioThumbnail is a ChangeBroadcaster, and will broadcast a message when its
  27014. listeners should repaint themselves.
  27015. The thumbnail stores an internal low-res version of the wave data, and this can
  27016. be loaded and saved to avoid having to scan the file again.
  27017. @see AudioThumbnailCache
  27018. */
  27019. class JUCE_API AudioThumbnail : public ChangeBroadcaster,
  27020. public TimeSliceClient,
  27021. private Timer
  27022. {
  27023. public:
  27024. /** Creates an audio thumbnail.
  27025. @param sourceSamplesPerThumbnailSample when creating a stored, low-res version
  27026. of the audio data, this is the scale at which it should be done
  27027. @param formatManagerToUse the audio format manager that is used to open the file
  27028. @param cacheToUse an instance of an AudioThumbnailCache - this provides a background
  27029. thread and storage that is used to by the thumbnail, and the cache
  27030. object can be shared between multiple thumbnails
  27031. */
  27032. AudioThumbnail (const int sourceSamplesPerThumbnailSample,
  27033. AudioFormatManager& formatManagerToUse,
  27034. AudioThumbnailCache& cacheToUse);
  27035. /** Destructor. */
  27036. ~AudioThumbnail();
  27037. /** Specifies the file or stream that contains the audio file.
  27038. For a file, just call
  27039. @code
  27040. setSource (new FileInputSource (file))
  27041. @endcode
  27042. You can pass a zero in here to clear the thumbnail.
  27043. The source that is passed in will be deleted by this object when it is no
  27044. longer needed
  27045. */
  27046. void setSource (InputSource* const newSource);
  27047. /** Reloads the low res thumbnail data from an input stream.
  27048. The thumb will automatically attempt to reload itself from its
  27049. AudioThumbnailCache.
  27050. */
  27051. void loadFrom (InputStream& input);
  27052. /** Saves the low res thumbnail data to an output stream.
  27053. The thumb will automatically attempt to save itself to its
  27054. AudioThumbnailCache after it finishes scanning the wave file.
  27055. */
  27056. void saveTo (OutputStream& output) const;
  27057. /** Returns the number of channels in the file.
  27058. */
  27059. int getNumChannels() const throw();
  27060. /** Returns the length of the audio file.
  27061. */
  27062. double getTotalLength() const throw();
  27063. /** Renders the waveform shape for a channel.
  27064. The waveform will be drawn within the specified rectangle, where startTime
  27065. and endTime specify the times within the audio file that should be positioned
  27066. at the left and right edges of the rectangle.
  27067. The waveform will be scaled vertically so that a full-volume sample will fill
  27068. the rectangle vertically, but you can also specify an extra vertical scale factor
  27069. with the verticalZoomFactor parameter.
  27070. */
  27071. void drawChannel (Graphics& g,
  27072. int x, int y, int w, int h,
  27073. double startTime,
  27074. double endTime,
  27075. int channelNum,
  27076. const float verticalZoomFactor);
  27077. /** Returns true if the low res preview is fully generated.
  27078. */
  27079. bool isFullyLoaded() const throw();
  27080. /** @internal */
  27081. bool useTimeSlice();
  27082. /** @internal */
  27083. void timerCallback();
  27084. juce_UseDebuggingNewOperator
  27085. private:
  27086. AudioFormatManager& formatManagerToUse;
  27087. AudioThumbnailCache& cache;
  27088. InputSource* source;
  27089. CriticalSection readerLock;
  27090. AudioFormatReader* reader;
  27091. MemoryBlock data, cachedLevels;
  27092. int orginalSamplesPerThumbnailSample;
  27093. int numChannelsCached, numSamplesCached;
  27094. double cachedStart, cachedTimePerPixel;
  27095. bool cacheNeedsRefilling;
  27096. void clear();
  27097. AudioFormatReader* createReader() const;
  27098. void generateSection (AudioFormatReader& reader,
  27099. int64 startSample,
  27100. int numSamples);
  27101. char* getChannelData (int channel) const;
  27102. void refillCache (const int numSamples,
  27103. double startTime,
  27104. const double timePerPixel);
  27105. friend class AudioThumbnailCache;
  27106. // true if it needs more callbacks from the readNextBlockFromAudioFile() method
  27107. bool initialiseFromAudioFile (AudioFormatReader& reader);
  27108. // returns true if more needs to be read
  27109. bool readNextBlockFromAudioFile (AudioFormatReader& reader);
  27110. };
  27111. #endif // __JUCE_AUDIOTHUMBNAIL_JUCEHEADER__
  27112. /********* End of inlined file: juce_AudioThumbnail.h *********/
  27113. #endif
  27114. #ifndef __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__
  27115. /********* Start of inlined file: juce_AudioThumbnailCache.h *********/
  27116. #ifndef __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__
  27117. #define __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__
  27118. struct ThumbnailCacheEntry;
  27119. /**
  27120. An instance of this class is used to manage multiple AudioThumbnail objects.
  27121. The cache runs a single background thread that is shared by all the thumbnails
  27122. that need it, and it maintains a set of low-res previews in memory, to avoid
  27123. having to re-scan audio files too often.
  27124. @see AudioThumbnail
  27125. */
  27126. class JUCE_API AudioThumbnailCache : public TimeSliceThread
  27127. {
  27128. public:
  27129. /** Creates a cache object.
  27130. The maxNumThumbsToStore parameter lets you specify how many previews should
  27131. be kept in memory at once.
  27132. */
  27133. AudioThumbnailCache (const int maxNumThumbsToStore);
  27134. /** Destructor. */
  27135. ~AudioThumbnailCache();
  27136. /** Clears out any stored thumbnails.
  27137. */
  27138. void clear();
  27139. /** Reloads the specified thumb if this cache contains the appropriate stored
  27140. data.
  27141. This is called automatically by the AudioThumbnail class, so you shouldn't
  27142. normally need to call it directly.
  27143. */
  27144. bool loadThumb (AudioThumbnail& thumb, const int64 hashCode);
  27145. /** Stores the cachable data from the specified thumb in this cache.
  27146. This is called automatically by the AudioThumbnail class, so you shouldn't
  27147. normally need to call it directly.
  27148. */
  27149. void storeThumb (const AudioThumbnail& thumb, const int64 hashCode);
  27150. juce_UseDebuggingNewOperator
  27151. private:
  27152. OwnedArray <ThumbnailCacheEntry> thumbs;
  27153. int maxNumThumbsToStore;
  27154. friend class AudioThumbnail;
  27155. void addThumbnail (AudioThumbnail* const thumb);
  27156. void removeThumbnail (AudioThumbnail* const thumb);
  27157. };
  27158. #endif // __JUCE_AUDIOTHUMBNAILCACHE_JUCEHEADER__
  27159. /********* End of inlined file: juce_AudioThumbnailCache.h *********/
  27160. #endif
  27161. #ifndef __JUCE_FLACAUDIOFORMAT_JUCEHEADER__
  27162. /********* Start of inlined file: juce_FlacAudioFormat.h *********/
  27163. #ifndef __JUCE_FLACAUDIOFORMAT_JUCEHEADER__
  27164. #define __JUCE_FLACAUDIOFORMAT_JUCEHEADER__
  27165. #if JUCE_USE_FLAC || defined (DOXYGEN)
  27166. /**
  27167. Reads and writes the lossless-compression FLAC audio format.
  27168. To compile this, you'll need to set the JUCE_USE_FLAC flag in juce_Config.h,
  27169. and make sure your include search path and library search path are set up to find
  27170. the FLAC header files and static libraries.
  27171. @see AudioFormat
  27172. */
  27173. class JUCE_API FlacAudioFormat : public AudioFormat
  27174. {
  27175. public:
  27176. FlacAudioFormat();
  27177. ~FlacAudioFormat();
  27178. const Array <int> getPossibleSampleRates();
  27179. const Array <int> getPossibleBitDepths();
  27180. bool canDoStereo();
  27181. bool canDoMono();
  27182. bool isCompressed();
  27183. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  27184. const bool deleteStreamIfOpeningFails);
  27185. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  27186. double sampleRateToUse,
  27187. unsigned int numberOfChannels,
  27188. int bitsPerSample,
  27189. const StringPairArray& metadataValues,
  27190. int qualityOptionIndex);
  27191. juce_UseDebuggingNewOperator
  27192. };
  27193. #endif
  27194. #endif // __JUCE_FLACAUDIOFORMAT_JUCEHEADER__
  27195. /********* End of inlined file: juce_FlacAudioFormat.h *********/
  27196. #endif
  27197. #ifndef __JUCE_OGGVORBISAUDIOFORMAT_JUCEHEADER__
  27198. /********* Start of inlined file: juce_OggVorbisAudioFormat.h *********/
  27199. #ifndef __JUCE_OGGVORBISAUDIOFORMAT_JUCEHEADER__
  27200. #define __JUCE_OGGVORBISAUDIOFORMAT_JUCEHEADER__
  27201. #if JUCE_USE_OGGVORBIS || defined (DOXYGEN)
  27202. /**
  27203. Reads and writes the Ogg-Vorbis audio format.
  27204. To compile this, you'll need to set the JUCE_USE_OGGVORBIS flag in juce_Config.h,
  27205. and make sure your include search path and library search path are set up to find
  27206. the Vorbis and Ogg header files and static libraries.
  27207. @see AudioFormat,
  27208. */
  27209. class JUCE_API OggVorbisAudioFormat : public AudioFormat
  27210. {
  27211. public:
  27212. OggVorbisAudioFormat();
  27213. ~OggVorbisAudioFormat();
  27214. const Array <int> getPossibleSampleRates();
  27215. const Array <int> getPossibleBitDepths();
  27216. bool canDoStereo();
  27217. bool canDoMono();
  27218. bool isCompressed();
  27219. const StringArray getQualityOptions();
  27220. /** Tries to estimate the quality level of an ogg file based on its size.
  27221. If it can't read the file for some reason, this will just return 1 (medium quality),
  27222. otherwise it will return the approximate quality setting that would have been used
  27223. to create the file.
  27224. @see getQualityOptions
  27225. */
  27226. int estimateOggFileQuality (const File& source);
  27227. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  27228. const bool deleteStreamIfOpeningFails);
  27229. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  27230. double sampleRateToUse,
  27231. unsigned int numberOfChannels,
  27232. int bitsPerSample,
  27233. const StringPairArray& metadataValues,
  27234. int qualityOptionIndex);
  27235. juce_UseDebuggingNewOperator
  27236. };
  27237. #endif
  27238. #endif // __JUCE_OGGVORBISAUDIOFORMAT_JUCEHEADER__
  27239. /********* End of inlined file: juce_OggVorbisAudioFormat.h *********/
  27240. #endif
  27241. #ifndef __JUCE_QUICKTIMEAUDIOFORMAT_JUCEHEADER__
  27242. /********* Start of inlined file: juce_QuickTimeAudioFormat.h *********/
  27243. #ifndef __JUCE_QUICKTIMEAUDIOFORMAT_JUCEHEADER__
  27244. #define __JUCE_QUICKTIMEAUDIOFORMAT_JUCEHEADER__
  27245. #if JUCE_QUICKTIME
  27246. /**
  27247. Uses QuickTime to read the audio track a movie or media file.
  27248. As well as QuickTime movies, this should also manage to open other audio
  27249. files that quicktime can understand, like mp3, m4a, etc.
  27250. @see AudioFormat
  27251. */
  27252. class JUCE_API QuickTimeAudioFormat : public AudioFormat
  27253. {
  27254. public:
  27255. /** Creates a format object. */
  27256. QuickTimeAudioFormat();
  27257. /** Destructor. */
  27258. ~QuickTimeAudioFormat();
  27259. const Array <int> getPossibleSampleRates();
  27260. const Array <int> getPossibleBitDepths();
  27261. bool canDoStereo();
  27262. bool canDoMono();
  27263. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  27264. const bool deleteStreamIfOpeningFails);
  27265. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  27266. double sampleRateToUse,
  27267. unsigned int numberOfChannels,
  27268. int bitsPerSample,
  27269. const StringPairArray& metadataValues,
  27270. int qualityOptionIndex);
  27271. juce_UseDebuggingNewOperator
  27272. };
  27273. #endif
  27274. #endif // __JUCE_QUICKTIMEAUDIOFORMAT_JUCEHEADER__
  27275. /********* End of inlined file: juce_QuickTimeAudioFormat.h *********/
  27276. #endif
  27277. #ifndef __JUCE_WAVAUDIOFORMAT_JUCEHEADER__
  27278. /********* Start of inlined file: juce_WavAudioFormat.h *********/
  27279. #ifndef __JUCE_WAVAUDIOFORMAT_JUCEHEADER__
  27280. #define __JUCE_WAVAUDIOFORMAT_JUCEHEADER__
  27281. /**
  27282. Reads and Writes WAV format audio files.
  27283. @see AudioFormat
  27284. */
  27285. class JUCE_API WavAudioFormat : public AudioFormat
  27286. {
  27287. public:
  27288. /** Creates a format object. */
  27289. WavAudioFormat();
  27290. /** Destructor. */
  27291. ~WavAudioFormat();
  27292. /** Metadata property name used by wav readers and writers for adding
  27293. a BWAV chunk to the file.
  27294. @see AudioFormatReader::metadataValues, createWriterFor
  27295. */
  27296. static const tchar* const bwavDescription;
  27297. /** Metadata property name used by wav readers and writers for adding
  27298. a BWAV chunk to the file.
  27299. @see AudioFormatReader::metadataValues, createWriterFor
  27300. */
  27301. static const tchar* const bwavOriginator;
  27302. /** Metadata property name used by wav readers and writers for adding
  27303. a BWAV chunk to the file.
  27304. @see AudioFormatReader::metadataValues, createWriterFor
  27305. */
  27306. static const tchar* const bwavOriginatorRef;
  27307. /** Metadata property name used by wav readers and writers for adding
  27308. a BWAV chunk to the file.
  27309. Date format is: yyyy-mm-dd
  27310. @see AudioFormatReader::metadataValues, createWriterFor
  27311. */
  27312. static const tchar* const bwavOriginationDate;
  27313. /** Metadata property name used by wav readers and writers for adding
  27314. a BWAV chunk to the file.
  27315. Time format is: hh-mm-ss
  27316. @see AudioFormatReader::metadataValues, createWriterFor
  27317. */
  27318. static const tchar* const bwavOriginationTime;
  27319. /** Metadata property name used by wav readers and writers for adding
  27320. a BWAV chunk to the file.
  27321. This is the number of samples from the start of an edit that the
  27322. file is supposed to begin at. Seems like an obvious mistake to
  27323. only allow a file to occur in an edit once, but that's the way
  27324. it is..
  27325. @see AudioFormatReader::metadataValues, createWriterFor
  27326. */
  27327. static const tchar* const bwavTimeReference;
  27328. /** Metadata property name used by wav readers and writers for adding
  27329. a BWAV chunk to the file.
  27330. This is a
  27331. @see AudioFormatReader::metadataValues, createWriterFor
  27332. */
  27333. static const tchar* const bwavCodingHistory;
  27334. /** Utility function to fill out the appropriate metadata for a BWAV file.
  27335. This just makes it easier than using the property names directly, and it
  27336. fills out the time and date in the right format.
  27337. */
  27338. static const StringPairArray createBWAVMetadata (const String& description,
  27339. const String& originator,
  27340. const String& originatorRef,
  27341. const Time& dateAndTime,
  27342. const int64 timeReferenceSamples,
  27343. const String& codingHistory);
  27344. const Array <int> getPossibleSampleRates();
  27345. const Array <int> getPossibleBitDepths();
  27346. bool canDoStereo();
  27347. bool canDoMono();
  27348. AudioFormatReader* createReaderFor (InputStream* sourceStream,
  27349. const bool deleteStreamIfOpeningFails);
  27350. AudioFormatWriter* createWriterFor (OutputStream* streamToWriteTo,
  27351. double sampleRateToUse,
  27352. unsigned int numberOfChannels,
  27353. int bitsPerSample,
  27354. const StringPairArray& metadataValues,
  27355. int qualityOptionIndex);
  27356. juce_UseDebuggingNewOperator
  27357. };
  27358. #endif // __JUCE_WAVAUDIOFORMAT_JUCEHEADER__
  27359. /********* End of inlined file: juce_WavAudioFormat.h *********/
  27360. #endif
  27361. #ifndef __JUCE_ACTIONBROADCASTER_JUCEHEADER__
  27362. /********* Start of inlined file: juce_ActionBroadcaster.h *********/
  27363. #ifndef __JUCE_ACTIONBROADCASTER_JUCEHEADER__
  27364. #define __JUCE_ACTIONBROADCASTER_JUCEHEADER__
  27365. /********* Start of inlined file: juce_ActionListenerList.h *********/
  27366. #ifndef __JUCE_ACTIONLISTENERLIST_JUCEHEADER__
  27367. #define __JUCE_ACTIONLISTENERLIST_JUCEHEADER__
  27368. /**
  27369. A set of ActionListeners.
  27370. Listeners can be added and removed from the list, and messages can be
  27371. broadcast to all the listeners.
  27372. @see ActionListener, ActionBroadcaster
  27373. */
  27374. class JUCE_API ActionListenerList : public MessageListener
  27375. {
  27376. public:
  27377. /** Creates an empty list. */
  27378. ActionListenerList() throw();
  27379. /** Destructor. */
  27380. ~ActionListenerList() throw();
  27381. /** Adds a listener to the list.
  27382. (Trying to add a listener that's already on the list will have no effect).
  27383. */
  27384. void addActionListener (ActionListener* const listener) throw();
  27385. /** Removes a listener from the list.
  27386. If the listener isn't on the list, this won't have any effect.
  27387. */
  27388. void removeActionListener (ActionListener* const listener) throw();
  27389. /** Removes all listeners from the list. */
  27390. void removeAllActionListeners() throw();
  27391. /** Broadcasts a message to all the registered listeners.
  27392. This sends the message asynchronously.
  27393. If a listener is on the list when this method is called but is removed from
  27394. the list before the message arrives, it won't receive the message. Similarly
  27395. listeners that are added to the list after the message is sent but before it
  27396. arrives won't get the message either.
  27397. */
  27398. void sendActionMessage (const String& message) const;
  27399. /** @internal */
  27400. void handleMessage (const Message&);
  27401. juce_UseDebuggingNewOperator
  27402. private:
  27403. SortedSet <void*> actionListeners_;
  27404. CriticalSection actionListenerLock_;
  27405. ActionListenerList (const ActionListenerList&);
  27406. const ActionListenerList& operator= (const ActionListenerList&);
  27407. };
  27408. #endif // __JUCE_ACTIONLISTENERLIST_JUCEHEADER__
  27409. /********* End of inlined file: juce_ActionListenerList.h *********/
  27410. /** Manages a list of ActionListeners, and can send them messages.
  27411. To quickly add methods to your class that can add/remove action
  27412. listeners and broadcast to them, you can derive from this.
  27413. @see ActionListenerList, ActionListener
  27414. */
  27415. class JUCE_API ActionBroadcaster
  27416. {
  27417. public:
  27418. /** Creates an ActionBroadcaster. */
  27419. ActionBroadcaster() throw();
  27420. /** Destructor. */
  27421. virtual ~ActionBroadcaster();
  27422. /** Adds a listener to the list.
  27423. (Trying to add a listener that's already on the list will have no effect).
  27424. */
  27425. void addActionListener (ActionListener* const listener);
  27426. /** Removes a listener from the list.
  27427. If the listener isn't on the list, this won't have any effect.
  27428. */
  27429. void removeActionListener (ActionListener* const listener);
  27430. /** Removes all listeners from the list. */
  27431. void removeAllActionListeners();
  27432. /** Broadcasts a message to all the registered listeners.
  27433. @see ActionListenerList::sendActionMessage
  27434. */
  27435. void sendActionMessage (const String& message) const;
  27436. private:
  27437. ActionListenerList actionListenerList;
  27438. ActionBroadcaster (const ActionBroadcaster&);
  27439. const ActionBroadcaster& operator= (const ActionBroadcaster&);
  27440. };
  27441. #endif // __JUCE_ACTIONBROADCASTER_JUCEHEADER__
  27442. /********* End of inlined file: juce_ActionBroadcaster.h *********/
  27443. #endif
  27444. #ifndef __JUCE_ACTIONLISTENER_JUCEHEADER__
  27445. #endif
  27446. #ifndef __JUCE_ACTIONLISTENERLIST_JUCEHEADER__
  27447. #endif
  27448. #ifndef __JUCE_ASYNCUPDATER_JUCEHEADER__
  27449. #endif
  27450. #ifndef __JUCE_CHANGEBROADCASTER_JUCEHEADER__
  27451. #endif
  27452. #ifndef __JUCE_CHANGELISTENER_JUCEHEADER__
  27453. #endif
  27454. #ifndef __JUCE_CHANGELISTENERLIST_JUCEHEADER__
  27455. #endif
  27456. #ifndef __JUCE_INTERPROCESSCONNECTION_JUCEHEADER__
  27457. /********* Start of inlined file: juce_InterprocessConnection.h *********/
  27458. #ifndef __JUCE_INTERPROCESSCONNECTION_JUCEHEADER__
  27459. #define __JUCE_INTERPROCESSCONNECTION_JUCEHEADER__
  27460. class InterprocessConnectionServer;
  27461. /**
  27462. Manages a simple two-way messaging connection to another process, using either
  27463. a socket or a named pipe as the transport medium.
  27464. To connect to a waiting socket or an open pipe, use the connectToSocket() or
  27465. connectToPipe() methods. If this succeeds, messages can be sent to the other end,
  27466. and incoming messages will result in a callback via the messageReceived()
  27467. method.
  27468. To open a pipe and wait for another client to connect to it, use the createPipe()
  27469. method.
  27470. To act as a socket server and create connections for one or more client, see the
  27471. InterprocessConnectionServer class.
  27472. @see InterprocessConnectionServer, Socket, NamedPipe
  27473. */
  27474. class JUCE_API InterprocessConnection : public Thread,
  27475. private MessageListener
  27476. {
  27477. public:
  27478. /** Creates a connection.
  27479. Connections are created manually, connecting them with the connectToSocket()
  27480. or connectToPipe() methods, or they are created automatically by a InterprocessConnectionServer
  27481. when a client wants to connect.
  27482. @param callbacksOnMessageThread if true, callbacks to the connectionMade(),
  27483. connectionLost() and messageReceived() methods will
  27484. always be made using the message thread; if false,
  27485. these will be called immediately on the connection's
  27486. own thread.
  27487. @param magicMessageHeaderNumber a magic number to use in the header to check the
  27488. validity of the data blocks being sent and received. This
  27489. can be any number, but the sender and receiver must obviously
  27490. use matching values or they won't recognise each other.
  27491. */
  27492. InterprocessConnection (const bool callbacksOnMessageThread = true,
  27493. const uint32 magicMessageHeaderNumber = 0xf2b49e2c);
  27494. /** Destructor. */
  27495. ~InterprocessConnection();
  27496. /** Tries to connect this object to a socket.
  27497. For this to work, the machine on the other end needs to have a InterprocessConnectionServer
  27498. object waiting to receive client connections on this port number.
  27499. @param hostName the host computer, either a network address or name
  27500. @param portNumber the socket port number to try to connect to
  27501. @param timeOutMillisecs how long to keep trying before giving up
  27502. @returns true if the connection is established successfully
  27503. @see Socket
  27504. */
  27505. bool connectToSocket (const String& hostName,
  27506. const int portNumber,
  27507. const int timeOutMillisecs);
  27508. /** Tries to connect the object to an existing named pipe.
  27509. For this to work, another process on the same computer must already have opened
  27510. an InterprocessConnection object and used createPipe() to create a pipe for this
  27511. to connect to.
  27512. You can optionally specify a timeout length to be passed to the NamedPipe::read() method.
  27513. @returns true if it connects successfully.
  27514. @see createPipe, NamedPipe
  27515. */
  27516. bool connectToPipe (const String& pipeName,
  27517. const int pipeReceiveMessageTimeoutMs = -1);
  27518. /** Tries to create a new pipe for other processes to connect to.
  27519. This creates a pipe with the given name, so that other processes can use
  27520. connectToPipe() to connect to the other end.
  27521. You can optionally specify a timeout length to be passed to the NamedPipe::read() method.
  27522. If another process is already using this pipe, this will fail and return false.
  27523. */
  27524. bool createPipe (const String& pipeName,
  27525. const int pipeReceiveMessageTimeoutMs = -1);
  27526. /** Disconnects and closes any currently-open sockets or pipes. */
  27527. void disconnect();
  27528. /** True if a socket or pipe is currently active. */
  27529. bool isConnected() const;
  27530. /** Returns the socket that this connection is using (or null if it uses a pipe). */
  27531. StreamingSocket* getSocket() const throw() { return socket; }
  27532. /** Returns the pipe that this connection is using (or null if it uses a socket). */
  27533. NamedPipe* getPipe() const throw() { return pipe; }
  27534. /** Returns the name of the machine at the other end of this connection.
  27535. This will return an empty string if the other machine isn't known for
  27536. some reason.
  27537. */
  27538. const String getConnectedHostName() const;
  27539. /** Tries to send a message to the other end of this connection.
  27540. This will fail if it's not connected, or if there's some kind of write error. If
  27541. it succeeds, the connection object at the other end will receive the message by
  27542. a callback to its messageReceived() method.
  27543. @see messageReceived
  27544. */
  27545. bool sendMessage (const MemoryBlock& message);
  27546. /** Called when the connection is first connected.
  27547. If the connection was created with the callbacksOnMessageThread flag set, then
  27548. this will be called on the message thread; otherwise it will be called on a server
  27549. thread.
  27550. */
  27551. virtual void connectionMade() = 0;
  27552. /** Called when the connection is broken.
  27553. If the connection was created with the callbacksOnMessageThread flag set, then
  27554. this will be called on the message thread; otherwise it will be called on a server
  27555. thread.
  27556. */
  27557. virtual void connectionLost() = 0;
  27558. /** Called when a message arrives.
  27559. When the object at the other end of this connection sends us a message with sendMessage(),
  27560. this callback is used to deliver it to us.
  27561. If the connection was created with the callbacksOnMessageThread flag set, then
  27562. this will be called on the message thread; otherwise it will be called on a server
  27563. thread.
  27564. @see sendMessage
  27565. */
  27566. virtual void messageReceived (const MemoryBlock& message) = 0;
  27567. juce_UseDebuggingNewOperator
  27568. private:
  27569. CriticalSection pipeAndSocketLock;
  27570. StreamingSocket* socket;
  27571. NamedPipe* pipe;
  27572. bool callbackConnectionState;
  27573. const bool useMessageThread;
  27574. const uint32 magicMessageHeader;
  27575. int pipeReceiveMessageTimeout;
  27576. friend class InterprocessConnectionServer;
  27577. void initialiseWithSocket (StreamingSocket* const socket_);
  27578. void initialiseWithPipe (NamedPipe* const pipe_);
  27579. void handleMessage (const Message& message);
  27580. void connectionMadeInt();
  27581. void connectionLostInt();
  27582. void deliverDataInt (const MemoryBlock& data);
  27583. bool readNextMessageInt();
  27584. void run();
  27585. InterprocessConnection (const InterprocessConnection&);
  27586. const InterprocessConnection& operator= (const InterprocessConnection&);
  27587. };
  27588. #endif // __JUCE_INTERPROCESSCONNECTION_JUCEHEADER__
  27589. /********* End of inlined file: juce_InterprocessConnection.h *********/
  27590. #endif
  27591. #ifndef __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__
  27592. /********* Start of inlined file: juce_InterprocessConnectionServer.h *********/
  27593. #ifndef __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__
  27594. #define __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__
  27595. /**
  27596. An object that waits for client sockets to connect to a port on this host, and
  27597. creates InterprocessConnection objects for each one.
  27598. To use this, create a class derived from it which implements the createConnectionObject()
  27599. method, so that it creates suitable connection objects for each client that tries
  27600. to connect.
  27601. @see InterprocessConnection
  27602. */
  27603. class JUCE_API InterprocessConnectionServer : private Thread
  27604. {
  27605. public:
  27606. /** Creates an uninitialised server object.
  27607. */
  27608. InterprocessConnectionServer();
  27609. /** Destructor. */
  27610. ~InterprocessConnectionServer();
  27611. /** Starts an internal thread which listens on the given port number.
  27612. While this is running, in another process tries to connect with the
  27613. InterprocessConnection::connectToSocket() method, this object will call
  27614. createConnectionObject() to create a connection to that client.
  27615. Use stop() to stop the thread running.
  27616. @see createConnectionObject, stop
  27617. */
  27618. bool beginWaitingForSocket (const int portNumber);
  27619. /** Terminates the listener thread, if it's active.
  27620. @see beginWaitingForSocket
  27621. */
  27622. void stop();
  27623. protected:
  27624. /** Creates a suitable connection object for a client process that wants to
  27625. connect to this one.
  27626. This will be called by the listener thread when a client process tries
  27627. to connect, and must return a new InterprocessConnection object that will
  27628. then run as this end of the connection.
  27629. @see InterprocessConnection
  27630. */
  27631. virtual InterprocessConnection* createConnectionObject() = 0;
  27632. public:
  27633. juce_UseDebuggingNewOperator
  27634. private:
  27635. StreamingSocket* volatile socket;
  27636. void run();
  27637. InterprocessConnectionServer (const InterprocessConnectionServer&);
  27638. const InterprocessConnectionServer& operator= (const InterprocessConnectionServer&);
  27639. };
  27640. #endif // __JUCE_INTERPROCESSCONNECTIONSERVER_JUCEHEADER__
  27641. /********* End of inlined file: juce_InterprocessConnectionServer.h *********/
  27642. #endif
  27643. #ifndef __JUCE_MESSAGE_JUCEHEADER__
  27644. #endif
  27645. #ifndef __JUCE_MESSAGELISTENER_JUCEHEADER__
  27646. #endif
  27647. #ifndef __JUCE_MESSAGEMANAGER_JUCEHEADER__
  27648. /********* Start of inlined file: juce_MessageManager.h *********/
  27649. #ifndef __JUCE_MESSAGEMANAGER_JUCEHEADER__
  27650. #define __JUCE_MESSAGEMANAGER_JUCEHEADER__
  27651. class Thread;
  27652. class InternalTimerThread;
  27653. /** See MessageManager::callFunctionOnMessageThread() for use of this function type
  27654. */
  27655. typedef void* (MessageCallbackFunction) (void* userData);
  27656. /** Delivers Message objects to MessageListeners, and handles the event-dispatch loop.
  27657. @see Message, MessageListener, MessageManagerLock, JUCEApplication
  27658. */
  27659. class JUCE_API MessageManager : private DeletedAtShutdown,
  27660. private Timer
  27661. {
  27662. public:
  27663. /** Returns the global instance of the MessageManager. */
  27664. static MessageManager* getInstance() throw();
  27665. /** Synchronously dispatches up to a certain number of messages from the queue.
  27666. This will return when the queue becomes empty, or when the given number of
  27667. messages has been sent.
  27668. */
  27669. void dispatchPendingMessages (int maxNumberOfMessagesToDispatch = 1000);
  27670. /** Synchronously sends the next pending message.
  27671. This must only be called by the message-thread.
  27672. @param returnImmediatelyIfNoMessages if false, it will block indefinitely until a message
  27673. needs dispatching. If true, then if no messages are
  27674. pending, it will return immediately.
  27675. @param wasAMessageDispatched if this is non-zero, it will be set to true or false
  27676. depending on whether a message was actually sent or
  27677. not.
  27678. @returns false if the thing that's calling it should stop calling - i.e. if the
  27679. app is trying to quit.
  27680. */
  27681. bool dispatchNextMessage (const bool returnImmediatelyIfNoMessages = false,
  27682. bool* const wasAMessageDispatched = 0);
  27683. /** Calls a function using the message-thread.
  27684. This can be used by any thread to cause this function to be called-back
  27685. by the message thread. If it's the message-thread that's calling this method,
  27686. then the function will just be called; if another thread is calling, a message
  27687. will be posted to the queue, and this method will block until that message
  27688. is delivered, the function is called, and the result is returned.
  27689. Be careful not to cause any deadlocks with this! It's easy to do - e.g. if the caller
  27690. thread has a critical section locked, which an unrelated message callback then tries to lock
  27691. before the message thread gets round to processing this callback.
  27692. @param callback the function to call - its signature must be @code
  27693. void* myCallbackFunction (void*) @endcode
  27694. @param userData a user-defined pointer that will be passed to the function that gets called
  27695. @returns the value that the callback function returns.
  27696. @see MessageManagerLock
  27697. */
  27698. void* callFunctionOnMessageThread (MessageCallbackFunction* callback,
  27699. void* userData);
  27700. /** Returns true if the caller-thread is the message thread. */
  27701. bool isThisTheMessageThread() const throw();
  27702. /** Called to tell the manager which thread is the one that's running the dispatch loop.
  27703. (Best to ignore this method unless you really know what you're doing..)
  27704. @see getCurrentMessageThread
  27705. */
  27706. void setCurrentMessageThread (const int threadId) throw();
  27707. /** Returns the ID of the current message thread, as set by setCurrentMessageThread().
  27708. (Best to ignore this method unless you really know what you're doing..)
  27709. @see setCurrentMessageThread
  27710. */
  27711. int getCurrentMessageThread() const throw() { return messageThreadId; }
  27712. /** Returns true if the caller thread has currenltly got the message manager locked.
  27713. see the MessageManagerLock class for more info about this.
  27714. This will be true if the caller is the message thread, because that automatically
  27715. gains a lock while a message is being dispatched.
  27716. */
  27717. bool currentThreadHasLockedMessageManager() const throw();
  27718. /** Sends a message to all other JUCE applications that are running.
  27719. @param messageText the string that will be passed to the actionListenerCallback()
  27720. method of the broadcast listeners in the other app.
  27721. @see registerBroadcastListener, ActionListener
  27722. */
  27723. static void broadcastMessage (const String& messageText) throw();
  27724. /** Registers a listener to get told about broadcast messages.
  27725. The actionListenerCallback() callback's string parameter
  27726. is the message passed into broadcastMessage().
  27727. @see broadcastMessage
  27728. */
  27729. void registerBroadcastListener (ActionListener* listener) throw();
  27730. /** Deregisters a broadcast listener. */
  27731. void deregisterBroadcastListener (ActionListener* listener) throw();
  27732. /** Sets a time-limit for the app to be 'busy' before an hourglass cursor will be shown.
  27733. @param millisecs how long before the cursor is shown (the default time is 500ms). If the
  27734. value is 0 or less, the wait cursor will never be shown (although on the
  27735. Mac the system might still decide to show it after a while).
  27736. @see MouseCursor::showWaitCursor
  27737. */
  27738. void setTimeBeforeShowingWaitCursor (const int millisecs) throw();
  27739. /** Returns the time-out before the 'busy' cursor is shown when the app is busy.
  27740. @see setTimeBeforeShowingWaitCursor, MouseCursor::showWaitCursor
  27741. */
  27742. int getTimeBeforeShowingWaitCursor() const throw();
  27743. /** Tells the message manager that the system isn't locked-up, even if the message
  27744. loop isn't active.
  27745. Used internally, this is handy when an OS enters its own modal loop.
  27746. */
  27747. static void delayWaitCursor() throw();
  27748. /** Returns true if JUCEApplication::quit() has been called. */
  27749. bool hasQuitMessageBeenPosted() const throw();
  27750. /** @internal */
  27751. void deliverMessage (void*);
  27752. /** @internal */
  27753. void deliverBroadcastMessage (const String&);
  27754. /** @internal */
  27755. void timerCallback();
  27756. juce_UseDebuggingNewOperator
  27757. private:
  27758. MessageManager() throw();
  27759. ~MessageManager() throw();
  27760. friend class MessageListener;
  27761. friend class ChangeBroadcaster;
  27762. friend class ActionBroadcaster;
  27763. static MessageManager* instance;
  27764. SortedSet<const MessageListener*> messageListeners;
  27765. ActionListenerList* broadcastListeners;
  27766. friend class JUCEApplication;
  27767. bool quitMessagePosted, quitMessageReceived, useMaximumForceWhenQuitting;
  27768. int messageThreadId;
  27769. int volatile messageCounter, lastMessageCounter, isInMessageDispatcher;
  27770. bool volatile needToGetRidOfWaitCursor;
  27771. int volatile timeBeforeWaitCursor;
  27772. unsigned int lastActivityCheckOkTime;
  27773. bool runDispatchLoop();
  27774. void postMessageToQueue (Message* const message);
  27775. void postQuitMessage (const bool useMaximumForce);
  27776. static void doPlatformSpecificInitialisation();
  27777. static void doPlatformSpecificShutdown();
  27778. friend class InternalTimerThread;
  27779. static void inactivityCheckCallback() throw();
  27780. void inactivityCheckCallbackInt() throw();
  27781. friend class MessageManagerLock;
  27782. CriticalSection messageDispatchLock;
  27783. int currentLockingThreadId;
  27784. MessageManager (const MessageManager&);
  27785. const MessageManager& operator= (const MessageManager&);
  27786. };
  27787. /** Used to make sure that the calling thread has exclusive access to the message loop.
  27788. Because it's not thread-safe to call any of the Component or other UI classes
  27789. from threads other than the message thread, one of these objects can be used to
  27790. lock the message loop and allow this to be done. The message thread will be
  27791. suspended for the lifetime of the MessageManagerLock object, so create one on
  27792. the stack like this: @code
  27793. void MyThread::run()
  27794. {
  27795. someData = 1234;
  27796. const MessageManagerLock mmLock;
  27797. // the event loop will now be locked so it's safe to make a few calls..
  27798. myComponent->setBounds (newBounds);
  27799. myComponent->repaint();
  27800. // ..the event loop will now be unlocked as the MessageManagerLock goes out of scope
  27801. }
  27802. @endcode
  27803. Obviously be careful not to create one of these and leave it lying around, or
  27804. your app will grind to a halt!
  27805. Another caveat is that using this in conjunction with other CriticalSections
  27806. can create lots of interesting ways of producing a deadlock! In particular, if
  27807. your message thread calls stopThread() for a thread that uses these locks,
  27808. you'll get an (occasional) deadlock..
  27809. @see MessageManager, MessageManager::currentThreadHasLockedMessageManager
  27810. */
  27811. class JUCE_API MessageManagerLock
  27812. {
  27813. public:
  27814. /** Tries to acquire a lock on the message manager.
  27815. If this constructor
  27816. When this constructor returns, the message manager will have finished processing the
  27817. last message and will not send another message until this MessageManagerLock is
  27818. deleted.
  27819. If the current thread already has the lock, nothing will be done, so it's perfectly
  27820. safe to create these locks recursively.
  27821. */
  27822. MessageManagerLock() throw();
  27823. /** Releases the current thread's lock on the message manager.
  27824. Make sure this object is created and deleted by the same thread,
  27825. otherwise there are no guarantees what will happen!
  27826. */
  27827. ~MessageManagerLock() throw();
  27828. /** Tries to acquire a lock on the message manager.
  27829. This does the same thing as the normal constructor, but while it's waiting to get
  27830. the lock, it checks the specified thread to see if it has been given the
  27831. Thread::signalThreadShouldExit() signal. If this happens, then it will return
  27832. without gaining the lock.
  27833. To find out whether the lock was successful, call lockWasGained(). If this is
  27834. false, your thread is being told to die, so you'd better get out of there.
  27835. If the current thread already has the lock, nothing will be done, so it's perfectly
  27836. safe to create these locks recursively.
  27837. E.g.
  27838. @code
  27839. void run()
  27840. {
  27841. ...
  27842. while (! threadShouldExit())
  27843. {
  27844. MessageManagerLock mml (Thread::getCurrentThread());
  27845. if (! mml.lockWasGained)
  27846. return; // another thread is trying to kill us!
  27847. ..do some locked stuff here..
  27848. }
  27849. ..and now the MM is now unlocked..
  27850. }
  27851. @endcode
  27852. */
  27853. MessageManagerLock (Thread* const threadToCheckForExitSignal) throw();
  27854. /** Returns true if the lock was successfully acquired.
  27855. (See the constructor that takes a Thread for more info).
  27856. */
  27857. bool lockWasGained() const throw() { return locked; }
  27858. private:
  27859. int lastLockingThreadId;
  27860. bool locked;
  27861. };
  27862. #endif // __JUCE_MESSAGEMANAGER_JUCEHEADER__
  27863. /********* End of inlined file: juce_MessageManager.h *********/
  27864. #endif
  27865. #ifndef __JUCE_MULTITIMER_JUCEHEADER__
  27866. /********* Start of inlined file: juce_MultiTimer.h *********/
  27867. #ifndef __JUCE_MULTITIMER_JUCEHEADER__
  27868. #define __JUCE_MULTITIMER_JUCEHEADER__
  27869. /**
  27870. A type of timer class that can run multiple timers with different frequencies,
  27871. all of which share a single callback.
  27872. This class is very similar to the Timer class, but allows you run multiple
  27873. separate timers, where each one has a unique ID number. The methods in this
  27874. class are exactly equivalent to those in Timer, but with the addition of
  27875. this ID number.
  27876. To use it, you need to create a subclass of MultiTimer, implementing the
  27877. timerCallback() method. Then you can start timers with startTimer(), and
  27878. each time the callback is triggered, it passes in the ID of the timer that
  27879. caused it.
  27880. @see Timer
  27881. */
  27882. class JUCE_API MultiTimer
  27883. {
  27884. protected:
  27885. /** Creates a MultiTimer.
  27886. When created, no timers are running, so use startTimer() to start things off.
  27887. */
  27888. MultiTimer() throw();
  27889. /** Creates a copy of another timer.
  27890. Note that this timer will not contain any running timers, even if the one you're
  27891. copying from was running.
  27892. */
  27893. MultiTimer (const MultiTimer& other) throw();
  27894. public:
  27895. /** Destructor. */
  27896. virtual ~MultiTimer();
  27897. /** The user-defined callback routine that actually gets called by each of the
  27898. timers that are running.
  27899. It's perfectly ok to call startTimer() or stopTimer() from within this
  27900. callback to change the subsequent intervals.
  27901. */
  27902. virtual void timerCallback (const int timerId) = 0;
  27903. /** Starts a timer and sets the length of interval required.
  27904. If the timer is already started, this will reset it, so the
  27905. time between calling this method and the next timer callback
  27906. will not be less than the interval length passed in.
  27907. @param timerId a unique Id number that identifies the timer to
  27908. start. This is the id that will be passed back
  27909. to the timerCallback() method when this timer is
  27910. triggered
  27911. @param intervalInMilliseconds the interval to use (any values less than 1 will be
  27912. rounded up to 1)
  27913. */
  27914. void startTimer (const int timerId, const int intervalInMilliseconds) throw();
  27915. /** Stops a timer.
  27916. If a timer has been started with the given ID number, it will be cancelled.
  27917. No more callbacks will be made for the specified timer after this method returns.
  27918. If this is called from a different thread, any callbacks that may
  27919. be currently executing may be allowed to finish before the method
  27920. returns.
  27921. */
  27922. void stopTimer (const int timerId) throw();
  27923. /** Checks whether a timer has been started for a specified ID.
  27924. @returns true if a timer with the given ID is running.
  27925. */
  27926. bool isTimerRunning (const int timerId) const throw();
  27927. /** Returns the interval for a specified timer ID.
  27928. @returns the timer's interval in milliseconds if it's running, or 0 if it's no timer
  27929. is running for the ID number specified.
  27930. */
  27931. int getTimerInterval (const int timerId) const throw();
  27932. private:
  27933. CriticalSection timerListLock;
  27934. VoidArray timers;
  27935. const MultiTimer& operator= (const MultiTimer&);
  27936. };
  27937. #endif // __JUCE_MULTITIMER_JUCEHEADER__
  27938. /********* End of inlined file: juce_MultiTimer.h *********/
  27939. #endif
  27940. #ifndef __JUCE_TIMER_JUCEHEADER__
  27941. #endif
  27942. #ifndef __JUCE_BRUSH_JUCEHEADER__
  27943. #endif
  27944. #ifndef __JUCE_GRADIENTBRUSH_JUCEHEADER__
  27945. /********* Start of inlined file: juce_GradientBrush.h *********/
  27946. #ifndef __JUCE_GRADIENTBRUSH_JUCEHEADER__
  27947. #define __JUCE_GRADIENTBRUSH_JUCEHEADER__
  27948. /********* Start of inlined file: juce_ColourGradient.h *********/
  27949. #ifndef __JUCE_COLOURGRADIENT_JUCEHEADER__
  27950. #define __JUCE_COLOURGRADIENT_JUCEHEADER__
  27951. /**
  27952. Structure used to define a colour gradient for painting areas.
  27953. @see GradientBrush
  27954. */
  27955. class JUCE_API ColourGradient
  27956. {
  27957. public:
  27958. /** Creates a gradient object.
  27959. (x1, y1) is the location to draw with colour1. Likewise (x2, y2) is where
  27960. colour2 should be. In between them there's a gradient.
  27961. If isRadial is true, the colours form a circular gradient with (x1, y1) at
  27962. its centre.
  27963. The alpha transparencies of the colours are used, so note that
  27964. if you blend from transparent to a solid colour, the RGB of the transparent
  27965. colour will become visible in parts of the gradient. e.g. blending
  27966. from Colour::transparentBlack to Colours::white will produce a
  27967. muddy grey colour midway, but Colour::transparentWhite to Colours::white
  27968. will be white all the way across.
  27969. @see ColourGradient
  27970. */
  27971. ColourGradient (const Colour& colour1,
  27972. const float x1,
  27973. const float y1,
  27974. const Colour& colour2,
  27975. const float x2,
  27976. const float y2,
  27977. const bool isRadial) throw();
  27978. /** Creates an uninitialised gradient.
  27979. If you use this constructor instead of the other one, be sure to set all the
  27980. object's public member variables before using it!
  27981. */
  27982. ColourGradient() throw();
  27983. /** Destructor */
  27984. ~ColourGradient() throw();
  27985. /** Removes any colours that have been added.
  27986. This will also remove any start and end colours, so the gradient won't work. You'll
  27987. need to add more colours with addColour().
  27988. */
  27989. void clearColours() throw();
  27990. /** Adds a colour at a point along the length of the gradient.
  27991. This allows the gradient to go through a spectrum of colours, instead of just a
  27992. start and end colour.
  27993. @param proportionAlongGradient a value between 0 and 1.0, which is the proportion
  27994. of the distance along the line between the two points
  27995. at which the colour should occur.
  27996. @param colour the colour that should be used at this point
  27997. */
  27998. void addColour (const double proportionAlongGradient,
  27999. const Colour& colour) throw();
  28000. /** Multiplies the alpha value of all the colours by the given scale factor */
  28001. void multiplyOpacity (const float multiplier) throw();
  28002. /** Returns the number of colour-stops that have been added. */
  28003. int getNumColours() const throw();
  28004. /** Returns the position along the length of the gradient of the colour with this index.
  28005. The index is from 0 to getNumColours() - 1. The return value will be between 0.0 and 1.0
  28006. */
  28007. double getColourPosition (const int index) const throw();
  28008. /** Returns the colour that was added with a given index.
  28009. The index is from 0 to getNumColours() - 1. The return value will be between 0.0 and 1.0
  28010. */
  28011. const Colour getColour (const int index) const throw();
  28012. /** Creates a set of interpolated premultiplied ARGB values.
  28013. The caller must delete the array that is returned using juce_free().
  28014. */
  28015. PixelARGB* createLookupTable (int& numEntries) const throw();
  28016. /** Returns true if all colours are opaque. */
  28017. bool isOpaque() const throw();
  28018. /** Returns true if all colours are completely transparent. */
  28019. bool isInvisible() const throw();
  28020. float x1;
  28021. float y1;
  28022. float x2;
  28023. float y2;
  28024. /** If true, the gradient should be filled circularly, centred around
  28025. (x1, y1), with (x2, y2) defining a point on the circumference.
  28026. If false, the gradient is linear between the two points.
  28027. */
  28028. bool isRadial;
  28029. /** A transform to apply to the resultant gradient shape */
  28030. AffineTransform transform;
  28031. juce_UseDebuggingNewOperator
  28032. private:
  28033. Array <uint32> colours;
  28034. };
  28035. #endif // __JUCE_COLOURGRADIENT_JUCEHEADER__
  28036. /********* End of inlined file: juce_ColourGradient.h *********/
  28037. /**
  28038. A Brush that fills areas with a colour gradient.
  28039. The gradient can either be linear or circular.
  28040. @see Brush, Graphics::setBrush, SolidColourBrush, ImageBrush
  28041. */
  28042. class JUCE_API GradientBrush : public Brush
  28043. {
  28044. public:
  28045. /** Creates a gradient brush, ready for use in Graphics::setBrush().
  28046. (x1, y1) is the location relative to the origin of the Graphics context,
  28047. at which the colour should be colour1. Likewise for (x2, y2) and colour2.
  28048. If isRadial is true, the colours form a circular gradient with (x1, y1) at
  28049. its centre.
  28050. The alpha transparencies of the colours are used, so the brush
  28051. need not be completely opaque. Note that this means that if you
  28052. blend from transparent to a solid colour, the RGB of the transparent
  28053. colour will become visible in parts of the gradient. e.g. blending
  28054. from Colour::transparentBlack to Colours::white will produce a
  28055. grey colour, but Colour::transparentWhite to Colours::white will be
  28056. white all the way across.
  28057. @see ColourGradient
  28058. */
  28059. GradientBrush (const Colour& colour1,
  28060. const float x1,
  28061. const float y1,
  28062. const Colour& colour2,
  28063. const float x2,
  28064. const float y2,
  28065. const bool isRadial) throw();
  28066. /** Creates a gradient brush from a ColourGradient object.
  28067. */
  28068. GradientBrush (const ColourGradient& gradient) throw();
  28069. /** Destructor. */
  28070. ~GradientBrush() throw();
  28071. Brush* createCopy() const throw();
  28072. void applyTransform (const AffineTransform& transform) throw();
  28073. void multiplyOpacity (const float multiple) throw();
  28074. bool isInvisible() const throw();
  28075. void paintPath (LowLevelGraphicsContext& context,
  28076. const Path& path, const AffineTransform& transform) throw();
  28077. void paintRectangle (LowLevelGraphicsContext& context,
  28078. int x, int y, int w, int h) throw();
  28079. void paintAlphaChannel (LowLevelGraphicsContext& context,
  28080. const Image& alphaChannelImage, int imageX, int imageY,
  28081. int x, int y, int w, int h) throw();
  28082. juce_UseDebuggingNewOperator
  28083. protected:
  28084. ColourGradient gradient;
  28085. private:
  28086. GradientBrush (const GradientBrush&);
  28087. const GradientBrush& operator= (const GradientBrush&);
  28088. };
  28089. #endif // __JUCE_GRADIENTBRUSH_JUCEHEADER__
  28090. /********* End of inlined file: juce_GradientBrush.h *********/
  28091. #endif
  28092. #ifndef __JUCE_IMAGEBRUSH_JUCEHEADER__
  28093. /********* Start of inlined file: juce_ImageBrush.h *********/
  28094. #ifndef __JUCE_IMAGEBRUSH_JUCEHEADER__
  28095. #define __JUCE_IMAGEBRUSH_JUCEHEADER__
  28096. /********* Start of inlined file: juce_Image.h *********/
  28097. #ifndef __JUCE_IMAGE_JUCEHEADER__
  28098. #define __JUCE_IMAGE_JUCEHEADER__
  28099. /**
  28100. Holds a fixed-size bitmap.
  28101. The image is stored in either 24-bit RGB or 32-bit premultiplied-ARGB format.
  28102. To draw into an image, create a Graphics object for it.
  28103. e.g. @code
  28104. // create a transparent 500x500 image..
  28105. Image myImage (Image::RGB, 500, 500, true);
  28106. Graphics g (myImage);
  28107. g.setColour (Colours::red);
  28108. g.fillEllipse (20, 20, 300, 200); // draws a red ellipse in our image.
  28109. @endcode
  28110. Other useful ways to create an image are with the ImageCache class, or the
  28111. ImageFileFormat, which provides a way to load common image files.
  28112. @see Graphics, ImageFileFormat, ImageCache, ImageConvolutionKernel
  28113. */
  28114. class JUCE_API Image
  28115. {
  28116. public:
  28117. enum PixelFormat
  28118. {
  28119. RGB, /**<< each pixel is a 3-byte packed RGB colour value. For byte order, see the PixelRGB class. */
  28120. ARGB, /**<< each pixel is a 4-byte ARGB premultiplied colour value. For byte order, see the PixelARGB class. */
  28121. SingleChannel /**<< each pixel is a 1-byte alpha channel value. */
  28122. };
  28123. /** Creates an in-memory image with a specified size and format.
  28124. @param format the number of colour channels in the image
  28125. @param imageWidth the desired width of the image, in pixels - this value must be
  28126. greater than zero (otherwise a width of 1 will be used)
  28127. @param imageHeight the desired width of the image, in pixels - this value must be
  28128. greater than zero (otherwise a height of 1 will be used)
  28129. @param clearImage if true, the image will initially be cleared to black or transparent
  28130. black. If false, the image may contain random data, and the
  28131. user will have to deal with this
  28132. */
  28133. Image (const PixelFormat format,
  28134. const int imageWidth,
  28135. const int imageHeight,
  28136. const bool clearImage);
  28137. /** Creates a copy of another image.
  28138. @see createCopy
  28139. */
  28140. Image (const Image& other);
  28141. /** Destructor. */
  28142. virtual ~Image();
  28143. /** Returns the image's width (in pixels). */
  28144. int getWidth() const throw() { return imageWidth; }
  28145. /** Returns the image's height (in pixels). */
  28146. int getHeight() const throw() { return imageHeight; }
  28147. /** Returns the image's pixel format. */
  28148. PixelFormat getFormat() const throw() { return format; }
  28149. /** True if the image's format is ARGB. */
  28150. bool isARGB() const throw() { return format == ARGB; }
  28151. /** True if the image's format is RGB. */
  28152. bool isRGB() const throw() { return format == RGB; }
  28153. /** True if the image contains an alpha-channel. */
  28154. bool hasAlphaChannel() const throw() { return format != RGB; }
  28155. /** Clears a section of the image with a given colour.
  28156. This won't do any alpha-blending - it just sets all pixels in the image to
  28157. the given colour (which may be non-opaque if the image has an alpha channel).
  28158. */
  28159. virtual void clear (int x, int y, int w, int h,
  28160. const Colour& colourToClearTo = Colour (0x00000000));
  28161. /** Returns a new image that's a copy of this one.
  28162. A new size for the copied image can be specified, or values less than
  28163. zero can be passed-in to use the image's existing dimensions.
  28164. It's up to the caller to delete the image when no longer needed.
  28165. */
  28166. virtual Image* createCopy (int newWidth = -1,
  28167. int newHeight = -1,
  28168. const Graphics::ResamplingQuality quality = Graphics::mediumResamplingQuality) const;
  28169. /** Returns the colour of one of the pixels in the image.
  28170. If the co-ordinates given are beyond the image's boundaries, this will
  28171. return Colours::transparentBlack.
  28172. (0, 0) is the image's top-left corner.
  28173. @see getAlphaAt, setPixelAt, blendPixelAt
  28174. */
  28175. virtual const Colour getPixelAt (const int x, const int y) const;
  28176. /** Sets the colour of one of the image's pixels.
  28177. If the co-ordinates are beyond the image's boundaries, then nothing will
  28178. happen.
  28179. Note that unlike blendPixelAt(), this won't do any alpha-blending, it'll
  28180. just replace the existing pixel with the given one. The colour's opacity
  28181. will be ignored if this image doesn't have an alpha-channel.
  28182. (0, 0) is the image's top-left corner.
  28183. @see blendPixelAt
  28184. */
  28185. virtual void setPixelAt (const int x, const int y, const Colour& colour);
  28186. /** Changes the opacity of a pixel.
  28187. This only has an effect if the image has an alpha channel and if the
  28188. given co-ordinates are inside the image's boundary.
  28189. The multiplier must be in the range 0 to 1.0, and the current alpha
  28190. at the given co-ordinates will be multiplied by this value.
  28191. @see getAlphaAt, setPixelAt
  28192. */
  28193. virtual void multiplyAlphaAt (const int x, const int y, const float multiplier);
  28194. /** Changes the overall opacity of the image.
  28195. This will multiply the alpha value of each pixel in the image by the given
  28196. amount (limiting the resulting alpha values between 0 and 255). This allows
  28197. you to make an image more or less transparent.
  28198. If the image doesn't have an alpha channel, this won't have any effect.
  28199. */
  28200. virtual void multiplyAllAlphas (const float amountToMultiplyBy);
  28201. /** Changes all the colours to be shades of grey, based on their current luminosity.
  28202. */
  28203. virtual void desaturate();
  28204. /** Locks some of the pixels in the image so they can be read and written to.
  28205. This returns a pointer to some memory containing the pixels in the given
  28206. rectangle. It also returns values for the line and pixel stride used within
  28207. the data. The format of the pixel data is the same as that of this image.
  28208. When you've finished reading and changing the data, you must call
  28209. releasePixelDataReadWrite() to give the pixels back to the image.
  28210. For images that are stored in memory, this method may just return a direct
  28211. pointer to the image's data, but other types of image may be stored elsewhere,
  28212. e.g. in video memory, and if so, this lockPixelDataReadWrite() and
  28213. releasePixelDataReadWrite() may need to create a temporary copy in main memory.
  28214. If you only need read-access to the pixel data, use lockPixelDataReadOnly()
  28215. instead.
  28216. @see releasePixelDataReadWrite, lockPixelDataReadOnly
  28217. */
  28218. virtual uint8* lockPixelDataReadWrite (int x, int y, int w, int h, int& lineStride, int& pixelStride);
  28219. /** Releases a block of memory that was locked with lockPixelDataReadWrite().
  28220. */
  28221. virtual void releasePixelDataReadWrite (void* sourceData);
  28222. /** Locks some of the pixels in the image so they can be read.
  28223. This returns a pointer to some memory containing the pixels in the given
  28224. rectangle. It also returns values for the line and pixel stride used within
  28225. the data. The format of the pixel data is the same as that of this image.
  28226. When you've finished reading the data, you must call releasePixelDataReadOnly()
  28227. to let the image free the memory if necessary.
  28228. For images that are stored in memory, this method may just return a direct
  28229. pointer to the image's data, but other types of image may be stored elsewhere,
  28230. e.g. in video memory, and if so, this lockPixelDataReadWrite() and
  28231. releasePixelDataReadWrite() may need to create a temporary copy in main memory.
  28232. If you only need to read and write the pixel data, use lockPixelDataReadWrite()
  28233. instead.
  28234. @see releasePixelDataReadOnly, lockPixelDataReadWrite
  28235. */
  28236. virtual const uint8* lockPixelDataReadOnly (int x, int y, int w, int h, int& lineStride, int& pixelStride) const;
  28237. /** Releases a block of memory that was locked with lockPixelDataReadOnly().
  28238. */
  28239. virtual void releasePixelDataReadOnly (const void* sourceData) const;
  28240. /** Copies some pixel values to a rectangle of the image.
  28241. The format of the pixel data must match that of the image itself, and the
  28242. rectangle supplied must be within the image's bounds.
  28243. */
  28244. virtual void setPixelData (int destX, int destY, int destW, int destH,
  28245. const uint8* sourcePixelData, int sourceLineStride);
  28246. /** Copies a section of the image to somewhere else within itself.
  28247. */
  28248. virtual void moveImageSection (int destX, int destY,
  28249. int sourceX, int sourceY,
  28250. int width, int height);
  28251. /** Creates a RectangleList containing rectangles for all non-transparent pixels
  28252. of the image.
  28253. @param result the list that will have the area added to it
  28254. @param alphaThreshold for a semi-transparent image, any pixels whose alpha is
  28255. above this level will be considered opaque
  28256. */
  28257. void createSolidAreaMask (RectangleList& result,
  28258. const float alphaThreshold = 0.5f) const;
  28259. juce_UseDebuggingNewOperator
  28260. /** Creates a context suitable for drawing onto this image.
  28261. Don't call this method directly! It's used internally by the Graphics class.
  28262. */
  28263. virtual LowLevelGraphicsContext* createLowLevelContext();
  28264. protected:
  28265. const PixelFormat format;
  28266. const int imageWidth, imageHeight;
  28267. /** Used internally so that subclasses can call a constructor that doesn't allocate memory */
  28268. Image (const PixelFormat format,
  28269. const int imageWidth,
  28270. const int imageHeight);
  28271. int pixelStride, lineStride;
  28272. uint8* imageData;
  28273. private:
  28274. const Image& operator= (const Image&);
  28275. };
  28276. #endif // __JUCE_IMAGE_JUCEHEADER__
  28277. /********* End of inlined file: juce_Image.h *********/
  28278. /**
  28279. A Brush that fills areas with tiled repetitions of an image.
  28280. @see Brush, Graphics::setBrush, SolidColourBrush, GradientBrush
  28281. */
  28282. class JUCE_API ImageBrush : public Brush
  28283. {
  28284. public:
  28285. /* Creates an image brush, ready for use in Graphics::setBrush().
  28286. (x, y) is an anchor point for the top-left of the image
  28287. A reference to the image passed in will be kept, so don't delete
  28288. it within the lifetime of this object
  28289. */
  28290. ImageBrush (Image* const image,
  28291. const int anchorX,
  28292. const int anchorY,
  28293. const float opacity) throw();
  28294. /** Destructor. */
  28295. ~ImageBrush() throw();
  28296. Brush* createCopy() const throw();
  28297. void applyTransform (const AffineTransform& transform) throw();
  28298. void multiplyOpacity (const float multiple) throw();
  28299. bool isInvisible() const throw();
  28300. void paintPath (LowLevelGraphicsContext& context,
  28301. const Path& path, const AffineTransform& transform) throw();
  28302. void paintRectangle (LowLevelGraphicsContext& context,
  28303. int x, int y, int w, int h) throw();
  28304. void paintAlphaChannel (LowLevelGraphicsContext& context,
  28305. const Image& alphaChannelImage, int imageX, int imageY,
  28306. int x, int y, int w, int h) throw();
  28307. juce_UseDebuggingNewOperator
  28308. protected:
  28309. Image* image;
  28310. int anchorX, anchorY;
  28311. float opacity;
  28312. private:
  28313. ImageBrush (const ImageBrush&);
  28314. const ImageBrush& operator= (const ImageBrush&);
  28315. void getStartXY (int& x, int& y) const throw();
  28316. };
  28317. #endif // __JUCE_IMAGEBRUSH_JUCEHEADER__
  28318. /********* End of inlined file: juce_ImageBrush.h *********/
  28319. #endif
  28320. #ifndef __JUCE_SOLIDCOLOURBRUSH_JUCEHEADER__
  28321. #endif
  28322. #ifndef __JUCE_COLOUR_JUCEHEADER__
  28323. #endif
  28324. #ifndef __JUCE_COLOURGRADIENT_JUCEHEADER__
  28325. #endif
  28326. #ifndef __JUCE_COLOURS_JUCEHEADER__
  28327. #endif
  28328. #ifndef __JUCE_PIXELFORMATS_JUCEHEADER__
  28329. #endif
  28330. #ifndef __JUCE_FONT_JUCEHEADER__
  28331. #endif
  28332. #ifndef __JUCE_GLYPHARRANGEMENT_JUCEHEADER__
  28333. /********* Start of inlined file: juce_GlyphArrangement.h *********/
  28334. #ifndef __JUCE_GLYPHARRANGEMENT_JUCEHEADER__
  28335. #define __JUCE_GLYPHARRANGEMENT_JUCEHEADER__
  28336. /**
  28337. An glyph from a particular font, with a particular size, style,
  28338. typeface and position.
  28339. @see GlyphArrangement, Font
  28340. */
  28341. class JUCE_API PositionedGlyph
  28342. {
  28343. public:
  28344. /** Returns the character the glyph represents. */
  28345. juce_wchar getCharacter() const throw() { return glyphInfo->getCharacter(); }
  28346. /** Checks whether the glyph is actually empty. */
  28347. bool isWhitespace() const throw() { return CharacterFunctions::isWhitespace (glyphInfo->getCharacter()); }
  28348. /** Returns the position of the glyph's left-hand edge. */
  28349. float getLeft() const throw() { return x; }
  28350. /** Returns the position of the glyph's right-hand edge. */
  28351. float getRight() const throw() { return x + w; }
  28352. /** Returns the y position of the glyph's baseline. */
  28353. float getBaselineY() const throw() { return y; }
  28354. /** Returns the y position of the top of the glyph. */
  28355. float getTop() const throw() { return y - fontAscent; }
  28356. /** Returns the y position of the bottom of the glyph. */
  28357. float getBottom() const throw() { return y + fontHeight - fontAscent; }
  28358. /** Shifts the glyph's position by a relative amount. */
  28359. void moveBy (const float deltaX,
  28360. const float deltaY) throw();
  28361. /** Draws the glyph into a graphics context. */
  28362. void draw (const Graphics& g) const throw();
  28363. /** Draws the glyph into a graphics context, with an extra transform applied to it. */
  28364. void draw (const Graphics& g, const AffineTransform& transform) const throw();
  28365. /** Returns the path for this glyph.
  28366. @param path the glyph's outline will be appended to this path
  28367. */
  28368. void createPath (Path& path) const throw();
  28369. /** Checks to see if a point lies within this glyph. */
  28370. bool hitTest (float x, float y) const throw();
  28371. juce_UseDebuggingNewOperator
  28372. private:
  28373. friend class GlyphArrangement;
  28374. float x, y, w;
  28375. float fontHeight, fontAscent, fontHorizontalScale;
  28376. bool isUnderlined;
  28377. const TypefaceGlyphInfo* glyphInfo;
  28378. PositionedGlyph() throw();
  28379. };
  28380. /**
  28381. A set of glyphs, each with a position.
  28382. You can create a GlyphArrangement, text to it and then draw it onto a
  28383. graphics context. It's used internally by the text methods in the
  28384. Graphics class, but can be used directly if more control is needed.
  28385. @see Font, PositionedGlyph
  28386. */
  28387. class JUCE_API GlyphArrangement
  28388. {
  28389. public:
  28390. /** Creates an empty arrangement. */
  28391. GlyphArrangement() throw();
  28392. /** Takes a copy of another arrangement. */
  28393. GlyphArrangement (const GlyphArrangement& other) throw();
  28394. /** Copies another arrangement onto this one.
  28395. To add another arrangement without clearing this one, use addGlyphArrangement().
  28396. */
  28397. const GlyphArrangement& operator= (const GlyphArrangement& other) throw();
  28398. /** Destructor. */
  28399. ~GlyphArrangement() throw();
  28400. /** Returns the total number of glyphs in the arrangement. */
  28401. int getNumGlyphs() const throw() { return numGlyphs; }
  28402. /** Returns one of the glyphs from the arrangement.
  28403. @param index the glyph's index, from 0 to (getNumGlyphs() - 1). Be
  28404. careful not to pass an out-of-range index here, as it
  28405. doesn't do any bounds-checking.
  28406. */
  28407. PositionedGlyph& getGlyph (const int index) const throw();
  28408. /** Clears all text from the arrangement and resets it.
  28409. */
  28410. void clear() throw();
  28411. /** Appends a line of text to the arrangement.
  28412. This will add the text as a single line, where x is the left-hand edge of the
  28413. first character, and y is the position for the text's baseline.
  28414. If the text contains new-lines or carriage-returns, this will ignore them - use
  28415. addJustifiedText() to add multi-line arrangements.
  28416. */
  28417. void addLineOfText (const Font& font,
  28418. const String& text,
  28419. const float x,
  28420. const float y) throw();
  28421. /** Adds a line of text, truncating it if it's wider than a specified size.
  28422. This is the same as addLineOfText(), but if the line's width exceeds the value
  28423. specified in maxWidthPixels, it will be truncated using either ellipsis (i.e. dots: "..."),
  28424. if useEllipsis is true, or if this is false, it will just drop any subsequent characters.
  28425. */
  28426. void addCurtailedLineOfText (const Font& font,
  28427. const String& text,
  28428. float x,
  28429. const float y,
  28430. const float maxWidthPixels,
  28431. const bool useEllipsis) throw();
  28432. /** Adds some multi-line text, breaking lines at word-boundaries if they are too wide.
  28433. This will add text to the arrangement, breaking it into new lines either where there
  28434. is a new-line or carriage-return character in the text, or where a line's width
  28435. exceeds the value set in maxLineWidth.
  28436. Each line that is added will be laid out using the flags set in horizontalLayout, so
  28437. the lines can be left- or right-justified, or centred horizontally in the space
  28438. between x and (x + maxLineWidth).
  28439. The y co-ordinate is the position of the baseline of the first line of text - subsequent
  28440. lines will be placed below it, separated by a distance of font.getHeight().
  28441. */
  28442. void addJustifiedText (const Font& font,
  28443. const String& text,
  28444. float x, float y,
  28445. const float maxLineWidth,
  28446. const Justification& horizontalLayout) throw();
  28447. /** Tries to fit some text withing a given space.
  28448. This does its best to make the given text readable within the specified rectangle,
  28449. so it useful for labelling things.
  28450. If the text is too big, it'll be squashed horizontally or broken over multiple lines
  28451. if the maximumLinesToUse value allows this. If the text just won't fit into the space,
  28452. it'll cram as much as possible in there, and put some ellipsis at the end to show that
  28453. it's been truncated.
  28454. A Justification parameter lets you specify how the text is laid out within the rectangle,
  28455. both horizontally and vertically.
  28456. @see Graphics::drawFittedText
  28457. */
  28458. void addFittedText (const Font& font,
  28459. const String& text,
  28460. float x, float y,
  28461. float width, float height,
  28462. const Justification& layout,
  28463. int maximumLinesToUse,
  28464. const float minimumHorizontalScale = 0.7f) throw();
  28465. /** Appends another glyph arrangement to this one. */
  28466. void addGlyphArrangement (const GlyphArrangement& other) throw();
  28467. /** Draws this glyph arrangement to a graphics context.
  28468. This uses cached bitmaps so is much faster than the draw (Graphics&, const AffineTransform&)
  28469. method, which renders the glyphs as filled vectors.
  28470. */
  28471. void draw (const Graphics& g) const throw();
  28472. /** Draws this glyph arrangement to a graphics context.
  28473. This renders the paths as filled vectors, so is far slower than the draw (Graphics&)
  28474. method for non-transformed arrangements.
  28475. */
  28476. void draw (const Graphics& g, const AffineTransform& transform) const throw();
  28477. /** Converts the set of glyphs into a path.
  28478. @param path the glyphs' outlines will be appended to this path
  28479. */
  28480. void createPath (Path& path) const throw();
  28481. /** Looks for a glyph that contains the given co-ordinate.
  28482. @returns the index of the glyph, or -1 if none were found.
  28483. */
  28484. int findGlyphIndexAt (float x, float y) const throw();
  28485. /** Finds the smallest rectangle that will enclose a subset of the glyphs.
  28486. @param startIndex the first glyph to test
  28487. @param numGlyphs the number of glyphs to include; if this is < 0, all glyphs after
  28488. startIndex will be included
  28489. @param left on return, the leftmost co-ordinate of the rectangle
  28490. @param top on return, the top co-ordinate of the rectangle
  28491. @param right on return, the rightmost co-ordinate of the rectangle
  28492. @param bottom on return, the bottom co-ordinate of the rectangle
  28493. @param includeWhitespace if true, the extent of any whitespace characters will also
  28494. be taken into account
  28495. */
  28496. void getBoundingBox (int startIndex,
  28497. int numGlyphs,
  28498. float& left,
  28499. float& top,
  28500. float& right,
  28501. float& bottom,
  28502. const bool includeWhitespace) const throw();
  28503. /** Shifts a set of glyphs by a given amount.
  28504. @param startIndex the first glyph to transform
  28505. @param numGlyphs the number of glyphs to move; if this is < 0, all glyphs after
  28506. startIndex will be used
  28507. @param deltaX the amount to add to their x-positions
  28508. @param deltaY the amount to add to their y-positions
  28509. */
  28510. void moveRangeOfGlyphs (int startIndex, int numGlyphs,
  28511. const float deltaX,
  28512. const float deltaY) throw();
  28513. /** Removes a set of glyphs from the arrangement.
  28514. @param startIndex the first glyph to remove
  28515. @param numGlyphs the number of glyphs to remove; if this is < 0, all glyphs after
  28516. startIndex will be deleted
  28517. */
  28518. void removeRangeOfGlyphs (int startIndex, int numGlyphs) throw();
  28519. /** Expands or compresses a set of glyphs horizontally.
  28520. @param startIndex the first glyph to transform
  28521. @param numGlyphs the number of glyphs to stretch; if this is < 0, all glyphs after
  28522. startIndex will be used
  28523. @param horizontalScaleFactor how much to scale their horizontal width by
  28524. */
  28525. void stretchRangeOfGlyphs (int startIndex, int numGlyphs,
  28526. const float horizontalScaleFactor) throw();
  28527. /** Justifies a set of glyphs within a given space.
  28528. This moves the glyphs as a block so that the whole thing is located within the
  28529. given rectangle with the specified layout.
  28530. If the Justification::horizontallyJustified flag is specified, each line will
  28531. be stretched out to fill the specified width.
  28532. */
  28533. void justifyGlyphs (const int startIndex, const int numGlyphs,
  28534. const float x,
  28535. const float y,
  28536. const float width,
  28537. const float height,
  28538. const Justification& justification) throw();
  28539. juce_UseDebuggingNewOperator
  28540. private:
  28541. int numGlyphs, numAllocated;
  28542. PositionedGlyph* glyphs;
  28543. void ensureNumGlyphsAllocated (int minGlyphs) throw();
  28544. void removeLast() throw();
  28545. void appendEllipsis (const Font& font, const float maxXPixels) throw();
  28546. void incGlyphRefCount (const int index) const throw();
  28547. void decGlyphRefCount (const int index) const throw();
  28548. void spreadOutLine (const int start, const int numGlyphs, const float targetWidth) throw();
  28549. };
  28550. #endif // __JUCE_GLYPHARRANGEMENT_JUCEHEADER__
  28551. /********* End of inlined file: juce_GlyphArrangement.h *********/
  28552. #endif
  28553. #ifndef __JUCE_TEXTLAYOUT_JUCEHEADER__
  28554. /********* Start of inlined file: juce_TextLayout.h *********/
  28555. #ifndef __JUCE_TEXTLAYOUT_JUCEHEADER__
  28556. #define __JUCE_TEXTLAYOUT_JUCEHEADER__
  28557. class Graphics;
  28558. /**
  28559. A laid-out arrangement of text.
  28560. You can add text in different fonts to a TextLayout object, then call its
  28561. layout() method to word-wrap it into lines. The layout can then be drawn
  28562. using a graphics context.
  28563. It's handy if you've got a message to display, because you can format it,
  28564. measure the extent of the layout, and then create a suitably-sized window
  28565. to show it in.
  28566. @see Font, Graphics::drawFittedText, GlyphArrangement
  28567. */
  28568. class JUCE_API TextLayout
  28569. {
  28570. public:
  28571. /** Creates an empty text layout.
  28572. Text can then be appended using the appendText() method.
  28573. */
  28574. TextLayout() throw();
  28575. /** Creates a copy of another layout object. */
  28576. TextLayout (const TextLayout& other) throw();
  28577. /** Creates a text layout from an initial string and font. */
  28578. TextLayout (const String& text, const Font& font) throw();
  28579. /** Destructor. */
  28580. ~TextLayout() throw();
  28581. /** Copies another layout onto this one. */
  28582. const TextLayout& operator= (const TextLayout& layoutToCopy) throw();
  28583. /** Clears the layout, removing all its text. */
  28584. void clear() throw();
  28585. /** Adds a string to the end of the arrangement.
  28586. The string will be broken onto new lines wherever it contains
  28587. carriage-returns or linefeeds. After adding it, you can call layout()
  28588. to wrap long lines into a paragraph and justify it.
  28589. */
  28590. void appendText (const String& textToAppend,
  28591. const Font& fontToUse) throw();
  28592. /** Replaces all the text with a new string.
  28593. This is equivalent to calling clear() followed by appendText().
  28594. */
  28595. void setText (const String& newText,
  28596. const Font& fontToUse) throw();
  28597. /** Breaks the text up to form a paragraph with the given width.
  28598. @param maximumWidth any text wider than this will be split
  28599. across multiple lines
  28600. @param justification how the lines are to be laid-out horizontally
  28601. @param attemptToBalanceLineLengths if true, it will try to split the lines at a
  28602. width that keeps all the lines of text at a
  28603. similar length - this is good when you're displaying
  28604. a short message and don't want it to get split
  28605. onto two lines with only a couple of words on
  28606. the second line, which looks untidy.
  28607. */
  28608. void layout (int maximumWidth,
  28609. const Justification& justification,
  28610. const bool attemptToBalanceLineLengths) throw();
  28611. /** Returns the overall width of the entire text layout. */
  28612. int getWidth() const throw();
  28613. /** Returns the overall height of the entire text layout. */
  28614. int getHeight() const throw();
  28615. /** Returns the total number of lines of text. */
  28616. int getNumLines() const throw() { return totalLines; }
  28617. /** Returns the width of a particular line of text.
  28618. @param lineNumber the line, from 0 to (getNumLines() - 1)
  28619. */
  28620. int getLineWidth (const int lineNumber) const throw();
  28621. /** Renders the text at a specified position using a graphics context.
  28622. */
  28623. void draw (Graphics& g,
  28624. const int topLeftX,
  28625. const int topLeftY) const throw();
  28626. /** Renders the text within a specified rectangle using a graphics context.
  28627. The justification flags dictate how the block of text should be positioned
  28628. within the rectangle.
  28629. */
  28630. void drawWithin (Graphics& g,
  28631. int x, int y, int w, int h,
  28632. const Justification& layoutFlags) const throw();
  28633. juce_UseDebuggingNewOperator
  28634. private:
  28635. VoidArray tokens;
  28636. int totalLines;
  28637. };
  28638. #endif // __JUCE_TEXTLAYOUT_JUCEHEADER__
  28639. /********* End of inlined file: juce_TextLayout.h *********/
  28640. #endif
  28641. #ifndef __JUCE_TYPEFACE_JUCEHEADER__
  28642. #endif
  28643. #ifndef __JUCE_EDGETABLE_JUCEHEADER__
  28644. /********* Start of inlined file: juce_EdgeTable.h *********/
  28645. #ifndef __JUCE_EDGETABLE_JUCEHEADER__
  28646. #define __JUCE_EDGETABLE_JUCEHEADER__
  28647. class Path;
  28648. static const int juce_edgeTableDefaultEdgesPerLine = 10;
  28649. /**
  28650. A table of horizontal scan-line segments - used for rasterising Paths.
  28651. @see Path, Graphics
  28652. */
  28653. class JUCE_API EdgeTable
  28654. {
  28655. public:
  28656. /** Indicates the quality at which the edge table should be generated.
  28657. Higher values will have better quality anti-aliasing, but will take
  28658. longer to generate the edge table and to render it.
  28659. */
  28660. enum OversamplingLevel
  28661. {
  28662. Oversampling_none = 0, /**< No vertical anti-aliasing at all. */
  28663. Oversampling_4times = 2, /**< Anti-aliased with 4 levels of grey - good enough for normal use. */
  28664. Oversampling_16times = 4, /**< Anti-aliased with 16 levels of grey - very good quality. */
  28665. Oversampling_32times = 5, /**< Anti-aliased with 32 levels of grey - very good quality but slower. */
  28666. Oversampling_256times = 8 /**< Anti-aliased with 256 levels of grey - best quality, but too slow for
  28667. normal user-interface use. */
  28668. };
  28669. /** Creates an empty edge table ready to have paths added.
  28670. A table is created with a fixed vertical size, and only sections of paths
  28671. which lie within their range will be added to the table.
  28672. @param topY the lowest y co-ordinate that the table can contain
  28673. @param height the number of horizontal lines it can contain
  28674. @param verticalOversampling the amount of oversampling used for anti-aliasing
  28675. @param expectedEdgesPerLine used to optimise the table's internal data usage - it's not
  28676. worth changing this except for very special purposes
  28677. */
  28678. EdgeTable (const int topY,
  28679. const int height,
  28680. const OversamplingLevel verticalOversampling = Oversampling_4times,
  28681. const int expectedEdgesPerLine = juce_edgeTableDefaultEdgesPerLine) throw();
  28682. /** Creates a copy of another edge table. */
  28683. EdgeTable (const EdgeTable& other) throw();
  28684. /** Copies from another edge table. */
  28685. const EdgeTable& operator= (const EdgeTable& other) throw();
  28686. /** Destructor. */
  28687. ~EdgeTable() throw();
  28688. /** Adds edges to the table for a path.
  28689. This will add horizontal lines to the edge table for any parts of the path
  28690. which lie within the vertical bounds for which this table was created.
  28691. @param path the path to add
  28692. @param transform an optional transform to apply to the path while it's
  28693. being added
  28694. */
  28695. void addPath (const Path& path,
  28696. const AffineTransform& transform) throw();
  28697. /** Reduces the amount of space the table has allocated.
  28698. This will shrink the table down to use as little memory as possible - useful for
  28699. read-only tables that get stored and re-used for rendering.
  28700. */
  28701. void optimiseTable() throw();
  28702. /** Iterates the lines in the table, for rendering.
  28703. This function will iterate each line in the table, and call a user-defined class
  28704. to render each pixel or continuous line of pixels that the table contains.
  28705. @param iterationCallback this templated class must contain the following methods:
  28706. @code
  28707. inline void setEdgeTableYPos (int y);
  28708. inline void handleEdgeTablePixel (int x, int alphaLevel) const;
  28709. inline void handleEdgeTableLine (int x, int width, int alphaLevel) const;
  28710. @endcode
  28711. (these don't necessarily have to be 'const', but it might help it go faster)
  28712. @param clipLeft the left-hand edge of the rectangle which should be iterated
  28713. @param clipTop the top edge of the rectangle which should be iterated
  28714. @param clipRight the right-hand edge of the rectangle which should be iterated
  28715. @param clipBottom the bottom edge of the rectangle which should be iterated
  28716. @param subPixelXOffset a fraction of 1 pixel by which to shift the table rightwards, in the range 0 to 255
  28717. */
  28718. template <class EdgeTableIterationCallback>
  28719. void iterate (EdgeTableIterationCallback& iterationCallback,
  28720. const int clipLeft,
  28721. int clipTop,
  28722. const int clipRight,
  28723. int clipBottom,
  28724. const int subPixelXOffset) const
  28725. {
  28726. if (clipTop < top)
  28727. clipTop = top;
  28728. if (clipBottom > top + height)
  28729. clipBottom = top + height;
  28730. const int* singleLine = table + lineStrideElements
  28731. * ((clipTop - top) << (int) oversampling);
  28732. int mergedLineAllocation = 128;
  28733. MemoryBlock temp (mergedLineAllocation * (2 * sizeof (int)));
  28734. int* mergedLine = (int*) temp.getData();
  28735. const int timesOverSampling = 1 << (int) oversampling;
  28736. for (int y = clipTop; y < clipBottom; ++y)
  28737. {
  28738. int numMergedPoints = 0;
  28739. // sort all the oversampled lines into a single merged line ready to draw..
  28740. for (int over = timesOverSampling; --over >= 0;)
  28741. {
  28742. const int* l = singleLine;
  28743. singleLine += lineStrideElements;
  28744. int num = *l;
  28745. jassert (num >= 0);
  28746. if (num > 0)
  28747. {
  28748. if (numMergedPoints + num >= mergedLineAllocation)
  28749. {
  28750. mergedLineAllocation = (numMergedPoints + num + 0x100) & ~0xff;
  28751. temp.setSize (mergedLineAllocation * (2 * sizeof (int)), false);
  28752. mergedLine = (int*) temp.getData();
  28753. }
  28754. while (--num >= 0)
  28755. {
  28756. const int x = *++l;
  28757. const int winding = *++l;
  28758. int n = numMergedPoints << 1;
  28759. while (n > 0)
  28760. {
  28761. const int cx = mergedLine [n - 2];
  28762. if (cx <= x)
  28763. break;
  28764. mergedLine [n] = cx;
  28765. --n;
  28766. mergedLine [n + 2] = mergedLine [n];
  28767. --n;
  28768. }
  28769. mergedLine [n] = x;
  28770. mergedLine [n + 1] = winding;
  28771. ++numMergedPoints;
  28772. }
  28773. }
  28774. }
  28775. if (--numMergedPoints > 0)
  28776. {
  28777. const int* line = mergedLine;
  28778. int x = subPixelXOffset + *line;
  28779. int level = *++line;
  28780. int levelAccumulator = 0;
  28781. iterationCallback.setEdgeTableYPos (y);
  28782. while (--numMergedPoints >= 0)
  28783. {
  28784. const int endX = subPixelXOffset + *++line;
  28785. jassert (endX >= x);
  28786. const int absLevel = abs (level);
  28787. int endOfRun = (endX >> 8);
  28788. if (endOfRun == (x >> 8))
  28789. {
  28790. // small segment within the same pixel, so just save it for the next
  28791. // time round..
  28792. levelAccumulator += (endX - x) * absLevel;
  28793. }
  28794. else
  28795. {
  28796. // plot the fist pixel of this segment, including any accumulated
  28797. // levels from smaller segments that haven't been drawn yet
  28798. levelAccumulator += (0xff - (x & 0xff)) * absLevel;
  28799. levelAccumulator >>= 8;
  28800. if (levelAccumulator > 0xff)
  28801. levelAccumulator = 0xff;
  28802. x >>= 8;
  28803. if (x >= clipRight)
  28804. {
  28805. levelAccumulator = 0;
  28806. break;
  28807. }
  28808. if (x >= clipLeft && x < clipRight && levelAccumulator > 0)
  28809. iterationCallback.handleEdgeTablePixel (x, levelAccumulator);
  28810. if (++x >= clipRight)
  28811. {
  28812. levelAccumulator = 0;
  28813. break;
  28814. }
  28815. // if there's a segment of solid pixels, do it all in one go..
  28816. if (absLevel > 0 && endOfRun > x)
  28817. {
  28818. if (x < clipLeft)
  28819. x = clipLeft;
  28820. if (endOfRun > clipRight)
  28821. endOfRun = clipRight;
  28822. const int numPix = endOfRun - x;
  28823. if (numPix > 0)
  28824. iterationCallback.handleEdgeTableLine (x, numPix,
  28825. jmin (absLevel, 0xff));
  28826. }
  28827. // save the bit at the end to be drawn next time round the loop.
  28828. levelAccumulator = (endX & 0xff) * absLevel;
  28829. }
  28830. level += *++line;
  28831. x = endX;
  28832. }
  28833. if (levelAccumulator > 0)
  28834. {
  28835. levelAccumulator >>= 8;
  28836. if (levelAccumulator > 0xff)
  28837. levelAccumulator = 0xff;
  28838. x >>= 8;
  28839. if (x >= clipLeft && x < clipRight)
  28840. iterationCallback.handleEdgeTablePixel (x, levelAccumulator);
  28841. }
  28842. }
  28843. }
  28844. }
  28845. juce_UseDebuggingNewOperator
  28846. private:
  28847. // table line format: number of points; point0 x, point0 levelDelta, point1 x, point1 levelDelta, etc
  28848. int* table;
  28849. int top, height, maxEdgesPerLine, lineStrideElements;
  28850. OversamplingLevel oversampling;
  28851. // this will assume that the y co-ord is within bounds, and will avoid checking
  28852. // this for speed.
  28853. void addEdgePoint (const int x, const int y, const int winding) throw();
  28854. void remapTableForNumEdges (const int newNumEdgesPerLine) throw();
  28855. };
  28856. #endif // __JUCE_EDGETABLE_JUCEHEADER__
  28857. /********* End of inlined file: juce_EdgeTable.h *********/
  28858. #endif
  28859. #ifndef __JUCE_GRAPHICS_JUCEHEADER__
  28860. #endif
  28861. #ifndef __JUCE_JUSTIFICATION_JUCEHEADER__
  28862. #endif
  28863. #ifndef __JUCE_LOWLEVELGRAPHICSCONTEXT_JUCEHEADER__
  28864. /********* Start of inlined file: juce_LowLevelGraphicsContext.h *********/
  28865. #ifndef __JUCE_LOWLEVELGRAPHICSCONTEXT_JUCEHEADER__
  28866. #define __JUCE_LOWLEVELGRAPHICSCONTEXT_JUCEHEADER__
  28867. /**
  28868. Interface class for graphics context objects, used internally by the Graphics class.
  28869. Users are not supposed to create instances of this class directly - do your drawing
  28870. via the Graphics object instead.
  28871. It's a base class for different types of graphics context, that may perform software-based
  28872. or OS-accelerated rendering.
  28873. E.g. the LowLevelGraphicsSoftwareRenderer renders onto an image in memory, but other
  28874. subclasses could render directly to a windows HDC, a Quartz context, or an OpenGL
  28875. context.
  28876. */
  28877. class JUCE_API LowLevelGraphicsContext
  28878. {
  28879. protected:
  28880. LowLevelGraphicsContext();
  28881. public:
  28882. virtual ~LowLevelGraphicsContext();
  28883. /** Returns true if this device is vector-based, e.g. a printer. */
  28884. virtual bool isVectorDevice() const = 0;
  28885. /** Moves the origin to a new position.
  28886. The co-ords are relative to the current origin, and indicate the new position
  28887. of (0, 0).
  28888. */
  28889. virtual void setOrigin (int x, int y) = 0;
  28890. /** Cliping co-ords are relative to the origin. */
  28891. virtual bool reduceClipRegion (int x, int y, int w, int h) = 0;
  28892. /** Cliping co-ords are relative to the origin. */
  28893. virtual bool reduceClipRegion (const RectangleList& clipRegion) = 0;
  28894. /** Cliping co-ords are relative to the origin. */
  28895. virtual void excludeClipRegion (int x, int y, int w, int h) = 0;
  28896. virtual void saveState() = 0;
  28897. virtual void restoreState() = 0;
  28898. virtual bool clipRegionIntersects (int x, int y, int w, int h) = 0;
  28899. virtual const Rectangle getClipBounds() const = 0;
  28900. virtual bool isClipEmpty() const = 0;
  28901. virtual void fillRectWithColour (int x, int y, int w, int h, const Colour& colour, const bool replaceExistingContents) = 0;
  28902. virtual void fillRectWithGradient (int x, int y, int w, int h, const ColourGradient& gradient) = 0;
  28903. virtual void fillPathWithColour (const Path& path, const AffineTransform& transform, const Colour& colour, EdgeTable::OversamplingLevel quality) = 0;
  28904. virtual void fillPathWithGradient (const Path& path, const AffineTransform& transform, const ColourGradient& gradient, EdgeTable::OversamplingLevel quality) = 0;
  28905. virtual void fillPathWithImage (const Path& path, const AffineTransform& transform,
  28906. const Image& image, int imageX, int imageY, float alpha, EdgeTable::OversamplingLevel quality) = 0;
  28907. virtual void fillAlphaChannelWithColour (const Image& alphaImage, int alphaImageX, int alphaImageY, const Colour& colour) = 0;
  28908. virtual void fillAlphaChannelWithGradient (const Image& alphaImage, int alphaImageX, int alphaImageY, const ColourGradient& gradient) = 0;
  28909. virtual void fillAlphaChannelWithImage (const Image& alphaImage, int alphaImageX, int alphaImageY,
  28910. const Image& fillerImage, int fillerImageX, int fillerImageY, float alpha) = 0;
  28911. virtual void blendImage (const Image& sourceImage,
  28912. int destX, int destY, int destW, int destH, int sourceX, int sourceY,
  28913. float alpha) = 0;
  28914. virtual void blendImageRescaling (const Image& sourceImage,
  28915. int destX, int destY, int destW, int destH,
  28916. int sourceX, int sourceY, int sourceW, int sourceH,
  28917. float alpha, const Graphics::ResamplingQuality quality) = 0;
  28918. virtual void blendImageWarping (const Image& sourceImage,
  28919. int srcClipX, int srcClipY, int srcClipW, int srcClipH,
  28920. const AffineTransform& transform,
  28921. float alpha, const Graphics::ResamplingQuality quality) = 0;
  28922. virtual void drawLine (double x1, double y1, double x2, double y2, const Colour& colour) = 0;
  28923. virtual void drawVerticalLine (const int x, double top, double bottom, const Colour& col) = 0;
  28924. virtual void drawHorizontalLine (const int y, double left, double right, const Colour& col) = 0;
  28925. };
  28926. #endif // __JUCE_LOWLEVELGRAPHICSCONTEXT_JUCEHEADER__
  28927. /********* End of inlined file: juce_LowLevelGraphicsContext.h *********/
  28928. #endif
  28929. #ifndef __JUCE_LOWLEVELGRAPHICSPOSTSCRIPTRENDERER_JUCEHEADER__
  28930. /********* Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.h *********/
  28931. #ifndef __JUCE_LOWLEVELGRAPHICSPOSTSCRIPTRENDERER_JUCEHEADER__
  28932. #define __JUCE_LOWLEVELGRAPHICSPOSTSCRIPTRENDERER_JUCEHEADER__
  28933. /**
  28934. An implementation of LowLevelGraphicsContext that turns the drawing operations
  28935. into a PostScript document.
  28936. */
  28937. class JUCE_API LowLevelGraphicsPostScriptRenderer : public LowLevelGraphicsContext
  28938. {
  28939. public:
  28940. LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  28941. const String& documentTitle,
  28942. const int totalWidth,
  28943. const int totalHeight);
  28944. ~LowLevelGraphicsPostScriptRenderer();
  28945. bool isVectorDevice() const;
  28946. void setOrigin (int x, int y);
  28947. bool reduceClipRegion (int x, int y, int w, int h);
  28948. bool reduceClipRegion (const RectangleList& clipRegion);
  28949. void excludeClipRegion (int x, int y, int w, int h);
  28950. void saveState();
  28951. void restoreState();
  28952. bool clipRegionIntersects (int x, int y, int w, int h);
  28953. const Rectangle getClipBounds() const;
  28954. bool isClipEmpty() const;
  28955. void fillRectWithColour (int x, int y, int w, int h, const Colour& colour, const bool replaceExistingContents);
  28956. void fillRectWithGradient (int x, int y, int w, int h, const ColourGradient& gradient);
  28957. void fillPathWithColour (const Path& path, const AffineTransform& transform, const Colour& colour, EdgeTable::OversamplingLevel quality);
  28958. void fillPathWithGradient (const Path& path, const AffineTransform& transform, const ColourGradient& gradient, EdgeTable::OversamplingLevel quality);
  28959. void fillPathWithImage (const Path& path, const AffineTransform& transform,
  28960. const Image& image, int imageX, int imageY, float alpha, EdgeTable::OversamplingLevel quality);
  28961. void fillAlphaChannelWithColour (const Image& alphaImage, int imageX, int imageY, const Colour& colour);
  28962. void fillAlphaChannelWithGradient (const Image& alphaImage, int imageX, int imageY, const ColourGradient& gradient);
  28963. void fillAlphaChannelWithImage (const Image& alphaImage, int alphaImageX, int alphaImageY,
  28964. const Image& fillerImage, int fillerImageX, int fillerImageY, float alpha);
  28965. void blendImage (const Image& sourceImage, int destX, int destY, int destW, int destH,
  28966. int sourceX, int sourceY, float alpha);
  28967. void blendImageRescaling (const Image& sourceImage, int destX, int destY, int destW, int destH,
  28968. int sourceX, int sourceY, int sourceW, int sourceH,
  28969. float alpha, const Graphics::ResamplingQuality quality);
  28970. void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH,
  28971. const AffineTransform& transform,
  28972. float alpha, const Graphics::ResamplingQuality quality);
  28973. void drawLine (double x1, double y1, double x2, double y2, const Colour& colour);
  28974. void drawVerticalLine (const int x, double top, double bottom, const Colour& col);
  28975. void drawHorizontalLine (const int x, double top, double bottom, const Colour& col);
  28976. juce_UseDebuggingNewOperator
  28977. protected:
  28978. OutputStream& out;
  28979. RectangleList* clip;
  28980. int totalWidth, totalHeight, xOffset, yOffset;
  28981. bool needToClip;
  28982. Colour lastColour;
  28983. struct SavedState
  28984. {
  28985. SavedState (RectangleList* const clip, const int xOffset, const int yOffset);
  28986. ~SavedState();
  28987. RectangleList* clip;
  28988. const int xOffset, yOffset;
  28989. private:
  28990. SavedState (const SavedState&);
  28991. const SavedState& operator= (const SavedState&);
  28992. };
  28993. OwnedArray <SavedState> stateStack;
  28994. void writeClip();
  28995. void writeColour (const Colour& colour);
  28996. void writePath (const Path& path) const;
  28997. void writeXY (const float x, const float y) const;
  28998. void writeTransform (const AffineTransform& trans) const;
  28999. void writeImage (const Image& im, const int sx, const int sy, const int maxW, const int maxH) const;
  29000. LowLevelGraphicsPostScriptRenderer (const LowLevelGraphicsPostScriptRenderer& other);
  29001. const LowLevelGraphicsPostScriptRenderer& operator= (const LowLevelGraphicsPostScriptRenderer&);
  29002. };
  29003. #endif // __JUCE_LOWLEVELGRAPHICSPOSTSCRIPTRENDERER_JUCEHEADER__
  29004. /********* End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.h *********/
  29005. #endif
  29006. #ifndef __JUCE_LOWLEVELGRAPHICSSOFTWARERENDERER_JUCEHEADER__
  29007. /********* Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.h *********/
  29008. #ifndef __JUCE_LOWLEVELGRAPHICSSOFTWARERENDERER_JUCEHEADER__
  29009. #define __JUCE_LOWLEVELGRAPHICSSOFTWARERENDERER_JUCEHEADER__
  29010. /**
  29011. A lowest-common-denominator implementation of LowLevelGraphicsContext that does all
  29012. its rendering in memory.
  29013. User code is not supposed to create instances of this class directly - do all your
  29014. rendering via the Graphics class instead.
  29015. */
  29016. class JUCE_API LowLevelGraphicsSoftwareRenderer : public LowLevelGraphicsContext
  29017. {
  29018. public:
  29019. LowLevelGraphicsSoftwareRenderer (Image& imageToRenderOn);
  29020. ~LowLevelGraphicsSoftwareRenderer();
  29021. bool isVectorDevice() const;
  29022. void setOrigin (int x, int y);
  29023. bool reduceClipRegion (int x, int y, int w, int h);
  29024. bool reduceClipRegion (const RectangleList& clipRegion);
  29025. void excludeClipRegion (int x, int y, int w, int h);
  29026. void saveState();
  29027. void restoreState();
  29028. bool clipRegionIntersects (int x, int y, int w, int h);
  29029. const Rectangle getClipBounds() const;
  29030. bool isClipEmpty() const;
  29031. void fillRectWithColour (int x, int y, int w, int h, const Colour& colour, const bool replaceExistingContents);
  29032. void fillRectWithGradient (int x, int y, int w, int h, const ColourGradient& gradient);
  29033. void fillPathWithColour (const Path& path, const AffineTransform& transform, const Colour& colour, EdgeTable::OversamplingLevel quality);
  29034. void fillPathWithGradient (const Path& path, const AffineTransform& transform, const ColourGradient& gradient, EdgeTable::OversamplingLevel quality);
  29035. void fillPathWithImage (const Path& path, const AffineTransform& transform,
  29036. const Image& image, int imageX, int imageY, float alpha, EdgeTable::OversamplingLevel quality);
  29037. void fillAlphaChannelWithColour (const Image& alphaImage, int imageX, int imageY, const Colour& colour);
  29038. void fillAlphaChannelWithGradient (const Image& alphaImage, int imageX, int imageY, const ColourGradient& gradient);
  29039. void fillAlphaChannelWithImage (const Image& alphaImage, int alphaImageX, int alphaImageY,
  29040. const Image& fillerImage, int fillerImageX, int fillerImageY, float alpha);
  29041. void blendImage (const Image& sourceImage, int destX, int destY, int destW, int destH,
  29042. int sourceX, int sourceY, float alpha);
  29043. void blendImageRescaling (const Image& sourceImage, int destX, int destY, int destW, int destH,
  29044. int sourceX, int sourceY, int sourceW, int sourceH,
  29045. float alpha, const Graphics::ResamplingQuality quality);
  29046. void blendImageWarping (const Image& sourceImage, int srcClipX, int srcClipY, int srcClipW, int srcClipH,
  29047. const AffineTransform& transform,
  29048. float alpha, const Graphics::ResamplingQuality quality);
  29049. void drawLine (double x1, double y1, double x2, double y2, const Colour& colour);
  29050. void drawVerticalLine (const int x, double top, double bottom, const Colour& col);
  29051. void drawHorizontalLine (const int x, double top, double bottom, const Colour& col);
  29052. RectangleList* getRawClipRegion() throw() { return clip; }
  29053. juce_UseDebuggingNewOperator
  29054. protected:
  29055. Image& image;
  29056. RectangleList* clip;
  29057. int xOffset, yOffset;
  29058. struct SavedState
  29059. {
  29060. SavedState (RectangleList* const clip, const int xOffset, const int yOffset);
  29061. ~SavedState();
  29062. RectangleList* clip;
  29063. const int xOffset, yOffset;
  29064. private:
  29065. SavedState (const SavedState&);
  29066. const SavedState& operator= (const SavedState&);
  29067. };
  29068. OwnedArray <SavedState> stateStack;
  29069. void drawVertical (const int x, const double top, const double bottom, const Colour& col);
  29070. void drawHorizontal (const int y, const double top, const double bottom, const Colour& col);
  29071. bool getPathBounds (int clipX, int clipY, int clipW, int clipH,
  29072. const Path& path, const AffineTransform& transform,
  29073. int& x, int& y, int& w, int& h) const;
  29074. void clippedFillRectWithColour (const Rectangle& clipRect, int x, int y, int w, int h, const Colour& colour, const bool replaceExistingContents);
  29075. void clippedFillPathWithColour (int clipX, int clipY, int clipW, int clipH, const Path& path, const AffineTransform& transform, const Colour& colour, EdgeTable::OversamplingLevel quality);
  29076. void clippedFillPathWithGradient (int clipX, int clipY, int clipW, int clipH, const Path& path, const AffineTransform& transform, const ColourGradient& gradient, EdgeTable::OversamplingLevel quality);
  29077. void clippedFillPathWithImage (int clipX, int clipY, int clipW, int clipH, const Path& path, const AffineTransform& transform,
  29078. const Image& image, int imageX, int imageY, float alpha, EdgeTable::OversamplingLevel quality);
  29079. void clippedFillAlphaChannelWithColour (int clipX, int clipY, int clipW, int clipH, const Image& alphaImage, int alphaImageX, int alphaImageY, const Colour& colour);
  29080. void clippedFillAlphaChannelWithGradient (int clipX, int clipY, int clipW, int clipH, const Image& alphaImage, int alphaImageX, int alphaImageY, const ColourGradient& gradient);
  29081. void clippedFillAlphaChannelWithImage (int clipX, int clipY, int clipW, int clipH, const Image& alphaImage, int alphaImageX, int alphaImageY,
  29082. const Image& fillerImage, int fillerImageX, int fillerImageY, float alpha);
  29083. void clippedBlendImage (int clipX, int clipY, int clipW, int clipH, const Image& sourceImage,
  29084. int destX, int destY, int destW, int destH, int sourceX, int sourceY,
  29085. float alpha);
  29086. void clippedBlendImageWarping (int clipX, int clipY, int clipW, int clipH, const Image& sourceImage,
  29087. int srcClipX, int srcClipY, int srcClipW, int srcClipH,
  29088. const AffineTransform& transform,
  29089. float alpha, const Graphics::ResamplingQuality quality);
  29090. void clippedDrawLine (int clipX, int clipY, int clipW, int clipH, double x1, double y1, double x2, double y2, const Colour& colour);
  29091. void clippedDrawVerticalLine (int clipX, int clipY, int clipW, int clipH, const int x, double top, double bottom, const Colour& col);
  29092. void clippedDrawHorizontalLine (int clipX, int clipY, int clipW, int clipH, const int x, double top, double bottom, const Colour& col);
  29093. LowLevelGraphicsSoftwareRenderer (const LowLevelGraphicsSoftwareRenderer& other);
  29094. const LowLevelGraphicsSoftwareRenderer& operator= (const LowLevelGraphicsSoftwareRenderer&);
  29095. };
  29096. #endif // __JUCE_LOWLEVELGRAPHICSSOFTWARERENDERER_JUCEHEADER__
  29097. /********* End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.h *********/
  29098. #endif
  29099. #ifndef __JUCE_RECTANGLEPLACEMENT_JUCEHEADER__
  29100. #endif
  29101. #ifndef __JUCE_AFFINETRANSFORM_JUCEHEADER__
  29102. #endif
  29103. #ifndef __JUCE_BORDERSIZE_JUCEHEADER__
  29104. #endif
  29105. #ifndef __JUCE_LINE_JUCEHEADER__
  29106. #endif
  29107. #ifndef __JUCE_PATH_JUCEHEADER__
  29108. #endif
  29109. #ifndef __JUCE_PATHITERATOR_JUCEHEADER__
  29110. /********* Start of inlined file: juce_PathIterator.h *********/
  29111. #ifndef __JUCE_PATHITERATOR_JUCEHEADER__
  29112. #define __JUCE_PATHITERATOR_JUCEHEADER__
  29113. /**
  29114. Flattens a Path object into a series of straight-line sections.
  29115. Use one of these to iterate through a Path object, and it will convert
  29116. all the curves into line sections so it's easy to render or perform
  29117. geometric operations on.
  29118. @see Path
  29119. */
  29120. class JUCE_API PathFlatteningIterator
  29121. {
  29122. public:
  29123. /** Creates a PathFlatteningIterator.
  29124. After creation, use the next() method to initialise the fields in the
  29125. object with the first line's position.
  29126. @param path the path to iterate along
  29127. @param transform a transform to apply to each point in the path being iterated
  29128. @param tolerence the amount by which the curves are allowed to deviate from the
  29129. lines into which they are being broken down - a higher tolerence
  29130. is a bit faster, but less smooth.
  29131. */
  29132. PathFlatteningIterator (const Path& path,
  29133. const AffineTransform& transform = AffineTransform::identity,
  29134. float tolerence = 9.0f) throw();
  29135. /** Destructor. */
  29136. ~PathFlatteningIterator() throw();
  29137. /** Fetches the next line segment from the path.
  29138. This will update the member variables x1, y1, x2, y2, subPathIndex and closesSubPath
  29139. so that they describe the new line segment.
  29140. @returns false when there are no more lines to fetch.
  29141. */
  29142. bool next() throw();
  29143. /** The x position of the start of the current line segment. */
  29144. float x1;
  29145. /** The y position of the start of the current line segment. */
  29146. float y1;
  29147. /** The x position of the end of the current line segment. */
  29148. float x2;
  29149. /** The y position of the end of the current line segment. */
  29150. float y2;
  29151. /** Indicates whether the current line segment is closing a sub-path.
  29152. If the current line is the one that connects the end of a sub-path
  29153. back to the start again, this will be true.
  29154. */
  29155. bool closesSubPath;
  29156. /** The index of the current line within the current sub-path.
  29157. E.g. you can use this to see whether the line is the first one in the
  29158. subpath by seeing if it's 0.
  29159. */
  29160. int subPathIndex;
  29161. /** Returns true if the current segment is the last in the current sub-path. */
  29162. bool isLastInSubpath() const throw() { return stackPos == stackBase; }
  29163. juce_UseDebuggingNewOperator
  29164. private:
  29165. const Path& path;
  29166. const AffineTransform transform;
  29167. float* points;
  29168. float tolerence, subPathCloseX, subPathCloseY;
  29169. bool isIdentityTransform;
  29170. float* stackBase;
  29171. float* stackPos;
  29172. int index, stackSize;
  29173. PathFlatteningIterator (const PathFlatteningIterator&);
  29174. const PathFlatteningIterator& operator= (const PathFlatteningIterator&);
  29175. };
  29176. #endif // __JUCE_PATHITERATOR_JUCEHEADER__
  29177. /********* End of inlined file: juce_PathIterator.h *********/
  29178. #endif
  29179. #ifndef __JUCE_PATHSTROKETYPE_JUCEHEADER__
  29180. #endif
  29181. #ifndef __JUCE_POINT_JUCEHEADER__
  29182. #endif
  29183. #ifndef __JUCE_POSITIONEDRECTANGLE_JUCEHEADER__
  29184. /********* Start of inlined file: juce_PositionedRectangle.h *********/
  29185. #ifndef __JUCE_POSITIONEDRECTANGLE_JUCEHEADER__
  29186. #define __JUCE_POSITIONEDRECTANGLE_JUCEHEADER__
  29187. /**
  29188. A rectangle whose co-ordinates can be defined in terms of absolute or
  29189. proportional distances.
  29190. Designed mainly for storing component positions, this gives you a lot of
  29191. control over how each co-ordinate is stored, either as an absolute position,
  29192. or as a proportion of the size of a parent rectangle.
  29193. It also allows you to define the anchor points by which the rectangle is
  29194. positioned, so for example you could specify that the top right of the
  29195. rectangle should be an absolute distance from its parent's bottom-right corner.
  29196. This object can be stored as a string, which takes the form "x y w h", including
  29197. symbols like '%' and letters to indicate the anchor point. See its toString()
  29198. method for more info.
  29199. Example usage:
  29200. @code
  29201. class MyComponent
  29202. {
  29203. void resized()
  29204. {
  29205. // this will set the child component's x to be 20% of our width, its y
  29206. // to be 30, its width to be 150, and its height to be 50% of our
  29207. // height..
  29208. const PositionedRectangle pos1 ("20% 30 150 50%");
  29209. pos1.applyToComponent (*myChildComponent1);
  29210. // this will inset the child component with a gap of 10 pixels
  29211. // around each of its edges..
  29212. const PositionedRectangle pos2 ("10 10 20M 20M");
  29213. pos2.applyToComponent (*myChildComponent2);
  29214. }
  29215. };
  29216. @endcode
  29217. */
  29218. class JUCE_API PositionedRectangle
  29219. {
  29220. public:
  29221. /** Creates an empty rectangle with all co-ordinates set to zero.
  29222. The default anchor point is top-left; the default
  29223. */
  29224. PositionedRectangle() throw();
  29225. /** Initialises a PositionedRectangle from a saved string version.
  29226. The string must be in the format generated by toString().
  29227. */
  29228. PositionedRectangle (const String& stringVersion) throw();
  29229. /** Creates a copy of another PositionedRectangle. */
  29230. PositionedRectangle (const PositionedRectangle& other) throw();
  29231. /** Copies another PositionedRectangle. */
  29232. const PositionedRectangle& operator= (const PositionedRectangle& other) throw();
  29233. /** Destructor. */
  29234. ~PositionedRectangle() throw();
  29235. /** Returns a string version of this position, from which it can later be
  29236. re-generated.
  29237. The format is four co-ordinates, "x y w h".
  29238. - If a co-ordinate is absolute, it is stored as an integer, e.g. "100".
  29239. - If a co-ordinate is proportional to its parent's width or height, it is stored
  29240. as a percentage, e.g. "80%".
  29241. - If the X or Y co-ordinate is relative to the parent's right or bottom edge, the
  29242. number has "R" appended to it, e.g. "100R" means a distance of 100 pixels from
  29243. the parent's right-hand edge.
  29244. - If the X or Y co-ordinate is relative to the parent's centre, the number has "C"
  29245. appended to it, e.g. "-50C" would be 50 pixels left of the parent's centre.
  29246. - If the X or Y co-ordinate should be anchored at the component's right or bottom
  29247. edge, then it has "r" appended to it. So "-50Rr" would mean that this component's
  29248. right-hand edge should be 50 pixels left of the parent's right-hand edge.
  29249. - If the X or Y co-ordinate should be anchored at the component's centre, then it
  29250. has "c" appended to it. So "-50Rc" would mean that this component's
  29251. centre should be 50 pixels left of the parent's right-hand edge. "40%c" means that
  29252. this component's centre should be placed 40% across the parent's width.
  29253. - If it's a width or height that should use the parentSizeMinusAbsolute mode, then
  29254. the number has "M" appended to it.
  29255. To reload a stored string, use the constructor that takes a string parameter.
  29256. */
  29257. const String toString() const throw();
  29258. /** Calculates the absolute position, given the size of the space that
  29259. it should go in.
  29260. This will work out any proportional distances and sizes relative to the
  29261. target rectangle, and will return the absolute position.
  29262. @see applyToComponent
  29263. */
  29264. const Rectangle getRectangle (const Rectangle& targetSpaceToBeRelativeTo) const throw();
  29265. /** Same as getRectangle(), but returning the values as doubles rather than ints.
  29266. */
  29267. void getRectangleDouble (const Rectangle& targetSpaceToBeRelativeTo,
  29268. double& x,
  29269. double& y,
  29270. double& width,
  29271. double& height) const throw();
  29272. /** This sets the bounds of the given component to this position.
  29273. This is equivalent to writing:
  29274. @code
  29275. comp.setBounds (getRectangle (Rectangle (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  29276. @endcode
  29277. @see getRectangle, updateFromComponent
  29278. */
  29279. void applyToComponent (Component& comp) const throw();
  29280. /** Updates this object's co-ordinates to match the given rectangle.
  29281. This will set all co-ordinates based on the given rectangle, re-calculating
  29282. any proportional distances, and using the current anchor points.
  29283. So for example if the x co-ordinate mode is currently proportional, this will
  29284. re-calculate x based on the rectangle's relative position within the target
  29285. rectangle's width.
  29286. If the target rectangle's width or height are zero then it may not be possible
  29287. to re-calculate some proportional co-ordinates. In this case, those co-ordinates
  29288. will not be changed.
  29289. */
  29290. void updateFrom (const Rectangle& newPosition,
  29291. const Rectangle& targetSpaceToBeRelativeTo) throw();
  29292. /** Same functionality as updateFrom(), but taking doubles instead of ints.
  29293. */
  29294. void updateFromDouble (const double x, const double y,
  29295. const double width, const double height,
  29296. const Rectangle& targetSpaceToBeRelativeTo) throw();
  29297. /** Updates this object's co-ordinates to match the bounds of this component.
  29298. This is equivalent to calling updateFrom() with the component's bounds and
  29299. it parent size.
  29300. If the component doesn't currently have a parent, then proportional co-ordinates
  29301. might not be updated because it would need to know the parent's size to do the
  29302. maths for this.
  29303. */
  29304. void updateFromComponent (const Component& comp) throw();
  29305. /** Specifies the point within the rectangle, relative to which it should be positioned. */
  29306. enum AnchorPoint
  29307. {
  29308. anchorAtLeftOrTop = 1 << 0, /**< The x or y co-ordinate specifies where the left or top edge of the rectangle should be. */
  29309. anchorAtRightOrBottom = 1 << 1, /**< The x or y co-ordinate specifies where the right or bottom edge of the rectangle should be. */
  29310. anchorAtCentre = 1 << 2 /**< The x or y co-ordinate specifies where the centre of the rectangle should be. */
  29311. };
  29312. /** Specifies how an x or y co-ordinate should be interpreted. */
  29313. enum PositionMode
  29314. {
  29315. absoluteFromParentTopLeft = 1 << 3, /**< The x or y co-ordinate specifies an absolute distance from the parent's top or left edge. */
  29316. absoluteFromParentBottomRight = 1 << 4, /**< The x or y co-ordinate specifies an absolute distance from the parent's bottom or right edge. */
  29317. absoluteFromParentCentre = 1 << 5, /**< The x or y co-ordinate specifies an absolute distance from the parent's centre. */
  29318. proportionOfParentSize = 1 << 6 /**< The x or y co-ordinate specifies a proportion of the parent's width or height, measured from the parent's top or left. */
  29319. };
  29320. /** Specifies how the width or height should be interpreted. */
  29321. enum SizeMode
  29322. {
  29323. absoluteSize = 1 << 0, /**< The width or height specifies an absolute size. */
  29324. parentSizeMinusAbsolute = 1 << 1, /**< The width or height is an amount that should be subtracted from the parent's width or height. */
  29325. proportionalSize = 1 << 2, /**< The width or height specifies a proportion of the parent's width or height. */
  29326. };
  29327. /** Sets all options for all co-ordinates.
  29328. This requires a reference rectangle to be specified, because if you're changing any
  29329. of the modes from proportional to absolute or vice-versa, then it'll need to convert
  29330. the co-ordinates, and will need to know the parent size so it can calculate this.
  29331. */
  29332. void setModes (const AnchorPoint xAnchorMode,
  29333. const PositionMode xPositionMode,
  29334. const AnchorPoint yAnchorMode,
  29335. const PositionMode yPositionMode,
  29336. const SizeMode widthMode,
  29337. const SizeMode heightMode,
  29338. const Rectangle& targetSpaceToBeRelativeTo) throw();
  29339. /** Returns the anchoring mode for the x co-ordinate.
  29340. To change any of the modes, use setModes().
  29341. */
  29342. AnchorPoint getAnchorPointX() const throw();
  29343. /** Returns the positioning mode for the x co-ordinate.
  29344. To change any of the modes, use setModes().
  29345. */
  29346. PositionMode getPositionModeX() const throw();
  29347. /** Returns the raw x co-ordinate.
  29348. If the x position mode is absolute, then this will be the absolute value. If it's
  29349. proportional, then this will be a fractional proportion, where 1.0 means the full
  29350. width of the parent space.
  29351. */
  29352. double getX() const throw() { return x; }
  29353. /** Sets the raw value of the x co-ordinate.
  29354. See getX() for the meaning of this value.
  29355. */
  29356. void setX (const double newX) throw() { x = newX; }
  29357. /** Returns the anchoring mode for the y co-ordinate.
  29358. To change any of the modes, use setModes().
  29359. */
  29360. AnchorPoint getAnchorPointY() const throw();
  29361. /** Returns the positioning mode for the y co-ordinate.
  29362. To change any of the modes, use setModes().
  29363. */
  29364. PositionMode getPositionModeY() const throw();
  29365. /** Returns the raw y co-ordinate.
  29366. If the y position mode is absolute, then this will be the absolute value. If it's
  29367. proportional, then this will be a fractional proportion, where 1.0 means the full
  29368. height of the parent space.
  29369. */
  29370. double getY() const throw() { return y; }
  29371. /** Sets the raw value of the y co-ordinate.
  29372. See getY() for the meaning of this value.
  29373. */
  29374. void setY (const double newY) throw() { y = newY; }
  29375. /** Returns the mode used to calculate the width.
  29376. To change any of the modes, use setModes().
  29377. */
  29378. SizeMode getWidthMode() const throw();
  29379. /** Returns the raw width value.
  29380. If the width mode is absolute, then this will be the absolute value. If the mode is
  29381. proportional, then this will be a fractional proportion, where 1.0 means the full
  29382. width of the parent space.
  29383. */
  29384. double getWidth() const throw() { return w; }
  29385. /** Sets the raw width value.
  29386. See getWidth() for the details about what this value means.
  29387. */
  29388. void setWidth (const double newWidth) throw() { w = newWidth; }
  29389. /** Returns the mode used to calculate the height.
  29390. To change any of the modes, use setModes().
  29391. */
  29392. SizeMode getHeightMode() const throw();
  29393. /** Returns the raw height value.
  29394. If the height mode is absolute, then this will be the absolute value. If the mode is
  29395. proportional, then this will be a fractional proportion, where 1.0 means the full
  29396. height of the parent space.
  29397. */
  29398. double getHeight() const throw() { return h; }
  29399. /** Sets the raw height value.
  29400. See getHeight() for the details about what this value means.
  29401. */
  29402. void setHeight (const double newHeight) throw() { h = newHeight; }
  29403. /** If the size and position are constance, and wouldn't be affected by changes
  29404. in the parent's size, then this will return true.
  29405. */
  29406. bool isPositionAbsolute() const throw();
  29407. /** Compares two objects. */
  29408. const bool operator== (const PositionedRectangle& other) const throw();
  29409. /** Compares two objects. */
  29410. const bool operator!= (const PositionedRectangle& other) const throw();
  29411. juce_UseDebuggingNewOperator
  29412. private:
  29413. double x, y, w, h;
  29414. uint8 xMode, yMode, wMode, hMode;
  29415. void addPosDescription (String& result, const uint8 mode, const double value) const throw();
  29416. void addSizeDescription (String& result, const uint8 mode, const double value) const throw();
  29417. void decodePosString (const String& s, uint8& mode, double& value) throw();
  29418. void decodeSizeString (const String& s, uint8& mode, double& value) throw();
  29419. void applyPosAndSize (double& xOut, double& wOut, const double x, const double w,
  29420. const uint8 xMode, const uint8 wMode,
  29421. const int parentPos, const int parentSize) const throw();
  29422. void updatePosAndSize (double& xOut, double& wOut, double x, const double w,
  29423. const uint8 xMode, const uint8 wMode,
  29424. const int parentPos, const int parentSize) const throw();
  29425. };
  29426. #endif // __JUCE_POSITIONEDRECTANGLE_JUCEHEADER__
  29427. /********* End of inlined file: juce_PositionedRectangle.h *********/
  29428. #endif
  29429. #ifndef __JUCE_RECTANGLE_JUCEHEADER__
  29430. #endif
  29431. #ifndef __JUCE_RECTANGLELIST_JUCEHEADER__
  29432. #endif
  29433. #ifndef __JUCE_IMAGE_JUCEHEADER__
  29434. #endif
  29435. #ifndef __JUCE_IMAGECACHE_JUCEHEADER__
  29436. /********* Start of inlined file: juce_ImageCache.h *********/
  29437. #ifndef __JUCE_IMAGECACHE_JUCEHEADER__
  29438. #define __JUCE_IMAGECACHE_JUCEHEADER__
  29439. /**
  29440. A global cache of images that have been loaded from files or memory.
  29441. If you're loading an image and may need to use the image in more than one
  29442. place, this is used to allow the same image to be shared rather than loading
  29443. multiple copies into memory.
  29444. Another advantage is that after images are released, they will be kept in
  29445. memory for a few seconds before it is actually deleted, so if you're repeatedly
  29446. loading/deleting the same image, it'll reduce the chances of having to reload it
  29447. each time.
  29448. @see Image, ImageFileFormat
  29449. */
  29450. class JUCE_API ImageCache : private DeletedAtShutdown,
  29451. private Timer
  29452. {
  29453. public:
  29454. /** Loads an image from a file, (or just returns the image if it's already cached).
  29455. If the cache already contains an image that was loaded from this file,
  29456. that image will be returned. Otherwise, this method will try to load the
  29457. file, add it to the cache, and return it.
  29458. It's very important not to delete the image that is returned - instead use
  29459. the ImageCache::release() method.
  29460. Also, remember that the image returned is shared, so drawing into it might
  29461. affect other things that are using it!
  29462. @param file the file to try to load
  29463. @returns the image, or null if it there was an error loading it
  29464. @see release, getFromMemory, getFromCache, ImageFileFormat::loadFrom
  29465. */
  29466. static Image* getFromFile (const File& file);
  29467. /** Loads an image from an in-memory image file, (or just returns the image if it's already cached).
  29468. If the cache already contains an image that was loaded from this block of memory,
  29469. that image will be returned. Otherwise, this method will try to load the
  29470. file, add it to the cache, and return it.
  29471. It's very important not to delete the image that is returned - instead use
  29472. the ImageCache::release() method.
  29473. Also, remember that the image returned is shared, so drawing into it might
  29474. affect other things that are using it!
  29475. @param imageData the block of memory containing the image data
  29476. @param dataSize the data size in bytes
  29477. @returns the image, or null if it there was an error loading it
  29478. @see release, getFromMemory, getFromCache, ImageFileFormat::loadFrom
  29479. */
  29480. static Image* getFromMemory (const void* imageData,
  29481. const int dataSize);
  29482. /** Releases an image that was previously created by the ImageCache.
  29483. If an image has been returned by the getFromFile() or getFromMemory() methods,
  29484. it mustn't be deleted directly, but should be released with this method
  29485. instead.
  29486. @see getFromFile, getFromMemory
  29487. */
  29488. static void release (Image* const imageToRelease);
  29489. /** Checks whether an image is in the cache or not.
  29490. @returns true if the image is currently in the cache
  29491. */
  29492. static bool isImageInCache (Image* const imageToLookFor);
  29493. /** Increments the reference-count for a cached image.
  29494. If the image isn't in the cache, this method won't do anything.
  29495. */
  29496. static void incReferenceCount (Image* const image);
  29497. /** Checks the cache for an image with a particular hashcode.
  29498. If there's an image in the cache with this hashcode, it will be returned,
  29499. otherwise it will return zero.
  29500. If an image is returned, it must be released with the release() method
  29501. when no longer needed, to maintain the correct reference counts.
  29502. @param hashCode the hash code that would have been associated with the
  29503. image by addImageToCache()
  29504. @see addImageToCache
  29505. */
  29506. static Image* getFromHashCode (const int64 hashCode);
  29507. /** Adds an image to the cache with a user-defined hash-code.
  29508. After calling this, responsibilty for deleting the image will be taken
  29509. by the ImageCache.
  29510. The image will be initially be given a reference count of 1, so call
  29511. the release() method to delete it.
  29512. @param image the image to add
  29513. @param hashCode the hash-code to associate with it
  29514. @see getFromHashCode
  29515. */
  29516. static void addImageToCache (Image* const image,
  29517. const int64 hashCode);
  29518. /** Changes the amount of time before an unused image will be removed from the cache.
  29519. By default this is about 5 seconds.
  29520. */
  29521. static void setCacheTimeout (const int millisecs);
  29522. juce_UseDebuggingNewOperator
  29523. private:
  29524. CriticalSection lock;
  29525. VoidArray images;
  29526. ImageCache() throw();
  29527. ImageCache (const ImageCache&);
  29528. const ImageCache& operator= (const ImageCache&);
  29529. ~ImageCache();
  29530. void timerCallback();
  29531. };
  29532. #endif // __JUCE_IMAGECACHE_JUCEHEADER__
  29533. /********* End of inlined file: juce_ImageCache.h *********/
  29534. #endif
  29535. #ifndef __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
  29536. /********* Start of inlined file: juce_ImageConvolutionKernel.h *********/
  29537. #ifndef __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
  29538. #define __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
  29539. /**
  29540. Represents a filter kernel to use in convoluting an image.
  29541. @see Image::applyConvolution
  29542. */
  29543. class JUCE_API ImageConvolutionKernel
  29544. {
  29545. public:
  29546. /** Creates an empty convulution kernel.
  29547. @param size the length of each dimension of the kernel, so e.g. if the size
  29548. is 5, it will create a 5x5 kernel
  29549. */
  29550. ImageConvolutionKernel (const int size) throw();
  29551. /** Destructor. */
  29552. ~ImageConvolutionKernel() throw();
  29553. /** Resets all values in the kernel to zero.
  29554. */
  29555. void clear() throw();
  29556. /** Sets the value of a specific cell in the kernel.
  29557. The x and y parameters must be in the range 0 < x < getKernelSize().
  29558. @see setOverallSum
  29559. */
  29560. void setKernelValue (const int x,
  29561. const int y,
  29562. const float value) throw();
  29563. /** Rescales all values in the kernel to make the total add up to a fixed value.
  29564. This will multiply all values in the kernel by (desiredTotalSum / currentTotalSum).
  29565. */
  29566. void setOverallSum (const float desiredTotalSum) throw();
  29567. /** Multiplies all values in the kernel by a value. */
  29568. void rescaleAllValues (const float multiplier) throw();
  29569. /** Intialises the kernel for a gaussian blur.
  29570. @param blurRadius this may be larger or smaller than the kernel's actual
  29571. size but this will obviously be wasteful or clip at the
  29572. edges. Ideally the kernel should be just larger than
  29573. (blurRadius * 2).
  29574. */
  29575. void createGaussianBlur (const float blurRadius) throw();
  29576. /** Returns the size of the kernel.
  29577. E.g. if it's a 3x3 kernel, this returns 3.
  29578. */
  29579. int getKernelSize() const throw() { return size; }
  29580. /** Returns a 2-dimensional array of the kernel's values.
  29581. The size of each dimension of the array will be getKernelSize().
  29582. */
  29583. float** getValues() const throw() { return values; }
  29584. /** Applies the kernel to an image.
  29585. @param destImage the image that will receive the resultant convoluted pixels.
  29586. @param sourceImage an optional source image to read from - if this is 0, then the
  29587. destination image will be used as the source. If an image is
  29588. specified, it must be exactly the same size and type as the destination
  29589. image.
  29590. @param x the region of the image to apply the filter to
  29591. @param y the region of the image to apply the filter to
  29592. @param width the region of the image to apply the filter to
  29593. @param height the region of the image to apply the filter to
  29594. */
  29595. void applyToImage (Image& destImage,
  29596. const Image* sourceImage,
  29597. int x,
  29598. int y,
  29599. int width,
  29600. int height) const;
  29601. juce_UseDebuggingNewOperator
  29602. private:
  29603. float** values;
  29604. int size;
  29605. // no reason not to implement these one day..
  29606. ImageConvolutionKernel (const ImageConvolutionKernel&);
  29607. const ImageConvolutionKernel& operator= (const ImageConvolutionKernel&);
  29608. };
  29609. #endif // __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
  29610. /********* End of inlined file: juce_ImageConvolutionKernel.h *********/
  29611. #endif
  29612. #ifndef __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
  29613. /********* Start of inlined file: juce_ImageFileFormat.h *********/
  29614. #ifndef __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
  29615. #define __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
  29616. /**
  29617. Base-class for codecs that can read and write image file formats such
  29618. as PNG, JPEG, etc.
  29619. This class also contains static methods to make it easy to load images
  29620. from files, streams or from memory.
  29621. @see Image, ImageCache
  29622. */
  29623. class JUCE_API ImageFileFormat
  29624. {
  29625. protected:
  29626. /** Creates an ImageFormat. */
  29627. ImageFileFormat() throw() {}
  29628. public:
  29629. /** Destructor. */
  29630. virtual ~ImageFileFormat() throw() {}
  29631. /** Returns a description of this file format.
  29632. E.g. "JPEG", "PNG"
  29633. */
  29634. virtual const String getFormatName() = 0;
  29635. /** Returns true if the given stream seems to contain data that this format
  29636. understands.
  29637. The format class should only read the first few bytes of the stream and sniff
  29638. for header bytes that it understands.
  29639. @see decodeImage
  29640. */
  29641. virtual bool canUnderstand (InputStream& input) = 0;
  29642. /** Tries to decode and return an image from the given stream.
  29643. This will be called for an image format after calling its canUnderStand() method
  29644. to see if it can handle the stream.
  29645. @param input the stream to read the data from. The stream will be positioned
  29646. at the start of the image data (but this may not necessarily
  29647. be position 0)
  29648. @returns the image that was decoded, or 0 if it fails. It's the
  29649. caller's responsibility to delete this image when no longer needed.
  29650. @see loadFrom
  29651. */
  29652. virtual Image* decodeImage (InputStream& input) = 0;
  29653. /** Attempts to write an image to a stream.
  29654. To specify extra information like encoding quality, there will be appropriate parameters
  29655. in the subclasses of the specific file types.
  29656. @returns true if it nothing went wrong.
  29657. */
  29658. virtual bool writeImageToStream (const Image& sourceImage,
  29659. OutputStream& destStream) = 0;
  29660. /** Tries the built-in decoders to see if it can find one to read this stream.
  29661. There are currently built-in decoders for PNG, JPEG and GIF formats.
  29662. The object that is returned should not be deleted by the caller.
  29663. @see canUnderstand, decodeImage, loadFrom
  29664. */
  29665. static ImageFileFormat* findImageFormatForStream (InputStream& input);
  29666. /** Tries to load an image from a stream.
  29667. This will use the findImageFormatForStream() method to locate a suitable
  29668. codec, and use that to load the image.
  29669. @returns the image that was decoded, or 0 if it fails to load one. It's the
  29670. caller's responsibility to delete this image when no longer needed.
  29671. */
  29672. static Image* loadFrom (InputStream& input);
  29673. /** Tries to load an image from a file.
  29674. This will use the findImageFormatForStream() method to locate a suitable
  29675. codec, and use that to load the image.
  29676. @returns the image that was decoded, or 0 if it fails to load one. It's the
  29677. caller's responsibility to delete this image when no longer needed.
  29678. */
  29679. static Image* loadFrom (const File& file);
  29680. /** Tries to load an image from a block of raw image data.
  29681. This will use the findImageFormatForStream() method to locate a suitable
  29682. codec, and use that to load the image.
  29683. @returns the image that was decoded, or 0 if it fails to load one. It's the
  29684. caller's responsibility to delete this image when no longer needed.
  29685. */
  29686. static Image* loadFrom (const void* rawData,
  29687. const int numBytesOfData);
  29688. };
  29689. /**
  29690. A type of ImageFileFormat for reading and writing PNG files.
  29691. @see ImageFileFormat, JPEGImageFormat
  29692. */
  29693. class PNGImageFormat : public ImageFileFormat
  29694. {
  29695. public:
  29696. PNGImageFormat() throw();
  29697. ~PNGImageFormat() throw();
  29698. const String getFormatName();
  29699. bool canUnderstand (InputStream& input);
  29700. Image* decodeImage (InputStream& input);
  29701. bool writeImageToStream (const Image& sourceImage, OutputStream& destStream);
  29702. };
  29703. /**
  29704. A type of ImageFileFormat for reading and writing JPEG files.
  29705. @see ImageFileFormat, PNGImageFormat
  29706. */
  29707. class JPEGImageFormat : public ImageFileFormat
  29708. {
  29709. public:
  29710. JPEGImageFormat() throw();
  29711. ~JPEGImageFormat() throw();
  29712. /** Specifies the quality to be used when writing a JPEG file.
  29713. @param newQuality a value 0 to 1.0, where 0 is low quality, 1.0 is best, or
  29714. any negative value is "default" quality
  29715. */
  29716. void setQuality (const float newQuality);
  29717. const String getFormatName();
  29718. bool canUnderstand (InputStream& input);
  29719. Image* decodeImage (InputStream& input);
  29720. bool writeImageToStream (const Image& sourceImage, OutputStream& destStream);
  29721. private:
  29722. float quality;
  29723. };
  29724. #endif // __JUCE_IMAGEFILEFORMAT_JUCEHEADER__
  29725. /********* End of inlined file: juce_ImageFileFormat.h *********/
  29726. #endif
  29727. #ifndef __JUCE_DRAWABLE_JUCEHEADER__
  29728. /********* Start of inlined file: juce_Drawable.h *********/
  29729. #ifndef __JUCE_DRAWABLE_JUCEHEADER__
  29730. #define __JUCE_DRAWABLE_JUCEHEADER__
  29731. /**
  29732. The base class for objects which can draw themselves, e.g. polygons, images, etc.
  29733. @see DrawableComposite, DrawableImage, DrawablePath, DrawableText
  29734. */
  29735. class JUCE_API Drawable
  29736. {
  29737. protected:
  29738. /** The base class can't be instantiated directly.
  29739. @see DrawableComposite, DrawableImage, DrawablePath, DrawableText
  29740. */
  29741. Drawable();
  29742. public:
  29743. /** Destructor. */
  29744. virtual ~Drawable();
  29745. /** Creates a deep copy of this Drawable object.
  29746. Use this to create a new copy of this and any sub-objects in the tree.
  29747. */
  29748. virtual Drawable* createCopy() const = 0;
  29749. /** Renders this Drawable object.
  29750. This is the main rendering method you should call to render a Drawable.
  29751. @see drawWithin
  29752. */
  29753. virtual void draw (Graphics& g,
  29754. const AffineTransform& transform = AffineTransform::identity) const = 0;
  29755. /** Renders the Drawable at a given offset within the Graphics context.
  29756. The co-ordinates passed-in are used to translate the object relative to its own
  29757. origin before drawing it - this is basically a quick way of saying:
  29758. @code
  29759. draw (g, AffineTransform::translation (x, y)).
  29760. @endcode
  29761. */
  29762. void drawAt (Graphics& g,
  29763. const float x,
  29764. const float y) const;
  29765. /** Renders the Drawable within a rectangle, scaling it to fit neatly inside without
  29766. changing its aspect-ratio.
  29767. The object can placed arbitrarily within the rectangle based on a Justification type,
  29768. and can either be made as big as possible, or just reduced to fit.
  29769. @param g the graphics context to render onto
  29770. @param destX top-left of the target rectangle to fit it into
  29771. @param destY top-left of the target rectangle to fit it into
  29772. @param destWidth size of the target rectangle to fit the image into
  29773. @param destHeight size of the target rectangle to fit the image into
  29774. @param placement defines the alignment and rescaling to use to fit
  29775. this object within the target rectangle.
  29776. */
  29777. void drawWithin (Graphics& g,
  29778. const int destX,
  29779. const int destY,
  29780. const int destWidth,
  29781. const int destHeight,
  29782. const RectanglePlacement& placement) const;
  29783. /** Returns the smallest rectangle that can contain this Drawable object.
  29784. Co-ordinates are relative to the object's own origin.
  29785. */
  29786. virtual void getBounds (float& x, float& y, float& width, float& height) const = 0;
  29787. /** Returns true if the given point is somewhere inside this Drawable.
  29788. Co-ordinates are relative to the object's own origin.
  29789. */
  29790. virtual bool hitTest (float x, float y) const = 0;
  29791. /** Returns the name given to this drawable.
  29792. @see setName
  29793. */
  29794. const String& getName() const throw() { return name; }
  29795. /** Assigns a name to this drawable. */
  29796. void setName (const String& newName) throw() { name = newName; }
  29797. /** Tries to turn some kind of image file into a drawable.
  29798. The data could be an image that the ImageFileFormat class understands, or it
  29799. could be SVG.
  29800. */
  29801. static Drawable* createFromImageData (const void* data, const int numBytes);
  29802. /** Tries to turn a stream containing some kind of image data into a drawable.
  29803. The data could be an image that the ImageFileFormat class understands, or it
  29804. could be SVG.
  29805. */
  29806. static Drawable* createFromImageDataStream (InputStream& dataSource);
  29807. /** Tries to turn a file containing some kind of image data into a drawable.
  29808. The data could be an image that the ImageFileFormat class understands, or it
  29809. could be SVG.
  29810. */
  29811. static Drawable* createFromImageFile (const File& file);
  29812. /** Attempts to parse an SVG (Scalable Vector Graphics) document, and to turn this
  29813. into a Drawable tree.
  29814. The object returned must be deleted by the caller. If something goes wrong
  29815. while parsing, it may return 0.
  29816. SVG is a pretty large and complex spec, and this doesn't aim to be a full
  29817. implementation, but it can return the basic vector objects.
  29818. */
  29819. static Drawable* createFromSVG (const XmlElement& svgDocument);
  29820. juce_UseDebuggingNewOperator
  29821. private:
  29822. Drawable (const Drawable&);
  29823. const Drawable& operator= (const Drawable&);
  29824. String name;
  29825. };
  29826. #endif // __JUCE_DRAWABLE_JUCEHEADER__
  29827. /********* End of inlined file: juce_Drawable.h *********/
  29828. #endif
  29829. #ifndef __JUCE_DRAWABLECOMPOSITE_JUCEHEADER__
  29830. /********* Start of inlined file: juce_DrawableComposite.h *********/
  29831. #ifndef __JUCE_DRAWABLECOMPOSITE_JUCEHEADER__
  29832. #define __JUCE_DRAWABLECOMPOSITE_JUCEHEADER__
  29833. /**
  29834. A drawable object which acts as a container for a set of other Drawables.
  29835. @see Drawable
  29836. */
  29837. class JUCE_API DrawableComposite : public Drawable
  29838. {
  29839. public:
  29840. /** Creates a composite Drawable.
  29841. */
  29842. DrawableComposite();
  29843. /** Destructor. */
  29844. virtual ~DrawableComposite();
  29845. /** Adds a new sub-drawable to this one.
  29846. This passes in a Drawable pointer for this object to look after. To add a copy
  29847. of a drawable, use the form of this method that takes a Drawable reference instead.
  29848. @param drawable the object to add - this will be deleted automatically
  29849. when no longer needed, so the caller mustn't keep any
  29850. pointers to it.
  29851. @param transform the transform to apply to this drawable when it's being
  29852. drawn
  29853. @param index where to insert it in the list of drawables. 0 is the back,
  29854. -1 is the front, or any value from 0 and getNumDrawables()
  29855. can be used
  29856. @see removeDrawable
  29857. */
  29858. void insertDrawable (Drawable* drawable,
  29859. const AffineTransform& transform = AffineTransform::identity,
  29860. const int index = -1);
  29861. /** Adds a new sub-drawable to this one.
  29862. This takes a copy of a Drawable and adds it to this object. To pass in a Drawable
  29863. for this object to look after, use the form of this method that takes a Drawable
  29864. pointer instead.
  29865. @param drawable the object to add - an internal copy will be made of this object
  29866. @param transform the transform to apply to this drawable when it's being
  29867. drawn
  29868. @param index where to insert it in the list of drawables. 0 is the back,
  29869. -1 is the front, or any value from 0 and getNumDrawables()
  29870. can be used
  29871. @see removeDrawable
  29872. */
  29873. void insertDrawable (const Drawable& drawable,
  29874. const AffineTransform& transform = AffineTransform::identity,
  29875. const int index = -1);
  29876. /** Deletes one of the Drawable objects.
  29877. @param index the index of the drawable to delete, between 0
  29878. and (getNumDrawables() - 1).
  29879. @see insertDrawable, getNumDrawables
  29880. */
  29881. void removeDrawable (const int index);
  29882. /** Returns the number of drawables contained inside this one.
  29883. @see getDrawable
  29884. */
  29885. int getNumDrawables() const throw() { return drawables.size(); }
  29886. /** Returns one of the drawables that are contained in this one.
  29887. Each drawable also has a transform associated with it - you can use getDrawableTransform()
  29888. to find it.
  29889. The pointer returned is managed by this object and will be deleted when no longer
  29890. needed, so be careful what you do with it.
  29891. @see getNumDrawables
  29892. */
  29893. Drawable* getDrawable (const int index) const throw() { return drawables [index]; }
  29894. /** Returns the transform that applies to one of the drawables that are contained in this one.
  29895. The pointer returned is managed by this object and will be deleted when no longer
  29896. needed, so be careful what you do with it.
  29897. @see getNumDrawables
  29898. */
  29899. const AffineTransform* getDrawableTransform (const int index) const throw() { return transforms [index]; }
  29900. /** Brings one of the Drawables to the front.
  29901. @param index the index of the drawable to move, between 0
  29902. and (getNumDrawables() - 1).
  29903. @see insertDrawable, getNumDrawables
  29904. */
  29905. void bringToFront (const int index);
  29906. /** @internal */
  29907. void draw (Graphics& g, const AffineTransform& transform) const;
  29908. /** @internal */
  29909. void getBounds (float& x, float& y, float& width, float& height) const;
  29910. /** @internal */
  29911. bool hitTest (float x, float y) const;
  29912. /** @internal */
  29913. Drawable* createCopy() const;
  29914. juce_UseDebuggingNewOperator
  29915. private:
  29916. OwnedArray <Drawable> drawables;
  29917. OwnedArray <AffineTransform> transforms;
  29918. DrawableComposite (const DrawableComposite&);
  29919. const DrawableComposite& operator= (const DrawableComposite&);
  29920. };
  29921. #endif // __JUCE_DRAWABLECOMPOSITE_JUCEHEADER__
  29922. /********* End of inlined file: juce_DrawableComposite.h *********/
  29923. #endif
  29924. #ifndef __JUCE_DRAWABLEIMAGE_JUCEHEADER__
  29925. /********* Start of inlined file: juce_DrawableImage.h *********/
  29926. #ifndef __JUCE_DRAWABLEIMAGE_JUCEHEADER__
  29927. #define __JUCE_DRAWABLEIMAGE_JUCEHEADER__
  29928. /**
  29929. A drawable object which is a bitmap image.
  29930. @see Drawable
  29931. */
  29932. class JUCE_API DrawableImage : public Drawable
  29933. {
  29934. public:
  29935. DrawableImage();
  29936. /** Destructor. */
  29937. virtual ~DrawableImage();
  29938. /** Sets the image that this drawable will render.
  29939. An internal copy is made of the image passed-in. If you want to provide an
  29940. image that this object can take charge of without needing to create a copy,
  29941. use the other setImage() method.
  29942. */
  29943. void setImage (const Image& imageToCopy);
  29944. /** Sets the image that this drawable will render.
  29945. An internal copy of this will not be made, so the caller mustn't delete
  29946. the image while it's still being used by this object.
  29947. A good way to use this is with the ImageCache - if you create an image
  29948. with ImageCache and pass it in here with releaseWhenNotNeeded = true, then
  29949. it'll be released neatly with its reference count being decreased.
  29950. @param imageToUse the image to render
  29951. @param releaseWhenNotNeeded if false, a simple pointer is kept to the image; if true,
  29952. then the image will be deleted when this object no longer
  29953. needs it - unless the image was created by the ImageCache,
  29954. in which case it will be released with ImageCache::release().
  29955. */
  29956. void setImage (Image* imageToUse,
  29957. const bool releaseWhenNotNeeded);
  29958. /** Returns the current image. */
  29959. Image* getImage() const throw() { return image; }
  29960. /** Clears (and possibly deletes) the currently set image. */
  29961. void clearImage();
  29962. /** Sets the opacity to use when drawing the image. */
  29963. void setOpacity (const float newOpacity);
  29964. /** Returns the image's opacity. */
  29965. float getOpacity() const throw() { return opacity; }
  29966. /** Sets a colour to draw over the image's alpha channel.
  29967. By default this is transparent so isn't drawn, but if you set a non-transparent
  29968. colour here, then it will be overlaid on the image, using the image's alpha
  29969. channel as a mask.
  29970. This is handy for doing things like darkening or lightening an image by overlaying
  29971. it with semi-transparent black or white.
  29972. */
  29973. void setOverlayColour (const Colour& newOverlayColour);
  29974. /** Returns the overlay colour. */
  29975. const Colour& getOverlayColour() const throw() { return overlayColour; }
  29976. /** @internal */
  29977. void draw (Graphics& g, const AffineTransform& transform) const;
  29978. /** @internal */
  29979. void getBounds (float& x, float& y, float& width, float& height) const;
  29980. /** @internal */
  29981. bool hitTest (float x, float y) const;
  29982. /** @internal */
  29983. Drawable* createCopy() const;
  29984. juce_UseDebuggingNewOperator
  29985. private:
  29986. Image* image;
  29987. bool canDeleteImage;
  29988. float opacity;
  29989. Colour overlayColour;
  29990. DrawableImage (const DrawableImage&);
  29991. const DrawableImage& operator= (const DrawableImage&);
  29992. };
  29993. #endif // __JUCE_DRAWABLEIMAGE_JUCEHEADER__
  29994. /********* End of inlined file: juce_DrawableImage.h *********/
  29995. #endif
  29996. #ifndef __JUCE_DRAWABLEPATH_JUCEHEADER__
  29997. /********* Start of inlined file: juce_DrawablePath.h *********/
  29998. #ifndef __JUCE_DRAWABLEPATH_JUCEHEADER__
  29999. #define __JUCE_DRAWABLEPATH_JUCEHEADER__
  30000. /**
  30001. A drawable object which renders a filled or outlined shape.
  30002. @see Drawable
  30003. */
  30004. class JUCE_API DrawablePath : public Drawable
  30005. {
  30006. public:
  30007. /** Creates a DrawablePath.
  30008. */
  30009. DrawablePath();
  30010. /** Destructor. */
  30011. virtual ~DrawablePath();
  30012. /** Changes the path that will be drawn.
  30013. @see setSolidFill, setOutline
  30014. */
  30015. void setPath (const Path& newPath);
  30016. /** Returns the current path. */
  30017. const Path& getPath() const throw() { return path; }
  30018. /** Sets a colour to fill the path with.
  30019. This colour is used to fill the path - if you don't want the path to be
  30020. filled (e.g. if you're just drawing an outline), set this colour to be
  30021. transparent.
  30022. @see setPath, setOutline
  30023. */
  30024. void setSolidFill (const Colour& newColour);
  30025. /** Sets a custom brush to use to fill the path.
  30026. @see setSolidFill
  30027. */
  30028. void setFillBrush (const Brush& newBrush);
  30029. /** Returns the brush currently being used to fill the shape. */
  30030. Brush* getCurrentBrush() const throw() { return fillBrush; }
  30031. /** Changes the properties of the outline that will be drawn around the path.
  30032. If the thickness value is 0, no outline will be drawn. If one is drawn, the
  30033. colour passed-in here will be used for it.
  30034. @see setPath, setSolidFill
  30035. */
  30036. void setOutline (const float thickness,
  30037. const Colour& outlineColour);
  30038. /** Changes the properties of the outline that will be drawn around the path.
  30039. If the stroke type has 0 thickness, no outline will be drawn.
  30040. @see setPath, setSolidFill
  30041. */
  30042. void setOutline (const PathStrokeType& strokeType,
  30043. const Brush& strokeBrush);
  30044. /** Returns the current outline style. */
  30045. const PathStrokeType& getOutlineStroke() const throw() { return strokeType; }
  30046. /** Returns the brush currently being used to draw the outline. */
  30047. Brush* getOutlineBrush() const throw() { return strokeBrush; }
  30048. /** @internal */
  30049. void draw (Graphics& g, const AffineTransform& transform) const;
  30050. /** @internal */
  30051. void getBounds (float& x, float& y, float& width, float& height) const;
  30052. /** @internal */
  30053. bool hitTest (float x, float y) const;
  30054. /** @internal */
  30055. Drawable* createCopy() const;
  30056. juce_UseDebuggingNewOperator
  30057. private:
  30058. Path path, outline;
  30059. Brush* fillBrush;
  30060. Brush* strokeBrush;
  30061. PathStrokeType strokeType;
  30062. void updateOutline();
  30063. DrawablePath (const DrawablePath&);
  30064. const DrawablePath& operator= (const DrawablePath&);
  30065. };
  30066. #endif // __JUCE_DRAWABLEPATH_JUCEHEADER__
  30067. /********* End of inlined file: juce_DrawablePath.h *********/
  30068. #endif
  30069. #ifndef __JUCE_DRAWABLETEXT_JUCEHEADER__
  30070. /********* Start of inlined file: juce_DrawableText.h *********/
  30071. #ifndef __JUCE_DRAWABLETEXT_JUCEHEADER__
  30072. #define __JUCE_DRAWABLETEXT_JUCEHEADER__
  30073. /**
  30074. A drawable object which renders a line of text.
  30075. @see Drawable
  30076. */
  30077. class JUCE_API DrawableText : public Drawable
  30078. {
  30079. public:
  30080. /** Creates a DrawableText object. */
  30081. DrawableText();
  30082. /** Destructor. */
  30083. virtual ~DrawableText();
  30084. /** Sets the block of text to render */
  30085. void setText (const GlyphArrangement& newText);
  30086. /** Sets a single line of text to render.
  30087. This is a convenient method of adding a single line - for
  30088. more complex text, use the setText() that takes a
  30089. GlyphArrangement instead.
  30090. */
  30091. void setText (const String& newText, const Font& fontToUse);
  30092. /** Returns the text arrangement that was set with setText(). */
  30093. const GlyphArrangement& getText() const throw() { return text; }
  30094. /** Sets the colour of the text. */
  30095. void setColour (const Colour& newColour);
  30096. /** Returns the current text colour. */
  30097. const Colour& getColour() const throw() { return colour; }
  30098. /** @internal */
  30099. void draw (Graphics& g, const AffineTransform& transform) const;
  30100. /** @internal */
  30101. void getBounds (float& x, float& y, float& width, float& height) const;
  30102. /** @internal */
  30103. bool hitTest (float x, float y) const;
  30104. /** @internal */
  30105. Drawable* createCopy() const;
  30106. juce_UseDebuggingNewOperator
  30107. private:
  30108. GlyphArrangement text;
  30109. Colour colour;
  30110. DrawableText (const DrawableText&);
  30111. const DrawableText& operator= (const DrawableText&);
  30112. };
  30113. #endif // __JUCE_DRAWABLETEXT_JUCEHEADER__
  30114. /********* End of inlined file: juce_DrawableText.h *********/
  30115. #endif
  30116. #ifndef __JUCE_COMPONENT_JUCEHEADER__
  30117. #endif
  30118. #ifndef __JUCE_COMPONENTDELETIONWATCHER_JUCEHEADER__
  30119. #endif
  30120. #ifndef __JUCE_COMPONENTLISTENER_JUCEHEADER__
  30121. #endif
  30122. #ifndef __JUCE_DESKTOP_JUCEHEADER__
  30123. #endif
  30124. #ifndef __JUCE_ARROWBUTTON_JUCEHEADER__
  30125. /********* Start of inlined file: juce_ArrowButton.h *********/
  30126. #ifndef __JUCE_ARROWBUTTON_JUCEHEADER__
  30127. #define __JUCE_ARROWBUTTON_JUCEHEADER__
  30128. /********* Start of inlined file: juce_DropShadowEffect.h *********/
  30129. #ifndef __JUCE_DROPSHADOWEFFECT_JUCEHEADER__
  30130. #define __JUCE_DROPSHADOWEFFECT_JUCEHEADER__
  30131. /**
  30132. An effect filter that adds a drop-shadow behind the image's content.
  30133. (This will only work on images/components that aren't opaque, of course).
  30134. When added to a component, this effect will draw a soft-edged
  30135. shadow based on what gets drawn inside it. The shadow will also
  30136. be applied to the component's children.
  30137. For speed, this doesn't use a proper gaussian blur, but cheats by
  30138. using a simple bilinear filter. If you need a really high-quality
  30139. shadow, check out ImageConvolutionKernel::createGaussianBlur()
  30140. @see Component::setComponentEffect
  30141. */
  30142. class JUCE_API DropShadowEffect : public ImageEffectFilter
  30143. {
  30144. public:
  30145. /** Creates a default drop-shadow effect.
  30146. To customise the shadow's appearance, use the setShadowProperties()
  30147. method.
  30148. */
  30149. DropShadowEffect();
  30150. /** Destructor. */
  30151. ~DropShadowEffect();
  30152. /** Sets up parameters affecting the shadow's appearance.
  30153. @param newRadius the (approximate) radius of the blur used
  30154. @param newOpacity the opacity with which the shadow is rendered
  30155. @param newShadowOffsetX allows the shadow to be shifted in relation to the
  30156. component's contents
  30157. @param newShadowOffsetY allows the shadow to be shifted in relation to the
  30158. component's contents
  30159. */
  30160. void setShadowProperties (const float newRadius,
  30161. const float newOpacity,
  30162. const int newShadowOffsetX,
  30163. const int newShadowOffsetY);
  30164. /** @internal */
  30165. void applyEffect (Image& sourceImage, Graphics& destContext);
  30166. juce_UseDebuggingNewOperator
  30167. private:
  30168. int offsetX, offsetY;
  30169. float radius, opacity;
  30170. };
  30171. #endif // __JUCE_DROPSHADOWEFFECT_JUCEHEADER__
  30172. /********* End of inlined file: juce_DropShadowEffect.h *********/
  30173. /**
  30174. A button with an arrow in it.
  30175. @see Button
  30176. */
  30177. class JUCE_API ArrowButton : public Button
  30178. {
  30179. public:
  30180. /** Creates an ArrowButton.
  30181. @param buttonName the name to give the button
  30182. @param arrowDirection the direction the arrow should point in, where 0.0 is
  30183. pointing right, 0.25 is down, 0.5 is left, 0.75 is up
  30184. @param arrowColour the colour to use for the arrow
  30185. */
  30186. ArrowButton (const String& buttonName,
  30187. float arrowDirection,
  30188. const Colour& arrowColour);
  30189. /** Destructor. */
  30190. ~ArrowButton();
  30191. juce_UseDebuggingNewOperator
  30192. protected:
  30193. /** @internal */
  30194. void paintButton (Graphics& g,
  30195. bool isMouseOverButton,
  30196. bool isButtonDown);
  30197. /** @internal */
  30198. void buttonStateChanged();
  30199. private:
  30200. Colour colour;
  30201. DropShadowEffect shadow;
  30202. Path path;
  30203. int offset;
  30204. ArrowButton (const ArrowButton&);
  30205. const ArrowButton& operator= (const ArrowButton&);
  30206. };
  30207. #endif // __JUCE_ARROWBUTTON_JUCEHEADER__
  30208. /********* End of inlined file: juce_ArrowButton.h *********/
  30209. #endif
  30210. #ifndef __JUCE_BUTTON_JUCEHEADER__
  30211. #endif
  30212. #ifndef __JUCE_DRAWABLEBUTTON_JUCEHEADER__
  30213. /********* Start of inlined file: juce_DrawableButton.h *********/
  30214. #ifndef __JUCE_DRAWABLEBUTTON_JUCEHEADER__
  30215. #define __JUCE_DRAWABLEBUTTON_JUCEHEADER__
  30216. /**
  30217. A button that displays a Drawable.
  30218. Up to three Drawable objects can be given to this button, to represent the
  30219. 'normal', 'over' and 'down' states.
  30220. @see Button
  30221. */
  30222. class JUCE_API DrawableButton : public Button
  30223. {
  30224. public:
  30225. enum ButtonStyle
  30226. {
  30227. ImageFitted, /**< The button will just display the images, but will resize and centre them to fit inside it. */
  30228. ImageRaw, /**< The button will just display the images in their normal size and position.
  30229. This leaves it up to the caller to make sure the images are the correct size and position for the button. */
  30230. ImageAboveTextLabel, /**< Draws the button as a text label across the bottom with the image resized and scaled to fit above it. */
  30231. ImageOnButtonBackground /**< Draws the button as a standard rounded-rectangle button with the image on top. */
  30232. };
  30233. /** Creates a DrawableButton.
  30234. After creating one of these, use setImages() to specify the drawables to use.
  30235. @param buttonName the name to give the component
  30236. @param buttonStyle the layout to use
  30237. @see ButtonStyle, setButtonStyle, setImages
  30238. */
  30239. DrawableButton (const String& buttonName,
  30240. const ButtonStyle buttonStyle);
  30241. /** Destructor. */
  30242. ~DrawableButton();
  30243. /** Sets up the images to draw for the various button states.
  30244. The button will keep its own internal copies of these drawables.
  30245. @param normalImage the thing to draw for the button's 'normal' state. An internal copy
  30246. will be made of the object passed-in if it is non-zero.
  30247. @param overImage the thing to draw for the button's 'over' state - if this is
  30248. zero, the button's normal image will be used when the mouse is
  30249. over it. An internal copy will be made of the object passed-in
  30250. if it is non-zero.
  30251. @param downImage the thing to draw for the button's 'down' state - if this is
  30252. zero, the 'over' image will be used instead (or the normal image
  30253. as a last resort). An internal copy will be made of the object
  30254. passed-in if it is non-zero.
  30255. @param disabledImage an image to draw when the button is disabled. If this is zero,
  30256. the normal image will be drawn with a reduced opacity instead.
  30257. An internal copy will be made of the object passed-in if it is
  30258. non-zero.
  30259. @param normalImageOn same as the normalImage, but this is used when the button's toggle
  30260. state is 'on'. If this is 0, the normal image is used instead
  30261. @param overImageOn same as the overImage, but this is used when the button's toggle
  30262. state is 'on'. If this is 0, the normalImageOn is drawn instead
  30263. @param downImageOn same as the downImage, but this is used when the button's toggle
  30264. state is 'on'. If this is 0, the overImageOn is drawn instead
  30265. @param disabledImageOn same as the disabledImage, but this is used when the button's toggle
  30266. state is 'on'. If this is 0, the normal image will be drawn instead
  30267. with a reduced opacity
  30268. */
  30269. void setImages (const Drawable* normalImage,
  30270. const Drawable* overImage = 0,
  30271. const Drawable* downImage = 0,
  30272. const Drawable* disabledImage = 0,
  30273. const Drawable* normalImageOn = 0,
  30274. const Drawable* overImageOn = 0,
  30275. const Drawable* downImageOn = 0,
  30276. const Drawable* disabledImageOn = 0);
  30277. /** Changes the button's style.
  30278. @see ButtonStyle
  30279. */
  30280. void setButtonStyle (const ButtonStyle newStyle);
  30281. /** Changes the button's background colours.
  30282. The toggledOffColour is the colour to use when the button's toggle state
  30283. is off, and toggledOnColour when it's on.
  30284. For an ImageOnly or ImageAboveTextLabel style, the background colour is
  30285. used to fill the background of the component.
  30286. For an ImageOnButtonBackground style, the colour is used to draw the
  30287. button's lozenge shape and exactly how the colour's used will depend
  30288. on the LookAndFeel.
  30289. */
  30290. void setBackgroundColours (const Colour& toggledOffColour,
  30291. const Colour& toggledOnColour);
  30292. /** Returns the current background colour being used.
  30293. @see setBackgroundColour
  30294. */
  30295. const Colour& getBackgroundColour() const throw();
  30296. /** Gives the button an optional amount of space around the edge of the drawable.
  30297. This will only apply to ImageFitted or ImageRaw styles, it won't affect the
  30298. ones on a button background. If the button is too small for the given gap, a
  30299. smaller gap will be used.
  30300. By default there's a gap of about 3 pixels.
  30301. */
  30302. void setEdgeIndent (const int numPixelsIndent);
  30303. /** Returns the image that the button is currently displaying. */
  30304. const Drawable* getCurrentImage() const throw();
  30305. const Drawable* getNormalImage() const throw();
  30306. const Drawable* getOverImage() const throw();
  30307. const Drawable* getDownImage() const throw();
  30308. juce_UseDebuggingNewOperator
  30309. protected:
  30310. /** @internal */
  30311. void paintButton (Graphics& g,
  30312. bool isMouseOverButton,
  30313. bool isButtonDown);
  30314. private:
  30315. ButtonStyle style;
  30316. Drawable* normalImage;
  30317. Drawable* overImage;
  30318. Drawable* downImage;
  30319. Drawable* disabledImage;
  30320. Drawable* normalImageOn;
  30321. Drawable* overImageOn;
  30322. Drawable* downImageOn;
  30323. Drawable* disabledImageOn;
  30324. Colour backgroundOff, backgroundOn;
  30325. int edgeIndent;
  30326. void deleteImages();
  30327. DrawableButton (const DrawableButton&);
  30328. const DrawableButton& operator= (const DrawableButton&);
  30329. };
  30330. #endif // __JUCE_DRAWABLEBUTTON_JUCEHEADER__
  30331. /********* End of inlined file: juce_DrawableButton.h *********/
  30332. #endif
  30333. #ifndef __JUCE_HYPERLINKBUTTON_JUCEHEADER__
  30334. /********* Start of inlined file: juce_HyperlinkButton.h *********/
  30335. #ifndef __JUCE_HYPERLINKBUTTON_JUCEHEADER__
  30336. #define __JUCE_HYPERLINKBUTTON_JUCEHEADER__
  30337. /**
  30338. A button showing an underlined weblink, that will launch the link
  30339. when it's clicked.
  30340. @see Button
  30341. */
  30342. class JUCE_API HyperlinkButton : public Button
  30343. {
  30344. public:
  30345. /** Creates a HyperlinkButton.
  30346. @param linkText the text that will be displayed in the button - this is
  30347. also set as the Component's name, but the text can be
  30348. changed later with the Button::getButtonText() method
  30349. @param linkURL the URL to launch when the user clicks the button
  30350. */
  30351. HyperlinkButton (const String& linkText,
  30352. const URL& linkURL);
  30353. /** Destructor. */
  30354. ~HyperlinkButton();
  30355. /** Changes the font to use for the text.
  30356. If resizeToMatchComponentHeight is true, the font's height will be adjusted
  30357. to match the size of the component.
  30358. */
  30359. void setFont (const Font& newFont,
  30360. const bool resizeToMatchComponentHeight,
  30361. const Justification& justificationType = Justification::horizontallyCentred);
  30362. /** A set of colour IDs to use to change the colour of various aspects of the link.
  30363. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  30364. methods.
  30365. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  30366. */
  30367. enum ColourIds
  30368. {
  30369. textColourId = 0x1001f00, /**< The colour to use for the URL text. */
  30370. };
  30371. /** Changes the URL that the button will trigger. */
  30372. void setURL (const URL& newURL) throw();
  30373. /** Returns the URL that the button will trigger. */
  30374. const URL& getURL() const throw() { return url; }
  30375. /** Resizes the button horizontally to fit snugly around the text.
  30376. This won't affect the button's height.
  30377. */
  30378. void changeWidthToFitText();
  30379. juce_UseDebuggingNewOperator
  30380. protected:
  30381. /** @internal */
  30382. void clicked();
  30383. /** @internal */
  30384. void colourChanged();
  30385. /** @internal */
  30386. void paintButton (Graphics& g,
  30387. bool isMouseOverButton,
  30388. bool isButtonDown);
  30389. private:
  30390. URL url;
  30391. Font font;
  30392. bool resizeFont;
  30393. Justification justification;
  30394. const Font getFontToUse() const;
  30395. HyperlinkButton (const HyperlinkButton&);
  30396. const HyperlinkButton& operator= (const HyperlinkButton&);
  30397. };
  30398. #endif // __JUCE_HYPERLINKBUTTON_JUCEHEADER__
  30399. /********* End of inlined file: juce_HyperlinkButton.h *********/
  30400. #endif
  30401. #ifndef __JUCE_IMAGEBUTTON_JUCEHEADER__
  30402. /********* Start of inlined file: juce_ImageButton.h *********/
  30403. #ifndef __JUCE_IMAGEBUTTON_JUCEHEADER__
  30404. #define __JUCE_IMAGEBUTTON_JUCEHEADER__
  30405. /**
  30406. As the title suggests, this is a button containing an image.
  30407. The colour and transparency of the image can be set to vary when the
  30408. button state changes.
  30409. @see Button, ShapeButton, TextButton
  30410. */
  30411. class JUCE_API ImageButton : public Button
  30412. {
  30413. public:
  30414. /** Creates an ImageButton.
  30415. Use setImage() to specify the image to use. The colours and opacities that
  30416. are specified here can be changed later using setDrawingOptions().
  30417. @param name the name to give the component
  30418. */
  30419. ImageButton (const String& name);
  30420. /** Destructor. */
  30421. ~ImageButton();
  30422. /** Sets up the images to draw in various states.
  30423. Important! Bear in mind that if you pass the same image in for more than one of
  30424. these parameters, this button will delete it (or release from the ImageCache)
  30425. multiple times!
  30426. @param resizeButtonNowToFitThisImage if true, the button will be immediately
  30427. resized to the same dimensions as the normal image
  30428. @param rescaleImagesWhenButtonSizeChanges if true, the image will be rescaled to fit the
  30429. button when the button's size changes
  30430. @param preserveImageProportions if true then any rescaling of the image to fit
  30431. the button will keep the image's x and y proportions
  30432. correct - i.e. it won't distort its shape, although
  30433. this might create gaps around the edges
  30434. @param normalImage the image to use when the button is in its normal state. The
  30435. image passed in will be deleted (or released if it
  30436. was created by the ImageCache class) when the
  30437. button no longer needs it.
  30438. @param imageOpacityWhenNormal the opacity to use when drawing the normal image.
  30439. @param overlayColourWhenNormal an overlay colour to use to fill the alpha channel of the
  30440. normal image - if this colour is transparent, no overlay
  30441. will be drawn. The overlay will be drawn over the top of the
  30442. image, so you can basically add a solid or semi-transparent
  30443. colour to the image to brighten or darken it
  30444. @param overImage the image to use when the mouse is over the button. If
  30445. you want to use the same image as was set in the normalImage
  30446. parameter, this value can be 0. As for normalImage, it
  30447. will be deleted or released by the button when no longer
  30448. needed
  30449. @param imageOpacityWhenOver the opacity to use when drawing the image when the mouse
  30450. is over the button
  30451. @param overlayColourWhenOver an overlay colour to use to fill the alpha channel of the
  30452. image when the mouse is over - if this colour is transparent,
  30453. no overlay will be drawn
  30454. @param downImage an image to use when the button is pressed down. If set
  30455. to zero, the 'over' image will be drawn instead (or the
  30456. normal image if there isn't an 'over' image either). This
  30457. image will be deleted or released by the button when no
  30458. longer needed
  30459. @param imageOpacityWhenDown the opacity to use when drawing the image when the button
  30460. is pressed
  30461. @param overlayColourWhenDown an overlay colour to use to fill the alpha channel of the
  30462. image when the button is pressed down - if this colour is
  30463. transparent, no overlay will be drawn
  30464. @param hitTestAlphaThreshold if set to zero, the mouse is considered to be over the button
  30465. whenever it's inside the button's bounding rectangle. If
  30466. set to values higher than 0, the mouse will only be
  30467. considered to be over the image when the value of the
  30468. image's alpha channel at that position is greater than
  30469. this level.
  30470. */
  30471. void setImages (const bool resizeButtonNowToFitThisImage,
  30472. const bool rescaleImagesWhenButtonSizeChanges,
  30473. const bool preserveImageProportions,
  30474. Image* const normalImage,
  30475. const float imageOpacityWhenNormal,
  30476. const Colour& overlayColourWhenNormal,
  30477. Image* const overImage,
  30478. const float imageOpacityWhenOver,
  30479. const Colour& overlayColourWhenOver,
  30480. Image* const downImage,
  30481. const float imageOpacityWhenDown,
  30482. const Colour& overlayColourWhenDown,
  30483. const float hitTestAlphaThreshold = 0.0f);
  30484. /** Returns the currently set 'normal' image. */
  30485. Image* getNormalImage() const throw();
  30486. /** Returns the image that's drawn when the mouse is over the button.
  30487. If an 'over' image has been set, this will return it; otherwise it'll
  30488. just return the normal image.
  30489. */
  30490. Image* getOverImage() const throw();
  30491. /** Returns the image that's drawn when the button is held down.
  30492. If a 'down' image has been set, this will return it; otherwise it'll
  30493. return the 'over' image or normal image, depending on what's available.
  30494. */
  30495. Image* getDownImage() const throw();
  30496. juce_UseDebuggingNewOperator
  30497. protected:
  30498. /** @internal */
  30499. bool hitTest (int x, int y);
  30500. /** @internal */
  30501. void paintButton (Graphics& g,
  30502. bool isMouseOverButton,
  30503. bool isButtonDown);
  30504. private:
  30505. bool scaleImageToFit, preserveProportions;
  30506. unsigned char alphaThreshold;
  30507. int imageX, imageY, imageW, imageH;
  30508. Image* normalImage;
  30509. Image* overImage;
  30510. Image* downImage;
  30511. float normalOpacity, overOpacity, downOpacity;
  30512. Colour normalOverlay, overOverlay, downOverlay;
  30513. Image* getCurrentImage() const;
  30514. void deleteImages();
  30515. ImageButton (const ImageButton&);
  30516. const ImageButton& operator= (const ImageButton&);
  30517. };
  30518. #endif // __JUCE_IMAGEBUTTON_JUCEHEADER__
  30519. /********* End of inlined file: juce_ImageButton.h *********/
  30520. #endif
  30521. #ifndef __JUCE_SHAPEBUTTON_JUCEHEADER__
  30522. /********* Start of inlined file: juce_ShapeButton.h *********/
  30523. #ifndef __JUCE_SHAPEBUTTON_JUCEHEADER__
  30524. #define __JUCE_SHAPEBUTTON_JUCEHEADER__
  30525. /**
  30526. A button that contains a filled shape.
  30527. @see Button, ImageButton, TextButton, ArrowButton
  30528. */
  30529. class JUCE_API ShapeButton : public Button
  30530. {
  30531. public:
  30532. /** Creates a ShapeButton.
  30533. @param name a name to give the component - see Component::setName()
  30534. @param normalColour the colour to fill the shape with when the mouse isn't over
  30535. @param overColour the colour to use when the mouse is over the shape
  30536. @param downColour the colour to use when the button is in the pressed-down state
  30537. */
  30538. ShapeButton (const String& name,
  30539. const Colour& normalColour,
  30540. const Colour& overColour,
  30541. const Colour& downColour);
  30542. /** Destructor. */
  30543. ~ShapeButton();
  30544. /** Sets the shape to use.
  30545. @param newShape the shape to use
  30546. @param resizeNowToFitThisShape if true, the button will be resized to fit the shape's bounds
  30547. @param maintainShapeProportions if true, the shape's proportions will be kept fixed when
  30548. the button is resized
  30549. @param hasDropShadow if true, the button will be given a drop-shadow effect
  30550. */
  30551. void setShape (const Path& newShape,
  30552. const bool resizeNowToFitThisShape,
  30553. const bool maintainShapeProportions,
  30554. const bool hasDropShadow);
  30555. /** Set the colours to use for drawing the shape.
  30556. @param normalColour the colour to fill the shape with when the mouse isn't over
  30557. @param overColour the colour to use when the mouse is over the shape
  30558. @param downColour the colour to use when the button is in the pressed-down state
  30559. */
  30560. void setColours (const Colour& normalColour,
  30561. const Colour& overColour,
  30562. const Colour& downColour);
  30563. /** Sets up an outline to draw around the shape.
  30564. @param outlineColour the colour to use
  30565. @param outlineStrokeWidth the thickness of line to draw
  30566. */
  30567. void setOutline (const Colour& outlineColour,
  30568. const float outlineStrokeWidth);
  30569. juce_UseDebuggingNewOperator
  30570. protected:
  30571. /** @internal */
  30572. void paintButton (Graphics& g,
  30573. bool isMouseOverButton,
  30574. bool isButtonDown);
  30575. private:
  30576. Colour normalColour, overColour, downColour, outlineColour;
  30577. DropShadowEffect shadow;
  30578. Path shape;
  30579. bool maintainShapeProportions;
  30580. float outlineWidth;
  30581. ShapeButton (const ShapeButton&);
  30582. const ShapeButton& operator= (const ShapeButton&);
  30583. };
  30584. #endif // __JUCE_SHAPEBUTTON_JUCEHEADER__
  30585. /********* End of inlined file: juce_ShapeButton.h *********/
  30586. #endif
  30587. #ifndef __JUCE_TEXTBUTTON_JUCEHEADER__
  30588. #endif
  30589. #ifndef __JUCE_TOGGLEBUTTON_JUCEHEADER__
  30590. /********* Start of inlined file: juce_ToggleButton.h *********/
  30591. #ifndef __JUCE_TOGGLEBUTTON_JUCEHEADER__
  30592. #define __JUCE_TOGGLEBUTTON_JUCEHEADER__
  30593. /**
  30594. A button that can be toggled on/off.
  30595. All buttons can be toggle buttons, but this lets you create one of the
  30596. standard ones which has a tick-box and a text label next to it.
  30597. @see Button, DrawableButton, TextButton
  30598. */
  30599. class JUCE_API ToggleButton : public Button
  30600. {
  30601. public:
  30602. /** Creates a ToggleButton.
  30603. @param buttonText the text to put in the button (the component's name is also
  30604. initially set to this string, but these can be changed later
  30605. using the setName() and setButtonText() methods)
  30606. */
  30607. ToggleButton (const String& buttonText);
  30608. /** Destructor. */
  30609. ~ToggleButton();
  30610. /** Resizes the button to fit neatly around its current text.
  30611. The button's height won't be affected, only its width.
  30612. */
  30613. void changeWidthToFitText();
  30614. /** A set of colour IDs to use to change the colour of various aspects of the button.
  30615. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  30616. methods.
  30617. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  30618. */
  30619. enum ColourIds
  30620. {
  30621. textColourId = 0x1006501 /**< The colour to use for the button's text. */
  30622. };
  30623. juce_UseDebuggingNewOperator
  30624. protected:
  30625. /** @internal */
  30626. void paintButton (Graphics& g,
  30627. bool isMouseOverButton,
  30628. bool isButtonDown);
  30629. /** @internal */
  30630. void colourChanged();
  30631. private:
  30632. ToggleButton (const ToggleButton&);
  30633. const ToggleButton& operator= (const ToggleButton&);
  30634. };
  30635. #endif // __JUCE_TOGGLEBUTTON_JUCEHEADER__
  30636. /********* End of inlined file: juce_ToggleButton.h *********/
  30637. #endif
  30638. #ifndef __JUCE_TOOLBARBUTTON_JUCEHEADER__
  30639. /********* Start of inlined file: juce_ToolbarButton.h *********/
  30640. #ifndef __JUCE_TOOLBARBUTTON_JUCEHEADER__
  30641. #define __JUCE_TOOLBARBUTTON_JUCEHEADER__
  30642. /********* Start of inlined file: juce_ToolbarItemComponent.h *********/
  30643. #ifndef __JUCE_TOOLBARITEMCOMPONENT_JUCEHEADER__
  30644. #define __JUCE_TOOLBARITEMCOMPONENT_JUCEHEADER__
  30645. /********* Start of inlined file: juce_Toolbar.h *********/
  30646. #ifndef __JUCE_TOOLBAR_JUCEHEADER__
  30647. #define __JUCE_TOOLBAR_JUCEHEADER__
  30648. /********* Start of inlined file: juce_DragAndDropContainer.h *********/
  30649. #ifndef __JUCE_DRAGANDDROPCONTAINER_JUCEHEADER__
  30650. #define __JUCE_DRAGANDDROPCONTAINER_JUCEHEADER__
  30651. /********* Start of inlined file: juce_DragAndDropTarget.h *********/
  30652. #ifndef __JUCE_DRAGANDDROPTARGET_JUCEHEADER__
  30653. #define __JUCE_DRAGANDDROPTARGET_JUCEHEADER__
  30654. /**
  30655. Components derived from this class can have things dropped onto them by a DragAndDropContainer.
  30656. To create a component that can receive things drag-and-dropped by a DragAndDropContainer,
  30657. derive your component from this class, and make sure that it is somewhere inside a
  30658. DragAndDropContainer component.
  30659. Note: If all that you need to do is to respond to files being drag-and-dropped from
  30660. the operating system onto your component, you don't need any of these classes: instead
  30661. see the FileDragAndDropTarget class.
  30662. @see DragAndDropContainer, FileDragAndDropTarget
  30663. */
  30664. class JUCE_API DragAndDropTarget
  30665. {
  30666. public:
  30667. /** Destructor. */
  30668. virtual ~DragAndDropTarget() {}
  30669. /** Callback to check whether this target is interested in the type of object being
  30670. dragged.
  30671. @param sourceDescription the description string passed into DragAndDropContainer::startDragging()
  30672. @param sourceComponent the component that was passed into DragAndDropContainer::startDragging()
  30673. @returns true if this component wants to receive the other callbacks regarging this
  30674. type of object; if it returns false, no other callbacks will be made.
  30675. */
  30676. virtual bool isInterestedInDragSource (const String& sourceDescription,
  30677. Component* sourceComponent) = 0;
  30678. /** Callback to indicate that something is being dragged over this component.
  30679. This gets called when the user moves the mouse into this component while dragging
  30680. something.
  30681. Use this callback as a trigger to make your component repaint itself to give the
  30682. user feedback about whether the item can be dropped here or not.
  30683. @param sourceDescription the description string passed into DragAndDropContainer::startDragging()
  30684. @param sourceComponent the component that was passed into DragAndDropContainer::startDragging()
  30685. @param x the mouse x position, relative to this component
  30686. @param y the mouse y position, relative to this component
  30687. @see itemDragExit
  30688. */
  30689. virtual void itemDragEnter (const String& sourceDescription,
  30690. Component* sourceComponent,
  30691. int x,
  30692. int y);
  30693. /** Callback to indicate that the user is dragging something over this component.
  30694. This gets called when the user moves the mouse over this component while dragging
  30695. something. Normally overriding itemDragEnter() and itemDragExit() are enough, but
  30696. this lets you know what happens in-between.
  30697. @param sourceDescription the description string passed into DragAndDropContainer::startDragging()
  30698. @param sourceComponent the component that was passed into DragAndDropContainer::startDragging()
  30699. @param x the mouse x position, relative to this component
  30700. @param y the mouse y position, relative to this component
  30701. */
  30702. virtual void itemDragMove (const String& sourceDescription,
  30703. Component* sourceComponent,
  30704. int x,
  30705. int y);
  30706. /** Callback to indicate that something has been dragged off the edge of this component.
  30707. This gets called when the user moves the mouse out of this component while dragging
  30708. something.
  30709. If you've used itemDragEnter() to repaint your component and give feedback, use this
  30710. as a signal to repaint it in its normal state.
  30711. @param sourceDescription the description string passed into DragAndDropContainer::startDragging()
  30712. @param sourceComponent the component that was passed into DragAndDropContainer::startDragging()
  30713. @see itemDragEnter
  30714. */
  30715. virtual void itemDragExit (const String& sourceDescription,
  30716. Component* sourceComponent);
  30717. /** Callback to indicate that the user has dropped something onto this component.
  30718. When the user drops an item this get called, and you can use the description to
  30719. work out whether your object wants to deal with it or not.
  30720. Note that after this is called, the itemDragExit method may not be called, so you should
  30721. clean up in here if there's anything you need to do when the drag finishes.
  30722. @param sourceDescription the description string passed into DragAndDropContainer::startDragging()
  30723. @param sourceComponent the component that was passed into DragAndDropContainer::startDragging()
  30724. @param x the mouse x position, relative to this component
  30725. @param y the mouse y position, relative to this component
  30726. */
  30727. virtual void itemDropped (const String& sourceDescription,
  30728. Component* sourceComponent,
  30729. int x,
  30730. int y) = 0;
  30731. /** Overriding this allows the target to tell the drag container whether to
  30732. draw the drag image while the cursor is over it.
  30733. By default it returns true, but if you return false, then the normal drag
  30734. image will not be shown when the cursor is over this target.
  30735. */
  30736. virtual bool shouldDrawDragImageWhenOver();
  30737. };
  30738. #endif // __JUCE_DRAGANDDROPTARGET_JUCEHEADER__
  30739. /********* End of inlined file: juce_DragAndDropTarget.h *********/
  30740. /**
  30741. Enables drag-and-drop behaviour for a component and all its sub-components.
  30742. For a component to be able to make or receive drag-and-drop events, one of its parent
  30743. components must derive from this class. It's probably best for the top-level
  30744. component to implement it.
  30745. Then to start a drag operation, any sub-component can just call the startDragging()
  30746. method, and this object will take over, tracking the mouse and sending appropriate
  30747. callbacks to any child components derived from DragAndDropTarget which the mouse
  30748. moves over.
  30749. Note: If all that you need to do is to respond to files being drag-and-dropped from
  30750. the operating system onto your component, you don't need any of these classes: you can do this
  30751. simply by overriding Component::filesDropped().
  30752. @see DragAndDropTarget
  30753. */
  30754. class JUCE_API DragAndDropContainer
  30755. {
  30756. public:
  30757. /** Creates a DragAndDropContainer.
  30758. The object that derives from this class must also be a Component.
  30759. */
  30760. DragAndDropContainer();
  30761. /** Destructor. */
  30762. virtual ~DragAndDropContainer();
  30763. /** Begins a drag-and-drop operation.
  30764. This starts a drag-and-drop operation - call it when the user drags the
  30765. mouse in your drag-source component, and this object will track mouse
  30766. movements until the user lets go of the mouse button, and will send
  30767. appropriate messages to DragAndDropTarget objects that the mouse moves
  30768. over.
  30769. findParentDragContainerFor() is a handy method to call to find the
  30770. drag container to use for a component.
  30771. @param sourceDescription a string to use as the description of the thing being
  30772. dragged - this will be passed to the objects that might be
  30773. dropped-onto so they can decide if they want to handle it or
  30774. not
  30775. @param sourceComponent the component that is being dragged
  30776. @param dragImage the image to drag around underneath the mouse. If this is
  30777. zero, a snapshot of the sourceComponent will be used instead. An
  30778. image passed-in will be deleted by this object when no longer
  30779. needed.
  30780. @param allowDraggingToOtherJuceWindows if true, the dragged component will appear as a desktop
  30781. window, and can be dragged to DragAndDropTargets that are the
  30782. children of components other than this one.
  30783. */
  30784. void startDragging (const String& sourceDescription,
  30785. Component* sourceComponent,
  30786. Image* dragImage = 0,
  30787. const bool allowDraggingToOtherJuceWindows = false);
  30788. /** Returns true if something is currently being dragged. */
  30789. bool isDragAndDropActive() const;
  30790. /** Returns the description of the thing that's currently being dragged.
  30791. If nothing's being dragged, this will return an empty string, otherwise it's the
  30792. string that was passed into startDragging().
  30793. @see startDragging
  30794. */
  30795. const String getCurrentDragDescription() const;
  30796. /** Utility to find the DragAndDropContainer for a given Component.
  30797. This will search up this component's parent hierarchy looking for the first
  30798. parent component which is a DragAndDropContainer.
  30799. It's useful when a component wants to call startDragging but doesn't know
  30800. the DragAndDropContainer it should to use.
  30801. Obviously this may return 0 if it doesn't find a suitable component.
  30802. */
  30803. static DragAndDropContainer* findParentDragContainerFor (Component* childComponent);
  30804. /** This performs a synchronous drag-and-drop of a set of files to some external
  30805. application.
  30806. You can call this function in response to a mouseDrag callback, and it will
  30807. block, running its own internal message loop and tracking the mouse, while it
  30808. uses a native operating system drag-and-drop operation to move or copy some
  30809. files to another application.
  30810. @param files a list of filenames to drag
  30811. @param canMoveFiles if true, the app that receives the files is allowed to move the files to a new location
  30812. (if this is appropriate). If false, the receiver is expected to make a copy of them.
  30813. @returns true if the files were successfully dropped somewhere, or false if it
  30814. was interrupted
  30815. @see performExternalDragDropOfText
  30816. */
  30817. static bool performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles);
  30818. /** This performs a synchronous drag-and-drop of a block of text to some external
  30819. application.
  30820. You can call this function in response to a mouseDrag callback, and it will
  30821. block, running its own internal message loop and tracking the mouse, while it
  30822. uses a native operating system drag-and-drop operation to move or copy some
  30823. text to another application.
  30824. @param text the text to copy
  30825. @returns true if the text was successfully dropped somewhere, or false if it
  30826. was interrupted
  30827. @see performExternalDragDropOfFiles
  30828. */
  30829. static bool performExternalDragDropOfText (const String& text);
  30830. juce_UseDebuggingNewOperator
  30831. protected:
  30832. /** Override this if you want to be able to perform an external drag a set of files
  30833. when the user drags outside of this container component.
  30834. This method will be called when a drag operation moves outside the Juce-based window,
  30835. and if you want it to then perform a file drag-and-drop, add the filenames you want
  30836. to the array passed in, and return true.
  30837. @param dragSourceDescription the description passed into the startDrag() call when the drag began
  30838. @param dragSourceComponent the component passed into the startDrag() call when the drag began
  30839. @param files on return, the filenames you want to drag
  30840. @param canMoveFiles on return, true if it's ok for the receiver to move the files; false if
  30841. it must make a copy of them (see the performExternalDragDropOfFiles()
  30842. method)
  30843. @see performExternalDragDropOfFiles
  30844. */
  30845. virtual bool shouldDropFilesWhenDraggedExternally (const String& dragSourceDescription,
  30846. Component* dragSourceComponent,
  30847. StringArray& files,
  30848. bool& canMoveFiles);
  30849. private:
  30850. friend class DragImageComponent;
  30851. Component* dragImageComponent;
  30852. String currentDragDesc;
  30853. };
  30854. #endif // __JUCE_DRAGANDDROPCONTAINER_JUCEHEADER__
  30855. /********* End of inlined file: juce_DragAndDropContainer.h *********/
  30856. /********* Start of inlined file: juce_ComponentAnimator.h *********/
  30857. #ifndef __JUCE_COMPONENTANIMATOR_JUCEHEADER__
  30858. #define __JUCE_COMPONENTANIMATOR_JUCEHEADER__
  30859. /**
  30860. Animates a set of components, moving it to a new position.
  30861. To use this, create a ComponentAnimator, and use its animateComponent() method
  30862. to tell it to move components to destination positions. Any number of
  30863. components can be animated by one ComponentAnimator object (if you've got a
  30864. lot of components to move, it's much more efficient to share a single animator
  30865. than to have many animators running at once).
  30866. You'll need to make sure the animator object isn't deleted before it finishes
  30867. moving the components.
  30868. */
  30869. class JUCE_API ComponentAnimator : private Timer
  30870. {
  30871. public:
  30872. /** Creates a ComponentAnimator. */
  30873. ComponentAnimator();
  30874. /** Destructor. */
  30875. ~ComponentAnimator();
  30876. /** Starts a component moving from its current position to a specified position.
  30877. If the component is already in the middle of an animation, that will be abandoned,
  30878. and a new animation will begin, moving the component from its current location.
  30879. The start and end speed parameters let you apply some acceleration to the component's
  30880. movement.
  30881. @param component the component to move
  30882. @param finalPosition the destination position and size to move it to
  30883. @param millisecondsToSpendMoving how long, in milliseconds, it should take
  30884. to arrive at its destination
  30885. @param startSpeed a value to indicate the relative start speed of the
  30886. animation. If this is 0, the component will start
  30887. by accelerating from rest; higher values mean that it
  30888. will have an initial speed greater than zero. If the
  30889. value if greater than 1, it will decelerate towards the
  30890. middle of its journey. To move the component at a constant
  30891. rate for its entire animation, set both the start and
  30892. end speeds to 1.0
  30893. @param endSpeed a relative speed at which the component should be moving
  30894. when the animation finishes. If this is 0, the component
  30895. will decelerate to a standstill at its final position; higher
  30896. values mean the component will still be moving when it stops.
  30897. To move the component at a constant rate for its entire
  30898. animation, set both the start and end speeds to 1.0
  30899. */
  30900. void animateComponent (Component* const component,
  30901. const Rectangle& finalPosition,
  30902. const int millisecondsToSpendMoving,
  30903. const double startSpeed = 1.0,
  30904. const double endSpeed = 1.0);
  30905. /** Stops a component if it's currently being animated.
  30906. If moveComponentToItsFinalPosition is true, then the component will
  30907. be immediately moved to its destination position and size. If false, it will be
  30908. left in whatever location it currently occupies.
  30909. */
  30910. void cancelAnimation (Component* const component,
  30911. const bool moveComponentToItsFinalPosition);
  30912. /** Clears all of the active animations.
  30913. If moveComponentsToTheirFinalPositions is true, all the components will
  30914. be immediately set to their final positions. If false, they will be
  30915. left in whatever locations they currently occupy.
  30916. */
  30917. void cancelAllAnimations (const bool moveComponentsToTheirFinalPositions);
  30918. /** Returns the destination position for a component.
  30919. If the component is being animated, this will return the target position that
  30920. was specified when animateComponent() was called.
  30921. If the specified component isn't currently being animated, this method will just
  30922. return its current position.
  30923. */
  30924. const Rectangle getComponentDestination (Component* const component);
  30925. juce_UseDebuggingNewOperator
  30926. private:
  30927. VoidArray tasks;
  30928. uint32 lastTime;
  30929. void* findTaskFor (Component* const component) const;
  30930. void timerCallback();
  30931. };
  30932. #endif // __JUCE_COMPONENTANIMATOR_JUCEHEADER__
  30933. /********* End of inlined file: juce_ComponentAnimator.h *********/
  30934. class ToolbarItemComponent;
  30935. class ToolbarItemFactory;
  30936. class MissingItemsComponent;
  30937. /**
  30938. A toolbar component.
  30939. A toolbar contains a horizontal or vertical strip of ToolbarItemComponents,
  30940. and looks after their order and layout.
  30941. Items (icon buttons or other custom components) are added to a toolbar using a
  30942. ToolbarItemFactory - each type of item is given a unique ID number, and a
  30943. toolbar might contain more than one instance of a particular item type.
  30944. Toolbars can be interactively customised, allowing the user to drag the items
  30945. around, and to drag items onto or off the toolbar, using the ToolbarItemPalette
  30946. component as a source of new items.
  30947. @see ToolbarItemFactory, ToolbarItemComponent, ToolbarItemPalette
  30948. */
  30949. class JUCE_API Toolbar : public Component,
  30950. public DragAndDropContainer,
  30951. public DragAndDropTarget,
  30952. private ButtonListener
  30953. {
  30954. public:
  30955. /** Creates an empty toolbar component.
  30956. To add some icons or other components to your toolbar, you'll need to
  30957. create a ToolbarItemFactory class that can create a suitable set of
  30958. ToolbarItemComponents.
  30959. @see ToolbarItemFactory, ToolbarItemComponents
  30960. */
  30961. Toolbar();
  30962. /** Destructor.
  30963. Any items on the bar will be deleted when the toolbar is deleted.
  30964. */
  30965. ~Toolbar();
  30966. /** Changes the bar's orientation.
  30967. @see isVertical
  30968. */
  30969. void setVertical (const bool shouldBeVertical);
  30970. /** Returns true if the bar is set to be vertical, or false if it's horizontal.
  30971. You can change the bar's orientation with setVertical().
  30972. */
  30973. bool isVertical() const throw() { return vertical; }
  30974. /** Returns the depth of the bar.
  30975. If the bar is horizontal, this will return its height; if it's vertical, it
  30976. will return its width.
  30977. @see getLength
  30978. */
  30979. int getThickness() const throw();
  30980. /** Returns the length of the bar.
  30981. If the bar is horizontal, this will return its width; if it's vertical, it
  30982. will return its height.
  30983. @see getThickness
  30984. */
  30985. int getLength() const throw();
  30986. /** Deletes all items from the bar.
  30987. */
  30988. void clear();
  30989. /** Adds an item to the toolbar.
  30990. The factory's ToolbarItemFactory::createItem() will be called by this method
  30991. to create the component that will actually be added to the bar.
  30992. The new item will be inserted at the specified index (if the index is -1, it
  30993. will be added to the right-hand or bottom end of the bar).
  30994. Once added, the component will be automatically deleted by this object when it
  30995. is no longer needed.
  30996. @see ToolbarItemFactory
  30997. */
  30998. void addItem (ToolbarItemFactory& factory,
  30999. const int itemId,
  31000. const int insertIndex = -1);
  31001. /** Deletes one of the items from the bar.
  31002. */
  31003. void removeToolbarItem (const int itemIndex);
  31004. /** Returns the number of items currently on the toolbar.
  31005. @see getItemId, getItemComponent
  31006. */
  31007. int getNumItems() const throw();
  31008. /** Returns the ID of the item with the given index.
  31009. If the index is less than zero or greater than the number of items,
  31010. this will return 0.
  31011. @see getNumItems
  31012. */
  31013. int getItemId (const int itemIndex) const throw();
  31014. /** Returns the component being used for the item with the given index.
  31015. If the index is less than zero or greater than the number of items,
  31016. this will return 0.
  31017. @see getNumItems
  31018. */
  31019. ToolbarItemComponent* getItemComponent (const int itemIndex) const throw();
  31020. /** Clears this toolbar and adds to it the default set of items that the specified
  31021. factory creates.
  31022. @see ToolbarItemFactory::getDefaultItemSet
  31023. */
  31024. void addDefaultItems (ToolbarItemFactory& factoryToUse);
  31025. /** Options for the way items should be displayed.
  31026. @see setStyle, getStyle
  31027. */
  31028. enum ToolbarItemStyle
  31029. {
  31030. iconsOnly, /**< Means that the toolbar should just contain icons. */
  31031. iconsWithText, /**< Means that the toolbar should have text labels under each icon. */
  31032. textOnly /**< Means that the toolbar only display text labels for each item. */
  31033. };
  31034. /** Returns the toolbar's current style.
  31035. @see ToolbarItemStyle, setStyle
  31036. */
  31037. ToolbarItemStyle getStyle() const throw() { return toolbarStyle; }
  31038. /** Changes the toolbar's current style.
  31039. @see ToolbarItemStyle, getStyle, ToolbarItemComponent::setStyle
  31040. */
  31041. void setStyle (const ToolbarItemStyle& newStyle);
  31042. /** Flags used by the showCustomisationDialog() method. */
  31043. enum CustomisationFlags
  31044. {
  31045. allowIconsOnlyChoice = 1, /**< If this flag is specified, the customisation dialog can
  31046. show the "icons only" option on its choice of toolbar styles. */
  31047. allowIconsWithTextChoice = 2, /**< If this flag is specified, the customisation dialog can
  31048. show the "icons with text" option on its choice of toolbar styles. */
  31049. allowTextOnlyChoice = 4, /**< If this flag is specified, the customisation dialog can
  31050. show the "text only" option on its choice of toolbar styles. */
  31051. showResetToDefaultsButton = 8, /**< If this flag is specified, the customisation dialog can
  31052. show a button to reset the toolbar to its default set of items. */
  31053. allCustomisationOptionsEnabled = (allowIconsOnlyChoice | allowIconsWithTextChoice | allowTextOnlyChoice | showResetToDefaultsButton)
  31054. };
  31055. /** Pops up a modal dialog box that allows this toolbar to be customised by the user.
  31056. The dialog contains a ToolbarItemPalette and various controls for editing other
  31057. aspects of the toolbar. This method will block and run the dialog box modally,
  31058. returning when the user closes it.
  31059. The factory is used to determine the set of items that will be shown on the
  31060. palette.
  31061. The optionFlags parameter is a bitwise-or of values from the CustomisationFlags
  31062. enum.
  31063. @see ToolbarItemPalette
  31064. */
  31065. void showCustomisationDialog (ToolbarItemFactory& factory,
  31066. const int optionFlags = allCustomisationOptionsEnabled);
  31067. /** Turns on or off the toolbar's editing mode, in which its items can be
  31068. rearranged by the user.
  31069. (In most cases it's easier just to use showCustomisationDialog() instead of
  31070. trying to enable editing directly).
  31071. @see ToolbarItemPalette
  31072. */
  31073. void setEditingActive (const bool editingEnabled);
  31074. /** A set of colour IDs to use to change the colour of various aspects of the toolbar.
  31075. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  31076. methods.
  31077. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  31078. */
  31079. enum ColourIds
  31080. {
  31081. backgroundColourId = 0x1003200, /**< A colour to use to fill the toolbar's background. For
  31082. more control over this, override LookAndFeel::paintToolbarBackground(). */
  31083. separatorColourId = 0x1003210, /**< A colour to use to draw the separator lines. */
  31084. buttonMouseOverBackgroundColourId = 0x1003220, /**< A colour used to paint the background of buttons when the mouse is
  31085. over them. */
  31086. buttonMouseDownBackgroundColourId = 0x1003230, /**< A colour used to paint the background of buttons when the mouse is
  31087. held down on them. */
  31088. labelTextColourId = 0x1003240, /**< A colour to use for drawing the text under buttons
  31089. when the style is set to iconsWithText or textOnly. */
  31090. editingModeOutlineColourId = 0x1003250 /**< A colour to use for an outline around buttons when
  31091. the customisation dialog is active and the mouse moves over them. */
  31092. };
  31093. /** Returns a string that represents the toolbar's current set of items.
  31094. This lets you later restore the same item layout using restoreFromString().
  31095. @see restoreFromString
  31096. */
  31097. const String toString() const;
  31098. /** Restores a set of items that was previously stored in a string by the toString()
  31099. method.
  31100. The factory object is used to create any item components that are needed.
  31101. @see toString
  31102. */
  31103. bool restoreFromString (ToolbarItemFactory& factoryToUse,
  31104. const String& savedVersion);
  31105. /** @internal */
  31106. void paint (Graphics& g);
  31107. /** @internal */
  31108. void resized();
  31109. /** @internal */
  31110. void buttonClicked (Button*);
  31111. /** @internal */
  31112. void mouseDown (const MouseEvent&);
  31113. /** @internal */
  31114. bool isInterestedInDragSource (const String&, Component*);
  31115. /** @internal */
  31116. void itemDragMove (const String&, Component*, int, int);
  31117. /** @internal */
  31118. void itemDragExit (const String&, Component*);
  31119. /** @internal */
  31120. void itemDropped (const String&, Component*, int, int);
  31121. /** @internal */
  31122. void updateAllItemPositions (const bool animate);
  31123. /** @internal */
  31124. static ToolbarItemComponent* createItem (ToolbarItemFactory&, const int itemId);
  31125. juce_UseDebuggingNewOperator
  31126. private:
  31127. Button* missingItemsButton;
  31128. bool vertical, isEditingActive;
  31129. ToolbarItemStyle toolbarStyle;
  31130. ComponentAnimator animator;
  31131. friend class MissingItemsComponent;
  31132. Array <ToolbarItemComponent*> items;
  31133. friend class ItemDragAndDropOverlayComponent;
  31134. static const tchar* const toolbarDragDescriptor;
  31135. void addItemInternal (ToolbarItemFactory& factory, const int itemId, const int insertIndex);
  31136. ToolbarItemComponent* getNextActiveComponent (int index, const int delta) const;
  31137. Toolbar (const Toolbar&);
  31138. const Toolbar& operator= (const Toolbar&);
  31139. };
  31140. #endif // __JUCE_TOOLBAR_JUCEHEADER__
  31141. /********* End of inlined file: juce_Toolbar.h *********/
  31142. class ItemDragAndDropOverlayComponent;
  31143. /**
  31144. A component that can be used as one of the items in a Toolbar.
  31145. Each of the items on a toolbar must be a component derived from ToolbarItemComponent,
  31146. and these objects are always created by a ToolbarItemFactory - see the ToolbarItemFactory
  31147. class for further info about creating them.
  31148. The ToolbarItemComponent class is actually a button, but can be used to hold non-button
  31149. components too. To do this, set the value of isBeingUsedAsAButton to false when
  31150. calling the constructor, and override contentAreaChanged(), in which you can position
  31151. any sub-components you need to add.
  31152. To add basic buttons without writing a special subclass, have a look at the
  31153. ToolbarButton class.
  31154. @see ToolbarButton, Toolbar, ToolbarItemFactory
  31155. */
  31156. class JUCE_API ToolbarItemComponent : public Button
  31157. {
  31158. public:
  31159. /** Constructor.
  31160. @param itemId the ID of the type of toolbar item which this represents
  31161. @param labelText the text to display if the toolbar's style is set to
  31162. Toolbar::iconsWithText or Toolbar::textOnly
  31163. @param isBeingUsedAsAButton set this to false if you don't want the button
  31164. to draw itself with button over/down states when the mouse
  31165. moves over it or clicks
  31166. */
  31167. ToolbarItemComponent (const int itemId,
  31168. const String& labelText,
  31169. const bool isBeingUsedAsAButton);
  31170. /** Destructor. */
  31171. ~ToolbarItemComponent();
  31172. /** Returns the item type ID that this component represents.
  31173. This value is in the constructor.
  31174. */
  31175. int getItemId() const throw() { return itemId; }
  31176. /** Returns the toolbar that contains this component, or 0 if it's not currently
  31177. inside one.
  31178. */
  31179. Toolbar* getToolbar() const;
  31180. /** Returns true if this component is currently inside a toolbar which is vertical.
  31181. @see Toolbar::isVertical
  31182. */
  31183. bool isToolbarVertical() const;
  31184. /** Returns the current style setting of this item.
  31185. Styles are listed in the Toolbar::ToolbarItemStyle enum.
  31186. @see setStyle, Toolbar::getStyle
  31187. */
  31188. Toolbar::ToolbarItemStyle getStyle() const throw() { return toolbarStyle; }
  31189. /** Changes the current style setting of this item.
  31190. Styles are listed in the Toolbar::ToolbarItemStyle enum, and are automatically updated
  31191. by the toolbar that holds this item.
  31192. @see setStyle, Toolbar::setStyle
  31193. */
  31194. virtual void setStyle (const Toolbar::ToolbarItemStyle& newStyle);
  31195. /** Returns the area of the component that should be used to display the button image or
  31196. other contents of the item.
  31197. This content area may change when the item's style changes, and may leave a space around the
  31198. edge of the component where the text label can be shown.
  31199. @see contentAreaChanged
  31200. */
  31201. const Rectangle getContentArea() const throw() { return contentArea; }
  31202. /** This method must return the size criteria for this item, based on a given toolbar
  31203. size and orientation.
  31204. The preferredSize, minSize and maxSize values must all be set by your implementation
  31205. method. If the toolbar is horizontal, these will be the width of the item; for a vertical
  31206. toolbar, they refer to the item's height.
  31207. The preferredSize is the size that the component would like to be, and this must be
  31208. between the min and max sizes. For a fixed-size item, simply set all three variables to
  31209. the same value.
  31210. The toolbarThickness parameter tells you the depth of the toolbar - the same as calling
  31211. Toolbar::getThickness().
  31212. The isToolbarVertical parameter tells you whether the bar is oriented horizontally or
  31213. vertically.
  31214. */
  31215. virtual bool getToolbarItemSizes (int toolbarThickness,
  31216. bool isToolbarVertical,
  31217. int& preferredSize,
  31218. int& minSize,
  31219. int& maxSize) = 0;
  31220. /** Your subclass should use this method to draw its content area.
  31221. The graphics object that is passed-in will have been clipped and had its origin
  31222. moved to fit the content area as specified get getContentArea(). The width and height
  31223. parameters are the width and height of the content area.
  31224. If the component you're writing isn't a button, you can just do nothing in this method.
  31225. */
  31226. virtual void paintButtonArea (Graphics& g,
  31227. int width, int height,
  31228. bool isMouseOver, bool isMouseDown) = 0;
  31229. /** Callback to indicate that the content area of this item has changed.
  31230. This might be because the component was resized, or because the style changed and
  31231. the space needed for the text label is different.
  31232. See getContentArea() for a description of what the area is.
  31233. */
  31234. virtual void contentAreaChanged (const Rectangle& newBounds) = 0;
  31235. /** Editing modes.
  31236. These are used by setEditingMode(), but will be rarely needed in user code.
  31237. */
  31238. enum ToolbarEditingMode
  31239. {
  31240. normalMode = 0, /**< Means that the component is active, inside a toolbar. */
  31241. editableOnToolbar, /**< Means that the component is on a toolbar, but the toolbar is in
  31242. customisation mode, and the items can be dragged around. */
  31243. editableOnPalette /**< Means that the component is on an new-item palette, so it can be
  31244. dragged onto a toolbar to add it to that bar.*/
  31245. };
  31246. /** Changes the editing mode of this component.
  31247. This is used by the ToolbarItemPalette and related classes for making the items draggable,
  31248. and is unlikely to be of much use in end-user-code.
  31249. */
  31250. void setEditingMode (const ToolbarEditingMode newMode);
  31251. /** Returns the current editing mode of this component.
  31252. This is used by the ToolbarItemPalette and related classes for making the items draggable,
  31253. and is unlikely to be of much use in end-user-code.
  31254. */
  31255. ToolbarEditingMode getEditingMode() const throw() { return mode; }
  31256. /** @internal */
  31257. void paintButton (Graphics& g, bool isMouseOver, bool isMouseDown);
  31258. /** @internal */
  31259. void resized();
  31260. juce_UseDebuggingNewOperator
  31261. private:
  31262. friend class Toolbar;
  31263. friend class ItemDragAndDropOverlayComponent;
  31264. const int itemId;
  31265. ToolbarEditingMode mode;
  31266. Toolbar::ToolbarItemStyle toolbarStyle;
  31267. Component* overlayComp;
  31268. int dragOffsetX, dragOffsetY;
  31269. bool isActive, isBeingDragged, isBeingUsedAsAButton;
  31270. Rectangle contentArea;
  31271. ToolbarItemComponent (const ToolbarItemComponent&);
  31272. const ToolbarItemComponent& operator= (const ToolbarItemComponent&);
  31273. };
  31274. #endif // __JUCE_TOOLBARITEMCOMPONENT_JUCEHEADER__
  31275. /********* End of inlined file: juce_ToolbarItemComponent.h *********/
  31276. /**
  31277. A type of button designed to go on a toolbar.
  31278. This simple button can have two Drawable objects specified - one for normal
  31279. use and another one (optionally) for the button's "on" state if it's a
  31280. toggle button.
  31281. @see Toolbar, ToolbarItemFactory, ToolbarItemComponent, Drawable, Button
  31282. */
  31283. class JUCE_API ToolbarButton : public ToolbarItemComponent
  31284. {
  31285. public:
  31286. /** Creates a ToolbarButton.
  31287. @param itemId the ID for this toolbar item type. This is passed through to the
  31288. ToolbarItemComponent constructor
  31289. @param labelText the text to display on the button (if the toolbar is using a style
  31290. that shows text labels). This is passed through to the
  31291. ToolbarItemComponent constructor
  31292. @param normalImage a drawable object that the button should use as its icon. The object
  31293. that is passed-in here will be kept by this object and will be
  31294. deleted when no longer needed or when this button is deleted.
  31295. @param toggledOnImage a drawable object that the button can use as its icon if the button
  31296. is in a toggled-on state (see the Button::getToggleState() method). If
  31297. 0 is passed-in here, then the normal image will be used instead, regardless
  31298. of the toggle state. The object that is passed-in here will be kept by
  31299. this object and will be deleted when no longer needed or when this button
  31300. is deleted.
  31301. */
  31302. ToolbarButton (const int itemId,
  31303. const String& labelText,
  31304. Drawable* const normalImage,
  31305. Drawable* const toggledOnImage);
  31306. /** Destructor. */
  31307. ~ToolbarButton();
  31308. /** @internal */
  31309. bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
  31310. int& minSize, int& maxSize);
  31311. /** @internal */
  31312. void paintButtonArea (Graphics& g, int width, int height, bool isMouseOver, bool isMouseDown);
  31313. /** @internal */
  31314. void contentAreaChanged (const Rectangle& newBounds);
  31315. juce_UseDebuggingNewOperator
  31316. private:
  31317. Drawable* const normalImage;
  31318. Drawable* const toggledOnImage;
  31319. ToolbarButton (const ToolbarButton&);
  31320. const ToolbarButton& operator= (const ToolbarButton&);
  31321. };
  31322. #endif // __JUCE_TOOLBARBUTTON_JUCEHEADER__
  31323. /********* End of inlined file: juce_ToolbarButton.h *********/
  31324. #endif
  31325. #ifndef __JUCE_DROPSHADOWEFFECT_JUCEHEADER__
  31326. #endif
  31327. #ifndef __JUCE_GLOWEFFECT_JUCEHEADER__
  31328. /********* Start of inlined file: juce_GlowEffect.h *********/
  31329. #ifndef __JUCE_GLOWEFFECT_JUCEHEADER__
  31330. #define __JUCE_GLOWEFFECT_JUCEHEADER__
  31331. /**
  31332. A component effect that adds a coloured blur around the component's contents.
  31333. (This will only work on non-opaque components).
  31334. @see Component::setComponentEffect, DropShadowEffect
  31335. */
  31336. class JUCE_API GlowEffect : public ImageEffectFilter
  31337. {
  31338. public:
  31339. /** Creates a default 'glow' effect.
  31340. To customise its appearance, use the setGlowProperties() method.
  31341. */
  31342. GlowEffect();
  31343. /** Destructor. */
  31344. ~GlowEffect();
  31345. /** Sets the glow's radius and colour.
  31346. The radius is how large the blur should be, and the colour is
  31347. used to render it (for a less intense glow, lower the colour's
  31348. opacity).
  31349. */
  31350. void setGlowProperties (const float newRadius,
  31351. const Colour& newColour);
  31352. /** @internal */
  31353. void applyEffect (Image& sourceImage, Graphics& destContext);
  31354. juce_UseDebuggingNewOperator
  31355. private:
  31356. float radius;
  31357. Colour colour;
  31358. };
  31359. #endif // __JUCE_GLOWEFFECT_JUCEHEADER__
  31360. /********* End of inlined file: juce_GlowEffect.h *********/
  31361. #endif
  31362. #ifndef __JUCE_IMAGEEFFECTFILTER_JUCEHEADER__
  31363. #endif
  31364. #ifndef __JUCE_REDUCEOPACITYEFFECT_JUCEHEADER__
  31365. /********* Start of inlined file: juce_ReduceOpacityEffect.h *********/
  31366. #ifndef __JUCE_REDUCEOPACITYEFFECT_JUCEHEADER__
  31367. #define __JUCE_REDUCEOPACITYEFFECT_JUCEHEADER__
  31368. /**
  31369. An effect filter that reduces the image's opacity.
  31370. This can be used to make a component (and its child components) more
  31371. transparent.
  31372. @see Component::setComponentEffect
  31373. */
  31374. class JUCE_API ReduceOpacityEffect : public ImageEffectFilter
  31375. {
  31376. public:
  31377. /** Creates the effect object.
  31378. The opacity of the component to which the effect is applied will be
  31379. scaled by the given factor (in the range 0 to 1.0f).
  31380. */
  31381. ReduceOpacityEffect (const float opacity = 1.0f);
  31382. /** Destructor. */
  31383. ~ReduceOpacityEffect();
  31384. /** Sets how much to scale the component's opacity.
  31385. @param newOpacity should be between 0 and 1.0f
  31386. */
  31387. void setOpacity (const float newOpacity);
  31388. /** @internal */
  31389. void applyEffect (Image& sourceImage, Graphics& destContext);
  31390. juce_UseDebuggingNewOperator
  31391. private:
  31392. float opacity;
  31393. };
  31394. #endif // __JUCE_REDUCEOPACITYEFFECT_JUCEHEADER__
  31395. /********* End of inlined file: juce_ReduceOpacityEffect.h *********/
  31396. #endif
  31397. #ifndef __JUCE_KEYBOARDFOCUSTRAVERSER_JUCEHEADER__
  31398. #endif
  31399. #ifndef __JUCE_KEYLISTENER_JUCEHEADER__
  31400. #endif
  31401. #ifndef __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__
  31402. /********* Start of inlined file: juce_KeyMappingEditorComponent.h *********/
  31403. #ifndef __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__
  31404. #define __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__
  31405. /********* Start of inlined file: juce_KeyPressMappingSet.h *********/
  31406. #ifndef __JUCE_KEYPRESSMAPPINGSET_JUCEHEADER__
  31407. #define __JUCE_KEYPRESSMAPPINGSET_JUCEHEADER__
  31408. /**
  31409. Manages and edits a list of keypresses, which it uses to invoke the appropriate
  31410. command in a ApplicationCommandManager.
  31411. Normally, you won't actually create a KeyPressMappingSet directly, because
  31412. each ApplicationCommandManager contains its own KeyPressMappingSet, so typically
  31413. you'd create yourself an ApplicationCommandManager, and call its
  31414. ApplicationCommandManager::getKeyMappings() method to get a pointer to its
  31415. KeyPressMappingSet.
  31416. For one of these to actually use keypresses, you'll need to add it as a KeyListener
  31417. to the top-level component for which you want to handle keystrokes. So for example:
  31418. @code
  31419. class MyMainWindow : public Component
  31420. {
  31421. ApplicationCommandManager* myCommandManager;
  31422. public:
  31423. MyMainWindow()
  31424. {
  31425. myCommandManager = new ApplicationCommandManager();
  31426. // first, make sure the command manager has registered all the commands that its
  31427. // targets can perform..
  31428. myCommandManager->registerAllCommandsForTarget (myCommandTarget1);
  31429. myCommandManager->registerAllCommandsForTarget (myCommandTarget2);
  31430. // this will use the command manager to initialise the KeyPressMappingSet with
  31431. // the default keypresses that were specified when the targets added their commands
  31432. // to the manager.
  31433. myCommandManager->getKeyMappings()->resetToDefaultMappings();
  31434. // having set up the default key-mappings, you might now want to load the last set
  31435. // of mappings that the user configured.
  31436. myCommandManager->getKeyMappings()->restoreFromXml (lastSavedKeyMappingsXML);
  31437. // Now tell our top-level window to send any keypresses that arrive to the
  31438. // KeyPressMappingSet, which will use them to invoke the appropriate commands.
  31439. addKeyListener (myCommandManager->getKeyMappings());
  31440. }
  31441. ...
  31442. }
  31443. @endcode
  31444. KeyPressMappingSet derives from ChangeBroadcaster so that interested parties can
  31445. register to be told when a command or mapping is added, removed, etc.
  31446. There's also a UI component called KeyMappingEditorComponent that can be used
  31447. to easily edit the key mappings.
  31448. @see Component::addKeyListener(), KeyMappingEditorComponent, ApplicationCommandManager
  31449. */
  31450. class JUCE_API KeyPressMappingSet : public KeyListener,
  31451. public ChangeBroadcaster,
  31452. public FocusChangeListener
  31453. {
  31454. public:
  31455. /** Creates a KeyPressMappingSet for a given command manager.
  31456. Normally, you won't actually create a KeyPressMappingSet directly, because
  31457. each ApplicationCommandManager contains its own KeyPressMappingSet, so the
  31458. best thing to do is to create your ApplicationCommandManager, and use the
  31459. ApplicationCommandManager::getKeyMappings() method to access its mappings.
  31460. When a suitable keypress happens, the manager's invoke() method will be
  31461. used to invoke the appropriate command.
  31462. @see ApplicationCommandManager
  31463. */
  31464. KeyPressMappingSet (ApplicationCommandManager* const commandManager) throw();
  31465. /** Creates an copy of a KeyPressMappingSet. */
  31466. KeyPressMappingSet (const KeyPressMappingSet& other) throw();
  31467. /** Destructor. */
  31468. ~KeyPressMappingSet();
  31469. ApplicationCommandManager* getCommandManager() const throw() { return commandManager; }
  31470. /** Returns a list of keypresses that are assigned to a particular command.
  31471. @param commandID the command's ID
  31472. */
  31473. const Array <KeyPress> getKeyPressesAssignedToCommand (const CommandID commandID) const throw();
  31474. /** Assigns a keypress to a command.
  31475. If the keypress is already assigned to a different command, it will first be
  31476. removed from that command, to avoid it triggering multiple functions.
  31477. @param commandID the ID of the command that you want to add a keypress to. If
  31478. this is 0, the keypress will be removed from anything that it
  31479. was previously assigned to, but not re-assigned
  31480. @param newKeyPress the new key-press
  31481. @param insertIndex if this is less than zero, the key will be appended to the
  31482. end of the list of keypresses; otherwise the new keypress will
  31483. be inserted into the existing list at this index
  31484. */
  31485. void addKeyPress (const CommandID commandID,
  31486. const KeyPress& newKeyPress,
  31487. int insertIndex = -1) throw();
  31488. /** Reset all mappings to the defaults, as dictated by the ApplicationCommandManager.
  31489. @see resetToDefaultMapping
  31490. */
  31491. void resetToDefaultMappings() throw();
  31492. /** Resets all key-mappings to the defaults for a particular command.
  31493. @see resetToDefaultMappings
  31494. */
  31495. void resetToDefaultMapping (const CommandID commandID) throw();
  31496. /** Removes all keypresses that are assigned to any commands. */
  31497. void clearAllKeyPresses() throw();
  31498. /** Removes all keypresses that are assigned to a particular command. */
  31499. void clearAllKeyPresses (const CommandID commandID) throw();
  31500. /** Removes one of the keypresses that are assigned to a command.
  31501. See the getKeyPressesAssignedToCommand() for the list of keypresses to
  31502. which the keyPressIndex refers.
  31503. */
  31504. void removeKeyPress (const CommandID commandID,
  31505. const int keyPressIndex) throw();
  31506. /** Removes a keypress from any command that it may be assigned to.
  31507. */
  31508. void removeKeyPress (const KeyPress& keypress) throw();
  31509. /** Returns true if the given command is linked to this key. */
  31510. bool containsMapping (const CommandID commandID,
  31511. const KeyPress& keyPress) const throw();
  31512. /** Looks for a command that corresponds to a keypress.
  31513. @returns the UID of the command or 0 if none was found
  31514. */
  31515. CommandID findCommandForKeyPress (const KeyPress& keyPress) const throw();
  31516. /** Tries to recreate the mappings from a previously stored state.
  31517. The XML passed in must have been created by the createXml() method.
  31518. If the stored state makes any reference to commands that aren't
  31519. currently available, these will be ignored.
  31520. If the set of mappings being loaded was a set of differences (using createXml (true)),
  31521. then this will call resetToDefaultMappings() and then merge the saved mappings
  31522. on top. If the saved set was created with createXml (false), then this method
  31523. will first clear all existing mappings and load the saved ones as a complete set.
  31524. @returns true if it manages to load the XML correctly
  31525. @see createXml
  31526. */
  31527. bool restoreFromXml (const XmlElement& xmlVersion);
  31528. /** Creates an XML representation of the current mappings.
  31529. This will produce a lump of XML that can be later reloaded using
  31530. restoreFromXml() to recreate the current mapping state.
  31531. The object that is returned must be deleted by the caller.
  31532. @param saveDifferencesFromDefaultSet if this is false, then all keypresses
  31533. will be saved into the XML. If it's true, then the XML will
  31534. only store the differences between the current mappings and
  31535. the default mappings you'd get from calling resetToDefaultMappings().
  31536. The advantage of saving a set of differences from the default is that
  31537. if you change the default mappings (in a new version of your app, for
  31538. example), then these will be merged into a user's saved preferences.
  31539. @see restoreFromXml
  31540. */
  31541. XmlElement* createXml (const bool saveDifferencesFromDefaultSet) const;
  31542. /** @internal */
  31543. bool keyPressed (const KeyPress& key, Component* originatingComponent);
  31544. /** @internal */
  31545. bool keyStateChanged (Component* originatingComponent);
  31546. /** @internal */
  31547. void globalFocusChanged (Component* focusedComponent);
  31548. juce_UseDebuggingNewOperator
  31549. private:
  31550. ApplicationCommandManager* commandManager;
  31551. struct CommandMapping
  31552. {
  31553. CommandID commandID;
  31554. Array <KeyPress> keypresses;
  31555. bool wantsKeyUpDownCallbacks;
  31556. };
  31557. OwnedArray <CommandMapping> mappings;
  31558. struct KeyPressTime
  31559. {
  31560. KeyPress key;
  31561. uint32 timeWhenPressed;
  31562. };
  31563. OwnedArray <KeyPressTime> keysDown;
  31564. void handleMessage (const Message& message);
  31565. void invokeCommand (const CommandID commandID,
  31566. const KeyPress& keyPress,
  31567. const bool isKeyDown,
  31568. const int millisecsSinceKeyPressed,
  31569. Component* const originatingComponent) const;
  31570. const KeyPressMappingSet& operator= (const KeyPressMappingSet&);
  31571. };
  31572. #endif // __JUCE_KEYPRESSMAPPINGSET_JUCEHEADER__
  31573. /********* End of inlined file: juce_KeyPressMappingSet.h *********/
  31574. /********* Start of inlined file: juce_TreeView.h *********/
  31575. #ifndef __JUCE_TREEVIEW_JUCEHEADER__
  31576. #define __JUCE_TREEVIEW_JUCEHEADER__
  31577. class TreeView;
  31578. /**
  31579. An item in a treeview.
  31580. A TreeViewItem can either be a leaf-node in the tree, or it can contain its
  31581. own sub-items.
  31582. To implement an item that contains sub-items, override the itemOpennessChanged()
  31583. method so that when it is opened, it adds the new sub-items to itself using the
  31584. addSubItem method. Depending on the nature of the item it might choose to only
  31585. do this the first time it's opened, or it might want to refresh itself each time.
  31586. It also has the option of deleting its sub-items when it is closed, or leaving them
  31587. in place.
  31588. */
  31589. class JUCE_API TreeViewItem
  31590. {
  31591. public:
  31592. /** Constructor. */
  31593. TreeViewItem();
  31594. /** Destructor. */
  31595. virtual ~TreeViewItem();
  31596. /** Returns the number of sub-items that have been added to this item.
  31597. Note that this doesn't mean much if the node isn't open.
  31598. @see getSubItem, mightContainSubItems, addSubItem
  31599. */
  31600. int getNumSubItems() const throw();
  31601. /** Returns one of the item's sub-items.
  31602. Remember that the object returned might get deleted at any time when its parent
  31603. item is closed or refreshed, depending on the nature of the items you're using.
  31604. @see getNumSubItems
  31605. */
  31606. TreeViewItem* getSubItem (const int index) const throw();
  31607. /** Removes any sub-items. */
  31608. void clearSubItems();
  31609. /** Adds a sub-item.
  31610. @param newItem the object to add to the item's sub-item list. Once added, these can be
  31611. found using getSubItem(). When the items are later removed with
  31612. removeSubItem() (or when this item is deleted), they will be deleted.
  31613. @param insertPosition the index which the new item should have when it's added. If this
  31614. value is less than 0, the item will be added to the end of the list.
  31615. */
  31616. void addSubItem (TreeViewItem* const newItem,
  31617. const int insertPosition = -1);
  31618. /** Removes one of the sub-items.
  31619. @param index the item to remove
  31620. @param deleteItem if true, the item that is removed will also be deleted.
  31621. */
  31622. void removeSubItem (const int index,
  31623. const bool deleteItem = true);
  31624. /** Returns the TreeView to which this item belongs. */
  31625. TreeView* getOwnerView() const throw() { return ownerView; }
  31626. /** Returns the item within which this item is contained. */
  31627. TreeViewItem* getParentItem() const throw() { return parentItem; }
  31628. /** True if this item is currently open in the treeview. */
  31629. bool isOpen() const throw();
  31630. /** Opens or closes the item.
  31631. When opened or closed, the item's itemOpennessChanged() method will be called,
  31632. and a subclass should use this callback to create and add any sub-items that
  31633. it needs to.
  31634. @see itemOpennessChanged, mightContainSubItems
  31635. */
  31636. void setOpen (const bool shouldBeOpen);
  31637. /** True if this item is currently selected.
  31638. Use this when painting the node, to decide whether to draw it as selected or not.
  31639. */
  31640. bool isSelected() const throw();
  31641. /** Selects or deselects the item.
  31642. This will cause a callback to itemSelectionChanged()
  31643. */
  31644. void setSelected (const bool shouldBeSelected,
  31645. const bool deselectOtherItemsFirst);
  31646. /** Returns the rectangle that this item occupies.
  31647. If relativeToTreeViewTopLeft is true, the co-ordinates are relative to the
  31648. top-left of the TreeView comp, so this will depend on the scroll-position of
  31649. the tree. If false, it is relative to the top-left of the topmost item in the
  31650. tree (so this would be unaffected by scrolling the view).
  31651. */
  31652. const Rectangle getItemPosition (const bool relativeToTreeViewTopLeft) const throw();
  31653. /** Sends a signal to the treeview to make it refresh itself.
  31654. Call this if your items have changed and you want the tree to update to reflect
  31655. this.
  31656. */
  31657. void treeHasChanged() const throw();
  31658. /** Returns the row number of this item in the tree.
  31659. The row number of an item will change according to which items are open.
  31660. @see TreeView::getNumRowsInTree(), TreeView::getItemOnRow()
  31661. */
  31662. int getRowNumberInTree() const throw();
  31663. /** Changes whether lines are drawn to connect any sub-items to this item.
  31664. By default, line-drawing is turned on.
  31665. */
  31666. void setLinesDrawnForSubItems (const bool shouldDrawLines) throw();
  31667. /** Tells the tree whether this item can potentially be opened.
  31668. If your item could contain sub-items, this should return true; if it returns
  31669. false then the tree will not try to open the item. This determines whether or
  31670. not the item will be drawn with a 'plus' button next to it.
  31671. */
  31672. virtual bool mightContainSubItems() = 0;
  31673. /** Returns a string to uniquely identify this item.
  31674. If you're planning on using the TreeView::getOpennessState() method, then
  31675. these strings will be used to identify which nodes are open. The string
  31676. should be unique amongst the item's sibling items, but it's ok for there
  31677. to be duplicates at other levels of the tree.
  31678. If you're not going to store the state, then it's ok not to bother implementing
  31679. this method.
  31680. */
  31681. virtual const String getUniqueName() const;
  31682. /** Called when an item is opened or closed.
  31683. When setOpen() is called and the item has specified that it might
  31684. have sub-items with the mightContainSubItems() method, this method
  31685. is called to let the item create or manage its sub-items.
  31686. So when this is called with isNowOpen set to true (i.e. when the item is being
  31687. opened), a subclass might choose to use clearSubItems() and addSubItem() to
  31688. refresh its sub-item list.
  31689. When this is called with isNowOpen set to false, the subclass might want
  31690. to use clearSubItems() to save on space, or it might choose to leave them,
  31691. depending on the nature of the tree.
  31692. You could also use this callback as a trigger to start a background process
  31693. which asynchronously creates sub-items and adds them, if that's more
  31694. appropriate for the task in hand.
  31695. @see mightContainSubItems
  31696. */
  31697. virtual void itemOpennessChanged (bool isNowOpen);
  31698. /** Must return the width required by this item.
  31699. If your item needs to have a particular width in pixels, return that value; if
  31700. you'd rather have it just fill whatever space is available in the treeview,
  31701. return -1.
  31702. If all your items return -1, no horizontal scrollbar will be shown, but if any
  31703. items have fixed widths and extend beyond the width of the treeview, a
  31704. scrollbar will appear.
  31705. Each item can be a different width, but if they change width, you should call
  31706. treeHasChanged() to update the tree.
  31707. */
  31708. virtual int getItemWidth() const { return -1; }
  31709. /** Must return the height required by this item.
  31710. This is the height in pixels that the item will take up. Items in the tree
  31711. can be different heights, but if they change height, you should call
  31712. treeHasChanged() to update the tree.
  31713. */
  31714. virtual int getItemHeight() const { return 20; }
  31715. /** Creates a component that will be used to represent this item.
  31716. You don't have to implement this method - if it returns 0 then no component
  31717. will be used for the item, and you can just draw it using the paintItem()
  31718. callback. But if you do return a component, it will be positioned in the
  31719. treeview so that it can be used to represent this item.
  31720. The component returned will be managed by the treeview, so always return
  31721. a new component, and don't keep a reference to it, as the treeview will
  31722. delete it later when it goes off the screen or is no longer needed. Also
  31723. bear in mind that if the component keeps a reference to the item that
  31724. created it, that item could be deleted before the component. Its position
  31725. and size will be completely managed by the tree, so don't attempt to move it
  31726. around.
  31727. Something you may want to do with your component is to give it a pointer to
  31728. the TreeView that created it. This is perfectly safe, and there's no danger
  31729. of it becoming a dangling pointer because the TreeView will always delete
  31730. the component before it is itself deleted.
  31731. As long as you stick to these rules you can return whatever kind of
  31732. component you like. It's most useful if you're doing things like drag-and-drop
  31733. of items, or want to use a Label component to edit item names, etc.
  31734. */
  31735. virtual Component* createItemComponent() { return 0; }
  31736. /** Draws the item's contents.
  31737. You can choose to either implement this method and draw each item, or you
  31738. can use createItemComponent() to create a component that will represent the
  31739. item.
  31740. If all you need in your tree is to be able to draw the items and detect when
  31741. the user selects or double-clicks one of them, it's probably enough to
  31742. use paintItem(), itemClicked() and itemDoubleClicked(). If you need more
  31743. complicated interactions, you may need to use createItemComponent() instead.
  31744. @param g the graphics context to draw into
  31745. @param width the width of the area available for drawing
  31746. @param height the height of the area available for drawing
  31747. */
  31748. virtual void paintItem (Graphics& g, int width, int height);
  31749. /** Called when the user clicks on this item.
  31750. If you're using createItemComponent() to create a custom component for the
  31751. item, the mouse-clicks might not make it through to the treeview, but this
  31752. is how you find out about clicks when just drawing each item individually.
  31753. The associated mouse-event details are passed in, so you can find out about
  31754. which button, where it was, etc.
  31755. @see itemDoubleClicked
  31756. */
  31757. virtual void itemClicked (const MouseEvent& e);
  31758. /** Called when the user double-clicks on this item.
  31759. If you're using createItemComponent() to create a custom component for the
  31760. item, the mouse-clicks might not make it through to the treeview, but this
  31761. is how you find out about clicks when just drawing each item individually.
  31762. The associated mouse-event details are passed in, so you can find out about
  31763. which button, where it was, etc.
  31764. If not overridden, the base class method here will open or close the item as
  31765. if the 'plus' button had been clicked.
  31766. @see itemClicked
  31767. */
  31768. virtual void itemDoubleClicked (const MouseEvent& e);
  31769. /** Called when the item is selected or deselected.
  31770. Use this if you want to do something special when the item's selectedness
  31771. changes. By default it'll get repainted when this happens.
  31772. */
  31773. virtual void itemSelectionChanged (bool isNowSelected);
  31774. /** To allow items from your treeview to be dragged-and-dropped, implement this method.
  31775. If this returns a non-empty name then when the user drags an item, the treeview will
  31776. try to find a DragAndDropContainer in its parent hierarchy, and will use it to trigger
  31777. a drag-and-drop operation, using this string as the source description, with the treeview
  31778. itself as the source component.
  31779. If you need more complex drag-and-drop behaviour, you can use custom components for
  31780. the items, and use those to trigger the drag.
  31781. @see DragAndDropContainer::startDragging
  31782. */
  31783. virtual const String getDragSourceDescription();
  31784. juce_UseDebuggingNewOperator
  31785. private:
  31786. TreeView* ownerView;
  31787. TreeViewItem* parentItem;
  31788. OwnedArray <TreeViewItem> subItems;
  31789. int y, itemHeight, totalHeight, itemWidth, totalWidth;
  31790. int uid;
  31791. bool selected : 1;
  31792. bool redrawNeeded : 1;
  31793. bool drawLinesInside : 1;
  31794. unsigned int openness : 2;
  31795. friend class TreeView;
  31796. friend class TreeViewContentComponent;
  31797. void updatePositions (int newY);
  31798. int getIndentX() const throw();
  31799. void setOwnerView (TreeView* const newOwner) throw();
  31800. void paintRecursively (Graphics& g, int width);
  31801. TreeViewItem* findItemRecursively (int y) throw();
  31802. TreeViewItem* getDeepestOpenParentItem() throw();
  31803. void restoreFromXml (const XmlElement& e);
  31804. XmlElement* createXmlOpenness() const;
  31805. bool isLastOfSiblings() const throw();
  31806. TreeViewItem* getTopLevelItem() throw();
  31807. int getNumRows() const throw();
  31808. TreeViewItem* getItemOnRow (int index) throw();
  31809. void deselectAllRecursively();
  31810. int countSelectedItemsRecursively() const throw();
  31811. TreeViewItem* getSelectedItemWithIndex (int index) throw();
  31812. TreeViewItem* getNextVisibleItem (const bool recurse) const throw();
  31813. TreeViewItem (const TreeViewItem&);
  31814. const TreeViewItem& operator= (const TreeViewItem&);
  31815. };
  31816. /**
  31817. A tree-view component.
  31818. Use one of these to hold and display a structure of TreeViewItem objects.
  31819. */
  31820. class JUCE_API TreeView : public Component,
  31821. public SettableTooltipClient,
  31822. private AsyncUpdater
  31823. {
  31824. public:
  31825. /** Creates an empty treeview.
  31826. Once you've got a treeview component, you'll need to give it something to
  31827. display, using the setRootItem() method.
  31828. */
  31829. TreeView (const String& componentName = String::empty);
  31830. /** Destructor. */
  31831. ~TreeView();
  31832. /** Sets the item that is displayed in the treeview.
  31833. A tree has a single root item which contains as many sub-items as it needs. If
  31834. you want the tree to contain a number of root items, you should still use a single
  31835. root item above these, but hide it using setRootItemVisible().
  31836. You can pass in 0 to this method to clear the tree and remove its current root item.
  31837. The object passed in will not be deleted by the treeview, it's up to the caller
  31838. to delete it when no longer needed. BUT make absolutely sure that you don't delete
  31839. this item until you've removed it from the tree, either by calling setRootItem (0),
  31840. or by deleting the tree first.
  31841. */
  31842. void setRootItem (TreeViewItem* const newRootItem);
  31843. /** Returns the tree's root item.
  31844. This will be the last object passed to setRootItem(), or 0 if none has been set.
  31845. */
  31846. TreeViewItem* getRootItem() const throw() { return rootItem; }
  31847. /** Changes whether the tree's root item is shown or not.
  31848. If the root item is hidden, only its sub-items will be shown in the treeview - this
  31849. lets you make the tree look as if it's got many root items. If it's hidden, this call
  31850. will also make sure the root item is open (otherwise the treeview would look empty).
  31851. */
  31852. void setRootItemVisible (const bool shouldBeVisible);
  31853. /** Returns true if the root item is visible.
  31854. @see setRootItemVisible
  31855. */
  31856. bool isRootItemVisible() const throw() { return rootItemVisible; }
  31857. /** Sets whether items are open or closed by default.
  31858. Normally, items are closed until the user opens them, but you can use this
  31859. to make them default to being open until explicitly closed.
  31860. @see areItemsOpenByDefault
  31861. */
  31862. void setDefaultOpenness (const bool isOpenByDefault);
  31863. /** Returns true if the tree's items default to being open.
  31864. @see setDefaultOpenness
  31865. */
  31866. bool areItemsOpenByDefault() const throw() { return defaultOpenness; }
  31867. /** This sets a flag to indicate that the tree can be used for multi-selection.
  31868. You can always select multiple items internally by calling the
  31869. TreeViewItem::setSelected() method, but this flag indicates whether the user
  31870. is allowed to multi-select by clicking on the tree.
  31871. By default it is disabled.
  31872. @see isMultiSelectEnabled
  31873. */
  31874. void setMultiSelectEnabled (const bool canMultiSelect);
  31875. /** Returns whether multi-select has been enabled for the tree.
  31876. @see setMultiSelectEnabled
  31877. */
  31878. bool isMultiSelectEnabled() const throw() { return multiSelectEnabled; }
  31879. /** Deselects any items that are currently selected. */
  31880. void clearSelectedItems();
  31881. /** Returns the number of items that are currently selected.
  31882. @see getSelectedItem, clearSelectedItems
  31883. */
  31884. int getNumSelectedItems() const throw();
  31885. /** Returns one of the selected items in the tree.
  31886. @param index the index, 0 to (getNumSelectedItems() - 1)
  31887. */
  31888. TreeViewItem* getSelectedItem (const int index) const throw();
  31889. /** Returns the number of rows the tree is using.
  31890. This will depend on which items are open.
  31891. @see TreeViewItem::getRowNumberInTree()
  31892. */
  31893. int getNumRowsInTree() const;
  31894. /** Returns the item on a particular row of the tree.
  31895. If the index is out of range, this will return 0.
  31896. @see getNumRowsInTree, TreeViewItem::getRowNumberInTree()
  31897. */
  31898. TreeViewItem* getItemOnRow (int index) const;
  31899. /** Tries to scroll the tree so that this item is on-screen somewhere. */
  31900. void scrollToKeepItemVisible (TreeViewItem* item);
  31901. /** Returns the treeview's Viewport object. */
  31902. Viewport* getViewport() const throw() { return viewport; }
  31903. /** Returns the number of pixels by which each nested level of the tree is indented.
  31904. @see setIndentSize
  31905. */
  31906. int getIndentSize() const throw() { return indentSize; }
  31907. /** Changes the distance by which each nested level of the tree is indented.
  31908. @see getIndentSize
  31909. */
  31910. void setIndentSize (const int newIndentSize);
  31911. /** Saves the current state of open/closed nodes so it can be restored later.
  31912. This takes a snapshot of which nodes have been explicitly opened or closed,
  31913. and records it as XML. To identify node objects it uses the
  31914. TreeViewItem::getUniqueName() method to create named paths. This
  31915. means that the same state of open/closed nodes can be restored to a
  31916. completely different instance of the tree, as long as it contains nodes
  31917. whose unique names are the same.
  31918. The caller is responsible for deleting the object that is returned.
  31919. @param alsoIncludeScrollPosition if this is true, the state will also
  31920. include information about where the
  31921. tree has been scrolled to vertically,
  31922. so this can also be restored
  31923. @see restoreOpennessState
  31924. */
  31925. XmlElement* getOpennessState (const bool alsoIncludeScrollPosition) const;
  31926. /** Restores a previously saved arrangement of open/closed nodes.
  31927. This will try to restore a snapshot of the tree's state that was created by
  31928. the getOpennessState() method. If any of the nodes named in the original
  31929. XML aren't present in this tree, they will be ignored.
  31930. @see getOpennessState
  31931. */
  31932. void restoreOpennessState (const XmlElement& newState);
  31933. /** A set of colour IDs to use to change the colour of various aspects of the treeview.
  31934. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  31935. methods.
  31936. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  31937. */
  31938. enum ColourIds
  31939. {
  31940. backgroundColourId = 0x1000500, /**< A background colour to fill the component with. */
  31941. linesColourId = 0x1000501 /**< The colour to draw the lines with.*/
  31942. };
  31943. /** @internal */
  31944. void paint (Graphics& g);
  31945. /** @internal */
  31946. void resized();
  31947. /** @internal */
  31948. bool keyPressed (const KeyPress& key);
  31949. /** @internal */
  31950. void colourChanged();
  31951. juce_UseDebuggingNewOperator
  31952. private:
  31953. friend class TreeViewItem;
  31954. friend class TreeViewContentComponent;
  31955. Viewport* viewport;
  31956. CriticalSection nodeAlterationLock;
  31957. TreeViewItem* rootItem;
  31958. int indentSize;
  31959. bool defaultOpenness : 1;
  31960. bool needsRecalculating : 1;
  31961. bool rootItemVisible : 1;
  31962. bool multiSelectEnabled : 1;
  31963. void itemsChanged() throw();
  31964. void handleAsyncUpdate();
  31965. void moveSelectedRow (int delta);
  31966. TreeView (const TreeView&);
  31967. const TreeView& operator= (const TreeView&);
  31968. };
  31969. #endif // __JUCE_TREEVIEW_JUCEHEADER__
  31970. /********* End of inlined file: juce_TreeView.h *********/
  31971. /**
  31972. A component to allow editing of the keymaps stored by a KeyPressMappingSet
  31973. object.
  31974. @see KeyPressMappingSet
  31975. */
  31976. class JUCE_API KeyMappingEditorComponent : public Component,
  31977. public TreeViewItem,
  31978. public ChangeListener,
  31979. private ButtonListener
  31980. {
  31981. public:
  31982. /** Creates a KeyMappingEditorComponent.
  31983. @param mappingSet this is the set of mappings to display and
  31984. edit. Make sure the mappings object is not
  31985. deleted before this component!
  31986. @param showResetToDefaultButton if true, then at the bottom of the
  31987. list, the component will include a 'reset to
  31988. defaults' button.
  31989. */
  31990. KeyMappingEditorComponent (KeyPressMappingSet* const mappingSet,
  31991. const bool showResetToDefaultButton);
  31992. /** Destructor. */
  31993. virtual ~KeyMappingEditorComponent();
  31994. /** Sets up the colours to use for parts of the component.
  31995. @param mainBackground colour to use for most of the background
  31996. @param textColour colour to use for the text
  31997. */
  31998. void setColours (const Colour& mainBackground,
  31999. const Colour& textColour);
  32000. /** Returns the KeyPressMappingSet that this component is acting upon.
  32001. */
  32002. KeyPressMappingSet* getMappings() const throw() { return mappings; }
  32003. /** Can be overridden if some commands need to be excluded from the list.
  32004. By default this will use the KeyPressMappingSet's shouldCommandBeVisibleInEditor()
  32005. method to decide what to return, but you can override it to handle special cases.
  32006. */
  32007. virtual bool shouldCommandBeIncluded (const CommandID commandID);
  32008. /** Can be overridden to indicate that some commands are shown as read-only.
  32009. By default this will use the KeyPressMappingSet's shouldCommandBeReadOnlyInEditor()
  32010. method to decide what to return, but you can override it to handle special cases.
  32011. */
  32012. virtual bool isCommandReadOnly (const CommandID commandID);
  32013. /** This can be overridden to let you change the format of the string used
  32014. to describe a keypress.
  32015. This is handy if you're using non-standard KeyPress objects, e.g. for custom
  32016. keys that are triggered by something else externally. If you override the
  32017. method, be sure to let the base class's method handle keys you're not
  32018. interested in.
  32019. */
  32020. virtual const String getDescriptionForKeyPress (const KeyPress& key);
  32021. /** @internal */
  32022. void parentHierarchyChanged();
  32023. /** @internal */
  32024. void resized();
  32025. /** @internal */
  32026. void changeListenerCallback (void*);
  32027. /** @internal */
  32028. bool mightContainSubItems();
  32029. /** @internal */
  32030. const String getUniqueName() const;
  32031. /** @internal */
  32032. void buttonClicked (Button* button);
  32033. juce_UseDebuggingNewOperator
  32034. private:
  32035. KeyPressMappingSet* mappings;
  32036. TreeView* tree;
  32037. friend class KeyMappingTreeViewItem;
  32038. friend class KeyCategoryTreeViewItem;
  32039. friend class KeyMappingItemComponent;
  32040. friend class KeyMappingChangeButton;
  32041. Colour backgroundColour, textColour;
  32042. TextButton* resetButton;
  32043. void assignNewKey (const CommandID commandID, int index);
  32044. KeyMappingEditorComponent (const KeyMappingEditorComponent&);
  32045. const KeyMappingEditorComponent& operator= (const KeyMappingEditorComponent&);
  32046. };
  32047. #endif // __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__
  32048. /********* End of inlined file: juce_KeyMappingEditorComponent.h *********/
  32049. #endif
  32050. #ifndef __JUCE_KEYPRESS_JUCEHEADER__
  32051. #endif
  32052. #ifndef __JUCE_KEYPRESSMAPPINGSET_JUCEHEADER__
  32053. #endif
  32054. #ifndef __JUCE_MODIFIERKEYS_JUCEHEADER__
  32055. #endif
  32056. #ifndef __JUCE_MENUBARCOMPONENT_JUCEHEADER__
  32057. /********* Start of inlined file: juce_MenuBarComponent.h *********/
  32058. #ifndef __JUCE_MENUBARCOMPONENT_JUCEHEADER__
  32059. #define __JUCE_MENUBARCOMPONENT_JUCEHEADER__
  32060. /********* Start of inlined file: juce_MenuBarModel.h *********/
  32061. #ifndef __JUCE_MENUBARMODEL_JUCEHEADER__
  32062. #define __JUCE_MENUBARMODEL_JUCEHEADER__
  32063. class MenuBarModel;
  32064. /**
  32065. A class to receive callbacks when a MenuBarModel changes.
  32066. @see MenuBarModel::addListener, MenuBarModel::removeListener, MenuBarModel::menuItemsChanged
  32067. */
  32068. class JUCE_API MenuBarModelListener
  32069. {
  32070. public:
  32071. /** Destructor. */
  32072. virtual ~MenuBarModelListener() {}
  32073. /** This callback is made when items are changed in the menu bar model.
  32074. */
  32075. virtual void menuBarItemsChanged (MenuBarModel* menuBarModel) = 0;
  32076. /** This callback is made when an application command is invoked that
  32077. is represented by one of the items in the menu bar model.
  32078. */
  32079. virtual void menuCommandInvoked (MenuBarModel* menuBarModel,
  32080. const ApplicationCommandTarget::InvocationInfo& info) = 0;
  32081. };
  32082. /**
  32083. A class for controlling MenuBar components.
  32084. This class is used to tell a MenuBar what menus to show, and to respond
  32085. to a menu being selected.
  32086. @see MenuBarModelListener, MenuBarComponent, PopupMenu
  32087. */
  32088. class JUCE_API MenuBarModel : private AsyncUpdater,
  32089. private ApplicationCommandManagerListener
  32090. {
  32091. public:
  32092. MenuBarModel() throw();
  32093. /** Destructor. */
  32094. virtual ~MenuBarModel();
  32095. /** Call this when some of your menu items have changed.
  32096. This method will cause a callback to any MenuBarListener objects that
  32097. are registered with this model.
  32098. If this model is displaying items from an ApplicationCommandManager, you
  32099. can use the setApplicationCommandManagerToWatch() method to cause
  32100. change messages to be sent automatically when the ApplicationCommandManager
  32101. is changed.
  32102. @see addListener, removeListener, MenuBarListener
  32103. */
  32104. void menuItemsChanged();
  32105. /** Tells the menu bar to listen to the specified command manager, and to update
  32106. itself when the commands change.
  32107. This will also allow it to flash a menu name when a command from that menu
  32108. is invoked using a keystroke.
  32109. */
  32110. void setApplicationCommandManagerToWatch (ApplicationCommandManager* const manager) throw();
  32111. /** Registers a listener for callbacks when the menu items in this model change.
  32112. The listener object will get callbacks when this object's menuItemsChanged()
  32113. method is called.
  32114. @see removeListener
  32115. */
  32116. void addListener (MenuBarModelListener* const listenerToAdd) throw();
  32117. /** Removes a listener.
  32118. @see addListener
  32119. */
  32120. void removeListener (MenuBarModelListener* const listenerToRemove) throw();
  32121. /** This method must return a list of the names of the menus. */
  32122. virtual const StringArray getMenuBarNames() = 0;
  32123. /** This should return the popup menu to display for a given top-level menu.
  32124. @param topLevelMenuIndex the index of the top-level menu to show
  32125. @param menuName the name of the top-level menu item to show
  32126. */
  32127. virtual const PopupMenu getMenuForIndex (int topLevelMenuIndex,
  32128. const String& menuName) = 0;
  32129. /** This is called when a menu item has been clicked on.
  32130. @param menuItemID the item ID of the PopupMenu item that was selected
  32131. @param topLevelMenuIndex the index of the top-level menu from which the item was
  32132. chosen (just in case you've used duplicate ID numbers
  32133. on more than one of the popup menus)
  32134. */
  32135. virtual void menuItemSelected (int menuItemID,
  32136. int topLevelMenuIndex) = 0;
  32137. #if JUCE_MAC || DOXYGEN
  32138. /** MAC ONLY - Sets the model that is currently being shown as the main
  32139. menu bar at the top of the screen on the Mac.
  32140. You can pass 0 to stop the current model being displayed. Be careful
  32141. not to delete a model while it is being used.
  32142. */
  32143. static void setMacMainMenu (MenuBarModel* newMenuBarModel) throw();
  32144. /** MAC ONLY - Returns the menu model that is currently being shown as
  32145. the main menu bar.
  32146. */
  32147. static MenuBarModel* getMacMainMenu() throw();
  32148. #endif
  32149. /** @internal */
  32150. void applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info);
  32151. /** @internal */
  32152. void applicationCommandListChanged();
  32153. /** @internal */
  32154. void handleAsyncUpdate();
  32155. juce_UseDebuggingNewOperator
  32156. private:
  32157. ApplicationCommandManager* manager;
  32158. SortedSet <void*> listeners;
  32159. MenuBarModel (const MenuBarModel&);
  32160. const MenuBarModel& operator= (const MenuBarModel&);
  32161. };
  32162. #endif // __JUCE_MENUBARMODEL_JUCEHEADER__
  32163. /********* End of inlined file: juce_MenuBarModel.h *********/
  32164. /**
  32165. A menu bar component.
  32166. @see MenuBarModel
  32167. */
  32168. class JUCE_API MenuBarComponent : public Component,
  32169. private MenuBarModelListener,
  32170. private Timer
  32171. {
  32172. public:
  32173. /** Creates a menu bar.
  32174. @param model the model object to use to control this bar. You can
  32175. pass 0 into this if you like, and set the model later
  32176. using the setModel() method
  32177. */
  32178. MenuBarComponent (MenuBarModel* const model);
  32179. /** Destructor. */
  32180. ~MenuBarComponent();
  32181. /** Changes the model object to use to control the bar.
  32182. This can be 0, in which case the bar will be empty. Don't delete the object
  32183. that is passed-in while it's still being used by this MenuBar.
  32184. */
  32185. void setModel (MenuBarModel* const newModel);
  32186. /** Pops up one of the menu items.
  32187. This lets you manually open one of the menus - it could be triggered by a
  32188. key shortcut, for example.
  32189. */
  32190. void showMenu (const int menuIndex);
  32191. /** @internal */
  32192. void paint (Graphics& g);
  32193. /** @internal */
  32194. void resized();
  32195. /** @internal */
  32196. void mouseEnter (const MouseEvent& e);
  32197. /** @internal */
  32198. void mouseExit (const MouseEvent& e);
  32199. /** @internal */
  32200. void mouseDown (const MouseEvent& e);
  32201. /** @internal */
  32202. void mouseDrag (const MouseEvent& e);
  32203. /** @internal */
  32204. void mouseUp (const MouseEvent& e);
  32205. /** @internal */
  32206. void mouseMove (const MouseEvent& e);
  32207. /** @internal */
  32208. void inputAttemptWhenModal();
  32209. /** @internal */
  32210. void handleCommandMessage (int commandId);
  32211. /** @internal */
  32212. bool keyPressed (const KeyPress& key);
  32213. /** @internal */
  32214. void menuBarItemsChanged (MenuBarModel* menuBarModel);
  32215. /** @internal */
  32216. void menuCommandInvoked (MenuBarModel* menuBarModel,
  32217. const ApplicationCommandTarget::InvocationInfo& info);
  32218. juce_UseDebuggingNewOperator
  32219. private:
  32220. MenuBarModel* model;
  32221. StringArray menuNames;
  32222. Array <int> xPositions;
  32223. int itemUnderMouse, currentPopupIndex, topLevelIndexClicked, indexToShowAgain;
  32224. int lastMouseX, lastMouseY;
  32225. bool inModalState;
  32226. Component* currentPopup;
  32227. int getItemAt (int x, int y);
  32228. void updateItemUnderMouse (const int x, const int y);
  32229. void hideCurrentMenu();
  32230. void timerCallback();
  32231. void repaintMenuItem (int index);
  32232. MenuBarComponent (const MenuBarComponent&);
  32233. const MenuBarComponent& operator= (const MenuBarComponent&);
  32234. };
  32235. #endif // __JUCE_MENUBARCOMPONENT_JUCEHEADER__
  32236. /********* End of inlined file: juce_MenuBarComponent.h *********/
  32237. #endif
  32238. #ifndef __JUCE_MENUBARMODEL_JUCEHEADER__
  32239. #endif
  32240. #ifndef __JUCE_POPUPMENU_JUCEHEADER__
  32241. #endif
  32242. #ifndef __JUCE_POPUPMENUCUSTOMCOMPONENT_JUCEHEADER__
  32243. #endif
  32244. #ifndef __JUCE_COMPONENTDRAGGER_JUCEHEADER__
  32245. /********* Start of inlined file: juce_ComponentDragger.h *********/
  32246. #ifndef __JUCE_COMPONENTDRAGGER_JUCEHEADER__
  32247. #define __JUCE_COMPONENTDRAGGER_JUCEHEADER__
  32248. /********* Start of inlined file: juce_ComponentBoundsConstrainer.h *********/
  32249. #ifndef __JUCE_COMPONENTBOUNDSCONSTRAINER_JUCEHEADER__
  32250. #define __JUCE_COMPONENTBOUNDSCONSTRAINER_JUCEHEADER__
  32251. /**
  32252. A class that imposes restrictions on a Component's size or position.
  32253. This is used by classes such as ResizableCornerComponent,
  32254. ResizableBorderComponent and ResizableWindow.
  32255. The base class can impose some basic size and position limits, but you can
  32256. also subclass this for custom uses.
  32257. @see ResizableCornerComponent, ResizableBorderComponent, ResizableWindow
  32258. */
  32259. class JUCE_API ComponentBoundsConstrainer
  32260. {
  32261. public:
  32262. /** When first created, the object will not impose any restrictions on the components. */
  32263. ComponentBoundsConstrainer() throw();
  32264. /** Destructor. */
  32265. virtual ~ComponentBoundsConstrainer();
  32266. /** Imposes a minimum width limit. */
  32267. void setMinimumWidth (const int minimumWidth) throw();
  32268. /** Returns the current minimum width. */
  32269. int getMinimumWidth() const throw() { return minW; }
  32270. /** Imposes a maximum width limit. */
  32271. void setMaximumWidth (const int maximumWidth) throw();
  32272. /** Returns the current maximum width. */
  32273. int getMaximumWidth() const throw() { return maxW; }
  32274. /** Imposes a minimum height limit. */
  32275. void setMinimumHeight (const int minimumHeight) throw();
  32276. /** Returns the current minimum height. */
  32277. int getMinimumHeight() const throw() { return minH; }
  32278. /** Imposes a maximum height limit. */
  32279. void setMaximumHeight (const int maximumHeight) throw();
  32280. /** Returns the current maximum height. */
  32281. int getMaximumHeight() const throw() { return maxH; }
  32282. /** Imposes a minimum width and height limit. */
  32283. void setMinimumSize (const int minimumWidth,
  32284. const int minimumHeight) throw();
  32285. /** Imposes a maximum width and height limit. */
  32286. void setMaximumSize (const int maximumWidth,
  32287. const int maximumHeight) throw();
  32288. /** Set all the maximum and minimum dimensions. */
  32289. void setSizeLimits (const int minimumWidth,
  32290. const int minimumHeight,
  32291. const int maximumWidth,
  32292. const int maximumHeight) throw();
  32293. /** Sets the amount by which the component is allowed to go off-screen.
  32294. The values indicate how many pixels must remain on-screen when dragged off
  32295. one of its parent's edges, so e.g. if minimumWhenOffTheTop is set to 10, then
  32296. when the component goes off the top of the screen, its y-position will be
  32297. clipped so that there are always at least 10 pixels on-screen. In other words,
  32298. the lowest y-position it can take would be (10 - the component's height).
  32299. If you pass 0 or less for one of these amounts, the component is allowed
  32300. to move beyond that edge completely, with no restrictions at all.
  32301. If you pass a very large number (i.e. larger that the dimensions of the
  32302. component itself), then the component won't be allowed to overlap that
  32303. edge at all. So e.g. setting minimumWhenOffTheLeft to 0xffffff will mean that
  32304. the component will bump into the left side of the screen and go no further.
  32305. */
  32306. void setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  32307. const int minimumWhenOffTheLeft,
  32308. const int minimumWhenOffTheBottom,
  32309. const int minimumWhenOffTheRight) throw();
  32310. /** Specifies a width-to-height ratio that the resizer should always maintain.
  32311. If the value is 0, no aspect ratio is enforced. If it's non-zero, the width
  32312. will always be maintained as this multiple of the height.
  32313. @see setResizeLimits
  32314. */
  32315. void setFixedAspectRatio (const double widthOverHeight) throw();
  32316. /** Returns the aspect ratio that was set with setFixedAspectRatio().
  32317. If no aspect ratio is being enforced, this will return 0.
  32318. */
  32319. double getFixedAspectRatio() const throw();
  32320. /** This callback changes the given co-ordinates to impose whatever the current
  32321. constraints are set to be.
  32322. @param x the x position that should be examined and adjusted
  32323. @param y the y position that should be examined and adjusted
  32324. @param w the width that should be examined and adjusted
  32325. @param h the height that should be examined and adjusted
  32326. @param previousBounds the component's current size
  32327. @param limits the region in which the component can be positioned
  32328. @param isStretchingTop whether the top edge of the component is being resized
  32329. @param isStretchingLeft whether the left edge of the component is being resized
  32330. @param isStretchingBottom whether the bottom edge of the component is being resized
  32331. @param isStretchingRight whether the right edge of the component is being resized
  32332. */
  32333. virtual void checkBounds (int& x, int& y, int& w, int& h,
  32334. const Rectangle& previousBounds,
  32335. const Rectangle& limits,
  32336. const bool isStretchingTop,
  32337. const bool isStretchingLeft,
  32338. const bool isStretchingBottom,
  32339. const bool isStretchingRight);
  32340. /** This callback happens when the resizer is about to start dragging. */
  32341. virtual void resizeStart();
  32342. /** This callback happens when the resizer has finished dragging. */
  32343. virtual void resizeEnd();
  32344. /** Checks the given bounds, and then sets the component to the corrected size. */
  32345. void setBoundsForComponent (Component* const component,
  32346. int x, int y, int w, int h,
  32347. const bool isStretchingTop,
  32348. const bool isStretchingLeft,
  32349. const bool isStretchingBottom,
  32350. const bool isStretchingRight);
  32351. /** Called by setBoundsForComponent() to apply a new constrained size to a
  32352. component.
  32353. By default this just calls setBounds(), but it virtual in case it's needed for
  32354. extremely cunning purposes.
  32355. */
  32356. virtual void applyBoundsToComponent (Component* component,
  32357. int x, int y, int w, int h);
  32358. juce_UseDebuggingNewOperator
  32359. private:
  32360. int minW, maxW, minH, maxH;
  32361. int minOffTop, minOffLeft, minOffBottom, minOffRight;
  32362. double aspectRatio;
  32363. ComponentBoundsConstrainer (const ComponentBoundsConstrainer&);
  32364. const ComponentBoundsConstrainer& operator= (const ComponentBoundsConstrainer&);
  32365. };
  32366. #endif // __JUCE_COMPONENTBOUNDSCONSTRAINER_JUCEHEADER__
  32367. /********* End of inlined file: juce_ComponentBoundsConstrainer.h *********/
  32368. /**
  32369. An object to take care of the logic for dragging components around with the mouse.
  32370. Very easy to use - in your mouseDown() callback, call startDraggingComponent(),
  32371. then in your mouseDrag() callback, call dragComponent().
  32372. When starting a drag, you can give it a ComponentBoundsConstrainer to use
  32373. to limit the component's position and keep it on-screen.
  32374. e.g. @code
  32375. class MyDraggableComp
  32376. {
  32377. ComponentDragger myDragger;
  32378. void mouseDown (const MouseEvent& e)
  32379. {
  32380. myDragger.startDraggingComponent (this, 0);
  32381. }
  32382. void mouseDrag (const MouseEvent& e)
  32383. {
  32384. myDragger.dragComponent (this, e);
  32385. }
  32386. };
  32387. @endcode
  32388. */
  32389. class JUCE_API ComponentDragger
  32390. {
  32391. public:
  32392. /** Creates a ComponentDragger. */
  32393. ComponentDragger();
  32394. /** Destructor. */
  32395. virtual ~ComponentDragger();
  32396. /** Call this from your component's mouseDown() method, to prepare for dragging.
  32397. @param componentToDrag the component that you want to drag
  32398. @param constrainer a constrainer object to use to keep the component
  32399. from going offscreen
  32400. @see dragComponent
  32401. */
  32402. void startDraggingComponent (Component* const componentToDrag,
  32403. ComponentBoundsConstrainer* constrainer);
  32404. /** Call this from your mouseDrag() callback to move the component.
  32405. This will move the component, but will first check the validity of the
  32406. component's new position using the checkPosition() method, which you
  32407. can override if you need to enforce special positioning limits on the
  32408. component.
  32409. @param componentToDrag the component that you want to drag
  32410. @param e the current mouse-drag event
  32411. @see dragComponent
  32412. */
  32413. void dragComponent (Component* const componentToDrag,
  32414. const MouseEvent& e);
  32415. juce_UseDebuggingNewOperator
  32416. private:
  32417. ComponentBoundsConstrainer* constrainer;
  32418. int originalX, originalY;
  32419. };
  32420. #endif // __JUCE_COMPONENTDRAGGER_JUCEHEADER__
  32421. /********* End of inlined file: juce_ComponentDragger.h *********/
  32422. #endif
  32423. #ifndef __JUCE_DRAGANDDROPCONTAINER_JUCEHEADER__
  32424. #endif
  32425. #ifndef __JUCE_DRAGANDDROPTARGET_JUCEHEADER__
  32426. #endif
  32427. #ifndef __JUCE_FILEDRAGANDDROPTARGET_JUCEHEADER__
  32428. /********* Start of inlined file: juce_FileDragAndDropTarget.h *********/
  32429. #ifndef __JUCE_FILEDRAGANDDROPTARGET_JUCEHEADER__
  32430. #define __JUCE_FILEDRAGANDDROPTARGET_JUCEHEADER__
  32431. /**
  32432. Components derived from this class can have files dropped onto them by an external application.
  32433. @see DragAndDropContainer
  32434. */
  32435. class JUCE_API FileDragAndDropTarget
  32436. {
  32437. public:
  32438. /** Destructor. */
  32439. virtual ~FileDragAndDropTarget() {}
  32440. /** Callback to check whether this target is interested in the set of files being offered.
  32441. Note that this will be called repeatedly when the user is dragging the mouse around over your
  32442. component, so don't do anything time-consuming in here, like opening the files to have a look
  32443. inside them!
  32444. @param files the set of (absolute) pathnames of the files that the user is dragging
  32445. @returns true if this component wants to receive the other callbacks regarging this
  32446. type of object; if it returns false, no other callbacks will be made.
  32447. */
  32448. virtual bool isInterestedInFileDrag (const StringArray& files) = 0;
  32449. /** Callback to indicate that some files are being dragged over this component.
  32450. This gets called when the user moves the mouse into this component while dragging.
  32451. Use this callback as a trigger to make your component repaint itself to give the
  32452. user feedback about whether the files can be dropped here or not.
  32453. @param files the set of (absolute) pathnames of the files that the user is dragging
  32454. @param x the mouse x position, relative to this component
  32455. @param y the mouse y position, relative to this component
  32456. */
  32457. virtual void fileDragEnter (const StringArray& files, int x, int y);
  32458. /** Callback to indicate that the user is dragging some files over this component.
  32459. This gets called when the user moves the mouse over this component while dragging.
  32460. Normally overriding itemDragEnter() and itemDragExit() are enough, but
  32461. this lets you know what happens in-between.
  32462. @param files the set of (absolute) pathnames of the files that the user is dragging
  32463. @param x the mouse x position, relative to this component
  32464. @param y the mouse y position, relative to this component
  32465. */
  32466. virtual void fileDragMove (const StringArray& files, int x, int y);
  32467. /** Callback to indicate that the mouse has moved away from this component.
  32468. This gets called when the user moves the mouse out of this component while dragging
  32469. the files.
  32470. If you've used fileDragEnter() to repaint your component and give feedback, use this
  32471. as a signal to repaint it in its normal state.
  32472. @param files the set of (absolute) pathnames of the files that the user is dragging
  32473. */
  32474. virtual void fileDragExit (const StringArray& files);
  32475. /** Callback to indicate that the user has dropped the files onto this component.
  32476. When the user drops the files, this get called, and you can use the files in whatever
  32477. way is appropriate.
  32478. Note that after this is called, the fileDragExit method may not be called, so you should
  32479. clean up in here if there's anything you need to do when the drag finishes.
  32480. @param files the set of (absolute) pathnames of the files that the user is dragging
  32481. @param x the mouse x position, relative to this component
  32482. @param y the mouse y position, relative to this component
  32483. */
  32484. virtual void filesDropped (const StringArray& files, int x, int y) = 0;
  32485. };
  32486. #endif // __JUCE_FILEDRAGANDDROPTARGET_JUCEHEADER__
  32487. /********* End of inlined file: juce_FileDragAndDropTarget.h *********/
  32488. #endif
  32489. #ifndef __JUCE_LASSOCOMPONENT_JUCEHEADER__
  32490. /********* Start of inlined file: juce_LassoComponent.h *********/
  32491. #ifndef __JUCE_LASSOCOMPONENT_JUCEHEADER__
  32492. #define __JUCE_LASSOCOMPONENT_JUCEHEADER__
  32493. /********* Start of inlined file: juce_SelectedItemSet.h *********/
  32494. #ifndef __JUCE_SELECTEDITEMSET_JUCEHEADER__
  32495. #define __JUCE_SELECTEDITEMSET_JUCEHEADER__
  32496. /** Manages a list of selectable items.
  32497. Use one of these to keep a track of things that the user has highlighted, like
  32498. icons or things in a list.
  32499. The class is templated so that you can use it to hold either a set of pointers
  32500. to objects, or a set of ID numbers or handles, for cases where each item may
  32501. not always have a corresponding object.
  32502. To be informed when items are selected/deselected, register a ChangeListener with
  32503. this object.
  32504. @see SelectableObject
  32505. */
  32506. template <class SelectableItemType>
  32507. class JUCE_API SelectedItemSet : public ChangeBroadcaster
  32508. {
  32509. public:
  32510. /** Creates an empty set. */
  32511. SelectedItemSet()
  32512. {
  32513. }
  32514. /** Creates a set based on an array of items. */
  32515. SelectedItemSet (const Array <SelectableItemType>& items)
  32516. : selectedItems (items)
  32517. {
  32518. }
  32519. /** Creates a copy of another set. */
  32520. SelectedItemSet (const SelectedItemSet& other)
  32521. : selectedItems (other.selectedItems)
  32522. {
  32523. }
  32524. /** Creates a copy of another set. */
  32525. const SelectedItemSet& operator= (const SelectedItemSet& other)
  32526. {
  32527. if (selectedItems != other.selectedItems)
  32528. {
  32529. selectedItems = other.selectedItems;
  32530. changed();
  32531. }
  32532. return *this;
  32533. }
  32534. /** Destructor. */
  32535. ~SelectedItemSet()
  32536. {
  32537. }
  32538. /** Clears any other currently selected items, and selects this item.
  32539. If this item is already the only thing selected, no change notification
  32540. will be sent out.
  32541. @see addToSelection, addToSelectionBasedOnModifiers
  32542. */
  32543. void selectOnly (SelectableItemType item)
  32544. {
  32545. if (isSelected (item))
  32546. {
  32547. for (int i = selectedItems.size(); --i >= 0;)
  32548. {
  32549. if (selectedItems.getUnchecked(i) != item)
  32550. {
  32551. deselect (selectedItems.getUnchecked(i));
  32552. i = jmin (i, selectedItems.size());
  32553. }
  32554. }
  32555. }
  32556. else
  32557. {
  32558. deselectAll();
  32559. changed();
  32560. selectedItems.add (item);
  32561. itemSelected (item);
  32562. }
  32563. }
  32564. /** Selects an item.
  32565. If the item is already selected, no change notification will be sent out.
  32566. @see selectOnly, addToSelectionBasedOnModifiers
  32567. */
  32568. void addToSelection (SelectableItemType item)
  32569. {
  32570. if (! isSelected (item))
  32571. {
  32572. changed();
  32573. selectedItems.add (item);
  32574. itemSelected (item);
  32575. }
  32576. }
  32577. /** Selects or deselects an item.
  32578. This will use the modifier keys to decide whether to deselect other items
  32579. first.
  32580. So if the shift key is held down, the item will be added without deselecting
  32581. anything (same as calling addToSelection() )
  32582. If no modifiers are down, the current selection will be cleared first (same
  32583. as calling selectOnly() )
  32584. If the ctrl (or command on the Mac) key is held down, the item will be toggled -
  32585. so it'll be added to the set unless it's already there, in which case it'll be
  32586. deselected.
  32587. If the items that you're selecting can also be dragged, you may need to use the
  32588. addToSelectionOnMouseDown() and addToSelectionOnMouseUp() calls to handle the
  32589. subtleties of this kind of usage.
  32590. @see selectOnly, addToSelection, addToSelectionOnMouseDown, addToSelectionOnMouseUp
  32591. */
  32592. void addToSelectionBasedOnModifiers (SelectableItemType item,
  32593. const ModifierKeys& modifiers)
  32594. {
  32595. if (modifiers.isShiftDown())
  32596. {
  32597. addToSelection (item);
  32598. }
  32599. else if (modifiers.isCommandDown())
  32600. {
  32601. if (isSelected (item))
  32602. deselect (item);
  32603. else
  32604. addToSelection (item);
  32605. }
  32606. else
  32607. {
  32608. selectOnly (item);
  32609. }
  32610. }
  32611. /** Selects or deselects items that can also be dragged, based on a mouse-down event.
  32612. If you call addToSelectionOnMouseDown() at the start of your mouseDown event,
  32613. and then call addToSelectionOnMouseUp() at the end of your mouseUp event, this
  32614. makes it easy to handle multiple-selection of sets of objects that can also
  32615. be dragged.
  32616. For example, if you have several items already selected, and you click on
  32617. one of them (without dragging), then you'd expect this to deselect the other, and
  32618. just select the item you clicked on. But if you had clicked on this item and
  32619. dragged it, you'd have expected them all to stay selected.
  32620. When you call this method, you'll need to store the boolean result, because the
  32621. addToSelectionOnMouseUp() method will need to be know this value.
  32622. @see addToSelectionOnMouseUp, addToSelectionBasedOnModifiers
  32623. */
  32624. bool addToSelectionOnMouseDown (SelectableItemType item,
  32625. const ModifierKeys& modifiers)
  32626. {
  32627. if (isSelected (item))
  32628. {
  32629. return ! modifiers.isPopupMenu();
  32630. }
  32631. else
  32632. {
  32633. addToSelectionBasedOnModifiers (item, modifiers);
  32634. return false;
  32635. }
  32636. }
  32637. /** Selects or deselects items that can also be dragged, based on a mouse-up event.
  32638. Call this during a mouseUp callback, when you have previously called the
  32639. addToSelectionOnMouseDown() method during your mouseDown event.
  32640. See addToSelectionOnMouseDown() for more info
  32641. @param item the item to select (or deselect)
  32642. @param modifiers the modifiers from the mouse-up event
  32643. @param wasItemDragged true if your item was dragged during the mouse click
  32644. @param resultOfMouseDownSelectMethod this is the boolean return value that came
  32645. back from the addToSelectionOnMouseDown() call that you
  32646. should have made during the matching mouseDown event
  32647. */
  32648. void addToSelectionOnMouseUp (SelectableItemType item,
  32649. const ModifierKeys& modifiers,
  32650. const bool wasItemDragged,
  32651. const bool resultOfMouseDownSelectMethod)
  32652. {
  32653. if (resultOfMouseDownSelectMethod && ! wasItemDragged)
  32654. addToSelectionBasedOnModifiers (item, modifiers);
  32655. }
  32656. /** Deselects an item. */
  32657. void deselect (SelectableItemType item)
  32658. {
  32659. const int i = selectedItems.indexOf (item);
  32660. if (i >= 0)
  32661. {
  32662. changed();
  32663. itemDeselected (selectedItems.remove (i));
  32664. }
  32665. }
  32666. /** Deselects all items. */
  32667. void deselectAll()
  32668. {
  32669. if (selectedItems.size() > 0)
  32670. {
  32671. changed();
  32672. for (int i = selectedItems.size(); --i >= 0;)
  32673. {
  32674. itemDeselected (selectedItems.remove (i));
  32675. i = jmin (i, selectedItems.size());
  32676. }
  32677. }
  32678. }
  32679. /** Returns the number of currently selected items.
  32680. @see getSelectedItem
  32681. */
  32682. int getNumSelected() const throw()
  32683. {
  32684. return selectedItems.size();
  32685. }
  32686. /** Returns one of the currently selected items.
  32687. Returns 0 if the index is out-of-range.
  32688. @see getNumSelected
  32689. */
  32690. SelectableItemType getSelectedItem (const int index) const throw()
  32691. {
  32692. return selectedItems [index];
  32693. }
  32694. /** True if this item is currently selected. */
  32695. bool isSelected (const SelectableItemType item) const throw()
  32696. {
  32697. return selectedItems.contains (item);
  32698. }
  32699. const Array <SelectableItemType>& getItemArray() const throw() { return selectedItems; }
  32700. /** Can be overridden to do special handling when an item is selected.
  32701. For example, if the item is an object, you might want to call it and tell
  32702. it that it's being selected.
  32703. */
  32704. virtual void itemSelected (SelectableItemType item) {}
  32705. /** Can be overridden to do special handling when an item is deselected.
  32706. For example, if the item is an object, you might want to call it and tell
  32707. it that it's being deselected.
  32708. */
  32709. virtual void itemDeselected (SelectableItemType item) {}
  32710. /** Used internally, but can be called to force a change message to be sent to the ChangeListeners.
  32711. */
  32712. void changed (const bool synchronous = false)
  32713. {
  32714. if (synchronous)
  32715. sendSynchronousChangeMessage (this);
  32716. else
  32717. sendChangeMessage (this);
  32718. }
  32719. juce_UseDebuggingNewOperator
  32720. private:
  32721. Array <SelectableItemType> selectedItems;
  32722. };
  32723. #endif // __JUCE_SELECTEDITEMSET_JUCEHEADER__
  32724. /********* End of inlined file: juce_SelectedItemSet.h *********/
  32725. /**
  32726. A class used by the LassoComponent to manage the things that it selects.
  32727. This allows the LassoComponent to find out which items are within the lasso,
  32728. and to change the list of selected items.
  32729. @see LassoComponent, SelectedItemSet
  32730. */
  32731. template <class SelectableItemType>
  32732. class LassoSource
  32733. {
  32734. public:
  32735. /** Destructor. */
  32736. virtual ~LassoSource() {}
  32737. /** Returns the set of items that lie within a given lassoable region.
  32738. Your implementation of this method must find all the relevent items that lie
  32739. within the given rectangle. and add them to the itemsFound array.
  32740. The co-ordinates are relative to the top-left of the lasso component's parent
  32741. component. (i.e. they are the same as the size and position of the lasso
  32742. component itself).
  32743. */
  32744. virtual void findLassoItemsInArea (Array <SelectableItemType>& itemsFound,
  32745. int x, int y, int width, int height) = 0;
  32746. /** Returns the SelectedItemSet that the lasso should update.
  32747. This set will be continuously updated by the LassoComponent as it gets
  32748. dragged around, so make sure that you've got a ChangeListener attached to
  32749. the set so that your UI objects will know when the selection changes and
  32750. be able to update themselves appropriately.
  32751. */
  32752. virtual SelectedItemSet <SelectableItemType>& getLassoSelection() = 0;
  32753. };
  32754. /**
  32755. A component that acts as a rectangular selection region, which you drag with
  32756. the mouse to select groups of objects (in conjunction with a SelectedItemSet).
  32757. To use one of these:
  32758. - In your mouseDown or mouseDrag event, add the LassoComponent to your parent
  32759. component, and call its beginLasso() method, giving it a
  32760. suitable LassoSource object that it can use to find out which items are in
  32761. the active area.
  32762. - Each time your parent component gets a mouseDrag event, call dragLasso()
  32763. to update the lasso's position - it will use its LassoSource to calculate and
  32764. update the current selection.
  32765. - After the drag has finished and you get a mouseUp callback, you should call
  32766. endLasso() to clean up. This will make the lasso component invisible, and you
  32767. can remove it from the parent component, or delete it.
  32768. The class takes into account the modifier keys that are being held down while
  32769. the lasso is being dragged, so if shift is pressed, then any lassoed items will
  32770. be added to the original selection; if ctrl or command is pressed, they will be
  32771. xor'ed with any previously selected items.
  32772. @see LassoSource, SelectedItemSet
  32773. */
  32774. template <class SelectableItemType>
  32775. class LassoComponent : public Component
  32776. {
  32777. public:
  32778. /** Creates a Lasso component.
  32779. The fill colour is used to fill the lasso'ed rectangle, and the outline
  32780. colour is used to draw a line around its edge.
  32781. */
  32782. LassoComponent (const int outlineThickness_ = 1)
  32783. : source (0),
  32784. outlineThickness (outlineThickness_)
  32785. {
  32786. }
  32787. /** Destructor. */
  32788. ~LassoComponent()
  32789. {
  32790. }
  32791. /** Call this in your mouseDown event, to initialise a drag.
  32792. Pass in a suitable LassoSource object which the lasso will use to find
  32793. the items and change the selection.
  32794. After using this method to initialise the lasso, repeatedly call dragLasso()
  32795. in your component's mouseDrag callback.
  32796. @see dragLasso, endLasso, LassoSource
  32797. */
  32798. void beginLasso (const MouseEvent& e,
  32799. LassoSource <SelectableItemType>* const lassoSource)
  32800. {
  32801. jassert (source == 0); // this suggests that you didn't call endLasso() after the last drag...
  32802. jassert (lassoSource != 0); // the source can't be null!
  32803. jassert (getParentComponent() != 0); // you need to add this to a parent component for it to work!
  32804. source = lassoSource;
  32805. if (lassoSource != 0)
  32806. originalSelection = lassoSource->getLassoSelection().getItemArray();
  32807. setSize (0, 0);
  32808. }
  32809. /** Call this in your mouseDrag event, to update the lasso's position.
  32810. This must be repeatedly calling when the mouse is dragged, after you've
  32811. first initialised the lasso with beginLasso().
  32812. This method takes into account the modifier keys that are being held down, so
  32813. if shift is pressed, then the lassoed items will be added to any that were
  32814. previously selected; if ctrl or command is pressed, then they will be xor'ed
  32815. with previously selected items.
  32816. @see beginLasso, endLasso
  32817. */
  32818. void dragLasso (const MouseEvent& e)
  32819. {
  32820. if (source != 0)
  32821. {
  32822. const int x1 = e.getMouseDownX();
  32823. const int y1 = e.getMouseDownY();
  32824. setBounds (jmin (x1, e.x), jmin (y1, e.y), abs (e.x - x1), abs (e.y - y1));
  32825. setVisible (true);
  32826. Array <SelectableItemType> itemsInLasso;
  32827. source->findLassoItemsInArea (itemsInLasso, getX(), getY(), getWidth(), getHeight());
  32828. if (e.mods.isShiftDown())
  32829. {
  32830. itemsInLasso.removeValuesIn (originalSelection); // to avoid duplicates
  32831. itemsInLasso.addArray (originalSelection);
  32832. }
  32833. else if (e.mods.isCommandDown() || e.mods.isAltDown())
  32834. {
  32835. Array <SelectableItemType> originalMinusNew (originalSelection);
  32836. originalMinusNew.removeValuesIn (itemsInLasso);
  32837. itemsInLasso.removeValuesIn (originalSelection);
  32838. itemsInLasso.addArray (originalMinusNew);
  32839. }
  32840. source->getLassoSelection() = SelectedItemSet <SelectableItemType> (itemsInLasso);
  32841. }
  32842. }
  32843. /** Call this in your mouseUp event, after the lasso has been dragged.
  32844. @see beginLasso, dragLasso
  32845. */
  32846. void endLasso()
  32847. {
  32848. source = 0;
  32849. originalSelection.clear();
  32850. setVisible (false);
  32851. }
  32852. /** A set of colour IDs to use to change the colour of various aspects of the label.
  32853. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  32854. methods.
  32855. Note that you can also use the constants from TextEditor::ColourIds to change the
  32856. colour of the text editor that is opened when a label is editable.
  32857. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  32858. */
  32859. enum ColourIds
  32860. {
  32861. lassoFillColourId = 0x1000440, /**< The colour to fill the lasso rectangle with. */
  32862. lassoOutlineColourId = 0x1000441, /**< The colour to draw the outline with. */
  32863. };
  32864. /** @internal */
  32865. void paint (Graphics& g)
  32866. {
  32867. g.fillAll (findColour (lassoFillColourId));
  32868. g.setColour (findColour (lassoOutlineColourId));
  32869. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  32870. // this suggests that you've left a lasso comp lying around after the
  32871. // mouse drag has finished.. Be careful to call endLasso() when you get a
  32872. // mouse-up event.
  32873. jassert (isMouseButtonDownAnywhere());
  32874. }
  32875. /** @internal */
  32876. bool hitTest (int x, int y) { return false; }
  32877. juce_UseDebuggingNewOperator
  32878. private:
  32879. Array <SelectableItemType> originalSelection;
  32880. LassoSource <SelectableItemType>* source;
  32881. int outlineThickness;
  32882. };
  32883. #endif // __JUCE_LASSOCOMPONENT_JUCEHEADER__
  32884. /********* End of inlined file: juce_LassoComponent.h *********/
  32885. #endif
  32886. #ifndef __JUCE_MOUSECURSOR_JUCEHEADER__
  32887. #endif
  32888. #ifndef __JUCE_MOUSEEVENT_JUCEHEADER__
  32889. #endif
  32890. #ifndef __JUCE_MOUSEHOVERDETECTOR_JUCEHEADER__
  32891. /********* Start of inlined file: juce_MouseHoverDetector.h *********/
  32892. #ifndef __JUCE_MOUSEHOVERDETECTOR_JUCEHEADER__
  32893. #define __JUCE_MOUSEHOVERDETECTOR_JUCEHEADER__
  32894. /**
  32895. Monitors a component for mouse activity, and triggers a callback
  32896. when the mouse hovers in one place for a specified length of time.
  32897. To use a hover-detector, just create one and call its setHoverComponent()
  32898. method to start it watching a component. You can call setHoverComponent (0)
  32899. to make it inactive.
  32900. (Be careful not to delete a component that's being monitored without first
  32901. stopping or deleting the hover detector).
  32902. */
  32903. class JUCE_API MouseHoverDetector
  32904. {
  32905. public:
  32906. /** Creates a hover detector.
  32907. Initially the object is inactive, and you need to tell it which component
  32908. to monitor, using the setHoverComponent() method.
  32909. @param hoverTimeMillisecs the number of milliseconds for which the mouse
  32910. needs to stay still before the mouseHovered() method
  32911. is invoked. You can change this setting later with
  32912. the setHoverTimeMillisecs() method
  32913. */
  32914. MouseHoverDetector (const int hoverTimeMillisecs = 400);
  32915. /** Destructor. */
  32916. virtual ~MouseHoverDetector();
  32917. /** Changes the time for which the mouse has to stay still before it's considered
  32918. to be hovering.
  32919. */
  32920. void setHoverTimeMillisecs (const int newTimeInMillisecs);
  32921. /** Changes the component that's being monitored for hovering.
  32922. Be careful not to delete a component that's being monitored without first
  32923. stopping or deleting the hover detector.
  32924. */
  32925. void setHoverComponent (Component* const newSourceComponent);
  32926. protected:
  32927. /** Called back when the mouse hovers.
  32928. After the mouse has stayed still over the component for the length of time
  32929. specified by setHoverTimeMillisecs(), this method will be invoked.
  32930. When the mouse is first moved after this callback has occurred, the
  32931. mouseMovedAfterHover() method will be called.
  32932. @param mouseX the mouse's X position relative to the component being monitored
  32933. @param mouseY the mouse's Y position relative to the component being monitored
  32934. */
  32935. virtual void mouseHovered (int mouseX,
  32936. int mouseY) = 0;
  32937. /** Called when the mouse is moved away after just having hovered. */
  32938. virtual void mouseMovedAfterHover() = 0;
  32939. private:
  32940. class JUCE_API HoverDetectorInternal : public MouseListener,
  32941. public Timer
  32942. {
  32943. public:
  32944. MouseHoverDetector* owner;
  32945. int lastX, lastY;
  32946. void timerCallback();
  32947. void mouseEnter (const MouseEvent&);
  32948. void mouseExit (const MouseEvent&);
  32949. void mouseDown (const MouseEvent&);
  32950. void mouseUp (const MouseEvent&);
  32951. void mouseMove (const MouseEvent&);
  32952. void mouseWheelMove (const MouseEvent&, float, float);
  32953. } internalTimer;
  32954. friend class HoverDetectorInternal;
  32955. Component* source;
  32956. int hoverTimeMillisecs;
  32957. bool hasJustHovered;
  32958. void hoverTimerCallback();
  32959. void checkJustHoveredCallback();
  32960. };
  32961. #endif // __JUCE_MOUSEHOVERDETECTOR_JUCEHEADER__
  32962. /********* End of inlined file: juce_MouseHoverDetector.h *********/
  32963. #endif
  32964. #ifndef __JUCE_MOUSELISTENER_JUCEHEADER__
  32965. #endif
  32966. #ifndef __JUCE_TOOLTIPCLIENT_JUCEHEADER__
  32967. #endif
  32968. #ifndef __JUCE_COMBOBOX_JUCEHEADER__
  32969. #endif
  32970. #ifndef __JUCE_LABEL_JUCEHEADER__
  32971. #endif
  32972. #ifndef __JUCE_LISTBOX_JUCEHEADER__
  32973. #endif
  32974. #ifndef __JUCE_PROGRESSBAR_JUCEHEADER__
  32975. /********* Start of inlined file: juce_ProgressBar.h *********/
  32976. #ifndef __JUCE_PROGRESSBAR_JUCEHEADER__
  32977. #define __JUCE_PROGRESSBAR_JUCEHEADER__
  32978. /**
  32979. A progress bar component.
  32980. To use this, just create one and make it visible. It'll run its own timer
  32981. to keep an eye on a variable that you give it, and will automatically
  32982. redraw itself when the variable changes.
  32983. For an easy way of running a background task with a dialog box showing its
  32984. progress, see the ThreadWithProgressWindow class.
  32985. @see ThreadWithProgressWindow
  32986. */
  32987. class JUCE_API ProgressBar : public Component,
  32988. public SettableTooltipClient,
  32989. private Timer
  32990. {
  32991. public:
  32992. /** Creates a ProgressBar.
  32993. @param progress pass in a reference to a double that you're going to
  32994. update with your task's progress. The ProgressBar will
  32995. monitor the value of this variable and will redraw itself
  32996. when the value changes. The range is from 0 to 1.0. Obviously
  32997. you'd better be careful not to delete this variable while the
  32998. ProgressBar still exists!
  32999. */
  33000. ProgressBar (double& progress);
  33001. /** Destructor. */
  33002. ~ProgressBar();
  33003. /** Turns the percentage display on or off.
  33004. By default this is on, and the progress bar will display a text string showing
  33005. its current percentage.
  33006. */
  33007. void setPercentageDisplay (const bool shouldDisplayPercentage);
  33008. /** Gives the progress bar a string to display inside it.
  33009. If you call this, it will turn off the percentage display.
  33010. @see setPercentageDisplay
  33011. */
  33012. void setTextToDisplay (const String& text);
  33013. /** A set of colour IDs to use to change the colour of various aspects of the bar.
  33014. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  33015. methods.
  33016. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  33017. */
  33018. enum ColourIds
  33019. {
  33020. backgroundColourId = 0x1001900, /**< The background colour, behind the bar. */
  33021. foregroundColourId = 0x1001a00, /**< The colour to use to draw the bar itself. LookAndFeel
  33022. classes will probably use variations on this colour. */
  33023. };
  33024. juce_UseDebuggingNewOperator
  33025. protected:
  33026. /** @internal */
  33027. void paint (Graphics& g);
  33028. /** @internal */
  33029. void lookAndFeelChanged();
  33030. /** @internal */
  33031. void visibilityChanged();
  33032. /** @internal */
  33033. void colourChanged();
  33034. private:
  33035. double& progress;
  33036. double currentValue;
  33037. bool displayPercentage;
  33038. String displayedMessage, currentMessage;
  33039. void timerCallback();
  33040. ProgressBar (const ProgressBar&);
  33041. const ProgressBar& operator= (const ProgressBar&);
  33042. };
  33043. #endif // __JUCE_PROGRESSBAR_JUCEHEADER__
  33044. /********* End of inlined file: juce_ProgressBar.h *********/
  33045. #endif
  33046. #ifndef __JUCE_SLIDER_JUCEHEADER__
  33047. /********* Start of inlined file: juce_Slider.h *********/
  33048. #ifndef __JUCE_SLIDER_JUCEHEADER__
  33049. #define __JUCE_SLIDER_JUCEHEADER__
  33050. /********* Start of inlined file: juce_SliderListener.h *********/
  33051. #ifndef __JUCE_SLIDERLISTENER_JUCEHEADER__
  33052. #define __JUCE_SLIDERLISTENER_JUCEHEADER__
  33053. class Slider;
  33054. /**
  33055. A class for receiving callbacks from a Slider.
  33056. To be told when a slider's value changes, you can register a SliderListener
  33057. object using Slider::addListener().
  33058. @see Slider::addListener, Slider::removeListener
  33059. */
  33060. class JUCE_API SliderListener
  33061. {
  33062. public:
  33063. /** Destructor. */
  33064. virtual ~SliderListener() {}
  33065. /** Called when the slider's value is changed.
  33066. This may be caused by dragging it, or by typing in its text entry box,
  33067. or by a call to Slider::setValue().
  33068. You can find out the new value using Slider::getValue().
  33069. @see Slider::valueChanged
  33070. */
  33071. virtual void sliderValueChanged (Slider* slider) = 0;
  33072. /** Called when the slider is about to be dragged.
  33073. This is called when a drag begins, then it's followed by multiple calls
  33074. to sliderValueChanged(), and then sliderDragEnded() is called after the
  33075. user lets go.
  33076. @see sliderDragEnded, Slider::startedDragging
  33077. */
  33078. virtual void sliderDragStarted (Slider* slider);
  33079. /** Called after a drag operation has finished.
  33080. @see sliderDragStarted, Slider::stoppedDragging
  33081. */
  33082. virtual void sliderDragEnded (Slider* slider);
  33083. };
  33084. #endif // __JUCE_SLIDERLISTENER_JUCEHEADER__
  33085. /********* End of inlined file: juce_SliderListener.h *********/
  33086. /**
  33087. A slider control for changing a value.
  33088. The slider can be horizontal, vertical, or rotary, and can optionally have
  33089. a text-box inside it to show an editable display of the current value.
  33090. To use it, create a Slider object and use the setSliderStyle() method
  33091. to set up the type you want. To set up the text-entry box, use setTextBoxStyle().
  33092. To define the values that it can be set to, see the setRange() and setValue() methods.
  33093. There are also lots of custom tweaks you can do by subclassing and overriding
  33094. some of the virtual methods, such as changing the scaling, changing the format of
  33095. the text display, custom ways of limiting the values, etc.
  33096. You can register SliderListeners with a slider, which will be informed when the value
  33097. changes, or a subclass can override valueChanged() to be informed synchronously.
  33098. @see SliderListener
  33099. */
  33100. class JUCE_API Slider : public Component,
  33101. public SettableTooltipClient,
  33102. private AsyncUpdater,
  33103. private ButtonListener,
  33104. private LabelListener
  33105. {
  33106. public:
  33107. /** Creates a slider.
  33108. When created, you'll need to set up the slider's style and range with setSliderStyle(),
  33109. setRange(), etc.
  33110. */
  33111. Slider (const String& componentName);
  33112. /** Destructor. */
  33113. ~Slider();
  33114. /** The types of slider available.
  33115. @see setSliderStyle, setRotaryParameters
  33116. */
  33117. enum SliderStyle
  33118. {
  33119. LinearHorizontal, /**< A traditional horizontal slider. */
  33120. LinearVertical, /**< A traditional vertical slider. */
  33121. LinearBar, /**< A horizontal bar slider with the text label drawn on top of it. */
  33122. Rotary, /**< A rotary control that you move by dragging the mouse in a circular motion, like a knob.
  33123. @see setRotaryParameters */
  33124. RotaryHorizontalDrag, /**< A rotary control that you move by dragging the mouse left-to-right.
  33125. @see setRotaryParameters */
  33126. RotaryVerticalDrag, /**< A rotary control that you move by dragging the mouse up-and-down.
  33127. @see setRotaryParameters */
  33128. IncDecButtons, /**< A pair of buttons that increment or decrement the slider's value by the increment set in setRange(). */
  33129. TwoValueHorizontal, /**< A horizontal slider that has two thumbs instead of one, so it can show a minimum and maximum value.
  33130. @see setMinValue, setMaxValue */
  33131. TwoValueVertical, /**< A vertical slider that has two thumbs instead of one, so it can show a minimum and maximum value.
  33132. @see setMinValue, setMaxValue */
  33133. ThreeValueHorizontal, /**< A horizontal slider that has three thumbs instead of one, so it can show a minimum and maximum
  33134. value, with the current value being somewhere between them.
  33135. @see setMinValue, setMaxValue */
  33136. ThreeValueVertical, /**< A vertical slider that has three thumbs instead of one, so it can show a minimum and maximum
  33137. value, with the current value being somewhere between them.
  33138. @see setMinValue, setMaxValue */
  33139. };
  33140. /** Changes the type of slider interface being used.
  33141. @param newStyle the type of interface
  33142. @see setRotaryParameters, setVelocityBasedMode,
  33143. */
  33144. void setSliderStyle (const SliderStyle newStyle);
  33145. /** Returns the slider's current style.
  33146. @see setSliderStyle
  33147. */
  33148. SliderStyle getSliderStyle() const throw() { return style; }
  33149. /** Changes the properties of a rotary slider.
  33150. @param startAngleRadians the angle (in radians, clockwise from the top) at which
  33151. the slider's minimum value is represented
  33152. @param endAngleRadians the angle (in radians, clockwise from the top) at which
  33153. the slider's maximum value is represented. This must be
  33154. greater than startAngleRadians
  33155. @param stopAtEnd if true, then when the slider is dragged around past the
  33156. minimum or maximum, it'll stop there; if false, it'll wrap
  33157. back to the opposite value
  33158. */
  33159. void setRotaryParameters (const float startAngleRadians,
  33160. const float endAngleRadians,
  33161. const bool stopAtEnd);
  33162. /** Sets the distance the mouse has to move to drag the slider across
  33163. the full extent of its range.
  33164. This only applies when in modes like RotaryHorizontalDrag, where it's using
  33165. relative mouse movements to adjust the slider.
  33166. */
  33167. void setMouseDragSensitivity (const int distanceForFullScaleDrag);
  33168. /** Changes the way the the mouse is used when dragging the slider.
  33169. If true, this will turn on velocity-sensitive dragging, so that
  33170. the faster the mouse moves, the bigger the movement to the slider. This
  33171. helps when making accurate adjustments if the slider's range is quite large.
  33172. If false, the slider will just try to snap to wherever the mouse is.
  33173. */
  33174. void setVelocityBasedMode (const bool isVelocityBased) throw();
  33175. /** Changes aspects of the scaling used when in velocity-sensitive mode.
  33176. These apply when you've used setVelocityBasedMode() to turn on velocity mode,
  33177. or if you're holding down ctrl.
  33178. @param sensitivity higher values than 1.0 increase the range of acceleration used
  33179. @param threshold the minimum number of pixels that the mouse needs to move for it
  33180. to be treated as a movement
  33181. @param offset values greater than 0.0 increase the minimum speed that will be used when
  33182. the threshold is reached
  33183. @param userCanPressKeyToSwapMode if true, then the user can hold down the ctrl or command
  33184. key to toggle velocity-sensitive mode
  33185. */
  33186. void setVelocityModeParameters (const double sensitivity = 1.0,
  33187. const int threshold = 1,
  33188. const double offset = 0.0,
  33189. const bool userCanPressKeyToSwapMode = true) throw();
  33190. /** Sets up a skew factor to alter the way values are distributed.
  33191. You may want to use a range of values on the slider where more accuracy
  33192. is required towards one end of the range, so this will logarithmically
  33193. spread the values across the length of the slider.
  33194. If the factor is < 1.0, the lower end of the range will fill more of the
  33195. slider's length; if the factor is > 1.0, the upper end of the range
  33196. will be expanded instead. A factor of 1.0 doesn't skew it at all.
  33197. To set the skew position by using a mid-point, use the setSkewFactorFromMidPoint()
  33198. method instead.
  33199. @see getSkewFactor, setSkewFactorFromMidPoint
  33200. */
  33201. void setSkewFactor (const double factor) throw();
  33202. /** Sets up a skew factor to alter the way values are distributed.
  33203. This allows you to specify the slider value that should appear in the
  33204. centre of the slider's visible range.
  33205. @see setSkewFactor, getSkewFactor
  33206. */
  33207. void setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint) throw();
  33208. /** Returns the current skew factor.
  33209. See setSkewFactor for more info.
  33210. @see setSkewFactor, setSkewFactorFromMidPoint
  33211. */
  33212. double getSkewFactor() const throw() { return skewFactor; }
  33213. /** Used by setIncDecButtonsMode().
  33214. */
  33215. enum IncDecButtonMode
  33216. {
  33217. incDecButtonsNotDraggable,
  33218. incDecButtonsDraggable_AutoDirection,
  33219. incDecButtonsDraggable_Horizontal,
  33220. incDecButtonsDraggable_Vertical
  33221. };
  33222. /** When the style is IncDecButtons, this lets you turn on a mode where the mouse
  33223. can be dragged on the buttons to drag the values.
  33224. By default this is turned off. When enabled, clicking on the buttons still works
  33225. them as normal, but by holding down the mouse on a button and dragging it a little
  33226. distance, it flips into a mode where the value can be dragged. The drag direction can
  33227. either be set explicitly to be vertical or horizontal, or can be set to
  33228. incDecButtonsDraggable_AutoDirection so that it depends on whether the buttons
  33229. are side-by-side or above each other.
  33230. */
  33231. void setIncDecButtonsMode (const IncDecButtonMode mode);
  33232. /** The position of the slider's text-entry box.
  33233. @see setTextBoxStyle
  33234. */
  33235. enum TextEntryBoxPosition
  33236. {
  33237. NoTextBox, /**< Doesn't display a text box. */
  33238. TextBoxLeft, /**< Puts the text box to the left of the slider, vertically centred. */
  33239. TextBoxRight, /**< Puts the text box to the right of the slider, vertically centred. */
  33240. TextBoxAbove, /**< Puts the text box above the slider, horizontally centred. */
  33241. TextBoxBelow /**< Puts the text box below the slider, horizontally centred. */
  33242. };
  33243. /** Changes the location and properties of the text-entry box.
  33244. @param newPosition where it should go (or NoTextBox to not have one at all)
  33245. @param isReadOnly if true, it's a read-only display
  33246. @param textEntryBoxWidth the width of the text-box in pixels. Make sure this leaves enough
  33247. room for the slider as well!
  33248. @param textEntryBoxHeight the height of the text-box in pixels. Make sure this leaves enough
  33249. room for the slider as well!
  33250. @see setTextBoxIsEditable, getValueFromText, getTextFromValue
  33251. */
  33252. void setTextBoxStyle (const TextEntryBoxPosition newPosition,
  33253. const bool isReadOnly,
  33254. const int textEntryBoxWidth,
  33255. const int textEntryBoxHeight);
  33256. /** Returns the status of the text-box.
  33257. @see setTextBoxStyle
  33258. */
  33259. const TextEntryBoxPosition getTextBoxPosition() const throw() { return textBoxPos; }
  33260. /** Returns the width used for the text-box.
  33261. @see setTextBoxStyle
  33262. */
  33263. int getTextBoxWidth() const throw() { return textBoxWidth; }
  33264. /** Returns the height used for the text-box.
  33265. @see setTextBoxStyle
  33266. */
  33267. int getTextBoxHeight() const throw() { return textBoxHeight; }
  33268. /** Makes the text-box editable.
  33269. By default this is true, and the user can enter values into the textbox,
  33270. but it can be turned off if that's not suitable.
  33271. @see setTextBoxStyle, getValueFromText, getTextFromValue
  33272. */
  33273. void setTextBoxIsEditable (const bool shouldBeEditable) throw();
  33274. /** Returns true if the text-box is read-only.
  33275. @see setTextBoxStyle
  33276. */
  33277. bool isTextBoxEditable() const throw() { return editableText; }
  33278. /** If the text-box is editable, this will give it the focus so that the user can
  33279. type directly into it.
  33280. This is basically the effect as the user clicking on it.
  33281. */
  33282. void showTextBox();
  33283. /** If the text-box currently has focus and is being edited, this resets it and takes keyboard
  33284. focus away from it.
  33285. @param discardCurrentEditorContents if true, the slider's value will be left
  33286. unchanged; if false, the current contents of the
  33287. text editor will be used to set the slider position
  33288. before it is hidden.
  33289. */
  33290. void hideTextBox (const bool discardCurrentEditorContents);
  33291. /** Changes the slider's current value.
  33292. This will trigger a callback to SliderListener::sliderValueChanged() for any listeners
  33293. that are registered, and will synchronously call the valueChanged() method in case subclasses
  33294. want to handle it.
  33295. @param newValue the new value to set - this will be restricted by the
  33296. minimum and maximum range, and will be snapped to the
  33297. nearest interval if one has been set
  33298. @param sendUpdateMessage if false, a change to the value will not trigger a call to
  33299. any SliderListeners or the valueChanged() method
  33300. @param sendMessageSynchronously if true, then a call to the SliderListeners will be made
  33301. synchronously; if false, it will be asynchronous
  33302. */
  33303. void setValue (double newValue,
  33304. const bool sendUpdateMessage = true,
  33305. const bool sendMessageSynchronously = false);
  33306. /** Returns the slider's current value. */
  33307. double getValue() const throw();
  33308. /** Sets the limits that the slider's value can take.
  33309. @param newMinimum the lowest value allowed
  33310. @param newMaximum the highest value allowed
  33311. @param newInterval the steps in which the value is allowed to increase - if this
  33312. is not zero, the value will always be (newMinimum + (newInterval * an integer)).
  33313. */
  33314. void setRange (const double newMinimum,
  33315. const double newMaximum,
  33316. const double newInterval = 0);
  33317. /** Returns the current maximum value.
  33318. @see setRange
  33319. */
  33320. double getMaximum() const throw() { return maximum; }
  33321. /** Returns the current minimum value.
  33322. @see setRange
  33323. */
  33324. double getMinimum() const throw() { return minimum; }
  33325. /** Returns the current step-size for values.
  33326. @see setRange
  33327. */
  33328. double getInterval() const throw() { return interval; }
  33329. /** For a slider with two or three thumbs, this returns the lower of its values.
  33330. For a two-value slider, the values are controlled with getMinValue() and getMaxValue().
  33331. A slider with three values also uses the normal getValue() and setValue() methods to
  33332. control the middle value.
  33333. @see setMinValue, getMaxValue, TwoValueHorizontal, TwoValueVertical, ThreeValueHorizontal, ThreeValueVertical
  33334. */
  33335. double getMinValue() const throw();
  33336. /** For a slider with two or three thumbs, this sets the lower of its values.
  33337. This will trigger a callback to SliderListener::sliderValueChanged() for any listeners
  33338. that are registered, and will synchronously call the valueChanged() method in case subclasses
  33339. want to handle it.
  33340. @param newValue the new value to set - this will be restricted by the
  33341. minimum and maximum range, and the max value (in a two-value
  33342. slider) or the mid value (in a three-value slider), and
  33343. will be snapped to the nearest interval if one has been set.
  33344. @param sendUpdateMessage if false, a change to the value will not trigger a call to
  33345. any SliderListeners or the valueChanged() method
  33346. @param sendMessageSynchronously if true, then a call to the SliderListeners will be made
  33347. synchronously; if false, it will be asynchronous
  33348. @see getMinValue, setMaxValue, setValue
  33349. */
  33350. void setMinValue (double newValue,
  33351. const bool sendUpdateMessage = true,
  33352. const bool sendMessageSynchronously = false);
  33353. /** For a slider with two or three thumbs, this returns the higher of its values.
  33354. For a two-value slider, the values are controlled with getMinValue() and getMaxValue().
  33355. A slider with three values also uses the normal getValue() and setValue() methods to
  33356. control the middle value.
  33357. @see getMinValue, TwoValueHorizontal, TwoValueVertical, ThreeValueHorizontal, ThreeValueVertical
  33358. */
  33359. double getMaxValue() const throw();
  33360. /** For a slider with two or three thumbs, this sets the lower of its values.
  33361. This will trigger a callback to SliderListener::sliderValueChanged() for any listeners
  33362. that are registered, and will synchronously call the valueChanged() method in case subclasses
  33363. want to handle it.
  33364. @param newValue the new value to set - this will be restricted by the
  33365. minimum and maximum range, and the max value (in a two-value
  33366. slider) or the mid value (in a three-value slider), and
  33367. will be snapped to the nearest interval if one has been set.
  33368. @param sendUpdateMessage if false, a change to the value will not trigger a call to
  33369. any SliderListeners or the valueChanged() method
  33370. @param sendMessageSynchronously if true, then a call to the SliderListeners will be made
  33371. synchronously; if false, it will be asynchronous
  33372. @see getMaxValue, setMinValue, setValue
  33373. */
  33374. void setMaxValue (double newValue,
  33375. const bool sendUpdateMessage = true,
  33376. const bool sendMessageSynchronously = false);
  33377. /** Adds a listener to be called when this slider's value changes. */
  33378. void addListener (SliderListener* const listener) throw();
  33379. /** Removes a previously-registered listener. */
  33380. void removeListener (SliderListener* const listener) throw();
  33381. /** This lets you choose whether double-clicking moves the slider to a given position.
  33382. By default this is turned off, but it's handy if you want a double-click to act
  33383. as a quick way of resetting a slider. Just pass in the value you want it to
  33384. go to when double-clicked.
  33385. @see getDoubleClickReturnValue
  33386. */
  33387. void setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  33388. const double valueToSetOnDoubleClick) throw();
  33389. /** Returns the values last set by setDoubleClickReturnValue() method.
  33390. Sets isEnabled to true if double-click is enabled, and returns the value
  33391. that was set.
  33392. @see setDoubleClickReturnValue
  33393. */
  33394. double getDoubleClickReturnValue (bool& isEnabled) const throw();
  33395. /** Tells the slider whether to keep sending change messages while the user
  33396. is dragging the slider.
  33397. If set to true, a change message will only be sent when the user has
  33398. dragged the slider and let go. If set to false (the default), then messages
  33399. will be continuously sent as they drag it while the mouse button is still
  33400. held down.
  33401. */
  33402. void setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease) throw();
  33403. /** This lets you change whether the slider thumb jumps to the mouse position
  33404. when you click.
  33405. By default, this is true. If it's false, then the slider moves with relative
  33406. motion when you drag it.
  33407. This only applies to linear bars, and won't affect two- or three- value
  33408. sliders.
  33409. */
  33410. void setSliderSnapsToMousePosition (const bool shouldSnapToMouse) throw();
  33411. /** If enabled, this gives the slider a pop-up bubble which appears while the
  33412. slider is being dragged.
  33413. This can be handy if your slider doesn't have a text-box, so that users can
  33414. see the value just when they're changing it.
  33415. If you pass a component as the parentComponentToUse parameter, the pop-up
  33416. bubble will be added as a child of that component when it's needed. If you
  33417. pass 0, the pop-up will be placed on the desktop instead (note that it's a
  33418. transparent window, so if you're using an OS that can't do transparent windows
  33419. you'll have to add it to a parent component instead).
  33420. */
  33421. void setPopupDisplayEnabled (const bool isEnabled,
  33422. Component* const parentComponentToUse) throw();
  33423. /** If this is set to true, then right-clicking on the slider will pop-up
  33424. a menu to let the user change the way it works.
  33425. By default this is turned off, but when turned on, the menu will include
  33426. things like velocity sensitivity, and for rotary sliders, whether they
  33427. use a linear or rotary mouse-drag to move them.
  33428. */
  33429. void setPopupMenuEnabled (const bool menuEnabled) throw();
  33430. /** This can be used to stop the mouse scroll-wheel from moving the slider.
  33431. By default it's enabled.
  33432. */
  33433. void setScrollWheelEnabled (const bool enabled) throw();
  33434. /** Returns a number to indicate which thumb is currently being dragged by the
  33435. mouse.
  33436. This will return 0 for the main thumb, 1 for the minimum-value thumb, 2 for
  33437. the maximum-value thumb, or -1 if none is currently down.
  33438. */
  33439. int getThumbBeingDragged() const throw() { return sliderBeingDragged; }
  33440. /** Callback to indicate that the user is about to start dragging the slider.
  33441. @see SliderListener::sliderDragStarted
  33442. */
  33443. virtual void startedDragging();
  33444. /** Callback to indicate that the user has just stopped dragging the slider.
  33445. @see SliderListener::sliderDragEnded
  33446. */
  33447. virtual void stoppedDragging();
  33448. /** Callback to indicate that the user has just moved the slider.
  33449. @see SliderListener::sliderValueChanged
  33450. */
  33451. virtual void valueChanged();
  33452. /** Callback to indicate that the user has just moved the slider.
  33453. Note - the valueChanged() method has changed its format and now no longer has
  33454. any parameters. Update your code to use the new version.
  33455. This version has been left here with an int as its return value to cause
  33456. a syntax error if you've got existing code that uses the old version.
  33457. */
  33458. virtual int valueChanged (double) { jassertfalse; return 0; }
  33459. /** Subclasses can override this to convert a text string to a value.
  33460. When the user enters something into the text-entry box, this method is
  33461. called to convert it to a value.
  33462. The default routine just tries to convert it to a double.
  33463. @see getTextFromValue
  33464. */
  33465. virtual double getValueFromText (const String& text);
  33466. /** Turns the slider's current value into a text string.
  33467. Subclasses can override this to customise the formatting of the text-entry box.
  33468. The default implementation just turns the value into a string, using
  33469. a number of decimal places based on the range interval. If a suffix string
  33470. has been set using setTextValueSuffix(), this will be appended to the text.
  33471. @see getValueFromText
  33472. */
  33473. virtual const String getTextFromValue (double value);
  33474. /** Sets a suffix to append to the end of the numeric value when it's displayed as
  33475. a string.
  33476. This is used by the default implementation of getTextFromValue(), and is just
  33477. appended to the numeric value. For more advanced formatting, you can override
  33478. getTextFromValue() and do something else.
  33479. */
  33480. void setTextValueSuffix (const String& suffix);
  33481. /** Allows a user-defined mapping of distance along the slider to its value.
  33482. The default implementation for this performs the skewing operation that
  33483. can be set up in the setSkewFactor() method. Override it if you need
  33484. some kind of custom mapping instead, but make sure you also implement the
  33485. inverse function in valueToProportionOfLength().
  33486. @param proportion a value 0 to 1.0, indicating a distance along the slider
  33487. @returns the slider value that is represented by this position
  33488. @see valueToProportionOfLength
  33489. */
  33490. virtual double proportionOfLengthToValue (double proportion);
  33491. /** Allows a user-defined mapping of value to the position of the slider along its length.
  33492. The default implementation for this performs the skewing operation that
  33493. can be set up in the setSkewFactor() method. Override it if you need
  33494. some kind of custom mapping instead, but make sure you also implement the
  33495. inverse function in proportionOfLengthToValue().
  33496. @param value a valid slider value, between the range of values specified in
  33497. setRange()
  33498. @returns a value 0 to 1.0 indicating the distance along the slider that
  33499. represents this value
  33500. @see proportionOfLengthToValue
  33501. */
  33502. virtual double valueToProportionOfLength (double value);
  33503. /** Returns the X or Y coordinate of a value along the slider's length.
  33504. If the slider is horizontal, this will be the X coordinate of the given
  33505. value, relative to the left of the slider. If it's vertical, then this will
  33506. be the Y coordinate, relative to the top of the slider.
  33507. If the slider is rotary, this will throw an assertion and return 0. If the
  33508. value is out-of-range, it will be constrained to the length of the slider.
  33509. */
  33510. float getPositionOfValue (const double value);
  33511. /** This can be overridden to allow the slider to snap to user-definable values.
  33512. If overridden, it will be called when the user tries to move the slider to
  33513. a given position, and allows a subclass to sanity-check this value, possibly
  33514. returning a different value to use instead.
  33515. @param attemptedValue the value the user is trying to enter
  33516. @param userIsDragging true if the user is dragging with the mouse; false if
  33517. they are entering the value using the text box
  33518. @returns the value to use instead
  33519. */
  33520. virtual double snapValue (double attemptedValue, const bool userIsDragging);
  33521. /** This can be called to force the text box to update its contents.
  33522. (Not normally needed, as this is done automatically).
  33523. */
  33524. void updateText();
  33525. /** True if the slider moves horizontally. */
  33526. bool isHorizontal() const throw();
  33527. /** True if the slider moves vertically. */
  33528. bool isVertical() const throw();
  33529. /** A set of colour IDs to use to change the colour of various aspects of the slider.
  33530. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  33531. methods.
  33532. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  33533. */
  33534. enum ColourIds
  33535. {
  33536. backgroundColourId = 0x1001200, /**< A colour to use to fill the slider's background. */
  33537. thumbColourId = 0x1001300, /**< The colour to draw the thumb with. It's up to the look
  33538. and feel class how this is used. */
  33539. trackColourId = 0x1001310, /**< The colour to draw the groove that the thumb moves along. */
  33540. rotarySliderFillColourId = 0x1001311, /**< For rotary sliders, this colour fills the outer curve. */
  33541. rotarySliderOutlineColourId = 0x1001312, /**< For rotary sliders, this colour is used to draw the outer curve's outline. */
  33542. textBoxTextColourId = 0x1001400, /**< The colour for the text in the text-editor box used for editing the value. */
  33543. textBoxBackgroundColourId = 0x1001500, /**< The background colour for the text-editor box. */
  33544. textBoxHighlightColourId = 0x1001600, /**< The text highlight colour for the text-editor box. */
  33545. textBoxOutlineColourId = 0x1001700 /**< The colour to use for a border around the text-editor box. */
  33546. };
  33547. juce_UseDebuggingNewOperator
  33548. protected:
  33549. /** @internal */
  33550. void labelTextChanged (Label*);
  33551. /** @internal */
  33552. void paint (Graphics& g);
  33553. /** @internal */
  33554. void resized();
  33555. /** @internal */
  33556. void mouseDown (const MouseEvent& e);
  33557. /** @internal */
  33558. void mouseUp (const MouseEvent& e);
  33559. /** @internal */
  33560. void mouseDrag (const MouseEvent& e);
  33561. /** @internal */
  33562. void mouseDoubleClick (const MouseEvent& e);
  33563. /** @internal */
  33564. void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  33565. /** @internal */
  33566. void modifierKeysChanged (const ModifierKeys& modifiers);
  33567. /** @internal */
  33568. void buttonClicked (Button* button);
  33569. /** @internal */
  33570. void lookAndFeelChanged();
  33571. /** @internal */
  33572. void enablementChanged();
  33573. /** @internal */
  33574. void focusOfChildComponentChanged (FocusChangeType cause);
  33575. /** @internal */
  33576. void handleAsyncUpdate();
  33577. /** @internal */
  33578. void colourChanged();
  33579. private:
  33580. SortedSet <void*> listeners;
  33581. double currentValue, valueMin, valueMax;
  33582. double minimum, maximum, interval, doubleClickReturnValue;
  33583. double valueWhenLastDragged, valueOnMouseDown, skewFactor, lastAngle;
  33584. double velocityModeSensitivity, velocityModeOffset, minMaxDiff;
  33585. int velocityModeThreshold;
  33586. float rotaryStart, rotaryEnd;
  33587. int numDecimalPlaces, mouseXWhenLastDragged, mouseYWhenLastDragged;
  33588. int sliderRegionStart, sliderRegionSize;
  33589. int sliderBeingDragged;
  33590. int pixelsForFullDragExtent;
  33591. Rectangle sliderRect;
  33592. String textSuffix;
  33593. SliderStyle style;
  33594. TextEntryBoxPosition textBoxPos;
  33595. int textBoxWidth, textBoxHeight;
  33596. IncDecButtonMode incDecButtonMode;
  33597. bool editableText : 1, doubleClickToValue : 1;
  33598. bool isVelocityBased : 1, userKeyOverridesVelocity : 1, rotaryStop : 1;
  33599. bool incDecButtonsSideBySide : 1, sendChangeOnlyOnRelease : 1, popupDisplayEnabled : 1;
  33600. bool menuEnabled : 1, menuShown : 1, mouseWasHidden : 1, incDecDragged : 1;
  33601. bool scrollWheelEnabled : 1, snapsToMousePos : 1;
  33602. Font font;
  33603. Label* valueBox;
  33604. Button* incButton;
  33605. Button* decButton;
  33606. Component* popupDisplay;
  33607. Component* parentForPopupDisplay;
  33608. float getLinearSliderPos (const double value);
  33609. void restoreMouseIfHidden();
  33610. void sendDragStart();
  33611. void sendDragEnd();
  33612. double constrainedValue (double value) const throw();
  33613. void triggerChangeMessage (const bool synchronous);
  33614. bool incDecDragDirectionIsHorizontal() const throw();
  33615. Slider (const Slider&);
  33616. const Slider& operator= (const Slider&);
  33617. };
  33618. #endif // __JUCE_SLIDER_JUCEHEADER__
  33619. /********* End of inlined file: juce_Slider.h *********/
  33620. #endif
  33621. #ifndef __JUCE_SLIDERLISTENER_JUCEHEADER__
  33622. #endif
  33623. #ifndef __JUCE_TABLEHEADERCOMPONENT_JUCEHEADER__
  33624. /********* Start of inlined file: juce_TableHeaderComponent.h *********/
  33625. #ifndef __JUCE_TABLEHEADERCOMPONENT_JUCEHEADER__
  33626. #define __JUCE_TABLEHEADERCOMPONENT_JUCEHEADER__
  33627. class TableHeaderComponent;
  33628. /**
  33629. Receives events from a TableHeaderComponent when columns are resized, moved, etc.
  33630. You can register one of these objects for table events using TableHeaderComponent::addListener()
  33631. and TableHeaderComponent::removeListener().
  33632. @see TableHeaderComponent
  33633. */
  33634. class JUCE_API TableHeaderListener
  33635. {
  33636. public:
  33637. TableHeaderListener() {}
  33638. /** Destructor. */
  33639. virtual ~TableHeaderListener() {}
  33640. /** This is called when some of the table's columns are added, removed, hidden,
  33641. or rearranged.
  33642. */
  33643. virtual void tableColumnsChanged (TableHeaderComponent* tableHeader) = 0;
  33644. /** This is called when one or more of the table's columns are resized.
  33645. */
  33646. virtual void tableColumnsResized (TableHeaderComponent* tableHeader) = 0;
  33647. /** This is called when the column by which the table should be sorted is changed.
  33648. */
  33649. virtual void tableSortOrderChanged (TableHeaderComponent* tableHeader) = 0;
  33650. /** This is called when the user begins or ends dragging one of the columns around.
  33651. When the user starts dragging a column, this is called with the ID of that
  33652. column. When they finish dragging, it is called again with 0 as the ID.
  33653. */
  33654. virtual void tableColumnDraggingChanged (TableHeaderComponent* tableHeader,
  33655. int columnIdNowBeingDragged);
  33656. };
  33657. /**
  33658. A component that displays a strip of column headings for a table, and allows these
  33659. to be resized, dragged around, etc.
  33660. This is just the component that goes at the top of a table. You can use it
  33661. directly for custom components, or to create a simple table, use the
  33662. TableListBox class.
  33663. To use one of these, create it and use addColumn() to add all the columns that you need.
  33664. Each column must be given a unique ID number that's used to refer to it.
  33665. @see TableListBox, TableHeaderListener
  33666. */
  33667. class JUCE_API TableHeaderComponent : public Component,
  33668. private AsyncUpdater
  33669. {
  33670. public:
  33671. /** Creates an empty table header.
  33672. */
  33673. TableHeaderComponent();
  33674. /** Destructor. */
  33675. ~TableHeaderComponent();
  33676. /** A combination of these flags are passed into the addColumn() method to specify
  33677. the properties of a column.
  33678. */
  33679. enum ColumnPropertyFlags
  33680. {
  33681. visible = 1, /**< If this is set, the column will be shown; if not, it will be hidden until the user enables it with the pop-up menu. */
  33682. resizable = 2, /**< If this is set, the column can be resized by dragging it. */
  33683. draggable = 4, /**< If this is set, the column can be dragged around to change its order in the table. */
  33684. appearsOnColumnMenu = 8, /**< If this is set, the column will be shown on the pop-up menu allowing it to be hidden/shown. */
  33685. sortable = 16, /**< If this is set, then clicking on the column header will set it to be the sort column, and clicking again will reverse the order. */
  33686. sortedForwards = 32, /**< If this is set, the column is currently the one by which the table is sorted (forwards). */
  33687. sortedBackwards = 64, /**< If this is set, the column is currently the one by which the table is sorted (backwards). */
  33688. /** This set of default flags is used as the default parameter value in addColumn(). */
  33689. defaultFlags = (visible | resizable | draggable | appearsOnColumnMenu | sortable),
  33690. /** A quick way of combining flags for a column that's not resizable. */
  33691. notResizable = (visible | draggable | appearsOnColumnMenu | sortable),
  33692. /** A quick way of combining flags for a column that's not resizable or sortable. */
  33693. notResizableOrSortable = (visible | draggable | appearsOnColumnMenu),
  33694. /** A quick way of combining flags for a column that's not sortable. */
  33695. notSortable = (visible | resizable | draggable | appearsOnColumnMenu)
  33696. };
  33697. /** Adds a column to the table.
  33698. This will add a column, and asynchronously call the tableColumnsChanged() method of any
  33699. registered listeners.
  33700. @param columnName the name of the new column. It's ok to have two or more columns with the same name
  33701. @param columnId an ID for this column. The ID can be any number apart from 0, but every column must have
  33702. a unique ID. This is used to identify the column later on, after the user may have
  33703. changed the order that they appear in
  33704. @param width the initial width of the column, in pixels
  33705. @param maximumWidth a maximum width that the column can take when the user is resizing it. This only applies
  33706. if the 'resizable' flag is specified for this column
  33707. @param minimumWidth a minimum width that the column can take when the user is resizing it. This only applies
  33708. if the 'resizable' flag is specified for this column
  33709. @param propertyFlags a combination of some of the values from the ColumnPropertyFlags enum, to define the
  33710. properties of this column
  33711. @param insertIndex the index at which the column should be added. A value of 0 puts it at the start (left-hand side)
  33712. and -1 puts it at the end (right-hand size) of the table. Note that the index the index within
  33713. all columns, not just the index amongst those that are currently visible
  33714. */
  33715. void addColumn (const String& columnName,
  33716. const int columnId,
  33717. const int width,
  33718. const int minimumWidth = 30,
  33719. const int maximumWidth = -1,
  33720. const int propertyFlags = defaultFlags,
  33721. const int insertIndex = -1);
  33722. /** Removes a column with the given ID.
  33723. If there is such a column, this will asynchronously call the tableColumnsChanged() method of any
  33724. registered listeners.
  33725. */
  33726. void removeColumn (const int columnIdToRemove);
  33727. /** Deletes all columns from the table.
  33728. If there are any columns to remove, this will asynchronously call the tableColumnsChanged() method of any
  33729. registered listeners.
  33730. */
  33731. void removeAllColumns();
  33732. /** Returns the number of columns in the table.
  33733. If onlyCountVisibleColumns is true, this will return the number of visible columns; otherwise it'll
  33734. return the total number of columns, including hidden ones.
  33735. @see isColumnVisible
  33736. */
  33737. int getNumColumns (const bool onlyCountVisibleColumns) const throw();
  33738. /** Returns the name for a column.
  33739. @see setColumnName
  33740. */
  33741. const String getColumnName (const int columnId) const throw();
  33742. /** Changes the name of a column. */
  33743. void setColumnName (const int columnId, const String& newName);
  33744. /** Moves a column to a different index in the table.
  33745. @param columnId the column to move
  33746. @param newVisibleIndex the target index for it, from 0 to the number of columns currently visible.
  33747. */
  33748. void moveColumn (const int columnId, int newVisibleIndex);
  33749. /** Changes the width of a column.
  33750. This will cause an asynchronous callback to the tableColumnsResized() method of any registered listeners.
  33751. */
  33752. void setColumnWidth (const int columnId, const int newWidth);
  33753. /** Shows or hides a column.
  33754. This can cause an asynchronous callback to the tableColumnsChanged() method of any registered listeners.
  33755. @see isColumnVisible
  33756. */
  33757. void setColumnVisible (const int columnId, const bool shouldBeVisible);
  33758. /** Returns true if this column is currently visible.
  33759. @see setColumnVisible
  33760. */
  33761. bool isColumnVisible (const int columnId) const;
  33762. /** Changes the column which is the sort column.
  33763. This can cause an asynchronous callback to the tableSortOrderChanged() method of any registered listeners.
  33764. If this method doesn't actually change the column ID, then no re-sort will take place (you can
  33765. call reSortTable() to force a re-sort to happen if you've modified the table's contents).
  33766. @see getSortColumnId, isSortedForwards, reSortTable
  33767. */
  33768. void setSortColumnId (const int columnId, const bool sortForwards);
  33769. /** Returns the column ID by which the table is currently sorted, or 0 if it is unsorted.
  33770. @see setSortColumnId, isSortedForwards
  33771. */
  33772. int getSortColumnId() const throw();
  33773. /** Returns true if the table is currently sorted forwards, or false if it's backwards.
  33774. @see setSortColumnId
  33775. */
  33776. bool isSortedForwards() const throw();
  33777. /** Triggers a re-sort of the table according to the current sort-column.
  33778. If you modifiy the table's contents, you can call this to signal that the table needs
  33779. to be re-sorted.
  33780. (This doesn't do any sorting synchronously - it just asynchronously sends a call to the
  33781. tableSortOrderChanged() method of any listeners).
  33782. */
  33783. void reSortTable();
  33784. /** Returns the total width of all the visible columns in the table.
  33785. */
  33786. int getTotalWidth() const throw();
  33787. /** Returns the index of a given column.
  33788. If there's no such column ID, this will return -1.
  33789. If onlyCountVisibleColumns is true, this will return the index amoungst the visible columns;
  33790. otherwise it'll return the index amongst all the columns, including any hidden ones.
  33791. */
  33792. int getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const throw();
  33793. /** Returns the ID of the column at a given index.
  33794. If onlyCountVisibleColumns is true, this will count the index amoungst the visible columns;
  33795. otherwise it'll count it amongst all the columns, including any hidden ones.
  33796. If the index is out-of-range, it'll return 0.
  33797. */
  33798. int getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const throw();
  33799. /** Returns the rectangle containing of one of the columns.
  33800. The index is an index from 0 to the number of columns that are currently visible (hidden
  33801. ones are not counted). It returns a rectangle showing the position of the column relative
  33802. to this component's top-left. If the index is out-of-range, an empty rectangle is retrurned.
  33803. */
  33804. const Rectangle getColumnPosition (const int index) const throw();
  33805. /** Finds the column ID at a given x-position in the component.
  33806. If there is a column at this point this returns its ID, or if not, it will return 0.
  33807. */
  33808. int getColumnIdAtX (const int xToFind) const throw();
  33809. /** If set to true, this indicates that the columns should be expanded or shrunk to fill the
  33810. entire width of the component.
  33811. By default this is disabled. Turning it on also means that when resizing a column, those
  33812. on the right will be squashed to fit.
  33813. */
  33814. void setStretchToFitActive (const bool shouldStretchToFit);
  33815. /** Returns true if stretch-to-fit has been enabled.
  33816. @see setStretchToFitActive
  33817. */
  33818. bool isStretchToFitActive() const throw();
  33819. /** If stretch-to-fit is enabled, this will resize all the columns to make them fit into the
  33820. specified width, keeping their relative proportions the same.
  33821. If the minimum widths of the columns are too wide to fit into this space, it may
  33822. actually end up wider.
  33823. */
  33824. void resizeAllColumnsToFit (int targetTotalWidth);
  33825. /** Enables or disables the pop-up menu.
  33826. The default menu allows the user to show or hide columns. You can add custom
  33827. items to this menu by overloading the addMenuItems() and reactToMenuItem() methods.
  33828. By default the menu is enabled.
  33829. @see isPopupMenuActive, addMenuItems, reactToMenuItem
  33830. */
  33831. void setPopupMenuActive (const bool hasMenu);
  33832. /** Returns true if the pop-up menu is enabled.
  33833. @see setPopupMenuActive
  33834. */
  33835. bool isPopupMenuActive() const throw();
  33836. /** Returns a string that encapsulates the table's current layout.
  33837. This can be restored later using restoreFromString(). It saves the order of
  33838. the columns, the currently-sorted column, and the widths.
  33839. @see restoreFromString
  33840. */
  33841. const String toString() const;
  33842. /** Restores the state of the table, based on a string previously created with
  33843. toString().
  33844. @see toString
  33845. */
  33846. void restoreFromString (const String& storedVersion);
  33847. /** Adds a listener to be informed about things that happen to the header. */
  33848. void addListener (TableHeaderListener* const newListener) throw();
  33849. /** Removes a previously-registered listener. */
  33850. void removeListener (TableHeaderListener* const listenerToRemove) throw();
  33851. /** This can be overridden to handle a mouse-click on one of the column headers.
  33852. The default implementation will use this click to call getSortColumnId() and
  33853. change the sort order.
  33854. */
  33855. virtual void columnClicked (int columnId, const ModifierKeys& mods);
  33856. /** This can be overridden to add custom items to the pop-up menu.
  33857. If you override this, you should call the superclass's method to add its
  33858. column show/hide items, if you want them on the menu as well.
  33859. Then to handle the result, override reactToMenuItem().
  33860. @see reactToMenuItem
  33861. */
  33862. virtual void addMenuItems (PopupMenu& menu, const int columnIdClicked);
  33863. /** Override this to handle any custom items that you have added to the
  33864. pop-up menu with an addMenuItems() override.
  33865. If the menuReturnId isn't one of your own custom menu items, you'll need to
  33866. call TableHeaderComponent::reactToMenuItem() to allow the base class to
  33867. handle the items that it had added.
  33868. @see addMenuItems
  33869. */
  33870. virtual void reactToMenuItem (const int menuReturnId, const int columnIdClicked);
  33871. /** @internal */
  33872. void paint (Graphics& g);
  33873. /** @internal */
  33874. void resized();
  33875. /** @internal */
  33876. void mouseMove (const MouseEvent&);
  33877. /** @internal */
  33878. void mouseEnter (const MouseEvent&);
  33879. /** @internal */
  33880. void mouseExit (const MouseEvent&);
  33881. /** @internal */
  33882. void mouseDown (const MouseEvent&);
  33883. /** @internal */
  33884. void mouseDrag (const MouseEvent&);
  33885. /** @internal */
  33886. void mouseUp (const MouseEvent&);
  33887. /** @internal */
  33888. const MouseCursor getMouseCursor();
  33889. juce_UseDebuggingNewOperator
  33890. private:
  33891. struct ColumnInfo
  33892. {
  33893. String name;
  33894. int id, propertyFlags, width, minimumWidth, maximumWidth;
  33895. double lastDeliberateWidth;
  33896. bool isVisible() const throw();
  33897. };
  33898. OwnedArray <ColumnInfo> columns;
  33899. Array <TableHeaderListener*> listeners;
  33900. Component* dragOverlayComp;
  33901. bool columnsChanged, columnsResized, sortChanged, menuActive, stretchToFit;
  33902. int columnIdBeingResized, columnIdBeingDragged, initialColumnWidth;
  33903. int columnIdUnderMouse, draggingColumnOffset, draggingColumnOriginalIndex, lastDeliberateWidth;
  33904. ColumnInfo* getInfoForId (const int columnId) const throw();
  33905. int visibleIndexToTotalIndex (const int visibleIndex) const throw();
  33906. void sendColumnsChanged();
  33907. void handleAsyncUpdate();
  33908. void beginDrag (const MouseEvent&);
  33909. void endDrag (const int finalIndex);
  33910. int getResizeDraggerAt (const int mouseX) const throw();
  33911. void updateColumnUnderMouse (int x, int y);
  33912. void showColumnChooserMenu (const int);
  33913. void resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth);
  33914. TableHeaderComponent (const TableHeaderComponent&);
  33915. const TableHeaderComponent operator= (const TableHeaderComponent&);
  33916. };
  33917. #endif // __JUCE_TABLEHEADERCOMPONENT_JUCEHEADER__
  33918. /********* End of inlined file: juce_TableHeaderComponent.h *********/
  33919. #endif
  33920. #ifndef __JUCE_TABLELISTBOX_JUCEHEADER__
  33921. /********* Start of inlined file: juce_TableListBox.h *********/
  33922. #ifndef __JUCE_TABLELISTBOX_JUCEHEADER__
  33923. #define __JUCE_TABLELISTBOX_JUCEHEADER__
  33924. /**
  33925. One of these is used by a TableListBox as the data model for the table's contents.
  33926. The virtual methods that you override in this class take care of drawing the
  33927. table cells, and reacting to events.
  33928. @see TableListBox
  33929. */
  33930. class JUCE_API TableListBoxModel
  33931. {
  33932. public:
  33933. TableListBoxModel() {}
  33934. /** Destructor. */
  33935. virtual ~TableListBoxModel() {}
  33936. /** This must return the number of rows currently in the table.
  33937. If the number of rows changes, you must call TableListBox::updateContent() to
  33938. cause it to refresh the list.
  33939. */
  33940. virtual int getNumRows() = 0;
  33941. /** This must draw the background behind one of the rows in the table.
  33942. The graphics context has its origin at the row's top-left, and your method
  33943. should fill the area specified by the width and height parameters.
  33944. */
  33945. virtual void paintRowBackground (Graphics& g,
  33946. int rowNumber,
  33947. int width, int height,
  33948. bool rowIsSelected) = 0;
  33949. /** This must draw one of the cells.
  33950. The graphics context's origin will already be set to the top-left of the cell,
  33951. whose size is specified by (width, height).
  33952. */
  33953. virtual void paintCell (Graphics& g,
  33954. int rowNumber,
  33955. int columnId,
  33956. int width, int height,
  33957. bool rowIsSelected) = 0;
  33958. /** This is used to create or update a custom component to go in a cell.
  33959. Any cell may contain a custom component, or can just be drawn with the paintCell() method
  33960. and handle mouse clicks with cellClicked().
  33961. This method will be called whenever a custom component might need to be updated - e.g.
  33962. when the table is changed, or TableListBox::updateContent() is called.
  33963. If you don't need a custom component for the specified cell, then return 0.
  33964. If you do want a custom component, and the existingComponentToUpdate is null, then
  33965. this method must create a new component suitable for the cell, and return it.
  33966. If the existingComponentToUpdate is non-null, it will be a pointer to a component previously created
  33967. by this method. In this case, the method must either update it to make sure it's correctly representing
  33968. the given cell (which may be different from the one that the component was created for), or it can
  33969. delete this component and return a new one.
  33970. */
  33971. virtual Component* refreshComponentForCell (int rowNumber, int columnId, bool isRowSelected,
  33972. Component* existingComponentToUpdate);
  33973. /** This callback is made when the user clicks on one of the cells in the table.
  33974. The mouse event's coordinates will be relative to the entire table row.
  33975. @see cellDoubleClicked, backgroundClicked
  33976. */
  33977. virtual void cellClicked (int rowNumber, int columnId, const MouseEvent& e);
  33978. /** This callback is made when the user clicks on one of the cells in the table.
  33979. The mouse event's coordinates will be relative to the entire table row.
  33980. @see cellClicked, backgroundClicked
  33981. */
  33982. virtual void cellDoubleClicked (int rowNumber, int columnId, const MouseEvent& e);
  33983. /** This can be overridden to react to the user double-clicking on a part of the list where
  33984. there are no rows.
  33985. @see cellClicked
  33986. */
  33987. virtual void backgroundClicked();
  33988. /** This callback is made when the table's sort order is changed.
  33989. This could be because the user has clicked a column header, or because the
  33990. TableHeaderComponent::setSortColumnId() method was called.
  33991. If you implement this, your method should re-sort the table using the given
  33992. column as the key.
  33993. */
  33994. virtual void sortOrderChanged (int newSortColumnId, const bool isForwards);
  33995. /** Returns the best width for one of the columns.
  33996. If you implement this method, you should measure the width of all the items
  33997. in this column, and return the best size.
  33998. Returning 0 means that the column shouldn't be changed.
  33999. This is used by TableListBox::autoSizeColumn() and TableListBox::autoSizeAllColumns().
  34000. */
  34001. virtual int getColumnAutoSizeWidth (int columnId);
  34002. /** Override this to be informed when rows are selected or deselected.
  34003. @see ListBox::selectedRowsChanged()
  34004. */
  34005. virtual void selectedRowsChanged (int lastRowSelected);
  34006. /** Override this to be informed when the delete key is pressed.
  34007. @see ListBox::deleteKeyPressed()
  34008. */
  34009. virtual void deleteKeyPressed (int lastRowSelected);
  34010. /** Override this to be informed when the return key is pressed.
  34011. @see ListBox::returnKeyPressed()
  34012. */
  34013. virtual void returnKeyPressed (int lastRowSelected);
  34014. /** Override this to be informed when the list is scrolled.
  34015. This might be caused by the user moving the scrollbar, or by programmatic changes
  34016. to the list position.
  34017. */
  34018. virtual void listWasScrolled();
  34019. /** To allow rows from your table to be dragged-and-dropped, implement this method.
  34020. If this returns a non-empty name then when the user drags a row, the table will try to
  34021. find a DragAndDropContainer in its parent hierarchy, and will use it to trigger a
  34022. drag-and-drop operation, using this string as the source description, and the listbox
  34023. itself as the source component.
  34024. @see DragAndDropContainer::startDragging
  34025. */
  34026. virtual const String getDragSourceDescription (const SparseSet<int>& currentlySelectedRows);
  34027. };
  34028. /**
  34029. A table of cells, using a TableHeaderComponent as its header.
  34030. This component makes it easy to create a table by providing a TableListBoxModel as
  34031. the data source.
  34032. @see TableListBoxModel, TableHeaderComponent
  34033. */
  34034. class JUCE_API TableListBox : public ListBox,
  34035. private ListBoxModel,
  34036. private TableHeaderListener
  34037. {
  34038. public:
  34039. /** Creates a TableListBox.
  34040. The model pointer passed-in can be null, in which case you can set it later
  34041. with setModel().
  34042. */
  34043. TableListBox (const String& componentName,
  34044. TableListBoxModel* const model);
  34045. /** Destructor. */
  34046. ~TableListBox();
  34047. /** Changes the TableListBoxModel that is being used for this table.
  34048. */
  34049. void setModel (TableListBoxModel* const newModel);
  34050. /** Returns the model currently in use. */
  34051. TableListBoxModel* getModel() const throw() { return model; }
  34052. /** Returns the header component being used in this table. */
  34053. TableHeaderComponent* getHeader() const throw() { return header; }
  34054. /** Changes the height of the table header component.
  34055. @see getHeaderHeight
  34056. */
  34057. void setHeaderHeight (const int newHeight);
  34058. /** Returns the height of the table header.
  34059. @see setHeaderHeight
  34060. */
  34061. int getHeaderHeight() const throw();
  34062. /** Resizes a column to fit its contents.
  34063. This uses TableListBoxModel::getColumnAutoSizeWidth() to find the best width,
  34064. and applies that to the column.
  34065. @see autoSizeAllColumns, TableHeaderComponent::setColumnWidth
  34066. */
  34067. void autoSizeColumn (const int columnId);
  34068. /** Calls autoSizeColumn() for all columns in the table. */
  34069. void autoSizeAllColumns();
  34070. /** Enables or disables the auto size options on the popup menu.
  34071. By default, these are enabled.
  34072. */
  34073. void setAutoSizeMenuOptionShown (const bool shouldBeShown);
  34074. /** True if the auto-size options should be shown on the menu.
  34075. @see setAutoSizeMenuOptionsShown
  34076. */
  34077. bool isAutoSizeMenuOptionShown() const throw();
  34078. /** Returns the position of one of the cells in the table.
  34079. If relativeToComponentTopLeft is true, the co-ordinates are relative to
  34080. the table component's top-left. The row number isn't checked to see if it's
  34081. in-range, but the column ID must exist or this will return an empty rectangle.
  34082. If relativeToComponentTopLeft is false, the co-ords are relative to the
  34083. top-left of the table's top-left cell.
  34084. */
  34085. const Rectangle getCellPosition (const int columnId,
  34086. const int rowNumber,
  34087. const bool relativeToComponentTopLeft) const;
  34088. /** Scrolls horizontally if necessary to make sure that a particular column is visible.
  34089. @see ListBox::scrollToEnsureRowIsOnscreen
  34090. */
  34091. void scrollToEnsureColumnIsOnscreen (const int columnId);
  34092. /** @internal */
  34093. int getNumRows();
  34094. /** @internal */
  34095. void paintListBoxItem (int, Graphics&, int, int, bool);
  34096. /** @internal */
  34097. Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate);
  34098. /** @internal */
  34099. void selectedRowsChanged (int lastRowSelected);
  34100. /** @internal */
  34101. void deleteKeyPressed (int currentSelectedRow);
  34102. /** @internal */
  34103. void returnKeyPressed (int currentSelectedRow);
  34104. /** @internal */
  34105. void backgroundClicked();
  34106. /** @internal */
  34107. void listWasScrolled();
  34108. /** @internal */
  34109. void tableColumnsChanged (TableHeaderComponent*);
  34110. /** @internal */
  34111. void tableColumnsResized (TableHeaderComponent*);
  34112. /** @internal */
  34113. void tableSortOrderChanged (TableHeaderComponent*);
  34114. /** @internal */
  34115. void tableColumnDraggingChanged (TableHeaderComponent*, int);
  34116. /** @internal */
  34117. void resized();
  34118. juce_UseDebuggingNewOperator
  34119. private:
  34120. TableHeaderComponent* header;
  34121. TableListBoxModel* model;
  34122. int columnIdNowBeingDragged;
  34123. bool autoSizeOptionsShown;
  34124. void updateColumnComponents() const;
  34125. TableListBox (const TableListBox&);
  34126. const TableListBox& operator= (const TableListBox&);
  34127. };
  34128. #endif // __JUCE_TABLELISTBOX_JUCEHEADER__
  34129. /********* End of inlined file: juce_TableListBox.h *********/
  34130. #endif
  34131. #ifndef __JUCE_TEXTEDITOR_JUCEHEADER__
  34132. #endif
  34133. #ifndef __JUCE_TOOLBAR_JUCEHEADER__
  34134. #endif
  34135. #ifndef __JUCE_TOOLBARITEMCOMPONENT_JUCEHEADER__
  34136. #endif
  34137. #ifndef __JUCE_TOOLBARITEMFACTORY_JUCEHEADER__
  34138. /********* Start of inlined file: juce_ToolbarItemFactory.h *********/
  34139. #ifndef __JUCE_TOOLBARITEMFACTORY_JUCEHEADER__
  34140. #define __JUCE_TOOLBARITEMFACTORY_JUCEHEADER__
  34141. /**
  34142. A factory object which can create ToolbarItemComponent objects.
  34143. A subclass of ToolbarItemFactory publishes a set of types of toolbar item
  34144. that it can create.
  34145. Each type of item is identified by a unique ID, and multiple instances of an
  34146. item type can exist at once (even on the same toolbar, e.g. spacers or separator
  34147. bars).
  34148. @see Toolbar, ToolbarItemComponent, ToolbarButton
  34149. */
  34150. class JUCE_API ToolbarItemFactory
  34151. {
  34152. public:
  34153. ToolbarItemFactory();
  34154. /** Destructor. */
  34155. virtual ~ToolbarItemFactory();
  34156. /** A set of reserved item ID values, used for the built-in item types.
  34157. */
  34158. enum SpecialItemIds
  34159. {
  34160. separatorBarId = -1, /**< The item ID for a vertical (or horizontal) separator bar that
  34161. can be placed between sets of items to break them into groups. */
  34162. spacerId = -2, /**< The item ID for a fixed-width space that can be placed between
  34163. items.*/
  34164. flexibleSpacerId = -3 /**< The item ID for a gap that pushes outwards against the things on
  34165. either side of it, filling any available space. */
  34166. };
  34167. /** Must return a list of the IDs for all the item types that this factory can create.
  34168. The ids should be added to the array that is passed-in.
  34169. An item ID can be any integer you choose, except for 0, which is considered a null ID,
  34170. and the predefined IDs in the SpecialItemIds enum.
  34171. You should also add the built-in types (separatorBarId, spacerId and flexibleSpacerId)
  34172. to this list if you want your toolbar to be able to contain those items.
  34173. The list returned here is used by the ToolbarItemPalette class to obtain its list
  34174. of available items, and their order on the palette will reflect the order in which
  34175. they appear on this list.
  34176. @see ToolbarItemPalette
  34177. */
  34178. virtual void getAllToolbarItemIds (Array <int>& ids) = 0;
  34179. /** Must return the set of items that should be added to a toolbar as its default set.
  34180. This method is used by Toolbar::addDefaultItems() to determine which items to
  34181. create.
  34182. The items that your method adds to the array that is passed-in will be added to the
  34183. toolbar in the same order. Items can appear in the list more than once.
  34184. */
  34185. virtual void getDefaultItemSet (Array <int>& ids) = 0;
  34186. /** Must create an instance of one of the items that the factory lists in its
  34187. getAllToolbarItemIds() method.
  34188. The itemId parameter can be any of the values listed by your getAllToolbarItemIds()
  34189. method, except for the built-in item types from the SpecialItemIds enum, which
  34190. are created internally by the toolbar code.
  34191. Try not to keep a pointer to the object that is returned, as it will be deleted
  34192. automatically by the toolbar, and remember that multiple instances of the same
  34193. item type are likely to exist at the same time.
  34194. */
  34195. virtual ToolbarItemComponent* createItem (const int itemId) = 0;
  34196. };
  34197. #endif // __JUCE_TOOLBARITEMFACTORY_JUCEHEADER__
  34198. /********* End of inlined file: juce_ToolbarItemFactory.h *********/
  34199. #endif
  34200. #ifndef __JUCE_TOOLBARITEMPALETTE_JUCEHEADER__
  34201. /********* Start of inlined file: juce_ToolbarItemPalette.h *********/
  34202. #ifndef __JUCE_TOOLBARITEMPALETTE_JUCEHEADER__
  34203. #define __JUCE_TOOLBARITEMPALETTE_JUCEHEADER__
  34204. /**
  34205. A component containing a list of toolbar items, which the user can drag onto
  34206. a toolbar to add them.
  34207. You can use this class directly, but it's a lot easier to call Toolbar::showCustomisationDialog(),
  34208. which automatically shows one of these in a dialog box with lots of extra controls.
  34209. @see Toolbar
  34210. */
  34211. class JUCE_API ToolbarItemPalette : public Component,
  34212. public DragAndDropContainer
  34213. {
  34214. public:
  34215. /** Creates a palette of items for a given factory, with the aim of adding them
  34216. to the specified toolbar.
  34217. The ToolbarItemFactory::getAllToolbarItemIds() method is used to create the
  34218. set of items that are shown in this palette.
  34219. The toolbar and factory must not be deleted while this object exists.
  34220. */
  34221. ToolbarItemPalette (ToolbarItemFactory& factory,
  34222. Toolbar* const toolbar);
  34223. /** Destructor. */
  34224. ~ToolbarItemPalette();
  34225. /** @internal */
  34226. void resized();
  34227. juce_UseDebuggingNewOperator
  34228. private:
  34229. ToolbarItemFactory& factory;
  34230. Toolbar* toolbar;
  34231. Viewport* viewport;
  34232. friend class Toolbar;
  34233. void replaceComponent (ToolbarItemComponent* const comp);
  34234. ToolbarItemPalette (const ToolbarItemPalette&);
  34235. const ToolbarItemPalette& operator= (const ToolbarItemPalette&);
  34236. };
  34237. #endif // __JUCE_TOOLBARITEMPALETTE_JUCEHEADER__
  34238. /********* End of inlined file: juce_ToolbarItemPalette.h *********/
  34239. #endif
  34240. #ifndef __JUCE_TREEVIEW_JUCEHEADER__
  34241. #endif
  34242. #ifndef __JUCE_BOOLEANPROPERTYCOMPONENT_JUCEHEADER__
  34243. /********* Start of inlined file: juce_BooleanPropertyComponent.h *********/
  34244. #ifndef __JUCE_BOOLEANPROPERTYCOMPONENT_JUCEHEADER__
  34245. #define __JUCE_BOOLEANPROPERTYCOMPONENT_JUCEHEADER__
  34246. /**
  34247. A PropertyComponent that contains an on/off toggle button.
  34248. This type of property component can be used if you have a boolean value to
  34249. toggle on/off.
  34250. @see PropertyComponent
  34251. */
  34252. class JUCE_API BooleanPropertyComponent : public PropertyComponent,
  34253. private ButtonListener
  34254. {
  34255. public:
  34256. /** Creates a button component.
  34257. @param propertyName the property name to be passed to the PropertyComponent
  34258. @param buttonTextWhenTrue the text shown in the button when the value is true
  34259. @param buttonTextWhenFalse the text shown in the button when the value is false
  34260. */
  34261. BooleanPropertyComponent (const String& propertyName,
  34262. const String& buttonTextWhenTrue,
  34263. const String& buttonTextWhenFalse);
  34264. /** Destructor. */
  34265. ~BooleanPropertyComponent();
  34266. /** Called to change the state of the boolean value. */
  34267. virtual void setState (const bool newState) = 0;
  34268. /** Must return the current value of the property. */
  34269. virtual bool getState() const = 0;
  34270. /** @internal */
  34271. void paint (Graphics& g);
  34272. /** @internal */
  34273. void refresh();
  34274. /** @internal */
  34275. void buttonClicked (Button*);
  34276. juce_UseDebuggingNewOperator
  34277. private:
  34278. ToggleButton* button;
  34279. String onText, offText;
  34280. };
  34281. #endif // __JUCE_BOOLEANPROPERTYCOMPONENT_JUCEHEADER__
  34282. /********* End of inlined file: juce_BooleanPropertyComponent.h *********/
  34283. #endif
  34284. #ifndef __JUCE_BUTTONPROPERTYCOMPONENT_JUCEHEADER__
  34285. /********* Start of inlined file: juce_ButtonPropertyComponent.h *********/
  34286. #ifndef __JUCE_BUTTONPROPERTYCOMPONENT_JUCEHEADER__
  34287. #define __JUCE_BUTTONPROPERTYCOMPONENT_JUCEHEADER__
  34288. /**
  34289. A PropertyComponent that contains a button.
  34290. This type of property component can be used if you need a button to trigger some
  34291. kind of action.
  34292. @see PropertyComponent
  34293. */
  34294. class JUCE_API ButtonPropertyComponent : public PropertyComponent,
  34295. private ButtonListener
  34296. {
  34297. public:
  34298. /** Creates a button component.
  34299. @param propertyName the property name to be passed to the PropertyComponent
  34300. @param triggerOnMouseDown this is passed to the Button::setTriggeredOnMouseDown() method
  34301. */
  34302. ButtonPropertyComponent (const String& propertyName,
  34303. const bool triggerOnMouseDown);
  34304. /** Destructor. */
  34305. ~ButtonPropertyComponent();
  34306. /** Called when the user clicks the button.
  34307. */
  34308. virtual void buttonClicked() = 0;
  34309. /** Returns the string that should be displayed in the button.
  34310. If you need to change this string, call refresh() to update the component.
  34311. */
  34312. virtual const String getButtonText() const = 0;
  34313. /** @internal */
  34314. void refresh();
  34315. /** @internal */
  34316. void buttonClicked (Button*);
  34317. juce_UseDebuggingNewOperator
  34318. private:
  34319. TextButton* button;
  34320. };
  34321. #endif // __JUCE_BUTTONPROPERTYCOMPONENT_JUCEHEADER__
  34322. /********* End of inlined file: juce_ButtonPropertyComponent.h *********/
  34323. #endif
  34324. #ifndef __JUCE_CHOICEPROPERTYCOMPONENT_JUCEHEADER__
  34325. /********* Start of inlined file: juce_ChoicePropertyComponent.h *********/
  34326. #ifndef __JUCE_CHOICEPROPERTYCOMPONENT_JUCEHEADER__
  34327. #define __JUCE_CHOICEPROPERTYCOMPONENT_JUCEHEADER__
  34328. /**
  34329. A PropertyComponent that shows its value as a combo box.
  34330. This type of property component contains a list of options and has a
  34331. combo box to choose one.
  34332. Your subclass's constructor must add some strings to the choices StringArray
  34333. and these are shown in the list.
  34334. The getIndex() method will be called to find out which option is the currently
  34335. selected one. If you call refresh() it will call getIndex() to check whether
  34336. the value has changed, and will update the combo box if needed.
  34337. If the user selects a different item from the list, setIndex() will be
  34338. called to let your class process this.
  34339. @see PropertyComponent, PropertyPanel
  34340. */
  34341. class JUCE_API ChoicePropertyComponent : public PropertyComponent,
  34342. private ComboBoxListener
  34343. {
  34344. public:
  34345. /** Creates the component.
  34346. Your subclass's constructor must add a list of options to the choices
  34347. member variable.
  34348. */
  34349. ChoicePropertyComponent (const String& propertyName);
  34350. /** Destructor. */
  34351. ~ChoicePropertyComponent();
  34352. /** Called when the user selects an item from the combo box.
  34353. Your subclass must use this callback to update the value that this component
  34354. represents. The index is the index of the chosen item in the choices
  34355. StringArray.
  34356. */
  34357. virtual void setIndex (const int newIndex) = 0;
  34358. /** Returns the index of the item that should currently be shown.
  34359. This is the index of the item in the choices StringArray that will be
  34360. shown.
  34361. */
  34362. virtual int getIndex() const = 0;
  34363. /** Returns the list of options. */
  34364. const StringArray& getChoices() const throw();
  34365. /** @internal */
  34366. void refresh();
  34367. /** @internal */
  34368. void comboBoxChanged (ComboBox*);
  34369. juce_UseDebuggingNewOperator
  34370. protected:
  34371. /** The list of options that will be shown in the combo box.
  34372. Your subclass must populate this array in its constructor. If any empty
  34373. strings are added, these will be replaced with horizontal separators (see
  34374. ComboBox::addSeparator() for more info).
  34375. */
  34376. StringArray choices;
  34377. private:
  34378. ComboBox* comboBox;
  34379. };
  34380. #endif // __JUCE_CHOICEPROPERTYCOMPONENT_JUCEHEADER__
  34381. /********* End of inlined file: juce_ChoicePropertyComponent.h *********/
  34382. #endif
  34383. #ifndef __JUCE_PROPERTYCOMPONENT_JUCEHEADER__
  34384. #endif
  34385. #ifndef __JUCE_PROPERTYPANEL_JUCEHEADER__
  34386. #endif
  34387. #ifndef __JUCE_SLIDERPROPERTYCOMPONENT_JUCEHEADER__
  34388. /********* Start of inlined file: juce_SliderPropertyComponent.h *********/
  34389. #ifndef __JUCE_SLIDERPROPERTYCOMPONENT_JUCEHEADER__
  34390. #define __JUCE_SLIDERPROPERTYCOMPONENT_JUCEHEADER__
  34391. /**
  34392. A PropertyComponent that shows its value as a slider.
  34393. @see PropertyComponent, Slider
  34394. */
  34395. class JUCE_API SliderPropertyComponent : public PropertyComponent,
  34396. private SliderListener
  34397. {
  34398. public:
  34399. /** Creates the property component.
  34400. The ranges, interval and skew factor are passed to the Slider component.
  34401. If you need to customise the slider in other ways, your constructor can
  34402. access the slider member variable and change it directly.
  34403. */
  34404. SliderPropertyComponent (const String& propertyName,
  34405. const double rangeMin,
  34406. const double rangeMax,
  34407. const double interval,
  34408. const double skewFactor = 1.0);
  34409. /** Destructor. */
  34410. ~SliderPropertyComponent();
  34411. /** Called when the user moves the slider to change its value.
  34412. Your subclass must use this method to update whatever item this property
  34413. represents.
  34414. */
  34415. virtual void setValue (const double newValue) = 0;
  34416. /** Returns the value that the slider should show. */
  34417. virtual const double getValue() const = 0;
  34418. /** @internal */
  34419. void refresh();
  34420. /** @internal */
  34421. void changeListenerCallback (void*);
  34422. /** @internal */
  34423. void sliderValueChanged (Slider*);
  34424. juce_UseDebuggingNewOperator
  34425. protected:
  34426. /** The slider component being used in this component.
  34427. Your subclass has access to this in case it needs to customise it in some way.
  34428. */
  34429. Slider* slider;
  34430. };
  34431. #endif // __JUCE_SLIDERPROPERTYCOMPONENT_JUCEHEADER__
  34432. /********* End of inlined file: juce_SliderPropertyComponent.h *********/
  34433. #endif
  34434. #ifndef __JUCE_TEXTPROPERTYCOMPONENT_JUCEHEADER__
  34435. /********* Start of inlined file: juce_TextPropertyComponent.h *********/
  34436. #ifndef __JUCE_TEXTPROPERTYCOMPONENT_JUCEHEADER__
  34437. #define __JUCE_TEXTPROPERTYCOMPONENT_JUCEHEADER__
  34438. /**
  34439. A PropertyComponent that shows its value as editable text.
  34440. @see PropertyComponent
  34441. */
  34442. class JUCE_API TextPropertyComponent : public PropertyComponent
  34443. {
  34444. public:
  34445. /** Creates a text property component.
  34446. The maxNumChars is used to set the length of string allowable, and isMultiLine
  34447. sets whether the text editor allows carriage returns.
  34448. @see TextEditor
  34449. */
  34450. TextPropertyComponent (const String& propertyName,
  34451. const int maxNumChars,
  34452. const bool isMultiLine);
  34453. /** Destructor. */
  34454. ~TextPropertyComponent();
  34455. /** Called when the user edits the text.
  34456. Your subclass must use this callback to change the value of whatever item
  34457. this property component represents.
  34458. */
  34459. virtual void setText (const String& newText) = 0;
  34460. /** Returns the text that should be shown in the text editor.
  34461. */
  34462. virtual const String getText() const = 0;
  34463. /** @internal */
  34464. void refresh();
  34465. /** @internal */
  34466. void textWasEdited();
  34467. juce_UseDebuggingNewOperator
  34468. private:
  34469. Label* textEditor;
  34470. };
  34471. #endif // __JUCE_TEXTPROPERTYCOMPONENT_JUCEHEADER__
  34472. /********* End of inlined file: juce_TextPropertyComponent.h *********/
  34473. #endif
  34474. #ifndef __JUCE_COMPONENTANIMATOR_JUCEHEADER__
  34475. #endif
  34476. #ifndef __JUCE_COMPONENTBOUNDSCONSTRAINER_JUCEHEADER__
  34477. #endif
  34478. #ifndef __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
  34479. /********* Start of inlined file: juce_ComponentMovementWatcher.h *********/
  34480. #ifndef __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
  34481. #define __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
  34482. /** An object that watches for any movement of a component or any of its parent components.
  34483. This makes it easy to check when a component is moved relative to its top-level
  34484. peer window. The normal Component::moved() method is only called when a component
  34485. moves relative to its immediate parent, and sometimes you want to know if any of
  34486. components higher up the tree have moved (which of course will affect the overall
  34487. position of all their sub-components).
  34488. It also includes a callback that lets you know when the top-level peer is changed.
  34489. This class is used by specialised components like OpenGLComponent or QuickTimeComponent
  34490. because they need to keep their custom windows in the right place and respond to
  34491. changes in the peer.
  34492. */
  34493. class JUCE_API ComponentMovementWatcher : public ComponentListener
  34494. {
  34495. public:
  34496. /** Creates a ComponentMovementWatcher to watch a given target component. */
  34497. ComponentMovementWatcher (Component* const component);
  34498. /** Destructor. */
  34499. ~ComponentMovementWatcher();
  34500. /** This callback happens when the component that is being watched is moved
  34501. relative to its top-level peer window, or when it is resized.
  34502. */
  34503. virtual void componentMovedOrResized (bool wasMoved, bool wasResized) = 0;
  34504. /** This callback happens when the component's top-level peer is changed.
  34505. */
  34506. virtual void componentPeerChanged() = 0;
  34507. juce_UseDebuggingNewOperator
  34508. /** @internal */
  34509. void componentParentHierarchyChanged (Component& component);
  34510. /** @internal */
  34511. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  34512. private:
  34513. Component* const component;
  34514. ComponentPeer* lastPeer;
  34515. VoidArray registeredParentComps;
  34516. bool reentrant;
  34517. int lastX, lastY, lastWidth, lastHeight;
  34518. #ifdef JUCE_DEBUG
  34519. ComponentDeletionWatcher* deletionWatcher;
  34520. #endif
  34521. void unregister() throw();
  34522. void registerWithParentComps() throw();
  34523. ComponentMovementWatcher (const ComponentMovementWatcher&);
  34524. const ComponentMovementWatcher& operator= (const ComponentMovementWatcher&);
  34525. };
  34526. #endif // __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
  34527. /********* End of inlined file: juce_ComponentMovementWatcher.h *********/
  34528. #endif
  34529. #ifndef __JUCE_GROUPCOMPONENT_JUCEHEADER__
  34530. /********* Start of inlined file: juce_GroupComponent.h *********/
  34531. #ifndef __JUCE_GROUPCOMPONENT_JUCEHEADER__
  34532. #define __JUCE_GROUPCOMPONENT_JUCEHEADER__
  34533. /**
  34534. A component that draws an outline around itself and has an optional title at
  34535. the top, for drawing an outline around a group of controls.
  34536. */
  34537. class JUCE_API GroupComponent : public Component
  34538. {
  34539. public:
  34540. /** Creates a GroupComponent.
  34541. @param componentName the name to give the component
  34542. @param labelText the text to show at the top of the outline
  34543. */
  34544. GroupComponent (const String& componentName,
  34545. const String& labelText);
  34546. /** Destructor. */
  34547. ~GroupComponent();
  34548. /** Changes the text that's shown at the top of the component. */
  34549. void setText (const String& newText) throw();
  34550. /** Returns the currently displayed text label. */
  34551. const String getText() const throw();
  34552. /** Sets the positioning of the text label.
  34553. (The default is Justification::left)
  34554. @see getTextLabelPosition
  34555. */
  34556. void setTextLabelPosition (const Justification& justification);
  34557. /** Returns the current text label position.
  34558. @see setTextLabelPosition
  34559. */
  34560. const Justification getTextLabelPosition() const throw() { return justification; }
  34561. /** A set of colour IDs to use to change the colour of various aspects of the component.
  34562. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  34563. methods.
  34564. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  34565. */
  34566. enum ColourIds
  34567. {
  34568. outlineColourId = 0x1005400, /**< The colour to use for drawing the line around the edge. */
  34569. textColourId = 0x1005410 /**< The colour to use to draw the text label. */
  34570. };
  34571. /** @internal */
  34572. void paint (Graphics& g);
  34573. /** @internal */
  34574. void enablementChanged();
  34575. /** @internal */
  34576. void colourChanged();
  34577. private:
  34578. String text;
  34579. Justification justification;
  34580. GroupComponent (const GroupComponent&);
  34581. const GroupComponent& operator= (const GroupComponent&);
  34582. };
  34583. #endif // __JUCE_GROUPCOMPONENT_JUCEHEADER__
  34584. /********* End of inlined file: juce_GroupComponent.h *********/
  34585. #endif
  34586. #ifndef __JUCE_MULTIDOCUMENTPANEL_JUCEHEADER__
  34587. /********* Start of inlined file: juce_MultiDocumentPanel.h *********/
  34588. #ifndef __JUCE_MULTIDOCUMENTPANEL_JUCEHEADER__
  34589. #define __JUCE_MULTIDOCUMENTPANEL_JUCEHEADER__
  34590. /********* Start of inlined file: juce_TabbedComponent.h *********/
  34591. #ifndef __JUCE_TABBEDCOMPONENT_JUCEHEADER__
  34592. #define __JUCE_TABBEDCOMPONENT_JUCEHEADER__
  34593. /********* Start of inlined file: juce_TabbedButtonBar.h *********/
  34594. #ifndef __JUCE_TABBEDBUTTONBAR_JUCEHEADER__
  34595. #define __JUCE_TABBEDBUTTONBAR_JUCEHEADER__
  34596. class TabbedButtonBar;
  34597. /** In a TabbedButtonBar, this component is used for each of the buttons.
  34598. If you want to create a TabbedButtonBar with custom tab components, derive
  34599. your component from this class, and override the TabbedButtonBar::createTabButton()
  34600. method to create it instead of the default one.
  34601. @see TabbedButtonBar
  34602. */
  34603. class JUCE_API TabBarButton : public Button
  34604. {
  34605. public:
  34606. /** Creates the tab button. */
  34607. TabBarButton (const String& name,
  34608. TabbedButtonBar* const ownerBar,
  34609. const int tabIndex);
  34610. /** Destructor. */
  34611. ~TabBarButton();
  34612. /** Chooses the best length for the tab, given the specified depth.
  34613. If the tab is horizontal, this should return its width, and the depth
  34614. specifies its height. If it's vertical, it should return the height, and
  34615. the depth is actually its width.
  34616. */
  34617. virtual int getBestTabLength (const int depth);
  34618. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown);
  34619. void clicked (const ModifierKeys& mods);
  34620. bool hitTest (int x, int y);
  34621. juce_UseDebuggingNewOperator
  34622. protected:
  34623. friend class TabbedButtonBar;
  34624. TabbedButtonBar* const owner;
  34625. int tabIndex, overlapPixels;
  34626. DropShadowEffect shadow;
  34627. /** Returns an area of the component that's safe to draw in.
  34628. This deals with the orientation of the tabs, which affects which side is
  34629. touching the tabbed box's content component.
  34630. */
  34631. void getActiveArea (int& x, int& y, int& w, int& h);
  34632. private:
  34633. TabBarButton (const TabBarButton&);
  34634. const TabBarButton& operator= (const TabBarButton&);
  34635. };
  34636. /**
  34637. A vertical or horizontal bar containing tabs that you can select.
  34638. You can use one of these to generate things like a dialog box that has
  34639. tabbed pages you can flip between. Attach a ChangeListener to the
  34640. button bar to be told when the user changes the page.
  34641. An easier method than doing this is to use a TabbedComponent, which
  34642. contains its own TabbedButtonBar and which takes care of the layout
  34643. and other housekeeping.
  34644. @see TabbedComponent
  34645. */
  34646. class JUCE_API TabbedButtonBar : public Component,
  34647. public ChangeBroadcaster,
  34648. public ButtonListener
  34649. {
  34650. public:
  34651. /** The placement of the tab-bar
  34652. @see setOrientation, getOrientation
  34653. */
  34654. enum Orientation
  34655. {
  34656. TabsAtTop,
  34657. TabsAtBottom,
  34658. TabsAtLeft,
  34659. TabsAtRight
  34660. };
  34661. /** Creates a TabbedButtonBar with a given placement.
  34662. You can change the orientation later if you need to.
  34663. */
  34664. TabbedButtonBar (const Orientation orientation);
  34665. /** Destructor. */
  34666. ~TabbedButtonBar();
  34667. /** Changes the bar's orientation.
  34668. This won't change the bar's actual size - you'll need to do that yourself,
  34669. but this determines which direction the tabs go in, and which side they're
  34670. stuck to.
  34671. */
  34672. void setOrientation (const Orientation orientation);
  34673. /** Returns the current orientation.
  34674. @see setOrientation
  34675. */
  34676. Orientation getOrientation() const throw() { return orientation; }
  34677. /** Deletes all the tabs from the bar.
  34678. @see addTab
  34679. */
  34680. void clearTabs();
  34681. /** Adds a tab to the bar.
  34682. Tabs are added in left-to-right reading order.
  34683. If this is the first tab added, it'll also be automatically selected.
  34684. */
  34685. void addTab (const String& tabName,
  34686. const Colour& tabBackgroundColour,
  34687. int insertIndex = -1);
  34688. /** Changes the name of one of the tabs. */
  34689. void setTabName (const int tabIndex,
  34690. const String& newName);
  34691. /** Gets rid of one of the tabs. */
  34692. void removeTab (const int tabIndex);
  34693. /** Moves a tab to a new index in the list.
  34694. Pass -1 as the index to move it to the end of the list.
  34695. */
  34696. void moveTab (const int currentIndex,
  34697. const int newIndex);
  34698. /** Returns the number of tabs in the bar. */
  34699. int getNumTabs() const;
  34700. /** Returns a list of all the tab names in the bar. */
  34701. const StringArray getTabNames() const;
  34702. /** Changes the currently selected tab.
  34703. This will send a change message and cause a synchronous callback to
  34704. the currentTabChanged() method. (But if the given tab is already selected,
  34705. nothing will be done).
  34706. To deselect all the tabs, use an index of -1.
  34707. */
  34708. void setCurrentTabIndex (int newTabIndex);
  34709. /** Returns the name of the currently selected tab.
  34710. This could be an empty string if none are selected.
  34711. */
  34712. const String& getCurrentTabName() const throw() { return tabs [currentTabIndex]; }
  34713. /** Returns the index of the currently selected tab.
  34714. This could return -1 if none are selected.
  34715. */
  34716. int getCurrentTabIndex() const throw() { return currentTabIndex; }
  34717. /** Callback method to indicate the selected tab has been changed.
  34718. @see setCurrentTabIndex
  34719. */
  34720. virtual void currentTabChanged (const int newCurrentTabIndex,
  34721. const String& newCurrentTabName);
  34722. /** Callback method to indicate that the user has right-clicked on a tab.
  34723. (Or ctrl-clicked on the Mac)
  34724. */
  34725. virtual void popupMenuClickOnTab (const int tabIndex,
  34726. const String& tabName);
  34727. /** Returns the colour of a tab.
  34728. This is the colour that was specified in addTab().
  34729. */
  34730. const Colour getTabBackgroundColour (const int tabIndex);
  34731. /** Changes the background colour of a tab.
  34732. @see addTab, getTabBackgroundColour
  34733. */
  34734. void setTabBackgroundColour (const int tabIndex, const Colour& newColour);
  34735. /** @internal */
  34736. void resized();
  34737. /** @internal */
  34738. void buttonClicked (Button* button);
  34739. /** @internal */
  34740. void lookAndFeelChanged();
  34741. juce_UseDebuggingNewOperator
  34742. protected:
  34743. /** This creates one of the tabs.
  34744. If you need to use custom tab components, you can override this method and
  34745. return your own class instead of the default.
  34746. */
  34747. virtual TabBarButton* createTabButton (const String& tabName,
  34748. const int tabIndex);
  34749. private:
  34750. Orientation orientation;
  34751. StringArray tabs;
  34752. Array <Colour> tabColours;
  34753. int currentTabIndex;
  34754. Component* behindFrontTab;
  34755. Button* extraTabsButton;
  34756. TabBarButton* getTabButton (const int index) const;
  34757. TabbedButtonBar (const TabbedButtonBar&);
  34758. const TabbedButtonBar& operator= (const TabbedButtonBar&);
  34759. };
  34760. #endif // __JUCE_TABBEDBUTTONBAR_JUCEHEADER__
  34761. /********* End of inlined file: juce_TabbedButtonBar.h *********/
  34762. /**
  34763. A component with a TabbedButtonBar along one of its sides.
  34764. This makes it easy to create a set of tabbed pages, just add a bunch of tabs
  34765. with addTab(), and this will take care of showing the pages for you when the
  34766. user clicks on a different tab.
  34767. @see TabbedButtonBar
  34768. */
  34769. class JUCE_API TabbedComponent : public Component
  34770. {
  34771. public:
  34772. /** Creates a TabbedComponent, specifying where the tabs should be placed.
  34773. Once created, add some tabs with the addTab() method.
  34774. */
  34775. TabbedComponent (const TabbedButtonBar::Orientation orientation);
  34776. /** Destructor. */
  34777. ~TabbedComponent();
  34778. /** Changes the placement of the tabs.
  34779. This will rearrange the layout to place the tabs along the appropriate
  34780. side of this component, and will shift the content component accordingly.
  34781. @see TabbedButtonBar::setOrientation
  34782. */
  34783. void setOrientation (const TabbedButtonBar::Orientation orientation);
  34784. /** Returns the current tab placement.
  34785. @see setOrientation, TabbedButtonBar::getOrientation
  34786. */
  34787. TabbedButtonBar::Orientation getOrientation() const throw();
  34788. /** Specifies how many pixels wide or high the tab-bar should be.
  34789. If the tabs are placed along the top or bottom, this specified the height
  34790. of the bar; if they're along the left or right edges, it'll be the width
  34791. of the bar.
  34792. */
  34793. void setTabBarDepth (const int newDepth);
  34794. /** Returns the current thickness of the tab bar.
  34795. @see setTabBarDepth
  34796. */
  34797. int getTabBarDepth() const throw() { return tabDepth; }
  34798. /** Specifies an outline that should be drawn around the entire content component.
  34799. If this thickness is > 0, a line of the specified colour will be drawn around
  34800. the three sides of the content component which don't touch the tab-bar, and
  34801. the content component will be inset by this amount.
  34802. */
  34803. void setOutline (const Colour& newOutlineColour,
  34804. const int newThickness);
  34805. /** Specifies a gap to leave around the edge of the content component.
  34806. Each edge of the content component will be indented by the given number of pixels.
  34807. */
  34808. void setIndent (const int indentThickness);
  34809. /** Removes all the tabs from the bar.
  34810. @see TabbedButtonBar::clearTabs
  34811. */
  34812. void clearTabs();
  34813. /** Adds a tab to the tab-bar.
  34814. The component passed in will be shown for the tab, and if deleteComponentWhenNotNeeded
  34815. is true, it will be deleted when the tab is removed or when this object is
  34816. deleted.
  34817. @see TabbedButtonBar::addTab
  34818. */
  34819. void addTab (const String& tabName,
  34820. const Colour& tabBackgroundColour,
  34821. Component* const contentComponent,
  34822. const bool deleteComponentWhenNotNeeded,
  34823. const int insertIndex = -1);
  34824. /** Changes the name of one of the tabs. */
  34825. void setTabName (const int tabIndex,
  34826. const String& newName);
  34827. /** Gets rid of one of the tabs. */
  34828. void removeTab (const int tabIndex);
  34829. /** Returns the number of tabs in the bar. */
  34830. int getNumTabs() const;
  34831. /** Returns a list of all the tab names in the bar. */
  34832. const StringArray getTabNames() const;
  34833. /** Returns the content component that was added for the given index.
  34834. Be sure not to use or delete the components that are returned, as this may interfere
  34835. with the TabbedComponent's use of them.
  34836. */
  34837. Component* getTabContentComponent (const int tabIndex) const throw();
  34838. /** Returns the colour of one of the tabs. */
  34839. const Colour getTabBackgroundColour (const int tabIndex) const throw();
  34840. /** Changes the background colour of one of the tabs. */
  34841. void setTabBackgroundColour (const int tabIndex, const Colour& newColour);
  34842. /** Changes the currently-selected tab.
  34843. To deselect all the tabs, pass -1 as the index.
  34844. @see TabbedButtonBar::setCurrentTabIndex
  34845. */
  34846. void setCurrentTabIndex (const int newTabIndex);
  34847. /** Returns the index of the currently selected tab.
  34848. @see addTab, TabbedButtonBar::getCurrentTabIndex()
  34849. */
  34850. int getCurrentTabIndex() const;
  34851. /** Returns the name of the currently selected tab.
  34852. @see addTab, TabbedButtonBar::getCurrentTabName()
  34853. */
  34854. const String& getCurrentTabName() const;
  34855. /** Returns the current component that's filling the panel.
  34856. This will return 0 if there isn't one.
  34857. */
  34858. Component* getCurrentContentComponent() const throw() { return panelComponent; }
  34859. /** Callback method to indicate the selected tab has been changed.
  34860. @see setCurrentTabIndex
  34861. */
  34862. virtual void currentTabChanged (const int newCurrentTabIndex,
  34863. const String& newCurrentTabName);
  34864. /** Callback method to indicate that the user has right-clicked on a tab.
  34865. (Or ctrl-clicked on the Mac)
  34866. */
  34867. virtual void popupMenuClickOnTab (const int tabIndex,
  34868. const String& tabName);
  34869. /** Returns the tab button bar component that is being used.
  34870. */
  34871. TabbedButtonBar& getTabbedButtonBar() const throw() { return *tabs; }
  34872. /** @internal */
  34873. void paint (Graphics& g);
  34874. /** @internal */
  34875. void resized();
  34876. juce_UseDebuggingNewOperator
  34877. protected:
  34878. TabbedButtonBar* tabs;
  34879. /** This creates one of the tab buttons.
  34880. If you need to use custom tab components, you can override this method and
  34881. return your own class instead of the default.
  34882. */
  34883. virtual TabBarButton* createTabButton (const String& tabName,
  34884. const int tabIndex);
  34885. private:
  34886. Array <Component*> contentComponents;
  34887. Component* panelComponent;
  34888. int tabDepth;
  34889. Colour outlineColour;
  34890. int outlineThickness, edgeIndent;
  34891. friend class TabCompButtonBar;
  34892. void changeCallback (const int newCurrentTabIndex, const String& newTabName);
  34893. TabbedComponent (const TabbedComponent&);
  34894. const TabbedComponent& operator= (const TabbedComponent&);
  34895. };
  34896. #endif // __JUCE_TABBEDCOMPONENT_JUCEHEADER__
  34897. /********* End of inlined file: juce_TabbedComponent.h *********/
  34898. /********* Start of inlined file: juce_DocumentWindow.h *********/
  34899. #ifndef __JUCE_DOCUMENTWINDOW_JUCEHEADER__
  34900. #define __JUCE_DOCUMENTWINDOW_JUCEHEADER__
  34901. /********* Start of inlined file: juce_ResizableWindow.h *********/
  34902. #ifndef __JUCE_RESIZABLEWINDOW_JUCEHEADER__
  34903. #define __JUCE_RESIZABLEWINDOW_JUCEHEADER__
  34904. /********* Start of inlined file: juce_TopLevelWindow.h *********/
  34905. #ifndef __JUCE_TOPLEVELWINDOW_JUCEHEADER__
  34906. #define __JUCE_TOPLEVELWINDOW_JUCEHEADER__
  34907. /********* Start of inlined file: juce_DropShadower.h *********/
  34908. #ifndef __JUCE_DROPSHADOWER_JUCEHEADER__
  34909. #define __JUCE_DROPSHADOWER_JUCEHEADER__
  34910. /**
  34911. Adds a drop-shadow to a component.
  34912. This object creates and manages a set of components which sit around a
  34913. component, creating a gaussian shadow around it. The components will track
  34914. the position of the component and if it's brought to the front they'll also
  34915. follow this.
  34916. For desktop windows you don't need to use this class directly - just
  34917. set the Component::windowHasDropShadow flag when calling
  34918. Component::addToDesktop(), and the system will create one of these if it's
  34919. needed (which it obviously isn't on the Mac, for example).
  34920. */
  34921. class JUCE_API DropShadower : public ComponentListener
  34922. {
  34923. public:
  34924. /** Creates a DropShadower.
  34925. @param alpha the opacity of the shadows, from 0 to 1.0
  34926. @param xOffset the horizontal displacement of the shadow, in pixels
  34927. @param yOffset the vertical displacement of the shadow, in pixels
  34928. @param blurRadius the radius of the blur to use for creating the shadow
  34929. */
  34930. DropShadower (const float alpha = 0.5f,
  34931. const int xOffset = 1,
  34932. const int yOffset = 5,
  34933. const float blurRadius = 10.0f);
  34934. /** Destructor. */
  34935. virtual ~DropShadower();
  34936. /** Attaches the DropShadower to the component you want to shadow. */
  34937. void setOwner (Component* componentToFollow);
  34938. /** @internal */
  34939. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  34940. /** @internal */
  34941. void componentBroughtToFront (Component& component);
  34942. /** @internal */
  34943. void componentChildrenChanged (Component& component);
  34944. /** @internal */
  34945. void componentParentHierarchyChanged (Component& component);
  34946. /** @internal */
  34947. void componentVisibilityChanged (Component& component);
  34948. juce_UseDebuggingNewOperator
  34949. private:
  34950. Component* owner;
  34951. int numShadows;
  34952. Component* shadowWindows[4];
  34953. Image* shadowImageSections[12];
  34954. const int shadowEdge, xOffset, yOffset;
  34955. const float alpha, blurRadius;
  34956. bool inDestructor, reentrant;
  34957. void updateShadows();
  34958. void setShadowImage (Image* const src,
  34959. const int num,
  34960. const int w, const int h,
  34961. const int sx, const int sy) throw();
  34962. void bringShadowWindowsToFront();
  34963. void deleteShadowWindows();
  34964. DropShadower (const DropShadower&);
  34965. const DropShadower& operator= (const DropShadower&);
  34966. };
  34967. #endif // __JUCE_DROPSHADOWER_JUCEHEADER__
  34968. /********* End of inlined file: juce_DropShadower.h *********/
  34969. /**
  34970. A base class for top-level windows.
  34971. This class is used for components that are considered a major part of your
  34972. application - e.g. ResizableWindow, DocumentWindow, DialogWindow, AlertWindow,
  34973. etc. Things like menus that pop up briefly aren't derived from it.
  34974. A TopLevelWindow is probably on the desktop, but this isn't mandatory - it
  34975. could itself be the child of another component.
  34976. The class manages a list of all instances of top-level windows that are in use,
  34977. and each one is also given the concept of being "active". The active window is
  34978. one that is actively being used by the user. This isn't quite the same as the
  34979. component with the keyboard focus, because there may be a popup menu or other
  34980. temporary window which gets keyboard focus while the active top level window is
  34981. unchanged.
  34982. A top-level window also has an optional drop-shadow.
  34983. @see ResizableWindow, DocumentWindow, DialogWindow
  34984. */
  34985. class JUCE_API TopLevelWindow : public Component
  34986. {
  34987. public:
  34988. /** Creates a TopLevelWindow.
  34989. @param name the name to give the component
  34990. @param addToDesktop if true, the window will be automatically added to the
  34991. desktop; if false, you can use it as a child component
  34992. */
  34993. TopLevelWindow (const String& name,
  34994. const bool addToDesktop);
  34995. /** Destructor. */
  34996. ~TopLevelWindow();
  34997. /** True if this is currently the TopLevelWindow that is actively being used.
  34998. This isn't quite the same as having keyboard focus, because the focus may be
  34999. on a child component or a temporary pop-up menu, etc, while this window is
  35000. still considered to be active.
  35001. @see activeWindowStatusChanged
  35002. */
  35003. bool isActiveWindow() const throw() { return windowIsActive_; }
  35004. /** This will set the bounds of the window so that it's centred in front of another
  35005. window.
  35006. If your app has a few windows open and want to pop up a dialog box for one of
  35007. them, you can use this to show it in front of the relevent parent window, which
  35008. is a bit neater than just having it appear in the middle of the screen.
  35009. If componentToCentreAround is 0, then the currently active TopLevelWindow will
  35010. be used instead. If no window is focused, it'll just default to the middle of the
  35011. screen.
  35012. */
  35013. void centreAroundComponent (Component* componentToCentreAround,
  35014. const int width, const int height);
  35015. /** Turns the drop-shadow on and off. */
  35016. void setDropShadowEnabled (const bool useShadow);
  35017. /** Sets whether an OS-native title bar will be used, or a Juce one.
  35018. @see isUsingNativeTitleBar
  35019. */
  35020. void setUsingNativeTitleBar (const bool useNativeTitleBar);
  35021. /** Returns true if the window is currently using an OS-native title bar.
  35022. @see setUsingNativeTitleBar
  35023. */
  35024. bool isUsingNativeTitleBar() const throw() { return useNativeTitleBar && isOnDesktop(); }
  35025. /** Returns the number of TopLevelWindow objects currently in use.
  35026. @see getTopLevelWindow
  35027. */
  35028. static int getNumTopLevelWindows() throw();
  35029. /** Returns one of the TopLevelWindow objects currently in use.
  35030. The index is 0 to (getNumTopLevelWindows() - 1).
  35031. */
  35032. static TopLevelWindow* getTopLevelWindow (const int index) throw();
  35033. /** Returns the currently-active top level window.
  35034. There might not be one, of course, so this can return 0.
  35035. */
  35036. static TopLevelWindow* getActiveTopLevelWindow() throw();
  35037. juce_UseDebuggingNewOperator
  35038. /** @internal */
  35039. virtual void addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo = 0);
  35040. protected:
  35041. /** This callback happens when this window becomes active or inactive.
  35042. @see isActiveWindow
  35043. */
  35044. virtual void activeWindowStatusChanged();
  35045. /** @internal */
  35046. void focusOfChildComponentChanged (FocusChangeType cause);
  35047. /** @internal */
  35048. void parentHierarchyChanged();
  35049. /** @internal */
  35050. void visibilityChanged();
  35051. /** @internal */
  35052. virtual int getDesktopWindowStyleFlags() const;
  35053. /** @internal */
  35054. void recreateDesktopWindow();
  35055. private:
  35056. friend class TopLevelWindowManager;
  35057. bool useDropShadow, useNativeTitleBar, windowIsActive_;
  35058. DropShadower* shadower;
  35059. void setWindowActive (const bool isNowActive) throw();
  35060. TopLevelWindow (const TopLevelWindow&);
  35061. const TopLevelWindow& operator= (const TopLevelWindow&);
  35062. };
  35063. #endif // __JUCE_TOPLEVELWINDOW_JUCEHEADER__
  35064. /********* End of inlined file: juce_TopLevelWindow.h *********/
  35065. /********* Start of inlined file: juce_ResizableBorderComponent.h *********/
  35066. #ifndef __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__
  35067. #define __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__
  35068. /**
  35069. A component that resizes its parent window when dragged.
  35070. This component forms a frame around the edge of a component, allowing it to
  35071. be dragged by the edges or corners to resize it - like the way windows are
  35072. resized in MSWindows or Linux.
  35073. To use it, just add it to your component, making it fill the entire parent component
  35074. (there's a mouse hit-test that only traps mouse-events which land around the
  35075. edge of the component, so it's even ok to put it on top of any other components
  35076. you're using). Make sure you rescale the resizer component to fill the parent
  35077. each time the parent's size changes.
  35078. @see ResizableCornerComponent
  35079. */
  35080. class JUCE_API ResizableBorderComponent : public Component
  35081. {
  35082. public:
  35083. /** Creates a resizer.
  35084. Pass in the target component which you want to be resized when this one is
  35085. dragged.
  35086. The target component will usually be a parent of the resizer component, but this
  35087. isn't mandatory.
  35088. Remember that when the target component is resized, it'll need to move and
  35089. resize this component to keep it in place, as this won't happen automatically.
  35090. If the constrainer parameter is non-zero, then this object will be used to enforce
  35091. limits on the size and position that the component can be stretched to. Make sure
  35092. that the constrainer isn't deleted while still in use by this object.
  35093. @see ComponentBoundsConstrainer
  35094. */
  35095. ResizableBorderComponent (Component* const componentToResize,
  35096. ComponentBoundsConstrainer* const constrainer);
  35097. /** Destructor. */
  35098. ~ResizableBorderComponent();
  35099. /** Specifies how many pixels wide the draggable edges of this component are.
  35100. @see getBorderThickness
  35101. */
  35102. void setBorderThickness (const BorderSize& newBorderSize) throw();
  35103. /** Returns the number of pixels wide that the draggable edges of this component are.
  35104. @see setBorderThickness
  35105. */
  35106. const BorderSize getBorderThickness() const throw();
  35107. juce_UseDebuggingNewOperator
  35108. protected:
  35109. /** @internal */
  35110. void paint (Graphics& g);
  35111. /** @internal */
  35112. void mouseEnter (const MouseEvent& e);
  35113. /** @internal */
  35114. void mouseMove (const MouseEvent& e);
  35115. /** @internal */
  35116. void mouseDown (const MouseEvent& e);
  35117. /** @internal */
  35118. void mouseDrag (const MouseEvent& e);
  35119. /** @internal */
  35120. void mouseUp (const MouseEvent& e);
  35121. /** @internal */
  35122. bool hitTest (int x, int y);
  35123. private:
  35124. Component* const component;
  35125. ComponentBoundsConstrainer* constrainer;
  35126. BorderSize borderSize;
  35127. int originalX, originalY, originalW, originalH;
  35128. int mouseZone;
  35129. void updateMouseZone (const MouseEvent& e) throw();
  35130. ResizableBorderComponent (const ResizableBorderComponent&);
  35131. const ResizableBorderComponent& operator= (const ResizableBorderComponent&);
  35132. };
  35133. #endif // __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__
  35134. /********* End of inlined file: juce_ResizableBorderComponent.h *********/
  35135. /********* Start of inlined file: juce_ResizableCornerComponent.h *********/
  35136. #ifndef __JUCE_RESIZABLECORNERCOMPONENT_JUCEHEADER__
  35137. #define __JUCE_RESIZABLECORNERCOMPONENT_JUCEHEADER__
  35138. /** A component that resizes a parent window when dragged.
  35139. This is the small triangular stripey resizer component you get in the bottom-right
  35140. of windows (more commonly on the Mac than Windows). Put one in the corner of
  35141. a larger component and it will automatically resize its parent when it gets dragged
  35142. around.
  35143. @see ResizableFrameComponent
  35144. */
  35145. class JUCE_API ResizableCornerComponent : public Component
  35146. {
  35147. public:
  35148. /** Creates a resizer.
  35149. Pass in the target component which you want to be resized when this one is
  35150. dragged.
  35151. The target component will usually be a parent of the resizer component, but this
  35152. isn't mandatory.
  35153. Remember that when the target component is resized, it'll need to move and
  35154. resize this component to keep it in place, as this won't happen automatically.
  35155. If the constrainer parameter is non-zero, then this object will be used to enforce
  35156. limits on the size and position that the component can be stretched to. Make sure
  35157. that the constrainer isn't deleted while still in use by this object. If you
  35158. pass a zero in here, no limits will be put on the sizes it can be stretched to.
  35159. @see ComponentBoundsConstrainer
  35160. */
  35161. ResizableCornerComponent (Component* const componentToResize,
  35162. ComponentBoundsConstrainer* const constrainer);
  35163. /** Destructor. */
  35164. ~ResizableCornerComponent();
  35165. juce_UseDebuggingNewOperator
  35166. protected:
  35167. /** @internal */
  35168. void paint (Graphics& g);
  35169. /** @internal */
  35170. void mouseDown (const MouseEvent& e);
  35171. /** @internal */
  35172. void mouseDrag (const MouseEvent& e);
  35173. /** @internal */
  35174. void mouseUp (const MouseEvent& e);
  35175. /** @internal */
  35176. bool hitTest (int x, int y);
  35177. private:
  35178. Component* const component;
  35179. ComponentBoundsConstrainer* constrainer;
  35180. int originalX, originalY, originalW, originalH;
  35181. ResizableCornerComponent (const ResizableCornerComponent&);
  35182. const ResizableCornerComponent& operator= (const ResizableCornerComponent&);
  35183. };
  35184. #endif // __JUCE_RESIZABLECORNERCOMPONENT_JUCEHEADER__
  35185. /********* End of inlined file: juce_ResizableCornerComponent.h *********/
  35186. /**
  35187. A base class for top-level windows that can be dragged around and resized.
  35188. To add content to the window, use its setContentComponent() method to
  35189. give it a component that will remain positioned inside it (leaving a gap around
  35190. the edges for a border).
  35191. It's not advisable to add child components directly to a ResizableWindow: put them
  35192. inside your content component instead. And overriding methods like resized(), moved(), etc
  35193. is also not recommended - instead override these methods for your content component.
  35194. (If for some obscure reason you do need to override these methods, always remember to
  35195. call the super-class's resized() method too, otherwise it'll fail to lay out the window
  35196. decorations correctly).
  35197. By default resizing isn't enabled - use the setResizable() method to enable it and
  35198. to choose the style of resizing to use.
  35199. @see TopLevelWindow
  35200. */
  35201. class JUCE_API ResizableWindow : public TopLevelWindow
  35202. {
  35203. public:
  35204. /** Creates a ResizableWindow.
  35205. @param name the name to give the component
  35206. @param backgroundColour the colour to use for filling the window's background.
  35207. @param addToDesktop if true, the window will be automatically added to the
  35208. desktop; if false, you can use it as a child component
  35209. */
  35210. ResizableWindow (const String& name,
  35211. const Colour& backgroundColour,
  35212. const bool addToDesktop);
  35213. /** Destructor.
  35214. If a content component has been set with setContentComponent(), it
  35215. will be deleted.
  35216. */
  35217. ~ResizableWindow();
  35218. /** Returns the colour currently being used for the window's background.
  35219. As a convenience the window will fill itself with this colour, but you
  35220. can override the paint() method if you need more customised behaviour.
  35221. @see setBackgroundColour
  35222. */
  35223. const Colour& getBackgroundColour() const throw() { return backgroundColour; }
  35224. /** Changes the colour currently being used for the window's background.
  35225. As a convenience the window will fill itself with this colour, but you
  35226. can override the paint() method if you need more customised behaviour.
  35227. Note that the opaque state of this window is altered by this call to reflect
  35228. the opacity of the colour passed-in. On window systems which can't support
  35229. semi-transparent windows this might cause problems, (though it's unlikely you'll
  35230. be using this class as a base for a semi-transparent component anyway).
  35231. @see getBackgroundColour
  35232. */
  35233. void setBackgroundColour (const Colour& newColour);
  35234. /** Make the window resizable or fixed.
  35235. @param shouldBeResizable whether it's resizable at all
  35236. @param useBottomRightCornerResizer if true, it'll add a ResizableCornerComponent at the
  35237. bottom-right; if false, it'll use a ResizableBorderComponent
  35238. around the edge
  35239. @see setResizeLimits, isResizable
  35240. */
  35241. void setResizable (const bool shouldBeResizable,
  35242. const bool useBottomRightCornerResizer);
  35243. /** True if resizing is enabled.
  35244. @see setResizable
  35245. */
  35246. bool isResizable() const throw();
  35247. /** This sets the maximum and minimum sizes for the window.
  35248. If the window's current size is outside these limits, it will be resized to
  35249. make sure it's within them.
  35250. Calling setBounds() on the component will bypass any size checking - it's only when
  35251. the window is being resized by the user that these values are enforced.
  35252. @see setResizable, setFixedAspectRatio
  35253. */
  35254. void setResizeLimits (const int newMinimumWidth,
  35255. const int newMinimumHeight,
  35256. const int newMaximumWidth,
  35257. const int newMaximumHeight) throw();
  35258. /** Returns the bounds constrainer object that this window is using.
  35259. You can access this to change its properties.
  35260. */
  35261. ComponentBoundsConstrainer* getConstrainer() throw() { return constrainer; }
  35262. /** Sets the bounds-constrainer object to use for resizing and dragging this window.
  35263. A pointer to the object you pass in will be kept, but it won't be deleted
  35264. by this object, so it's the caller's responsiblity to manage it.
  35265. If you pass 0, then no contraints will be placed on the positioning of the window.
  35266. */
  35267. void setConstrainer (ComponentBoundsConstrainer* newConstrainer);
  35268. /** Calls the window's setBounds method, after first checking these bounds
  35269. with the current constrainer.
  35270. @see setConstrainer
  35271. */
  35272. void setBoundsConstrained (int x, int y, int width, int height);
  35273. /** Returns true if the window is currently in full-screen mode.
  35274. @see setFullScreen
  35275. */
  35276. bool isFullScreen() const;
  35277. /** Puts the window into full-screen mode, or restores it to its normal size.
  35278. If true, the window will become full-screen; if false, it will return to the
  35279. last size it was before being made full-screen.
  35280. @see isFullScreen
  35281. */
  35282. void setFullScreen (const bool shouldBeFullScreen);
  35283. /** Returns true if the window is currently minimised.
  35284. @see setMinimised
  35285. */
  35286. bool isMinimised() const;
  35287. /** Minimises the window, or restores it to its previous position and size.
  35288. When being un-minimised, it'll return to the last position and size it
  35289. was in before being minimised.
  35290. @see isMinimised
  35291. */
  35292. void setMinimised (const bool shouldMinimise);
  35293. /** Returns a string which encodes the window's current size and position.
  35294. This string will encapsulate the window's size, position, and whether it's
  35295. in full-screen mode. It's intended for letting your application save and
  35296. restore a window's position.
  35297. Use the restoreWindowStateFromString() to restore from a saved state.
  35298. @see restoreWindowStateFromString
  35299. */
  35300. const String getWindowStateAsString();
  35301. /** Restores the window to a previously-saved size and position.
  35302. This restores the window's size, positon and full-screen status from an
  35303. string that was previously created with the getWindowStateAsString()
  35304. method.
  35305. @returns false if the string wasn't a valid window state
  35306. @see getWindowStateAsString
  35307. */
  35308. bool restoreWindowStateFromString (const String& previousState);
  35309. /** Returns the current content component.
  35310. This will be the component set by setContentComponent(), or 0 if none
  35311. has yet been specified.
  35312. @see setContentComponent
  35313. */
  35314. Component* getContentComponent() const throw() { return contentComponent; }
  35315. /** Changes the current content component.
  35316. This sets a component that will be placed in the centre of the ResizableWindow,
  35317. (leaving a space around the edge for the border).
  35318. You should never add components directly to a ResizableWindow (or any of its subclasses)
  35319. with addChildComponent(). Instead, add them to the content component.
  35320. @param newContentComponent the new component to use (or null to not use one) - this
  35321. component will be deleted either when replaced by another call
  35322. to this method, or when the ResizableWindow is deleted.
  35323. To remove a content component without deleting it, use
  35324. setContentComponent (0, false).
  35325. @param deleteOldOne if true, the previous content component will be deleted; if
  35326. false, the previous component will just be removed without
  35327. deleting it.
  35328. @param resizeToFit if true, the ResizableWindow will maintain its size such that
  35329. it always fits around the size of the content component. If false, the
  35330. new content will be resized to fit the current space available.
  35331. */
  35332. void setContentComponent (Component* const newContentComponent,
  35333. const bool deleteOldOne = true,
  35334. const bool resizeToFit = false);
  35335. /** Changes the window so that the content component ends up with the specified size.
  35336. This is basically a setSize call on the window, but which adds on the borders,
  35337. so you can specify the content component's target size.
  35338. */
  35339. void setContentComponentSize (int width, int height);
  35340. juce_UseDebuggingNewOperator
  35341. protected:
  35342. /** @internal */
  35343. void paint (Graphics& g);
  35344. /** (if overriding this, make sure you call ResizableWindow::resized() in your subclass) */
  35345. void moved();
  35346. /** (if overriding this, make sure you call ResizableWindow::resized() in your subclass) */
  35347. void resized();
  35348. /** @internal */
  35349. void mouseDown (const MouseEvent& e);
  35350. /** @internal */
  35351. void mouseDrag (const MouseEvent& e);
  35352. /** @internal */
  35353. void lookAndFeelChanged();
  35354. /** @internal */
  35355. void childBoundsChanged (Component* child);
  35356. /** @internal */
  35357. void parentSizeChanged();
  35358. /** @internal */
  35359. void visibilityChanged();
  35360. /** @internal */
  35361. void activeWindowStatusChanged();
  35362. /** @internal */
  35363. int getDesktopWindowStyleFlags() const;
  35364. /** Returns the width of the border to use around the window.
  35365. @see getContentComponentBorder
  35366. */
  35367. virtual const BorderSize getBorderThickness();
  35368. /** Returns the insets to use when positioning the content component.
  35369. @see getBorderThickness
  35370. */
  35371. virtual const BorderSize getContentComponentBorder();
  35372. #ifdef JUCE_DEBUG
  35373. /** Overridden to warn people about adding components directly to this component
  35374. instead of using setContentComponent().
  35375. If you know what you're doing and are sure you really want to add a component, specify
  35376. a base-class method call to Component::addAndMakeVisible(), to side-step this warning.
  35377. */
  35378. void addChildComponent (Component* const child, int zOrder = -1);
  35379. /** Overridden to warn people about adding components directly to this component
  35380. instead of using setContentComponent().
  35381. If you know what you're doing and are sure you really want to add a component, specify
  35382. a base-class method call to Component::addAndMakeVisible(), to side-step this warning.
  35383. */
  35384. void addAndMakeVisible (Component* const child, int zOrder = -1);
  35385. #endif
  35386. ResizableCornerComponent* resizableCorner;
  35387. ResizableBorderComponent* resizableBorder;
  35388. private:
  35389. Component* contentComponent;
  35390. bool resizeToFitContent, fullscreen;
  35391. Colour backgroundColour;
  35392. ComponentDragger dragger;
  35393. Rectangle lastNonFullScreenPos;
  35394. ComponentBoundsConstrainer defaultConstrainer;
  35395. ComponentBoundsConstrainer* constrainer;
  35396. #ifdef JUCE_DEBUG
  35397. bool hasBeenResized;
  35398. #endif
  35399. void updateLastPos();
  35400. ResizableWindow (const ResizableWindow&);
  35401. const ResizableWindow& operator= (const ResizableWindow&);
  35402. // (xxx remove these eventually)
  35403. // temporarily here to stop old code compiling, as the parameters for these methods have changed..
  35404. void getBorderThickness (int& left, int& top, int& right, int& bottom);
  35405. // temporarily here to stop old code compiling, as the parameters for these methods have changed..
  35406. void getContentComponentBorder (int& left, int& top, int& right, int& bottom);
  35407. };
  35408. #endif // __JUCE_RESIZABLEWINDOW_JUCEHEADER__
  35409. /********* End of inlined file: juce_ResizableWindow.h *********/
  35410. /**
  35411. A resizable window with a title bar and maximise, minimise and close buttons.
  35412. This subclass of ResizableWindow creates a fairly standard type of window with
  35413. a title bar and various buttons. The name of the component is shown in the
  35414. title bar, and an icon can optionally be specified with setIcon().
  35415. All the methods available to a ResizableWindow are also available to this,
  35416. so it can easily be made resizable, minimised, maximised, etc.
  35417. It's not advisable to add child components directly to a DocumentWindow: put them
  35418. inside your content component instead. And overriding methods like resized(), moved(), etc
  35419. is also not recommended - instead override these methods for your content component.
  35420. (If for some obscure reason you do need to override these methods, always remember to
  35421. call the super-class's resized() method too, otherwise it'll fail to lay out the window
  35422. decorations correctly).
  35423. You can also automatically add a menu bar to the window, using the setMenuBar()
  35424. method.
  35425. @see ResizableWindow, DialogWindow
  35426. */
  35427. class JUCE_API DocumentWindow : public ResizableWindow
  35428. {
  35429. public:
  35430. /** The set of available button-types that can be put on the title bar.
  35431. @see setTitleBarButtonsRequired
  35432. */
  35433. enum TitleBarButtons
  35434. {
  35435. minimiseButton = 1,
  35436. maximiseButton = 2,
  35437. closeButton = 4,
  35438. /** A combination of all the buttons above. */
  35439. allButtons = 7
  35440. };
  35441. /** Creates a DocumentWindow.
  35442. @param name the name to give the component - this is also
  35443. the title shown at the top of the window. To change
  35444. this later, use setName()
  35445. @param backgroundColour the colour to use for filling the window's background.
  35446. @param requiredButtons specifies which of the buttons (close, minimise, maximise)
  35447. should be shown on the title bar. This value is a bitwise
  35448. combination of values from the TitleBarButtons enum. Note
  35449. that it can be "allButtons" to get them all. You
  35450. can change this later with the setTitleBarButtonsRequired()
  35451. method, which can also specify where they are positioned.
  35452. @param addToDesktop if true, the window will be automatically added to the
  35453. desktop; if false, you can use it as a child component
  35454. @see TitleBarButtons
  35455. */
  35456. DocumentWindow (const String& name,
  35457. const Colour& backgroundColour,
  35458. const int requiredButtons,
  35459. const bool addToDesktop = true);
  35460. /** Destructor.
  35461. If a content component has been set with setContentComponent(), it
  35462. will be deleted.
  35463. */
  35464. ~DocumentWindow();
  35465. /** Changes the component's name.
  35466. (This is overridden from Component::setName() to cause a repaint, as
  35467. the name is what gets drawn across the window's title bar).
  35468. */
  35469. void setName (const String& newName);
  35470. /** Sets an icon to show in the title bar, next to the title.
  35471. A copy is made internally of the image, so the caller can delete the
  35472. image after calling this. If 0 is passed-in, any existing icon will be
  35473. removed.
  35474. */
  35475. void setIcon (const Image* imageToUse);
  35476. /** Changes the height of the title-bar. */
  35477. void setTitleBarHeight (const int newHeight);
  35478. /** Returns the current title bar height. */
  35479. int getTitleBarHeight() const;
  35480. /** Changes the set of title-bar buttons being shown.
  35481. @param requiredButtons specifies which of the buttons (close, minimise, maximise)
  35482. should be shown on the title bar. This value is a bitwise
  35483. combination of values from the TitleBarButtons enum. Note
  35484. that it can be "allButtons" to get them all.
  35485. @param positionTitleBarButtonsOnLeft if true, the buttons should go at the
  35486. left side of the bar; if false, they'll be placed at the right
  35487. */
  35488. void setTitleBarButtonsRequired (const int requiredButtons,
  35489. const bool positionTitleBarButtonsOnLeft);
  35490. /** Sets whether the title should be centred within the window.
  35491. If true, the title text is shown in the middle of the title-bar; if false,
  35492. it'll be shown at the left of the bar.
  35493. */
  35494. void setTitleBarTextCentred (const bool textShouldBeCentred);
  35495. /** Creates a menu inside this window.
  35496. @param menuBarModel this specifies a MenuBarModel that should be used to
  35497. generate the contents of a menu bar that will be placed
  35498. just below the title bar, and just above any content
  35499. component. If this value is zero, any existing menu bar
  35500. will be removed from the component; if non-zero, one will
  35501. be added if it's required.
  35502. @param menuBarHeight the height of the menu bar component, if one is needed. Pass a value of zero
  35503. or less to use the look-and-feel's default size.
  35504. */
  35505. void setMenuBar (MenuBarModel* menuBarModel,
  35506. const int menuBarHeight = 0);
  35507. /** This method is called when the user tries to close the window.
  35508. This is triggered by the user clicking the close button, or using some other
  35509. OS-specific key shortcut or OS menu for getting rid of a window.
  35510. If the window is just a pop-up, you should override this closeButtonPressed()
  35511. method and make it delete the window in whatever way is appropriate for your
  35512. app. E.g. you might just want to call "delete this".
  35513. If your app is centred around this window such that the whole app should quit when
  35514. the window is closed, then you will probably want to use this method as an opportunity
  35515. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  35516. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  35517. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  35518. or closing it via the taskbar icon on Windows).
  35519. (Note that the DocumentWindow class overrides Component::userTriedToCloseWindow() and
  35520. redirects it to call this method, so any methods of closing the window that are
  35521. caught by userTriedToCloseWindow() will also end up here).
  35522. */
  35523. virtual void closeButtonPressed();
  35524. /** Callback that is triggered when the minimise button is pressed.
  35525. The default implementation of this calls ResizableWindow::setMinimised(), but
  35526. you can override it to do more customised behaviour.
  35527. */
  35528. virtual void minimiseButtonPressed();
  35529. /** Callback that is triggered when the maximise button is pressed, or when the
  35530. title-bar is double-clicked.
  35531. The default implementation of this calls ResizableWindow::setFullScreen(), but
  35532. you can override it to do more customised behaviour.
  35533. */
  35534. virtual void maximiseButtonPressed();
  35535. /** Returns the close button, (or 0 if there isn't one). */
  35536. Button* getCloseButton() const throw();
  35537. /** Returns the minimise button, (or 0 if there isn't one). */
  35538. Button* getMinimiseButton() const throw();
  35539. /** Returns the maximise button, (or 0 if there isn't one). */
  35540. Button* getMaximiseButton() const throw();
  35541. /** @internal */
  35542. void paint (Graphics& g);
  35543. /** @internal */
  35544. void resized();
  35545. /** @internal */
  35546. void lookAndFeelChanged();
  35547. /** @internal */
  35548. const BorderSize getBorderThickness();
  35549. /** @internal */
  35550. const BorderSize getContentComponentBorder();
  35551. /** @internal */
  35552. void mouseDoubleClick (const MouseEvent& e);
  35553. /** @internal */
  35554. void userTriedToCloseWindow();
  35555. /** @internal */
  35556. void activeWindowStatusChanged();
  35557. /** @internal */
  35558. int getDesktopWindowStyleFlags() const;
  35559. /** @internal */
  35560. void parentHierarchyChanged();
  35561. juce_UseDebuggingNewOperator
  35562. private:
  35563. int titleBarHeight, menuBarHeight, requiredButtons;
  35564. bool positionTitleBarButtonsOnLeft, drawTitleTextCentred;
  35565. Button* titleBarButtons [3];
  35566. Image* titleBarIcon;
  35567. MenuBarComponent* menuBar;
  35568. MenuBarModel* menuBarModel;
  35569. class ButtonListenerProxy : public ButtonListener
  35570. {
  35571. public:
  35572. ButtonListenerProxy();
  35573. void buttonClicked (Button* button);
  35574. DocumentWindow* owner;
  35575. } buttonListener;
  35576. int getBorderSize() const;
  35577. void repaintTitleBar();
  35578. DocumentWindow (const DocumentWindow&);
  35579. const DocumentWindow& operator= (const DocumentWindow&);
  35580. };
  35581. #endif // __JUCE_DOCUMENTWINDOW_JUCEHEADER__
  35582. /********* End of inlined file: juce_DocumentWindow.h *********/
  35583. class MultiDocumentPanel;
  35584. class MDITabbedComponentInternal;
  35585. /**
  35586. This is a derivative of DocumentWindow that is used inside a MultiDocumentPanel
  35587. component.
  35588. It's like a normal DocumentWindow but has some extra functionality to make sure
  35589. everything works nicely inside a MultiDocumentPanel.
  35590. @see MultiDocumentPanel
  35591. */
  35592. class JUCE_API MultiDocumentPanelWindow : public DocumentWindow
  35593. {
  35594. public:
  35595. /**
  35596. */
  35597. MultiDocumentPanelWindow (const Colour& backgroundColour);
  35598. /** Destructor. */
  35599. ~MultiDocumentPanelWindow();
  35600. /** @internal */
  35601. void maximiseButtonPressed();
  35602. /** @internal */
  35603. void closeButtonPressed();
  35604. /** @internal */
  35605. void activeWindowStatusChanged();
  35606. /** @internal */
  35607. void broughtToFront();
  35608. juce_UseDebuggingNewOperator
  35609. private:
  35610. void updateOrder();
  35611. MultiDocumentPanel* getOwner() const throw();
  35612. };
  35613. /**
  35614. A component that contains a set of other components either in floating windows
  35615. or tabs.
  35616. This acts as a panel that can be used to hold a set of open document windows, with
  35617. different layout modes.
  35618. Use addDocument() and closeDocument() to add or remove components from the
  35619. panel - never use any of the Component methods to access the panel's child
  35620. components directly, as these are managed internally.
  35621. */
  35622. class JUCE_API MultiDocumentPanel : public Component,
  35623. private ComponentListener
  35624. {
  35625. public:
  35626. /** Creates an empty panel.
  35627. Use addDocument() and closeDocument() to add or remove components from the
  35628. panel - never use any of the Component methods to access the panel's child
  35629. components directly, as these are managed internally.
  35630. */
  35631. MultiDocumentPanel();
  35632. /** Destructor.
  35633. When deleted, this will call closeAllDocuments (false) to make sure all its
  35634. components are deleted. If you need to make sure all documents are saved
  35635. before closing, then you should call closeAllDocuments (true) and check that
  35636. it returns true before deleting the panel.
  35637. */
  35638. ~MultiDocumentPanel();
  35639. /** Tries to close all the documents.
  35640. If checkItsOkToCloseFirst is true, then the tryToCloseDocument() method will
  35641. be called for each open document, and any of these calls fails, this method
  35642. will stop and return false, leaving some documents still open.
  35643. If checkItsOkToCloseFirst is false, then all documents will be closed
  35644. unconditionally.
  35645. @see closeDocument
  35646. */
  35647. bool closeAllDocuments (const bool checkItsOkToCloseFirst);
  35648. /** Adds a document component to the panel.
  35649. If the number of documents would exceed the limit set by setMaximumNumDocuments() then
  35650. this will fail and return false. (If it does fail, the component passed-in will not be
  35651. deleted, even if deleteWhenRemoved was set to true).
  35652. The MultiDocumentPanel will deal with creating a window border to go around your component,
  35653. so just pass in the bare content component here, no need to give it a ResizableWindow
  35654. or DocumentWindow.
  35655. @param component the component to add
  35656. @param backgroundColour the background colour to use to fill the component's
  35657. window or tab
  35658. @param deleteWhenRemoved if true, then when the component is removed by closeDocument()
  35659. or closeAllDocuments(), then it will be deleted. If false, then
  35660. the caller must handle the component's deletion
  35661. */
  35662. bool addDocument (Component* const component,
  35663. const Colour& backgroundColour,
  35664. const bool deleteWhenRemoved);
  35665. /** Closes one of the documents.
  35666. If checkItsOkToCloseFirst is true, then the tryToCloseDocument() method will
  35667. be called, and if it fails, this method will return false without closing the
  35668. document.
  35669. If checkItsOkToCloseFirst is false, then the documents will be closed
  35670. unconditionally.
  35671. The component will be deleted if the deleteWhenRemoved parameter was set to
  35672. true when it was added with addDocument.
  35673. @see addDocument, closeAllDocuments
  35674. */
  35675. bool closeDocument (Component* component,
  35676. const bool checkItsOkToCloseFirst);
  35677. /** Returns the number of open document windows.
  35678. @see getDocument
  35679. */
  35680. int getNumDocuments() const throw();
  35681. /** Returns one of the open documents.
  35682. The order of the documents in this array may change when they are added, removed
  35683. or moved around.
  35684. @see getNumDocuments
  35685. */
  35686. Component* getDocument (const int index) const throw();
  35687. /** Returns the document component that is currently focused or on top.
  35688. If currently using floating windows, then this will be the component in the currently
  35689. active window, or the top component if none are active.
  35690. If it's currently in tabbed mode, then it'll return the component in the active tab.
  35691. @see setActiveDocument
  35692. */
  35693. Component* getActiveDocument() const throw();
  35694. /** Makes one of the components active and brings it to the top.
  35695. @see getActiveDocument
  35696. */
  35697. void setActiveDocument (Component* component);
  35698. /** Callback which gets invoked when the currently-active document changes. */
  35699. virtual void activeDocumentChanged();
  35700. /** Sets a limit on how many windows can be open at once.
  35701. If this is zero or less there's no limit (the default). addDocument() will fail
  35702. if this number is exceeded.
  35703. */
  35704. void setMaximumNumDocuments (const int maximumNumDocuments);
  35705. /** Sets an option to make the document fullscreen if there's only one document open.
  35706. If set to true, then if there's only one document, it'll fill the whole of this
  35707. component without tabs or a window border. If false, then tabs or a window
  35708. will always be shown, even if there's only one document. If there's more than
  35709. one document open, then this option makes no difference.
  35710. */
  35711. void useFullscreenWhenOneDocument (const bool shouldUseTabs);
  35712. /** Returns the result of the last time useFullscreenWhenOneDocument() was called.
  35713. */
  35714. bool isFullscreenWhenOneDocument() const throw();
  35715. /** The different layout modes available. */
  35716. enum LayoutMode
  35717. {
  35718. FloatingWindows, /**< In this mode, there are overlapping DocumentWindow components for each document. */
  35719. MaximisedWindowsWithTabs /**< In this mode, a TabbedComponent is used to show one document at a time. */
  35720. };
  35721. /** Changes the panel's mode.
  35722. @see LayoutMode, getLayoutMode
  35723. */
  35724. void setLayoutMode (const LayoutMode newLayoutMode);
  35725. /** Returns the current layout mode. */
  35726. LayoutMode getLayoutMode() const throw() { return mode; }
  35727. /** Sets the background colour for the whole panel.
  35728. Each document has its own background colour, but this is the one used to fill the areas
  35729. behind them.
  35730. */
  35731. void setBackgroundColour (const Colour& newBackgroundColour);
  35732. /** Returns the current background colour.
  35733. @see setBackgroundColour
  35734. */
  35735. const Colour& getBackgroundColour() const throw() { return backgroundColour; }
  35736. /** A subclass must override this to say whether its currently ok for a document
  35737. to be closed.
  35738. This method is called by closeDocument() and closeAllDocuments() to indicate that
  35739. a document should be saved if possible, ready for it to be closed.
  35740. If this method returns true, then it means the document is ok and can be closed.
  35741. If it returns false, then it means that the closeDocument() method should stop
  35742. and not close.
  35743. Normally, you'd use this method to ask the user if they want to save any changes,
  35744. then return true if the save operation went ok. If the user cancelled the save
  35745. operation you could return false here to abort the close operation.
  35746. If your component is based on the FileBasedDocument class, then you'd probably want
  35747. to call FileBasedDocument::saveIfNeededAndUserAgrees() and return true if this returned
  35748. FileBasedDocument::savedOk
  35749. @see closeDocument, FileBasedDocument::saveIfNeededAndUserAgrees()
  35750. */
  35751. virtual bool tryToCloseDocument (Component* component) = 0;
  35752. /** Creates a new window to be used for a document.
  35753. The default implementation of this just returns a basic MultiDocumentPanelWindow object,
  35754. but you might want to override it to return a custom component.
  35755. */
  35756. virtual MultiDocumentPanelWindow* createNewDocumentWindow();
  35757. /** @internal */
  35758. void paint (Graphics& g);
  35759. /** @internal */
  35760. void resized();
  35761. /** @internal */
  35762. void componentNameChanged (Component&);
  35763. juce_UseDebuggingNewOperator
  35764. private:
  35765. LayoutMode mode;
  35766. Array <Component*> components;
  35767. TabbedComponent* tabComponent;
  35768. Colour backgroundColour;
  35769. int maximumNumDocuments, numDocsBeforeTabsUsed;
  35770. friend class MultiDocumentPanelWindow;
  35771. friend class MDITabbedComponentInternal;
  35772. Component* getContainerComp (Component* c) const;
  35773. void updateOrder();
  35774. void addWindow (Component* component);
  35775. };
  35776. #endif // __JUCE_MULTIDOCUMENTPANEL_JUCEHEADER__
  35777. /********* End of inlined file: juce_MultiDocumentPanel.h *********/
  35778. #endif
  35779. #ifndef __JUCE_RESIZABLEBORDERCOMPONENT_JUCEHEADER__
  35780. #endif
  35781. #ifndef __JUCE_RESIZABLECORNERCOMPONENT_JUCEHEADER__
  35782. #endif
  35783. #ifndef __JUCE_SCROLLBAR_JUCEHEADER__
  35784. #endif
  35785. #ifndef __JUCE_STRETCHABLELAYOUTMANAGER_JUCEHEADER__
  35786. /********* Start of inlined file: juce_StretchableLayoutManager.h *********/
  35787. #ifndef __JUCE_STRETCHABLELAYOUTMANAGER_JUCEHEADER__
  35788. #define __JUCE_STRETCHABLELAYOUTMANAGER_JUCEHEADER__
  35789. /**
  35790. For laying out a set of components, where the components have preferred sizes
  35791. and size limits, but where they are allowed to stretch to fill the available
  35792. space.
  35793. For example, if you have a component containing several other components, and
  35794. each one should be given a share of the total size, you could use one of these
  35795. to resize the child components when the parent component is resized. Then
  35796. you could add a StretchableLayoutResizerBar to easily let the user rescale them.
  35797. A StretchableLayoutManager operates only in one dimension, so if you have a set
  35798. of components stacked vertically on top of each other, you'd use one to manage their
  35799. heights. To build up complex arrangements of components, e.g. for applications
  35800. with multiple nested panels, you would use more than one StretchableLayoutManager.
  35801. E.g. by using two (one vertical, one horizontal), you could create a resizable
  35802. spreadsheet-style table.
  35803. E.g.
  35804. @code
  35805. class MyComp : public Component
  35806. {
  35807. StretchableLayoutManager myLayout;
  35808. MyComp()
  35809. {
  35810. myLayout.setItemLayout (0, // for item 0
  35811. 50, 100, // must be between 50 and 100 pixels in size
  35812. -0.6); // and its preferred size is 60% of the total available space
  35813. myLayout.setItemLayout (1, // for item 1
  35814. -0.2, -0.6, // size must be between 20% and 60% of the available space
  35815. 50); // and its preferred size is 50 pixels
  35816. }
  35817. void resized()
  35818. {
  35819. // make a list of two of our child components that we want to reposition
  35820. Component* comps[] = { myComp1, myComp2 };
  35821. // this will position the 2 components, one above the other, to fit
  35822. // vertically into the rectangle provided.
  35823. myLayout.layOutComponents (comps, 2,
  35824. 0, 0, getWidth(), getHeight(),
  35825. true);
  35826. }
  35827. };
  35828. @endcode
  35829. @see StretchableLayoutResizerBar
  35830. */
  35831. class JUCE_API StretchableLayoutManager
  35832. {
  35833. public:
  35834. /** Creates an empty layout.
  35835. You'll need to add some item properties to the layout before it can be used
  35836. to resize things - see setItemLayout().
  35837. */
  35838. StretchableLayoutManager();
  35839. /** Destructor. */
  35840. ~StretchableLayoutManager();
  35841. /** For a numbered item, this sets its size limits and preferred size.
  35842. @param itemIndex the index of the item to change.
  35843. @param minimumSize the minimum size that this item is allowed to be - a positive number
  35844. indicates an absolute size in pixels. A negative number indicates a
  35845. proportion of the available space (e.g -0.5 is 50%)
  35846. @param maximumSize the maximum size that this item is allowed to be - a positive number
  35847. indicates an absolute size in pixels. A negative number indicates a
  35848. proportion of the available space
  35849. @param preferredSize the size that this item would like to be, if there's enough room. A
  35850. positive number indicates an absolute size in pixels. A negative number
  35851. indicates a proportion of the available space
  35852. @see getItemLayout
  35853. */
  35854. void setItemLayout (const int itemIndex,
  35855. const double minimumSize,
  35856. const double maximumSize,
  35857. const double preferredSize);
  35858. /** For a numbered item, this returns its size limits and preferred size.
  35859. @param itemIndex the index of the item.
  35860. @param minimumSize the minimum size that this item is allowed to be - a positive number
  35861. indicates an absolute size in pixels. A negative number indicates a
  35862. proportion of the available space (e.g -0.5 is 50%)
  35863. @param maximumSize the maximum size that this item is allowed to be - a positive number
  35864. indicates an absolute size in pixels. A negative number indicates a
  35865. proportion of the available space
  35866. @param preferredSize the size that this item would like to be, if there's enough room. A
  35867. positive number indicates an absolute size in pixels. A negative number
  35868. indicates a proportion of the available space
  35869. @returns false if the item's properties hadn't been set
  35870. @see setItemLayout
  35871. */
  35872. bool getItemLayout (const int itemIndex,
  35873. double& minimumSize,
  35874. double& maximumSize,
  35875. double& preferredSize) const;
  35876. /** Clears all the properties that have been set with setItemLayout() and resets
  35877. this object to its initial state.
  35878. */
  35879. void clearAllItems();
  35880. /** Takes a set of components that correspond to the layout's items, and positions
  35881. them to fill a space.
  35882. This will try to give each item its preferred size, whether that's a relative size
  35883. or an absolute one.
  35884. @param components an array of components that correspond to each of the
  35885. numbered items that the StretchableLayoutManager object
  35886. has been told about with setItemLayout()
  35887. @param numComponents the number of components in the array that is passed-in. This
  35888. should be the same as the number of items this object has been
  35889. told about.
  35890. @param x the left of the rectangle in which the components should
  35891. be laid out
  35892. @param y the top of the rectangle in which the components should
  35893. be laid out
  35894. @param width the width of the rectangle in which the components should
  35895. be laid out
  35896. @param height the height of the rectangle in which the components should
  35897. be laid out
  35898. @param vertically if true, the components will be positioned in a vertical stack,
  35899. so that they fill the height of the rectangle. If false, they
  35900. will be placed side-by-side in a horizontal line, filling the
  35901. available width
  35902. @param resizeOtherDimension if true, this means that the components will have their
  35903. other dimension resized to fit the space - i.e. if the 'vertically'
  35904. parameter is true, their x-positions and widths are adjusted to fit
  35905. the x and width parameters; if 'vertically' is false, their y-positions
  35906. and heights are adjusted to fit the y and height parameters.
  35907. */
  35908. void layOutComponents (Component** const components,
  35909. int numComponents,
  35910. int x, int y, int width, int height,
  35911. const bool vertically,
  35912. const bool resizeOtherDimension);
  35913. /** Returns the current position of one of the items.
  35914. This is only a valid call after layOutComponents() has been called, as it
  35915. returns the last position that this item was placed at. If the layout was
  35916. vertical, the value returned will be the y position of the top of the item,
  35917. relative to the top of the rectangle in which the items were placed (so for
  35918. example, item 0 will always have position of 0, even in the rectangle passed
  35919. in to layOutComponents() wasn't at y = 0). If the layout was done horizontally,
  35920. the position returned is the item's left-hand position, again relative to the
  35921. x position of the rectangle used.
  35922. @see getItemCurrentSize, setItemPosition
  35923. */
  35924. int getItemCurrentPosition (const int itemIndex) const;
  35925. /** Returns the current size of one of the items.
  35926. This is only meaningful after layOutComponents() has been called, as it
  35927. returns the last size that this item was given. If the layout was done
  35928. vertically, it'll return the item's height in pixels; if it was horizontal,
  35929. it'll return its width.
  35930. @see getItemCurrentRelativeSize
  35931. */
  35932. int getItemCurrentAbsoluteSize (const int itemIndex) const;
  35933. /** Returns the current size of one of the items.
  35934. This is only meaningful after layOutComponents() has been called, as it
  35935. returns the last size that this item was given. If the layout was done
  35936. vertically, it'll return a negative value representing the item's height relative
  35937. to the last size used for laying the components out; if the layout was done
  35938. horizontally it'll be the proportion of its width.
  35939. @see getItemCurrentAbsoluteSize
  35940. */
  35941. double getItemCurrentRelativeSize (const int itemIndex) const;
  35942. /** Moves one of the items, shifting along any other items as necessary in
  35943. order to get it to the desired position.
  35944. Calling this method will also update the preferred sizes of the items it
  35945. shuffles along, so that they reflect their new positions.
  35946. (This is the method that a StretchableLayoutResizerBar uses to shift the items
  35947. about when it's dragged).
  35948. @param itemIndex the item to move
  35949. @param newPosition the absolute position that you'd like this item to move
  35950. to. The item might not be able to always reach exactly this position,
  35951. because other items may have minimum sizes that constrain how
  35952. far it can go
  35953. */
  35954. void setItemPosition (const int itemIndex,
  35955. int newPosition);
  35956. juce_UseDebuggingNewOperator
  35957. private:
  35958. struct ItemLayoutProperties
  35959. {
  35960. int itemIndex;
  35961. int currentSize;
  35962. double minSize, maxSize, preferredSize;
  35963. };
  35964. OwnedArray <ItemLayoutProperties> items;
  35965. int totalSize;
  35966. static int sizeToRealSize (double size, int totalSpace);
  35967. ItemLayoutProperties* getInfoFor (const int itemIndex) const;
  35968. void setTotalSize (const int newTotalSize);
  35969. int fitComponentsIntoSpace (const int startIndex,
  35970. const int endIndex,
  35971. const int availableSpace,
  35972. int startPos);
  35973. int getMinimumSizeOfItems (const int startIndex, const int endIndex) const;
  35974. int getMaximumSizeOfItems (const int startIndex, const int endIndex) const;
  35975. void updatePrefSizesToMatchCurrentPositions();
  35976. StretchableLayoutManager (const StretchableLayoutManager&);
  35977. const StretchableLayoutManager& operator= (const StretchableLayoutManager&);
  35978. };
  35979. #endif // __JUCE_STRETCHABLELAYOUTMANAGER_JUCEHEADER__
  35980. /********* End of inlined file: juce_StretchableLayoutManager.h *********/
  35981. #endif
  35982. #ifndef __JUCE_STRETCHABLELAYOUTRESIZERBAR_JUCEHEADER__
  35983. /********* Start of inlined file: juce_StretchableLayoutResizerBar.h *********/
  35984. #ifndef __JUCE_STRETCHABLELAYOUTRESIZERBAR_JUCEHEADER__
  35985. #define __JUCE_STRETCHABLELAYOUTRESIZERBAR_JUCEHEADER__
  35986. /**
  35987. A component that acts as one of the vertical or horizontal bars you see being
  35988. used to resize panels in a window.
  35989. One of these acts with a StretchableLayoutManager to resize the other components.
  35990. @see StretchableLayoutManager
  35991. */
  35992. class JUCE_API StretchableLayoutResizerBar : public Component
  35993. {
  35994. public:
  35995. /** Creates a resizer bar for use on a specified layout.
  35996. @param layoutToUse the layout that will be affected when this bar
  35997. is dragged
  35998. @param itemIndexInLayout the item index in the layout that corresponds to
  35999. this bar component. You'll need to set up the item
  36000. properties in a suitable way for a divider bar, e.g.
  36001. for an 8-pixel wide bar which, you could call
  36002. myLayout->setItemLayout (barIndex, 8, 8, 8)
  36003. @param isBarVertical true if it's an upright bar that you drag left and
  36004. right; false for a horizontal one that you drag up and
  36005. down
  36006. */
  36007. StretchableLayoutResizerBar (StretchableLayoutManager* const layoutToUse,
  36008. const int itemIndexInLayout,
  36009. const bool isBarVertical);
  36010. /** Destructor. */
  36011. ~StretchableLayoutResizerBar();
  36012. /** This is called when the bar is dragged.
  36013. This method must update the positions of any components whose position is
  36014. determined by the StretchableLayoutManager, because they might have just
  36015. moved.
  36016. The default implementation calls the resized() method of this component's
  36017. parent component, because that's often where you're likely to apply the
  36018. layout, but it can be overridden for more specific needs.
  36019. */
  36020. virtual void hasBeenMoved();
  36021. /** @internal */
  36022. void paint (Graphics& g);
  36023. /** @internal */
  36024. void mouseDown (const MouseEvent& e);
  36025. /** @internal */
  36026. void mouseDrag (const MouseEvent& e);
  36027. juce_UseDebuggingNewOperator
  36028. private:
  36029. StretchableLayoutManager* layout;
  36030. int itemIndex, mouseDownPos;
  36031. bool isVertical;
  36032. StretchableLayoutResizerBar (const StretchableLayoutResizerBar&);
  36033. const StretchableLayoutResizerBar& operator= (const StretchableLayoutResizerBar&);
  36034. };
  36035. #endif // __JUCE_STRETCHABLELAYOUTRESIZERBAR_JUCEHEADER__
  36036. /********* End of inlined file: juce_StretchableLayoutResizerBar.h *********/
  36037. #endif
  36038. #ifndef __JUCE_STRETCHABLEOBJECTRESIZER_JUCEHEADER__
  36039. /********* Start of inlined file: juce_StretchableObjectResizer.h *********/
  36040. #ifndef __JUCE_STRETCHABLEOBJECTRESIZER_JUCEHEADER__
  36041. #define __JUCE_STRETCHABLEOBJECTRESIZER_JUCEHEADER__
  36042. /**
  36043. A utility class for fitting a set of objects whose sizes can vary between
  36044. a minimum and maximum size, into a space.
  36045. This is a trickier algorithm than it would first seem, so I've put it in this
  36046. class to allow it to be shared by various bits of code.
  36047. To use it, create one of these objects, call addItem() to add the list of items
  36048. you need, then call resizeToFit(), which will change all their sizes. You can
  36049. then retrieve the new sizes with getItemSize() and getNumItems().
  36050. It's currently used by the TableHeaderComponent for stretching out the table
  36051. headings to fill the table's width.
  36052. */
  36053. class StretchableObjectResizer
  36054. {
  36055. public:
  36056. /** Creates an empty object resizer. */
  36057. StretchableObjectResizer();
  36058. /** Destructor. */
  36059. ~StretchableObjectResizer();
  36060. /** Adds an item to the list.
  36061. The order parameter lets you specify groups of items that are resized first when some
  36062. space needs to be found. Those items with an order of 0 will be the first ones to be
  36063. resized, and if that doesn't provide enough space to meet the requirements, the algorithm
  36064. will then try resizing the items with an order of 1, then 2, and so on.
  36065. */
  36066. void addItem (const double currentSize,
  36067. const double minSize,
  36068. const double maxSize,
  36069. const int order = 0);
  36070. /** Resizes all the items to fit this amount of space.
  36071. This will attempt to fit them in without exceeding each item's miniumum and
  36072. maximum sizes. In cases where none of the items can be expanded or enlarged any
  36073. further, the final size may be greater or less than the size passed in.
  36074. After calling this method, you can retrieve the new sizes with the getItemSize()
  36075. method.
  36076. */
  36077. void resizeToFit (const double targetSize);
  36078. /** Returns the number of items that have been added. */
  36079. int getNumItems() const throw() { return items.size(); }
  36080. /** Returns the size of one of the items. */
  36081. double getItemSize (const int index) const throw();
  36082. juce_UseDebuggingNewOperator
  36083. private:
  36084. struct Item
  36085. {
  36086. double size;
  36087. double minSize;
  36088. double maxSize;
  36089. int order;
  36090. };
  36091. OwnedArray <Item> items;
  36092. StretchableObjectResizer (const StretchableObjectResizer&);
  36093. const StretchableObjectResizer& operator= (const StretchableObjectResizer&);
  36094. };
  36095. #endif // __JUCE_STRETCHABLEOBJECTRESIZER_JUCEHEADER__
  36096. /********* End of inlined file: juce_StretchableObjectResizer.h *********/
  36097. #endif
  36098. #ifndef __JUCE_TABBEDBUTTONBAR_JUCEHEADER__
  36099. #endif
  36100. #ifndef __JUCE_TABBEDCOMPONENT_JUCEHEADER__
  36101. #endif
  36102. #ifndef __JUCE_VIEWPORT_JUCEHEADER__
  36103. #endif
  36104. #ifndef __JUCE_DIRECTORYCONTENTSDISPLAYCOMPONENT_JUCEHEADER__
  36105. /********* Start of inlined file: juce_DirectoryContentsDisplayComponent.h *********/
  36106. #ifndef __JUCE_DIRECTORYCONTENTSDISPLAYCOMPONENT_JUCEHEADER__
  36107. #define __JUCE_DIRECTORYCONTENTSDISPLAYCOMPONENT_JUCEHEADER__
  36108. /********* Start of inlined file: juce_DirectoryContentsList.h *********/
  36109. #ifndef __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__
  36110. #define __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__
  36111. /********* Start of inlined file: juce_FileFilter.h *********/
  36112. #ifndef __JUCE_FILEFILTER_JUCEHEADER__
  36113. #define __JUCE_FILEFILTER_JUCEHEADER__
  36114. /**
  36115. Interface for deciding which files are suitable for something.
  36116. For example, this is used by DirectoryContentsList to select which files
  36117. go into the list.
  36118. @see WildcardFileFilter, DirectoryContentsList, FileListComponent, FileBrowserComponent
  36119. */
  36120. class JUCE_API FileFilter
  36121. {
  36122. public:
  36123. /** Creates a filter with the given description.
  36124. The description can be returned later with the getDescription() method.
  36125. */
  36126. FileFilter (const String& filterDescription);
  36127. /** Destructor. */
  36128. virtual ~FileFilter();
  36129. /** Returns the description that the filter was created with. */
  36130. const String& getDescription() const throw();
  36131. /** Should return true if this file is suitable for inclusion in whatever context
  36132. the object is being used.
  36133. */
  36134. virtual bool isFileSuitable (const File& file) const = 0;
  36135. /** Should return true if this directory is suitable for inclusion in whatever context
  36136. the object is being used.
  36137. */
  36138. virtual bool isDirectorySuitable (const File& file) const = 0;
  36139. protected:
  36140. String description;
  36141. };
  36142. #endif // __JUCE_FILEFILTER_JUCEHEADER__
  36143. /********* End of inlined file: juce_FileFilter.h *********/
  36144. /**
  36145. A class to asynchronously scan for details about the files in a directory.
  36146. This keeps a list of files and some information about them, using a background
  36147. thread to scan for more files. As files are found, it broadcasts change messages
  36148. to tell any listeners.
  36149. @see FileListComponent, FileBrowserComponent
  36150. */
  36151. class JUCE_API DirectoryContentsList : public ChangeBroadcaster,
  36152. public TimeSliceClient
  36153. {
  36154. public:
  36155. /** Creates a directory list.
  36156. To set the directory it should point to, use setDirectory(), which will
  36157. also start it scanning for files on the background thread.
  36158. When the background thread finds and adds new files to this list, the
  36159. ChangeBroadcaster class will send a change message, so you can register
  36160. listeners and update them when the list changes.
  36161. @param fileFilter an optional filter to select which files are
  36162. included in the list. If this is 0, then all files
  36163. and directories are included. Make sure that the
  36164. filter doesn't get deleted during the lifetime of this
  36165. object
  36166. @param threadToUse a thread object that this list can use
  36167. to scan for files as a background task. Make sure
  36168. that the thread you give it has been started, or you
  36169. won't get any files!
  36170. */
  36171. DirectoryContentsList (const FileFilter* const fileFilter,
  36172. TimeSliceThread& threadToUse);
  36173. /** Destructor. */
  36174. ~DirectoryContentsList();
  36175. /** Sets the directory to look in for files.
  36176. If the directory that's passed in is different to the current one, this will
  36177. also start the background thread scanning it for files.
  36178. */
  36179. void setDirectory (const File& directory,
  36180. const bool includeDirectories,
  36181. const bool includeFiles);
  36182. /** Returns the directory that's currently being used. */
  36183. const File& getDirectory() const throw();
  36184. /** Clears the list, and stops the thread scanning for files. */
  36185. void clear();
  36186. /** Clears the list and restarts scanning the directory for files. */
  36187. void refresh();
  36188. /** True if the background thread hasn't yet finished scanning for files. */
  36189. bool isStillLoading() const;
  36190. /** Tells the list whether or not to ignore hidden files.
  36191. By default these are ignored.
  36192. */
  36193. void setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles);
  36194. /** Contains cached information about one of the files in a DirectoryContentsList.
  36195. */
  36196. struct FileInfo
  36197. {
  36198. /** The filename.
  36199. This isn't a full pathname, it's just the last part of the path, same as you'd
  36200. get from File::getFileName().
  36201. To get the full pathname, use DirectoryContentsList::getDirectory().getChildFile (filename).
  36202. */
  36203. String filename;
  36204. /** File size in bytes. */
  36205. int64 fileSize;
  36206. /** File modification time.
  36207. As supplied by File::getLastModificationTime().
  36208. */
  36209. Time modificationTime;
  36210. /** File creation time.
  36211. As supplied by File::getCreationTime().
  36212. */
  36213. Time creationTime;
  36214. /** True if the file is a directory. */
  36215. bool isDirectory;
  36216. /** True if the file is read-only. */
  36217. bool isReadOnly;
  36218. };
  36219. /** Returns the number of files currently available in the list.
  36220. The info about one of these files can be retrieved with getFileInfo() or
  36221. getFile().
  36222. Obviously as the background thread runs and scans the directory for files, this
  36223. number will change.
  36224. @see getFileInfo, getFile
  36225. */
  36226. int getNumFiles() const;
  36227. /** Returns the cached information about one of the files in the list.
  36228. If the index is in-range, this will return true and will copy the file's details
  36229. to the structure that is passed-in.
  36230. If it returns false, then the index wasn't in range, and the structure won't
  36231. be affected.
  36232. @see getNumFiles, getFile
  36233. */
  36234. bool getFileInfo (const int index,
  36235. FileInfo& resultInfo) const;
  36236. /** Returns one of the files in the list.
  36237. @param index should be less than getNumFiles(). If this is out-of-range, the
  36238. return value will be File::nonexistent
  36239. @see getNumFiles, getFileInfo
  36240. */
  36241. const File getFile (const int index) const;
  36242. /** Returns the file filter being used.
  36243. The filter is specified in the constructor.
  36244. */
  36245. const FileFilter* getFilter() const throw() { return fileFilter; }
  36246. /** @internal */
  36247. bool useTimeSlice();
  36248. /** @internal */
  36249. TimeSliceThread& getTimeSliceThread() throw() { return thread; }
  36250. /** @internal */
  36251. static int compareElements (const DirectoryContentsList::FileInfo* const first,
  36252. const DirectoryContentsList::FileInfo* const second) throw();
  36253. juce_UseDebuggingNewOperator
  36254. private:
  36255. File root;
  36256. const FileFilter* fileFilter;
  36257. TimeSliceThread& thread;
  36258. bool includeDirectories, includeFiles, ignoreHiddenFiles;
  36259. CriticalSection fileListLock;
  36260. OwnedArray <FileInfo> files;
  36261. void* volatile fileFindHandle;
  36262. bool volatile shouldStop;
  36263. void changed();
  36264. bool checkNextFile (bool& hasChanged);
  36265. bool addFile (const String& filename, const bool isDir, const bool isHidden,
  36266. const int64 fileSize, const Time& modTime,
  36267. const Time& creationTime, const bool isReadOnly);
  36268. DirectoryContentsList (const DirectoryContentsList&);
  36269. const DirectoryContentsList& operator= (const DirectoryContentsList&);
  36270. };
  36271. #endif // __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__
  36272. /********* End of inlined file: juce_DirectoryContentsList.h *********/
  36273. /********* Start of inlined file: juce_FileBrowserListener.h *********/
  36274. #ifndef __JUCE_FILEBROWSERLISTENER_JUCEHEADER__
  36275. #define __JUCE_FILEBROWSERLISTENER_JUCEHEADER__
  36276. /**
  36277. A listener for user selection events in a file browser.
  36278. This is used by a FileBrowserComponent or FileListComponent.
  36279. */
  36280. class JUCE_API FileBrowserListener
  36281. {
  36282. public:
  36283. /** Destructor. */
  36284. virtual ~FileBrowserListener();
  36285. /** Callback when the user selects a different file in the browser. */
  36286. virtual void selectionChanged() = 0;
  36287. /** Callback when the user clicks on a file in the browser. */
  36288. virtual void fileClicked (const File& file, const MouseEvent& e) = 0;
  36289. /** Callback when the user double-clicks on a file in the browser. */
  36290. virtual void fileDoubleClicked (const File& file) = 0;
  36291. };
  36292. #endif // __JUCE_FILEBROWSERLISTENER_JUCEHEADER__
  36293. /********* End of inlined file: juce_FileBrowserListener.h *********/
  36294. /**
  36295. A base class for components that display a list of the files in a directory.
  36296. @see DirectoryContentsList
  36297. */
  36298. class JUCE_API DirectoryContentsDisplayComponent
  36299. {
  36300. public:
  36301. /**
  36302. */
  36303. DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow);
  36304. /** Destructor. */
  36305. virtual ~DirectoryContentsDisplayComponent();
  36306. /** Returns the file that the user has currently selected.
  36307. Returns File::nonexistent if none is selected.
  36308. */
  36309. virtual const File getSelectedFile() const = 0;
  36310. /** Scrolls this view to the top. */
  36311. virtual void scrollToTop() = 0;
  36312. /** Adds a listener to be told when files are selected or clicked.
  36313. @see removeListener
  36314. */
  36315. void addListener (FileBrowserListener* const listener) throw();
  36316. /** Removes a listener.
  36317. @see addListener
  36318. */
  36319. void removeListener (FileBrowserListener* const listener) throw();
  36320. /** A set of colour IDs to use to change the colour of various aspects of the label.
  36321. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  36322. methods.
  36323. Note that you can also use the constants from TextEditor::ColourIds to change the
  36324. colour of the text editor that is opened when a label is editable.
  36325. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  36326. */
  36327. enum ColourIds
  36328. {
  36329. highlightColourId = 0x1000540, /**< The colour to use to fill a highlighted row of the list. */
  36330. textColourId = 0x1000541, /**< The colour for the text. */
  36331. };
  36332. /** @internal */
  36333. void sendSelectionChangeMessage();
  36334. /** @internal */
  36335. void sendDoubleClickMessage (const File& file);
  36336. /** @internal */
  36337. void sendMouseClickMessage (const File& file, const MouseEvent& e);
  36338. juce_UseDebuggingNewOperator
  36339. protected:
  36340. DirectoryContentsList& fileList;
  36341. SortedSet <void*> listeners;
  36342. DirectoryContentsDisplayComponent (const DirectoryContentsDisplayComponent&);
  36343. const DirectoryContentsDisplayComponent& operator= (const DirectoryContentsDisplayComponent&);
  36344. };
  36345. #endif // __JUCE_DIRECTORYCONTENTSDISPLAYCOMPONENT_JUCEHEADER__
  36346. /********* End of inlined file: juce_DirectoryContentsDisplayComponent.h *********/
  36347. #endif
  36348. #ifndef __JUCE_DIRECTORYCONTENTSLIST_JUCEHEADER__
  36349. #endif
  36350. #ifndef __JUCE_FILEBROWSERCOMPONENT_JUCEHEADER__
  36351. /********* Start of inlined file: juce_FileBrowserComponent.h *********/
  36352. #ifndef __JUCE_FILEBROWSERCOMPONENT_JUCEHEADER__
  36353. #define __JUCE_FILEBROWSERCOMPONENT_JUCEHEADER__
  36354. /********* Start of inlined file: juce_FilePreviewComponent.h *********/
  36355. #ifndef __JUCE_FILEPREVIEWCOMPONENT_JUCEHEADER__
  36356. #define __JUCE_FILEPREVIEWCOMPONENT_JUCEHEADER__
  36357. /**
  36358. Base class for components that live inside a file chooser dialog box and
  36359. show previews of the files that get selected.
  36360. One of these allows special extra information to be displayed for files
  36361. in a dialog box as the user selects them. Each time the current file or
  36362. directory is changed, the selectedFileChanged() method will be called
  36363. to allow it to update itself appropriately.
  36364. @see FileChooser, ImagePreviewComponent
  36365. */
  36366. class JUCE_API FilePreviewComponent : public Component
  36367. {
  36368. public:
  36369. /** Creates a FilePreviewComponent. */
  36370. FilePreviewComponent();
  36371. /** Destructor. */
  36372. ~FilePreviewComponent();
  36373. /** Called to indicate that the user's currently selected file has changed.
  36374. @param newSelectedFile the newly selected file or directory, which may be
  36375. File::nonexistent if none is selected.
  36376. */
  36377. virtual void selectedFileChanged (const File& newSelectedFile) = 0;
  36378. juce_UseDebuggingNewOperator
  36379. private:
  36380. FilePreviewComponent (const FilePreviewComponent&);
  36381. const FilePreviewComponent& operator= (const FilePreviewComponent&);
  36382. };
  36383. #endif // __JUCE_FILEPREVIEWCOMPONENT_JUCEHEADER__
  36384. /********* End of inlined file: juce_FilePreviewComponent.h *********/
  36385. /**
  36386. A component for browsing and selecting a file or directory to open or save.
  36387. This contains a FileListComponent and adds various boxes and controls for
  36388. navigating and selecting a file. It can work in different modes so that it can
  36389. be used for loading or saving a file, or for choosing a directory.
  36390. @see FileChooserDialogBox, FileChooser, FileListComponent
  36391. */
  36392. class JUCE_API FileBrowserComponent : public Component,
  36393. public ChangeBroadcaster,
  36394. private FileBrowserListener,
  36395. private TextEditorListener,
  36396. private ButtonListener,
  36397. private ComboBoxListener
  36398. {
  36399. public:
  36400. /** Various modes that the browser can be used in.
  36401. One of these is passed into the constructor.
  36402. */
  36403. enum FileChooserMode
  36404. {
  36405. loadFileMode, /**< the component should allow the user to choose an existing
  36406. file with the intention of opening it. */
  36407. saveFileMode, /**< the component should allow the user to specify the name of
  36408. a file that will be used to save something. */
  36409. chooseDirectoryMode /**< the component should allow the user to select an existing
  36410. directory. */
  36411. };
  36412. /** Creates a FileBrowserComponent.
  36413. @param browserMode The intended purpose for the browser - see the
  36414. FileChooserMode enum for the various options
  36415. @param initialFileOrDirectory The file or directory that should be selected when
  36416. the component begins. If this is File::nonexistent,
  36417. a default directory will be chosen.
  36418. @param fileFilter an optional filter to use to determine which files
  36419. are shown. If this is 0 then all files are displayed. Note
  36420. that a pointer is kept internally to this object, so
  36421. make sure that it is not deleted before the browser object
  36422. is deleted.
  36423. @param previewComp an optional preview component that will be used to
  36424. show previews of files that the user selects
  36425. @param useTreeView if this is false, the files are shown in a list; if true,
  36426. they are shown in a treeview
  36427. @param filenameTextBoxIsReadOnly if true, the user won't be allowed to type their own
  36428. text into the filename box.
  36429. */
  36430. FileBrowserComponent (FileChooserMode browserMode,
  36431. const File& initialFileOrDirectory,
  36432. const FileFilter* fileFilter,
  36433. FilePreviewComponent* previewComp,
  36434. const bool useTreeView = false,
  36435. const bool filenameTextBoxIsReadOnly = false);
  36436. /** Destructor. */
  36437. ~FileBrowserComponent();
  36438. /**
  36439. */
  36440. const File getCurrentFile() const throw();
  36441. /** Returns true if the current file is usable.
  36442. This can be used to decide whether the user can press "ok" for the
  36443. current file. What it does depends on the mode, so for example in an "open"
  36444. mode, the current file is only valid if one has been selected and if the file
  36445. exists. In a "save" mode, a non-existent file would also be valid.
  36446. */
  36447. bool currentFileIsValid() const;
  36448. /** Returns the directory whose contents are currently being shown in the listbox. */
  36449. const File getRoot() const;
  36450. /** Changes the directory that's being shown in the listbox. */
  36451. void setRoot (const File& newRootDirectory);
  36452. /** Equivalent to pressing the "up" button to browse the parent directory. */
  36453. void goUp();
  36454. /** Refreshes the directory that's currently being listed. */
  36455. void refresh();
  36456. /** Returns the browser's current mode. */
  36457. FileChooserMode getMode() const throw() { return mode; }
  36458. /** Returns a verb to describe what should happen when the file is accepted.
  36459. E.g. if browsing in "load file" mode, this will be "Open", if in "save file"
  36460. mode, it'll be "Save", etc.
  36461. */
  36462. virtual const String getActionVerb() const;
  36463. /** Adds a listener to be told when the user selects and clicks on files.
  36464. @see removeListener
  36465. */
  36466. void addListener (FileBrowserListener* const listener) throw();
  36467. /** Removes a listener.
  36468. @see addListener
  36469. */
  36470. void removeListener (FileBrowserListener* const listener) throw();
  36471. /** @internal */
  36472. void resized();
  36473. /** @internal */
  36474. void buttonClicked (Button* b);
  36475. /** @internal */
  36476. void comboBoxChanged (ComboBox*);
  36477. /** @internal */
  36478. void textEditorTextChanged (TextEditor& editor);
  36479. /** @internal */
  36480. void textEditorReturnKeyPressed (TextEditor& editor);
  36481. /** @internal */
  36482. void textEditorEscapeKeyPressed (TextEditor& editor);
  36483. /** @internal */
  36484. void textEditorFocusLost (TextEditor& editor);
  36485. /** @internal */
  36486. void selectionChanged();
  36487. /** @internal */
  36488. void fileClicked (const File& f, const MouseEvent& e);
  36489. /** @internal */
  36490. void fileDoubleClicked (const File& f);
  36491. /** @internal */
  36492. FilePreviewComponent* getPreviewComponent() const throw();
  36493. juce_UseDebuggingNewOperator
  36494. protected:
  36495. virtual const BitArray getRoots (StringArray& rootNames, StringArray& rootPaths);
  36496. private:
  36497. DirectoryContentsList* fileList;
  36498. FileFilter* directoriesOnlyFilter;
  36499. FileChooserMode mode;
  36500. File currentRoot;
  36501. SortedSet <void*> listeners;
  36502. DirectoryContentsDisplayComponent* fileListComponent;
  36503. FilePreviewComponent* previewComp;
  36504. ComboBox* currentPathBox;
  36505. TextEditor* filenameBox;
  36506. Button* goUpButton;
  36507. TimeSliceThread thread;
  36508. void sendListenerChangeMessage();
  36509. FileBrowserComponent (const FileBrowserComponent&);
  36510. const FileBrowserComponent& operator= (const FileBrowserComponent&);
  36511. };
  36512. #endif // __JUCE_FILEBROWSERCOMPONENT_JUCEHEADER__
  36513. /********* End of inlined file: juce_FileBrowserComponent.h *********/
  36514. #endif
  36515. #ifndef __JUCE_FILEBROWSERLISTENER_JUCEHEADER__
  36516. #endif
  36517. #ifndef __JUCE_FILECHOOSER_JUCEHEADER__
  36518. /********* Start of inlined file: juce_FileChooser.h *********/
  36519. #ifndef __JUCE_FILECHOOSER_JUCEHEADER__
  36520. #define __JUCE_FILECHOOSER_JUCEHEADER__
  36521. /**
  36522. Creates a dialog box to choose a file or directory to load or save.
  36523. To use a FileChooser:
  36524. - create one (as a local stack variable is the neatest way)
  36525. - call one of its browseFor.. methods
  36526. - if this returns true, the user has selected a file, so you can retrieve it
  36527. with the getResult() method.
  36528. e.g. @code
  36529. void loadMooseFile()
  36530. {
  36531. FileChooser myChooser ("Please select the moose you want to load...",
  36532. File::getSpecialLocation (File::userHomeDirectory),
  36533. "*.moose");
  36534. if (myChooser.browseForFileToOpen())
  36535. {
  36536. File mooseFile (myChooser.getResult());
  36537. loadMoose (mooseFile);
  36538. }
  36539. }
  36540. @endcode
  36541. */
  36542. class JUCE_API FileChooser
  36543. {
  36544. public:
  36545. /** Creates a FileChooser.
  36546. After creating one of these, use one of the browseFor... methods to display it.
  36547. @param dialogBoxTitle a text string to display in the dialog box to
  36548. tell the user what's going on
  36549. @param initialFileOrDirectory the file or directory that should be selected when
  36550. the dialog box opens. If this parameter is set to
  36551. File::nonexistent, a sensible default directory
  36552. will be used instead.
  36553. @param filePatternsAllowed a set of file patterns to specify which files can be
  36554. selected - each pattern should be separated by a
  36555. comma or semi-colon, e.g. "*" or "*.jpg;*.gif". An
  36556. empty string means that all files are allowed
  36557. @param useOSNativeDialogBox if true, then a native dialog box will be used if
  36558. possible; if false, then a Juce-based browser dialog
  36559. box will always be used
  36560. @see browseForFileToOpen, browseForFileToSave, browseForDirectory
  36561. */
  36562. FileChooser (const String& dialogBoxTitle,
  36563. const File& initialFileOrDirectory = File::nonexistent,
  36564. const String& filePatternsAllowed = String::empty,
  36565. const bool useOSNativeDialogBox = true);
  36566. /** Destructor. */
  36567. ~FileChooser();
  36568. /** Shows a dialog box to choose a file to open.
  36569. This will display the dialog box modally, using an "open file" mode, so that
  36570. it won't allow non-existent files or directories to be chosen.
  36571. @param previewComponent an optional component to display inside the dialog
  36572. box to show special info about the files that the user
  36573. is browsing. The component will not be deleted by this
  36574. object, so the caller must take care of it.
  36575. @returns true if the user selected a file, in which case, use the getResult()
  36576. method to find out what it was. Returns false if they cancelled instead.
  36577. @see browseForFileToSave, browseForDirectory
  36578. */
  36579. bool browseForFileToOpen (FilePreviewComponent* previewComponent = 0);
  36580. /** Same as browseForFileToOpen, but allows the user to select multiple files.
  36581. The files that are returned can be obtained by calling getResults(). See
  36582. browseForFileToOpen() for more info about the behaviour of this method.
  36583. */
  36584. bool browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent = 0);
  36585. /** Shows a dialog box to choose a file to save.
  36586. This will display the dialog box modally, using an "save file" mode, so it
  36587. will allow non-existent files to be chosen, but not directories.
  36588. @param warnAboutOverwritingExistingFiles if true, the dialog box will ask
  36589. the user if they're sure they want to overwrite a file that already
  36590. exists
  36591. @returns true if the user chose a file and pressed 'ok', in which case, use
  36592. the getResult() method to find out what the file was. Returns false
  36593. if they cancelled instead.
  36594. @see browseForFileToOpen, browseForDirectory
  36595. */
  36596. bool browseForFileToSave (const bool warnAboutOverwritingExistingFiles);
  36597. /** Shows a dialog box to choose a directory.
  36598. This will display the dialog box modally, using an "open directory" mode, so it
  36599. will only allow directories to be returned, not files.
  36600. @returns true if the user chose a directory and pressed 'ok', in which case, use
  36601. the getResult() method to find out what they chose. Returns false
  36602. if they cancelled instead.
  36603. @see browseForFileToOpen, browseForFileToSave
  36604. */
  36605. bool browseForDirectory();
  36606. /** Returns the last file that was chosen by one of the browseFor methods.
  36607. After calling the appropriate browseFor... method, this method lets you
  36608. find out what file or directory they chose.
  36609. Note that the file returned is only valid if the browse method returned true (i.e.
  36610. if the user pressed 'ok' rather than cancelling).
  36611. If you're using a multiple-file select, then use the getResults() method instead,
  36612. to obtain the list of all files chosen.
  36613. @see getResults
  36614. */
  36615. const File getResult() const;
  36616. /** Returns a list of all the files that were chosen during the last call to a
  36617. browse method.
  36618. This array may be empty if no files were chosen, or can contain multiple entries
  36619. if multiple files were chosen.
  36620. @see getResult
  36621. */
  36622. const OwnedArray <File>& getResults() const;
  36623. juce_UseDebuggingNewOperator
  36624. private:
  36625. String title, filters;
  36626. File startingFile;
  36627. OwnedArray <File> results;
  36628. bool useNativeDialogBox;
  36629. bool showDialog (const bool isDirectory,
  36630. const bool isSave,
  36631. const bool warnAboutOverwritingExistingFiles,
  36632. const bool selectMultipleFiles,
  36633. FilePreviewComponent* const previewComponent);
  36634. static void showPlatformDialog (OwnedArray<File>& results,
  36635. const String& title,
  36636. const File& file,
  36637. const String& filters,
  36638. bool isDirectory,
  36639. bool isSave,
  36640. bool warnAboutOverwritingExistingFiles,
  36641. bool selectMultipleFiles,
  36642. FilePreviewComponent* previewComponent);
  36643. };
  36644. #endif // __JUCE_FILECHOOSER_JUCEHEADER__
  36645. /********* End of inlined file: juce_FileChooser.h *********/
  36646. #endif
  36647. #ifndef __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  36648. /********* Start of inlined file: juce_FileChooserDialogBox.h *********/
  36649. #ifndef __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  36650. #define __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  36651. /**
  36652. A file open/save dialog box.
  36653. This is a Juce-based file dialog box; to use a native file chooser, see the
  36654. FileChooser class.
  36655. To use one of these, create it and call its show() method. e.g.
  36656. @code
  36657. {
  36658. WildcardFileFilter wildcardFilter (T("*.foo"), T("Foo files"));
  36659. FileBrowserComponent browser (FileBrowserComponent::loadFileMode,
  36660. File::nonexistent,
  36661. &wildcardFilter,
  36662. 0);
  36663. FileChooserDialogBox dialogBox (T("Open some kind of file"),
  36664. T("Please choose some kind of file that you want to open..."),
  36665. browser,
  36666. getLookAndFeel().alertWindowBackground);
  36667. if (dialogBox.show())
  36668. {
  36669. File selectedFile = browser.getCurrentFile();
  36670. ...
  36671. }
  36672. }
  36673. @endcode
  36674. @see FileChooser
  36675. */
  36676. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  36677. public ButtonListener,
  36678. public FileBrowserListener
  36679. {
  36680. public:
  36681. /** Creates a file chooser box.
  36682. @param title the main title to show at the top of the box
  36683. @param instructions an optional longer piece of text to show below the title in
  36684. a smaller font, describing in more detail what's required.
  36685. @param browserComponent a FileBrowserComponent that will be shown inside this dialog
  36686. box. Make sure you delete this after (but not before!) the
  36687. dialog box has been deleted.
  36688. @param warnAboutOverwritingExistingFiles if true, then the user will be asked to confirm
  36689. if they try to select a file that already exists. (This
  36690. flag is only used when saving files)
  36691. @param backgroundColour the background colour for the top level window
  36692. @see FileBrowserComponent, FilePreviewComponent
  36693. */
  36694. FileChooserDialogBox (const String& title,
  36695. const String& instructions,
  36696. FileBrowserComponent& browserComponent,
  36697. const bool warnAboutOverwritingExistingFiles,
  36698. const Colour& backgroundColour);
  36699. /** Destructor. */
  36700. ~FileChooserDialogBox();
  36701. /** Displays and runs the dialog box modally.
  36702. This will show the box with the specified size, returning true if the user
  36703. pressed 'ok', or false if they cancelled.
  36704. Leave the width or height as 0 to use the default size
  36705. */
  36706. bool show (int width = 0,int height = 0);
  36707. /** @internal */
  36708. void buttonClicked (Button* button);
  36709. /** @internal */
  36710. void closeButtonPressed();
  36711. /** @internal */
  36712. void selectionChanged();
  36713. /** @internal */
  36714. void fileClicked (const File& file, const MouseEvent& e);
  36715. /** @internal */
  36716. void fileDoubleClicked (const File& file);
  36717. juce_UseDebuggingNewOperator
  36718. private:
  36719. class ContentComponent : public Component
  36720. {
  36721. public:
  36722. ContentComponent();
  36723. ~ContentComponent();
  36724. void paint (Graphics& g);
  36725. void resized();
  36726. String instructions;
  36727. GlyphArrangement text;
  36728. FileBrowserComponent* chooserComponent;
  36729. FilePreviewComponent* previewComponent;
  36730. TextButton* okButton;
  36731. TextButton* cancelButton;
  36732. };
  36733. ContentComponent* content;
  36734. const bool warnAboutOverwritingExistingFiles;
  36735. FileChooserDialogBox (const FileChooserDialogBox&);
  36736. const FileChooserDialogBox& operator= (const FileChooserDialogBox&);
  36737. };
  36738. #endif // __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  36739. /********* End of inlined file: juce_FileChooserDialogBox.h *********/
  36740. #endif
  36741. #ifndef __JUCE_FILEFILTER_JUCEHEADER__
  36742. #endif
  36743. #ifndef __JUCE_FILELISTCOMPONENT_JUCEHEADER__
  36744. /********* Start of inlined file: juce_FileListComponent.h *********/
  36745. #ifndef __JUCE_FILELISTCOMPONENT_JUCEHEADER__
  36746. #define __JUCE_FILELISTCOMPONENT_JUCEHEADER__
  36747. /**
  36748. A component that displays the files in a directory as a listbox.
  36749. This implements the DirectoryContentsDisplayComponent base class so that
  36750. it can be used in a FileBrowserComponent.
  36751. To attach a listener to it, use its DirectoryContentsDisplayComponent base
  36752. class and the FileBrowserListener class.
  36753. @see DirectoryContentsList, FileTreeComponent
  36754. */
  36755. class JUCE_API FileListComponent : public ListBox,
  36756. public DirectoryContentsDisplayComponent,
  36757. private ListBoxModel,
  36758. private ChangeListener
  36759. {
  36760. public:
  36761. /** Creates a listbox to show the contents of a specified directory.
  36762. */
  36763. FileListComponent (DirectoryContentsList& listToShow);
  36764. /** Destructor. */
  36765. ~FileListComponent();
  36766. /** Returns the file that the user has currently selected.
  36767. Returns File::nonexistent if none is selected.
  36768. */
  36769. const File getSelectedFile() const;
  36770. /** Scrolls to the top of the list. */
  36771. void scrollToTop();
  36772. /** @internal */
  36773. void changeListenerCallback (void*);
  36774. /** @internal */
  36775. int getNumRows();
  36776. /** @internal */
  36777. void paintListBoxItem (int, Graphics&, int, int, bool);
  36778. /** @internal */
  36779. Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate);
  36780. /** @internal */
  36781. void selectedRowsChanged (int lastRowSelected);
  36782. /** @internal */
  36783. void deleteKeyPressed (int currentSelectedRow);
  36784. /** @internal */
  36785. void returnKeyPressed (int currentSelectedRow);
  36786. juce_UseDebuggingNewOperator
  36787. private:
  36788. FileListComponent (const FileListComponent&);
  36789. const FileListComponent& operator= (const FileListComponent&);
  36790. File lastDirectory;
  36791. };
  36792. #endif // __JUCE_FILELISTCOMPONENT_JUCEHEADER__
  36793. /********* End of inlined file: juce_FileListComponent.h *********/
  36794. #endif
  36795. #ifndef __JUCE_FILENAMECOMPONENT_JUCEHEADER__
  36796. /********* Start of inlined file: juce_FilenameComponent.h *********/
  36797. #ifndef __JUCE_FILENAMECOMPONENT_JUCEHEADER__
  36798. #define __JUCE_FILENAMECOMPONENT_JUCEHEADER__
  36799. class FilenameComponent;
  36800. /**
  36801. Listens for events happening to a FilenameComponent.
  36802. Use FilenameComponent::addListener() and FilenameComponent::removeListener() to
  36803. register one of these objects for event callbacks when the filename is changed.
  36804. @See FilenameComponent
  36805. */
  36806. class JUCE_API FilenameComponentListener
  36807. {
  36808. public:
  36809. /** Destructor. */
  36810. virtual ~FilenameComponentListener() {}
  36811. /** This method is called after the FilenameComponent's file has been changed. */
  36812. virtual void filenameComponentChanged (FilenameComponent* fileComponentThatHasChanged) = 0;
  36813. };
  36814. /**
  36815. Shows a filename as an editable text box, with a 'browse' button and a
  36816. drop-down list for recently selected files.
  36817. A handy component for dialogue boxes where you want the user to be able to
  36818. select a file or directory.
  36819. Attach an FilenameComponentListener using the addListener() method, and it will
  36820. get called each time the user changes the filename, either by browsing for a file
  36821. and clicking 'ok', or by typing a new filename into the box and pressing return.
  36822. @see FileChooser, ComboBox
  36823. */
  36824. class JUCE_API FilenameComponent : public Component,
  36825. public SettableTooltipClient,
  36826. public FileDragAndDropTarget,
  36827. private AsyncUpdater,
  36828. private ButtonListener,
  36829. private ComboBoxListener
  36830. {
  36831. public:
  36832. /** Creates a FilenameComponent.
  36833. @param name the name for this component.
  36834. @param currentFile the file to initially show in the box
  36835. @param canEditFilename if true, the user can manually edit the filename; if false,
  36836. they can only change it by browsing for a new file
  36837. @param isDirectory if true, the file will be treated as a directory, and
  36838. an appropriate directory browser used
  36839. @param isForSaving if true, the file browser will allow non-existent files to
  36840. be picked, as the file is assumed to be used for saving rather
  36841. than loading
  36842. @param fileBrowserWildcard a wildcard pattern to use in the file browser - e.g. "*.txt;*.foo".
  36843. If an empty string is passed in, then the pattern is assumed to be "*"
  36844. @param enforcedSuffix if this is non-empty, it is treated as a suffix that will be added
  36845. to any filenames that are entered or chosen
  36846. @param textWhenNothingSelected the message to display in the box before any filename is entered. (This
  36847. will only appear if the initial file isn't valid)
  36848. */
  36849. FilenameComponent (const String& name,
  36850. const File& currentFile,
  36851. const bool canEditFilename,
  36852. const bool isDirectory,
  36853. const bool isForSaving,
  36854. const String& fileBrowserWildcard,
  36855. const String& enforcedSuffix,
  36856. const String& textWhenNothingSelected);
  36857. /** Destructor. */
  36858. ~FilenameComponent();
  36859. /** Returns the currently displayed filename. */
  36860. const File getCurrentFile() const;
  36861. /** Changes the current filename.
  36862. If addToRecentlyUsedList is true, the filename will also be added to the
  36863. drop-down list of recent files.
  36864. If sendChangeNotification is false, then the listeners won't be told of the
  36865. change.
  36866. */
  36867. void setCurrentFile (File newFile,
  36868. const bool addToRecentlyUsedList,
  36869. const bool sendChangeNotification = true);
  36870. /** Changes whether the use can type into the filename box.
  36871. */
  36872. void setFilenameIsEditable (const bool shouldBeEditable);
  36873. /** Sets a file or directory to be the default starting point for the browser to show.
  36874. This is only used if the current file hasn't been set.
  36875. */
  36876. void setDefaultBrowseTarget (const File& newDefaultDirectory) throw();
  36877. /** Returns all the entries on the recent files list.
  36878. This can be used in conjunction with setRecentlyUsedFilenames() for saving the
  36879. state of this list.
  36880. @see setRecentlyUsedFilenames
  36881. */
  36882. const StringArray getRecentlyUsedFilenames() const;
  36883. /** Sets all the entries on the recent files list.
  36884. This can be used in conjunction with getRecentlyUsedFilenames() for saving the
  36885. state of this list.
  36886. @see getRecentlyUsedFilenames, addRecentlyUsedFile
  36887. */
  36888. void setRecentlyUsedFilenames (const StringArray& filenames);
  36889. /** Adds an entry to the recently-used files dropdown list.
  36890. If the file is already in the list, it will be moved to the top. A limit
  36891. is also placed on the number of items that are kept in the list.
  36892. @see getRecentlyUsedFilenames, setRecentlyUsedFilenames, setMaxNumberOfRecentFiles
  36893. */
  36894. void addRecentlyUsedFile (const File& file);
  36895. /** Changes the limit for the number of files that will be stored in the recent-file list.
  36896. */
  36897. void setMaxNumberOfRecentFiles (const int newMaximum);
  36898. /** Changes the text shown on the 'browse' button.
  36899. By default this button just says "..." but you can change it. The button itself
  36900. can be changed using the look-and-feel classes, so it might not actually have any
  36901. text on it.
  36902. */
  36903. void setBrowseButtonText (const String& browseButtonText);
  36904. /** Adds a listener that will be called when the selected file is changed. */
  36905. void addListener (FilenameComponentListener* const listener) throw();
  36906. /** Removes a previously-registered listener. */
  36907. void removeListener (FilenameComponentListener* const listener) throw();
  36908. /** Gives the component a tooltip. */
  36909. void setTooltip (const String& newTooltip);
  36910. /** @internal */
  36911. void paintOverChildren (Graphics& g);
  36912. /** @internal */
  36913. void resized();
  36914. /** @internal */
  36915. void lookAndFeelChanged();
  36916. /** @internal */
  36917. bool isInterestedInFileDrag (const StringArray& files);
  36918. /** @internal */
  36919. void filesDropped (const StringArray& files, int, int);
  36920. /** @internal */
  36921. void fileDragEnter (const StringArray& files, int, int);
  36922. /** @internal */
  36923. void fileDragExit (const StringArray& files);
  36924. juce_UseDebuggingNewOperator
  36925. private:
  36926. ComboBox* filenameBox;
  36927. String lastFilename;
  36928. Button* browseButton;
  36929. int maxRecentFiles;
  36930. bool isDir, isSaving, isFileDragOver;
  36931. String wildcard, enforcedSuffix, browseButtonText;
  36932. SortedSet <void*> listeners;
  36933. File defaultBrowseFile;
  36934. void comboBoxChanged (ComboBox*);
  36935. void buttonClicked (Button* button);
  36936. void handleAsyncUpdate();
  36937. FilenameComponent (const FilenameComponent&);
  36938. const FilenameComponent& operator= (const FilenameComponent&);
  36939. };
  36940. #endif // __JUCE_FILENAMECOMPONENT_JUCEHEADER__
  36941. /********* End of inlined file: juce_FilenameComponent.h *********/
  36942. #endif
  36943. #ifndef __JUCE_FILEPREVIEWCOMPONENT_JUCEHEADER__
  36944. #endif
  36945. #ifndef __JUCE_FILESEARCHPATHLISTCOMPONENT_JUCEHEADER__
  36946. /********* Start of inlined file: juce_FileSearchPathListComponent.h *********/
  36947. #ifndef __JUCE_FILESEARCHPATHLISTCOMPONENT_JUCEHEADER__
  36948. #define __JUCE_FILESEARCHPATHLISTCOMPONENT_JUCEHEADER__
  36949. /**
  36950. Shows a set of file paths in a list, allowing them to be added, removed or
  36951. re-ordered.
  36952. @see FileSearchPath
  36953. */
  36954. class JUCE_API FileSearchPathListComponent : public Component,
  36955. public SettableTooltipClient,
  36956. public FileDragAndDropTarget,
  36957. private ButtonListener,
  36958. private ListBoxModel
  36959. {
  36960. public:
  36961. /** Creates an empty FileSearchPathListComponent.
  36962. */
  36963. FileSearchPathListComponent();
  36964. /** Destructor. */
  36965. ~FileSearchPathListComponent();
  36966. /** Returns the path as it is currently shown. */
  36967. const FileSearchPath& getPath() const throw() { return path; }
  36968. /** Changes the current path. */
  36969. void setPath (const FileSearchPath& newPath);
  36970. /** Sets a file or directory to be the default starting point for the browser to show.
  36971. This is only used if the current file hasn't been set.
  36972. */
  36973. void setDefaultBrowseTarget (const File& newDefaultDirectory) throw();
  36974. /** A set of colour IDs to use to change the colour of various aspects of the label.
  36975. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  36976. methods.
  36977. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  36978. */
  36979. enum ColourIds
  36980. {
  36981. backgroundColourId = 0x1004100, /**< The background colour to fill the component with.
  36982. Make this transparent if you don't want the background to be filled. */
  36983. };
  36984. /** @internal */
  36985. int getNumRows();
  36986. /** @internal */
  36987. void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected);
  36988. /** @internal */
  36989. void deleteKeyPressed (int lastRowSelected);
  36990. /** @internal */
  36991. void returnKeyPressed (int lastRowSelected);
  36992. /** @internal */
  36993. void listBoxItemDoubleClicked (int row, const MouseEvent&);
  36994. /** @internal */
  36995. void selectedRowsChanged (int lastRowSelected);
  36996. /** @internal */
  36997. void resized();
  36998. /** @internal */
  36999. void paint (Graphics& g);
  37000. /** @internal */
  37001. bool isInterestedInFileDrag (const StringArray& files);
  37002. /** @internal */
  37003. void filesDropped (const StringArray& files, int, int);
  37004. /** @internal */
  37005. void buttonClicked (Button* button);
  37006. juce_UseDebuggingNewOperator
  37007. private:
  37008. FileSearchPath path;
  37009. File defaultBrowseTarget;
  37010. ListBox* listBox;
  37011. Button* addButton;
  37012. Button* removeButton;
  37013. Button* changeButton;
  37014. Button* upButton;
  37015. Button* downButton;
  37016. void changed() throw();
  37017. void updateButtons() throw();
  37018. FileSearchPathListComponent (const FileSearchPathListComponent&);
  37019. const FileSearchPathListComponent& operator= (const FileSearchPathListComponent&);
  37020. };
  37021. #endif // __JUCE_FILESEARCHPATHLISTCOMPONENT_JUCEHEADER__
  37022. /********* End of inlined file: juce_FileSearchPathListComponent.h *********/
  37023. #endif
  37024. #ifndef __JUCE_FILETREECOMPONENT_JUCEHEADER__
  37025. /********* Start of inlined file: juce_FileTreeComponent.h *********/
  37026. #ifndef __JUCE_FILETREECOMPONENT_JUCEHEADER__
  37027. #define __JUCE_FILETREECOMPONENT_JUCEHEADER__
  37028. /**
  37029. A component that displays the files in a directory as a treeview.
  37030. This implements the DirectoryContentsDisplayComponent base class so that
  37031. it can be used in a FileBrowserComponent.
  37032. To attach a listener to it, use its DirectoryContentsDisplayComponent base
  37033. class and the FileBrowserListener class.
  37034. @see DirectoryContentsList, FileListComponent
  37035. */
  37036. class JUCE_API FileTreeComponent : public TreeView,
  37037. public DirectoryContentsDisplayComponent
  37038. {
  37039. public:
  37040. /** Creates a listbox to show the contents of a specified directory.
  37041. */
  37042. FileTreeComponent (DirectoryContentsList& listToShow);
  37043. /** Destructor. */
  37044. ~FileTreeComponent();
  37045. /** Returns the number of selected files in the tree.
  37046. */
  37047. int getNumSelectedFiles() const throw() { return TreeView::getNumSelectedItems(); }
  37048. /** Returns one of the files that the user has currently selected.
  37049. Returns File::nonexistent if none is selected.
  37050. */
  37051. const File getSelectedFile (int index) const throw();
  37052. /** Returns the first of the files that the user has currently selected.
  37053. Returns File::nonexistent if none is selected.
  37054. */
  37055. const File getSelectedFile() const;
  37056. /** Scrolls the list to the top. */
  37057. void scrollToTop();
  37058. /** Setting a name for this allows tree items to be dragged.
  37059. The string that you pass in here will be returned by the getDragSourceDescription()
  37060. of the items in the tree. For more info, see TreeViewItem::getDragSourceDescription().
  37061. */
  37062. void setDragAndDropDescription (const String& description) throw();
  37063. /** Returns the last value that was set by setDragAndDropDescription().
  37064. */
  37065. const String& getDragAndDropDescription() const throw() { return dragAndDropDescription; }
  37066. juce_UseDebuggingNewOperator
  37067. private:
  37068. String dragAndDropDescription;
  37069. FileTreeComponent (const FileTreeComponent&);
  37070. const FileTreeComponent& operator= (const FileTreeComponent&);
  37071. };
  37072. #endif // __JUCE_FILETREECOMPONENT_JUCEHEADER__
  37073. /********* End of inlined file: juce_FileTreeComponent.h *********/
  37074. #endif
  37075. #ifndef __JUCE_IMAGEPREVIEWCOMPONENT_JUCEHEADER__
  37076. /********* Start of inlined file: juce_ImagePreviewComponent.h *********/
  37077. #ifndef __JUCE_IMAGEPREVIEWCOMPONENT_JUCEHEADER__
  37078. #define __JUCE_IMAGEPREVIEWCOMPONENT_JUCEHEADER__
  37079. /**
  37080. A simple preview component that shows thumbnails of image files.
  37081. @see FileChooserDialogBox, FilePreviewComponent
  37082. */
  37083. class JUCE_API ImagePreviewComponent : public FilePreviewComponent,
  37084. private Timer
  37085. {
  37086. public:
  37087. /** Creates an ImagePreviewComponent. */
  37088. ImagePreviewComponent();
  37089. /** Destructor. */
  37090. ~ImagePreviewComponent();
  37091. /** @internal */
  37092. void selectedFileChanged (const File& newSelectedFile);
  37093. /** @internal */
  37094. void paint (Graphics& g);
  37095. /** @internal */
  37096. void timerCallback();
  37097. juce_UseDebuggingNewOperator
  37098. private:
  37099. File fileToLoad;
  37100. Image* currentThumbnail;
  37101. String currentDetails;
  37102. void getThumbSize (int& w, int& h) const;
  37103. ImagePreviewComponent (const ImagePreviewComponent&);
  37104. const ImagePreviewComponent& operator= (const ImagePreviewComponent&);
  37105. };
  37106. #endif // __JUCE_IMAGEPREVIEWCOMPONENT_JUCEHEADER__
  37107. /********* End of inlined file: juce_ImagePreviewComponent.h *********/
  37108. #endif
  37109. #ifndef __JUCE_WILDCARDFILEFILTER_JUCEHEADER__
  37110. /********* Start of inlined file: juce_WildcardFileFilter.h *********/
  37111. #ifndef __JUCE_WILDCARDFILEFILTER_JUCEHEADER__
  37112. #define __JUCE_WILDCARDFILEFILTER_JUCEHEADER__
  37113. /**
  37114. A type of FileFilter that works by wildcard pattern matching.
  37115. This filter only allows files that match one of the specified patterns, but
  37116. allows all directories through.
  37117. @see FileFilter, DirectoryContentsList, FileListComponent, FileBrowserComponent
  37118. */
  37119. class JUCE_API WildcardFileFilter : public FileFilter
  37120. {
  37121. public:
  37122. /**
  37123. Creates a wildcard filter for one or more patterns.
  37124. The wildcardPatterns parameter is a comma or semicolon-delimited set of
  37125. patterns, e.g. "*.wav;*.aiff" would look for files ending in either .wav
  37126. or .aiff.
  37127. The description is a name to show the user in a list of possible patterns, so
  37128. for the wav/aiff example, your description might be "audio files".
  37129. */
  37130. WildcardFileFilter (const String& wildcardPatterns,
  37131. const String& description);
  37132. /** Destructor. */
  37133. ~WildcardFileFilter();
  37134. /** Returns true if the filename matches one of the patterns specified. */
  37135. bool isFileSuitable (const File& file) const;
  37136. /** This always returns true. */
  37137. bool isDirectorySuitable (const File& file) const;
  37138. juce_UseDebuggingNewOperator
  37139. private:
  37140. StringArray wildcards;
  37141. };
  37142. #endif // __JUCE_WILDCARDFILEFILTER_JUCEHEADER__
  37143. /********* End of inlined file: juce_WildcardFileFilter.h *********/
  37144. #endif
  37145. #ifndef __JUCE_ALERTWINDOW_JUCEHEADER__
  37146. /********* Start of inlined file: juce_AlertWindow.h *********/
  37147. #ifndef __JUCE_ALERTWINDOW_JUCEHEADER__
  37148. #define __JUCE_ALERTWINDOW_JUCEHEADER__
  37149. /** A window that displays a message and has buttons for the user to react to it.
  37150. For simple dialog boxes with just a couple of buttons on them, there are
  37151. some static methods for running these.
  37152. For more complex dialogs, an AlertWindow can be created, then it can have some
  37153. buttons and components added to it, and its runModalLoop() method is then used to
  37154. show it. The value returned by runModalLoop() shows which button the
  37155. user pressed to dismiss the box.
  37156. @see ThreadWithProgressWindow
  37157. */
  37158. class JUCE_API AlertWindow : public TopLevelWindow,
  37159. private ButtonListener
  37160. {
  37161. public:
  37162. /** The type of icon to show in the dialog box. */
  37163. enum AlertIconType
  37164. {
  37165. NoIcon, /**< No icon will be shown on the dialog box. */
  37166. QuestionIcon, /**< A question-mark icon, for dialog boxes that need the
  37167. user to answer a question. */
  37168. WarningIcon, /**< An exclamation mark to indicate that the dialog is a
  37169. warning about something and shouldn't be ignored. */
  37170. InfoIcon /**< An icon that indicates that the dialog box is just
  37171. giving the user some information, which doesn't require
  37172. a response from them. */
  37173. };
  37174. /** Creates an AlertWindow.
  37175. @param title the headline to show at the top of the dialog box
  37176. @param message a longer, more descriptive message to show underneath the
  37177. headline
  37178. @param iconType the type of icon to display
  37179. */
  37180. AlertWindow (const String& title,
  37181. const String& message,
  37182. AlertIconType iconType);
  37183. /** Destroys the AlertWindow */
  37184. ~AlertWindow();
  37185. /** Returns the type of alert icon that was specified when the window
  37186. was created. */
  37187. AlertIconType getAlertType() const throw() { return alertIconType; }
  37188. /** Changes the dialog box's message.
  37189. This will also resize the window to fit the new message if required.
  37190. */
  37191. void setMessage (const String& message);
  37192. /** Adds a button to the window.
  37193. @param name the text to show on the button
  37194. @param returnValue the value that should be returned from runModalLoop()
  37195. if this is the button that the user presses.
  37196. @param shortcutKey1 an optional key that can be pressed to trigger this button
  37197. @param shortcutKey2 a second optional key that can be pressed to trigger this button
  37198. */
  37199. void addButton (const String& name,
  37200. const int returnValue,
  37201. const KeyPress& shortcutKey1 = KeyPress(),
  37202. const KeyPress& shortcutKey2 = KeyPress());
  37203. /** Returns the number of buttons that the window currently has. */
  37204. int getNumButtons() const;
  37205. /** Adds a textbox to the window for entering strings.
  37206. @param name an internal name for the text-box. This is the name to pass to
  37207. the getTextEditorContents() method to find out what the
  37208. user typed-in.
  37209. @param initialContents a string to show in the text box when it's first shown
  37210. @param onScreenLabel if this is non-empty, it will be displayed next to the
  37211. text-box to label it.
  37212. @param isPasswordBox if true, the text editor will display asterisks instead of
  37213. the actual text
  37214. @see getTextEditorContents
  37215. */
  37216. void addTextEditor (const String& name,
  37217. const String& initialContents,
  37218. const String& onScreenLabel = String::empty,
  37219. const bool isPasswordBox = false);
  37220. /** Returns the contents of a named textbox.
  37221. After showing an AlertWindow that contains a text editor, this can be
  37222. used to find out what the user has typed into it.
  37223. @param nameOfTextEditor the name of the text box that you're interested in
  37224. @see addTextEditor
  37225. */
  37226. const String getTextEditorContents (const String& nameOfTextEditor) const;
  37227. /** Adds a drop-down list of choices to the box.
  37228. After the box has been shown, the getComboBoxComponent() method can
  37229. be used to find out which item the user picked.
  37230. @param name the label to use for the drop-down list
  37231. @param items the list of items to show in it
  37232. @param onScreenLabel if this is non-empty, it will be displayed next to the
  37233. combo-box to label it.
  37234. @see getComboBoxComponent
  37235. */
  37236. void addComboBox (const String& name,
  37237. const StringArray& items,
  37238. const String& onScreenLabel = String::empty);
  37239. /** Returns a drop-down list that was added to the AlertWindow.
  37240. @param nameOfList the name that was passed into the addComboBox() method
  37241. when creating the drop-down
  37242. @returns the ComboBox component, or 0 if none was found for the given name.
  37243. */
  37244. ComboBox* getComboBoxComponent (const String& nameOfList) const;
  37245. /** Adds a block of text.
  37246. This is handy for adding a multi-line note next to a textbox or combo-box,
  37247. to provide more details about what's going on.
  37248. */
  37249. void addTextBlock (const String& text);
  37250. /** Adds a progress-bar to the window.
  37251. @param progressValue a variable that will be repeatedly checked while the
  37252. dialog box is visible, to see how far the process has
  37253. got. The value should be in the range 0 to 1.0
  37254. */
  37255. void addProgressBarComponent (double& progressValue);
  37256. /** Adds a user-defined component to the dialog box.
  37257. @param component the component to add - its size should be set up correctly
  37258. before it is passed in. The caller is responsible for deleting
  37259. the component later on - the AlertWindow won't delete it.
  37260. */
  37261. void addCustomComponent (Component* const component);
  37262. /** Returns the number of custom components in the dialog box.
  37263. @see getCustomComponent, addCustomComponent
  37264. */
  37265. int getNumCustomComponents() const;
  37266. /** Returns one of the custom components in the dialog box.
  37267. @param index a value 0 to (getNumCustomComponents() - 1). Out-of-range indexes
  37268. will return 0
  37269. @see getNumCustomComponents, addCustomComponent
  37270. */
  37271. Component* getCustomComponent (const int index) const;
  37272. /** Removes one of the custom components in the dialog box.
  37273. Note that this won't delete it, it just removes the component from the window
  37274. @param index a value 0 to (getNumCustomComponents() - 1). Out-of-range indexes
  37275. will return 0
  37276. @returns the component that was removed (or zero)
  37277. @see getNumCustomComponents, addCustomComponent
  37278. */
  37279. Component* removeCustomComponent (const int index);
  37280. /** Returns true if the window contains any components other than just buttons.*/
  37281. bool containsAnyExtraComponents() const;
  37282. // easy-to-use message box functions:
  37283. /** Shows a dialog box that just has a message and a single button to get rid of it.
  37284. The box is shown modally, and the method returns after the user
  37285. has clicked the button (or pressed the escape or return keys).
  37286. @param iconType the type of icon to show
  37287. @param title the headline to show at the top of the box
  37288. @param message a longer, more descriptive message to show underneath the
  37289. headline
  37290. @param buttonText the text to show in the button - if this string is empty, the
  37291. default string "ok" (or a localised version) will be used.
  37292. */
  37293. static void JUCE_CALLTYPE showMessageBox (AlertIconType iconType,
  37294. const String& title,
  37295. const String& message,
  37296. const String& buttonText = String::empty);
  37297. /** Shows a dialog box with two buttons.
  37298. Ideal for ok/cancel or yes/no choices. The return key can also be used
  37299. to trigger the first button, and the escape key for the second button.
  37300. @param iconType the type of icon to show
  37301. @param title the headline to show at the top of the box
  37302. @param message a longer, more descriptive message to show underneath the
  37303. headline
  37304. @param button1Text the text to show in the first button - if this string is
  37305. empty, the default string "ok" (or a localised version of it)
  37306. will be used.
  37307. @param button2Text the text to show in the second button - if this string is
  37308. empty, the default string "cancel" (or a localised version of it)
  37309. will be used.
  37310. @returns true if button 1 was clicked, false if it was button 2
  37311. */
  37312. static bool JUCE_CALLTYPE showOkCancelBox (AlertIconType iconType,
  37313. const String& title,
  37314. const String& message,
  37315. const String& button1Text = String::empty,
  37316. const String& button2Text = String::empty);
  37317. /** Shows a dialog box with three buttons.
  37318. Ideal for yes/no/cancel boxes.
  37319. The escape key can be used to trigger the third button.
  37320. @param iconType the type of icon to show
  37321. @param title the headline to show at the top of the box
  37322. @param message a longer, more descriptive message to show underneath the
  37323. headline
  37324. @param button1Text the text to show in the first button - if an empty string, then
  37325. "yes" will be used (or a localised version of it)
  37326. @param button2Text the text to show in the first button - if an empty string, then
  37327. "no" will be used (or a localised version of it)
  37328. @param button3Text the text to show in the first button - if an empty string, then
  37329. "cancel" will be used (or a localised version of it)
  37330. @returns one of the following values:
  37331. - 0 if the third button was pressed (normally used for 'cancel')
  37332. - 1 if the first button was pressed (normally used for 'yes')
  37333. - 2 if the middle button was pressed (normally used for 'no')
  37334. */
  37335. static int JUCE_CALLTYPE showYesNoCancelBox (AlertIconType iconType,
  37336. const String& title,
  37337. const String& message,
  37338. const String& button1Text = String::empty,
  37339. const String& button2Text = String::empty,
  37340. const String& button3Text = String::empty);
  37341. /** Shows an operating-system native dialog box.
  37342. @param title the title to use at the top
  37343. @param bodyText the longer message to show
  37344. @param isOkCancel if true, this will show an ok/cancel box, if false,
  37345. it'll show a box with just an ok button
  37346. @returns true if the ok button was pressed, false if they pressed cancel.
  37347. */
  37348. static bool JUCE_CALLTYPE showNativeDialogBox (const String& title,
  37349. const String& bodyText,
  37350. bool isOkCancel);
  37351. /** A set of colour IDs to use to change the colour of various aspects of the alert box.
  37352. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  37353. methods.
  37354. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  37355. */
  37356. enum ColourIds
  37357. {
  37358. backgroundColourId = 0x1001800, /**< The background colour for the window. */
  37359. textColourId = 0x1001810, /**< The colour for the text. */
  37360. outlineColourId = 0x1001820 /**< An optional colour to use to draw a border around the window. */
  37361. };
  37362. juce_UseDebuggingNewOperator
  37363. protected:
  37364. /** @internal */
  37365. void paint (Graphics& g);
  37366. /** @internal */
  37367. void mouseDown (const MouseEvent& e);
  37368. /** @internal */
  37369. void mouseDrag (const MouseEvent& e);
  37370. /** @internal */
  37371. bool keyPressed (const KeyPress& key);
  37372. /** @internal */
  37373. void buttonClicked (Button* button);
  37374. /** @internal */
  37375. void lookAndFeelChanged();
  37376. private:
  37377. String text;
  37378. TextLayout textLayout;
  37379. AlertIconType alertIconType;
  37380. ComponentBoundsConstrainer constrainer;
  37381. ComponentDragger dragger;
  37382. Rectangle textArea;
  37383. VoidArray buttons, textBoxes, comboBoxes;
  37384. VoidArray progressBars, customComps, textBlocks, allComps;
  37385. StringArray textboxNames, comboBoxNames;
  37386. Font font;
  37387. void updateLayout (const bool onlyIncreaseSize);
  37388. // disable copy constructor
  37389. AlertWindow (const AlertWindow&);
  37390. const AlertWindow& operator= (const AlertWindow&);
  37391. };
  37392. #endif // __JUCE_ALERTWINDOW_JUCEHEADER__
  37393. /********* End of inlined file: juce_AlertWindow.h *********/
  37394. #endif
  37395. #ifndef __JUCE_COMPONENTPEER_JUCEHEADER__
  37396. #endif
  37397. #ifndef __JUCE_DIALOGWINDOW_JUCEHEADER__
  37398. /********* Start of inlined file: juce_DialogWindow.h *********/
  37399. #ifndef __JUCE_DIALOGWINDOW_JUCEHEADER__
  37400. #define __JUCE_DIALOGWINDOW_JUCEHEADER__
  37401. /**
  37402. A dialog-box style window.
  37403. This class is a convenient way of creating a DocumentWindow with a close button
  37404. that can be triggered by pressing the escape key.
  37405. Any of the methods available to a DocumentWindow or ResizableWindow are also
  37406. available to this, so it can be made resizable, have a menu bar, etc.
  37407. To add items to the box, see the ResizableWindow::setContentComponent() method.
  37408. Don't add components directly to this class - always put them in a content component!
  37409. You'll need to override the DocumentWindow::closeButtonPressed() method to handle
  37410. the user clicking the close button - for more info, see the DocumentWindow
  37411. help.
  37412. @see DocumentWindow, ResizableWindow
  37413. */
  37414. class JUCE_API DialogWindow : public DocumentWindow
  37415. {
  37416. public:
  37417. /** Creates a DialogWindow.
  37418. @param name the name to give the component - this is also
  37419. the title shown at the top of the window. To change
  37420. this later, use setName()
  37421. @param backgroundColour the colour to use for filling the window's background.
  37422. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  37423. close button to be triggered
  37424. @param addToDesktop if true, the window will be automatically added to the
  37425. desktop; if false, you can use it as a child component
  37426. */
  37427. DialogWindow (const String& name,
  37428. const Colour& backgroundColour,
  37429. const bool escapeKeyTriggersCloseButton,
  37430. const bool addToDesktop = true);
  37431. /** Destructor.
  37432. If a content component has been set with setContentComponent(), it
  37433. will be deleted.
  37434. */
  37435. ~DialogWindow();
  37436. /** Easy way of quickly showing a dialog box containing a given component.
  37437. This will open and display a DialogWindow containing a given component, returning
  37438. when the user clicks its close button.
  37439. It returns the value that was returned by the dialog box's runModalLoop() call.
  37440. To close the dialog programatically, you should call exitModalState (returnValue) on
  37441. the DialogWindow that is created. To find a pointer to this window from your
  37442. contentComponent, you can do something like this:
  37443. @code
  37444. Dialogwindow* dw = contentComponent->findParentComponentOfClass ((DialogWindow*) 0);
  37445. if (dw != 0)
  37446. dw->exitModalState (1234);
  37447. @endcode
  37448. @param dialogTitle the dialog box's title
  37449. @param contentComponent the content component for the dialog box. Make sure
  37450. that this has been set to the size you want it to
  37451. be before calling this method. The component won't
  37452. be deleted by this call, so you can re-use it or delete
  37453. it afterwards
  37454. @param componentToCentreAround if this is non-zero, it indicates a component that
  37455. you'd like to show this dialog box in front of. See the
  37456. DocumentWindow::centreAroundComponent() method for more
  37457. info on this parameter
  37458. @param backgroundColour a colour to use for the dialog box's background colour
  37459. @param escapeKeyTriggersCloseButton if true, then pressing the escape key will cause the
  37460. close button to be triggered
  37461. @param shouldBeResizable if true, the dialog window has either a resizable border, or
  37462. a corner resizer
  37463. @param useBottomRightCornerResizer if shouldBeResizable is true, this indicates whether
  37464. to use a border or corner resizer component. See ResizableWindow::setResizable()
  37465. */
  37466. static int showModalDialog (const String& dialogTitle,
  37467. Component* contentComponent,
  37468. Component* componentToCentreAround,
  37469. const Colour& backgroundColour,
  37470. const bool escapeKeyTriggersCloseButton,
  37471. const bool shouldBeResizable = false,
  37472. const bool useBottomRightCornerResizer = false);
  37473. juce_UseDebuggingNewOperator
  37474. protected:
  37475. /** @internal */
  37476. void resized();
  37477. private:
  37478. bool escapeKeyTriggersCloseButton;
  37479. DialogWindow (const DialogWindow&);
  37480. const DialogWindow& operator= (const DialogWindow&);
  37481. };
  37482. #endif // __JUCE_DIALOGWINDOW_JUCEHEADER__
  37483. /********* End of inlined file: juce_DialogWindow.h *********/
  37484. #endif
  37485. #ifndef __JUCE_DOCUMENTWINDOW_JUCEHEADER__
  37486. #endif
  37487. #ifndef __JUCE_RESIZABLEWINDOW_JUCEHEADER__
  37488. #endif
  37489. #ifndef __JUCE_SPLASHSCREEN_JUCEHEADER__
  37490. /********* Start of inlined file: juce_SplashScreen.h *********/
  37491. #ifndef __JUCE_SPLASHSCREEN_JUCEHEADER__
  37492. #define __JUCE_SPLASHSCREEN_JUCEHEADER__
  37493. /** A component for showing a splash screen while your app starts up.
  37494. This will automatically position itself, and delete itself when the app has
  37495. finished initialising (it uses the JUCEApplication::isInitialising() to detect
  37496. this).
  37497. To use it, just create one of these in your JUCEApplication::initialise() method,
  37498. call its show() method and let the object delete itself later.
  37499. E.g. @code
  37500. void MyApp::initialise (const String& commandLine)
  37501. {
  37502. SplashScreen* splash = new SplashScreen();
  37503. splash->show (T("welcome to my app"),
  37504. ImageCache::getFromFile (File ("/foobar/splash.jpg")),
  37505. 4000, false);
  37506. .. no need to delete the splash screen - it'll do that itself.
  37507. }
  37508. @endcode
  37509. */
  37510. class JUCE_API SplashScreen : public Component,
  37511. public Timer,
  37512. private DeletedAtShutdown
  37513. {
  37514. public:
  37515. /** Creates a SplashScreen object.
  37516. After creating one of these (or your subclass of it), call one of the show()
  37517. methods to display it.
  37518. */
  37519. SplashScreen();
  37520. /** Destructor. */
  37521. ~SplashScreen();
  37522. /** Creates a SplashScreen object that will display an image.
  37523. As soon as this is called, the SplashScreen will be displayed in the centre of the
  37524. screen. This method will also dispatch any pending messages to make sure that when
  37525. it returns, the splash screen has been completely drawn, and your initialisation
  37526. code can carry on.
  37527. @param title the name to give the component
  37528. @param backgroundImage an image to draw on the component. The component's size
  37529. will be set to the size of this image, and if the image is
  37530. semi-transparent, the component will be made semi-transparent
  37531. too. This image will be deleted (or released from the ImageCache
  37532. if that's how it was created) by the splash screen object when
  37533. it is itself deleted.
  37534. @param minimumTimeToDisplayFor how long (in milliseconds) the splash screen
  37535. should stay visible for. If the initialisation takes longer than
  37536. this time, the splash screen will wait for it to finish before
  37537. disappearing, but if initialisation is very quick, this lets
  37538. you make sure that people get a good look at your splash.
  37539. @param useDropShadow if true, the window will have a drop shadow
  37540. @param removeOnMouseClick if true, the window will go away as soon as the user clicks
  37541. the mouse (anywhere)
  37542. */
  37543. void show (const String& title,
  37544. Image* const backgroundImage,
  37545. const int minimumTimeToDisplayFor,
  37546. const bool useDropShadow,
  37547. const bool removeOnMouseClick = true);
  37548. /** Creates a SplashScreen object with a specified size.
  37549. For a custom splash screen, you can use this method to display it at a certain size
  37550. and then override the paint() method yourself to do whatever's necessary.
  37551. As soon as this is called, the SplashScreen will be displayed in the centre of the
  37552. screen. This method will also dispatch any pending messages to make sure that when
  37553. it returns, the splash screen has been completely drawn, and your initialisation
  37554. code can carry on.
  37555. @param title the name to give the component
  37556. @param width the width to use
  37557. @param height the height to use
  37558. @param minimumTimeToDisplayFor how long (in milliseconds) the splash screen
  37559. should stay visible for. If the initialisation takes longer than
  37560. this time, the splash screen will wait for it to finish before
  37561. disappearing, but if initialisation is very quick, this lets
  37562. you make sure that people get a good look at your splash.
  37563. @param useDropShadow if true, the window will have a drop shadow
  37564. @param removeOnMouseClick if true, the window will go away as soon as the user clicks
  37565. the mouse (anywhere)
  37566. */
  37567. void show (const String& title,
  37568. const int width,
  37569. const int height,
  37570. const int minimumTimeToDisplayFor,
  37571. const bool useDropShadow,
  37572. const bool removeOnMouseClick = true);
  37573. /** @internal */
  37574. void paint (Graphics& g);
  37575. /** @internal */
  37576. void timerCallback();
  37577. juce_UseDebuggingNewOperator
  37578. private:
  37579. Image* backgroundImage;
  37580. Time earliestTimeToDelete;
  37581. int originalClickCounter;
  37582. bool isImageInCache;
  37583. SplashScreen (const SplashScreen&);
  37584. const SplashScreen& operator= (const SplashScreen&);
  37585. };
  37586. #endif // __JUCE_SPLASHSCREEN_JUCEHEADER__
  37587. /********* End of inlined file: juce_SplashScreen.h *********/
  37588. #endif
  37589. #ifndef __JUCE_THREADWITHPROGRESSWINDOW_JUCEHEADER__
  37590. /********* Start of inlined file: juce_ThreadWithProgressWindow.h *********/
  37591. #ifndef __JUCE_THREADWITHPROGRESSWINDOW_JUCEHEADER__
  37592. #define __JUCE_THREADWITHPROGRESSWINDOW_JUCEHEADER__
  37593. /**
  37594. A thread that automatically pops up a modal dialog box with a progress bar
  37595. and cancel button while it's busy running.
  37596. These are handy for performing some sort of task while giving the user feedback
  37597. about how long there is to go, etc.
  37598. E.g. @code
  37599. class MyTask : public ThreadWithProgressWindow
  37600. {
  37601. public:
  37602. MyTask() : ThreadWithProgressWindow (T("busy..."), true, true)
  37603. {
  37604. }
  37605. ~MyTask()
  37606. {
  37607. }
  37608. void run()
  37609. {
  37610. for (int i = 0; i < thingsToDo; ++i)
  37611. {
  37612. // must check this as often as possible, because this is
  37613. // how we know if the user's pressed 'cancel'
  37614. if (threadShouldExit())
  37615. break;
  37616. // this will update the progress bar on the dialog box
  37617. setProgress (i / (double) thingsToDo);
  37618. // ... do the business here...
  37619. }
  37620. }
  37621. };
  37622. void doTheTask()
  37623. {
  37624. MyTask m;
  37625. if (m.runThread())
  37626. {
  37627. // thread finished normally..
  37628. }
  37629. else
  37630. {
  37631. // user pressed the cancel button..
  37632. }
  37633. }
  37634. @endcode
  37635. @see Thread, AlertWindow
  37636. */
  37637. class JUCE_API ThreadWithProgressWindow : public Thread,
  37638. private Timer
  37639. {
  37640. public:
  37641. /** Creates the thread.
  37642. Initially, the dialog box won't be visible, it'll only appear when the
  37643. runThread() method is called.
  37644. @param windowTitle the title to go at the top of the dialog box
  37645. @param hasProgressBar whether the dialog box should have a progress bar (see
  37646. setProgress() )
  37647. @param hasCancelButton whether the dialog box should have a cancel button
  37648. @param timeOutMsWhenCancelling when 'cancel' is pressed, this is how long to wait for
  37649. the thread to stop before killing it forcibly (see
  37650. Thread::stopThread() )
  37651. @param cancelButtonText the text that should be shown in the cancel button
  37652. (if it has one)
  37653. */
  37654. ThreadWithProgressWindow (const String& windowTitle,
  37655. const bool hasProgressBar,
  37656. const bool hasCancelButton,
  37657. const int timeOutMsWhenCancelling = 10000,
  37658. const String& cancelButtonText = JUCE_T("Cancel"));
  37659. /** Destructor. */
  37660. ~ThreadWithProgressWindow();
  37661. /** Starts the thread and waits for it to finish.
  37662. This will start the thread, make the dialog box appear, and wait until either
  37663. the thread finishes normally, or until the cancel button is pressed.
  37664. Before returning, the dialog box will be hidden.
  37665. @param threadPriority the priority to use when starting the thread - see
  37666. Thread::startThread() for values
  37667. @returns true if the thread finished normally; false if the user pressed cancel
  37668. */
  37669. bool runThread (const int threadPriority = 5);
  37670. /** The thread should call this periodically to update the position of the progress bar.
  37671. @param newProgress the progress, from 0.0 to 1.0
  37672. @see setStatusMessage
  37673. */
  37674. void setProgress (const double newProgress);
  37675. /** The thread can call this to change the message that's displayed in the dialog box.
  37676. */
  37677. void setStatusMessage (const String& newStatusMessage);
  37678. juce_UseDebuggingNewOperator
  37679. private:
  37680. void timerCallback();
  37681. double progress;
  37682. AlertWindow alertWindow;
  37683. String message;
  37684. CriticalSection messageLock;
  37685. const int timeOutMsWhenCancelling;
  37686. ThreadWithProgressWindow (const ThreadWithProgressWindow&);
  37687. const ThreadWithProgressWindow& operator= (const ThreadWithProgressWindow&);
  37688. };
  37689. #endif // __JUCE_THREADWITHPROGRESSWINDOW_JUCEHEADER__
  37690. /********* End of inlined file: juce_ThreadWithProgressWindow.h *********/
  37691. #endif
  37692. #ifndef __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  37693. #endif
  37694. #ifndef __JUCE_TOPLEVELWINDOW_JUCEHEADER__
  37695. #endif
  37696. #ifndef __JUCE_ACTIVEXCONTROLCOMPONENT_JUCEHEADER__
  37697. /********* Start of inlined file: juce_ActiveXControlComponent.h *********/
  37698. #ifndef __JUCE_ACTIVEXCONTROLCOMPONENT_JUCEHEADER__
  37699. #define __JUCE_ACTIVEXCONTROLCOMPONENT_JUCEHEADER__
  37700. #if JUCE_WIN32 || DOXYGEN
  37701. /**
  37702. A Windows-specific class that can create and embed an ActiveX control inside
  37703. itself.
  37704. To use it, create one of these, put it in place and make sure it's visible in a
  37705. window, then use createControl() to instantiate an ActiveX control. The control
  37706. will then be moved and resized to follow the movements of this component.
  37707. Of course, since the control is a heavyweight window, it'll obliterate any
  37708. juce components that may overlap this component, but that's life.
  37709. */
  37710. class JUCE_API ActiveXControlComponent : public Component
  37711. {
  37712. public:
  37713. /** Create an initially-empty container. */
  37714. ActiveXControlComponent();
  37715. /** Destructor. */
  37716. ~ActiveXControlComponent();
  37717. /** Tries to create an ActiveX control and embed it in this peer.
  37718. The peer controlIID is a pointer to an IID structure - it's treated
  37719. as a void* because when including the Juce headers, you might not always
  37720. have included windows.h first, in which case IID wouldn't be defined.
  37721. e.g. @code
  37722. const IID myIID = __uuidof (QTControl);
  37723. myControlComp->createControl (&myIID);
  37724. @endcode
  37725. */
  37726. bool createControl (const void* controlIID);
  37727. /** Deletes the ActiveX control, if one has been created.
  37728. */
  37729. void deleteControl();
  37730. /** Returns true if a control is currently in use. */
  37731. bool isControlOpen() const throw() { return control != 0; }
  37732. /** Does a QueryInterface call on the embedded control object.
  37733. This allows you to cast the control to whatever type of COM object you need.
  37734. The iid parameter is a pointer to an IID structure - it's treated
  37735. as a void* because when including the Juce headers, you might not always
  37736. have included windows.h first, in which case IID wouldn't be defined, but
  37737. you should just pass a pointer to an IID.
  37738. e.g. @code
  37739. const IID iid = __uuidof (IOleWindow);
  37740. IOleWindow* oleWindow = (IOleWindow*) myControlComp->queryInterface (&iid);
  37741. if (oleWindow != 0)
  37742. {
  37743. HWND hwnd;
  37744. oleWindow->GetWindow (&hwnd);
  37745. ...
  37746. oleWindow->Release();
  37747. }
  37748. @endcode
  37749. */
  37750. void* queryInterface (const void* iid) const;
  37751. /** Set this to false to stop mouse events being allowed through to the control.
  37752. */
  37753. void setMouseEventsAllowed (const bool eventsCanReachControl);
  37754. /** Returns true if mouse events are allowed to get through to the control.
  37755. */
  37756. bool areMouseEventsAllowed() const throw() { return mouseEventsAllowed; }
  37757. /** @internal */
  37758. void paint (Graphics& g);
  37759. /** @internal */
  37760. void* originalWndProc;
  37761. juce_UseDebuggingNewOperator
  37762. private:
  37763. friend class ActiveXControlData;
  37764. void* control;
  37765. bool mouseEventsAllowed;
  37766. ActiveXControlComponent (const ActiveXControlComponent&);
  37767. const ActiveXControlComponent& operator= (const ActiveXControlComponent&);
  37768. void setControlBounds (const Rectangle& bounds) const;
  37769. void setControlVisible (const bool b) const;
  37770. };
  37771. #endif
  37772. #endif // __JUCE_ACTIVEXCONTROLCOMPONENT_JUCEHEADER__
  37773. /********* End of inlined file: juce_ActiveXControlComponent.h *********/
  37774. #endif
  37775. #ifndef __JUCE_AUDIODEVICESELECTORCOMPONENT_JUCEHEADER__
  37776. /********* Start of inlined file: juce_AudioDeviceSelectorComponent.h *********/
  37777. #ifndef __JUCE_AUDIODEVICESELECTORCOMPONENT_JUCEHEADER__
  37778. #define __JUCE_AUDIODEVICESELECTORCOMPONENT_JUCEHEADER__
  37779. class MidiInputSelectorComponentListBox;
  37780. /**
  37781. A component containing controls to let the user change the audio settings of
  37782. an AudioDeviceManager object.
  37783. Very easy to use - just create one of these and show it to the user.
  37784. @see AudioDeviceManager
  37785. */
  37786. class JUCE_API AudioDeviceSelectorComponent : public Component,
  37787. public ComboBoxListener,
  37788. public ButtonListener,
  37789. public ChangeListener
  37790. {
  37791. public:
  37792. /** Creates the component.
  37793. If your app needs only output channels, you might ask for a maximum of 0 input
  37794. channels, and the component won't display any options for choosing the input
  37795. channels. And likewise if you're doing an input-only app.
  37796. @param deviceManager the device manager that this component should control
  37797. @param minAudioInputChannels the minimum number of audio input channels that the application needs
  37798. @param maxAudioInputChannels the maximum number of audio input channels that the application needs
  37799. @param minAudioOutputChannels the minimum number of audio output channels that the application needs
  37800. @param maxAudioOutputChannels the maximum number of audio output channels that the application needs
  37801. @param showMidiInputOptions if true, the component will allow the user to select which midi inputs are enabled
  37802. @param showMidiOutputSelector if true, the component will let the user choose a default midi output device
  37803. @param showChannelsAsStereoPairs if true, channels will be treated as pairs; if false, channels will be
  37804. treated as a set of separate mono channels.
  37805. @param hideAdvancedOptionsWithButton if true, only the minimum amount of UI components
  37806. are shown, with an "advanced" button that shows the rest of them
  37807. */
  37808. AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager,
  37809. const int minAudioInputChannels,
  37810. const int maxAudioInputChannels,
  37811. const int minAudioOutputChannels,
  37812. const int maxAudioOutputChannels,
  37813. const bool showMidiInputOptions,
  37814. const bool showMidiOutputSelector,
  37815. const bool showChannelsAsStereoPairs,
  37816. const bool hideAdvancedOptionsWithButton);
  37817. /** Destructor */
  37818. ~AudioDeviceSelectorComponent();
  37819. /** @internal */
  37820. void resized();
  37821. /** @internal */
  37822. void comboBoxChanged (ComboBox*);
  37823. /** @internal */
  37824. void buttonClicked (Button*);
  37825. /** @internal */
  37826. void changeListenerCallback (void*);
  37827. juce_UseDebuggingNewOperator
  37828. private:
  37829. AudioDeviceManager& deviceManager;
  37830. ComboBox* deviceTypeDropDown;
  37831. Label* deviceTypeDropDownLabel;
  37832. Component* audioDeviceSettingsComp;
  37833. String audioDeviceSettingsCompType;
  37834. const int minOutputChannels, maxOutputChannels, minInputChannels, maxInputChannels;
  37835. const bool showChannelsAsStereoPairs;
  37836. const bool hideAdvancedOptionsWithButton;
  37837. MidiInputSelectorComponentListBox* midiInputsList;
  37838. Label* midiInputsLabel;
  37839. ComboBox* midiOutputSelector;
  37840. Label* midiOutputLabel;
  37841. AudioDeviceSelectorComponent (const AudioDeviceSelectorComponent&);
  37842. const AudioDeviceSelectorComponent& operator= (const AudioDeviceSelectorComponent&);
  37843. };
  37844. #endif // __JUCE_AUDIODEVICESELECTORCOMPONENT_JUCEHEADER__
  37845. /********* End of inlined file: juce_AudioDeviceSelectorComponent.h *********/
  37846. #endif
  37847. #ifndef __JUCE_BUBBLECOMPONENT_JUCEHEADER__
  37848. /********* Start of inlined file: juce_BubbleComponent.h *********/
  37849. #ifndef __JUCE_BUBBLECOMPONENT_JUCEHEADER__
  37850. #define __JUCE_BUBBLECOMPONENT_JUCEHEADER__
  37851. /**
  37852. A component for showing a message or other graphics inside a speech-bubble-shaped
  37853. outline, pointing at a location on the screen.
  37854. This is a base class that just draws and positions the bubble shape, but leaves
  37855. the drawing of any content up to a subclass. See BubbleMessageComponent for a subclass
  37856. that draws a text message.
  37857. To use it, create your subclass, then either add it to a parent component or
  37858. put it on the desktop with addToDesktop (0), use setPosition() to
  37859. resize and position it, then make it visible.
  37860. @see BubbleMessageComponent
  37861. */
  37862. class JUCE_API BubbleComponent : public Component
  37863. {
  37864. protected:
  37865. /** Creates a BubbleComponent.
  37866. Your subclass will need to implement the getContentSize() and paintContent()
  37867. methods to draw the bubble's contents.
  37868. */
  37869. BubbleComponent();
  37870. public:
  37871. /** Destructor. */
  37872. ~BubbleComponent();
  37873. /** A list of permitted placements for the bubble, relative to the co-ordinates
  37874. at which it should be pointing.
  37875. @see setAllowedPlacement
  37876. */
  37877. enum BubblePlacement
  37878. {
  37879. above = 1,
  37880. below = 2,
  37881. left = 4,
  37882. right = 8
  37883. };
  37884. /** Tells the bubble which positions it's allowed to put itself in, relative to the
  37885. point at which it's pointing.
  37886. By default when setPosition() is called, the bubble will place itself either
  37887. above, below, left, or right of the target area. You can pass in a bitwise-'or' of
  37888. the values in BubblePlacement to restrict this choice.
  37889. E.g. if you only want your bubble to appear above or below the target area,
  37890. use setAllowedPlacement (above | below);
  37891. @see BubblePlacement
  37892. */
  37893. void setAllowedPlacement (const int newPlacement);
  37894. /** Moves and resizes the bubble to point at a given component.
  37895. This will resize the bubble to fit its content, then find a position for it
  37896. so that it's next to, but doesn't overlap the given component.
  37897. It'll put itself either above, below, or to the side of the component depending
  37898. on where there's the most space, honouring any restrictions that were set
  37899. with setAllowedPlacement().
  37900. */
  37901. void setPosition (Component* componentToPointTo);
  37902. /** Moves and resizes the bubble to point at a given point.
  37903. This will resize the bubble to fit its content, then position it
  37904. so that the tip of the bubble points to the given co-ordinate. The co-ordinates
  37905. are relative to either the bubble component's parent component if it has one, or
  37906. they are screen co-ordinates if not.
  37907. It'll put itself either above, below, or to the side of this point, depending
  37908. on where there's the most space, honouring any restrictions that were set
  37909. with setAllowedPlacement().
  37910. */
  37911. void setPosition (const int arrowTipX,
  37912. const int arrowTipY);
  37913. /** Moves and resizes the bubble to point at a given rectangle.
  37914. This will resize the bubble to fit its content, then find a position for it
  37915. so that it's next to, but doesn't overlap the given rectangle. The rectangle's
  37916. co-ordinates are relative to either the bubble component's parent component
  37917. if it has one, or they are screen co-ordinates if not.
  37918. It'll put itself either above, below, or to the side of the component depending
  37919. on where there's the most space, honouring any restrictions that were set
  37920. with setAllowedPlacement().
  37921. */
  37922. void setPosition (const Rectangle& rectangleToPointTo);
  37923. protected:
  37924. /** Subclasses should override this to return the size of the content they
  37925. want to draw inside the bubble.
  37926. */
  37927. virtual void getContentSize (int& width, int& height) = 0;
  37928. /** Subclasses should override this to draw their bubble's contents.
  37929. The graphics object's clip region and the dimensions passed in here are
  37930. set up to paint just the rectangle inside the bubble.
  37931. */
  37932. virtual void paintContent (Graphics& g, int width, int height) = 0;
  37933. public:
  37934. /** @internal */
  37935. void paint (Graphics& g);
  37936. juce_UseDebuggingNewOperator
  37937. private:
  37938. Rectangle content;
  37939. int side, allowablePlacements;
  37940. float arrowTipX, arrowTipY;
  37941. DropShadowEffect shadow;
  37942. BubbleComponent (const BubbleComponent&);
  37943. const BubbleComponent& operator= (const BubbleComponent&);
  37944. };
  37945. #endif // __JUCE_BUBBLECOMPONENT_JUCEHEADER__
  37946. /********* End of inlined file: juce_BubbleComponent.h *********/
  37947. #endif
  37948. #ifndef __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__
  37949. /********* Start of inlined file: juce_BubbleMessageComponent.h *********/
  37950. #ifndef __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__
  37951. #define __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__
  37952. /**
  37953. A speech-bubble component that displays a short message.
  37954. This can be used to show a message with the tail of the speech bubble
  37955. pointing to a particular component or location on the screen.
  37956. @see BubbleComponent
  37957. */
  37958. class JUCE_API BubbleMessageComponent : public BubbleComponent,
  37959. private Timer
  37960. {
  37961. public:
  37962. /** Creates a bubble component.
  37963. After creating one a BubbleComponent, do the following:
  37964. - add it to an appropriate parent component, or put it on the
  37965. desktop with Component::addToDesktop (0).
  37966. - use the showAt() method to show a message.
  37967. - it will make itself invisible after it times-out (and can optionally
  37968. also delete itself), or you can reuse it somewhere else by calling
  37969. showAt() again.
  37970. */
  37971. BubbleMessageComponent (const int fadeOutLengthMs = 150);
  37972. /** Destructor. */
  37973. ~BubbleMessageComponent();
  37974. /** Shows a message bubble at a particular position.
  37975. This shows the bubble with its stem pointing to the given location
  37976. (co-ordinates being relative to its parent component).
  37977. For details about exactly how it decides where to position itself, see
  37978. BubbleComponent::updatePosition().
  37979. @param x the x co-ordinate of end of the bubble's tail
  37980. @param y the y co-ordinate of end of the bubble's tail
  37981. @param message the text to display
  37982. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  37983. from its parent compnent. If this is 0 or less, it
  37984. will stay there until manually removed.
  37985. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  37986. mouse button is pressed (anywhere on the screen)
  37987. @param deleteSelfAfterUse if true, then the component will delete itself after
  37988. it becomes invisible
  37989. */
  37990. void showAt (int x, int y,
  37991. const String& message,
  37992. const int numMillisecondsBeforeRemoving,
  37993. const bool removeWhenMouseClicked = true,
  37994. const bool deleteSelfAfterUse = false);
  37995. /** Shows a message bubble next to a particular component.
  37996. This shows the bubble with its stem pointing at the given component.
  37997. For details about exactly how it decides where to position itself, see
  37998. BubbleComponent::updatePosition().
  37999. @param component the component that you want to point at
  38000. @param message the text to display
  38001. @param numMillisecondsBeforeRemoving how long to leave it on the screen before removing itself
  38002. from its parent compnent. If this is 0 or less, it
  38003. will stay there until manually removed.
  38004. @param removeWhenMouseClicked if this is true, the bubble will disappear as soon as a
  38005. mouse button is pressed (anywhere on the screen)
  38006. @param deleteSelfAfterUse if true, then the component will delete itself after
  38007. it becomes invisible
  38008. */
  38009. void showAt (Component* const component,
  38010. const String& message,
  38011. const int numMillisecondsBeforeRemoving,
  38012. const bool removeWhenMouseClicked = true,
  38013. const bool deleteSelfAfterUse = false);
  38014. /** @internal */
  38015. void getContentSize (int& w, int& h);
  38016. /** @internal */
  38017. void paintContent (Graphics& g, int w, int h);
  38018. /** @internal */
  38019. void timerCallback();
  38020. juce_UseDebuggingNewOperator
  38021. private:
  38022. int fadeOutLength, mouseClickCounter;
  38023. TextLayout textLayout;
  38024. int64 expiryTime;
  38025. bool deleteAfterUse;
  38026. void init (const int numMillisecondsBeforeRemoving,
  38027. const bool removeWhenMouseClicked,
  38028. const bool deleteSelfAfterUse);
  38029. BubbleMessageComponent (const BubbleMessageComponent&);
  38030. const BubbleMessageComponent& operator= (const BubbleMessageComponent&);
  38031. };
  38032. #endif // __JUCE_BUBBLEMESSAGECOMPONENT_JUCEHEADER__
  38033. /********* End of inlined file: juce_BubbleMessageComponent.h *********/
  38034. #endif
  38035. #ifndef __JUCE_COLOURSELECTOR_JUCEHEADER__
  38036. /********* Start of inlined file: juce_ColourSelector.h *********/
  38037. #ifndef __JUCE_COLOURSELECTOR_JUCEHEADER__
  38038. #define __JUCE_COLOURSELECTOR_JUCEHEADER__
  38039. /**
  38040. A component that lets the user choose a colour.
  38041. This shows RGB sliders and a colourspace that the user can pick colours from.
  38042. This class is also a ChangeBroadcaster, so listeners can register to be told
  38043. when the colour changes.
  38044. */
  38045. class JUCE_API ColourSelector : public Component,
  38046. public ChangeBroadcaster,
  38047. protected SliderListener
  38048. {
  38049. public:
  38050. /** Options for the type of selector to show. These are passed into the constructor. */
  38051. enum ColourSelectorOptions
  38052. {
  38053. showAlphaChannel = 1 << 0, /**< if set, the colour's alpha channel can be changed as well as its RGB. */
  38054. showColourAtTop = 1 << 1, /**< if set, a swatch of the colour is shown at the top of the component. */
  38055. showSliders = 1 << 2, /**< if set, RGB sliders are shown at the bottom of the component. */
  38056. showColourspace = 1 << 3 /**< if set, a big HSV selector is shown. */
  38057. };
  38058. /** Creates a ColourSelector object.
  38059. The flags are a combination of values from the ColourSelectorOptions enum, specifying
  38060. which of the selector's features should be visible.
  38061. The edgeGap value specifies the amount of space to leave around the edge.
  38062. gapAroundColourSpaceComponent indicates how much of a gap to put around the
  38063. colourspace and hue selector components.
  38064. */
  38065. ColourSelector (const int sectionsToShow = (showAlphaChannel | showColourAtTop | showSliders | showColourspace),
  38066. const int edgeGap = 4,
  38067. const int gapAroundColourSpaceComponent = 7);
  38068. /** Destructor. */
  38069. ~ColourSelector();
  38070. /** Returns the colour that the user has currently selected.
  38071. The ColourSelector class is also a ChangeBroadcaster, so listeners can
  38072. register to be told when the colour changes.
  38073. @see setCurrentColour
  38074. */
  38075. const Colour getCurrentColour() const;
  38076. /** Changes the colour that is currently being shown.
  38077. */
  38078. void setCurrentColour (const Colour& newColour);
  38079. /** Tells the selector how many preset colour swatches you want to have on the component.
  38080. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  38081. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  38082. their values.
  38083. */
  38084. virtual int getNumSwatches() const;
  38085. /** Called by the selector to find out the colour of one of the swatches.
  38086. Your subclass should return the colour of the swatch with the given index.
  38087. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  38088. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  38089. their values.
  38090. */
  38091. virtual const Colour getSwatchColour (const int index) const;
  38092. /** Called by the selector when the user puts a new colour into one of the swatches.
  38093. Your subclass should change the colour of the swatch with the given index.
  38094. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  38095. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  38096. their values.
  38097. */
  38098. virtual void setSwatchColour (const int index, const Colour& newColour) const;
  38099. /** A set of colour IDs to use to change the colour of various aspects of the keyboard.
  38100. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  38101. methods.
  38102. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  38103. */
  38104. enum ColourIds
  38105. {
  38106. backgroundColourId = 0x1007000, /**< the colour used to fill the component's background. */
  38107. labelTextColourId = 0x1007001 /**< the colour used for the labels next to the sliders. */
  38108. };
  38109. juce_UseDebuggingNewOperator
  38110. private:
  38111. friend class ColourSpaceView;
  38112. friend class HueSelectorComp;
  38113. Colour colour;
  38114. float h, s, v;
  38115. Slider* sliders[4];
  38116. Component* colourSpace;
  38117. Component* hueSelector;
  38118. VoidArray swatchComponents;
  38119. const int flags;
  38120. int topSpace, edgeGap;
  38121. void setHue (float newH);
  38122. void setSV (float newS, float newV);
  38123. void updateHSV();
  38124. void update();
  38125. void sliderValueChanged (Slider*);
  38126. void paint (Graphics& g);
  38127. void resized();
  38128. ColourSelector (const ColourSelector&);
  38129. const ColourSelector& operator= (const ColourSelector&);
  38130. // this constructor is here temporarily to prevent old code compiling, because the parameters
  38131. // have changed - if you get an error here, update your code to use the new constructor instead..
  38132. // (xxx - note to self: remember to remove this at some point in the future)
  38133. ColourSelector (const bool);
  38134. };
  38135. #endif // __JUCE_COLOURSELECTOR_JUCEHEADER__
  38136. /********* End of inlined file: juce_ColourSelector.h *********/
  38137. #endif
  38138. #ifndef __JUCE_DROPSHADOWER_JUCEHEADER__
  38139. #endif
  38140. #ifndef __JUCE_MAGNIFIERCOMPONENT_JUCEHEADER__
  38141. /********* Start of inlined file: juce_MagnifierComponent.h *********/
  38142. #ifndef __JUCE_MAGNIFIERCOMPONENT_JUCEHEADER__
  38143. #define __JUCE_MAGNIFIERCOMPONENT_JUCEHEADER__
  38144. /**
  38145. A component that contains another component, and can magnify or shrink it.
  38146. This component will continually update its size so that it fits the zoomed
  38147. version of the content component that you put inside it, so don't try to
  38148. change the size of this component directly - instead change that of the
  38149. content component.
  38150. To make it all work, the magnifier uses extremely cunning ComponentPeer tricks
  38151. to remap mouse events correctly. This means that the content component won't
  38152. appear to be a direct child of this component, and instead will think its
  38153. on the desktop.
  38154. */
  38155. class JUCE_API MagnifierComponent : public Component
  38156. {
  38157. public:
  38158. /** Creates a MagnifierComponent.
  38159. This component will continually update its size so that it fits the zoomed
  38160. version of the content component that you put inside it, so don't try to
  38161. change the size of this component directly - instead change that of the
  38162. content component.
  38163. @param contentComponent the component to add as the magnified one
  38164. @param deleteContentCompWhenNoLongerNeeded if true, the content component will
  38165. be deleted when this component is deleted. If false,
  38166. it's the caller's responsibility to delete it later.
  38167. */
  38168. MagnifierComponent (Component* const contentComponent,
  38169. const bool deleteContentCompWhenNoLongerNeeded);
  38170. /** Destructor. */
  38171. ~MagnifierComponent();
  38172. /** Returns the current content component. */
  38173. Component* getContentComponent() const throw() { return content; }
  38174. /** Changes the zoom level.
  38175. The scale factor must be greater than zero. Values less than 1 will shrink the
  38176. image; values greater than 1 will multiply its size by this amount.
  38177. When this is called, this component will change its size to fit the full extent
  38178. of the newly zoomed content.
  38179. */
  38180. void setScaleFactor (double newScaleFactor);
  38181. /** Returns the current zoom factor. */
  38182. double getScaleFactor() const throw() { return scaleFactor; }
  38183. juce_UseDebuggingNewOperator
  38184. /** @internal */
  38185. void childBoundsChanged (Component*);
  38186. private:
  38187. Component* content;
  38188. Component* holderComp;
  38189. double scaleFactor;
  38190. ComponentPeer* peer;
  38191. bool deleteContent;
  38192. void paint (Graphics& g);
  38193. void mouseDown (const MouseEvent& e);
  38194. void mouseUp (const MouseEvent& e);
  38195. void mouseDrag (const MouseEvent& e);
  38196. void mouseMove (const MouseEvent& e);
  38197. void mouseEnter (const MouseEvent& e);
  38198. void mouseExit (const MouseEvent& e);
  38199. void mouseWheelMove (const MouseEvent& e, float, float);
  38200. int scaleInt (const int n) const throw();
  38201. MagnifierComponent (const MagnifierComponent&);
  38202. const MagnifierComponent& operator= (const MagnifierComponent&);
  38203. };
  38204. #endif // __JUCE_MAGNIFIERCOMPONENT_JUCEHEADER__
  38205. /********* End of inlined file: juce_MagnifierComponent.h *********/
  38206. #endif
  38207. #ifndef __JUCE_MIDIKEYBOARDCOMPONENT_JUCEHEADER__
  38208. /********* Start of inlined file: juce_MidiKeyboardComponent.h *********/
  38209. #ifndef __JUCE_MIDIKEYBOARDCOMPONENT_JUCEHEADER__
  38210. #define __JUCE_MIDIKEYBOARDCOMPONENT_JUCEHEADER__
  38211. /**
  38212. A component that displays a piano keyboard, whose notes can be clicked on.
  38213. This component will mimic a physical midi keyboard, showing the current state of
  38214. a MidiKeyboardState object. When the on-screen keys are clicked on, it will play these
  38215. notes by calling the noteOn() and noteOff() methods of its MidiKeyboardState object.
  38216. Another feature is that the computer keyboard can also be used to play notes. By
  38217. default it maps the top two rows of a standard querty keyboard to the notes, but
  38218. these can be remapped if needed. It will only respond to keypresses when it has
  38219. the keyboard focus, so to disable this feature you can call setWantsKeyboardFocus (false).
  38220. The component is also a ChangeBroadcaster, so if you want to be informed when the
  38221. keyboard is scrolled, you can register a ChangeListener for callbacks.
  38222. @see MidiKeyboardState
  38223. */
  38224. class JUCE_API MidiKeyboardComponent : public Component,
  38225. public MidiKeyboardStateListener,
  38226. public ChangeBroadcaster,
  38227. private Timer,
  38228. private AsyncUpdater
  38229. {
  38230. public:
  38231. /** The direction of the keyboard.
  38232. @see setOrientation
  38233. */
  38234. enum Orientation
  38235. {
  38236. horizontalKeyboard,
  38237. verticalKeyboardFacingLeft,
  38238. verticalKeyboardFacingRight,
  38239. };
  38240. /** Creates a MidiKeyboardComponent.
  38241. @param state the midi keyboard model that this component will represent
  38242. @param orientation whether the keyboard is horizonal or vertical
  38243. */
  38244. MidiKeyboardComponent (MidiKeyboardState& state,
  38245. const Orientation orientation);
  38246. /** Destructor. */
  38247. ~MidiKeyboardComponent();
  38248. /** Changes the velocity used in midi note-on messages that are triggered by clicking
  38249. on the component.
  38250. Values are 0 to 1.0, where 1.0 is the heaviest.
  38251. @see setMidiChannel
  38252. */
  38253. void setVelocity (const float velocity);
  38254. /** Changes the midi channel number that will be used for events triggered by clicking
  38255. on the component.
  38256. The channel must be between 1 and 16 (inclusive). This is the channel that will be
  38257. passed on to the MidiKeyboardState::noteOn() method when the user clicks the component.
  38258. Although this is the channel used for outgoing events, the component can display
  38259. incoming events from more than one channel - see setMidiChannelsToDisplay()
  38260. @see setVelocity
  38261. */
  38262. void setMidiChannel (const int midiChannelNumber);
  38263. /** Returns the midi channel that the keyboard is using for midi messages.
  38264. @see setMidiChannel
  38265. */
  38266. int getMidiChannel() const throw() { return midiChannel; }
  38267. /** Sets a mask to indicate which incoming midi channels should be represented by
  38268. key movements.
  38269. The mask is a set of bits, where bit 0 = midi channel 1, bit 1 = midi channel 2, etc.
  38270. If the MidiKeyboardState has a key down for any of the channels whose bits are set
  38271. in this mask, the on-screen keys will also go down.
  38272. By default, this mask is set to 0xffff (all channels displayed).
  38273. @see setMidiChannel
  38274. */
  38275. void setMidiChannelsToDisplay (const int midiChannelMask);
  38276. /** Returns the current set of midi channels represented by the component.
  38277. This is the value that was set with setMidiChannelsToDisplay().
  38278. */
  38279. int getMidiChannelsToDisplay() const throw() { return midiInChannelMask; }
  38280. /** Changes the width used to draw the white keys. */
  38281. void setKeyWidth (const float widthInPixels);
  38282. /** Returns the width that was set by setKeyWidth(). */
  38283. float getKeyWidth() const throw() { return keyWidth; }
  38284. /** Changes the keyboard's current direction. */
  38285. void setOrientation (const Orientation newOrientation);
  38286. /** Returns the keyboard's current direction. */
  38287. const Orientation getOrientation() const throw() { return orientation; }
  38288. /** Sets the range of midi notes that the keyboard will be limited to.
  38289. By default the range is 0 to 127 (inclusive), but you can limit this if you
  38290. only want a restricted set of the keys to be shown.
  38291. Note that the values here are inclusive and must be between 0 and 127.
  38292. */
  38293. void setAvailableRange (const int lowestNote,
  38294. const int highestNote);
  38295. /** Returns the first note in the available range.
  38296. @see setAvailableRange
  38297. */
  38298. int getRangeStart() const throw() { return rangeStart; }
  38299. /** Returns the last note in the available range.
  38300. @see setAvailableRange
  38301. */
  38302. int getRangeEnd() const throw() { return rangeEnd; }
  38303. /** If the keyboard extends beyond the size of the component, this will scroll
  38304. it to show the given key at the start.
  38305. Whenever the keyboard's position is changed, this will use the ChangeBroadcaster
  38306. base class to send a callback to any ChangeListeners that have been registered.
  38307. */
  38308. void setLowestVisibleKey (int noteNumber);
  38309. /** Returns the number of the first key shown in the component.
  38310. @see setLowestVisibleKey
  38311. */
  38312. int getLowestVisibleKey() const throw() { return firstKey; }
  38313. /** If set to true, then scroll buttons will appear at either end of the keyboard
  38314. if there are too many notes to fit them all in the component at once.
  38315. */
  38316. void setScrollButtonsVisible (const bool canScroll);
  38317. /** A set of colour IDs to use to change the colour of various aspects of the keyboard.
  38318. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  38319. methods.
  38320. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  38321. */
  38322. enum ColourIds
  38323. {
  38324. whiteNoteColourId = 0x1005000,
  38325. blackNoteColourId = 0x1005001,
  38326. keySeparatorLineColourId = 0x1005002,
  38327. mouseOverKeyOverlayColourId = 0x1005003, /**< This colour will be overlaid on the normal note colour. */
  38328. keyDownOverlayColourId = 0x1005004, /**< This colour will be overlaid on the normal note colour. */
  38329. textLabelColourId = 0x1005005,
  38330. upDownButtonBackgroundColourId = 0x1005006,
  38331. upDownButtonArrowColourId = 0x1005007
  38332. };
  38333. /** Returns the position within the component of the left-hand edge of a key.
  38334. Depending on the keyboard's orientation, this may be a horizontal or vertical
  38335. distance, in either direction.
  38336. */
  38337. int getKeyStartPosition (const int midiNoteNumber) const;
  38338. /** Deletes all key-mappings.
  38339. @see setKeyPressForNote
  38340. */
  38341. void clearKeyMappings();
  38342. /** Maps a key-press to a given note.
  38343. @param key the key that should trigger the note
  38344. @param midiNoteOffsetFromC how many semitones above C the triggered note should
  38345. be. The actual midi note that gets played will be
  38346. this value + (12 * the current base octave). To change
  38347. the base octave, see setKeyPressBaseOctave()
  38348. */
  38349. void setKeyPressForNote (const KeyPress& key,
  38350. const int midiNoteOffsetFromC);
  38351. /** Removes any key-mappings for a given note.
  38352. For a description of what the note number means, see setKeyPressForNote().
  38353. */
  38354. void removeKeyPressForNote (const int midiNoteOffsetFromC);
  38355. /** Changes the base note above which key-press-triggered notes are played.
  38356. The set of key-mappings that trigger notes can be moved up and down to cover
  38357. the entire scale using this method.
  38358. The value passed in is an octave number between 0 and 10 (inclusive), and
  38359. indicates which C is the base note to which the key-mapped notes are
  38360. relative.
  38361. */
  38362. void setKeyPressBaseOctave (const int newOctaveNumber);
  38363. /** This sets the octave number which is shown as the octave number for middle C.
  38364. This affects only the default implementation of getWhiteNoteText(), which
  38365. passes this octave number to MidiMessage::getMidiNoteName() in order to
  38366. get the note text. See MidiMessage::getMidiNoteName() for more info about
  38367. the parameter.
  38368. By default this value is set to 3.
  38369. @see getOctaveForMiddleC
  38370. */
  38371. void setOctaveForMiddleC (const int octaveNumForMiddleC) throw();
  38372. /** This returns the value set by setOctaveForMiddleC().
  38373. @see setOctaveForMiddleC
  38374. */
  38375. int getOctaveForMiddleC() const throw() { return octaveNumForMiddleC; }
  38376. /** @internal */
  38377. void paint (Graphics& g);
  38378. /** @internal */
  38379. void resized();
  38380. /** @internal */
  38381. void mouseMove (const MouseEvent& e);
  38382. /** @internal */
  38383. void mouseDrag (const MouseEvent& e);
  38384. /** @internal */
  38385. void mouseDown (const MouseEvent& e);
  38386. /** @internal */
  38387. void mouseUp (const MouseEvent& e);
  38388. /** @internal */
  38389. void mouseEnter (const MouseEvent& e);
  38390. /** @internal */
  38391. void mouseExit (const MouseEvent& e);
  38392. /** @internal */
  38393. void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
  38394. /** @internal */
  38395. void timerCallback();
  38396. /** @internal */
  38397. bool keyStateChanged();
  38398. /** @internal */
  38399. void focusLost (FocusChangeType cause);
  38400. /** @internal */
  38401. void handleNoteOn (MidiKeyboardState* source, int midiChannel, int midiNoteNumber, float velocity);
  38402. /** @internal */
  38403. void handleNoteOff (MidiKeyboardState* source, int midiChannel, int midiNoteNumber);
  38404. /** @internal */
  38405. void handleAsyncUpdate();
  38406. /** @internal */
  38407. void colourChanged();
  38408. juce_UseDebuggingNewOperator
  38409. protected:
  38410. friend class MidiKeyboardUpDownButton;
  38411. /** Draws a white note in the given rectangle.
  38412. isOver indicates whether the mouse is over the key, isDown indicates whether the key is
  38413. currently pressed down.
  38414. When doing this, be sure to note the keyboard's orientation.
  38415. */
  38416. virtual void drawWhiteNote (int midiNoteNumber,
  38417. Graphics& g,
  38418. int x, int y, int w, int h,
  38419. bool isDown, bool isOver,
  38420. const Colour& lineColour,
  38421. const Colour& textColour);
  38422. /** Draws a black note in the given rectangle.
  38423. isOver indicates whether the mouse is over the key, isDown indicates whether the key is
  38424. currently pressed down.
  38425. When doing this, be sure to note the keyboard's orientation.
  38426. */
  38427. virtual void drawBlackNote (int midiNoteNumber,
  38428. Graphics& g,
  38429. int x, int y, int w, int h,
  38430. bool isDown, bool isOver,
  38431. const Colour& noteFillColour);
  38432. /** Allows text to be drawn on the white notes.
  38433. By default this is used to label the C in each octave, but could be used for other things.
  38434. @see setOctaveForMiddleC
  38435. */
  38436. virtual const String getWhiteNoteText (const int midiNoteNumber);
  38437. /** Draws the up and down buttons that change the base note. */
  38438. virtual void drawUpDownButton (Graphics& g, int w, int h,
  38439. const bool isMouseOver,
  38440. const bool isButtonPressed,
  38441. const bool movesOctavesUp);
  38442. /** Callback when the mouse is clicked on a key.
  38443. You could use this to do things like handle right-clicks on keys, etc.
  38444. Return true if you want the click to trigger the note, or false if you
  38445. want to handle it yourself and not have the note played.
  38446. @see mouseDraggedToKey
  38447. */
  38448. virtual bool mouseDownOnKey (int midiNoteNumber, const MouseEvent& e);
  38449. /** Callback when the mouse is dragged from one key onto another.
  38450. @see mouseDownOnKey
  38451. */
  38452. virtual void mouseDraggedToKey (int midiNoteNumber, const MouseEvent& e);
  38453. /** Calculates the positon of a given midi-note.
  38454. This can be overridden to create layouts with custom key-widths.
  38455. @param midiNoteNumber the note to find
  38456. @param keyWidth the desired width in pixels of one key - see setKeyWidth()
  38457. @param x the x position of the left-hand edge of the key (this method
  38458. always works in terms of a horizontal keyboard)
  38459. @param w the width of the key
  38460. */
  38461. virtual void getKeyPosition (int midiNoteNumber, float keyWidth,
  38462. int& x, int& w) const;
  38463. private:
  38464. MidiKeyboardState& state;
  38465. int xOffset, blackNoteLength;
  38466. float keyWidth;
  38467. Orientation orientation;
  38468. int midiChannel, midiInChannelMask;
  38469. float velocity;
  38470. int noteUnderMouse, mouseDownNote;
  38471. BitArray keysPressed, keysCurrentlyDrawnDown;
  38472. int rangeStart, rangeEnd, firstKey;
  38473. bool canScroll, mouseDragging;
  38474. Button* scrollDown;
  38475. Button* scrollUp;
  38476. Array <KeyPress> keyPresses;
  38477. Array <int> keyPressNotes;
  38478. int keyMappingOctave;
  38479. int octaveNumForMiddleC;
  38480. void getKeyPos (int midiNoteNumber, int& x, int& w) const;
  38481. int xyToNote (int x, int y);
  38482. int remappedXYToNote (int x, int y) const;
  38483. void resetAnyKeysInUse();
  38484. void updateNoteUnderMouse (int x, int y);
  38485. void repaintNote (const int midiNoteNumber);
  38486. MidiKeyboardComponent (const MidiKeyboardComponent&);
  38487. const MidiKeyboardComponent& operator= (const MidiKeyboardComponent&);
  38488. };
  38489. #endif // __JUCE_MIDIKEYBOARDCOMPONENT_JUCEHEADER__
  38490. /********* End of inlined file: juce_MidiKeyboardComponent.h *********/
  38491. #endif
  38492. #ifndef __JUCE_OPENGLCOMPONENT_JUCEHEADER__
  38493. /********* Start of inlined file: juce_OpenGLComponent.h *********/
  38494. #ifndef __JUCE_OPENGLCOMPONENT_JUCEHEADER__
  38495. #define __JUCE_OPENGLCOMPONENT_JUCEHEADER__
  38496. // this is used to disable OpenGL, and is defined in juce_Config.h
  38497. #if JUCE_OPENGL || DOXYGEN
  38498. class OpenGLComponentWatcher;
  38499. /**
  38500. Represents the various properties of an OpenGL bitmap format.
  38501. @see OpenGLComponent::setPixelFormat
  38502. */
  38503. struct OpenGLPixelFormat
  38504. {
  38505. /** Creates an OpenGLPixelFormat.
  38506. The default constructor just initialises the object as a simple 8-bit
  38507. RGBA format.
  38508. */
  38509. OpenGLPixelFormat (const int bitsPerRGBComponent = 8,
  38510. const int alphaBits = 8,
  38511. const int depthBufferBits = 16,
  38512. const int stencilBufferBits = 0) throw();
  38513. int redBits; /**< The number of bits per pixel to use for the red channel. */
  38514. int greenBits; /**< The number of bits per pixel to use for the green channel. */
  38515. int blueBits; /**< The number of bits per pixel to use for the blue channel. */
  38516. int alphaBits; /**< The number of bits per pixel to use for the alpha channel. */
  38517. int depthBufferBits; /**< The number of bits per pixel to use for a depth buffer. */
  38518. int stencilBufferBits; /**< The number of bits per pixel to use for a stencil buffer. */
  38519. int accumulationBufferRedBits; /**< The number of bits per pixel to use for an accumulation buffer's red channel. */
  38520. int accumulationBufferGreenBits; /**< The number of bits per pixel to use for an accumulation buffer's green channel. */
  38521. int accumulationBufferBlueBits; /**< The number of bits per pixel to use for an accumulation buffer's blue channel. */
  38522. int accumulationBufferAlphaBits; /**< The number of bits per pixel to use for an accumulation buffer's alpha channel. */
  38523. uint8 fullSceneAntiAliasingNumSamples; /**< The number of samples to use in full-scene anti-aliasing (if available). */
  38524. /** Returns a list of all the pixel formats that can be used in this system.
  38525. A reference component is needed in case there are multiple screens with different
  38526. capabilities - in which case, the one that the component is on will be used.
  38527. */
  38528. static void getAvailablePixelFormats (Component* component,
  38529. OwnedArray <OpenGLPixelFormat>& results);
  38530. bool operator== (const OpenGLPixelFormat&) const throw();
  38531. juce_UseDebuggingNewOperator
  38532. };
  38533. /**
  38534. A base class for types of OpenGL context.
  38535. An OpenGLComponent will supply its own context for drawing in its window.
  38536. */
  38537. class OpenGLContext
  38538. {
  38539. public:
  38540. /** Destructor. */
  38541. virtual ~OpenGLContext();
  38542. /** Makes this context the currently active one. */
  38543. virtual bool makeActive() const throw() = 0;
  38544. /** If this context is currently active, it is disactivated. */
  38545. virtual bool makeInactive() const throw() = 0;
  38546. /** Returns true if this context is currently active. */
  38547. virtual bool isActive() const throw() = 0;
  38548. /** Swaps the buffers (if the context can do this). */
  38549. virtual void swapBuffers() = 0;
  38550. /** Sets whether the context checks the vertical sync before swapping.
  38551. The value is the number of frames to allow between buffer-swapping. This is
  38552. fairly system-dependent, but 0 turns off syncing, 1 makes it swap on frame-boundaries,
  38553. and greater numbers indicate that it should swap less often.
  38554. Returns true if it sets the value successfully.
  38555. */
  38556. virtual bool setSwapInterval (const int numFramesPerSwap) = 0;
  38557. /** Returns the current swap-sync interval.
  38558. See setSwapInterval() for info about the value returned.
  38559. */
  38560. virtual int getSwapInterval() const = 0;
  38561. /** Returns the pixel format being used by this context. */
  38562. virtual const OpenGLPixelFormat getPixelFormat() const = 0;
  38563. /** For windowed contexts, this moves the context within the bounds of
  38564. its parent window.
  38565. */
  38566. virtual void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight) = 0;
  38567. /** For windowed contexts, this triggers a repaint of the window.
  38568. (Not relevent on all platforms).
  38569. */
  38570. virtual void repaint() = 0;
  38571. /** Returns an OS-dependent handle to the raw GL context.
  38572. On win32, this will be a HGLRC; on the Mac, an AGLContext; on Linux,
  38573. a GLXContext.
  38574. */
  38575. virtual void* getRawContext() const throw() = 0;
  38576. /** This tries to create a context that can be used for drawing into the
  38577. area occupied by the specified component.
  38578. Note that you probably shouldn't use this method directly unless you know what
  38579. you're doing - the OpenGLComponent calls this and manages the context for you.
  38580. */
  38581. static OpenGLContext* createContextForWindow (Component* componentToDrawTo,
  38582. const OpenGLPixelFormat& pixelFormat,
  38583. const OpenGLContext* const contextToShareWith);
  38584. /** Returns the context that's currently in active use by the calling thread.
  38585. Returns 0 if there isn't an active context.
  38586. */
  38587. static OpenGLContext* getCurrentContext();
  38588. juce_UseDebuggingNewOperator
  38589. protected:
  38590. OpenGLContext() throw();
  38591. };
  38592. /**
  38593. A component that contains an OpenGL canvas.
  38594. Override this, add it to whatever component you want to, and use the renderOpenGL()
  38595. method to draw its contents.
  38596. */
  38597. class JUCE_API OpenGLComponent : public Component
  38598. {
  38599. public:
  38600. /** Creates an OpenGLComponent.
  38601. */
  38602. OpenGLComponent();
  38603. /** Destructor. */
  38604. ~OpenGLComponent();
  38605. /** Changes the pixel format used by this component.
  38606. @see OpenGLPixelFormat::getAvailablePixelFormats()
  38607. */
  38608. void setPixelFormat (const OpenGLPixelFormat& formatToUse);
  38609. /** Returns the pixel format that this component is currently using. */
  38610. const OpenGLPixelFormat getPixelFormat() const;
  38611. /** Specifies an OpenGL context which should be shared with the one that this
  38612. component is using.
  38613. This is an OpenGL feature that lets two contexts share their texture data.
  38614. Note that this pointer is stored by the component, and when the component
  38615. needs to recreate its internal context for some reason, the same context
  38616. will be used again to share lists. So if you pass a context in here,
  38617. don't delete the context while this component is still using it! You can
  38618. call shareWith (0) to stop this component from sharing with it.
  38619. */
  38620. void shareWith (OpenGLContext* contextToShareListsWith);
  38621. /** Returns the context that this component is sharing with.
  38622. @see shareWith
  38623. */
  38624. OpenGLContext* getShareContext() const throw() { return contextToShareListsWith; }
  38625. /** Flips the openGL buffers over. */
  38626. void swapBuffers();
  38627. /** This replaces the normal paint() callback - use it to draw your openGL stuff.
  38628. When this is called, makeCurrentContextActive() will already have been called
  38629. for you, so you just need to draw.
  38630. */
  38631. virtual void renderOpenGL() = 0;
  38632. /** This method is called when the component creates a new OpenGL context.
  38633. A new context may be created when the component is first used, or when it
  38634. is moved to a different window, or when the window is hidden and re-shown,
  38635. etc.
  38636. You can use this callback as an opportunity to set up things like textures
  38637. that your context needs.
  38638. New contexts are created on-demand by the makeCurrentContextActive() method - so
  38639. if the context is deleted, e.g. by changing the pixel format or window, no context
  38640. will be created until the next call to makeCurrentContextActive(), which will
  38641. synchronously create one and call this method. This means that if you're using
  38642. a non-GUI thread for rendering, you can make sure this method is be called by
  38643. your renderer thread.
  38644. When this callback happens, the context will already have been made current
  38645. using the makeCurrentContextActive() method, so there's no need to call it
  38646. again in your code.
  38647. */
  38648. virtual void newOpenGLContextCreated() = 0;
  38649. /** Returns the context that will draw into this component.
  38650. This may return 0 if the component is currently invisible or hasn't currently
  38651. got a context. The context object can be deleted and a new one created during
  38652. the lifetime of this component, and there may be times when it doesn't have one.
  38653. @see newOpenGLContextCreated()
  38654. */
  38655. OpenGLContext* getCurrentContext() const throw() { return context; }
  38656. /** Makes this component the current openGL context.
  38657. You might want to use this in things like your resize() method, before calling
  38658. GL commands.
  38659. If this returns false, then the context isn't active, so you should avoid
  38660. making any calls.
  38661. This call may actually create a context if one isn't currently initialised. If
  38662. it does this, it will also synchronously call the newOpenGLContextCreated()
  38663. method to let you initialise it as necessary.
  38664. @see OpenGLContext::makeActive
  38665. */
  38666. bool makeCurrentContextActive();
  38667. /** Stops the current component being the active OpenGL context.
  38668. This is the opposite of makeCurrentContextActive()
  38669. @see OpenGLContext::makeInactive
  38670. */
  38671. void makeCurrentContextInactive();
  38672. /** Returns true if this component is the active openGL context for the
  38673. current thread.
  38674. @see OpenGLContext::isActive
  38675. */
  38676. bool isActiveContext() const throw();
  38677. /** Calls the rendering callback, and swaps the buffers afterwards.
  38678. This is called automatically by paint() when the component needs to be rendered.
  38679. It can be overridden if you need to decouple the rendering from the paint callback
  38680. and render with a custom thread.
  38681. Returns true if the operation succeeded.
  38682. */
  38683. virtual bool renderAndSwapBuffers();
  38684. /** This returns a critical section that can be used to lock the current context.
  38685. Because the context that is used by this component can change, e.g. when the
  38686. component is shown or hidden, then if you're rendering to it on a background
  38687. thread, this allows you to lock the context for the duration of your rendering
  38688. routine.
  38689. */
  38690. CriticalSection& getContextLock() throw() { return contextLock; }
  38691. /** @internal */
  38692. void paint (Graphics& g);
  38693. juce_UseDebuggingNewOperator
  38694. private:
  38695. friend class OpenGLComponentWatcher;
  38696. OpenGLComponentWatcher* componentWatcher;
  38697. OpenGLContext* context;
  38698. OpenGLContext* contextToShareListsWith;
  38699. CriticalSection contextLock;
  38700. OpenGLPixelFormat preferredPixelFormat;
  38701. bool needToUpdateViewport;
  38702. void deleteContext();
  38703. void updateContextPosition();
  38704. void internalRepaint (int x, int y, int w, int h);
  38705. OpenGLComponent (const OpenGLComponent&);
  38706. const OpenGLComponent& operator= (const OpenGLComponent&);
  38707. };
  38708. #endif
  38709. #endif // __JUCE_OPENGLCOMPONENT_JUCEHEADER__
  38710. /********* End of inlined file: juce_OpenGLComponent.h *********/
  38711. #endif
  38712. #ifndef __JUCE_PREFERENCESPANEL_JUCEHEADER__
  38713. /********* Start of inlined file: juce_PreferencesPanel.h *********/
  38714. #ifndef __JUCE_PREFERENCESPANEL_JUCEHEADER__
  38715. #define __JUCE_PREFERENCESPANEL_JUCEHEADER__
  38716. /**
  38717. A component with a set of buttons at the top for changing between pages of
  38718. preferences.
  38719. This is just a handy way of writing a Mac-style preferences panel where you
  38720. have a row of buttons along the top for the different preference categories,
  38721. each button having an icon above its name. Clicking these will show an
  38722. appropriate prefs page below it.
  38723. You can either put one of these inside your own component, or just use the
  38724. showInDialogBox() method to show it in a window and run it modally.
  38725. To use it, just add a set of named pages with the addSettingsPage() method,
  38726. and implement the createComponentForPage() method to create suitable components
  38727. for each of these pages.
  38728. */
  38729. class JUCE_API PreferencesPanel : public Component,
  38730. private ButtonListener
  38731. {
  38732. public:
  38733. /** Creates an empty panel.
  38734. Use addSettingsPage() to add some pages to it in your constructor.
  38735. */
  38736. PreferencesPanel();
  38737. /** Destructor. */
  38738. ~PreferencesPanel();
  38739. /** Creates a page using a set of drawables to define the page's icon.
  38740. Note that the other version of this method is much easier if you're using
  38741. an image instead of a custom drawable.
  38742. @param pageTitle the name of this preferences page - you'll need to
  38743. make sure your createComponentForPage() method creates
  38744. a suitable component when it is passed this name
  38745. @param normalIcon the drawable to display in the page's button normally
  38746. @param overIcon the drawable to display in the page's button when the mouse is over
  38747. @param downIcon the drawable to display in the page's button when the button is down
  38748. @see DrawableButton
  38749. */
  38750. void addSettingsPage (const String& pageTitle,
  38751. const Drawable* normalIcon,
  38752. const Drawable* overIcon,
  38753. const Drawable* downIcon);
  38754. /** Creates a page using a set of drawables to define the page's icon.
  38755. The other version of this method gives you more control over the icon, but this
  38756. one is much easier if you're just loading it from a file.
  38757. @param pageTitle the name of this preferences page - you'll need to
  38758. make sure your createComponentForPage() method creates
  38759. a suitable component when it is passed this name
  38760. @param imageData a block of data containing an image file, e.g. a jpeg, png or gif.
  38761. For this to look good, you'll probably want to use a nice
  38762. transparent png file.
  38763. @param imageDataSize the size of the image data, in bytes
  38764. */
  38765. void addSettingsPage (const String& pageTitle,
  38766. const char* imageData,
  38767. const int imageDataSize);
  38768. /** Utility method to display this panel in a DialogWindow.
  38769. Calling this will create a DialogWindow containing this panel with the
  38770. given size and title, and will run it modally, returning when the user
  38771. closes the dialog box.
  38772. */
  38773. void showInDialogBox (const String& dialogtitle,
  38774. int dialogWidth,
  38775. int dialogHeight,
  38776. const Colour& backgroundColour = Colours::white);
  38777. /** Subclasses must override this to return a component for each preferences page.
  38778. The subclass should return a pointer to a new component representing the named
  38779. page, which the panel will then display.
  38780. The panel will delete the component later when the user goes to another page
  38781. or deletes the panel.
  38782. */
  38783. virtual Component* createComponentForPage (const String& pageName) = 0;
  38784. /** Changes the current page being displayed. */
  38785. void setCurrentPage (const String& pageName);
  38786. /** @internal */
  38787. void resized();
  38788. /** @internal */
  38789. void paint (Graphics& g);
  38790. /** @internal */
  38791. void buttonClicked (Button* button);
  38792. juce_UseDebuggingNewOperator
  38793. private:
  38794. String currentPageName;
  38795. Component* currentPage;
  38796. int buttonSize;
  38797. PreferencesPanel (const PreferencesPanel&);
  38798. const PreferencesPanel& operator= (const PreferencesPanel&);
  38799. };
  38800. #endif // __JUCE_PREFERENCESPANEL_JUCEHEADER__
  38801. /********* End of inlined file: juce_PreferencesPanel.h *********/
  38802. #endif
  38803. #ifndef __JUCE_QUICKTIMEMOVIECOMPONENT_JUCEHEADER__
  38804. /********* Start of inlined file: juce_QuickTimeMovieComponent.h *********/
  38805. #ifndef __JUCE_QUICKTIMEMOVIECOMPONENT_JUCEHEADER__
  38806. #define __JUCE_QUICKTIMEMOVIECOMPONENT_JUCEHEADER__
  38807. // this is used to disable QuickTime, and is defined in juce_Config.h
  38808. #if JUCE_QUICKTIME || DOXYGEN
  38809. #if JUCE_WIN32
  38810. typedef ActiveXControlComponent QTWinBaseClass;
  38811. #else
  38812. typedef Component QTWinBaseClass;
  38813. #endif
  38814. /**
  38815. A window that can play back a QuickTime movie.
  38816. */
  38817. class JUCE_API QuickTimeMovieComponent : public QTWinBaseClass
  38818. #if JUCE_MAC
  38819. , private Timer
  38820. #endif
  38821. {
  38822. public:
  38823. /** Creates a QuickTimeMovieComponent, initially blank.
  38824. Use the loadMovie() method to load a movie once you've added the
  38825. component to a window, (or put it on the desktop as a heavyweight window).
  38826. Loading a movie when the component isn't visible can cause problems, as
  38827. QuickTime needs a window handle to initialise properly.
  38828. */
  38829. QuickTimeMovieComponent();
  38830. /** Destructor. */
  38831. ~QuickTimeMovieComponent();
  38832. /** Returns true if QT is installed and working on this machine.
  38833. */
  38834. static bool isQuickTimeAvailable() throw();
  38835. /** Tries to load a QuickTime movie into the player.
  38836. It's best to call this function once you've added the component to a window,
  38837. (or put it on the desktop as a heavyweight window). Loading a movie when the
  38838. component isn't visible can cause problems, because QuickTime needs a window
  38839. handle to do its stuff.
  38840. @param movieFile the .mov file to open
  38841. @param isControllerVisible whether to show a controller bar at the bottom
  38842. @returns true if the movie opens successfully
  38843. */
  38844. bool loadMovie (const File& movieFile,
  38845. const bool isControllerVisible);
  38846. bool loadMovie (InputStream* movieStream,
  38847. const bool isControllerVisible);
  38848. /** Closes the movie, if one is open. */
  38849. void closeMovie();
  38850. /** Returns the movie file that is currently open.
  38851. If there isn't one, this returns File::nonexistent
  38852. */
  38853. const File getCurrentMovieFile() const;
  38854. /** Returns true if there's currently a movie open. */
  38855. bool isMovieOpen() const;
  38856. /** Returns the length of the movie, in seconds. */
  38857. double getMovieDuration() const;
  38858. /** Returns the movie's natural size, in pixels.
  38859. You can use this to resize the component to show the movie at its preferred
  38860. scale.
  38861. If no movie is loaded, the size returned will be 0 x 0.
  38862. */
  38863. void getMovieNormalSize (int& width, int& height) const;
  38864. /** This will position the component within a given area, keeping its aspect
  38865. ratio correct according to the movie's normal size.
  38866. The component will be made as large as it can go within the space, and will
  38867. be aligned according to the justification value if this means there are gaps at
  38868. the top or sides.
  38869. */
  38870. void setBoundsWithCorrectAspectRatio (const Rectangle& spaceToFitWithin,
  38871. const RectanglePlacement& placement);
  38872. /** Starts the movie playing. */
  38873. void play();
  38874. /** Stops the movie playing. */
  38875. void stop();
  38876. /** Returns true if the movie is currently playing. */
  38877. bool isPlaying() const;
  38878. /** Moves the movie's position back to the start. */
  38879. void goToStart();
  38880. /** Sets the movie's position to a given time. */
  38881. void setPosition (const double seconds);
  38882. /** Returns the current play position of the movie. */
  38883. double getPosition() const;
  38884. /** Changes the movie playback rate.
  38885. A value of 1 is normal speed, greater values play it proportionately faster,
  38886. smaller values play it slower.
  38887. */
  38888. void setSpeed (const float newSpeed);
  38889. /** Changes the movie's playback volume.
  38890. @param newVolume the volume in the range 0 (silent) to 1.0 (full)
  38891. */
  38892. void setMovieVolume (const float newVolume);
  38893. /** Returns the movie's playback volume.
  38894. @returns the volume in the range 0 (silent) to 1.0 (full)
  38895. */
  38896. float getMovieVolume() const;
  38897. /** Tells the movie whether it should loop. */
  38898. void setLooping (const bool shouldLoop);
  38899. /** Returns true if the movie is currently looping.
  38900. @see setLooping
  38901. */
  38902. bool isLooping() const;
  38903. /** True if the native QuickTime controller bar is shown in the window.
  38904. @see loadMovie
  38905. */
  38906. bool isControllerVisible() const;
  38907. /** @internal */
  38908. void paint (Graphics& g);
  38909. /** @internal */
  38910. void parentHierarchyChanged();
  38911. /** @internal */
  38912. void visibilityChanged();
  38913. #if JUCE_MAC
  38914. /** @internal */
  38915. void handleMCEvent (void*);
  38916. /** @internal */
  38917. void assignMovieToWindow();
  38918. /** @internal */
  38919. void timerCallback();
  38920. /** @internal */
  38921. void moved();
  38922. /** @internal */
  38923. void resized();
  38924. #endif
  38925. juce_UseDebuggingNewOperator
  38926. private:
  38927. File movieFile;
  38928. bool movieLoaded, controllerVisible;
  38929. void* internal;
  38930. #if JUCE_MAC
  38931. void* associatedWindow;
  38932. Rectangle lastPositionApplied;
  38933. bool controllerAssignedToWindow, reentrant, looping;
  38934. void checkWindowAssociation();
  38935. #endif
  38936. void createControlIfNeeded();
  38937. bool isControlCreated() const;
  38938. QuickTimeMovieComponent (const QuickTimeMovieComponent&);
  38939. const QuickTimeMovieComponent& operator= (const QuickTimeMovieComponent&);
  38940. };
  38941. #endif
  38942. #endif // __JUCE_QUICKTIMEMOVIECOMPONENT_JUCEHEADER__
  38943. /********* End of inlined file: juce_QuickTimeMovieComponent.h *********/
  38944. #endif
  38945. #ifndef __JUCE_SYSTEMTRAYICONCOMPONENT_JUCEHEADER__
  38946. /********* Start of inlined file: juce_SystemTrayIconComponent.h *********/
  38947. #ifndef __JUCE_SYSTEMTRAYICONCOMPONENT_JUCEHEADER__
  38948. #define __JUCE_SYSTEMTRAYICONCOMPONENT_JUCEHEADER__
  38949. #if JUCE_WIN32 || JUCE_LINUX
  38950. /**
  38951. On Windows only, this component sits in the taskbar tray as a small icon.
  38952. To use it, just create one of these components, but don't attempt to make it
  38953. visible, add it to a parent, or put it on the desktop.
  38954. You can then call setIconImage() to create an icon for it in the taskbar.
  38955. To change the icon's tooltip, you can use setIconTooltip().
  38956. To respond to mouse-events, you can override the normal mouseDown(),
  38957. mouseUp(), mouseDoubleClick() and mouseMove() methods, and although the x, y
  38958. position will not be valid, you can use this to respond to clicks. Traditionally
  38959. you'd use a left-click to show your application's window, and a right-click
  38960. to show a pop-up menu.
  38961. */
  38962. class JUCE_API SystemTrayIconComponent : public Component
  38963. {
  38964. public:
  38965. SystemTrayIconComponent();
  38966. /** Destructor. */
  38967. ~SystemTrayIconComponent();
  38968. /** Changes the image shown in the taskbar.
  38969. */
  38970. void setIconImage (const Image& newImage);
  38971. /** Changes the tooltip that Windows shows above the icon. */
  38972. void setIconTooltip (const String& tooltip);
  38973. #if JUCE_LINUX
  38974. /** @internal */
  38975. void paint (Graphics& g);
  38976. #endif
  38977. juce_UseDebuggingNewOperator
  38978. private:
  38979. SystemTrayIconComponent (const SystemTrayIconComponent&);
  38980. const SystemTrayIconComponent& operator= (const SystemTrayIconComponent&);
  38981. };
  38982. #endif
  38983. #endif // __JUCE_SYSTEMTRAYICONCOMPONENT_JUCEHEADER__
  38984. /********* End of inlined file: juce_SystemTrayIconComponent.h *********/
  38985. #endif
  38986. #ifndef __JUCE_WEBBROWSERCOMPONENT_JUCEHEADER__
  38987. /********* Start of inlined file: juce_WebBrowserComponent.h *********/
  38988. #ifndef __JUCE_WEBBROWSERCOMPONENT_JUCEHEADER__
  38989. #define __JUCE_WEBBROWSERCOMPONENT_JUCEHEADER__
  38990. class WebBrowserComponentInternal;
  38991. /**
  38992. A component that displays an embedded web browser.
  38993. The browser itself will be platform-dependent. On the Mac, probably Safari, on
  38994. Windows, probably IE.
  38995. */
  38996. class WebBrowserComponent : public Component
  38997. {
  38998. public:
  38999. /** Creates a WebBrowserComponent.
  39000. Once it's created and visible, send the browser to a URL using goToURL().
  39001. */
  39002. WebBrowserComponent();
  39003. /** Destructor. */
  39004. ~WebBrowserComponent();
  39005. /** Sends the browser to a particular URL.
  39006. @param url the URL to go to.
  39007. @param headers an optional set of parameters to put in the HTTP header. If
  39008. you supply this, it should be a set of string in the form
  39009. "HeaderKey: HeaderValue"
  39010. @param postData an optional block of data that will be attached to the HTTP
  39011. POST request
  39012. */
  39013. void goToURL (const String& url,
  39014. const StringArray* headers = 0,
  39015. const MemoryBlock* postData = 0);
  39016. /** Stops the current page loading.
  39017. */
  39018. void stop();
  39019. /** Sends the browser back one page.
  39020. */
  39021. void goBack();
  39022. /** Sends the browser forward one page.
  39023. */
  39024. void goForward();
  39025. /** This callback is called when the browser is about to navigate
  39026. to a new location.
  39027. You can override this method to perform some action when the user
  39028. tries to go to a particular URL. To allow the operation to carry on,
  39029. return true, or return false to stop the navigation happening.
  39030. */
  39031. virtual bool pageAboutToLoad (const String& newURL);
  39032. /** @internal */
  39033. void paint (Graphics& g);
  39034. /** @internal */
  39035. void moved();
  39036. /** @internal */
  39037. void resized();
  39038. /** @internal */
  39039. void parentHierarchyChanged();
  39040. /** @internal */
  39041. void visibilityChanged();
  39042. juce_UseDebuggingNewOperator
  39043. private:
  39044. WebBrowserComponentInternal* browser;
  39045. bool blankPageShown;
  39046. String lastURL;
  39047. StringArray lastHeaders;
  39048. MemoryBlock lastPostData;
  39049. #if JUCE_MAC
  39050. void* associatedWindow;
  39051. void updateBrowserPosition();
  39052. void createBrowser();
  39053. void deleteBrowser();
  39054. #endif
  39055. void reloadLastURL();
  39056. void checkWindowAssociation();
  39057. WebBrowserComponent (const WebBrowserComponent&);
  39058. const WebBrowserComponent& operator= (const WebBrowserComponent&);
  39059. };
  39060. #endif // __JUCE_WEBBROWSERCOMPONENT_JUCEHEADER__
  39061. /********* End of inlined file: juce_WebBrowserComponent.h *********/
  39062. #endif
  39063. #ifndef __JUCE_LOOKANDFEEL_JUCEHEADER__
  39064. /********* Start of inlined file: juce_LookAndFeel.h *********/
  39065. #ifndef __JUCE_LOOKANDFEEL_JUCEHEADER__
  39066. #define __JUCE_LOOKANDFEEL_JUCEHEADER__
  39067. class ToggleButton;
  39068. class TextButton;
  39069. class AlertWindow;
  39070. class TextLayout;
  39071. class ScrollBar;
  39072. class BubbleComponent;
  39073. class ComboBox;
  39074. class Button;
  39075. class FilenameComponent;
  39076. class DocumentWindow;
  39077. class ResizableWindow;
  39078. class GroupComponent;
  39079. class MenuBarComponent;
  39080. class DropShadower;
  39081. class GlyphArrangement;
  39082. class PropertyComponent;
  39083. class TableHeaderComponent;
  39084. class Toolbar;
  39085. class ToolbarItemComponent;
  39086. class PopupMenu;
  39087. class ProgressBar;
  39088. class FileBrowserComponent;
  39089. class DirectoryContentsDisplayComponent;
  39090. class FilePreviewComponent;
  39091. /**
  39092. LookAndFeel objects define the appearance of all the JUCE widgets, and subclasses
  39093. can be used to apply different 'skins' to the application.
  39094. */
  39095. class JUCE_API LookAndFeel
  39096. {
  39097. public:
  39098. /** Creates the default JUCE look and feel. */
  39099. LookAndFeel();
  39100. /** Destructor. */
  39101. virtual ~LookAndFeel();
  39102. /** Returns the current default look-and-feel for a component to use when it
  39103. hasn't got one explicitly set.
  39104. @see setDefaultLookAndFeel
  39105. */
  39106. static LookAndFeel& getDefaultLookAndFeel() throw();
  39107. /** Changes the default look-and-feel.
  39108. @param newDefaultLookAndFeel the new look-and-feel object to use - if this is
  39109. set to 0, it will revert to using the default one. The
  39110. object passed-in must be deleted by the caller when
  39111. it's no longer needed.
  39112. @see getDefaultLookAndFeel
  39113. */
  39114. static void setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw();
  39115. /** Looks for a colour that has been registered with the given colour ID number.
  39116. If a colour has been set for this ID number using setColour(), then it is
  39117. returned. If none has been set, it will just return Colours::black.
  39118. The colour IDs for various purposes are stored as enums in the components that
  39119. they are relevent to - for an example, see Slider::ColourIds,
  39120. Label::ColourIds, TextEditor::ColourIds, TreeView::ColourIds, etc.
  39121. If you're looking up a colour for use in drawing a component, it's usually
  39122. best not to call this directly, but to use the Component::findColour() method
  39123. instead. That will first check whether a suitable colour has been registered
  39124. directly with the component, and will fall-back on calling the component's
  39125. LookAndFeel's findColour() method if none is found.
  39126. @see setColour, Component::findColour, Component::setColour
  39127. */
  39128. const Colour findColour (const int colourId) const throw();
  39129. /** Registers a colour to be used for a particular purpose.
  39130. For more details, see the comments for findColour().
  39131. @see findColour, Component::findColour, Component::setColour
  39132. */
  39133. void setColour (const int colourId, const Colour& colour) throw();
  39134. /** Draws the lozenge-shaped background for a standard button. */
  39135. virtual void drawButtonBackground (Graphics& g,
  39136. Button& button,
  39137. const Colour& backgroundColour,
  39138. bool isMouseOverButton,
  39139. bool isButtonDown);
  39140. /** Draws the text for a TextButton. */
  39141. virtual void drawButtonText (Graphics& g,
  39142. TextButton& button,
  39143. bool isMouseOverButton,
  39144. bool isButtonDown);
  39145. /** Draws the contents of a standard ToggleButton. */
  39146. virtual void drawToggleButton (Graphics& g,
  39147. ToggleButton& button,
  39148. bool isMouseOverButton,
  39149. bool isButtonDown);
  39150. virtual void changeToggleButtonWidthToFitText (ToggleButton& button);
  39151. virtual void drawTickBox (Graphics& g,
  39152. Component& component,
  39153. int x, int y, int w, int h,
  39154. const bool ticked,
  39155. const bool isEnabled,
  39156. const bool isMouseOverButton,
  39157. const bool isButtonDown);
  39158. /** Draws the contents of a message box.
  39159. */
  39160. virtual void drawAlertBox (Graphics& g,
  39161. AlertWindow& alert,
  39162. const Rectangle& textArea,
  39163. TextLayout& textLayout);
  39164. virtual int getAlertBoxWindowFlags();
  39165. /** Draws a progress bar.
  39166. If the progress value is less than 0 or greater than 1.0, this should draw a spinning
  39167. bar that fills the whole space (i.e. to say that the app is still busy but the progress
  39168. isn't known). It can use the current time as a basis for playing an animation.
  39169. (Used by progress bars in AlertWindow).
  39170. */
  39171. virtual void drawProgressBar (Graphics& g, ProgressBar& progressBar,
  39172. int width, int height,
  39173. double progress, const String& textToShow);
  39174. /** Draws one of the buttons on a scrollbar.
  39175. @param g the context to draw into
  39176. @param scrollbar the bar itself
  39177. @param width the width of the button
  39178. @param height the height of the button
  39179. @param buttonDirection the direction of the button, where 0 = up, 1 = right, 2 = down, 3 = left
  39180. @param isScrollbarVertical true if it's a vertical bar, false if horizontal
  39181. @param isMouseOverButton whether the mouse is currently over the button (also true if it's held down)
  39182. @param isButtonDown whether the mouse button's held down
  39183. */
  39184. virtual void drawScrollbarButton (Graphics& g,
  39185. ScrollBar& scrollbar,
  39186. int width, int height,
  39187. int buttonDirection,
  39188. bool isScrollbarVertical,
  39189. bool isMouseOverButton,
  39190. bool isButtonDown);
  39191. /** Draws the thumb area of a scrollbar.
  39192. @param g the context to draw into
  39193. @param scrollbar the bar itself
  39194. @param x the x position of the left edge of the thumb area to draw in
  39195. @param y the y position of the top edge of the thumb area to draw in
  39196. @param width the width of the thumb area to draw in
  39197. @param height the height of the thumb area to draw in
  39198. @param isScrollbarVertical true if it's a vertical bar, false if horizontal
  39199. @param thumbStartPosition for vertical bars, the y co-ordinate of the top of the
  39200. thumb, or its x position for horizontal bars
  39201. @param thumbSize for vertical bars, the height of the thumb, or its width for
  39202. horizontal bars. This may be 0 if the thumb shouldn't be drawn.
  39203. @param isMouseOver whether the mouse is over the thumb area, also true if the mouse is
  39204. currently dragging the thumb
  39205. @param isMouseDown whether the mouse is currently dragging the scrollbar
  39206. */
  39207. virtual void drawScrollbar (Graphics& g,
  39208. ScrollBar& scrollbar,
  39209. int x, int y,
  39210. int width, int height,
  39211. bool isScrollbarVertical,
  39212. int thumbStartPosition,
  39213. int thumbSize,
  39214. bool isMouseOver,
  39215. bool isMouseDown);
  39216. /** Returns the component effect to use for a scrollbar */
  39217. virtual ImageEffectFilter* getScrollbarEffect();
  39218. /** Returns the minimum length in pixels to use for a scrollbar thumb. */
  39219. virtual int getMinimumScrollbarThumbSize (ScrollBar& scrollbar);
  39220. /** Returns the default thickness to use for a scrollbar. */
  39221. virtual int getDefaultScrollbarWidth();
  39222. /** Returns the length in pixels to use for a scrollbar button. */
  39223. virtual int getScrollbarButtonSize (ScrollBar& scrollbar);
  39224. /** Returns a tick shape for use in yes/no boxes, etc. */
  39225. virtual const Path getTickShape (const float height);
  39226. /** Returns a cross shape for use in yes/no boxes, etc. */
  39227. virtual const Path getCrossShape (const float height);
  39228. /** Draws the + or - box in a treeview. */
  39229. virtual void drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus);
  39230. virtual void fillTextEditorBackground (Graphics& g, int width, int height, TextEditor& textEditor);
  39231. virtual void drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor);
  39232. // these return an image from the ImageCache, so use ImageCache::release() to free it
  39233. virtual Image* getDefaultFolderImage();
  39234. virtual Image* getDefaultDocumentFileImage();
  39235. virtual void createFileChooserHeaderText (const String& title,
  39236. const String& instructions,
  39237. GlyphArrangement& destArrangement,
  39238. int width);
  39239. virtual void drawFileBrowserRow (Graphics& g, int width, int height,
  39240. const String& filename, Image* icon,
  39241. const String& fileSizeDescription,
  39242. const String& fileTimeDescription,
  39243. const bool isDirectory,
  39244. const bool isItemSelected,
  39245. const int itemIndex);
  39246. virtual Button* createFileBrowserGoUpButton();
  39247. virtual void layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  39248. DirectoryContentsDisplayComponent* fileListComponent,
  39249. FilePreviewComponent* previewComp,
  39250. ComboBox* currentPathBox,
  39251. TextEditor* filenameBox,
  39252. Button* goUpButton);
  39253. virtual void drawBubble (Graphics& g,
  39254. float tipX, float tipY,
  39255. float boxX, float boxY, float boxW, float boxH);
  39256. /** Fills the background of a popup menu component. */
  39257. virtual void drawPopupMenuBackground (Graphics& g, int width, int height);
  39258. /** Draws one of the items in a popup menu. */
  39259. virtual void drawPopupMenuItem (Graphics& g,
  39260. int width, int height,
  39261. const bool isSeparator,
  39262. const bool isActive,
  39263. const bool isHighlighted,
  39264. const bool isTicked,
  39265. const bool hasSubMenu,
  39266. const String& text,
  39267. const String& shortcutKeyText,
  39268. Image* image,
  39269. const Colour* const textColour);
  39270. /** Returns the size and style of font to use in popup menus. */
  39271. virtual const Font getPopupMenuFont();
  39272. virtual void drawPopupMenuUpDownArrow (Graphics& g,
  39273. int width, int height,
  39274. bool isScrollUpArrow);
  39275. /** Finds the best size for an item in a popup menu. */
  39276. virtual void getIdealPopupMenuItemSize (const String& text,
  39277. const bool isSeparator,
  39278. int standardMenuItemHeight,
  39279. int& idealWidth,
  39280. int& idealHeight);
  39281. virtual int getMenuWindowFlags();
  39282. virtual void drawMenuBarBackground (Graphics& g, int width, int height,
  39283. bool isMouseOverBar,
  39284. MenuBarComponent& menuBar);
  39285. virtual int getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText);
  39286. virtual const Font getMenuBarFont (MenuBarComponent& menuBar, int itemIndex, const String& itemText);
  39287. virtual void drawMenuBarItem (Graphics& g,
  39288. int width, int height,
  39289. int itemIndex,
  39290. const String& itemText,
  39291. bool isMouseOverItem,
  39292. bool isMenuOpen,
  39293. bool isMouseOverBar,
  39294. MenuBarComponent& menuBar);
  39295. virtual void drawComboBox (Graphics& g, int width, int height,
  39296. const bool isButtonDown,
  39297. int buttonX, int buttonY,
  39298. int buttonW, int buttonH,
  39299. ComboBox& box);
  39300. virtual const Font getComboBoxFont (ComboBox& box);
  39301. virtual Label* createComboBoxTextBox (ComboBox& box);
  39302. virtual void positionComboBoxText (ComboBox& box, Label& labelToPosition);
  39303. virtual void drawLinearSlider (Graphics& g,
  39304. int x, int y,
  39305. int width, int height,
  39306. float sliderPos,
  39307. float minSliderPos,
  39308. float maxSliderPos,
  39309. const Slider::SliderStyle style,
  39310. Slider& slider);
  39311. virtual void drawLinearSliderBackground (Graphics& g,
  39312. int x, int y,
  39313. int width, int height,
  39314. float sliderPos,
  39315. float minSliderPos,
  39316. float maxSliderPos,
  39317. const Slider::SliderStyle style,
  39318. Slider& slider);
  39319. virtual void drawLinearSliderThumb (Graphics& g,
  39320. int x, int y,
  39321. int width, int height,
  39322. float sliderPos,
  39323. float minSliderPos,
  39324. float maxSliderPos,
  39325. const Slider::SliderStyle style,
  39326. Slider& slider);
  39327. virtual int getSliderThumbRadius (Slider& slider);
  39328. virtual void drawRotarySlider (Graphics& g,
  39329. int x, int y,
  39330. int width, int height,
  39331. float sliderPosProportional,
  39332. const float rotaryStartAngle,
  39333. const float rotaryEndAngle,
  39334. Slider& slider);
  39335. virtual Button* createSliderButton (const bool isIncrement);
  39336. virtual Label* createSliderTextBox (Slider& slider);
  39337. virtual ImageEffectFilter* getSliderEffect();
  39338. virtual void getTooltipSize (const String& tipText, int& width, int& height);
  39339. virtual void drawTooltip (Graphics& g, const String& text, int width, int height);
  39340. virtual Button* createFilenameComponentBrowseButton (const String& text);
  39341. virtual void layoutFilenameComponent (FilenameComponent& filenameComp,
  39342. ComboBox* filenameBox, Button* browseButton);
  39343. virtual void drawCornerResizer (Graphics& g,
  39344. int w, int h,
  39345. bool isMouseOver,
  39346. bool isMouseDragging);
  39347. virtual void drawResizableFrame (Graphics& g,
  39348. int w, int h,
  39349. const BorderSize& borders);
  39350. virtual void drawResizableWindowBorder (Graphics& g,
  39351. int w, int h,
  39352. const BorderSize& border,
  39353. ResizableWindow& window);
  39354. virtual void drawDocumentWindowTitleBar (DocumentWindow& window,
  39355. Graphics& g, int w, int h,
  39356. int titleSpaceX, int titleSpaceW,
  39357. const Image* icon,
  39358. bool drawTitleTextOnLeft);
  39359. virtual Button* createDocumentWindowButton (int buttonType);
  39360. virtual void positionDocumentWindowButtons (DocumentWindow& window,
  39361. int titleBarX, int titleBarY,
  39362. int titleBarW, int titleBarH,
  39363. Button* minimiseButton,
  39364. Button* maximiseButton,
  39365. Button* closeButton,
  39366. bool positionTitleBarButtonsOnLeft);
  39367. virtual int getDefaultMenuBarHeight();
  39368. virtual DropShadower* createDropShadowerForComponent (Component* component);
  39369. virtual void drawStretchableLayoutResizerBar (Graphics& g,
  39370. int w, int h,
  39371. bool isVerticalBar,
  39372. bool isMouseOver,
  39373. bool isMouseDragging);
  39374. virtual void drawGroupComponentOutline (Graphics& g, int w, int h,
  39375. const String& text,
  39376. const Justification& position,
  39377. GroupComponent& group);
  39378. virtual void createTabButtonShape (Path& p,
  39379. int width, int height,
  39380. int tabIndex,
  39381. const String& text,
  39382. Button& button,
  39383. TabbedButtonBar::Orientation orientation,
  39384. const bool isMouseOver,
  39385. const bool isMouseDown,
  39386. const bool isFrontTab);
  39387. virtual void fillTabButtonShape (Graphics& g,
  39388. const Path& path,
  39389. const Colour& preferredBackgroundColour,
  39390. int tabIndex,
  39391. const String& text,
  39392. Button& button,
  39393. TabbedButtonBar::Orientation orientation,
  39394. const bool isMouseOver,
  39395. const bool isMouseDown,
  39396. const bool isFrontTab);
  39397. virtual void drawTabButtonText (Graphics& g,
  39398. int x, int y, int w, int h,
  39399. const Colour& preferredBackgroundColour,
  39400. int tabIndex,
  39401. const String& text,
  39402. Button& button,
  39403. TabbedButtonBar::Orientation orientation,
  39404. const bool isMouseOver,
  39405. const bool isMouseDown,
  39406. const bool isFrontTab);
  39407. virtual int getTabButtonOverlap (int tabDepth);
  39408. virtual int getTabButtonSpaceAroundImage();
  39409. virtual int getTabButtonBestWidth (int tabIndex,
  39410. const String& text,
  39411. int tabDepth,
  39412. Button& button);
  39413. virtual void drawTabButton (Graphics& g,
  39414. int w, int h,
  39415. const Colour& preferredColour,
  39416. int tabIndex,
  39417. const String& text,
  39418. Button& button,
  39419. TabbedButtonBar::Orientation orientation,
  39420. const bool isMouseOver,
  39421. const bool isMouseDown,
  39422. const bool isFrontTab);
  39423. virtual void drawTabAreaBehindFrontButton (Graphics& g,
  39424. int w, int h,
  39425. TabbedButtonBar& tabBar,
  39426. TabbedButtonBar::Orientation orientation);
  39427. virtual Button* createTabBarExtrasButton();
  39428. virtual void drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header);
  39429. virtual void drawTableHeaderColumn (Graphics& g, const String& columnName, int columnId,
  39430. int width, int height,
  39431. bool isMouseOver, bool isMouseDown,
  39432. int columnFlags);
  39433. virtual void paintToolbarBackground (Graphics& g, int width, int height, Toolbar& toolbar);
  39434. virtual Button* createToolbarMissingItemsButton (Toolbar& toolbar);
  39435. virtual void paintToolbarButtonBackground (Graphics& g, int width, int height,
  39436. bool isMouseOver, bool isMouseDown,
  39437. ToolbarItemComponent& component);
  39438. virtual void paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  39439. const String& text, ToolbarItemComponent& component);
  39440. virtual void drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  39441. bool isOpen, int width, int height);
  39442. virtual void drawPropertyComponentBackground (Graphics& g, int width, int height,
  39443. PropertyComponent& component);
  39444. virtual void drawPropertyComponentLabel (Graphics& g, int width, int height,
  39445. PropertyComponent& component);
  39446. virtual const Rectangle getPropertyComponentContentPosition (PropertyComponent& component);
  39447. virtual void drawLevelMeter (Graphics& g, int width, int height, float level);
  39448. /**
  39449. */
  39450. virtual void playAlertSound();
  39451. /** Utility function to draw a shiny, glassy circle (for round LED-type buttons). */
  39452. static void drawGlassSphere (Graphics& g,
  39453. const float x, const float y,
  39454. const float diameter,
  39455. const Colour& colour,
  39456. const float outlineThickness) throw();
  39457. static void drawGlassPointer (Graphics& g,
  39458. const float x, const float y,
  39459. const float diameter,
  39460. const Colour& colour, const float outlineThickness,
  39461. const int direction) throw();
  39462. /** Utility function to draw a shiny, glassy oblong (for text buttons). */
  39463. static void drawGlassLozenge (Graphics& g,
  39464. const float x, const float y,
  39465. const float width, const float height,
  39466. const Colour& colour,
  39467. const float outlineThickness,
  39468. const float cornerSize,
  39469. const bool flatOnLeft, const bool flatOnRight,
  39470. const bool flatOnTop, const bool flatOnBottom) throw();
  39471. juce_UseDebuggingNewOperator
  39472. protected:
  39473. // xxx the following methods are only here to cause a compiler error, because they've been
  39474. // deprecated or their parameters have changed. Hopefully these definitions should cause an
  39475. // error if you try to build a subclass with the old versions.
  39476. virtual int drawTickBox (Graphics&, int, int, int, int, bool, const bool, const bool, const bool) { return 0; }
  39477. virtual int drawProgressBar (Graphics&, int, int, int, int, float) { return 0; }
  39478. virtual int drawProgressBar (Graphics&, ProgressBar&, int, int, int, int, float) { return 0; }
  39479. virtual void getTabButtonBestWidth (int, const String&, int) {}
  39480. private:
  39481. friend void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI();
  39482. static void clearDefaultLookAndFeel() throw(); // called at shutdown
  39483. Array <int> colourIds;
  39484. Array <Colour> colours;
  39485. void drawShinyButtonShape (Graphics& g,
  39486. float x, float y, float w, float h, float maxCornerSize,
  39487. const Colour& baseColour,
  39488. const float strokeWidth,
  39489. const bool flatOnLeft,
  39490. const bool flatOnRight,
  39491. const bool flatOnTop,
  39492. const bool flatOnBottom) throw();
  39493. LookAndFeel (const LookAndFeel&);
  39494. const LookAndFeel& operator= (const LookAndFeel&);
  39495. };
  39496. #endif // __JUCE_LOOKANDFEEL_JUCEHEADER__
  39497. /********* End of inlined file: juce_LookAndFeel.h *********/
  39498. #endif
  39499. #ifndef __JUCE_OLDSCHOOLLOOKANDFEEL_JUCEHEADER__
  39500. /********* Start of inlined file: juce_OldSchoolLookAndFeel.h *********/
  39501. #ifndef __JUCE_OLDSCHOOLLOOKANDFEEL_JUCEHEADER__
  39502. #define __JUCE_OLDSCHOOLLOOKANDFEEL_JUCEHEADER__
  39503. /**
  39504. The original Juce look-and-feel.
  39505. */
  39506. class JUCE_API OldSchoolLookAndFeel : public LookAndFeel
  39507. {
  39508. public:
  39509. /** Creates the default JUCE look and feel. */
  39510. OldSchoolLookAndFeel();
  39511. /** Destructor. */
  39512. virtual ~OldSchoolLookAndFeel();
  39513. /** Draws the lozenge-shaped background for a standard button. */
  39514. virtual void drawButtonBackground (Graphics& g,
  39515. Button& button,
  39516. const Colour& backgroundColour,
  39517. bool isMouseOverButton,
  39518. bool isButtonDown);
  39519. /** Draws the contents of a standard ToggleButton. */
  39520. virtual void drawToggleButton (Graphics& g,
  39521. ToggleButton& button,
  39522. bool isMouseOverButton,
  39523. bool isButtonDown);
  39524. virtual void drawTickBox (Graphics& g,
  39525. Component& component,
  39526. int x, int y, int w, int h,
  39527. const bool ticked,
  39528. const bool isEnabled,
  39529. const bool isMouseOverButton,
  39530. const bool isButtonDown);
  39531. virtual void drawProgressBar (Graphics& g, ProgressBar& progressBar,
  39532. int width, int height,
  39533. double progress, const String& textToShow);
  39534. virtual void drawScrollbarButton (Graphics& g,
  39535. ScrollBar& scrollbar,
  39536. int width, int height,
  39537. int buttonDirection,
  39538. bool isScrollbarVertical,
  39539. bool isMouseOverButton,
  39540. bool isButtonDown);
  39541. virtual void drawScrollbar (Graphics& g,
  39542. ScrollBar& scrollbar,
  39543. int x, int y,
  39544. int width, int height,
  39545. bool isScrollbarVertical,
  39546. int thumbStartPosition,
  39547. int thumbSize,
  39548. bool isMouseOver,
  39549. bool isMouseDown);
  39550. virtual ImageEffectFilter* getScrollbarEffect();
  39551. virtual void drawTextEditorOutline (Graphics& g,
  39552. int width, int height,
  39553. TextEditor& textEditor);
  39554. /** Fills the background of a popup menu component. */
  39555. virtual void drawPopupMenuBackground (Graphics& g, int width, int height);
  39556. virtual void drawMenuBarBackground (Graphics& g, int width, int height,
  39557. bool isMouseOverBar,
  39558. MenuBarComponent& menuBar);
  39559. virtual void drawComboBox (Graphics& g, int width, int height,
  39560. const bool isButtonDown,
  39561. int buttonX, int buttonY,
  39562. int buttonW, int buttonH,
  39563. ComboBox& box);
  39564. virtual const Font getComboBoxFont (ComboBox& box);
  39565. virtual void drawLinearSlider (Graphics& g,
  39566. int x, int y,
  39567. int width, int height,
  39568. float sliderPos,
  39569. float minSliderPos,
  39570. float maxSliderPos,
  39571. const Slider::SliderStyle style,
  39572. Slider& slider);
  39573. virtual int getSliderThumbRadius (Slider& slider);
  39574. virtual Button* createSliderButton (const bool isIncrement);
  39575. virtual ImageEffectFilter* getSliderEffect();
  39576. virtual void drawCornerResizer (Graphics& g,
  39577. int w, int h,
  39578. bool isMouseOver,
  39579. bool isMouseDragging);
  39580. virtual Button* createDocumentWindowButton (int buttonType);
  39581. virtual void positionDocumentWindowButtons (DocumentWindow& window,
  39582. int titleBarX, int titleBarY,
  39583. int titleBarW, int titleBarH,
  39584. Button* minimiseButton,
  39585. Button* maximiseButton,
  39586. Button* closeButton,
  39587. bool positionTitleBarButtonsOnLeft);
  39588. juce_UseDebuggingNewOperator
  39589. private:
  39590. DropShadowEffect scrollbarShadow;
  39591. OldSchoolLookAndFeel (const OldSchoolLookAndFeel&);
  39592. const OldSchoolLookAndFeel& operator= (const OldSchoolLookAndFeel&);
  39593. };
  39594. #endif // __JUCE_OLDSCHOOLLOOKANDFEEL_JUCEHEADER__
  39595. /********* End of inlined file: juce_OldSchoolLookAndFeel.h *********/
  39596. #endif
  39597. #ifndef __JUCE_FILEBASEDDOCUMENT_JUCEHEADER__
  39598. /********* Start of inlined file: juce_FileBasedDocument.h *********/
  39599. #ifndef __JUCE_FILEBASEDDOCUMENT_JUCEHEADER__
  39600. #define __JUCE_FILEBASEDDOCUMENT_JUCEHEADER__
  39601. /**
  39602. A class to take care of the logic involved with the loading/saving of some kind
  39603. of document.
  39604. There's quite a lot of tedious logic involved in writing all the load/save/save-as
  39605. functions you need for documents that get saved to a file, so this class attempts
  39606. to abstract most of the boring stuff.
  39607. Your subclass should just implement all the pure virtual methods, and you can
  39608. then use the higher-level public methods to do the load/save dialogs, to warn the user
  39609. about overwriting files, etc.
  39610. The document object keeps track of whether it has changed since it was last saved or
  39611. loaded, so when you change something, call its changed() method. This will set a
  39612. flag so it knows it needs saving, and will also broadcast a change message using the
  39613. ChangeBroadcaster base class.
  39614. @see ChangeBroadcaster
  39615. */
  39616. class JUCE_API FileBasedDocument : public ChangeBroadcaster
  39617. {
  39618. public:
  39619. /** Creates a FileBasedDocument.
  39620. @param fileExtension the extension to use when loading/saving files, e.g. ".doc"
  39621. @param fileWildCard the wildcard to use in file dialogs, e.g. "*.doc"
  39622. @param openFileDialogTitle the title to show on an open-file dialog, e.g. "Choose a file to open.."
  39623. @param saveFileDialogTitle the title to show on an save-file dialog, e.g. "Choose a file to save as.."
  39624. */
  39625. FileBasedDocument (const String& fileExtension,
  39626. const String& fileWildCard,
  39627. const String& openFileDialogTitle,
  39628. const String& saveFileDialogTitle);
  39629. /** Destructor. */
  39630. virtual ~FileBasedDocument();
  39631. /** Returns true if the changed() method has been called since the file was
  39632. last saved or loaded.
  39633. @see resetChangedFlag, changed
  39634. */
  39635. bool hasChangedSinceSaved() const throw() { return changedSinceSave; }
  39636. /** Called to indicate that the document has changed and needs saving.
  39637. This method will also trigger a change message to be sent out using the
  39638. ChangeBroadcaster base class.
  39639. After calling the method, the hasChangedSinceSaved() method will return true, until
  39640. it is reset either by saving to a file or using the resetChangedFlag() method.
  39641. @see hasChangedSinceSaved, resetChangedFlag
  39642. */
  39643. virtual void changed();
  39644. /** Sets the state of the 'changed' flag.
  39645. The 'changed' flag is set to true when the changed() method is called - use this method
  39646. to reset it or to set it without also broadcasting a change message.
  39647. @see changed, hasChangedSinceSaved
  39648. */
  39649. void setChangedFlag (const bool hasChanged);
  39650. /** Tries to open a file.
  39651. If the file opens correctly, the document's file (see the getFile() method) is set
  39652. to this new one; if it fails, the document's file is left unchanged, and optionally
  39653. a message box is shown telling the user there was an error.
  39654. @returns true if the new file loaded successfully
  39655. @see loadDocument, loadFromUserSpecifiedFile
  39656. */
  39657. bool loadFrom (const File& fileToLoadFrom,
  39658. const bool showMessageOnFailure);
  39659. /** Asks the user for a file and tries to load it.
  39660. This will pop up a dialog box using the title, file extension and
  39661. wildcard specified in the document's constructor, and asks the user
  39662. for a file. If they pick one, the loadFrom() method is used to
  39663. try to load it, optionally showing a message if it fails.
  39664. @returns true if a file was loaded; false if the user cancelled or if they
  39665. picked a file which failed to load correctly
  39666. @see loadFrom
  39667. */
  39668. bool loadFromUserSpecifiedFile (const bool showMessageOnFailure);
  39669. /** A set of possible outcomes of one of the save() methods
  39670. */
  39671. enum SaveResult
  39672. {
  39673. savedOk = 0, /**< indicates that a file was saved successfully. */
  39674. userCancelledSave, /**< indicates that the user aborted the save operation. */
  39675. failedToWriteToFile /**< indicates that it tried to write to a file but this failed. */
  39676. };
  39677. /** Tries to save the document to the last file it was saved or loaded from.
  39678. This will always try to write to the file, even if the document isn't flagged as
  39679. having changed.
  39680. @param askUserForFileIfNotSpecified if there's no file currently specified and this is
  39681. true, it will prompt the user to pick a file, as if
  39682. saveAsInteractive() was called.
  39683. @param showMessageOnFailure if true it will show a warning message when if the
  39684. save operation fails
  39685. @see saveIfNeededAndUserAgrees, saveAs, saveAsInteractive
  39686. */
  39687. SaveResult save (const bool askUserForFileIfNotSpecified,
  39688. const bool showMessageOnFailure);
  39689. /** If the file needs saving, it'll ask the user if that's what they want to do, and save
  39690. it if they say yes.
  39691. If you've got a document open and want to close it (e.g. to quit the app), this is the
  39692. method to call.
  39693. If the document doesn't need saving it'll return the value savedOk so
  39694. you can go ahead and delete the document.
  39695. If it does need saving it'll prompt the user, and if they say "discard changes" it'll
  39696. return savedOk, so again, you can safely delete the document.
  39697. If the user clicks "cancel", it'll return userCancelledSave, so if you can abort the
  39698. close-document operation.
  39699. And if they click "save changes", it'll try to save and either return savedOk, or
  39700. failedToWriteToFile if there was a problem.
  39701. @see save, saveAs, saveAsInteractive
  39702. */
  39703. SaveResult saveIfNeededAndUserAgrees();
  39704. /** Tries to save the document to a specified file.
  39705. If this succeeds, it'll also change the document's internal file (as returned by
  39706. the getFile() method). If it fails, the file will be left unchanged.
  39707. @param newFile the file to try to write to
  39708. @param warnAboutOverwritingExistingFiles if true and the file exists, it'll ask
  39709. the user first if they want to overwrite it
  39710. @param askUserForFileIfNotSpecified if the file is non-existent and this is true, it'll
  39711. use the saveAsInteractive() method to ask the user for a
  39712. filename
  39713. @param showMessageOnFailure if true and the write operation fails, it'll show
  39714. a message box to warn the user
  39715. @see saveIfNeededAndUserAgrees, save, saveAsInteractive
  39716. */
  39717. SaveResult saveAs (const File& newFile,
  39718. const bool warnAboutOverwritingExistingFiles,
  39719. const bool askUserForFileIfNotSpecified,
  39720. const bool showMessageOnFailure);
  39721. /** Prompts the user for a filename and tries to save to it.
  39722. This will pop up a dialog box using the title, file extension and
  39723. wildcard specified in the document's constructor, and asks the user
  39724. for a file. If they pick one, the saveAs() method is used to try to save
  39725. to this file.
  39726. @param warnAboutOverwritingExistingFiles if true and the file exists, it'll ask
  39727. the user first if they want to overwrite it
  39728. @see saveIfNeededAndUserAgrees, save, saveAs
  39729. */
  39730. SaveResult saveAsInteractive (const bool warnAboutOverwritingExistingFiles);
  39731. /** Returns the file that this document was last successfully saved or loaded from.
  39732. When the document object is created, this will be set to File::nonexistent.
  39733. It is changed when one of the load or save methods is used, or when setFile()
  39734. is used to explicitly set it.
  39735. */
  39736. const File getFile() const throw() { return documentFile; }
  39737. /** Sets the file that this document thinks it was loaded from.
  39738. This won't actually load anything - it just changes the file stored internally.
  39739. @see getFile
  39740. */
  39741. void setFile (const File& newFile);
  39742. protected:
  39743. /** Overload this to return the title of the document.
  39744. This is used in message boxes, filenames and file choosers, so it should be
  39745. something sensible.
  39746. */
  39747. virtual const String getDocumentTitle() = 0;
  39748. /** This method should try to load your document from the given file.
  39749. If it fails, it should return an error message. If it succeeds, it should return
  39750. an empty string.
  39751. */
  39752. virtual const String loadDocument (const File& file) = 0;
  39753. /** This method should try to write your document to the given file.
  39754. If it fails, it should return an error message. If it succeeds, it should return
  39755. an empty string.
  39756. */
  39757. virtual const String saveDocument (const File& file) = 0;
  39758. /** This is used for dialog boxes to make them open at the last folder you
  39759. were using.
  39760. getLastDocumentOpened() and setLastDocumentOpened() are used to store
  39761. the last document that was used - you might want to store this value
  39762. in a static variable, or even in your application's properties. It should
  39763. be a global setting rather than a property of this object.
  39764. This method works very well in conjunction with a RecentlyOpenedFilesList
  39765. object to manage your recent-files list.
  39766. As a default value, it's ok to return File::nonexistent, and the document
  39767. object will use a sensible one instead.
  39768. @see RecentlyOpenedFilesList
  39769. */
  39770. virtual const File getLastDocumentOpened() = 0;
  39771. /** This is used for dialog boxes to make them open at the last folder you
  39772. were using.
  39773. getLastDocumentOpened() and setLastDocumentOpened() are used to store
  39774. the last document that was used - you might want to store this value
  39775. in a static variable, or even in your application's properties. It should
  39776. be a global setting rather than a property of this object.
  39777. This method works very well in conjunction with a RecentlyOpenedFilesList
  39778. object to manage your recent-files list.
  39779. @see RecentlyOpenedFilesList
  39780. */
  39781. virtual void setLastDocumentOpened (const File& file) = 0;
  39782. public:
  39783. juce_UseDebuggingNewOperator
  39784. private:
  39785. File documentFile;
  39786. bool changedSinceSave;
  39787. String fileExtension, fileWildcard, openFileDialogTitle, saveFileDialogTitle;
  39788. FileBasedDocument (const FileBasedDocument&);
  39789. const FileBasedDocument& operator= (const FileBasedDocument&);
  39790. };
  39791. #endif // __JUCE_FILEBASEDDOCUMENT_JUCEHEADER__
  39792. /********* End of inlined file: juce_FileBasedDocument.h *********/
  39793. #endif
  39794. #ifndef __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__
  39795. /********* Start of inlined file: juce_RecentlyOpenedFilesList.h *********/
  39796. #ifndef __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__
  39797. #define __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__
  39798. /**
  39799. Manages a set of files for use as a list of recently-opened documents.
  39800. This is a handy class for holding your list of recently-opened documents, with
  39801. helpful methods for things like purging any non-existent files, automatically
  39802. adding them to a menu, and making persistence easy.
  39803. @see File, FileBasedDocument
  39804. */
  39805. class JUCE_API RecentlyOpenedFilesList
  39806. {
  39807. public:
  39808. /** Creates an empty list.
  39809. */
  39810. RecentlyOpenedFilesList();
  39811. /** Destructor. */
  39812. ~RecentlyOpenedFilesList();
  39813. /** Sets a limit for the number of files that will be stored in the list.
  39814. When addFile() is called, then if there is no more space in the list, the
  39815. least-recently added file will be dropped.
  39816. @see getMaxNumberOfItems
  39817. */
  39818. void setMaxNumberOfItems (const int newMaxNumber);
  39819. /** Returns the number of items that this list will store.
  39820. @see setMaxNumberOfItems
  39821. */
  39822. int getMaxNumberOfItems() const throw() { return maxNumberOfItems; }
  39823. /** Returns the number of files in the list.
  39824. The most recently added file is always at index 0.
  39825. */
  39826. int getNumFiles() const;
  39827. /** Returns one of the files in the list.
  39828. The most recently added file is always at index 0.
  39829. */
  39830. const File getFile (const int index) const;
  39831. /** Returns an array of all the absolute pathnames in the list.
  39832. */
  39833. const StringArray& getAllFilenames() const throw() { return files; }
  39834. /** Clears all the files from the list. */
  39835. void clear();
  39836. /** Adds a file to the list.
  39837. The file will be added at index 0. If this file is already in the list, it will
  39838. be moved up to index 0, but a file can only appear once in the list.
  39839. If the list already contains the maximum number of items that is permitted, the
  39840. least-recently added file will be dropped from the end.
  39841. */
  39842. void addFile (const File& file);
  39843. /** Checks each of the files in the list, removing any that don't exist.
  39844. You might want to call this after reloading a list of files, or before putting them
  39845. on a menu.
  39846. */
  39847. void removeNonExistentFiles();
  39848. /** Adds entries to a menu, representing each of the files in the list.
  39849. This is handy for creating an "open recent file..." menu in your app. The
  39850. menu items are numbered consecutively starting with the baseItemId value,
  39851. and can either be added as complete pathnames, or just the last part of the
  39852. filename.
  39853. If dontAddNonExistentFiles is true, then each file will be checked and only those
  39854. that exist will be added.
  39855. If filesToAvoid is non-zero, then it is considered to be a zero-terminated array of
  39856. pointers to file objects. Any files that appear in this list will not be added to the
  39857. menu - the reason for this is that you might have a number of files already open, so
  39858. might not want these to be shown in the menu.
  39859. It returns the number of items that were added.
  39860. */
  39861. int createPopupMenuItems (PopupMenu& menuToAddItemsTo,
  39862. const int baseItemId,
  39863. const bool showFullPaths,
  39864. const bool dontAddNonExistentFiles,
  39865. const File** filesToAvoid = 0);
  39866. /** Returns a string that encapsulates all the files in the list.
  39867. The string that is returned can later be passed into restoreFromString() in
  39868. order to recreate the list. This is handy for persisting your list, e.g. in
  39869. a PropertiesFile object.
  39870. @see restoreFromString
  39871. */
  39872. const String toString() const;
  39873. /** Restores the list from a previously stringified version of the list.
  39874. Pass in a stringified version created with toString() in order to persist/restore
  39875. your list.
  39876. @see toString
  39877. */
  39878. void restoreFromString (const String& stringifiedVersion);
  39879. juce_UseDebuggingNewOperator
  39880. private:
  39881. StringArray files;
  39882. int maxNumberOfItems;
  39883. };
  39884. #endif // __JUCE_RECENTLYOPENEDFILESLIST_JUCEHEADER__
  39885. /********* End of inlined file: juce_RecentlyOpenedFilesList.h *********/
  39886. #endif
  39887. #ifndef __JUCE_SELECTEDITEMSET_JUCEHEADER__
  39888. #endif
  39889. #ifndef __JUCE_UNDOABLEACTION_JUCEHEADER__
  39890. #endif
  39891. #ifndef __JUCE_UNDOMANAGER_JUCEHEADER__
  39892. #endif
  39893. #endif
  39894. /********* End of inlined file: juce_app_includes.h *********/
  39895. #endif
  39896. #if JUCE_MSVC
  39897. #pragma warning (pop)
  39898. #pragma pack (pop)
  39899. #endif
  39900. #if JUCE_MAC
  39901. #pragma align=reset
  39902. #endif
  39903. END_JUCE_NAMESPACE
  39904. #ifndef DONT_SET_USING_JUCE_NAMESPACE
  39905. #ifdef JUCE_NAMESPACE
  39906. // this will obviously save a lot of typing, but can be disabled by
  39907. // defining DONT_SET_USING_JUCE_NAMESPACE, in case there are conflicts.
  39908. using namespace JUCE_NAMESPACE;
  39909. /* On the Mac, these symbols are defined in the Mac libraries, so
  39910. these macros make it easier to reference them without writing out
  39911. the namespace every time.
  39912. If you run into difficulties where these macros interfere with the contents
  39913. of 3rd party header files, you may need to use the juce_WithoutMacros.h file - see
  39914. the comments in that file for more information.
  39915. */
  39916. #if JUCE_MAC && ! JUCE_DONT_DEFINE_MACROS
  39917. #define Component JUCE_NAMESPACE::Component
  39918. #define MemoryBlock JUCE_NAMESPACE::MemoryBlock
  39919. #define Point JUCE_NAMESPACE::Point
  39920. #define Button JUCE_NAMESPACE::Button
  39921. #endif
  39922. /* "Rectangle" is defined in some of the newer windows header files, so this makes
  39923. it easier to use the juce version explicitly.
  39924. If you run into difficulties where this macro interferes with other 3rd party header
  39925. files, you may need to use the juce_WithoutMacros.h file - see the comments in that
  39926. file for more information.
  39927. */
  39928. #if JUCE_WIN32 && ! JUCE_DONT_DEFINE_MACROS
  39929. #define Rectangle JUCE_NAMESPACE::Rectangle
  39930. #endif
  39931. #endif
  39932. #endif
  39933. /* Easy autolinking to the right JUCE libraries under win32.
  39934. Note that this can be disabled by defining DONT_AUTOLINK_TO_JUCE_LIBRARY before
  39935. including this header file.
  39936. */
  39937. #if JUCE_MSVC
  39938. #ifndef DONT_AUTOLINK_TO_JUCE_LIBRARY
  39939. /** If you want your application to link to Juce as a DLL instead of
  39940. a static library (on win32), just define the JUCE_DLL macro before
  39941. including juce.h
  39942. */
  39943. #ifdef JUCE_DLL
  39944. #ifdef JUCE_DEBUG
  39945. #define AUTOLINKEDLIB "JUCE_debug.lib"
  39946. #else
  39947. #define AUTOLINKEDLIB "JUCE.lib"
  39948. #endif
  39949. #else
  39950. #ifdef JUCE_DEBUG
  39951. #ifdef _WIN64
  39952. #define AUTOLINKEDLIB "jucelib_static_x64_debug.lib"
  39953. #else
  39954. #define AUTOLINKEDLIB "jucelib_static_Win32_debug.lib"
  39955. #endif
  39956. #else
  39957. #ifdef _WIN64
  39958. #define AUTOLINKEDLIB "jucelib_static_x64.lib"
  39959. #else
  39960. #define AUTOLINKEDLIB "jucelib_static_Win32.lib"
  39961. #endif
  39962. #endif
  39963. #endif
  39964. #pragma comment(lib, AUTOLINKEDLIB)
  39965. #if ! DONT_LIST_JUCE_AUTOLINKEDLIBS
  39966. #pragma message("JUCE! Library to link to: " AUTOLINKEDLIB)
  39967. #endif
  39968. // Auto-link the other win32 libs that are needed by library calls..
  39969. #if ! (defined (DONT_AUTOLINK_TO_WIN32_LIBRARIES) || defined (JUCE_DLL))
  39970. /********* Start of inlined file: juce_win32_AutoLinkLibraries.h *********/
  39971. // Auto-links to various win32 libs that are needed by library calls..
  39972. #pragma comment(lib, "kernel32.lib")
  39973. #pragma comment(lib, "user32.lib")
  39974. #pragma comment(lib, "shell32.lib")
  39975. #pragma comment(lib, "gdi32.lib")
  39976. #pragma comment(lib, "vfw32.lib")
  39977. #pragma comment(lib, "comdlg32.lib")
  39978. #pragma comment(lib, "winmm.lib")
  39979. #pragma comment(lib, "wininet.lib")
  39980. #pragma comment(lib, "ole32.lib")
  39981. #pragma comment(lib, "advapi32.lib")
  39982. #pragma comment(lib, "ws2_32.lib")
  39983. #pragma comment(lib, "comsupp.lib")
  39984. #if JUCE_OPENGL
  39985. #pragma comment(lib, "OpenGL32.Lib")
  39986. #pragma comment(lib, "GlU32.Lib")
  39987. #endif
  39988. #if JUCE_QUICKTIME
  39989. #pragma comment (lib, "QTMLClient.lib")
  39990. #endif
  39991. /********* End of inlined file: juce_win32_AutoLinkLibraries.h *********/
  39992. #endif
  39993. #endif
  39994. #endif
  39995. /*
  39996. To start a JUCE app, use this macro: START_JUCE_APPLICATION (AppSubClass) where
  39997. AppSubClass is the name of a class derived from JUCEApplication.
  39998. See the JUCEApplication class documentation (juce_Application.h) for more details.
  39999. */
  40000. #if defined (JUCE_GCC) || defined (__MWERKS__)
  40001. #define START_JUCE_APPLICATION(AppClass) \
  40002. int main (int argc, char* argv[]) \
  40003. { \
  40004. return JUCE_NAMESPACE::JUCEApplication::main (argc, argv, new AppClass()); \
  40005. }
  40006. #elif JUCE_WIN32
  40007. #ifdef _CONSOLE
  40008. #define START_JUCE_APPLICATION(AppClass) \
  40009. int main (int, char* argv[]) \
  40010. { \
  40011. JUCE_NAMESPACE::String commandLineString (JUCE_NAMESPACE::PlatformUtilities::getCurrentCommandLineParams()); \
  40012. return JUCE_NAMESPACE::JUCEApplication::main (commandLineString, new AppClass()); \
  40013. }
  40014. #elif ! defined (_AFXDLL)
  40015. #ifdef _WINDOWS_
  40016. #define START_JUCE_APPLICATION(AppClass) \
  40017. int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int) \
  40018. { \
  40019. JUCE_NAMESPACE::String commandLineString (JUCE_NAMESPACE::PlatformUtilities::getCurrentCommandLineParams()); \
  40020. return JUCE_NAMESPACE::JUCEApplication::main (commandLineString, new AppClass()); \
  40021. }
  40022. #else
  40023. #define START_JUCE_APPLICATION(AppClass) \
  40024. int __stdcall WinMain (int, int, const char*, int) \
  40025. { \
  40026. JUCE_NAMESPACE::String commandLineString (JUCE_NAMESPACE::PlatformUtilities::getCurrentCommandLineParams()); \
  40027. return JUCE_NAMESPACE::JUCEApplication::main (commandLineString, new AppClass()); \
  40028. }
  40029. #endif
  40030. #endif
  40031. #endif
  40032. #endif // __JUCE_JUCEHEADER__
  40033. /********* End of inlined file: juce.h *********/
  40034. #endif // __JUCE_AMALGAMATED_TEMPLATE_JUCEHEADER__