Ejemplo n.º 1
0
WWidget *WItemDelegate::update(WWidget *widget, const WModelIndex& index,
			       WFlags<ViewItemRenderFlag> flags)
{
  bool editing = widget && widget->find("t") == 0;

  if (flags & RenderEditing) {
    if (!editing) {
      widget = createEditor(index, flags);
      WInteractWidget *iw = dynamic_cast<WInteractWidget *>(widget);
      if (iw) {
	// Disable drag & drop and selection behaviour
	iw->mouseWentDown().preventPropagation();
	iw->clicked().preventPropagation();
      }
    }
  } else {
    if (editing)
      widget = 0;
  }

  WidgetRef widgetRef(widget);

  bool isNew = false;

  if (!(flags & RenderEditing)) {
    if (!widgetRef.w) {
      isNew = true;
      IndexText *t = new IndexText(index);
      t->setObjectName("t");
      if (index.isValid() && !(index.flags() & ItemIsXHTMLText))
	t->setTextFormat(PlainText);
      t->setWordWrap(true);
      widgetRef.w = t;
    }

    if (!index.isValid())
      return widgetRef.w;

    bool haveCheckBox = false;

    boost::any checkedData = index.data(CheckStateRole);
    if (!checkedData.empty()) {
      haveCheckBox = true;
      CheckState state =
	(checkedData.type() == typeid(bool) ?
	   (boost::any_cast<bool>(checkedData) ? Checked : Unchecked)
	   : (checkedData.type() == typeid(CheckState) ?
	      boost::any_cast<CheckState>(checkedData) : Unchecked));
      IndexCheckBox *icb =
        checkBox(widgetRef, index, true, index.flags() & ItemIsTristate);
      icb->setCheckState(state);
      icb->setEnabled(index.flags() & ItemIsUserCheckable);
    } else if (!isNew)
      delete checkBox(widgetRef, index, false);

    boost::any linkData = index.data(LinkRole);
    if (!linkData.empty()) {
      WLink link = boost::any_cast<WLink>(linkData);
      IndexAnchor *a = anchorWidget(widgetRef, index);
      a->setLink(link);
      if (link.type() == WLink::Resource)
	a->setTarget(TargetNewWindow);
    }

    IndexText *t = textWidget(widgetRef, index);

    WString label = asString(index.data(), textFormat_);
    if (label.empty() && haveCheckBox)
      label = WString::fromUTF8(" ");
    t->setText(label);

    std::string iconUrl = asString(index.data(DecorationRole)).toUTF8();
    if (!iconUrl.empty()) {
      iconWidget(widgetRef, index, true)->setImageLink(WLink(iconUrl));
    } else if (!isNew)
      delete iconWidget(widgetRef, index, false);
  }

  if (index.flags() & ItemHasDeferredTooltip){
    widgetRef.w->setDeferredToolTip(true, (index.flags() & ItemIsXHTMLText) ?
                                      XHTMLText : PlainText);
  } else {
  WString tooltip = asString(index.data(ToolTipRole));
  if (!tooltip.empty() || !isNew)
    widgetRef.w->setToolTip(tooltip,
			    (index.flags() & ItemIsXHTMLText) ? 
			    XHTMLText : PlainText);
  }

  WT_USTRING sc = asString(index.data(StyleClassRole));

  if (flags & RenderSelected)
    sc += WT_USTRING::fromUTF8
      (" " + WApplication::instance()->theme()->activeClass());

  if (flags & RenderEditing)
    sc += WT_USTRING::fromUTF8(" Wt-delegate-edit");

  widgetRef.w->setStyleClass(sc);

  if (index.flags() & ItemIsDropEnabled)
    widgetRef.w->setAttributeValue("drop", WString::fromUTF8("true"));
  else
    if (!widgetRef.w->attributeValue("drop").empty())
      widgetRef.w->setAttributeValue("drop", WString::fromUTF8("f"));

  return widgetRef.w;
}
Ejemplo n.º 2
0
void dbload()
{
    // If the file doesn't exist, there is no DB to load
    if(!FileExists(dbpath))
        return;

    dprintf("Loading database...");
    DWORD ticks = GetTickCount();

    // Multi-byte (UTF8) file path converted to UTF16
    WString databasePathW = StringUtils::Utf8ToUtf16(dbpath);

    // Decompress the file if compression was enabled
    bool useCompression = !settingboolget("Engine", "DisableCompression");
    LZ4_STATUS lzmaStatus = LZ4_INVALID_ARCHIVE;
    {
        lzmaStatus = LZ4_decompress_fileW(databasePathW.c_str(), databasePathW.c_str());

        // Check return code
        if(useCompression && lzmaStatus != LZ4_SUCCESS && lzmaStatus != LZ4_INVALID_ARCHIVE)
        {
            dputs("\nInvalid database file!");
            return;
        }
    }

    // Open the file for reading by the JSON parser
    FILE* jsonFile = nullptr;
    long jsonFileSize = 0;

    if(_wfopen_s(&jsonFile, databasePathW.c_str(), L"rb"))
    {
        dputs("\nFailed to open database file!");
        return;
    }

    // Get the current file size
    fseek(jsonFile, 0, SEEK_END);
    jsonFileSize = ftell(jsonFile);
    fseek(jsonFile, 0, SEEK_SET);

    // Verify that the file size is greater than 0.
    // This corrects a bug when a file exists, but there is no data inside.
    JSON root = nullptr;

    if(jsonFileSize > 0)
        root = json_loadf(jsonFile, 0, 0);

    // Release the file handle and re-compress
    fclose(jsonFile);

    if(lzmaStatus != LZ4_INVALID_ARCHIVE && useCompression)
        LZ4_compress_fileW(databasePathW.c_str(), databasePathW.c_str());

    // Validate JSON load status
    if(!root)
    {
        dputs("\nInvalid database file (JSON)!");
        return;
    }

    // Finally load all structures
    CommentCacheLoad(root);
    LabelCacheLoad(root);
    BookmarkCacheLoad(root);
    FunctionCacheLoad(root);
    LoopCacheLoad(root);
    BpCacheLoad(root);

    // Free root
    json_decref(root);
    dprintf("%ums\n", GetTickCount() - ticks);
}
Ejemplo n.º 3
0
std::string EncodeHttpHeaderField(const std::string &fieldname,
                                  const WString &fieldValue)
{
  // This implements RFC 5987
  return fieldname + "*=UTF-8''" + urlEncode(fieldValue.toUTF8());
}
Ejemplo n.º 4
0
    //-----------------------------------------------------------------------
	Ogre::DataStreamPtr UnicodeFileSystemArchive::open(const String& _filename, bool _readOnly) const
    {
		WString wfullpath = getFullPath(_filename);

		// Use filesystem to determine size 
		// (quicker than streaming to the end and back)
		struct _stat tagStat;
		int ret = _wstat(wfullpath.c_str(), &tagStat);
		if(ret != 0)
		{
			GOTHOGRE_EXCEPT(_filename << " - Problem getting file size"
				<< " (archive " << getName() << ").");
		}

		// Always open in binary mode
		// Also, always include reading
		std::ios::openmode mode = std::ios::in | std::ios::binary;
		std::istream* baseStream = 0;
		std::ifstream* roStream = 0;
		std::fstream* rwStream = 0;

		if (_readOnly)
		{
			roStream = OGRE_NEW_T(std::ifstream, MEMCATEGORY_GENERAL)();
			roStream->open(wfullpath.c_str(), mode);
			baseStream = roStream;
		}
		else
		{
			if (isReadOnly())
			{
				GOTHOGRE_EXCEPT(_filename << " - Cannot open a file for writing in"
					<< " read-only archive " << getName() << ".");
			}
			mode |= std::ios::out;
			rwStream = OGRE_NEW_T(std::fstream, MEMCATEGORY_GENERAL)();
			rwStream->open(wfullpath.c_str(), mode);
			baseStream = rwStream;
		}

		// Should check ensure open succeeded, in case fail for some reason.
		if (baseStream->fail())
		{
			OGRE_DELETE_T(roStream, basic_ifstream, MEMCATEGORY_GENERAL);
			OGRE_DELETE_T(rwStream, basic_fstream, MEMCATEGORY_GENERAL);
			GOTHOGRE_EXCEPT(_filename << " - Cannot open file in"
				<< " archive " << getName() << ".");
		}

		GOTHOGRE_INFO(_filename << " - " << (_readOnly ? "Loading from" : "Saving to")
			<< " archive " << getName() << ".");

		/// Construct return stream, tell it to delete on destroy
		FileStreamDataStream* stream = 0;
		if (rwStream)
		{
			// use the writeable stream 
			stream = OGRE_NEW FileStreamDataStream(_filename,
				rwStream, tagStat.st_size, true);
		}
		else
		{
			// read-only stream
			stream = OGRE_NEW FileStreamDataStream(_filename,
				roStream, tagStat.st_size, true);
		}
		return DataStreamPtr(stream);
    }
Ejemplo n.º 5
0
	void Console::Write(const WString& string)
	{
		DWORD count = 0;
		WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), string.Buffer(), (int)string.Length(), &count, 0);
	}
Ejemplo n.º 6
0
void Draw::DrawText(int x, int y, const String& text, Font font, Color ink, const int *dx)
{
	WString h = TextUnicode(text, text.GetLength(), CHARSET_DEFAULT, font);
	DrawText(x, y, h, font, ink, h.GetLength(), dx);
}
Ejemplo n.º 7
0
void   LineEdit::Paint0(Draw& w) {
	int sell, selh;
	GetSelection(sell, selh);
	if(!IsEnabled())
		sell = selh = 0;
	Size sz = GetSize();
	Size fsz = GetFontSize();
	Point sc = sb;
	int ll = min(line.GetCount(), sz.cy / fsz.cy + sc.y + 1);
	int  y = 0;
	cpos = GetPos(sc.y);
	cline = sc.y;
	sell -= cpos;
	selh -= cpos;
	int pos = cpos;
	Vector<int> dx, dx2;
	int fascent = font.Info().GetAscent();
	for(int i = sc.y; i < ll; i++) {
		WString tx = line[i];
		int len = tx.GetLength();
		if(w.IsPainting(0, y, sz.cx, fsz.cy)) {
			Highlight ih;
			ih.ink = color[IsShowEnabled() ? INK_NORMAL : INK_DISABLED];
			ih.paper = color[IsReadOnly() || !IsShowEnabled() ? PAPER_READONLY : PAPER_NORMAL];
			if(nobg)
				ih.paper = Null;
			ih.font = font;
			ih.chr = 0;
			Vector<Highlight> hl;
			hl.SetCount(len + 1, ih);
			for(int q = 0; q < tx.GetCount(); q++)
				hl[q].chr = tx[q];
			HighlightLine(i, hl, pos);
			int ln = hl.GetCount() - 1;
			int l = max(sell, 0);
			int h = selh > len ? len : selh;
			if(l < h)
				for(int i = l; i < h; i++) {
					hl[i].paper = color[PAPER_SELECTED];
					hl[i].ink = color[INK_SELECTED];
				}
			if(sell <= len && selh > len)
				for(int i = len; i < hl.GetCount(); i++) {
					hl[i].paper = color[PAPER_SELECTED];
					hl[i].ink = color[INK_SELECTED];
				}
			Buffer<wchar> txt(ln);
			for(int i = 0; i < ln; i++)
				txt[i] = hl[i].chr;
			for(int pass = 0; pass < 2; pass++) {
				int gp = 0;
				int scx = fsz.cx * sc.x;
				if(ln >= 0) {
					int q = 0;
					while(q < ln) {
						Highlight& h = hl[q];
						if(txt[q] == '\t') {
							int ngp = (gp + tabsize) / tabsize * tabsize;
							int l = ngp - gp;
							LLOG("Highlight -> tab[" << q << "] paper = " << h.paper);
							if(pass == 0) {
								w.DrawRect(gp * fsz.cx - scx, y, fsz.cx * l, fsz.cy, h.paper);
								if(showtabs && h.paper != SColorHighlight && q < tx.GetLength()) {
									Color c = Blend(SColorLight, SColorHighlight);
									w.DrawRect(gp * fsz.cx - scx + 2, y + fsz.cy / 2,
									           l * fsz.cx - 4, 1, c);
									w.DrawRect(ngp * fsz.cx - scx - 3, y + 3,
									           1, fsz.cy - 6, c);
								}
								if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + l)
									w.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
							}
							q++;
							gp = ngp;
						}
						else
						if(txt[q] == ' ') {
						    LLOG("Highlight -> space[" << q << "] paper = " << h.paper);
						    if(pass == 0) {
						        w.DrawRect(gp * fsz.cx - scx, y, fsz.cx, fsz.cy, h.paper);
						        if(showspaces && h.paper != SColorHighlight && q < tx.GetLength()) {
						            Color c = Blend(SColorLight, SColorHighlight);
						            w.DrawRect(gp * fsz.cx - scx + fsz.cx / 2, y + fsz.cy / 2,
						                       2, 2, c);
						        }
						        if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + 1)
						            w.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
						    }
						    q++;
						    gp++;
						}
						else {
							bool cjk = IsCJKIdeograph(txt[q]);
							int p = q + 1;
							while(p < len && h == hl[p] && txt[p] != '\t' && txt[p] != ' ' && IsCJKIdeograph(txt[p]) == cjk && p - q < 128)
								p++;
							int l = p - q;
							int ll = cjk ? 2 * l : l;
							LLOG("Highlight -> paper[" << q << "] = " << h.paper);
							int x = gp * fsz.cx - scx;
							int xx = x + (gp + ll) * fsz.cx;
							if(max(x, 0) < min(xx, sz.cx))
								if(pass == 0) {
									w.DrawRect(x, y, fsz.cx * ll, fsz.cy, h.paper);
									if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + ll)
										w.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
								}
								else {
									if(cjk)
										dx2.At(l, 2 * fsz.cx);
									else
										dx.At(l, fsz.cx);
									w.DrawText(x,
									           y + fascent - h.font.Info().GetAscent(),
									           ~txt + q, h.font, h.ink, l, cjk ? dx2 : dx);
								}
							q = p;
							gp += ll;
							if(x > sz.cx)
								break;
						}
					}
				}
				if(pass == 0) {
					int gpx = gp * fsz.cx - scx;
					w.DrawRect(gpx, y, sz.cx - gpx, fsz.cy, hl.Top().paper);
					if(bordercolumn > 0 && bordercolumn >= gp)
						w.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
				}
			}
		}
		y += fsz.cy;
		sell -= len + 1;
		selh -= len + 1;
		pos += len + 1;
	}
	w.DrawRect(0, y, sz.cx, sz.cy - y, color[IsReadOnly() || !IsShowEnabled() ? PAPER_READONLY : PAPER_NORMAL]);
	DrawTiles(w, DropCaret(), CtrlImg::checkers());
}
Ejemplo n.º 8
0
void FontSupport::drawText(const WFont& font, const WRectF& rect,
			   WFlags<AlignmentFlag> flags, const WString& text)
{
  PANGO_LOCK;

  enabledFontFormats = enabledFontFormats_;

  std::string utf8 = text.toUTF8();

  std::vector<PangoGlyphString *> glyphs;
  int width;

  GList *items = layoutText(font, utf8, glyphs, width);

  AlignmentFlag hAlign = flags & AlignHorizontalMask;
  AlignmentFlag vAlign = flags & AlignVerticalMask;

  /* FIXME handle bidi ! */

  double x;
  switch (hAlign) {
  case AlignmentFlag::Left:
    x = rect.left();
    break;
  case AlignmentFlag::Right:
    x = rect.right() - pangoUnitsToDouble(width);
    break;
  case AlignmentFlag::Center:
    x = rect.center().x() - pangoUnitsToDouble(width/2);
    break;
  default:
    x = 0;
  }

  unsigned i = 0;
  for (GList *elem = items; elem; elem = elem->next) {
    PangoItem *item = (PangoItem *)elem->data;
    PangoAnalysis *analysis = &item->analysis;

    PangoGlyphString *gl = glyphs[i++];

    currentFont_ = analysis->font;

    /*
     * Note, we are actually ignoring the selected glyphs here, which
     * is a pitty and possibly wrong if the device does not make the
     * same selection !
     */
    WString s = WString::fromUTF8(utf8.substr(item->offset,
                                              item->length));

    device_->drawText(WRectF(x, rect.y(),
			     1000, rect.height()),
		      AlignmentFlag::Left | vAlign, TextFlag::SingleLine,
		      s, nullptr);

    WTextItem textItem = device_->measureText(s, -1, false);

    x += textItem.width();

    pango_item_free(item);
    pango_glyph_string_free(gl);
  }

  g_list_free(items);

  currentFont_ = nullptr;
}
Ejemplo n.º 9
0
WTextItem FontSupport::measureText(const WFont& font, const WString& text,
				   double maxWidth, bool wordWrap)
{
  PANGO_LOCK;

  enabledFontFormats = enabledFontFormats_;

  /*
   * Note: accurate measuring on a bitmap requires that the transformation
   * is applied, because hinting may push chars to boundaries e.g. when
   * rotated (or scaled too?)
   */
  std::string utf8 = text.toUTF8();
  const char *s = utf8.c_str();

  if (wordWrap) {
    int utflen = g_utf8_strlen(s, -1);
    PangoLogAttr *attrs = new PangoLogAttr[utflen + 1];
    PangoLanguage *language = pango_language_from_string("en-US");

    pango_get_log_attrs(s, utf8.length(), -1, language, attrs, utflen + 1);

    double w = 0, nextW = -1;

    int current = 0;
    int measured = 0;
    int end = 0;

    bool maxWidthReached = false;

    for (int i = 0; i < utflen + 1; ++i) {
      if (i == utflen || attrs[i].is_line_break) {
	int cend = g_utf8_offset_to_pointer(s, end) - s;

	WTextItem ti
	  = measureText(font, WString::fromUTF8(utf8.substr(measured,
							    cend - measured)),
			-1, false);

	if (isEpsilonMore(w + ti.width(), maxWidth)) {
	  nextW = ti.width();
	  maxWidthReached = true;
	  break;
	} else {
	  measured = cend;
	  current = g_utf8_offset_to_pointer(s, i) - s;
	  w += ti.width();

	  if (i == utflen) {
	    w += measureText(font, WString::fromUTF8(utf8.substr(measured)),
			     -1, false).width();
	    measured = utf8.length();
	  }
	}
      }

      if (!attrs[i].is_white)
	end = i + 1;
    }

    delete[] attrs;

    if (maxWidthReached) {
      return WTextItem(WString::fromUTF8(utf8.substr(0, current)), w, nextW);
    } else {
      /*
       * For some reason, the sum of the individual widths is a bit less
       * (for longer stretches of text), so we re-measure it !
       */
      w = measureText(font, WString::fromUTF8(utf8.substr(0, measured)),
		      -1, false).width();
      return WTextItem(text, w);
    }
  } else {
    std::vector<PangoGlyphString *> glyphs;
    int width;

    GList *items = layoutText(font, utf8, glyphs, width);

    double w = pangoUnitsToDouble(width);

    for (unsigned i = 0; i < glyphs.size(); ++i)
      pango_glyph_string_free(glyphs[i]);

    g_list_foreach(items, (GFunc) pango_item_free, nullptr);
    g_list_free(items);

    return WTextItem(text, w);
  }
}
Ejemplo n.º 10
0
void WPdfImage::drawText(const WRectF& rect, 
			 WFlags<AlignmentFlag> flags,
			 TextFlag textFlag,
			 const WString& text,
			 const WPointF *clipPoint)
{
  // FIXME: textFlag
  
  if (clipPoint && painter() && !painter()->clipPath().isEmpty()) {
    if (!painter()->clipPathTransform().map(painter()->clipPath())
	  .isPointInPath(painter()->worldTransform().map(*clipPoint)))
      return;
  }

  if (trueTypeFont_ && !trueTypeFonts_->busy())
    trueTypeFonts_->drawText(painter()->font(), rect, flags, text);
  else {
    HPDF_REAL left, top, right, bottom;
    HPDF_TextAlignment alignment = HPDF_TALIGN_LEFT;

    AlignmentFlag horizontalAlign = flags & AlignHorizontalMask;
    AlignmentFlag verticalAlign = flags & AlignVerticalMask;

    switch (horizontalAlign) {
    default:
      // should never happen
    case AlignmentFlag::Left:
      left = rect.left();
      right = left + 10000;
      alignment = HPDF_TALIGN_LEFT;
      break;
    case AlignmentFlag::Right:
      right = rect.right();
      left = right - 10000;
      alignment = HPDF_TALIGN_RIGHT;
      break;
    case AlignmentFlag::Center:
      {
	float center = rect.center().x();
	left = center - 5000;
	right = center + 5000;
	alignment = HPDF_TALIGN_CENTER;
	break;
      }
    }

    switch (verticalAlign) {
    default:
      // fall-through ; should never happen
    case AlignmentFlag::Top:
      top = rect.top(); break;
    case AlignmentFlag::Middle:
      // FIXME: use font metrics to center middle of ascent !
      top = rect.center().y() - 0.60 * fontSize_; break;
    case AlignmentFlag::Bottom:
      top = rect.bottom() - fontSize_; break;
    }

    bottom = top + fontSize_;

    if (trueTypeFonts_->busy())
      setChanged(PainterChangeFlag::Font);

    HPDF_Page_GSave(page_);

    // Undo the global inversion
    HPDF_Page_Concat(page_, 1, 0, 0, -1, 0, bottom);

    HPDF_Page_BeginText(page_);

    // Need to fill text using pen color
    const WColor& penColor = painter()->pen().color();
    HPDF_Page_SetRGBFill(page_,
			 penColor.red() / 255.,
			 penColor.green() / 255.,
			 penColor.blue() / 255.);

    std::string s = trueTypeFont_ ? text.toUTF8() : text.narrow();

    HPDF_Page_TextRect(page_, left, fontSize_, right, 0, s.c_str(),
		       alignment, nullptr);

    HPDF_Page_EndText(page_);

    HPDF_Page_GRestore(page_);
  }
}
Ejemplo n.º 11
0
FILE *OpenRead(const char *inUtf8Name)
{
   WString wide = UTF8ToWide(inUtf8Name);
   return OpenRead( wide.c_str() );
}
Ejemplo n.º 12
0
///
/// Handle emitting result clicked or selected (they do the same thing except
/// for the signal so combined into one function)
///
void ResultsTable::emitJobClickedOrSelected(const WModelIndex& item, bool clicked)
{

    int modelRow = item.row();

    boost::any d = mSortFilterProxyModel->data(modelRow, 0, UserRole);
    boost::any d1 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 1);
    boost::any d2 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 2);
    boost::any d3 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 3);
    boost::any d4 = mSortFilterProxyModel->data(modelRow, 1, DisplayRole);
    boost::any d5 = mSortFilterProxyModel->data(modelRow, 0, UserRole + 4);

    if (!d.empty() && !d1.empty() && !d2.empty())
    {
        WString clusterCommand = boost::any_cast<WString>(d);
        WString metaScript = boost::any_cast<WString>(d1);
        WString arguments = boost::any_cast<WString>(d2);

        WString jobID;
        if (!d3.empty())
        {
            jobID = boost::any_cast<WString>(d3);
        }

        WString user;
        if (!d4.empty())
        {
            user = boost::any_cast<WString>(d4);
        }

        WString project;
        if (!d5.empty())
        {
            project = boost::any_cast<WString>(d5);
        }

        if (clicked)
        {
            mResultClicked.emit(clusterCommand.toUTF8(), metaScript.toUTF8(), arguments.toUTF8(),
                                jobID.toUTF8(), user.toUTF8(), project.toUTF8());
        }
        else
        {
            mResultSelected.emit(clusterCommand.toUTF8(), metaScript.toUTF8(), arguments.toUTF8(),
                                jobID.toUTF8(), user.toUTF8(), project.toUTF8());
        }
    }

}
Ejemplo n.º 13
0
void TreeNode::debugInfo( TreeRoot * root )
//-----------------------------------------
{
    WString boundLine;
    WString descendLine;
    char *  enabled;
    char *  placed;
    WString statLine;
    WString refLine;
    WString rootLine;

    TreeCoord   ox, oy;
    TreeRect rootRect;

    ox = _parent->getXOff();
    oy = _parent->getYOff();

    root->getBound( rootRect );

    rootLine.printf( "_rootNode = %s, bounding(%ld,%ld,%ld,%ld) ",
                     root->node()->name(), rootRect.x(), rootRect.y(),
                     rootRect.w(), rootRect.h() );
    boundLine.printf( "_bounding [%s] = (%ld,%ld,%ld,%ld), offset = (%ld,%ld) ",
                        (_flags.boundSet) ? "set" : "unset",
                        _bounding.x(), _bounding.y(),
                        _bounding.w(), _bounding.h(),
                        ox, oy );
    descendLine.printf( "_sibWidth = %ld, _descend = (%ld,%ld,%ld,%ld) ",
                        _sibWidth, _descend.x(), _descend.y(),
                        _descend.w(), _descend.h() );

    switch( _flags.enabled ) {
    case Hidden:
        enabled = "Hidden";
        break;
    default:
        enabled = "Visible";
        break;
    }

    switch( _flags.placed ) {
    case NotPlaced:
        placed = "NotPlaced";
        break;
    case PartiallyPlaced:
        placed = "PartiallyPlaced";
        break;
    case Arranging:
        placed = "Arranging";
        break;
    default:
        placed = "Placed";
    }
    statLine.printf( " enabled = %s, placed = %s, selected = %s, _level = %d\n",
                        enabled, placed, (_flags.selected) ? "true" : "false",
                        getLevel() );

    refLine.printf( "hasReference() = %s, isReference() = %s",
                    hasReference() ? "true" : "false",
                    isReference() ? "true" : "false" );

    WMessageDialog::messagef( _parent, MsgPlain, MsgOk, name(), "%s%s%s%s%s",
                            (const char *)rootLine, (const char *)boundLine,
                            (const char *)descendLine, (const char *)statLine,
                            (const char *)refLine );
}
Ejemplo n.º 14
0
	WString wupper(const WString& string)
	{
		WString result = string.Buffer();
		_wcsupr_s((wchar_t*)result.Buffer(), result.Length() + 1);
		return result;
	}
Ejemplo n.º 15
0
	bool Folder::Rename(const WString& newName)const
	{
		WString oldFileName = filePath_.GetFullPath();
		WString newFileName = (filePath_.GetFolder() / newName).GetFullPath();
		return MoveFile(oldFileName.Buffer(), newFileName.Buffer()) != 0;
	}
Ejemplo n.º 16
0
void FontSupport::drawText(const WFont& font, const WRectF& rect,
			   const WTransform& transform, Bitmap& bitmap,
			   WFlags<AlignmentFlag> flags,
			   const WString& text)
{
  PANGO_LOCK;

  enabledFontFormats = enabledFontFormats_;

  PangoMatrix matrix;
  matrix.xx = transform.m11();
  matrix.xy = transform.m21();
  matrix.yx = transform.m12();
  matrix.yy = transform.m22();
  matrix.x0 = transform.dx();
  matrix.y0 = transform.dy();

  std::string utf8 = text.toUTF8();

  std::vector<PangoGlyphString *> glyphs;
  int width;

  pango_context_set_matrix(context_, &matrix);

  /*
   * Oh my god, somebody explain me why we need to do this...
   */
  WFont f = font;
  f.setSize(font.sizeLength().toPixels()
	    / pango_matrix_get_font_scale_factor(&matrix));

  GList *items = layoutText(f, utf8, glyphs, width);
  pango_context_set_matrix(context_, nullptr);

  AlignmentFlag hAlign = flags & AlignHorizontalMask;

  /* FIXME handle bidi ! */

  double x;
  switch (hAlign) {
  case AlignmentFlag::Left:
    x = rect.left();
    break;
  case AlignmentFlag::Right:
    x = rect.right() - pangoUnitsToDouble(width);
    break;
  case AlignmentFlag::Center:
    x = rect.center().x() - pangoUnitsToDouble(width/2);
    break;
  default:
    x = 0;
  }

  AlignmentFlag vAlign = flags & AlignVerticalMask;

  PangoFont *pangoFont = matchFont(font).pangoFont();
  PangoFontMetrics *metrics = pango_font_get_metrics(pangoFont, nullptr);

  double ascent
    = pangoUnitsToDouble(pango_font_metrics_get_ascent(metrics));
  double descent 
    = pangoUnitsToDouble(pango_font_metrics_get_descent(metrics));

  pango_font_metrics_unref(metrics);

  double baseline = ascent;
  double height = ascent + descent;

  double y;
  switch (vAlign) {
  case AlignmentFlag::Top:
    y = rect.top() + baseline;
    break;
  case AlignmentFlag::Middle:
    y = rect.center().y() - height / 2 + baseline;
    break;
  case AlignmentFlag::Bottom:
    y = rect.bottom() - height + baseline;
    break;
  default:
    y = 0;
  }

  FT_Bitmap bmp;
  bmp.buffer = bitmap.buffer();
  bmp.width = bitmap.width();
  bmp.rows = bitmap.height();
  bmp.pitch = bitmap.pitch();
  bmp.pixel_mode = FT_PIXEL_MODE_GRAY;
  bmp.num_grays = 16; // ???

  GList *elem;
  unsigned i = 0;

  for (elem = items; elem; elem = elem->next) {
    PangoItem *item = (PangoItem *)elem->data;
    PangoAnalysis *analysis = &item->analysis;

    PangoGlyphString *gl = glyphs[i++];

    pango_ft2_render_transformed(&bmp, &matrix,
				 analysis->font, gl,
				 pangoUnitsFromDouble(x),
				 pangoUnitsFromDouble(y));

    x += pangoUnitsToDouble(pango_glyph_string_get_width(gl));

    pango_glyph_string_free(gl);
    pango_item_free(item);
  }

  g_list_free(items);
}
Ejemplo n.º 17
0
void Draw::DrawText(int x, int y, int angle, const WString& text, Font font,
                    Color ink, const int *dx)
{
	DrawText(x, y, angle, ~text, font, ink, text.GetLength(), dx);
}
Ejemplo n.º 18
0
void WDialog::setWindowTitle(const WString& windowTitle)
{
  caption_->setText(WString::fromUTF8("<h3>" + windowTitle.toUTF8()
				      + "</h3>"));
}
Ejemplo n.º 19
0
Size GetTextSize(const WString& text, Font font)
{
	return GetTextSize(text, font, text.GetLength());
}
Ejemplo n.º 20
0
bool WTemplate::renderTemplateText(std::ostream& result, const WString& templateText)
{
  errorText_ = "";

  std::string text;
  if (encodeTemplateText_)
    text = encode(templateText.toUTF8());
  else
    text = templateText.toUTF8();

  std::size_t lastPos = 0;
  std::vector<WString> args;
  std::vector<std::string> conditions;
  int suppressing = 0;

  for (std::size_t pos = text.find('$'); pos != std::string::npos;
       pos = text.find('$', pos)) {

    if (!suppressing)
      result << text.substr(lastPos, pos - lastPos);

    lastPos = pos;

    if (pos + 1 < text.length()) {
      if (text[pos + 1] == '$') { // $$ -> $
	if (!suppressing)
	  result << '$';

	lastPos += 2;
      } else if (text[pos + 1] == '{') {
	std::size_t startName = pos + 2;
	std::size_t endName = text.find_first_of(" \r\n\t}", startName);

        args.clear();
        std::size_t endVar = parseArgs(text, endName, args);

        if (endVar == std::string::npos) {
          std::stringstream errorStream;
          errorStream << "variable syntax error near \"" << text.substr(pos)
                      << "\"";
          errorText_ = errorStream.str();
          LOG_ERROR(errorText_);
          return false;
        }

        std::string name = text.substr(startName, endName - startName);
	std::size_t nl = name.length();

	if (nl > 2 && name[0] == '<' && name[nl - 1] == '>') {
	  if (name[1] != '/') {
	    std::string cond = name.substr(1, nl - 2);
	    conditions.push_back(cond);
	    if (suppressing || !conditionValue(cond))
	      ++suppressing;
	  } else {
	    std::string cond = name.substr(2, nl - 3);
	    if (conditions.empty() || conditions.back() != cond) {
              std::stringstream errorStream;
              errorStream << "mismatching condition block end: " << cond;
              errorText_ = errorStream.str();
              LOG_ERROR(errorText_);
              return false;
	    }
	    conditions.pop_back();

	    if (suppressing)
	      --suppressing;
	  }
	} else {
	  if (!suppressing) {
	    std::size_t colonPos = name.find(':');

	    bool handled = false;
	    if (colonPos != std::string::npos) {
	      std::string fname = name.substr(0, colonPos);
	      std::string arg0 = name.substr(colonPos + 1);
	      args.insert(args.begin(), WString::fromUTF8(arg0));
	      if (resolveFunction(fname, args, result))
		handled = true;
	      else
		args.erase(args.begin());
	    }

	    if (!handled)
	      resolveString(name, args, result);
	  }
	}

	lastPos = endVar + 1;
      } else {
	if (!suppressing)
	  result << '$'; // $. -> $.
	lastPos += 1;
      }
    } else {
      if (!suppressing)
	result << '$'; // $ at end of template -> $
      lastPos += 1;
    }

    pos = lastPos;
  }

  result << text.substr(lastPos);
  return true;
}
Ejemplo n.º 21
0
	//-----------------------------------------------------------------------
	void UnicodeFileSystemArchive::FileFinder::_run(const String& _dir, const WString& _wFullDir)
	{
		wchar_t wFindPattern[MAX_PATH];
		wcscpy(wFindPattern, _wFullDir.c_str());
		wcscpy(&wFindPattern[_wFullDir.length()], L"*");
       
        long lHandle;
		struct _wfinddata_t wTagData;
        lHandle = _wfindfirst(wFindPattern, &wTagData);

		String  tagDataName;
		String  dir2;
		WString wFullDir2;

		while(lHandle != -1)
		{
			bool isSubDir = ((wTagData.attrib & _A_SUBDIR) != 0);
			bool isHidden = ((wTagData.attrib & _A_HIDDEN) != 0);
			if((!mIgnoreHidden || !isHidden)
				&& !isReservedDir(wTagData.name)
				&& ((isSubDir == mDirs) || (isSubDir && mRecursive)))
			{
				tagDataName = mArchive->toString(wTagData.name);

				if(isSubDir == mDirs
					&& (mMask.empty() || StrUtil::match(tagDataName, mMask)))
				{
					if (mSimpleList)
					{
						mSimpleList->push_back(String());
						String& back = mSimpleList->back();
						back = _dir;
						back += tagDataName;
					}
					else if (mDetailList)
					{
						FileInfo fi;
						fi.archive = mArchive;
						fi.filename = _dir;
						fi.filename += tagDataName;
						fi.basename = tagDataName;
						fi.path = _dir;
						fi.compressedSize = wTagData.size;
						fi.uncompressedSize = wTagData.size;
						mDetailList->push_back(fi);
					}
				}

				if(isSubDir && mRecursive)
				{
					dir2 = _dir;
					dir2 += tagDataName;
					dir2 += '/';
					
					wFullDir2 = _wFullDir;
					wFullDir2 += wTagData.name;
					wFullDir2 += '/';
					
					_run(dir2, wFullDir2);
				}
			}
			
			if(_wfindnext( lHandle, &wTagData ) == -1)
			{
				_findclose(lHandle);
				lHandle = -1;
			}
        }
    }
Ejemplo n.º 22
0
DescriptionPaint::DescriptionPaint( WBRWindow * prnt, const WRect & r,
                                    Symbol * sym )
                    : _parent( prnt )
                    , _rect( r )
                    , _current( -1 )
//--------------------------------------------------------------------
{
    int             i;
    WVList          desc;
    Description *   entry;
    WString         buf;
    const char *    uDefSymName;
    int             x = r.x();
    int             w;
    int             h;

    _parts = new WCPtrOrderedVector<DescriptionPart>;

    sym->description( desc );

    for( i = 0; i < desc.count(); i += 1 ) {
        entry = (Description *) desc[i];
        if( entry->symbol() ) {
            if( sym->isEqual( entry->symbol() ) ) {

                // don't hilight the symbol we're describing
                buf.concat( entry->name() );
                delete entry->symbol();

            } else {

                if( buf != "" ) { // flush buf
                    w = prnt->getTextExtentX( buf );
                    h = prnt->getTextExtentY( buf );
                    _parts->append( new DescriptionPart( buf.gets(), NULL,
                                        WRect(x,r.y(),w, h ) ) );

                    buf="";
                    x+=w;
                }

                uDefSymName = entry->name();
                w = prnt->getTextExtentX( uDefSymName );
                h = prnt->getTextExtentY( uDefSymName );
                _parts->append( new DescriptionPart( uDefSymName,
                                                     entry->symbol(),
                                                     WRect(x,r.y(),w, h ) ) );
                x+=w;
            }
        } else {
            buf.concat( entry->name() );
        }
    }

    desc.deleteContents();


    if( buf != "" ) { // flush buf
        w = prnt->getTextExtentX( buf );
        h = prnt->getTextExtentY( buf );
        _parts->append( new DescriptionPart( buf, NULL,
                                WRect(x,r.y(),w, h ) ) );

        buf="";
        x+=w;
    }

    _rect.w( x - abs( _rect.x() ) );
}
Ejemplo n.º 23
0
Archivo: Utils.C Proyecto: 913862627/wt
WString htmlEncode(const WString& text, WFlags<HtmlEncodingFlag> flags)
{
  return WString::fromUTF8(htmlEncode(text.toUTF8(), flags));
}
Ejemplo n.º 24
0
WString GetFileDisplayName(const WString& fullPath)
{
	SHFILEINFO info;
	DWORD result=SHGetFileInfo(fullPath.Buffer(), 0, &info, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME);
	return result?info.szDisplayName:L"";
}
Ejemplo n.º 25
0
	void Console::SetTitle(const WString& string)
	{
		SetConsoleTitle(string.Buffer());
	}
Ejemplo n.º 26
0
WString GetFileTypeName(const WString& fullPath)
{
	SHFILEINFO info;
	DWORD result=SHGetFileInfo(fullPath.Buffer(), 0, &info, sizeof(SHFILEINFO), SHGFI_TYPENAME);
	return result?info.szTypeName:L"";
}
Ejemplo n.º 27
0
void WTemplate::renderTemplateText(std::ostream& result, const WString& templateText)
{
  std::string text;

  WApplication *app = WApplication::instance();

  if (app && (encodeInternalPaths_ || app->session()->hasSessionIdInUrl())) {
    WFlags<RefEncoderOption> options;
    if (encodeInternalPaths_)
      options |= EncodeInternalPaths;
    if (app->session()->hasSessionIdInUrl())
      options |= EncodeRedirectTrampoline;
    WString t = templateText;
    EncodeRefs(t, options);
    text = t.toUTF8();
  } else
    text = templateText.toUTF8();

  std::size_t lastPos = 0;
  std::vector<WString> args;
  std::vector<std::string> conditions;
  int suppressing = 0;

  for (std::size_t pos = text.find('$'); pos != std::string::npos;
       pos = text.find('$', pos)) {

    if (!suppressing)
      result << text.substr(lastPos, pos - lastPos);

    lastPos = pos;

    if (pos + 1 < text.length()) {
      if (text[pos + 1] == '$') { // $$ -> $
	if (!suppressing)
	  result << '$';

	lastPos += 2;
      } else if (text[pos + 1] == '{') {
	std::size_t startName = pos + 2;
	std::size_t endName = text.find_first_of(" \r\n\t}", startName);

	args.clear();
	std::size_t endVar = parseArgs(text, endName, args);

	if (endVar == std::string::npos) {
	  LOG_ERROR("variable syntax error near \"" << text.substr(pos)
		    << "\"");
	  return;
	}

	std::string name = text.substr(startName, endName - startName);
	std::size_t nl = name.length();

	if (nl > 2 && name[0] == '<' && name[nl - 1] == '>') {
	  if (name[1] != '/') {
	    std::string cond = name.substr(1, nl - 2);
	    conditions.push_back(cond);
	    if (suppressing || !conditionValue(cond))
	      ++suppressing;
	  } else {
	    std::string cond = name.substr(2, nl - 3);
	    if (conditions.back() != cond) {
	      LOG_ERROR("mismatching condition block end: " << cond);
	      return;
	    }
	    conditions.pop_back();

	    if (suppressing)
	      --suppressing;
	  }
	} else {
	  if (!suppressing) {
	    std::size_t colonPos = name.find(':');

	    bool handled = false;
	    if (colonPos != std::string::npos) {
	      std::string fname = name.substr(0, colonPos);
	      std::string arg0 = name.substr(colonPos + 1);
	      args.insert(args.begin(), WString::fromUTF8(arg0));
	      if (resolveFunction(fname, args, result))
		handled = true;
	      else
		args.erase(args.begin());
	    }

	    if (!handled)
	      resolveString(name, args, result);
	  }
	}

	lastPos = endVar + 1;
      } else {
	if (!suppressing)
	  result << '$'; // $. -> $.
	lastPos += 1;
      }
    } else {
      if (!suppressing)
	result << '$'; // $ at end of template -> $
      lastPos += 1;
    }

    pos = lastPos;
  }

  result << text.substr(lastPos);
}
Ejemplo n.º 28
0
	void GUIStatusBar::logModified()
	{
		LogEntry entry;
		if(!gDebug().getLog().getLastEntry(entry))
		{
			GUIContent messageContent(HString(L""));
			mMessage->setContent(messageContent);

			return;
		}

		HSpriteTexture iconTexture;
		Color textColor = COLOR_INFO;

		UINT32 logChannel = entry.getChannel();
		switch (logChannel)
		{
		case (UINT32)DebugChannel::Debug:
			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Info, 16, false);
			break;
		case (UINT32)DebugChannel::Warning:
		case (UINT32)DebugChannel::CompilerWarning:
			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Warning, 16, false);
			textColor = COLOR_WARNING;
			break;
		case (UINT32)DebugChannel::Error:
		case (UINT32)DebugChannel::CompilerError:
			iconTexture = BuiltinEditorResources::instance().getLogMessageIcon(LogMessageIcon::Error, 16, false);
			textColor = COLOR_ERROR;
			break;
		}

		WString message = toWString(entry.getMessage());
		size_t lfPos = message.find_first_of('\n');
		size_t crPos = message.find_first_of('\r');
		size_t newlinePos;

		if (lfPos != WString::npos)
		{
			if (crPos != WString::npos)
				newlinePos = std::min(lfPos, crPos);
			else
				newlinePos = lfPos;
		}
		else if (crPos != WString::npos)
			newlinePos = crPos;
		else
			newlinePos = -1;

		if (newlinePos == -1)
		{
			GUIContent messageContent(HString(message), iconTexture);
			mMessage->setContent(messageContent);
			mMessage->setTint(textColor);
		}
		else
		{
			WString firstLine = message.substr(0, newlinePos);

			GUIContent messageContent(HString(firstLine), iconTexture);
			mMessage->setContent(messageContent);
			mMessage->setTint(textColor);
		}		
	}
Ejemplo n.º 29
0
void RichQtfParser::Parse(const char *qtf, int _accesskey)
{
	accesskey = _accesskey;
	term = qtf;
	while(*term) {
		if(Key('[')) {
			Flush();
			fstack.Add(format);
			for(;;) {
				int c = *term;
				if(!c)
					Error("Unexpected end of text");
				term++;
				if(c == ' ' || c == '\n') break;
				switch(c) {
				case 's': {
					Uuid id;
					c = *term;
					if(Key('\"') || Key('\''))
						id = target.GetStyleId(GetText(c));
					else {
						int i = ReadNumber();
						if(i >= 0 && i < styleid.GetCount())
							id = styleid[i];
						else
							id = RichStyle::GetDefaultId();
					}
					const RichStyle& s = target.GetStyle(id);
					bool p = format.newpage;
					int lng = format.language;
					(RichPara::Format&) format = s.format;
					format.styleid = id;
					format.language = lng;
					format.newpage = p;
					break;
				}
				case '/': format.Italic(!format.IsItalic()); break;
				case '*': format.Bold(!format.IsBold()); break;
				case '_': format.Underline(!format.IsUnderline()); break;
				case 'T': format.NonAntiAliased(!format.IsNonAntiAliased()); break;
				case '-': format.Strikeout(!format.IsStrikeout()); break;
				case 'c': format.capitals = !format.capitals; break;
				case 'd': format.dashed = !format.dashed; break;
				case '`': format.sscript = format.sscript == 1 ? 0 : 1; break;
				case ',': format.sscript = format.sscript == 2 ? 0 : 2; break;
				case '^': format.link = GetText('^'); break;
				case 'I': format.indexentry = FromUtf8(GetText(';')); break;
				case '+': format.Height(GetNumber()); break;
				case '@': format.ink = GetColor(); break;
				case '$': format.paper = GetColor(); break;
				case 'A': format.Face(Font::ARIAL); break;
				case 'R': format.Face(Font::ROMAN); break;
				case 'C': format.Face(Font::COURIER); break;
				case 'G': format.Face(Font::STDFONT); break;
				case 'S':
#ifdef PLATFORM_WIN32
					format.Face(Font::SYMBOL);
#endif
					break;
				case '.': {
					int n = GetNumber();
					if(n >= Font::GetFaceCount())
						Error("Invalid face number");
					format.Face(n); break;
				}
				case '!': {
						String fn = GetText('!');
						int i = Font::FindFaceNameIndex(fn);
						if(i < 0)
							i = Font::ARIAL;
						format.Face(i);
					}
					break;
				case '{': {
						String cs = GetText('}');
						if(cs.GetLength() == 1) {
							int c = *cs;
							if(c == '_')
								format.charset = CHARSET_UTF8;
							if(c >= '0' && c <= '8')
								format.charset = c - '0' + CHARSET_WIN1250;
							if(c >= 'A' && c <= 'Z')
								format.charset = c - '0' + CHARSET_ISO8859_1;
						}
						else {
							for(int i = 0; i < CharsetCount(); i++)
								if(stricmp(CharsetName(i), cs) == 0) {
									format.charset = i;
									break;
								}
						}
						break;
					}
				case '%': {
						String h;
						if(*term == '-') {
							format.language = 0;
							term++;
						}
						else
						if(*term == '%') {
							format.language = LNG_ENGLISH;
							term++;
						}
						else {
							while(*term && h.GetLength() < 5)
								h.Cat(*term++);
							format.language = LNGFromText(h);
						}
						break;
					}
				case 'g':
					format.Face(Font::STDFONT);
					format.Height(GetRichTextScreenStdFontHeight());
					break;
				default:
					if(c >= '0' && c <= '9') {
						format.Height(QTFFontHeight[c - '0']);
						break;
					}
					switch(c) {
					case ':': format.label = GetText(':'); break;
					case '<': format.align = ALIGN_LEFT; break;
					case '>': format.align = ALIGN_RIGHT; break;
					case '=': format.align = ALIGN_CENTER; break;
					case '#': format.align = ALIGN_JUSTIFY; break;
					case 'l': format.lm = GetNumber(); break;
					case 'r': format.rm = GetNumber(); break;
					case 'i': format.indent = GetNumber(); break;
					case 'b': format.before = GetNumber(); break;
					case 'a': format.after = GetNumber(); break;
					case 'P': format.newpage = !format.newpage; break;
					case 'k': format.keep = !format.keep; break;
					case 'K': format.keepnext = !format.keepnext; break;
					case 'H': format.ruler = GetNumber(); break;
					case 'h': format.rulerink = GetColor(); break;
					case 'L': format.rulerstyle = GetNumber(); break;
					case 'Q': format.orphan = !format.orphan; break;
					case 'n': format.before_number = GetText(';'); break;
					case 'm': format.after_number = GetText(';'); break;
					case 'N': {
						memset(format.number, 0, sizeof(format.number));
						format.reset_number = false;
						int i = 0;
						while(i < 8) {
							int c;
							if(Key('-'))
								c = RichPara::NUMBER_NONE;
							else
							if(Key('1'))
								c = RichPara::NUMBER_1;
							else
							if(Key('0'))
								c = RichPara::NUMBER_0;
							else
							if(Key('a'))
								c = RichPara::NUMBER_a;
							else
							if(Key('A'))
								c = RichPara::NUMBER_A;
							else
							if(Key('i'))
								c = RichPara::NUMBER_i;
							else
							if(Key('I'))
								c = RichPara::NUMBER_I;
							else
								break;
							format.number[i++] = c;
						}
						if(Key('!'))
							format.reset_number = true;
						break;
					}
					case 'o': format.bullet = RichPara::BULLET_ROUND;
					          format.indent = 150; break;
					case 'O':
						if(Key('_'))
							format.bullet = RichPara::BULLET_NONE;
						else {
							int c = *term++;
							if(!c)
								Error("Unexpected end of text");
							format.bullet =
							                c == '1' ? RichPara::BULLET_ROUNDWHITE :
							                c == '2' ? RichPara::BULLET_BOX :
							                c == '3' ? RichPara::BULLET_BOXWHITE :
							                c == '9' ? RichPara::BULLET_TEXT :
							                           RichPara::BULLET_ROUND;
						}
						break;
					case 'p':
						switch(*term++) {
						case 0:   Error("Unexpected end of text");
						case 'h': format.linespacing = RichPara::LSP15; break;
						case 'd': format.linespacing = RichPara::LSP20; break;
						default:  format.linespacing = RichPara::LSP10;
						}
						break;
					case 't':
						if(IsDigit(*term)) //temporary fix... :(
							format.tabsize = ReadNumber();
						break;
					case '~': {
							if(Key('~'))
								format.tab.Clear();
							else {
								RichPara::Tab tab;
								Key('<');
								if(Key('>'))
									tab.align = ALIGN_RIGHT;
								if(Key('='))
									tab.align = ALIGN_CENTER;
								if(Key('.'))
									tab.fillchar = 1;
								if(Key('-'))
									tab.fillchar = 2;
								if(Key('_'))
									tab.fillchar = 3;
								int rightpos = Key('>') ? RichPara::TAB_RIGHTPOS : 0;
								tab.pos = rightpos | ReadNumber();
								format.tab.Add(tab);
							}
						}
						break;
					default:
						continue;
					}
				}
			}
			SetFormat();
		}
		else
		if(Key(']')) {
			Flush();
			if(fstack.GetCount()) {
				format = fstack.Top();
				fstack.Drop();
			}
			else
				Error("Unmatched ']'");
		}
		else
		if(Key2('{')) {
			if(oldtab)
				Error("{{ in ++ table");
			if(text.GetLength() || paragraph.GetCount())
				EndPart();
			table.Add();
			int r = IsDigit(*term) ? ReadNumber() : 1;
			Table().AddColumn(r);
			while(Key(':'))
				Table().AddColumn(ReadNumber());
			TableFormat();
			SetFormat();
		}
		else
		if(Key2('}')) {
			if(oldtab)
				Error("}} in ++ table");
			FinishTable();
		}
		else
		if(Key2('+'))
			if(oldtab)
				FinishOldTable();
			else {
				Flush();
				if(text.GetLength() || paragraph.GetCount())
					EndPart();
				Tab& b = table.Add();
				b.rown.Add(0);
				b.hspan = 1;
				b.Old();
				oldtab = true;
			}
		else
		if(Key2('|'))
			FinishCell();
		else
		if(Key2('-')) {
			FinishCell();
			table.Top().rown.Add(0);
		}
		else
		if(Key2(':')) {
			if(!oldtab)
				FinishCell();
			TableFormat(oldtab);
		}
		else
		if(Key2('^')) {
			EndPart();
			breakpage = true;
		}
		else
		if(Key2('@')) {
			ReadObject();
		}
		else
		if(Key2('@', '$')) {
			String xu;
			while(isxdigit(*term))
				xu.Cat(*term++);
			int c = stou(~xu, NULL, 16);
			if(c >= 32)
				Cat(c);
			if(*term == ';')
				term++;
			SetFormat();
		}
		else
		if(Key2('^', 'H'))
			target.SetHeaderQtf(GetText2('^', '^'));
		else
		if(Key2('^', 'F'))
			target.SetFooterQtf(GetText2('^', '^'));
		else
		if(Key2('{', ':')) {
			Flush();
			String field = GetText(':');
			String param = GetText(':');
			Id fid(field);
			if(RichPara::fieldtype().Find(fid) >= 0)
				paragraph.Cat(fid, param, format);
			Key('}');
		}
		else
		if(Key('&')) {
			SetFormat();
			EndPart();
		}
		else
		if(Key2('$')) {
			Flush();
			int i = GetNumber();
			Uuid id;
			RichStyle style;
			style.format = format;
			if(Key(','))
				stylenext.At(i, 0) = GetNumber();
			else
				stylenext.At(i, 0) = i;
			if(Key('#')) {
				String xu;
				while(isxdigit(*term))
					xu.Cat(*term++);
				if(xu.GetLength() != 32)
					Error("Invalid UUID !");
				id = ScanUuid(xu);
			}
			else
				if(i)
					id = Uuid::Create();
				else
					id = RichStyle::GetDefaultId();
			if(Key(':'))
				style.name = GetText(']');
			if(fstack.GetCount()) {
				format = fstack.Top();
				fstack.Drop();
			}
			target.SetStyle(id, style);
			styleid.At(i, RichStyle::GetDefaultId()) = id;
			if(id == RichStyle::GetDefaultId()) {
				bool p = format.newpage;
				int lng = format.language;
				(RichPara::Format&) format = style.format;
				format.styleid = id;
				format.language = lng;
				format.newpage = p;
			}
		}
		else
		if(*term == '_') {
			SetFormat();
			text.Cat(160);
			term++;
		}
		else
		if(Key2('-', '|')) {
			SetFormat();
			text.Cat(9);
		}
		else
		if(*term == '\1') {
			if(istable)
				EndPart();
			SetFormat();
			const char *b = ++term;
			for(; *term && *term != '\1'; term++) {
				if((byte)*term == '\n') {
					text.Cat(ToUnicode(b, (int)(term - b), format.charset));
					EndPart();
					b = term + 1;
				}
				if((byte)*term == '\t') {
					text.Cat(ToUnicode(b, (int)(term - b), format.charset));
					text.Cat(9);
					b = term + 1;
				}
			}
			text.Cat(ToUnicode(b, (int)(term - b), format.charset));
			if(*term == '\1')
				term++;
		}
		else {
			if(!Key('`')) Key('\\');
			if((byte)*term >= ' ') {
				SetFormat();
				do {
					if(istable)
						EndPart();
					if(format.charset == CHARSET_UTF8) {
						word code = (byte)*term++;
						if(code <= 0x7F)
							Cat(code);
						else
						if(code <= 0xDF) {
							if(*term == '\0') break;
							int c0 = (byte)*term++;
							if(c0 < 0x80)
								Error("Invalid UTF-8 sequence");
							Cat(((code - 0xC0) << 6) + c0 - 0x80);
						}
						else
						if(code <= 0xEF) {
							int c0 = (byte)*term++;
							int c1 = (byte)*term++;
							if(c0 < 0x80 || c1 < 0x80)
								Error("Invalid UTF-8 sequence");
							Cat(((code - 0xE0) << 12) + ((c0 - 0x80) << 6) + c1 - 0x80);
						}
						else
							Error("Invalid UTF-8 sequence");
					}
					else
						Cat(ToUnicode((byte)*term++, format.charset));
				}
				while((byte)*term >= 128 || s_nodeqtf[(byte)*term]);
			}
			else
			if(*term)
				term++;
		}
	}
//	if(paragraph.GetCount() == 0) // TRC 11/02/15: kills formatting of last paragraph in text
//		SetFormat();
	if(oldtab)
		FinishOldTable();
	else
		while(table.GetCount())
			FinishTable();
	EndPart();
	FlushStyles();
}
Ejemplo n.º 30
0
bool TreeFuncNode::TreeFuncHook( drmem_hdl owner, dr_ref_info * ref,
                                 char* ownerName, void * info )
//------------------------------------------------------------------
// this function really needs to be split up
{
    int             parentIndex;
    int             parentRoot;
    TreeFuncNode *  parent = NULL;
    int             childIndex;
    int             childRoot;
    TreeFuncNode *  child = NULL;
    FuncSearchData* data = (FuncSearchData *) info;
    char *          depName;
    bool            accept;

    #if DEBUG
    data->funcsFound += 1;

    if( !(data->funcsFound % 10) ) {
        WString stat;
        stat.printf( "Loading - %d found", data->funcsFound );
        browseTop->statusText( stat.gets() );
    }
    #endif

    // find if the symbol matches the filter

    depName = DRGetName( ref->dependent );
    accept = data->key->matches( ref->dependent, depName );
    WBRFree( depName ); // OPTIMIZE -- could use this later

    if( !accept ) {
        return true;    // <---- early return -- discard symbol, keep looking
    }


    for( int i = data->roots->count(); i > 0; i -= 1 ) {
        TreeFuncNode * rt = (TreeFuncNode*) (*data->roots)[ i - 1 ];
        parentIndex = rt->findNode( owner );
        if( !parent ) {
            if( parentIndex >= 0 ) {
                parent = (TreeFuncNode *)(*rt->_flatNodes)[ parentIndex ];
                parentRoot = i - 1;
            }
        }

        if( !child ) {
            childIndex = rt->findNode( ref->dependent );
            if( childIndex >= 0 ) {
                child = (TreeFuncNode *)(*rt->_flatNodes)[ childIndex ];
                childRoot = i - 1;
            }
        }

        if( child != NULL && parent != NULL ) {
            break;
        }
    }

    if( child != NULL && parent != NULL ) {
        WBRFree( ownerName );

        if( parentRoot == childRoot ) {
            int prtIdx = child->findParent( parent );
            if( prtIdx < 0 ) {
                if( ref->dependent == owner ) {     // direct recursion -- a->a
                    bool inReferences = false;

                    for( int refIdx = 0; refIdx < child->_flatReferences->count(); refIdx += 1 ) {
                        if( (*child->_flatReferences)[ refIdx ]->getHandle() == owner ) {
                            TreeNode * node = (*child->_flatReferences)[ refIdx ];
                            for( int ref2idx = 0; ref2idx < node->getCount( ParentList ); ref2idx += 1 ) {
                                if( node->getNode( ParentList, ref2idx )->getHandle() == owner ) {
                                    TreePtr * ptr = node->getPtr( ParentList, ref2idx );
                                    ((TreeRefPtr*)ptr)->incRefs();
                                    inReferences = true;
                                    break;
                                }
                            }
                        }
                        if( inReferences ) {
                            break;
                        }
                    }

                    if( !inReferences ) {
                        TreeRefNode * newRef;
                        newRef = new TreeRefNode( data->parentWin, parent, parent );
                        parent->_children.add( newRef );
                        parent->_hasRef = true;

                        parent->_flatReferences->add( newRef );
                    }
                } else {
                    parent->_children.add( child );
                    child->_parents.add(
                        new TreeFuncPtr( data->parentWin, child, parent, *ref ) );
                }
            } else {
                TreePtr * ptr = child->getPtr( ParentList, prtIdx );
                ((TreeFuncPtr *)ptr)->incRefs();
            }
        } else {
            int     i;

            for( i = child->_flatNodes->count(); i > 0; i -= 1 ) {
                parent->_flatNodes->add( (*child->_flatNodes)[ i - 1 ] );
            }

            data->roots->removeAt( childRoot );
            parent->_children.add( child );
            child->_parents.add(
                    new TreeFuncPtr( data->parentWin, child, parent, *ref ) );

            TreeCycleList * fList = child->_flatNodes;
            TreeRefList * rList = child->_flatReferences;

            for( i = fList->count(); i > 0; i -= 1 ) {
                TreeFuncNode * node = (TreeFuncNode *) (*fList)[ i - 1 ];
                node->_flatNodes = parent->_flatNodes;
                node->_flatReferences = parent->_flatReferences;
            }

            for( i = rList->count(); i > 0; i -= 1 ) {
                parent->_flatReferences->add( (*rList)[ i - 1 ] );
            }

            delete fList;
            delete rList;
        }
    } else {
        if( child != NULL ) {
            parent = new TreeFuncNode( data->parentWin, DRGetSymType( owner ),
                                       owner, data->mod, ownerName,
                                       child->_flatNodes,
                                       child->_flatReferences );

            parent->_children.add( child );
            child->_parents.add(
                    new TreeFuncPtr( data->parentWin, child, parent, *ref ) );
        } else {
            if( parent != NULL ) {
                WBRFree( ownerName );

                child = new TreeFuncNode( data->parentWin,
                                          DRGetSymType( ref->dependent ),
                                          ref->dependent, data->mod,
                                          DRGetName( ref->dependent ),
                                          parent->_flatNodes,
                                          parent->_flatReferences );
                parent->_children.add( child );
                child->_parents.add(
                    new TreeFuncPtr( data->parentWin, child, parent, *ref ) );

            } else {    // child == parent == NULL

                parent = new TreeFuncNode( data->parentWin,
                                           DRGetSymType( owner ),
                                           owner, data->mod, ownerName );

                if( ref->dependent == owner ) {
                    TreeRefNode * newRef;
                    newRef = new TreeRefNode( data->parentWin, parent, parent );
                    parent->_children.add( newRef );
                    parent->_hasRef = true;

                    parent->_flatReferences->add( newRef );
                } else {
                    child = new TreeFuncNode( data->parentWin,
                                              DRGetSymType( ref->dependent ),
                                              ref->dependent, data->mod,
                                              DRGetName( ref->dependent ),
                                              parent->_flatNodes,
                                              parent->_flatReferences );

                    child->_parents.add(
                        new TreeFuncPtr( data->parentWin, child, parent, *ref ) );
                    parent->_children.add( child );
                }

                data->roots->add( parent );
            }
        }
    }

    return true;
}