--- nono/wx/wxsubwindow.cpp 2026/04/29 17:04:37 1.1.1.2 +++ nono/wx/wxsubwindow.cpp 2026/04/29 17:05:08 1.1.1.7 @@ -4,11 +4,17 @@ // Licensed under nono-license.txt // +// +// サブウィンドウ +// + #include "wxsubwindow.h" +#include "fontmanager.h" #include "wxmainframe.h" +#include "wxtextscreen.h" // -// サブウィンドウ +// サブウィンドウ (基本クラス) // // イベントテーブル @@ -16,19 +22,13 @@ wxBEGIN_EVENT_TABLE(WXSubWindow, inherit EVT_CLOSE(WXSubWindow::OnClose) wxEND_EVENT_TABLE() -// コンストラクタ (スタイル指定あり) +// コンストラクタ WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name, int style) : inherited(parent, id, name, wxDefaultPosition, wxDefaultSize, style) { } -// コンストラクタ (スタイル指定なし) -WXSubWindow::WXSubWindow(wxWindow *parent, wxWindowID id, const wxString& name) - : WXSubWindow(parent, id, name, DEFAULT_STYLE) -{ -} - // デストラクタ WXSubWindow::~WXSubWindow() { @@ -39,8 +39,103 @@ void WXSubWindow::OnClose(wxCloseEvent& event) { // ウィンドウリストから自身を削除 - gMainFrame->DeleteWindow(GetId()); + gMainFrame->DeleteWindow(this); +} + +// フォントサイズ変更 +void +WXSubWindow::FontChanged() +{ + // WXTextPanel 派生の子コントロールに対し FontChanged() を呼ぶ + for (auto child : GetChildren()) { + auto textpanel = dynamic_cast(child); + if (textpanel) { + textpanel->FontChanged(); + } + } + + DoSize(); +} + +// 中身に応じてこのウィンドウの大きさを変更 +void +WXSubWindow::DoSize() +{ + wxSize csize; + + auto *topsizer = GetSizer(); + if (topsizer) { + // Sizer があればそれがサイズを知っている + csize = topsizer->GetMinSize(); + } else { + // Sizer を使ってなければ子コントロールは1人のはず + auto& children = GetChildren(); + assert(children.GetCount() == 1); + auto child = children[0]; + csize = child->GetMinSize(); + } + SetClientSize(csize); +} + + +// +// 縦リサイズ可能なサブウィンドウ +// + +// コンストラクタ +WXVResizeSubWindow::WXVResizeSubWindow(wxWindow *parent, wxWindowID id, + const wxString& name) + : inherited(parent, id, name, DEFAULT_STYLE | wxRESIZE_BORDER) +{ +} + +// デストラクタ +WXVResizeSubWindow::~WXVResizeSubWindow() +{ +} + +void +WXVResizeSubWindow::FontChanged() +{ + screen->FontChanged(); + Layout(); + DoSize(); +} + +void +WXVResizeSubWindow::DoSize() +{ + wxSize tsize = GetSizer()->ComputeFittingClientSize(this); + SetClientSize(tsize); } -// スタティック変数 (初期化は wxmainframe.cpp で行っている) -/*static*/ wxSizerFlags WXSubWindow::BorderFlags; +bool +WXVResizeSubWindow::Layout() +{ + if (inherited::Layout() == false) { + return false; + } + + wxSize tsize = GetSizer()->ComputeFittingClientSize(this); + + // 高さ計算。 + // 高さの最小は fixed と TextScreen 2行分にしておく。 + int h = fixed_height; + h += screen->GetPaddingTop(); + h += screen->GetFontHeight() * 2; + h += screen->GetPaddingBottom(); + + // サイズを変える時は、大きくする時は Max を先に、小さくする時は Min を + // 先に変えないと、サイズ制約の不整合の GTK ワーニングが出てしまう。 + // うーんこの API…。 + wxSize csize = GetClientSize(); + if (tsize.x > csize.x) { + SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord)); + SetMinClientSize(wxSize(tsize.x, h)); + } else { + SetMinClientSize(wxSize(tsize.x, h)); + SetMaxClientSize(wxSize(tsize.x, wxDefaultCoord)); + } + + return true; +}