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

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"
1.1.1.7 ! root       14: #include "scheduler.h"
1.1.1.3   root       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: 
1.1.1.7 ! root       56:        rv = gMainApp.Init1(false, argc, argv);
1.1.1.5   root       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.1.7 ! root       86:                return EXIT_FAILURE;
1.1       root       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.1.7 ! root       96:                        return EXIT_FAILURE;
1.1       root       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.7 ! root      103:        // 引数処理が終わったので、スレッド作成を伴う初期化。
        !           104:        if (!gMainApp.Init2()) {
        !           105:                return EXIT_FAILURE;
        !           106:        }
        !           107: 
        !           108:        // VM にコールバックを登録
        !           109:        gScheduler->SetPowerOffCallback(wxmainframe_poweroff_callback);
        !           110:        if (gMPU680x0) {
        !           111:                gMPU680x0->SetHaltCallback(wxmainframe_halt_callback, this);
1.1       root      112:        }
                    113: 
1.1.1.2   root      114:        // メインウィンドウ
                    115:        gMainFrame = new WXMainFrame(NULL);
                    116:        gMainFrame->Show(true);
                    117:        SetTopWindow(gMainFrame);
1.1.1.6   root      118: 
                    119:        return inherited::OnRun();
1.1       root      120: }
                    121: 
                    122: // -M オプションの解析。書式は
                    123: //  -M <name>[,<name>[,...]]
                    124: //  -M help
                    125: // 継続不能なエラーなら false を返す。
                    126: bool
                    127: WXApp::ParseMonitors(const wxString& str)
                    128: {
1.1.1.3   root      129:        int s;
                    130:        int end;
1.1       root      131: 
1.1.1.3   root      132:        if (str == "help") {
1.1       root      133:                for (int i = 0; i < WinID_MAX; i++) {
1.1.1.3   root      134:                        auto& info = WXMainFrame::monitor_info[i];
                    135:                        if (gMainApp.HasVMFeature(info.feature)) {
                    136:                                fprintf(stderr, " %s\n", info.name);
                    137:                        }
1.1       root      138:                }
                    139:                return false;
                    140:        }
                    141: 
1.1.1.3   root      142:        for (s = 0, end = 0; s < str.Length(); s = end + 1) {
                    143:                end = str.find(',', s);
                    144:                if (end == wxString::npos) {
                    145:                        end = str.size();
                    146:                }
                    147:                wxString word = str.SubString(s, end - 1);
1.1       root      148:                int i = SearchMonitorName(word);
                    149:                if (i < 0) {
1.1.1.3   root      150:                        warnx("Unknown window name \"%s\"", (const char *)word.mb_str());
1.1       root      151:                        return false;
                    152:                }
                    153:                WXMainFrame::monitor_start[i] = true;
                    154:        }
                    155:        return true;
                    156: }
                    157: 
                    158: int
                    159: WXApp::SearchMonitorName(const char *name)
                    160: {
                    161:        for (int i = 0; i < WinID_MAX; i++) {
1.1.1.3   root      162:                auto& info = WXMainFrame::monitor_info[i];
                    163:                if (gMainApp.HasVMFeature(info.feature) &&
                    164:                    strcmp(name, info.name) == 0)
                    165:                {
1.1       root      166:                        return i;
                    167:                }
                    168:        }
                    169:        return -1;
                    170: }

unix.superglobalmegacorp.com

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