Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.95 KB | None | 0 0
  1. void MyFrame::CreateControls()
  2. {
  3.  
  4.    
  5.     //Adding menu and menu items . To add menu items add your code here.
  6.    
  7.    
  8.     wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL);
  9.     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
  10.     button_sizer->Add(
  11.         new wxButton( this, wxID_LOAD, "Load" ),
  12.         0,           // make horizontally unstretchable
  13.         wxALL,       // make border all around (implicit top alignment)
  14.         10 );        // set border width to 10
  15.     button_sizer->Add(
  16.         new wxButton( this, wxID_CANCEL, "Cancel" ),
  17.         0,           // make horizontally unstretchable
  18.         wxALL,       // make border all around (implicit top alignment)
  19.         10 );        // set border width to 10
  20.  
  21.     wxBoxSizer *tree_sizer = new wxBoxSizer( wxHORIZONTAL );
  22.    
  23.  
  24.     tree = new MyTreeCtrl(this, wxID_TREE,
  25.         wxDefaultPosition, wxSize(250,300),
  26.         wxTR_DEFAULT_STYLE);
  27.     tree->mypanel = new MyPanel(this,wxID_PANEL,wxDefaultPosition,wxSize(250,250),wxTAB_TRAVERSAL|wxBORDER_SUNKEN);
  28.    
  29.    
  30.     tree_sizer->Add(tree,1,wxEXPAND |    // make horizontally stretchable
  31.         wxALL|wxALIGN_LEFT,        //   and make border all around
  32.         10);
  33.     tree_sizer->Add(tree->mypanel,1,wxEXPAND |    // make horizontally stretchable
  34.         wxALL|wxALIGN_LEFT,        //   and make border all around
  35.         10);
  36.  
  37.     mainsizer->Add(tree_sizer,1,            // make vertically stretchable
  38.         wxEXPAND |    // make horizontally stretchable
  39.         wxALL|wxALIGN_CENTRE,        //   and make border all around
  40.         10);
  41.     mainsizer->Add(
  42.         button_sizer,
  43.         0,                // make vertically unstretchable
  44.         wxALIGN_CENTRE ); // no border and allign right
  45.  
  46.     SetSizer(mainsizer );      // use the sizer for layout
  47.     this->Refresh(true);
  48.     this->Show(true);
  49. };
  50.  
  51.  
  52.  
  53. void MyTreeCtrl::OnSelChanged(wxTreeEvent& event)
  54. {
  55.     wxTreeItemId itemId = event.GetItem();
  56.     this->SetEventItemId(itemId);
  57.     wxString name=this->GetItemText(itemId);
  58.     wxTreeItemData *data=new MyData();
  59.     MyData* tData;
  60.     data=this->GetItemData(itemId);
  61.     tData = dynamic_cast<MyData*>(data);
  62.     wxTreeItemId rootid = this->GetRootItem();
  63.     if (itemId == rootid)
  64.     {
  65.         this->PopulateTextNode();
  66.     }
  67.     else if (tData->type == wxXML_ELEMENT_NODE)
  68.     {
  69.         this->PopulateElementNode(itemId);
  70.     }
  71.     else
  72.         this->PopulateTextNode();
  73.  
  74. }
  75.  
  76.  
  77.  
  78.    1.
  79.       void MyTreeCtrl::PopulateElementNode(wxTreeItemId &id)
  80.    2.
  81.       {
  82.    3.
  83.        
  84.    4.
  85.       //adding panel control elements and setting its sizer
  86.    5.
  87.        
  88.    6.
  89.          //the next two lines do not work .  A MyTreeCtrl  and a MyPanel are children of MyFrame ,which is the top level window. A MyPanel object exists inside MyTreeCtrl Class.An event on a node in the tree should populate the panel.I am setting a sizer with the panel ,but it does not get set. The sizer for the toplevel frame was set at a different place before this event.
  90.    7.
  91.        
  92.    8.
  93.               wxBoxSizer *paneltopsizer = new wxBoxSizer(wxVERTICAL);
  94.    9.
  95.               (this->mypanel)->SetSizer(paneltopsizer);
  96.   10.
  97.        
  98.   11.
  99.        
  100.   12.
  101.               this->MyListCtrl=new wxListCtrl(this->mypanel,
  102.   13.
  103.                       wxID_LISTCTRL,wxDefaultPosition,wxSize(245,100),wxLC_REPORT);
  104.   14.
  105.               wxButton *Add=new wxButton(this->mypanel,wxID_ADD,wxT("Add"));
  106.   15.
  107.               *Delete=new wxButton(this->mypanel,wxID_DELETE,wxT("Delete"));
  108.   16.
  109.               wxButton *ApplyChanges=new wxButton(this->mypanel,wxID_APPLYCHANGES,wxT("ApplyChanges"));
  110.   17.
  111.        
  112.   18.
  113.               wxBoxSizer *panelbuttonsizer = new wxBoxSizer(wxHORIZONTAL);
  114.   19.
  115.               panelbuttonsizer->Add(Add,0,wxALL|wxALIGN_RIGHT,5);
  116.   20.
  117.               panelbuttonsizer->Add(Delete,0,wxALL|wxALIGN_RIGHT,5);
  118.   21.
  119.               panelbuttonsizer->Add(ApplyChanges,0,wxALL|wxALIGN_RIGHT,5);
  120.   22.
  121.               paneltopsizer->Add(this->MyListCtrl,1,wxALL|wxEXPAND,10);
  122.   23.
  123.               paneltopsizer->Add(panelbuttonsizer,0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
  124.   24.
  125.        
  126.   25.
  127.       //panel control ends
  128.   26.
  129.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement