Permalink
Browse files

MOSYNC implemented optionbox escape

  • Loading branch information...
1 parent 09edd9d commit 53fefb59439fe95229365f22788cfeb36fccf81b @chrisws chrisws committed Jul 22, 2012
@@ -11,6 +11,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <wchar.h>
#include "platform/mosync/ansiwidget.h"
#include "platform/mosync/utils.h"
@@ -943,6 +944,34 @@ void AnsiWidget::createLink(char *&p, bool execLink) {
deleteItems(items);
}
+// create an options dialog
+void AnsiWidget::createOptionsBox(char *&p) {
+ Vector<String *> *items = getItems(p);
+ if (items->size()) {
+ // calculate the size of the options buffer
+ int optionsBytes = sizeof(int);
+ Vector_each(String*, it, *items) {
+ const char *str = (*it)->c_str();
+ optionsBytes += (strlen(str) + 1) * sizeof(wchar);
+ }
+
+ // create the options buffer
+ char *buffer = new char[optionsBytes];
+ *(int *)buffer = items->size();
+ wchar_t *dst = (wchar_t *)(buffer + sizeof(int));
+
+ Vector_each(String*, it, *items) {
+ const char *str = (*it)->c_str();
+ int len = strlen(str);
+ swprintf(dst, len + 1, L"%hs", str);
+ dst[len] = 0;
+ dst += (len + 1);
+ }
+ maOptionsBox(L"SmallBASIC", NULL, L"Close", (MAAddress)buffer, optionsBytes);
+ }
+ deleteItems(items);
+}
+
// cleanup the string list created in getItems()
void AnsiWidget::deleteItems(Vector<String *> *items) {
Vector_each(String*, it, *items) {
@@ -981,6 +1010,9 @@ bool AnsiWidget::doEscape(char *&p, int textHeight) {
case 'H':
createLink(p, true);
break;
+ case 'O':
+ createOptionsBox(p);
+ break;
case 'P':
paintScreen(p);
break;
@@ -138,6 +138,7 @@ class AnsiWidget {
private:
void createButton(char *&p);
void createLink(char *&p, bool execLink);
+ void createOptionsBox(char *&p);
void deleteItems(Vector<String *> *items);
bool doEscape(char *&p, int textHeight);
Vector<String *> *getItems(char *&p);
@@ -19,7 +19,13 @@
#include "platform/mosync/controller.h"
#include "platform/mosync/utils.h"
-#define LONG_PRESS_TIME 3000
+#define LONG_PRESS_TIME 4000
+#define SYSTEM_MENU "\033[ OHome|Options|View Source|Break|Help|About;"
+
+#define MENU_HOME 1
+#define MENU_SRC 2
+#define MENU_HELP 3
+#define MENU_BREAK 4
Controller::Controller() :
Environment(),
@@ -30,7 +36,8 @@ Controller::Controller() :
penMode(PEN_OFF),
penDownX(-1),
penDownY(-1),
- penDownTime(0) {
+ penDownTime(0),
+ systemMenu(false) {
logEntered();
}
@@ -189,10 +196,13 @@ MAEvent Controller::processEvents(int ms, int untilType) {
MAEvent event;
MAExtent screenSize;
+ // long press = menu
if (penDownTime != 0) {
int now = maGetMilliSecondCount();
if ((now - penDownTime) > LONG_PRESS_TIME) {
penDownTime = now;
+ systemMenu = true;
+ output->print(SYSTEM_MENU);
}
}
@@ -203,6 +213,23 @@ MAEvent Controller::processEvents(int ms, int untilType) {
}
switch (event.type) {
+ case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
+ if (systemMenu) {
+ systemMenu = false;
+ switch (event.optionsBoxButtonIndex) {
+ case MENU_HOME:
+ break;
+ case MENU_SRC:
+ break;
+ case MENU_HELP:
+ break;
+ case MENU_BREAK:
+ break;
+ }
+ } else {
+ dev_pushkey(event.optionsBoxButtonIndex);
+ }
+ break;
case EVENT_TYPE_SCREEN_CHANGED:
screenSize = maGetScrSize();
output->resize(EXTENT_X(screenSize), EXTENT_Y(screenSize));
@@ -389,6 +416,10 @@ void Controller::handleKey(int key) {
case MAK_BACK:
runMode = exit_state;
break;
+ case MAK_MENU:
+ systemMenu = true;
+ output->print(SYSTEM_MENU);
+ break;
}
if (isRunning()) {
@@ -405,9 +436,6 @@ void Controller::handleKey(int key) {
case MAK_INSERT:
dev_pushkey(SB_KEY_INSERT);
break;
- case MAK_MENU:
- dev_pushkey(SB_KEY_MENU);
- break;
case MAK_KP_MULTIPLY:
dev_pushkey(SB_KEY_KP_MUL);
break;
@@ -72,5 +72,6 @@ struct Controller : public Environment, ButtonListener {
int penDownX;
int penDownY;
int penDownTime;
+ bool systemMenu;
String loadPath;
};

0 comments on commit 53fefb5

Please sign in to comment.