--- nono/wx/wxsubwindow.cpp 2026/04/29 17:04:28 1.1 +++ nono/wx/wxsubwindow.cpp 2026/04/29 17:04:53 1.1.1.4 @@ -1,11 +1,13 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include "wxheader.h" -#include "wxmainframe.h" #include "wxsubwindow.h" +#include "wxcolor.h" +#include "wxmainframe.h" +#include "wxtextscreen.h" // // サブウィンドウ @@ -19,7 +21,7 @@ wxEND_EVENT_TABLE() // コンストラクタ (スタイル指定あり) WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name, int style) - : inherited(parent, id, name, wxDefaultPosition, wxDefaultSize, style) + : inherited(parent, id, name, style) { } @@ -41,3 +43,132 @@ WXSubWindow::OnClose(wxCloseEvent& event // ウィンドウリストから自身を削除 gMainFrame->DeleteWindow(GetId()); } + +// テキスト系パネルのフォントサイズを変更する +void +WXSubWindow::SetFontSize(FontId fontid) +{ + // このウィンドウの子のうち.. + wxWindowList& children = GetChildren(); + for (wxWindow *child : children) { + // すべての WXTextPanel の継承クラスだけに対して + // フォントサイズの変更を指示する。 + WXTextPanel *textpanel = dynamic_cast(child); + if (textpanel) { + textpanel->SetFontSize(fontid); + } + } + + // 大きさを変更 + Fit(); +} + + +// +// 縦リサイズ可能なサブウィンドウ +// + +// コンストラクタ +WXVResizeSubWindow::WXVResizeSubWindow(wxWindow *parent, wxWindowID id, + const wxString& name) + : inherited(parent, id, name, DEFAULT_STYLE | wxRESIZE_BORDER) +{ +} + +// デストラクタ +WXVResizeSubWindow::~WXVResizeSubWindow() +{ +} + +// フォントサイズ変更 +void +WXVResizeSubWindow::SetFontSize(FontId fontid) +{ + // 親クラスの処理をして.. + inherited::SetFontSize(fontid); + + // フォントサイズが確定したので、継承先のウィンドウサイズ計算処理。 + // 引数なしの DoSize() は継承先ごとに実装する仮想関数、 + // そいつが共通の CalcVSize(int) を呼び出してくる。 + DoSize(); +} + +// ウィンドウサイズを再計算する共通部分。 +// +// テキスト系ウィンドウではウィンドウの縦方向のリサイズは1行の高さ分ずつ +// 行いたいが、そのためにはこのウィンドウのクライアント領域が1行の高さの +// 整数倍になっている必要がある。TextScreen 自身は行の高さの整数倍だが、 +// 他に余白や別コントロールを追加して、フォントサイズも動的に変化すると +// なると、諸々自動で計算したい。 +// フォントサイズが確定したところで呼び出すこと。 +// +// fixed は TextScreen とパディングを除いたコントロールの高さ +void +WXVResizeSubWindow::CalcVSize(int fixed) +{ + const wxSize& fontsize = screen->GetFontSize(); + + int pad_top = 0; + int pad_btm = 0; + + // pad は必要なパディング高 + int pad = 0; + if (fixed == 0) { + // 追加のコントロールが一切なければ1行分のパディング + pad = fontsize.y; + } else { + // 追加のコントロールがあれば、繰り上がるまでの余りをとる + pad = ((fixed + fontsize.y - 1) / fontsize.y) * fontsize.y - fixed; + } + + if (pad > fontsize.y / 2) { + // 必要なパディングが行の 1/2 以上なら、下に 1/2、残りを上に + pad_btm = fontsize.y / 2; + pad_top = pad - pad_btm; + } else { + // 必要なパディングが行の 1/2 以下なら、半分ずつ + pad_btm = pad / 2; + pad_top = pad - pad_btm; + } + + // パディングを設定 + wxSize size1(1, pad_top); + wxSize size2(1, pad_btm); + padding1->SetSize(size1); + padding1->SetMinSize(size1); + padding2->SetSize(size2); + padding2->SetMinSize(size2); + + // 横は固定、縦方向は1行ずつ伸縮可能 + // 最小サイズは fixed と1行分とパディング。 + wxSize tsize = topsizer->ComputeFittingWindowSize(this); + wxSize minsize = wxSize(tsize.x, fixed + fontsize.y + pad); + wxSize maxsize = wxSize(tsize.x, -1); + wxSize incsize = wxSize(0, fontsize.y); + SetSizeHints(minsize, maxsize, incsize); + + Fit(); +} + + +// +// サブウィンドウの四辺に置くためのパディングパネル +// + +// コンストラクタ (サイズ指定なし) +WXPaddingPanel::WXPaddingPanel(wxWindow *parent) + : WXPaddingPanel(parent, wxSize(DefaultPadding, DefaultPadding)) +{ +} + +// コンストラクタ (サイズ指定あり) +WXPaddingPanel::WXPaddingPanel(wxWindow *parent, const wxSize& size) + : inherited(parent, wxID_ANY, wxDefaultPosition, size) +{ + SetBackgroundColour(BGPANEL); +} + +// デストラクタ +WXPaddingPanel::~WXPaddingPanel() +{ +}