1 /* AbiWord
2  * Copyright (C) 2003 Dom Lachowicz
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_STYLIST_H
21 #define AP_DIALOG_STYLIST_H
22 
23 #include "ut_types.h"
24 #include "xap_Frame.h"
25 #include "xap_Dialog.h"
26 #include "xav_View.h"
27 #include "ut_vector.h"
28 #include "ut_string_class.h"
29 
30 class UT_Timer;
31 class XAP_Frame;
32 class PD_Document;
33 class PD_Style;
34 
35 class ABI_EXPORT Stylist_row
36 {
37 public:
38 	Stylist_row(void);
39 	virtual ~Stylist_row(void);
40 	void       addStyle(const std::string & sStyle);
41 	void       setRowName(const std::string & sRowname);
42 	void       getRowName(std::string & sRowname) const;
43 	UT_sint32  getNumCols(void) const;
44 	bool       findStyle(UT_UTF8String & sStyleName, UT_sint32 & col);
45 	bool       getStyle(UT_UTF8String & sStyleName, UT_sint32 col);
46 private:
47 	UT_GenericVector<UT_UTF8String *> m_vecStyles;
48 	std::string  m_sRowName;
49 };
50 
51 class ABI_EXPORT Stylist_tree
52 {
53 public:
54 	Stylist_tree(PD_Document * pDoc);
55 	virtual ~Stylist_tree(void);
56 	bool             findStyle(UT_UTF8String & sStyleName,UT_sint32 & row, UT_sint32 & col);
57 	bool             getStyleAtRowCol(UT_UTF8String & sStyle, UT_sint32 row, UT_sint32 col);
58 	UT_sint32        getNumRows(void) const;
59 	UT_sint32        getNumCols(UT_sint32 row) const;
60 	void             buildStyles(PD_Document * pDoc);
61 	UT_sint32        getNumStyles(void) const;
62 	bool             getNameOfRow(std::string &sName, UT_sint32 row) const;
63 	bool             isHeading(const PD_Style * pStyle, UT_sint32 iDepth=10) const;
64 	bool             isList(const PD_Style * pStyle, UT_sint32 iDepth=10) const;
65 	bool             isFootnote(const PD_Style * pStyle,UT_sint32 iDepth=10) const;
66 	bool             isUser(const PD_Style *pStyle) const;
67 private:
68 	UT_GenericVector<const PD_Style *>    m_vecAllStyles;
69 	UT_GenericVector<Stylist_row *> m_vecStyleRows;
70 };
71 
72 
73 class ABI_EXPORT AP_Dialog_Stylist : public XAP_Dialog_Modeless
74 {
75 public:
76 	AP_Dialog_Stylist(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id);
77 	virtual ~AP_Dialog_Stylist(void);
78 
79 	virtual void runModeless(XAP_Frame * pFrame) = 0;
80 	virtual void runModal(XAP_Frame * pFrame) = 0;
81 
isStyleValid(void)82 	bool              isStyleValid(void)
83 		{ return  m_bStyleValid;}
84 	void              startUpdater(void);
85 	void              stopUpdater(void);
86 	// I am gonna be nice and make this an empty implementation instead of pure virtual
setSensitivity(bool)87 	virtual void      setSensitivity(bool /*bSens*/) {};
88     void              setActiveFrame(XAP_Frame *pFrame);
89 	void              event_update(void);
90 	void              finalize(void);
getStyleTree(void)91 	Stylist_tree *  getStyleTree(void) const
92 		{ return m_pStyleTree;}
getCurStyle(void)93 	const UT_UTF8String *   getCurStyle(void) const
94 		{ return &m_sCurStyle;}
getSelectedStyle(void)95 	UT_UTF8String     getSelectedStyle(void) const
96 		{ return m_sCurStyle;}
setCurStyle(UT_UTF8String & sStyle)97 	void              setCurStyle(UT_UTF8String & sStyle)
98 		{ m_sCurStyle = sStyle;}
99 	void              Apply(void);
100 	virtual void      setStyleInGUI(void) = 0;
101 	static void       autoUpdate(UT_Worker * pTimer);
102 	void              updateDialog(void);
isStyleChanged(void)103 	bool              isStyleChanged(void) const
104 		{ return m_bStyleChanged;}
isStyleTreeChanged(void)105 	bool              isStyleTreeChanged(void) const
106 		{ return m_bStyleTreeChanged;}
107 	UT_sint32         getNumStyles(void) const;
setStyleTreeChanged(bool b)108 	void              setStyleTreeChanged(bool b)
109 		{ m_bStyleTreeChanged = b;}
setStyleChanged(bool b)110 	void              setStyleChanged(bool b)
111 		{ m_bStyleChanged = b;}
setStyleValid(bool bValid)112 	void              setStyleValid(bool bValid)
113 		{ m_bStyleValid = bValid;}
114 protected:
115 	// call to ensure the dialog is enabled/disabled on overall
116 	void setAllSensitivities();
117 	bool                  m_bIsModal;
118 private:
119 	PD_Document *         m_pDoc;
120 	UT_Timer *            m_pAutoUpdater;
121 	UT_uint32             m_iTick;
122 	UT_UTF8String         m_sCurStyle;
123 	Stylist_tree *        m_pStyleTree;
124 	bool                  m_bStyleTreeChanged;
125 	bool                  m_bStyleChanged;
126 	bool                  m_bStyleValid;
127 };
128 
129 #endif /* AP_DIALOG_STYLIST_H */
130