summaryrefslogtreecommitdiff
path: root/iup/src/iup_strmessage.c
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-11-04 11:56:41 -0800
committerPixel <pixel@nobis-crew.org>2009-11-04 11:59:33 -0800
commitd577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch)
tree590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/iup_strmessage.c
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/iup_strmessage.c')
-rwxr-xr-xiup/src/iup_strmessage.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/iup/src/iup_strmessage.c b/iup/src/iup_strmessage.c
new file mode 100755
index 0000000..5f23528
--- /dev/null
+++ b/iup/src/iup_strmessage.c
@@ -0,0 +1,137 @@
+/** \file
+ * \brief String Utilities
+ *
+ * See Copyright Notice in "iup.h"
+ */
+
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <stdarg.h>
+
+#include "iup.h"
+
+#include "iup_attrib.h"
+#include "iup_str.h"
+#include "iup_strmessage.h"
+#include "iup_table.h"
+
+
+static Itable *istrmessage_table = NULL; /* the function hast table indexed by the name string */
+
+void iupStrMessageInit(void)
+{
+ istrmessage_table = iupTableCreate(IUPTABLE_STRINGINDEXED);
+}
+
+void iupStrMessageFinish(void)
+{
+ iupTableDestroy(istrmessage_table);
+ istrmessage_table = NULL;
+}
+
+char* iupStrMessageGet(const char* message)
+{
+ return (char*)iupTableGet(istrmessage_table, message);
+}
+
+static void iStrMessageSet(const char* message, const char* str)
+{
+ iupTableSet(istrmessage_table, message, (char*)str, IUPTABLE_POINTER);
+}
+
+void iupStrMessageShowError(Ihandle* parent, const char* message)
+{
+ Ihandle* dlg = IupMessageDlg();
+ char* title = NULL, *str_message;
+
+ if (parent)
+ {
+ IupSetAttributeHandle(dlg, "PARENTDIALOG", parent);
+ title = IupGetAttribute(parent, "TITLE");
+ }
+
+ if (!title)
+ title = iupStrMessageGet("IUP_ERROR");
+
+ IupSetAttribute(dlg, "TITLE", title);
+ IupSetAttribute(dlg, "DIALOGTYPE", "ERROR");
+ IupSetAttribute(dlg, "BUTTONS", "OK");
+
+ str_message = iupStrMessageGet(message);
+ if (!str_message)
+ str_message = (char*)message;
+ IupSetAttribute(dlg, "VALUE", str_message);
+
+ IupPopup(dlg, IUP_CURRENT, IUP_CURRENT);
+
+ IupDestroy(dlg);
+}
+
+typedef struct _IstdMessage
+{
+ const char* code;
+ const char* lng_msg[3]; /* 2+1 for expansion */
+} IstdMessage;
+
+/* Edit this table to add support for more languages */
+
+static IstdMessage iStdMessages[] =
+{
+ {"IUP_ERROR", {"Error", "Erro", NULL}},
+ {"IUP_YES", {"Yes", "Sim", NULL}},
+ {"IUP_NO", {"No", "Não", NULL}},
+ {"IUP_INVALIDDIR", {"Invalid directory.", "Diretório inválido.", NULL}},
+ {"IUP_FILEISDIR", {"The selected name is a directory.", "O nome selecionado é um diretório.", NULL}},
+ {"IUP_FILENOTEXIST", {"File does not exist.", "Arquivo inexistente.", NULL}},
+ {"IUP_FILEOVERWRITE", {"Overwrite existing file?", "Sobrescrever arquivo?", NULL}},
+ {"IUP_CREATEFOLDER", {"Create Folder", "Criar Diretório", NULL}},
+ {"IUP_NAMENEWFOLDER", {"Name of the new folder:", "Nome do novo diretório:", NULL}},
+ {"IUP_SAVEAS", {"Save As", "Salvar Como", NULL}},
+ {"IUP_OPEN", {"Open", "Abrir", NULL}},
+ {"IUP_SELECTDIR", {"Select Directory", "Selecionar Diretório", NULL}},
+ {"IUP_CANCEL", {"Cancel", "Cancela", NULL}},
+ {"IUP_GETCOLOR", {"Color Selection", "Seleção de Cor", NULL}},
+ {"IUP_HELP", {"Help", "Ajuda", NULL}},
+ {"IUP_RED", {"&Red:", "&Vermelho:", NULL}},
+ {"IUP_GREEN", {"&Green:", "V&erde:", NULL}},
+ {"IUP_BLUE", {"&Blue:", "&Azul:", NULL}},
+ {"IUP_HUE", {"&Hue:", "&Matiz:", NULL}},
+ {"IUP_SATURATION", {"&Saturation:", "&Saturação:", NULL}},
+ {"IUP_INTENSITY", {"&Intensity:", "&Intensidade:", NULL}},
+ {"IUP_OPACITY", {"&Opacity:", "&Opacidade:", NULL}},
+ {"IUP_PALETTE", {"&Palette:", "&Paleta:", NULL}},
+ {"IUP_TRUE", {"True", "Verdadeiro", NULL}},
+ {"IUP_FALSE", {"False", "Falso", NULL}},
+ {NULL, {NULL, NULL, NULL}}
+};
+
+static void iStrRegisterInternalMessages(int lng)
+{
+ IstdMessage* messages = iStdMessages;
+ while (messages->code)
+ {
+ iStrMessageSet(messages->code, messages->lng_msg[lng]);
+ messages++;
+ }
+}
+
+void iupStrMessageUpdateLanguage(const char* language)
+{
+ int lng = 0;
+ if (iupStrEqualNoCase(language, "PORTUGUESE"))
+ lng = 1;
+ iStrRegisterInternalMessages(lng);
+}
+
+void IupSetLanguage(const char *language)
+{
+ IupStoreGlobal("LANGUAGE", language);
+}
+
+char *IupGetLanguage(void)
+{
+ return IupGetGlobal("LANGUAGE");
+}