1 /* AbiWord
2  * Copyright (C) 1998 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 #ifndef AP_DIALOG_TAB_H
21 #define AP_DIALOG_TAB_H
22 
23 #include "xap_Frame.h"
24 #include "xap_Dialog.h"
25 #include "xav_View.h"
26 #include "ut_units.h"
27 #include "fl_BlockLayout.h"
28 
29 class XAP_Frame;
30 class AP_Dialog_Tab;
31 class FV_View;
32 
33 #define MAX_TAB_LENGTH 15 // the maximum length the the tab input can have
34 
35 typedef void (*TabSaveCallBack)(AP_Dialog_Tab * pDlg,
36 								FV_View *pView, const char * szTabStops,
37 								const char * szDflTabStop, void * closure);
38 
39 class ABI_EXPORT AP_Dialog_Tab : public XAP_Dialog_NonPersistent
40 {
41  public:
42 
43 	AP_Dialog_Tab(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id);
44 	virtual ~AP_Dialog_Tab(void);
45 
46 	virtual void	runModal(XAP_Frame * pFrame) = 0;
47 
48 	// answer from dialog
49 	typedef enum { a_OK, a_CANCEL } tAnswer;
50 
51 	// control ids
52 	typedef enum { id_EDIT_TAB = 0, id_LIST_TAB,
53 				   id_SPIN_DEFAULT_TAB_STOP,
54 
55 				   // should be in same order as eTabType (fl_BlockLayout.h)
56 				   id_ALIGN_LEFT, id_ALIGN_CENTER, id_ALIGN_RIGHT, id_ALIGN_DECIMAL, id_ALIGN_BAR,
57 
58 				   // should be in same order as eTabLeader (fl_BlockLayout.h)
59 				   id_LEADER_NONE, id_LEADER_DOT, id_LEADER_DASH, id_LEADER_UNDERLINE,
60 
61 				   id_BUTTON_SET, id_BUTTON_CLEAR, id_BUTTON_CLEAR_ALL,
62 				   id_BUTTON_OK, id_BUTTON_CANCEL,
63 
64 				   id_last } tControl;
65 
66 	AP_Dialog_Tab::tAnswer	getAnswer(void) const;
67 
68 	// clear the tab list
69 	void clearList();
70 
71 	static unsigned char AlignmentToChar( eTabType a );
72 	static eTabType		 CharToAlignment( unsigned char ch );
73 
74 	void setSaveCallback (TabSaveCallBack, void * closure);
75 
76  protected:
77 
78 	// to enable/disable a control
79 	virtual void _controlEnable( tControl id, bool value )=0;
80 
81 	// disable controls appropriately
82 	void _initEnableControls();
83 
84 	// initial population / final storage of window data
85 	void _populateWindowData(void);
86 	void _storeWindowData(void);
87 
88 	// grab tab from the current text/align/leader controls
89 	bool buildTab( UT_String & buffer );
90 
_getDimension()91 	UT_Dimension _getDimension () { return m_dim; }
92 	char *_getTabDimensionString(UT_sint32 tabIndex);
93 	char *_getTabString(fl_TabStop *pTabInfo);
94 	void _deleteTabFromTabString(fl_TabStop *pTabInfo);
95 	void _doSpin( tControl id, UT_sint32 amount);
96 
97 	// the actual access functions
98 #define SET_GATHER(a,u) virtual u _gather##a(void) = 0; \
99 					 	virtual void    _set##a( u ) = 0
100 	SET_GATHER			(Alignment,			eTabType);
101 	SET_GATHER			(Leader,			eTabLeader);
102 	SET_GATHER			(DefaultTabStop,	const gchar*);
103 
104 	// to populate the whole list
105 	virtual void _setTabList(UT_uint32 count) = 0;
106 
107 	// get/set the selected tab
108 	// the list of n tabs are index 0..(n-1)
109 	// -1 deselects everything
110 	SET_GATHER			(SelectTab,			UT_sint32);
111 
112 	// a pointer to the text in the edit box, MUST BE FREEd on get
113 	SET_GATHER			(TabEdit,			const char *);
114 #undef SET_GATHER
115 
116 	// clear all the items from the tab list - only gui side
117 	virtual void _clearList()=0;
118 
119  protected:
120 	tAnswer				m_answer;
121 	XAP_Frame *			m_pFrame;
122 	UT_Dimension		m_dim;
123 
124 	char *		m_pszTabStops;	// from rulerInfo
125 	UT_GenericVector<fl_TabStop*>	m_tabInfo;		// list of fl_TabStop *
126 
127 	// AP level handlers
128 	void _event_TabChange(void);		// when the edit box changes
129 	void _event_TabSelected( UT_sint32 index);	// when a list item is selected
130 	void _event_AlignmentChange(void);
131 
132 	void _event_Set(void);				// buttons
133 	void _event_Update(void);
134 	void _event_Clear(void);
135 	void _event_ClearAll(void);
136 
137 	void _event_somethingChanged();			// when anything changes - text, align, or leader
138 
139 private:
140 	TabSaveCallBack m_pCallbackFn;
141 	void * m_closure;
142 
143 	char buf[20];
144 
145 };
146 
147 #endif /* AP_DIALOG_PARAGRAPH_H */
148