own Popup for wxcomboctrl (wxPanel) Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 183
Joined: Mon Jan 28, 2019 8:22 am

own Popup for wxcomboctrl (wxPanel)

Post by Wolfgang »

I have problem the popup does not all the time show, and if it shows it only appears for a glimpse.
With this I define the popup.

Code: Select all

 lv_buname = new wxComboCtrlWithCustomPopupAnim();
    lv_buname->SetTextCtrlStyle(wxTE_RIGHT);
    lv_buname->Create(tb1);
    lv_buname->UseAltPopupWindow();
    lv_buname->SetId(ID_lv_buname);
    llv_buname->SetInitialSize(wxSize(200, 30));
    ownpanel* itest;
    itest = new ownpanel(this);
    wxComboCtrl::GetFeatures();
    lv_buname->SetPopupControl(itest);
    lv_buname->SetPopupMinWidth(150 * (hcol + 1));
    lv_buname->SetPopupMaxHeight(count / (hcol + 1) * 19.5 + 7);
    lv_buname->SetText(bunam[subnr[jetwin]].Upper());
    tb1->AddControl(lv_buname);

Code: Select all

class ownpanel : public wxComboPopup, public wxListView,public wxPanel
{

    virtual bool Create(wxWindow* parent) wxOVERRIDE
    {
        wxPanel *mynewpanel;
        mynewpanel= new wxPanel(parent);
        wxBoxSizer* msiz = new wxBoxSizer(wxVERTICAL);
        wxListView* myview = new wxListView(mynewpanel, 1,
            wxPoint(0, 0), wxDefaultSize,
            //    wxLC_LIST | wxLC_SINGLE_SEL | wxSIMPLE_BORDER
            wxLC_REPORT | wxLC_SINGLE_SEL | wxSIMPLE_BORDER);
        myview->SetId(9191);
        myview->AppendColumn("", wxLIST_FORMAT_LEFT, 150);
        wxInt16 count = 1, hcount = 0;
        wxColour ncol, acol, nocol;
        ncol.Set("#" + neucolor);

        acol.Set("#" + apocolor);
        nocol.Set("#" + notcolor);
        myview->AppendColumn("", wxLIST_FORMAT_LEFT, 150);

        while (bunam[count] != "")
        {
            if (count <= 30)
            {
                //       myview->InsertItem(count - 1, bunam[count].Upper());
            }
            myview->InsertItem(count - 1, bunam[count].Upper());
            if (hcount == 30)
            {
                
                //myview->AppendColumn("", wxLIST_FORMAT_LEFT,150);

                hcount = 0;

            }
            hcount++;
            if (count > 39 && count < 67)
            {
                if (ncol.IsOk())
                {
                    //    myview->SetItemTextColour(count - 1, ncol);
                }
            }
            if (count > 66)
            {
                // myview->SetItemTextColour(count-1, acol);
            }
            wxSQLite3ResultSet set;
            wxString bhelp;
            bhelp << count;
            set = h_dbi[subibi[1]].ExecuteQuery(wxS("SELECT * FROM bibel where book=" + bhelp + ";"));
            set.NextRow();
            if (set.Eof())
            {
                //  myview->SetItemTextColour(count-1, nocol);
            }


            count++;
        }
        wxStaticText* hg;

        msiz->Add(myview);
        hg = new wxStaticText(mynewpanel, wxID_ANY, "test");
        mynewpanel->wxPanel::SetSizerAndFit(msiz);
        wxString help = "";
        help << subnr[jetwin] - 1;

        myview->Select(wxAtoi(help), true);
        mynewpanel->SetSize(200, 200); //Just tried if this solves the problem
        return mynewpanel;
    }

    virtual wxWindow* GetControl() wxOVERRIDE { return FindWindowById(9191); }
    virtual wxString GetStringValue() const wxOVERRIDE
    {
        if (m_value >= 0)
        {
            return  bunam[m_value + 1];
        }
        //  return wxListView::GetItemText(m_value);
        return wxEmptyString;
        /* wxInt16 ma_item, m_count;
         m_count = 0;
         ma_item = wxListView::GetItemCount();
         while (!wxListView::IsSelected(m_count))
         {
             m_count++;
         }
         return wxListView::GetItemText(m_count);*/
    }
    void OnMouseMove(wxMouseEvent& event)
    {
        // Move selection to cursor if it is inside the popup

        int resFlags;
        int itemHere = wxListView::HitTest(event.GetPosition(), resFlags);

        if (itemHere >= 0)
        {
            wxListView::Select(itemHere, true);
            m_itemHere = itemHere;
        }
        event.Skip();
    }

public:
    //MyFrame* my_frame;
    wxAuiManager* my_mgr;

    void setmgr(MyFrame* frame);
    void   OnActivm(wxMouseEvent& event);
    ownpanel(wxWindow* parent);
    void OnMouseMotion(wxMouseEvent& event);
    int             m_value; // current item index

protected:

    int             m_itemHere; // hot item in popup

private:
   // wxDECLARE_EVENT_TABLE();
};
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 183
Joined: Mon Jan 28, 2019 8:22 am

Re: own Popup for wxcomboctrl (wxPanel)

Post by Wolfgang »

It is not showing an error,but the expected behaviour is not comming as well.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: own Popup for wxcomboctrl (wxPanel)

Post by PB »

TBH, I think the code you posted is not good for other people to spot an error. It misses important parts and/or has a lot of irrelevant ones.

Is it really that difficult to prepare the most basic, preferably compilable, code manifesting the issue?
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 183
Joined: Mon Jan 28, 2019 8:22 am

Re: own Popup for wxcomboctrl (wxPanel)

Post by Wolfgang »

The problem here was same id for comboctrl and for popup, that did not work. After I found that it worked, rest was just test and find the right solution, now it works, with multiple optional rows. In general it helpd me already that I could read that this code was on the right track and should work. Then I figured out the rest.
Post Reply