void wxTextCtrl::DoSendEvents(void *wxcbs, long keycode) { // we're in process of updating the text control m_tempCallbackStruct = wxcbs; XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)wxcbs; wxKeyEvent event (wxEVT_CHAR); event.SetId(GetId()); event.m_keyCode = keycode; event.SetEventObject(this); // Only if wxTextCtrl::OnChar is called will this be set to True (and // the character passed through) cbs->doit = False; HandleWindowEvent(event); if ( !InSetValue() && m_processedDefault ) { // Can generate a command wxCommandEvent commandEvent(wxEVT_COMMAND_TEXT_UPDATED, GetId()); commandEvent.SetEventObject(this); ProcessCommand(commandEvent); } // do it after the (user) event handlers processed the events because // otherwise GetValue() would return incorrect (not yet updated value) m_tempCallbackStruct = NULL; }
bool wxFrameBase::ProcessCommand(wxMenuItem *item) { wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item->GetId()); commandEvent.SetEventObject(this); if (!item->IsEnabled()) return true; if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() ) return true; if (item->IsCheckable()) { item->Toggle(); // use the new value commandEvent.SetInt(item->IsChecked()); } else // Uncheckable item. { commandEvent.SetInt(-1); } return HandleWindowEvent(commandEvent); }
void wxGL_PMFCanvas::ray_pick(vector3d point, vector3d norm){ int idx1=-1; int idx2=-1; float max_dist = FLT_MAX; for(unsigned int i = 0; i<omni.point.size(); i++){ for(unsigned int j = 0; j< omni.point[i].size(); j++){ float d = point_line_distance(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), point, norm); float rad = 0.0f; if(omni.flags & OMNIPOINT_ANY_PATH)//paths can have rediculusly huge radius's rad = log(omni.point[i][j].rad)+1.0f; else rad = omni.point[i][j].rad; if(d < rad && d<max_dist){ max_dist = d; idx1 = i; idx2 = j; } } } if(idx1 >-1 && idx2 >-1){ set_selected_omni_points(idx1, idx2); wxCommandEvent commandEvent(OMNIPOINT_RAY_PICKED, GetId()); GetEventHandler()->ProcessEvent(commandEvent); Render(); } }
bool wxFrameBase::ProcessCommand(int id) { #if wxUSE_MENUS wxMenuBar *bar = GetMenuBar(); if ( !bar ) return false; wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); commandEvent.SetEventObject(this); wxMenuItem *item = bar->FindItem(id); if (item) { if (!item->IsEnabled()) return true; if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() ) return true; if (item->IsCheckable()) { item->Toggle(); // use the new value commandEvent.SetInt(item->IsChecked()); } } return GetEventHandler()->ProcessEvent(commandEvent); #else // !wxUSE_MENUS return false; #endif // wxUSE_MENUS/!wxUSE_MENUS }
bool wxTopLevelWindowMSW::HandleCommand(WXWORD id, WXWORD WXUNUSED(cmd), WXHWND WXUNUSED(control)) { // handle here commands from Smartphone menu bar if ( id == IDM_LEFT || id == IDM_RIGHT ) { int menuId = id == IDM_LEFT ? m_LeftButton.GetId() : m_RightButton.GetId() ; wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, menuId); commandEvent.SetEventObject(this); GetEventHandler()->ProcessEvent(commandEvent); return true; } return false; }
void wxCheckListCtrl::OnMouseEvent(wxMouseEvent& event) { int flags = 0; long l_subitem; long item = HitTest(wxPoint(event.GetX(), event.GetY()), flags, &l_subitem); std::cout << "Item : " << std::dec << item << '\n'; if (event.LeftDown()) { if (flags & wxLIST_HITTEST_ONITEMICON) { std::cout << "Flag: " << flags << '\n'; std::cout << "Item: " << std::dec << item << '\n'; //wxCheckListItemAttr* data = (wxCheckListItemAttr*) GetItemData(item); wxListItem l_item; l_item.SetId(item); GetItem(l_item); wxCheckListItemAttr* data = (wxCheckListItemAttr*) l_item.GetData(); std::cout << l_item.GetText().char_str() << '\n'; std::cout << "Data: " << data << '\n'; std::cout << "Image: " << l_item.GetImage() << '\n'; if(data != 0) { std::cout << "mouse event" << data->GetEnabled() << " " << data->GetChecked() << '\n'; } if (data && data->GetEnabled()) { data->SetChecked(!data->GetChecked()); SetIcon(item); wxCheckListEvent commandEvent(wxEVT_COMMAND_CHECKLISTCTRL_TOGGLED, GetId()); commandEvent.SetEventObject(this); commandEvent.SetListItemId(item); commandEvent.SetChecked(data->GetChecked()); commandEvent.SetData(data); GetEventHandler()->ProcessEvent(commandEvent); } } } event.Skip(); }
bool wxFrame::HandleMenuSelect(WXEVENTPTR event) { const EventType *palmEvent = (EventType *)event; const int ItemID = palmEvent->data.menu.itemID; if (!m_frameMenuBar) return false; const int item = m_frameMenuBar->ProcessCommand(ItemID); if (item==-1) return false; wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item); commandEvent.SetEventObject(this); GetEventHandler()->ProcessEvent(commandEvent); return true; }
bool SudokuSheetModel::writeToCell( int cellX, int cellY, int blockX, int blockY, int value, bool inInk ) { int cellIdx = CALC_2DARR_IDX(cellX, cellY, CELL_STRIDE); int blockIdx = CALC_2DARR_IDX(blockX, blockY, BLOCK_STRIDE); if( inInk && m_blocks[blockIdx]->m_cells[cellIdx].inkValue != 0 ) { log("error: trying to write ink over ink"); return false; } if( !inInk && m_blocks[blockIdx]->m_cells[cellIdx].inkValue != 0 ) { log("error: trying to write pencil over ink"); return false; } if( value == 0 || value > TOTAL_VALUES ) { log("error: value out of bounds"); return false; } bool gameOverLose = false; bool gameOverWin = false; bool valueExhausted = false; bool pencilErased = false; if( inInk ) { m_blocks[blockIdx]->m_cells[cellIdx].inkValue = value; if(m_blocks[blockIdx]->m_cells[cellIdx].value != value ) { log("player lost"); gameOverLose = true; } else if(isValueExhausted(value)) { log("value exhausted"); if( isPuzzleComplete() ) { log("puzzle completed"); gameOverWin = true; } else { erasePencilValueInSheet(value); valueExhausted = true; } } else { erasePencilValueInBlock(blockX, blockY, value); erasePencilValueInColumn(cellX, blockX, value); erasePencilValueInRow(cellY, blockY, value); } } else { int valueIdx = value - 1; m_blocks[blockIdx]->m_cells[cellIdx].pencilValues[valueIdx] = !m_blocks[blockIdx]->m_cells[cellIdx].pencilValues[valueIdx]; if(!m_blocks[blockIdx]->m_cells[cellIdx].pencilValues[valueIdx]) pencilErased = true; } //todo: send pencil erased instead of write if erased detected SACEvent commandEvent( inInk ? SAC_WRITE_INK : SAC_WRITE_PENCIL ); commandEvent.cmd.data["blockX"] = blockX; commandEvent.cmd.data["blockY"] = blockY; commandEvent.cmd.data["cellX"] = cellX; commandEvent.cmd.data["cellY"] = cellY; commandEvent.cmd.data["val"] = value; ZZ::EventBus::game()->dispatch(&commandEvent); if( gameOverLose ) { SACEvent commandEvent( SAC_GAME_OVER_LOSE ); ZZ::EventBus::game()->dispatch(&commandEvent); } else if( gameOverWin ) { SACEvent commandEvent( SAC_GAME_OVER_WIN ); ZZ::EventBus::game()->dispatch(&commandEvent); } else if( valueExhausted ) { SACEvent commandEvent( SAC_EXHAUSTED_NUMBER ); commandEvent.cmd.data["val"] = value; ZZ::EventBus::game()->dispatch(&commandEvent); } return true; }
static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) { if (g_isIdle) wxapp_install_idle_handler(); int id = menu->FindMenuIdByMenuItem(widget); /* should find it for normal (not popup) menu */ wxASSERT_MSG( (id != -1) || (menu->GetWindow() != NULL), wxT("menu item not found in gtk_menu_clicked_callback") ); if (!menu->IsEnabled(id)) return; wxMenuItem* item = menu->FindChildItem( id ); wxCHECK_RET( item, wxT("error in menu item callback") ); if ( item->GetId() == wxGTK_TITLE_ID ) { // ignore events from the menu title return; } if (item->IsCheckable()) { bool isReallyChecked = item->IsChecked(), isInternallyChecked = item->wxMenuItemBase::IsChecked(); // ensure that the internal state is always consistent with what is // shown on the screen item->wxMenuItemBase::Check(isReallyChecked); // we must not report the events for the radio button going up nor the // events resulting from the calls to wxMenuItem::Check() if ( (item->GetKind() == wxITEM_RADIO && !isReallyChecked) || (isInternallyChecked == isReallyChecked) ) { return; } } // Is this menu on a menubar? (possibly nested) wxFrame* frame = NULL; if(menu->IsAttached()) frame = menu->GetMenuBar()->GetFrame(); // FIXME: why do we have to call wxFrame::GetEventHandler() directly here? // normally wxMenu::SendEvent() should be enough, if it doesn't work // in wxGTK then we have a bug in wxMenu::GetWindow() which // should be fixed instead of working around it here... if (frame) { // If it is attached then let the frame send the event. // Don't call frame->ProcessCommand(id) because it toggles // checkable items and we've already done that above. wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); commandEvent.SetEventObject(frame); if (item->IsCheckable()) commandEvent.SetInt(item->IsChecked()); commandEvent.SetEventObject(menu); frame->HandleWindowEvent(commandEvent); } else { // otherwise let the menu have it menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1); } }
void wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) { wxClientDC dc( this ); PrepareDC( dc ); if ( (eventId != WXLOWIN_MENU_MOUSEMOVE #ifndef __WXMSW__ || m_FocusFollowMode #endif ) && (wxWindow::FindFocus() != this) ) { SetFocus(); } wxPoint findPos; findPos.x = dc.DeviceToLogicalX(event.GetX()); findPos.y = dc.DeviceToLogicalY(event.GetY()); findPos.x -= WXLO_XOFFSET; findPos.y -= WXLO_YOFFSET; if(findPos.x < 0) findPos.x = 0; if(findPos.y < 0) findPos.y = 0; m_ClickPosition = wxPoint(event.GetX(), event.GetY()); // Scroll the window if the mouse is at the end of it: if(m_Selecting && eventId == WXLOWIN_MENU_MOUSEMOVE) { //WXLO_DEBUG(("selecting at : %d/%d", (int) event.GetX(), (int)event.GetY())); int left, top; GetViewStart(&left, &top); wxSize size = GetClientSize(); int xdelta, ydelta; if(event.GetX() < WXLO_SCROLLMARGIN_X) xdelta = -(WXLO_SCROLLMARGIN_X-event.GetX()); else if(event.GetX() > size.x-WXLO_SCROLLMARGIN_X) xdelta = event.GetX()-size.x+WXLO_SCROLLMARGIN_X; else xdelta = 0; if(event.GetY() < WXLO_SCROLLMARGIN_Y) ydelta = -(WXLO_SCROLLMARGIN_Y-event.GetY()); else if(event.GetY() > size.y-WXLO_SCROLLMARGIN_Y) ydelta = event.GetY()-size.y+WXLO_SCROLLMARGIN_Y; else ydelta = 0; //WXLO_DEBUG(("xdelta: %d", (int) xdelta)); if(xdelta != 0 || ydelta != 0) { top += ydelta; if(top < 0) top = 0; left += xdelta; if(left < 0) left = 0; Scroll(left, top); } } wxPoint cursorPos; bool found; wxLayoutObject *obj = m_llist->FindObjectScreen(dc, findPos, &cursorPos, &found); wxLayoutObject::UserData *u = obj ? obj->GetUserData() : NULL; // has the mouse only been moved? switch ( eventId ) { case WXLOWIN_MENU_MOUSEMOVE: { // this variables is used to only erase the message in the status // bar if we had put it there previously - otherwise empting status // bar might be undesirable #if wxUSE_STATUSBAR static bool s_hasPutMessageInStatusBar = false; #endif // wxUSE_STATUSBAR // found is only true if we are really over an object, not just // behind it if(found && u && ! m_Selecting) { if(!m_HandCursor) SetCursor(wxCURSOR_HAND); m_HandCursor = true; #if wxUSE_STATUSBAR if(m_StatusBar && m_StatusFieldLabel != -1) { const wxString &label = u->GetLabel(); if(label.Length()) { m_StatusBar->SetStatusText(label,m_StatusFieldLabel); s_hasPutMessageInStatusBar = true; } } #endif // wxUSE_STATUSBAR } else { if(m_HandCursor) SetCursor(wxCURSOR_IBEAM); m_HandCursor = false; #if wxUSE_STATUSBAR if( m_StatusBar && m_StatusFieldLabel != -1 && s_hasPutMessageInStatusBar ) { m_StatusBar->SetStatusText(wxEmptyString, m_StatusFieldLabel); } #endif // wxUSE_STATUSBAR } } // selecting? if ( event.LeftIsDown() ) { // m_Selecting might not be set if the button got pressed // outside this window, so check for it: if( m_Selecting ) { m_llist->ContinueSelection(cursorPos, m_ClickPosition); RequestUpdate(); // TODO: we don't have to redraw everything! } } if ( u ) { u->DecRef(); u = NULL; } break; case WXLOWIN_MENU_LDOWN: { // always move cursor to mouse click: m_llist->MoveCursorTo(cursorPos); // clicking a mouse removes the selection if ( m_llist->HasSelection() ) { m_llist->DiscardSelection(); m_Selecting = false; RequestUpdate(); // TODO: we don't have to redraw everything! } // Calculate where the top of the visible area is: int x0, y0; GetViewStart(&x0,&y0); int dx, dy; GetScrollPixelsPerUnit(&dx, &dy); x0 *= dx; y0 *= dy; wxPoint offset(-x0+WXLO_XOFFSET, -y0+WXLO_YOFFSET); if(m_CursorVisibility == -1) m_CursorVisibility = 1; #ifdef WXLAYOUT_USE_CARET if ( m_CursorVisibility == 1 ) GetCaret()->Show(); #endif // WXLAYOUT_USE_CARET if(m_CursorVisibility) { // draw a thick cursor for editable windows with focus m_llist->DrawCursor(dc, m_HaveFocus && IsEditable(), offset); } #ifdef __WXGTK__ RequestUpdate(); // RequestUpdate suppresses flicker under GTK #endif // wxGTK // start selection m_llist->StartSelection(wxPoint(-1, -1), m_ClickPosition); m_Selecting = true; } break; case WXLOWIN_MENU_LUP: if ( m_Selecting ) { // end selection at the cursor position corresponding to the // current mouse position, but don´t move cursor there. m_llist->EndSelection(cursorPos,m_ClickPosition); m_Selecting = false; RequestUpdate(); // TODO: we don't have to redraw everything! } break; case WXLOWIN_MENU_MDOWN: Paste(true); break; case WXLOWIN_MENU_DBLCLICK: // select a word under cursor m_llist->MoveCursorTo(cursorPos); m_llist->MoveCursorWord(-1); m_llist->StartSelection(); m_llist->MoveCursorWord(1, false); m_llist->EndSelection(); m_Selecting = false; RequestUpdate(); // TODO: we don't have to redraw everything! break; } // notify about mouse events? if( m_doSendEvents ) { // only do the menu if activated, editable and not on a clickable object if(eventId == WXLOWIN_MENU_RCLICK && IsEditable() && (! obj || u == NULL)) { PopupMenu(m_PopupMenu, m_ClickPosition.x, m_ClickPosition.y); if(u) u->DecRef(); return; } // find the object at this position if(obj) { wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, eventId); commandEvent.SetEventObject( this ); commandEvent.SetClientData((char *)obj); GetEventHandler()->ProcessEvent(commandEvent); } } if( u ) u->DecRef(); }