--- nono/wx/wxsubwindow.cpp 2026/04/29 17:04:37 1.1.1.2 +++ nono/wx/wxsubwindow.cpp 2026/04/29 17:05:44 1.1.1.10 @@ -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,47 @@ void WXSubWindow::OnClose(wxCloseEvent& event) { // ウィンドウリストから自身を削除 - gMainFrame->DeleteWindow(GetId()); + auto mainframe = dynamic_cast(GetParent()); + mainframe->DeleteWindow(this); +} + +// フォントサイズ変更 +void +WXSubWindow::FontChanged() +{ + // WXTextPanel 派生の子コントロールに対し FontChanged() を呼ぶ + for (auto child : GetChildren()) { + auto textpanel = dynamic_cast(child); + if (textpanel) { + textpanel->FontChanged(); + } + } + + Fit(); } -// スタティック変数 (初期化は wxmainframe.cpp で行っている) -/*static*/ wxSizerFlags WXSubWindow::BorderFlags; +// 中身に応じてこのウィンドウの大きさを変更。 +// このウィンドウを sizer が支配しているか、 +// このウィンドウにコントロールが1つしかない時に使える。 +// +// コントロールが複数ある場合、どう配置するかの情報がないのでここでは処理 +// 出来ない。これを継承したウィンドウが Fit() をオーバーライドし、適切に +// ウィンドウサイズを計算して SetClientSize() すること。 +void +WXSubWindow::Fit() +{ + wxSize csize; + + auto *topsizer = GetSizer(); + if (topsizer) { + // Sizer があればそれがサイズを知っている + csize = topsizer->ComputeFittingClientSize(this); + } else { + // Sizer を使ってなければ子コントロールは1人のはず + auto& children = GetChildren(); + assert(children.GetCount() == 1); + auto child = children[0]; + csize = child->GetSize(); + } + SetClientSize(csize); +}