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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #include "vm.h"
                      7: #include "wxheader.h"
                      8: #include "wxmainframe.h"
                      9: #include "wxmainview.h"
                     10: #include "wxtextpanel.h"
                     11: #include "mainapp.h"
                     12: 
                     13: // イベントタイプの定義
                     14: DEFINE_EVENT_TYPE(WXW_EVT_CREATE);
                     15: DEFINE_EVENT_TYPE(WXW_EVT_MONITOR_UPDATE);
                     16: 
                     17: class WXApp
                     18:        : public wxApp
                     19: {
                     20:  public:
                     21:        bool OnInit();
                     22:  private:
                     23:        bool ParseMonitors(const wxString& str);
                     24:        int SearchMonitorName(const char *name);
                     25: };
                     26: 
                     27: IMPLEMENT_APP(WXApp)
                     28: 
                     29: bool
                     30: WXApp::OnInit()
                     31: {
1.1.1.2 ! root       32:        if (!gMainApp.Init(false, argc, argv)) {
1.1       root       33:                return false;
                     34:        }
                     35: 
1.1.1.2 ! root       36:        // --fontsize テキスト系コントロールのフォントサイズ
        !            37:        // 紛らわしいが ::global_fontsize は 12, 16 とかいう値。
        !            38:        // WXTextPanel::global_fontsize (fontsize_t) は enum 値。
        !            39:        fontsize_t fontsize;
        !            40:        switch (gMainApp.fontsize) {
        !            41:         case 12:
        !            42:                fontsize = FONT_6x12;
        !            43:                break;
        !            44:         case 16:
        !            45:                fontsize = FONT_8x16;
        !            46:                break;
        !            47:         case 24:
        !            48:                fontsize = FONT_12x24;
        !            49:                break;
        !            50:         default:
        !            51:                warnx("invalid fontsize: %d", gMainApp.fontsize);
1.1       root       52:                return false;
                     53:        }
1.1.1.2 ! root       54:        WXTextPanel::global_fontsize = fontsize;
1.1       root       55: 
                     56:        // -M 起動時に表示するモニタ
1.1.1.2 ! root       57:        if (!gMainApp.monitor_opt.empty()) {
        !            58:                if (!ParseMonitors(gMainApp.monitor_opt)) {
1.1       root       59:                        return false;
                     60:                }
                     61:        }
                     62: 
1.1.1.2 ! root       63:        // -s screen scale
        !            64:        WXMainView::screen_scale = gMainApp.screen_scale;
1.1       root       65: 
1.1.1.2 ! root       66:        // 引数処理が終わったので VM 開始。
        !            67:        if (!gMainApp.Start()) {
        !            68:                return false;
1.1       root       69:        }
                     70: 
1.1.1.2 ! root       71:        // メインウィンドウ
        !            72:        gMainFrame = new WXMainFrame(NULL);
        !            73:        gMainFrame->Show(true);
        !            74:        SetTopWindow(gMainFrame);
1.1       root       75:        return true;
                     76: }
                     77: 
                     78: // -M オプションの解析。書式は
                     79: //  -M <name>[,<name>[,...]]
                     80: //  -M help
                     81: // 継続不能なエラーなら false を返す。
                     82: bool
                     83: WXApp::ParseMonitors(const wxString& str)
                     84: {
                     85:        const char *sep = ",";
                     86:        char *word;
                     87:        char *last;
                     88:        char buf[str.Length() + 1];
                     89: 
                     90:        if (str == wxT("help")) {
                     91:                for (int i = 0; i < WinID_MAX; i++) {
                     92:                        fprintf(stderr, " %s\n", WXMainFrame::monitor_names[i]);
                     93:                }
                     94:                return false;
                     95:        }
                     96: 
                     97:        // 由緒正しい C でパースしてしまう
                     98:        strcpy(buf, (const char *)str.mb_str());
                     99:        for (word = strtok_r(buf, sep, &last);
                    100:             word;
                    101:             word = strtok_r(NULL, sep, &last))
                    102:        {
                    103:                int i = SearchMonitorName(word);
                    104:                if (i < 0) {
                    105:                        warnx("Unknown window name \"%s\"", word);
                    106:                        return false;
                    107:                }
                    108:                WXMainFrame::monitor_start[i] = true;
                    109:        }
                    110:        return true;
                    111: }
                    112: 
                    113: int
                    114: WXApp::SearchMonitorName(const char *name)
                    115: {
                    116:        for (int i = 0; i < WinID_MAX; i++) {
                    117:                if (strcmp(name, WXMainFrame::monitor_names[i]) == 0) {
                    118:                        return i;
                    119:                }
                    120:        }
                    121:        return -1;
                    122: }

unix.superglobalmegacorp.com

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