Skip to content

Commit

Permalink
Added drag and drop example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmdev committed Jun 8, 2015
1 parent 39aa75c commit ddc5dfa
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
132 changes: 132 additions & 0 deletions examples/dragdrop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

/**
* Define Text Drop Target class
*/
class TextDropTarget extends wxTextDropTarget
{
public $obj;

function __construct($obj)
{
parent::__construct();

$this->obj = $obj;
}

public function OnDropText($x, $y, $data)
{
$this->obj->Clear();
$this->obj->WriteText($data);
}
}

/**
* Define File Drop Target class
*/
class FileDropTarget extends wxFileDropTarget
{
public $obj;

function __construct($obj)
{
parent::__construct();

$this->obj = $obj;
}

public function OnDropFiles($x, $y, $filenames)
{
$this->obj->Clear();

$files = "";
foreach($filenames as $file)
{
$files .= $file . "\n";
}

$this->obj->WriteText($files);
}
}

/**
* Main window with 2 drop targets.
*/
class MainWindow extends wxFrame {

function __construct( $parent=null ){
parent::__construct ( $parent, wxID_ANY, "Drag and Drop Sample", wxDefaultPosition, new wxSize( 500,300 ), wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );

$this->SetSizeHints( wxDefaultSize, wxDefaultSize );

$bSizer1 = new wxBoxSizer( wxVERTICAL );

$bSizer4 = new wxBoxSizer( wxVERTICAL );

$this->m_staticText1 = new wxStaticText( $this, wxID_ANY, "Drop Text:", wxDefaultPosition, wxDefaultSize, 0 );
$this->m_staticText1->Wrap( -1 );
$bSizer4->Add( $this->m_staticText1, 0, wxALL, 5 );


$bSizer1->Add( $bSizer4, 0, wxEXPAND, 5 );

$bSizer2 = new wxBoxSizer( wxVERTICAL );

$this->m_textCtrl1 = new wxTextCtrl( $this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxTE_MULTILINE );
$bSizer2->Add( $this->m_textCtrl1, 1, wxALL|wxEXPAND, 5 );


$bSizer1->Add( $bSizer2, 1, wxEXPAND, 5 );

$bSizer41 = new wxBoxSizer( wxVERTICAL );

$this->m_staticText11 = new wxStaticText( $this, wxID_ANY, "Drop Files:", wxDefaultPosition, wxDefaultSize, 0 );
$this->m_staticText11->Wrap( -1 );
$bSizer41->Add( $this->m_staticText11, 0, wxALL, 5 );


$bSizer1->Add( $bSizer41, 0, wxEXPAND, 5 );

$bSizer21 = new wxBoxSizer( wxVERTICAL );

$this->m_textCtrl11 = new wxTextCtrl( $this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxTE_MULTILINE|wxTE_READONLY );
$bSizer21->Add( $this->m_textCtrl11, 1, wxALL|wxEXPAND, 5 );


$bSizer1->Add( $bSizer21, 1, wxEXPAND, 5 );


$this->SetSizer( $bSizer1 );
$this->Layout();
$this->m_menubar1 = new wxMenuBar( 0 );
$this->m_menu1 = new wxMenu();
$this->m_menuItem1 = new wxMenuItem( $this->m_menu1, wxID_ANY, "&Quit", wxEmptyString, wxITEM_NORMAL );
$this->m_menu1->Append( $this->m_menuItem1 );

$this->m_menubar1->Append( $this->m_menu1, "&File" );

$this->SetMenuBar( $this->m_menubar1 );


$this->Centre( wxBOTH );

// Drag stuff
$dt2 = new TextDropTarget($this->m_textCtrl1);
$this->m_textCtrl1->SetDropTarget($dt2);

$dt3 = new FileDropTarget($this->m_textCtrl11);
$this->m_textCtrl11->SetDropTarget($dt3);

// Connect Events
$this->Connect( $this->m_menuItem1->GetId(), wxEVT_COMMAND_MENU_SELECTED, array($this, "CloseWindow") );
}

function CloseWindow( $event ){
$this->Close();
}

}

$window = new MainWindow();
$window->Show();
wxEntry();
7 changes: 7 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
* Removed trace of debugging code.
* Merge child class method overrides that differ into parent methods
which should fix #97.
* Added drag and drop example.
* Disabled pointer deletion for wxDropTarget and child classes
to fix segmentation fault which fixes #98.
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -178,6 +181,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file name="examples/statbar/red.xpm" role="doc" />
<file name="examples/statbar/sample.xpm" role="doc" />
<file name="examples/statbar/statbar.php" role="doc" />
<file name="examples/dragdrop.php" role="doc" />
<file name="examples/choicelistbox.php" role="doc" />
<file name="examples/grid.php" role="doc" />
<file name="examples/styledtextctrl.php" role="doc" />
Expand Down Expand Up @@ -261,6 +265,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
* Removed trace of debugging code.
* Merge child class method overrides that differ into parent methods
which should fix #97.
* Added drag and drop example.
* Disabled pointer deletion for wxDropTarget and child classes
to fix segmentation fault which fixes #98.
</notes>
</release>
<release>
Expand Down

0 comments on commit ddc5dfa

Please sign in to comment.