Exemplo n.º 1
0
void GUIFrame::AddPanel_5()
{
    m_panel5 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );

    wxFlexGridSizer* fgSizer4;
    fgSizer4 = new wxFlexGridSizer( 0, 2, 0, 0 );
    fgSizer4->SetFlexibleDirection( wxBOTH );
    fgSizer4->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );

    wxString m_choice1Choices[] = { _("wxChoice"), _("Item1"), _("Item2"), _("Item3"), _("Item4") };
    int m_choice1NChoices = sizeof( m_choice1Choices ) / sizeof( wxString );
    m_choice1 = new wxChoice( m_panel5, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choice1NChoices, m_choice1Choices, 0 );
    m_choice1->SetSelection( 0 );
    fgSizer4->Add( m_choice1, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 20 );

    m_comboBox1 = new wxComboBox( m_panel5, wxID_ANY, _("wxComboBox"), wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
    m_comboBox1->Append( _("wxComboBox") );
    m_comboBox1->Append( _("Item1") );
    m_comboBox1->Append( _("Item2") );
    m_comboBox1->Append( _("Item3") );
    m_comboBox1->Append( _("Item4") );
    m_comboBox1->Select(0);
    // To look better under gtk
    #ifdef __WXGTK__
    m_comboBox1->Delete(4);
    #endif
    fgSizer4->Add( m_comboBox1, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 20 );

    fgSizer4->Add( 0, 120, 1, wxEXPAND, 5 );

    fgSizer4->Add( 0, 120, 1, wxEXPAND, 5 );

    /*
    Create the wxBitmapComboBox control with wxCB_READONLY to ensure
    it shows a bitmap next to the edit field which is more suitable
    for a screenshot.
    */
    m_bmpComboBox1 = new wxBitmapComboBox(m_panel5, wxID_ANY,_("Item1"),
        wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY);
    m_bmpComboBox1->Append(_("Item1"), wxBitmap(wxT("bitmaps/bell.png"),wxBITMAP_TYPE_PNG));
    m_bmpComboBox1->Append(_("Item2"), wxBitmap(wxT("bitmaps/sound.png"),wxBITMAP_TYPE_PNG));
    m_bmpComboBox1->Append(_("Item3"), wxBitmap(wxT("bitmaps/bell.png"),wxBITMAP_TYPE_PNG));
    m_bmpComboBox1->Append(_("Item4"), wxBitmap(wxT("bitmaps/sound.png"),wxBITMAP_TYPE_PNG));
    m_bmpComboBox1->SetToolTip(_("wxBitmapComboBox"));
    m_bmpComboBox1->SetSelection(0);
    fgSizer4->Add(m_bmpComboBox1, m_commonExpandFlags);


    m_ownerDrawnComboBox1 = PenStyleComboBox::CreateSample(m_panel5);
    m_ownerDrawnComboBox1->SetToolTip(_("wxOwnerDrawnComboBox"));
    fgSizer4->Add(m_ownerDrawnComboBox1, m_commonExpandFlags);

    fgSizer4->Add( 0, 90, 1, wxEXPAND, 5 );

    fgSizer4->Add( 0, 90, 1, wxEXPAND, 5 );

    //wxComboCtrl 1
        m_comboCtrl1 = new wxComboCtrl(m_panel5,wxID_ANY,wxEmptyString);
        // first of all, set the popup control!
        ListViewComboPopup* popupList = new ListViewComboPopup();
        m_comboCtrl1->SetPopupControl(popupList);
        m_comboCtrl1->SetPopupMaxHeight(80);

        m_comboCtrl1->SetText(wxT("wxComboCtrl"));
        m_comboCtrl1->SetToolTip(_("wxComboCtrl"));

        // Populate using wxListView methods
        popupList->InsertItem(popupList->GetItemCount(),wxT("wxComboCtrl"));
        popupList->InsertItem(popupList->GetItemCount(),wxT("with"));
        popupList->InsertItem(popupList->GetItemCount(),wxT("wxListView"));
        popupList->InsertItem(popupList->GetItemCount(),wxT("popup"));
        popupList->InsertItem(popupList->GetItemCount(),wxT("Item1"));
        popupList->InsertItem(popupList->GetItemCount(),wxT("Item2"));
        popupList->InsertItem(popupList->GetItemCount(),wxT("Item3"));

        popupList->Select(0, true);
        fgSizer4->Add(m_comboCtrl1, m_commonExpandFlags);

    //wxComboCtrl 2
        m_comboCtrl2 = new wxComboCtrl(m_panel5,wxID_ANY,wxEmptyString);
        // first of all, set the popup control!
        TreeCtrlComboPopup* popupTree = new TreeCtrlComboPopup();
        m_comboCtrl2->SetPopupControl(popupTree);
        m_comboCtrl2->SetPopupMaxHeight(80);

        m_comboCtrl2->SetText(wxT("wxComboCtrl"));
        m_comboCtrl2->SetToolTip(_("wxComboCtrl"));

        //Add a root and some nodes using wxTreeCtrl methods
        wxTreeItemId root = popupTree->AddRoot(_("wxComboCtrl"));

        popupTree->AppendItem(root, _("with"));
        popupTree->AppendItem(root, _("wxTreeCtrl"));

        wxTreeItemId node2 = popupTree->AppendItem(root, _("popout"));
        popupTree->AppendItem(node2, _("Node1"));
        popupTree->AppendItem(node2, _("Node2"));

        popupTree->ExpandAll();
        fgSizer4->Add(m_comboCtrl2, m_commonExpandFlags);

    m_panel5->SetSizer( fgSizer4 );
    m_panel5->Layout();
    fgSizer4->Fit( m_panel5 );

    m_notebook1->AddPage( m_panel5, _("Drop-down Controls"), false );
}
Exemplo n.º 2
0
// frame constructor
MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
    wxBoxSizer* topSizer;
    wxBoxSizer* topRowSizer;
    wxBoxSizer* colSizer;
    wxBoxSizer* rowSizer;

    // set the frame icon
    SetIcon(wxICON(sample));

#if wxUSE_MENUS
    // create a menu bar
    wxMenu *fileMenu = new wxMenu;

    // the "About" item should be in the help menu
    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(ComboCtrl_About, wxT("&About\tF1"), wxT("Show about dialog"));

    fileMenu->Append(ComboCtrl_Compare, wxT("&Compare against wxComboBox..."),
        wxT("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
    fileMenu->AppendSeparator();
    fileMenu->Append(ComboCtrl_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));

    // now append the freshly created menu to the menu bar...
    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, wxT("&File"));
    menuBar->Append(helpMenu, wxT("&Help"));

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);
#endif // wxUSE_MENUS

    wxPanel* panel = new wxPanel(this);

    // Prepare log window right away since it shows EVT_TEXTs
    m_logWin = new wxTextCtrl(panel, 105, wxEmptyString,
                              wxDefaultPosition,
                              wxSize(-1, 125),
                              wxTE_MULTILINE);
    wxLogTextCtrl* logger = new wxLogTextCtrl(m_logWin);
    m_logOld = logger->SetActiveTarget(logger);
    logger->DisableTimestamp();


    topSizer = new wxBoxSizer( wxVERTICAL );

    topRowSizer = new wxBoxSizer( wxHORIZONTAL );

    colSizer = new wxBoxSizer( wxVERTICAL );


    wxComboCtrl* cc;
    wxGenericComboCtrl* gcc;
    wxOwnerDrawnComboBox* odc;

    // Create common strings array
    m_arrItems.Add( wxT("Solid") );
    m_arrItems.Add( wxT("Transparent") );
    m_arrItems.Add( wxT("Dot") );
    m_arrItems.Add( wxT("Long Dash") );
    m_arrItems.Add( wxT("Short Dash") );
    m_arrItems.Add( wxT("Dot Dash") );
    m_arrItems.Add( wxT("Backward Diagonal Hatch") );
    m_arrItems.Add( wxT("Cross-diagonal Hatch") );
    m_arrItems.Add( wxT("Forward Diagonal Hatch") );
    m_arrItems.Add( wxT("Cross Hatch") );
    m_arrItems.Add( wxT("Horizontal Hatch") );
    m_arrItems.Add( wxT("Vertical Hatch") );


    //
    // Create pen selector ODComboBox with owner-drawn items
    //
    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    rowSizer->Add( new wxStaticText(panel,wxID_ANY,
                   wxT("OwnerDrawnComboBox with owner-drawn items:")), 1,
                   wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );

    rowSizer = new wxBoxSizer( wxHORIZONTAL );


    // When defining derivative class for callbacks, we need
    // to use two-stage creation (or redefine the common wx
    // constructor).
    odc = new wxPenStyleComboBox();
    odc->Create(panel,wxID_ANY,wxEmptyString,
                wxDefaultPosition, wxDefaultSize,
                m_arrItems,
                wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
               );


    odc->SetSelection(0);

    rowSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
    rowSizer->AddStretchSpacer(1);
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );



    //
    // Same but with changed button position
    //
    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    rowSizer->Add( new wxStaticText(panel,wxID_ANY,
                   wxT("OwnerDrawnComboBox with owner-drawn items and button on the left:")), 1,
                   wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );

    rowSizer = new wxBoxSizer( wxHORIZONTAL );


    // When defining derivative class for callbacks, we need
    // to use two-stage creation (or redefine the common wx
    // constructor).
    odc = new wxPenStyleComboBox();
    odc->Create(panel,wxID_ANY,wxEmptyString,
                wxDefaultPosition, wxDefaultSize,
                m_arrItems,
                wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
               );


    odc->SetSelection(0);

    // Use button size that is slightly smaller than the default.
    wxSize butSize = odc->GetButtonSize();
    odc->SetButtonPosition(butSize.x - 2, // button width
                           butSize.y - 6, // button height
                           wxLEFT, // side
                           2 // horizontal spacing
                          );

    rowSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
    rowSizer->AddStretchSpacer(1);
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );


    //
    // List View wxComboCtrl
    //

    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    rowSizer->Add( new wxStaticText(panel,
                        wxID_ANY,
                        "List View wxComboCtrl (custom animation):"),
                   1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
    rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("Tree Ctrl wxComboCtrl:")), 1,
                   wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );

    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    cc = new wxComboCtrlWithCustomPopupAnim();

    // Let's set a custom style for the contained wxTextCtrl. We need to
    // use two-step creation for it to work properly.
    cc->SetTextCtrlStyle(wxTE_RIGHT);

    cc->Create(panel, wxID_ANY, wxEmptyString);

    // Make sure we use popup that allows focusing the listview.
    cc->UseAltPopupWindow();

    cc->SetPopupMinWidth(300);

    ListViewComboPopup* iface = new ListViewComboPopup();
    cc->SetPopupControl(iface);

    int i;
    for ( i=0; i<100; i++ )
        iface->AddSelection( wxString::Format(wxT("Item %02i"),i));

    rowSizer->Add( cc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );


    //
    // Tree Ctrl wxComboCtrl
    //

    // Note that we test that wxGenericComboCtrl works
    gcc = new wxGenericComboCtrl(panel,wxID_ANY,wxEmptyString,
                                 wxDefaultPosition, wxDefaultSize);

    // Make sure we use popup that allows focusing the treectrl.
    gcc->UseAltPopupWindow();

    // Set popup interface right away, otherwise some of the calls
    // below may fail
    TreeCtrlComboPopup* tcPopup = new TreeCtrlComboPopup();
    gcc->SetPopupControl(tcPopup);

    // Add items using wxTreeCtrl methods directly
    wxTreeItemId rootId = tcPopup->AddRoot(wxT("<hidden_root>"));

    wxTreeItemId groupId;

    for ( i=0; i<4; i++ )
    {
        groupId = tcPopup->AppendItem(rootId,
            wxString::Format(wxT("Branch %02i"),i));

        int n;
        for ( n=0; n<25; n++ )
            tcPopup->AppendItem(groupId,
                wxString::Format(wxT("Subitem %02i"),(i*25)+n));
    }

    gcc->SetValue(wxT("Subitem 05"));

    // Move button to left - it makes more sense for a tree ctrl
    gcc->SetButtonPosition(-1, // button width
                           -1, // button height
                           wxLEFT, // side
                           0 // horizontal spacing
                          );

    rowSizer->Add( gcc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );

    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );

#if wxUSE_IMAGE
    wxInitAllImageHandlers();

    //
    // Custom Dropbutton Bitmaps
    // (second one uses blank button background)
    //
    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    rowSizer->Add( new wxStaticText(panel,wxID_ANY,
                   wxT("OwnerDrawnComboBox with simple dropbutton graphics:")), 1,
                   wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );

    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );

    rowSizer = new wxBoxSizer( wxHORIZONTAL );

    odc = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
                                   wxDefaultPosition, wxDefaultSize,
                                   m_arrItems,
                                   (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
                                  );

    wxOwnerDrawnComboBox* odc2;
    odc2 = new wxOwnerDrawnComboBox(panel,wxID_ANY,wxEmptyString,
                                    wxDefaultPosition, wxDefaultSize,
                                    m_arrItems,
                                    (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
                                   );

    // Load images from disk
    wxImage imgNormal(wxT("dropbutn.png"));
    wxImage imgPressed(wxT("dropbutp.png"));
    wxImage imgHover(wxT("dropbuth.png"));

    if ( imgNormal.IsOk() && imgPressed.IsOk() && imgHover.IsOk() )
    {
        wxBitmap bmpNormal(imgNormal);
        wxBitmap bmpPressed(imgPressed);
        wxBitmap bmpHover(imgHover);
        odc->SetButtonBitmaps(bmpNormal,false,bmpPressed,bmpHover);
        odc2->SetButtonBitmaps(bmpNormal,true,bmpPressed,bmpHover);
    }
    else
        wxLogError(wxT("Dropbutton images not found"));

    //odc2->SetButtonPosition(0, // width adjustment
    //                        0, // height adjustment
    //                        wxLEFT, // side
    //                        0 // horizontal spacing
    //                       );

    rowSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
    rowSizer->Add( odc2, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );
#endif


    //
    // wxComboCtrl with totally custom button action (open file dialog)
    //
    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    rowSizer->Add( new wxStaticText(panel,wxID_ANY,
                        wxT("wxComboCtrl with custom button action:")), 1,
                   wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );


    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );

    rowSizer = new wxBoxSizer( wxHORIZONTAL );
    wxFileSelectorCombo* fsc;

    fsc = new wxFileSelectorCombo(panel,wxID_ANY,wxEmptyString,
                                  wxDefaultPosition, wxDefaultSize,
                                  (long)0
                                 );

    rowSizer->Add( fsc, 1, wxALIGN_CENTER_VERTICAL|wxALL, 4 );
    colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 );


    // Make sure GetFeatures is implemented
    wxComboCtrl::GetFeatures();


    topRowSizer->Add( colSizer, 1, wxALL, 2 );

    colSizer = new wxBoxSizer( wxVERTICAL );

    colSizer->AddSpacer(8);
    colSizer->Add( new wxStaticText(panel, wxID_ANY, wxT("Log Messages:")), 0, wxTOP|wxLEFT, 3 );
    colSizer->Add( m_logWin, 1, wxEXPAND|wxALL, 3 );

    topRowSizer->Add( colSizer, 1, wxEXPAND|wxALL, 2 );
    topSizer->Add( topRowSizer, 1, wxEXPAND );

    panel->SetSizer( topSizer );
    topSizer->SetSizeHints( panel );

    Fit();
    Centre();
}