epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkOSMenu.h" |
| 9 | |
| 10 | static int gOSMenuCmd = 7000; |
| 11 | |
| 12 | SkOSMenu::SkOSMenu(const char title[]) |
| 13 | { |
| 14 | fTitle = title; |
| 15 | } |
| 16 | |
| 17 | SkOSMenu::~SkOSMenu() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | int SkOSMenu::countItems() const |
| 22 | { |
| 23 | return fItems.count(); |
| 24 | } |
| 25 | |
| 26 | void SkOSMenu::appendItem(const char title[], const char eventType[], int32_t eventData) |
| 27 | { |
| 28 | Item* item = fItems.append(); |
| 29 | |
| 30 | item->fTitle = title; |
| 31 | item->fEventType = eventType; |
| 32 | item->fEventData = eventData; |
| 33 | item->fOSCmd = ++gOSMenuCmd; |
| 34 | } |
| 35 | |
| 36 | SkEvent* SkOSMenu::createEvent(uint32_t os_cmd) |
| 37 | { |
| 38 | const Item* iter = fItems.begin(); |
| 39 | const Item* stop = fItems.end(); |
| 40 | |
| 41 | while (iter < stop) |
| 42 | { |
| 43 | if (iter->fOSCmd == os_cmd) |
| 44 | { |
| 45 | SkEvent* evt = new SkEvent(iter->fEventType); |
| 46 | evt->setFast32(iter->fEventData); |
| 47 | return evt; |
| 48 | } |
| 49 | iter++; |
| 50 | } |
| 51 | return NULL; |
| 52 | } |
| 53 | |
| 54 | const char* SkOSMenu::getItem(int index, uint32_t* cmdID) const |
| 55 | { |
| 56 | if (cmdID) |
| 57 | *cmdID = fItems[index].fOSCmd; |
| 58 | return fItems[index].fTitle; |
| 59 | } |
| 60 | |