Compare commits
	
		
			2 Commits
		
	
	
		
			e28e576fdb
			...
			d13b4a793d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d13b4a793d | |||
| 0570a4d050 | 
							
								
								
									
										42
									
								
								src/sdtui.c
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								src/sdtui.c
									
									
									
									
									
								
							| @ -166,6 +166,7 @@ struct application | |||||||
| 	GPtrArray     * entries;            ///< ViewEntry-s within the view
 | 	GPtrArray     * entries;            ///< ViewEntry-s within the view
 | ||||||
| 
 | 
 | ||||||
| 	gchar         * search_label;       ///< Text of the "Search" label
 | 	gchar         * search_label;       ///< Text of the "Search" label
 | ||||||
|  | 	gsize           search_label_width; ///< Visible width of "search_label"
 | ||||||
| 	GArray        * input;              ///< The current search input
 | 	GArray        * input;              ///< The current search input
 | ||||||
| 	guint           input_pos;          ///< Cursor position within input
 | 	guint           input_pos;          ///< Cursor position within input
 | ||||||
| 	guint           input_offset;       ///< Render offset in codepoints
 | 	guint           input_offset;       ///< Render offset in codepoints
 | ||||||
| @ -486,6 +487,17 @@ app_init_attrs (Application *self) | |||||||
| #undef XX | #undef XX | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static gsize | ||||||
|  | app_utf8_width (Application *self, const char *utf8) | ||||||
|  | { | ||||||
|  | 	gsize width = 0; | ||||||
|  | 	gunichar *ucs4 = g_utf8_to_ucs4_fast (utf8, -1, NULL); | ||||||
|  | 	for (gunichar *it = ucs4; *it; it++) | ||||||
|  | 		width += app_char_width (self, *it); | ||||||
|  | 	g_free (ucs4); | ||||||
|  | 	return width; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static gboolean | static gboolean | ||||||
| app_load_dictionaries (Application *self, GError **e) | app_load_dictionaries (Application *self, GError **e) | ||||||
| { | { | ||||||
| @ -500,11 +512,7 @@ app_load_dictionaries (Application *self, GError **e) | |||||||
| 		gchar *tmp = g_strdup_printf (" %s ", dict->super.name); | 		gchar *tmp = g_strdup_printf (" %s ", dict->super.name); | ||||||
| 		g_free (dict->super.name); | 		g_free (dict->super.name); | ||||||
| 		dict->super.name = tmp; | 		dict->super.name = tmp; | ||||||
| 
 | 		dict->name_width = app_utf8_width (self, dict->super.name); | ||||||
| 		gunichar *ucs4 = g_utf8_to_ucs4_fast (dict->super.name, -1, NULL); |  | ||||||
| 		for (gunichar *it = ucs4; *it; it++) |  | ||||||
| 			dict->name_width += app_char_width (self, *it); |  | ||||||
| 		g_free (ucs4); |  | ||||||
| 	} | 	} | ||||||
| 	return TRUE; | 	return TRUE; | ||||||
| } | } | ||||||
| @ -520,6 +528,15 @@ app_init (Application *self, char **filenames) | |||||||
| 	self->tk = NULL; | 	self->tk = NULL; | ||||||
| 	self->tk_timer = 0; | 	self->tk_timer = 0; | ||||||
| 
 | 
 | ||||||
|  | 	const char *charset = NULL; | ||||||
|  | 	self->locale_is_utf8 = g_get_charset (&charset); | ||||||
|  | #if G_BYTE_ORDER == G_LITTLE_ENDIAN | ||||||
|  | 	self->ucs4_to_locale = g_iconv_open (charset, "UTF-32LE"); | ||||||
|  | #else // G_BYTE_ORDER != G_LITTLE_ENDIAN
 | ||||||
|  | 	self->ucs4_to_locale = g_iconv_open (charset, "UTF-32BE"); | ||||||
|  | #endif // G_BYTE_ORDER != G_LITTLE_ENDIAN
 | ||||||
|  | 	self->focused = TRUE; | ||||||
|  | 
 | ||||||
| 	self->show_help = TRUE; | 	self->show_help = TRUE; | ||||||
| 	self->center_search = TRUE; | 	self->center_search = TRUE; | ||||||
| 	self->underline_last = TRUE; | 	self->underline_last = TRUE; | ||||||
| @ -533,6 +550,7 @@ app_init (Application *self, char **filenames) | |||||||
| 		((GDestroyNotify) view_entry_free); | 		((GDestroyNotify) view_entry_free); | ||||||
| 
 | 
 | ||||||
| 	self->search_label = g_strdup_printf ("%s: ", _("Search")); | 	self->search_label = g_strdup_printf ("%s: ", _("Search")); | ||||||
|  | 	self->search_label_width = app_utf8_width (self, self->search_label); | ||||||
| 
 | 
 | ||||||
| 	self->input = g_array_new (TRUE, FALSE, sizeof (gunichar)); | 	self->input = g_array_new (TRUE, FALSE, sizeof (gunichar)); | ||||||
| 	self->input_pos = self->input_offset = 0; | 	self->input_pos = self->input_offset = 0; | ||||||
| @ -540,15 +558,6 @@ app_init (Application *self, char **filenames) | |||||||
| 
 | 
 | ||||||
| 	self->division = 0.5; | 	self->division = 0.5; | ||||||
| 
 | 
 | ||||||
| 	const char *charset; |  | ||||||
| 	self->locale_is_utf8 = g_get_charset (&charset); |  | ||||||
| #if G_BYTE_ORDER == G_LITTLE_ENDIAN |  | ||||||
| 	self->ucs4_to_locale = g_iconv_open (charset, "UTF-32LE"); |  | ||||||
| #else // G_BYTE_ORDER != G_LITTLE_ENDIAN
 |  | ||||||
| 	self->ucs4_to_locale = g_iconv_open (charset, "UTF-32BE"); |  | ||||||
| #endif // G_BYTE_ORDER != G_LITTLE_ENDIAN
 |  | ||||||
| 	self->focused = TRUE; |  | ||||||
| 
 |  | ||||||
| 	app_init_attrs (self); | 	app_init_attrs (self); | ||||||
| 	self->dictionaries = | 	self->dictionaries = | ||||||
| 		g_ptr_array_new_with_free_func ((GDestroyNotify) dictionary_destroy); | 		g_ptr_array_new_with_free_func ((GDestroyNotify) dictionary_destroy); | ||||||
| @ -1922,10 +1931,7 @@ app_process_left_mouse_click (Application *self, int line, int column) | |||||||
| 	} | 	} | ||||||
| 	else if (line == 1) | 	else if (line == 1) | ||||||
| 	{ | 	{ | ||||||
| 		// FIXME: this is only an approximation
 | 		gint pos = column - self->search_label_width; | ||||||
| 		glong label_width = g_utf8_strlen (self->search_label, -1); |  | ||||||
| 
 |  | ||||||
| 		gint pos = column - label_width; |  | ||||||
| 		if (pos >= 0) | 		if (pos >= 0) | ||||||
| 		{ | 		{ | ||||||
| 			// On clicking the left arrow, go to that invisible character
 | 			// On clicking the left arrow, go to that invisible character
 | ||||||
|  | |||||||
| @ -1014,6 +1014,10 @@ stardict_longest_common_collation_prefix (StardictDict *sd, | |||||||
| 	u_strFromUTF8 (NULL, 0, &uc2_len, s2, -1, &error); | 	u_strFromUTF8 (NULL, 0, &uc2_len, s2, -1, &error); | ||||||
| 	error = U_ZERO_ERROR; | 	error = U_ZERO_ERROR; | ||||||
| 
 | 
 | ||||||
|  | 	// Prevent undefined behaviour with VLAs.
 | ||||||
|  | 	if (!uc1_len || !uc2_len) | ||||||
|  | 		return 0; | ||||||
|  | 
 | ||||||
| 	UChar uc1[uc1_len]; | 	UChar uc1[uc1_len]; | ||||||
| 	UChar uc2[uc2_len]; | 	UChar uc2[uc2_len]; | ||||||
| 	u_strFromUTF8 (uc1, uc1_len, NULL, s1, -1, &error); | 	u_strFromUTF8 (uc1, uc1_len, NULL, s1, -1, &error); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user