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

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

unix.superglobalmegacorp.com

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