"Fossies" - the Fresh Open Source Software Archive

Member "yudit-3.0.7/gui/SKMapPanel.cpp" (7 Jun 2020, 11907 Bytes) of package /linux/misc/yudit-3.0.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "SKMapPanel.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.0.5_vs_3.0.7.

    1 /** 
    2  *  Yudit Unicode Editor Source File
    3  *
    4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>  
    5  *
    6  *  This program is free software; you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License, version 2,
    8  *  dated June 1991. See file COPYYING for details.
    9  *
   10  *  This program is distributed in the hope that it will be useful,
   11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *  GNU General Public License for more details.
   14  *
   15  *  You should have received a copy of the GNU General Public License
   16  *  along with this program; if not, write to the Free Software
   17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18  */
   19 
   20 #include "gui/SKMapPanel.h"
   21 #include "swidget/SIconFactory.h"
   22 
   23 #include "stoolkit/SUtil.h"
   24 #include "stoolkit/SEncoder.h"
   25 
   26 SKMapPanel::SKMapPanel (void)
   27 {
   28   SPanel::forceLayout (SLayout (SDimension (2000, 3000)));
   29   selectedKMap = -1;
   30   titleLabel = new SLabel (translate ("Current KMap:"));
   31   add (titleLabel);
   32   currentLabel = new SLabel ("");
   33   sampleTitleLabel = new SLabel (translate ("Characters:"));
   34   sampleLabel = new SLabel ("");
   35   listBox = new SListBox(translate ("Available KMaps"));
   36   listBox->setListListener(this);
   37   replaceButton = new SButton ("", SIconFactory::getIcon("Right"));
   38   replaceButton->setButtonListener(this);
   39   SStringVector v;
   40   v.append (translate ("F-Key"));
   41   v.append (translate ("Current KMaps"));
   42   kmapTable = new STextTable (v);
   43   kmapTable->setListListener(this);
   44   SStringVector s;
   45   s.append (translate ("Key Input"));
   46   s.append (translate ("Output"));
   47   sample = new STextTable (s);
   48   sample->setListListener(this);
   49   
   50   add (currentLabel);
   51   add (sampleLabel);
   52   add (sampleTitleLabel);
   53   add (listBox);
   54   add (replaceButton);
   55   add (kmapTable);
   56   add (sample);
   57   SStringVector bext = SEncoder::external();
   58   
   59   SBinHashtable<bool> ph;
   60   unsigned int ib;
   61   unsigned int ic;
   62   for (ib=0; ib<bext.size(); ib++)
   63   {
   64     /* this is an input method and it is misleading. */
   65     if (bext[ib].match("jis*"))
   66     {
   67       continue;
   68     }
   69     else if (bext[ib].match("gb-*"))
   70     {
   71       continue;
   72     }
   73     else if (bext[ib].match("ksc-*"))
   74     {
   75       continue;
   76     }
   77     else if (bext[ib].match("ksx-*"))
   78     {
   79       continue;
   80     }
   81     else if (bext[ib].match("cp-*"))
   82     {
   83       continue;
   84     }
   85     else if (bext[ib].match("koi8-*"))
   86     {
   87       continue;
   88     }
   89     else if (bext[ib].match("IS_*")) /* ISCII maps */
   90     {
   91       continue;
   92     }
   93     else if (bext[ib].match("iso-*"))
   94     {
   95       continue;
   96     }
   97     else if (bext[ib] == "precompose")
   98     {
   99       continue;
  100     }
  101     else if (bext[ib] == "unicode")
  102     {
  103       continue;
  104     }
  105     else if (bext[ib] == "category")
  106     {
  107       continue;
  108     }
  109     else if (bext[ib] == "cluster")
  110     {
  111       continue;
  112     }
  113     else if (bext[ib] == "indic")
  114     {
  115       continue;
  116     }
  117     else if (bext[ib] == "wingreek")
  118     {
  119       continue;
  120     }
  121     ph.put (bext[ib], true);
  122   }
  123   ph.remove ("kinput2");
  124   ph.remove ("WindowsIM");
  125   ph.remove ("straight");
  126   ph.remove ("freehand");
  127   ph.remove ("None");
  128   ph.remove ("none");
  129   ph.remove ("unicode");
  130   ph.remove ("Unicode");
  131   /* these are converter maps, unlikely to work as keymaps */
  132   ph.remove ("mirroring");
  133   ph.remove ("nastaliq");
  134   ph.remove ("rovas");
  135   ph.remove ("shape");
  136   ph.remove ("tcvn");
  137   ph.remove ("viscii");
  138   ph.remove ("windows-1255");
  139   ph.remove ("tscii");
  140   ph.remove ("mik");
  141 
  142   SStringVector addEnc;
  143   for (ic=0; ic<ph.size(); ic++)
  144   {
  145     for (ib=0; ib<ph.size(ic); ib++)
  146     {
  147        bool vle = ph.get (ic, ib);
  148        if (vle)
  149        {
  150          addEnc.append (ph.key (ic, ib));
  151        }
  152     }
  153   }
  154   addEnc.sort ();
  155 #ifdef USE_WINAPI
  156   addEnc.insert (0, "WindowsIM");
  157 #else
  158   addEnc.insert (0, "kinput2");
  159 #endif
  160   addEnc.insert (0, "unicode");
  161   addEnc.insert (0, "freehand");
  162   addEnc.insert (0, "straight");
  163   addEnc.insert (0, "None");
  164   allinputs = addEnc;
  165   listBox->setText (allinputs);
  166   //recalc();
  167 }
  168 
  169 SKMapPanel::~SKMapPanel ()
  170 {
  171 }
  172 
  173 void
  174 SKMapPanel::setList (const SStringVector& _kmapList, int selected)
  175 {
  176   if (_kmapList.size()==0) return;
  177   SStringVector key;
  178   selectedKMap = selected;
  179   kmapList = _kmapList;
  180 
  181   currentLabel->setText (kmapList[selected]);
  182   char s[64];
  183   unsigned int i;
  184   for (i=0; i<kmapList.size(); i++)
  185   {
  186     sprintf (s, "F%u", i+1);
  187     key.append (s);
  188   }
  189   while (i<12)
  190   {
  191     sprintf (s, "F%u", i+1);
  192     key.append (s);
  193     kmapList.append ("None");
  194     i++;
  195   }
  196   SStringTable t;
  197   t.append (key);
  198   t.append (kmapList);
  199 
  200   kmapTable->setText (t);
  201   kmapTable->selectItem (selected);
  202   getSample();
  203 }
  204 
  205 void
  206 SKMapPanel::setFont (const SString& font, double fontSize)
  207 {
  208   titleLabel->setFont (font, fontSize);
  209   currentLabel->setFont (font, fontSize);
  210   sampleLabel->setFont (font, fontSize);
  211   sampleTitleLabel->setFont (font, fontSize);
  212   listBox->setFont (font, fontSize);
  213   replaceButton->setFont (font, fontSize);
  214   kmapTable->setFont (font, fontSize);
  215   sample->setFont (font, fontSize);
  216   //recalc();
  217 }
  218 
  219 void
  220 SKMapPanel::setFontSize (double fontSize)
  221 {
  222   titleLabel->setFontSize (fontSize);
  223   currentLabel->setFontSize (fontSize);
  224   sampleLabel->setFontSize (fontSize);
  225   sampleTitleLabel->setFontSize (fontSize);
  226   listBox->setFontSize (fontSize);
  227   replaceButton->setFontSize (fontSize);
  228   kmapTable->setFontSize (fontSize);
  229   sample->setFontSize (fontSize);
  230   //recalc();
  231 }
  232 
  233 void
  234 SKMapPanel::setBackground (const SColor& bg)
  235 {
  236   SPanel::setBackground(bg);
  237 }
  238 
  239 void
  240 SKMapPanel::setForeground (const SColor& lrfg, const SColor& rlfg)
  241 {
  242   kmapTable->setForeground (lrfg, rlfg);
  243   sample->setForeground (lrfg, rlfg);
  244 }
  245 
  246 const SStringVector&
  247 SKMapPanel::getKMapList() const
  248 {
  249   return kmapList;
  250 }
  251 int
  252 SKMapPanel::getSelectedKMap() const
  253 {
  254   return selectedKMap;
  255 }
  256 
  257 void
  258 SKMapPanel::buttonPressedAccel (void* source, const SAccelerator* acc)
  259 {
  260   int ksel = selectedKMap;
  261   int lsel = listBox->textList->getLastSelected();
  262   if (ksel < 0 || lsel < 0)
  263   {
  264     return;
  265   }
  266   SString si = listBox->textList->getLastSelectedText();
  267   
  268   SStringVector l = kmapList;
  269   l.remove ((unsigned int) ksel);
  270   l.insert ((unsigned int) ksel, si);
  271   setList (l, ksel);
  272 }
  273 
  274 void
  275 SKMapPanel::itemSelected (void* source, const SAccelerator* acc)
  276 {
  277   if (source == kmapTable)
  278   {
  279     if (kmapTable->getLastSelected()>=0)
  280     {
  281        selectedKMap = kmapTable->getLastSelected();
  282        currentLabel->setText (kmapList[(unsigned int)selectedKMap]);
  283        getSample ();
  284     }
  285   }
  286   else if (source == sample)
  287   {
  288     if (sample->getLastSelected()>=0)
  289     {
  290        sampleLabel->setText (unicodeValueOf(sampleList[
  291                 (unsigned int)sample->getLastSelected()]));
  292     }
  293   }
  294 }
  295 
  296 void
  297 SKMapPanel::setTitleForeground (const SColor& fg)
  298 {
  299   listBox->setForeground (fg, fg);
  300   titleLabel->setForeground (fg);
  301   sampleTitleLabel->setForeground (fg);
  302   listBox->setLabelForeground (fg);
  303   kmapTable->setLabelForeground (fg);
  304   sample->setLabelForeground (fg);
  305 }
  306 
  307 void
  308 SKMapPanel::setSliderBackground (const SColor& bg)
  309 {
  310   listBox->setSliderBackground (bg);
  311   kmapTable->setSliderBackground (bg);
  312   sample->setSliderBackground (bg);
  313 }
  314 
  315 void
  316 SKMapPanel::setLabelForeground (const SColor& fg)
  317 {
  318   replaceButton->setForeground (fg);
  319   currentLabel->setForeground (fg);
  320   sampleLabel->setForeground (fg);
  321 }
  322 
  323 /**
  324  * recalculate the layout of components and set preferred size.
  325  * It calculates preferred size as well.
  326  */
  327 void
  328 SKMapPanel::recalc()
  329 {
  330   SDimension tld = titleLabel->getPreferredSize();
  331   SDimension lbd = listBox->getPreferredSize();
  332   SDimension bd = replaceButton->getPreferredSize();
  333   SDimension kd = kmapTable->getPreferredSize();
  334   SDimension sd = sample->getPreferredSize();
  335   unsigned int w = lbd.width + 2 + bd.width + 2 + kd.width + 2 + sd.width;
  336   unsigned int h = tld.height + 2 + lbd.height;
  337   if ((w*2)/4 + 10> h) h = (w*2)/4+ 10;
  338 
  339   preferredSize = SDimension (w, h);
  340   SDimension d = preferredSize;
  341 
  342   titleLabel->setLayout (
  343     SLayout (
  344        SLocation (0, 0),
  345        SLocation (tld.width, tld.height),
  346        SLocation (0, 0),
  347        SLocation (100, 0)
  348     )
  349   );
  350   currentLabel->setLayout (
  351     SLayout (
  352        SLocation (tld.width+2, 0),
  353        SLocation (d.width/2 - 2, tld.height),
  354        SLocation (0, 0),
  355        SLocation (50, 0)
  356     )
  357   );
  358   unsigned int tw = sampleTitleLabel->getPreferredSize().width;
  359   sampleTitleLabel->setLayout (
  360     SLayout (
  361        SLocation (d.width/2, 0),
  362        SLocation (d.width/2 + tw, tld.height),
  363        SLocation (50, 0),
  364        SLocation (50, 0)
  365     )
  366   );
  367   sampleLabel->setLayout (
  368     SLayout (
  369        SLocation (d.width/2 + tw + 2, 0),
  370        SLocation (d.width, tld.height),
  371        SLocation (50, 0),
  372        SLocation (100, 0)
  373     )
  374   );
  375   unsigned int cx = (lbd.width * d.width) / w;
  376   listBox->setLayout (
  377     SLayout (
  378        SLocation (0, tld.height+5),
  379        SLocation (cx, d.height-10),
  380        SLocation (0, 0),
  381        SLocation (20, 100)
  382     )
  383   );
  384   cx = cx + 2;
  385   replaceButton->setLayout (
  386     SLayout (
  387        SLocation (cx, d.height/2-10),
  388        SLocation (cx + bd.width, d.height/2 + bd.height-10),
  389        SLocation (20, 50),
  390        SLocation (20, 50)
  391     )
  392   );
  393   cx += bd.width + 2;
  394   kmapTable->setLayout (
  395     SLayout (
  396        SLocation (cx, tld.height+5),
  397        SLocation (cx + (kd.width * d.width)/w , d.height-10),
  398        SLocation (20, 0),
  399        SLocation (40, 100)
  400     )
  401   );
  402   cx += (kd.width * d.width)/w + 2;
  403   sample->setLayout (
  404     SLayout (
  405        SLocation (cx, tld.height+5),
  406        SLocation (cx + (sd.width * d.width)/w , d.height-10),
  407        SLocation (40, 0),
  408        SLocation (100, 100)
  409     )
  410   );
  411   /* save current */
  412   SLayout goodlayout = layout;
  413 
  414   /* pretend we have this layout */
  415   SPanel::forceLayout (preferredSize);
  416 
  417   /* accept old layout */
  418   SPanel::setLayout (goodlayout);
  419   //resize (preferredSize);
  420 }
  421 
  422 void
  423 SKMapPanel::getSample()
  424 {
  425   if (selectedKMap < 0) return;
  426   SString map = kmapList[selectedKMap];
  427   SStringTable t;
  428   SStringVector kv;
  429   SStringVector vv;
  430   
  431   bool more = true;
  432   if (map == "None" || map == "none")
  433   {
  434      /* nothing */
  435   }
  436   else if (map.size()>1 && (map[0] == 'x' || map[0] == 'X') && (map[1] == '-'))
  437   {
  438      /* nothing */
  439   }
  440   else if (map == "straight" || map == "x-none" ||  map == "x-utf-8" || map == "x-ascii")
  441   {
  442      char s[64];
  443      for (unsigned int i=0; i<100 && i<128-32; i++)
  444      {
  445        s[0] = (char)(i+32);
  446        s[1] = 0;
  447        kv.append (s);
  448        vv.append (s);
  449     }
  450   }
  451   else
  452   {
  453     SStringVector allkv;
  454     SStringVector allvv;
  455 
  456     SEncoder enc (map);
  457     if (enc.isOK())
  458     {
  459       more = (enc.getDecoderMap (&allkv, &allvv, 2000) > 2000);
  460     }
  461     unsigned int i;
  462     // put . at the end.
  463     for (i=0; i<allkv.size(); i++) {
  464         SString key = allkv[i];
  465         if (key.size() > 0 && key[0] == '.') continue;
  466         kv.append (key);
  467         vv.append (allvv[i]);
  468     }
  469     for (i=0; i<allkv.size(); i++) {
  470         SString key = allkv[i];
  471         if (key.size() > 0 && key[0] != '.') continue;
  472         kv.append (key);
  473         vv.append (allvv[i]);
  474     }
  475   }
  476   if (more) 
  477   {
  478     kv.append ("..");
  479     vv.append ("..");
  480   }
  481   t.append (kv);
  482   t.append (vv);
  483   sampleList = vv;
  484   sample->setText (t);
  485   sampleLabel->setText ("");
  486 }
  487 
  488 /**
  489  * Set the xinputs in the form of: x-name-locale
  490  */
  491 void
  492 SKMapPanel::setXInputs (const SStringVector& list)
  493 {
  494   SBinHashtable<int> check;
  495   /* no support yet */
  496   if (isWinAPI ()) return;
  497 
  498   //xinputs = SStringVector("x-utf-8,x-ascii");
  499   xinputs.clear();
  500   for (unsigned int i=0; i<list.size(); i++)
  501   {
  502     SStringVector v (list[i], ":");
  503     SString s = v[0];
  504     if (s=="x-utf-8")
  505     {
  506       s = list[i];
  507     }
  508     if (check.get (s) == 0)
  509     {
  510       check.put (s, 1);
  511       xinputs.append (list[i]);
  512     }
  513   }
  514   SStringVector v = allinputs;
  515   v.append (xinputs);
  516   listBox->setText (v);
  517 }