summaryrefslogtreecommitdiff
path: root/iup/src/iup_strmessage.c
blob: 5f23528116f889c0982bce827246f7eb19576e16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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");
}