kicad/pcbnew/layer_widget.cpp

684 lines
21 KiB
C++
Raw Normal View History

2010-01-07 02:18:25 +00:00
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* This source module implements the layer visibility and selection widget
*/
#define STAND_ALONE 1 // define to enable test program for LAYER_WIDGET
// also enable KICAD_AUIMANAGER and KICAD_AUITOOLBAR in ccmake to
// build this test program
#include <wx/wx.h>
2010-01-07 16:33:41 +00:00
#include <wx/statbmp.h>
2010-01-07 02:18:25 +00:00
#include <wx/aui/aui.h>
2010-01-10 07:56:07 +00:00
#include "macros.h"
2010-01-09 15:51:09 +00:00
#include "common.h"
#include "layer_panel_base.h"
#include "colors.h"
/* no external data knowledge needed or wanted
#include "pcbnew.h"
#include "wxPcbStruct.h"
*/
2010-01-07 16:33:41 +00:00
2010-01-11 16:49:11 +00:00
#define LAYER_COLUMN_COUNT 4
2010-01-07 16:33:41 +00:00
/* XPM */
static const char * clear_xpm[] = {
2010-01-08 01:17:59 +00:00
"28 14 1 1",
2010-01-07 16:33:41 +00:00
" c None",
2010-01-08 01:17:59 +00:00
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
2010-01-07 16:33:41 +00:00
/* XPM */
static const char * rightarrow_xpm[] = {
2010-01-08 01:17:59 +00:00
"28 14 5 1",
2010-01-07 16:33:41 +00:00
" c None",
". c white",
"X c #8080ff",
"o c BLUE",
"O c gray56",
2010-01-10 06:40:22 +00:00
" .X ",
2010-01-08 01:17:59 +00:00
" .XX ",
" .XXX ",
" .XXXX ",
" ................XXXXX ",
" XXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXX ",
" oooooooooooooooooooooooO",
" ooooooooooooooooooooooO ",
" OOOOOOOOOOOOOOOoooooO ",
" ooooO ",
" oooO ",
" ooO ",
" oO "};
2010-01-07 16:33:41 +00:00
2010-01-11 16:49:11 +00:00
/**
* Function layerId
* is here to allow saving a layer index within a control as its wxControl id,
* but to do so in a way that all child wxControl ids within a wxWindow are unique,
* since this is required by Windows.
* @see getLayerId()
*/
static int layerId( int aColumn, int aLayer )
{
int id = aLayer * LAYER_COLUMN_COUNT + aColumn;
return id;
}
/**
* Function getLayerId
* decodes \a aControlId to return a layer.
*/
static int getLayerId( int aControlId )
{
int layer = aControlId / LAYER_COLUMN_COUNT; // rounding is OK.
return layer;
}
/**
* Function makeColorTxt
* returns a string containing the numeric value of the color.
* in a form like 0x00000000. (Color is currently an index, not RGB).
*/
static wxString makeColorTxt( int aColor )
{
char colorValue[64];
sprintf( colorValue, "0x%08x", aColor );
return wxString( CONV_FROM_UTF8(colorValue) );
}
2010-01-07 02:18:25 +00:00
/**
* Struct LAYER_SPEC
2010-01-09 15:51:09 +00:00
* provides all the data needed to add a layer row to a LAYER_WIDGET
2010-01-07 02:18:25 +00:00
*/
struct LAYER_SPEC
{
wxString layerName;
2010-01-08 01:17:59 +00:00
int layer;
2010-01-10 07:56:07 +00:00
int color;
2010-01-07 02:18:25 +00:00
2010-01-10 07:56:07 +00:00
LAYER_SPEC( const wxString& aLayerName, int aLayer, int aColor = 0 )
2010-01-07 02:18:25 +00:00
{
layerName = aLayerName;
2010-01-08 01:17:59 +00:00
layer = aLayer;
2010-01-10 07:56:07 +00:00
color = aColor;
2010-01-07 02:18:25 +00:00
}
};
/**
2010-01-09 15:51:09 +00:00
* Class LAYER_WIDGET
* is abstract and is derived from a wxFormBuilder maintained class called
* LAYER_PANEL_BASE. It is used to manage a list of layers, with the notion of
* a "current" layer, and layer specific visibility control. You must derive from
* it to use it so you can implement the abstract functions which recieve the
* events. Each layer is given its own color, and that color can be changed
* within the UI provided here. This widget knows nothing of the client code, meaning
* it has no knowledge of a BOARD or anything. To use it you must derive from
* this class and implement the abstract functions:
* <p>
2010-01-11 16:49:11 +00:00
* void OnColorChange( int aLayer, int aColor );
2010-01-09 15:51:09 +00:00
* <p>
2010-01-11 16:49:11 +00:00
* bool OnLayerSelect( int aLayer );
* <p>
* void OnLayerVisible( int aLayer, bool isVisible );
2010-01-07 02:18:25 +00:00
*/
2010-01-09 15:51:09 +00:00
class LAYER_WIDGET : public LAYER_PANEL_BASE
2010-01-07 02:18:25 +00:00
{
2010-01-10 05:44:29 +00:00
#define MAX_LAYER_ROWS 64
2010-01-10 07:56:07 +00:00
#define BUTT_SIZE_X 32
#define BUTT_SIZE_Y 22
2010-01-11 16:49:11 +00:00
#define BUTT_VOID 6
2010-01-10 05:44:29 +00:00
2010-01-09 15:51:09 +00:00
protected:
2010-01-07 16:33:41 +00:00
wxBitmap* m_BlankBitmap;
wxBitmap* m_RightArrowBitmap;
wxSize m_BitmapSize;
2010-01-10 05:44:29 +00:00
int m_CurrentRow; ///< selected row of layer list
2010-01-07 16:33:41 +00:00
2010-01-11 16:49:11 +00:00
static wxBitmap makeBitmap( int aColor )
2010-01-07 02:18:25 +00:00
{
2010-01-11 16:49:11 +00:00
// the bitmap will be 8 pixels smaller than the button, leaving a
// border of 4 pixels on each side.
wxBitmap bitmap( BUTT_SIZE_X - 2 * BUTT_VOID, BUTT_SIZE_Y - 2 * BUTT_VOID );
2010-01-07 02:18:25 +00:00
wxBrush brush;
wxMemoryDC iconDC;
iconDC.SelectObject( bitmap );
2010-01-10 07:56:07 +00:00
brush.SetColour( MakeColour( aColor ) );
2010-01-07 02:18:25 +00:00
brush.SetStyle( wxSOLID );
iconDC.SetBrush( brush );
2010-01-11 16:49:11 +00:00
iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X - 2 * BUTT_VOID, BUTT_SIZE_Y - 2 * BUTT_VOID );
2010-01-07 02:18:25 +00:00
2010-01-10 07:56:07 +00:00
return bitmap;
}
/**
* Function makeColorButton
* creates a wxBitmapButton and assigns it a solid color and a control ID
*/
wxBitmapButton* makeColorButton( int aColor, int aID )
{
// dynamically make a wxBitMap and brush it with the appropriate color,
// then create a wxBitmapButton from it.
wxBitmap bitmap = makeBitmap( aColor );
2010-01-08 01:17:59 +00:00
wxBitmapButton* ret = new wxBitmapButton( m_LayerScrolledWindow, aID, bitmap,
2010-01-07 16:33:41 +00:00
wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y), wxBORDER_RAISED );
2010-01-10 07:56:07 +00:00
// save the color value in the name, no where else to put it.
ret->SetName( makeColorTxt( aColor ) );
2010-01-07 16:33:41 +00:00
return ret;
2010-01-07 02:18:25 +00:00
}
2010-01-08 01:17:59 +00:00
2010-01-07 02:18:25 +00:00
void OnLeftDownLayers( wxMouseEvent& event )
{
2010-01-09 15:51:09 +00:00
int row;
2010-01-11 16:49:11 +00:00
wxWindow* eventSource = (wxWindow*) event.GetEventObject();
2010-01-08 01:17:59 +00:00
// if mouse event is coming from the m_LayerScrolledWindow and not one
// of its children, we have to find the row manually based on y coord.
2010-01-11 16:49:11 +00:00
if( eventSource == m_LayerScrolledWindow )
2010-01-08 01:17:59 +00:00
{
int y = event.GetY();
wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights();
int height = 0;
int rowCount = GetLayerRowCount();
for( row = 0; row<rowCount; ++row )
{
if( y < height + heights[row] )
break;
height += heights[row];
}
if( row >= rowCount )
row = rowCount - 1;
}
else
{
2010-01-11 16:49:11 +00:00
// all nested controls on a given row will have their ID encoded with
// makeLayerId(), and the corresponding decoding is getLayerId()
int layer = getLayerId( eventSource ->GetId() );
2010-01-09 15:51:09 +00:00
row = findLayerRow( layer );
}
2010-01-08 01:17:59 +00:00
2010-01-11 16:49:11 +00:00
if( OnLayerSelect( row ) ) // if client allows this change.
2010-01-08 01:17:59 +00:00
SelectLayerRow( row );
2010-01-07 02:18:25 +00:00
}
2010-01-08 01:17:59 +00:00
2010-01-10 07:56:07 +00:00
/**
2010-01-11 16:49:11 +00:00
* Function OnMiddleDownLayerColor
* is called only from a color button when user right clicks.
2010-01-10 07:56:07 +00:00
*/
2010-01-11 16:49:11 +00:00
void OnMiddleDownLayerColor( wxMouseEvent& event )
2010-01-07 02:18:25 +00:00
{
2010-01-10 07:56:07 +00:00
wxBitmapButton* eventSource = (wxBitmapButton*) event.GetEventObject();
wxString colorTxt = eventSource->GetName();
int oldColor = strtoul( CONV_TO_UTF8(colorTxt), NULL, 0 );
int newColor = DisplayColorFrame( this, oldColor );
if( newColor >= 0 )
{
eventSource->SetName( makeColorTxt( newColor ) );
wxBitmap bm = makeBitmap( newColor );
eventSource->SetBitmapLabel( bm );
2010-01-11 16:49:11 +00:00
int layer = getLayerId( eventSource->GetId() );
// tell the client code.
OnColorChange( layer, newColor );
2010-01-10 07:56:07 +00:00
}
2010-01-07 02:18:25 +00:00
}
2010-01-08 01:17:59 +00:00
2010-01-11 16:49:11 +00:00
/**
* Function OnRightDownLayers
* puts up a popup menu for the layer panel.
*/
void OnRightDownLayers( wxMouseEvent& event )
{
// popup menu
printf( "OnRightDownLayers\n" );
}
/**
* Function OnLayerCheckBox
* handles the "is layer visible" checkbox and propogates the
* event to the client's notification function.
*/
void OnLayerCheckBox( wxCommandEvent& event )
{
wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
int layer = getLayerId( eventSource->GetId() );
OnLayerVisible( layer, eventSource->IsChecked() );
}
2010-01-07 16:33:41 +00:00
/**
* Function getLayerComp
* returns the component within the m_LayersFlexGridSizer at aSizerNdx.
2010-01-08 01:17:59 +00:00
*
* @param aSizerNdx is the 0 based index into all the wxWindows which have
* been added to the m_LayersFlexGridSizer.
2010-01-07 16:33:41 +00:00
*/
wxWindow* getLayerComp( int aSizerNdx )
{
return m_LayersFlexGridSizer->GetChildren()[aSizerNdx]->GetWindow();
}
2010-01-07 02:18:25 +00:00
2010-01-08 01:17:59 +00:00
/**
* Function findLayerRow
* returns the row index that \a aLayer resides in, or -1 if not found.
*/
int findLayerRow( int aLayer )
{
int count = GetLayerRowCount();
for( int row=0; row<count; ++row )
{
// column 0 in the layer scroll window has a wxStaticBitmap, get its ID.
wxStaticBitmap* bm = (wxStaticBitmap*) getLayerComp( row * LAYER_COLUMN_COUNT + 0 );
2010-01-11 16:49:11 +00:00
if( aLayer == getLayerId( bm->GetId() ))
2010-01-08 01:17:59 +00:00
return row;
}
return -1;
}
2010-01-07 16:33:41 +00:00
/**
2010-01-09 15:51:09 +00:00
* Function insertLayerRow
* appends or inserts a new row in the layer portion of the widget.
2010-01-07 16:33:41 +00:00
*/
2010-01-09 15:51:09 +00:00
void insertLayerRow( int aRow, const LAYER_SPEC& aSpec )
2010-01-07 16:33:41 +00:00
{
2010-01-10 05:44:29 +00:00
wxASSERT( aRow >= 0 && aRow < MAX_LAYER_ROWS );
2010-01-07 16:33:41 +00:00
2010-01-09 15:51:09 +00:00
size_t index = aRow * LAYER_COLUMN_COUNT;
2010-01-07 16:33:41 +00:00
2010-01-09 15:51:09 +00:00
wxSizerFlags flags;
2010-01-08 01:17:59 +00:00
2010-01-09 15:51:09 +00:00
flags.Align(wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
2010-01-07 16:33:41 +00:00
2010-01-09 15:51:09 +00:00
// column 0
2010-01-11 16:49:11 +00:00
wxStaticBitmap* sbm = new wxStaticBitmap( m_LayerScrolledWindow, layerId( 0, aSpec.layer ),
*m_BlankBitmap, wxDefaultPosition, m_BitmapSize );
sbm->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
sbm->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
2010-01-10 05:44:29 +00:00
m_LayersFlexGridSizer->Insert( index+0,
2010-01-11 16:49:11 +00:00
new wxSizerItem( sbm, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL ) ) );
2010-01-09 15:51:09 +00:00
// column 1
2010-01-11 16:49:11 +00:00
wxBitmapButton* bmb = makeColorButton( aSpec.color, layerId( 1, aSpec.layer ) );
bmb->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
bmb->Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnMiddleDownLayerColor ), NULL, this );
bmb->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
2010-01-09 15:51:09 +00:00
bmb->SetToolTip( _("Right click to change layer color, left click to select layer" ) );
2010-01-10 05:44:29 +00:00
m_LayersFlexGridSizer->Insert( index+1,
new wxSizerItem( bmb, flags ) );
2010-01-07 16:33:41 +00:00
2010-01-09 15:51:09 +00:00
// column 2
2010-01-11 16:49:11 +00:00
wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, layerId( 2, aSpec.layer ), aSpec.layerName );
2010-01-09 15:51:09 +00:00
st->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnLeftDownLayers ), NULL, this );
2010-01-11 16:49:11 +00:00
st->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
2010-01-09 15:51:09 +00:00
st->SetToolTip( _( "Click here to select this layer" ) );
2010-01-10 05:44:29 +00:00
m_LayersFlexGridSizer->Insert( index+2,
new wxSizerItem( st, wxSizerFlags().Align( wxALIGN_CENTER_VERTICAL )) );
2010-01-08 01:17:59 +00:00
2010-01-09 15:51:09 +00:00
// column 3
2010-01-11 16:49:11 +00:00
wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, layerId( 3, aSpec.layer ), wxEmptyString );
cb->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( LAYER_WIDGET::OnLayerCheckBox ), NULL, this );
2010-01-09 15:51:09 +00:00
cb->SetToolTip( _( "Enable this for visibility" ) );
2010-01-10 05:44:29 +00:00
m_LayersFlexGridSizer->Insert( index+3, new wxSizerItem( cb, flags ) );
2010-01-07 16:33:41 +00:00
}
2010-01-11 16:49:11 +00:00
2010-01-09 15:51:09 +00:00
public:
2010-01-07 16:33:41 +00:00
2010-01-07 02:18:25 +00:00
/** Constructor */
2010-01-09 15:51:09 +00:00
LAYER_WIDGET( wxWindow* parent ) :
2010-01-07 02:18:25 +00:00
LAYER_PANEL_BASE( parent )
{
2010-01-07 16:33:41 +00:00
m_CurrentRow = 0;
m_RightArrowBitmap = new wxBitmap( rightarrow_xpm );
m_BlankBitmap = new wxBitmap( clear_xpm ); // translucent
2010-01-07 02:18:25 +00:00
2010-01-07 16:33:41 +00:00
m_BitmapSize = wxSize(m_BlankBitmap->GetWidth(), m_BlankBitmap->GetHeight());
2010-01-11 16:49:11 +00:00
m_LayerScrolledWindow->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( LAYER_WIDGET::OnRightDownLayers ), NULL, this );
2010-01-09 15:51:09 +00:00
AppendLayerRow( LAYER_SPEC( wxT("layer 1"), 0, RED ) );
AppendLayerRow( LAYER_SPEC( wxT("layer 2"), 1, GREEN ) );
AppendLayerRow( LAYER_SPEC( wxT("brown_layer"), 2, BROWN ) );
AppendLayerRow( LAYER_SPEC( wxT("layer_4_you"), 3, BLUE ) );
2010-01-07 16:33:41 +00:00
SelectLayerRow( 1 );
2010-01-10 05:44:29 +00:00
2010-01-11 16:49:11 +00:00
SetMinSize( GetPreferredSize() );
}
/**
* Function GetPreferredSize
* returns the preferred minimum size, taking into consideration the
* dynamic content. Nothing in wxWidgets was reliable enough.
*/
wxSize GetPreferredSize()
{
m_LayersFlexGridSizer->Layout();
wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths();
int totWidth = 0;
for( int i=0; i<LAYER_COLUMN_COUNT; ++i )
{
totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap();
printf("widths[%d]:%d\n", i, widths[i] );
}
wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights();
int totHeight = 0;
int rowCount = GetLayerRowCount();
for( int i=0; i<rowCount; ++i )
{
totHeight += heights[i] + m_LayersFlexGridSizer->GetVGap();
printf("heights[%d]:%d\n", i, heights[i] );
}
wxSize layerPanelSize( totWidth, totHeight );
// this aint done yet, just a place holder for more work.
2010-01-10 05:44:29 +00:00
2010-01-11 16:49:11 +00:00
return layerPanelSize;
2010-01-07 02:18:25 +00:00
}
2010-01-07 16:33:41 +00:00
2010-01-09 15:51:09 +00:00
/**
* Function GetLayerRowCount
* returns the number of rows in the layer tab.
*/
2010-01-11 16:49:11 +00:00
int GetLayerRowCount() const
2010-01-09 15:51:09 +00:00
{
int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount();
return controlCount / LAYER_COLUMN_COUNT;
}
/**
* Function AppendLayerRow
* appends a new row in the layer portion of the widget.
*/
void AppendLayerRow( const LAYER_SPEC& aSpec )
{
int nextRow = GetLayerRowCount();
insertLayerRow( nextRow, aSpec );
}
2010-01-11 16:49:11 +00:00
/**
* Function ClearLayerRows
* empties out the layer rows.
*/
void ClearLayerRows()
{
m_LayerScrolledWindow->DestroyChildren();
}
2010-01-09 15:51:09 +00:00
/**
* Function SelectLayerRow
* changes the row selection in the layer list to the given row.
*/
bool SelectLayerRow( int aRow )
{
2010-01-11 16:49:11 +00:00
// enable the layer tab at index 0
m_notebook->ChangeSelection( 0 );
2010-01-09 15:51:09 +00:00
if( (unsigned) aRow < (unsigned) GetLayerRowCount() )
{
int newNdx = LAYER_COLUMN_COUNT * aRow;
int oldNdx = LAYER_COLUMN_COUNT * m_CurrentRow;
wxStaticBitmap* oldbm = (wxStaticBitmap*) getLayerComp( oldNdx );
wxStaticBitmap* newbm = (wxStaticBitmap*) getLayerComp( newNdx );
oldbm->SetBitmap( *m_BlankBitmap );
newbm->SetBitmap( *m_RightArrowBitmap );
m_CurrentRow = aRow;
2010-01-11 16:49:11 +00:00
// Change the focus to the wxBitmapButton in column 1 for this row.
// We really do not need or want the focus, but because we get focus
// and it changes the appearance of these wxBitmapButtons, if any focused
// button is going to look different, we want it to be the current
// row.
getLayerComp( newNdx + 1 /* 1 is column */ )->SetFocus();
// Make sure the desired layer row is visible.
// It seems that as of 2.8.2, setting the focus
// does this and generally I don't expect the scrolling to be needed at all because
// the minimum window size may end up being established by the number of layers.
2010-01-09 15:51:09 +00:00
return true;
}
return false;
}
/**
* Function SelectLayer
2010-01-11 16:49:11 +00:00
* changes the row selection in the layer list to \a aLayer provided.
2010-01-09 15:51:09 +00:00
*/
bool SelectLayer( int aLayer )
{
int row = findLayerRow( aLayer );
return SelectLayerRow( row );
}
2010-01-11 16:49:11 +00:00
2010-01-10 05:44:29 +00:00
//-----<abstract functions>-------------------------------------------
2010-01-09 15:51:09 +00:00
/**
2010-01-11 16:49:11 +00:00
* Function OnColorChange
* is called to notify client code about a layer color change. Derived
2010-01-09 15:51:09 +00:00
* classes will handle this accordingly.
*/
2010-01-11 16:49:11 +00:00
virtual void OnColorChange( int aLayer, int aColor ) = 0;
/**
* Function OnLayerSelect
* is called to notify client code whenever the user selects a different
* layer. Derived classes will handle this accordingly, and can deny
* the change by returning false.
*/
virtual bool OnLayerSelect( int aLayer ) = 0;
2010-01-09 15:51:09 +00:00
/**
2010-01-11 16:49:11 +00:00
* Function OnLayerVisible
* is called to notify client code about a layer visibility change.
2010-01-09 15:51:09 +00:00
*/
2010-01-11 16:49:11 +00:00
virtual void OnLayerVisible( int aLayer, bool isVisible ) = 0;
2010-01-07 02:18:25 +00:00
2010-01-10 05:44:29 +00:00
//-----</abstract functions>------------------------------------------
2010-01-07 02:18:25 +00:00
2010-01-10 05:44:29 +00:00
};
2010-01-07 02:18:25 +00:00
#if defined(STAND_ALONE)
/**
* Class MYFRAME
* is a test class here to exercise the LAYER_WIDGET and explore use cases.
* @see http://www.kirix.com/labs/wxaui/screenshots.html
* for ideas.
*/
2010-01-09 15:51:09 +00:00
class MYFRAME : public wxFrame
{
2010-01-10 05:44:29 +00:00
// example of how to derive from LAYER_WIDGET in order to provide the
// abstract methods.
2010-01-09 15:51:09 +00:00
class MYLAYERS : public LAYER_WIDGET
{
MYFRAME* frame;
public:
2010-01-10 06:40:22 +00:00
// your constructor could take a BOARD argument. here I leave it
// out because this source module wants to know nothing of BOARDs
// to maximize re-use.
2010-01-09 15:51:09 +00:00
MYLAYERS( wxWindow* aParent, MYFRAME* aFrame ) :
LAYER_WIDGET( aParent ),
frame( aFrame )
{
}
2010-01-11 16:49:11 +00:00
void OnColorChange( int aLayer, int aColor )
2010-01-09 15:51:09 +00:00
{
2010-01-11 16:49:11 +00:00
printf( "OnColorChange( aLayer:%d, aColor:%d )\n", aLayer, aColor );
// a test trigger only
if( aLayer == 2 )
{
ClearLayerRows();
printf(" GetLayerRowCount(): %d\n", GetLayerRowCount() );
}
2010-01-09 15:51:09 +00:00
}
2010-01-11 16:49:11 +00:00
bool OnLayerSelect( int aLayer )
2010-01-09 15:51:09 +00:00
{
2010-01-11 16:49:11 +00:00
printf( "OnLayerSelect( aLayer:%d )\n", aLayer );
2010-01-09 15:51:09 +00:00
return true;
}
2010-01-11 16:49:11 +00:00
void OnLayerVisible( int aLayer, bool isVisible )
{
printf( "OnLayerVisible( aLayer:%d, isVisible:%d )\n", aLayer, isVisible );
}
2010-01-09 15:51:09 +00:00
};
2010-01-07 02:18:25 +00:00
public:
2010-01-10 06:40:22 +00:00
MYFRAME( wxWindow * parent ) :
wxFrame( parent, -1, _( "wxAUI Test" ), wxDefaultPosition,
wxSize( 800, 600 ), wxDEFAULT_FRAME_STYLE )
2010-01-07 02:18:25 +00:00
{
// notify wxAUI which frame to use
m_mgr.SetManagedWindow( this );
2010-01-11 16:49:11 +00:00
MYLAYERS* layerWidget = new MYLAYERS( this, this );
2010-01-07 02:18:25 +00:00
wxTextCtrl* text2 = new wxTextCtrl( this, -1, _( "Pane 2 - sample text" ),
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
wxTextCtrl* text3 = new wxTextCtrl( this, -1, _( "Main content window" ),
wxDefaultPosition, wxSize( 200, 150 ),
wxNO_BORDER | wxTE_MULTILINE );
// add the panes to the manager
2010-01-10 06:40:22 +00:00
wxAuiPaneInfo li;
2010-01-11 16:49:11 +00:00
li.MinSize( layerWidget->GetPreferredSize() ); // ignored on linux
li.BestSize( layerWidget->GetPreferredSize() );
2010-01-10 06:40:22 +00:00
li.Left();
2010-01-11 16:49:11 +00:00
li.MaximizeButton( true );
li.MinimizeButton( true );
2010-01-10 06:40:22 +00:00
li.CloseButton( false );
li.Caption( wxT( "Layers" ) );
m_mgr.AddPane( layerWidget, li );
2010-01-07 02:18:25 +00:00
m_mgr.AddPane( text2, wxBOTTOM, wxT( "Pane Number Two" ) );
m_mgr.AddPane( text3, wxCENTER );
// tell the manager to "commit" all the changes just made
m_mgr.Update();
}
~MYFRAME()
{
// deinitialize the frame manager
m_mgr.UnInit();
}
private:
wxAuiManager m_mgr;
};
// our normal wxApp-derived class, as usual
2010-01-10 07:56:07 +00:00
class MyApp : public wxApp
{
2010-01-07 02:18:25 +00:00
public:
bool OnInit()
{
wxFrame* frame = new MYFRAME( NULL );
SetTopWindow( frame );
frame->Show();
return true;
}
};
DECLARE_APP( MyApp );
IMPLEMENT_APP( MyApp );
2010-01-11 16:49:11 +00:00
#endif // STAND_ALONE