void wxSpinCtrlGTKBase::OnChar( wxKeyEvent &event ) { wxCHECK_RET( m_widget != NULL, wxT("invalid spin ctrl") ); if (event.GetKeyCode() == WXK_RETURN) { wxWindow *top_frame = wxGetTopLevelParent(m_parent); if ( GTK_IS_WINDOW(top_frame->m_widget) ) { GtkWindow *window = GTK_WINDOW(top_frame->m_widget); if ( window ) { GtkWidget* widgetDef = gtk_window_get_default_widget(window); if ( widgetDef ) { gtk_widget_activate(widgetDef); return; } } } } if ((event.GetKeyCode() == WXK_RETURN) && (m_windowStyle & wxTE_PROCESS_ENTER)) { wxCommandEvent evt( wxEVT_COMMAND_TEXT_ENTER, m_windowId ); evt.SetEventObject(this); GtkSpinButton *gsb = GTK_SPIN_BUTTON(m_widget); wxString val = wxGTK_CONV_BACK( gtk_entry_get_text( &gsb->entry ) ); evt.SetString( val ); if (HandleWindowEvent(evt)) return; } event.Skip(); }
void TimeTextCtrl::OnKeyDown(wxKeyEvent &event) { event.Skip(false); int keyCode = event.GetKeyCode(); int digit = mFocusedDigit; if (mFocusedDigit < 0) mFocusedDigit = 0; if (mFocusedDigit >= (int)mDigits.GetCount()) mFocusedDigit = mDigits.GetCount()-1; // Convert numeric keypad entries. if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) keyCode -= WXK_NUMPAD0 - '0'; if (keyCode >= '0' && keyCode <= '9') { mValueString[mDigits[mFocusedDigit].pos] = wxChar(keyCode); ControlsToValue(); ValueToControls(); mFocusedDigit = (mFocusedDigit+1)%(mDigits.GetCount()); Updated(); } else if (keyCode == WXK_BACK) { // Moves left, replaces that char with '0', stays there... mFocusedDigit--; mFocusedDigit += mDigits.GetCount(); mFocusedDigit %= mDigits.GetCount(); mValueString[mDigits[mFocusedDigit].pos] = '0'; ControlsToValue(); ValueToControls(); Updated(); } else if (keyCode == WXK_LEFT) { mFocusedDigit--; mFocusedDigit += mDigits.GetCount(); mFocusedDigit %= mDigits.GetCount(); Refresh(); } else if (keyCode == WXK_RIGHT) { mFocusedDigit++; mFocusedDigit %= mDigits.GetCount(); Refresh(); } else if (keyCode == WXK_HOME) { mFocusedDigit = 0; Refresh(); } else if (keyCode == WXK_END) { mFocusedDigit = mDigits.GetCount() - 1; Refresh(); } else if (keyCode == WXK_UP) { Increase(1); Updated(); } else if (keyCode == WXK_DOWN) { Decrease(1); Updated(); } else if (keyCode == WXK_TAB) { wxWindow *parent = GetParent(); wxNavigationKeyEvent nevent; nevent.SetWindowChange(event.ControlDown()); nevent.SetDirection(!event.ShiftDown()); nevent.SetEventObject(parent); nevent.SetCurrentFocus(parent); GetParent()->ProcessEvent(nevent); } else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER) { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); wxWindow *def = tlw->GetDefaultItem(); if (def && def->IsEnabled()) { wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId()); GetParent()->ProcessEvent(cevent); } } else { event.Skip(); return; } if (digit != mFocusedDigit) { SetFieldFocus(mFocusedDigit); } event.Skip(false); }
void LWSlider::OnKeyEvent(wxKeyEvent & event) { if (mEnabled) { switch( event.GetKeyCode() ) { case WXK_RIGHT: case WXK_UP: Increase( mScrollLine ); SendUpdate( mCurrentValue ); break; case WXK_LEFT: case WXK_DOWN: Decrease( mScrollLine ); SendUpdate( mCurrentValue ); break; case WXK_PAGEUP: #if !wxCHECK_VERSION(2,7,0) case WXK_PRIOR: #endif Increase( mScrollPage ); SendUpdate( mCurrentValue ); break; case WXK_PAGEDOWN: #if !wxCHECK_VERSION(2,7,0) case WXK_NEXT: #endif Decrease( mScrollPage ); SendUpdate( mCurrentValue ); break; case WXK_HOME: SendUpdate( mMinValue ); break; case WXK_END: SendUpdate( mMaxValue ); break; case WXK_TAB: { wxNavigationKeyEvent nevent; nevent.SetWindowChange( event.ControlDown() ); nevent.SetDirection( !event.ShiftDown() ); nevent.SetEventObject( mParent ); nevent.SetCurrentFocus( mParent ); mParent->GetParent()->ProcessEvent( nevent ); } break; case WXK_RETURN: case WXK_NUMPAD_ENTER: { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(mParent), wxTopLevelWindow); wxWindow *def = tlw->GetDefaultItem(); if (def && def->IsEnabled()) { wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId()); mParent->ProcessEvent(cevent); } } default: // Allow it to propagate event.Skip(); break; } } event.Skip(); }
void wxSplitterWindow::OnSize(wxSizeEvent& event) { // only process this message if we're not iconized - otherwise iconizing // and restoring a window containing the splitter has a funny side effect // of changing the splitter position! wxWindow *parent = wxGetTopLevelParent(this); bool iconized; wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow); if ( winTop ) { iconized = winTop->IsIconized(); } else { wxFAIL_MSG(wxT("should have a top level parent!")); iconized = false; } if ( iconized ) { m_lastSize = wxSize(0,0); event.Skip(); return; } const wxSize curSize = event.GetSize(); // Update the sash position if needed. // // Notice that we shouldn't do this if the sash position requested by user // couldn't be set yet as it would never be taken into account at all if we // modified it before this happens. if ( m_windowTwo && m_requestedSashPosition == INT_MAX ) { int size = m_splitMode == wxSPLIT_VERTICAL ? curSize.x : curSize.y; int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y; // Don't do anything if the size didn't really change. if ( size != old_size ) { int newPosition = -1; // Apply gravity if we use it. int delta = (int) ( (size - old_size)*m_sashGravity ); if ( delta != 0 ) { newPosition = m_sashPosition + delta; if( newPosition < m_minimumPaneSize ) newPosition = m_minimumPaneSize; } // Also check if the second window became too small. newPosition = AdjustSashPosition(newPosition == -1 ? m_sashPosition : newPosition); if ( newPosition != m_sashPosition ) SetSashPositionAndNotify(newPosition); } } m_lastSize = curSize; SizeWindows(); }
bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , wxChar uniChar ) { if ( !focus ) return false ; wxKeyEvent event(wxEVT_CHAR) ; MacCreateKeyEvent( event, focus , keymessage , modifiers , when , uniChar ) ; bool handled = false ; #if wxOSX_USE_CARBON long keyval = event.m_keyCode ; { wxKeyEvent eventCharHook(wxEVT_CHAR_HOOK, event); handled = focus->HandleWindowEvent( eventCharHook ); if ( handled && eventCharHook.IsNextEventAllowed() ) handled = false ; } if ( !handled ) { handled = focus->HandleWindowEvent( event ) ; } if ( !handled && (keyval == WXK_TAB) ) { wxWindow* iter = focus->GetParent() ; while ( iter && !handled ) { if ( iter->HasFlag( wxTAB_TRAVERSAL ) ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( focus ); new_event.SetDirection( !event.ShiftDown() ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( event.ControlDown() ); new_event.SetCurrentFocus( focus ); handled = focus->GetParent()->HandleWindowEvent( new_event ); if ( handled && new_event.GetSkipped() ) handled = false ; } iter = iter->GetParent() ; } } // backdoor handler for default return and command escape if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->AcceptsFocus() ) ) { // if window is not having a focus still testing for default enter or cancel // TODO: add the UMA version for ActiveNonFloatingWindow #ifndef __LP64__ wxWindow* focus = wxNonOwnedWindow::GetFromWXWindow( (WXWindow) FrontWindow() ) ; if ( focus ) { if ( keyval == WXK_RETURN || keyval == WXK_NUMPAD_ENTER ) { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(focus), wxTopLevelWindow); if ( tlw && tlw->GetDefaultItem() ) { wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); if ( def && def->IsEnabled() ) { wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); event.SetEventObject(def); def->Command(event); return true ; } } } else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) { // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) wxCommandEvent new_event(wxEVT_BUTTON,wxID_CANCEL); new_event.SetEventObject( focus ); handled = focus->HandleWindowEvent( new_event ); } } #endif } #endif return handled ; }
void Grid::OnKeyDown(wxKeyEvent &event) { switch (event.GetKeyCode()) { case WXK_LEFT: case WXK_RIGHT: { int rows = GetNumberRows(); int cols = GetNumberCols(); int crow = GetGridCursorRow(); int ccol = GetGridCursorCol(); if (event.GetKeyCode() == WXK_LEFT) { if (crow == 0 && ccol == 0) { // do nothing } else if (ccol == 0) { SetGridCursor(crow - 1, cols - 1); } else { SetGridCursor(crow, ccol - 1); } } else { if (crow == rows - 1 && ccol == cols - 1) { // do nothing } else if (ccol == cols - 1) { SetGridCursor(crow + 1, 0); } else { SetGridCursor(crow, ccol + 1); } } #if wxUSE_ACCESSIBILITY // Make sure the NEW cell is made available to the screen reader mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol()); #endif } break; case WXK_TAB: { int rows = GetNumberRows(); int cols = GetNumberCols(); int crow = GetGridCursorRow(); int ccol = GetGridCursorCol(); if (event.ControlDown()) { int flags = wxNavigationKeyEvent::FromTab | ( event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward ); Navigate(flags); return; } else if (event.ShiftDown()) { if (crow == 0 && ccol == 0) { Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward); return; } else if (ccol == 0) { SetGridCursor(crow - 1, cols - 1); } else { SetGridCursor(crow, ccol - 1); } } else { if (crow == rows - 1 && ccol == cols - 1) { Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward); return; } else if (ccol == cols - 1) { SetGridCursor(crow + 1, 0); } else { SetGridCursor(crow, ccol + 1); } } MakeCellVisible(GetGridCursorRow(), GetGridCursorCol()); #if wxUSE_ACCESSIBILITY // Make sure the NEW cell is made available to the screen reader mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol()); #endif } break; case WXK_RETURN: case WXK_NUMPAD_ENTER: { if (!IsCellEditControlShown()) { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); wxWindow *def = tlw->GetDefaultItem(); if (def && def->IsEnabled()) { wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId()); GetParent()->GetEventHandler()->ProcessEvent(cevent); } } else { wxGrid::OnKeyDown(event); // This looks strange, but what it does is selects the cell when // enter is pressed after editing. Without it, Jaws and Window-Eyes // do not speak the NEW cell contents (the one below the edited one). SetGridCursor(GetGridCursorRow(), GetGridCursorCol()); } break; } default: wxGrid::OnKeyDown(event); break; } }
void GameDialog::createDialog(wxWindow* parent, const wxString& title, const wxString& infoText) { Create(wxGetTopLevelParent(parent), wxID_ANY, title); createGui(title, infoText); bindObservers(); CentreOnParent(); }
wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption, long style, const wxPoint& WXUNUSED(pos)) { m_caption = caption; m_message = message; SetMessageDialogStyle(style); m_parent = wxGetTopLevelParent(parent); GtkMessageType type = GTK_MESSAGE_ERROR; GtkButtonsType buttons = GTK_BUTTONS_OK; if (style & wxYES_NO) { buttons = GTK_BUTTONS_YES_NO; } if (style & wxOK) { if (style & wxCANCEL) buttons = GTK_BUTTONS_OK_CANCEL; else buttons = GTK_BUTTONS_OK; } if (style & wxICON_EXCLAMATION) type = GTK_MESSAGE_WARNING; else if (style & wxICON_ERROR) type = GTK_MESSAGE_ERROR; else if (style & wxICON_INFORMATION) type = GTK_MESSAGE_INFO; else if (style & wxICON_QUESTION) type = GTK_MESSAGE_QUESTION; else { // GTK+ doesn't have a "typeless" msg box, so try to auto detect... type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO; } m_widget = gtk_message_dialog_new(m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL, GTK_DIALOG_MODAL, type, buttons, "%s", (const char*)wxGTK_CONV(m_message)); if (m_caption != wxMessageBoxCaptionStr) gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption)); if (style & wxYES_NO) { if (style & wxCANCEL) gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); if (style & wxNO_DEFAULT) gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO); else gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES); } if (m_parent) gtk_window_set_transient_for(GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget)); }
bool EffectNyquist::PromptUser() { if (!SetXlispPath()) { return false; } if (mInteractive) { NyquistInputDialog dlog(wxGetTopLevelParent(NULL), -1, _("Nyquist Prompt"), _("Enter Nyquist Command: "), mInputCmd); dlog.CentreOnParent(); int result = dlog.ShowModal(); if (result == wxID_CANCEL) { return false; } /*if (result == eDebugID) { mDebug = true; }*/ mDebug = (result == eDebugID); // remember exact input in mInputCmd which will appear in the next // NyquistInputDialog. Copy to mCmd for possible embedding in // "function main() begin ... end": mCmd = mInputCmd = dlog.GetCommand(); // Is this LISP or SAL? Both allow comments. After comments, LISP // must begin with "(". Technically, a LISP expression could be a // symbol or number or string, etc., but these are not really // useful expressions. If the input begins with a symbol, number, // or string, etc., it is more likely an erroneous attempt to type // a SAL expression (which should probably begin with "return"), // so we will treat it as SAL. // this is a state machine to scan past LISP comments and white // space to find the first real character of LISP or SAL. Note // that #| ... |# style comments are not valid in SAL, so we do // not skip these. Instead, "#|" indicates LISP if found. // unsigned int i = 0; bool inComment = false; // handle "; ... \n" comments while (i < mCmd.Len()) { if (inComment) { inComment = (mCmd[i] != wxT('\n')); } else if (mCmd[i] == wxT(';')) { inComment = true; } else if (!wxIsspace(mCmd[i])) { break; // found the first non-comment, non-space character } i++; } // invariant: i == mCmd.Len() | // mCmd[i] is first non-comment, non-space character mIsSal = false; if (mCmd.Len() > i && mCmd[i] != wxT('(') && (mCmd[i] != wxT('#') || mCmd.Len() <= i + 1 || mCmd[i + 1] != wxT('|'))) { mIsSal = true; wxString cmdUp = mCmd.Upper(); int returnLoc = cmdUp.Find(wxT("RETURN")); if (returnLoc == wxNOT_FOUND) { wxMessageBox(_("Your code looks like SAL syntax, but there is no return statement. Either use a return statement such as\n\treturn s * 0.1\nfor SAL, or begin with an open parenthesis such as\n\t(mult s 0.1)\n for LISP."), _("Error in Nyquist code"), wxOK | wxCENTRE); return false; } } return true; } if (!mExternal) { if (mFileName.GetModificationTime().IsLaterThan(mFileModified)) { ParseFile(); mFileModified = mFileName.GetModificationTime(); } } if (mControls.GetCount() == 0) { return true; } for (unsigned int i = 0; i < mControls.GetCount(); i++) { NyqControl *ctrl = &mControls[i]; if (ctrl->type == NYQ_CTRL_STRING) { continue; } if (ctrl->val == UNINITIALIZED_CONTROL) { ctrl->val = GetCtrlValue(ctrl->valStr); } if (ctrl->type == NYQ_CTRL_CHOICE) { continue; } ctrl->low = GetCtrlValue(ctrl->lowStr); ctrl->high = GetCtrlValue(ctrl->highStr); if (ctrl->high < ctrl->low) { ctrl->high = ctrl->low + 1; } if (ctrl->val < ctrl->low) { ctrl->val = ctrl->low; } if (ctrl->val > ctrl->high) { ctrl->val = ctrl->high; } ctrl->ticks = 1000; if (ctrl->type == NYQ_CTRL_INT && (ctrl->high - ctrl->low < ctrl->ticks)) { ctrl->ticks = (int)(ctrl->high - ctrl->low); } } NyquistDialog dlog(mParent, -1, mName, mInfo, &mControls); dlog.CentreOnParent(); int result = dlog.ShowModal(); if (result == wxID_CANCEL) { return false; } /* if (result == eDebugID) { mDebug = true; } */ mDebug = (result == eDebugID); return true; }
bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) { if ( !focus ) return false ; wxKeyEvent event(wxEVT_CHAR) ; MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ; long keyval = event.m_keyCode ; bool handled = false ; wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ; if (tlw) { event.SetEventType( wxEVT_CHAR_HOOK ); handled = tlw->GetEventHandler()->ProcessEvent( event ); if ( handled && event.GetSkipped() ) handled = false ; } if ( !handled ) { event.SetEventType( wxEVT_CHAR ); event.Skip( false ) ; handled = focus->GetEventHandler()->ProcessEvent( event ) ; } if ( !handled && (keyval == WXK_TAB) ) { wxWindow* iter = focus->GetParent() ; while ( iter && !handled ) { if ( iter->HasFlag( wxTAB_TRAVERSAL ) ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( focus ); new_event.SetDirection( !event.ShiftDown() ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( event.ControlDown() ); new_event.SetCurrentFocus( focus ); handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event ); if ( handled && new_event.GetSkipped() ) handled = false ; } iter = iter->GetParent() ; } } // backdoor handler for default return and command escape if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) ) { // if window is not having a focus still testing for default enter or cancel // TODO: add the UMA version for ActiveNonFloatingWindow wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; if ( focus ) { if ( keyval == WXK_RETURN || keyval == WXK_NUMPAD_ENTER ) { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(focus), 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 true ; } } } else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) { // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); new_event.SetEventObject( focus ); handled = focus->GetEventHandler()->ProcessEvent( new_event ); } } } return handled ; }
void wxListBox::OnChar(wxKeyEvent& event) { if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) { 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 ; } } event.Skip() ; } /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) ) { // FIXME: look in ancestors, not just parent. wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ; if (win) { wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); new_event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( new_event ); } } else if ( event.GetKeyCode() == WXK_TAB ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( this ); new_event.SetDirection( !event.ShiftDown() ); /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ new_event.SetWindowChange( event.ControlDown() ); new_event.SetCurrentFocus( this ); if ( !GetEventHandler()->ProcessEvent( new_event ) ) event.Skip() ; } else if ( event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_UP ) { // perform the default key handling first wxControl::OnKeyDown( event ) ; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); event.SetEventObject( this ); wxArrayInt aSelections; int n, count = GetSelections(aSelections); if ( count > 0 ) { n = aSelections[0]; if ( HasClientObjectData() ) event.SetClientObject( GetClientObject(n) ); else if ( HasClientUntypedData() ) event.SetClientData( GetClientData(n) ); event.SetString(GetString(n)); } else { n = -1; } event.SetInt(n); GetEventHandler()->ProcessEvent(event); } else { if ( event.GetTimestamp() > m_lastTypeIn + 60 ) { m_typeIn = wxEmptyString ; } m_lastTypeIn = event.GetTimestamp() ; m_typeIn += (char) event.GetKeyCode() ; int line = FindString(wxT("*")+m_typeIn+wxT("*")) ; if ( line >= 0 ) { if ( GetSelection() != line ) { SetSelection(line) ; wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); event.SetEventObject( this ); if ( HasClientObjectData() ) event.SetClientObject( GetClientObject( line ) ); else if ( HasClientUntypedData() ) event.SetClientData( GetClientData(line) ); event.SetString(GetString(line)); event.SetInt(line); GetEventHandler()->ProcessEvent(event); } } } }
void wxInfoBarGeneric::UpdateParent() { wxWindow * const parent = wxGetTopLevelParent(GetParent()); parent->Layout(); }
static gboolean gtk_listbox_key_press_callback( GtkWidget *WXUNUSED(widget), GdkEventKey *gdk_event, wxListBox *listbox ) { if ((gdk_event->keyval == GDK_Return) || (gdk_event->keyval == GDK_ISO_Enter) || (gdk_event->keyval == GDK_KP_Enter)) { int index = -1; if (!listbox->HasMultipleSelection()) index = listbox->GetSelection(); else { wxArrayInt sels; if (listbox->GetSelections( sels ) < 1) return FALSE; index = sels[0]; } if (index != wxNOT_FOUND) { wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, listbox->GetId() ); event.SetEventObject( listbox ); GtkTreeEntry* entry = listbox->GTKGetEntry( index ); // indicate that this is a selection event.SetExtraLong( 1 ); event.SetInt( index ); event.SetString(wxConvUTF8.cMB2WX(gtk_tree_entry_get_label(entry))); if ( listbox->HasClientObjectData() ) event.SetClientObject( (wxClientData*) gtk_tree_entry_get_userdata(entry) ); else if ( listbox->HasClientUntypedData() ) event.SetClientData( gtk_tree_entry_get_userdata(entry) ); /* bool ret = */ listbox->HandleWindowEvent( event ); g_object_unref (entry); // wxMac and wxMSW always invoke default action // if (!ret) { // DClick not handled -> invoke default action wxWindow *tlw = wxGetTopLevelParent( listbox ); if (tlw) { GtkWindow *gtk_window = GTK_WINDOW( tlw->GetHandle() ); if (gtk_window) gtk_window_activate_default( gtk_window ); } } // Always intercept, otherwise we'd get another dclick // event from row_activated return TRUE; } } return FALSE; }
void wxRadioButton::SetValue(bool value) { ::SendMessage(GetHwnd(), BM_SETCHECK, value ? BST_CHECKED : BST_UNCHECKED, 0); m_isChecked = value; if ( !value ) return; // if we set the value of one radio button we also must clear all the other // buttons in the same group: Windows doesn't do it automatically // // moreover, if another radiobutton in the group currently has the focus, // we have to set it to this radiobutton, else the old radiobutton will be // reselected automatically, if a parent window loses the focus and regains // it. wxWindow * const focus = FindFocus(); wxTopLevelWindow * const tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); wxCHECK_RET( tlw, _T("radio button outside of TLW?") ); wxWindow * const focusInTLW = tlw->GetLastFocus(); const wxWindowList& siblings = GetParent()->GetChildren(); wxWindowList::compatibility_iterator nodeThis = siblings.Find(this); wxCHECK_RET( nodeThis, _T("radio button not a child of its parent?") ); // this will be set to true in the code below if the focus is in our TLW // and belongs to one of the other buttons in the same group bool shouldSetFocus = false; // this will be set to true if the focus is outside of our TLW currently // but the remembered focus of this TLW is one of the other buttons in the // same group bool shouldSetTLWFocus = false; // if it's not the first item of the group ... if ( !HasFlag(wxRB_GROUP) ) { // ... turn off all radio buttons before it for ( wxWindowList::compatibility_iterator nodeBefore = nodeThis->GetPrevious(); nodeBefore; nodeBefore = nodeBefore->GetPrevious() ) { wxRadioButton *btn = wxDynamicCast(nodeBefore->GetData(), wxRadioButton); if ( !btn ) { // don't stop on non radio buttons, we could have intermixed // buttons and e.g. static labels continue; } if ( btn->HasFlag(wxRB_SINGLE) ) { // A wxRB_SINGLE button isn't part of this group break; } if ( btn == focus ) shouldSetFocus = true; else if ( btn == focusInTLW ) shouldSetTLWFocus = true; btn->SetValue(false); if ( btn->HasFlag(wxRB_GROUP) ) { // even if there are other radio buttons before this one, // they're not in the same group with us break; } } } // ... and also turn off all buttons after this one for ( wxWindowList::compatibility_iterator nodeAfter = nodeThis->GetNext(); nodeAfter; nodeAfter = nodeAfter->GetNext() ) { wxRadioButton *btn = wxDynamicCast(nodeAfter->GetData(), wxRadioButton); if ( !btn ) continue; if ( btn->HasFlag(wxRB_GROUP | wxRB_SINGLE) ) { // no more buttons or the first button of the next group break; } if ( btn == focus ) shouldSetFocus = true; else if ( btn == focusInTLW ) shouldSetTLWFocus = true; btn->SetValue(false); } if ( shouldSetFocus ) SetFocus(); else if ( shouldSetTLWFocus ) tlw->SetLastFocus(this); }
void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) { if (IsShown()) return; onShow(); // find selection selected_item = selection(); // width size_t count = itemCount(); if (item_size.width == 100) { // not initialized wxClientDC dc(this); dc.SetFont(*wxNORMAL_FONT); for (size_t i = 0 ; i < count ; ++i) { int text_width; dc.GetTextExtent(capitalize(itemText(i)), &text_width, 0); item_size.width = max(item_size.width, text_width + icon_size.width + 14); // 14 = room for popup arrow + padding } } // height int line_count = 0; for (size_t i = 0 ; i < count ; ++i) if (lineBelow(i)) line_count += 1; // size RealSize border_size(2,2); // GetClientSize() - GetSize(), assume 1px borders RealSize size( item_size.width + marginW * 2, item_size.height * count + marginH * 2 + line_count ); // placement int parent_height = 0; if (!in_place && viewer) { // Position the drop down list below the editor control (based on the style) Rotation rot = viewer->viewer.getRotation(); Rotater rr(rot, viewer->getRotation()); RealRect r = rot.trRectToBB(rect ? *rect : rot.getInternalRect()); if (viewer->viewer.nativeLook()) { pos = RealPoint(r.x - 3, r.y - 3); size.width = max(size.width, r.width + 6); parent_height = (int)r.height + 6; } else { pos = RealPoint(r.x - 1, r.y - 1); parent_height = (int)r.height; } } else if (parent_menu) { parent_height = -(int)item_size.height - 1; } pos = GetParent()->ClientToScreen(pos); // virtual size = item size RealSize virtual_size = size; SetVirtualSize(virtual_size); item_size.width = virtual_size.width - marginW * 2; // is there enough room for all items, or do we need a scrollbar? int room_below = wxGetDisplaySize().y - border_size.height - pos.y - parent_height - 50; int max_height = max(300, room_below); if (size.height > max_height) { size.height = max_height; size.width += wxSystemSettings::GetMetric(wxSYS_VSCROLL_ARROW_X); // width of scrollbar SetScrollbar(wxVERTICAL, 0, size.height, virtual_size.height, false); } else { SetScrollbar(wxVERTICAL,0,0,0,false); } // move & resize SetSize(add_diagonal(size, border_size)); Position(pos, wxSize(0, parent_height)); // visible item visible_start = 0; ensureSelectedItemVisible(); // set event handler if (hider) { assert(hider2); wxGetTopLevelParent(GetParent())->PushEventHandler(hider); GetParent() ->PushEventHandler(hider2); } // show if (selected_item == NO_SELECTION && itemCount() > 0) selected_item = 0; // select first item by default mouse_down = false; close_on_mouse_out = false; wxPopupWindow::Show(); if (isRoot() && GetParent()->HasCapture()) { // release capture on parent GetParent()->ReleaseMouse(); } // fix drop down arrow redrawArrowOnParent(); }
bool wxTopLevelWindowGTK::Create( wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& sizeOrig, long style, const wxString &name ) { // always create a frame of some reasonable, even if arbitrary, size (at // least for MSW compatibility) wxSize size = sizeOrig; size.x = WidthDefault(size.x); size.y = HeightDefault(size.y); wxTopLevelWindows.Append( this ); if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") ); return false; } m_title = title; // NB: m_widget may be !=NULL if it was created by derived class' Create, // e.g. in wxTaskBarIconAreaGTK if (m_widget == NULL) { #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 // we must create HildonWindow and not a normal GtkWindow as the latter // doesn't look correctly in Maemo environment and it must also be // registered with the main program object m_widget = hildon_window_new(); hildon_program_add_window(wxTheApp->GetHildonProgram(), HILDON_WINDOW(m_widget)); #else // !wxUSE_LIBHILDON || !wxUSE_LIBHILDON2 m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) { // Tell WM that this is a dialog window and make it center // on parent by default (this is what GtkDialog ctor does): gtk_window_set_type_hint(GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_position(GTK_WINDOW(m_widget), GTK_WIN_POS_CENTER_ON_PARENT); } else { if (style & wxFRAME_TOOL_WINDOW) { gtk_window_set_type_hint(GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_UTILITY); // On some WMs, like KDE, a TOOL_WINDOW will still show // on the taskbar, but on Gnome a TOOL_WINDOW will not. // For consistency between WMs and with Windows, we // should set the NO_TASKBAR flag which will apply // the set_skip_taskbar_hint if it is available, // ensuring no taskbar entry will appear. style |= wxFRAME_NO_TASKBAR; } } #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2 g_object_ref(m_widget); } wxWindow *topParent = wxGetTopLevelParent(m_parent); if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) && (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) || (style & wxFRAME_FLOAT_ON_PARENT))) { gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(topParent->m_widget) ); } if (style & wxFRAME_NO_TASKBAR) { gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), TRUE); } if (style & wxSTAY_ON_TOP) { gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE); } if (style & wxMAXIMIZE) gtk_window_maximize(GTK_WINDOW(m_widget)); #if 0 if (!name.empty()) gtk_window_set_role( GTK_WINDOW(m_widget), wxGTK_CONV( name ) ); #endif gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); gtk_widget_set_can_focus(m_widget, false); g_signal_connect (m_widget, "delete_event", G_CALLBACK (gtk_frame_delete_callback), this); // m_mainWidget is a GtkVBox, holding the bars and client area (m_wxwindow) m_mainWidget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_show( m_mainWidget ); gtk_widget_set_can_focus(m_mainWidget, false); gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); // m_wxwindow is the client area m_wxwindow = wxPizza::New(); gtk_widget_show( m_wxwindow ); gtk_box_pack_start(GTK_BOX(m_mainWidget), m_wxwindow, true, true, 0); // we donm't allow the frame to get the focus as otherwise // the frame will grab it at arbitrary focus changes gtk_widget_set_can_focus(m_wxwindow, false); if (m_parent) m_parent->AddChild( this ); g_signal_connect(m_wxwindow, "size_allocate", G_CALLBACK(size_allocate), this); PostCreation(); #ifndef __WXGTK3__ if ((m_x != -1) || (m_y != -1)) gtk_widget_set_uposition( m_widget, m_x, m_y ); #endif // for some reported size corrections g_signal_connect (m_widget, "map_event", G_CALLBACK (gtk_frame_map_callback), this); // for iconized state g_signal_connect (m_widget, "window_state_event", G_CALLBACK (gtk_frame_window_state_callback), this); // for wxMoveEvent g_signal_connect (m_widget, "configure_event", G_CALLBACK (gtk_frame_configure_callback), this); // activation g_signal_connect_after (m_widget, "focus_in_event", G_CALLBACK (gtk_frame_focus_in_callback), this); g_signal_connect_after (m_widget, "focus_out_event", G_CALLBACK (gtk_frame_focus_out_callback), this); // GTK processes key events at the top level first, which handles for // menu accelerators and shortcuts before passing the event on to the // focus child window to begin propagation. We want to propagate // first, so we connect gtk_window_propagate_key_event to // key_press_event. g_signal_connect (m_widget, "key_press_event", G_CALLBACK (gtk_window_propagate_key_event), NULL); #ifdef GDK_WINDOWING_X11 #ifdef __WXGTK3__ if (GDK_IS_X11_SCREEN(gtk_window_get_screen(GTK_WINDOW(m_widget)))) #endif { gtk_widget_add_events(m_widget, GDK_PROPERTY_CHANGE_MASK); g_signal_connect(m_widget, "property_notify_event", G_CALLBACK(property_notify_event), this); } #endif // GDK_WINDOWING_X11 // translate wx decorations styles into Motif WM hints (they are recognized // by other WMs as well) // always enable moving the window as we have no separate flag for enabling // it m_gdkFunc = GDK_FUNC_MOVE; if ( style & wxCLOSE_BOX ) m_gdkFunc |= GDK_FUNC_CLOSE; if ( style & wxMINIMIZE_BOX ) m_gdkFunc |= GDK_FUNC_MINIMIZE; if ( style & wxMAXIMIZE_BOX ) m_gdkFunc |= GDK_FUNC_MAXIMIZE; if ( (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER) ) { m_gdkDecor = 0; } else // have border { m_gdkDecor = GDK_DECOR_BORDER; if ( style & wxCAPTION ) m_gdkDecor |= GDK_DECOR_TITLE; if ( style & wxSYSTEM_MENU ) m_gdkDecor |= GDK_DECOR_MENU; if ( style & wxMINIMIZE_BOX ) m_gdkDecor |= GDK_DECOR_MINIMIZE; if ( style & wxMAXIMIZE_BOX ) m_gdkDecor |= GDK_DECOR_MAXIMIZE; if ( style & wxRESIZE_BORDER ) { m_gdkFunc |= GDK_FUNC_RESIZE; m_gdkDecor |= GDK_DECOR_RESIZEH; } } // GTK sometimes chooses very small size if max size hint is not explicitly set DoSetSizeHints(m_minWidth, m_minHeight, m_maxWidth, m_maxHeight, m_incWidth, m_incHeight); m_decorSize = GetCachedDecorSize(); int w, h; GTKDoGetSize(&w, &h); gtk_window_set_default_size(GTK_WINDOW(m_widget), w, h); return true; }
bool wxTopLevelWindowGTK::Create( wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& sizeOrig, long style, const wxString &name ) { wxSize size(sizeOrig); if (!size.IsFullySpecified()) size.SetDefaults(GetDefaultSize()); wxTopLevelWindows.Append( this ); if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") ); return false; } m_title = title; // NB: m_widget may be !=NULL if it was created by derived class' Create, // e.g. in wxTaskBarIconAreaGTK if (m_widget == NULL) { m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) { // Tell WM that this is a dialog window and make it center // on parent by default (this is what GtkDialog ctor does): gtk_window_set_type_hint(GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_window_set_position(GTK_WINDOW(m_widget), GTK_WIN_POS_CENTER_ON_PARENT); } else { if (style & wxFRAME_TOOL_WINDOW) { gtk_window_set_type_hint(GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_UTILITY); // On some WMs, like KDE, a TOOL_WINDOW will still show // on the taskbar, but on Gnome a TOOL_WINDOW will not. // For consistency between WMs and with Windows, we // should set the NO_TASKBAR flag which will apply // the set_skip_taskbar_hint if it is available, // ensuring no taskbar entry will appear. style |= wxFRAME_NO_TASKBAR; } } g_object_ref(m_widget); } wxWindow *topParent = wxGetTopLevelParent(m_parent); if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) && (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) || (style & wxFRAME_FLOAT_ON_PARENT))) { gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(topParent->m_widget) ); } if (style & wxFRAME_NO_TASKBAR) { gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), TRUE); } if (style & wxSTAY_ON_TOP) { gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE); } if (style & wxMAXIMIZE) gtk_window_maximize(GTK_WINDOW(m_widget)); #if 0 if (!name.empty()) gtk_window_set_role( GTK_WINDOW(m_widget), wxGTK_CONV( name ) ); #endif gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); gtk_widget_set_can_focus(m_widget, false); g_signal_connect (m_widget, "delete_event", G_CALLBACK (gtk_frame_delete_callback), this); // m_mainWidget is a GtkVBox, holding the bars and client area (m_wxwindow) m_mainWidget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_show( m_mainWidget ); gtk_widget_set_can_focus(m_mainWidget, false); gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); // m_wxwindow is the client area m_wxwindow = wxPizza::New(); gtk_widget_show( m_wxwindow ); gtk_box_pack_start(GTK_BOX(m_mainWidget), m_wxwindow, true, true, 0); // we donm't allow the frame to get the focus as otherwise // the frame will grab it at arbitrary focus changes gtk_widget_set_can_focus(m_wxwindow, false); if (m_parent) m_parent->AddChild( this ); g_signal_connect(m_wxwindow, "size_allocate", G_CALLBACK(size_allocate), this); PostCreation(); #ifndef __WXGTK3__ if (pos != wxDefaultPosition) gtk_widget_set_uposition( m_widget, m_x, m_y ); #endif // for some reported size corrections g_signal_connect (m_widget, "map_event", G_CALLBACK (gtk_frame_map_callback), this); // for iconized state g_signal_connect (m_widget, "window_state_event", G_CALLBACK (gtk_frame_window_state_callback), this); // for wxMoveEvent g_signal_connect (m_widget, "configure_event", G_CALLBACK (gtk_frame_configure_callback), this); // activation g_signal_connect_after (m_widget, "focus_in_event", G_CALLBACK (gtk_frame_focus_in_callback), this); g_signal_connect_after (m_widget, "focus_out_event", G_CALLBACK (gtk_frame_focus_out_callback), this); // We need to customize the default GTK+ logic for key processing to make // it conforming to wxWidgets event processing order. g_signal_connect (m_widget, "key_press_event", G_CALLBACK (wxgtk_tlw_key_press_event), NULL); #ifdef GDK_WINDOWING_X11 #ifdef __WXGTK3__ if (GDK_IS_X11_SCREEN(gtk_window_get_screen(GTK_WINDOW(m_widget)))) #endif { gtk_widget_add_events(m_widget, GDK_PROPERTY_CHANGE_MASK); g_signal_connect(m_widget, "property_notify_event", G_CALLBACK(property_notify_event), this); } #endif // GDK_WINDOWING_X11 // translate wx decorations styles into Motif WM hints (they are recognized // by other WMs as well) // always enable moving the window as we have no separate flag for enabling // it m_gdkFunc = GDK_FUNC_MOVE; if ( style & wxCLOSE_BOX ) m_gdkFunc |= GDK_FUNC_CLOSE; if ( style & wxMINIMIZE_BOX ) m_gdkFunc |= GDK_FUNC_MINIMIZE; if ( style & wxMAXIMIZE_BOX ) m_gdkFunc |= GDK_FUNC_MAXIMIZE; if ( (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER) ) { m_gdkDecor = 0; gtk_window_set_decorated(GTK_WINDOW(m_widget), false); } else // have border { m_gdkDecor = GDK_DECOR_BORDER; if ( style & wxCAPTION ) m_gdkDecor |= GDK_DECOR_TITLE; #if defined(GDK_WINDOWING_WAYLAND) && GTK_CHECK_VERSION(3,10,0) else if ( GDK_IS_WAYLAND_DISPLAY(gtk_widget_get_display(m_widget)) && gtk_check_version(3,10,0) == NULL) { gtk_window_set_titlebar(GTK_WINDOW(m_widget), gtk_header_bar_new()); } #endif if ( style & wxSYSTEM_MENU ) m_gdkDecor |= GDK_DECOR_MENU; if ( style & wxMINIMIZE_BOX ) m_gdkDecor |= GDK_DECOR_MINIMIZE; if ( style & wxMAXIMIZE_BOX ) m_gdkDecor |= GDK_DECOR_MAXIMIZE; if ( style & wxRESIZE_BORDER ) { m_gdkFunc |= GDK_FUNC_RESIZE; m_gdkDecor |= GDK_DECOR_RESIZEH; } } m_decorSize = GetCachedDecorSize(); int w, h; GTKDoGetSize(&w, &h); if (style & wxRESIZE_BORDER) { gtk_window_set_default_size(GTK_WINDOW(m_widget), w, h); #ifndef __WXGTK3__ gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1); #endif } else { gtk_window_set_resizable(GTK_WINDOW(m_widget), false); // gtk_window_set_default_size() does not work for un-resizable windows, // unless you set the size hints, but that causes Ubuntu's WM to make // the window resizable even though GDK_FUNC_RESIZE is not set. gtk_widget_set_size_request(m_widget, w, h); } return true; }
void ScreenshotCommand::Capture(wxString filename, wxWindow *window, int x, int y, int width, int height, bool bg) { if (window) { if (window->IsTopLevel()) { window->Raise(); } else { wxGetTopLevelParent(window)->Raise(); } } Yield(); int screenW, screenH; wxDisplaySize(&screenW, &screenH); wxBitmap full(screenW, screenH); wxScreenDC screenDC; wxMemoryDC fullDC; // We grab the whole screen image since there seems to be a problem with // using non-zero source coordinates on OSX. (as of wx2.8.9) fullDC.SelectObject(full); fullDC.Blit(0, 0, screenW, screenH, &screenDC, 0, 0); fullDC.SelectObject(wxNullBitmap); wxRect r(x, y, width, height); // Ensure within bounds (x/y are negative on Windows when maximized) r.Intersect(wxRect(0, 0, screenW, screenH)); // Convert to screen coordinates if needed if (window && window->GetParent() && !window->IsTopLevel()) { r.SetPosition(window->GetParent()->ClientToScreen(r.GetPosition())); } // Extract the actual image wxBitmap part = full.GetSubBitmap(r); // Add a background if (bg && mBackground) { wxRect b = GetBackgroundRect(); wxBitmap back(width + b.width, height + b.height); fullDC.SelectObject(back); fullDC.SetBackground(wxBrush(mBackColor, wxSOLID)); fullDC.Clear(); fullDC.DrawBitmap(part, b.x, b.y); fullDC.SelectObject(wxNullBitmap); part = back; } // Save the final image wxImage image = part.ConvertToImage(); if (image.SaveFile(filename)) { mOutput->Status(_("Saved ") + filename); } else { mOutput->Error(_("Error trying to save file: ") + filename); } ::wxBell(); }
void wxGenericCollapsiblePane::OnStateChange(const wxSize& sz) { // minimal size has priority over the best size so set here our min size SetMinSize(sz); SetSize(sz); if (this->HasFlag(wxCP_NO_TLW_RESIZE)) { // the user asked to explicitely handle the resizing itself... return; } // // NB: the following block of code has been accurately designed to // as much flicker-free as possible; be careful when modifying it! // wxTopLevelWindow * top = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); if ( top ) { // NB: don't Layout() the 'top' window as its size has not been correctly // updated yet and we don't want to do an initial Layout() with the old // size immediately followed by a SetClientSize/Fit call for the new // size; that would provoke flickering! if (top->GetSizer()) #ifdef __WXGTK__ // FIXME: the SetSizeHints() call would be required also for GTK+ for // the expanded->collapsed transition. Unfortunately if we // enable this line, then the GTK+ top window won't always be // resized by the SetClientSize() call below! As a side effect // of this dirty fix, the minimal size for the pane window is // not set in GTK+ and the user can hide it shrinking the "top" // window... if (IsCollapsed()) #endif top->GetSizer()->SetSizeHints(top); // we shouldn't attempt to resize a maximized window, whatever happens if ( !top->IsMaximized() ) { if ( IsCollapsed() ) { // expanded -> collapsed transition if (top->GetSizer()) { // we have just set the size hints... wxSize sz = top->GetSizer()->CalcMin(); // use SetClientSize() and not SetSize() otherwise the size for // e.g. a wxFrame with a menubar wouldn't be correctly set top->SetClientSize(sz); } else top->Layout(); } else { // collapsed -> expanded transition // force our parent to "fit", i.e. expand so that it can honour // our minimal size top->Fit(); } } } }
void OnNextWindow(const CommandContext &context) { auto &project = context.project; auto isEnabled = project.IsEnabled(); wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus()); const auto & list = project.GetChildren(); auto iter = list.begin(), end = list.end(); // If the project window has the current focus, start the search with the // first child if (w == &project) { } // Otherwise start the search with the current window's next sibling else { // Find the window in this projects children. If the window with the // focus isn't a child of this project (like when a dialog is created // without specifying a parent), then we'll get back NULL here. while (iter != end && *iter != w) ++iter; if (iter != end) ++iter; } // Search for the next toplevel window for (; iter != end; ++iter) { // If it's a toplevel, visible (we have hidden windows) and is enabled, // then we're done. The IsEnabled() prevents us from moving away from // a modal dialog because all other toplevel windows will be disabled. w = *iter; if (w->IsTopLevel() && w->IsShown() && w->IsEnabled()) { break; } } // Ran out of siblings, so make the current project active if ((iter == end) && isEnabled) { w = &project; } // And make sure it's on top (only for floating windows...project window will // not raise) // (Really only works on Windows) w->Raise(); #if defined(__WXMAC__) || defined(__WXGTK__) // bug 868 // Simulate a TAB key press before continuing, else the cycle of // navigation among top level windows stops because the keystrokes don't // go to the CommandManager. if (dynamic_cast<wxDialog*>(w)) { w->SetFocus(); } #endif }
bool wxTopLevelWindowGTK::Create( wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& sizeOrig, long style, const wxString &name ) { // always create a frame of some reasonable, even if arbitrary, size (at // least for MSW compatibility) wxSize size = sizeOrig; size.x = WidthDefault(size.x); size.y = HeightDefault(size.y); wxTopLevelWindows.Append( this ); m_needParent = false; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") ); return false; } m_title = title; m_insertCallback = (wxInsertChildFunction) wxInsertChildInTopLevelWindow; // NB: m_widget may be !=NULL if it was created by derived class' Create, // e.g. in wxTaskBarIconAreaGTK if (m_widget == NULL) { if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) { m_widget = gtk_window_new(GTK_WINDOW_DIALOG); } else { m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); #if GTK_CHECK_VERSION(2,1,0) if (!gtk_check_version(2,1,0)) { if (style & wxFRAME_TOOL_WINDOW) { gtk_window_set_type_hint(GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_UTILITY); // On some WMs, like KDE, a TOOL_WINDOW will still show // on the taskbar, but on Gnome a TOOL_WINDOW will not. // For consistency between WMs and with Windows, we // should set the NO_TASKBAR flag which will apply // the set_skip_taskbar_hint if it is available, // ensuring no taskbar entry will appear. style |= wxFRAME_NO_TASKBAR; } } #endif } } wxWindow *topParent = wxGetTopLevelParent(m_parent); if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) && (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) || (style & wxFRAME_FLOAT_ON_PARENT))) { gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(topParent->m_widget) ); } if (!name.empty()) gtk_window_set_wmclass( GTK_WINDOW(m_widget), wxGTK_CONV( name ), wxGTK_CONV( name ) ); gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); // m_mainWidget holds the toolbar, the menubar and the client area m_mainWidget = gtk_pizza_new(); gtk_widget_show( m_mainWidget ); GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); if (m_miniEdge == 0) // wxMiniFrame has its own version. { // For m_mainWidget themes gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event", GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw", GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this ); } // m_wxwindow only represents the client area without toolbar and menubar m_wxwindow = gtk_pizza_new(); gtk_widget_show( m_wxwindow ); gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); // we donm't allow the frame to get the focus as otherwise // the frame will grab it at arbitrary focus changes GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); if (m_parent) m_parent->AddChild( this ); // the user resized the frame by dragging etc. gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); PostCreation(); if ((m_x != -1) || (m_y != -1)) gtk_widget_set_uposition( m_widget, m_x, m_y ); gtk_window_set_default_size( GTK_WINDOW(m_widget), m_width, m_height ); // we cannot set MWM hints and icons before the widget has // been realized, so we do this directly after realization gtk_signal_connect( GTK_OBJECT(m_widget), "realize", GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this ); // map and unmap for iconized state gtk_signal_connect( GTK_OBJECT(m_widget), "map_event", GTK_SIGNAL_FUNC(gtk_frame_map_callback), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_widget), "unmap_event", GTK_SIGNAL_FUNC(gtk_frame_unmap_callback), (gpointer)this ); // the only way to get the window size is to connect to this event gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); // disable native tab traversal gtk_signal_connect( GTK_OBJECT(m_widget), "focus", GTK_SIGNAL_FUNC(gtk_frame_focus_callback), (gpointer)this ); // activation gtk_signal_connect( GTK_OBJECT(m_widget), "focus_in_event", GTK_SIGNAL_FUNC(gtk_frame_focus_in_callback), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_widget), "focus_out_event", GTK_SIGNAL_FUNC(gtk_frame_focus_out_callback), (gpointer)this ); // decorations if ((m_miniEdge > 0) || (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER)) { m_gdkDecor = 0; m_gdkFunc = 0; } else { m_gdkDecor = (long) GDK_DECOR_BORDER; m_gdkFunc = (long) GDK_FUNC_MOVE; // All this is for Motif Window Manager "hints" and is supposed to be // recognized by other WMs as well. if ((style & wxCAPTION) != 0) { m_gdkDecor |= GDK_DECOR_TITLE; } if ((style & wxCLOSE_BOX) != 0) { m_gdkFunc |= GDK_FUNC_CLOSE; } if ((style & wxSYSTEM_MENU) != 0) { m_gdkDecor |= GDK_DECOR_MENU; } if ((style & wxMINIMIZE_BOX) != 0) { m_gdkFunc |= GDK_FUNC_MINIMIZE; m_gdkDecor |= GDK_DECOR_MINIMIZE; } if ((style & wxMAXIMIZE_BOX) != 0) { m_gdkFunc |= GDK_FUNC_MAXIMIZE; m_gdkDecor |= GDK_DECOR_MAXIMIZE; } if ((style & wxRESIZE_BORDER) != 0) { m_gdkFunc |= GDK_FUNC_RESIZE; m_gdkDecor |= GDK_DECOR_RESIZEH; } } return true; }
static void gtk_collapsiblepane_expanded_callback(GObject * WXUNUSED(object), GParamSpec * WXUNUSED(param_spec), wxCollapsiblePane *p) { // NB: unlike for the "activate" signal, when this callback is called, if // we try to query the "collapsed" status through p->IsCollapsed(), we // get the right value. I.e. here p->IsCollapsed() will return false if // this callback has been called at the end of a collapsed->expanded // transition and viceversa. Inside the "activate" signal callback // p->IsCollapsed() would return the wrong value! wxSize sz; if ( p->IsExpanded() ) { // NB: we cannot use the p->GetBestSize() or p->GetMinSize() functions // here as they would return the size for the collapsed expander // even if the collapsed->expanded transition has already been // completed; we solve this problem doing: sz = p->m_szCollapsed; wxSize panesz = p->GetPane()->GetBestSize(); sz.x = wxMax(sz.x, panesz.x); sz.y += gtk_expander_get_spacing(GTK_EXPANDER(p->m_widget)) + panesz.y; } else // collapsed { // same problem described above: using p->Get[Best|Min]Size() here we // would get the size of the control when it is expanded even if the // expanded->collapsed transition should be complete now... // So, we use the size cached at control-creation time... sz = p->m_szCollapsed; } // VERY IMPORTANT: // just calling // p->OnStateChange(sz); // here would work work BUT: // 1) in the expanded->collapsed transition it provokes a lot of flickering // 2) in the collapsed->expanded transition using the "Change status" wxButton // in samples/collpane application some strange warnings would be generated // by the "clearlooks" theme, if that's your theme. // // So we prefer to use some GTK+ native optimized calls, which prevent too many resize // calculations to happen. Note that the following code has been very carefully designed // and tested - be VERY careful when changing it! // 1) need to update our size hints // NB: this function call won't actually do any long operation // (redraw/relayout/resize) so that it's flicker-free p->SetMinSize(sz); if (p->HasFlag(wxCP_NO_TLW_RESIZE)) { // fire an event wxCollapsiblePaneEvent ev(p, p->GetId(), p->IsCollapsed()); p->HandleWindowEvent(ev); // the user asked to explicitly handle the resizing itself... return; } wxTopLevelWindow * top = wxDynamicCast(wxGetTopLevelParent(p), wxTopLevelWindow); if ( top && top->GetSizer() ) { // 2) recalculate minimal size of the top window sz = top->GetSizer()->CalcMin(); if (top->m_mainWidget) { // 3) MAGIC HACK: if you ever used GtkExpander in a GTK+ program // you know that this magic call is required to make it possible // to shrink the top level window in the expanded->collapsed // transition. This may be sometimes undesired but *is* // necessary and if you look carefully, all GTK+ programs using // GtkExpander perform this trick (e.g. the standard "open file" // dialog of GTK+>=2.4 is not resizable when the expander is // collapsed!) gtk_window_set_resizable (GTK_WINDOW (top->m_widget), p->IsExpanded()); // 4) set size hints top->SetMinClientSize(sz); // 5) set size top->SetClientSize(sz); } } if ( p->m_bIgnoreNextChange ) { // change generated programmatically - do not send an event! p->m_bIgnoreNextChange = false; return; } // fire an event wxCollapsiblePaneEvent ev(p, p->GetId(), p->IsCollapsed()); p->HandleWindowEvent(ev); }
void wxSTEditorNotebook::OnFindDialog(wxFindDialogEvent &event) { wxSTERecursionGuard guard(m_rGuard_OnFindDialog); if (guard.IsInside()) return; // currently opened page is where the search starts wxSTEditor *editor = GetEditor(); if (!editor) return; // just search the given page by letting the editor handle it if (!STE_HASBIT(event.GetFlags(), STE_FR_ALLDOCS)) { editor->HandleFindDialogEvent(event); return; } wxEventType eventType = event.GetEventType(); wxString findString = event.GetFindString(); long flags = event.GetFlags(); editor->SetFindString(findString, true); editor->SetFindFlags(flags, true); STE_TextPos pos = editor->GetCurrentPos(); if ((eventType == wxEVT_COMMAND_FIND) && STE_HASBIT(flags, STE_FR_WHOLEDOC)) pos = -1; // we have to move cursor to start of word if last backwards search suceeded // note cmp is ok since regexp doesn't handle searching backwards if ((eventType == wxEVT_COMMAND_FIND_NEXT) && !STE_HASBIT(flags, wxFR_DOWN)) { if ((labs(editor->GetSelectionEnd() - editor->GetSelectionStart()) == long(findString.Length())) && (editor->GetFindReplaceData()->StringCmp(findString, editor->GetSelectedText(), flags))) pos -= (STE_TextPos)findString.Length() + 1; // doesn't matter if it matches or not, skip it } if (eventType == wxEVT_STEFIND_GOTO) { wxString findAllString(event.GetString()); wxString fileName; int line_number = 0; int line_start_pos = 0; int string_start_pos = 0; int string_length = 0; wxString lineText; bool ok = wxSTEditorFindReplaceData::ParseFindAllString(findAllString, fileName, line_number, line_start_pos, string_start_pos, string_length, lineText); int page = wxNOT_FOUND; if (ok) page = FindEditorPageByFileName(fileName); if (page != wxNOT_FOUND) { SetSelection(page); GetEditor(page)->HandleFindDialogEvent(event); } } else if ((eventType == wxEVT_COMMAND_FIND) || (eventType == wxEVT_COMMAND_FIND_NEXT)) { if (STE_HASBIT(flags, STE_FR_FINDALL|STE_FR_BOOKMARKALL)) { // sum up all of the find strings in all editors int n, count = (int)GetPageCount(); for (n = 0; n < count; n++) { wxSTEditor* e = GetEditor(n); if (e) e->HandleFindDialogEvent(event); } } else { if ((eventType == wxEVT_COMMAND_FIND) && STE_HASBIT(flags, STE_FR_WHOLEDOC)) pos = 0; pos = FindString(findString, pos, flags, STE_FINDSTRING_SELECT|STE_FINDSTRING_GOTO); if (pos >= 0) { //editor->SetFocus(); } else { wxBell(); // bell ok to signify no more occurances? } } } else if (eventType == wxEVT_COMMAND_FIND_REPLACE) { if (!editor->GetFindReplaceData()->StringCmp(findString, editor->GetSelectedText(), flags)) { wxBell(); return; } STE_TextPos pos = editor->GetSelectionStart(); wxString replaceString(event.GetReplaceString()); editor->ReplaceSelection(replaceString); editor->EnsureCaretVisible(); editor->SetSelection(pos, pos + (STE_TextPos)replaceString.Length()); editor->UpdateCanDo(true); //editor->SetFocus(); } else if (eventType == wxEVT_COMMAND_FIND_REPLACE_ALL) { wxString replaceString(event.GetReplaceString()); if (editor->GetFindReplaceData()->StringCmp(findString, replaceString, flags)) return; wxBusyCursor busy; int pages = 0; int count = ReplaceAllStrings(findString, replaceString, flags, &pages); wxString msg( wxString::Format(_("Replaced %d occurances of\n'%s' with '%s'\nin %d documents."), count, findString.wx_str(), replaceString.wx_str(), pages) ); wxMessageBox( msg, _("Finished replacing"), wxOK|wxICON_INFORMATION|wxSTAY_ON_TOP, wxGetTopLevelParent(this) ); // make it be on top in GTK //wxDynamicCast(event.GetEventObject(), wxDialog)); } else if (eventType == wxEVT_COMMAND_FIND_CLOSE) { //if (wxDynamicCast(event.GetEventObject(), wxDialog)) // ((wxDialog*)event.GetEventObject())->Destroy(); } }
wxProgressDialog::wxProgressDialog(wxString const &title, wxString const &message, int maximum, wxWindow *parent, int style) : wxDialog(parent, wxID_ANY, title), m_skip(false), m_delay(3), m_hasAbortButton(false), m_hasSkipButton(false) { // we may disappear at any moment, let the others know about it SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT); m_windowStyle |= style; m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0; m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0; bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) // we have to remove the "Close" button from the title bar then as it is // confusing to have it - it doesn't work anyhow // // FIXME: should probably have a (extended?) window style for this if ( !m_hasAbortButton ) { EnableCloseButton(false); } #endif // wxMSW #if defined(__SMARTPHONE__) SetLeftMenu(); #endif m_state = m_hasAbortButton ? Continue : Uncancelable; m_maximum = maximum; #if defined(__WXMSW__) || defined(__WXPM__) // we can't have values > 65,536 in the progress control under Windows, so // scale everything down m_factor = m_maximum / 65536 + 1; m_maximum /= m_factor; #endif // __WXMSW__ m_parentTop = wxGetTopLevelParent(parent); wxClientDC dc(this); dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); long widthText = 0; dc.GetTextExtent(message, &widthText, NULL, NULL, NULL, NULL); wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); m_msg = new wxStaticText(this, wxID_ANY, message); sizer->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN); wxSize sizeDlg, sizeLabel = m_msg->GetSize(); sizeDlg.y = 2*LAYOUT_MARGIN + sizeLabel.y; if ( maximum > 0 ) { int gauge_style = wxGA_HORIZONTAL; if ( ( style & wxPD_SMOOTH ) == wxPD_SMOOTH ) gauge_style |= wxGA_SMOOTH; m_gauge = new wxGauge(this, wxID_ANY, m_maximum, wxDefaultPosition, wxDefaultSize, gauge_style ); sizer->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN); m_gauge->SetValue(0); wxSize sizeGauge = m_gauge->GetSize(); sizeDlg.y += 2*LAYOUT_MARGIN + sizeGauge.y; } else m_gauge = (wxGauge *)NULL; // create the estimated/remaining/total time zones if requested m_elapsed = m_estimated = m_remaining = (wxStaticText*)NULL; m_display_estimated = m_last_timeupdate = m_break = 0; m_ctdelay = 0; // if we are going to have at least one label, remember it in this var wxStaticText *label = NULL; // also count how many labels we really have size_t nTimeLabels = 0; if ( style & wxPD_ELAPSED_TIME ) { nTimeLabels++; label = m_elapsed = CreateLabel(_("Elapsed time : "), sizer); } if ( style & wxPD_ESTIMATED_TIME ) { nTimeLabels++; label = m_estimated = CreateLabel(_("Estimated time : "), sizer); } if ( style & wxPD_REMAINING_TIME ) { nTimeLabels++; label = m_remaining = CreateLabel(_("Remaining time : "), sizer); } if ( nTimeLabels > 0 ) { // set it to the current time m_timeStart = wxGetCurrentTime(); sizeDlg.y += nTimeLabels * (label->GetSize().y + LAYOUT_MARGIN); } #if defined(__SMARTPHONE__) if ( m_hasSkipButton ) SetRightMenu(wxID_SKIP, _("Skip")); if ( m_hasAbortButton ) SetLeftMenu(wxID_CANCEL); #else m_btnAbort = m_btnSkip = (wxButton *)NULL; bool sizeDlgModified = false; wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); const int sizerFlags = #if defined(__WXMSW__) || defined(__WXPM__) wxALIGN_RIGHT | wxALL #else // !MSW wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP #endif // MSW/!MSW ; if ( m_hasSkipButton ) { m_btnSkip = new wxButton(this, wxID_SKIP, _("Skip")); // Windows dialogs usually have buttons in the lower right corner buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN); sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y; sizeDlgModified = true; } if ( m_hasAbortButton ) { m_btnAbort = new wxButton(this, wxID_CANCEL); // Windows dialogs usually have buttons in the lower right corner buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN); if(!sizeDlgModified) sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y; } sizer->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN ); #endif // __SMARTPHONE__/!__SMARTPHONE__ SetSizerAndFit(sizer); if (!isPda) { sizeDlg.y += 2*LAYOUT_MARGIN; // try to make the dialog not square but rectangular of reasonable width sizeDlg.x = (wxCoord)wxMax(3*widthText/2, 4*sizeDlg.y/3); SetClientSize(sizeDlg); } Centre(wxCENTER_FRAME | wxBOTH); if ( style & wxPD_APP_MODAL ) { m_winDisabler = new wxWindowDisabler(this); } else { if ( m_parentTop ) m_parentTop->Disable(); m_winDisabler = NULL; } Show(); Enable(); // this one can be initialized even if the others are unknown for now // // NB: do it after calling Layout() to keep the labels correctly aligned if ( m_elapsed ) { SetTimeLabel(0, m_elapsed); } Update(); }
wxProgressDialog::wxProgressDialog(const wxString& title, const wxString& message, int maximum, wxWindow *parent, int style) : wxDialog(GetParentForModalDialog(parent), wxID_ANY, title), m_skip(false), m_delay(3), m_hasAbortButton(false), m_hasSkipButton(false) { // we may disappear at any moment, let the others know about it SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT); m_windowStyle |= style; m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0; m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0; #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) // we have to remove the "Close" button from the title bar then as it is // confusing to have it - it doesn't work anyhow // // FIXME: should probably have a (extended?) window style for this if ( !m_hasAbortButton ) { EnableCloseButton(false); } #endif // wxMSW #if defined(__SMARTPHONE__) SetLeftMenu(); #endif m_state = m_hasAbortButton ? Continue : Uncancelable; m_maximum = maximum; #if defined(__WXMSW__) || defined(__WXPM__) // we can't have values > 65,536 in the progress control under Windows, so // scale everything down m_factor = m_maximum / 65536 + 1; m_maximum /= m_factor; #endif // __WXMSW__ m_parentTop = wxGetTopLevelParent(parent); wxClientDC dc(this); dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); wxCoord widthText = 0; dc.GetTextExtent(message, &widthText, NULL, NULL, NULL, NULL); // top-level sizerTop wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL); m_msg = new wxStaticText(this, wxID_ANY, message); sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN); if ( maximum > 0 ) { int gauge_style = wxGA_HORIZONTAL; if ( style & wxPD_SMOOTH ) gauge_style |= wxGA_SMOOTH; m_gauge = new wxGauge ( this, wxID_ANY, m_maximum, wxDefaultPosition, // make the progress bar sufficiently long wxSize(wxMin(wxGetClientDisplayRect().width/3, 300), -1), gauge_style ); sizerTop->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN); m_gauge->SetValue(0); } else { m_gauge = NULL; } // create the estimated/remaining/total time zones if requested m_elapsed = m_estimated = m_remaining = NULL; m_display_estimated = m_last_timeupdate = m_break = 0; m_ctdelay = 0; // also count how many labels we really have size_t nTimeLabels = 0; wxSizer * const sizerLabels = new wxFlexGridSizer(2); if ( style & wxPD_ELAPSED_TIME ) { nTimeLabels++; m_elapsed = CreateLabel(_("Elapsed time:"), sizerLabels); } if ( style & wxPD_ESTIMATED_TIME ) { nTimeLabels++; m_estimated = CreateLabel(_("Estimated time:"), sizerLabels); } if ( style & wxPD_REMAINING_TIME ) { nTimeLabels++; m_remaining = CreateLabel(_("Remaining time:"), sizerLabels); } sizerTop->Add(sizerLabels, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN); if ( nTimeLabels > 0 ) { // set it to the current time m_timeStart = wxGetCurrentTime(); } #if defined(__SMARTPHONE__) if ( m_hasSkipButton ) SetRightMenu(wxID_SKIP, _("Skip")); if ( m_hasAbortButton ) SetLeftMenu(wxID_CANCEL); #else m_btnAbort = m_btnSkip = NULL; wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); // Windows dialogs usually have buttons in the lower right corner const int sizerFlags = #if defined(__WXMSW__) || defined(__WXPM__) wxALIGN_RIGHT | wxALL #else // !MSW wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP #endif // MSW/!MSW ; if ( m_hasSkipButton ) { m_btnSkip = new wxButton(this, wxID_SKIP, _("&Skip")); buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN); } if ( m_hasAbortButton ) { m_btnAbort = new wxButton(this, wxID_CANCEL); buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN); } sizerTop->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN ); #endif // __SMARTPHONE__/!__SMARTPHONE__ SetSizerAndFit(sizerTop); Centre(wxCENTER_FRAME | wxBOTH); if ( style & wxPD_APP_MODAL ) { m_winDisabler = new wxWindowDisabler(this); } else { if ( m_parentTop ) m_parentTop->Disable(); m_winDisabler = NULL; } Show(); Enable(); // this one can be initialized even if the others are unknown for now // // NB: do it after calling Layout() to keep the labels correctly aligned if ( m_elapsed ) { SetTimeLabel(0, m_elapsed); } Update(); }
// Find the top-most parent window wxWindow* wxHtmlHelpController::FindTopLevelWindow() { return wxGetTopLevelParent(m_helpWindow); }
bool wxGenericProgressDialog::Create( const wxString& title, const wxString& message, int maximum, wxWindow *parent, int style ) { SetTopParent(parent); m_parentTop = wxGetTopLevelParent(parent); m_pdStyle = style; wxWindow* const realParent = GetParentForModalDialog(parent, GetWindowStyle()); if (!wxDialog::Create(realParent, wxID_ANY, title)) return false; SetMaximum(maximum); // We need a running event loop in order to update the dialog and be able // to process clicks on its buttons, so ensure that there is one running // even if this means we have to start it ourselves (this happens most // commonly during the program initialization, e.g. for the progress // dialogs shown from overridden wxApp::OnInit()). if ( !wxEventLoopBase::GetActive() ) { m_tempEventLoop = new wxEventLoop; wxEventLoop::SetActive(m_tempEventLoop); } #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) // we have to remove the "Close" button from the title bar then as it is // confusing to have it - it doesn't work anyhow // // FIXME: should probably have a (extended?) window style for this if ( !HasPDFlag(wxPD_CAN_ABORT) ) { EnableCloseButton(false); } #endif // wxMSW #if defined(__SMARTPHONE__) SetLeftMenu(); #endif m_state = HasPDFlag(wxPD_CAN_ABORT) ? Continue : Uncancelable; // top-level sizerTop wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL); m_msg = new wxStaticText(this, wxID_ANY, message); sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN); int gauge_style = wxGA_HORIZONTAL; if ( style & wxPD_SMOOTH ) gauge_style |= wxGA_SMOOTH; #ifdef __WXMSW__ maximum /= m_factor; #endif m_gauge = new wxGauge ( this, wxID_ANY, maximum, wxDefaultPosition, // make the progress bar sufficiently long wxSize(wxMin(wxGetClientDisplayRect().width/3, 300), -1), gauge_style ); sizerTop->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN); m_gauge->SetValue(0); // create the estimated/remaining/total time zones if requested m_elapsed = m_estimated = m_remaining = NULL; // also count how many labels we really have size_t nTimeLabels = 0; wxSizer * const sizerLabels = new wxFlexGridSizer(2); if ( style & wxPD_ELAPSED_TIME ) { nTimeLabels++; m_elapsed = CreateLabel(GetElapsedLabel(), sizerLabels); } if ( style & wxPD_ESTIMATED_TIME ) { nTimeLabels++; m_estimated = CreateLabel(GetEstimatedLabel(), sizerLabels); } if ( style & wxPD_REMAINING_TIME ) { nTimeLabels++; m_remaining = CreateLabel(GetRemainingLabel(), sizerLabels); } sizerTop->Add(sizerLabels, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN); #if defined(__SMARTPHONE__) if ( HasPDFlag(wxPD_CAN_SKIP) ) SetRightMenu(wxID_SKIP, _("Skip")); if ( HasPDFlag(wxPD_CAN_ABORT) ) SetLeftMenu(wxID_CANCEL); #else m_btnAbort = m_btnSkip = NULL; wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); // Windows dialogs usually have buttons in the lower right corner const int sizerFlags = #if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXOSX__) wxALIGN_RIGHT | wxALL #else // !MSW wxALIGN_CENTER_HORIZONTAL | wxBOTTOM | wxTOP #endif // MSW/!MSW ; if ( HasPDFlag(wxPD_CAN_SKIP) ) { m_btnSkip = new wxButton(this, wxID_SKIP, _("&Skip")); buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN); } if ( HasPDFlag(wxPD_CAN_ABORT) ) { m_btnAbort = new wxButton(this, wxID_CANCEL); buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN); } if ( !HasPDFlag(wxPD_CAN_SKIP | wxPD_CAN_ABORT) ) buttonSizer->AddSpacer(LAYOUT_MARGIN); sizerTop->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN ); #endif // __SMARTPHONE__/!__SMARTPHONE__ SetSizerAndFit(sizerTop); Centre(wxCENTER_FRAME | wxBOTH); DisableOtherWindows(); Show(); Enable(); // this one can be initialized even if the others are unknown for now // // NB: do it after calling Layout() to keep the labels correctly aligned if ( m_elapsed ) { SetTimeLabel(0, m_elapsed); } Update(); return true; }
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 ; } if ( !GetTextPeer()->CanClipMaxLength() ) { // 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_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_BUTTON, 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_TEXT, m_windowId); event1.SetEventObject( this ); wxPostEvent( GetEventHandler(), event1 ); } #endif }
void CompilerMainPage::OnAddCompilers(wxCommandEvent& event) { AdvancedDlg* dlg = dynamic_cast<AdvancedDlg*>(wxGetTopLevelParent(this)); dlg->OnAutoDetectCompilers(m_button222); }