Kirix Support Forums

Pane Activation Events

Please post any wxAUI patches or modifications you've created here. Thanks!

Pane Activation Events

Postby AmorphisOne on Wed May 17, 2006 10:16 am

Hi, as Ben proposed here i've put together my changes to evaluate the activation & deactivation of a pane. I'm unsure if anyone else finds this useful - but for my purpose it works. What the change does is to send an EVT_ACTIVATE,true to the panel that transits from inactive to active state and, on the other hand sends EVT_ACTIVATE,false to the former active panel (if any). It handles active floating panes as well. Of course only if the ActivePane Option is set in the framemanager.
The patch is either available here : http://www.geminirealms.de/dta/activation_event.p
or here :
Code: Select all
--- D:\GR\spectre\code\inc\3rdParty\wxAui0.9.2\original\manager.h   Wed Apr 19 17:19:36 2006
+++ D:\GR\spectre\code\inc\3rdParty\wxAui0.9.2\manager.h   Wed May 17 16:53:15 2006
@@ -418,7 +418,7 @@
     void OnFloatingPaneMoveStart(wxWindow* window);
     void OnFloatingPaneMoving(wxWindow* window);
     void OnFloatingPaneMoved(wxWindow* window);
-    void OnFloatingPaneActivated(wxWindow* window);
+    void OnFloatingPaneActivate(wxWindow* window,bool state);
     void OnFloatingPaneClosed(wxWindow* window);
     void OnFloatingPaneResized(wxWindow* window, const wxSize& size);
     void Render(wxDC* dc);
@@ -447,6 +447,7 @@
     void OnPaneButton(wxFrameManagerEvent& event);
     void OnChildFocus(wxChildFocusEvent& event);
     void OnHintFadeTimer(wxTimerEvent& event);
+   void OnActivate(wxActivateEvent& event);

private:

--- D:\GR\spectre\code\src\3rdParty\wxAui0.9.2\original\manager.cpp   Wed May 03 20:39:52 2006
+++ D:\GR\spectre\code\src\3rdParty\wxAui0.9.2\manager.cpp   Wed May 17 16:57:41 2006
@@ -698,10 +698,8 @@

     void OnActivate(wxActivateEvent& event)
     {
-        if (event.GetActive())
-        {
-            m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
-        }
+        // notify the owner manager that the panes activation changed
+        m_owner_mgr->OnFloatingPaneActivate(m_pane_window,event.GetActive());
     }

     // utility function which determines the state of the mouse button
@@ -745,7 +743,7 @@
     EVT_MOVING(wxFloatingPane::OnMoveEvent)
     EVT_CLOSE(wxFloatingPane::OnClose)
     EVT_IDLE(wxFloatingPane::OnIdle)
-    EVT_ACTIVATE(wxFloatingPane::OnActivate)
+   EVT_ACTIVATE(wxFloatingPane::OnActivate)
END_EVENT_TABLE()


@@ -1020,21 +1018,53 @@
     }
}

+static void KillActivePane(wxPaneInfoArray& panes)
+{
+    int i, pane_count;
+    for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
+    {
+        wxPaneInfo& pane = panes.Item(i);
+        if (pane.state & wxPaneInfo::optionActive)
+      {
+         pane.state &= ~wxPaneInfo::optionActive;   // Generate a deactivation event for
+         wxActivateEvent e(wxEVT_ACTIVATE,false);   // the pane that becomes deactivated
+         pane.window->ProcessEvent(e);
+      } // if (pane.state & wxPaneInfo::optionActive)
+   }

-
+}
static void SetActivePane(wxPaneInfoArray& panes, wxWindow* active_pane)
{
     int i, pane_count;
     for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
     {
         wxPaneInfo& pane = panes.Item(i);
-        pane.state &= ~wxPaneInfo::optionActive;
+       
         if (pane.window == active_pane)
-            pane.state |= wxPaneInfo::optionActive;
+      {
+         if (!(pane.state & wxPaneInfo::optionActive))
+         {
+            pane.state |= wxPaneInfo::optionActive;
+            wxActivateEvent e(wxEVT_ACTIVATE,true);      // Generate an activation event for
+            pane.window->ProcessEvent(e);            // the pane that becomes activated
+            pane.window->SetFocus();               // and transfer focus to activated pane
+            
+         } // if (!(pane.state & wxPaneInfo::optionActive))
+           
+      } // if (pane.window == active_pane)
+      else
+      {
+         if (pane.state & wxPaneInfo::optionActive)
+         {
+            pane.state &= ~wxPaneInfo::optionActive;   // Generate a deactivation event for
+            wxActivateEvent e(wxEVT_ACTIVATE,false);   // the pane that becomes deactivated
+            pane.window->ProcessEvent(e);
+         } // if (pane.state & wxPaneInfo::optionActive)
+         
+      }
     }
}

-
// this function is used to sort panes by dock position
static int PaneSortFunc(wxPaneInfo** p1, wxPaneInfo** p2)
{
@@ -1057,6 +1087,7 @@
     EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow)
     EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus)
     EVT_TIMER(101, wxFrameManager::OnHintFadeTimer)
+   EVT_ACTIVATE( wxFrameManager::OnActivate )
END_EVENT_TABLE()


@@ -3450,8 +3481,8 @@
     pane.frame = NULL;
     pane.Hide();
}
-
-void wxFrameManager::OnFloatingPaneActivated(wxWindow* wnd)
+// We're now passing the activation state
+void wxFrameManager::OnFloatingPaneActivate(wxWindow* wnd,bool state)
{
     if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
     {
@@ -3459,7 +3490,8 @@
         wxPaneInfo& pane = GetPane(wnd);
         wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));

-        SetActivePane(m_panes, wnd);
+      if (state) SetActivePane(m_panes, wnd);
+      else KillActivePane(m_panes);
         Repaint();
     }
}
@@ -4162,3 +4194,24 @@
         Update();
     }
}
+
+// OnActivate() is an event handler that gets called when
+// the frame managed by the frame manager gets activated / deactivated
+void wxFrameManager::OnActivate(wxActivateEvent& event)
+{
+    int i, pane_count;
+    for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
+    {
+        wxPaneInfo& pane = m_panes.Item(i);
+       
+      // Loop through all valid panes and check if one of them was activated
+      // before, if so, "reactivate" it
+      if (event.GetActive() && (pane.state & wxPaneInfo::optionActive))      // Only send to the pane that was active before
+      {
+         wxActivateEvent e(wxEVT_ACTIVATE,true);   // the pane that was last activated
+         pane.window->ProcessEvent(e);
+         
+      } // if (pane.state & wxPaneInfo::optionActive)
+    }
+   event.Skip();   // let other handlers also process this message
+}
\ No newline at end of file


AmorphisOne
AmorphisOne
Registered User
 
Posts: 3
Joined: Thu May 11, 2006 2:56 pm

Return to wxAUI Patches & Modifications