Debian Codegraph @

src/af/xap/cocoa/xap_CocoaDlg_FontChooser.cpp

raw
1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiSource Application Framework
4 * Copyright (C) 1998 AbiSource, Inc.
5 * Copyright (C) 2003, 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 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include "ut_assert.h"
27 #include "ut_debugmsg.h"
28 #include "ut_string.h"
29 #include "ut_misc.h"
30 #include "ut_units.h"
31 #include "xap_CocoaDialog_Utilities.h"
32 #include "xap_CocoaDlg_FontChooser.h"
33 #include "xap_CocoaApp.h"
34 #include "xap_CocoaCompat.h"
35
36 #include "xap_EncodingManager.h"
37 #include "gr_CocoaCairoGraphics.h"
38
39 // your typographer's standard nonsense latin font phrase
40 #define PREVIEW_ENTRY_DEFAULT_STRING "Lorem ipsum dolor sit amet, consectetaur adipisicing..."
41
42
43
44 /*****************************************************************/
45 XAP_Dialog * XAP_CocoaDialog_FontChooser::static_constructor(XAP_DialogFactory * pFactory, XAP_Dialog_Id dlgid)
46 {
47 XAP_CocoaDialog_FontChooser * p = new XAP_CocoaDialog_FontChooser(pFactory,dlgid);
48 return p;
49 }
50
51 XAP_CocoaDialog_FontChooser::XAP_CocoaDialog_FontChooser(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id dlgid) :
52 XAP_Dialog_FontChooser(pDlgFactory,dlgid),
53 m_bSuperScriptInitialValue(false),
54 m_bSubScriptInitialValue(false),
55 m_currentFamily(NULL),
56 m_dlg(nil)
57 {
58 //
59 }
60
61 XAP_CocoaDialog_FontChooser::~XAP_CocoaDialog_FontChooser(void)
62 {
63 FREEP(m_currentFamily);
64 DELETEP(m_pGraphics);
65 }
66
67
68 /*****************************************************************/
69
70 void XAP_CocoaDialog_FontChooser::strikeoutChanged(bool value)
71 {
72 m_bStrikeout = value;
73 m_bChangedStrikeOut = !m_bChangedStrikeOut;
74 setFontDecoration(m_bUnderline,m_bOverline,m_bStrikeout,m_bTopline,m_bBottomline);
75 updatePreview();
76 }
77
78 void XAP_CocoaDialog_FontChooser::underlineChanged(bool value)
79 {
80 m_bUnderline = value;
81 m_bChangedUnderline = !m_bChangedUnderline;
82 setFontDecoration(m_bUnderline,m_bOverline,m_bStrikeout,m_bTopline,m_bBottomline);
83 updatePreview();
84 }
85
86 void XAP_CocoaDialog_FontChooser::overlineChanged(bool value)
87 {
88 m_bOverline = value;
89 m_bChangedOverline = !m_bChangedOverline;
90 setFontDecoration(m_bUnderline,m_bOverline,m_bStrikeout,m_bTopline,m_bBottomline);
91 updatePreview();
92 }
93
94 void XAP_CocoaDialog_FontChooser::superscriptChanged(bool value)
95 {
96 m_bSuperScript = value;
97 m_bSubScript = false;
98
99 [m_dlg setSubscript:m_bSubScript];
100
101 m_bChangedSuperScript = (m_bSuperScript != m_bSuperScriptInitialValue);
102 m_bChangedSubScript = (m_bSubScript != m_bSubScriptInitialValue );
103
104 setSuperScript(m_bSuperScript);
105 setSubScript (m_bSubScript);
106
107 updatePreview();
108 }
109
110 void XAP_CocoaDialog_FontChooser::subscriptChanged(bool value)
111 {
112 m_bSuperScript = false;
113 m_bSubScript = value;
114
115 [m_dlg setSuperscript:m_bSuperScript];
116
117 m_bChangedSuperScript = (m_bSuperScript != m_bSuperScriptInitialValue);
118 m_bChangedSubScript = (m_bSubScript != m_bSubScriptInitialValue );
119
120 setSuperScript(m_bSuperScript);
121 setSubScript (m_bSubScript);
122
123 updatePreview();
124 }
125
126 void XAP_CocoaDialog_FontChooser::transparencyChanged(bool value)
127 {
128 bool bTrans = value;
129 if(bTrans)
130 {
131 addOrReplaceVecProp("bgcolor","transparent");
132 UT_DEBUGMSG (("Update background color"));
133 }
134 updatePreview();
135 }
136
137 void XAP_CocoaDialog_FontChooser::fontRowChanged(void)
138 {
139 NSString *fontFamily;
140
141 fontFamily = [m_dlg selectedFont];
142 FREEP(m_currentFamily);
143 m_currentFamily = g_strdup([fontFamily UTF8String]);
144 addOrReplaceVecProp("font-family",m_currentFamily);
145
146 updatePreview();
147 }
148
149 void XAP_CocoaDialog_FontChooser::styleRowChanged(int rowNumber)
150 {
151 if (rowNumber == 0)
152 {
153 addOrReplaceVecProp("font-style","normal");
154 addOrReplaceVecProp("font-weight","normal");
155 }
156 else if (rowNumber == 1)
157 {
158 addOrReplaceVecProp("font-style","italic");
159 addOrReplaceVecProp("font-weight","normal");
160 }
161 else if (rowNumber == 2)
162 {
163 addOrReplaceVecProp("font-style","normal");
164 addOrReplaceVecProp("font-weight","bold");
165 }
166 else if (rowNumber == 3)
167 {
168 addOrReplaceVecProp("font-style","italic");
169 addOrReplaceVecProp("font-weight","bold");
170 }
171 else
172 {
173 UT_ASSERT(0);
174 }
175 updatePreview();
176 }
177
178 void XAP_CocoaDialog_FontChooser::sizeRowChanged(void)
179 {
180 NSString* fontSize;
181 static char szFontSize[60];
182
183 fontSize = [m_dlg selectedSize];
184
185 snprintf(szFontSize, sizeof(szFontSize), "%spt",
186 (gchar *)XAP_EncodingManager::fontsizes_mapping.lookupByTarget([fontSize UTF8String]));
187 addOrReplaceVecProp("font-size",(gchar *)szFontSize);
188
189 updatePreview();
190 }
191
192 /*!
193 Change the color for the property.
194
195 \param color the NSColor
196 \param attr the CSS attribute
197 \param buf the buf to store the color (static in the caller)
198 */
199 void XAP_CocoaDialog_FontChooser::_colorChanged(NSColor * color, const gchar * attr, char * buf)
200 {
201 XAP_CGFloat r,g,b,a;
202 color = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
203 [color getRed:&r green:&g blue:&b alpha:&a];
204 snprintf(buf, 7, "%02x%02x%02x",
205 (unsigned int) (r * (float) 255.0),
206 (unsigned int) (g * (float) 255.0),
207 (unsigned int) (b * (float) 255.0));
208 addOrReplaceVecProp(attr,(gchar *)buf);
209 updatePreview();
210 }
211
212 /*!
213 Called when text color has been changed in the widget
214 */
215 void XAP_CocoaDialog_FontChooser::fgColorChanged(void)
216 {
217 static char buf_color[8];
218 _colorChanged([m_dlg textColor], "color", buf_color);
219 }
220
221 /*!
222 Called when text background color has been changed in the widget
223 */
224 void XAP_CocoaDialog_FontChooser::bgColorChanged(void)
225 {
226 static char buf_color[8];
227 _colorChanged([m_dlg bgColor], "bgcolor", buf_color);
228 }
229
230 void XAP_CocoaDialog_FontChooser::runModal(XAP_Frame * /*pFrame*/)
231 {
232 UT_ASSERT(m_pApp);
233
234 m_dlg = [[XAP_CocoaDialog_FontChooserController alloc] initFromNib];
235
236 // used similarly to convert between text and numeric arguments
237 [m_dlg setXAPOwner:this];
238
239 // build the dialog
240 NSWindow * window = [m_dlg window];
241 UT_ASSERT(window);
242
243 // freeze updates of the preview
244 _createGC([m_dlg preview]);
245 event_previewClear();
246
247
248 // Set the defaults in the list boxes according to dialog data
249 [m_dlg selectFont:(char*)getVal("font-family").c_str()];
250 [m_dlg selectStyle:(char*)getVal("font-style").c_str() withWeight:(char*)getVal("font-weight").c_str()];
251 [m_dlg selectSize:(char*)getVal("font-size").c_str()];
252
253 // Set color in the color selector
254 const std::string sColor = getVal("color");
255 if (!sColor.empty())
256 {
257 UT_RGBColor c;
258 UT_parseColor(sColor.c_str(), c);
259
260 NSColor *color = GR_CocoaCairoGraphics::_utRGBColorToNSColor(c);
261 [m_dlg setTextColor:color];
262 }
263 else {
264 [m_dlg setTextColor:[[NSColor blackColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace]];
265 }
266
267 // Set color in the color selector
268 const std::string sBGCol = getVal("bgcolor");
269 if (!sBGCol.empty() && strcmp(sBGCol.c_str(),"transparent") != 0)
270 {
271 UT_RGBColor c;
272 UT_parseColor(sBGCol.c_str(), c);
273
274 NSColor *color = GR_CocoaCairoGraphics::_utRGBColorToNSColor(c);
275 [m_dlg setBgColor:color];
276 }
277 else
278 {
279 [m_dlg setBgColor:[[NSColor whiteColor] colorUsingColorSpaceName:NSDeviceRGBColorSpace]];
280 }
281
282 // set the strikeout and underline check buttons
283 [m_dlg setStrikeout:m_bStrikeout];
284 [m_dlg setUnderline:m_bUnderline];
285 [m_dlg setOverline:m_bOverline];
286
287 m_bSuperScriptInitialValue = m_bSuperScript;
288 m_bSubScriptInitialValue = m_bSubScript;
289
290 [m_dlg setSuperscript:m_bSuperScript];
291 [m_dlg setSubscript:m_bSubScript];
292
293 updatePreview();
294 // Run the dialog
295 [NSApp runModalForWindow:window];
296
297 [m_dlg discardXAP];
298 [m_dlg close];
299 [m_dlg release];
300 m_dlg = nil;
301
302 UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s]\n",
303 getVal("font-family").c_str(), ((m_bChangedFontFamily) ? "(chg)" : ""),
304 getVal("font-size").c_str(), ((m_bChangedFontSize) ? "(chg)" : ""),
305 getVal("font-weight").c_str(), ((m_bChangedFontWeight) ? "(chg)" : ""),
306 getVal("font-style").c_str(), ((m_bChangedFontStyle) ? "(chg)" : ""),
307 getVal("color").c_str(), ((m_bChangedColor) ? "(chg)" : ""),
308 m_bUnderline, ((m_bChangedUnderline) ? "(chg)" : ""),
309 m_bStrikeout, ((m_bChangedStrikeOut) ? "(chg)" : "")));
310
311 }
312
313 bool XAP_CocoaDialog_FontChooser::getEntryString(const char ** string)
314 {
315 UT_ASSERT(string);
316
317 // Maybe this will be editable in the future, if one wants to
318 // hook up a mini formatter to the entry area. Probably not.
319
320 *string = PREVIEW_ENTRY_DEFAULT_STRING;
321
322 return true;
323 }
324
325 void XAP_CocoaDialog_FontChooser::updatePreview(void)
326 {
327 // if we don't have anything yet, just ignore this request
328 if (!m_pGraphics) {
329 return;
330 }
331
332 // if a font has been set since this dialog was launched, draw things with it
333 const char * entryString;
334
335 if (!getEntryString(&entryString)) {
336 return;
337 }
338
339 UT_UCSChar * unicodeString = NULL;
340 UT_UCS4_cloneString_char(&unicodeString, entryString);
341 event_previewExposed(unicodeString);
342 FREEP(unicodeString);
343 }
344
345 void XAP_CocoaDialog_FontChooser::_okAction(void)
346 {
347 m_answer = XAP_Dialog_FontChooser::a_OK;
348 [NSApp stopModal];
349 }
350
351
352 void XAP_CocoaDialog_FontChooser::_cancelAction(void)
353 {
354 m_answer = XAP_Dialog_FontChooser::a_CANCEL;
355 [NSApp stopModal];
356 }
357
358 /* callbacks to create / release the GR_Graphics when the window is loaded / released */
359 void XAP_CocoaDialog_FontChooser::_createGC(XAP_CocoaNSView* owner)
360 {
361 NSSize size;
362 GR_CocoaCairoAllocInfo ai(owner);
363 m_pGraphics = static_cast<GR_CocoaCairoGraphics*>(XAP_App::getApp()->newGraphics(ai));
364
365 size = [owner bounds].size;
366 _createFontPreviewFromGC(m_pGraphics, lrintf(size.width), lrintf(size.height));
367 }
368
369 void XAP_CocoaDialog_FontChooser::_deleteGC(void)
370 {
371 DELETEP(m_pGraphics);
372 m_pGraphics = NULL;
373 }
374
375 @implementation XAP_CocoaDialog_FontChooserController
376
377 - (id)initFromNib
378 {
379 return [super initWithWindowNibName:@"xap_CocoaDlg_FontChooser"];
380 }
381
382 -(void)discardXAP
383 {
384 if (_xap) {
385 _xap->_deleteGC();
386 _xap = NULL;
387 }
388 }
389
390 -(void)dealloc
391 {
392 [m_sizeDataSource release];
393 [m_stylesDataSource release];
394 [m_fontDataSource release];
395 [super dealloc];
396 }
397
398 - (void)setXAPOwner:(XAP_Dialog *)owner
399 {
400 _xap = dynamic_cast<XAP_CocoaDialog_FontChooser*>(owner);
401 }
402
403 -(void)windowDidLoad
404 {
405 if (_xap) {
406 const XAP_StringSet * pSS = _xap->getApp()->getStringSet();
407
408 LocalizeControl([self window], pSS, XAP_STRING_ID_DLG_UFS_FontTitle);
409
410 LocalizeControl(_okBtn, pSS, XAP_STRING_ID_DLG_OK);
411 LocalizeControl(_cancelBtn, pSS, XAP_STRING_ID_DLG_Cancel);
412 LocalizeControl(_fontLabel, pSS, XAP_STRING_ID_DLG_UFS_FontLabel);
413 LocalizeControl(_styleLabel, pSS, XAP_STRING_ID_DLG_UFS_StyleLabel);
414 LocalizeControl(_sizeLabel, pSS, XAP_STRING_ID_DLG_UFS_SizeLabel);
415 LocalizeControl(_effectLabel, pSS, XAP_STRING_ID_DLG_UFS_EffectsFrameLabel);
416 LocalizeControl(_strikeButton, pSS, XAP_STRING_ID_DLG_UFS_StrikeoutCheck);
417 LocalizeControl(_underlineButton, pSS, XAP_STRING_ID_DLG_UFS_UnderlineCheck);
418 LocalizeControl(_overlineButton, pSS, XAP_STRING_ID_DLG_UFS_OverlineCheck);
419 LocalizeControl(_strikeButton, pSS, XAP_STRING_ID_DLG_UFS_StrikeoutCheck);
420 // LocalizeControl(_strikeButton, pSS, XAP_STRING_ID_DLG_UFS_EncodingLabel);
421 LocalizeControl(_superscriptButton, pSS, XAP_STRING_ID_DLG_UFS_SuperScript);
422 LocalizeControl(_subscriptButton, pSS, XAP_STRING_ID_DLG_UFS_SubScript);
423 LocalizeControl(_textColorLabel, pSS, XAP_STRING_ID_DLG_UFS_ColorTab);
424 LocalizeControl(_textHighlightColorLabel, pSS, XAP_STRING_ID_DLG_UFS_BGColorTab);
425 LocalizeControl(_noHighlightColorButton, pSS, XAP_STRING_ID_DLG_UFS_TransparencyCheck);
426
427 m_fontDataSource = [[XAP_StringListDataSource alloc] init];
428 [m_fontDataSource loadFontList];
429 [_fontList setDataSource:m_fontDataSource];
430 [_fontList setDelegate:self];
431
432 m_stylesDataSource = [[XAP_StringListDataSource alloc] init];
433 std::string label;
434 pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_StyleRegular, label);
435 [m_stylesDataSource addCString:label.c_str()];
436 pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_StyleItalic, label);
437 [m_stylesDataSource addCString:label.c_str()];
438 pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_StyleBold, label);
439 [m_stylesDataSource addCString:label.c_str()];
440 pSS->getValueUTF8(XAP_STRING_ID_DLG_UFS_StyleBoldItalic, label);
441 [m_stylesDataSource addCString:label.c_str()];
442 [_styleList setDataSource:m_stylesDataSource];
443 [_styleList setDelegate:self];
444
445 m_sizeDataSource = [[XAP_StringListDataSource alloc] init];
446 {
447 int sz = XAP_EncodingManager::fontsizes_mapping.size();
448 for (int i = 0; i < sz; ++i)
449 {
450 char* str = (char*)XAP_EncodingManager::fontsizes_mapping.nth2(i);
451 if (str) {
452 [m_sizeDataSource addString:[NSString stringWithUTF8String:str]];
453 }
454 else {
455 NSLog(@"attempting to add NULL to string data source (%s:%d)", __FILE__, __LINE__);
456 }
457 }
458 }
459 [_sizeList setDataSource:m_sizeDataSource];
460 [_sizeList setDelegate:self];
461 }
462 else {
463 NSLog(@"Loaded Windows without XAP (%s:%d)", __FILE__, __LINE__);
464 }
465
466 if ([[NSColorPanel sharedColorPanel] isVisible])
467 {
468 [_textColorWell activate:YES];
469 }
470 }
471
472 -(IBAction)okAction:(id)sender
473 {
474 UT_UNUSED(sender);
475 [[NSColorPanel sharedColorPanel] orderOut:self];
476
477 static_cast<XAP_CocoaDialog_FontChooser *>(_xap)->_okAction();
478 }
479
480 -(IBAction)cancelAction:(id)sender
481 {
482 UT_UNUSED(sender);
483 [[NSColorPanel sharedColorPanel] orderOut:self];
484
485 static_cast<XAP_CocoaDialog_FontChooser *>(_xap)->_cancelAction();
486 }
487
488 -(IBAction)colorWellAction:(id)sender
489 {
490 if (sender == _textColorWell) {
491 _xap->fgColorChanged();
492 }
493 else if (sender == _textHighlightColorWell) {
494 _xap->bgColorChanged();
495 }
496 }
497
498 -(IBAction)underlineAction:(id)sender
499 {
500 static_cast<XAP_CocoaDialog_FontChooser*>(_xap)->underlineChanged
501 ([(NSControl*)sender intValue] == NSOffState ? 0 : 1);
502 }
503
504 -(IBAction)overlineAction:(id)sender
505 {
506 static_cast<XAP_CocoaDialog_FontChooser*>(_xap)->overlineChanged
507 ([(NSControl*)sender intValue] == NSOffState ? 0 : 1);
508 }
509
510 -(IBAction)strikeoutAction:(id)sender
511 {
512 static_cast<XAP_CocoaDialog_FontChooser*>(_xap)->strikeoutChanged
513 ([(NSControl*)sender intValue] == NSOffState ? 0 : 1);
514 }
515
516 -(IBAction)superscriptAction:(id)sender
517 {
518 static_cast<XAP_CocoaDialog_FontChooser*>(_xap)->superscriptChanged
519 ([(NSControl*)sender intValue] == NSOffState ? 0 : 1);
520 }
521
522 -(IBAction)subscriptAction:(id)sender
523 {
524 static_cast<XAP_CocoaDialog_FontChooser*>(_xap)->subscriptChanged
525 ([(NSControl*)sender intValue] == NSOffState ? 0 : 1);
526 }
527
528 -(IBAction)transparentAction:(id)sender
529 {
530 static_cast<XAP_CocoaDialog_FontChooser*>(_xap)->transparencyChanged
531 ([(NSControl*)sender intValue] == NSOffState ? 0 : 1);
532 }
533
534 - (void)tableViewSelectionDidChange:(NSNotification *)aNotification
535 {
536 id obj = [aNotification object];
537 if (obj == _fontList) {
538 _xap->fontRowChanged();
539 }
540 else if (obj == _styleList) {
541 int idx;
542 idx = [_styleList selectedRow];
543 _xap->styleRowChanged(idx);
544 }
545 else if (obj == _sizeList) {
546 _xap->sizeRowChanged();
547 }
548 }
549
550 - (XAP_CocoaNSView*)preview;
551 {
552 return _preview;
553 }
554
555 -(void)setStrikeout:(bool)value
556 {
557 [_strikeButton setState:(value ? NSOnState : NSOffState)];
558 }
559
560 -(void)setUnderline:(bool)value
561 {
562 [_underlineButton setState:(value ? NSOnState : NSOffState)];
563 }
564
565 -(void)setOverline:(bool)value
566 {
567 [_overlineButton setState:(value ? NSOnState : NSOffState)];
568 }
569
570 -(void)setSuperscript:(bool)value
571 {
572 [_superscriptButton setState:(value ? NSOnState : NSOffState)];
573 }
574
575 -(void)setSubscript:(bool)value
576 {
577 [_subscriptButton setState:(value ? NSOnState : NSOffState)];
578 }
579
580 -(void)selectFont:(char*)value
581 {
582 if (value) {
583 int idx = [(XAP_StringListDataSource*)[_fontList dataSource] rowWithCString:value];
584 if (idx >= 0) {
585 [_fontList selectRowIndexes:[NSIndexSet indexSetWithIndex:idx] byExtendingSelection:NO];
586 [_fontList scrollRowToVisible:idx];
587 }
588 }
589 else {
590 UT_DEBUGMSG(("selectFont: called with NULL value\n"));
591 [_fontList setAllowsEmptySelection:YES];
592 [_fontList deselectAll:nil];
593 return;
594 }
595
596 }
597
598
599 -(NSString*)selectedFont
600 {
601 int idx = [_fontList selectedRow];
602 return [[(XAP_StringListDataSource*)[_fontList dataSource] array] objectAtIndex:idx];
603 }
604
605
606 -(void)selectSize:(char*)value
607 {
608 int idx;
609 char sizeString[60];
610
611 if (value == NULL) {
612 UT_DEBUGMSG(("selectSize: called with NULL value\n"));
613 [_sizeList setAllowsEmptySelection:YES];
614 [_sizeList deselectAll:nil];
615 return;
616 }
617 snprintf(sizeString, 60, "%s", std_size_string(UT_convertToPoints(value)));
618 idx = [(XAP_StringListDataSource*)[_sizeList dataSource] rowWithCString:(char *)XAP_EncodingManager::fontsizes_mapping.lookupBySource(sizeString)];
619 if (idx >= 0) {
620 [_sizeList selectRowIndexes:[NSIndexSet indexSetWithIndex:idx] byExtendingSelection:NO];
621 [_sizeList scrollRowToVisible:idx];
622 }
623 }
624
625
626 -(NSString*)selectedSize
627 {
628 int idx = [_sizeList selectedRow];
629 return [[(XAP_StringListDataSource*)[_sizeList dataSource] array] objectAtIndex:idx];
630 }
631
632
633 -(void)selectStyle:(char*)style withWeight:(char*)weight
634 {
635 // this is pretty messy
636 int st = 0;
637 if (!style || !weight) {
638 st = -1;
639 }
640 else if (!g_ascii_strcasecmp(style, "normal") &&
641 !g_ascii_strcasecmp(weight, "normal")) {
642 st = 0;
643 }
644 else if (!g_ascii_strcasecmp(style, "italic") &&
645 !g_ascii_strcasecmp(weight, "normal")) {
646 st = 1;
647 }
648 else if (!g_ascii_strcasecmp(style, "normal") &&
649 !g_ascii_strcasecmp(weight, "bold")){
650 st = 2;
651 }
652 else if (!g_ascii_strcasecmp(style, "italic") &&
653 !g_ascii_strcasecmp(weight, "bold")) {
654 st = 3;
655 }
656 else {
657 UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
658 }
659 if (st != -1) {
660 [_styleList selectRowIndexes:[NSIndexSet indexSetWithIndex:st] byExtendingSelection:NO];
661 [_styleList scrollRowToVisible:st];
662 }
663 }
664
665
666 -(NSColor*)textColor
667 {
668 return [_textColorWell color];
669 }
670
671 -(void)setTextColor:(NSColor*)color
672 {
673 [_textColorWell setColor:color];
674 }
675
676 -(NSColor*)bgColor
677 {
678 return [_textHighlightColorWell color];
679 }
680
681 -(void)setBgColor:(NSColor*)color
682 {
683 [_textHighlightColorWell setColor:color];
684 }
685
686 @end
687