1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2 
3 /* AbiSource Application Framework
4  * Copyright (C) 1998-2000 AbiSource, Inc.
5  * Copyright (C) 2009 Hubert Figuiere
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  */
22 
23 // 9/4/04 Updated to use GtkTreeView , Tim O'Brien (obrientimo@vuw.ac.nz)
24 
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 
29 #include <set>
30 #include <string>
31 
32 #include <gtk/gtk.h>
33 #include "ut_assert.h"
34 #include "ut_debugmsg.h"
35 #include "ut_string.h"
36 #include "ut_misc.h"
37 #include "ut_units.h"
38 #include "xap_UnixDialogHelper.h"
39 #include "xap_UnixDlg_FontChooser.h"
40 #include "xap_UnixApp.h"
41 #include "xap_Frame.h"
42 #include "xap_UnixFrameImpl.h"
43 #include "xap_EncodingManager.h"
44 #include "xav_View.h"
45 #include "gr_UnixCairoGraphics.h"
46 
47 #define PREVIEW_BOX_BORDER_WIDTH_PIXELS 8
48 #define PREVIEW_BOX_HEIGHT_PIXELS	80
49 
50 // your typographer's standard nonsense latin font phrase
51 #define PREVIEW_ENTRY_DEFAULT_STRING	"Lorem ipsum dolor sit amet, consectetaur adipisicing..."
52 
53 //
54 // For Screen color picker
55 	enum
56 	{
57 		RED,
58 		GREEN,
59 		BLUE,
60 		OPACITY
61 	};
62 
63 //
64 // List store model , used as model for GtkTreeView
65 	enum
66 	{
67 		TEXT_COLUMN,
68 		N_COLUMNS
69 	};
70 
searchTreeView(GtkTreeView * tv,const char * compareText)71 static gint searchTreeView(GtkTreeView* tv, const char * compareText)
72 {
73        GtkTreeModel* model;
74        GtkTreeIter iter;
75        char* text;
76 
77        UT_ASSERT(tv);
78 
79        // if text is null, it's not found
80        if (!compareText)
81                return -1;
82 
83        model = gtk_tree_view_get_model(GTK_TREE_VIEW(tv));
84        if (! gtk_tree_model_get_iter_first(model, &iter) )
85 		return -1;
86 
87        gint i = 0;
88        do {
89        	       gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1);
90 	       if (!g_ascii_strcasecmp(text, compareText))
91 	                       return i;
92 	       i++;
93        } while(gtk_tree_model_iter_next (model, &iter));
94 
95        return -1;
96 }
97 
98 //
99 // Create GtkTreeView that is similar to a CList
100 // ie single text column, with no header
createFontTabTreeView()101 GtkWidget* createFontTabTreeView()
102 {
103 	GtkWidget* treeView;
104 	GtkListStore* listStore;
105 	GtkTreeViewColumn* column;
106 	GtkCellRenderer* renderer;
107 
108 	treeView = gtk_tree_view_new();
109 	listStore = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
110 	gtk_tree_view_set_model(GTK_TREE_VIEW(treeView), GTK_TREE_MODEL(listStore));
111 	column = gtk_tree_view_column_new();
112 	renderer = gtk_cell_renderer_text_new();
113 	gtk_tree_view_column_pack_start(column, renderer, TRUE);
114 	gtk_tree_view_column_set_attributes(column, renderer, "text", TEXT_COLUMN, NULL);
115 	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
116 	gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), column);
117 	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeView), FALSE);
118 
119 	return treeView;
120 }
121 
122 
123 /*****************************************************************/
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id id)124 XAP_Dialog * XAP_UnixDialog_FontChooser::static_constructor(XAP_DialogFactory * pFactory,
125 														 XAP_Dialog_Id id)
126 {
127 	XAP_UnixDialog_FontChooser * p = new XAP_UnixDialog_FontChooser(pFactory,id);
128 	return p;
129 }
130 
XAP_UnixDialog_FontChooser(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)131 XAP_UnixDialog_FontChooser::XAP_UnixDialog_FontChooser(XAP_DialogFactory * pDlgFactory,
132 												   XAP_Dialog_Id id)
133 	: XAP_Dialog_FontChooser(pDlgFactory,id)
134 {
135 	m_fontList = NULL;
136 	m_styleList = NULL;
137 	m_sizeList = NULL;
138 	m_checkStrikeOut = NULL;
139 	m_checkUnderline = NULL;
140 	m_checkOverline = NULL;
141 	m_checkHidden = NULL;
142 	m_checkTransparency = NULL;
143 	m_checkSubScript = NULL;
144 	m_iSubScriptId = 0;
145 	m_checkSuperScript = NULL;
146 	m_iSuperScriptId = 0;
147 	m_colorSelector = NULL;
148 	m_bgcolorSelector = NULL;
149 	m_preview = NULL;
150 
151 	m_gc = NULL;
152 	m_pFrame = NULL;
153 	m_doneFirstFont = false;
154 
155 	memset(&m_currentFGColor, 0, sizeof(m_currentFGColor));
156 	memset(&m_currentBGColor, 0, sizeof(m_currentBGColor));
157 	m_currentBGColorTransparent = false;
158 	memset(&m_funkyColor, 0, sizeof(m_funkyColor));
159 }
160 
~XAP_UnixDialog_FontChooser(void)161 XAP_UnixDialog_FontChooser::~XAP_UnixDialog_FontChooser(void)
162 {
163 	DELETEP(m_gc);
164 }
165 
166 
167 /*****************************************************************/
168 
s_color_update(GtkWidget *,GdkRGBA *,XAP_UnixDialog_FontChooser * dlg)169 static gint s_color_update(GtkWidget * /* widget */,
170 #if GTK_CHECK_VERSION(3,4,0)
171                            GdkRGBA * /* color */,
172 #endif
173                            XAP_UnixDialog_FontChooser * dlg)
174 {
175 	UT_return_val_if_fail(dlg,FALSE);
176 	dlg->fgColorChanged();
177 	return FALSE;
178 }
179 
s_bgcolor_update(GtkWidget *,GdkRGBA *,XAP_UnixDialog_FontChooser * dlg)180 static gint s_bgcolor_update(GtkWidget * /* widget */,
181 #if GTK_CHECK_VERSION(3,4,0)
182                            GdkRGBA * /* color */,
183 #endif
184 						   XAP_UnixDialog_FontChooser * dlg)
185 {
186 	UT_return_val_if_fail(dlg,FALSE);
187 	dlg->bgColorChanged();
188 	return FALSE;
189 }
190 
s_select_row_font(GtkTreeSelection *,XAP_UnixDialog_FontChooser * dlg)191 static void s_select_row_font(GtkTreeSelection * /* widget */, XAP_UnixDialog_FontChooser * dlg)
192 {
193 	UT_return_if_fail(dlg);
194     // update the row number and show the changed preview
195 	// redisplay the preview text
196 	dlg->fontRowChanged();
197 }
198 
199 
s_select_row_style(GtkTreeSelection *,XAP_UnixDialog_FontChooser * dlg)200 static void s_select_row_style(GtkTreeSelection * /* widget */, XAP_UnixDialog_FontChooser * dlg)
201 {
202 	UT_return_if_fail(dlg);
203 
204 	// redisplay the preview text
205 	dlg->styleRowChanged();
206 }
207 
s_select_row_size(GtkTreeSelection *,XAP_UnixDialog_FontChooser * dlg)208 static void s_select_row_size(GtkTreeSelection * /* widget */, XAP_UnixDialog_FontChooser * dlg)
209 {
210 	UT_return_if_fail(dlg);
211 
212 	// redisplay the preview text
213 	dlg->sizeRowChanged();
214 }
215 
s_drawing_area_draw(GtkWidget * w,cairo_t *)216 static gboolean s_drawing_area_draw(GtkWidget * w,
217 #if GTK_CHECK_VERSION(3,0,0)
218 								  cairo_t * /* pExposeEvent */)
219 #else
220 								  GdkEventExpose * /* pExposeEvent */)
221 #endif
222 {
223 	XAP_UnixDialog_FontChooser * dlg =
224 		(XAP_UnixDialog_FontChooser *)g_object_get_data(G_OBJECT(w), "user-data");
225 	dlg->updatePreview();
226 //	g_idle_add(static_cast<GSourceFunc>(do_update),static_cast<gpointer>(dlg));
227 	return TRUE;
228 }
229 
s_underline_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)230 static void s_underline_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
231 {
232 	dlg->underlineChanged();
233 }
234 
235 
s_overline_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)236 static void s_overline_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
237 {
238 	dlg->overlineChanged();
239 }
240 
241 
s_subscript_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)242 static void s_subscript_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
243 {
244     dlg->subscriptChanged();
245 }
246 
247 
s_superscript_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)248 static void s_superscript_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
249 {
250     dlg->superscriptChanged();
251 }
252 
253 
s_strikeout_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)254 static void s_strikeout_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
255 {
256 	dlg->strikeoutChanged();
257 }
258 
s_hidden_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)259 static void s_hidden_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
260 {
261 	dlg->hiddenChanged();
262 }
263 
264 
s_transparency_toggled(GtkWidget *,XAP_UnixDialog_FontChooser * dlg)265 static void s_transparency_toggled(GtkWidget * ,  XAP_UnixDialog_FontChooser * dlg)
266 {
267 	dlg->transparencyChanged();
268 }
269 
270 /*****************************************************************/
271 
underlineChanged(void)272 void XAP_UnixDialog_FontChooser::underlineChanged(void)
273 {
274 	m_bUnderline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkUnderline));
275 	m_bChangedUnderline = !m_bChangedUnderline;
276 	setFontDecoration(m_bUnderline,m_bOverline,m_bStrikeout,m_bTopline,m_bBottomline);
277 	updatePreview();
278 }
279 
280 
strikeoutChanged(void)281 void XAP_UnixDialog_FontChooser::strikeoutChanged(void)
282 {
283 	m_bStrikeout = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkStrikeOut));
284 	m_bChangedStrikeOut = !m_bChangedStrikeOut;
285 	setFontDecoration(m_bUnderline,m_bOverline,m_bStrikeout,m_bTopline,m_bBottomline);
286 	updatePreview();
287 }
288 
289 
overlineChanged(void)290 void XAP_UnixDialog_FontChooser::overlineChanged(void)
291 {
292 	m_bOverline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkOverline));
293 	m_bChangedOverline = !m_bChangedOverline;
294 	setFontDecoration(m_bUnderline,m_bOverline,m_bStrikeout,m_bTopline,m_bBottomline);
295 	updatePreview();
296 }
297 
298 
subscriptChanged(void)299 void XAP_UnixDialog_FontChooser::subscriptChanged(void)
300 {
301     m_bSubScript = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkSubScript));
302     m_bChangedSubScript = !m_bChangedSubScript;
303     if (m_bSubScript)
304 	{
305 		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkSuperScript)))
306 		{
307 			g_signal_handler_block(G_OBJECT(m_checkSuperScript), m_iSuperScriptId);
308 			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSuperScript), false);
309 			g_signal_handler_unblock(G_OBJECT(m_checkSuperScript), m_iSuperScriptId);
310 			m_bChangedSuperScript = !m_bChangedSuperScript;
311 			setSuperScript(false);
312 		}
313 	}
314     setSubScript(m_bSubScript);
315     updatePreview();
316 }
317 
superscriptChanged(void)318 void XAP_UnixDialog_FontChooser::superscriptChanged(void)
319 {
320     m_bSuperScript = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkSuperScript));
321     m_bChangedSuperScript = !m_bChangedSuperScript;
322     if (m_bSuperScript)
323 	{
324 		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkSubScript)))
325 		{
326 			g_signal_handler_block(G_OBJECT(m_checkSubScript), m_iSubScriptId);
327     		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSubScript), false);
328 			g_signal_handler_unblock(G_OBJECT(m_checkSubScript), m_iSubScriptId);
329 			m_bChangedSubScript = !m_bChangedSubScript;
330 			setSubScript(false);
331 		}
332 	}
333     setSuperScript(m_bSuperScript);
334     updatePreview();
335 }
336 
337 
hiddenChanged(void)338 void XAP_UnixDialog_FontChooser::hiddenChanged(void)
339 {
340 	m_bHidden = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkHidden));
341 	m_bChangedHidden = !m_bChangedHidden;
342 }
343 
transparencyChanged(void)344 void XAP_UnixDialog_FontChooser::transparencyChanged(void)
345 {
346 	bool bTrans = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_checkTransparency));
347 	if(bTrans)
348 	{
349 		addOrReplaceVecProp("bgcolor","transparent");
350 		m_currentBGColorTransparent = true;
351 	}
352 	updatePreview();
353 }
354 
textTransformChanged(void)355 void XAP_UnixDialog_FontChooser::textTransformChanged(void)
356 {
357 #if 0
358 	// todo
359 	static char szTextTransform[60];
360 	GtkTreeSelection *selection;
361 	GtkTreeModel *model;
362 	GtkTreeIter iter;
363 	gchar *text;
364 
365 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_fontList));
366 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_fontList));
367 	if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
368 	{
369 		gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1);
370 		g_snprintf(szTextTransform, 50, "%s",text);
371 		g_free(text), text = NULL;
372 		addOrReplaceVecProp("text-transform",static_cast<gchar*>(szTextTransform));
373 	}
374 #endif
375 
376 	updatePreview();
377 }
378 
fontRowChanged(void)379 void XAP_UnixDialog_FontChooser::fontRowChanged(void)
380 {
381 	static char szFontFamily[60];
382 	GtkTreeSelection *selection;
383 	GtkTreeModel *model;
384 	GtkTreeIter iter;
385 	gchar *text;
386 
387 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_fontList));
388 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_fontList));
389 	if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
390 	{
391 		gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1);
392 		g_snprintf(szFontFamily, 50, "%s",text);
393 		g_free(text), text = NULL;
394 		addOrReplaceVecProp("font-family",static_cast<gchar*>(szFontFamily));
395 	}
396 
397 	updatePreview();
398 }
399 
styleRowChanged(void)400 void XAP_UnixDialog_FontChooser::styleRowChanged(void)
401 {
402 	GtkTreeSelection* selection;
403 	GtkTreeModel* model;
404 	GtkTreeIter iter;
405 	gint rowNumber;
406 	GtkTreePath* path;
407 
408 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_styleList));
409 	if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
410 	{
411 		path = gtk_tree_model_get_path(model, &iter);
412 		rowNumber = gtk_tree_path_get_indices(path)[0];
413 		gtk_tree_path_free(path);
414 
415 		// perhaps these attributes really should be smashed
416 		// into bitfields.  :)
417 		if (rowNumber == LIST_STYLE_NORMAL)
418 		{
419 			addOrReplaceVecProp("font-style","normal");
420 			addOrReplaceVecProp("font-weight","normal");
421 		}
422 		else if (rowNumber == LIST_STYLE_BOLD)
423 		{
424 			addOrReplaceVecProp("font-style","normal");
425 			addOrReplaceVecProp("font-weight","bold");
426 		}
427 		else if (rowNumber == LIST_STYLE_ITALIC)
428 		{
429 			addOrReplaceVecProp("font-style","italic");
430 			addOrReplaceVecProp("font-weight","normal");
431 		}
432 		else if (rowNumber == LIST_STYLE_BOLD_ITALIC)
433 		{
434 			addOrReplaceVecProp("font-style","italic");
435 			addOrReplaceVecProp("font-weight","bold");
436 		}
437 		else
438 		{
439 			UT_ASSERT_HARMLESS(0);
440 		}
441 	}
442 	updatePreview();
443 }
444 
445 
sizeRowChanged(void)446 void XAP_UnixDialog_FontChooser::sizeRowChanged(void)
447 {
448 	// used similarly to convert between text and numeric arguments
449 	static char szFontSize[50];
450 	GtkTreeSelection* selection;
451 	GtkTreeModel* model;
452 	GtkTreeIter iter;
453 	gchar* text;
454 
455 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_sizeList));
456 	if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
457 	{
458 		gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1);
459 		UT_ASSERT(text);
460 		g_snprintf(szFontSize, 50, "%spt",
461 				   static_cast<const gchar *>(XAP_EncodingManager::fontsizes_mapping.lookupByTarget(text)));
462 		g_free(text), text = NULL;
463 		addOrReplaceVecProp("font-size",static_cast<gchar *>(szFontSize));
464 	}
465 	updatePreview();
466 }
467 
fgColorChanged(void)468 void XAP_UnixDialog_FontChooser::fgColorChanged(void)
469 {
470 	gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(m_colorSelector),
471 							   &m_currentFGColor);
472 	UT_RGBColor * rgbcolor = UT_UnixGdkColorToRGBColor(m_currentFGColor);
473 	UT_HashColor hash_color;
474 	const char * c = hash_color.setColor(*rgbcolor);
475 	addOrReplaceVecProp("color",  c + 1);
476 	delete rgbcolor;
477 	updatePreview();
478 }
479 
480 
bgColorChanged(void)481 void XAP_UnixDialog_FontChooser::bgColorChanged(void)
482 {
483 	gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(m_bgcolorSelector),
484 								&m_currentBGColor);
485 	UT_RGBColor * rgbcolor = UT_UnixGdkColorToRGBColor(m_currentBGColor);
486 	UT_HashColor hash_color;
487 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), FALSE);
488 	m_currentBGColorTransparent = false;
489 	// test for funkyColor-has-been-changed-to-sane-color case
490 	addOrReplaceVecProp("bgcolor", hash_color.setColor(*rgbcolor) + 1);
491 	delete rgbcolor;
492 	updatePreview();
493 }
494 
constructWindow(void)495 GtkWidget * XAP_UnixDialog_FontChooser::constructWindow(void)
496 {
497 	const XAP_StringSet * pSS = m_pApp->getStringSet();
498 	GtkWidget *windowFontSelection;
499 	GtkWidget *vboxMain;
500 	GtkWidget *vboxOuter;
501 
502 	std::string s;
503 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_FontTitle,s);
504 	windowFontSelection = abiDialogNew ( "font dialog", TRUE, s.c_str() ) ;
505 	gtk_window_set_position(GTK_WINDOW(windowFontSelection), GTK_WIN_POS_CENTER_ON_PARENT);
506 #if !GTK_CHECK_VERSION(3,0,0)
507 	gtk_dialog_set_has_separator(GTK_DIALOG(windowFontSelection), FALSE);
508 #endif
509 
510 	vboxOuter = gtk_dialog_get_content_area(GTK_DIALOG(windowFontSelection));
511 
512 	vboxMain = constructWindowContents(vboxOuter);
513 	gtk_box_pack_start (GTK_BOX (vboxOuter), vboxMain, TRUE, TRUE, 0);
514 
515 	abiAddStockButton ( GTK_DIALOG(windowFontSelection), GTK_STOCK_CANCEL, BUTTON_CANCEL ) ;
516 	abiAddStockButton ( GTK_DIALOG(windowFontSelection), GTK_STOCK_OK, BUTTON_OK ) ;
517 
518 	return windowFontSelection;
519 }
520 
521 // GtkBuilder generated dialog, using fixed widgets to closely match
522 // the Windows layout, with some changes for color selector
constructWindowContents(GtkWidget * parent)523 GtkWidget * XAP_UnixDialog_FontChooser::constructWindowContents(GtkWidget *parent)
524 {
525 	GtkTreeSelection *selection;
526 	GtkWidget *vboxMain;
527 	GtkWidget *notebookMain;
528 	GtkWidget *labelFont;
529 	GtkWidget *labelStyle;
530 	GtkWidget *listFonts;
531 	GtkWidget *labelSize;
532 	GtkWidget *frameEffects;
533 	GtkWidget *tblEffectRows;
534 	GtkWidget *checkbuttonStrikeout;
535 	GtkWidget *checkbuttonUnderline;
536 	GtkWidget *checkbuttonOverline;
537 	GtkWidget *checkbuttonHidden;
538 	GtkWidget *checkbuttonSubscript;
539 	GtkWidget *checkbuttonSuperscript;
540  	GtkWidget *listStyles;
541 	GtkWidget *listSizes;
542 	GtkWidget *hbox1;
543 	GtkWidget *colorSelector;
544 	GtkWidget *colorBGSelector;
545 	GtkWidget *labelTabFont;
546 	GtkWidget *labelTabColor;
547 	GtkWidget *labelTabBGColor;
548 	GtkWidget *frame4;
549 
550 	// the entry is a special drawing area full of one
551 	// of our graphics contexts
552 	GtkWidget *entryArea;
553 
554 	const XAP_StringSet * pSS = m_pApp->getStringSet();
555 
556 	vboxMain = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
557 	gtk_widget_show (vboxMain);
558 
559 	notebookMain = gtk_notebook_new ();
560 	gtk_widget_show (notebookMain);
561 	gtk_box_pack_start (GTK_BOX (vboxMain), notebookMain, 1, 1, 0);
562 	gtk_container_set_border_width (GTK_CONTAINER (notebookMain), 8);
563 
564 	GtkWidget *window1 = parent;
565 	GtkWidget *table1;
566 	GtkWidget *vbox1;
567 
568 	GtkWidget *scrolledwindow1;
569 	GtkWidget *vbox2;
570 	GtkWidget *scrolledwindow2;
571 	GtkWidget *vbox3;
572 	GtkWidget *scrolledwindow3;
573 	GtkWidget *vboxmisc;
574 //  	GtkWidget *hboxForEncoding;
575 	table1 = gtk_table_new (2, 3, FALSE);
576 	gtk_widget_set_name (table1, "table1");
577 	g_object_ref (G_OBJECT(table1));
578 	g_object_set_data_full (G_OBJECT (window1), "table1", table1,
579 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
580 	gtk_widget_show (table1);
581 
582 	std::string s;
583 	// Label for first page of the notebook
584 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_FontTab,s);
585 	labelTabFont = gtk_label_new (s.c_str());
586 	gtk_widget_show (labelTabFont);
587 //
588 // Make first page of the notebook
589 //
590 	gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), table1,labelTabFont);
591 
592 	vbox1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
593 	gtk_widget_set_name (vbox1, "vbox1");
594 	g_object_ref (G_OBJECT(vbox1));
595 	g_object_set_data_full (G_OBJECT (window1), "vbox1", vbox1,
596 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
597 	gtk_widget_show (vbox1);
598 	gtk_table_attach (GTK_TABLE (table1), vbox1, 0, 1, 0, 2,
599 					  static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
600 					  static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 0, 0);
601 
602 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_FontLabel,s);
603 	labelFont = gtk_label_new (s.c_str());
604 	gtk_widget_set_name (labelFont, "labelFont");
605 	g_object_ref (labelFont);
606 	g_object_set_data_full (G_OBJECT (window1), "labelFont", labelFont,
607 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
608 	gtk_widget_show (labelFont);
609 	gtk_box_pack_start (GTK_BOX (vbox1), labelFont, FALSE, FALSE, 6);
610 
611 	scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
612 	gtk_widget_set_name (scrolledwindow1, "scrolledwindow1");
613 	g_object_ref (scrolledwindow1);
614 	g_object_set_data_full (G_OBJECT (window1), "scrolledwindow1", scrolledwindow1,
615 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
616 	gtk_widget_show (scrolledwindow1);
617 	gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
618 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
619 	gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow1), 3);
620 	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow1), GTK_SHADOW_IN);
621 
622 	listFonts = createFontTabTreeView();
623 	gtk_widget_set_name (listFonts, "listFonts");
624 	g_object_ref (listFonts);
625 	g_object_set_data_full (G_OBJECT (window1), "listFonts", listFonts,
626 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
627 	gtk_widget_show (listFonts);
628 	gtk_container_add (GTK_CONTAINER (scrolledwindow1), listFonts);
629 
630 	vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
631 	gtk_widget_set_name (vbox2, "vbox2");
632 	g_object_ref (vbox2);
633 	g_object_set_data_full (G_OBJECT (window1), "vbox2", vbox2,
634 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
635 	gtk_widget_show (vbox2);
636 	gtk_table_attach (GTK_TABLE (table1), vbox2, 1, 2, 0, 1,
637 					  static_cast<GtkAttachOptions>(GTK_FILL),
638 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
639 
640 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_StyleLabel,s);
641 	labelStyle = gtk_label_new (s.c_str());
642 	gtk_widget_set_name (labelStyle, "labelStyle");
643 	g_object_ref (labelStyle);
644 	g_object_set_data_full (G_OBJECT (window1), "labelStyle", labelStyle,
645 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
646 	gtk_widget_show (labelStyle);
647 	gtk_box_pack_start (GTK_BOX (vbox2), labelStyle, FALSE, FALSE, 6);
648 
649 	scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
650 	gtk_widget_set_name (scrolledwindow2, "scrolledwindow2");
651 	g_object_ref (scrolledwindow2);
652 	g_object_set_data_full (G_OBJECT (window1), "scrolledwindow2", scrolledwindow2,
653 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
654 	gtk_widget_show (scrolledwindow2);
655 	gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow2, TRUE, TRUE, 0);
656 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
657 	gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow2), 3);
658 	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow2), GTK_SHADOW_IN);
659 
660 	listStyles = createFontTabTreeView();
661 	gtk_widget_set_name (listStyles, "listStyles");
662 	g_object_ref (listStyles);
663 	g_object_set_data_full (G_OBJECT (window1), "listStyles", listStyles,
664 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
665 	gtk_widget_show (listStyles);
666 	gtk_container_add (GTK_CONTAINER (scrolledwindow2), listStyles);
667 
668 	vbox3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
669 	gtk_widget_set_name (vbox3, "vbox3");
670 	g_object_ref (vbox3);
671 	g_object_set_data_full (G_OBJECT (window1), "vbox3", vbox3,
672 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
673 	gtk_widget_show (vbox3);
674 	gtk_table_attach (GTK_TABLE (table1), vbox3, 2, 3, 0, 1,
675 					  static_cast<GtkAttachOptions>(GTK_FILL),
676 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
677 
678 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_SizeLabel,s);
679 	labelSize = gtk_label_new (s.c_str());
680 	gtk_widget_set_name (labelSize, "labelSize");
681 	g_object_ref (labelSize);
682 	g_object_set_data_full (G_OBJECT (window1), "labelSize", labelSize,
683 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
684 	gtk_widget_show (labelSize);
685 	gtk_box_pack_start (GTK_BOX (vbox3), labelSize, FALSE, FALSE, 6);
686 
687 	scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
688 	gtk_widget_set_name (scrolledwindow3, "scrolledwindow3");
689 	g_object_ref (scrolledwindow3);
690 	g_object_set_data_full (G_OBJECT (window1), "scrolledwindow3", scrolledwindow3,
691 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
692 	gtk_widget_show (scrolledwindow3);
693 	gtk_box_pack_start (GTK_BOX (vbox3), scrolledwindow3, TRUE, TRUE, 0);
694 	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
695 	gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow3), 3);
696 	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow3), GTK_SHADOW_IN);
697 
698 	listSizes = createFontTabTreeView();
699 	gtk_widget_set_name (listSizes, "listSizes");
700 	g_object_ref (listSizes);
701 	g_object_set_data_full (G_OBJECT (window1), "listSizes", listSizes,
702 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
703 	gtk_widget_show (listSizes);
704 	gtk_container_add (GTK_CONTAINER (scrolledwindow3), listSizes);
705 
706 	vboxmisc = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
707 	gtk_widget_set_name (vboxmisc, "vboxmisc");
708 	g_object_ref (vboxmisc);
709 	g_object_set_data_full (G_OBJECT (window1), "vboxmisc", vboxmisc,
710 							  reinterpret_cast<GDestroyNotify>(g_object_unref));
711 	gtk_widget_show (vboxmisc);
712 	gtk_table_attach (GTK_TABLE (table1), vboxmisc, 1, 3, 1, 2,
713 					  static_cast<GtkAttachOptions>(GTK_FILL),
714 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
715 
716 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_EffectsFrameLabel,s);
717 	frameEffects = gtk_frame_new (s.c_str());
718 	gtk_frame_set_shadow_type(GTK_FRAME(frameEffects), GTK_SHADOW_NONE);
719 	gtk_widget_show (frameEffects);
720 	gtk_box_pack_start(GTK_BOX (vboxmisc), frameEffects, 0,0, 6);
721 
722 	tblEffectRows = gtk_table_new(2, 4, FALSE);
723 	gtk_widget_show (tblEffectRows);
724 	gtk_container_add (GTK_CONTAINER (frameEffects), tblEffectRows);
725 
726 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_StrikeoutCheck,s);
727 	checkbuttonStrikeout = gtk_check_button_new_with_label (s.c_str());
728 	gtk_container_set_border_width (GTK_CONTAINER (checkbuttonStrikeout), 5);
729 	gtk_widget_show (checkbuttonStrikeout);
730 	gtk_table_attach(GTK_TABLE(tblEffectRows), checkbuttonStrikeout, 0, 1, 0, 1,
731 					  static_cast<GtkAttachOptions>(GTK_FILL),
732 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
733 
734 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_UnderlineCheck,s);
735 	checkbuttonUnderline = gtk_check_button_new_with_label (s.c_str());
736 	gtk_container_set_border_width (GTK_CONTAINER (checkbuttonUnderline), 5);
737 	gtk_widget_show (checkbuttonUnderline);
738 	gtk_table_attach(GTK_TABLE(tblEffectRows), checkbuttonUnderline, 1, 2, 0, 1,
739 					  static_cast<GtkAttachOptions>(GTK_FILL),
740 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
741 
742 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_OverlineCheck,s);
743 	checkbuttonOverline = gtk_check_button_new_with_label (s.c_str());
744 	gtk_container_set_border_width (GTK_CONTAINER (checkbuttonOverline), 5);
745 	gtk_widget_show (checkbuttonOverline);
746 	gtk_table_attach(GTK_TABLE(tblEffectRows), checkbuttonOverline, 2, 3, 0, 1,
747 					  static_cast<GtkAttachOptions>(GTK_FILL),
748 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
749 
750 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_HiddenCheck,s);
751 	checkbuttonHidden = gtk_check_button_new_with_label (s.c_str());
752 	gtk_container_set_border_width (GTK_CONTAINER (checkbuttonHidden), 5);
753 	gtk_widget_show (checkbuttonHidden);
754 	gtk_table_attach(GTK_TABLE(tblEffectRows), checkbuttonHidden, 3, 4, 0, 1,
755 					  static_cast<GtkAttachOptions>(GTK_FILL),
756 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
757 
758 	/* subscript/superscript */
759 
760 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_SubScript,s);
761 	checkbuttonSubscript = gtk_check_button_new_with_label (s.c_str());
762 	gtk_container_set_border_width (GTK_CONTAINER (checkbuttonSubscript), 5);
763 	gtk_widget_show (checkbuttonSubscript);
764 	gtk_table_attach(GTK_TABLE(tblEffectRows), checkbuttonSubscript, 0, 1, 1, 2,
765 					  static_cast<GtkAttachOptions>(GTK_FILL),
766 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
767 
768 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_SuperScript,s);
769 	checkbuttonSuperscript = gtk_check_button_new_with_label (s.c_str());
770 	gtk_container_set_border_width (GTK_CONTAINER (checkbuttonSuperscript), 5);
771 	gtk_widget_show (checkbuttonSuperscript);
772 	gtk_table_attach(GTK_TABLE(tblEffectRows), checkbuttonSuperscript, 1, 2, 1, 2,
773 					  static_cast<GtkAttachOptions>(GTK_FILL),
774 					  static_cast<GtkAttachOptions>(GTK_FILL), 0, 0);
775 
776 	/* Notebook page for ForeGround Color Selector */
777 
778 	hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
779 	gtk_widget_show (hbox1);
780 
781     // Label for second page of the notebook
782 
783 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_ColorTab,s);
784 	labelTabColor = gtk_label_new (s.c_str());
785 	gtk_widget_show (labelTabColor);
786 
787 //
788 // Make second page of the notebook
789 //
790     gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), hbox1,labelTabColor);
791 
792 	colorSelector = gtk_color_chooser_widget_new ();
793 	gtk_container_set_border_width(GTK_CONTAINER(colorSelector), 6);
794 	gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(colorSelector), FALSE);
795 	gtk_widget_show (colorSelector);
796 	gtk_box_pack_start (GTK_BOX (hbox1), colorSelector, TRUE, TRUE, 0);
797 
798 	/*Notebook page for Background Color Selector*/
799 
800 	GtkWidget * vboxBG = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
801 	gtk_widget_show (vboxBG);
802 
803     // Label for third page of the notebook
804 
805 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_BGColorTab,s);
806 	labelTabBGColor = gtk_label_new (s.c_str());
807 	gtk_widget_show (labelTabBGColor);
808 //
809 // Make third page of the notebook
810 //
811     gtk_notebook_append_page(GTK_NOTEBOOK(notebookMain), vboxBG,labelTabBGColor);
812 
813 	colorBGSelector = gtk_color_chooser_widget_new ();
814 	gtk_container_set_border_width(GTK_CONTAINER(colorBGSelector), 6);
815 	gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(colorBGSelector), FALSE);
816 	gtk_widget_show (colorBGSelector);
817 	gtk_box_pack_start (GTK_BOX (vboxBG), colorBGSelector, TRUE, TRUE, 0);
818 
819 //
820 // Make a toggle button to set hightlight color transparent
821 //
822 	pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_TransparencyCheck,s);
823 	GtkWidget * checkbuttonTrans = gtk_check_button_new_with_label (s.c_str());
824 	gtk_container_set_border_width(GTK_CONTAINER(checkbuttonTrans), 6);
825 	gtk_widget_show (checkbuttonTrans);
826 	gtk_box_pack_start (GTK_BOX (vboxBG), checkbuttonTrans, TRUE, TRUE, 0);
827 
828 	/* frame with preview */
829 
830 	frame4 = gtk_frame_new (NULL);
831 	gtk_frame_set_shadow_type(GTK_FRAME(frame4), GTK_SHADOW_NONE);
832 	gtk_widget_show (frame4);
833 	gtk_box_pack_start (GTK_BOX (vboxMain), frame4, FALSE, FALSE, PREVIEW_BOX_BORDER_WIDTH_PIXELS);
834 	// setting the height takes into account the border applied on all
835 	// sides, so we need to double the single border width
836 	gtk_widget_set_size_request (frame4, -1, PREVIEW_BOX_HEIGHT_PIXELS + (PREVIEW_BOX_BORDER_WIDTH_PIXELS * 2));
837 	gtk_container_set_border_width (GTK_CONTAINER (frame4), PREVIEW_BOX_BORDER_WIDTH_PIXELS);
838 
839 	entryArea = createDrawingArea ();
840 	gtk_widget_set_events(entryArea, GDK_EXPOSURE_MASK);
841 #if GTK_CHECK_VERSION(3,0,0)
842 	g_signal_connect(G_OBJECT(entryArea), "draw",
843 					   G_CALLBACK(s_drawing_area_draw), NULL);
844 #else
845 	g_signal_connect(G_OBJECT(entryArea), "expose_event",
846 					   G_CALLBACK(s_drawing_area_draw), NULL);
847 #endif
848 	gtk_widget_set_size_request (entryArea, -1, PREVIEW_BOX_HEIGHT_PIXELS);
849 	gtk_widget_show (entryArea);
850 	gtk_container_add (GTK_CONTAINER (frame4), entryArea);
851 
852 
853 	// save out to members for callback and class access
854 	m_fontList = listFonts;
855 	m_styleList = listStyles;
856 	m_sizeList = listSizes;
857 	m_colorSelector = colorSelector;
858 	m_bgcolorSelector = colorBGSelector;
859 	m_preview = entryArea;
860 	m_checkStrikeOut = checkbuttonStrikeout;
861 	m_checkUnderline = checkbuttonUnderline;
862 	m_checkOverline = checkbuttonOverline;
863 	m_checkSubScript = checkbuttonSubscript;
864 	m_checkSuperScript = checkbuttonSuperscript;
865 	m_checkHidden = checkbuttonHidden;
866 	m_checkTransparency = checkbuttonTrans;
867 
868 	// bind signals to things
869 	g_signal_connect(G_OBJECT(m_checkUnderline),
870 					   "toggled",
871 					   G_CALLBACK(s_underline_toggled),
872 					   static_cast<gpointer>(this));
873 
874 	g_signal_connect(G_OBJECT(m_checkOverline),
875 					   "toggled",
876 					   G_CALLBACK(s_overline_toggled),
877 					   static_cast<gpointer>(this));
878 
879 	g_signal_connect(G_OBJECT(m_checkStrikeOut),
880 					   "toggled",
881 					   G_CALLBACK(s_strikeout_toggled),
882 					   static_cast<gpointer>(this));
883 
884 	g_signal_connect(G_OBJECT(m_checkHidden),
885 					   "toggled",
886 					   G_CALLBACK(s_hidden_toggled),
887 					   static_cast<gpointer>(this));
888 
889 	m_iSubScriptId = g_signal_connect(G_OBJECT(m_checkSubScript),
890 					   "toggled",
891 					   G_CALLBACK(s_subscript_toggled),
892 					   static_cast<gpointer>(this));
893 
894 	m_iSuperScriptId = g_signal_connect(G_OBJECT(m_checkSuperScript),
895 					   "toggled",
896 					   G_CALLBACK(s_superscript_toggled),
897 					   static_cast<gpointer>(this));
898 
899 	g_signal_connect(G_OBJECT(m_checkTransparency),
900 					   "toggled",
901 					   G_CALLBACK(s_transparency_toggled),
902 					   static_cast<gpointer>(this));
903 
904 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listFonts));
905 	g_signal_connect(G_OBJECT(selection),
906 					   "changed",
907 					   G_CALLBACK(s_select_row_font),
908 					   static_cast<gpointer>(this));
909 	selection = NULL;
910 
911 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listStyles));
912 	g_signal_connect(G_OBJECT(selection),
913 					   "changed",
914 					   G_CALLBACK(s_select_row_style),
915 					   static_cast<gpointer>(this));
916 	selection = NULL;
917 
918 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listSizes));
919 	g_signal_connect(G_OBJECT(selection),
920 					   "changed",
921 					   G_CALLBACK(s_select_row_size),
922 					   static_cast<gpointer>(this));
923 	selection = NULL;
924 
925 	// This is a catch-all color selector callback which catches any
926 	// real-time updating of the color so we can refresh our preview
927 	// text
928 	g_signal_connect(G_OBJECT(colorSelector),
929 #if GTK_CHECK_VERSION(3,4,0)
930 			 "color-activated",
931 #else
932 			 "color-changed", //"event",
933 #endif
934 			 G_CALLBACK(s_color_update),
935 			 static_cast<gpointer>(this));
936 
937 	g_signal_connect(G_OBJECT(colorBGSelector),
938 #if GTK_CHECK_VERSION(3,4,0)
939 			 "color-activated",
940 #else
941 			 "color-changed", //"event",
942 #endif
943 			 G_CALLBACK(s_bgcolor_update),
944 			 static_cast<gpointer>(this));
945 
946 	gtk_widget_set_can_focus(listFonts, true);
947 	gtk_widget_set_can_focus(listStyles, true);
948 	gtk_widget_set_can_focus(listSizes, true);
949 
950 	// Make the tab focus list more sensible
951 	// font -> syle -> size -> other options ...
952 	GList* focusList = NULL;
953 
954 	focusList = g_list_append(focusList, vbox1);
955 	focusList = g_list_append(focusList, vbox2);
956 	focusList = g_list_append(focusList, vbox3);
957 	focusList = g_list_append(focusList, vboxmisc);
958 	gtk_container_set_focus_chain(GTK_CONTAINER(table1), focusList);
959 	g_list_free(focusList);
960 	gtk_widget_grab_focus(scrolledwindow1);
961 
962 
963 	const gchar * text;
964 	GtkTreeModel* model;
965 	GtkTreeIter iter;
966 
967 	// update the styles list
968 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_styleList));
969 	gtk_list_store_clear(GTK_LIST_STORE(model));
970 
971 	text = pSS->getValue(XAP_STRING_ID_DLG_UFS_StyleRegular);
972 	gtk_list_store_append(GTK_LIST_STORE(model), &iter);
973 	gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, text, -1);
974 	text = pSS->getValue(XAP_STRING_ID_DLG_UFS_StyleItalic);
975 	gtk_list_store_append(GTK_LIST_STORE(model), &iter);
976 	gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, text, -1);
977 	text = pSS->getValue(XAP_STRING_ID_DLG_UFS_StyleBold);
978 	gtk_list_store_append(GTK_LIST_STORE(model), &iter);
979 	gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, text, -1);
980 	text = pSS->getValue(XAP_STRING_ID_DLG_UFS_StyleBoldItalic);
981 	gtk_list_store_append(GTK_LIST_STORE(model), &iter);
982 	gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, text, -1);
983 
984 
985 
986 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_sizeList));
987 	gtk_list_store_clear(GTK_LIST_STORE(model));
988 	// TODO perhaps populate the list based on the selected font/style?
989 	{
990 		int sz = XAP_EncodingManager::fontsizes_mapping.size();
991 		for (int i = 0; i < sz; ++i)
992 		{
993 			text = XAP_EncodingManager::fontsizes_mapping.nth2(i);
994 			gtk_list_store_append(GTK_LIST_STORE(model), &iter);
995 			gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, text, -1);
996 	    }
997 	}
998 
999 	return vboxMain;
1000 }
1001 
runModal(XAP_Frame * pFrame)1002 void XAP_UnixDialog_FontChooser::runModal(XAP_Frame * pFrame)
1003 {
1004 	m_pFrame = static_cast<XAP_Frame *>(pFrame);
1005 
1006 	// used similarly to convert between text and numeric arguments
1007 	static char sizeString[50];
1008 
1009 	// build the dialog
1010 	GtkWidget * cf = constructWindow();
1011 
1012 	// freeze updates of the preview
1013 	m_blockUpdate = true;
1014 
1015 	// to sort out dupes
1016     std::set<std::string> fontSet;
1017 
1018 	GtkTreeModel* model;
1019 	GtkTreeIter iter;
1020 
1021 	model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_fontList));
1022 	gtk_list_store_clear(GTK_LIST_STORE(model));
1023 
1024 	GR_GraphicsFactory * pGF = XAP_App::getApp()->getGraphicsFactory();
1025 	if(!pGF)
1026 	{
1027 		return;
1028 	}
1029 
1030 	const std::vector<std::string> & names = GR_CairoGraphics::getAllFontNames();
1031 
1032 	for (std::vector<std::string>::const_iterator  i = names.begin();
1033 		 i != names.end(); ++i)
1034 	{
1035 		const std::string & fName = *i;
1036 
1037 		if (fontSet.find(fName) == fontSet.end())
1038 		{
1039             fontSet.insert(fName);
1040 
1041 		    gtk_list_store_append(GTK_LIST_STORE(model), &iter);
1042 		    gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN,
1043                                fName.c_str(), -1);
1044 
1045 		  }
1046 	}
1047 
1048 	// Set the defaults in the list boxes according to dialog data
1049 	gint foundAt = 0;
1050 
1051 	const std::string sFontFamily = getVal("font-family");
1052 	foundAt = searchTreeView(GTK_TREE_VIEW(m_fontList), sFontFamily.c_str());
1053 
1054 	// select and scroll to font name
1055 	if (foundAt >= 0) {
1056 		GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1);
1057 		gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_fontList), path, NULL, FALSE);
1058 		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_fontList), path, NULL, TRUE, 0.5 , 0.0);
1059 		gtk_tree_path_free(path);
1060 	}
1061 
1062 	// this is pretty messy
1063 	listStyle st = LIST_STYLE_NORMAL;
1064 	const std::string sWeight = getVal("font-weight");
1065 	const std::string sStyle = getVal("font-style");
1066 	if (sStyle.empty() || sWeight.empty())
1067 		st = LIST_STYLE_NONE;
1068 	else {
1069 		bool isBold = !g_ascii_strcasecmp(sWeight.c_str(), "bold");
1070 		bool isItalic = !g_ascii_strcasecmp(sStyle.c_str(), "italic");
1071 		if (!isBold && !isItalic) {
1072 			st = LIST_STYLE_NORMAL;
1073 		}
1074 		else if (!isItalic && isBold) {
1075 			st = LIST_STYLE_BOLD;
1076 		}
1077 		else if (isItalic && !isBold) {
1078 			st = LIST_STYLE_ITALIC;
1079 		}
1080 		else if (isItalic && isBold) {
1081 			st = LIST_STYLE_BOLD_ITALIC;
1082 		}
1083 		else {
1084 			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
1085 		}
1086 	}
1087 
1088 	// select and scroll to style name
1089 	if (st != LIST_STYLE_NONE) {
1090 		GtkTreePath* path = gtk_tree_path_new_from_indices(st, -1);
1091 		gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_styleList), path, NULL, FALSE);
1092 		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_styleList), path, NULL, TRUE, 0.5 , 0.0);
1093 		gtk_tree_path_free(path);
1094 	}
1095 
1096 	g_snprintf(sizeString, 60, "%s", std_size_string(UT_convertToPoints(getVal("font-size").c_str())));
1097 	foundAt = searchTreeView(GTK_TREE_VIEW(m_sizeList),
1098 				 XAP_EncodingManager::fontsizes_mapping.lookupBySource(sizeString));
1099 
1100 	// select and scroll to size name
1101 	if (foundAt >= 0) {
1102 		GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1);
1103 		gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_sizeList), path, NULL, FALSE);
1104 		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_sizeList), path, NULL, TRUE, 0.5 , 0.0);
1105 		gtk_tree_path_free(path);
1106 	}
1107 
1108 	// Set color in the color selector
1109 	const std::string sColor = getVal("color");
1110 	if (!sColor.empty())
1111 	{
1112 		UT_RGBColor c;
1113 		UT_parseColor(sColor.c_str(), c);
1114 
1115 		GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c);
1116 		m_currentFGColor = *color;
1117 		gdk_rgba_free(color);
1118 		gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_currentFGColor);
1119 	}
1120 	else
1121 	{
1122 		// if we have no color, use a placeholder of funky values
1123 		// the user can't pick interactively.  This catches ALL
1124 		// the cases except where the user specifically enters -1 for
1125 		// all Red, Green and Blue attributes manually.  This user
1126 		// should expect it not to touch the color.  :)
1127 		gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_funkyColor);
1128 	}
1129 
1130 	// Set color in the color selector
1131 	const std::string sBGCol = getVal("bgcolor");
1132 	if (!sBGCol.empty() && strcmp(sBGCol.c_str(),"transparent") != 0)
1133 	{
1134 		UT_RGBColor c;
1135 		UT_parseColor(sBGCol.c_str(), c);
1136 
1137 		GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c);
1138 		m_currentBGColor = *color;
1139 		gdk_rgba_free(color);
1140 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), FALSE);
1141 		gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_bgcolorSelector), &m_currentBGColor);
1142 	}
1143 	else
1144 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), TRUE);
1145 
1146 	// fix for GTK's questionable gtk_toggle_set_active behaviour (emits when setting TRUE)
1147 	m_bChangedStrikeOut = m_bStrikeout;
1148 	m_bChangedUnderline = m_bUnderline;
1149 	m_bChangedOverline = m_bOverline;
1150 	m_bChangedHidden = m_bHidden;
1151 	m_bChangedSubScript = m_bSubScript;
1152 	m_bChangedSuperScript = m_bSuperScript;
1153 
1154 	// set the strikeout, underline, overline, and hidden check buttons
1155 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkStrikeOut), m_bStrikeout);
1156 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkUnderline), m_bUnderline);
1157 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkOverline), m_bOverline);
1158 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkHidden), m_bHidden);
1159 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSubScript), m_bSubScript);
1160 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSuperScript), m_bSuperScript);
1161 
1162 	m_doneFirstFont = true;
1163 
1164 	// attach a new graphics context
1165 	gtk_widget_show ( cf ) ;
1166 
1167 	GR_UnixCairoAllocInfo ai(m_preview);
1168 	m_gc = (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai);
1169 	GtkAllocation alloc;
1170 
1171 	gtk_widget_get_allocation(m_preview, &alloc);
1172 	_createFontPreviewFromGC(m_gc,alloc.width,alloc.height);
1173 //
1174 // This enables callbacks on the preview area with a widget pointer to
1175 // access this dialog.
1176 //
1177 	g_object_set_data(G_OBJECT(m_preview), "user-data", this);
1178 
1179 	// unfreeze updates of the preview
1180 	m_blockUpdate = false;
1181 	// manually trigger an update
1182 	updatePreview();
1183 
1184 
1185 	switch ( abiRunModalDialog ( GTK_DIALOG(cf), pFrame, this, BUTTON_CANCEL, true ) )
1186 	  {
1187 	  case BUTTON_OK:
1188 	    {
1189 	      m_answer = a_OK;
1190 	      break ;
1191 	    }
1192 	  default:
1193 	    {
1194 	      m_answer = a_CANCEL;
1195 	      break;
1196 	    }
1197 	  }
1198 
1199 	// these dialogs are cached around through the dialog framework,
1200 	// and this variable needs to get set back
1201 	m_doneFirstFont = false;
1202 
1203 	UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s] SubScript[%d%s] SuperScript[%d%s]\n",
1204 				 getVal("font-family").c_str(),			((m_bChangedFontFamily) ? "(chg)" : ""),
1205 				 getVal("font-size").c_str(),			((m_bChangedFontSize) ? "(chg)" : ""),
1206 				 getVal("font-weight").c_str(),			((m_bChangedFontWeight) ? "(chg)" : ""),
1207 				 getVal("font-style").c_str(),			((m_bChangedFontStyle) ? "(chg)" : ""),
1208 				 getVal("color").c_str(),				((m_bChangedColor) ? "(chg)" : ""),
1209 				 m_bUnderline,							((m_bChangedUnderline) ? "(chg)" : ""),
1210 				 m_bStrikeout,							((m_bChangedStrikeOut) ? "(chg)" : ""),
1211 				 m_bSubScript,							((m_bChangedSubScript) ? "(chg)" : ""),
1212 				 m_bSuperScript,						((m_bChangedSuperScript) ? "(chg)" : "")
1213 	            ));
1214 
1215 	// answer should be set by the appropriate callback
1216 	// the caller can get the answer from getAnswer().
1217 
1218 	m_pFrame = NULL;
1219 }
1220 
updatePreview(void)1221 void XAP_UnixDialog_FontChooser::updatePreview(void)
1222 {
1223 	// if we don't have anything yet, just ignore this request
1224 	if (!m_gc)
1225 		return;
1226 	// if a font has been set since this dialog was launched, draw things with it
1227 	if (m_doneFirstFont)
1228 	{
1229 	  const UT_UCSChar * entryString = getDrawString ();
1230 
1231 	  if (!entryString)
1232 		  return;
1233 
1234 	  event_previewExposed(entryString);
1235 	}
1236 	else
1237 		event_previewClear();
1238 }
1239 
1240 
1241 
1242 
1243 
1244