blob: 2f28b51592c2784a941edfa8be9c1e7a36dace32 [file] [log] [blame]
yangsu@google.com1a2b4c12011-06-24 17:20:50 +00001#import <UIKit/UIKit.h>
yangsu@google.com1a2b4c12011-06-24 17:20:50 +00002#include "SkCanvas.h"
yangsu@google.com2e20c242011-07-07 19:26:42 +00003#include "SkGraphics.h"
yangsu@google.come938b192011-08-02 13:23:15 +00004#import "SkEventNotifier.h"
yangsu@google.com1a2b4c12011-06-24 17:20:50 +00005#include "SkOSMenu.h"
6#include "SkTime.h"
yangsu@google.com2e20c242011-07-07 19:26:42 +00007#include "SkTypes.h"
yangsu@google.comc5aeccd2011-07-17 14:42:08 +00008#import "SkUIView.h"
yangsu@google.com2e20c242011-07-07 19:26:42 +00009#include "SkWindow.h"
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000010
11#define kINVAL_UIVIEW_EventType "inval-uiview"
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000012
13SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
14 fInvalEventIsPending = false;
yangsu@google.come938b192011-08-02 13:23:15 +000015 fNotifier = [[SkEventNotifier alloc] init];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000016}
17SkOSWindow::~SkOSWindow() {
yangsu@google.come938b192011-08-02 13:23:15 +000018 [(SkEventNotifier*)fNotifier release];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000019}
20
21void SkOSWindow::onHandleInval(const SkIRect& r) {
22 if (!fInvalEventIsPending) {
23 fInvalEventIsPending = true;
24 (new SkEvent(kINVAL_UIVIEW_EventType))->post(this->getSinkID());
25 }
26}
27
28bool SkOSWindow::onEvent(const SkEvent& evt) {
29 if (evt.isType(kINVAL_UIVIEW_EventType)) {
30 fInvalEventIsPending = false;
31 const SkIRect& r = this->getDirtyBounds();
yangsu@google.comc5aeccd2011-07-17 14:42:08 +000032 [(SkUIView*)fHWND postInvalWithRect:&r];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000033 return true;
34 }
yangsu@google.comc5aeccd2011-07-17 14:42:08 +000035 if ([(SkUIView*)fHWND onHandleEvent:evt]) {
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000036 return true;
37 }
yangsu@google.com2e20c242011-07-07 19:26:42 +000038 return this->INHERITED::onEvent(evt);
39}
40
41bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner) {
42 return this->INHERITED::onDispatchClick(x, y, state, owner);
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000043}
44
45void SkOSWindow::onSetTitle(const char title[]) {
yangsu@google.comc5aeccd2011-07-17 14:42:08 +000046 [(SkUIView*)fHWND setSkTitle:title];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000047}
48
yangsu@google.come938b192011-08-02 13:23:15 +000049void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
50 [(SkUIView*)fHWND onAddMenu:menu];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000051}
52
yangsu@google.come938b192011-08-02 13:23:15 +000053void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
54 [(SkUIView*)fHWND onUpdateMenu:menu];
55}
yangsu@google.com2e20c242011-07-07 19:26:42 +000056
yangsu@google.come938b192011-08-02 13:23:15 +000057bool SkOSWindow::attachGL() {
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000058 bool success = true;
59 return success;
60}
61
yangsu@google.come938b192011-08-02 13:23:15 +000062void SkOSWindow::detachGL() {}
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000063
64void SkOSWindow::presentGL() {
65 glFlush();
66}