blob: 94579aa14b244dbfa1b3a60aaf21021cbb1dc2c2 [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;
yangsu@google.comf3493f02011-08-08 15:12:05 +000024 (new SkEvent(kINVAL_UIVIEW_EventType, this->getSinkID()))->post();
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000025 }
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
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000041void SkOSWindow::onSetTitle(const char title[]) {
yangsu@google.comc5aeccd2011-07-17 14:42:08 +000042 [(SkUIView*)fHWND setSkTitle:title];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000043}
44
yangsu@google.come938b192011-08-02 13:23:15 +000045void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
46 [(SkUIView*)fHWND onAddMenu:menu];
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000047}
48
caryclark@google.com867cbd82012-09-20 15:45:41 +000049void SkOSWindow::onUpdateMenu(SkOSMenu* menu) {
yangsu@google.come938b192011-08-02 13:23:15 +000050 [(SkUIView*)fHWND onUpdateMenu:menu];
51}
yangsu@google.com2e20c242011-07-07 19:26:42 +000052
bsalomon@google.com11959252012-04-06 20:13:38 +000053bool SkOSWindow::attach(SkBackEndTypes /* attachType */,
54 int /* msaaSampleCount */) {
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000055 bool success = true;
56 return success;
57}
58
robertphillips@google.comd5b05ef2012-04-02 20:19:28 +000059void SkOSWindow::detach() {}
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000060
robertphillips@google.comd5b05ef2012-04-02 20:19:28 +000061void SkOSWindow::present() {
yangsu@google.com1a2b4c12011-06-24 17:20:50 +000062}