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(); }
bool wxComboBox::CanCut() const { return CanCopy() && IsEditable(); }
FText ButtonText() const { return IsEditable() ? LOCTEXT("Generate", "Generate") : LOCTEXT("Close", "Close"); }
void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) { long from, to; GetSelection(& from, & to); event.Enable(from != -1 && to != -1 && from != to && IsEditable()) ; }
virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case AIC_WIDGET_DECREASE: case AIC_WIDGET_INCREASE: { int new_value; if (widget == AIC_WIDGET_DECREASE) { new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1); } else { new_value = min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1); } IConsoleSetSetting("difficulty.max_no_competitors", new_value); this->InvalidateData(); break; } case AIC_WIDGET_LIST: { // Select a slot this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height); this->InvalidateData(); if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot); break; } case AIC_WIDGET_MOVE_UP: if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) { Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]); this->selected_slot--; this->vscroll->ScrollTowards(this->selected_slot); this->InvalidateData(); } break; case AIC_WIDGET_MOVE_DOWN: if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) { Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]); this->selected_slot++; this->vscroll->ScrollTowards(this->selected_slot); this->InvalidateData(); } break; case AIC_WIDGET_CHANGE: // choose other AI ShowAIListWindow((CompanyID)this->selected_slot); break; case AIC_WIDGET_CONFIGURE: // change the settings for an AI ShowAISettingsWindow((CompanyID)this->selected_slot); break; case AIC_WIDGET_CLOSE: delete this; break; case AIC_WIDGET_CONTENT_DOWNLOAD: if (!_network_available) { ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR); } else { #if defined(ENABLE_NETWORK) ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI); #endif } break; } }
bool wxTextCtrlBase::CanPaste() const { // can paste if we are not read only return IsEditable(); }
void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) { event.Enable(IsEditable() && !wxTextEntry::IsEmpty()); }
void ETextEditable::KeyDown(const char *bytes, eint32 numBytes) { if(!IsEnabled() || !(IsEditable() || IsSelectable()) || !IsFocus() || numBytes < 1) return; if(bytes[0] == E_ENTER) return; EWindow *win = Window(); if(!win) return; EMessage *msg = win->CurrentMessage(); if(!msg || !(msg->what == E_KEY_DOWN || msg->what == E_UNMAPPED_KEY_DOWN)) return; eint32 modifiers = 0; msg->FindInt32("modifiers", &modifiers); if((modifiers & E_CONTROL_KEY) || (modifiers & E_COMMAND_KEY) || (modifiers & E_MENU_KEY) || (modifiers & E_OPTION_KEY)) return; bool shift_only = false; if(IsSelectable()) { modifiers &= ~(E_CAPS_LOCK | E_SCROLL_LOCK | E_NUM_LOCK | E_LEFT_SHIFT_KEY | E_RIGHT_SHIFT_KEY); if(modifiers == E_SHIFT_KEY) shift_only = true; } if(numBytes == 1) { switch(bytes[0]) { case E_ESCAPE: if(IsSelectable() && (fSelectTracking > 0 || IsSelected())) { fSelectTracking = -1; fSelectStart = fSelectEnd = -1; // call virtual function Select(fSelectStart, fSelectEnd); Invalidate(); } break; case E_UP_ARROW: case E_DOWN_ARROW: break; case E_LEFT_ARROW: { bool redraw = false; eint32 oldStart = fSelectStart; eint32 oldEnd = fSelectEnd; if(IsSelectable() && shift_only) { if(fSelectTracking < 0) { if(IsSelected() && fSelectStart == fPosition) { fSelectTracking = fSelectEnd + 1; if(fPosition > 0) fSelectStart = fPosition - 1; } else { fSelectTracking = fPosition; fSelectStart = fSelectEnd = fPosition - 1; } } else if(fPosition > 0) { if(fPosition <= fSelectTracking) { fSelectStart = fPosition - 1; fSelectEnd = fSelectTracking - 1; } else { fSelectStart = fSelectTracking; fSelectEnd = fPosition - 2; } } } else if(IsSelectable()) { fSelectStart = fSelectEnd = -1; } if(oldStart != fSelectStart || oldEnd != fSelectEnd) { // call virtual function Select(fSelectStart, fSelectEnd); redraw = true; } if(fPosition > 0) { fPosition = fPosition - 1; redraw = true; } if(redraw) Invalidate(); } break; case E_RIGHT_ARROW: { bool redraw = false; eint32 oldStart = fSelectStart; eint32 oldEnd = fSelectEnd; if(IsSelectable() && shift_only) { if(fSelectTracking < 0) { if(IsSelected() && fSelectEnd == fPosition - 1) { fSelectTracking = fSelectStart; if(fPosition < fCount) fSelectEnd = fPosition; } else { fSelectTracking = fPosition; fSelectStart = fSelectEnd = fPosition; } } else if(fPosition < fCount) { if(fPosition >= fSelectTracking) { fSelectStart = fSelectTracking; fSelectEnd = fPosition; } else { fSelectStart = fPosition + 1; fSelectEnd = fSelectTracking - 1; } } } else if(IsSelectable()) { fSelectStart = fSelectEnd = -1; } if(oldStart != fSelectStart || oldEnd != fSelectEnd) { // call virtual function Select(fSelectStart, fSelectEnd); redraw = true; } if(fPosition < fCount) { fPosition = fPosition + 1; redraw = true; } if(redraw) Invalidate(); } break; case E_DELETE: if(IsSelectable() && IsEditable() && IsSelected()) { eint32 oldPos = fSelectStart; RemoveText(fSelectStart, fSelectEnd); SetPosition(oldPos); } else if(fPosition < fCount && fPosition >= 0 && IsEditable()) { RemoveText(fPosition, fPosition); } break; case E_BACKSPACE: if(IsSelectable() && IsEditable() && IsSelected()) { eint32 oldPos = fSelectStart; RemoveText(fSelectStart, fSelectEnd); SetPosition(oldPos); } else if(fPosition > 0 && fPosition <= fCount && IsEditable()) { eint32 oldCount = fCount; eint32 oldPos = fPosition; RemoveText(fPosition - 1, fPosition - 1); if(fCount < oldCount && oldPos == fPosition) SetPosition(oldPos - 1); } break; case E_HOME: { bool redraw = false; eint32 oldStart = fSelectStart; eint32 oldEnd = fSelectEnd; if(IsSelectable() && shift_only) { if(fSelectTracking < 0) { if(IsSelected() && fSelectStart == fPosition) fSelectTracking = fSelectEnd + 1; else fSelectTracking = fPosition; } fSelectStart = 0; fSelectEnd = fSelectTracking - 1; } else if(IsSelectable()) { fSelectStart = fSelectEnd = -1; } if(oldStart != fSelectStart || oldEnd != fSelectEnd) { // call virtual function Select(fSelectStart, fSelectEnd); redraw = true; } if(fPosition != 0) { fPosition = 0; redraw = true; } if(redraw) Invalidate(); } break; case E_END: { bool redraw = false; eint32 oldStart = fSelectStart; eint32 oldEnd = fSelectEnd; if(IsSelectable() && shift_only) { if(fSelectTracking < 0) { if(IsSelected() && fSelectEnd == fPosition - 1) fSelectTracking = fSelectStart; else fSelectTracking = fPosition; } fSelectStart = fSelectTracking; fSelectEnd = fCount - 1; } else if(IsSelectable()) { fSelectStart = fSelectEnd = -1; } if(oldStart != fSelectStart || oldEnd != fSelectEnd) { // call virtual function Select(fSelectStart, fSelectEnd); redraw = true; } if(fPosition != fCount) { fPosition = fCount; redraw = true; } if(redraw) Invalidate(); } break; default: if(bytes[0] >= 0x20 && bytes[0] <= 0x7e && IsEditable()) // printable { if(IsSelectable() && IsSelected()) { eint32 oldPos = fSelectStart; RemoveText(fSelectStart, fSelectEnd); InsertText(bytes, 1, oldPos); SetPosition(oldPos + 1); } else { eint32 oldCount = fCount; eint32 oldPos = fPosition; InsertText(bytes, 1, fPosition); if(fCount > oldCount && oldPos == fPosition) SetPosition(oldPos + 1); } } break; } } else { if(IsEditable()) { eint32 len = e_utf8_strlen(bytes); if(len > 0) { if(IsSelectable() && IsSelected()) { eint32 oldPos = fSelectStart; RemoveText(fSelectStart, fSelectEnd); InsertText(bytes, len, oldPos); SetPosition(oldPos + len); } else { eint32 oldCount = fCount; eint32 oldPos = fPosition; InsertText(bytes, len, fPosition); if(fCount > oldCount && oldPos == fPosition) SetPosition(oldPos + len); } } } // TODO: input method } }
OP_STATUS GroupsModelItem::GetItemData(ItemData* item_data) { if (item_data->query_type == INIT_QUERY) { if (m_subscribed) { item_data->flags |= FLAG_INITIALLY_CHECKED; } if (!IsEditable()) { item_data->flags |= FLAG_INITIALLY_DISABLED; } return OpStatus::OK; } // note that for chat rooms, m_name = topic and m_path = room name OpString& name = m_type == CHATROOM_TYPE ? m_path : m_name; if (item_data->query_type == MATCH_QUERY) { if (item_data->match_query_data.match_text->HasContent() && uni_stristr(name.CStr(), item_data->match_query_data.match_text->CStr())) { item_data->flags |= FLAG_MATCHED; } return OpStatus::OK; } if (item_data->query_type != COLUMN_QUERY) { return OpStatus::OK; } switch (item_data->column_query_data.column) { case 0: // name item_data->column_query_data.column_text->Set(name); break; case 1: // status { if (m_type == CHATROOM_TYPE) { if (m_subscribed) { uni_char users[16]; uni_ltoa(m_subscribed, users, 10); item_data->column_query_data.column_text->Set(users); } } else { if (m_subscribed) { OpString subscribed; RETURN_IF_ERROR(g_languageManager->GetString(Str::S_SUBSCRIBED, subscribed)); item_data->column_query_data.column_text->Set(subscribed); } else { item_data->column_query_data.column_text->Empty(); } } break; } case 2: // topic { if (m_type == CHATROOM_TYPE) { item_data->column_query_data.column_text->Set(m_name); } break; } } return OpStatus::OK; }
void ETextEditable::MouseDown(EPoint where) { ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(!IsEnabled() || !rect.Contains(where) || !QueryCurrentMouse(true, E_PRIMARY_MOUSE_BUTTON)) return; if(!(IsEditable() || IsSelectable())) return; if(!IsFocus()) MakeFocus(true); EFont font; GetFont(&font); float x = 0; if(!GetCharLocation(0, &x, NULL, &font)) return; eint32 pos = 0; if(where.x > x) { for(eint32 i = 0; i <= fCount; i++) { if(i == fCount) { pos = fCount; } else { x += (float)ceil((double)fCharWidths[i]); if(where.x < x) { pos = i; break; } x += (float)ceil((double)(font.Spacing() * font.Size())); if(where.x < x) { pos = i + 1; break; } } } } bool redraw = IsSelected(); if(IsFocus() && fSelectTracking < 0) { if(!(!IsSelectable() || SetPrivateEventMask(E_POINTER_EVENTS, E_LOCK_WINDOW_FOCUS) != E_OK)) { fSelectStart = fSelectEnd = -1; fSelectTracking = pos; } else { fSelectStart = fSelectEnd = -1; fSelectTracking = -1; } // call virtual function Select(fSelectStart, fSelectEnd); } if(fPosition != pos) { fPosition = pos; redraw = true; } if(redraw) Invalidate(); }
void ETextEditable::MouseMoved(EPoint where, euint32 code, const EMessage *a_message) { ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(rect.Contains(where) == false || code == E_EXITED_VIEW) { etk_app->SetCursor(E_CURSOR_SYSTEM_DEFAULT, false); return; } etk_app->SetCursor(E_CURSOR_I_BEAM, false); if(!IsEnabled() || !IsSelectable() || fSelectTracking < 0) return; EWindow *win = Window(); if(!win) return; if(!VisibleBounds().Contains(where)) return; if(!(IsEditable() || IsSelectable())) return; EFont font; GetFont(&font); float x = 0; if(!GetCharLocation(0, &x, NULL, &font)) return; eint32 pos = 0; if(where.x > x) { for(eint32 i = 0; i <= fCount; i++) { if(i == fCount) { pos = fCount; } else { x += (float)ceil((double)fCharWidths[i]); if(where.x < x) { pos = i; break; } x += (float)ceil((double)(font.Spacing() * font.Size())); if(where.x < x) { pos = i + 1; break; } } } } bool redraw = false; eint32 oldStart = fSelectStart; eint32 oldEnd = fSelectEnd; if(pos == fSelectTracking) { if(IsSelected()) redraw = true; fSelectStart = fSelectEnd = -1; } else if(pos > fSelectTracking) { fSelectStart = fSelectTracking; fSelectEnd = pos - 1; } else // pos < fSelectTracking { fSelectStart = pos; fSelectEnd = fSelectTracking - 1; } if(oldStart != fSelectStart || oldEnd != fSelectEnd) { // call virtual function Select(fSelectStart, fSelectEnd); redraw = true; } if(fPosition != pos) { fPosition = pos; redraw = true; } if(redraw) Invalidate(); }
void ETextEditable::Draw(ERect updateRect) { if(!IsVisible()) return; ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; if(!rect.IsValid()) return; ERegion clipping; GetClippingRegion(&clipping); if(clipping.CountRects() > 0) clipping &= (rect & updateRect); else clipping = (rect & updateRect); if(clipping.CountRects() <= 0) return; e_rgb_color bkColor = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); e_rgb_color fgColor = e_ui_color(E_DOCUMENT_TEXT_COLOR); if(!IsEnabled()) { bkColor.disable(ViewColor()); fgColor.disable(ViewColor()); } if(!IsFocusChanging()) { PushState(); ConstrainClippingRegion(&clipping); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(bkColor); FillRect(rect & updateRect, E_SOLID_HIGH); PopState(); } EFont font; e_font_height fontHeight; GetFont(&font); font.GetHeight(&fontHeight); if(fCount > 0 && !IsFocusChanging()) { PushState(); ConstrainClippingRegion(&clipping); float x = 0, y = 0; if(GetCharLocation(0, &x, &y, &font)) { SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(fgColor); SetLowColor(bkColor); _DrawString(fText, EPoint(x, y)); if(IsEnabled() && IsSelected()) { char *selectedText = DuplicateText(fSelectStart, fSelectEnd); if(selectedText != NULL) { x = 0; y = 0; if(GetCharLocation(fSelectStart, &x, &y, &font)) { DrawSelectedBackground(updateRect); SetLowColor(e_ui_color(E_DOCUMENT_HIGHLIGHT_COLOR)); _DrawString(selectedText, EPoint(x, y)); } free(selectedText); } } } PopState(); } if(IsEnabled() && IsEditable() && (IsFocus() || IsFocusChanging())) { PushState(); ConstrainClippingRegion(&clipping); DrawCursor(); PopState(); } if((IsFocus() || IsFocusChanging()) && Window()->IsActivate() && IsEnabled() && (Flags() & E_NAVIGABLE)) { e_rgb_color color = e_ui_color(E_NAVIGATION_BASE_COLOR); if(IsFocusChanging() && !IsFocus()) color = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR); PushState(); ConstrainClippingRegion(&clipping); SetDrawingMode(E_OP_COPY); SetPenSize(0); SetHighColor(color); StrokeRect(rect, E_SOLID_HIGH); PopState(); } }
bool ETextEditable::GetCharLocation(eint32 pos, float *x, float *y, EFont *tFont) { if(!x) return false; ERect rect = Frame().OffsetToSelf(E_ORIGIN); rect.left += fMargins.left; rect.top += fMargins.top; rect.right -= fMargins.right; rect.bottom -= fMargins.bottom; rect.InsetBy(2, 2); if(!rect.IsValid()) return false; EFont font; e_font_height fontHeight; if(tFont) font = *tFont; else GetFont(&font); font.GetHeight(&fontHeight); float sHeight = fontHeight.ascent + fontHeight.descent; float strWidth = (fCount <= 0 ? 0.f : max_c(0.f, _StringWidth(font, fText))); float fontSpacing = (float)ceil((double)font.Spacing() * font.Size()); if(fAlignment == E_ALIGN_RIGHT) *x = rect.right - strWidth; else if(fAlignment == E_ALIGN_CENTER) *x = rect.Center().x - strWidth / 2.f; else *x = rect.left; /* E_ALIGN_LEFT */ if(y) *y = (rect.Center().y - sHeight/ 2.f + fontHeight.ascent + 1); if(strWidth <= rect.Width() || !IsEnabled() || !(IsEditable() || (IsSelectable() && IsSelected())) || fPosition < 0 || fPosition > fCount) { locationOffset = 0; } else { float xx = *x + locationOffset; if(fPosition > 0 && fPosition < fCount) { const char *p = e_utf8_at((const char*)fText, fPosition, NULL); if(p != NULL) { EString str; str.Append(fText, (eint32)(p - (const char*)fText)); xx += _StringWidth(font, str.String()) + fontSpacing; } } else if(fPosition == fCount) { xx += strWidth + fontSpacing; } if(xx < rect.left) locationOffset += (rect.left - xx); else if(xx > rect.right) locationOffset += (rect.right - xx); } *x += locationOffset; if(pos > 0 && pos < fCount) { const char *p = e_utf8_at((const char*)fText, pos, NULL); if(p != NULL) { EString str; str.Append(fText, (eint32)(p - (const char*)fText)); *x += _StringWidth(font, str.String()) + fontSpacing; } } else if(pos < 0 || pos >= fCount) { *x += strWidth + fontSpacing; } return true; }
//***************************************************************************************** void CBCGPCalendarMenuButton::OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* pImages, BOOL bHorz, BOOL bCustomizeMode, BOOL bHighlight, BOOL bDrawBorder, BOOL bGrayDisabledButtons) { ASSERT_VALID (this); ASSERT_VALID (pDC); if (m_bMenuMode) { DrawMenuItem (pDC, rect, pImages, bCustomizeMode, bHighlight, bGrayDisabledButtons); return; } //---------------------- // Fill button interior: //---------------------- FillInterior (pDC, rect, bHighlight || IsDroppedDown ()); CSize sizeImage = CBCGPMenuImages::Size (); if (CBCGPToolBar::IsLargeIcons ()) { sizeImage.cx *= 2; sizeImage.cy *= 2; } CRect rectInternal = rect; CSize sizeExtra = m_bExtraSize ? visualManagerInstance->GetButtonExtraBorder () : CSize (0, 0); if (sizeExtra != CSize (0, 0)) { rectInternal.DeflateRect (sizeExtra.cx / 2 + 1, sizeExtra.cy / 2 + 1); } CRect rectParent = rect; CRect rectArrow = rectInternal; const int nMargin = visualManagerInstance->GetMenuImageMargin (); const int xMargin = bHorz ? nMargin : 0; const int yMargin = bHorz ? 0 : nMargin; rectInternal.DeflateRect (xMargin, yMargin); rectParent.DeflateRect (xMargin, yMargin); if (m_bDrawDownArrow) { if (bHorz) { rectParent.right -= sizeImage.cx + SEPARATOR_SIZE; rectArrow.left = rectParent.right - 1; rectArrow.OffsetRect (-sizeExtra.cx / 2, -sizeExtra.cy / 2); } else { rectParent.bottom -= sizeImage.cy + SEPARATOR_SIZE; rectArrow.top = rectParent.bottom - 1; } } UINT uiStyle = m_nStyle; if (visualManagerInstance->IsMenuFlatLook ()) { m_nStyle &= ~(TBBS_PRESSED | TBBS_CHECKED); } else { if (m_bClickedOnMenu && m_nID != 0 && m_nID != (UINT) -1 && !m_bMenuOnly) { m_nStyle &= ~TBBS_PRESSED; } else if (m_pPopupMenu != NULL) { m_nStyle |= TBBS_PRESSED; } } BOOL bDisableFill = m_bDisableFill; m_bDisableFill = TRUE; CBCGPToolbarButton::OnDraw (pDC, rectParent, pImages, bHorz, bCustomizeMode, bHighlight, bDrawBorder, bGrayDisabledButtons); m_bDisableFill = bDisableFill; if (m_bDrawDownArrow) { if ((m_nStyle & (TBBS_PRESSED | TBBS_CHECKED)) && !visualManagerInstance->IsMenuFlatLook ()) { rectArrow.OffsetRect (1, 1); } BOOL bDisabled = (bCustomizeMode && !IsEditable ()) || (!bCustomizeMode && (m_nStyle & TBBS_DISABLED)); int iImage; if (bHorz && !m_bMenuOnly) { iImage = CBCGPMenuImages::IdArowDown; } else { iImage = CBCGPMenuImages::IdArowRight; } if (m_pPopupMenu != NULL && (m_nStyle & (TBBS_PRESSED | TBBS_CHECKED)) == 0 && !visualManagerInstance->IsMenuFlatLook ()) { rectArrow.OffsetRect (1, 1); } CBCGPMenuImages::Draw (pDC, (CBCGPMenuImages::IMAGES_IDS) iImage, rectArrow, bDisabled ? CBCGPMenuImages::ImageGray : CBCGPMenuImages::ImageBlack, sizeImage); } m_nStyle = uiStyle; if (!bCustomizeMode) { if ((m_nStyle & (TBBS_PRESSED | TBBS_CHECKED)) || m_pPopupMenu != NULL) { //----------------------- // Pressed in or checked: //----------------------- if (!visualManagerInstance->IsMenuFlatLook () && m_bClickedOnMenu && m_nID != 0 && m_nID != (UINT) -1 && !m_bMenuOnly) { visualManagerInstance->OnDrawButtonBorder (pDC, this, rectParent, visualManager::ButtonsIsHighlighted); rectArrow.right --; rectArrow.bottom --; visualManagerInstance->OnDrawButtonBorder (pDC, this, rectArrow, visualManager::ButtonsIsPressed); } else { visualManagerInstance->OnDrawButtonBorder (pDC, this, rect, visualManager::ButtonsIsPressed); } } else if (bHighlight && !(m_nStyle & TBBS_DISABLED) && !(m_nStyle & (TBBS_CHECKED | TBBS_INDETERMINATE))) { visualManagerInstance->OnDrawButtonBorder (pDC, this, rect, visualManager::ButtonsIsHighlighted); } } }
void wxLayoutWindow::OnChar(wxKeyEvent& event) { int keyCode = event.GetKeyCode(); bool ctrlDown = event.ControlDown(); #ifdef WXLAYOUT_DEBUG if(keyCode == WXK_F1) { m_llist->Debug(); return; } #endif // Force m_Selecting to be false if shift is no longer // pressed. OnKeyUp() cannot catch all Shift-Up events. if(m_Selecting && !event.ShiftDown()) { m_Selecting = false; m_llist->EndSelection(); m_llist->DiscardSelection(); //FIXME: correct? } // If we deleted the selection here, we must not execute the // deletion in Delete/Backspace handling. bool deletedSelection = false; // pressing any non-arrow key optionally replaces the selection: if(m_AutoDeleteSelection && IsEditable() && !m_Selecting && m_llist->HasSelection() && ! IsDirectionKey(keyCode) && ! (event.AltDown() || ctrlDown) ) { m_llist->DeleteSelection(); deletedSelection = true; SetDirty(); } // <Shift>+<arrow> starts selection if ( IsDirectionKey(keyCode) ) { // just continue the old selection if ( m_Selecting && event.ShiftDown() ) { m_llist->ContinueSelection(); } else { m_llist->DiscardSelection(); m_Selecting = false; if( event.ShiftDown() ) { m_Selecting = true; m_llist->StartSelection(); } } } // If needed, make cursor visible: if(m_CursorVisibility == -1) m_CursorVisibility = 1; /* These two nested switches work like this: The first one processes all non-editing keycodes, to move the cursor, etc. It's default will process all keycodes causing modifications to the buffer, but only if editing is allowed. */ switch(keyCode) { case WXK_RIGHT: if ( ctrlDown ) m_llist->MoveCursorWord(1); else m_llist->MoveCursorHorizontally(1); break; case WXK_LEFT: if ( ctrlDown ) m_llist->MoveCursorWord(-1); else m_llist->MoveCursorHorizontally(-1); break; case WXK_UP: m_llist->MoveCursorVertically(-1); break; case WXK_DOWN: m_llist->MoveCursorVertically(1); break; case WXK_PRIOR: m_llist->MoveCursorVertically(-Y_SCROLL_PAGE); break; case WXK_NEXT: m_llist->MoveCursorVertically(Y_SCROLL_PAGE); break; case WXK_HOME: if ( ctrlDown ) m_llist->MoveCursorTo(wxPoint(0, 0)); else m_llist->MoveCursorToBeginOfLine(); break; case WXK_END: if ( ctrlDown ) m_llist->MoveCursorToEnd(); else m_llist->MoveCursorToEndOfLine(); break; default: if(ctrlDown && ! IsEditable()) { switch(keyCode) { case 'c': // this should work even in read-only mode Copy(true, true); break; case 's': // search Find(wxEmptyString); break; case 't': // search again FindAgain(); break; default: // we don't handle it, maybe an accelerator? event.Skip(); ; } } else if( IsEditable() ) { /* First, handle control keys */ if(ctrlDown && ! event.AltDown()) { if(keyCode >= 'A' && keyCode <= 'Z') keyCode = tolower(keyCode); switch(keyCode) { case WXK_INSERT: Copy(); break; case WXK_DELETE : if(! deletedSelection) { m_llist->DeleteWord(); SetDirty(); } break; case 'd': if(! deletedSelection) // already done { m_llist->Delete(1); SetDirty(); } break; case 'y': m_llist->DeleteLines(1); SetDirty(); break; case 'h': // like backspace if(m_llist->MoveCursorHorizontally(-1)) { m_llist->Delete(1); SetDirty(); } break; case 's': // search Find(wxEmptyString); break; case 't': // search again FindAgain(); break; case 'u': m_llist->DeleteToBeginOfLine(); SetDirty(); break; case 'k': m_llist->DeleteToEndOfLine(); SetDirty(); break; case 'c': Copy(true, true); break; case 'v': Paste(true); break; case 'x': Cut(); break; case 'w': if(m_WrapMargin > 0) m_llist->WrapLine(m_WrapMargin); break; case 'q': if(m_WrapMargin > 0) m_llist->WrapAll(m_WrapMargin); break; #ifdef WXLAYOUT_DEBUG case WXK_F1: m_llist->SetFont(-1,-1,-1,-1,true); // underlined break; case 'l': Refresh(true); break; #endif default: // we don't handle it, maybe an accelerator? event.Skip(); } } // ALT only: else if( event.AltDown() && ! event.ControlDown() ) { switch(keyCode) { case WXK_DELETE: case 'd': m_llist->DeleteWord(); SetDirty(); break; default: // we don't handle it, maybe an accelerator? event.Skip(); } } // no control keys: else if ( ! event.AltDown() && ! event.ControlDown()) { switch(keyCode) { case WXK_INSERT: if(event.ShiftDown()) Paste(); break; case WXK_DELETE : if(event.ShiftDown()) { Cut(); } else if(! deletedSelection) { m_llist->Delete(1); SetDirty(); } break; case WXK_BACK: // backspace if(! deletedSelection) { if(m_llist->MoveCursorHorizontally(-1)) { m_llist->Delete(1); SetDirty(); } } break; case WXK_RETURN: if (m_DoWordWrap && m_WrapMargin > 0 && m_llist->GetCursorPos().x > m_WrapMargin ) { m_llist->WrapLine(m_WrapMargin); } m_llist->LineBreak(); SetDirty(); break; case WXK_TAB: if ( !event.ShiftDown() ) { // TODO should be configurable static const int tabSize = 8; CoordType x = m_llist->GetCursorPos().x; size_t numSpaces = tabSize - x % tabSize; m_llist->Insert(wxString(' ', numSpaces)); SetDirty(); } break; default: if ( ( !(event.ControlDown() || event.AltDown()) ) && (keyCode < 256 && keyCode >= 32) ) { if ( m_DoWordWrap && m_WrapMargin > 0 && m_llist->GetCursorPos().x > m_WrapMargin && isspace(keyCode) ) { m_llist->WrapLine(m_WrapMargin); } m_llist->Insert((wxChar)keyCode); SetDirty(); } else { // we don't handle it, maybe an accelerator? event.Skip(); } break; } } }// if(IsEditable()) else { // we don't handle it, maybe an accelerator? event.Skip(); } }// first switch() if ( m_Selecting ) { // continue selection to the current (new) cursor position m_llist->ContinueSelection(); } ScrollToCursor(); // refresh the screen RequestUpdate(m_llist->GetUpdateRect()); }
void BTextWidget::StartEdit(BRect bounds, BPoseView* view, BPose* pose) { view->SetTextWidgetToCheck(NULL, this); if (!IsEditable() || IsActive()) return; BEntry entry(pose->TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK && !ConfirmChangeIfWellKnownDirectory(&entry, B_TRANSLATE_COMMENT("rename", "As in 'if you rename this folder...' (en) " "'Wird dieser Ordner umbenannt...' (de)"), B_TRANSLATE_COMMENT("rename", "As in 'to rename this folder...' (en) " "'Um diesen Ordner umzubenennen...' (de)"), B_TRANSLATE_COMMENT("Rename", "Button label, 'Rename' (en), 'Umbenennen' (de)"))) return; // get bounds with full text length BRect rect(bounds); BRect textRect(bounds); rect.OffsetBy(-2, -1); rect.right += 1; BFont font; view->GetFont(&font); BTextView* textView = new BTextView(rect, "WidgetTextView", textRect, &font, 0, B_FOLLOW_ALL, B_WILL_DRAW); textView->SetWordWrap(false); DisallowMetaKeys(textView); fText->SetUpEditing(textView); textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter)); rect.right = rect.left + textView->LineWidth() + 3; // center new width, if necessary if (view->ViewMode() == kIconMode || (view->ViewMode() == kListMode && fAlignment == B_ALIGN_CENTER)) { rect.OffsetBy(bounds.Width() / 2 - rect.Width() / 2, 0); } rect.bottom = rect.top + textView->LineHeight() + 1; textRect = rect.OffsetToCopy(2, 1); textRect.right -= 3; textRect.bottom--; textView->SetTextRect(textRect); BPoint origin = view->LeftTop(); textRect = view->Bounds(); bool hitBorder = false; if (rect.left <= origin.x) rect.left = origin.x + 1, hitBorder = true; if (rect.right >= textRect.right) rect.right = textRect.right - 1, hitBorder = true; textView->MoveTo(rect.LeftTop()); textView->ResizeTo(rect.Width(), rect.Height()); BScrollView* scrollView = new BScrollView("BorderView", textView, 0, 0, false, false, B_PLAIN_BORDER); view->AddChild(scrollView); // configure text view switch (view->ViewMode()) { case kIconMode: textView->SetAlignment(B_ALIGN_CENTER); break; case kMiniIconMode: textView->SetAlignment(B_ALIGN_LEFT); break; case kListMode: textView->SetAlignment(fAlignment); break; } textView->MakeResizable(true, hitBorder ? NULL : scrollView); view->SetActivePose(pose); // tell view about pose SetActive(true); // for widget textView->SelectAll(); textView->MakeFocus(); // make this text widget invisible while we edit it SetVisible(false); ASSERT(view->Window() != NULL); // how can I not have a Window here??? if (view->Window()) { // force immediate redraw so TextView appears instantly view->Window()->UpdateIfNeeded(); } }
bool wxTextCtrlBase::CanCut() const { // can cut if there's a selection and if we're not read only return CanCopy() && IsEditable(); }
wex::grid::grid(const window_data& data) : wxGrid( data.parent(), data.id(), data.pos(), data.size(), data.style(), data.name()) { SetDropTarget(new text_droptarget(this)); m_use_drag_and_drop = true; Bind(wxEVT_MENU, [=](wxCommandEvent& event) { empty_selection();}, wxID_DELETE); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { SelectAll();}, wxID_SELECTALL); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { ClearSelection();}, ID_EDIT_SELECT_NONE); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { copy_selected_cells_to_clipboard();}, wxID_COPY); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { copy_selected_cells_to_clipboard(); empty_selection();}, wxID_CUT); Bind(wxEVT_MENU, [=](wxCommandEvent& event) { paste_cells_from_clipboard();}, wxID_PASTE); Bind(wxEVT_FIND, [=](wxFindDialogEvent& event) { find_next( find_replace_data::get()->get_find_string(), find_replace_data::get()->search_down());}); Bind(wxEVT_FIND_NEXT, [=](wxFindDialogEvent& event) { find_next( find_replace_data::get()->get_find_string(), find_replace_data::get()->search_down());}); Bind(wxEVT_GRID_CELL_LEFT_CLICK, [=](wxGridEvent& event) { // Removed extra check for !IsEditable(), // drag/drop is different from editing, so allow that. if (!IsSelection()) { event.Skip(); return; } if (m_use_drag_and_drop) { // This is because drag/drop is not really supported by the wxGrid. // Even the wxEVT_GRID_CELL_BEGIN_DRAG does not seem to come in. // Therefore, we are really dragging if you click again in // your selection and move mouse and drop elsewhere. // So, if not clicked in the selection, do nothing, this was no drag. if (!IsInSelection(event.GetRow(), event.GetCol())) { event.Skip(); return; } // Is it allowed to drag current selection?? if (!is_allowed_drag_selection()) { event.Skip(); return; } // Start drag operation. wxTextDataObject textData(get_selected_cells_value()); wxDropSource source(textData, this); wxDragResult result = source.DoDragDrop(wxDrag_DefaultMove); if (result != wxDragError && result != wxDragNone && result != wxDragCancel) { // The old contents is not deleted, as should be by moving. // To fix this, do not call Skip so selection remains active, // and call empty_selection. // event.Skip(); empty_selection(); ClearSelection(); } else { // Do not call Skip so selection remains active. // event.Skip(); } } else { event.Skip(); } }); Bind(wxEVT_GRID_CELL_RIGHT_CLICK, [=](wxGridEvent& event) { int style = (IsEditable() ? wex::menu::DEFAULT: wex::menu::IS_READ_ONLY); if (IsSelection()) style |= wex::menu::IS_SELECTED; wex::menu menu(style); build_popup_menu(menu); PopupMenu(&menu); }); Bind(wxEVT_GRID_SELECT_CELL, [=](wxGridEvent& event) { frame::statustext( std::to_string(1 + event.GetCol()) + "," + std::to_string(1 + event.GetRow()), "PaneInfo"); event.Skip();}); Bind(wxEVT_GRID_RANGE_SELECT, [=](wxGridRangeSelectEvent& event) { event.Skip(); frame::statustext(std::to_string(GetSelectedCells().GetCount()), "PaneInfo"); }); Bind(wxEVT_SET_FOCUS, [=](wxFocusEvent& event) { wex::frame* frame = dynamic_cast<wex::frame*>(wxTheApp->GetTopWindow()); if (frame != nullptr) { frame->set_find_focus(this); } event.Skip();}); }
void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) { event.Enable( IsEditable() && CanRedo() ); }
void WrappingTextView::KeyDown(const char *bytes, int32 numBytes) { if (IsEditable() && numBytes==1) { m_last_key_was_del = (bytes[0]==B_DELETE); switch( bytes[0]) { case B_RIGHT_ARROW: { // implement word-wise movement: int32 mods = Window()->CurrentMessage()->FindInt32("modifiers"); if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) { int32 len=TextLength(); int32 startPos, endPos; GetSelection( &startPos, &endPos); if (endPos==len) break; if (startPos==endPos && (mods & B_SHIFT_KEY)) m_selection_start=B_RIGHT_ARROW; int32 wordStart, wordEnd; if (mods & B_SHIFT_KEY && m_selection_start==B_LEFT_ARROW) { do { FindWord( startPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( ++startPos < len); Select( MIN(endPos, wordEnd), endPos); } else { do { FindWord( endPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( ++endPos < len); if (mods & B_SHIFT_KEY) { Select( startPos, wordEnd); } else Select( wordEnd, wordEnd); } ScrollToSelection(); } else inherited::KeyDown( bytes, numBytes); break; } case B_LEFT_ARROW: { // implement word-wise movement: int32 mods = Window()->CurrentMessage()->FindInt32("modifiers"); if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) { int32 startPos, endPos; GetSelection( &startPos, &endPos); if (!startPos) break; if (startPos==endPos && (mods & B_SHIFT_KEY)) m_selection_start=B_LEFT_ARROW; int32 wordStart, wordEnd; if (mods & B_SHIFT_KEY && m_selection_start==B_RIGHT_ARROW) { --endPos; do { FindWord( endPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( --endPos > 0); Select( startPos, MAX( startPos, wordStart)); } else { --startPos; do { FindWord( startPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( --startPos > 0); if (mods & B_SHIFT_KEY) Select( wordStart, endPos); else Select( wordStart, wordStart); } ScrollToSelection(); } else inherited::KeyDown( bytes, numBytes); break; } default: inherited::KeyDown( bytes, numBytes); break; } } else if ( numBytes == 1 ) { // in read-only mode, we use cursor-keys to move scrollbar, and // we remap HOME / END to the vertical scrollbar (not the horizontal, // which is default). switch( bytes[0]) { case B_PAGE_UP: case B_PAGE_DOWN: case B_UP_ARROW: case B_DOWN_ARROW: case B_HOME: case B_END: { // move vertical scrollbar: float min, max, smallStep, bigStep, value; BScrollBar* bar = ScrollBar( B_VERTICAL); if (!bar) return; bar->GetRange( &min, &max); bar->GetSteps( &smallStep, &bigStep); value = bar->Value(); if (bytes[0] == B_UP_ARROW) { value = MAX( value-smallStep, min); } else if (bytes[0] == B_DOWN_ARROW) { value = MIN( value+smallStep, max); } else if (bytes[0] == B_PAGE_UP) { value = MAX( value-bigStep, min); } else if (bytes[0] == B_PAGE_DOWN) { value = MIN( value+bigStep, max); } else if (bytes[0] == B_HOME) { value = min; } else if (bytes[0] == B_END) { value = max; } bar->SetValue( value); break; } default: BTextView::KeyDown( bytes, numBytes); break; } } else inherited::KeyDown( bytes, numBytes); }
bool DataModelListCtrl::CanEditLabel() { return (m_column_clicked != wxNOT_FOUND) && IsEditable(); }
bool wxWebFrame::ExecuteEditCommand(const wxString& command, const wxString& parameter) { if (m_impl->frame && IsEditable()) return m_impl->frame->editor()->command(command).execute(parameter); }
bool wxTextCtrl::CanCut() const { return CanCopy() && IsEditable(); }
void BTextWidget::StartEdit(BRect bounds, BPoseView *view, BPose *pose) { if (!IsEditable()) return; // don't allow editing of the trash directory name if (pose->TargetModel()->IsTrash()) return; // don't allow editing of the "Disks" icon name if (pose->TargetModel()->IsRoot()) return; BEntry entry(pose->TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK && !ConfirmChangeIfWellKnownDirectory(&entry, "rename")) return; // get bounds with full text length BRect rect(bounds); BRect textRect(bounds); rect.OffsetBy(-2, -1); rect.right += 1; BFont font; view->GetFont(&font); BTextView *textView = new BTextView(rect, "WidgetTextView", textRect, &font, 0, B_FOLLOW_ALL, B_WILL_DRAW); textView->SetWordWrap(false); DisallowMetaKeys(textView); fText->SetUpEditing(textView); textView->AddFilter(new BMessageFilter(B_KEY_DOWN, TextViewFilter)); rect.right = rect.left + textView->LineWidth() + 3; // center new width, if necessary if (view->ViewMode() == kIconMode || view->ViewMode() == kListMode && fAlignment == B_ALIGN_CENTER) { rect.OffsetBy(bounds.Width() / 2 - rect.Width() / 2, 0); } rect.bottom = rect.top + textView->LineHeight() + 1; textRect = rect.OffsetToCopy(2, 1); textRect.right -= 3; textRect.bottom--; textView->SetTextRect(textRect); textRect = view->Bounds(); bool hitBorder = false; if (rect.left < 1) rect.left = 1, hitBorder = true; if (rect.right > textRect.right) rect.right = textRect.right - 2, hitBorder = true; textView->MoveTo(rect.LeftTop()); textView->ResizeTo(rect.Width(), rect.Height()); BScrollView *scrollView = new BScrollView("BorderView", textView, 0, 0, false, false, B_PLAIN_BORDER); view->AddChild(scrollView); // configure text view switch (view->ViewMode()) { case kIconMode: textView->SetAlignment(B_ALIGN_CENTER); break; case kMiniIconMode: textView->SetAlignment(B_ALIGN_LEFT); break; case kListMode: textView->SetAlignment(fAlignment); break; } textView->MakeResizable(true, hitBorder ? NULL : scrollView); view->SetActivePose(pose); // tell view about pose SetActive(true); // for widget textView->SelectAll(); textView->MakeFocus(); // make this text widget invisible while we edit it SetVisible(false); ASSERT(view->Window()); // how can I not have a Window here??? if (view->Window()) // force immediate redraw so TextView appears instantly view->Window()->UpdateIfNeeded(); }
void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) { event.Enable(HasSelection() && IsEditable()) ; }
void wxTextCtrl::OnChar(wxKeyEvent& event) { int key = event.GetKeyCode() ; bool eat_key = false ; long from, to; if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) && !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END ) { // eat it return ; } // Check if we have reached the max # of chars (if it is set), but still // allow navigation and deletion GetSelection( &from, &to ); if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB | WXK_CATEGORY_CUT) && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) && from == to ) { // eat it, we don't want to add more than allowed # of characters // TODO: generate EVT_TEXT_MAXLEN() return; } // assume that any key not processed yet is going to modify the control m_dirty = true; switch ( key ) { case WXK_RETURN: if (m_windowStyle & wxTE_PROCESS_ENTER) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject( this ); event.SetString( GetValue() ); if ( HandleWindowEvent(event) ) return; } if ( !(m_windowStyle & wxTE_MULTILINE) ) { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); if ( tlw && tlw->GetDefaultItem() ) { wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); if ( def && def->IsEnabled() ) { wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); event.SetEventObject(def); def->Command(event); return ; } } // this will make wxWidgets eat the ENTER key so that // we actually prevent line wrapping in a single line text control eat_key = true; } break; case WXK_TAB: if ( !(m_windowStyle & wxTE_PROCESS_TAB)) { int flags = 0; if (!event.ShiftDown()) flags |= wxNavigationKeyEvent::IsForward ; if (event.ControlDown()) flags |= wxNavigationKeyEvent::WinChange ; Navigate(flags); return; } else { // This is necessary (don't know why); // otherwise the tab will not be inserted. WriteText(wxT("\t")); eat_key = true; } break; default: break; } if (!eat_key) { // perform keystroke handling event.Skip(true) ; } // osx_cocoa sends its event upon insertText #if wxOSX_USE_CARBON if ( ( key >= 0x20 && key < WXK_START ) || ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || key == WXK_RETURN || key == WXK_DELETE || key == WXK_BACK) { wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); event1.SetEventObject( this ); wxPostEvent( GetEventHandler(), event1 ); } #endif }
bool wxComboBox::CanPaste() const { // TODO: check for text on the clipboard return IsEditable() ; }
void ComboBox::FocusGain() { if (IsEditable()) { edit_text_box_->SetIsFocused(true); } }