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

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.9 ! root       42:        auto mainframe = dynamic_cast<WXMainFrame*>(GetParent());
        !            43:        mainframe->DeleteWindow(this);
1.1       root       44: }
1.1.1.2   root       45: 
1.1.1.7   root       46: // フォントサイズ変更
1.1.1.3   root       47: void
1.1.1.7   root       48: WXSubWindow::FontChanged()
1.1.1.3   root       49: {
1.1.1.7   root       50:        // WXTextPanel 派生の子コントロールに対し FontChanged() を呼ぶ
                     51:        for (auto child : GetChildren()) {
                     52:                auto textpanel = dynamic_cast<WXTextPanel*>(child);
1.1.1.3   root       53:                if (textpanel) {
1.1.1.7   root       54:                        textpanel->FontChanged();
1.1.1.3   root       55:                }
                     56:        }
                     57: 
1.1.1.7   root       58:        DoSize();
                     59: }
                     60: 
                     61: // 中身に応じてこのウィンドウの大きさを変更
                     62: void
                     63: WXSubWindow::DoSize()
                     64: {
                     65:        wxSize csize;
                     66: 
                     67:        auto *topsizer = GetSizer();
                     68:        if (topsizer) {
                     69:                // Sizer があればそれがサイズを知っている
                     70:                csize = topsizer->GetMinSize();
                     71:        } else {
                     72:                // Sizer を使ってなければ子コントロールは1人のはず
                     73:                auto& children = GetChildren();
                     74:                assert(children.GetCount() == 1);
                     75:                auto child = children[0];
                     76:                csize = child->GetMinSize();
                     77:        }
                     78:        SetClientSize(csize);
1.1.1.3   root       79: }
                     80: 
1.1.1.8   root       81: // このサブウィンドウが縦リサイズ可能なテキストパネルの場合の Layout()。
                     82: // 本来は screen を持っている継承クラスが個別に行うことだが、定形処理なので
                     83: // ここでサブルーチンとして用意しておく。必要なら継承クラスが呼ぶこと。
1.1.1.7   root       84: bool
1.1.1.8   root       85: WXSubWindow::LayoutTextVResize(const WXTextScreen *screen, int fixed_height)
1.1.1.7   root       86: {
                     87:        if (inherited::Layout() == false) {
                     88:                return false;
1.1.1.3   root       89:        }
                     90: 
1.1.1.7   root       91:        wxSize tsize = GetSizer()->ComputeFittingClientSize(this);
                     92: 
                     93:        // 高さ計算。
                     94:        // 高さの最小は fixed と TextScreen 2行分にしておく。
                     95:        int h = fixed_height;
                     96:        h += screen->GetPaddingTop();
                     97:        h += screen->GetFontHeight() * 2;
                     98:        h += screen->GetPaddingBottom();
                     99: 
                    100:        // サイズを変える時は、大きくする時は Max を先に、小さくする時は Min を
                    101:        // 先に変えないと、サイズ制約の不整合の GTK ワーニングが出てしまう。
                    102:        // うーんこの API…。
                    103:        wxSize csize = GetClientSize();
                    104:        if (tsize.x > csize.x) {
                    105:                SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord));
                    106:                SetMinClientSize(wxSize(tsize.x, h));
1.1.1.3   root      107:        } else {
1.1.1.7   root      108:                SetMinClientSize(wxSize(tsize.x, h));
                    109:                SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord));
1.1.1.3   root      110:        }
                    111: 
1.1.1.7   root      112:        return true;
1.1.1.4   root      113: }

unix.superglobalmegacorp.com

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