Skip to content

Commit

Permalink
Merge pull request #1694 from GillesDuvert/solve_1685
Browse files Browse the repository at this point in the history
closes #1685
  • Loading branch information
GillesDuvert authored Dec 16, 2023
2 parents 533016c + 61e9af1 commit 33ea0c9
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/gdlwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6266,12 +6266,12 @@ GDLWidgetDraw::GDLWidgetDraw( WidgetIDT p, EnvT* e, int windowIndex,
if ( eventFlags & GDLWidget::EV_BUTTON) {
this->AddToDesiredEvents(wxEVT_LEFT_DOWN, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDown),draw);
this->AddToDesiredEvents(wxEVT_LEFT_UP, wxMouseEventHandler(gdlwxDrawPanel::OnMouseUp),draw);
this->AddToDesiredEvents(wxEVT_LEFT_DCLICK, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDown),draw);
this->AddToDesiredEvents(wxEVT_LEFT_DCLICK, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDownDble),draw);
this->AddToDesiredEvents(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDown),draw);
this->AddToDesiredEvents(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDown),draw);
this->AddToDesiredEvents(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDownDble),draw);
this->AddToDesiredEvents(wxEVT_MIDDLE_UP, wxMouseEventHandler(gdlwxDrawPanel::OnMouseUp),draw);
this->AddToDesiredEvents(wxEVT_RIGHT_DOWN, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDown),draw);
this->AddToDesiredEvents(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDown),draw);
this->AddToDesiredEvents(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(gdlwxDrawPanel::OnMouseDownDble),draw);
this->AddToDesiredEvents(wxEVT_RIGHT_UP, wxMouseEventHandler(gdlwxDrawPanel::OnMouseUp),draw);
}
if (eventFlags & GDLWidget::EV_KEYBOARD2 || eventFlags & GDLWidget::EV_KEYBOARD){
Expand Down
36 changes: 34 additions & 2 deletions src/gdlwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "str.hpp"
#include "datatypes.hpp"
#include "widget.hpp"
#include "GDLInterpreter.hpp"

#define gdlSCROLL_RATE 10
#define gdlABSENT_SIZE_VALUE 15
Expand Down Expand Up @@ -585,6 +586,18 @@ class GDLWidget
this->setFont();
this->SetSensitive(sensitive);
// if (this->GetRealized()) this->RefreshWidget();
if (eventPro.size() > 0 ) {
#ifdef GDL_DEBUG_WIDGETS
wxMessageOutputStderr().Printf(_T("Realize: SetEventPro: \"%s\" for %d\n"), eventPro, widgetID);
#endif
bool found=GDLInterpreter::SearchCompilePro(eventPro, true); // true -> search for procedure
}
if (eventFun.size() > 0 ) {
#ifdef GDL_DEBUG_WIDGETS
wxMessageOutputStderr().Printf(_T("Realize: SetEventFun: \"%s\" for %d\n"), eventFun, widgetID);
#endif
bool found=GDLInterpreter::SearchCompilePro(eventFun, false); // false -> search for function
}
if( notifyRealize != "") { //insure it is called once only for this.
std::string note=notifyRealize;
notifyRealize.clear();
Expand Down Expand Up @@ -676,9 +689,27 @@ class GDLWidget

virtual bool IsUsingInteractiveEventLoop() {/*std::cerr<<"IsEventLoopBlocked on a not-top widget, please report."<<std::endl*/;return false;} //default for a normal widget

void SetEventPro( const DString& ePro) { eventPro = StrUpCase( ePro);}
void SetEventPro( const DString& ePro) {
eventPro = StrUpCase( ePro);
#ifdef GDL_DEBUG_WIDGETS
wxMessageOutputStderr().Printf(_T("SetEventPro: \"%s\" for %d\n"), eventPro, widgetID);
#endif
if (eventPro.size() > 0) {
bool found = GDLInterpreter::SearchCompilePro(eventPro, true); // true -> search for procedure
}
}

const DString& GetEventPro() const { return eventPro;};
void SetEventFun( const DString& eFun) { eventFun = StrUpCase( eFun);}

void SetEventFun( const DString& eFun) {
eventFun = StrUpCase(eFun);
#ifdef GDL_DEBUG_WIDGETS
wxMessageOutputStderr().Printf(_T("SetEventFun: \"%s\" for %d\n"),eventFun, widgetID);
#endif
if (eventFun.size() > 0) {
bool found = GDLInterpreter::SearchCompilePro(eventFun, false); // false -> search for function
}
}
const DString& GetEventFun() const { return eventFun;}
void SetNotifyRealize( const DString& eNR) { notifyRealize = StrUpCase( eNR);}
const DString& GetNotifyRealize() const { return notifyRealize;}
Expand Down Expand Up @@ -2233,6 +2264,7 @@ class gdlwxDrawPanel : public gdlwxGraphicsPanel
void OnMouseMove(wxMouseEvent& event);
void OnMouseDown(wxMouseEvent& event);
void OnMouseUp(wxMouseEvent& event);
void OnMouseDownDble(wxMouseEvent& event);
void OnMouseWheel(wxMouseEvent& event);
void OnKey(wxKeyEvent& event);
void OnFakeDropFileEvent(wxDropFilesEvent& event);
Expand Down
30 changes: 29 additions & 1 deletion src/gdlwidgeteventhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,34 @@ void gdlwxDrawPanel::OnMouseDown( wxMouseEvent &event ) {
} else event.Skip(); //normal end of event processing!
}

//Only difference with above is CLICKS=2
void gdlwxDrawPanel::OnMouseDownDble(wxMouseEvent &event) {
#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_KBRD_EVENTS)
wxMessageOutputStderr().Printf(_T("in gdlwxDrawPanel::OnMouseDown: %d\n"), event.GetId());
#endif
DULong eventFlags = myWidgetDraw->GetEventFlags();

if (eventFlags & GDLWidget::EV_BUTTON) {
WidgetIDT baseWidgetID = GDLWidget::GetIdOfTopLevelBase(event.GetId());
DStructGDL* widgdraw = new DStructGDL("WIDGET_DRAW");
widgdraw->InitTag("ID", DLongGDL(myWidgetDraw->GetWidgetID()));
widgdraw->InitTag("TOP", DLongGDL(baseWidgetID));
widgdraw->InitTag("HANDLER", DLongGDL(baseWidgetID));
widgdraw->InitTag("TYPE", DIntGDL(0)); //button Press
wxPoint where = WhereIsMouse(event);
widgdraw->InitTag("X", DLongGDL(where.x));
widgdraw->InitTag("Y", DLongGDL(drawSize.y - where.y));
unsigned long btn = 1 << (event.GetButton() - 1);
widgdraw->InitTag("PRESS", DByteGDL(btn));
widgdraw->InitTag("RELEASE", DByteGDL(0));
widgdraw->InitTag("CLICKS", DLongGDL(2));
widgdraw->InitTag("MODIFIERS", DLongGDL(RemapModifiers(event)));
widgdraw->InitTag("CH", DByteGDL(0));
widgdraw->InitTag("KEY", DLongGDL(0));
GDLWidget::PushEvent(baseWidgetID, widgdraw);
} else event.Skip(); //normal end of event processing!
}

void gdlwxDrawPanel::OnMouseUp( wxMouseEvent &event ) {
#if (GDL_DEBUG_ALL_EVENTS || GDL_DEBUG_KBRD_EVENTS)
wxMessageOutputStderr().Printf(_T("in gdlwxDrawPanel::OnMouseUp: %d\n"),event.GetId());
Expand All @@ -1549,7 +1577,7 @@ void gdlwxDrawPanel::OnMouseUp( wxMouseEvent &event ) {
unsigned long btn=1<<(event.GetButton()-1);
widgdraw->InitTag( "PRESS", DByteGDL( 0 ) );
widgdraw->InitTag( "RELEASE", DByteGDL( btn ) );
widgdraw->InitTag( "CLICKS", DLongGDL( 1 ) );
widgdraw->InitTag( "CLICKS", DLongGDL( 0 ) );
widgdraw->InitTag( "MODIFIERS", DLongGDL( RemapModifiers(event)));
widgdraw->InitTag( "CH", DByteGDL( 0 ) );
widgdraw->InitTag( "KEY", DLongGDL( 0 ) );
Expand Down
1 change: 1 addition & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ DStructGDL* CallEventHandler( DStructGDL* ev ) {
GDLDelete(ev);
throw GDLException(eventHandlerFun + ": Event handler return struct must contain ID, TOP, HANDLER as first tags.");
}
return ev;
} else { //not a struct, same as a procedure, has swallowed the event
ev = NULL;
break;
Expand Down
39 changes: 38 additions & 1 deletion testsuite/interactive_tests/test_widgets.pro
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,43 @@ pro deletedraw,ev
tobedeleted = WIDGET_INFO(ev.TOP, FIND_BY_UNAME = 'drawToBeDeleted')
widget_control,tobedeleted,/destroy
end
function draw2_event,ev
print,"draw2 event"
return,ev
end

pro draw1_event,ev
widget_id=ev.id
print,"draw1 started, will exit on key 1 release"
sav_draw_motion_events = widget_info(widget_id, /draw_motion_events)
sav_draw_button_events = widget_info(widget_id, /draw_button_events)
sav_event_pro = widget_info(widget_id,/event_pro)
sav_event_func = widget_info(widget_id,/event_func)

widget_control, widget_id, /draw_button_events
widget_control, widget_id, event_pro=''
widget_control, widget_id, event_func='draw2_event'
while 1 do begin

ev = widget_event (widget_id)
; print,'event in stretch_box
; help,ev,/st

if ev.press eq 1 then begin
print,"keypress 1"
endif

if ev.release eq 1 then begin
if sav_event_pro ne '' then widget_control, widget_id, event_pro=sav_event_pro
if sav_event_func ne '' then widget_control, widget_id, event_func=sav_event_func
widget_control, widget_id, draw_button_events=sav_draw_button_events, $
draw_motion_events=sav_draw_motion_events
print,"reset pro fun events & exit draw1"
return
endif
wait, .1
endwhile
end

pro list_event,event
toto=["A","list","created","with","WIDGET_LIST","YSIZE=3"]
Expand Down Expand Up @@ -354,7 +391,7 @@ endif

; populate
if ~keyword_set(nocanvas) then begin
draw = WIDGET_DRAW(yoff=offy,draw_base, XSIZE = 1800, YSIZE = 600,x_scroll_size=256,y_scroll_size=256,frame=20) & offy+=300 ;
draw = WIDGET_DRAW(yoff=offy,draw_base, XSIZE = 1800, YSIZE = 600,x_scroll_size=256,y_scroll_size=256,frame=20,/button_events,event_pro="draw1_event") & offy+=300 ;
draw2 = WIDGET_DRAW(yoff=offy,draw_base, xoff=100, xsize=400,ysize=400,x_scroll_size=200,y_scroll_size=200,/button_events,keyboard_events=1,/motion_events) & offy+=250 ;
tmp=widget_label(xoff=200,yoff=offy,draw_base,value="below, has tooltip and has a popup") & offy+=10 ;

Expand Down

0 comments on commit 33ea0c9

Please sign in to comment.