//---------------------------------------------------------------------------- // common event handlers void Edit::OnSize( wxSizeEvent& event ) { int x = GetClientSize().x + (g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0) + (g_CommonPrefs.foldEnable? m_FoldingMargin: 0); if (x > 0) SetScrollWidth (x); event.Skip(); }
//---------------------------------------------------------------------------- // Common event handlers void CodeEditor::OnSize(wxSizeEvent& event) { int x = GetClientSize().x + mLineNumMargin + mFoldingMargin; if (x > 0) SetScrollWidth(x); event.Skip(); }
void Edit::OnAnnotationAdd(wxCommandEvent& WXUNUSED(event)) { const int line = GetCurrentLine(); wxString ann = AnnotationGetText(line); ann = wxGetTextFromUser ( wxString::Format("Enter annotation for the line %d", line), "Edit annotation", ann, this ); if ( ann.empty() ) return; AnnotationSetText(line, ann); AnnotationSetStyle(line, ANNOTATION_STYLE); // Scintilla doesn't update the scroll width for annotations, even with // scroll width tracking on, so do it manually. const int width = GetScrollWidth(); // NB: The following adjustments are only needed when using // wxSTC_ANNOTATION_BOXED annotations style, but we apply them always // in order to make things simpler and not have to redo the width // calculations when the annotations visibility changes. In a real // program you'd either just stick to a fixed annotations visibility or // update the width when it changes. // Take into account the fact that the annotation is shown indented, with // the same indent as the line it's attached to. int indent = GetLineIndentation(line); // This is just a hack to account for the width of the box, there doesn't // seem to be any way to get it directly from Scintilla. indent += 3; const int widthAnn = TextWidth(ANNOTATION_STYLE, ann + wxString(indent, ' ')); if (widthAnn > width) SetScrollWidth(widthAnn); }
void PythonCodeCtrl::OnUserInput(wxKeyEvent& ke) { if(ke.GetModifiers()==wxMOD_CONTROL) { // wxMessageBox(_T("control pressed")); // wxMessageBox(wxString::Format(_("Key: %i"),ke.GetKeyCode())); if(ke.GetKeyCode()=='D') { m_pyctrl->DispatchCode(GetValue()); // if(m_pyctrl->DispatchCode(GetValue())) // ChangeValue(_T("")); return; } if(ke.GetKeyCode()=='K') { m_pyctrl->BreakCode(); return; } if(ke.GetKeyCode()==WXK_RETURN) { m_pyctrl->DispatchCode(GetValue()); return; } if(ke.GetKeyCode()==WXK_UP) //TODO: If the text is ever changed, set m_history_position to -1 { if (m_history_position < 0) m_history_working = GetValue(); m_history_position--; if (m_history_position < -1) m_history_position = m_history_commands.GetCount()-1; if (m_history_position >= 0) SetValue(m_history_commands[m_history_position]); else SetValue(m_history_working); int pos = GetLength(); //was GetLastPosition(); SetSelectionStart(pos);//was SetSelection(pos,pos); SetSelectionEnd(pos); SetScrollWidth(5); //Hides horizontal scrollbar if text doesn't exceed the window width return; } if(ke.GetKeyCode()==WXK_DOWN) { if (m_history_position < 0) m_history_working = GetValue(); m_history_position++; if (m_history_position >= int(m_history_commands.GetCount())) m_history_position = -1; if (m_history_position >= 0) SetValue(m_history_commands[m_history_position]); else SetValue(m_history_working); int pos = GetLength(); //was LastPosition(); SetSelectionStart(pos); //was SetSelection(pos,pos); SetSelectionEnd(pos); SetScrollWidth(5); //Hides horizontal scrollbar if text doesn't exceed the window width return; } } ke.Skip(); }
PythonCodeCtrl::PythonCodeCtrl(wxWindow *parent, PythonInterpCtrl *py) : cbStyledTextCtrl(parent, wxID_ANY) { m_pyctrl = py; EditorManager *em = Manager::Get()->GetEditorManager(); // Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(PythonCodeCtrl::OnUserInput)); ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor")); //MOST OF THIS STUFF IS TAKEN FROM CB EDITOR wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL); wxString fontstring = mgr->Read(_T("/font"), wxEmptyString); if (!fontstring.IsEmpty()) { wxNativeFontInfo nfi; nfi.FromString(fontstring); font.SetNativeFontInfo(nfi); } SetMouseDwellTime(1000); SetScrollWidthTracking(true); SetScrollWidth(5); //Hides horizontal scrollbar if text doesn't exceed the window width int caretStyle = mgr->ReadInt(_T("/caret/style"), wxSCI_CARETSTYLE_LINE); SetCaretStyle(caretStyle); if (caretStyle == wxSCI_CARETSTYLE_LINE) SetCaretWidth(mgr->ReadInt(_T("/caret/width"), 1)); else SetCaretWidth(1); ColourManager *colours = Manager::Get()->GetColourManager(); SetCaretForeground(colours->GetColour(wxT("editor_caret"))); SetCaretPeriod(mgr->ReadInt(_T("/caret/period"), 500)); SetCaretLineVisible(mgr->ReadBool(_T("/highlight_caret_line"), false)); SetCaretLineBackground( Manager::Get()->GetConfigManager(_T("editor"))->ReadColour(_T("/highlight_caret_line_colour"), wxColour(0xFF, 0xFF, 0x00))); SetFoldMarginColour(true, colours->GetColour(wxT("editor_margin_chrome"))); SetFoldMarginHiColour(true, colours->GetColour(wxT("editor_margin_chrome_highlight"))); // setup for "CamelCase selection" if (mgr->ReadBool(_T("/camel_case"), false)) { // consider CamelCase for both: cursor movement with CTRL and selection with CTRL+SHIFT: CmdKeyAssign(wxSCI_KEY_LEFT, wxSCI_SCMOD_CTRL, wxSCI_CMD_WORDPARTLEFT); CmdKeyAssign(wxSCI_KEY_RIGHT, wxSCI_SCMOD_CTRL, wxSCI_CMD_WORDPARTRIGHT); CmdKeyAssign(wxSCI_KEY_LEFT, wxSCI_SCMOD_CTRL|wxSCI_SCMOD_SHIFT, wxSCI_CMD_WORDPARTLEFTEXTEND); CmdKeyAssign(wxSCI_KEY_RIGHT, wxSCI_SCMOD_CTRL|wxSCI_SCMOD_SHIFT, wxSCI_CMD_WORDPARTRIGHTEXTEND); } else // else set default "none CamelCase" key behavior (also default scintilla behaviour, see scintilla docs) { CmdKeyAssign(wxSCI_KEY_LEFT, wxSCI_SCMOD_CTRL, wxSCI_CMD_WORDLEFT); CmdKeyAssign(wxSCI_KEY_RIGHT, wxSCI_SCMOD_CTRL, wxSCI_CMD_WORDRIGHT); CmdKeyAssign(wxSCI_KEY_LEFT, wxSCI_SCMOD_CTRL|wxSCI_SCMOD_SHIFT, wxSCI_CMD_WORDLEFTEXTEND); CmdKeyAssign(wxSCI_KEY_RIGHT, wxSCI_SCMOD_CTRL|wxSCI_SCMOD_SHIFT, wxSCI_CMD_WORDRIGHTEXTEND); } SetUseTabs(mgr->ReadBool(_T("/use_tab"), false)); SetIndentationGuides(mgr->ReadBool(_T("/show_indent_guides"), false)?wxSCI_IV_LOOKBOTH:wxSCI_IV_NONE); SetTabIndents(mgr->ReadBool(_T("/tab_indents"), true)); SetBackSpaceUnIndents(mgr->ReadBool(_T("/backspace_unindents"), true)); SetWrapMode(mgr->ReadBool(_T("/word_wrap"), false)); if (mgr->ReadBool(_T("/word_wrap_style_home_end"), true)) { // in word wrap mode, home/end keys goto the wrap point if not already there, // otherwise to the start/end of the entire line. // alt+home/end go to start/end of the entire line. // in unwrapped mode, there is no difference between home/end and alt+home/end CmdKeyAssign(wxSCI_KEY_END, wxSCI_SCMOD_NORM, wxSCI_CMD_LINEENDWRAP); CmdKeyAssign(wxSCI_KEY_END, wxSCI_SCMOD_ALT, wxSCI_CMD_LINEEND); CmdKeyAssign(wxSCI_KEY_END, wxSCI_SCMOD_SHIFT, wxSCI_CMD_LINEENDWRAPEXTEND); CmdKeyAssign(wxSCI_KEY_END, wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT, wxSCI_CMD_LINEENDEXTEND); // if user wants "Home" key to set cursor to the very beginning of line if (mgr->ReadBool(_T("/simplified_home"), false)) { CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_NORM,wxSCI_CMD_HOMEWRAP); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_ALT,wxSCI_CMD_HOME); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT,wxSCI_CMD_HOMEWRAPEXTEND); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_HOMEEXTEND); } else // else set default "Home" key behavior { CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_NORM,wxSCI_CMD_VCHOMEWRAP); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOME); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT,wxSCI_CMD_VCHOMEWRAPEXTEND); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOMEEXTEND); } } else { // in word wrap mode, home/end keys goto start/end of the entire line. alt+home/end goes to wrap points CmdKeyAssign(wxSCI_KEY_END, wxSCI_SCMOD_ALT, wxSCI_CMD_LINEENDWRAP); CmdKeyAssign(wxSCI_KEY_END, wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT, wxSCI_CMD_LINEENDWRAPEXTEND); // if user wants "Home" key to set cursor to the very beginning of line if (mgr->ReadBool(_T("/simplified_home"), false)) { CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_ALT,wxSCI_CMD_HOMEWRAP); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_HOMEWRAPEXTEND); } else // else set default "Home" key behavior { CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOMEWRAP); CmdKeyAssign(wxSCI_KEY_HOME,wxSCI_SCMOD_SHIFT|wxSCI_SCMOD_ALT,wxSCI_CMD_VCHOMEWRAPEXTEND); } } SetViewEOL(mgr->ReadBool(_T("/show_eol"), false)); SetViewWhiteSpace(mgr->ReadInt(_T("/view_whitespace"), 0)); // gutter SetEdgeMode(mgr->ReadInt(_T("/gutter/mode"), 0)); SetEdgeColour(Manager::Get()->GetColourManager()->GetColour(wxT("editor_gutter"))); SetEdgeColumn(mgr->ReadInt(_T("/gutter/column"), 80)); StyleSetFont(wxSCI_STYLE_DEFAULT, font); StyleClearAll(); SetTabWidth(mgr->ReadInt(_T("/tab_size"), 4)); SetIndent(mgr->ReadInt(_T("/tab_size"), 4)); //NEEDED FOR AUTO INDENTATION (NOT IN CB EDITOR) em->GetColourSet()->Apply(_("Python"),this); }
void ScriptEditCtrl::Impl::PreSubclassWindow() { self_->m_hWnd = m_hWnd; // expose HWND SetupDirectAccess(); // If we are running as Unicode, then use the UTF8 codepage #ifdef _UNICODE SetCodePage(SC_CP_UTF8); #endif SetLexer(SCLEX_LUA); StyleSetFont(STYLE_DEFAULT, "Lucida Console"); StyleSetSize(STYLE_DEFAULT, 10); SetKeyWords(0, LuaKeywords); SetKeyWords(1, LuaFunctions); if (enable_input_attribs_) SetKeyWords(2, LuaUser); SetKeyWords(3, ConcatAttributes().c_str()); COLORREF comment= RGB(0,128,128); COLORREF string= RGB(128,128,0); StyleSetFore(SCE_LUA_COMMENT, comment); StyleSetFore(SCE_LUA_COMMENTLINE, comment); StyleSetFore(SCE_LUA_COMMENTDOC, comment); StyleSetFore(SCE_LUA_NUMBER, RGB(0,0,255)); StyleSetFore(SCE_LUA_WORD, RGB(34,78,160)); // keywords StyleSetFore(SCE_LUA_STRING, string); StyleSetFore(SCE_LUA_CHARACTER, string); StyleSetFore(SCE_LUA_LITERALSTRING, string); StyleSetFore(SCE_LUA_WORD2, RGB(53,113,202)); // functions StyleSetFore(SCE_LUA_WORD3, RGB(124,37,203)); // test & number StyleSetBack(SCE_LUA_WORD3, CalcColor(::GetSysColor(COLOR_WINDOW), RGB(0,0,255), 0.95f)); StyleSetFore(SCE_LUA_WORD4, RGB(164,97,49)); // todo: attributes StyleSetFont(SCE_LUA_WORD, "Lucida Console"); StyleSetSize(SCE_LUA_WORD, 10); StyleSetBold(SCE_LUA_WORD, true); //#define SCE_LUA_PREPROCESSOR 9 //#define SCE_LUA_OPERATOR 10 //#define SCE_LUA_IDENTIFIER 11 //#define SCE_LUA_STRINGEOL 12 //#define SCE_LUA_WORD2 13 //#define SCE_LUA_WORD3 14 //#define SCE_LUA_WORD4 15 //#define SCE_LUA_WORD5 16 //#define SCE_LUA_WORD6 17 //#define SCE_LUA_WORD7 18 //#define SCE_LUA_WORD8 19 Colorize(0, -1); //MarkerDefine(MARKER_POINTER, SC_MARK_ARROW); //MarkerSetBack(MARKER_POINTER, RGB(255,255,0)); //MarkerDefine(MARKER_BREAKPOINT, SC_MARK_ROUNDRECT); //MarkerSetBack(MARKER_BREAKPOINT, RGB(0,0,255)); //MarkerDefine(MARKER_ERROR, SC_MARK_ARROW); //MarkerSetBack(MARKER_ERROR, RGB(255,0,0)); int width= 0; SetMarginWidthN(1, width); SetScrollWidthTracking(true); SetScrollWidth(1); SetWrapMode(SC_WRAP_WORD); SetWrapVisualFlags(SC_WRAPVISUALFLAG_END); SetSelBack(true, CalcShade(::GetSysColor(COLOR_HIGHLIGHT), 50.0f)); SetTabWidth(4); SetIndent(4); DWORD pixels= 1; ::SystemParametersInfo(SPI_GETCARETWIDTH, 0, &pixels, 0); SetCaretWidth(pixels); // hwnd is attached, but message processing is not working yet, we are not yet subclassed, // so postpone this WM_NCCALCSIZE call: PostMessage(WM_APP+1234); }