~ubuntu-branches/ubuntu/trusty/libcdk5/trusty

« back to all changes in this revision

Viewing changes to cdk_display.c

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2007-06-06 03:54:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070606035431-ba4gdvw0h6ybffsu
Tags: 5.0.20060507-1
* New upstream release.
* Fixed header patching.  Patch from Robert Schiele.
  Closes: #402978, #416336.
* Update widget count in description.  Closes: #294709.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cdk_int.h>
 
2
 
 
3
/*
 
4
 * $Author: tom $
 
5
 * $Date: 2006/04/18 00:06:07 $
 
6
 * $Revision: 1.3 $
 
7
 */
 
8
 
 
9
/*
 
10
 * Given a character pointer, returns the equivalent display type.
 
11
 */
 
12
EDisplayType char2DisplayType (char *string)
 
13
{
 
14
   /* *INDENT-OFF* */
 
15
   static const struct {
 
16
      const char *name;
 
17
      EDisplayType code;
 
18
   } table[] = {
 
19
      { "CHAR",         vCHAR },
 
20
      { "HCHAR",        vHCHAR },
 
21
      { "INT",          vINT },
 
22
      { "HINT",         vHINT },
 
23
      { "UCHAR",        vUCHAR },
 
24
      { "LCHAR",        vLCHAR },
 
25
      { "UHCHAR",       vUHCHAR },
 
26
      { "LHCHAR",       vLHCHAR },
 
27
      { "MIXED",        vMIXED },
 
28
      { "HMIXED",       vHMIXED },
 
29
      { "UMIXED",       vUMIXED },
 
30
      { "LMIXED",       vLMIXED },
 
31
      { "UHMIXED",      vUHMIXED },
 
32
      { "LHMIXED",      vLHMIXED },
 
33
      { "VIEWONLY",     vVIEWONLY },
 
34
      { 0,              vINVALID },
 
35
   };
 
36
   /* *INDENT-ON* */
 
37
 
 
38
   if (string != 0)
 
39
   {
 
40
      int n;
 
41
      for (n = 0; table[n].name != 0; n++)
 
42
      {
 
43
         if (!strcmp (string, table[n].name))
 
44
            return table[n].code;
 
45
      }
 
46
   }
 
47
   return (EDisplayType) vINVALID;
 
48
}
 
49
 
 
50
/*
 
51
 * Tell if a display type is "hidden"
 
52
 */
 
53
boolean isHiddenDisplayType (EDisplayType type)
 
54
{
 
55
   boolean result = FALSE;
 
56
 
 
57
   switch (type)
 
58
   {
 
59
   case vHCHAR:
 
60
   case vHINT:
 
61
   case vHMIXED:
 
62
   case vLHCHAR:
 
63
   case vLHMIXED:
 
64
   case vUHCHAR:
 
65
   case vUHMIXED:
 
66
      result = TRUE;
 
67
      break;
 
68
   case vCHAR:
 
69
   case vINT:
 
70
   case vINVALID:
 
71
   case vLCHAR:
 
72
   case vLMIXED:
 
73
   case vMIXED:
 
74
   case vUCHAR:
 
75
   case vUMIXED:
 
76
   case vVIEWONLY:
 
77
      result = FALSE;
 
78
      break;
 
79
   }
 
80
   return result;
 
81
}
 
82
 
 
83
/*
 
84
 * Given a character input, check if it is allowed by the display type,
 
85
 * and return the character to apply to the display, or ERR if not.
 
86
 */
 
87
int filterByDisplayType (EDisplayType type, chtype input)
 
88
{
 
89
   int result = CharOf (input);
 
90
 
 
91
   if (!isChar (input))
 
92
   {
 
93
      result = ERR;
 
94
   }
 
95
   else if ((type == vINT ||
 
96
             type == vHINT) &&
 
97
            !isdigit (CharOf (result)))
 
98
   {
 
99
      result = ERR;
 
100
   }
 
101
   else if ((type == vCHAR ||
 
102
             type == vUCHAR ||
 
103
             type == vLCHAR ||
 
104
             type == vUHCHAR ||
 
105
             type == vLHCHAR) &&
 
106
            isdigit (CharOf (result)))
 
107
   {
 
108
      result = ERR;
 
109
   }
 
110
   else if (type == vVIEWONLY)
 
111
   {
 
112
      result = ERR;
 
113
   }
 
114
   else if ((type == vUCHAR ||
 
115
             type == vUHCHAR ||
 
116
             type == vUMIXED ||
 
117
             type == vUHMIXED) &&
 
118
            isalpha (CharOf (result)))
 
119
   {
 
120
      result = toupper (result);
 
121
   }
 
122
   else if ((type == vLCHAR ||
 
123
             type == vLHCHAR ||
 
124
             type == vLMIXED ||
 
125
             type == vLHMIXED) &&
 
126
            isalpha (CharOf (result)))
 
127
   {
 
128
      result = tolower (result);
 
129
   }
 
130
   return result;
 
131
}