/******************************************************************************
 JXSRTextDialogBase.h

	Interface for the JXSRTextDialogBase class

	Copyright © 1996 by John Lindal. All rights reserved.

 ******************************************************************************/

#ifndef _H_JXSRTextDialogBase
#define _H_JXSRTextDialogBase

#include <JXWindowDirector.h>
#include <JString.h>

class JString;
class JRegex;
class JXTextButton;
class JXInputField;
class JXTextCheckbox;
class JXRadioGroup;
class JXStringHistoryMenu;
class JXSRDialogUpdateTask;
class JXSRTextBase;

class JXSRTextDialogBase : public JXWindowDirector
{
public:

	JXSRTextDialogBase(JXDirector* supervisor);

	virtual ~JXSRTextDialogBase();

	virtual void		Activate();
	virtual JBoolean	Deactivate();

	JBoolean	HasSearchString() const;
	void		SetSearchString(const JCharacter* str);

	JBoolean	HasReplaceString() const;
	void		SetReplaceString(const JCharacter* str);

	JBoolean	GetSearchParameters(JString* searchStr, JBoolean* searchIsRegex,
									JBoolean* caseSensitive, JBoolean* entireWord,
									JBoolean* wrapSearch,
									JBoolean* preserveCase,
									JRegex** regex) const;

	JBoolean	GetReplaceParameters(JString* replaceStr, 
									JBoolean* replaceIsRegex) const;

	void		SetSearchObjects(JXRadioGroup* 				searchRG, 
									JXTextButton* 			closeButton,
			    					JXTextButton* 			findButton, 
			    					JXTextCheckbox* 		ignoreCaseCB,
								    JXTextCheckbox* 		wrapSearchCB, 
								    JXTextCheckbox* 		entireWordCB, 
								    JXStringHistoryMenu*	prevSearchMenu,
								    JXInputField* 			searchInput,
								    JXTextButton* 			helpButton,
								    JXTextCheckbox* 		searchIsRegexCB,
								    JXTextCheckbox* 		singleLineCB,
								    JXTextCheckbox* 		preserveCaseCB,
								    JXTextButton* 			qRefButton,
								    const JCharacter* 		regexHelpName,
								    const JCharacter* 		qRefHelpName);

	void		SetReplaceObjects(JXTextButton* 			replaceButton,
								    JXTextButton* 			replaceAllButton, 
								    JXTextButton* 			replaceFindButton,
								    JXStringHistoryMenu* 	prevReplaceMenu,
								    JXInputField* 			replaceInput,
								    JXTextCheckbox* 		replaceIsRegexCB);

	void		SetActiveTextEditor(JXSRTextBase* editor);
	JBoolean	GetActiveTextEditor(JXSRTextBase** editor);

	JBoolean	CanReplace();

	void	SetFont(const JCharacter* name, const JSize size);

	// called by JXSRDialogUpdateTask

	void	UpdateDisplay();

	// called by PrefsManager

	void	ReadSetup(istream& input);
	void	WriteSetup(ostream& output) const;

protected:

	virtual void	Receive(JBroadcaster* sender, const Message& message);

private:

	JRegex*					itsRegex;
	JXSRDialogUpdateTask*	itsUpdateTask;
	JXSRTextBase*			itsActiveTextEditor;
	JBoolean				itsCanReplace;
	JString					itsRegexHelpName;
	JString					itsRegexQRefName;

// begin JXLayout

    JXRadioGroup*        itsSearchRG;
    JXTextButton*        itsCloseButton;
    JXTextButton*        itsFindButton;
    JXTextCheckbox*      itsIgnoreCaseCB;
    JXTextCheckbox*      itsWrapSearchCB;
    JXTextButton*        itsReplaceButton;
    JXTextButton*        itsReplaceAllButton;
    JXTextButton*        itsReplaceFindButton;
    JXTextCheckbox*      itsEntireWordCB;
    JXStringHistoryMenu* itsPrevReplaceMenu;
    JXStringHistoryMenu* itsPrevSearchMenu;
    JXInputField*       itsSearchInput;
    JXInputField*       itsReplaceInput;
    JXTextButton*        itsHelpButton;
    JXTextCheckbox*      itsSearchIsRegexCB;
    JXTextCheckbox*      itsReplaceIsRegexCB;
    JXTextCheckbox*      itsSingleLineCB;
    JXTextCheckbox*      itsPreserveCaseCB;
    JXTextButton*        itsQRefButton;

// end JXLayout

private:

	// not allowed

	JXSRTextDialogBase(const JXSRTextDialogBase& source);
	const JXSRTextDialogBase& operator=(const JXSRTextDialogBase& source);
};

#endif
