00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "a2dprec.h"
00012
00013 #ifdef __BORLANDC__
00014 #pragma hdrstop
00015 #endif
00016
00017 #include "wx/canvas/canmod.h"
00018 #include "wx/editor/doccancom.h"
00019 #include "wx/canvas/layerinf.h"
00020
00021 #include "wx/editor/identifydlg.h"
00022
00023
00024 IMPLEMENT_DYNAMIC_CLASS( IdentifyDialog, wxDialog )
00025
00026 BEGIN_EVENT_TABLE( IdentifyDialog, wxDialog )
00027 EVT_BUTTON (ID_IDENT_HIDE, IdentifyDialog::hide)
00028 EVT_BUTTON (ID_IDENT_UPDATE,IdentifyDialog::Update)
00029 EVT_ACTIVATE (IdentifyDialog::OnActivate)
00030 EVT_CLOSE (IdentifyDialog::OnCloseWindow)
00031 EVT_SIZE (IdentifyDialog::OnSize )
00032 EVT_DO (IdentifyDialog::OnDoEvent )
00033 EVT_COM_EVENT (IdentifyDialog::OnComEvent )
00034 END_EVENT_TABLE()
00035
00036
00037
00038
00039 IdentifyDialog::IdentifyDialog( )
00040 {
00041 a2dDocviewGlobals->GetEventDistributer()->Register( this );
00042 m_showObject = NULL;
00043 }
00044
00045 IdentifyDialog::IdentifyDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00046 {
00047 a2dDocviewGlobals->GetEventDistributer()->Register( this );
00048 Create(parent, id, caption, pos, size, style);
00049 }
00050
00051 IdentifyDialog::~IdentifyDialog( )
00052 {
00053 a2dDocviewGlobals->GetEventDistributer()->Unregister( this );
00054 }
00055
00056
00057
00058
00059
00060 bool IdentifyDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00061 {
00062 m_showObject = NULL;
00063 m_objectsList = NULL;
00064 m_update = NULL;
00065
00066 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00067 wxDialog::Create( parent, id, caption, pos, size, style );
00068
00069 CreateControls();
00070
00071
00072 Centre();
00073 return TRUE;
00074 }
00075
00076
00077
00078
00079 void IdentifyDialog::CreateControls()
00080 {
00081 IdentifyDialog* itemDialog1 = this;
00082
00083 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00084 itemDialog1->SetSizer(itemBoxSizer2);
00085
00086 wxString* m_objectsListStrings = NULL;
00087 m_objectsList = new wxListBox( itemDialog1, ID_IDENT_LISTBOX, wxDefaultPosition, wxDefaultSize, 0, m_objectsListStrings, wxLB_SINGLE|wxLB_NEEDED_SB|wxLB_SORT );
00088 m_objectsList->SetHelpText(_("Object selected for identify"));
00089 if (ShowToolTips())
00090 m_objectsList->SetToolTip(_("Object selected for identify"));
00091 itemBoxSizer2->Add(m_objectsList, 1, wxGROW|wxALL, 0);
00092
00093 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
00094 itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
00095
00096 wxButton* itemButton5 = new wxButton( itemDialog1, ID_IDENT_HIDE, _("Hide"), wxDefaultPosition, wxDefaultSize, 0 );
00097 itemButton5->SetHelpText(_("Hide dialog"));
00098 if (ShowToolTips())
00099 itemButton5->SetToolTip(_("Hide dialog"));
00100 itemBoxSizer4->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
00101
00102 m_update = new wxButton( itemDialog1, ID_IDENT_UPDATE, _("Update"), wxDefaultPosition, wxDefaultSize, 0 );
00103 m_update->SetHelpText(_("Update dialog for selected objects in view"));
00104 if (ShowToolTips())
00105 m_update->SetToolTip(_("Update dialog for selected objects in view"));
00106 itemBoxSizer4->Add(m_update, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
00107 }
00108
00109
00110
00111
00112 bool IdentifyDialog::ShowToolTips()
00113 {
00114 return TRUE;
00115 }
00116
00117 void IdentifyDialog::hide(wxCommandEvent &)
00118 {
00119 m_objectsList->Clear();
00120 Show( FALSE );
00121 }
00122
00123 void IdentifyDialog::OnCloseWindow(wxCloseEvent& event)
00124 {
00125 m_objectsList->Clear();
00126 Show( FALSE );
00127 }
00128
00129 void IdentifyDialog::Update(wxCommandEvent &)
00130 {
00131 Init( m_showObject );
00132 }
00133
00134 void IdentifyDialog::Init( a2dCanvasObject* showObject )
00135 {
00136 m_objectsList->Clear();
00137 if ( !showObject )
00138 return;
00139
00140 m_showObject = showObject;
00141
00142 a2dCanvasObjectList* childList = m_showObject->GetChildObjectList();
00143 for( a2dCanvasObjectList::iterator iter = childList->begin(); iter != childList->end(); ++iter )
00144 {
00145 a2dCanvasObject *obj = (*iter);
00146 if ( obj->GetSelected() )
00147 {
00148 wxString layerName;
00149 a2dCanvasDocument* rootdoc = obj->GetCanvasDocument();
00150 a2dLayerInfo* layerobj;
00151 if ( rootdoc->GetLayerSetup() )
00152 layerobj = rootdoc->GetLayerSetup()->GetLayerIndex()[obj->GetLayer()];
00153 if ( layerobj != wxNullLayerInfo )
00154 layerName = layerobj->GetName();
00155
00156 wxString listline;
00157 listline = wxString::Format( wxT("layerId=%d layer=%s "), obj->GetLayer(), layerName.c_str() );
00158 listline += wxString::Format( wxT("x=%lg, y=%lg "), obj->GetPosX(), obj->GetPosY() );
00159 listline << wxT("name=") << obj->GetName() << wxT(" class=") << obj->GetClassInfo()->GetClassName();
00160 m_objectsList->Append( listline );
00161 }
00162 }
00163 }
00164
00165 void IdentifyDialog::OnActivate(wxActivateEvent& viewevent)
00166 {
00167 a2dCanvasView* view = wxDynamicCast( viewevent.GetEventObject(), a2dCanvasView );
00168 viewevent.Skip();
00169
00170 if ( ! view )
00171 return;
00172
00173 Init( view->GetShowObject() );
00174 }
00175
00176
00177 void IdentifyDialog::OnSize(wxSizeEvent& WXUNUSED(event) )
00178 {
00179 Layout();
00180 }
00181 void IdentifyDialog::OnDoEvent( a2dCommandProcessorEvent& event )
00182 {
00183 wxString cmdName = event.GetCommand()->GetName();
00184
00185 if ( event.GetCommand()->GetCommandId() == &a2dCommand_SetShowObject::Id )
00186 {
00187 a2dCanvasView* drawer = a2dGetCmdh()->CheckDrawer();
00188 if ( drawer )
00189 {
00190 m_showObject = drawer->GetShowObject();
00191 Init( m_showObject );
00192 }
00193 }
00194 }
00195
00196 void IdentifyDialog::OnComEvent( a2dComEvent& event )
00197 {
00198 if ( event.GetEventComId() == &a2dCanvasView::sm_changedShowObject )
00199 {
00200
00201
00202
00203 a2dCanvasObject* newtop = wxStaticCast( event.GetProperty()->GetRefObject(), a2dCanvasObject );
00204 if ( newtop )
00205 {
00206 m_showObject = newtop;
00207 Init( m_showObject );
00208 }
00209 }
00210 else
00211 event.Skip();
00212 }
00213