| 1 |
#include "DirectoryChanger.h" |
| 2 |
#include "allocator_mgr.h" |
| 3 |
#include "designer_container_panel.h" |
| 4 |
#include "designer_panel.h" |
| 5 |
#include "gui.h" |
| 6 |
#include "menu_bar.h" |
| 7 |
#include "tool_bar.h" |
| 8 |
#include "wxcTreeView.h" |
| 9 |
#include "wxgui_helpers.h" |
| 10 |
#include "wxguicraft_main_view.h" |
| 11 |
#include <drawingutils.h> |
| 12 |
#include <event_notifier.h> |
| 13 |
#include <wx/app.h> |
| 14 |
#include <wx/bookctrl.h> |
| 15 |
#include <wx/choicebk.h> |
| 16 |
#include <wx/clrpicker.h> |
| 17 |
#include <wx/collpane.h> |
| 18 |
#include <wx/combobox.h> |
| 19 |
#include <wx/dataview.h> |
| 20 |
#include <wx/dcbuffer.h> |
| 21 |
#include <wx/dcscreen.h> |
| 22 |
#include <wx/dirctrl.h> |
| 23 |
#include <wx/filepicker.h> |
| 24 |
#include <wx/gbsizer.h> |
| 25 |
//#include <wx/grid.h> |
| 26 |
#include <wx/listbook.h> |
| 27 |
#include <wx/listctrl.h> |
| 28 |
#include <wx/log.h> |
| 29 |
#include <wx/menu.h> |
| 30 |
#include <wx/msgdlg.h> |
| 31 |
#include <wx/notebook.h> |
| 32 |
#include <wx/radiobox.h> |
| 33 |
#include <wx/settings.h> |
| 34 |
#include <wx/srchctrl.h> |
| 35 |
#include <wx/statusbr.h> |
| 36 |
#include <wx/toolbar.h> |
| 37 |
#include <wx/toolbook.h> |
| 38 |
#include <wx/treebook.h> |
| 39 |
#include <wx/treelist.h> |
| 40 |
#include <wx/wupdlock.h> |
| 41 |
#include <wx/xrc/xmlres.h> |
| 42 |
|
| 43 |
class BOOL_LOCKER |
| 44 |
{ |
| 45 |
bool& m_bool; |
| 46 |
|
| 47 |
public: |
| 48 |
BOOL_LOCKER(bool& b) |
| 49 |
: m_bool(b) |
| 50 |
{ |
| 51 |
m_bool = true; |
| 52 |
} |
| 53 |
~BOOL_LOCKER() { m_bool = false; } |
| 54 |
}; |
| 55 |
|
| 56 |
class CONTEXT_MENU |
| 57 |
{ |
| 58 |
bool m_fireEvent; |
| 59 |
|
| 60 |
public: |
| 61 |
CONTEXT_MENU(bool fireEvent) |
| 62 |
: m_fireEvent(fireEvent) |
| 63 |
{ |
| 64 |
} |
| 65 |
~CONTEXT_MENU() |
| 66 |
{ |
| 67 |
if(m_fireEvent) { |
| 68 |
wxCommandEvent contextMenuEvent(wxEVT_SHOW_CONTEXT_MENU); |
| 69 |
EventNotifier::Get()->AddPendingEvent(contextMenuEvent); |
| 70 |
} |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
class HiddenFrame : public wxFrame |
| 75 |
{ |
| 76 |
public: |
| 77 |
HiddenFrame() |
| 78 |
: wxFrame(NULL, wxID_ANY, wxT("")) |
| 79 |
{ |
| 80 |
Hide(); |
| 81 |
} |
| 82 |
virtual ~HiddenFrame() {} |
| 83 |
}; |
| 84 |
|
| 85 |
const wxEventType wxEVT_PREVIEW_CTRL_SELECTED = wxNewEventType(); |
| 86 |
const wxEventType wxEVT_PREVIEW_BOOKPAGE_SELECTED = wxNewEventType(); |
| 87 |
const wxEventType wxEVT_PREVIEW_RIBBON_PAGE_SELECTED = wxNewEventType(); |
| 88 |
|
| 89 |
BEGIN_EVENT_TABLE(DesignerPanel, wxScrolledWindow) |
| 90 |
EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnAuiPageChanged) |
| 91 |
EVT_AUINOTEBOOK_PAGE_CHANGING(wxID_ANY, DesignerPanel::OnAuiPageChanging) |
| 92 |
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnNotebookPageChanged) |
| 93 |
EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnListbookPageChanged) |
| 94 |
EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnToolbookPageChanged) |
| 95 |
EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnChoicebookPageChanged) |
| 96 |
EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnTreebookPageChanged) |
| 97 |
EVT_TOOL(wxID_ANY, DesignerPanel::OnAuiToolClicked) |
| 98 |
EVT_RADIOBOX(wxID_ANY, DesignerPanel::OnRadioBox) |
| 99 |
EVT_RIBBONBAR_PAGE_CHANGED(wxID_ANY, DesignerPanel::OnRibbonPageChanged) |
| 100 |
EVT_SIZE(DesignerPanel::OnSize) |
| 101 |
END_EVENT_TABLE() |
| 102 |
|
| 103 |
DesignerPanel::DesignerPanel(wxWindow* parent, wxWindowID id, const wxPoint& position, const wxSize& size, long style) |
| 104 |
: wxScrolledWindow(parent, wxID_ANY, position, size, style) |
| 105 |
, m_constructing(true) |
| 106 |
, m_hintedWin(NULL) |
| 107 |
, m_parentWin(NULL) |
| 108 |
, m_hintedSizeritem(NULL) |
| 109 |
, m_hintedContainer(NULL) |
| 110 |
{ |
| 111 |
this->SetScrollRate(5, 5); |
| 112 |
wxBoxSizer* sz = new wxBoxSizer(wxVERTICAL); |
| 113 |
SetSizer(sz); |
| 114 |
|
| 115 |
m_mainPanel = new DesignerContainerPanel(this); |
| 116 |
GetSizer()->Add(m_mainPanel, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5); |
| 117 |
|
| 118 |
wxColour bgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); |
| 119 |
if(DrawingUtils::IsDark(bgColour)) { |
| 120 |
bgColour = bgColour.ChangeLightness(120); |
| 121 |
} else { |
| 122 |
bgColour = bgColour.ChangeLightness(90); |
| 123 |
} |
| 124 |
SetBackgroundColour(bgColour); |
| 125 |
EventNotifier::Get()->Connect(wxEVT_UPDATE_PREVIEW, wxCommandEventHandler(DesignerPanel::OnUpdatePreview), NULL, |
| 126 |
this); |
| 127 |
EventNotifier::Get()->Connect(wxEVT_WXGUI_PROJECT_CLOSED, wxCommandEventHandler(DesignerPanel::OnClearPreview), |
| 128 |
NULL, this); |
| 129 |
EventNotifier::Get()->Connect(wxEVT_WXGUI_PROJECT_LOADED, wxCommandEventHandler(DesignerPanel::OnLoadPreview), NULL, |
| 130 |
this); |
| 131 |
EventNotifier::Get()->Connect(wxEVT_TREE_ITEM_SELECTED, wxCommandEventHandler(DesignerPanel::OnHighlightControl), |
| 132 |
NULL, this); |
| 133 |
GetSizer()->Layout(); |
| 134 |
} |
| 135 |
|
| 136 |
DesignerPanel::~DesignerPanel() |
| 137 |
{ |
| 138 |
EventNotifier::Get()->Disconnect(wxEVT_UPDATE_PREVIEW, wxCommandEventHandler(DesignerPanel::OnUpdatePreview), NULL, |
| 139 |
this); |
| 140 |
EventNotifier::Get()->Disconnect(wxEVT_WXGUI_PROJECT_CLOSED, wxCommandEventHandler(DesignerPanel::OnClearPreview), |
| 141 |
NULL, this); |
| 142 |
EventNotifier::Get()->Disconnect(wxEVT_WXGUI_PROJECT_LOADED, wxCommandEventHandler(DesignerPanel::OnLoadPreview), |
| 143 |
NULL, this); |
| 144 |
EventNotifier::Get()->Disconnect(wxEVT_TREE_ITEM_SELECTED, wxCommandEventHandler(DesignerPanel::OnHighlightControl), |
| 145 |
NULL, this); |
| 146 |
} |
| 147 |
|
| 148 |
void DesignerPanel::OnUpdatePreview(wxCommandEvent& e) |
| 149 |
{ |
| 150 |
e.Skip(); |
| 151 |
|
| 152 |
BOOL_LOCKER bl(m_constructing); |
| 153 |
if(m_xrcLoaded == e.GetString()) |
| 154 |
return; |
| 155 |
|
| 156 |
#ifdef __WXMSW__ |
| 157 |
wxWindowUpdateLocker locker(this); |
| 158 |
#endif |
| 159 |
|
| 160 |
if(m_mainPanel) { |
| 161 |
DoClear(); |
| 162 |
} |
| 163 |
|
| 164 |
m_xrcLoaded = e.GetString(); |
| 165 |
DoLoadXRC(e.GetInt()); |
| 166 |
} |
| 167 |
|
| 168 |
void DesignerPanel::OnClearPreview(wxCommandEvent& e) |
| 169 |
{ |
| 170 |
e.Skip(); |
| 171 |
#ifdef __WXMSW__ |
| 172 |
wxWindowUpdateLocker locker(this); |
| 173 |
#endif |
| 174 |
BOOL_LOCKER bl(m_constructing); |
| 175 |
DoClear(); |
| 176 |
} |
| 177 |
|
| 178 |
void DesignerPanel::OnLoadPreview(wxCommandEvent& e) |
| 179 |
{ |
| 180 |
e.Skip(); |
| 181 |
#ifdef __WXMSW__ |
| 182 |
wxWindowUpdateLocker locker(this); |
| 183 |
#endif |
| 184 |
BOOL_LOCKER bl(m_constructing); |
| 185 |
DoClear(); |
| 186 |
|
| 187 |
m_xrcLoaded = e.GetString(); |
| 188 |
DoLoadXRC(e.GetInt()); |
| 189 |
} |
| 190 |
|
| 191 |
void DesignerPanel::OnMouseLeftDown(wxMouseEvent& e) { DoControlSelected(e); } |
| 192 |
|
| 193 |
void DesignerPanel::DoControlSelected(wxEvent& e) |
| 194 |
{ |
| 195 |
bool bIsRightUp = ::wxGetMouseState().RightIsDown(); |
| 196 |
wxWindow* win = dynamic_cast<wxWindow*>(e.GetEventObject()); |
| 197 |
if(win) { |
| 198 |
|
| 199 |
// Fire context menu if needed |
| 200 |
CONTEXT_MENU eventStarte(bIsRightUp); |
| 201 |
|
| 202 |
wxString clsname, parent_clsname; |
| 203 |
const wxClassInfo* clsInfo = win->GetClassInfo(); |
| 204 |
if(clsInfo && clsInfo->GetClassName()) { |
| 205 |
clsname = clsInfo->GetClassName(); |
| 206 |
} |
| 207 |
|
| 208 |
if(win->GetParent() && win->GetParent()->GetClassInfo() && win->GetParent()->GetClassInfo()->GetClassName()) { |
| 209 |
parent_clsname = win->GetParent()->GetClassInfo()->GetClassName(); |
| 210 |
} |
| 211 |
|
| 212 |
wxWindow* selectedWin = win; |
| 213 |
wxString thename = win->GetName(); |
| 214 |
|
| 215 |
if(parent_clsname == wxT("wxGrid")) { |
| 216 |
selectedWin = win->GetParent(); |
| 217 |
thename = win->GetParent()->GetName(); |
| 218 |
|
| 219 |
} else if(parent_clsname == "OpenGLCanvas") { |
| 220 |
selectedWin = win->GetParent(); |
| 221 |
thename = win->GetParent()->GetName(); |
| 222 |
|
| 223 |
} else if(parent_clsname == "wxPropertyGridManager") { |
| 224 |
selectedWin = win->GetParent(); |
| 225 |
thename = win->GetParent()->GetName(); |
| 226 |
|
| 227 |
} else if(parent_clsname == wxT("wxListCtrl")) { |
| 228 |
selectedWin = win->GetParent(); |
| 229 |
thename = win->GetParent()->GetName(); |
| 230 |
|
| 231 |
} else if(parent_clsname == wxT("wxSearchCtrl")) { |
| 232 |
selectedWin = win->GetParent(); |
| 233 |
thename = win->GetParent()->GetName(); |
| 234 |
|
| 235 |
} else if(parent_clsname == wxT("wxColourPickerCtrl")) { |
| 236 |
selectedWin = win->GetParent(); |
| 237 |
thename = win->GetParent()->GetName(); |
| 238 |
|
| 239 |
} else if(parent_clsname == wxT("wxFilePickerCtrl")) { |
| 240 |
selectedWin = win->GetParent(); |
| 241 |
thename = win->GetParent()->GetName(); |
| 242 |
|
| 243 |
} else if(parent_clsname == wxT("wxDirPickerCtrl")) { |
| 244 |
selectedWin = win->GetParent(); |
| 245 |
thename = win->GetParent()->GetName(); |
| 246 |
|
| 247 |
} else if(parent_clsname == wxT("wxGenericDirCtrl")) { |
| 248 |
selectedWin = win->GetParent(); |
| 249 |
thename = win->GetParent()->GetName(); |
| 250 |
|
| 251 |
} else if(parent_clsname == "wxDataViewListCtrl") { |
| 252 |
selectedWin = win->GetParent(); |
| 253 |
thename = win->GetParent()->GetName(); |
| 254 |
|
| 255 |
} else if(parent_clsname == "wxDataViewTreeCtrl") { |
| 256 |
selectedWin = win->GetParent(); |
| 257 |
thename = win->GetParent()->GetName(); |
| 258 |
|
| 259 |
} else if(parent_clsname == "wxDataViewCtrl") { |
| 260 |
selectedWin = win->GetParent(); |
| 261 |
thename = win->GetParent()->GetName(); |
| 262 |
} |
| 263 |
|
| 264 |
// Allow click on wxNotebook to actually switch pages |
| 265 |
if(clsname == wxT("wxNotebook") || (parent_clsname == wxT("wxToolbook") && clsname == wxT("wxToolBar")) || |
| 266 |
(parent_clsname == wxT("wxListbook") && clsname == wxT("wxListView")) || |
| 267 |
(clsname == wxT("wxAuiTabCtrl") || parent_clsname == wxT("wxAuiNotebook")) || |
| 268 |
(parent_clsname == wxT("wxTreebook") || clsname == "wxRibbonBar")) { |
| 269 |
e.Skip(); |
| 270 |
DoDrawSurroundingMarker(selectedWin); |
| 271 |
return; |
| 272 |
} |
| 273 |
|
| 274 |
if(clsname == wxT("wxAuiToolBar")) { |
| 275 |
// We handle clicks in the OnAuiToolbarClicked() method |
| 276 |
e.Skip(); |
| 277 |
DoDrawSurroundingMarker(selectedWin); |
| 278 |
return; |
| 279 |
} |
| 280 |
|
| 281 |
if(clsname == wxT("wxToolBar")) { |
| 282 |
e.Skip(); |
| 283 |
DoDrawSurroundingMarker(selectedWin); |
| 284 |
return; |
| 285 |
} |
| 286 |
|
| 287 |
DoDrawSurroundingMarker(selectedWin); |
| 288 |
wxCommandEvent evt(wxEVT_PREVIEW_CTRL_SELECTED); |
| 289 |
evt.SetString(thename); |
| 290 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
void DesignerPanel::RecurseConnectEvents(wxWindow* pclComponent) |
| 295 |
{ |
| 296 |
if(pclComponent) { |
| 297 |
wxString name = pclComponent->GetName(); |
| 298 |
name.Trim(); |
| 299 |
m_windows.insert(std::make_pair(name, pclComponent)); |
| 300 |
pclComponent->Connect(wxID_ANY, wxEVT_LEFT_DOWN, wxMouseEventHandler(DesignerPanel::OnMouseLeftDown), |
| 301 |
(wxObject*)NULL, this); |
| 302 |
|
| 303 |
pclComponent->Connect(wxID_ANY, wxEVT_RIGHT_DOWN, wxMouseEventHandler(DesignerPanel::OnMouseLeftDown), |
| 304 |
(wxObject*)NULL, this); |
| 305 |
|
| 306 |
pclComponent->Connect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(DesignerPanel::OnControlFocus), |
| 307 |
(wxObject*)NULL, this); |
| 308 |
// Now, for container windows e.g. panels, grab the opportunity to identify all contained sizers/spacers |
| 309 |
StoreSizersRecursively(pclComponent->GetSizer(), |
| 310 |
pclComponent); // For non-containers this will harmlessly pass NULL |
| 311 |
|
| 312 |
wxWindowList::compatibility_iterator pclNode = pclComponent->GetChildren().GetFirst(); |
| 313 |
while(pclNode) { |
| 314 |
wxWindow* pclChild = pclNode->GetData(); |
| 315 |
this->RecurseConnectEvents(pclChild); |
| 316 |
|
| 317 |
pclNode = pclNode->GetNext(); |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
void DesignerPanel::RecurseDisconnectEvents(wxWindow* pclComponent) |
| 323 |
{ |
| 324 |
if(pclComponent) { |
| 325 |
pclComponent->Disconnect(wxID_ANY, wxEVT_LEFT_DOWN, wxMouseEventHandler(DesignerPanel::OnMouseLeftDown), |
| 326 |
(wxObject*)NULL, this); |
| 327 |
|
| 328 |
pclComponent->Disconnect(wxID_ANY, wxEVT_RIGHT_DOWN, wxMouseEventHandler(DesignerPanel::OnMouseLeftDown), |
| 329 |
(wxObject*)NULL, this); |
| 330 |
|
| 331 |
pclComponent->Disconnect(wxID_ANY, wxEVT_SET_FOCUS, wxFocusEventHandler(DesignerPanel::OnControlFocus), |
| 332 |
(wxObject*)NULL, this); |
| 333 |
wxWindowList::compatibility_iterator pclNode = pclComponent->GetChildren().GetFirst(); |
| 334 |
while(pclNode) { |
| 335 |
wxWindow* pclChild = pclNode->GetData(); |
| 336 |
this->RecurseDisconnectEvents(pclChild); |
| 337 |
|
| 338 |
pclNode = pclNode->GetNext(); |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
void DesignerPanel::StoreSizersRecursively(wxSizer* sizer, wxWindow* container) |
| 344 |
{ |
| 345 |
// There doesn't seem to be any way to retrieve a wxSizerItem for a top-level sizer :/ |
| 346 |
// So ignore it (fortunately it won't have borders or an interesting outline) but add all children |
| 347 |
if(sizer) { |
| 348 |
wxSizerItemList::compatibility_iterator node = sizer->GetChildren().GetFirst(); |
| 349 |
while(node) { |
| 350 |
wxSizerItem* child = node->GetData(); |
| 351 |
// We need to process the contents of a staticboxsizer differently; they are positioned wrt the staticbox, |
| 352 |
// not the real container |
| 353 |
if(child->IsSizer()) { |
| 354 |
wxStaticBoxSizer* sbs = wxDynamicCast(child->GetSizer(), wxStaticBoxSizer); |
| 355 |
if(sbs) { |
| 356 |
container = (wxWindow*)(sbs->GetStaticBox()); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
int id = child->GetId(); // GetId() returns XRCID(name), or wxNOT_FOUND for "" |
| 361 |
if(id != wxNOT_FOUND) { |
| 362 |
m_sizeritems.insert(std::make_pair(id, SizeritemData(container, child))); |
| 363 |
} |
| 364 |
|
| 365 |
if(child->IsSizer()) { |
| 366 |
wxSizer* childsizer = child->GetSizer(); |
| 367 |
StoreSizersRecursively(childsizer, container); |
| 368 |
if(!childsizer->GetItemCount()) { |
| 369 |
// Empty sizers all get positioned at 0,0, which breaks outlining; they also annoy gtk. |
| 370 |
// So let's pretend it contains a 5*5 spacer |
| 371 |
// But be careful if it's a gridbagsizer: a plain AddSpacer() asserts |
| 372 |
wxGridBagSizer* gbs = wxDynamicCast(childsizer, wxGridBagSizer); |
| 373 |
if(gbs) { |
| 374 |
gbs->Add(0, 0, wxGBPosition()); |
| 375 |
} else { |
| 376 |
childsizer->AddSpacer(5); |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
node = node->GetNext(); |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
void DesignerPanel::DoMarkSizeritem(wxSizerItem* szitem, wxWindow* container) |
| 387 |
{ |
| 388 |
// If no item provided, remark the current selection |
| 389 |
if(!szitem && m_hintedContainer && m_hintedSizeritem) { |
| 390 |
wxClientDC dc(m_hintedContainer); |
| 391 |
dc.SetPen(wxColour("ORANGE")); |
| 392 |
wxRect rect(m_hintedSizeritem->GetRect()); |
| 393 |
MarkOutline(dc, &rect); |
| 394 |
DoMarkBorders(dc, rect, m_hintedSizeritem->GetBorder(), m_hintedSizeritem->GetFlag()); |
| 395 |
return; |
| 396 |
} |
| 397 |
|
| 398 |
ClearStaleOutlines(); |
| 399 |
|
| 400 |
if(szitem && container) { |
| 401 |
m_hintedSizeritem = szitem; |
| 402 |
m_hintedContainer = container; |
| 403 |
wxClientDC dc(container); |
| 404 |
dc.SetPen(wxColour("ORANGE")); |
| 405 |
|
| 406 |
wxRect rect(m_hintedSizeritem->GetRect()); |
| 407 |
MarkOutline(dc, &rect); |
| 408 |
DoMarkBorders(dc, rect, m_hintedSizeritem->GetBorder(), m_hintedSizeritem->GetFlag()); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
void DesignerPanel::DoDrawSurroundingMarker(wxWindow* win) |
| 413 |
{ |
| 414 |
// NULL provided, remark the current selection |
| 415 |
if(!win && m_parentWin && m_hintedWin) { |
| 416 |
wxClientDC dc(m_parentWin); |
| 417 |
dc.SetPen(*wxRED_PEN); |
| 418 |
MarkOutline(dc); |
| 419 |
MarkBorders(dc); |
| 420 |
return; |
| 421 |
|
| 422 |
} else if(!win) { |
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
wxWindow* parent = win->GetParent(); |
| 427 |
if(!parent) { |
| 428 |
return; |
| 429 |
} |
| 430 |
|
| 431 |
ClearStaleOutlines(); |
| 432 |
|
| 433 |
{ |
| 434 |
m_hintedWin = win; |
| 435 |
m_parentWin = parent; |
| 436 |
|
| 437 |
wxClientDC dc(m_parentWin); |
| 438 |
dc.SetPen(*wxRED_PEN); |
| 439 |
MarkOutline(dc); |
| 440 |
MarkBorders(dc); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
void DesignerPanel::MarkOutline(wxDC& dc, wxRect* rect /*=NULL*/) const |
| 445 |
{ |
| 446 |
wxRect rr; |
| 447 |
if(!rect) { |
| 448 |
rr = m_hintedWin->GetRect(); |
| 449 |
} else { |
| 450 |
rr = *rect; |
| 451 |
} |
| 452 |
const wxPoint pt = GetOutlineOffset(); |
| 453 |
|
| 454 |
rr.Offset(pt); |
| 455 |
rr.Inflate(1, 1); |
| 456 |
#if wxVERSION_NUMBER > 2904 |
| 457 |
if(pt != wxPoint()) { |
| 458 |
// i.e. this is a notebookpage, so (for some reason) it needs to be more inflated |
| 459 |
rr.Inflate(2, 2); |
| 460 |
} |
| 461 |
#endif |
| 462 |
|
| 463 |
dc.SetBrush(*wxTRANSPARENT_BRUSH); |
| 464 |
dc.DrawRectangle(rr); |
| 465 |
} |
| 466 |
|
| 467 |
void DesignerPanel::MarkBorders(wxDC& dc) const |
| 468 |
{ |
| 469 |
wxSizer* sizer = m_hintedWin->GetContainingSizer(); |
| 470 |
if(!sizer) { |
| 471 |
return; |
| 472 |
} |
| 473 |
|
| 474 |
wxSizerItem* szitem = sizer->GetItem(m_hintedWin); |
| 475 |
if(!szitem || !szitem->GetBorder()) { |
| 476 |
return; |
| 477 |
} |
| 478 |
|
| 479 |
dc.SetBrush(*wxTRANSPARENT_BRUSH); |
| 480 |
|
| 481 |
DoMarkBorders(dc, m_hintedWin->GetRect(), szitem->GetBorder(), szitem->GetFlag()); |
| 482 |
} |
| 483 |
|
| 484 |
void DesignerPanel::DoMarkBorders(wxDC& dc, wxRect rr, int bdrwidth, int flags) const |
| 485 |
{ |
| 486 |
if(flags & wxTOP) { |
| 487 |
wxPoint mid = rr.GetTopLeft() + wxPoint(rr.GetWidth() / 2, 0); |
| 488 |
dc.DrawLine(mid, mid - wxPoint(0, bdrwidth)); |
| 489 |
} |
| 490 |
|
| 491 |
if(flags & wxBOTTOM) { |
| 492 |
wxPoint mid = rr.GetBottomLeft() + wxPoint(rr.GetWidth() / 2, 0); |
| 493 |
dc.DrawLine(mid, mid + wxPoint(0, bdrwidth)); |
| 494 |
} |
| 495 |
|
| 496 |
if(flags & wxLEFT) { |
| 497 |
wxPoint mid = rr.GetTopLeft() + wxPoint(0, rr.GetHeight() / 2); |
| 498 |
dc.DrawLine(mid, mid - wxPoint(bdrwidth, 0)); |
| 499 |
} |
| 500 |
|
| 501 |
if(flags & wxRIGHT) { |
| 502 |
wxPoint mid = rr.GetTopRight() + wxPoint(0, rr.GetHeight() / 2); |
| 503 |
dc.DrawLine(mid, mid + wxPoint(bdrwidth, 0)); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
void DesignerPanel::ClearStaleOutlines() const |
| 508 |
{ |
| 509 |
// First any control |
| 510 |
if(m_parentWin && m_hintedWin) { |
| 511 |
wxClientDC dc(m_parentWin); |
| 512 |
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); |
| 513 |
MarkOutline(dc); |
| 514 |
MarkBorders(dc); |
| 515 |
} |
| 516 |
|
| 517 |
// Now any sizer/spacer |
| 518 |
if(m_hintedContainer && m_hintedSizeritem) { |
| 519 |
wxClientDC dc(m_hintedContainer); |
| 520 |
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); |
| 521 |
wxRect rect(m_hintedSizeritem->GetRect()); |
| 522 |
MarkOutline(dc, &rect); |
| 523 |
DoMarkBorders(dc, rect, m_hintedSizeritem->GetBorder(), m_hintedSizeritem->GetFlag()); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
wxPoint DesignerPanel::GetOutlineOffset() const |
| 528 |
{ |
| 529 |
wxPoint pt; |
| 530 |
if(m_parentWin && m_hintedWin && wxDynamicCast(m_parentWin, wxNotebook)) { |
| 531 |
int x, y, px, py; |
| 532 |
m_hintedWin->GetScreenPosition(&x, &y); |
| 533 |
m_parentWin->GetScreenPosition(&px, &py); |
| 534 |
#if wxVERSION_NUMBER < 2905 |
| 535 |
// If a wxNotebook has top or left tabs, the page outline needs offsetting to avoid them |
| 536 |
if(m_parentWin->GetWindowStyle() & wxNB_TOP) { |
| 537 |
pt.y = y - py; |
| 538 |
} else if(m_parentWin->GetWindowStyle() & wxNB_LEFT) { |
| 539 |
pt.x = x - px; |
| 540 |
} |
| 541 |
#else |
| 542 |
// In 2.9.5 that's no longer true. However the small margin between the notebook and the page needs offsetting |
| 543 |
if(m_parentWin->GetWindowStyle() & wxNB_TOP) { |
| 544 |
pt.x = pt.y = px - x - 3; // The -3 is a kludge |
| 545 |
} else if(m_parentWin->GetWindowStyle() & wxNB_LEFT) { |
| 546 |
pt.x = pt.y = py - y - 3; |
| 547 |
} |
| 548 |
#endif |
| 549 |
} |
| 550 |
return pt; |
| 551 |
} |
| 552 |
|
| 553 |
void DesignerPanel::DoClear() |
| 554 |
{ |
| 555 |
// Remove all children of this sizer |
| 556 |
if(!GetSizer()->IsEmpty()) { |
| 557 |
GetSizer()->Clear(); |
| 558 |
} |
| 559 |
if(m_mainPanel) { |
| 560 |
m_mainPanel->Destroy(); |
| 561 |
} |
| 562 |
m_mainPanel = nullptr; |
| 563 |
|
| 564 |
// create new panel and place it |
| 565 |
m_mainPanel = new DesignerContainerPanel(this); |
| 566 |
GetSizer()->Add(m_mainPanel, 0, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxALL, 5); |
| 567 |
|
| 568 |
|
| 569 |
m_xrcLoaded.Clear(); |
| 570 |
m_hintedWin = NULL; |
| 571 |
m_parentWin = NULL; |
| 572 |
m_hintedSizeritem = NULL; |
| 573 |
m_hintedContainer = NULL; |
| 574 |
m_windows.clear(); |
| 575 |
} |
| 576 |
|
| 577 |
void DesignerPanel::DoNotebookPageChangeEvent(wxEvent& e) |
| 578 |
{ |
| 579 |
if(m_constructing) { |
| 580 |
return; |
| 581 |
} |
| 582 |
|
| 583 |
wxBookCtrlBase* nbk = dynamic_cast<wxBookCtrlBase*>(e.GetEventObject()); |
| 584 |
if(!nbk) { |
| 585 |
return; |
| 586 |
} |
| 587 |
|
| 588 |
int idx = nbk->GetSelection(); |
| 589 |
if(idx != wxNOT_FOUND) { |
| 590 |
wxWindow* page = nbk->GetPage(idx); |
| 591 |
if(page) { |
| 592 |
wxCommandEvent evt(wxEVT_PREVIEW_BOOKPAGE_SELECTED); |
| 593 |
evt.SetString(page->GetName()); |
| 594 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 595 |
} |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
void DesignerPanel::OnListbookPageChanged(wxListbookEvent& e) { DoNotebookPageChangeEvent(e); } |
| 600 |
|
| 601 |
void DesignerPanel::OnNotebookPageChanged(wxNotebookEvent& e) { DoNotebookPageChangeEvent(e); } |
| 602 |
|
| 603 |
void DesignerPanel::OnToolbookPageChanged(wxToolbookEvent& e) { DoNotebookPageChangeEvent(e); } |
| 604 |
|
| 605 |
void DesignerPanel::OnChoicebookPageChanged(wxChoicebookEvent& e) { DoNotebookPageChangeEvent(e); } |
| 606 |
|
| 607 |
void DesignerPanel::OnTreebookPageChanged(wxTreebookEvent& e) { DoNotebookPageChangeEvent(e); } |
| 608 |
|
| 609 |
void DesignerPanel::DoAuiBookChanged(wxAuiNotebookEvent& e) |
| 610 |
{ |
| 611 |
if(m_constructing) { |
| 612 |
return; |
| 613 |
} |
| 614 |
|
| 615 |
wxAuiNotebook* nbk = dynamic_cast<wxAuiNotebook*>(e.GetEventObject()); |
| 616 |
if(!nbk) |
| 617 |
return; |
| 618 |
|
| 619 |
int idx = nbk->GetSelection(); |
| 620 |
if(idx != wxNOT_FOUND) { |
| 621 |
wxWindow* page = nbk->GetPage(idx); |
| 622 |
if(page) { |
| 623 |
wxCommandEvent evt(wxEVT_PREVIEW_BOOKPAGE_SELECTED); |
| 624 |
evt.SetString(page->GetName()); |
| 625 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 626 |
} |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
void DesignerPanel::OnAuiPageChanged(wxAuiNotebookEvent& e) { DoAuiBookChanged(e); } |
| 631 |
|
| 632 |
void DesignerPanel::OnAuiPageChanging(wxAuiNotebookEvent& e) { DoAuiBookChanged(e); } |
| 633 |
|
| 634 |
void DesignerPanel::DoLoadXRC(int topLeveWinType) |
| 635 |
{ |
| 636 |
m_windows.clear(); |
| 637 |
m_sizeritems.clear(); |
| 638 |
wxPanel* panel = NULL; |
| 639 |
wxString caption; |
| 640 |
wxString styleString; |
| 641 |
wxString bmpIcon; |
| 642 |
wxFileName fn = wxCrafter::LoadXRC(m_xrcLoaded, wxT("DesignerPanel.xrc"), caption, styleString, bmpIcon); |
| 643 |
|
| 644 |
// We must be in the directory of the project to be able to load the bitmaps properly |
| 645 |
DirectoryChanger dc(wxcProjectMetadata::Get().GetProjectPath()); |
| 646 |
panel = wxXmlResource::Get()->LoadPanel(m_mainPanel, wxT("PreviewPanel")); |
| 647 |
|
| 648 |
if(panel) { |
| 649 |
|
| 650 |
if(topLeveWinType == ID_WXFRAME || topLeveWinType == ID_WXDIALOG) { |
| 651 |
wxBitmap tlwIcon; |
| 652 |
if(!bmpIcon.IsEmpty()) { |
| 653 |
// convert bmpIcon to fullpath |
| 654 |
wxFileName fnBmp(bmpIcon); |
| 655 |
fnBmp.MakeAbsolute(wxcProjectMetadata::Get().GetProjectPath()); |
| 656 |
tlwIcon = wxBitmap(fnBmp.GetFullPath(), wxBITMAP_TYPE_ANY); |
| 657 |
} |
| 658 |
m_mainPanel->EnableCaption(caption, styleString, tlwIcon); |
| 659 |
} |
| 660 |
|
| 661 |
RecurseConnectEvents(panel); |
| 662 |
wxMenuBar* mb = wxXmlResource::Get()->LoadMenuBar(wxT("MENU_BAR_ID")); |
| 663 |
if(mb) { |
| 664 |
#ifdef __WXGTK__ |
| 665 |
// GTK assumes that a wxMenuBar is attached to a frame |
| 666 |
// so give it one |
| 667 |
HiddenFrame* hf = new HiddenFrame(); |
| 668 |
hf->SetMenuBar(mb); |
| 669 |
#endif |
| 670 |
m_mainPanel->SetMenuBar(new MenuBar(m_mainPanel, mb)); |
| 671 |
|
| 672 |
#ifdef __WXGTK__ |
| 673 |
hf->Destroy(); |
| 674 |
#endif |
| 675 |
} |
| 676 |
|
| 677 |
ToolBar* pane = new ToolBar(m_mainPanel); |
| 678 |
wxToolBar* tb = wxXmlResource::Get()->LoadToolBar(pane, wxT("TOOL_BAR_ID")); |
| 679 |
if(tb) { |
| 680 |
pane->AddToolbar(tb); |
| 681 |
m_mainPanel->SetToolbar(pane); |
| 682 |
|
| 683 |
} else { |
| 684 |
pane->Destroy(); |
| 685 |
} |
| 686 |
panel->Show(); |
| 687 |
m_mainPanel->AddMainView(panel); |
| 688 |
GetSizer()->Layout(); |
| 689 |
wxStatusBar* sb = dynamic_cast<wxStatusBar*>( |
| 690 |
wxXmlResource::Get()->LoadObject(m_mainPanel, wxT("STATUS_BAR_ID"), wxT("wxStatusBar"))); |
| 691 |
if(sb) { |
| 692 |
m_mainPanel->SetStatusBar(sb); |
| 693 |
} |
| 694 |
m_mainPanel->CalcBestSize(topLeveWinType); |
| 695 |
wxXmlResource::Get()->Unload(fn.GetFullPath()); |
| 696 |
|
| 697 |
if(topLeveWinType == ID_WXWIZARD) { |
| 698 |
GetSizer()->Fit(m_mainPanel); |
| 699 |
} |
| 700 |
} |
| 701 |
Layout(); |
| 702 |
} |
| 703 |
|
| 704 |
void DesignerPanel::OnAuiToolClicked(wxCommandEvent& e) |
| 705 |
{ |
| 706 |
wxAuiToolBar* tb = dynamic_cast<wxAuiToolBar*>(e.GetEventObject()); |
| 707 |
wxToolBar* bar = dynamic_cast<wxToolBar*>(e.GetEventObject()); |
| 708 |
if(tb) { |
| 709 |
|
| 710 |
wxAuiToolBarItem* tool = tb->FindTool(e.GetId()); |
| 711 |
if(tool) { |
| 712 |
wxString label = tool->GetLabel(); |
| 713 |
wxString s = tb->GetName(); |
| 714 |
s << wxT(":") << label; |
| 715 |
wxCommandEvent evt(wxEVT_PREVIEW_BAR_SELECTED); |
| 716 |
evt.SetString(s); |
| 717 |
evt.SetInt(ID_WXAUITOOLBAR); |
| 718 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 719 |
|
| 720 |
} else { |
| 721 |
e.Skip(); |
| 722 |
} |
| 723 |
|
| 724 |
} else if(bar) { |
| 725 |
wxToolBarToolBase* tool = bar->FindById(e.GetId()); |
| 726 |
if(tool) { |
| 727 |
wxString label = tool->GetLabel(); |
| 728 |
wxString s; |
| 729 |
s << bar->GetName() << wxT(":") << label; |
| 730 |
wxCommandEvent evt(wxEVT_PREVIEW_BAR_SELECTED); |
| 731 |
evt.SetString(s); |
| 732 |
evt.SetInt(ID_WXTOOLBAR); |
| 733 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 734 |
|
| 735 |
} else { |
| 736 |
e.Skip(); |
| 737 |
} |
| 738 |
|
| 739 |
} else { |
| 740 |
e.Skip(); |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
void DesignerPanel::OnHighlightControl(wxCommandEvent& e) |
| 745 |
{ |
| 746 |
e.Skip(); |
| 747 |
wxString s = e.GetString(); |
| 748 |
|
| 749 |
if(m_windows.count(s)) { |
| 750 |
DoDrawSurroundingMarker(m_windows[s]); |
| 751 |
} else { |
| 752 |
// If it wasn't in the window list, it should be a sizer or spacer |
| 753 |
int id = wxXmlResource::GetXRCID(s); |
| 754 |
if((id != wxID_NONE) && m_sizeritems.count(id)) { |
| 755 |
SizeritemData* sid = &(m_sizeritems.find(id)->second); |
| 756 |
DoMarkSizeritem(sid->m_sizeritem, sid->m_parentWin); |
| 757 |
} |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
void DesignerPanel::OnControlFocus(wxFocusEvent& event) |
| 762 |
{ |
| 763 |
event.Skip(); |
| 764 |
#if defined(__WXGTK__) || defined(__WXMAC__) |
| 765 |
wxDataViewTreeCtrl* win1 = dynamic_cast<wxDataViewTreeCtrl*>(event.GetEventObject()); |
| 766 |
wxDataViewCtrl* win2 = dynamic_cast<wxDataViewCtrl*>(event.GetEventObject()); |
| 767 |
wxDataViewListCtrl* win3 = dynamic_cast<wxDataViewListCtrl*>(event.GetEventObject()); |
| 768 |
if(win1 || win2 || win3) { |
| 769 |
DoControlSelected(event); |
| 770 |
} |
| 771 |
#endif |
| 772 |
} |
| 773 |
|
| 774 |
void DesignerPanel::OnRadioBox(wxCommandEvent& e) |
| 775 |
{ |
| 776 |
e.Skip(); |
| 777 |
wxRadioBox* rb = dynamic_cast<wxRadioBox*>(e.GetEventObject()); |
| 778 |
if(rb) { |
| 779 |
DoControlSelected(e); |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
void DesignerPanel::OnRibbonPageChanged(wxRibbonBarEvent& e) |
| 784 |
{ |
| 785 |
e.Skip(); |
| 786 |
if(e.GetPage()) { |
| 787 |
wxCommandEvent evt(wxEVT_PREVIEW_RIBBON_PAGE_SELECTED); |
| 788 |
evt.SetString(e.GetPage()->GetName()); |
| 789 |
EventNotifier::Get()->AddPendingEvent(evt); |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
void DesignerPanel::OnTreeListCtrlFocus(wxFocusEvent& e) |
| 794 |
{ |
| 795 |
e.Skip(); |
| 796 |
wxTreeListCtrl* rb = dynamic_cast<wxTreeListCtrl*>(e.GetEventObject()); |
| 797 |
if(rb) { |
| 798 |
DoControlSelected(e); |
| 799 |
} |
| 800 |
} |
| 801 |
|
| 802 |
void DesignerPanel::OnSize(wxSizeEvent& event) |
| 803 |
{ |
| 804 |
event.Skip(); |
| 805 |
Refresh(); |
| 806 |
} |