Annotation of nono/wx/wxapp.cpp, revision 1.1.1.6

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #include "wxmainframe.h"
                      8: #include "wxmainview.h"
                      9: #include "wxtextpanel.h"
1.1.1.4   root       10: #include "wxversion.h"
1.1       root       11: #include "mainapp.h"
1.1.1.3   root       12: #include "mpu680x0.h"
                     13: #include "mpu88xx0.h"
                     14: #include "vm.h"
                     15: #include <wx/intl.h>
1.1       root       16: 
                     17: // イベントタイプの定義
1.1.1.3   root       18: wxDEFINE_EVENT(WXW_EVT_CREATE, wxCommandEvent);
                     19: wxDEFINE_EVENT(WXW_EVT_HALT_NOTIFY, wxCommandEvent);
1.1       root       20: 
                     21: class WXApp
                     22:        : public wxApp
                     23: {
1.1.1.6 ! root       24:        using inherited = wxApp;
1.1       root       25:  public:
                     26:        bool OnInit();
1.1.1.6 ! root       27:        int OnRun() override;
1.1       root       28:  private:
                     29:        bool ParseMonitors(const wxString& str);
                     30:        int SearchMonitorName(const char *name);
1.1.1.3   root       31: 
                     32:        wxLocale locale;
1.1       root       33: };
                     34: 
1.1.1.3   root       35: // IMPLEMENT_APP() は闇マクロすぎて clang のちからには耐えられない
                     36: #if defined(__clang__)
                     37: #pragma clang diagnostic push
                     38: #pragma clang diagnostic ignored "-Weverything"
                     39: #endif
1.1       root       40: IMPLEMENT_APP(WXApp)
1.1.1.3   root       41: #if defined(__clang__)
                     42: #pragma clang diagnostic pop
                     43: #endif
1.1       root       44: 
                     45: bool
                     46: WXApp::OnInit()
                     47: {
1.1.1.6 ! root       48:        return true;
        !            49: }
        !            50: 
        !            51: int
        !            52: WXApp::OnRun()
        !            53: {
1.1.1.5   root       54:        int rv;
                     55: 
                     56:        rv = gMainApp.Init(false, argc, argv);
                     57:        if (rv != MainApp::PASS) {
1.1.1.6 ! root       58:                return rv;
1.1       root       59:        }
                     60: 
1.1.1.3   root       61:        // 環境変数 $NONO_BUILD_HOME が定義されていればカタログ検索パスに
                     62:        // $NONO_BUILD_HOME/po を追加する (システムパスより前に挿入される)。
                     63:        // カタログ開発時にワークツリーにあるカタログを見るため。
                     64:        locale.Init(wxLANGUAGE_DEFAULT);
                     65:        const char *build_home = getenv("NONO_BUILD_HOME");
                     66:        if (build_home) {
                     67:                wxString path(build_home);
                     68:                path += "/po";
                     69:                wxLocale::AddCatalogLookupPathPrefix(path);
                     70:        }
                     71:        locale.AddCatalog("nono");
                     72: 
1.1.1.2   root       73:        // --fontsize テキスト系コントロールのフォントサイズ
                     74:        // 紛らわしいが ::global_fontsize は 12, 16 とかいう値。
1.1.1.4   root       75:        // WXTextPanel::global_fontsize (FontId) は enum 値。
                     76:        FontId fontid;
1.1.1.2   root       77:        switch (gMainApp.fontsize) {
                     78:         case 12:
1.1.1.4   root       79:                fontid = FontId::_6x12;
1.1.1.2   root       80:                break;
                     81:         case 16:
1.1.1.4   root       82:                fontid = FontId::_8x16;
1.1.1.2   root       83:                break;
                     84:         default:
                     85:                warnx("invalid fontsize: %d", gMainApp.fontsize);
1.1       root       86:                return false;
                     87:        }
1.1.1.4   root       88:        WXTextPanel::global_fontid = fontid;
                     89: 
                     90:        // グローバルオブジェクト (どこでやるのがいいか)
                     91:        gHostInfo.reset(new HostInfoMonitor());
1.1       root       92: 
                     93:        // -M 起動時に表示するモニタ
1.1.1.2   root       94:        if (!gMainApp.monitor_opt.empty()) {
                     95:                if (!ParseMonitors(gMainApp.monitor_opt)) {
1.1       root       96:                        return false;
                     97:                }
                     98:        }
                     99: 
1.1.1.2   root      100:        // -s screen scale
                    101:        WXMainView::screen_scale = gMainApp.screen_scale;
1.1       root      102: 
1.1.1.2   root      103:        // 引数処理が終わったので VM 開始。
                    104:        if (!gMainApp.Start()) {
1.1.1.6 ! root      105:                return 1;
1.1       root      106:        }
                    107: 
1.1.1.2   root      108:        // メインウィンドウ
                    109:        gMainFrame = new WXMainFrame(NULL);
                    110:        gMainFrame->Show(true);
                    111:        SetTopWindow(gMainFrame);
1.1.1.6 ! root      112: 
        !           113:        return inherited::OnRun();
1.1       root      114: }
                    115: 
                    116: // -M オプションの解析。書式は
                    117: //  -M <name>[,<name>[,...]]
                    118: //  -M help
                    119: // 継続不能なエラーなら false を返す。
                    120: bool
                    121: WXApp::ParseMonitors(const wxString& str)
                    122: {
1.1.1.3   root      123:        int s;
                    124:        int end;
1.1       root      125: 
1.1.1.3   root      126:        if (str == "help") {
1.1       root      127:                for (int i = 0; i < WinID_MAX; i++) {
1.1.1.3   root      128:                        auto& info = WXMainFrame::monitor_info[i];
                    129:                        if (gMainApp.HasVMFeature(info.feature)) {
                    130:                                fprintf(stderr, " %s\n", info.name);
                    131:                        }
1.1       root      132:                }
                    133:                return false;
                    134:        }
                    135: 
1.1.1.3   root      136:        for (s = 0, end = 0; s < str.Length(); s = end + 1) {
                    137:                end = str.find(',', s);
                    138:                if (end == wxString::npos) {
                    139:                        end = str.size();
                    140:                }
                    141:                wxString word = str.SubString(s, end - 1);
1.1       root      142:                int i = SearchMonitorName(word);
                    143:                if (i < 0) {
1.1.1.3   root      144:                        warnx("Unknown window name \"%s\"", (const char *)word.mb_str());
1.1       root      145:                        return false;
                    146:                }
                    147:                WXMainFrame::monitor_start[i] = true;
                    148:        }
                    149:        return true;
                    150: }
                    151: 
                    152: int
                    153: WXApp::SearchMonitorName(const char *name)
                    154: {
                    155:        for (int i = 0; i < WinID_MAX; i++) {
1.1.1.3   root      156:                auto& info = WXMainFrame::monitor_info[i];
                    157:                if (gMainApp.HasVMFeature(info.feature) &&
                    158:                    strcmp(name, info.name) == 0)
                    159:                {
1.1       root      160:                        return i;
                    161:                }
                    162:        }
                    163:        return -1;
                    164: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.