yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame^] | 1 | |
| 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.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 13 | #include "SkOSMenu.h" |
| 14 | #include "SkTypes.h" |
| 15 | #include "SkWindow.h" |
yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame^] | 16 | #import "SkNSView.h" |
| 17 | #import "SkEventNotifier.h" |
| 18 | #define kINVAL_NSVIEW_EventType "inval-nsview" |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 19 | |
| 20 | SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { |
| 21 | fInvalEventIsPending = false; |
| 22 | fGLContext = NULL; |
| 23 | fNotifier = [[SkEventNotifier alloc] init]; |
| 24 | } |
| 25 | SkOSWindow::~SkOSWindow() { |
| 26 | [(SkEventNotifier*)fNotifier release]; |
| 27 | } |
| 28 | |
| 29 | void SkOSWindow::onHandleInval(const SkIRect& r) { |
| 30 | if (!fInvalEventIsPending) { |
| 31 | fInvalEventIsPending = true; |
yangsu@google.com | f3493f0 | 2011-08-08 15:12:05 +0000 | [diff] [blame] | 32 | (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post(); |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
| 36 | bool 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 | |
| 50 | bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner) { |
| 51 | return this->INHERITED::onDispatchClick(x, y, state, owner); |
| 52 | } |
| 53 | |
| 54 | void SkOSWindow::onSetTitle(const char title[]) { |
| 55 | [(SkNSView*)fHWND setSkTitle:title]; |
| 56 | } |
| 57 | |
| 58 | void SkOSWindow::onAddMenu(const SkOSMenu* menu) { |
| 59 | [(SkNSView*)fHWND onAddMenu:menu]; |
| 60 | } |
| 61 | |
| 62 | void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) { |
| 63 | [(SkNSView*)fHWND onUpdateMenu:menu]; |
| 64 | } |
| 65 | |
| 66 | bool SkOSWindow::attachGL() { |
| 67 | [(SkNSView*)fHWND attachGL]; |
| 68 | } |
| 69 | |
| 70 | void SkOSWindow::detachGL() { |
| 71 | [(SkNSView*)fHWND detachGL]; |
| 72 | } |
| 73 | |
| 74 | void SkOSWindow::presentGL() { |
| 75 | [(SkNSView*)fHWND presentGL]; |
yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame^] | 76 | } |
| 77 | |
| 78 | #endif |