Logo Search packages:      
Sourcecode: yudit version File versions

SYudit::SYudit ( const SStringVector args,
const SProperties props 
)

A caret that redraws itself differently for lr and rl text

Definition at line 39 of file SYudit.cpp.

References SString::append(), SBinVector< Type >::append(), SBinVector< Type >::array(), composeFileNameCommand(), SEncoder::decode(), SScriptProcessor::doInit(), SEncoder::encode(), SHashtable< BType >::get(), SColor::getValue(), SDimension::height, SHashtable< BType >::put(), SString::replaceAll(), SMessageBar::setColumn(), SMessageBar::setFontSize(), SMessageBar::setRow(), SVector< BType >::size(), SBinVector< Type >::size(), SStringVector::smartSplit(), SScriptProcessor::support(), and SDimension::width.

{
  freeHandShown = false;
  freehand = 0;
  freeHandHeight = 0;
  setLayout (SLayout (SLocation (0,0), SLocation (3000,2000)));
  originalProperties = props;

  /* TODO: move this to config file */
  helpStrings.put ("hilfe", "de");
  SEncoder kana("Kana");
  SEncoder utf8("utf-8-s");
  helpStrings.put (utf8.encode (kana.decode ("HERUPU", false)), "ja");
  SEncoder hung("Hungarian");
  helpStrings.put ("segit", "hu");
  helpStrings.put (utf8.encode (hung.decode ("segi't", false)), "hu");
  helpStrings.put (utf8.encode (hung.decode ("segi'tse'g", false)), "hu");
  SEncoder yidd("Yiddish");
  SV_UCS4 yi0;
  yi0.append (SD_CD_RLO);
  yi0.append (yidd.decode ("gehilF", false));
  yi0.append (SD_CD_PDF);
  SV_UCS4 yi1;
  yi1.append (SD_CD_RLO);
  yi1.append (yidd.decode ("helF", false));
  yi1.append (SD_CD_PDF);
  helpStrings.put (utf8.encode (yi0), "yi");
  helpStrings.put (utf8.encode (yi1), "yi");
  helpStrings.put (utf8.encode (yidd.decode ("gehilF", false)), "yi");
  helpStrings.put (utf8.encode (yidd.decode ("helF", false)), "yi");
  helpStrings.put ("ayuda", "es");

  configFile = props["yudit.config"];

  char fnc[64];
  /* get an unused filename */
  for (unsigned int fn=0; fn<100000; fn++)
  {
   if (fn==0)
   {
     sprintf (fnc, "untitled.txt"); 
   }
   else
   {
     sprintf (fnc, "untitled%d.txt", fn); 
   }
   currentFileName = SString (fnc);
   SFile cfile (currentFileName);
   if (cfile.size() < 0) break;
  }  
  lastprinterOption = props["yudit.default.printer.options"];
  lastpreviewOption ="-e ";
  lastpreviewOption.append (props["yudit.default.preview.command"]);
  lastpreviewOption.replaceAll("\\", "/");
  lastpreviewOption.replaceAll("//", "/");
  lastencoding=props["yudit.default.filetype"];

  setFrameListener (this);
  command = new STextEdit ();
  SString commandFont ("default");
  if (props.get("yudit.command.font"))
  {
    commandFont = props["yudit.command.font"];
  }
  SString commandFontSizeString ("16");
  if (props.get("yudit.command.fontsize"))
  {
    commandFontSizeString = props["yudit.command.fontsize"];
  }
  commandFontSizeString.append ((char)0);
  double commandFontSize=0;
  sscanf (commandFontSizeString.array(), "%lf", &commandFontSize);

  if (commandFontSize < 2.0) commandFontSize = 2.0;
  command->setFont (commandFont, commandFontSize);
  unsigned int commandHeight = command->getPreferredSize().height;
  command->setMultiline (false);
  command->setLineEndMark (false);

  messagebar = new SMessageBar (props);
  unsigned int msgbarHeight = messagebar->getPreferredSize().height;


  toolbar = new SToolBar (props);
  unsigned int toobarHeight = toolbar->getPreferredSize().height;

  toolbar->setLayout (
    SLayout (
     SLocation (2,0),
     SLocation (2998, toobarHeight+0),
     SLocation (0, 0),
     SLocation (100, 0)
    )
  );
  toolbar->setListener (this);

  messagelabel = new SMessageLabel (props);
  unsigned int messagelabeHeight = messagelabel->getPreferredSize().height;

  messagelabel->setLayout (
    SLayout (
      SLocation (2, 1998-messagelabeHeight),
      SLocation (2998, 1998),
      SLocation (0, 100),
      SLocation (100, 100)
    )
  );
  command->setLayout (
    SLayout (
      SLocation (2, 1998-commandHeight-messagelabeHeight),
      SLocation (2998, 1998-messagelabeHeight),
      SLocation (0, 100),
      SLocation (100, 100)
    )
  );

  messagebar->setLayout (
    SLayout (
     SLocation (2,1998-msgbarHeight-commandHeight-messagelabeHeight),
     SLocation (2998, 1998-commandHeight-messagelabeHeight),
     SLocation (0, 100),
     SLocation (100, 100)
    )
  );

  sliderLayout =  SLayout (
      SLocation (2978, toobarHeight+2),
      SLocation (2998, 1998 - commandHeight - msgbarHeight - messagelabeHeight),
      SLocation (100, 0),
      SLocation (100, 100)
  );

  slider = new SSlider ();
  slider->setLayout (sliderLayout);
  /* on mac somehow it did not want to resize - force it */
  slider->resize (SDimension (10, 200));
  
  SString currentFont = toolbar->fonts[toolbar->currentFont];
  SString currentFontSize = toolbar->fontsizes[toolbar->currentFontSize];
  SString currentInput = toolbar->inputs[toolbar->currentInput];
  SString currentParagraphSeparator = toolbar->paragraphBreaks[toolbar->currentParagraphSeparator];
  

  editor = new STextEdit ();
  currentFontSize.append ((char)0);
  double df;
  if (sscanf (currentFontSize.array(), "%lf", &df)==0 || df < 2.0) df = 2.0;
  editor->setFont (currentFont, df);

  editor->setMultiline (true);
  editor->setLineEndMark (true);
  editor->setDocumentEmbedding (toolbar->currentEmbedding);

  editorLayout = 
    SLayout (
      SLocation (2, toobarHeight+2),
      SLocation (2978, 1998 - commandHeight - msgbarHeight - messagelabeHeight),
      SLocation (0, 0),
      SLocation (100, 100)
    );
  editor->setLayout (editorLayout);

  /*SGC */
  SString inputStyle = originalProperties["yudit.editor.xinputs.style"];

  /* allowed styles */
  if (inputStyle=="preedit-over-status-under" 
       || inputStyle == "preedit-under-status-under"
       || inputStyle=="preedit-over-status-over"
       || inputStyle == "preedit-root-status-root" )
  {
    SProperties p;
    SColor cbg(originalProperties["yudit.background"]);
    SColor cfg(originalProperties["yudit.label.foreground"]);

    sprintf (fnc, "%lu,%lu", (unsigned long)cbg.getValue(),
      (unsigned long)cfg.getValue());
    p.put ("InputClientColor", fnc);

    SColor sbg(originalProperties["yudit.background"]);
    SColor sfg(originalProperties["yudit.title.foreground"]);

    sprintf (fnc, "%lu,%lu", (unsigned long)sbg.getValue(),
      (unsigned long)sfg.getValue());
    p.put ("InputStatusColor", fnc);
    editor->setXIMProperties (p);

    p.put ("InputStyle", inputStyle);
    editor->setXIMProperties (p);
  }
  else
  {
    fprintf (stderr, "Yudit: unkown yudit.editor.xinputs.style=%*.*s\n",
       SSARGS(inputStyle));
  }

  /* showInputStatus has set up the xim properties for editor */
  editor->setInputMethod (currentInput);

  if (currentInput.size() > 2) 
  {
    if (currentInput != SS_KINPUT2_IM  
       && currentInput != SS_WINDOWS_IM
       && currentInput[0] != 'x' 
       && currentInput[1] != 'X')
    {
      command->setInputMethod (currentInput);
    }
  }
  if (props["yudit.editor.showbreak"]=="true")
  {
    editor->setLineEndMark (true);
  }
  else
  {
    editor->setLineEndMark (false);
  }
  if (props["yudit.editor.wordwrap"]=="true")
  {
    editor->setWordWrap (true);
  }
  else
  {
    editor->setWordWrap (false);
  }
  const SString& hl = props["yudit.editor.syntax"];
  int mode = translateHighlightMode (hl);
  if (mode >= 0) 
  {
    editor->setHighlightMode ((STextView::SS_HighlightMode)mode);
  }

  SEditor e(currentParagraphSeparator);
  editor->setEditor (e);
  messagebar->setFontSize(df);
  command->setEditor(SEditor());
  
  add (slider);
  add (editor);
  add (command);
  add (toolbar);
  add (messagebar);
  add (messagelabel);

  setBackground (props["yudit.background"]);
  editor->setTextBackground (props["yudit.editor.background"]);
  editor->setForeground (props["yudit.editor.left.foreground"],
            props["yudit.editor.right.foreground"]);
  editor->setCaretForeground (props["yudit.editor.caret.left.foreground"],
            props["yudit.editor.caret.right.foreground"]);
  command->setTextBackground (props["yudit.command.background"]);
  command->setForeground (props["yudit.command.left.foreground"],
            props["yudit.command.right.foreground"]);
  command->setCaretForeground (props["yudit.command.caret.left.foreground"],
            props["yudit.command.caret.right.foreground"]);
  slider->setSliderBackground (props["yudit.slider.background"]);


  SString version("Yudit-");
  version.append (SD_YUDIT_VERSION);
  setTitle (version);

  SDimension pw = toolbar->getPreferredSize();
  /* get the dimension */
  SDimension ms(props["yudit.default.geometry"]);
  if (ms.width < pw.width + 10) ms.width = pw.width + 10;
  if (ms.height < pw.height + 10) ms.width = pw.height + 10;
  resize (ms);
  setMinimumSize (SDimension (150, 100));

  caretNow = STextIndex (0,0);
  messagebar->setRow(1);
  messagebar->setColumn (0);
  editor->setCursorIndex(SCursorIndex(0,0));
  editor->addTextEditLS (this);
  command->addTextEditLS (this);
  command->setHistorySize(30);

  kmapDialog = 0;
  fileDialog = 0;
  textDialog = 0;

#ifdef USE_WINAPI
  SToolBar::SFormatIndex ft=SToolBar::SS_FORMAT_DOS;
#else 
  SToolBar::SFormatIndex ft=SToolBar::SS_FORMAT_UNIX;
#endif
  toolbar->setParagraphSeparator (ft, true);

  if (args.size())
  {
    SString comm ("open -yes ");
    SString enc ((lastencoding.size()==0)?SString("utf-8"):lastencoding);
    SString filename;
    bool help=false;
    unsigned int i;
    for (i=1; i<args.size(); i++)
    {
      if (args[i] == SString("-e") && i+1 < args.size())
      {
        i++;
        enc = args[i];
      }
      else if (args[i] == SString("-help") || args[i] == SString("-h"))
      {
        help = true;
      }
      else if (args[i] == SString("-us"))
      {
        SScriptProcessor::support(true);
      }
      else if (args[i] == SString("-nus"))
      {
        SScriptProcessor::support(false);
      }
      else if (args[i] == SString("-noinit"))
      {
        SScriptProcessor::doInit(false);
      }
      else if ((args[i] == SString("-d") || args[i] == SString("-geometry")) 
            && i+1 < args.size()) {
        i++;
      ms = SDimension (args[i]);  
        if (ms.width < pw.width + 10) ms.width = pw.width + 10;
        if (ms.height < pw.height + 10) ms.width = pw.height + 10;
        resize (ms);
      }
      else 
      {
        filename = args[i];
        break;
      }
    }
    if (help)
    {
      filename = SString("help");
      command->putHistory (filename);
    }
    else
    {
       filename = composeFileNameCommand (comm, enc, 
            completeFileName(filename));
       /* now it comes handy - args starts with 1 */
       unsigned int j;
       for (j=args.size(); j>i; j--)
       {
          SString ss = composeFileNameCommand (comm, enc, 
                completeFileName (args[j-1]));
          command->putHistory (ss);
       }
    }
    SStringVector v;
    v.smartSplit (filename);
    load (v, filename);
  }

  toolbar->setFileName(currentFileName, lastencoding);
//fprintf (stderr, "SYudit.cpp EDITOR FOCUS REQUEST\n");
  setDropListener (this, SStringVector ("text/uri-list,text/plain"));
  showFreeHand (currentInput=="freehand");
  editor->setFocus ();
}


Generated by  Doxygen 1.6.0   Back to index