LMMS
Loading...
Searching...
No Matches
juce_mac_NSViewFrameWatcher.h
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
26#if JUCE_MAC
27
28namespace juce
29{
30
31JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wundeclared-selector")
32const auto nsViewFrameChangedSelector = @selector (frameChanged:);
34
35struct NSViewCallbackInterface
36{
37 virtual ~NSViewCallbackInterface() = default;
38 virtual void frameChanged() = 0;
39};
40
41//==============================================================================
42struct NSViewFrameChangeCallbackClass : public ObjCClass<NSObject>
43{
44 NSViewFrameChangeCallbackClass()
45 : ObjCClass ("JUCE_NSViewCallback_")
46 {
47 addIvar<NSViewCallbackInterface*> ("target");
48
49 addMethod (nsViewFrameChangedSelector, frameChanged);
50
51 registerClass();
52 }
53
54 static void setTarget (id self, NSViewCallbackInterface* c)
55 {
56 object_setInstanceVariable (self, "target", c);
57 }
58
59private:
60 static void frameChanged (id self, SEL, NSNotification*)
61 {
62 if (auto* target = getIvar<NSViewCallbackInterface*> (self, "target"))
63 target->frameChanged();
64 }
65
66 JUCE_DECLARE_NON_COPYABLE (NSViewFrameChangeCallbackClass)
67};
68
69//==============================================================================
70class NSViewFrameWatcher : private NSViewCallbackInterface
71{
72public:
73 NSViewFrameWatcher (NSView* viewToWatch, std::function<void()> viewResizedIn)
74 : viewResized (std::move (viewResizedIn)), callback (makeCallbackForView (viewToWatch))
75 {
76 }
77
78 ~NSViewFrameWatcher() override
79 {
80 [[NSNotificationCenter defaultCenter] removeObserver: callback];
81 [callback release];
82 callback = nil;
83 }
84
85 JUCE_DECLARE_NON_COPYABLE (NSViewFrameWatcher)
86 JUCE_DECLARE_NON_MOVEABLE (NSViewFrameWatcher)
87
88private:
89 id makeCallbackForView (NSView* view)
90 {
91 static NSViewFrameChangeCallbackClass cls;
92 auto* result = [cls.createInstance() init];
93 NSViewFrameChangeCallbackClass::setTarget (result, this);
94
95 [[NSNotificationCenter defaultCenter] addObserver: result
96 selector: nsViewFrameChangedSelector
97 name: NSViewFrameDidChangeNotification
98 object: view];
99
100 return result;
101 }
102
103 void frameChanged() override { viewResized(); }
104
105 std::function<void()> viewResized;
106 id callback;
107};
108
109} // namespace juce
110
111#endif
static const char * name
Definition pugl.h:1582
void * object
Definition jmemsys.h:50
#define JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE(...)
Definition juce_CompilerWarnings.h:181
#define JUCE_END_IGNORE_WARNINGS_GCC_LIKE
Definition juce_CompilerWarnings.h:182
#define JUCE_DECLARE_NON_MOVEABLE(className)
#define JUCE_DECLARE_NON_COPYABLE(className)
void move(void *from, void *to)
Definition juce_FixedSizeFunction.h:53
Definition carla_juce.cpp:31
RECT const char void(* callback)(const char *droppath))) SWELL_API_DEFINE(BOOL
Definition swell-functions.h:1004
return c
Definition crypt.c:175
ZCONST uch * init
Definition extract.c:2392
int result
Definition process.c:1455
#define void
Definition unzip.h:396
#define const
Definition zconf.h:137