summaryrefslogtreecommitdiff
path: root/TAO/utils/wxNamingViewer/wxBindDialog.cpp
blob: 008b52677961ef5a2c3a628d01f5bbf3c41ed320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// @file wxBindDialog.cpp
//
// @author Charlie Frasch  <cfrasch@atdesk.com>
//
// $Id$

#include "pch.h"
#include "wxBindDialog.h"

#include "wxAutoDialog.h"
#include "wxNamingViewer.h"
#include "wxViewIORDialog.h"

#include "wx/sizer.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, "ID:" ), 0, wxALL, 5);
    wxTextCtrl* text = new wxTextCtrl(dialog, IDC_ID);
    text->SetName("idTextCtrl");
    sizer->Add(text, 1, wxALL, 5);
    topsizer->Add(sizer, 0, wxALIGN_LEFT | wxEXPAND);
  }

  {
    wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
    sizer->Add(new wxStaticText(dialog, -1, "Kind:" ), 0, wxALL, 5);
    wxTextCtrl* text = new wxTextCtrl(dialog, IDC_KIND);
    text->SetName("kindTextCtrl");
    sizer->Add(text, 1, wxALL, 5);
    topsizer->Add(sizer, 0, wxALIGN_LEFT | wxEXPAND);
  }

  {
    wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
    sizer->Add(new wxStaticText( dialog, -1, "IOR:" ), 0, wxALL, 5);
    wxTextCtrl* text = new wxTextCtrl(dialog, IDC_IOR);
    text->SetName( "iorTextCtrl");
    sizer->Add(text, 1, wxALL, 5);
    topsizer->Add(sizer, 0, wxALIGN_LEFT | wxEXPAND);
  }

  wxBoxSizer* button_sizer = new wxBoxSizer( wxHORIZONTAL);
  {
    wxButton* button = new wxButton( dialog, wxID_OK, "OK" );
    button->SetName( "okButton");
    button_sizer->Add(button, 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( WxBindDialog, wxDialog)
  EVT_BUTTON( IDC_VIEWIOR, WxBindDialog::onViewIOR)
END_EVENT_TABLE()


WxBindDialog::WxBindDialog(
    bool isContext,
    CORBA::ORB_ptr orb,
    wxWindow* parent)
#if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  : wxDialog()
#else
  : wxDialog(
      parent,
      IDD_BIND,
      "Bind Object/Context",
      wxDefaultPosition,
      wxSize( 300, 75),
      wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU,
      "bindObject")
#endif  // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  , ior()
  , id ()
  , kind ()
  , object ()
  , orb (orb)
  , name ()
  , isContext (isContext)
{
#if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  LoadFromResource( parent, "bindObject");
#else
  create_dialog_components( this);
#endif  // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
  if (isContext) {

    SetTitle( "Bind Context");

  } else {

    SetTitle( "Bind Object");
  }
  wxButton* ctrl = static_cast<wxButton*>( wxFindWindowByName(
      "okButton",
      this));
  assert( ctrl);
  ctrl->SetDefault();
}


void WxBindDialog::onViewIOR( wxCommandEvent& WXUNUSED(event))
{
  TransferDataFromWindow();
  WxAutoDialog<WxViewIORDialog> dialog( new WxViewIORDialog( orb, object.in(), 0));
  dialog->ShowModal();
}


bool WxBindDialog::TransferDataFromWindow()
{
  wxTextCtrl* ctrl = static_cast<wxTextCtrl*>( wxFindWindowByName(
      "iorTextCtrl",
      this));
  assert( ctrl);
  ior = ctrl->GetValue();

  ctrl = static_cast<wxTextCtrl*>( wxFindWindowByName(
      "idTextCtrl",
      this));
  assert( ctrl);
  id = ctrl->GetValue();

  ctrl = static_cast<wxTextCtrl*>( wxFindWindowByName(
      "kindTextCtrl",
      this));
  assert( ctrl);
  kind = ctrl->GetValue();

  name.length( 1);
  name[0].id = CORBA::string_dup( id);
  name[0].kind = CORBA::string_dup( kind);
  try {

    object = orb->string_to_object( ior);

  } catch(CORBA::Exception& ex) {

    wxMessageBox( ex._rep_id(), "Invalid IOR");
    object = CORBA::Object::_nil();

  }
  return true;
}