|
|
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.2 root 8: #include "wxmainframe.h"
1.1.1.3 ! root 9: #include "wxtextscreen.h"
1.1 root 10:
11: //
12: // サブウィンドウ
13: //
14:
15: // イベントテーブル
16: wxBEGIN_EVENT_TABLE(WXSubWindow, inherited)
17: EVT_CLOSE(WXSubWindow::OnClose)
18: wxEND_EVENT_TABLE()
19:
20: // コンストラクタ (スタイル指定あり)
21: WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name,
22: int style)
23: : inherited(parent, id, name, wxDefaultPosition, wxDefaultSize, style)
24: {
25: }
26:
27: // コンストラクタ (スタイル指定なし)
28: WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name)
29: : WXSubWindow(parent, id, name, DEFAULT_STYLE)
30: {
31: }
32:
33: // デストラクタ
34: WXSubWindow::~WXSubWindow()
35: {
36: }
37:
38: // クローズイベント
39: void
40: WXSubWindow::OnClose(wxCloseEvent& event)
41: {
42: // ウィンドウリストから自身を削除
43: gMainFrame->DeleteWindow(GetId());
44: }
1.1.1.2 root 45:
1.1.1.3 ! root 46: // テキスト系パネルのフォントサイズを変更する
! 47: void
! 48: WXSubWindow::SetFontSize(FontId fontid)
! 49: {
! 50: // このウィンドウの子のうち..
! 51: wxWindowList& children = GetChildren();
! 52: for (wxWindow *child : children) {
! 53: // すべての WXTextPanel の継承クラスだけに対して
! 54: // フォントサイズの変更を指示する。
! 55: WXTextPanel *textpanel = dynamic_cast<WXTextPanel*>(child);
! 56: if (textpanel) {
! 57: textpanel->SetFontSize(fontid);
! 58: }
! 59: }
! 60:
! 61: // 大きさを変更
! 62: Layout();
! 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: Layout();
! 151: Fit();
! 152: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.