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_REPLACE_H
21 #define AP_DIALOG_REPLACE_H
22 
23 #include "xap_Frame.h"
24 #include "xap_Dialog.h"
25 #include "fv_View.h"
26 #include "xav_View.h"
27 #include "pt_Types.h"
28 
29 class ABI_EXPORT AP_Dialog_Replace : public XAP_Dialog_Modeless
30 {
31 public:
32 	AP_Dialog_Replace(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id);
33 	virtual ~AP_Dialog_Replace(void);
34 
35 	//------------------------------------------------------------
36 	// All these are needed for a modeless dialog
37 
38 	virtual void     useStart(void);
39 	virtual void     useEnd(void);
40 	virtual void	 runModal(XAP_Frame * pFrame) = 0;
41 	virtual void	 runModeless(XAP_Frame * pFrame) = 0;
42         virtual void     destroy(void)=0;
43         virtual void     activate(void)=0;
44 	void		 setActiveFrame(XAP_Frame *pFrame);
45 	virtual void		notifyActiveFrame(XAP_Frame *pFrame) = 0;
46 
47 	typedef enum { find_FIND_NEXT, find_REPLACE, find_REPLACE_ALL } tFindType;
48 	typedef enum { a_VOID, a_FIND_NEXT, a_REPLACE, a_REPLACE_ALL, a_CANCEL }	tAnswer;
49         void                                       ConstructWindowName(void);
getWindowName(void)50 	char *		getWindowName(void) { return m_WindowName; };
51 
52     AP_Dialog_Replace::tAnswer	getAnswer(void) const;
53 
54 	// These are called from edit methods or from dialogs
55 	// to set or read the variables in the current
56 	// instance of the dialog.  These do not read the persistent
57 	// values.
58 	bool						setView(AV_View * view);
59 	AV_View * 					getView(void);
60 	FV_View * 					getFvView(void);
61 
62 	void						setFindString(const UT_UCSChar * string);
63 	UT_UCSChar *				getFindString(void);
64 
65 	void						setReplaceString(const UT_UCSChar * string);
66 	UT_UCSChar * 				getReplaceString(void);
67 
68 	void						setMatchCase(bool match);
69 	bool						getMatchCase(void);
70 
71 	void						setReverseFind( bool newValue);
72 	bool						getReverseFind(void);
73 
74 	void						setWholeWord( bool newValue);
75 	bool						getWholeWord(void);
76 
77 	// Action functions... set data using the accessors
78 	// above and call one of these.
79 	bool						findNext(void);
80 	bool						findPrev(void);
81 	bool						findReplaceReverse(void);
82 	bool						findReplace(void);
83 	bool 						findReplaceAll(void);
84 
85  protected:
86 
87 	// These are the "current use" dialog data items,
88 	// which are liberally read and set by the
89 	// accessor methods above.  Note that the buffers
90 	// these may point to are destroyed when useEnd()
91 	// is done storing them away
92 	FV_View * 					m_pView;
93 	UT_UCSChar *				m_findString;
94 	UT_UCSChar *				m_replaceString;
95 
96 	// Message boxes for events during search
97 	XAP_Frame *					m_pFrame;
98 
99 	void						_messageFinishedFind(void);
100 	void						_messageFinishedReplace(UT_uint32 numReplaced = 0);
101 	void 						_messageBox(const char * message);
102 
103 	// is this used in a modeless dialog like this?
104 	tAnswer						m_answer;
105 	char						m_WindowName[100];
106 
107 	// save a list of find a replace texts
108 	UT_GenericVector<UT_UCS4Char*>	m_findList;
109 	UT_GenericVector<UT_UCS4Char*>	m_replaceList;
110 	virtual void				_updateLists() = 0; // must be implemented in non-xp code
111 
112  private:
113 	// returns true when the internal list was changed
114 	bool						_manageList(UT_GenericVector<UT_UCS4Char*>* list, UT_UCSChar* string);
115 };
116 
117 #endif /* AP_DIALOG_REPLACE_H */
118