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

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

unix.superglobalmegacorp.com

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