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

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: 
                      7: #include "wxsubwindow.h"
1.1.1.4 ! root        8: #include "wxcolor.h"
1.1.1.2   root        9: #include "wxmainframe.h"
1.1.1.3   root       10: #include "wxtextscreen.h"
1.1       root       11: 
                     12: //
                     13: // サブウィンドウ
                     14: //
                     15: 
                     16: // イベントテーブル
                     17: wxBEGIN_EVENT_TABLE(WXSubWindow, inherited)
                     18:        EVT_CLOSE(WXSubWindow::OnClose)
                     19: wxEND_EVENT_TABLE()
                     20: 
                     21: // コンストラクタ (スタイル指定あり)
                     22: WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name,
                     23:        int style)
1.1.1.4 ! root       24:        : inherited(parent, id, name, style)
1.1       root       25: {
                     26: }
                     27: 
                     28: // コンストラクタ (スタイル指定なし)
                     29: WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name)
                     30:        : WXSubWindow(parent, id, name, DEFAULT_STYLE)
                     31: {
                     32: }
                     33: 
                     34: // デストラクタ
                     35: WXSubWindow::~WXSubWindow()
                     36: {
                     37: }
                     38: 
                     39: // クローズイベント
                     40: void
                     41: WXSubWindow::OnClose(wxCloseEvent& event)
                     42: {
                     43:        // ウィンドウリストから自身を削除
                     44:        gMainFrame->DeleteWindow(GetId());
                     45: }
1.1.1.2   root       46: 
1.1.1.3   root       47: // テキスト系パネルのフォントサイズを変更する
                     48: void
                     49: WXSubWindow::SetFontSize(FontId fontid)
                     50: {
                     51:        // このウィンドウの子のうち..
                     52:        wxWindowList& children = GetChildren();
                     53:        for (wxWindow *child : children) {
                     54:                // すべての WXTextPanel の継承クラスだけに対して
                     55:                // フォントサイズの変更を指示する。
                     56:                WXTextPanel *textpanel = dynamic_cast<WXTextPanel*>(child);
                     57:                if (textpanel) {
                     58:                        textpanel->SetFontSize(fontid);
                     59:                }
                     60:        }
                     61: 
                     62:        // 大きさを変更
                     63:        Fit();
                     64: }
                     65: 
                     66: 
                     67: //
                     68: // 縦リサイズ可能なサブウィンドウ
                     69: //
                     70: 
                     71: // コンストラクタ
                     72: WXVResizeSubWindow::WXVResizeSubWindow(wxWindow *parent, wxWindowID id,
                     73:        const wxString& name)
                     74:        : inherited(parent, id, name, DEFAULT_STYLE | wxRESIZE_BORDER)
                     75: {
                     76: }
                     77: 
                     78: // デストラクタ
                     79: WXVResizeSubWindow::~WXVResizeSubWindow()
                     80: {
                     81: }
                     82: 
                     83: // フォントサイズ変更
                     84: void
                     85: WXVResizeSubWindow::SetFontSize(FontId fontid)
                     86: {
                     87:        // 親クラスの処理をして..
                     88:        inherited::SetFontSize(fontid);
                     89: 
                     90:        // フォントサイズが確定したので、継承先のウィンドウサイズ計算処理。
                     91:        // 引数なしの DoSize() は継承先ごとに実装する仮想関数、
                     92:        // そいつが共通の CalcVSize(int) を呼び出してくる。
                     93:        DoSize();
                     94: }
                     95: 
                     96: // ウィンドウサイズを再計算する共通部分。
                     97: //
                     98: // テキスト系ウィンドウではウィンドウの縦方向のリサイズは1行の高さ分ずつ
                     99: // 行いたいが、そのためにはこのウィンドウのクライアント領域が1行の高さの
                    100: // 整数倍になっている必要がある。TextScreen 自身は行の高さの整数倍だが、
                    101: // 他に余白や別コントロールを追加して、フォントサイズも動的に変化すると
                    102: // なると、諸々自動で計算したい。
                    103: // フォントサイズが確定したところで呼び出すこと。
                    104: //
                    105: // fixed は TextScreen とパディングを除いたコントロールの高さ
                    106: void
                    107: WXVResizeSubWindow::CalcVSize(int fixed)
                    108: {
                    109:        const wxSize& fontsize = screen->GetFontSize();
                    110: 
                    111:        int pad_top = 0;
                    112:        int pad_btm = 0;
                    113: 
                    114:        // pad は必要なパディング高
                    115:        int pad = 0;
                    116:        if (fixed == 0) {
                    117:                // 追加のコントロールが一切なければ1行分のパディング
                    118:                pad = fontsize.y;
                    119:        } else {
                    120:                // 追加のコントロールがあれば、繰り上がるまでの余りをとる
                    121:                pad = ((fixed + fontsize.y - 1) / fontsize.y) * fontsize.y - fixed;
                    122:        }
                    123: 
                    124:        if (pad > fontsize.y / 2) {
                    125:                // 必要なパディングが行の 1/2 以上なら、下に 1/2、残りを上に
                    126:                pad_btm = fontsize.y / 2;
                    127:                pad_top = pad - pad_btm;
                    128:        } else {
                    129:                // 必要なパディングが行の 1/2 以下なら、半分ずつ
                    130:                pad_btm = pad / 2;
                    131:                pad_top = pad - pad_btm;
                    132:        }
                    133: 
                    134:        // パディングを設定
                    135:        wxSize size1(1, pad_top);
                    136:        wxSize size2(1, pad_btm);
                    137:        padding1->SetSize(size1);
                    138:        padding1->SetMinSize(size1);
                    139:        padding2->SetSize(size2);
                    140:        padding2->SetMinSize(size2);
                    141: 
                    142:        // 横は固定、縦方向は1行ずつ伸縮可能
                    143:        // 最小サイズは fixed と1行分とパディング。
                    144:        wxSize tsize = topsizer->ComputeFittingWindowSize(this);
                    145:        wxSize minsize = wxSize(tsize.x, fixed + fontsize.y + pad);
                    146:        wxSize maxsize = wxSize(tsize.x, -1);
                    147:        wxSize incsize = wxSize(0, fontsize.y);
                    148:        SetSizeHints(minsize, maxsize, incsize);
                    149: 
                    150:        Fit();
                    151: }
1.1.1.4 ! root      152: 
        !           153: 
        !           154: //
        !           155: // サブウィンドウの四辺に置くためのパディングパネル
        !           156: //
        !           157: 
        !           158: // コンストラクタ (サイズ指定なし)
        !           159: WXPaddingPanel::WXPaddingPanel(wxWindow *parent)
        !           160:        : WXPaddingPanel(parent, wxSize(DefaultPadding, DefaultPadding))
        !           161: {
        !           162: }
        !           163: 
        !           164: // コンストラクタ (サイズ指定あり)
        !           165: WXPaddingPanel::WXPaddingPanel(wxWindow *parent, const wxSize& size)
        !           166:        : inherited(parent, wxID_ANY, wxDefaultPosition, size)
        !           167: {
        !           168:        SetBackgroundColour(BGPANEL);
        !           169: }
        !           170: 
        !           171: // デストラクタ
        !           172: WXPaddingPanel::~WXPaddingPanel()
        !           173: {
        !           174: }

unix.superglobalmegacorp.com

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