From 4a2c0dbbfad529e30c1cd54a14ea3c774a9cdc8c Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Thu, 29 Jun 2006 23:14:54 +0000 Subject: [PATCH] Added the kanamemo & traydict side projects to repository Originally committed to SVN as r436. --- kanamemo/game_display.cpp | Bin 0 -> 29394 bytes kanamemo/game_display.h | 100 ++++++ kanamemo/game_panel.cpp | 109 +++++++ kanamemo/game_panel.h | 72 +++++ kanamemo/game_window.cpp | 166 ++++++++++ kanamemo/game_window.h | 86 +++++ kanamemo/icon.ico | Bin 0 -> 15014 bytes kanamemo/kana_table.cpp | 294 +++++++++++++++++ kanamemo/kana_table.h | 80 +++++ kanamemo/level.cpp | 117 +++++++ kanamemo/level.h | 65 ++++ kanamemo/main.cpp | 115 +++++++ kanamemo/main.h | 47 +++ kanamemo/res.rc | 3 + kanamemo/switch_user.cpp | 178 +++++++++++ kanamemo/switch_user.h | 71 ++++ kanamemo/version.cpp | 51 +++ kanamemo/version.h | 44 +++ traydict/dict_window.cpp | 228 +++++++++++++ traydict/dict_window.h | 95 ++++++ traydict/dictionary.cpp | 587 ++++++++++++++++++++++++++++++++++ traydict/dictionary.h | 102 ++++++ traydict/icon.ico | Bin 0 -> 7406 bytes traydict/kana_table.cpp | 432 +++++++++++++++++++++++++ traydict/kana_table.h | 83 +++++ traydict/main.cpp | 115 +++++++ traydict/main.h | 47 +++ traydict/res.rc | 3 + traydict/systray.cpp | 110 +++++++ traydict/systray.h | 68 ++++ traydict/text_file_reader.cpp | 238 ++++++++++++++ traydict/text_file_reader.h | 77 +++++ 32 files changed, 3783 insertions(+) create mode 100644 kanamemo/game_display.cpp create mode 100644 kanamemo/game_display.h create mode 100644 kanamemo/game_panel.cpp create mode 100644 kanamemo/game_panel.h create mode 100644 kanamemo/game_window.cpp create mode 100644 kanamemo/game_window.h create mode 100644 kanamemo/icon.ico create mode 100644 kanamemo/kana_table.cpp create mode 100644 kanamemo/kana_table.h create mode 100644 kanamemo/level.cpp create mode 100644 kanamemo/level.h create mode 100644 kanamemo/main.cpp create mode 100644 kanamemo/main.h create mode 100644 kanamemo/res.rc create mode 100644 kanamemo/switch_user.cpp create mode 100644 kanamemo/switch_user.h create mode 100644 kanamemo/version.cpp create mode 100644 kanamemo/version.h create mode 100644 traydict/dict_window.cpp create mode 100644 traydict/dict_window.h create mode 100644 traydict/dictionary.cpp create mode 100644 traydict/dictionary.h create mode 100644 traydict/icon.ico create mode 100644 traydict/kana_table.cpp create mode 100644 traydict/kana_table.h create mode 100644 traydict/main.cpp create mode 100644 traydict/main.h create mode 100644 traydict/res.rc create mode 100644 traydict/systray.cpp create mode 100644 traydict/systray.h create mode 100644 traydict/text_file_reader.cpp create mode 100644 traydict/text_file_reader.h diff --git a/kanamemo/game_display.cpp b/kanamemo/game_display.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3aad1e25ade8b88c921a1c3fcde355530dc841d9 GIT binary patch literal 29394 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 ULAmbE{WU?Rk6OQ1%CY9Z0Vz_+D*ylh literal 0 HcmV?d00001 diff --git a/kanamemo/game_display.h b/kanamemo/game_display.h new file mode 100644 index 000000000..2c6cdbcfd --- /dev/null +++ b/kanamemo/game_display.h @@ -0,0 +1,100 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include + + +////////////// +// Prototypes +class KanaTable; +class KanaEntry; +class SwitchUserDialog; +class GamePanel; + + +////////////////////// +// Game display class +class GameDisplay : public wxWindow { + friend class SwitchUserDialog; + +private: + wxStatusBar *statusBar; + const KanaEntry *current; + const KanaEntry *previous; + int curn; + int curTable; + int lastTable; + std::vector scores[2]; + bool enabled[2]; + wxMenuItem *menuCheck[2]; + int status; + int levelUp; + wxString lastEntry; + + wxString playerName; + + void OnPaint(wxPaintEvent &event); + void OnClick(wxMouseEvent &event); + + void Reset(); + int GetNAtLevel(int level,int table); + void UpdateStatusBar(); + +public: + bool autoLevel; + bool isOn; + int level[2]; + KanaTable *table; + GamePanel *panel; + + GameDisplay(wxWindow *parent); + ~GameDisplay(); + + void ResetTable(int id); + void GetNextKana(); + void EnterRomaji(wxString romaji); + void EnableTable(int table,bool enable); + void SetLevel(int table,int level); + void EnableGame(bool enable); + + void Save(); + void Load(); + + DECLARE_EVENT_TABLE(); +}; diff --git a/kanamemo/game_panel.cpp b/kanamemo/game_panel.cpp new file mode 100644 index 000000000..8dfc80e60 --- /dev/null +++ b/kanamemo/game_panel.cpp @@ -0,0 +1,109 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "game_panel.h" +#include "game_display.h" + + +/////////////// +// Constructor +GamePanel::GamePanel(wxWindow *parent,GameDisplay *dsp) +: wxPanel (parent,-1,wxDefaultPosition,wxDefaultSize,wxRAISED_BORDER) +{ + // Set display + display = dsp; + + // Controls + enterField = new wxTextCtrl(this,Enter_Box,_T(""),wxDefaultPosition,wxSize(50,-1),wxTE_PROCESS_ENTER); + enterField->SetMaxLength(3); + enterField->SetToolTip(_T("Enter the hepburn romaji for the kana you see here and press the Enter key or the enter button to accept. Type '?' for the answer.")); + wxButton *enterButton = new wxButton(this,Enter_Button,_T("Enter"),wxDefaultPosition,wxSize(60,-1)); + enterButton->SetToolTip(_T("Enter text. (Pressing the enter key on the keyboard will also work)")); + wxButton *questionButton = new wxButton(this,Question_Button,_T("?"),wxDefaultPosition,wxSize(30,-1)); + questionButton->SetToolTip(_T("Shows the correct hepburn romaji for the shown kana.")); + + // Sizers + wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); + wxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL); + topSizer->AddStretchSpacer(1); + topSizer->Add(new wxStaticText(this,-1,_T("Enter hepburn romaji:")),0,wxALIGN_CENTER | wxRIGHT,8); + topSizer->Add(enterField,0,wxALIGN_CENTER | wxRIGHT,2); + topSizer->Add(enterButton,0,0,0); + topSizer->Add(questionButton,0,0,0); + topSizer->AddStretchSpacer(1); + mainSizer->Add(topSizer,1,wxEXPAND,0); + mainSizer->Add(new wxStaticText(this,-1,_T("Copyright © 2006 - Rodrigo Braz Monteiro. All rights reserved.")),0,wxALIGN_CENTER | wxALL,5); + mainSizer->SetSizeHints(this); + SetSizer(mainSizer); +} + + +////////////// +// Destructor +GamePanel::~GamePanel() { +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(GamePanel,wxPanel) + EVT_BUTTON(Enter_Button,OnEnterPress) + EVT_BUTTON(Question_Button,OnQuestionPress) + EVT_TEXT_ENTER(Enter_Box,OnEnterPress) +END_EVENT_TABLE() + + +///////////////// +// Enter pressed +void GamePanel::OnEnterPress(wxCommandEvent &event) { + wxString value = enterField->GetValue(); + if (!value.IsEmpty()) { + display->EnterRomaji(value); + enterField->Clear(); + } + enterField->SetFocus(); +} + + +//////////////////// +// Question pressed +void GamePanel::OnQuestionPress(wxCommandEvent &event) { + display->EnterRomaji(_T("?")); + enterField->Clear(); + enterField->SetFocus(); +} diff --git a/kanamemo/game_panel.h b/kanamemo/game_panel.h new file mode 100644 index 000000000..e16a21edb --- /dev/null +++ b/kanamemo/game_panel.h @@ -0,0 +1,72 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +////////////// +// Prototypes +class GameDisplay; + + +/////////////// +// Panel class +class GamePanel : public wxPanel { +private: + GameDisplay *display; + + void OnEnterPress(wxCommandEvent &event); + void OnQuestionPress(wxCommandEvent &event); + +public: + wxTextCtrl *enterField; + + GamePanel(wxWindow *parent,GameDisplay *dsp); + ~GamePanel(); + + DECLARE_EVENT_TABLE(); +}; + + +/////// +// IDs +enum { + Enter_Box = 2500, + Enter_Button, + Question_Button +}; diff --git a/kanamemo/game_window.cpp b/kanamemo/game_window.cpp new file mode 100644 index 000000000..6af61816e --- /dev/null +++ b/kanamemo/game_window.cpp @@ -0,0 +1,166 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "game_window.h" +#include "game_display.h" +#include "game_panel.h" +#include "version.h" +#include "level.h" +#include "switch_user.h" + + +/////////////// +// Constructor +GameWindow::GameWindow() +: GameWindowBase(NULL,-1,GetVersionString(),wxDefaultPosition,wxDefaultSize,wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN) +{ + // Menu bar + menu = new wxMenuBar(); + SetMenuBar(menu); + SetIcon(wxICON(wxicon)); + + // File menu + wxMenu *fileMenu = new wxMenu; + //fileMenu->Append(Menu_File_New,_T("&New Player"),_T("")); + fileMenu->Append(Menu_File_Load,_T("&Switch User..."),_T("")); + fileMenu->Append(Menu_File_Exit,_T("E&xit"),_T("")); + menu->Append(fileMenu,_T("&File")); + + // Options menu + wxMenu *optionsMenu = new wxMenu; + optionsMenu->Append(Menu_Options_Hiragana,_T("Hiragana"),_T(""),wxITEM_CHECK); + optionsMenu->Append(Menu_Options_Katakana,_T("Katakana"),_T(""),wxITEM_CHECK); + optionsMenu->Append(Menu_Options_Level,_T("Set Level..."),_T("")); + menu->Append(optionsMenu,_T("&Options")); + + // Status bar + wxStatusBar *bar = CreateStatusBar(3,0); + int widths[] = { 85, -1, -1 }; + bar->SetStatusWidths(3,widths); + + // Subwindows + display = new GameDisplay(this); + panel = new GamePanel(this,display); + display->panel = panel; + + // Sizer + wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); + mainSizer->Add(display,1,wxEXPAND,0); + mainSizer->Add(panel,0,wxEXPAND,0); + mainSizer->SetSizeHints(this); + SetSizer(mainSizer); + + // Prompt user for name + Show(); + SwitchUserDialog user(display); + user.ShowModal(); + if (!display->isOn) Destroy(); +} + + +////////////// +// Destructor +GameWindow::~GameWindow() { +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(GameWindow,GameWindowBase) + EVT_CLOSE(GameWindow::OnClose) + EVT_MENU(Menu_File_Exit,GameWindow::OnFileExit) + EVT_MENU(Menu_File_New,GameWindow::OnFileNew) + EVT_MENU(Menu_File_Load,GameWindow::OnFileLoad) + EVT_MENU(Menu_Options_Hiragana,GameWindow::OnOptionsHiragana) + EVT_MENU(Menu_Options_Katakana,GameWindow::OnOptionsKatakana) + EVT_MENU(Menu_Options_Level,GameWindow::OnOptionsLevel) +END_EVENT_TABLE() + + +/////////////// +// Close event +void GameWindow::OnClose(wxCloseEvent &event) { + Destroy(); +} + + +//////// +// Exit +void GameWindow::OnFileExit(wxCommandEvent &event) { + Close(); +} + + +////////////// +// New player +void GameWindow::OnFileNew(wxCommandEvent &event) { +} + + +/////////////// +// Load player +void GameWindow::OnFileLoad(wxCommandEvent &event) { + display->Save(); + SwitchUserDialog user(display); + user.ShowModal(); +} + + +/////////////////// +// Toggle hiragana +void GameWindow::OnOptionsHiragana(wxCommandEvent &event) { + display->EnableTable(0,event.IsChecked()); + display->Save(); +} + + +/////////////////// +// Toggle katakana +void GameWindow::OnOptionsKatakana(wxCommandEvent &event) { + display->EnableTable(1,event.IsChecked()); + display->Save(); +} + + +//////////////////// +// Difficulty Level +void GameWindow::OnOptionsLevel(wxCommandEvent &event) { + LevelWindow level(this,display); + level.ShowModal(); + display->Save(); +} diff --git a/kanamemo/game_window.h b/kanamemo/game_window.h new file mode 100644 index 000000000..d28f7e338 --- /dev/null +++ b/kanamemo/game_window.h @@ -0,0 +1,86 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +////////////// +// Prototypes +class GameDisplay; +class GamePanel; + + +/////////// +// Typedef +typedef wxFrame GameWindowBase; + + +///////////////////// +// Game window class +class GameWindow : public GameWindowBase { +private: + GameDisplay *display; + GamePanel *panel; + wxMenuBar *menu; + + void OnClose(wxCloseEvent &event); + void OnFileExit(wxCommandEvent &event); + void OnFileNew(wxCommandEvent &event); + void OnFileLoad(wxCommandEvent &event); + void OnOptionsHiragana(wxCommandEvent &event); + void OnOptionsKatakana(wxCommandEvent &event); + void OnOptionsLevel(wxCommandEvent &event); + +public: + GameWindow(); + ~GameWindow(); + + DECLARE_EVENT_TABLE(); +}; + + +//////////////////// +// Menu identifiers +enum { + Menu_File_Exit = 2000, + Menu_File_New, + Menu_File_Load, + Menu_Options_Hiragana, + Menu_Options_Katakana, + Menu_Options_Level +}; diff --git a/kanamemo/icon.ico b/kanamemo/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..7b70e91f81af4754c04d88d0613e0d9438beb330 GIT binary patch literal 15014 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 NzkQ-z)$y13`hOA64aWcg literal 0 HcmV?d00001 diff --git a/kanamemo/kana_table.cpp b/kanamemo/kana_table.cpp new file mode 100644 index 000000000..e74dc66ae --- /dev/null +++ b/kanamemo/kana_table.cpp @@ -0,0 +1,294 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "kana_table.h" + + +/////////////// +// Constructor +KanaTable::KanaTable() { + level = 0; + groups[0] = 0; + groups[1] = 0; + + BeginGroup(); + Insert(L"あ",L"ケ",L"a"); + Insert(L"い",L"ă‚€",L"i"); + Insert(L"う",L"ォ",L"u"); + Insert(L"え",L"ス",L"e"); + Insert(L"お",L"ă‚Ș",L"o"); + + BeginGroup(); + Insert(L"か",L"ă‚«",L"ka"); + Insert(L"き",L"キ",L"ki"); + Insert(L"く",L"ク",L"ku"); + Insert(L"け",L"ケ",L"ke"); + Insert(L"こ",L"コ",L"ko"); + + BeginGroup(); + Insert(L"さ",L"ă‚”",L"sa"); + Insert(L"し",L"ă‚·",L"shi"); + Insert(L"す",L"ă‚č",L"su"); + Insert(L"せ",L"ă‚»",L"se"); + Insert(L"そ",L"ă‚œ",L"so"); + + BeginGroup(); + Insert(L"た",L"タ",L"ta"); + Insert(L"づ",L"チ",L"chi"); + Insert(L"぀",L"ツ",L"tsu"); + Insert(L"お",L"テ",L"te"); + Insert(L"ず",L"ト",L"to"); + + BeginGroup(); + Insert(L"ăȘ",L"ナ",L"na"); + Insert(L"に",L"ニ",L"ni"); + Insert(L"く",L"ヌ",L"nu"); + Insert(L"ね",L"ネ",L"ne"); + Insert(L"た",L"ノ",L"no"); + + BeginGroup(); + Insert(L"は",L"ハ",L"ha"); + Insert(L"ăČ",L"ヒ",L"hi"); + Insert(L"ご",L"フ",L"fu"); + Insert(L"ぞ",L"ヘ",L"he"); + Insert(L"ほ",L"ホ",L"ho"); + + BeginGroup(); + Insert(L"ăŸ",L"マ",L"ma"); + Insert(L"み",L"ミ",L"mi"); + Insert(L"む",L"ム",L"mu"); + Insert(L"め",L"ュ",L"me"); + Insert(L"も",L"ヹ",L"mo"); + + BeginGroup(); + Insert(L"や",L"ダ",L"ya"); + Insert(L"ゆ",L"ナ",L"yu"); + Insert(L"よ",L"ペ",L"yo"); + + BeginGroup(); + Insert(L"ら",L"ラ",L"ra"); + Insert(L"り",L"ăƒȘ",L"ri"); + Insert(L"る",L"ル",L"ru"); + Insert(L"れ",L"ハ",L"re"); + Insert(L"ろ",L"ロ",L"ro"); + + BeginGroup(); + Insert(L"わ",L"ワ",L"wa"); + Insert(L"を",L"ăƒČ",L"wo"); + + BeginGroup(); + level--; + Insert(L"ん",L"ン",L"n"); + + BeginGroup(); + Insert(L"が",L"ガ",L"ga"); + Insert(L"ぎ",L"ゼ",L"gi"); + Insert(L"ぐ",L"グ",L"gu"); + Insert(L"げ",L"ă‚Č",L"ge"); + Insert(L"ご",L"ギ",L"go"); + + BeginGroup(); + Insert(L"ざ",L"ザ",L"za"); + Insert(L"じ",L"ゾ",L"ji"); + Insert(L"ず",L"ă‚ș",L"zu"); + Insert(L"ぜ",L"ă‚Œ",L"ze"); + Insert(L"ぞ",L"ă‚Ÿ",L"zo"); + + BeginGroup(); + Insert(L"だ",L"ダ",L"da"); + Insert(L"べ",L"ヂ",L"ji"); + Insert(L"い",L"ヅ",L"zu"); + Insert(L"で",L"デ",L"de"); + Insert(L"ど",L"ド",L"do"); + + BeginGroup(); + Insert(L"ば",L"バ",L"ba"); + Insert(L"び",L"ビ",L"bi"); + Insert(L"ぶ",L"ブ",L"bu"); + Insert(L"ăč",L"ベ",L"be"); + Insert(L"ăŒ",L"ボ",L"bo"); + + BeginGroup(); + Insert(L"ぱ",L"パ",L"pa"); + Insert(L"ぎ",L"ピ",L"pi"); + Insert(L"ぷ",L"プ",L"pu"); + Insert(L"ăș",L"ペ",L"pe"); + Insert(L"ăœ",L"ポ",L"po"); + + BeginGroup(); + Insert(L"きゃ",L"キャ",L"kya"); + Insert(L"きゅ",L"ă‚­ăƒ„",L"kyu"); + Insert(L"きょ",L"キョ",L"kyo"); + + BeginGroup(); + Insert(L"しゃ",L"ă‚·ăƒŁ",L"sha"); + Insert(L"しゅ",L"ă‚·ăƒ„",L"shu"); + Insert(L"しょ",L"ă‚·ăƒ§",L"sho"); + + BeginGroup(); + Insert(L"ちゃ",L"チャ",L"cha"); + Insert(L"ちゅ",L"チツ",L"chu"); + Insert(L"ちょ",L"チョ",L"cho"); + + BeginGroup(); + Insert(L"ă«ă‚ƒ",L"ニャ",L"nya"); + Insert(L"にゅ",L"ăƒ‹ăƒ„",L"nyu"); + Insert(L"にょ",L"ニョ",L"nyo"); + + BeginGroup(); + Insert(L"ăČゃ",L"ヒャ",L"hya"); + Insert(L"ăČゅ",L"ăƒ’ăƒ„",L"hyu"); + Insert(L"ăČょ",L"ヒョ",L"hyo"); + + BeginGroup(); + Insert(L"みゃ",L"ミャ",L"mya"); + Insert(L"みゅ",L"ăƒŸăƒ„",L"myu"); + Insert(L"みょ",L"ミョ",L"myo"); + + BeginGroup(); + Insert(L"りゃ",L"ăƒȘャ",L"rya"); + Insert(L"りゅ",L"ăƒȘツ",L"ryu"); + Insert(L"りょ",L"ăƒȘョ",L"ryo"); + + BeginGroup(); + Insert(L"ぎゃ",L"ゼャ",L"gya"); + Insert(L"ぎゅ",L"ă‚źăƒ„",L"gyu"); + Insert(L"ぎょ",L"ゼョ",L"gyo"); + + BeginGroup(); + Insert(L"じゃ",L"ゾャ",L"ja"); + Insert(L"じゅ",L"ă‚žăƒ„",L"ju"); + Insert(L"じょ",L"ゾョ",L"jo"); + + BeginGroup(); + Insert(L"ぱゃ",L"ヂャ",L"ja"); + Insert(L"ぱゅ",L"ăƒ‚ăƒ„",L"ju"); + Insert(L"ぱょ",L"ヂョ",L"jo"); + + BeginGroup(); + Insert(L"びゃ",L"ビャ",L"bya"); + Insert(L"びゅ",L"ăƒ“ăƒ„",L"byu"); + Insert(L"びょ",L"ビョ",L"byo"); + + BeginGroup(); + Insert(L"のゃ",L"ピャ",L"pya"); + Insert(L"のゅ",L"ăƒ”ăƒ„",L"pyu"); + Insert(L"のょ",L"ピョ",L"pyo"); + + BeginGroup(); + Insert(L"",L"ファ",L"fa"); + Insert(L"",L"フィ",L"fi"); + Insert(L"",L"フェ",L"fe"); + Insert(L"",L"ăƒ•ă‚©",L"fo"); + + BeginGroup(); + Insert(L"",L"ヮァ",L"va"); + Insert(L"",L"ヮィ",L"vi"); + Insert(L"",L"ノ",L"vu"); + Insert(L"",L"ヮェ",L"ve"); + Insert(L"",L"ăƒŽă‚©",L"vo"); +} + + +////////////// +// Destructor +KanaTable::~KanaTable() { +} + + +/////////////// +// Begin group +void KanaTable::BeginGroup() { + curGroup = _T(""); + level++; +} + + +////////// +// Insert +void KanaTable::Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep) { +#ifdef _UNICODE + KanaEntry entry(hira,kata,hep); + if (curGroup.IsEmpty()) curGroup = hep; + entry.group = curGroup; + entry.level = level; + if (!entry.hiragana.IsEmpty() && level > groups[0]) groups[0] = level; + if (!entry.katakana.IsEmpty() && level > groups[1]) groups[1] = level; + entries.push_back(entry); +#endif +} + + +///////////////////// +// Number of entries +int KanaTable::GetNumberEntries(int level) const { + if (level == -1) return entries.size(); + else { + int count = 0; + int n = entries.size(); + for (int i=0;i +#include + + +/////////////////////////// +// Hiragana/katakana entry +class KanaEntry { +public: + wxString hiragana; + wxString katakana; + wxString hepburn; + wxString group; + int level; + + KanaEntry(wxString hira,wxString kata,wxString hep) { + hiragana = hira; + katakana = kata; + hepburn = hep; + } +}; + + +/////////////////////////// +// Hiragana/Katakana table +class KanaTable { +private: + std::vector entries; + void Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep); + void BeginGroup(); + wxString curGroup; + int groups[2]; + int level; + +public: + KanaTable(); + ~KanaTable(); + + int GetNumberEntries(int level=-1) const; + int GetLevels(int table) const; + const KanaEntry &GetEntry(int i) const; + const KanaEntry *FindByRomaji(wxString romaji) const; +}; diff --git a/kanamemo/level.cpp b/kanamemo/level.cpp new file mode 100644 index 000000000..b9fde3d03 --- /dev/null +++ b/kanamemo/level.cpp @@ -0,0 +1,117 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "level.h" +#include "game_display.h" +#include "kana_table.h" + + +/////////////// +// Constructor +LevelWindow::LevelWindow(wxWindow *parent,GameDisplay *dsp) +: wxDialog(parent,-1,_T("Set Level"),wxDefaultPosition,wxDefaultSize) +{ + // Set display + display = dsp; + + // Sliders + int levelHira = display->level[0]; + int levelKata = display->level[1]; + int maxLevelHira = display->table->GetLevels(0); + int maxLevelKata = display->table->GetLevels(1); + hiraSlider = new wxSlider(this,-1,levelHira,1,maxLevelHira,wxDefaultPosition,wxSize(200,-1)); + kataSlider = new wxSlider(this,-1,levelKata,1,maxLevelKata,wxDefaultPosition,wxSize(200,-1)); + + // Checkbox + autoLevelCheck = new wxCheckBox(this,-1,_T("Automatically level up")); + autoLevelCheck->SetValue(display->autoLevel); + + // Sizers + wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); + wxSizer *sizer1 = new wxStaticBoxSizer(wxVERTICAL,this,_T("Hiragana and Katakana")); + wxSizer *sizer2 = new wxFlexGridSizer(2,2,5,5); + wxSizer *sizer3 = new wxBoxSizer(wxHORIZONTAL); + + // Insert controls + sizer2->Add(new wxStaticText(this,-1,_T("Hiragana")),0,wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT,5); + sizer2->Add(hiraSlider,1,wxEXPAND,0); + sizer2->Add(new wxStaticText(this,-1,_T("Katakana")),0,wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT,5); + sizer2->Add(kataSlider,1,wxEXPAND,0); + + // Sizer layout + sizer1->Add(sizer2,1,wxEXPAND,0); + sizer1->Add(autoLevelCheck,0,wxALIGN_LEFT | wxTOP,5); + sizer3->AddStretchSpacer(1); + sizer3->Add(new wxButton(this,wxID_OK),0,0,0); + sizer3->Add(new wxButton(this,wxID_CANCEL),0,0,0); + mainSizer->Add(sizer1,1,wxEXPAND | wxALL,5); + mainSizer->Add(sizer3,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5); + mainSizer->SetSizeHints(this); + SetSizer(mainSizer); +} + + +////////////// +// Destructor +LevelWindow::~LevelWindow() { +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(LevelWindow,wxDialog) + EVT_BUTTON(wxID_OK,LevelWindow::OnOK) + EVT_BUTTON(wxID_CANCEL,LevelWindow::OnCancel) +END_EVENT_TABLE() + + +////// +// OK +void LevelWindow::OnOK(wxCommandEvent &event) { + display->autoLevel = autoLevelCheck->GetValue(); + display->SetLevel(0,hiraSlider->GetValue()); + display->SetLevel(1,kataSlider->GetValue()); + Destroy(); +} + + +////////// +// Cancel +void LevelWindow::OnCancel(wxCommandEvent &event) { + Destroy(); +} diff --git a/kanamemo/level.h b/kanamemo/level.h new file mode 100644 index 000000000..77b977a97 --- /dev/null +++ b/kanamemo/level.h @@ -0,0 +1,65 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +////////////// +// Prototypes +class GameDisplay; + + +///////////////////// +// Game window class +class LevelWindow : public wxDialog { +private: + GameDisplay *display; + + wxSlider *hiraSlider; + wxSlider *kataSlider; + wxCheckBox *autoLevelCheck; + + void OnOK(wxCommandEvent &event); + void OnCancel(wxCommandEvent &event); + +public: + LevelWindow(wxWindow *parent,GameDisplay *dsp); + ~LevelWindow(); + + DECLARE_EVENT_TABLE(); +}; \ No newline at end of file diff --git a/kanamemo/main.cpp b/kanamemo/main.cpp new file mode 100644 index 000000000..55a4e74c9 --- /dev/null +++ b/kanamemo/main.cpp @@ -0,0 +1,115 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include "main.h" +#include "game_window.h" + + +///////////////// +// Implement app +IMPLEMENT_APP(KanaMemo) + + +////////////// +// Initialize +bool KanaMemo::OnInit() { + // Configuration + SetAppName(_T("KanaMemo")); + srand((unsigned)time(NULL)); + + // Get path + GetFullPath(argv[0]); + GetFolderName(); + + // Create the window + GameWindow *window = new GameWindow(); + window->Show(); + + // Initialization OK + return true; +} + + +///////////////////////////// +// Gets and stores full path +void KanaMemo::GetFullPath(wxString arg) { + if (wxIsAbsolutePath(arg)) { + fullPath = arg; + return; + } + + // Is it a relative path? + wxString currentDir(wxFileName::GetCwd()); + if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH; + wxString str = currentDir + arg; + if (wxFileExists(str)) { + fullPath = str; + return; + } + + // OK, it's neither an absolute path nor a relative path. + // Search PATH. + wxPathList pathList; + pathList.AddEnvList(_T("PATH")); + str = pathList.FindAbsoluteValidPath(arg); + if (!str.IsEmpty()) { + fullPath = str; + return; + } + + fullPath = _T(""); + return; +} + + +/////////////////////////////////// +// Gets folder name from full path +void KanaMemo::GetFolderName () { + folderName = _T(""); + wxFileName path(fullPath); + folderName += path.GetPath(wxPATH_GET_VOLUME); + folderName += _T("/"); +} + + +/////////// +// Statics +wxString KanaMemo::folderName; +wxString KanaMemo::fullPath; diff --git a/kanamemo/main.h b/kanamemo/main.h new file mode 100644 index 000000000..5cb438c46 --- /dev/null +++ b/kanamemo/main.h @@ -0,0 +1,47 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +////////////// +// Main class +class KanaMemo : public wxApp { +public: + bool OnInit(); + void GetFullPath(wxString arg); + void GetFolderName(); + + static wxString folderName; + static wxString fullPath; +}; diff --git a/kanamemo/res.rc b/kanamemo/res.rc new file mode 100644 index 000000000..f14c1570a --- /dev/null +++ b/kanamemo/res.rc @@ -0,0 +1,3 @@ +wxicon ICON "icon.ico" + +#include "wx/msw/wx.rc" diff --git a/kanamemo/switch_user.cpp b/kanamemo/switch_user.cpp new file mode 100644 index 000000000..935508872 --- /dev/null +++ b/kanamemo/switch_user.cpp @@ -0,0 +1,178 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include +#include "switch_user.h" +#include "game_display.h" +#include "main.h" + + +/////////////// +// Constructor +SwitchUserDialog::SwitchUserDialog(GameDisplay *dspl) +: wxDialog(NULL,-1,_T("Select user..."),wxDefaultPosition,wxDefaultSize) +{ + display = dspl; + + // Sizers + wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); + wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); + wxSizer *listSizer = new wxStaticBoxSizer(wxVERTICAL,this,_T("Users:")); + + // Load list + wxArrayString choices; + wxArrayString files; + wxDir::GetAllFiles(KanaMemo::folderName,&files,_T("*.usr"),wxDIR_FILES); + for (size_t i=0;iAdd(listBox,1,wxEXPAND,0); + + // Button sizer + buttonSizer->AddStretchSpacer(1); + okButton = new wxButton(this,wxID_OK); + buttonSizer->Add(new wxButton(this,wxID_NEW),0,0,0); + buttonSizer->Add(okButton,0,0,0); + buttonSizer->Add(new wxButton(this,wxID_CANCEL),0,0,0); + + // Main sizer + mainSizer->Add(listSizer,1,wxEXPAND | wxALL,5); + mainSizer->Add(buttonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5); + mainSizer->SetSizeHints(this); + SetSizer(mainSizer); + + // If list is empty, prompt for new user + if (listBox->GetCount() == 0) NewUser(); + UpdateButtons(); +} + + +////////////// +// Destructor +SwitchUserDialog::~SwitchUserDialog() { +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(SwitchUserDialog,wxDialog) + EVT_BUTTON(wxID_NEW,SwitchUserDialog::OnButtonCreate) + EVT_BUTTON(wxID_OK,SwitchUserDialog::OnButtonOK) + EVT_BUTTON(wxID_CANCEL,SwitchUserDialog::OnButtonCancel) + EVT_LISTBOX(1337, SwitchUserDialog::OnClickList) + EVT_LISTBOX_DCLICK(1337, SwitchUserDialog::OnDoubleClickList) +END_EVENT_TABLE() + + +////////// +// Create +void SwitchUserDialog::OnButtonCreate(wxCommandEvent &event) { + NewUser(); +} + + +////// +// OK +void SwitchUserDialog::OnButtonOK(wxCommandEvent &event) { + Select(); +} + + +////////// +// Cancel +void SwitchUserDialog::OnButtonCancel(wxCommandEvent &event) { + Destroy(); +} + + +//////////// +// New user +void SwitchUserDialog::NewUser() { + wxString userName = wxGetTextFromUser(_T("Enter the name of the new user:"),_T("New user"),_T(""),this); + if (!userName.IsEmpty()) { + // Create file + wxString path = KanaMemo::folderName + _T("/") + userName + _T(".usr"); + FILE *fp = fopen(path.mb_str(wxConvLocal),"wb"); + fclose(fp); + + // Update stuff + listBox->Append(userName); + listBox->SetStringSelection(userName); + UpdateButtons(); + } +} + + +//////////////// +// List clicked +void SwitchUserDialog::OnClickList(wxCommandEvent &event) { + UpdateButtons(); +} + + +/////////////////////// +// List double clicked +void SwitchUserDialog::OnDoubleClickList(wxCommandEvent &event) { + Select(); +} + + +////////////////// +// Update buttons +void SwitchUserDialog::UpdateButtons() { + okButton->Enable(!listBox->GetStringSelection().IsEmpty()); +} + + +/////////////// +// Select user +void SwitchUserDialog::Select() { + wxString user = listBox->GetStringSelection(); + if (!user.IsEmpty()) { + display->playerName = user; + display->Load(); + display->EnableGame(true); + Destroy(); + } +} \ No newline at end of file diff --git a/kanamemo/switch_user.h b/kanamemo/switch_user.h new file mode 100644 index 000000000..3e34e9258 --- /dev/null +++ b/kanamemo/switch_user.h @@ -0,0 +1,71 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +////////////// +// Prototypes +class GameDisplay; + + +/////////////////////// +// Switch users dialog +class SwitchUserDialog : public wxDialog { +private: + GameDisplay *display; + + wxListBox *listBox; + wxButton *okButton; + + void OnButtonCreate(wxCommandEvent &event); + void OnButtonOK(wxCommandEvent &event); + void OnButtonCancel(wxCommandEvent &event); + void OnClickList(wxCommandEvent &event); + void OnDoubleClickList(wxCommandEvent &event); + + void NewUser(); + void UpdateButtons(); + void Select(); + +public: + SwitchUserDialog(GameDisplay *display); + ~SwitchUserDialog(); + + DECLARE_EVENT_TABLE() +}; diff --git a/kanamemo/version.cpp b/kanamemo/version.cpp new file mode 100644 index 000000000..cc73974f7 --- /dev/null +++ b/kanamemo/version.cpp @@ -0,0 +1,51 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "version.h" + + +//////////////////// +// Version function +wxString GetVersionString() { + wxString final; + final = _T("KanaMemo v0.06"); +#ifdef _DEBUG + final += _T(" DEBUG"); +#endif + return final; +} diff --git a/kanamemo/version.h b/kanamemo/version.h new file mode 100644 index 000000000..e1dc6bde6 --- /dev/null +++ b/kanamemo/version.h @@ -0,0 +1,44 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +//////////////////// +// Version function +wxString GetVersionString(); diff --git a/traydict/dict_window.cpp b/traydict/dict_window.cpp new file mode 100644 index 000000000..cf4f558c7 --- /dev/null +++ b/traydict/dict_window.cpp @@ -0,0 +1,228 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include "dict_window.h" +#include "systray.h" +#include "dictionary.h" +#include "main.h" + + +/////////////// +// Constructor +DictWindow::DictWindow() +: wxFrame(NULL,-1,_T("TrayDict v0.06 - By Rodrigo Braz Monteiro"),wxDefaultPosition,wxSize(620,500),wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN) +{ + // Icons + SetIcon(wxICON(wxicon)); + systray = new Systray(this); + + // Menu bar + //menu = new wxMenuBar(); + //SetMenuBar(menu); + + // Status bar + //wxStatusBar *bar = CreateStatusBar(3,0); + //int widths[] = { 85, -1, -1 }; + //bar->SetStatusWidths(3,widths); + + // Panel + panel = new wxPanel(this); + + // Controls + entry = new wxTextCtrl(panel,ENTRY_FIELD,_T(""),wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER); + results = new wxTextCtrl(panel,-1,_T(""),wxDefaultPosition,wxSize(280,400),wxTE_RICH2 | wxTE_MULTILINE | wxTE_DONTWRAP | wxTE_READONLY); + wxButton *searchButton = new wxButton(panel,BUTTON_SEARCH,_T("Search"),wxDefaultPosition,wxSize(80,-1)); + wxSizer *entrySizer = new wxBoxSizer(wxHORIZONTAL); + entrySizer->Add(entry,1,wxEXPAND | wxRIGHT,5); + entrySizer->Add(searchButton,0,wxEXPAND,0); + + // Options + checkKanji = new wxCheckBox(panel,CHECK_KANJI,_T("Kanji")); + checkKana = new wxCheckBox(panel,CHECK_KANA,_T("Kana")); + checkRomaji = new wxCheckBox(panel,CHECK_ROMAJI,_T("Romaji")); + checkEnglish = new wxCheckBox(panel,CHECK_ENGLISH,_T("English")); + checkEdict = new wxCheckBox(panel,CHECK_ENGLISH,_T("EDICT")); + checkEnamdict = new wxCheckBox(panel,CHECK_ENGLISH,_T("ENAMDICT")); + checkCompdic = new wxCheckBox(panel,CHECK_ENGLISH,_T("COMPDIC")); + checkJplaces = new wxCheckBox(panel,CHECK_ENGLISH,_T("J_PLACES")); + checkKanji->SetValue(true); + checkKana->SetValue(true); + checkRomaji->SetValue(true); + checkEnglish->SetValue(true); + checkEdict->SetValue(true); + checkEnamdict->SetValue(false); + checkCompdic->SetValue(false); + checkJplaces->SetValue(false); + wxSizer *optionsSizer = new wxBoxSizer(wxHORIZONTAL); + optionsSizer->Add(new wxStaticText(panel,-1,_T("Display:")),0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkKanji,0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkKana,0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkRomaji,0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkEnglish,0,wxCENTER | wxRIGHT,20); + optionsSizer->Add(new wxStaticText(panel,-1,_T("Dictionary:")),0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkEdict,0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkEnamdict,0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkCompdic,0,wxCENTER | wxRIGHT,5); + optionsSizer->Add(checkJplaces,0,wxCENTER | wxRIGHT,0); + optionsSizer->AddStretchSpacer(1); + + // Main sizer + wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); + mainSizer->Add(entrySizer,0,wxEXPAND | wxALL,5); + mainSizer->Add(optionsSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5); + mainSizer->Add(results,1,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5); + panel->SetSizer(mainSizer); + + // Create dictionary files + if (false) { + Dictionary::Convert(TrayDict::folderName + _T("edict"),TrayDict::folderName + _T("edict.dic")); + Dictionary::Convert(TrayDict::folderName + _T("enamdict"),TrayDict::folderName + _T("enamdict.dic")); + Dictionary::Convert(TrayDict::folderName + _T("compdic"),TrayDict::folderName + _T("compdic.dic")); + Dictionary::Convert(TrayDict::folderName + _T("j_places"),TrayDict::folderName + _T("j_places.dic")); + } + + // Load dictionary files + dict.push_back(new Dictionary(_T("edict"),checkEdict)); + dict.push_back(new Dictionary(_T("enamdict"),checkEnamdict)); + dict.push_back(new Dictionary(_T("compdic"),checkCompdic)); + dict.push_back(new Dictionary(_T("j_places"),checkJplaces)); + + // Register hotkey + RegisterHotKey(HOTKEY_ID,wxMOD_WIN,'Z'); +} + + +////////////// +// Destructor +DictWindow::~DictWindow() { + if (systray->IsOk()) { + systray->RemoveIcon(); + } + delete systray; + + for (size_t i=0;iIsOk()) { + Hide(); + } +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(DictWindow,wxFrame) + EVT_ICONIZE(DictWindow::OnIconize) + EVT_BUTTON(BUTTON_SEARCH,DictWindow::OnSearch) + EVT_TEXT_ENTER(ENTRY_FIELD,DictWindow::OnSearch) + EVT_HOTKEY(HOTKEY_ID,DictWindow::OnHotkey) + EVT_CLOSE(DictWindow::OnClose) +END_EVENT_TABLE() + + +///////////////// +// Iconize event +void DictWindow::OnIconize(wxIconizeEvent &event) { + if (event.Iconized()) { + GoToTray(); + } +} + + +////////////////// +// Hotkey pressed +void DictWindow::OnHotkey(wxKeyEvent &event) { + if (IsShown()) GoToTray(); + else systray->BringUp(); +} + + +///////////////////////// +// Search button pressed +void DictWindow::OnSearch(wxCommandEvent &event) { + Search(entry->GetValue()); +} + + +////////// +// Search +void DictWindow::Search(wxString text) { + // Prepare + int bitmask = (checkKanji->GetValue() ? 1 : 0) | (checkKana->GetValue() ? 2 : 0) | (checkRomaji->GetValue() ? 4 : 0) | (checkEnglish->GetValue() ? 8 : 0); + + // Clear text + results->Clear(); + entry->SetSelection(0,entry->GetValue().Length()); + + // Search each dictionary + for (size_t i=0;icheck->GetValue() && dict[i]->check->IsEnabled()) { + // Search + ResultSet res; + dict[i]->Search(res,text); + + // Sort results by relevancy + res.results.sort(); + + // Print + res.Print(results,bitmask); + } + } + + // Show start + results->ShowPosition(0); + results->SetSelection(0,0); +} + + +//////////////// +// Close window +void DictWindow::OnClose(wxCloseEvent &event) { + if (event.CanVeto()) { + event.Veto(); + GoToTray(); + } + else Destroy(); +} diff --git a/traydict/dict_window.h b/traydict/dict_window.h new file mode 100644 index 000000000..25e67a955 --- /dev/null +++ b/traydict/dict_window.h @@ -0,0 +1,95 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +////////////// +// Prototypes +class Systray; +class Dictionary; + + +////////////////////////// +// Dictionary main window +class DictWindow : public wxFrame { +private: + wxMenuBar *menu; + wxTextCtrl *results; + Systray *systray; + std::vector dict; + + void GoToTray(); + void ComeFromTray(); + void OnIconize(wxIconizeEvent &event); + void OnSearch(wxCommandEvent &event); + void OnHotkey(wxKeyEvent &event); + void OnClose(wxCloseEvent &event); + + void Search(wxString text); + +public: + wxTextCtrl *entry; + wxPanel *panel; + wxCheckBox *checkKanji; + wxCheckBox *checkKana; + wxCheckBox *checkRomaji; + wxCheckBox *checkEnglish; + wxCheckBox *checkEdict; + wxCheckBox *checkEnamdict; + wxCheckBox *checkCompdic; + wxCheckBox *checkJplaces; + + DictWindow(); + ~DictWindow(); + + DECLARE_EVENT_TABLE(); +}; + + +/////// +// IDs +enum { + BUTTON_SEARCH = 1200, + ENTRY_FIELD, + CHECK_KANJI, + CHECK_KANA, + CHECK_ROMAJI, + CHECK_ENGLISH, + HOTKEY_ID = 0x19E2 // Totally arbitrary +}; diff --git a/traydict/dictionary.cpp b/traydict/dictionary.cpp new file mode 100644 index 000000000..e52abb0a2 --- /dev/null +++ b/traydict/dictionary.cpp @@ -0,0 +1,587 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include +#include +#include +#include +#include "dictionary.h" +#include "text_file_reader.h" +#include "main.h" + + +/////////////// +// Constructor +Dictionary::Dictionary(wxString _name,wxCheckBox *_check) { + name = _name; + check = _check; + + // Set file + wxString filename = TrayDict::folderName + _name + _T(".dic"); + Load(filename); + + // Set checkbox + wxFileName file(filename); + check->Enable(file.FileExists()); +} + + +////////////// +// Destructor +Dictionary::~Dictionary() { +} + + +////////// +// Static +KanaTable Dictionary::kanatable; + + +//////// +// Load +void Dictionary::Convert(wxString source,wxString dest) { + // Variables + const wchar_t *str = NULL; + short len; + DictEntry curEntry; + + try { + // Open source file + TextFileReader file(source,_T("EUC-JP")); + + // Open destination file + wxFileOutputStream out(dest); + wxBufferedOutputStream buf(out); + wxZlibOutputStream fp(buf,9,wxZLIB_GZIP); + + // Skip first line + if (file.HasMoreLines()) file.ReadLineFromFile(); + + // Read lines + while (file.HasMoreLines()) { + // Get string + wxString string = file.ReadLineFromFile(); + + // Process string to account for lack of kana + if (!string.Contains(_T("["))) { + if (!string.Contains(_T("]"))) { + int pos = string.Find(_T(' ')); + if (pos == -1) continue; + wxString temp = string; + string = temp.Left(pos) + _T(" []") + temp.Right(temp.Length() - pos); + } + else continue; + } + + // Tokenize + wxStringTokenizer token(string,_T("[]"),wxTOKEN_RET_EMPTY); + + // Kanji + if (token.HasMoreTokens()) { + curEntry.kanji = token.GetNextToken().Trim(false).Trim(true); + } + else continue; + + // Kana & romaji + if (token.HasMoreTokens()) { + curEntry.kana = token.GetNextToken().Trim(false).Trim(true); + if (curEntry.kana.IsEmpty()) curEntry.kana = curEntry.kanji; + curEntry.romaji = kanatable.KanaToRomaji(curEntry.kana,0); + } + else continue; + + // English + if (token.HasMoreTokens()) { + curEntry.english = token.GetNextToken().Trim(false).Trim(true); + curEntry.english = curEntry.english.Mid(1,curEntry.english.Length()-2); + } + else continue; + + // Write kanji + str = curEntry.kanji.c_str(); + len = wcslen(str); + fp.Write(&len,2); + fp.Write(str,len*2); + + // Write kana + str = curEntry.kana.c_str(); + len = wcslen(str); + fp.Write(&len,2); + fp.Write(str,len*2); + + // Write romaji + str = curEntry.romaji.c_str(); + len = wcslen(str); + fp.Write(&len,2); + fp.Write(str,len*2); + + // Write english + str = curEntry.english.c_str(); + len = wcslen(str); + fp.Write(&len,2); + fp.Write(str,len*2); + } + } + + catch (...) { + wxMessageBox(_T("Could not find dictionary file: ") + source,_T("File not found!"),wxICON_ERROR); + } +} + + +//////// +// Load +void Dictionary::Load(wxString filename) { + dictFile = filename; +} + + +////////// +// Search +void Dictionary::Search(ResultSet &results,wxString query) { + // Prepare results + int resCount = 0; + results.ownData = true; + results.dicName = name; + results.query = query; + query.Trim(true); + query.Trim(false); + + // Determine query type + bool isJapanese = false; + for (size_t i=0;i 255) { + isJapanese = true; + break; + } + } + + // Stopwatch + wxStopWatch stopwatch; + + // Open file + wxInputStream *file; + wxFileInputStream filestream(dictFile); + wxBufferedInputStream buf(filestream); + wxZlibInputStream zstream(buf); + wxBufferedInputStream buf2(zstream); + file = &zstream; + + // Buffer + wchar_t buffer[16384]; + short len; + DictEntry *cur = NULL; + + // Search for matches + while (!file->Eof()) { + // Prepare + bool addThis = false; + int rel = 0; + + // Create data + if (!cur) cur = new DictEntry; + + // Read kanji + file->Read(&len,2); + if (len < 0) return; + file->Read(buffer,2*len); + buffer[len] = 0; + cur->kanji = buffer; + + // Read kana + file->Read(&len,2); + if (len < 0) return; + file->Read(buffer,2*len); + buffer[len] = 0; + cur->kana = buffer; + + // Read romaji + file->Read(&len,2); + if (len < 0) return; + file->Read(buffer,2*len); + buffer[len] = 0; + cur->romaji = buffer; + + // Read english + file->Read(&len,2); + if (len < 0) return; + file->Read(buffer,2*len); + buffer[len] = 0; + cur->english = buffer; + + // Japanese query + if (isJapanese) { + // Matches kanji? + if (cur->kanji.Contains(query)) { + addThis = true; + rel = GetRelevancy(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)"))); + } + } + + // English/romaji query + else { + // Lowercase query + wxString lowQuery = query.Lower(); + + // Matches english? + if (cur->english.Lower().Contains(lowQuery)) { + addThis = true; + rel = GetRelevancy(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)"))); + } + } + + // Add entry + if (addThis) { + SearchResult res; + res.relevancy = rel; + res.entry = cur; + results.results.push_back(res); + cur = NULL; + } + } + + // Delete cur + if (cur) delete cur; + + // Time + stopwatch.Pause(); + results.time = stopwatch.Time(); + + // Close file +} + + +///////////////// +// Get relevancy +int Dictionary::GetRelevancy(wxString substr,wxString _str,bool isPop,bool english) { + // Best score + int bestScore = 0; + + // Generate list of strings + wxArrayString strings; + if (!english) strings.Add(_str.Lower()); + else { + wxStringTokenizer tkn(_str.Lower(),_T("/")); + while (tkn.HasMoreTokens()) { + // Get token + wxString token = tkn.GetNextToken(); + + // Remove parenthesis + wxString temp; + bool inside = false; + bool gotOne = false; + for (size_t i=0;i temp2) score += temp1; + else score += temp2; + } + + // Best score? + if (score > bestScore) bestScore = score; + } + + return bestScore; +} + + +////////////////////////// +// Comparison for sorting +bool operator < (const SearchResult &a,const SearchResult &b) { + return (a.relevancy > b.relevancy); +} + + +///////////////// +// Compact entry +void DictEntry::Compact() { + kanji.Trim(true).Trim(false).Shrink(); + kana.Trim(true).Trim(false).Shrink(); + english.Trim(true).Trim(false).Shrink(); +} + + +/////////////// +// Constructor +ResultSet::ResultSet() { + ownData = false; +} + + +////////////// +// Destructor +ResultSet::~ResultSet() { + if (ownData) { + std::list::iterator cur; + for (cur = results.begin(); cur != results.end();cur++) { + delete (*cur).entry; + } + } +} + + +/////////////////// +// Print resultset +void ResultSet::Print(wxTextCtrl *target,int bitmask) { + // Get options + bool drawKanji = (bitmask & 1) != 0; + bool drawKana = (bitmask & 2) != 0; + bool drawRomaji = (bitmask & 4) != 0; + bool drawEnglish = (bitmask & 8) != 0; + + // Fonts + wxFont font; + font.SetFaceName(_T("MS Mincho")); + font.SetPointSize(9); + wxFont font2; + font2.SetFaceName(_T("Tahoma")); + + // Text attributes + wchar_t space = 0x3000; + wxString spaceStr = space; + wxTextAttr fontAttr; + fontAttr.SetFont(font); + wxTextAttr kanjiCol; + kanjiCol.SetFont(font); + kanjiCol.SetTextColour(wxColour(192,0,0)); + wxTextAttr kanaCol; + kanaCol.SetTextColour(wxColour(0,0,192)); + wxTextAttr romajiCol; + romajiCol.SetTextColour(wxColour(0,128,0)); + wxTextAttr engCol; + engCol.SetFont(font2); + engCol.SetTextColour(wxColour(0,0,0)); + wxTextAttr commonCol; + commonCol.SetTextColour(wxColour(0,128,128)); + commonCol.SetFont(font2); + wxTextAttr sepCol; + sepCol.SetTextColour(wxColour(128,90,0)); + wxTextAttr boldCol; + font2.SetWeight(wxBOLD); + boldCol.SetFont(font2); + wxTextAttr notBoldCol; + font2.SetWeight(wxNORMAL); + notBoldCol.SetFont(font); + + // Find column widths + int kanjiWidth = 0; + int kanaWidth = 0; + int romajiWidth = 0; + std::list::iterator cur; + DictEntry *entry; + int curLen; + int resPrinted = 0; + for (cur=results.begin();cur!=results.end();cur++) { + entry = cur->entry; + curLen = entry->kanji.Length(); + if (curLen > kanjiWidth) kanjiWidth = curLen; + curLen = entry->kana.Length(); + if (curLen > kanaWidth) kanaWidth = curLen; + wxString temp = Dictionary::kanatable.KanaToRomaji(entry->kana); + curLen = temp.Length() - temp.Freq(0x304); + if (curLen > romajiWidth) romajiWidth = curLen; + + // Limit to 1000 + resPrinted++; + if (resPrinted >= 1000) break; + } + + // List number of results + target->SetDefaultStyle(boldCol); + int maxDisp = results.size(); + if (maxDisp > 1000) maxDisp = 1000; + target->AppendText(wxString::Format(_T("Searched %s for \"%s\". Displaying %i matches. Search took %i ms.\n"),dicName.Upper().c_str(),query.c_str(),maxDisp,time)); + target->SetDefaultStyle(notBoldCol); + target->SetDefaultStyle(fontAttr); + + // Append to results + wxString curText; + resPrinted = 0; + for (cur=results.begin();cur!=results.end();cur++) { + entry = cur->entry; + + // Write kanji + if (drawKanji) { + target->SetDefaultStyle(kanjiCol); + curText = entry->kanji; + curLen = kanjiWidth - curText.Length() + 1; + for (int i=0;iAppendText(curText); + } + + // Write kana + if (drawKana) { + target->SetDefaultStyle(kanaCol); + //curText = _T("[") + entry->kana + _T("]"); + curText = entry->kana; + curLen = kanaWidth - curText.Length() + 1; + for (int i=0;iAppendText(curText); + } + + // Write romaji + if (drawRomaji) { + target->SetDefaultStyle(romajiCol); + curText = Dictionary::kanatable.KanaToRomaji(entry->kana); + curLen = romajiWidth - curText.Length() + curText.Freq(0x304) + 1; + for (int i=0;iAppendText(curText); + } + + // Write english + if (drawEnglish) { + // Search for grammatical class + wxString mainText; + int pos = entry->english.Find(_T(')')); + if (entry->english[0] == _T('(') && pos != -1) { + mainText = entry->english.Mid(pos+1); + mainText.Trim(false); + + // Draw grammatical class + target->SetDefaultStyle(sepCol); + target->AppendText(entry->english.Left(pos+1) + _T(" ")); + } + else mainText = entry->english; + target->SetDefaultStyle(engCol); + + // Draw rest + target->SetDefaultStyle(engCol); + wxStringTokenizer tkn(mainText,_T("/")); + bool hadPrev = false; + while (tkn.HasMoreTokens()) { + // Popular entry + wxString token = tkn.GetNextToken(); + if (token == _T("(P)")) { + target->SetDefaultStyle(commonCol); + target->AppendText(_T(" [Common]")); + target->SetDefaultStyle(engCol); + } + + // Normal entry + else { + // Separator + if (hadPrev) { + target->SetDefaultStyle(sepCol); + target->AppendText(_T(" / ")); + target->SetDefaultStyle(engCol); + } + + // Append text + target->AppendText(token); + hadPrev = true; + } + } + } + + // Line break + target->SetDefaultStyle(fontAttr); + target->AppendText(_T("\n")); + + // Limit to 1000 + resPrinted++; + if (resPrinted >= 1000) { + target->SetDefaultStyle(boldCol); + target->AppendText(wxString::Format(_T("Too many (%i) matches, stopping.\n"),results.size())); + break; + } + } + + // Print two carriage returns + target->AppendText(_T("\n\n")); +} diff --git a/traydict/dictionary.h b/traydict/dictionary.h new file mode 100644 index 000000000..8ee3e0c96 --- /dev/null +++ b/traydict/dictionary.h @@ -0,0 +1,102 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include "kana_table.h" + + +////////////////////////// +// Dictionary entry class +class DictEntry { +public: + wxString english; + wxString kanji; + wxString kana; + wxString romaji; + + void Compact(); +}; + + +/////////// +// Results +class SearchResult { +public: + DictEntry *entry; + int relevancy; +}; +bool operator < (const SearchResult &a,const SearchResult &b); + + +////////////// +// Result set +class ResultSet { +public: + wxString query; + wxString dicName; + + std::list results; + void Print(wxTextCtrl *target,int bitmask); + bool ownData; + int time; + + ResultSet(); + ~ResultSet(); +}; + + +//////////////////// +// Dictionary class +class Dictionary { +private: + std::list entries; + wxString dictFile; + wxString name; + +public: + wxCheckBox *check; + static KanaTable kanatable; + static void Convert(wxString source,wxString dest); + + void Load(wxString filename); + void Search(ResultSet &results,wxString query); + int GetRelevancy(wxString substr,wxString str,bool isPop,bool english=false); + + Dictionary(wxString name,wxCheckBox *check); + ~Dictionary(); +}; diff --git a/traydict/icon.ico b/traydict/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..a28419f952db8245ba1187f1a9081c6a8d410995 GIT binary patch literal 7406 zcmeI0eN0_v9ml_nQYvqyFSI~kpj$8WWi4>W)^07OQ`-Q^3`Qw6{bWVm9hNUHPSF;wY6@(NIH(~f+0j; zP8?20v+QqrI<~J$*M^?Z*5X3>E4Rq}dQ|4Zmu0TLs6RaaMU@ui%lwA2vwbon{W8HP zWzIjP(gMnFO{l79wal;1t28f99}V=0>h+2-`qE>c(#!atd~HDfigFoqUFPCfWzO}f zprlM2w^gh2@E&5nEAxXPeW4EbiAfIHXo0DOK&{& zxHd4~--Y_e`@XG)51iDYwhl#@@Ae*iSRd)`)A${uYws96bl{-AhyUHPXPhqm=r2a* zwevEsGnZd_MxQ)(Q0B+q)X7ixsPE#>w5oWM>bGx_nHzP-7tEvM> z74HAMzCUMl;ccUr{%F+md`Pc7ep0Vrd0CTh{ZnTt5B%g)e-t=r-sgLg0Dt2vaXLPnztLgBjgiO*9M zijx;=OD43TFt=!aQC|>=x4|Pe2004eu`ZChL0Axv-DTP^q;kv5v&I?oH!O^)$IPkG z%&NkKwbroVz_PI{OxAj^Myw*tjs(kP|B;Pl%~5F01+x&aCd9I^Y=qZ3;w-PmWMjX; zjIrmzTI^A5exH&@CY}<`h5^}&eT?(7a1#!P6`l%f_Ud(KgLPowI0oDemr0&a7$B@+0CHY$wnSq~xAAui$?}BfKZNr-3 z8{q5Ueeh-Q=#GxU_rrI>H^KX0otD81Uhslft7hOQ;78yG;Je`4;oIPwHKhjlI(Q#^ z8T>5#G<*bp96kgegb%_G!gs@Wz_-Br;SIcjH}D4Dz#DjbO>tf38sh5WYIXQo_-XhE z{5X6F-l_+o2cf&6JD^*j{pioYPr#4Bvrla5f^Ua!gKvg!fUkr1!I#0KJIa2qpL2U> zCwvpU4_@%8qr<4pz)!&2bN&E)7koQ>8+dvF2tEj(;q%c9 z`~>_6`~Z9xd^>!G&j;OzM&bM6JK>w)eejtEC}L*dC*Vim2jCfL(+=-FKoR~ZN6j>R z1b!So1kd1P7$CckAI18yPOJ&@VVMT#)~#E*dGn@j+_<61$w`fkjp@>*O9}>q8Xg|j z;NYN6pFXYb?rxnrbxIu_9XfI1gj!l!bmYhp`Tc%XRaL3Hyj(>^_CGi8`qbOo`yaHi zx3{FEWZ3}@z3hNEy}W<~dKm!=G@XTCybnqAk^#xIGoFjokVY>aV8`1@_9cPFQszE* z(Zpm7NY`Gx2Kc0wxD8sQhQxNy(~C7J5lX!G?n5Gxa_1+2FM)?0yq^*tOTt#5Sd z;go3DWs(rE|D(17bJin3yF3IC3fl+xsOznOt;h;kZw0J(1n^D^tPjM>t$@?RsM~V{ d8trogtV6(gjDRyR2sAq7CJ=MxRo5rEe*?0bXS)CZ literal 0 HcmV?d00001 diff --git a/traydict/kana_table.cpp b/traydict/kana_table.cpp new file mode 100644 index 000000000..ad895ab05 --- /dev/null +++ b/traydict/kana_table.cpp @@ -0,0 +1,432 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "kana_table.h" + + +/////////////// +// Constructor +KanaTable::KanaTable() { + level = 0; + groups[0] = 0; + groups[1] = 0; + + BeginGroup(); + Insert(L"あ",L"ケ",L"a"); + Insert(L"い",L"ă‚€",L"i"); + Insert(L"う",L"ォ",L"u"); + Insert(L"え",L"ス",L"e"); + Insert(L"お",L"ă‚Ș",L"o"); + + BeginGroup(); + Insert(L"か",L"ă‚«",L"ka"); + Insert(L"き",L"キ",L"ki"); + Insert(L"く",L"ク",L"ku"); + Insert(L"け",L"ケ",L"ke"); + Insert(L"こ",L"コ",L"ko"); + + BeginGroup(); + Insert(L"さ",L"ă‚”",L"sa"); + Insert(L"し",L"ă‚·",L"shi"); + Insert(L"す",L"ă‚č",L"su"); + Insert(L"せ",L"ă‚»",L"se"); + Insert(L"そ",L"ă‚œ",L"so"); + + BeginGroup(); + Insert(L"た",L"タ",L"ta"); + Insert(L"づ",L"チ",L"chi"); + Insert(L"぀",L"ツ",L"tsu"); + Insert(L"お",L"テ",L"te"); + Insert(L"ず",L"ト",L"to"); + + BeginGroup(); + Insert(L"ăȘ",L"ナ",L"na"); + Insert(L"に",L"ニ",L"ni"); + Insert(L"く",L"ヌ",L"nu"); + Insert(L"ね",L"ネ",L"ne"); + Insert(L"た",L"ノ",L"no"); + + BeginGroup(); + Insert(L"は",L"ハ",L"ha"); + Insert(L"ăČ",L"ヒ",L"hi"); + Insert(L"ご",L"フ",L"fu"); + Insert(L"ぞ",L"ヘ",L"he"); + Insert(L"ほ",L"ホ",L"ho"); + + BeginGroup(); + Insert(L"ăŸ",L"マ",L"ma"); + Insert(L"み",L"ミ",L"mi"); + Insert(L"む",L"ム",L"mu"); + Insert(L"め",L"ュ",L"me"); + Insert(L"も",L"ヹ",L"mo"); + + BeginGroup(); + Insert(L"や",L"ダ",L"ya"); + Insert(L"ゆ",L"ナ",L"yu"); + Insert(L"よ",L"ペ",L"yo"); + + BeginGroup(); + Insert(L"ら",L"ラ",L"ra"); + Insert(L"り",L"ăƒȘ",L"ri"); + Insert(L"る",L"ル",L"ru"); + Insert(L"れ",L"ハ",L"re"); + Insert(L"ろ",L"ロ",L"ro"); + + BeginGroup(); + Insert(L"わ",L"ワ",L"wa"); + Insert(L"ゐ",L"ヰ",L"wi"); + Insert(L"ゑ",L"ヱ",L"we"); + Insert(L"を",L"ăƒČ",L"wo"); + + BeginGroup(); + level--; + Insert(L"ん",L"ン",L"n"); + + BeginGroup(); + Insert(L"が",L"ガ",L"ga"); + Insert(L"ぎ",L"ゼ",L"gi"); + Insert(L"ぐ",L"グ",L"gu"); + Insert(L"げ",L"ă‚Č",L"ge"); + Insert(L"ご",L"ギ",L"go"); + + BeginGroup(); + Insert(L"ざ",L"ザ",L"za"); + Insert(L"じ",L"ゾ",L"ji"); + Insert(L"ず",L"ă‚ș",L"zu"); + Insert(L"ぜ",L"ă‚Œ",L"ze"); + Insert(L"ぞ",L"ă‚Ÿ",L"zo"); + + BeginGroup(); + Insert(L"だ",L"ダ",L"da"); + Insert(L"べ",L"ヂ",L"ji"); + Insert(L"い",L"ヅ",L"zu"); + Insert(L"で",L"デ",L"de"); + Insert(L"ど",L"ド",L"do"); + + BeginGroup(); + Insert(L"ば",L"バ",L"ba"); + Insert(L"び",L"ビ",L"bi"); + Insert(L"ぶ",L"ブ",L"bu"); + Insert(L"ăč",L"ベ",L"be"); + Insert(L"ăŒ",L"ボ",L"bo"); + + BeginGroup(); + Insert(L"ぱ",L"パ",L"pa"); + Insert(L"ぎ",L"ピ",L"pi"); + Insert(L"ぷ",L"プ",L"pu"); + Insert(L"ăș",L"ペ",L"pe"); + Insert(L"ăœ",L"ポ",L"po"); + + BeginGroup(); + Insert(L"きゃ",L"キャ",L"kya"); + Insert(L"きゅ",L"ă‚­ăƒ„",L"kyu"); + Insert(L"きょ",L"キョ",L"kyo"); + + BeginGroup(); + Insert(L"しゃ",L"ă‚·ăƒŁ",L"sha"); + Insert(L"しゅ",L"ă‚·ăƒ„",L"shu"); + Insert(L"しょ",L"ă‚·ăƒ§",L"sho"); + + BeginGroup(); + Insert(L"ちゃ",L"チャ",L"cha"); + Insert(L"ちゅ",L"チツ",L"chu"); + Insert(L"ちょ",L"チョ",L"cho"); + + BeginGroup(); + Insert(L"ă«ă‚ƒ",L"ニャ",L"nya"); + Insert(L"にゅ",L"ăƒ‹ăƒ„",L"nyu"); + Insert(L"にょ",L"ニョ",L"nyo"); + + BeginGroup(); + Insert(L"ăČゃ",L"ヒャ",L"hya"); + Insert(L"ăČゅ",L"ăƒ’ăƒ„",L"hyu"); + Insert(L"ăČょ",L"ヒョ",L"hyo"); + + BeginGroup(); + Insert(L"みゃ",L"ミャ",L"mya"); + Insert(L"みゅ",L"ăƒŸăƒ„",L"myu"); + Insert(L"みょ",L"ミョ",L"myo"); + + BeginGroup(); + Insert(L"りゃ",L"ăƒȘャ",L"rya"); + Insert(L"りゅ",L"ăƒȘツ",L"ryu"); + Insert(L"りょ",L"ăƒȘョ",L"ryo"); + + BeginGroup(); + Insert(L"ぎゃ",L"ゼャ",L"gya"); + Insert(L"ぎゅ",L"ă‚źăƒ„",L"gyu"); + Insert(L"ぎょ",L"ゼョ",L"gyo"); + + BeginGroup(); + Insert(L"じゃ",L"ゾャ",L"ja"); + Insert(L"じゅ",L"ă‚žăƒ„",L"ju"); + Insert(L"じょ",L"ゾョ",L"jo"); + + BeginGroup(); + Insert(L"ぱゃ",L"ヂャ",L"ja"); + Insert(L"ぱゅ",L"ăƒ‚ăƒ„",L"ju"); + Insert(L"ぱょ",L"ヂョ",L"jo"); + + BeginGroup(); + Insert(L"びゃ",L"ビャ",L"bya"); + Insert(L"びゅ",L"ăƒ“ăƒ„",L"byu"); + Insert(L"びょ",L"ビョ",L"byo"); + + BeginGroup(); + Insert(L"のゃ",L"ピャ",L"pya"); + Insert(L"のゅ",L"ăƒ”ăƒ„",L"pyu"); + Insert(L"のょ",L"ピョ",L"pyo"); + + BeginGroup(); + Insert(L"",L"ファ",L"fa"); + Insert(L"",L"フィ",L"fi"); + Insert(L"",L"フェ",L"fe"); + Insert(L"",L"ăƒ•ă‚©",L"fo"); + + BeginGroup(); + Insert(L"",L"ヮァ",L"va"); + Insert(L"",L"ヮィ",L"vi"); + Insert(L"",L"ノ",L"vu"); + Insert(L"",L"ヮェ",L"ve"); + Insert(L"",L"ăƒŽă‚©",L"vo"); + Insert(L"",L"ăƒ•ăƒ„",L"fyu"); + + BeginGroup(); + Insert(L"",L"むェ",L"ye"); + Insert(L"",L"ォィ",L"wi"); + Insert(L"",L"ォェ",L"we"); + Insert(L"",L"ă‚Šă‚©",L"wo"); + + BeginGroup(); + Insert(L"",L"ノャ",L"vya"); + Insert(L"",L"ノツ",L"vyu"); + Insert(L"",L"ノョ",L"vyo"); + + BeginGroup(); + Insert(L"",L"シェ",L"she"); + Insert(L"",L"ゾェ",L"je"); + Insert(L"",L"チェ",L"che"); + + BeginGroup(); + Insert(L"",L"ティ",L"ti"); + Insert(L"",L"ăƒ†ă‚„",L"tu"); + Insert(L"",L"ăƒ†ăƒ„",L"tyu"); + + BeginGroup(); + Insert(L"",L"ディ",L"di"); + Insert(L"",L"ăƒ‡ă‚„",L"du"); + Insert(L"",L"ăƒ‡ă‚„",L"dyu"); + + BeginGroup(); + Insert(L"",L"ツァ",L"tsa"); + Insert(L"",L"ツィ",L"tsi"); + Insert(L"",L"ツェ",L"tse"); + Insert(L"",L"ăƒ„ă‚©",L"tso"); +} + + +////////////// +// Destructor +KanaTable::~KanaTable() { +} + + +/////////////// +// Begin group +void KanaTable::BeginGroup() { + curGroup = _T(""); + level++; +} + + +////////// +// Insert +void KanaTable::Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep) { +#ifdef _UNICODE + KanaEntry entry(hira,kata,hep); + if (curGroup.IsEmpty()) curGroup = hep; + entry.group = curGroup; + entry.level = level; + if (!entry.hiragana.IsEmpty() && level > groups[0]) groups[0] = level; + if (!entry.katakana.IsEmpty() && level > groups[1]) groups[1] = level; + entries.push_back(entry); +#endif +} + + +///////////////////// +// Number of entries +int KanaTable::GetNumberEntries(int level) const { + if (level == -1) return entries.size(); + else { + int count = 0; + int n = entries.size(); + for (int i=0;ihepburn.Left(1); + bool add = false; + if (fl == _T("y") || fl == _T("a") || fl == _T("e") || fl == _T("i") || fl == _T("o") || fl == _T("u")) add = true; + if (fl == _T("n") && cur->hiragana == _T("っ")) add = true; + if (add) final += _T("'"); + } + + // 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; + vetoAdd = true; + } + } + } + + // Wapura + else { + if (longVowel) { + longVowel = false; + final += lastSyl.Right(1); + vetoAdd = true; + } + } + + // Add syllable + if (!vetoAdd) { + // Little tsu + if (ltsu) { + ltsu = false; + final += cur->hepburn.Left(1); + } + + // Standard + final += cur->hepburn; + } + + // Set last + if (cur) lastSyl = cur->hepburn; + } + } + return final; +} diff --git a/traydict/kana_table.h b/traydict/kana_table.h new file mode 100644 index 000000000..6e2b02f4a --- /dev/null +++ b/traydict/kana_table.h @@ -0,0 +1,83 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include + + +/////////////////////////// +// Hiragana/katakana entry +class KanaEntry { +public: + wxString hiragana; + wxString katakana; + wxString hepburn; + wxString group; + int level; + + KanaEntry(wxString hira,wxString kata,wxString hep) { + hiragana = hira; + katakana = kata; + hepburn = hep; + } +}; + + +/////////////////////////// +// Hiragana/Katakana table +class KanaTable { +private: + std::vector entries; + void Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep); + void BeginGroup(); + wxString curGroup; + int groups[2]; + int level; + +public: + KanaTable(); + ~KanaTable(); + + int GetNumberEntries(int level=-1) const; + int GetLevels(int table) const; + const KanaEntry &GetEntry(int i) const; + const KanaEntry *FindByRomaji(wxString romaji) const; + const KanaEntry *FindByKana(wxString kana) const; + + wxString KanaToRomaji(wxString kana,int type=1); +}; diff --git a/traydict/main.cpp b/traydict/main.cpp new file mode 100644 index 000000000..63ed704d6 --- /dev/null +++ b/traydict/main.cpp @@ -0,0 +1,115 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include "main.h" +#include "dict_window.h" + + +///////////////// +// Implement app +IMPLEMENT_APP(TrayDict) + + +////////////// +// Initialize +bool TrayDict::OnInit() { + // Configuration + SetAppName(_T("TrayDict")); + srand((unsigned)time(NULL)); + + // Get path + GetFullPath(argv[0]); + GetFolderName(); + + // Create the window + DictWindow *window = new DictWindow(); + window->Show(); + + // Initialization OK + return true; +} + + +///////////////////////////// +// Gets and stores full path +void TrayDict::GetFullPath(wxString arg) { + if (wxIsAbsolutePath(arg)) { + fullPath = arg; + return; + } + + // Is it a relative path? + wxString currentDir(wxFileName::GetCwd()); + if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH; + wxString str = currentDir + arg; + if (wxFileExists(str)) { + fullPath = str; + return; + } + + // OK, it's neither an absolute path nor a relative path. + // Search PATH. + wxPathList pathList; + pathList.AddEnvList(_T("PATH")); + str = pathList.FindAbsoluteValidPath(arg); + if (!str.IsEmpty()) { + fullPath = str; + return; + } + + fullPath = _T(""); + return; +} + + +/////////////////////////////////// +// Gets folder name from full path +void TrayDict::GetFolderName () { + folderName = _T(""); + wxFileName path(fullPath); + folderName += path.GetPath(wxPATH_GET_VOLUME); + folderName += _T("/"); +} + + +/////////// +// Statics +wxString TrayDict::folderName; +wxString TrayDict::fullPath; diff --git a/traydict/main.h b/traydict/main.h new file mode 100644 index 000000000..2d1a7b6e2 --- /dev/null +++ b/traydict/main.h @@ -0,0 +1,47 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +////////////// +// Main class +class TrayDict : public wxApp { +public: + bool OnInit(); + void GetFullPath(wxString arg); + void GetFolderName(); + + static wxString folderName; + static wxString fullPath; +}; diff --git a/traydict/res.rc b/traydict/res.rc new file mode 100644 index 000000000..f14c1570a --- /dev/null +++ b/traydict/res.rc @@ -0,0 +1,3 @@ +wxicon ICON "icon.ico" + +#include "wx/msw/wx.rc" diff --git a/traydict/systray.cpp b/traydict/systray.cpp new file mode 100644 index 000000000..3c06d48c0 --- /dev/null +++ b/traydict/systray.cpp @@ -0,0 +1,110 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include "systray.h" +#include "dict_window.h" + + +/////////////// +// Constructor +Systray::Systray(wxFrame *mast) { + master = mast; + SetIcon(wxICON(wxicon),_T("TrayDict")); +} + + +////////////// +// Destructor +Systray::~Systray() { +} + + +/////////////// +// Event table +BEGIN_EVENT_TABLE(Systray,wxTaskBarIcon) + EVT_TASKBAR_LEFT_UP(Systray::OnLeftClick) + EVT_MENU(SYSTRAY_OPEN,Systray::OnOpen) + EVT_MENU(SYSTRAY_EXIT,Systray::OnExit) +END_EVENT_TABLE() + + +////////////// +// Left click +void Systray::OnLeftClick(wxTaskBarIconEvent &event) { + if (master->IsShown()) master->Hide(); + else BringUp(); +} + + +//////// +// Open +void Systray::OnOpen(wxCommandEvent &event) { + if (master->IsShown()) master->Hide(); + else BringUp(); +} + + +//////// +// Exit +void Systray::OnExit(wxCommandEvent &event) { + master->Destroy(); +} + + +///////// +// Popup +wxMenu* Systray::CreatePopupMenu() { + wxMenu *popup = new wxMenu(); + if (master->IsShown()) popup->Append(SYSTRAY_OPEN,_T("Hide")); + else popup->Append(SYSTRAY_OPEN,_T("Show")); + popup->Append(SYSTRAY_EXIT,_T("Exit")); + return popup; +} + + +//////////// +// Bring up +void Systray::BringUp() { + //if (IsOk()) RemoveIcon(); + master->Show(); + master->Restore(); + master->Raise(); + ((DictWindow*)master)->entry->SetFocus(); +} diff --git a/traydict/systray.h b/traydict/systray.h new file mode 100644 index 000000000..4e907cf3e --- /dev/null +++ b/traydict/systray.h @@ -0,0 +1,68 @@ +// Copyright (c) 2006, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include + + +////////////////////// +// Systray icon class +class Systray : public wxTaskBarIcon { +private: + wxFrame *master; + + void OnLeftClick(wxTaskBarIconEvent &event); + void OnExit(wxCommandEvent &event); + void OnOpen(wxCommandEvent &event); + wxMenu* CreatePopupMenu(); + +public: + Systray(wxFrame *master); + ~Systray(); + + void BringUp(); + + DECLARE_EVENT_TABLE(); +}; + + +/////// +// IDs +enum { + SYSTRAY_EXIT = 1500, + SYSTRAY_OPEN +}; diff --git a/traydict/text_file_reader.cpp b/traydict/text_file_reader.cpp new file mode 100644 index 000000000..232a18cc3 --- /dev/null +++ b/traydict/text_file_reader.cpp @@ -0,0 +1,238 @@ +// Copyright (c) 2005, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include +#include +#include +#include "text_file_reader.h" + + +/////////////// +// Constructor +TextFileReader::TextFileReader(wxString _filename,wxString enc,bool _trim) { + // Setup + open = false; + customConv = false; + trim = _trim; + filename = _filename; + + // Open file + Open(); + + // Set encoding + encoding = enc; + if (encoding.IsEmpty()) encoding = GetEncoding(filename); + SetEncodingConfiguration(); +} + + +////////////// +// Destructor +TextFileReader::~TextFileReader() { + Close(); + + // Clean up conversion + if (customConv) delete conv; +} + + +/////////////////////////// +// Determine file encoding +wxString TextFileReader::GetEncoding(const wxString _filename) { + // Prepare + using namespace std; + unsigned char b[4]; + for (int i=0;i<4;i++) b[i] = 0; + + // Read four bytes from file + ifstream ifile; + ifile.open(_filename.mb_str(wxConvLocal)); + if (!ifile.is_open()) { + return _T("unknown"); + } + ifile.read((char*)b,4); + ifile.close(); + + // Try to get the byte order mark from them + if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF) return _T("UTF-8"); + else if (b[0] == 0xFF && b[1] == 0xFE && b[2] == 0x00 && b[3] == 0x00) return _T("UTF-32LE"); + else if (b[0] == 0x00 && b[1] == 0x00 && b[2] == 0xFE && b[3] == 0xFF) return _T("UTF-32BE"); + else if (b[0] == 0xFF && b[1] == 0xFE) return _T("UTF-16LE"); + else if (b[0] == 0xFE && b[1] == 0xFF) return _T("UTF-16BE"); + else if (b[0] == 0x2B && b[1] == 0x2F && b[2] == 0x76) return _T("UTF-7"); + + // Try to guess UTF-16 + else if (b[0] == 0x00 && b[2] == 0x00) return _T("UTF-16BE"); + else if (b[1] == 0x00 && b[3] == 0x00) return _T("UTF-16LE"); + + // Fallback to ascii + return _T("Local"); +} + + +////////////////////////////// +// Set encoding configuration +void TextFileReader::SetEncodingConfiguration() { + // Set encoding configuration + swap = false; + Is16 = false; + customConv = false; + conv = NULL; + if (encoding == _T("UTF-8")) { + conv = new wxMBConvUTF8; + customConv = true; + } + else if (encoding == _T("UTF-16LE")) { + Is16 = true; + } + else if (encoding == _T("UTF-16BE")) { + Is16 = true; + swap = true; + } + else if (encoding == _T("UTF-7")) { + conv = new wxCSConv(encoding); + customConv = true; + } + else if (encoding == _T("Local")) { + conv = wxConvCurrent; + } + else { + conv = new wxCSConv(encoding); + customConv = true; + } +} + + +////////////////////////// +// Reads a line from file +wxString TextFileReader::ReadLineFromFile() { + Open(); + wxString wxbuffer = _T(""); + + // Read UTF-16 line from file + if (Is16) { + char charbuffer[3]; + charbuffer[2] = 0; + char aux; + wchar_t ch = 0; + int n = 0; + while (ch != L'\n' && !file.eof()) { + // Read two chars from file + file.read(charbuffer,2); + + // Swap bytes for big endian + if (swap) { + aux = charbuffer[0]; + charbuffer[0] = charbuffer[1]; + charbuffer[1] = aux; + } + + // Convert two chars into a widechar and append to string + ch = *((wchar_t*)charbuffer); + wxbuffer += ch; + n++; + } + } + + // Read ASCII/UTF-8 line from file + else { + std::string buffer; + getline(file,buffer); + wxString lineresult(buffer.c_str(),*conv); + wxbuffer = lineresult; + } + + // Remove line breaks + wxbuffer.Replace(_T("\r"),_T("")); + wxbuffer.Replace(_T("\n"),_T("")); + + // Final string + wxString final = wxString(wxbuffer); + + // Remove BOM + if (final[0] == 0xFEFF) { + final = final.Mid(1); + } + + // Trim + if (trim) { + final.Trim(true); + final.Trim(false); + } + return final; +} + + +///////////// +// Open file +void TextFileReader::Open() { + if (open) return; + file.open(filename.mb_str(wxConvLocal),std::ios::in | std::ios::binary); + if (!file.is_open()) { + throw _T("Failed opening file."); + } + open = true; +} + + +////////////// +// Close file +void TextFileReader::Close() { + if (!open) return; + file.close(); + open = false; +} + + +////////////////////////////////// +// Checks if there's more to read +bool TextFileReader::HasMoreLines() { + return (!file.eof()); +} + + +//////////////////////////////// +// Ensure that charset is valid +void TextFileReader::EnsureValid(wxString enc) { + if (enc == _T("unknown") || enc == _T("UTF-32BE") || enc == _T("UTF-32LE")) { + wxString error = _T("Character set "); + error += enc; + error += _T(" is not supported."); + throw error; + } +} diff --git a/traydict/text_file_reader.h b/traydict/text_file_reader.h new file mode 100644 index 000000000..f0bdf604e --- /dev/null +++ b/traydict/text_file_reader.h @@ -0,0 +1,77 @@ +// Copyright (c) 2005, 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 Aegisub 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#ifndef TEXT_FILE_READER_H +#define TEXT_FILE_READER_H + + +/////////// +// Headers +#include +#include +#include + + +///////// +// Class +class TextFileReader { +private: + wxString filename; + wxString encoding; + std::ifstream file; + wxMBConv *conv; + bool Is16; + bool swap; + bool open; + bool customConv; + bool trim; + + void Open(); + void Close(); + void SetEncodingConfiguration(); + +public: + TextFileReader(wxString filename,wxString encoding=_T(""),bool trim=true); + ~TextFileReader(); + + wxString ReadLineFromFile(); + bool HasMoreLines(); + static void EnsureValid(const wxString encoding); + static wxString GetEncoding(const wxString filename); +}; + + +#endif