Debian Codegraph @

src/af/xap/gtk/xap_UnixDlg_FontChooser.cpp

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