summaryrefslogtreecommitdiff
path: root/atari/msgbox.c
diff options
context:
space:
mode:
authorOle Loots <ole@monochrom.net>2012-11-12 21:23:39 +0100
committerOle Loots <ole@monochrom.net>2012-11-12 21:23:39 +0100
commit44808e1c52b217cced501b946059324e55848dfa (patch)
treea468d7c527b41640d7fad34e4afec0fde79b8ddd /atari/msgbox.c
parentc040fbc4cca119ba4dcaac866e0eb4c23b76c4c7 (diff)
downloadnetsurf-44808e1c52b217cced501b946059324e55848dfa.tar.gz
netsurf-44808e1c52b217cced501b946059324e55848dfa.tar.bz2
Added message box, so warn_user works as expected.
Diffstat (limited to 'atari/msgbox.c')
-rw-r--r--atari/msgbox.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/atari/msgbox.c b/atari/msgbox.c
new file mode 100644
index 000000000..a9de5d299
--- /dev/null
+++ b/atari/msgbox.c
@@ -0,0 +1,84 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gem.h>
+#include "atari/msgbox.h"
+
+#ifndef min
+# define min(x,y) ((x<y) ? x : y )
+#endif
+
+short msg_box_show(short type, char * msg)
+{
+ #define MSG_BOX_STR_SIZE 256
+ short retval=0, i=0, z=0, l=0;
+ char c;
+ int len_msg = strlen(msg);
+
+ // TODO: localize strings
+ const char *str_yes = "Yes";
+ const char *str_no = "No";
+ const char *str_ok = "OK";
+ char msg_box_str[MSG_BOX_STR_SIZE];
+ char *dst = msg_box_str;
+
+ memset(msg_box_str, 0, MSG_BOX_STR_SIZE);
+
+ strncat(msg_box_str, "[1]", MSG_BOX_STR_SIZE);
+ strncat(msg_box_str, "[", MSG_BOX_STR_SIZE);
+
+ dst = msg_box_str + strlen(msg_box_str);
+
+ for (i=0; i<min(len_msg,40*5); i++) {
+
+ c = msg[i];
+
+ if(c==0)
+ break;
+
+ if (z==40) {
+ if(l==4){
+ break;
+ }
+ z = 0;
+ l++;
+ *dst = (char)'|';
+ dst++;
+ }
+
+ if ((c=='\r' || c=='\n') && *dst != '|') {
+ if(l==4){
+ break;
+ }
+ z = 0;
+ l++;
+ *dst = '|';
+ dst++;
+ }
+ else {
+ z++;
+ *dst = c;
+ dst++;
+ }
+ }
+ strncat(msg_box_str, "][", MSG_BOX_STR_SIZE);
+
+ if(type == MSG_BOX_CONFIRM){
+ strncat(msg_box_str, str_yes, MSG_BOX_STR_SIZE);
+ strncat(msg_box_str, "|", MSG_BOX_STR_SIZE);
+ strncat(msg_box_str, str_no, MSG_BOX_STR_SIZE);
+ } else {
+ strncat(msg_box_str, str_ok, MSG_BOX_STR_SIZE);
+ }
+ strncat(msg_box_str, "]", MSG_BOX_STR_SIZE);
+
+ retval = form_alert(type, msg_box_str);
+ if(type == MSG_BOX_CONFIRM){
+ if(retval != 1){
+ retval = 0;
+ }
+ }
+ return(retval);
+
+ #undef MSG_BOX_STR_SIZE
+}