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

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

unix.superglobalmegacorp.com

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