Esempio n. 1
0
static std::vector<wchar_t> FindPathStr( int drive, const unicode_t* s, wchar_t* cat )
{
	int lcat = Utf16Chars( cat );

	std::vector<wchar_t> p( 10 + unicode_strlen( s ) + lcat + 1 );
	wchar_t* d = p.data();

	d[0] = '\\';
	d[1] = '\\';
	d[2] = '?';
	d[3] = '\\';
	d += 4;

	if ( drive == -1 ) //???
	{
		d[0] = 'U';
		d[1] = 'N';
		d[2] = 'C';
		//d[3]='\\'; //еше \ добавится из пути
		d += 3;
	}
	else
	{
		d[0] = drive + 'a';
		d[1] = ':';
		d += 2;
	}

	for ( ; *s; s++, d++ ) { *d = *s; }

	for ( ; *cat; cat++, d++ ) { *d = *cat; }

	*d = 0;
	return p;
}
Esempio n. 2
0
/* static void Editable_Delete( SDLGuiTK_Editable * editable, int del_index ) */
void SDLGuiTK_editable_delete_text( SDLGuiTK_Editable *editable, \
				    int start_pos, int end_pos )
{
  char *s, *t;
  char *result;
  int from_size, index;

  char *ts;
  from_size=unicode_strlen(editable->text,-1);

  if( start_pos<=-1 ) return;
  if( end_pos>from_size ) return;

  result = calloc( MyTTF_MAX_CHARS, sizeof(char) );
  s = editable->text;
  t = result;
  index = 0;
  while( *s ) {
    if( index<start_pos || index>=end_pos ) {
      ts = s;
      s = unicode_next_utf8( s );
      while( ts!=s ) { *t = *ts; ts++; t++; };
    } else {
      s = unicode_next_utf8( s );
    }
    index++;
  }
  *t = 0;
  free( editable->text );
  editable->text = result;
}
Esempio n. 3
0
static std::vector<wchar_t> SysPathStr( int drive, const unicode_t* s )
{
	std::vector<wchar_t> p( 10 + unicode_strlen( s ) + 1 ); //+10 прозапас, вообще +8 (макс \\?\UNC\)
	wchar_t* d = p.data();

	d[0] = '\\';
	d[1] = '\\';
	d[2] = '?';
	d[3] = '\\';
	d += 4;

	if ( drive == -1 ) //???
	{
		d[0] = 'U';
		d[1] = 'N';
		d[2] = 'C';
		//d[3]='\\'; //еше \ добавится из пути
		d += 3;
	}
	else
	{
		d[0] = drive + 'a';
		d[1] = ':';
		d += 2;
	}

	for ( ; *s; s++, d++ ) { *d = *s; }

	*d = 0;
	return p;
}
  void set_role(const char *role) {

    if (unicode_strlen(role) > 255) {
      throw xml_error(
          "Relation Role has more than 255 unicode characters");
    }

    m_role = std::string(role);
  }
Esempio n. 5
0
void PROT__editable_settext( SDLGuiTK_Editable * editable, \
			     const char *text )
{
  int text_lenght;

  text_lenght = unicode_strlen( text, -1 );

  free( editable->text );
  editable->text = calloc( MyTTF_MAX_CHARS, sizeof( char ) );
  strcpy( editable->text, text );
  editable->cursor_position = text_lenght;
}
Esempio n. 6
0
inline std::vector<wchar_t> UnicodeToUtf16_cat( const unicode_t* s, wchar_t* cat )
{
	int lcat = Utf16Chars( cat );
	std::vector<wchar_t> p( unicode_strlen( s ) + lcat + 1 );
	wchar_t* d;

	for ( d = p.data(); *s; s++, d++ ) { *d = *s; }

	for ( ; *cat; cat++, d++ ) { *d = *cat; }

	*d = 0;
	return p;
}
Esempio n. 7
0
void DrawStaticText(GC &gc, int x, int y, const unicode_t *s, cfont *font, bool transparent)
{
	if (font) gc.Set(font);
	while (*s) {
		const unicode_t *t = unicode_strchr(s,'\n');
		int len = (t ? t-s : unicode_strlen(s));
		gc.TextOutF(x,y,s,len);
		cpoint c = gc.GetTextExtents(s,len);
		s +=len;
		if (t) s++;
		if (*s == '\r') s++;
		y += c.y;
	}
}
Esempio n. 8
0
cpoint StaticTextSize(GC &gc, const unicode_t *s, cfont *font)
{
	cpoint p(0,0);
	if (font) gc.Set(font);
	while (*s) {
		const unicode_t *t = unicode_strchr(s,'\n');
		int len = (t ? t-s : unicode_strlen(s));

		cpoint c = gc.GetTextExtents(s,len); 
		s +=len;
		if (t) s++;
		if (*s == '\r') s++;
		p.y += c.y;
		if (p.x<c.x) p.x = c.x;
	}
	return p;
}
Esempio n. 9
0
cpoint GetStaticTextExtent(GC &gc, const unicode_t *s, cfont *font)
{
	cpoint res(0,0),c;
	if (font) gc.Set(font);
	while (*s) {
		const unicode_t *t = unicode_strchr(s,'\n');
		int len = (t ? t-s : unicode_strlen(s));

		c = gc.GetTextExtents(s,len);
		s +=len;
		if (t) s++;
		if (*s == '\r') s++;
		res.y += c.y;
		if (res.x < c.x)
			res.x = c.x;
	}
	return res;
}
Esempio n. 10
0
void OperFileNameWin::Paint(wal::GC &gc, const crect &paintRect)
{
	crect rect = ClientRect();
	gc.SetFillColor(UiGetColor(uiBackground,0,0,0xFFFFFF));
	gc.FillRect(rect); 
	gc.SetTextColor(UiGetColor(uiColor,0,0,0));
	gc.Set(GetFont());
	
	unicode_t *p = text.ptr();
	if (p) 
	{
		int l = unicode_strlen(p);
		if (l > _ccount) 
		{
			p += l - _ccount;
		}
		DrawStaticText(gc,0,0,p);
	}
}
Esempio n. 11
0
static char *
convert_ucs2xx_to_utf8(iconv_t cd, const uint16_t *us)
{
	char *obuf, *optr;
	const char *iptr;
	size_t  ileft, obsize, oleft, ret;

	if (cd == (iconv_t)-1) {
		smb_error(dgettext(TEXT_DOMAIN,
		    "iconv_open(UTF-8/UCS-2)"), -1);
		return (NULL);
	}

	iptr = (const char *)us;
	ileft = unicode_strlen(us);
	ileft *= 2; /* now bytes */

	/* Worst-case output size is 2x input size. */
	oleft = ileft * 2;
	obsize = oleft + 2; /* room for null */
	obuf = malloc(obsize);
	if (!obuf)
		return (NULL);
	optr = obuf;

	ret = iconv(cd, &iptr, &ileft, &optr, &oleft);
	*optr = '\0';
	if (ret == (size_t)-1) {
		smb_error(dgettext(TEXT_DOMAIN,
		    "iconv(%s) failed"), errno, obuf);
	}
	if (ileft) {
		smb_error(dgettext(TEXT_DOMAIN,
		    "iconv(%s) failed"), -1, obuf);
		/*
		 * XXX: What's better?  return NULL?
		 * The truncated string? << for now
		 */
	}

	return (obuf);
}
Esempio n. 12
0
SDL_Surface * PROT__editable_makeblended( SDL_Surface * render_text, \
					 SDLGuiTK_Editable * editable, \
					 int size, SDL_Color color )
{
  char tmpstr[512];
  int text_lenght;
  int index=0, i=0;
  int current_pos=0;
  SDL_Surface * line_surf[3];
  SDL_Rect      line_area[3];
  SDLGuiTK_Theme * theme;
  char   text_displayed[512];
  char line_text[3][MyTTF_MAX_CHARS];
  char *s, *s_cursor;

  char *ts;

  strcpy( text_displayed, editable->text );
  strcat( text_displayed, " " );
  text_lenght = unicode_strlen( text_displayed, MyTTF_MAX_CHARS );
  s = text_displayed;
/*   printf( "text_lenght=%d (%s) curs_pos=%d\n", text_lenght, text_displayed, editable->cursor_position); */

  if( render_text!=NULL ) {
    MySDL_FreeSurface( render_text );
    render_text = NULL;
  }

  if( editable->cursor_position>=text_lenght ) {
    SDLGUITK_ERROR( "MyTTF_Editable_MakeBlended(): cursor_pos>=text_lenght\n" );
    editable->cursor_position = text_lenght-1;
  } else if( editable->cursor_position<=-1 ) {
    SDLGUITK_ERROR( "MyTTF_Editable_MakeBlended(): cursor_pos<0\n" );
    editable->cursor_position = 0;
  }

  s_cursor = text_displayed;
  i=0;
  while(i!=editable->cursor_position) {
    s_cursor = unicode_next_utf8( s_cursor );
    i++;
  }

  if( editable->cursor_position>0 ) {
    while( s!=s_cursor ) {
      ts = s;
      s = unicode_next_utf8( s );
      while( ts!=s ) {
	line_text[0][current_pos++] = *ts;
	ts++;
      }
      
      index++;
    }
    line_text[0][current_pos] = 0;
    current_pos = 0;

    line_surf[0] = MyTTF_Render_Blended( NULL, \
					 line_text[0], size, \
					 MyTTF_STYLE_NORMAL, \
					 color );
    sprintf( tmpstr, "MyTTF_Editable_MakeBlended(): part0 \"%s\"\n", \
	     line_text[0] );
    SDLGUITK_LOG( tmpstr );
    line_area[0].x = 0;
    line_area[0].y = 0;
    line_area[0].w = line_surf[0]->w;
    line_area[0].h = line_surf[0]->h;
  } else {
    line_surf[0] = NULL;
    line_area[0].x = 0;
    line_area[0].y = 0;
    line_area[0].w = 0;
    line_area[0].h = 0;
  }
  
  ts = s;
  s = unicode_next_utf8( s );
  while( ts!=s ) {
    line_text[1][current_pos++] = *ts;
    ts++;
  }
  line_text[1][current_pos++] = 0;
  index++;
  current_pos = 0;

  line_surf[1] = MyTTF_Render_Blended( NULL, \
				       line_text[1], size, \
				       MyTTF_STYLE_UNDERLINE, \
				       color );
  sprintf( tmpstr, "MyTTF_Editable_MakeBlended(): part1 \"%s\"\n", \
	   line_text[1] );
  SDLGUITK_LOG( tmpstr );
  line_area[1].x = line_area[0].w+1;
  line_area[1].y = 0;
  line_area[1].w = line_surf[1]->w;
  line_area[1].h = line_surf[1]->h;
  
  if( editable->cursor_position<text_lenght-1 ) {
    while( *s ) {
      ts = s;
      s = unicode_next_utf8( s );
      while( ts!=s ) {
	line_text[2][current_pos++] = *ts;
	ts++;
      }
      index++;
    }
    line_text[2][current_pos++] = 0;
    current_pos = 0;

    line_surf[2] = MyTTF_Render_Blended( NULL, \
					 line_text[2], size, \
					 MyTTF_STYLE_NORMAL, \
					 color );
    sprintf( tmpstr, "MyTTF_Editable_MakeBlended(): part2 \"%s\"\n", \
	     line_text[2] );
    SDLGUITK_LOG( tmpstr );
    line_area[2].x = line_area[0].w+line_area[1].w+1;
    line_area[2].y = 0;
    line_area[2].w = line_surf[2]->w;
    line_area[2].h = line_surf[2]->h;
  } else {
    line_surf[2] = NULL;
    line_area[2].x = 0;
    line_area[2].y = 0;
    line_area[2].w = 0;
    line_area[2].h = 0;
  }
  theme = PROT__theme_get_and_lock();
  render_text = MySDL_CreateRGBSurface_WithColor( render_text, \
						  line_area[0].w+line_area[1].w+line_area[2].w, line_area[1].h, \
						  theme->bgcolor );
  PROT__theme_unlock( theme );
  for( i=0; i<=2; i++ ) {
    if( line_surf[i]!=NULL ) {
      SDL_BlitSurface( line_surf[i], NULL, \
		       render_text, &line_area[i] );
      //2SDL_UpdateRects( render_text, 1, &line_area[i] );
	  //SDL_UpdateWindowSurface( render_text );
      SDL_FreeSurface( line_surf[i] );
    }
  }

  return render_text;
}
Esempio n. 13
0
void SDLGuiTK_editable_insert_text( SDLGuiTK_Editable *editable, \
				    const char *new_text, \
				    int new_text_length, int *position )
{
  int from_index=0, result_index=0;
  char *result=calloc( MyTTF_MAX_CHARS, sizeof( char ) );
  int from_size, new_text_size, cursor_mvt=0;
  char *f, *nt;

  char *ts;

  from_size = unicode_strlen( editable->text, -1 );
  new_text_size = unicode_strlen( new_text, -1 );
  if( new_text_size==0 || new_text_length==0 ) return;
  if( new_text_length>=0 && new_text_length<new_text_size ) {
    new_text_size = new_text_length;
  }
/*   ch = PROT_editable_getUTF8( keysym->unicode ); */
  f = editable->text;
  nt = (char *) new_text;

  while( *f ) {
    if( from_index==*position ) {
      while( new_text_size!=0 && *nt ) {
	ts = nt;
	nt = unicode_next_utf8( nt );
	while( ts!=nt ) {
	  result[result_index++] = *ts;
	  ts++;
	}
	cursor_mvt++;
	new_text_size--;
      }
    }
    ts = f;
    f = unicode_next_utf8( f );
    while( ts!=f ) {
      result[result_index++] = *ts;
      ts++;
    }
    from_index++;
  }
  if( *position==from_size ) {
    while( new_text_size!=0 && *nt ) {
      ts = nt;
      nt = unicode_next_utf8( nt );
      while( ts!=nt ) {
	result[result_index++] = *ts;
	ts++;
      }
      cursor_mvt++;
      new_text_size--;
    }
  }
  result[result_index] = 0;
/*   printf( "A from_size=%d from_index=%d to_index=%d (%s)\n", from_size, from_index, to_index, result ); */

  free( editable->text );
  editable->text = &result[0];
  *position += cursor_mvt;

}
Esempio n. 14
0
void FSPath::MakeCache( int cs, unicode_t splitter )
{
	ASSERT( data.count() >= 0 );

	if ( Count() == 1 && data[0].IsEmpty() ) // значит просто "/"
	{
		if ( cs == CS_UNICODE )
		{
			SetCacheSize( 2 * sizeof( unicode_t ) );
			( ( unicode_t* )cache.data() )[0] = splitter;
			( ( unicode_t* )cache.data() )[1] = 0;
		}
		else
		{
			SetCacheSize( 2 );
			cache[0] = char( splitter & 0xFF );
			cache[1] = 0;
		}

		cacheCs = cs;
		cacheSplitter = splitter;
		return;
	}

	int i, l;

	if ( cs == CS_UNICODE )
	{
		for ( i = l = 0; i < data.count(); i++ )
		{
			l += unicode_strlen( ( unicode_t* )data[i].Get( cs ) );
		}

		l += data.count() - 1; //разделители

		if ( l < 0 ) { l = 0; }

		SetCacheSize( ( l + 1 )*sizeof( unicode_t ) );

		unicode_t* p = ( unicode_t* ) cache.data();

		for ( i = 0; i < data.count(); i++ )
		{
			const void* v = data[i].Get( cs );
			l = unicode_strlen( ( unicode_t* )v );

			if ( l ) { memcpy( p, v, l * sizeof( unicode_t ) ); }

			p += l;

			if ( i + 1 < data.count() ) { *( p++ ) = splitter; }      /////////////// !!!
		}

		*p++ = 0;
	}
	else
	{
		for ( i = l = 0; i < data.count(); i++ )
		{
			l += strlen( ( char* )data[i].Get( cs ) );
		}

		l += data.count() - 1; //разделители

		if ( l < 0 ) { l = 0; }

		SetCacheSize( ( l + 1 )*sizeof( char ) );

		char* p = cache.data();

		for ( i = 0; i < data.count(); i++ )
		{
			const void* v = data[i].Get( cs );
			l = strlen( ( char* )v );

			if ( l ) { strcpy( p, ( char* )v ); }

			p += l;

			if ( i + 1 < data.count() ) { *( p++ ) = char( splitter & 0xFF ); }        /////////////// !!!
		}

		*p++ = 0;
	}

	cacheCs = cs;
	cacheSplitter = splitter;
}