1 /* AbiWord
2 * Copyright (C) 1998-2000 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27
28 #include "ap_Features.h"
29
30 #include "ut_types.h"
31 #include "ut_assert.h"
32 #include "ut_misc.h"
33 #include "ut_string.h"
34 #include "ut_std_string.h"
35 #include "ut_units.h"
36 #include "ut_debugmsg.h"
37
38 #include "ap_Toolbar_Id.h"
39 #include "ap_Toolbar_Functions.h"
40 #include "ev_Toolbar_Actions.h"
41 #include "ev_Toolbar_Labels.h"
42 #include "xap_App.h"
43 #include "xap_Prefs.h"
44 #include "xap_Clipboard.h"
45 #include "xap_Frame.h"
46 #include "fv_View.h"
47 #include "gr_Graphics.h"
48 #include "fl_AutoNum.h"
49 #include "fl_BlockLayout.h"
50 #include "ap_Prefs_SchemeIds.h"
51 #include "ap_FrameData.h"
52 #include "pd_Document.h"
53 #include "pd_DocumentRDF.h"
54 #include "ut_Script.h"
55
56 #ifdef ENABLE_SPELL
57 #include "spell_manager.h"
58 #endif
59
60 #include "ap_EditMethods.h"
61 #include "fp_TableContainer.h"
62
63 #define ABIWORD_VIEW FV_View * pView = static_cast<FV_View *>(pAV_View)
64
65 #if 0
66
67 static bool s_ToolbarFunctions_check_inc_load(FV_View * pView)
68 {
69 // todo: we probably need to make this function smarter.
70 // see ap_EditMethods.cpp around line 1024
71
72 //XAP_Frame * pFrame = XAP_App::getApp()->getLastFocussedFrame();
73 UT_DEBUGMSG(("pView = %x \n",pView));
74 if(pView && ((pView->getPoint() == 0) || pView->isLayoutFilling()))
75 {
76 return true;
77 }
78
79 return false ;
80 }
81
82 #define CHECK_INC_LOAD if(s_ToolbarFunctions_check_inc_load(pView)) return EV_TIS_Gray;
83 #else
84 #define CHECK_INC_LOAD
85 #endif
86
87 /****************************************************************/
88
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_ScriptsActive)89 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_ScriptsActive)
90 {
91 UT_UNUSED(pAV_View);
92 UT_UNUSED(id);
93 UT_UNUSED(pszState);
94
95 EV_Toolbar_ItemState s = EV_TIS_ZERO;
96
97 UT_ScriptLibrary * instance = UT_ScriptLibrary::instance ();
98 UT_uint32 filterCount = instance->getNumScripts ();
99
100 if ( filterCount == 0 )
101 s = EV_TIS_Gray;
102
103 return s;
104 }
105
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_BookmarkOK)106 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_BookmarkOK)
107 {
108 ABIWORD_VIEW;
109 CHECK_INC_LOAD;
110 UT_UNUSED(id);
111 UT_UNUSED(pszState);
112
113 EV_Toolbar_ItemState s = EV_TIS_ZERO;
114
115 if(pView->isTOCSelected())
116 {
117 s = EV_TIS_Gray ;
118 return s;
119 }
120 PT_DocPosition posStart = pView->getPoint();
121 PT_DocPosition posEnd = pView->getSelectionAnchor();
122 fl_BlockLayout * pBL1 = pView->getBlockAtPosition(posStart);
123 fl_BlockLayout * pBL2 = pView->getBlockAtPosition(posEnd);
124 if((pBL1 == NULL) || (pBL2 == NULL)) // make sure we get valid blocks from selection beginning and end
125 {
126 s = EV_TIS_Gray;
127 return s;
128 }
129 if(pBL1 != pBL2) // don't allow Insert bookmark if selection spans multiple blocks
130 {
131 s = EV_TIS_Gray ;
132 return s;
133 }
134
135 return s ;
136 }
137
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_HyperlinkOK)138 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_HyperlinkOK)
139 {
140 ABIWORD_VIEW ;
141 CHECK_INC_LOAD;
142 UT_UNUSED(id);
143 UT_UNUSED(pszState);
144 UT_return_val_if_fail (pView, EV_TIS_Gray);
145
146 EV_Toolbar_ItemState s = EV_TIS_ZERO;
147 if ( pView->isSelectionEmpty())
148 {
149 if(pView->getHyperLinkRun(pView->getPoint()) == NULL)
150 {
151 s = EV_TIS_Gray ;
152 return s;
153 }
154 return s;
155 }
156 if(pView->isTOCSelected())
157 {
158 s = EV_TIS_Gray ;
159 return s;
160 }
161 PT_DocPosition posStart = pView->getPoint();
162 PT_DocPosition posEnd = pView->getSelectionAnchor();
163 fl_BlockLayout * pBL1 = pView->getBlockAtPosition(posStart);
164 fl_BlockLayout * pBL2 = pView->getBlockAtPosition(posEnd);
165 if((pBL1 == NULL) || (pBL2 == NULL)) // make sure we get valid blocks from selection beginning and end
166 {
167 s = EV_TIS_Gray;
168 return s;
169 }
170 if(pBL1 != pBL2) // don't allow Insert Hyperlink if selection spans multiple blocks
171 {
172 s = EV_TIS_Gray ;
173 return s;
174 }
175 if(pBL1->getLength() == 1)
176 {
177 s = EV_TIS_Gray ;
178 return s;
179 }
180
181 if(UT_MIN(posStart,posEnd) < pBL1->getPosition(true))
182 {
183 s = EV_TIS_Gray ;
184 return s;
185 }
186
187
188 return s ;
189 }
190
191 #ifdef ENABLE_SPELL
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Spelling)192 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Spelling)
193 {
194 //ABIWORD_VIEW;
195 CHECK_INC_LOAD;
196 UT_UNUSED(pAV_View);
197 UT_UNUSED(id);
198 UT_UNUSED(pszState);
199
200 EV_Toolbar_ItemState s = EV_TIS_ZERO;
201
202 XAP_Prefs *pPrefs = XAP_App::getApp()->getPrefs();
203 UT_return_val_if_fail ( pPrefs, EV_TIS_Gray );
204
205 bool b = true ;
206 pPrefs->getPrefsValueBool(static_cast<const gchar *>(AP_PREF_KEY_AutoSpellCheck),&b) ;
207
208 // if there are no loaded dictionaries and we are spell checking
209 // as we type
210 if ( SpellManager::instance ().numLoadedDicts() == 0 && b )
211 s = EV_TIS_Gray;
212
213 // either have a loaded dictionary or want to spell-check manually. allow
214
215 return s;
216 }
217 #endif
218
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Changes)219 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Changes)
220 {
221 ABIWORD_VIEW;
222 CHECK_INC_LOAD;
223
224 EV_Toolbar_ItemState s = EV_TIS_ZERO;
225
226 if(!pView)
227 {
228 return s;
229 }
230 if (pszState)
231 *pszState = NULL;
232
233 switch (id)
234 {
235 case AP_TOOLBAR_ID_FILE_SAVE: // see bug 7580
236 if (!pView->getDocument()->isDirty() /*|| !pView->canDo(true)*/ /*|| pView->getDocument()->getFilename() == NULL */)
237 s = EV_TIS_Gray;
238 break;
239 case AP_TOOLBAR_ID_EDIT_UNDO:
240 if (!pView->canDo(true))
241 s = EV_TIS_Gray;
242 break;
243
244 case AP_TOOLBAR_ID_EDIT_REDO:
245 if (!pView->canDo(false))
246 s = EV_TIS_Gray;
247 break;
248
249 default:
250 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
251 break;
252 }
253
254 return s;
255 }
256
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Selection)257 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Selection)
258 {
259 ABIWORD_VIEW;
260 CHECK_INC_LOAD;
261
262 if (pszState)
263 *pszState = NULL;
264
265 EV_Toolbar_ItemState s = EV_TIS_ZERO;
266
267 switch (id)
268 {
269 case AP_TOOLBAR_ID_EDIT_CUT:
270 case AP_TOOLBAR_ID_EDIT_COPY:
271 case AP_TOOLBAR_ID_FMT_HYPERLINK:
272 if (pView->isSelectionEmpty())
273 s = EV_TIS_Gray;
274 break;
275
276 default:
277 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
278 break;
279 }
280
281 return s;
282 }
283
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Clipboard)284 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Clipboard)
285 {
286 ABIWORD_VIEW;
287
288 if (pszState)
289 *pszState = NULL;
290
291 EV_Toolbar_ItemState s = EV_TIS_ZERO;
292
293 switch (id)
294 {
295 case AP_TOOLBAR_ID_EDIT_PASTE:
296 s = ((XAP_App::getApp()->canPasteFromClipboard()) ? EV_TIS_ZERO : EV_TIS_Gray );
297 break;
298
299 case AP_TOOLBAR_ID_FMTPAINTER:
300 if (pView && XAP_App::getApp()->canPasteFromClipboard() &&
301 !pView->isSelectionEmpty() && !pView->getDocument()->areStylesLocked())
302 s = EV_TIS_ZERO;
303 else
304 s = EV_TIS_Gray;
305 break;
306
307 default:
308 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
309 break;
310 }
311
312 return s;
313 }
314
315
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_HdrFtr)316 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_HdrFtr)
317 {
318 ABIWORD_VIEW;
319 UT_return_val_if_fail (pView, EV_TIS_Gray);
320
321 if (pszState)
322 *pszState = NULL;
323
324 EV_Toolbar_ItemState s = EV_TIS_ZERO;
325
326
327 switch (id)
328 {
329 case AP_TOOLBAR_ID_EDIT_REMOVEHEADER:
330 if (!pView->isHeaderOnPage())
331 s = EV_TIS_Gray;
332 break;
333
334 case AP_TOOLBAR_ID_EDIT_REMOVEFOOTER:
335 if (!pView->isFooterOnPage())
336 s = EV_TIS_Gray;
337 break;
338 default:
339 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
340 break;
341 }
342 return s;
343 }
344
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Style)345 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Style)
346 {
347 ABIWORD_VIEW;
348 CHECK_INC_LOAD;
349
350 EV_Toolbar_ItemState s = EV_TIS_ZERO;
351
352 switch (id)
353 {
354 case AP_TOOLBAR_ID_FMT_STYLE:
355 {
356 const gchar * sz = NULL;
357 if (!pView->getStyle(&sz))
358 {
359 static const char * sz2 ="None";
360 *pszState = sz2;
361 s = EV_TIS_UseString;
362 }
363
364 if (sz)
365 {
366 static const char * sz2 = "None";
367 sz2 = sz;
368 *pszState = sz2;
369 s = EV_TIS_UseString;
370 }
371 else
372 {
373 static const char * sz2 ="None";
374 *pszState = sz2;
375 s = EV_TIS_UseString;
376 }
377 break;
378 }
379
380 default:
381 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
382 break;
383 }
384 return s;
385 }
386
387
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Bullets)388 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Bullets)
389 {
390 ABIWORD_VIEW;
391 CHECK_INC_LOAD;
392 UT_UNUSED(id);
393 UT_UNUSED(pszState);
394
395 EV_Toolbar_ItemState s = EV_TIS_ZERO;
396
397 if(pView->isHdrFtrEdit() || pView->isInHdrFtr(pView->getPoint()))
398 {
399 return EV_TIS_Gray;
400 }
401
402 fl_BlockLayout * pBlock = pView->getCurrentBlock();
403 UT_return_val_if_fail (pBlock, EV_TIS_Gray);
404 if(pBlock->isListItem() == false)
405 return s;
406 if(pBlock->getListType() == BULLETED_LIST)
407 s = EV_TIS_Toggled;
408 return s;
409 }
410
411
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Numbers)412 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Numbers)
413 {
414 ABIWORD_VIEW;
415 CHECK_INC_LOAD;
416 UT_UNUSED(id);
417 UT_UNUSED(pszState);
418
419 EV_Toolbar_ItemState s = EV_TIS_ZERO;
420 if(pView->isHdrFtrEdit() || pView->isInHdrFtr(pView->getPoint()))
421 {
422 return EV_TIS_Gray;
423 }
424
425 fl_BlockLayout * pBlock = pView->getCurrentBlock();
426 UT_return_val_if_fail (pBlock, EV_TIS_Gray);
427 if(pBlock->isListItem() == false)
428 return s;
429 if(pBlock->getListType() == NUMBERED_LIST)
430 s = EV_TIS_Toggled;
431 return s;
432 }
433
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Indents)434 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Indents)
435 {
436 ABIWORD_VIEW;
437 UT_UNUSED(pszState);
438
439 EV_Toolbar_ItemState s = EV_TIS_ZERO;
440
441 double margin_left = 0., margin_right = 0., allowed = 0.,
442 page_margin_left = 0., page_margin_right = 0.,
443 page_margin_top = 0., page_margin_bottom = 0.;
444
445 s_getPageMargins(pView, margin_left, margin_right,
446 page_margin_left, page_margin_right,
447 page_margin_top, page_margin_bottom);
448
449 UT_BidiCharType iBlockDir = UT_BIDI_LTR;
450 if(pView->getCurrentBlock())
451 iBlockDir = pView->getCurrentBlock()->getDominantDirection();
452
453 switch(id)
454 {
455 case AP_TOOLBAR_ID_INDENT:
456 allowed = pView->getPageSize().Width (DIM_IN) - page_margin_left - page_margin_right;
457 if (margin_left >= allowed)
458 s = EV_TIS_Gray;
459 break;
460 case AP_TOOLBAR_ID_UNINDENT:
461 allowed = iBlockDir == UT_BIDI_LTR ? margin_left : margin_right;
462
463 if (allowed <= 0.)
464 s = EV_TIS_Gray;
465 break;
466 }
467
468 return s;
469 }
470
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_CharFmt)471 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_CharFmt)
472 {
473 ABIWORD_VIEW;
474 CHECK_INC_LOAD;
475
476 bool bMultiple = false;
477 bool bSize = false;
478 bool bString = false;
479
480 const gchar * prop = NULL;
481 const gchar * val = NULL;
482
483 EV_Toolbar_ItemState s = EV_TIS_ZERO;
484
485 // todo: rtl/ltr/dom-dir are legal
486 if(pView->getDocument()->areStylesLocked() && !(AP_TOOLBAR_ID_FMT_SUPERSCRIPT == id || AP_TOOLBAR_ID_FMT_SUBSCRIPT == id)) {
487 return EV_TIS_Gray;
488 }
489
490 switch (id)
491 {
492 case AP_TOOLBAR_ID_FMT_FONT:
493 prop = "font-family";
494 val = "";
495 bString = true;
496 break;
497
498 case AP_TOOLBAR_ID_FMT_SIZE:
499 prop = "font-size";
500 val = "";
501 bSize = true;
502 break;
503
504 case AP_TOOLBAR_ID_FMT_BOLD:
505 prop = "font-weight";
506 val = "bold";
507 break;
508
509 case AP_TOOLBAR_ID_FMT_ITALIC:
510 prop = "font-style";
511 val = "italic";
512 break;
513
514 case AP_TOOLBAR_ID_FMT_UNDERLINE:
515 prop = "text-decoration";
516 val = "underline";
517 bMultiple = true;
518 break;
519
520 case AP_TOOLBAR_ID_FMT_OVERLINE:
521 prop = "text-decoration";
522 val = "overline";
523 bMultiple = true;
524 break;
525
526 case AP_TOOLBAR_ID_FMT_STRIKE:
527 prop = "text-decoration";
528 val = "line-through";
529 bMultiple = true;
530 break;
531
532
533 case AP_TOOLBAR_ID_FMT_TOPLINE:
534 prop = "text-decoration";
535 val = "topline";
536 bMultiple = true;
537 break;
538
539
540 case AP_TOOLBAR_ID_FMT_BOTTOMLINE:
541 prop = "text-decoration";
542 val = "bottomline";
543 bMultiple = true;
544 break;
545
546 case AP_TOOLBAR_ID_FMT_SUPERSCRIPT:
547 prop = "text-position";
548 val = "superscript";
549 bMultiple = true;
550 break;
551
552 case AP_TOOLBAR_ID_FMT_SUBSCRIPT:
553 prop = "text-position";
554 val = "subscript";
555 bMultiple = true;
556 break;
557
558 case AP_TOOLBAR_ID_FMT_DIR_OVERRIDE_LTR:
559 prop = "dir-override";
560 val = "ltr";
561 break;
562
563 case AP_TOOLBAR_ID_FMT_DIR_OVERRIDE_RTL:
564 prop = "dir-override";
565 val = "rtl";
566 break;
567
568 default:
569 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
570 break;
571 }
572
573 if (prop && val)
574 {
575 // get current char properties from pView
576 const gchar ** props_in = NULL;
577 const gchar * sz = NULL;
578
579 if (!pView->getCharFormat(&props_in))
580 return s;
581
582 // NB: maybe *no* properties are consistent across the selection
583 if (props_in && props_in[0])
584 sz = UT_getAttribute(prop, props_in);
585
586 if (sz)
587 {
588 if (bSize)
589 {
590 static char buf[7];
591 sprintf(buf, "%s", std_size_string(static_cast<float>(UT_convertToPoints(sz))));
592 *pszState = buf;
593 s = EV_TIS_UseString;
594 }
595 else if (bString)
596 {
597 static const char * sz2;
598 sz2 = sz;
599 *pszState = sz2;
600 s = EV_TIS_UseString;
601 }
602 else if (bMultiple)
603 {
604 // some properties have multiple values
605 if (strstr(sz, val))
606 s = EV_TIS_Toggled;
607 }
608 else
609 {
610 if (0 == strcmp(sz, val))
611 s = EV_TIS_Toggled;
612 }
613 }
614
615 g_free(props_in);
616 }
617
618 return s;
619 }
620
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_SectionFmt)621 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_SectionFmt)
622 {
623 ABIWORD_VIEW;
624 CHECK_INC_LOAD;
625
626 if (pszState)
627 *pszState = NULL;
628
629 const gchar * prop = "";
630 const gchar * val = NULL;
631
632 EV_Toolbar_ItemState s = EV_TIS_ZERO;
633
634 if(pView->isHdrFtrEdit() || pView->isInHdrFtr(pView->getPoint()))
635 {
636 switch(id)
637 {
638 // only 1 column allowed
639 case AP_TOOLBAR_ID_1COLUMN:
640 return EV_TIS_Toggled;
641
642 // not allowed
643 case AP_TOOLBAR_ID_2COLUMN:
644 case AP_TOOLBAR_ID_3COLUMN:
645 case AP_TOOLBAR_ID_INSERT_TABLE:
646 return EV_TIS_Gray;
647 }
648 }
649 if(id == AP_TOOLBAR_ID_INSERT_TABLE)
650 {
651 return EV_TIS_ZERO;
652 }
653 switch (id)
654 {
655 case AP_TOOLBAR_ID_1COLUMN:
656 prop = "columns";
657 val = "1";
658 break;
659 case AP_TOOLBAR_ID_2COLUMN:
660 prop = "columns";
661 val = "2";
662 break;
663 case AP_TOOLBAR_ID_3COLUMN:
664 prop = "columns";
665 val = "3";
666 break;
667 default:
668 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
669 break;
670 }
671 s = EV_TIS_ZERO;
672 if (prop && val)
673 {
674 // get current block properties from pView
675 const gchar ** props_in = NULL;
676 const gchar * sz = NULL;
677
678 bool bResult = pView->getSectionFormat(&props_in);
679
680 if (!bResult)
681 {
682 return s;
683 }
684 // NB: maybe *no* properties are consistent across the selection
685 if (props_in && props_in[0])
686 sz = UT_getAttribute(prop, props_in);
687
688 if (sz)
689 {
690 if (0 == strcmp(sz, val))
691 {
692 s = EV_TIS_Toggled;
693 }
694 else
695 {
696 s = EV_TIS_ZERO;
697 }
698 }
699
700 g_free(props_in);
701 }
702
703 return s;
704 }
705
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_BlockFmt)706 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_BlockFmt)
707 {
708 ABIWORD_VIEW;
709 CHECK_INC_LOAD;
710
711 if (pszState)
712 *pszState = NULL;
713
714 bool bPoints = false;
715
716 const gchar * prop = "text-align";
717 const gchar * val = NULL;
718
719 EV_Toolbar_ItemState s = EV_TIS_ZERO;
720
721 if(pView->getDocument()->areStylesLocked()) {
722 return EV_TIS_Gray;
723 }
724
725 switch (id)
726 {
727 case AP_TOOLBAR_ID_ALIGN_LEFT:
728 val = "left";
729 break;
730
731 case AP_TOOLBAR_ID_ALIGN_CENTER:
732 val = "center";
733 break;
734
735 case AP_TOOLBAR_ID_ALIGN_RIGHT:
736 val = "right";
737 break;
738
739 case AP_TOOLBAR_ID_ALIGN_JUSTIFY:
740 val = "justify";
741 break;
742
743 case AP_TOOLBAR_ID_PARA_0BEFORE:
744 prop = "margin-top";
745 val = "0pt";
746 bPoints = true;
747 break;
748
749 case AP_TOOLBAR_ID_PARA_12BEFORE:
750 prop = "margin-top";
751 val = "12pt";
752 bPoints = true;
753 break;
754
755 case AP_TOOLBAR_ID_SINGLE_SPACE:
756 prop = "line-height";
757 val = "1.0";
758 break;
759
760 case AP_TOOLBAR_ID_MIDDLE_SPACE:
761 prop = "line-height";
762 val = "1.5";
763 break;
764
765 case AP_TOOLBAR_ID_DOUBLE_SPACE:
766 prop = "line-height";
767 val = "2.0";
768 break;
769
770 case AP_TOOLBAR_ID_FMT_DOM_DIRECTION:
771 prop = "dom-dir";
772 val = "rtl";
773 xxx_UT_DEBUGMSG(("ap_ToolbarGetState_BlockFmt: dom-dir\n"));
774 break;
775
776 default:
777 UT_DEBUGMSG(("id=%d", id));
778 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
779 break;
780 }
781
782 if (prop && val)
783 {
784 // get current block properties from pView
785 const gchar ** props_in = NULL;
786 const gchar * sz = NULL;
787
788 if (!pView->getBlockFormat(&props_in))
789 return s;
790
791 // NB: maybe *no* properties are consistent across the selection
792 if (props_in && props_in[0])
793 sz = UT_getAttribute(prop, props_in);
794
795 if (sz)
796 {
797 if (bPoints)
798 {
799 if ((static_cast<int>(UT_convertToPoints(sz))) == (static_cast<int>(UT_convertToPoints(val))))
800 s = EV_TIS_Toggled;
801 }
802 else
803 {
804 if (0 == strcmp(sz, val))
805 s = EV_TIS_Toggled;
806 }
807 }
808
809 g_free(props_in);
810 }
811
812 return s;
813 }
814
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Zoom)815 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Zoom)
816 {
817 ABIWORD_VIEW;
818 UT_UNUSED(id);
819 UT_return_val_if_fail (pView, EV_TIS_Gray);
820
821 XAP_Frame * pFrame = static_cast<XAP_Frame *> ( pView->getParentData());
822 const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
823
824 EV_Toolbar_ItemState s = EV_TIS_UseString;
825
826 UT_uint32 iZoom = 0 ;
827 static std::string str;
828
829 switch(pFrame->getZoomType())
830 {
831 // special cases
832 case XAP_Frame::z_PAGEWIDTH:
833 pSS->getValueUTF8(XAP_STRING_ID_TB_Zoom_PageWidth, str);
834 break;
835 case XAP_Frame::z_WHOLEPAGE:
836 pSS->getValueUTF8(XAP_STRING_ID_TB_Zoom_WholePage, str);
837 break;
838 default:
839 iZoom = pView->getGraphics()->getZoomPercentage();
840 str = UT_std_string_sprintf("%d%%", iZoom);
841 break;
842 }
843
844 *pszState = str.c_str();
845
846 return s;
847 }
848
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_View)849 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_View)
850 {
851 ABIWORD_VIEW;
852 UT_UNUSED(pszState);
853 UT_return_val_if_fail (pView, EV_TIS_Gray);
854
855 XAP_Frame * pFrame = static_cast<XAP_Frame *> (pAV_View->getParentData());
856 UT_return_val_if_fail (pFrame, EV_TIS_Gray);
857
858 AP_FrameData *pFrameData = static_cast<AP_FrameData *> (pFrame->getFrameData());
859 UT_return_val_if_fail (pFrameData, EV_TIS_Gray);
860
861 EV_Toolbar_ItemState s = EV_TIS_ZERO;
862
863 switch(id)
864 {
865 case AP_TOOLBAR_ID_VIEW_SHOWPARA:
866 if ( pFrameData->m_bShowPara )
867 s = EV_TIS_Toggled;
868 break;
869
870 default:
871 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
872 break;
873 }
874
875 return s;
876 }
877
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_StylesLocked)878 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_StylesLocked)
879 {
880 ABIWORD_VIEW;
881 UT_UNUSED(id);
882 UT_UNUSED(pszState);
883 UT_return_val_if_fail (pView, EV_TIS_Gray);
884
885 if(pView->getDocument()->areStylesLocked()) {
886 return EV_TIS_Gray;
887 }
888
889 return EV_TIS_ZERO;
890 }
891
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Table)892 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_Table)
893 {
894 ABIWORD_VIEW;
895 UT_UNUSED(id);
896 UT_UNUSED(pszState);
897 UT_return_val_if_fail (pView, EV_TIS_Gray);
898
899 if(pView->isInTable() )
900 {
901 return EV_TIS_ZERO;
902 }
903 return EV_TIS_Gray;
904 }
905
906
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_TableOK)907 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_TableOK)
908 {
909 ABIWORD_VIEW;
910 UT_UNUSED(id);
911 UT_UNUSED(pszState);
912 UT_return_val_if_fail (pView, EV_TIS_Gray);
913
914 if(pView->isInTable() && (pView->isHdrFtrEdit() || pView->isInHdrFtr(pView->getPoint())))
915 {
916 return EV_TIS_Gray;
917 }
918 else if(pView->isInFootnote())
919 {
920 return EV_TIS_Gray;
921 }
922 else if(pView->isInAnnotation())
923 {
924 return EV_TIS_Gray;
925 }
926 else if(pView->isInEndnote())
927 {
928 return EV_TIS_Gray;
929 }
930 else if(pView->getHyperLinkRun(pView->getPoint()) != NULL)
931 {
932 return EV_TIS_Gray;
933 }
934
935 return EV_TIS_ZERO;
936 }
937
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_TableMerged)938 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_TableMerged)
939 {
940 ABIWORD_VIEW;
941 UT_UNUSED(id);
942 UT_UNUSED(pszState);
943 UT_return_val_if_fail (pView, EV_TIS_Gray);
944
945 if(pView->isInTable())
946 {
947 return EV_TIS_ZERO;
948 }
949 return EV_TIS_Gray;
950 }
951
952 // HACK TO ALWAYS DISABLE A TOOLBAR ITEM... DELETE ME
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_AlwaysDisabled)953 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_AlwaysDisabled)
954 {
955 UT_UNUSED(pAV_View);
956 UT_UNUSED(id);
957 UT_UNUSED(pszState);
958 return EV_TIS_Gray;
959 }
960
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_HasRevisions)961 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_HasRevisions)
962 {
963 UT_UNUSED(id);
964 UT_UNUSED(pszState);
965 ABIWORD_VIEW;
966 UT_return_val_if_fail (pView, EV_TIS_Gray);
967
968 if(pView->getDocument()->getHighestRevisionId() == 0)
969 return EV_TIS_Hidden;
970
971 return EV_TIS_ZERO;
972
973 }
974
Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_CursorInSemItem)975 Defun_EV_GetToolbarItemState_Fn(ap_ToolbarGetState_CursorInSemItem)
976 {
977 UT_UNUSED(pszState);
978 ABIWORD_VIEW;
979 UT_return_val_if_fail (pView, EV_TIS_Gray);
980
981 /* The editors aren't working yet. Remove if they do work. */
982 if (id == AP_TOOLBAR_ID_SEMITEM_EDIT)
983 return EV_TIS_Gray;
984
985 xxx_UT_DEBUGMSG((" ap_ToolbarGetState_CursorInSemItem() pDoc:%p\n", pView->getDocument() ));
986 if( PD_Document * pDoc = pView->getDocument() )
987 {
988 if( PD_DocumentRDFHandle rdf = pDoc->getDocumentRDF() )
989 {
990 if( !rdf->haveSemItems() )
991 {
992 return EV_TIS_Gray;
993 }
994
995 xxx_UT_DEBUGMSG((" ap_ToolbarGetState_CursorInSemItem(have rdf) point:%d\n", pView->getPoint() ));
996 std::set< std::string > col;
997 rdf->addRelevantIDsForPosition( col, pView->getPoint() );
998 if( col.empty() )
999 rdf->addRelevantIDsForPosition( col, pView->getPoint()-1 );
1000 xxx_UT_DEBUGMSG((" ap_ToolbarGetState_CursorInSemItem(d) point:%ld col.sz:%ld\n",
1001 pView->getPoint(), col.size() ));
1002 if( col.empty() )
1003 {
1004 return EV_TIS_Gray;
1005 }
1006 }
1007 }
1008
1009 return EV_TIS_ZERO;
1010 }
1011