1 /*
2  * Copyright 2005-2007 Gerald Schmidt.
3  *
4  * This file is part of Xml Copy Editor.
5  *
6  * Xml Copy Editor is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * Xml Copy Editor is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Xml Copy Editor; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 #ifndef STYLEDIALOG_H
22 #define STYLEDIALOG_H
23 
24 #define XHTML_START "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>XML Copy Editor report</title><meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\"/><style type=\"text/css\"><!-- body, h1, h2, h3, h4, th, td { font-family: \"Arial\", \"Helvetica\", sans-serif; } table { border-collapse: collapse; } th { text-align: left; font-size: smaller; padding-left: 5px; padding-right: 5px; } td { border-width: 1px; border-style: solid; border-color: gray; font-size: smaller; padding-left: 5px; padding-right: 5px; } --></style></head>"
25 #define XHTML_END "</html>"
26 
27 #include <wx/wx.h>
28 #include <wx/listctrl.h>
29 #include <wx/filename.h>
30 #include <iostream>
31 #include <fstream>
32 #include "housestyle.h"
33 #include "contexthandler.h"
34 #include "housestylewriter.h"
35 
36 enum
37 {
38 	ID_STYLE_TABLE = wxID_HIGHEST + 100,
39 	ID_STYLE_COMBO_RULESET,
40 	ID_STYLE_COMBO_FILTER,
41 	ID_STYLE_REPORT,
42 	ID_MENU_IGNORE_ONCE,
43 	ID_MENU_IGNORE_ALL,
44 	ID_MENU_CHANGE_ONCE,
45 	ID_MENU_CHANGE_ALL,
46 	ID_MENU_NEW_SUGGESTION,
47 	ID_MENU_APPLY_SUGGESTION_ALL,
48 	// disabled unless table contains items
49 	ID_STYLE_EDIT,
50 	ID_STYLE_WEB_REPORT,
51 	ID_STYLE_WEB_SUMMARY,
52 	ID_STYLE_IGNORE_ALL,
53 	ID_STYLE_CHANGE_ALL,
54 	ID_TYPE_SPELL,
55 	ID_TYPE_STYLE
56 };
57 
58 struct SortData
59 {
60 	int column;
61 	wxListCtrl *table;
62 };
63 
64 class StyleDialog : public wxDialog
65 {
66 	public:
67 		StyleDialog (
68 		    wxWindow *parent,
69 		    wxIcon icon,
70 		    const std::string& bufferParameterUtf8,
71 		    const wxString& fileNameParameter,
72 		    const wxString& ruleSetDirectoryParameter,
73 		    const wxString& filterDirectoryParameter,
74 		    const wxString& ruleSetPresetParameter,
75 		    const wxString& filterPresetParameter,
76   #ifdef __WXMSW__
77             const wxString& aspellDataPath,
78             const wxString& aspellDictPath,
79   #endif
80 		    int type = ID_TYPE_STYLE,
81 		    bool readOnlyParameter = false,
82 		    wxPoint position = wxDefaultPosition,
83 		    wxSize size = wxSize ( 720, 540 ) );
84 		~StyleDialog();
85 
86 		void OnColumnClick ( wxListEvent& event );
87 		void OnItemRightClick ( wxListEvent& event );
88 		void OnItemActivated ( wxListEvent& event );
89 		void OnReport ( wxCommandEvent& event );
90 		void OnStyleEdit ( wxCommandEvent& event );
91 		void OnStyleWebReport ( wxCommandEvent& event );
92 		void OnStyleWebSummary ( wxCommandEvent& event );
93 		void OnStyleChangeAll ( wxCommandEvent& event );
94 		void OnStyleIgnoreAll ( wxCommandEvent& event );
95 		void OnMenuChangeOnce ( wxCommandEvent& event );
96 		void OnMenuChangeAll ( wxCommandEvent& event );
97 		void OnMenuIgnoreOnce ( wxCommandEvent& event );
98 		void OnMenuIgnoreAll ( wxCommandEvent& event );
99 		void OnCancel ( wxCommandEvent& event );
100 		void OnMenuNewSuggestion ( wxCommandEvent& event );
101 		void OnMenuApplySuggestionAll ( wxCommandEvent& event );
102 		void OnUpdateTableRange ( wxUpdateUIEvent& event );
103 		void styleSetIgnoreAll ( bool ignore );
104 		std::string getEditedString();
getRuleSetPreset()105 		wxString getRuleSetPreset()
106 		{
107 			return ruleSetPreset;
108 		}
getFilterPreset()109 		wxString getFilterPreset()
110 		{
111 			return filterPreset;
112 		}
113 		wxPoint getPosition();
114 		wxSize getSize();
115 	private:
116 		int indexForContextMenu;
117 		wxPoint framePosition;
118 		wxSize frameSize;
119 		wxComboBox *ruleSetCombo, *filterCombo;
120 		wxListCtrl *table;
121 		wxStatusBar *status;
122 		std::string bufferUtf8;
123 		wxString aspellDataPath, aspellDictPath;
124 		std::set<wxString> tempFiles;
125 		wxString fileName, ruleSetDirectory, filterDirectory;
126 		wxString ruleSetPreset, filterPreset;
127 		vector<ContextMatch> matchVector;
128 		int type;
129 		bool readOnly;
130 		bool isIgnore ( int item );
131 		void setIgnore ( int item, bool ignore );
132 		std::string flatWhiteSpace ( std::string& s );
133 		static bool elementAndOffsetCompareFunction (
134 		    ContextMatch m1,
135 		    ContextMatch m2 );
136 		static bool reportCompareFunction ( ContextMatch m1, ContextMatch m2 );
137 
138 		static int wxCALLBACK MyCompareFunction (
139 #if wxCHECK_VERSION(2,9,0) || defined (_WIN64) || defined (__x86_64__)
140 		    wxIntPtr item1,
141 		    wxIntPtr item2,
142 		    wxIntPtr sortData );
143 #else
144 		    long item1,
145 		    long item2,
146 		    long sortData );
147 #endif
148 		void getAllMatches ( vector<ContextMatch> &v );
149 		void getSelectedMatches ( vector<ContextMatch> &v );
150 		void updateSizeInformation();
151 		static wxString getTextByColumn ( wxListCtrl *table, long index, int col );
152 		DECLARE_EVENT_TABLE()
153 };
154 
155 
156 #endif
157