X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfunc.C;h=5c6eece450d21a820e797518a324d35a5c30c503;hb=0031da054f072922ed081bc8a877ffd8eb280210;hp=3c9e0515ad97441096ac95fe176bf3ceae4e4c85;hpb=67191fe11fa0e00588abf530518ace508cd94921;p=features.git diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3c9e0515ad..5c6eece450 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -10,12 +10,7 @@ #include -#ifdef HAVE_SSTREAM -#include -using std::istringstream; -#else -#include -#endif +#include "Lsstream.h" #include #include @@ -86,12 +81,11 @@ using std::istringstream; #include "bufferview_funcs.h" #include "frontends/Dialogs.h" #include "frontends/Toolbar.h" -#ifdef NEW_MENUBAR #include "frontends/Menubar.h" -#else -#include "menus.h" -#endif #include "FloatList.h" +#include "exporter.h" +#include "FontLoader.h" +#include "TextCache.h" using std::pair; using std::endl; @@ -99,7 +93,7 @@ using std::endl; extern bool cursor_follows_scrollbar; extern void InsertAsciiFile(BufferView *, string const &, bool); -extern void math_insert_symbol(char const *); +extern void math_insert_symbol(string const &); extern bool math_insert_greek(char); extern BufferList bufferlist; extern LyXServer * lyxserver; @@ -113,12 +107,16 @@ extern bool MenuWriteAs(Buffer *); extern int MenuRunLaTeX(Buffer *); extern int MenuBuildProg(Buffer *); extern int MenuRunChktex(Buffer *); +#ifndef NEW_EXPORT extern bool CreatePostscript(Buffer *, bool); +#endif extern void MenuPrint(Buffer *); extern void MenuSendto(); extern void QuitLyX(); extern void MenuFax(Buffer *); +#ifndef NEW_EXPORT extern void MenuExport(Buffer *, string const &); +#endif extern void show_symbols_form(LyXFunc *); extern LyXAction lyxaction; @@ -126,9 +124,11 @@ extern LyXAction lyxaction; extern tex_accent_struct get_accent(kb_action action); extern void AutoSave(BufferView *); +#ifndef NEW_EXPORT extern bool PreviewDVI(Buffer *); extern bool PreviewPostscript(Buffer *); -extern void MenuInsertLabel(char const *); +#endif +extern void MenuInsertLabel(string const &); extern void MenuLayoutCharacter(); extern void MenuLayoutParagraph(); extern void MenuLayoutDocument(); @@ -185,13 +185,133 @@ void LyXFunc::moveCursorUpdate(bool selecting) } +int LyXFunc::processKeySym(KeySym keysym, unsigned int state) +{ + string argument; + + if (lyxerr.debugging(Debug::KEY)) { + char * tmp = XKeysymToString(keysym); + string stm = (tmp ? tmp : ""); + lyxerr << "KeySym is " + << stm + << "[" + << keysym << "]" + << endl; + } + // Do nothing if we have nothing (JMarc) + if (keysym == NoSymbol) { + lyxerr[Debug::KEY] << "Empty kbd action (probably composing)" + << endl; + //return 0; + return FL_PREEMPT; + } + + // this function should be used always [asierra060396] + UpdatableInset * tli = owner->view()->the_locking_inset; + if (owner->view()->available() && tli && (keysym == XK_Escape)) { + if (tli == tli->GetLockingInset()) { + owner->view()->unlockInset(tli); + owner->view()->text->CursorRight(owner->view()); + moveCursorUpdate(false); + owner->showState(); + } else { + tli->UnlockInsetInInset(owner->view(), + tli->GetLockingInset(),true); + } + //return 0; + return FL_PREEMPT; + } + + // Can we be sure that this will work for all X-Windows + // implementations? (Lgb) + // This code snippet makes lyx ignore some keys. Perhaps + // all of them should be explictly mentioned? + if((keysym >= XK_Shift_L && keysym <= XK_Hyper_R) + || keysym == XK_Mode_switch || keysym == 0x0) + return 0; + + // Do a one-deep top-level lookup for + // cancel and meta-fake keys. RVDK_PATCH_5 + cancel_meta_seq.reset(); + + int action = cancel_meta_seq.addkey(keysym, state + &(ShiftMask|ControlMask + |Mod1Mask)); + + // When not cancel or meta-fake, do the normal lookup. + // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards. + // Mostly, meta_fake_bit = 0. RVDK_PATCH_5. + if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) { + + // remove Caps Lock and Mod2 as a modifiers + action = keyseq.addkey(keysym, + (state | meta_fake_bit) + &(ShiftMask|ControlMask + |Mod1Mask)); + } + // Dont remove this unless you know what you are doing. + meta_fake_bit = 0; + + if (action == 0) action = LFUN_PREFIX; + + if (lyxerr.debugging(Debug::KEY)) { + string buf; + keyseq.print(buf); + lyxerr << "Key [" + << action << "][" + << buf << "]" + << endl; + } + + // already here we know if it any point in going further + // why not return already here if action == -1 and + // num_bytes == 0? (Lgb) + + if(keyseq.length > 1 || keyseq.length < -1) { + string buf; + keyseq.print(buf); + owner->getMiniBuffer()->Set(buf); + } + + if (action == -1) { + if (keyseq.length < -1) { // unknown key sequence... + string buf; + LyXBell(); + keyseq.print(buf); + owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf); + return 0; + } + + char isochar = keyseq.getiso(); + if (!(state & ControlMask) && + !(state & Mod1Mask) && + (isochar && keysym < 0xF000)) { + argument += isochar; + } + if (argument.empty()) { + lyxerr.debug() << "Empty argument!" << endl; + // This can`t possibly be of any use + // so we`ll skip the dispatch. + return 0; + } + } + + bool tmp_sc = show_sc; + show_sc = false; + Dispatch(action, argument); + show_sc = tmp_sc; + + return 0; +} + + +#if 0 int LyXFunc::processKeyEvent(XEvent * ev) { char s_r[10]; + KeySym keysym_return = 0; string argument; XKeyEvent * keyevent = &ev->xkey; - KeySym keysym_return = 0; - int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return); s_r[num_bytes] = '\0'; @@ -205,7 +325,8 @@ int LyXFunc::processKeyEvent(XEvent * ev) << " and num_bytes is " << num_bytes << " the string returned is \"" - << s_r << '\"' << endl; + << s_r << '\"' + << endl; } // Do nothing if we have nothing (JMarc) if (num_bytes == 0 && keysym_return == NoSymbol) { @@ -266,8 +387,10 @@ int LyXFunc::processKeyEvent(XEvent * ev) keyseq.print(buf); lyxerr << "Key [" << action << "][" - << buf << "][" - << num_bytes << "]" << endl; + << buf << "]" + << "[" + << num_bytes << "]" + << endl; } // already here we know if it any point in going further @@ -301,18 +424,20 @@ int LyXFunc::processKeyEvent(XEvent * ev) // so we`ll skip the dispatch. return 0; } - } else + } + else if (action == LFUN_SELFINSERT) { argument = s_r[0]; } - + bool tmp_sc = show_sc; show_sc = false; - Dispatch(action, argument.c_str()); + Dispatch(action, argument); show_sc = tmp_sc; return 0; } +#endif LyXFunc::func_status LyXFunc::getStatus(int ac) const @@ -359,6 +484,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const static bool noLaTeX = lyxrc.latex_command == "none"; bool disable = false; switch (action) { +#ifndef NEW_EXPORT case LFUN_PREVIEW: disable = noLaTeX || lyxrc.view_dvi_command == "none"; break; @@ -369,6 +495,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const case LFUN_RUNDVIPS: disable = noLaTeX; break; +#endif case LFUN_MENUPRINT: disable = noLaTeX || lyxrc.print_command == "none"; break; @@ -381,6 +508,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const else if (argument == "linuxdoc") disable = lyxrc.linuxdoc_to_lyx_command == "none"; break; +#ifndef NEW_EXPORT case LFUN_EXPORT: if (argument == "latex") disable = (! buf->isLatex() && ! buf->isLiterate()) ; @@ -400,6 +528,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const else if (argument == "custom") disable = (! buf->isLatex() && ! buf->isLiterate()); break; +#endif case LFUN_UNDO: disable = buf->undostack.empty(); break; @@ -433,7 +562,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const case LFUN_TABULAR_FEATURE: disable = true; if (owner->view()->the_locking_inset) { - int ret = 0; + func_status ret = LyXFunc::Disabled; if (owner->view()->the_locking_inset->LyxCode() == Inset::TABULAR_CODE) { ret = static_cast (owner->view()->the_locking_inset)-> @@ -444,21 +573,17 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const GetFirstLockingInsetOfType(Inset::TABULAR_CODE))-> getStatus(argument); } - switch(ret) { - case 0: - break; - case 1: - disable = false; - break; - case 2: - disable = false; - flag |= LyXFunc::ToggleOn; - break; - case 3: - disable = false; - flag |= LyXFunc::ToggleOff; - break; - } + flag |= ret; + disable = false; + } else { + static InsetTabular inset(owner->buffer(), 1, 1); + func_status ret; + + disable = true; + ret = inset.getStatus(argument); + if ((ret & LyXFunc::ToggleOn) || + (ret & LyXFunc::ToggleOff)) + flag |= LyXFunc::ToggleOff; } break; @@ -476,6 +601,9 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const case LFUN_VC_HISTORY: disable = !buf->lyxvc.inUse(); break; + case LFUN_REF_BACK: + disable = owner->view()->NoSavedPositions(); + break; default: break; } @@ -484,7 +612,13 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const if (buf) { func_status box = LyXFunc::ToggleOff; - LyXFont font = owner->view()->text->real_current_font; + LyXFont font; + if (owner->view()->the_locking_inset && + owner->view()->the_locking_inset->getLyXText(owner->view())) + font = owner->view()->the_locking_inset-> + getLyXText(owner->view())->real_current_font; + else + font = owner->view()->text->real_current_font; switch (action) { case LFUN_EMPH: if (font.emph() == LyXFont::ON) @@ -513,18 +647,19 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const } -string LyXFunc::Dispatch(string const & s) +string const LyXFunc::Dispatch(string const & s) { // Split command string into command and argument - string cmd, line = frontStrip(s); + string cmd; + string line = frontStrip(s); string arg = strip(frontStrip(split(line, cmd, ' '))); - return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str()); + return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg); } -string LyXFunc::Dispatch(int ac, - char const * do_not_use_this_arg) +string const LyXFunc::Dispatch(int ac, + string const & do_not_use_this_arg) { string argument; kb_action action; @@ -542,7 +677,7 @@ string LyXFunc::Dispatch(int ac, argument = tmparg; } else { action = static_cast(ac); - if (do_not_use_this_arg) + if (!do_not_use_this_arg.empty()) argument = do_not_use_this_arg; // except here } @@ -834,6 +969,15 @@ string LyXFunc::Dispatch(int ac, reloadBuffer(); break; +#ifdef NEW_EXPORT + case LFUN_UPDATE: + Exporter::Export(owner->buffer(), argument, true); + break; + + case LFUN_PREVIEW: + Exporter::Preview(owner->buffer(), argument); + break; +#else case LFUN_PREVIEW: PreviewDVI(owner->buffer()); break; @@ -845,6 +989,11 @@ string LyXFunc::Dispatch(int ac, case LFUN_RUNLATEX: MenuRunLaTeX(owner->buffer()); break; + + case LFUN_RUNDVIPS: + CreatePostscript(owner->buffer(), false); + break; +#endif case LFUN_BUILDPROG: MenuBuildProg(owner->buffer()); @@ -853,11 +1002,7 @@ string LyXFunc::Dispatch(int ac, case LFUN_RUNCHKTEX: MenuRunChktex(owner->buffer()); break; - - case LFUN_RUNDVIPS: - CreatePostscript(owner->buffer(), false); - break; - + case LFUN_MENUPRINT: owner->getDialogs()->showPrint(); break; @@ -867,7 +1012,11 @@ string LyXFunc::Dispatch(int ac, break; case LFUN_EXPORT: +#ifdef NEW_EXPORT + Exporter::Export(owner->buffer(), argument, false); +#else MenuExport(owner->buffer(), argument); +#endif break; case LFUN_IMPORT: @@ -920,7 +1069,7 @@ string LyXFunc::Dispatch(int ac, break; } - case LFUN_TABLE: + case LFUN_DIALOG_TABULAR_INSERT: #ifndef NEW_TABULAR Table(); #else @@ -1240,7 +1389,7 @@ string LyXFunc::Dispatch(int ac, Dispatch(int(LFUN_LAYOUT), textclasslist.NameOfLayout(owner->view() ->buffer()->params.textclass, - sel).c_str()); + sel)); return string(); } @@ -1286,7 +1435,11 @@ string LyXFunc::Dispatch(int ac, break; case LFUN_LAYOUT_DOCUMENT: +#ifdef USE_OLD_DOCUMENT_LAYOUT MenuLayoutDocument(); +#else + owner->getDialogs()->showLayoutDocument(); +#endif break; case LFUN_LAYOUT_PARAGRAPH: @@ -1321,11 +1474,15 @@ string LyXFunc::Dispatch(int ac, break; case LFUN_LAYOUT_PAPER: +#ifdef USE_OLD_DOCUMENT_LAYOUT MenuLayoutPaper(); +#endif break; case LFUN_LAYOUT_QUOTES: +#ifdef USE_OLD_DOCUMENT_LAYOUT MenuLayoutQuotes(); +#endif break; case LFUN_LAYOUT_PREAMBLE: @@ -1420,26 +1577,22 @@ string LyXFunc::Dispatch(int ac, MenuInsertLabel(argument.c_str()); break; - case LFUN_REF_CREATE: - { - InsetCommandParams p( "ref" ); - owner->getDialogs()->createRef( p.getAsString() ); - } - break; - case LFUN_REF_INSERT: - { - InsetCommandParams p; - p.setFromString( argument ); + if (argument.empty()) { + InsetCommandParams p("ref"); + owner->getDialogs()->createRef(p.getAsString()); + } else { + InsetCommandParams p; + p.setFromString(argument); + + InsetRef * inset = new InsetRef(p); + if (!owner->view()->insertInset(inset)) + delete inset; + else + owner->view()->updateInset(inset, true); + } + break; - InsetRef * inset = new InsetRef( p ); - if (!owner->view()->insertInset(inset)) - delete inset; - else - owner->view()->updateInset( inset, true ); - } - break; - case LFUN_REF_BACK: { owner->view()->restorePosition(); @@ -1467,11 +1620,7 @@ string LyXFunc::Dispatch(int ac, break; case LFUN_MENU_OPEN_BY_NAME: -#ifdef NEW_MENUBAR owner->getMenubar()->openByName(argument); -#else - owner->getMenus()->openByName(argument); -#endif break; // RVDK_PATCH_5 case LFUN_SPELLCHECK: @@ -2069,11 +2218,8 @@ string LyXFunc::Dispatch(int ac, cur_value = par->spacing.getValue(); } -#ifdef HAVE_SSTREAM istringstream istr(argument); -#else - istrstream istr(argument.c_str()); -#endif + string tmp; istr >> tmp; Spacing::Space new_spacing = cur_spacing; @@ -2369,6 +2515,24 @@ string LyXFunc::Dispatch(int ac, } break; + case LFUN_GOTO_PARAGRAPH: + { + istringstream istr(argument); + + int id; + istr >> id; + LyXParagraph * par = owner->view()->text->GetParFromID(id); + + // Set the cursor + owner->view()->text->SetCursor(owner->view(), par, 0); + owner->view()->setState(); + owner->showState(); + + // Recenter screen + owner->view()->center(); + } + break; + case LFUN_APROPOS: case LFUN_GETTIP: { @@ -2840,6 +3004,22 @@ string LyXFunc::Dispatch(int ac, } break; + case LFUN_SCREEN_FONT_UPDATE: + { + // handle the screen font changes. + // + lyxrc.set_font_norm_type(); + fontloader.update(); + // Of course we should only do the resize and the textcache.clear + // if values really changed...but not very important right now. (Lgb) + // All buffers will need resize + bufferlist.resize(); + // We also need to empty the textcache so that + // the buffer will be formatted correctly after + // a zoom change. + textcache.clear(); + } + case LFUN_SET_COLOR: { string lyx_name, x11_name; @@ -3027,12 +3207,13 @@ void LyXFunc::MenuNew(bool fromTemplate) } } } else { - s = lyxrc.document_path + "newfile" + tostr(++newfile_number); + s = AddPath(lyxrc.document_path, + "newfile" + tostr(++newfile_number)); FileInfo fi(s); while (bufferlist.exists(s) || fi.readable()) { ++newfile_number; - s = lyxrc.document_path + "newfile" + - tostr(newfile_number); + s = AddPath(lyxrc.document_path, + "newfile" + tostr(newfile_number)); fi.newFile(s); } }