LMMS
Loading...
Searching...
No Matches
juce_DocumentWindow.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
31public:
33
34 void buttonClicked (Button* button) override
35 {
36 if (button == owner.getMinimiseButton()) owner.minimiseButtonPressed();
37 else if (button == owner.getMaximiseButton()) owner.maximiseButtonPressed();
38 else if (button == owner.getCloseButton()) owner.closeButtonPressed();
39 }
40
41private:
43
45};
46
47//==============================================================================
49 Colour backgroundColour,
50 int requiredButtons_,
51 bool addToDesktop_)
52 : ResizableWindow (title, backgroundColour, addToDesktop_),
53 requiredButtons (requiredButtons_),
54 #if JUCE_MAC
56 #else
58 #endif
59{
60 setResizeLimits (128, 128, 32768, 32768);
61
63}
64
66{
67 // Don't delete or remove the resizer components yourself! They're managed by the
68 // DocumentWindow, and you should leave them alone! You may have deleted them
69 // accidentally by careless use of deleteAllChildren()..?
70 jassert (menuBar == nullptr || getIndexOfChildComponent (menuBar.get()) >= 0);
71 jassert (titleBarButtons[0] == nullptr || getIndexOfChildComponent (titleBarButtons[0].get()) >= 0);
72 jassert (titleBarButtons[1] == nullptr || getIndexOfChildComponent (titleBarButtons[1].get()) >= 0);
73 jassert (titleBarButtons[2] == nullptr || getIndexOfChildComponent (titleBarButtons[2].get()) >= 0);
74
75 for (auto& b : titleBarButtons)
76 b.reset();
77
78 menuBar.reset();
79}
80
81//==============================================================================
86
87void DocumentWindow::setName (const String& newName)
88{
89 if (newName != getName())
90 {
91 Component::setName (newName);
93 }
94}
95
96void DocumentWindow::setIcon (const Image& imageToUse)
97{
98 titleBarIcon = imageToUse;
100}
101
102void DocumentWindow::setTitleBarHeight (const int newHeight)
103{
104 titleBarHeight = newHeight;
105 resized();
107}
108
109void DocumentWindow::setTitleBarButtonsRequired (const int buttons, const bool onLeft)
110{
111 requiredButtons = buttons;
114}
115
116void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
117{
118 drawTitleTextCentred = textShouldBeCentred;
120}
121
122//==============================================================================
123void DocumentWindow::setMenuBar (MenuBarModel* newMenuBarModel, const int newMenuBarHeight)
124{
125 if (menuBarModel != newMenuBarModel)
126 {
127 menuBar.reset();
128
129 menuBarModel = newMenuBarModel;
130 menuBarHeight = newMenuBarHeight > 0 ? newMenuBarHeight
131 : getLookAndFeel().getDefaultMenuBarHeight();
132
133 if (menuBarModel != nullptr)
135
136 resized();
137 }
138}
139
144
146{
147 menuBar.reset (newMenuBarComponent);
148 Component::addAndMakeVisible (menuBar.get()); // (call the superclass method directly to avoid the assertion in ResizableWindow)
149
150 if (menuBar != nullptr)
151 menuBar->setEnabled (isActiveWindow());
152
153 resized();
154}
155
156//==============================================================================
158{
159 /* If you've got a close button, you have to override this method to get
160 rid of your window!
161
162 If the window is just a pop-up, you should override this method and make
163 it delete the window in whatever way is appropriate for your app. E.g. you
164 might just want to call "delete this".
165
166 If your app is centred around this window such that the whole app should quit when
167 the window is closed, then you will probably want to use this method as an opportunity
168 to call JUCEApplicationBase::quit(), and leave the window to be deleted later by your
169 JUCEApplicationBase::shutdown() method. (Doing it this way means that your window will
170 still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
171 or closing it via the taskbar icon on Windows).
172 */
174}
175
180
185
186//==============================================================================
188{
190
191 auto titleBarArea = getTitleBarArea();
192 g.reduceClipRegion (titleBarArea);
193 g.setOrigin (titleBarArea.getPosition());
194
195 int titleSpaceX1 = 6;
196 int titleSpaceX2 = titleBarArea.getWidth() - 6;
197
198 for (auto& b : titleBarButtons)
199 {
200 if (b != nullptr)
201 {
203 titleSpaceX1 = jmax (titleSpaceX1, b->getRight() + (getWidth() - b->getRight()) / 8);
204 else
205 titleSpaceX2 = jmin (titleSpaceX2, b->getX() - (b->getX() / 8));
206 }
207 }
208
209 getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
210 titleBarArea.getWidth(),
211 titleBarArea.getHeight(),
212 titleSpaceX1,
213 jmax (1, titleSpaceX2 - titleSpaceX1),
214 titleBarIcon.isValid() ? &titleBarIcon : nullptr,
216}
217
219{
221
222 if (auto* b = getMaximiseButton())
223 b->setToggleState (isFullScreen(), dontSendNotification);
224
225 auto titleBarArea = getTitleBarArea();
226
228 .positionDocumentWindowButtons (*this,
229 titleBarArea.getX(), titleBarArea.getY(),
230 titleBarArea.getWidth(), titleBarArea.getHeight(),
231 titleBarButtons[0].get(),
232 titleBarButtons[1].get(),
233 titleBarButtons[2].get(),
235
236 if (menuBar != nullptr)
237 menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
238 titleBarArea.getWidth(), menuBarHeight);
239}
240
245
247{
248 auto border = getBorderThickness();
249
250 if (! isKioskMode())
251 border.setTop (border.getTop()
253 + (menuBar != nullptr ? menuBarHeight : 0));
254
255 return border;
256}
257
262
264{
265 if (isKioskMode())
266 return {};
267
268 auto border = getBorderThickness();
269 return { border.getLeft(), border.getTop(), getWidth() - border.getLeftAndRight(), getTitleBarHeight() };
270}
271
275
286
288{
289 for (auto& b : titleBarButtons)
290 b.reset();
291
292 if (! isUsingNativeTitleBar())
293 {
294 auto& lf = getLookAndFeel();
295
296 if ((requiredButtons & minimiseButton) != 0) titleBarButtons[0].reset (lf.createDocumentWindowButton (minimiseButton));
297 if ((requiredButtons & maximiseButton) != 0) titleBarButtons[1].reset (lf.createDocumentWindowButton (maximiseButton));
298 if ((requiredButtons & closeButton) != 0) titleBarButtons[2].reset (lf.createDocumentWindowButton (closeButton));
299
300 for (auto& b : titleBarButtons)
301 {
302 if (b != nullptr)
303 {
304 if (buttonListener == nullptr)
305 buttonListener.reset (new ButtonListenerProxy (*this));
306
307 b->addListener (buttonListener.get());
308 b->setWantsKeyboardFocus (false);
309
310 // (call the Component method directly to avoid the assertion in ResizableWindow)
312 }
313 }
314
315 if (auto* b = getCloseButton())
316 {
317 #if JUCE_MAC
318 b->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
319 #else
321 #endif
322 }
323 }
324
326
328}
329
334
336{
338 bool isActive = isActiveWindow();
339
340 for (auto& b : titleBarButtons)
341 if (b != nullptr)
342 b->setEnabled (isActive);
343
344 if (menuBar != nullptr)
345 menuBar->setEnabled (isActive);
346}
347
349{
350 if (getTitleBarArea().contains (e.x, e.y))
351 if (auto* maximise = getMaximiseButton())
352 maximise->triggerClick();
353}
354
359
360} // namespace juce
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_BorderSize.h:42
Definition juce_Button.h:189
Definition juce_Button.h:43
Definition juce_Colour.h:38
Definition juce_Component.h:36
bool contains(Point< int > localPoint)
Definition juce_Component.cpp:1434
int getIndexOfChildComponent(const Component *child) const noexcept
Definition juce_Component.cpp:1653
int getHeight() const noexcept
Definition juce_Component.h:274
void addAndMakeVisible(Component *child, int zOrder=-1)
Definition juce_Component.cpp:1554
void repaint()
Definition juce_Component.cpp:1917
virtual void setName(const String &newName)
Definition juce_Component.cpp:551
int getWidth() const noexcept
Definition juce_Component.h:271
LookAndFeel & getLookAndFeel() const noexcept
Definition juce_Component.cpp:2173
String getName() const noexcept
Definition juce_Component.h:76
@ windowHasMaximiseButton
Definition juce_ComponentPeer.h:62
@ windowHasCloseButton
Definition juce_ComponentPeer.h:64
@ windowHasMinimiseButton
Definition juce_ComponentPeer.h:60
Definition juce_DocumentWindow.cpp:30
ButtonListenerProxy(DocumentWindow &w)
Definition juce_DocumentWindow.cpp:32
DocumentWindow & owner
Definition juce_DocumentWindow.cpp:42
void buttonClicked(Button *button) override
Definition juce_DocumentWindow.cpp:34
int titleBarHeight
Definition juce_DocumentWindow.h:292
Rectangle< int > getTitleBarArea()
Definition juce_DocumentWindow.cpp:263
virtual void maximiseButtonPressed()
Definition juce_DocumentWindow.cpp:181
void parentHierarchyChanged() override
Definition juce_DocumentWindow.cpp:330
bool drawTitleTextCentred
Definition juce_DocumentWindow.h:293
Button * getCloseButton() const noexcept
Definition juce_DocumentWindow.cpp:272
int getDesktopWindowStyleFlags() const override
Definition juce_DocumentWindow.cpp:276
void activeWindowStatusChanged() override
Definition juce_DocumentWindow.cpp:335
Component * getMenuBarComponent() const noexcept
Definition juce_DocumentWindow.cpp:140
void paint(Graphics &) override
Definition juce_DocumentWindow.cpp:187
Image titleBarIcon
Definition juce_DocumentWindow.h:295
MenuBarModel * menuBarModel
Definition juce_DocumentWindow.h:297
std::unique_ptr< ButtonListenerProxy > buttonListener
Definition juce_DocumentWindow.h:300
DocumentWindow(const String &name, Colour backgroundColour, int requiredButtons, bool addToDesktop=true)
Definition juce_DocumentWindow.cpp:48
void repaintTitleBar()
Definition juce_DocumentWindow.cpp:82
BorderSize< int > getBorderThickness() override
Definition juce_DocumentWindow.cpp:241
@ closeButton
Definition juce_DocumentWindow.h:66
@ maximiseButton
Definition juce_DocumentWindow.h:65
@ minimiseButton
Definition juce_DocumentWindow.h:64
Button * getMaximiseButton() const noexcept
Definition juce_DocumentWindow.cpp:274
void setMenuBarComponent(Component *newMenuBarComponent)
Definition juce_DocumentWindow.cpp:145
~DocumentWindow() override
Definition juce_DocumentWindow.cpp:65
virtual void minimiseButtonPressed()
Definition juce_DocumentWindow.cpp:176
void setTitleBarTextCentred(bool textShouldBeCentred)
Definition juce_DocumentWindow.cpp:116
void setIcon(const Image &imageToUse)
Definition juce_DocumentWindow.cpp:96
bool positionTitleBarButtonsOnLeft
Definition juce_DocumentWindow.h:293
void setTitleBarHeight(int newHeight)
Definition juce_DocumentWindow.cpp:102
std::unique_ptr< Button > titleBarButtons[3]
Definition juce_DocumentWindow.h:294
Button * getMinimiseButton() const noexcept
Definition juce_DocumentWindow.cpp:273
virtual void closeButtonPressed()
Definition juce_DocumentWindow.cpp:157
void setMenuBar(MenuBarModel *menuBarModel, int menuBarHeight=0)
Definition juce_DocumentWindow.cpp:123
void setName(const String &newName) override
Definition juce_DocumentWindow.cpp:87
void setTitleBarButtonsRequired(int requiredButtons, bool positionTitleBarButtonsOnLeft)
Definition juce_DocumentWindow.cpp:109
void lookAndFeelChanged() override
Definition juce_DocumentWindow.cpp:287
void userTriedToCloseWindow() override
Definition juce_DocumentWindow.cpp:355
int getTitleBarHeight() const
Definition juce_DocumentWindow.cpp:258
int requiredButtons
Definition juce_DocumentWindow.h:292
std::unique_ptr< Component > menuBar
Definition juce_DocumentWindow.h:296
void mouseDoubleClick(const MouseEvent &) override
Definition juce_DocumentWindow.cpp:348
int menuBarHeight
Definition juce_DocumentWindow.h:292
BorderSize< int > getContentComponentBorder() override
Definition juce_DocumentWindow.cpp:246
void resized() override
Definition juce_DocumentWindow.cpp:218
Definition juce_GraphicsContext.h:45
Definition juce_Image.h:58
Definition juce_KeyPress.h:40
static const int F4Key
Definition juce_KeyPress.h:210
Definition juce_MenuBarComponent.h:40
Definition juce_MenuBarModel.h:42
@ commandModifier
Definition juce_ModifierKeys.h:147
@ altModifier
Definition juce_ModifierKeys.h:127
Definition juce_MouseEvent.h:39
Definition juce_Rectangle.h:67
void setFullScreen(bool shouldBeFullScreen)
Definition juce_ResizableWindow.cpp:406
void resized() override
Definition juce_ResizableWindow.cpp:178
int getDesktopWindowStyleFlags() const override
Definition juce_ResizableWindow.cpp:69
void setResizeLimits(int newMinimumWidth, int newMinimumHeight, int newMaximumWidth, int newMaximumHeight) noexcept
Definition juce_ResizableWindow.cpp:291
bool isKioskMode() const
Definition juce_ResizableWindow.cpp:466
void lookAndFeelChanged() override
Definition juce_ResizableWindow.cpp:366
void paint(Graphics &) override
Definition juce_ResizableWindow.cpp:339
virtual BorderSize< int > getBorderThickness()
Definition juce_ResizableWindow.cpp:154
bool isFullScreen() const
Definition juce_ResizableWindow.cpp:395
void activeWindowStatusChanged() override
Definition juce_ResizableWindow.cpp:233
ResizableWindow(const String &name, bool addToDesktop)
Definition juce_ResizableWindow.cpp:29
void setMinimised(bool shouldMinimise)
Definition juce_ResizableWindow.cpp:450
Definition juce_String.h:53
bool isUsingNativeTitleBar() const noexcept
Definition juce_TopLevelWindow.cpp:181
bool isActiveWindow() const noexcept
Definition juce_TopLevelWindow.h:77
* e
Definition inflate.c:1404
UINT_D64 w
Definition inflate.c:942
int g
Definition inflate.c:1573
static ZCONST unsigned border[]
Definition inflate.c:749
static const char * title
Definition pugl.h:1747
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
Definition carla_juce.cpp:31
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
@ dontSendNotification
Definition juce_NotificationType.h:33
@ button
Definition juce_AccessibilityRole.h:38
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
if(GLOBAL(newzip))
Definition crypt.c:475
b
Definition crypt.c:628
else
Definition fileio.c:764
#define const
Definition zconf.h:137