blob: def95f5bc33838707cd802899d8dd087c007f700 [file] [log] [blame]
yangsu@google.coma8540412011-08-30 14:40:49 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#if defined(SK_BUILD_FOR_MAC) && !defined(SK_USE_WXWIDGETS)
10
11#import <Cocoa/Cocoa.h>
12#include "SkOSWindow_Mac.h"
yangsu@google.com12d177d2011-08-01 17:07:12 +000013#include "SkOSMenu.h"
14#include "SkTypes.h"
15#include "SkWindow.h"
yangsu@google.coma8540412011-08-30 14:40:49 +000016#import "SkNSView.h"
17#import "SkEventNotifier.h"
18#define kINVAL_NSVIEW_EventType "inval-nsview"
yangsu@google.com12d177d2011-08-01 17:07:12 +000019
20SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
21 fInvalEventIsPending = false;
22 fGLContext = NULL;
23 fNotifier = [[SkEventNotifier alloc] init];
24}
25SkOSWindow::~SkOSWindow() {
26 [(SkEventNotifier*)fNotifier release];
27}
28
29void SkOSWindow::onHandleInval(const SkIRect& r) {
30 if (!fInvalEventIsPending) {
31 fInvalEventIsPending = true;
yangsu@google.comf3493f02011-08-08 15:12:05 +000032 (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post();
yangsu@google.com12d177d2011-08-01 17:07:12 +000033 }
34}
35
36bool SkOSWindow::onEvent(const SkEvent& evt) {
37 if (evt.isType(kINVAL_NSVIEW_EventType)) {
38 fInvalEventIsPending = false;
39 const SkIRect& r = this->getDirtyBounds();
40 [(SkNSView*)fHWND postInvalWithRect:&r];
41 [(NSOpenGLContext*)fGLContext update];
42 return true;
43 }
44 if ([(SkNSView*)fHWND onHandleEvent:evt]) {
45 return true;
46 }
47 return this->INHERITED::onEvent(evt);
48}
49
50bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner) {
51 return this->INHERITED::onDispatchClick(x, y, state, owner);
52}
53
54void SkOSWindow::onSetTitle(const char title[]) {
55 [(SkNSView*)fHWND setSkTitle:title];
56}
57
58void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
59 [(SkNSView*)fHWND onAddMenu:menu];
60}
61
62void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
63 [(SkNSView*)fHWND onUpdateMenu:menu];
64}
65
66bool SkOSWindow::attachGL() {
67 [(SkNSView*)fHWND attachGL];
68}
69
70void SkOSWindow::detachGL() {
71 [(SkNSView*)fHWND detachGL];
72}
73
74void SkOSWindow::presentGL() {
75 [(SkNSView*)fHWND presentGL];
yangsu@google.coma8540412011-08-30 14:40:49 +000076}
77
78#endif