paragui-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-users] Source for DnD+Modal problem


From: Henric Carlsson
Subject: [paragui-users] Source for DnD+Modal problem
Date: Wed, 25 Sep 2002 23:22:01 +0200 (CEST)
User-agent: IMP/PHP IMAP webmail program 2.2.7

Hi again.

Here is code that demonstrates the afforementioned DnD+Modal
bug (yes, I think it's a bug).

The main function first creates a dialog that works fine. 
The second dialog shows up after dragging "dragwidget"
to "dropwidget". This dialog will not react to mouse clicks.
Interestingly, the OK button mouse-over highlight still works. 

Note that this program will crash if "dragwidget" is dropped
on the empty screen area. The reason is that dragimage is NULL,
which causes problems in PG_WidgetDnD::drawDragArea().

Oh, and shouldn't the PG_WidgetDnD destructor be virtual?
Ditto for the eventMouse* functions. Or am I missing something
here?

I apologize if these issues have been fixed in current CVS.

cheers,
Henric



// BEGINNING OF CODE
////////////////////////////////////////////////////////////

#include <iostream>
#include <cstdlib>

#include <pgapplication.h>
#include <pgwindow.h>
#include <pgwidgetdnd.h>
#include <pglineedit.h>

////////////////////////////////////////////////////////////

class AmountDlg : public PG_Window
{
public:
   ~AmountDlg();
   static int getAmount();
   static AmountDlg *instance();
   
protected:
   bool eventButtonClick(int id, PG_Widget *);

private:
   PG_LineEdit *m_le;
   static AmountDlg *s_instance;
   AmountDlg();
};

////////////////////////////////////////////////////////////

AmountDlg *AmountDlg::s_instance = 0;

AmountDlg::AmountDlg()
  : PG_Window(0, PG_Rect(300, 100, 200, 100), "Enter  amount",
              WF_MODAL, "Window", 20)
{
    new PG_Button(this, 1, PG_Rect(10, 30, 70, 30), "OK");
    m_le = new PG_LineEdit(this, PG_Rect(90, 30, 100, 30));
    m_le->SetEditable(true);
}

AmountDlg::~AmountDlg() {}


int AmountDlg::getAmount()
{
    AmountDlg *dlg = AmountDlg::instance();
    
    dlg->m_le->SetText("100");
    dlg->Show();
    dlg->RunModal();
    dlg->Hide();
    
    return atoi(dlg->m_le->GetText());
}

AmountDlg *AmountDlg::instance()
{
    if (!s_instance) s_instance = new AmountDlg();
    return s_instance;
}

bool AmountDlg::eventButtonClick(int id, PG_Widget *)
{
    if (id == 1)
      {
          SendMessage(this, MSG_MODALQUIT, 0, 0);
          return true;
      }
    
    return false;
}
                                                           
////////////////////////////////////////////////////////////

class dndtest : public PG_WidgetDnD
{
public:   
   dndtest(const PG_Rect &, const char *msg);
   
protected:   
   void eventBlit(SDL_Surface *, const PG_Rect &, const PG_Rect &);
   
   bool eventDragStart();
   bool eventDragDrop(PG_WidgetDnD *src, int dndID);

private:
   const char *m_msg;
};


////////////////////////////////////////////////////////////


dndtest::dndtest(const PG_Rect &r, const char *msg)
  : PG_WidgetDnD(NULL, 198, r, false),
    m_msg(msg)
{
}


void dndtest::eventBlit(SDL_Surface *, const PG_Rect &, const PG_Rect &)
{
    DrawText(0, 0, m_msg);
}


bool dndtest::eventDragStart()
{
    std::cout << "eventDragStart " << m_msg << std::endl;
    return true;
}

bool dndtest::eventDragDrop(PG_WidgetDnD *src, int dndID)
{
    std::cout << "eventDragDrop " << m_msg << std::endl;

    int amount = AmountDlg::getAmount();
    std::cout << "Amount is " << amount << std::endl;
    return true;
}

////////////////////////////////////////////////////////////

int main(int argc, char *argv[])
{
    PG_Application app;
    
    app.SetEmergencyQuit(true);
    app.LoadTheme("simple");
    app.InitScreen(640, 480, 16);
    
    // Try the dialog without DnD. This will work.
    int amount = AmountDlg::getAmount();
    std::cout << "Amount is " << amount << std::endl;

    dndtest w1(PG_Rect(10, 10, 200, 100), "dragwidget");
    dndtest w2(PG_Rect(330, 10, 200, 100), "dropwidget");
    
    w1.SetDrag(true);
    w1.SetDrop(false);
    w2.SetDrag(false);
    w2.SetDrop(true);
    
    w1.Show();
    w2.Show();
    
    // Now try dragging from w1 to w2!
    
    app.Run();
    
    return EXIT_SUCCESS;
}

////////////////////////////////////////////////////////////
// END OF CODE




reply via email to

[Prev in Thread] Current Thread [Next in Thread]