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

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

unix.superglobalmegacorp.com

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