diff --git a/kanamemo/game_display.cpp b/kanamemo/game_display.cpp new file mode 100644 index 000000000..3aad1e25a Binary files /dev/null and b/kanamemo/game_display.cpp differ 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 000000000..7b70e91f8 Binary files /dev/null and b/kanamemo/icon.ico differ 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 000000000..a28419f95 Binary files /dev/null and b/traydict/icon.ico differ 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