Skip to content

Commit

Permalink
Merge pull request #142 from halfer/auimanager4
Browse files Browse the repository at this point in the history
Bug fixes and notes for further work for the AUI demo
  • Loading branch information
jgmdev committed Feb 6, 2016
2 parents 9601372 + 76ba31a commit e85f6f2
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
50 changes: 47 additions & 3 deletions examples/AUI/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use wxPoint;
use wxEvent;
use wxAuiManagerEvent;
use wxAuiPaneInfo;

class controllerDialog extends \wxDialog
Expand All @@ -14,6 +15,7 @@ class controllerDialog extends \wxDialog
use \WxPhpExamples\AUI\Pane;

protected $managedWindow;
protected $windowSaves = [];

// Frame captions are read from the window and stored here
protected $captions = [
Expand Down Expand Up @@ -61,6 +63,7 @@ public function SetManagedWindow(auiDemoDialog $managedWindow)

$this->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, array($this, "onTickboxChangeEvent"));
$this->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, "onButtonClick"));
$managedWindow->Connect(wxEVT_AUI_PANE_CLOSE, array($this, "onPaneClose"));
}

public function onTickboxChangeEvent(wxEvent $event)
Expand Down Expand Up @@ -121,20 +124,61 @@ protected function tickBoxIterator($function)
/**
* This is called when any button click event happens in this window
*
* @todo Move the contents of this method to another one called reopenAllPanes()
*
* @param wxEvent $event
*/
public function onButtonClick(wxEvent $event)
{
// Not currently checking which button was clicked, as this is the only button
$this->reopenAllPanes();
}

protected function reopenAllPanes()
{
// Show all available panes
for($i = 0; $i <= 7; $i++)
{
$this->getPaneInfoByIndex($i)->Show();
if (isset($this->windowSaves[$i]))
{
// Any items in here must be closed, since open windows do not feature
// in the saved windows array
$this->getManagedWindow()->getAuiManager()->LoadPaneInfo(
$this->windowSaves[$i],
$this->getPaneInfoByIndex($i)
);
}
}

// Redraw the managed window
$this->getManagedWindow()->getAuiManager()->Update();

// Once we have restored the panes we can throw their saves states away - this
// will be re-added when they close
$this->windowSaves = [];
}

/**
* Handles the pane close before it is closed (it can still be vetoed)
*
* The logic here determines the index of the closing pane, and uses this to save its
* pre-close perspective string.
*
* @param wxAuiManagerEvent $event
*/
public function onPaneClose(wxAuiManagerEvent $event)
{
// In the absence of being able to read the pane name from a paneinfo method, we
// can parse it out from the perpective string
$info = $event->GetPane();
$persp = $this->getManagedWindow()->getAuiManager()->SavePaneInfo($info);

// Fish out the number, which represents the pane ordinal
$matches = [];
preg_match('#name=auiPane(\d+)#', $persp, $matches);
if ($matches)
{
$index = $matches[1];
$this->windowSaves[$index] = $persp;
}
}

public function onSpinnerChangeEvent(wxEvent $event)
Expand Down
6 changes: 6 additions & 0 deletions examples/AUI/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public function getPaneSettings($name)
return $this->getAuiManager()->GetPane($name);
}

/**
* Returns the window item from the managed pane
*
* @param integer $index
* @return \wxWindow
*/
public function getWindowByIndex($index)
{
return $this->controls[$index];
Expand Down
10 changes: 7 additions & 3 deletions examples/AUI/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
*
* /usr/bin/php -d extension=wxwidgets.so AUI/main.php
*
* @todo Is there a better way to refresh panes other than detaching and re-adding? This
* sometimes moves the pane to a new attachment location, which is confusing
* @todo If resizeable is turned off, I often get crashes on resize - wxPHP issue? I have
* disabled this control for now, but readers can re-enable it if they wish
* @todo If gripper is turned off, disable gripper top and unselect it
* @todo Repeated clicking on the gripper tickbox for various panes results eventually in a
* wxPHP segmentation fault - I expect this would be less of a problem if pane updates
* were done in a better fashion (see pane.php:onPaneTickBoxChange) but this issue
* would be good to fix C-side anyway
* @todo An existing bug: for a pane that has a top gripper at start up, if the gripper flag
* is turned off and then on again, the gripper moves to the side even though the top flag
* is on. However toggling the top flag stops this behaviour. Needs some looking into.
*/

namespace WxPhpExamples\AUI;
Expand Down
32 changes: 32 additions & 0 deletions examples/AUI/pane.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ trait Pane
* move. It's not a bad start, but I'd like to improve this, see:
* http://stackoverflow.com/q/34597763
*
* 2016-01-31: I've tried to replace the DetachPane/AddPane with code that resets the
* perspective, to force a redraw without needing to re-attach but this does not always work:
*
* $perspective = $manager->SavePaneInfo($this->getPaneInfoByIndex($paneIndex));
* $manager->LoadPaneInfo($perspective, $this->getPaneInfoByIndex($paneIndex));
*
* Setting the gripper (top or side) works fine without either this block or attaching and
* reattaching. However it looks like detect/re-attach is necessary for close, pin and
* maximise buttons. Could be a wxPHP bug?
*
* @param wxEvent $event
*/
protected function onPaneTickBoxChange(wxEvent $event)
Expand Down Expand Up @@ -42,6 +52,24 @@ protected function onPaneTickBoxChange(wxEvent $event)

// Now redraw the panes
$this->getManagedWindow()->getAuiManager()->Update();

$this->applySpecialRules($ctrl);
}

/**
* If the supplied tickbox is the gripper tick, this shows/hides the top gripper tick
*
* This helps to indicate that the top gripper flag will not make any difference unless
* the gripper flag is set also.
*
* @param wxCheckBox $ctrl
*/
protected function applySpecialRules(wxCheckBox $ctrl)
{
if ($ctrl->GetName() == 'tickGripper')
{
$this->setTickBoxEnabled('tickGripperTop', $ctrl->GetValue(), false);
}
}

/**
Expand Down Expand Up @@ -86,6 +114,10 @@ protected function setPaneTickBoxValues($pane)
$boolean = $paneInfo->$methodName();
$this->setTickBoxValue($controlName, $boolean);
}

// Apply special rules at the start
$ctrl = wxDynamicCast($this->FindWindow('tickGripper'), "wxCheckBox");
$this->applySpecialRules($ctrl);
}

/**
Expand Down

0 comments on commit e85f6f2

Please sign in to comment.