How to activate a view

a2dView is most of the time activated via events from wxWidgets when a wxWidgets gets the focus or the wxWidgets containing the a2dView (also nested as a child of a wxFrame) is activated. One can force a view to be active by calling:

a2dView::Activate( true )

this leads to one of these depending if you are using only docview module or also the canvas module:

   1 a2dDocumentCommandProcessor::OnActivateView()
   2 a2dCentralCanvasCommandProcessor::OnActivateView()

Or your own central command processor which can intercept wxEVT_ACTIVATE_VIEW. Or actually any class registered to the global a2dEventDistributer found via a2dGeneralGlobals->GetEventDistibuter().

See a2dView::Activate() for how the wxEVT_ACTIVATE_VIEW is distributed via a2dObject::DistributeEvent(). And also notice that there is yet another one set direct up the m_display window chain, called wxEVT_ACTIVATE_VIEW_SENT_FROM_CHILD. This last one make the window containing the view, know what is the their current view.

Now a2dDocumentCommandProcessor::OnActivateView() calls the next, which disable the last active view and sets the new one as being the new current view for the commandprocessor:

   1 a2dDocumentCommandProcessor::SetActiveView( a2dView* )

So when is a2dView::Activate() itself called? The a2dView::ProcessEvent() takes the following events to do that:

The above event or coming from the m_display of the a2dView, being a a2dDocumentFrame or a2dViewWindow derived class, which have m_view pointer them selfs, and event processing to redirect above event to the a2dView before treating the event themselfs. Notice also a2dDocumentFrame::OnActivateViewSentFromChild() which sets this pointer.

There or several reasons to activate a a2dView without an event doing it, search for Activate() in docviewref.cpp for knowing when. The main reason for calling it so often, is to let the the commandprocessor have the current active view set correctly or as expected.

A related topic DetectActivateView.

wxArt2D: ActivateView (last edited 2008-08-08 22:35:33 by KlaasHolwerda)