1 /************************************************************************/
2 /*									*/
3 /*  Utility routines for the FormatTool.				*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"tedConfig.h"
8 
9 #   include	<stdio.h>
10 #   include	<stddef.h>
11 #   include	<limits.h>
12 
13 #   include	<appUnit.h>
14 
15 #   include	"tedApp.h"
16 #   include	"tedToolUtil.h"
17 #   include	"tedDocument.h"
18 #   include	<guiTextUtil.h>
19 #   include	<docEditCommand.h>
20 #   include	<docTreeNode.h>
21 #   include	<docNodeTree.h>
22 
23 #   include	<appDebugon.h>
24 
25 /************************************************************************/
26 /*									*/
27 /*  Validate a dimension						*/
28 /*									*/
29 /************************************************************************/
30 
tedFormatValidateDimension(int * pNewValue,int * pChanged,APP_WIDGET w,int oldValue)31 int tedFormatValidateDimension(		int *		pNewValue,
32 					int *		pChanged,
33 					APP_WIDGET	w,
34 					int		oldValue )
35     {
36     int				changed;
37 
38     const int			minValue= 1;
39     const int			adaptToMin= 0;
40     const int			maxValue= INT_MAX;
41     const int			adaptToMax= 0;
42 
43     if  ( ! appGetLengthFromTextWidget( w, &oldValue, &changed, UNITtyPOINTS,
44 				minValue, adaptToMin, maxValue, adaptToMax ) )
45 	{
46 	appLengthToTextWidget( w, oldValue, UNITtyPOINTS );
47 
48 	if  ( changed )
49 	    { *pNewValue= oldValue;	}
50 
51 	*pChanged= changed; return 0;
52 	}
53 
54     return -1;
55     }
56 
tedFormatCurDoc(EditDocument ** pEd,int * pTraced,EditApplication * ea)57 BufferDocument * tedFormatCurDoc(	EditDocument **		pEd,
58 					int *			pTraced,
59 					EditApplication *	ea )
60     {
61     EditDocument *		ed= ea->eaCurrentDocument;
62 
63     TedDocument *		td;
64     BufferDocument *		bd;
65 
66     if  ( ! ed )
67 	{ XDEB(ed); return (BufferDocument *)0;	}
68 
69     td= (TedDocument *)ed->edPrivateData;
70     bd= td->tdDocument;
71 
72     if  ( pTraced )
73 	{ *pTraced= td->tdTraced;	}
74 
75     *pEd= ed; return bd;
76     }
77 
78 
tedRefreshParaSubjectControls(InspectorSubject * is,const DocumentSelection * ds,const SelectionGeometry * sg,const SelectionDescription * sd,const unsigned char * cmdEnabled)79 void tedRefreshParaSubjectControls(
80 				InspectorSubject *		is,
81 				const DocumentSelection *	ds,
82 				const SelectionGeometry *	sg,
83 				const SelectionDescription *	sd,
84 				const unsigned char *		cmdEnabled )
85     {
86     BufferItem *			paraNode= ds->dsHead.dpNode;
87 
88     guiEnableWidget( is->isDeleteButton, cmdEnabled[EDITcmdDELETE_PARA] );
89 
90     guiEnableWidget( is->isSelectButton, sd->sdInContiguousParagraphs );
91     guiEnableWidget( is->isInsertButton, cmdEnabled[EDITcmdINSERT_PARA] );
92     guiEnableWidget( is->isAppendButton, cmdEnabled[EDITcmdAPPEND_PARA] );
93 
94     guiEnableWidget( is->isPrevButton,
95 				sd->sdInContiguousParagraphs		&&
96 				docPrevParagraph( paraNode ) != (BufferItem *)0 );
97     guiEnableWidget( is->isNextButton,
98 				sd->sdInContiguousParagraphs		&&
99 				docNextParagraph( paraNode ) != (BufferItem *)0 );
100 
101     guiEnableWidget( is->isRevertButton, cmdEnabled[EDITcmdUPD_PARA_PROPS] );
102     guiEnableWidget( is->isApplyButton, cmdEnabled[EDITcmdUPD_PARA_PROPS] );
103 
104     return;
105     }
106 
107