|
|
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:
1.1.1.8 ! root 80: // このサブウィンドウが縦リサイズ可能なテキストパネルの場合の Layout()。
! 81: // 本来は screen を持っている継承クラスが個別に行うことだが、定形処理なので
! 82: // ここでサブルーチンとして用意しておく。必要なら継承クラスが呼ぶこと。
1.1.1.7 root 83: bool
1.1.1.8 ! root 84: WXSubWindow::LayoutTextVResize(const WXTextScreen *screen, int fixed_height)
1.1.1.7 root 85: {
86: if (inherited::Layout() == false) {
87: return false;
1.1.1.3 root 88: }
89:
1.1.1.7 root 90: wxSize tsize = GetSizer()->ComputeFittingClientSize(this);
91:
92: // 高さ計算。
93: // 高さの最小は fixed と TextScreen 2行分にしておく。
94: int h = fixed_height;
95: h += screen->GetPaddingTop();
96: h += screen->GetFontHeight() * 2;
97: h += screen->GetPaddingBottom();
98:
99: // サイズを変える時は、大きくする時は Max を先に、小さくする時は Min を
100: // 先に変えないと、サイズ制約の不整合の GTK ワーニングが出てしまう。
101: // うーんこの API…。
102: wxSize csize = GetClientSize();
103: if (tsize.x > csize.x) {
104: SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord));
105: SetMinClientSize(wxSize(tsize.x, h));
1.1.1.3 root 106: } else {
1.1.1.7 root 107: SetMinClientSize(wxSize(tsize.x, h));
108: SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord));
1.1.1.3 root 109: }
110:
1.1.1.7 root 111: return true;
1.1.1.4 root 112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.