wxviewiordialog.cpp

来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 271 行

CPP
271
字号
// @file wxViewIORDialog.cpp
//
// @author Charlie Frasch  <cfrasch@atdesk.com>
//
// wxViewIORDialog.cpp,v 1.4 2003/11/21 14:54:42 schmidt Exp

#include "pch.h"
#include "wxViewIORDialog.h"

#include "tao/Profile.h"
#include "tao/Stub.h"
#include "wx/sizer.h"
#include "wx/textctrl.h"
#include "wx/treectrl.h"
#include "wxNamingViewer.h"

namespace  // anonymous
{
  void create_dialog_components( wxDialog* dialog)
    {
      wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL);
 
      {
        wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
        sizer->Add(
                   new wxStaticText( dialog, -1, "IOR:" ),
                   0,
                   wxALL,
                   5);
        wxTextCtrl* iorText = new wxTextCtrl(
                                             dialog,
                                             IDC_IOR
                                             );
        iorText->SetName( "iorText");
        sizer->Add(
                   iorText,
                   1,
                   wxALL,
                   5);
        topsizer->Add(
                      sizer,
                      0,
                      wxALIGN_LEFT | wxEXPAND);
      }
 
      {
        wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
        sizer->Add(
                   new wxStaticText( dialog, -1, "Repository ID:" ),
                   0,
                   wxALL,
                   5);
        wxTextCtrl* typeID = new wxTextCtrl(
                                            dialog,
                                            IDC_TYPE_ID
                                            );
        typeID->SetName( "typeIDText");
        sizer->Add(
                   typeID,
                   1,
                   wxALL,
                   5);
        topsizer->Add(
                      sizer,
                      0,
                      wxALIGN_LEFT | wxEXPAND);
      }
 
      {
        wxTreeCtrl* profiles = new wxTreeCtrl(
                                              dialog,
                                              IDC_PROFILES,
                                              wxDefaultPosition,
                                              wxSize( 675, 140)
                                              );
        profiles->SetName( "profilesTree");
        topsizer->Add(
                      profiles,
                      1,
                      wxALL | wxEXPAND,
                      5);
      }
  
      wxBoxSizer* button_sizer = new wxBoxSizer( wxHORIZONTAL);
      {
        wxButton* okButton = new wxButton( dialog, wxID_OK, "OK" );
        okButton->SetName( "okButton");
        button_sizer->Add(
                          okButton,
                          0,
                          wxALL,
                          5);
      }
      {
        wxButton* applyButton = new wxButton( dialog, wxID_APPLY, "Apply" );
        applyButton->SetName( "applyButton");
        button_sizer->Add(
                          applyButton,
                          0,
                          wxALL,
                          5);
      }
      {
        button_sizer->Add(
                          new wxButton( dialog, wxID_CANCEL, "Cancel" ),
                          0,
                          wxALL,
                          5);
      }
      topsizer->Add(
                    button_sizer,
                    0,
                    wxALIGN_CENTER);
 
      dialog->SetSizer( topsizer);
      topsizer->SetSizeHints( dialog);
    }
 
};  // anonymous

BEGIN_EVENT_TABLE( WxViewIORDialog, wxDialog)
  EVT_BUTTON( wxID_APPLY, WxViewIORDialog::OnApply)
  EVT_TEXT( IDC_IOR, WxViewIORDialog::onIORText)
END_EVENT_TABLE()


WxViewIORDialog::WxViewIORDialog(
    CORBA::ORB_ptr orb,
    CORBA::Object_ptr object,
    wxWindow* parent)
#if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  : wxDialog()
#else
  : wxDialog(
      parent,
      IDD_NAMINGVIEWER_DIALOG,
      "View IOR",
      wxDefaultPosition,
      wxSize(394,127),
      wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU,
      "viewIOR")
#endif  // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  , orb( orb)
{
#if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  LoadFromResource( parent, "viewIOR");
#else
  create_dialog_components( this);
#endif  // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  iorText = static_cast<wxTextCtrl*>( wxFindWindowByName(
      "iorText",
      this));
  assert( iorText);
  typeIDText = static_cast<wxTextCtrl*>( wxFindWindowByName(
      "typeIDText",
      this));
  assert( typeIDText);
  profiles = static_cast<wxTreeCtrl*>( wxFindWindowByName(
      "profilesTree",
      this));
  assert( typeIDText);
  wxButton* ctrl = static_cast<wxButton*>( wxFindWindowByName(
      "okButton",
      this));
  assert( ctrl);
  ctrl->SetDefault();
  applyButton = static_cast<wxButton*>( wxFindWindowByName(
      "applyButton",
      this));
  assert( applyButton);
  applyButton->Enable( false);

  if (object != CORBA::Object::_nil()) {

    WxViewIORDialog::object = CORBA::Object::_duplicate( object);

  }
  CORBA::String_var ior = orb->object_to_string( object);
  WxViewIORDialog::ior = ior;
  decodeIOR();
}


void WxViewIORDialog::decodeIOR()
{
  profiles->DeleteAllItems();

  // if object is nil, return out
  if(CORBA::is_nil( object.in())) {

    typeID = "";
    TransferDataToWindow();
    return;

  }

  // Get the stub
  TAO_Stub* stub = object->_stubobj();
  const char* type = stub->type_id;
  typeID = type ? type : ""; // special case for INS objects, tao doesn't get the type id
  TransferDataToWindow();

  // Iterate through each profile and add an entry to the tree control
  const TAO_MProfile& baseProfiles = stub->base_profiles();
  CORBA::ULong count = baseProfiles.profile_count();
  wxTreeItemId rootItem = profiles->AddRoot( "Profiles");
  for( CORBA::ULong slot = 0; slot < count; slot++) {

    const TAO_Profile* profile = baseProfiles.get_profile( slot);
    ACE_DECLARE_NEW_CORBA_ENV;
    ACE_TRY {

      // The need to const_cast should disappear in TAO 1.1.2 BUT IT DIDN'T
      char* profileString =
          const_cast<TAO_Profile*>(profile)->to_string(ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;
      profiles->AppendItem( rootItem, profileString);
      delete [] profileString;

    } ACE_CATCH( CORBA::Exception, ex) {

      wxMessageBox( ex._info().c_str(), "CORBA::Exception");

    } ACE_ENDTRY;

  }
  profiles->Expand( rootItem);
}


void WxViewIORDialog::OnApply( wxCommandEvent& event)
{
  wxDialog::OnApply( event);
  try {

    object = orb->string_to_object( ior);
    decodeIOR();

  } catch( CORBA::Exception& ex) {

    wxMessageBox( ex._info().c_str(), "CORBA::Exception");
  }
}


void WxViewIORDialog::onIORText( wxCommandEvent& event)
{
  // Enable the Apply button if the IOR has changed
  if (event.GetString() != ior) {

    applyButton->Enable( true);

  }
}


bool WxViewIORDialog::TransferDataFromWindow()
{
  ior = iorText->GetValue();
  return true;
}


bool WxViewIORDialog::TransferDataToWindow()
{
  iorText->SetValue( ior);
  typeIDText->SetValue( typeID);
  return true;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?