static void wxTextWindowChangedProc (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr)) { if (!wxGetWindowFromTable(w)) // Widget has been deleted! return; wxTextCtrl *tw = (wxTextCtrl *) clientData; tw->SetModified(true); }
void wxArrowButton::StartTimerCallback( Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr) ) { if( !wxGetWindowFromTable( w ) ) // Widget has been deleted! return; wxArrowButton* btn = (wxArrowButton*)clientData; btn->GetFreshTimer()->Start( TICK_INTERVAL ); }
void wxArrowButton::StopTimerCallback( Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr) ) { if( !wxGetWindowFromTable( w ) ) // Widget has been deleted! return; wxArrowButton* btn = (wxArrowButton*)clientData; wxDELETE(btn->m_timer); }
void wxTLWEventHandler( Widget wid, XtPointer WXUNUSED(client_data), XEvent* event, Boolean* continueToDispatch) { wxTopLevelWindowMotif* tlw = (wxTopLevelWindowMotif*)wxGetWindowFromTable( wid ); if( tlw ) { wxMouseEvent wxevent( wxEVT_NULL ); if( wxTranslateMouseEvent( wxevent, tlw, wid, event ) ) { wxevent.SetEventObject( tlw ); wxevent.SetId( tlw->GetId() ); tlw->HandleWindowEvent( wxevent ); } else { // An attempt to implement OnCharHook by calling OnCharHook first; // if this returns true, set continueToDispatch to False // (don't continue processing). // Otherwise set it to True and call OnChar. wxKeyEvent keyEvent( wxEVT_CHAR ); if( wxTranslateKeyEvent( keyEvent, tlw, wid, event )) { keyEvent.SetEventObject( tlw ); keyEvent.SetId( tlw->GetId() ); keyEvent.SetEventType( wxEVT_CHAR_HOOK ); if( tlw->HandleWindowEvent( keyEvent ) ) { *continueToDispatch = False; return; } else { // For simplicity, OnKeyDown is the same as OnChar // TODO: filter modifier key presses from OnChar keyEvent.SetEventType( wxEVT_KEY_DOWN ); // Only process OnChar if OnKeyDown didn't swallow it if( !tlw->HandleWindowEvent( keyEvent ) ) { keyEvent.SetEventType( wxEVT_CHAR ); tlw->HandleWindowEvent( keyEvent ); } } } } } *continueToDispatch = True; }
void wxButtonCallback (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr)) { if (!wxGetWindowFromTable(w)) // Widget has been deleted! return; wxButton *item = (wxButton *) clientData; wxCommandEvent event (wxEVT_COMMAND_BUTTON_CLICKED, item->GetId()); event.SetEventObject(item); item->ProcessCommand (event); }
static void wxTextWindowLoseFocusProc (Widget w, XtPointer clientData, XmAnyCallbackStruct *WXUNUSED(cbs)) { if (!wxGetWindowFromTable(w)) return; wxTextCtrl *tw = (wxTextCtrl *) clientData; wxFocusEvent event(wxEVT_KILL_FOCUS, tw->GetId()); event.SetEventObject(tw); tw->HandleWindowEvent(event); }
void wxArrowButton::SpinButtonCallback( Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr) ) { if( !wxGetWindowFromTable( w ) ) // Widget has been deleted! return; wxArrowButton* btn = (wxArrowButton*)clientData; btn->GetSpinButton()->Increment( btn->m_increment ); }
static void wxTextWindowActivateProc(Widget w, XtPointer clientData, XmAnyCallbackStruct *WXUNUSED(ptr)) { if (!wxGetWindowFromTable(w)) return; wxTextCtrl *tw = (wxTextCtrl *) clientData; if (tw->InSetValue()) return; wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER); event.SetId(tw->GetId()); event.SetEventObject(tw); tw->ProcessCommand(event); }
// Get the window with the focus wxWindow *wxWindowBase::DoFindFocus() { Window xfocus = (Window) 0; int revert = 0; XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert); if (xfocus) { wxWindow *win = wxGetWindowFromTable( xfocus ); if (!win) { win = wxGetClientWindowFromTable( xfocus ); } return win; } return NULL; }
bool wxApp::ProcessXEvent(WXEvent* _event) { XEvent* event = (XEvent*) _event; wxWindow* win = NULL; Window window = XEventGetWindow(event); #if 0 Window actualWindow = window; #endif // Find the first wxWindow that corresponds to this event window // Because we're receiving events after a window // has been destroyed, assume a 1:1 match between // Window and wxWindow, so if it's not in the table, // it must have been destroyed. win = wxGetWindowFromTable(window); if (!win) { #if wxUSE_TWO_WINDOWS win = wxGetClientWindowFromTable(window); if (!win) #endif return false; } switch (event->type) { case Expose: { #if wxUSE_TWO_WINDOWS && !wxUSE_NANOX if (event->xexpose.window != (Window)win->GetClientAreaWindow()) { XEvent tmp_event; wxExposeInfo info; info.window = event->xexpose.window; info.found_non_matching = false; while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info )) { // Don't worry about optimizing redrawing the border etc. } win->NeedUpdateNcAreaInIdle(); } else #endif { win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event), XExposeEventGetWidth(event), XExposeEventGetHeight(event)); win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event), XExposeEventGetWidth(event), XExposeEventGetHeight(event)); #if !wxUSE_NANOX XEvent tmp_event; wxExposeInfo info; info.window = event->xexpose.window; info.found_non_matching = false; while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, wxX11ExposePredicate, (XPointer) &info )) { win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y, tmp_event.xexpose.width, tmp_event.xexpose.height ); win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y, tmp_event.xexpose.width, tmp_event.xexpose.height ); } #endif // This simplifies the expose and clear areas to simple // rectangles. win->GetUpdateRegion() = win->GetUpdateRegion().GetBox(); win->GetClearRegion() = win->GetClearRegion().GetBox(); // If we only have one X11 window, always indicate // that borders might have to be redrawn. if (win->X11GetMainWindow() == win->GetClientAreaWindow()) win->NeedUpdateNcAreaInIdle(); // Only erase background, paint in idle time. win->SendEraseEvents(); // EXPERIMENT //win->Update(); } return true; } #if !wxUSE_NANOX case GraphicsExpose: { wxLogTrace( wxT("expose"), wxT("GraphicsExpose from %s"), win->GetName().c_str()); win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y, event->xgraphicsexpose.width, event->xgraphicsexpose.height); win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y, event->xgraphicsexpose.width, event->xgraphicsexpose.height); if (event->xgraphicsexpose.count == 0) { // Only erase background, paint in idle time. win->SendEraseEvents(); // win->Update(); } return true; } #endif case KeyPress: { if (!win->IsEnabled()) return false; wxKeyEvent keyEvent(wxEVT_KEY_DOWN); wxTranslateKeyEvent(keyEvent, win, window, event); // wxLogDebug( "OnKey from %s", win->GetName().c_str() ); // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR if (win->HandleWindowEvent( keyEvent )) return true; keyEvent.SetEventType(wxEVT_CHAR); // Do the translation again, retaining the ASCII // code. if (wxTranslateKeyEvent(keyEvent, win, window, event, true) && win->HandleWindowEvent( keyEvent )) return true; if ( (keyEvent.m_keyCode == WXK_TAB) && win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( win->GetParent() ); /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */ new_event.SetDirection( (keyEvent.m_keyCode == WXK_TAB) ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( keyEvent.ControlDown() ); new_event.SetCurrentFocus( win ); return win->GetParent()->HandleWindowEvent( new_event ); } return false; } case KeyRelease: { if (!win->IsEnabled()) return false; wxKeyEvent keyEvent(wxEVT_KEY_UP); wxTranslateKeyEvent(keyEvent, win, window, event); return win->HandleWindowEvent( keyEvent ); } case ConfigureNotify: { #if wxUSE_NANOX if (event->update.utype == GR_UPDATE_SIZE) #endif { wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); if ( tlw ) { tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event), XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) ); } if ( tlw && tlw->IsShown() ) { tlw->SetNeedResizeInIdle(); } else { wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() ); sizeEvent.SetEventObject( win ); return win->HandleWindowEvent( sizeEvent ); } } return false; } #if !wxUSE_NANOX case PropertyNotify: return HandlePropertyChange(_event); case ClientMessage: { if (!win->IsEnabled()) return false; Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True); Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True); if (event->xclient.message_type == wm_protocols) { if ((Atom) (event->xclient.data.l[0]) == wm_delete_window) { win->Close(false); return true; } } return false; } #if 0 case DestroyNotify: { printf( "destroy from %s\n", win->GetName().c_str() ); break; } case CreateNotify: { printf( "create from %s\n", win->GetName().c_str() ); break; } case MapRequest: { printf( "map request from %s\n", win->GetName().c_str() ); break; } case ResizeRequest: { printf( "resize request from %s\n", win->GetName().c_str() ); Display *disp = (Display*) wxGetDisplay(); XEvent report; // to avoid flicker report = * event; while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report)); wxSize sz = win->GetSize(); wxSizeEvent sizeEvent(sz, win->GetId()); sizeEvent.SetEventObject(win); return win->HandleWindowEvent( sizeEvent ); } #endif #endif #if wxUSE_NANOX case GR_EVENT_TYPE_CLOSE_REQ: { if (win) { win->Close(false); return true; } return false; break; } #endif case EnterNotify: case LeaveNotify: case ButtonPress: case ButtonRelease: case MotionNotify: { if (!win->IsEnabled()) return false; // Here we check if the top level window is // disabled, which is one aspect of modality. wxWindow *tlw = win; while (tlw && !tlw->IsTopLevel()) tlw = tlw->GetParent(); if (tlw && !tlw->IsEnabled()) return false; if (event->type == ButtonPress) { if ((win != wxWindow::FindFocus()) && win->CanAcceptFocus()) { // This might actually be done in wxWindow::SetFocus() // and not here. TODO. g_prevFocus = wxWindow::FindFocus(); g_nextFocus = win; wxLogTrace( wxT("focus"), wxT("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); // Record the fact that this window is // getting the focus, because we'll need to // check if its parent is getting a bogus // focus and duly ignore it. // TODO: may need to have this code in SetFocus, too. extern wxWindow* g_GettingFocus; g_GettingFocus = win; win->SetFocus(); } } #if !wxUSE_NANOX if (event->type == LeaveNotify || event->type == EnterNotify) { // Throw out NotifyGrab and NotifyUngrab if (event->xcrossing.mode != NotifyNormal) return false; } #endif wxMouseEvent wxevent; wxTranslateMouseEvent(wxevent, win, window, event); return win->HandleWindowEvent( wxevent ); } case FocusIn: #if !wxUSE_NANOX if ((event->xfocus.detail != NotifyPointer) && (event->xfocus.mode == NotifyNormal)) #endif { wxLogTrace( wxT("focus"), wxT("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); extern wxWindow* g_GettingFocus; if (g_GettingFocus && g_GettingFocus->GetParent() == win) { // Ignore this, this can be a spurious FocusIn // caused by a child having its focus set. g_GettingFocus = NULL; wxLogTrace( wxT("focus"), wxT("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); return true; } else { wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId()); focusEvent.SetEventObject(win); focusEvent.SetWindow( g_prevFocus ); g_prevFocus = NULL; return win->HandleWindowEvent(focusEvent); } } return false; case FocusOut: #if !wxUSE_NANOX if ((event->xfocus.detail != NotifyPointer) && (event->xfocus.mode == NotifyNormal)) #endif { wxLogTrace( wxT("focus"), wxT("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() ); wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId()); focusEvent.SetEventObject(win); focusEvent.SetWindow( g_nextFocus ); g_nextFocus = NULL; return win->HandleWindowEvent(focusEvent); } return false; } return false; }
static void wxScrollBarCallback(Widget widget, XtPointer clientData, XmScaleCallbackStruct *cbs) { wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget); wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData); wxEventType eventType = wxEVT_NULL; switch (cbs->reason) { case XmCR_INCREMENT: { eventType = wxEVT_SCROLL_LINEDOWN; break; } case XmCR_DECREMENT: { eventType = wxEVT_SCROLL_LINEUP; break; } case XmCR_DRAG: { eventType = wxEVT_SCROLL_THUMBTRACK; break; } case XmCR_VALUE_CHANGED: { eventType = wxEVT_SCROLL_THUMBRELEASE; break; } case XmCR_PAGE_INCREMENT: { eventType = wxEVT_SCROLL_PAGEDOWN; break; } case XmCR_PAGE_DECREMENT: { eventType = wxEVT_SCROLL_PAGEUP; break; } case XmCR_TO_TOP: { eventType = wxEVT_SCROLL_TOP; break; } case XmCR_TO_BOTTOM: { eventType = wxEVT_SCROLL_BOTTOM; break; } default: { // Should never get here wxFAIL_MSG("Unknown scroll event."); break; } } wxScrollEvent event(eventType, scrollBar->GetId(), cbs->value, orientation); event.SetEventObject(scrollBar); scrollBar->GetEventHandler()->ProcessEvent(event); }