doc/view madness Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
theigor
Experienced Solver
Experienced Solver
Posts: 78
Joined: Thu Jan 12, 2006 6:51 pm

doc/view madness

Post by theigor » Wed May 24, 2006 2:25 pm

In the doc/view architecture, you have a wxDocument and a wxView, managed by a wxDocManager, and they create new frames for a "file->new" command, for example, on demand.
If you are working with wxDocMDIParent and Child frames, when a new child is created, it overrides the main parent frame's menu.

The thing is, I only have direct access to the main parent frame, since I created is as global, so I can say, for example,

Code: Select all

mainFrame->GetMenuBar()->Check(ID_WHATEVER, true );
What happens when that code runs and a document is already open? nothing(aparently), because that document's menu is overriding the main frame's menu. So I need to run that code with a pointer to the child frame, instead of "mainFrame->" so I can see the menu which ID I set to be checked.

The question is, how can I get this pointer to the child frame when wxView is creating it on demand and I don't know where it is?

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Wed May 24, 2006 2:39 pm

If you just want to check menu item, you should use wxUpdateUIEvent [1] events to check-it on or off.

Code: Select all

BEGIN_EVENT_TABLE()
  EVT_UPDATE_UI(yourid, AFrame::OnUpdateItem)
END_EVENT_TABLE()

void AFrame::OnUpdateItem(wxUpdateUIEvent event){
  event.Check(true);
}

[1] : http://www.wxwidgets.org/manuals/2.6.3/ ... ateuievent
What is little and green, witch go up and down ??
Yoda playing with the force.

theigor
Experienced Solver
Experienced Solver
Posts: 78
Joined: Thu Jan 12, 2006 6:51 pm

Post by theigor » Wed May 31, 2006 11:38 am

Thanks for the answer Cursor, it seems thats exactly what I wanted, but I can't compile with the code you posted:

Code: Select all

c:\Documents and Settings\...\App.cpp(415): error C2440: 'static_cast' : cannot convert from 'void (__thiscall MainFrame::* )(wxUpdateUIEvent)' to 'wxUpdateUIEventFunction'
What could be the problem?

theigor
Experienced Solver
Experienced Solver
Posts: 78
Joined: Thu Jan 12, 2006 6:51 pm

Post by theigor » Wed May 31, 2006 11:43 am

nvm, I just had to put an "&" in

Code: Select all

void AFrame::OnUpdateItem(wxUpdateUIEvent& event){ 
  event.Check(true); 
} 

Post Reply