changes to traydict

Originally committed to SVN as r1639.
This commit is contained in:
Rodrigo Braz Monteiro 2007-10-29 17:43:42 +00:00
parent c22c36c687
commit 67b15eacd4
15 changed files with 362 additions and 107 deletions

View File

@ -45,11 +45,13 @@
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdwx.h"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DisableSpecificWarnings="4996"
ForcedIncludeFiles="stdwx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@ -123,11 +125,13 @@
AdditionalIncludeDirectories="D:\wxWidgets-2.8.6\lib\vc_lib\mswu"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdwx.h"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DisableSpecificWarnings="4996"
ForcedIncludeFiles="stdwx.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@ -178,6 +182,9 @@
<References>
</References>
<Files>
<Filter
Name="Dialogs"
>
<File
RelativePath=".\dict_window.cpp"
>
@ -186,22 +193,10 @@
RelativePath=".\dict_window.h"
>
</File>
<File
RelativePath=".\dictionary.cpp"
</Filter>
<Filter
Name="Core"
>
</File>
<File
RelativePath=".\dictionary.h"
>
</File>
<File
RelativePath=".\kana_table.cpp"
>
</File>
<File
RelativePath=".\kana_table.h"
>
</File>
<File
RelativePath=".\main.cpp"
>
@ -214,6 +209,22 @@
RelativePath=".\res.rc"
>
</File>
<File
RelativePath=".\stdwx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\stdwx.h"
>
</File>
<File
RelativePath=".\systray.cpp"
>
@ -222,6 +233,18 @@
RelativePath=".\systray.h"
>
</File>
</Filter>
<Filter
Name="Utils"
>
<File
RelativePath=".\kana_table.cpp"
>
</File>
<File
RelativePath=".\kana_table.h"
>
</File>
<File
RelativePath="..\aegisub\text_file_reader.cpp"
>
@ -246,6 +269,27 @@
RelativePath="..\aegisub\text_file_reader.h"
>
</File>
</Filter>
<Filter
Name="Dictionary"
>
<File
RelativePath=".\dictionary.cpp"
>
</File>
<File
RelativePath=".\dictionary.h"
>
</File>
<File
RelativePath=".\dictionary_display.cpp"
>
</File>
<File
RelativePath=".\dictionary_display.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
@ -41,6 +41,7 @@
#include "dict_window.h"
#include "systray.h"
#include "dictionary.h"
#include "dictionary_display.h"
#include "main.h"
@ -120,7 +121,7 @@ DictWindow::DictWindow()
searchPane.CloseButton(false);
// Results
results = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(280,400),wxTE_RICH2 | wxTE_MULTILINE | wxTE_DONTWRAP | wxTE_READONLY);
results = new DictionaryDisplay(this);
manager->AddPane(results,wxCENTER,_("Results"));
manager->Update();
@ -207,7 +208,7 @@ void DictWindow::Search(wxString text) {
int bitmask = (checkKanji->GetValue() ? 1 : 0) | (checkKana->GetValue() ? 2 : 0) | (checkRomaji->GetValue() ? 4 : 0) | (checkEnglish->GetValue() ? 8 : 0);
// Clear text
results->Clear();
results->ResultsStart();
entry->SetSelection(0,entry->GetValue().Length());
// Search each dictionary
@ -217,17 +218,16 @@ void DictWindow::Search(wxString text) {
ResultSet res;
dict[i]->Search(res,text);
// Sort results by relevancy
// Sort results by relevance
res.results.sort();
// Print
res.Print(results,bitmask);
results->Print(res);
}
}
// Show start
results->ShowPosition(0);
results->SetSelection(0,0);
// Done
results->ResultsDone();
}

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
@ -44,6 +44,7 @@
// Prototypes
class Systray;
class Dictionary;
class DictionaryDisplay;
//////////////////////////
@ -51,7 +52,7 @@ class Dictionary;
class DictWindow : public wxFrame {
private:
wxMenuBar *menu;
wxTextCtrl *results;
DictionaryDisplay *results;
Systray *systray;
std::vector<Dictionary*> dict;

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
@ -251,13 +251,13 @@ void Dictionary::Search(ResultSet &results,wxString query) {
// Matches kanji?
if (cur->kanji.Contains(query)) {
addThis = true;
rel = GetRelevancy(query,cur->kanji,cur->english.Contains(_T("(P)")));
rel = GetRelevance(query,cur->kanji,cur->english.Contains(_T("(P)")));
}
// Matches kana?
else if (cur->kana.Contains(query)) {
addThis = true;
rel = GetRelevancy(query,cur->kana,cur->english.Contains(_T("(P)")));
rel = GetRelevance(query,cur->kana,cur->english.Contains(_T("(P)")));
}
}
@ -269,20 +269,20 @@ void Dictionary::Search(ResultSet &results,wxString query) {
// Matches english?
if (cur->english.Lower().Contains(lowQuery)) {
addThis = true;
rel = GetRelevancy(lowQuery,cur->english,cur->english.Contains(_T("(P)")),true);
rel = GetRelevance(lowQuery,cur->english,cur->english.Contains(_T("(P)")),true);
}
// Matches wapuro romaji?
if (cur->romaji.Contains(lowQuery)) {
addThis = true;
rel = GetRelevancy(lowQuery,cur->romaji,cur->english.Contains(_T("(P)")));
rel = GetRelevance(lowQuery,cur->romaji,cur->english.Contains(_T("(P)")));
}
}
// Add entry
if (addThis) {
SearchResult res;
res.relevancy = rel;
res.relevance = rel;
res.entry = cur;
results.results.push_back(res);
cur = NULL;
@ -302,7 +302,7 @@ void Dictionary::Search(ResultSet &results,wxString query) {
/////////////////
// Get relevancy
int Dictionary::GetRelevancy(wxString substr,wxString _str,bool isPop,bool english) {
int Dictionary::GetRelevance(wxString substr,wxString _str,bool isPop,bool english) {
// Best score
int bestScore = 0;
@ -384,7 +384,7 @@ int Dictionary::GetRelevancy(wxString substr,wxString _str,bool isPop,bool engli
//////////////////////////
// Comparison for sorting
bool operator < (const SearchResult &a,const SearchResult &b) {
return (a.relevancy > b.relevancy);
return (a.relevance > b.relevance);
}
@ -418,6 +418,7 @@ ResultSet::~ResultSet() {
///////////////////
// Print resultset
/*
void ResultSet::Print(wxTextCtrl *target,int bitmask) {
// Get options
bool drawKanji = (bitmask & 1) != 0;
@ -585,3 +586,4 @@ void ResultSet::Print(wxTextCtrl *target,int bitmask) {
// Print two carriage returns
target->AppendText(_T("\n\n"));
}
*/

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,13 +27,16 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include <list>
@ -58,7 +61,7 @@ public:
class SearchResult {
public:
DictEntry *entry;
int relevancy;
int relevance;
};
bool operator < (const SearchResult &a,const SearchResult &b);
@ -71,7 +74,6 @@ public:
wxString dicName;
std::list<SearchResult> results;
void Print(wxTextCtrl *target,int bitmask);
bool ownData;
int time;
@ -95,7 +97,7 @@ public:
void Load(wxString filename);
void Search(ResultSet &results,wxString query);
int GetRelevancy(wxString substr,wxString str,bool isPop,bool english=false);
int GetRelevance(wxString substr,wxString str,bool isPop,bool english=false);
Dictionary(wxString name,wxCheckBox *check);
~Dictionary();

View File

@ -0,0 +1,111 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/html/htmlwin.h>
#include "dictionary_display.h"
#include "main.h"
#include "../aegisub/text_file_reader.h"
///////////////
// Constructor
DictionaryDisplay::DictionaryDisplay(wxWindow *parent)
: wxHtmlWindow(parent,-1)
{
SetBorders(0);
}
/////////////////
// Print results
void DictionaryDisplay::Print(const ResultSet &results)
{
// Clear page
SetPage(_T(""));
// Colours
wchar_t col[][8] = {L"#FFFFFF",L"#FEFAED"};
// Go through each result
AppendToPage(_T("<table cellpadding='2' cellspacing='0' border='0'>"));
int i = 0;
for (std::list<SearchResult>::const_iterator cur=results.results.begin();cur!=results.results.end();cur++) {
// Get entry
DictEntry *entry = (*cur).entry;
// Generate row string
wxString row = wxString::Format(_T("<tr bgcolor='%s'>"),col[(i/3) % 2]);
row += _T("<td>") + entry->kanji + _T("</td>");
row += _T("<td>") + entry->kana + _T(" </td>");
row += _T("<td>") + Dictionary::kanatable.KanaToRomaji(entry->kana) + _T(" </td>");
row += _T("<td>") + entry->english + _T("</td>");
row += _T("</tr>");
// Append string to page
AppendToPage(row);
i++;
}
AppendToPage(_T("</table>"));
}
/////////////////
// Start results
void DictionaryDisplay::ResultsStart()
{
Freeze();
// Get stylesheet path
wxString stylesheet;
TextFileReader styleFile(TrayDict::folderName + _T("traydict.css"));
while (styleFile.HasMoreLines()) {
stylesheet += styleFile.ReadLineFromFile() + _T("\n");
}
// Insert header
AppendToPage(wxString::Format(_T("<html><head><style>%s</style></head><body>"),stylesheet.c_str()));
}
/////////////////////////
// Done printing results
void DictionaryDisplay::ResultsDone()
{
AppendToPage(_T("</body></html>"));
HistoryClear();
Thaw();
}

View File

@ -0,0 +1,53 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include <wx/html/htmlwin.h>
#include "dictionary.h"
///////////////////////////////////
// Dictionary result display class
class DictionaryDisplay : public wxHtmlWindow {
public:
DictionaryDisplay(wxWindow *parent);
void Print(const ResultSet &results);
void ResultsStart();
void ResultsDone();
};

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
@ -396,14 +396,22 @@ wxString KanaTable::KanaToRomaji(wxString kana,int type) {
// Check if it needs to add a macron
wxString last = lastSyl.Right(1);
wxString curV = cur->hepburn;
if ((last == _T("o") && curV == _T("u")) || (last == curV && last != lastSyl && last != _T("n"))) {
final += 0x304;
if ((last == _T("o") && curV == _T("u")) || (last == curV && last != _T("n") /*&& last != lastSyl */)) {
wchar_t macron;
switch(last[0]) {
case L'a': macron = 257; break;
case L'e': macron = 275; break;
case L'i': macron = 299; break;
case L'o': macron = 333; break;
case L'u': macron = 363; break;
}
final = final.Left(final.Length()-1) + macron;
vetoAdd = true;
}
}
}
// Wapura
// Wopura
else {
if (longVowel) {
longVowel = false;

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,13 +27,16 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include <vector>

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
@ -66,6 +66,7 @@ IMPLEMENT_APP(TrayDict)
#pragma comment(lib, "wxmsw28ud_core.lib")
#pragma comment(lib, "wxmsw28ud_adv.lib")
#pragma comment(lib, "wxmsw28ud_aui.lib")
#pragma comment(lib, "wxmsw28ud_html.lib")
#pragma comment(lib, "wxbase28ud_xml.lib")
#pragma comment(lib, "wxexpatd.lib")
#else
@ -76,6 +77,7 @@ IMPLEMENT_APP(TrayDict)
#pragma comment(lib, "wxmsw28u_core.lib")
#pragma comment(lib, "wxmsw28u_adv.lib")
#pragma comment(lib, "wxmsw28u_aui.lib")
#pragma comment(lib, "wxmsw28u_html.lib")
#pragma comment(lib, "wxbase28u_xml.lib")
#pragma comment(lib, "wxexpat.lib")
#endif

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com

1
traydict/stdwx.cpp Normal file
View File

@ -0,0 +1 @@
#include "stdwx.h"

28
traydict/stdwx.h Normal file
View File

@ -0,0 +1,28 @@
// Precompiled header file
#include <wx/wxprec.h>
#include <wx/notebook.h>
#include <wx/statline.h>
#include <wx/tglbtn.h>
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <wx/filename.h>
#include <wx/sashwin.h>
#include <wx/file.h>
#include <wx/filedlg.h>
#include <wx/grid.h>
#include <wx/fontdlg.h>
#include <wx/clipbrd.h>
#include <wx/msgdlg.h>
#include <wx/stackwalk.h>
#include <wx/spinctrl.h>
#include <wx/wfstream.h>
#include <wx/tipdlg.h>
#include <wx/event.h>
#include <wx/string.h>
#include <wx/aui/aui.h>
#include <wx/html/htmlwin.h>
#include <vector>
#include <list>
#include <map>

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com

View File

@ -9,7 +9,7 @@
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// * Neither the name of the TrayDict Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
@ -27,7 +27,7 @@
//
// -----------------------------------------------------------------------------
//
// AEGISUB
// TRAYDICT
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com