1 /* 2 * DISTRHO Plugin Framework (DPF) 3 * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com> 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any purpose with 6 * or without fee is hereby granted, provided that the above copyright notice and this 7 * permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD 10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN 11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef DGL_WINDOW_HPP_INCLUDED 18 #define DGL_WINDOW_HPP_INCLUDED 19 20 #include "Geometry.hpp" 21 22 START_NAMESPACE_DISTRHO 23 class UIExporter; 24 END_NAMESPACE_DISTRHO 25 26 START_NAMESPACE_DGL 27 28 // ----------------------------------------------------------------------- 29 30 class Application; 31 class Widget; 32 class StandaloneWindow; 33 34 class Window 35 { 36 public: 37 #ifndef DGL_FILE_BROWSER_DISABLED 38 /** 39 File browser options. 40 */ 41 struct FileBrowserOptions { 42 const char* startDir; 43 const char* title; 44 uint width; 45 uint height; 46 47 /** 48 File browser buttons. 49 50 0 means hidden. 51 1 means visible and unchecked. 52 2 means visible and checked. 53 */ 54 struct Buttons { 55 uint listAllFiles; 56 uint showHidden; 57 uint showPlaces; 58 59 /** Constuctor for default values */ ButtonsWindow::FileBrowserOptions::Buttons60 Buttons() 61 : listAllFiles(2), 62 showHidden(1), 63 showPlaces(1) {} 64 } buttons; 65 66 /** Constuctor for default values */ FileBrowserOptionsWindow::FileBrowserOptions67 FileBrowserOptions() 68 : startDir(nullptr), 69 title(nullptr), 70 width(0), 71 height(0), 72 buttons() {} 73 }; 74 #endif // DGL_FILE_BROWSER_DISABLED 75 76 explicit Window(Application& app); 77 explicit Window(Application& app, Window& parent); 78 explicit Window(Application& app, intptr_t parentId); 79 virtual ~Window(); 80 81 void show(); 82 void hide(); 83 void close(); 84 void exec(bool lockWait = false); 85 86 void focus(); 87 void repaint() noexcept; 88 89 #ifndef DGL_FILE_BROWSER_DISABLED 90 bool openFileBrowser(const FileBrowserOptions& options); 91 #endif 92 93 bool isVisible() const noexcept; 94 void setVisible(bool yesNo); 95 96 bool isResizable() const noexcept; 97 void setResizable(bool yesNo); 98 99 uint getWidth() const noexcept; 100 uint getHeight() const noexcept; 101 Size<uint> getSize() const noexcept; 102 void setSize(uint width, uint height); 103 void setSize(Size<uint> size); 104 105 const char* getTitle() const noexcept; 106 void setTitle(const char* title); 107 108 void setTransientWinId(uintptr_t winId); 109 110 Application& getApp() const noexcept; 111 intptr_t getWindowId() const noexcept; 112 113 void addIdleCallback(IdleCallback* const callback); 114 void removeIdleCallback(IdleCallback* const callback); 115 116 protected: 117 virtual void onDisplayBefore(); 118 virtual void onDisplayAfter(); 119 virtual void onReshape(uint width, uint height); 120 virtual void onClose(); 121 122 #ifndef DGL_FILE_BROWSER_DISABLED 123 virtual void fileBrowserSelected(const char* filename); 124 #endif 125 126 private: 127 struct PrivateData; 128 PrivateData* const pData; 129 friend class Application; 130 friend class Widget; 131 friend class StandaloneWindow; 132 friend class DISTRHO_NAMESPACE::UIExporter; 133 134 virtual void _addWidget(Widget* const widget); 135 virtual void _removeWidget(Widget* const widget); 136 void _idle(); 137 138 bool handlePluginKeyboard(const bool press, const uint key); 139 bool handlePluginSpecial(const bool press, const Key key); 140 141 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window) 142 }; 143 144 // ----------------------------------------------------------------------- 145 146 END_NAMESPACE_DGL 147 148 #endif // DGL_WINDOW_HPP_INCLUDED 149