LCOV - code coverage report
Current view: top level - gdraw - gchardlg.c (source / functions) Hit Total Coverage
Test: FontForge coverage report 2017-08-04 01:21:11+02:00 (commit d35f7e4107a9e1db65cce47c468fcc914cecb8fd) Lines: 0 547 0.0 %
Date: 2017-08-04 Functions: 0 24 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2000-2012 by George Williams */
       2             : /*
       3             :  * Redistribution and use in source and binary forms, with or without
       4             :  * modification, are permitted provided that the following conditions are met:
       5             : 
       6             :  * Redistributions of source code must retain the above copyright notice, this
       7             :  * list of conditions and the following disclaimer.
       8             : 
       9             :  * Redistributions in binary form must reproduce the above copyright notice,
      10             :  * this list of conditions and the following disclaimer in the documentation
      11             :  * and/or other materials provided with the distribution.
      12             : 
      13             :  * The name of the author may not be used to endorse or promote products
      14             :  * derived from this software without specific prior written permission.
      15             : 
      16             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
      17             :  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      18             :  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
      19             :  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      20             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      21             :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
      22             :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
      23             :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      24             :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
      25             :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      26             :  */
      27             : #include <stdlib.h>
      28             : #include <string.h>
      29             : #include <ustring.h>
      30             : #include <utype.h>
      31             : #include <gdraw.h>
      32             : #include <gwidget.h>
      33             : #include <ggadget.h>
      34             : #include <charset.h>
      35             : #include <chardata.h>
      36             : #include <gresource.h>
      37             : #include "ggadgetP.h"         /* For the font family names */
      38             : 
      39             : #include "gutils/unicodelibinfo.h"
      40             : //#include "../fontforge/unicodelibinfo.c"
      41             : 
      42             : #define INSCHR_CharSet  1
      43             : #define INSCHR_Char     2
      44             : #define INSCHR_Hex      3
      45             : #define INSCHR_Dec      4
      46             : #define INSCHR_Unicode  5
      47             : #define INSCHR_KuTen    6
      48             : #define INSCHR_Prev     7
      49             : #define INSCHR_Next     8
      50             : #define INSCHR_Insert   9
      51             : #define INSCHR_Close    10
      52             : #define INSCHR_Show     11
      53             : 
      54             : enum dsp_mode { d_hex, d_dec, d_unicode, d_kuten };
      55             : 
      56             : static struct inschr {
      57             :     GWindow icw;
      58             :     int width, height;
      59             :     int spacing, ybase;
      60             :     long sel_char;
      61             :     enum charset map;
      62             :     int page;
      63             :     enum dsp_mode dsp_mode;
      64             :     unsigned int hidden: 1;
      65             :     unsigned int show_enabled: 1;
      66             :     unsigned int mouse_down: 1;
      67             :     unsigned int mouse_in: 1;
      68             :     unsigned int pageable: 1;
      69             :     unsigned int flash: 1;
      70             :     int as,sas;
      71             :     short x,y;
      72             :     GTimer *flash_time;
      73             :     GFont *font;
      74             :     GFont *smallfont;
      75             : } inschr = {
      76             :      NULL, 0, 0, 0, 0, EOF, em_iso8859_1, 0, d_hex,
      77             :      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL
      78             : };
      79             : 
      80             : static struct unicode_subranges { unichar_t first; int len; const char *name; } unicode_ranges[] = {
      81             :         { 0x100, 0x80, "Latin Extended A" },
      82             :         { 0x180, 0x98, "Latin Extended B" },
      83             :         { 0x250, 0x60, "IPA Extensions" },
      84             :         { 0x1e00, 0x100, "Latin Additional Extensions" },
      85             :         { 0xfb00, 0x010, "Latin Ligatures" },
      86             :         { 0xff00, 0x060, "Latin Fullwidth" },
      87             :         { 0x02b0, 0x040, "Spacing Modifier Letters" },
      88             :         { 0x0300, 0x070, "Combining Diacritics" },
      89             :         { 0x0370, 0x90, "Greek & Coptic" },
      90             :         { 0x1f00, 0x100, "Greek Additional Extensions" },
      91             :         { 0x0400, 0x100, "Cyrillic" },
      92             :         { 0x0530, 0x060, "Armenian" },
      93             :         { 0xfb10, 0x010, "Armenian Ligatures" },
      94             :         { 0x0590, 0x070, "Hebrew" },
      95             :         { 0xfb20, 0x030, "Hebrew Ligatures" },
      96             :         { 0x0600, 0x100, "Arabic" },
      97             :         { 0xfb50, 0x100, "Arabic Ligatures A1" },
      98             :         { 0xfc50, 0x100, "Arabic Ligatures A2" },
      99             :         { 0xfd50, 0x0b0, "Arabic Ligatures A3" },
     100             :         { 0xfe70, 0x090, "Arabic Ligatures B" },
     101             :         { 0x0700, 0x080, "Syriac" },
     102             :         { 0x0780, 0x080, "Thaana" },
     103             :         { 0x0900, 0x080, "Devanagari" },
     104             :         { 0x0980, 0x080, "Bengali" },
     105             :         { 0x0a00, 0x080, "Gurmukhi" },
     106             :         { 0x0a80, 0x080, "Gujarati" },
     107             :         { 0x0b00, 0x080, "Oriya" },
     108             :         { 0x0b80, 0x080, "Tamil" },
     109             :         { 0x0c00, 0x080, "Telugu" },
     110             :         { 0x0c80, 0x080, "Kannada" },
     111             :         { 0x0d00, 0x080, "Malayalam" },
     112             :         { 0x0d80, 0x080, "Sinhala" },
     113             :         { 0x0e00, 0x080, "Thai" },
     114             :         { 0x0e80, 0x080, "Lao" },
     115             :         { 0x0f00, 0x100, "Tibetan" },
     116             :         { 0x1000, 0x080, "Myanmar" },
     117             :         { 0x10A0, 0x080, "Georgian" },
     118             :         { 0x1100, 0x100, "Hangul Jamo" },
     119             :         { 0xffa0, 0x040, "Hangul Jamo Halfwidth" },
     120             :         { 0x1200, 0x100, "Ethiopic A" },
     121             :         { 0x1300, 0x080, "Ethiopic B" },
     122             :         { 0x1380, 0x080, "Cherokee" },
     123             :         { 0x1400, 0x100, "Canadian Syllabics A" },
     124             :         { 0x1500, 0x100, "Canadian Syllabics B" },
     125             :         { 0x1600, 0x080, "Canadian Syllabics C" },
     126             :         { 0x1680, 0x020, "Ogham" },
     127             :         { 0x16A0, 0x060, "Runic" },
     128             :         { 0x1780, 0x080, "Khmer" },
     129             :         { 0x1800, 0x100, "Mongolian" },
     130             :         { 0x2000, 0x070, "General Punctuation" },
     131             :         { 0x2070, 0x030, "Super & Sub scripts" },
     132             :         { 0x20a0, 0x030, "Currency Symbols" },
     133             :         { 0x20D0, 0x030, "Combining Symbol Diacritics" },
     134             :         { 0x2100, 0x050, "Letterlike Symbols" },
     135             :         { 0x2150, 0x040, "Number Forms" },
     136             :         { 0x2190, 0x070, "Arrows" },
     137             :         { 0x2200, 0x100, "Mathematical Operators" },
     138             :         { 0x2300, 0x080, "Miscellaneous Technical" },
     139             :         { 0x2400, 0x040, "Control Pictures" },
     140             :         { 0x2440, 0x020, "OCR" },
     141             :         { 0x2460, 0x0a0, "Enclosed Alphanumerics" },
     142             :         { 0x2500, 0x080, "Box Drawing" },
     143             :         { 0x2580, 0x020, "Block Elements" },
     144             :         { 0x25a0, 0x060, "Geometric Shapes" },
     145             :         { 0x2600, 0x080, "Miscellaneous Symbols" },
     146             :         { 0x2700, 0x0c0, "Dingbats" },
     147             :         { 0x3000, 0x040, "CJK Symbols and Punctuation" },
     148             :         { 0x3040, 0x060, "Hiragana" },
     149             :         { 0x30a0, 0x060, "Katakana" },
     150             :         { 0xff60, 0x040, "Halfwidth Katakana" },
     151             :         { 0xfe30, 0x020, "CJK Compatibility Forms" },
     152             :         { 0xfe50, 0x020, "Small Form Variants" },
     153             :         { 0xffe0, 0x010, "Fullwidth Symbol Variants" },
     154             :         { 0xfff0, 0x010, "Specials" },
     155             :         { 0, 0, NULL }
     156             : };
     157             : 
     158             : struct namemap encodingnames[] = {
     159             :     {"Latin1 (iso8859-1)", em_iso8859_1 },
     160             :     {"Latin0 (iso8859-15)", em_iso8859_15 },
     161             :     {"Latin2 (iso8859-2)", em_iso8859_2 },
     162             :     {"Latin3 (iso8859-3)", em_iso8859_3 },
     163             :     {"Latin4 (iso8859-4)", em_iso8859_4 },
     164             :     {"Latin5 (iso8859-9)", em_iso8859_9 },
     165             :     {"Latin6 (iso8859-10)", em_iso8859_10 },
     166             :     {"Latin7 (iso8859-13)", em_iso8859_13 },
     167             :     {"Latin8 (iso8859-14)", em_iso8859_14 },
     168             :     {"Latin10 (iso8859-16)", em_iso8859_16 },
     169             :     {"Cyrillic (iso8859-5)", em_iso8859_5 },
     170             :     {"Cyrillic (koi8-r)", em_koi8_r },
     171             :     {"Arabic (iso8859-6)", em_iso8859_6 },
     172             :     {"Greek (iso8859-7)", em_iso8859_7 },
     173             :     {"Hebrew (iso8859-8)", em_iso8859_8 },
     174             :     {"Thai (iso8859-11)", em_iso8859_11 },
     175             :     {"KataKana (jis201)", em_jis201 },
     176             :     {"Windows Latin1 extended", em_win },
     177             :     {"Macintosh Latin", em_mac },
     178             :     {"Kanji (jis208)", em_jis208 },
     179             :     {"Kanji (jis212)", em_jis212 },
     180             :     {"Hangul (ksc5601)", em_ksc5601 },
     181             :     {"Han (gb2312)", em_gb2312 },
     182             :     {"Big5 (Taiwan)", em_big5 },
     183             :     {"Unicode", em_unicode },
     184             :     {"Symbol", em_symbol },
     185             :     {"Zapf Dingbats", em_zapfding },
     186             :     {"Adobe Standard", em_user },
     187             :     {"-", -1 },
     188             :     {"Arabic", em_max+16 },
     189             :     {"Arabic Ligatures A1", em_max+17 },
     190             :     {"Arabic Ligatures A2", em_max+18 },
     191             :     {"Arabic Ligatures A3", em_max+19 },
     192             :     {"Arabic Ligatures B", em_max+20 },
     193             :     {"Armenian", em_max+12 },
     194             :     {"Armenian Ligatures", em_max+13 },
     195             :     {"Arrows", em_max+56 },
     196             :     {"Bengali", em_max+24 },
     197             :     {"Block Elements", em_max+63 },
     198             :     {"Box Drawing", em_max+62 },
     199             :     {"Canadian Syllabics A", em_max+43 },
     200             :     {"Canadian Syllabics B", em_max+44 },
     201             :     {"Canadian Syllabics C", em_max+45 },
     202             :     {"Cherokee", em_max+42 },
     203             :     {"CJK Compatibility Forms", em_max+71 },
     204             :     {"CJK Symbols and Punctuation", em_max+67 },
     205             :     {"Combining Diacritics", em_max+8 },
     206             :     {"Combining Symbol Diacritics", em_max+53 },
     207             :     {"Control Pictures", em_max+59 },
     208             :     {"Currency Symbols", em_max+52 },
     209             :     {"Cyrillic", em_max+11 },
     210             :     {"Devanagari", em_max+23 },
     211             :     {"Dingbats", em_max+66 },
     212             :     {"Enclosed Alphanumerics", em_max+61 },
     213             :     {"Ethiopic A", em_max+40 },
     214             :     {"Ethiopic B", em_max+41 },
     215             :     {"Fullwidth Symbol Variants", em_max+73 },
     216             :     {"General Punctuation", em_max+50 },
     217             :     {"Geometric Shapes", em_max+64 },
     218             :     {"Georgian", em_max+37 },
     219             :     {"Greek & Coptic", em_max+9 },
     220             :     {"Greek Additional Extensions", em_max+10 },
     221             :     {"Gujarati", em_max+26 },
     222             :     {"Gurmukhi", em_max+25 },
     223             :     {"Halfwidth Katakana", em_max+70 },
     224             :     {"Hangul Jamo", em_max+38 },
     225             :     {"Hangul Jamo Halfwidth", em_max+39 },
     226             :     {"Hebrew", em_max+14 },
     227             :     {"Hebrew Ligatures", em_max+15 },
     228             :     {"Hiragana", em_max+68 },
     229             :     {"IPA Extensions", em_max+3 },
     230             :     {"Kannada", em_max+30 },
     231             :     {"Katakana", em_max+69 },
     232             :     {"Khmer", em_max+48 },
     233             :     {"Latin Additional Extensions", em_max+4 },
     234             :     {"Latin Fullwidth", em_max+6 },
     235             :     {"Latin Extended A", em_max+1 },
     236             :     {"Latin Extended B", em_max+2 },
     237             :     {"Latin Ligatures", em_max+5 },
     238             :     {"Letterlike Symbols", em_max+54 },
     239             :     {"Lao", em_max+34 },
     240             :     {"Malayalam", em_max+31 },
     241             :     {"Mathematical Operators", em_max+57 },
     242             :     {"Miscellaneous Symbols", em_max+65 },
     243             :     {"Miscellaneous Technical", em_max+58 },
     244             :     {"Mongolian", em_max+49 },
     245             :     {"Myanmar", em_max+36 },
     246             :     {"Number Forms", em_max+55 },
     247             :     {"OCR", em_max+60 },
     248             :     {"Ogham", em_max+46 },
     249             :     {"Oriya", em_max+27 },
     250             :     {"Punctuation", em_max+50 },
     251             :     {"Runic", em_max+47 },
     252             :     {"Sinhala", em_max+32 },
     253             :     {"Small Form Variants", em_max+72 },
     254             :     {"Spacing Modifier Letters", em_max+7 },
     255             :     {"Specials", em_max+74 },
     256             :     {"Super & Sub scripts", em_max+51 },
     257             :     {"Syriac", em_max+21 },
     258             :     {"Tamil", em_max+28 },
     259             :     {"Telugu", em_max+29 },
     260             :     {"Thaana", em_max+22 },
     261             :     {"Thai", em_max+33 },
     262             :     {"Tibetan", em_max+35 },
     263             :     /* {"Latin Extended A", em_max+1 }, */
     264             :     /* {"Latin Extended B", em_max+2 }, */
     265             :     /* {"IPA Extensions", em_max+3 }, */
     266             :     /* {"Latin Additional Extensions", em_max+4 }, */
     267             :     /* {"Latin Ligatures", em_max+5 }, */
     268             :     /* {"Latin Fullwidth", em_max+6 }, */
     269             :     /* {"Spacing Modifier Letters", em_max+7 }, */
     270             :     /* {"Combining Diacritics", em_max+8 }, */
     271             :     /* {"Greek & Coptic", em_max+9 }, */
     272             :     /* {"Greek Additional Extensions", em_max+10 }, */
     273             :     /* {"Cyrillic", em_max+11 }, */
     274             :     /* {"Armenian", em_max+12 }, */
     275             :     /* {"Armenian Ligatures", em_max+13 }, */
     276             :     /* {"Hebrew", em_max+14 }, */
     277             :     /* {"Hebrew Ligatures", em_max+15 }, */
     278             :     /* {"Arabic", em_max+16 }, */
     279             :     /* {"Arabic Ligatures A1", em_max+17 }, */
     280             :     /* {"Arabic Ligatures A2", em_max+18 }, */
     281             :     /* {"Arabic Ligatures A3", em_max+19 }, */
     282             :     /* {"Arabic Ligatures B", em_max+20 }, */
     283             :     /* {"Syriac", em_max+21 }, */
     284             :     /* {"Thaana", em_max+22 }, */
     285             :     /* {"Devanagari", em_max+23 }, */
     286             :     /* {"Bengali", em_max+24 }, */
     287             :     /* {"Gurmukhi", em_max+25 }, */
     288             :     /* {"Gujarati", em_max+26 }, */
     289             :     /* {"Oriya", em_max+27 }, */
     290             :     /* {"Tamil", em_max+28 }, */
     291             :     /* {"Telugu", em_max+29 }, */
     292             :     /* {"Kannada", em_max+30 }, */
     293             :     /* {"Malayalam", em_max+31 }, */
     294             :     /* {"Sinhala", em_max+32 }, */
     295             :     /* {"Thai", em_max+33 }, */
     296             :     /* {"Lao", em_max+34 }, */
     297             :     /* {"Tibetan", em_max+35 }, */
     298             :     /* {"Myanmar", em_max+36 }, */
     299             :     /* {"Georgian", em_max+37 }, */
     300             :     /* {"Hangul Jamo", em_max+38 }, */
     301             :     /* {"Hangul Jamo Halfwidth", em_max+39 }, */
     302             :     /* {"Ethiopic A", em_max+40 }, */
     303             :     /* {"Ethiopic B", em_max+41 }, */
     304             :     /* {"Cherokee", em_max+42 }, */
     305             :     /* {"Canadian Syllabics A", em_max+43 }, */
     306             :     /* {"Canadian Syllabics B", em_max+44 }, */
     307             :     /* {"Canadian Syllabics C", em_max+45 }, */
     308             :     /* {"Ogham", em_max+46 }, */
     309             :     /* {"Runic", em_max+47 }, */
     310             :     /* {"Khmer", em_max+48 }, */
     311             :     /* {"Mongolian", em_max+49 }, */
     312             :     /* {"General Punctuation", em_max+50 }, */
     313             :     /* {"Super & Sub scripts", em_max+51 }, */
     314             :     /* {"Currency Symbols", em_max+52 }, */
     315             :     /* {"Combining Symbol Diacritics", em_max+53 }, */
     316             :     /* {"Letterlike Symbols", em_max+54 }, */
     317             :     /* {"Number Forms", em_max+55 }, */
     318             :     /* {"Arrows", em_max+56 }, */
     319             :     /* {"Mathematical Operators", em_max+57 }, */
     320             :     /* {"Miscellaneous Technical", em_max+58 }, */
     321             :     /* {"Control Pictures", em_max+59 }, */
     322             :     /* {"OCR", em_max+60 }, */
     323             :     /* {"Enclosed Alphanumerics", em_max+61 }, */
     324             :     /* {"Box Drawing", em_max+62 }, */
     325             :     /* {"Block Elements", em_max+63 }, */
     326             :     /* {"Geometric Shapes", em_max+64 }, */
     327             :     /* {"Miscellaneous Symbols", em_max+65 }, */
     328             :     /* {"Dingbats", em_max+66 }, */
     329             :     /* {"CJK Symbols and Punctuation", em_max+67 }, */
     330             :     /* {"Hiragana", em_max+68 }, */
     331             :     /* {"Katakana", em_max+69 }, */
     332             :     /* {"Halfwidth Katakana", em_max+70 }, */
     333             :     /* {"CJK Compatibility Forms", em_max+71 }, */
     334             :     /* {"Small Form Variants", em_max+72 }, */
     335             :     /* {"Fullwidth Symbol Variants", em_max+73 }, */
     336             :     /* {"Specials", em_max+74 }, */
     337             :     { NULL, 0 }};
     338             : 
     339           0 : static int mapFromIndex(int i) {
     340           0 : return( encodingnames[i].map );
     341             : }
     342             : 
     343           0 : static void InsChrRedraw(void) {
     344             :     GRect r;
     345             : 
     346           0 :     r.x = 0; r.width = inschr.width;
     347             :     /* it would be ybase, except we added the Page: field which needs to be updated */
     348           0 :     r.y = GDrawPointsToPixels(inschr.icw,90); r.height = inschr.height-r.y;
     349           0 :     GDrawRequestExpose(inschr.icw,&r,false);
     350           0 : }
     351             : 
     352           0 : static void InsChrXorChar(GWindow pixmap, int x, int y) {
     353             :     GRect rct;
     354             : 
     355           0 :     rct.x = x*inschr.spacing+1; rct.width = inschr.spacing-1;
     356           0 :     rct.y = inschr.ybase+y*inschr.spacing+1; rct.height = inschr.spacing-1;
     357           0 :     GDrawSetXORMode(pixmap);
     358           0 :     GDrawSetXORBase(pixmap,GDrawGetDefaultBackground(GDrawGetDisplayOfWindow(pixmap)));
     359           0 :     GDrawFillRect(pixmap,&rct,0x000000);
     360           0 :     GDrawSetCopyMode(pixmap);
     361           0 : }
     362             : 
     363           0 : static void InsChrSetNextPrev() {
     364             : 
     365           0 :     if ( inschr.icw==NULL )
     366           0 : return;
     367           0 :     if ( inschr.map<em_first2byte || inschr.map>em_max ) {
     368           0 :         inschr.pageable = false;
     369           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Next),false);
     370           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Prev),false);
     371           0 :     } else if ( inschr.map==em_unicode ) {
     372           0 :         inschr.pageable = true;
     373           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Next),inschr.page<255);
     374           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Prev),inschr.page>0);
     375           0 :     } else if ( inschr.map==em_big5 ) {
     376           0 :         inschr.pageable = true;
     377           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Next),inschr.page<0xf9);
     378           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Prev),inschr.page>0xa1);
     379             :     } else {
     380           0 :         inschr.pageable = true;
     381           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Next),inschr.page<0x7e);
     382           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Prev),inschr.page>0x21);
     383             :     }
     384             : }
     385             : 
     386           0 : static long InsChrToUni(long val) {
     387             : 
     388           0 :     if ( inschr.map==em_unicode )
     389           0 : return( val );
     390           0 :     if ( inschr.map==em_iso8859_1 ) {   /* Our latin 1 map is really windows */
     391           0 :         if ( val>=0 && val<=255 ) /*  so do the real latin1->unicode */
     392           0 : return( val );
     393           0 :     } else if ( inschr.map<em_first2byte ) {
     394           0 :         if ( val>=0 && val<=255 )
     395           0 : return( unicode_from_alphabets[inschr.map+3][val] );
     396           0 :     } else if ( inschr.map>em_max ) {
     397           0 :         if ( val>=0 && val<unicode_ranges[inschr.map-em_max-1].len )
     398           0 : return( unicode_ranges[inschr.map-em_max-1].first+val );
     399           0 :     } else if ( inschr.map==em_big5 ) {
     400           0 :         if ( val<0xa100 || val>0xFfff )
     401           0 : return( -1 );
     402           0 : return( unicode_from_big5[val-0xa100] );
     403             :     } else {
     404           0 :         if ( (val>>8)<0x21 || (val>>8)>0x7e || (val&0xff)<0x21 || (val&0xff)>0x7e )
     405           0 : return( -1 );
     406           0 :         val = ((val>>8)-0x21)*94 + ((val&0xff)-0x21);
     407           0 :         if ( inschr.map==em_jis208 )
     408           0 : return( unicode_from_jis208[val]);
     409           0 :         else if ( inschr.map==em_jis212 )
     410           0 : return( unicode_from_jis212[val]);
     411           0 :         else if ( inschr.map==em_gb2312 )
     412           0 : return( unicode_from_gb2312[val]);
     413             :         else /*if ( inschr.map==em_ksc5601 )*/
     414           0 : return( unicode_from_ksc5601[val]);
     415             :     }
     416           0 : return( -1 );
     417             : }
     418             : 
     419           0 : static unichar_t InsChrMapChar(unichar_t ch) {
     420           0 :     if ( inschr.map==em_iso8859_1 ) {   /* Our latin 1 map is really windows */
     421           0 : return( ch );                           /*  so do the real latin1->unicode */
     422           0 :     } else if ( inschr.map<em_first2byte ) {
     423           0 : return( unicode_from_alphabets[inschr.map+3][ch] );
     424           0 :     } else if ( inschr.map>em_max ) {
     425           0 : return( unicode_ranges[inschr.map-em_max-1].first+ch );
     426           0 :     } else if ( inschr.map==em_unicode ) {
     427           0 : return( (inschr.page<<8) + ch );
     428           0 :     } else if ( inschr.map==em_jis208 ) {
     429           0 : return(  unicode_from_jis208[(inschr.page-0x21)*94-0x21+ch]);
     430           0 :     } else if ( inschr.map==em_jis212 ) {
     431           0 : return(  unicode_from_jis212[(inschr.page-0x21)*94-0x21+ch]);
     432           0 :     } else if ( inschr.map==em_gb2312 ) {
     433           0 : return( unicode_from_gb2312[(inschr.page-0x21)*94-0x21+ch]);
     434           0 :     } else if ( inschr.map==em_ksc5601 ) {
     435           0 : return( unicode_from_ksc5601[(inschr.page-0x21)*94-0x21+ch]);
     436           0 :     } else if ( inschr.map==em_big5 ) {
     437           0 : return( unicode_from_big5[inschr.page*256-0xa100+ch] );
     438             :     }
     439           0 : return( 0x20 );
     440             : }
     441             : 
     442           0 : static long InsChrUniVal(void) {
     443             :     const unichar_t *str, *pt; unichar_t *pos;
     444             :     long val, val2;
     445             : 
     446           0 :     str = _GGadgetGetTitle(GWidgetGetControl(inschr.icw,INSCHR_Char));
     447           0 :     for ( pt = str; isspace(*pt); ++pt );
     448           0 :     if ( *pt=='\0' )
     449           0 : return( -1 );
     450           0 :     if ( *pt=='u' || *pt=='U' ) {
     451           0 :         ++pt;
     452           0 :         if ( *pt=='+' ) ++pt;
     453           0 :         val = u_strtol(pt,&pos,16);
     454           0 :         if ( *pos!='\0' )
     455           0 : return( -1 );
     456           0 : return( val );
     457           0 :     } else if ( u_strchr(pt,',')!=NULL && inschr.map!=em_big5 &&
     458           0 :             inschr.map>=em_first2byte && inschr.map<em_max ) {
     459           0 :         val = u_strtol(pt,&pos,10);
     460           0 :         while ( isspace(*pos)) ++pos;
     461           0 :         if ( *pos!=',' )
     462           0 : return( -1 );
     463           0 :         val2 = u_strtol(pos+1,&pos,10);
     464           0 :         if ( *pos!='\0' )
     465           0 : return( -1 );
     466           0 :         if ( inschr.map==em_unicode )
     467           0 : return( 256*val+val2 );
     468           0 :         val = 256*(val+0x20) + (val2+0x20);
     469             :     } else {
     470           0 :         if ( inschr.dsp_mode!=d_dec || (val=u_strtol(pt,&pos,10))<0 || *pos!='\0' )
     471           0 :             val = u_strtol(pt,&pos,16);
     472           0 :         if ( *pos!='\0' )
     473           0 : return( -1 );
     474             :     }
     475           0 : return( InsChrToUni(val));
     476             : }
     477             : 
     478           0 : static int InsChrInCurrentEncoding(void) {
     479           0 :     int enable = false;
     480             :     long ch;
     481             :     long resch;
     482             : 
     483           0 :     if ( inschr.icw==NULL )
     484           0 : return(0);
     485           0 :     if ( (ch = InsChrUniVal())<=0 ) {
     486           0 :         enable = false;
     487           0 :         if ( inschr.map==em_unicode && ch==0 ) enable = true;
     488           0 :     } else if ( inschr.map>em_max ) {
     489           0 :         resch = ch - unicode_ranges[inschr.map-em_max-1].first;
     490           0 :         enable = (resch>=0 && resch<unicode_ranges[inschr.map-em_max-1].len);
     491           0 :     } else if ( inschr.map>=em_first2byte ) {
     492           0 :         int highch = (ch>>8);
     493           0 :         struct charmap2 *table2=NULL;
     494             :         unsigned short *plane;
     495           0 :         if ( inschr.map<=em_jis212 )
     496           0 :             table2 = &jis_from_unicode;
     497           0 :         else if ( inschr.map==em_gb2312 )
     498           0 :             table2 = &gb2312_from_unicode;
     499           0 :         else if ( inschr.map==em_ksc5601 )
     500           0 :             table2 = &ksc5601_from_unicode;
     501           0 :         else if ( inschr.map==em_big5 )
     502           0 :             table2 = &big5_from_unicode;
     503             : 
     504           0 :         if ( inschr.map==em_unicode )
     505           0 :             enable = /*( (ch>>8)!=inschr.page )*/true;
     506           0 :         else if ( highch>=table2->first && highch<=table2->last &&
     507           0 :                  (plane = table2->table[highch])!=NULL &&
     508           0 :                  (resch = plane[ch&0xff])!=0 &&
     509           0 :                  ((inschr.map==em_jis212 && (resch&0x8000) && ((resch&~0x8000)>>8)!=inschr.page) ||
     510           0 :                   (inschr.map!=em_jis212 && !(resch&0x8000) && (resch!=inschr.page))) )
     511           0 :             enable = true;
     512             :     } else {
     513           0 :         int highch = (ch>>8);
     514           0 :         struct charmap *table = NULL;
     515             :         unsigned char *plane;
     516           0 :         table = alphabets_from_unicode[inschr.map+3];   /* Skip the 3 asciis */
     517           0 :         if ( (highch>=table->first && highch<=table->last &&
     518           0 :                  (plane = table->table[highch])!=NULL &&
     519           0 :                  (resch=plane[ch&0xff])!=0 ))
     520           0 :             enable = true;;
     521             :     }
     522           0 : return( enable );
     523             : }
     524             : 
     525           0 : static int InsChrFigureShow() {
     526             :     long ch;
     527             :     const unichar_t *str;
     528           0 :     int enable = true;
     529             : 
     530           0 :     if ( inschr.icw==NULL )
     531           0 : return(false);
     532           0 :     if ( InsChrInCurrentEncoding() )
     533           0 :         enable = true;
     534             :     else {
     535           0 :         str = _GGadgetGetTitle(GWidgetGetControl(inschr.icw,INSCHR_Char));
     536           0 :         if ( *str!='u' && *str!='U' )
     537           0 :             enable = false;
     538           0 :         else if ( str[1]!='+' )
     539           0 :             enable = false;
     540           0 :         else if ((ch = InsChrUniVal())<=0 || ch>=0x10000 )
     541           0 :             enable = false;
     542             :     }
     543             : 
     544           0 :     if ( enable!=inschr.show_enabled ) {
     545           0 :         inschr.show_enabled = enable;
     546           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_Show),enable);
     547             :     }
     548           0 : return( enable );
     549             : }
     550             : 
     551           0 : static int _InsChrSetSelChar(unichar_t ch, int refresh_page) {
     552           0 :     int inmap=0;
     553           0 :     int highch = (ch>>8);
     554           0 :     struct charmap *table = NULL;
     555             :     unsigned char *plane;
     556           0 :     struct charmap2 *table2 = NULL;
     557             :     unsigned short *plane2;
     558           0 :     unichar_t resch=0;
     559             :     char buffer[30];
     560             :     unichar_t ubuffer[30];
     561             : 
     562           0 :     if ( inschr.icw==NULL || inschr.hidden )
     563           0 :         inschr.sel_char = ch;
     564             :     else {
     565             :         /* Is it in the current map? */
     566           0 :         if ( inschr.map<em_first2byte )
     567           0 :             table = alphabets_from_unicode[inschr.map+3];       /* Skip the 3 asciis */
     568           0 :         else if ( inschr.map<=em_jis212 )
     569           0 :             table2 = &jis_from_unicode;
     570           0 :         else if ( inschr.map==em_gb2312 )
     571           0 :             table2 = &gb2312_from_unicode;
     572           0 :         else if ( inschr.map==em_ksc5601 )
     573           0 :             table2 = &ksc5601_from_unicode;
     574           0 :         else if ( inschr.map==em_big5 )
     575           0 :             table2 = &big5_from_unicode;
     576             : 
     577           0 :         inmap = true;
     578           0 :         if ( inschr.map == em_unicode )
     579           0 :             resch = ch;
     580           0 :         else if ( inschr.map>em_max ) {
     581           0 :             resch = ch-unicode_ranges[inschr.map-em_max-1].first;
     582             :             /* resch is unsigned so the <0 check is also >len */
     583           0 :             if ( resch>unicode_ranges[inschr.map-em_max-1].len )
     584           0 :                 inmap = false;
     585           0 :         } else if ( inschr.map<em_first2byte &&
     586           0 :                 (highch<table->first || highch>table->last ||
     587           0 :                  (plane = table->table[highch])==NULL ||
     588           0 :                  (resch=plane[ch&0xff])==0 ))
     589           0 :             inmap = false;
     590           0 :         else if ( inschr.map>=em_first2byte &&
     591           0 :                 (highch<table2->first || highch>table2->last ||
     592           0 :                  (plane2 = table2->table[highch])==NULL ||
     593           0 :                  (resch=plane2[ch&0xff])==0 ))
     594           0 :             inmap = false;
     595           0 :         if ( inmap && inschr.map==em_jis208 && (resch&0x8000))
     596           0 :             inmap = false;
     597           0 :         else if ( inmap && inschr.map==em_jis212 && !(resch&0x8000))
     598           0 :             inmap = false;
     599           0 :         if ( inschr.map==em_jis212 ) resch &= ~0x8000;
     600           0 :         if ( !inmap || inschr.dsp_mode==d_unicode || inschr.map>em_max )
     601           0 :             sprintf( buffer,"U+0x%04x", ch );
     602           0 :         else if ( inschr.dsp_mode==d_dec )
     603           0 :             sprintf( buffer,"%d", resch );
     604           0 :         else if ( inschr.dsp_mode==d_hex )
     605           0 :             sprintf( buffer,inschr.map<em_first2byte?"0x%02x":"0x%04x", resch );
     606           0 :         else if ( inschr.map==em_unicode )
     607           0 :             sprintf( buffer,"%d,%d", highch, ch&0xff );
     608             :         else
     609           0 :             sprintf( buffer,"%d,%d", (resch>>8)-0x20, (resch&0xff)-0x20 );
     610           0 :         uc_strcpy(ubuffer, buffer);
     611           0 :         GGadgetSetTitle(GWidgetGetControl(inschr.icw,INSCHR_Char),ubuffer);
     612           0 :         if ( inschr.flash ) {
     613           0 :             GDrawCancelTimer(inschr.flash_time);
     614           0 :             InsChrXorChar(inschr.icw,inschr.x,inschr.y);
     615           0 :             inschr.flash = false;
     616             :         }
     617           0 :         if ( inmap && refresh_page ) {
     618           0 :             inschr.x = resch&0xf; inschr.y = (resch>>4)&0xf;
     619           0 :             inschr.flash = true;
     620           0 :             if ( inschr.map>=em_first2byte && inschr.map<em_max &&
     621           0 :                     inschr.page!=(resch>>8) ) {
     622             :                 /* Set the page correctly */
     623           0 :                 inschr.page = resch>>8;
     624           0 :                 InsChrSetNextPrev();
     625           0 :                 InsChrRedraw();
     626           0 :                 InsChrSetNextPrev();
     627           0 :                 InsChrFigureShow();
     628             :             } else {
     629           0 :                 InsChrXorChar(inschr.icw,inschr.x,inschr.y);
     630             :             }
     631           0 :             inschr.flash_time = GDrawRequestTimer(inschr.icw,500,0,NULL);
     632             :         }
     633           0 :         inschr.sel_char = EOF;
     634             :     }
     635           0 : return( inmap );
     636             : }
     637             : 
     638           0 : static void InsChrSetFormat(enum dsp_mode format) {
     639           0 :     if ( inschr.dsp_mode!=format ) {
     640           0 :         unichar_t ch = InsChrUniVal();
     641           0 :         inschr.dsp_mode = format;
     642           0 :         if ( ch>0 )
     643           0 :             _InsChrSetSelChar(ch,false);
     644             :     }
     645           0 : }
     646             : 
     647           0 : static void InsChrSetCharset(int map) {
     648             :     int enabled;
     649             :     long ch;
     650             : 
     651           0 :     if ( map!=inschr.map ) {
     652           0 :         ch = InsChrUniVal();
     653           0 :         inschr.map = map;
     654           0 :         if ( inschr.map<em_first2byte ) {
     655           0 :             inschr.page = 0;
     656           0 :             enabled = false;
     657           0 :         } else if ( inschr.map>em_max ) {
     658           0 :             inschr.page = 0;
     659           0 :             enabled = false;
     660           0 :         } else if ( inschr.map==em_unicode ) {
     661           0 :             inschr.page = 0;
     662           0 :             enabled = true;
     663           0 :         } else if ( inschr.map==em_big5 ) {
     664           0 :             inschr.page = 0xa1;
     665           0 :             enabled = false;
     666             :         } else {
     667           0 :             inschr.page = 0x21;
     668           0 :             enabled = true;
     669             :         }
     670           0 :         if ( !enabled && inschr.dsp_mode==d_kuten ) {
     671           0 :             GGadgetSetChecked(GWidgetGetControl(inschr.icw,INSCHR_Hex),true);
     672           0 :             inschr.dsp_mode = d_hex;
     673             :         }
     674           0 :         GGadgetSetEnabled(GWidgetGetControl(inschr.icw,INSCHR_KuTen),enabled);
     675           0 :         InsChrSetNextPrev();
     676           0 :         InsChrRedraw();
     677           0 :         if ( ch>0 )          /* Must happen after we set display mode */
     678           0 :             _InsChrSetSelChar(ch,false);
     679           0 :         InsChrFigureShow();
     680             :     }
     681           0 : }
     682             : 
     683           0 : static void InsChrCharset() {
     684           0 :     int map = mapFromIndex(GGadgetGetFirstListSelectedItem(GWidgetGetControl(inschr.icw,INSCHR_CharSet)));
     685           0 :     if ( map!=-1 )
     686           0 :         InsChrSetCharset(map);
     687             :     else {
     688             :         int i;
     689           0 :         for ( i=0; encodingnames[i].name!=NULL && encodingnames[i].map!=inschr.map; ++i );
     690           0 :         if ( encodingnames[i].name!=NULL )
     691           0 :             GGadgetSelectOneListItem(GWidgetGetControl(inschr.icw,INSCHR_CharSet),i);
     692             :     }
     693           0 : }
     694             : 
     695           0 : static void InsChrShow(void) {
     696           0 :     long ch = InsChrUniVal();
     697             :     int i;
     698             : 
     699           0 :     if ( ch>0 ) {
     700           0 :         if ( !InsChrInCurrentEncoding() ) {
     701           0 :             InsChrSetCharset(em_unicode);
     702           0 :             for ( i=0; encodingnames[i].name!=NULL && strcmp(encodingnames[i].name,"Unicode")!=0; ++i );
     703           0 :             if ( encodingnames[i].name!=NULL )
     704           0 :                 GGadgetSelectOneListItem(GWidgetGetControl(inschr.icw,INSCHR_CharSet),i);
     705             :         }
     706           0 :         _InsChrSetSelChar(ch, true);
     707             :     }
     708           0 : }
     709             : 
     710           0 : static void InsChrInsert(void) {
     711           0 :     long ch = InsChrUniVal();
     712             :     GEvent e;
     713             : 
     714           0 :     e.type = et_char;
     715           0 :     e.w = GWidgetGetPreviousFocusTopWindow();
     716           0 :     if ( e.w==NULL || e.w==inschr.icw ) {
     717           0 :         GDrawBeep(NULL);
     718           0 : return;
     719             :     }
     720           0 :     e.u.chr.state = 0;
     721           0 :     e.u.chr.x = e.u.chr.y = -1;
     722           0 :     e.u.chr.keysym = 0;
     723           0 :     e.u.chr.chars[0] = ch;
     724           0 :     e.u.chr.chars[1] = '\0';
     725           0 :     GDrawPostEvent(&e);
     726             : }
     727             : 
     728           0 : static void InsChrExpose( GWindow pixmap, GRect *rect) {
     729             :     GRect old, r;
     730             :     int i, j;
     731             :     int highi, lowi, is94x94;
     732             : 
     733           0 :     if ( inschr.pageable ) {
     734             :         char buffer[20]; unichar_t ubuf[20];
     735           0 :         GDrawPushClip(pixmap,rect,&old);
     736           0 :         GDrawSetFont(pixmap,inschr.smallfont);
     737           0 :         if ( inschr.dsp_mode==d_hex || inschr.dsp_mode == d_unicode )
     738           0 :             sprintf( buffer, "Page: 0x%02X", inschr.page );
     739             :         else
     740           0 :             sprintf( buffer, "Page: %d", inschr.page );
     741           0 :         uc_strcpy(ubuf,buffer);
     742           0 :         GDrawDrawText(pixmap,GDrawPointsToPixels(pixmap,6),
     743           0 :                 GDrawPointsToPixels(pixmap,90)+inschr.sas,
     744             :                 ubuf, -1, 0x000000 );
     745           0 :         GDrawPopClip(pixmap,&old);
     746             :     }
     747           0 :     if ( rect->y+rect->height < inschr.ybase )
     748           0 : return;
     749           0 :     if ( rect->y < inschr.ybase ) {
     750           0 :         r = *rect; rect = &r;
     751           0 :         rect->height -= (inschr.ybase-rect->y);
     752           0 :         rect->y = inschr.ybase;
     753             :     }
     754           0 :     GDrawPushClip(pixmap,rect,&old);
     755           0 :     for ( i=0; i<17; ++i ) {
     756           0 :         GDrawDrawLine(pixmap,0,inschr.ybase+i*inschr.spacing,
     757           0 :                 inschr.width,inschr.ybase+i*inschr.spacing, 0x000000);
     758           0 :         GDrawDrawLine(pixmap,i*inschr.spacing,inschr.ybase,
     759           0 :                 i*inschr.spacing,inschr.height, 0x000000);
     760             :     }
     761           0 :     GDrawSetFont(pixmap,inschr.font);
     762             : 
     763           0 :     lowi = 0; highi = 16; is94x94 = false;
     764           0 :     if ( inschr.map>em_max ) {
     765           0 :         highi = (unicode_ranges[inschr.map-em_max-1].len+15)/16;
     766           0 :     } else if ( inschr.map==em_jis208 || inschr.map==em_jis212 ||
     767           0 :             inschr.map==em_gb2312 || inschr.map==em_ksc5601 ) {
     768           0 :         lowi=2; highi = 8;
     769           0 :         is94x94 = true;
     770           0 :     } else if ( inschr.map==em_big5 ) {
     771           0 :         lowi=4; highi = 16;
     772             :     }
     773           0 :     for ( i=lowi; i<highi; ++i ) for ( j=0; j<16; ++j ) {
     774             :         unichar_t buf[1];
     775             :         int width;
     776           0 :         if ( j==15 && i==7 && is94x94 )
     777           0 :     break;
     778           0 :         if ( j==0 && i==2 && is94x94 )
     779           0 :     continue;
     780           0 :         if (( i==8 || i==9 ) &&
     781           0 :                 (inschr.map<=em_iso8859_15 ||
     782           0 :                  (inschr.map==em_unicode && inschr.page==0 )))
     783           0 :     continue;
     784           0 :         buf[0] = InsChrMapChar(i*16+j);
     785           0 :         if ( buf[0]==0xad ) buf[0] = '-';       /* 0xad usually doesn't print */
     786           0 :         width = GDrawGetTextWidth(pixmap,buf,1);
     787           0 :         GDrawDrawText(pixmap,
     788           0 :                 j*inschr.spacing+(inschr.spacing-width)/2,
     789           0 :                 i*inschr.spacing+inschr.ybase+inschr.as+4,
     790             :                 buf,1,0x000000);
     791             :     }
     792           0 :     if ( inschr.flash )
     793           0 :         InsChrXorChar(pixmap,inschr.x,inschr.y);
     794           0 :     GDrawPopClip(pixmap,&old);
     795             : }
     796             : 
     797           0 : static void InsChrTimer() {
     798           0 :     GDrawCancelTimer(inschr.flash_time);
     799           0 :     if ( inschr.flash ) {
     800           0 :         InsChrXorChar(inschr.icw,inschr.x,inschr.y);
     801           0 :         inschr.flash = false;
     802             :     }
     803           0 : }
     804             : 
     805           0 : static void InsChrMouseDown(GWindow gw, GEvent *event) {
     806             :     int x,y;
     807             :     int ch;
     808             :     char buffer[20]; unichar_t ubuffer[20];
     809             : 
     810           0 :     x= event->u.mouse.x/inschr.spacing;
     811           0 :     y= (event->u.mouse.y-inschr.ybase)/inschr.spacing;
     812           0 :     ch = 256*inschr.page + (y*16)+x;
     813             :     /* Is it on a border line? */
     814           0 :     if ( y<0 || x*inschr.spacing==event->u.mouse.x ||
     815           0 :             y*inschr.spacing==event->u.mouse.y-inschr.ybase )
     816           0 : return;
     817             :     /* Is it a valid character in the current map? */
     818           0 :     if ( inschr.map>em_max ) {
     819           0 :         if ( ch>unicode_ranges[inschr.map-em_max-1].len )
     820           0 : return;
     821           0 :     } else if ( (ch<32 && inschr.map!=em_mac) || ch==127 ||
     822           0 :             (inschr.map<em_first2byte && inschr.map!=em_mac &&
     823           0 :                 inschr.map!=em_win && inschr.map!=em_symbol &&
     824           0 :                 inschr.map!=em_user &&
     825           0 :                 ch>=128 && ch<160) ||
     826           0 :             (inschr.map>=em_first2byte && inschr.map<=em_gb2312 &&
     827           0 :                 ((ch&0xff)<0x21 || (ch&0xff)>0x7e)) )
     828           0 : return;
     829           0 :     inschr.mouse_down = true;
     830           0 :     inschr.mouse_in = true;
     831           0 :     inschr.x = x;
     832           0 :     inschr.y = y;
     833             : 
     834           0 :     InsChrXorChar(inschr.icw,x,y);
     835             : 
     836           0 :     if ( inschr.dsp_mode==d_unicode || inschr.map>em_max )
     837           0 :         sprintf( buffer, "U+%04lx", InsChrToUni(ch) );
     838           0 :     else if ( inschr.dsp_mode==d_hex )
     839           0 :         sprintf( buffer, inschr.map<em_first2byte?"0x%02x":"0x%04x", ch );
     840           0 :     else if ( inschr.dsp_mode==d_dec )
     841           0 :         sprintf( buffer, "%d", ch );
     842           0 :     else if ( inschr.map==em_unicode )
     843           0 :         sprintf( buffer, "%d,%d", (ch>>8), (ch&0xff) );
     844             :     else
     845           0 :         sprintf( buffer, "%d,%d", (ch>>8)-0x21, (ch&0xff)-0x21 );
     846           0 :     uc_strcpy(ubuffer,buffer);
     847           0 :     GGadgetSetTitle(GWidgetGetControl(inschr.icw,INSCHR_Char),ubuffer);
     848           0 :     InsChrFigureShow();
     849             : }
     850             : 
     851           0 : static void uc_annot_strncat(unichar_t *to, const char *from, int len) {
     852             :     register unichar_t ch;
     853             : 
     854           0 :     to += u_strlen(to);
     855           0 :     while ( (ch = utf8_ildb(&from)) != '\0' && --len>=0 )
     856           0 :         *(to++) = ch;
     857           0 :     *to = 0;
     858           0 : }
     859             : 
     860           0 : static void InsChrMouseMove(GWindow gw, GEvent *event) {
     861             :     int x, y;
     862             : 
     863           0 :     x= event->u.mouse.x/inschr.spacing;
     864           0 :     y= (event->u.mouse.y-inschr.ybase)/inschr.spacing;
     865           0 :     if ( !inschr.mouse_down && event->u.mouse.y>inschr.ybase ) {
     866           0 :         int uch = InsChrMapChar(16*y + x);
     867             :         static unichar_t space[600];
     868             :         char cspace[40];
     869             :         char *uniname;
     870             :         char *uniannot;
     871             : 
     872           0 :         if ( (uniname=unicode_name(uch))!=NULL ) {
     873           0 :             uc_strncpy(space, uniname, 550);
     874           0 :             sprintf( cspace, " U+%04X", uch );
     875           0 :             uc_strcpy(space+u_strlen(space),cspace);
     876           0 :             free(uniname);
     877             :         } else {
     878           0 :             if ( uch<160 )
     879           0 :                 sprintf(cspace, "Control Char U+%04X ", uch);
     880           0 :             else if ( uch>=0x3400 && uch<=0x4db5 )
     881           0 :                 sprintf(cspace, "CJK Ideograph Extension A U+%04X ", uch);
     882           0 :             else if ( uch>=0x4E00 && uch<=0x9FA5 )
     883           0 :                 sprintf(cspace, "CJK Ideograph U+%04X ", uch);
     884           0 :             else if ( uch>=0xAC00 && uch<=0xD7A3 )
     885           0 :                 sprintf(cspace, "Hangul Syllable U+%04X ", uch);
     886           0 :             else if ( uch>=0xD800 && uch<=0xDB7F )
     887           0 :                 sprintf(cspace, "Non Private Use High Surrogate U+%04X ", uch);
     888           0 :             else if ( uch>=0xDB80 && uch<=0xDBFF )
     889           0 :                 sprintf(cspace, "Private Use High Surrogate U+%04X ", uch);
     890           0 :             else if ( uch>=0xDC00 && uch<=0xDFFF )
     891           0 :                 sprintf(cspace, "Low Surrogate U+%04X ", uch);
     892           0 :             else if ( uch>=0xE000 && uch<=0xF8FF )
     893           0 :                 sprintf(cspace, "Private Use U+%04X ", uch);
     894             :             else
     895           0 :                 sprintf(cspace, "Unencoded Unicode U+%04X ", uch);
     896           0 :             uc_strcpy(space,cspace);
     897             :         }
     898           0 :         if ( (uniannot=unicode_annot(uch))!=NULL ) {
     899           0 :             int left = sizeof(space)/sizeof(space[0]) - u_strlen(space)-1;
     900           0 :             if ( left>4 ) {
     901           0 :                 uc_strcat(space,"\n");
     902           0 :                 uc_annot_strncat(space, uniannot, left-2);
     903             :             }
     904           0 :             free(uniannot);
     905             :         }
     906           0 :         GGadgetPreparePopup(gw,space);
     907           0 :     } else if ( inschr.mouse_down ) {
     908           0 :         int in = true;
     909           0 :         if ( y<0 || x*inschr.spacing==event->u.mouse.x ||
     910           0 :                 y*inschr.spacing==event->u.mouse.y-inschr.ybase ||
     911           0 :                 x!=inschr.x || y!=inschr.y )
     912           0 :             in = false;
     913           0 :         if ( in!=inschr.mouse_in ) {
     914           0 :             InsChrXorChar(inschr.icw,inschr.x,inschr.y);
     915           0 :             inschr.mouse_in = in;
     916             :         }
     917             :     }
     918           0 : }
     919             : 
     920           0 : static void InsChrMouseUp(GWindow gw, GEvent *event) {
     921           0 :     if ( !inschr.mouse_down )
     922           0 : return;
     923           0 :     InsChrMouseMove(gw,event);
     924           0 :     inschr.mouse_down = false;
     925           0 :     if ( inschr.mouse_in ) {
     926           0 :         InsChrXorChar(inschr.icw,inschr.x,inschr.y);
     927             : 
     928           0 :         if ( !(event->u.mouse.state&ksm_control) )
     929           0 :             InsChrInsert();
     930             :     }
     931             : }
     932             : 
     933           0 : static int inschr_e_h(GWindow gw, GEvent *event) {
     934           0 :     GGadgetPopupExternalEvent(event);
     935           0 :     switch ( event->type ) {
     936             :       case et_close:
     937           0 :         inschr.hidden = true;
     938           0 :         GDrawSetVisible(gw,false);
     939           0 :       break;
     940             :       case et_expose:
     941           0 :         InsChrExpose(gw,&event->u.expose.rect);
     942           0 :       break;
     943             :       case et_mousedown:
     944           0 :           InsChrMouseDown(gw,event);
     945           0 :       break;
     946             :       case et_mousemove:
     947           0 :           InsChrMouseMove(gw,event);
     948           0 :       break;
     949             :       case et_mouseup:
     950           0 :           InsChrMouseUp(gw,event);
     951           0 :       break;
     952             :       case et_char:
     953           0 :           if ( event->u.chr.chars[0]=='\r' )
     954           0 :                 InsChrShow();
     955           0 :       break;
     956             :       case et_timer:
     957           0 :           InsChrTimer();
     958           0 :       break;
     959             :       case et_controlevent:
     960           0 :         if ( event->u.control.subtype == et_buttonactivate ) {
     961           0 :             switch ( GGadgetGetCid(event->u.control.g)) {
     962             :               case INSCHR_Close:
     963           0 :                 inschr.hidden = true;
     964           0 :                 GDrawSetVisible(gw,false);
     965           0 :               break;
     966             :               case INSCHR_Next:
     967           0 :                 ++inschr.page;
     968           0 :                 InsChrSetNextPrev();
     969           0 :                 InsChrRedraw();
     970           0 :               break;
     971             :               case INSCHR_Prev:
     972           0 :                 --inschr.page;
     973           0 :                 InsChrSetNextPrev();
     974           0 :                 InsChrRedraw();
     975           0 :               break;
     976             :               case INSCHR_Show:
     977           0 :                 InsChrShow();
     978           0 :               break;
     979             :               case INSCHR_Insert:
     980           0 :                 InsChrInsert();
     981           0 :               break;
     982             :             }
     983           0 :         } else if ( event->u.control.subtype == et_radiochanged ) {
     984           0 :             int cid = GGadgetGetCid(event->u.control.g);
     985           0 :             InsChrSetFormat(cid==INSCHR_Hex?d_hex:
     986             :                             cid==INSCHR_Dec?d_dec:
     987             :                             cid==INSCHR_Unicode?d_unicode:
     988             :                                     d_kuten);
     989           0 :         } else if ( event->u.control.subtype == et_textchanged ) {
     990           0 :             if ( !InsChrFigureShow()) {
     991             :                 /*GDrawBeep(NULL)*/
     992             :                 ;
     993             :             }
     994           0 :         } else if ( event->u.control.subtype == et_listselected ) {
     995           0 :             InsChrCharset();
     996             :         }
     997           0 :       break;
     998             :     }
     999           0 : return( true );
    1000             : }
    1001             : 
    1002             : static unichar_t inschar[] = { 'I', 'n', 's', 'e', 'r', 't', ' ', 'C', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', '\0' };
    1003           0 : void GWidgetCreateInsChar(void) {
    1004             :     GTextInfo charsetnames[sizeof(encodingnames)/sizeof(struct namemap)];
    1005             :     static GTextInfo labels[11] = {
    1006             :         { (unichar_t *) "Character Set", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
    1007             :         { (unichar_t *) "Character", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1008             :         { (unichar_t *) "Hex", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1009             :         { (unichar_t *) "Dec", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1010             :         { (unichar_t *) "Unicode", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1011             :         { (unichar_t *) "Ku Ten", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1012             :         { (unichar_t *) "< Prev", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1013             :         { (unichar_t *) "Next >", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1014             :         { (unichar_t *) "Insert", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1015             :         { (unichar_t *) "Close", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1016             :         { (unichar_t *) "Show", NULL, COLOR_UNKNOWN, COLOR_UNKNOWN, NULL, NULL, 0,0,0,0,0,0, 1, 0, 0, '\0' },
    1017             :     };
    1018             :     static GGadgetCreateData gcd[] = {
    1019             :         { GLabelCreate, { { 6, 6, 0, 0 }, NULL, 'e', 0, 0, 0, 0, &labels[0], { NULL }, gg_visible | gg_enabled | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1020             :         { GListButtonCreate, { { 6, 21, 168, 0 }, NULL, 'e', 0, 0, 0, INSCHR_CharSet, NULL, { NULL }, gg_visible | gg_enabled | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1021             :         { GLabelCreate, { { 6, 50, 0, 0 }, NULL, 'C', 0, 0, 0, 0, &labels[1], { NULL }, gg_visible | gg_enabled | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1022             :         /* gg_textarea_wrap means (here) that we should not invoke the InsChar Hook for selections */
    1023             :         { GTextFieldCreate, { { 6, 64, 65, 0 }, NULL, 'C', 0, 0, 0, INSCHR_Char, NULL, { NULL }, gg_visible | gg_enabled | gg_pos_use0 | gg_textarea_wrap, NULL, NULL }, NULL, NULL },
    1024             :         { GRadioCreate, { { 85, 48, 0, 0 }, NULL, 'H', 0, 0, 0, INSCHR_Hex, &labels[2], { NULL }, gg_visible | gg_enabled | gg_cb_on | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1025             :         { GRadioCreate, { { 85, 68, 0, 0 }, NULL, 'D', 0, 0, 0, INSCHR_Dec, &labels[3], { NULL }, gg_visible | gg_enabled | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1026             :         { GRadioCreate, { { 127, 48, 0, 0 }, NULL, 'U', 0, 0, 0, INSCHR_Unicode, &labels[4], { NULL }, gg_visible | gg_enabled | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1027             :         { GRadioCreate, { { 127, 68, 0, 0 }, NULL, 'K', 0, 0, 0, INSCHR_KuTen, &labels[5], { NULL }, gg_visible | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1028             :         { GButtonCreate, { { 73, 93, 50, 0 }, NULL, 'P', 0, 0, 0, INSCHR_Prev, &labels[6], { NULL }, gg_visible | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1029             :         { GButtonCreate, { { 137, 93, 50, 0 }, NULL, 'N', 0, 0, 0, INSCHR_Next, &labels[7], { NULL }, gg_visible | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1030             :         { GButtonCreate, { { 196-3, 6-3, 50+6, 0 }, NULL, 'I', 0, 0, 0, INSCHR_Insert, &labels[8], { NULL }, gg_visible | gg_enabled | gg_but_default | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1031             :         { GButtonCreate, { { 196, 36, 50, 0 }, NULL, 'l', 0, 0, 0, INSCHR_Close, &labels[9], { NULL }, gg_visible | gg_enabled | gg_but_cancel | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1032             :         { GButtonCreate, { { 196, 64, 50, 0 }, NULL, 'S', 0, 0, 0, INSCHR_Show, &labels[10], { NULL }, gg_visible | gg_pos_use0, NULL, NULL }, NULL, NULL },
    1033             :         GGADGETCREATEDATA_EMPTY
    1034             :     };
    1035             : #define keyboard_width 15
    1036             : #define keyboard_height 9
    1037             :     static unsigned char keyboard_bits[] = {
    1038             :        0xff, 0x7f, 0x01, 0x40, 0x55, 0x55, 0x01, 0x40, 0xad, 0x5a, 0x01, 0x40,
    1039             :        0xd5, 0x55, 0x01, 0x40, 0xff, 0x7f};
    1040             :     GRect pos;
    1041             :     GWindowAttrs wattrs;
    1042             :     int i;
    1043             :     FontRequest rq;
    1044             :     int as, ds, ld;
    1045             :     static int inited= false;
    1046             : 
    1047           0 :     if ( !inited ) {
    1048           0 :         inituninameannot();
    1049           0 :         inited = true;
    1050             :     }
    1051           0 :     if ( inschr.icw!=NULL ) {
    1052           0 :         inschr.hidden = false;
    1053           0 :         GDrawSetVisible(inschr.icw,true);
    1054           0 :         GDrawRaise(inschr.icw);
    1055             :     } else {
    1056           0 :         memset(charsetnames,'\0',sizeof(charsetnames));
    1057           0 :         for ( i=0; encodingnames[i].name!=NULL; ++i ) {
    1058           0 :             if ( *encodingnames[i].name=='-' )
    1059           0 :                 charsetnames[i].line = true;
    1060             :             else {
    1061           0 :                 charsetnames[i].text = (unichar_t *) (encodingnames[i].name);
    1062           0 :                 charsetnames[i].text_is_1byte = true;
    1063             :             }
    1064             :         }
    1065           0 :         gcd[1].gd.u.list = charsetnames;
    1066             : 
    1067           0 :         inschr.spacing = GDrawPointsToPixels(NULL,16);
    1068           0 :         inschr.ybase = GDrawPointsToPixels(NULL,123);
    1069           0 :         pos.x = pos.y = 0;
    1070           0 :         inschr.width = pos.width = 16*inschr.spacing+1;
    1071           0 :         inschr.height = pos.height = inschr.ybase + pos.width;
    1072           0 :         memset(&wattrs,0,sizeof(wattrs));
    1073           0 :         wattrs.mask = wam_events|wam_cursor|wam_wtitle|wam_isdlg|wam_notrestricted|wam_icon;
    1074           0 :         wattrs.event_masks = 0xffffffff;
    1075           0 :         wattrs.cursor = ct_pointer;
    1076           0 :         wattrs.window_title = inschar;
    1077           0 :         wattrs.is_dlg = true;
    1078           0 :         wattrs.not_restricted = true;
    1079           0 :         wattrs.icon = GDrawCreateBitmap(NULL,keyboard_width,keyboard_height,keyboard_bits);
    1080           0 :         inschr.icw = GDrawCreateTopWindow(NULL,&pos,inschr_e_h,&inschr,&wattrs);
    1081           0 :         GGadgetsCreate(inschr.icw,gcd);
    1082             : 
    1083           0 :         memset(&rq,0,sizeof(rq));
    1084           0 :         rq.utf8_family_name = copy(GResourceFindString("InsChar.Family"));
    1085           0 :         if ( rq.utf8_family_name==NULL )
    1086           0 :             rq.utf8_family_name = SANS_UI_FAMILIES;
    1087           0 :         rq.point_size = /*15*/12;
    1088           0 :         rq.weight = 400;
    1089           0 :         rq.style = 0;
    1090           0 :         inschr.font = GDrawInstanciateFont(inschr.icw,&rq);
    1091           0 :         GDrawWindowFontMetrics(inschr.icw,inschr.font,&as, &ds, &ld);
    1092           0 :         inschr.as = as;
    1093           0 :         rq.point_size = 8;
    1094           0 :         inschr.smallfont = GDrawInstanciateFont(inschr.icw,&rq);
    1095           0 :         GDrawWindowFontMetrics(inschr.icw,inschr.smallfont,&as, &ds, &ld);
    1096           0 :         inschr.sas = as;
    1097             : 
    1098           0 :         GDrawSetVisible(inschr.icw,true);
    1099             :     }
    1100           0 :     if ( inschr.sel_char > 0 )
    1101           0 :         _InsChrSetSelChar(inschr.sel_char,true);
    1102             :     else
    1103           0 :         InsChrFigureShow();
    1104           0 : }
    1105             : 
    1106           0 : void GInsCharSetChar(unichar_t ch) {
    1107           0 :     _InsChrSetSelChar(ch,true);
    1108           0 : }

Generated by: LCOV version 1.10