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

1.1       root        1: //
                      2: // nono
1.1.1.2   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.7 ! root        7: //
        !             8: // サブウィンドウ
        !             9: //
        !            10: 
1.1       root       11: #include "wxsubwindow.h"
1.1.1.7 ! root       12: #include "fontmanager.h"
1.1.1.2   root       13: #include "wxmainframe.h"
1.1.1.3   root       14: #include "wxtextscreen.h"
1.1       root       15: 
                     16: //
1.1.1.7 ! root       17: // サブウィンドウ (基本クラス)
1.1       root       18: //
                     19: 
                     20: // イベントテーブル
                     21: wxBEGIN_EVENT_TABLE(WXSubWindow, inherited)
                     22:        EVT_CLOSE(WXSubWindow::OnClose)
                     23: wxEND_EVENT_TABLE()
                     24: 
1.1.1.5   root       25: // コンストラクタ
1.1       root       26: WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name,
                     27:        int style)
1.1.1.5   root       28:        : inherited(parent, id, name, wxDefaultPosition, wxDefaultSize, style)
1.1       root       29: {
                     30: }
                     31: 
                     32: // デストラクタ
                     33: WXSubWindow::~WXSubWindow()
                     34: {
                     35: }
                     36: 
                     37: // クローズイベント
                     38: void
                     39: WXSubWindow::OnClose(wxCloseEvent& event)
                     40: {
                     41:        // ウィンドウリストから自身を削除
1.1.1.5   root       42:        gMainFrame->DeleteWindow(this);
1.1       root       43: }
1.1.1.2   root       44: 
1.1.1.7 ! root       45: // フォントサイズ変更
1.1.1.3   root       46: void
1.1.1.7 ! root       47: WXSubWindow::FontChanged()
1.1.1.3   root       48: {
1.1.1.7 ! root       49:        // WXTextPanel 派生の子コントロールに対し FontChanged() を呼ぶ
        !            50:        for (auto child : GetChildren()) {
        !            51:                auto textpanel = dynamic_cast<WXTextPanel*>(child);
1.1.1.3   root       52:                if (textpanel) {
1.1.1.7 ! root       53:                        textpanel->FontChanged();
1.1.1.3   root       54:                }
                     55:        }
                     56: 
1.1.1.7 ! root       57:        DoSize();
        !            58: }
        !            59: 
        !            60: // 中身に応じてこのウィンドウの大きさを変更
        !            61: void
        !            62: WXSubWindow::DoSize()
        !            63: {
        !            64:        wxSize csize;
        !            65: 
        !            66:        auto *topsizer = GetSizer();
        !            67:        if (topsizer) {
        !            68:                // Sizer があればそれがサイズを知っている
        !            69:                csize = topsizer->GetMinSize();
        !            70:        } else {
        !            71:                // Sizer を使ってなければ子コントロールは1人のはず
        !            72:                auto& children = GetChildren();
        !            73:                assert(children.GetCount() == 1);
        !            74:                auto child = children[0];
        !            75:                csize = child->GetMinSize();
        !            76:        }
        !            77:        SetClientSize(csize);
1.1.1.3   root       78: }
                     79: 
                     80: 
                     81: //
                     82: // 縦リサイズ可能なサブウィンドウ
                     83: //
                     84: 
                     85: // コンストラクタ
                     86: WXVResizeSubWindow::WXVResizeSubWindow(wxWindow *parent, wxWindowID id,
                     87:        const wxString& name)
                     88:        : inherited(parent, id, name, DEFAULT_STYLE | wxRESIZE_BORDER)
                     89: {
                     90: }
                     91: 
                     92: // デストラクタ
                     93: WXVResizeSubWindow::~WXVResizeSubWindow()
                     94: {
                     95: }
                     96: 
                     97: void
1.1.1.7 ! root       98: WXVResizeSubWindow::FontChanged()
1.1.1.3   root       99: {
1.1.1.7 ! root      100:        screen->FontChanged();
        !           101:        Layout();
1.1.1.3   root      102:        DoSize();
                    103: }
                    104: 
                    105: void
1.1.1.7 ! root      106: WXVResizeSubWindow::DoSize()
1.1.1.3   root      107: {
1.1.1.7 ! root      108:        wxSize tsize = GetSizer()->ComputeFittingClientSize(this);
        !           109:        SetClientSize(tsize);
        !           110: }
1.1.1.3   root      111: 
1.1.1.7 ! root      112: bool
        !           113: WXVResizeSubWindow::Layout()
        !           114: {
        !           115:        if (inherited::Layout() == false) {
        !           116:                return false;
1.1.1.3   root      117:        }
                    118: 
1.1.1.7 ! root      119:        wxSize tsize = GetSizer()->ComputeFittingClientSize(this);
        !           120: 
        !           121:        // 高さ計算。
        !           122:        // 高さの最小は fixed と TextScreen 2行分にしておく。
        !           123:        int h = fixed_height;
        !           124:        h += screen->GetPaddingTop();
        !           125:        h += screen->GetFontHeight() * 2;
        !           126:        h += screen->GetPaddingBottom();
        !           127: 
        !           128:        // サイズを変える時は、大きくする時は Max を先に、小さくする時は Min を
        !           129:        // 先に変えないと、サイズ制約の不整合の GTK ワーニングが出てしまう。
        !           130:        // うーんこの API…。
        !           131:        wxSize csize = GetClientSize();
        !           132:        if (tsize.x > csize.x) {
        !           133:                SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord));
        !           134:                SetMinClientSize(wxSize(tsize.x, h));
1.1.1.3   root      135:        } else {
1.1.1.7 ! root      136:                SetMinClientSize(wxSize(tsize.x, h));
        !           137:                SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord));
1.1.1.3   root      138:        }
                    139: 
1.1.1.7 ! root      140:        return true;
1.1.1.4   root      141: }

unix.superglobalmegacorp.com

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