1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include "EventLoop.h"
#include "Interface.h"
#import <Cocoa/Cocoa.h>
// TODO: this probably should be a window *delegate*, so we don't need
// the NoficationCenter hack.
@interface CocoaEditorWindow : NSWindow {
vst::IWindow *owner_;
}
- (void)setOwner:(vst::IWindow *)owner;
- (BOOL)windowShouldClose:(id)sender;
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;
- (void)windowDidResize:(NSNotification *)notification;
- (void)windowDidMiniaturize:(NSNotification *)notification;
- (void)windowDidDeminiaturize:(NSNotification *)notification;
- (void)windowDidMove:(NSNotification *)notification;
- (BOOL)performKeyEquivalent:(NSEvent *)event;
- (void)updateEditor;
@end
// EventLoopProxy
namespace vst { namespace Cocoa {
class EventLoop;
}}
@interface EventLoopProxy : NSObject {
vst::Cocoa::EventLoop *owner_;
}
- (id)initWithOwner:(vst::Cocoa::EventLoop*)owner;
- (void)poll;
@end
namespace vst {
namespace Cocoa {
class EventLoop : public BaseEventLoop {
public:
static EventLoop& instance();
EventLoop();
~EventLoop();
bool callSync(UIThread::Callback cb, void *user);
bool callAsync(UIThread::Callback cb, void *user);
bool available() const {
return haveNSApp_;
}
using BaseEventLoop::doPoll; // make public
private:
void startPolling() override;
void stopPolling() override;
bool haveNSApp_ = false;
EventLoopProxy *proxy_ = nil;
NSTimer *timer_ = nil;
};
class Window : public IWindow {
public:
Window(IPlugin& plugin);
~Window();
void open() override;
void close() override;
void setPos(int x, int y) override;
void setSize(int w, int h) override;
void resize(int w, int h) override;
void doOpen();
void onClose();
void onResize(int w, int h);
void updateEditor();
private:
void *getHandle();
void updateFrame();
bool canResize() const;
CocoaEditorWindow * window_ = nullptr;
IPlugin *plugin_;
NSTimer *timer_;
Rect rect_{ 100, 100, 0, 0 }; // empty rect!
bool adjustSize_ = false;
bool adjustPos_ = false;
bool loading_ = false;
static std::atomic<int> numWindows_;
struct Command {
Window *owner;
int x;
int y;
};
};
} // Cocoa
} // vst
|