void BF_GUI_Text::Find(char *pc_Sample, uint32 i_StartLine, uint32 i_StartCol) { uint32 iColumn = i_StartCol; BString *poString; char cSample[256]; bool bFound = false; BF_GUI_MessageBox *po_Message; ClearMatch(); if (pc_Sample == NULL) { FromUtf8(poMatch->String(),cSample); } else { FromUtf8(pc_Sample,cSample); } for(int32 i = i_StartLine; i < ploString->CountItems();i++) { poString = (BString *) ploString->ItemAt(i); if (poString->FindFirst(cSample,iColumn) != B_ERROR) { iMatchLine = i; bFound = true; break; }; iColumn = 0; }; if (bFound) { if (pc_Sample != NULL) { if (poMatch != NULL) delete(poMatch); poMatch = new BString(pc_Sample); }; bDrawSel = true; BRect oRect = Bounds(); float y = iMatchLine * poSysSetup->oFontNode.fHeight; ScrollTo(oRect.left,y); iStartSel = iColumn; DrawPage(); } else { bDrawSel = false; if (i_StartLine) { po_Message = new BF_GUI_MessageBox(BRect(30,30,300,150),"Error","Not more samles found!",Parent(),"Ok"); } else { po_Message = new BF_GUI_MessageBox(BRect(30,30,300,150),"Error","The sample is not found in this file!",Parent(),"Ok"); } Parent()->AddChild(po_Message); }; };
Speller *sGetSpeller(int lang) { static ArrayMap<int, Speller> speller; int q = speller.Find(lang); if(q < 0) { String pp = spell_path; DoSpellerPath(pp, GetExeDirFile("scd")); DoSpellerPath(pp, ConfigFile("scd")); pp << spell_path << ';' << getenv("LIB") << ';' << getenv("PATH") << ';'; String path = GetFileOnPath(ToLower(LNGAsText(lang)) + ".udc", pp); if(IsNull(path)) path = GetFileOnPath(ToLower(LNGAsText(lang)) + ".scd", pp); if(IsNull(path)) return NULL; FileIn in(path); if(!in) return NULL; q = speller.GetCount(); Speller& f = speller.Add(lang); FileIn user(sUserFile(lang)); while(!user.IsEof()) { String s = user.GetLine(); if(!s.IsEmpty()) f.user.Add(FromUtf8(s)); } if(in.Get() != 255) f.SetOld(LoadFile(path)); else { f.path = path; int n = in.GetL(); LLOG("Found scd file " << path << " blocks " << n); if(n > 0 && n < 100000) { for(int i = 0; i < n; i++) { SpellBlock& b = f.block.Add(); b.first = in.Get(in.Get()); b.ctrl_len = in.GetL(); b.text_len = in.GetL(); } if(in.IsEof()) f.block.Clear(); else { int off = (int)in.GetPos(); for(int i = 0; i < n; i++) { SpellBlock& b = f.block[i]; b.offset = off; off += b.ctrl_len + b.text_len; } } } } } return &speller[q]; }
NAMESPACE_UPP static void sLoadBom(Stream& in, String *t, WString *wt, byte def_charset) { if(in.IsOpen()) { String s; if(in.GetLeft() > 3) { word header = in.Get16le(); if(header == 0xfffe || header == 0xfeff) { int n = (int)in.GetLeft() / 2; WStringBuffer ws(n); ws.SetLength(in.Get(~ws, 2 * n) / 2); if(header == 0xfffe) EndianSwap((word *)~ws, ws.GetCount()); if(wt) *wt = ws; else *t = FromUnicode(ws); return; } int c = in.Get(); if(c < 0) return; byte *h = (byte *)&header; if(h[0] == 0xef && h[1] == 0xbb && c == 0xbf) { if(wt) *wt = FromUtf8(LoadStream(in)); else *t = ToCharset(CHARSET_DEFAULT, LoadStream(in), CHARSET_UTF8); return; } s.Cat(h, 2); s.Cat(c); } s.Cat(LoadStream(in)); if(wt) *wt = ToUnicode(s, def_charset); else *t = ToCharset(CHARSET_DEFAULT, s, def_charset); return; } return; }
bool HelpWindow::GoTo0(const String& link) { if(IsNull(link) || current_link == link) return true; Topic t = AcquireTopic(link); SetBar(); if(!IsNull(t.text)) { label = t.label; topic = t.link; Title(FromUtf8(t.title)); RichText txt = ParseQTF(t.text); FinishText(txt); view.Pick(pick(txt), zoom); view.GotoLabel(label, true); current_link = link; tree.FindSetCursor(topic); return true; } return false; }
int LineEdit::GetGPos(int ln, int cl) const { ln = minmax(ln, 0, line.GetCount() - 1); const String& stxt = line[ln].text; const char *s = stxt; const char *e = stxt.End(); const char *b = s; int gl = 0; int wpos = 0; while(s < e) { if(*s == '\t') gl = (gl + tabsize) / tabsize * tabsize; else if((byte)*s < 128) gl++; else { WString txt = FromUtf8(s, int(e - s)); const wchar *b = txt; const wchar *e = txt.End(); const wchar *s = b; while(s < e) { if(*s == '\t') gl = (gl + tabsize) / tabsize * tabsize; else gl += 1 + IsCJKIdeograph(*s); if(cl < gl) break; s++; } wpos = int(s - b); break; } if(cl < gl) break; s++; } return GetPos(ln, int(s - b) + wpos); }
void RichQtfParser::Parse(const char *qtf, int _accesskey) { accesskey = _accesskey; term = qtf; while(*term) { if(Key('[')) { Flush(); fstack.Add(format); for(;;) { int c = *term; if(!c) Error("Unexpected end of text"); term++; if(c == ' ' || c == '\n') break; switch(c) { case 's': { Uuid id; c = *term; if(Key('\"') || Key('\'')) id = target.GetStyleId(GetText(c)); else { int i = ReadNumber(); if(i >= 0 && i < styleid.GetCount()) id = styleid[i]; else id = RichStyle::GetDefaultId(); } const RichStyle& s = target.GetStyle(id); bool p = format.newpage; int lng = format.language; (RichPara::Format&) format = s.format; format.styleid = id; format.language = lng; format.newpage = p; break; } case '/': format.Italic(!format.IsItalic()); break; case '*': format.Bold(!format.IsBold()); break; case '_': format.Underline(!format.IsUnderline()); break; case 'T': format.NonAntiAliased(!format.IsNonAntiAliased()); break; case '-': format.Strikeout(!format.IsStrikeout()); break; case 'c': format.capitals = !format.capitals; break; case 'd': format.dashed = !format.dashed; break; case '`': format.sscript = format.sscript == 1 ? 0 : 1; break; case ',': format.sscript = format.sscript == 2 ? 0 : 2; break; case '^': format.link = GetText('^'); break; case 'I': format.indexentry = FromUtf8(GetText(';')); break; case '+': format.Height(GetNumber()); break; case '@': format.ink = GetColor(); break; case '$': format.paper = GetColor(); break; case 'A': format.Face(Font::ARIAL); break; case 'R': format.Face(Font::ROMAN); break; case 'C': format.Face(Font::COURIER); break; case 'G': format.Face(Font::STDFONT); break; case 'S': #ifdef PLATFORM_WIN32 format.Face(Font::SYMBOL); #endif break; case '.': { int n = GetNumber(); if(n >= Font::GetFaceCount()) Error("Invalid face number"); format.Face(n); break; } case '!': { String fn = GetText('!'); int i = Font::FindFaceNameIndex(fn); if(i < 0) i = Font::ARIAL; format.Face(i); } break; case '{': { String cs = GetText('}'); if(cs.GetLength() == 1) { int c = *cs; if(c == '_') format.charset = CHARSET_UTF8; if(c >= '0' && c <= '8') format.charset = c - '0' + CHARSET_WIN1250; if(c >= 'A' && c <= 'Z') format.charset = c - '0' + CHARSET_ISO8859_1; } else { for(int i = 0; i < CharsetCount(); i++) if(stricmp(CharsetName(i), cs) == 0) { format.charset = i; break; } } break; } case '%': { String h; if(*term == '-') { format.language = 0; term++; } else if(*term == '%') { format.language = LNG_ENGLISH; term++; } else { while(*term && h.GetLength() < 5) h.Cat(*term++); format.language = LNGFromText(h); } break; } case 'g': format.Face(Font::STDFONT); format.Height(GetRichTextScreenStdFontHeight()); break; default: if(c >= '0' && c <= '9') { format.Height(QTFFontHeight[c - '0']); break; } switch(c) { case ':': format.label = GetText(':'); break; case '<': format.align = ALIGN_LEFT; break; case '>': format.align = ALIGN_RIGHT; break; case '=': format.align = ALIGN_CENTER; break; case '#': format.align = ALIGN_JUSTIFY; break; case 'l': format.lm = GetNumber(); break; case 'r': format.rm = GetNumber(); break; case 'i': format.indent = GetNumber(); break; case 'b': format.before = GetNumber(); break; case 'a': format.after = GetNumber(); break; case 'P': format.newpage = !format.newpage; break; case 'k': format.keep = !format.keep; break; case 'K': format.keepnext = !format.keepnext; break; case 'H': format.ruler = GetNumber(); break; case 'h': format.rulerink = GetColor(); break; case 'L': format.rulerstyle = GetNumber(); break; case 'Q': format.orphan = !format.orphan; break; case 'n': format.before_number = GetText(';'); break; case 'm': format.after_number = GetText(';'); break; case 'N': { memset(format.number, 0, sizeof(format.number)); format.reset_number = false; int i = 0; while(i < 8) { int c; if(Key('-')) c = RichPara::NUMBER_NONE; else if(Key('1')) c = RichPara::NUMBER_1; else if(Key('0')) c = RichPara::NUMBER_0; else if(Key('a')) c = RichPara::NUMBER_a; else if(Key('A')) c = RichPara::NUMBER_A; else if(Key('i')) c = RichPara::NUMBER_i; else if(Key('I')) c = RichPara::NUMBER_I; else break; format.number[i++] = c; } if(Key('!')) format.reset_number = true; break; } case 'o': format.bullet = RichPara::BULLET_ROUND; format.indent = 150; break; case 'O': if(Key('_')) format.bullet = RichPara::BULLET_NONE; else { int c = *term++; if(!c) Error("Unexpected end of text"); format.bullet = c == '1' ? RichPara::BULLET_ROUNDWHITE : c == '2' ? RichPara::BULLET_BOX : c == '3' ? RichPara::BULLET_BOXWHITE : c == '9' ? RichPara::BULLET_TEXT : RichPara::BULLET_ROUND; } break; case 'p': switch(*term++) { case 0: Error("Unexpected end of text"); case 'h': format.linespacing = RichPara::LSP15; break; case 'd': format.linespacing = RichPara::LSP20; break; default: format.linespacing = RichPara::LSP10; } break; case 't': if(*term == 'P') { term++; format.newhdrftr = true; format.header_qtf = GetText2('^', '^'); format.footer_qtf = GetText2('^', '^'); } else if(IsDigit(*term)) format.tabsize = ReadNumber(); break; case '~': { if(Key('~')) format.tab.Clear(); else { RichPara::Tab tab; Key('<'); if(Key('>')) tab.align = ALIGN_RIGHT; if(Key('=')) tab.align = ALIGN_CENTER; if(Key('.')) tab.fillchar = 1; if(Key('-')) tab.fillchar = 2; if(Key('_')) tab.fillchar = 3; int rightpos = Key('>') ? RichPara::TAB_RIGHTPOS : 0; tab.pos = rightpos | ReadNumber(); format.tab.Add(tab); } } break; default: continue; } } } SetFormat(); } else if(Key(']')) { Flush(); if(fstack.GetCount()) { format = fstack.Top(); fstack.Drop(); } else Error("Unmatched ']'"); } else if(Key2('{')) { if(oldtab) Error("{{ in ++ table"); if(text.GetLength() || paragraph.GetCount()) EndPart(); table.Add(); int r = IsDigit(*term) ? ReadNumber() : 1; Table().AddColumn(r); while(Key(':')) Table().AddColumn(ReadNumber()); if(breakpage) { RichTable& tab = Table(); RichTable::Format tabformat = tab.GetFormat(); tabformat.newpage = true; tab.SetFormat(tabformat); breakpage = false; } TableFormat(); SetFormat(); } else if(Key2('}')) { if(oldtab) Error("}} in ++ table"); FinishTable(); } else if(Key2('+')) if(oldtab) FinishOldTable(); else { Flush(); if(text.GetLength() || paragraph.GetCount()) EndPart(); Tab& b = table.Add(); b.rown.Add(0); b.hspan = 1; b.Old(); oldtab = true; } else if(Key2('|')) FinishCell(); else if(Key2('-')) { FinishCell(); table.Top().rown.Add(0); } else if(Key2(':')) { if(!oldtab) FinishCell(); TableFormat(oldtab); } else if(Key2('^')) { EndPart(); breakpage = true; } else if(Key2('@')) { ReadObject(); } else if(Key2('@', '$')) { String xu; while(isxdigit(*term)) xu.Cat(*term++); int c = stou(~xu, NULL, 16); if(c >= 32) Cat(c); if(*term == ';') term++; SetFormat(); } else if(Key2('^', 'H')) target.SetHeaderQtf(GetText2('^', '^')); else if(Key2('^', 'F')) target.SetFooterQtf(GetText2('^', '^')); else if(Key2('{', ':')) { Flush(); String field = GetText(':'); String param = GetText(':'); Id fid(field); if(RichPara::fieldtype().Find(fid) >= 0) paragraph.Cat(fid, param, format); Key('}'); } else if(Key('&')) { SetFormat(); EndPart(); } else if(Key2('$')) { Flush(); int i = GetNumber(); Uuid id; RichStyle style; style.format = format; if(Key(',')) stylenext.At(i, 0) = GetNumber(); else stylenext.At(i, 0) = i; if(Key('#')) { String xu; while(isxdigit(*term)) xu.Cat(*term++); if(xu.GetLength() != 32) Error("Invalid UUID !"); id = ScanUuid(xu); } else if(i) id = Uuid::Create(); else id = RichStyle::GetDefaultId(); if(Key(':')) style.name = GetText(']'); if(fstack.GetCount()) { format = fstack.Top(); fstack.Drop(); } target.SetStyle(id, style); styleid.At(i, RichStyle::GetDefaultId()) = id; if(id == RichStyle::GetDefaultId()) { bool p = format.newpage; int lng = format.language; (RichPara::Format&) format = style.format; format.styleid = id; format.language = lng; format.newpage = p; } } else if(*term == '_') { SetFormat(); text.Cat(160); term++; } else if(Key2('-', '|')) { SetFormat(); text.Cat(9); } else if(*term == '\1') { if(istable) EndPart(); SetFormat(); const char *b = ++term; for(; *term && *term != '\1'; term++) { if((byte)*term == '\n') { text.Cat(ToUnicode(b, (int)(term - b), format.charset)); EndPart(); b = term + 1; } if((byte)*term == '\t') { text.Cat(ToUnicode(b, (int)(term - b), format.charset)); text.Cat(9); b = term + 1; } } text.Cat(ToUnicode(b, (int)(term - b), format.charset)); if(*term == '\1') term++; } else { if(!Key('`')) Key('\\'); if((byte)*term >= ' ') { SetFormat(); do { if(istable) EndPart(); if(format.charset == CHARSET_UTF8) { word code = (byte)*term++; if(code <= 0x7F) Cat(code); else if(code <= 0xDF) { if(*term == '\0') break; int c0 = (byte)*term++; if(c0 < 0x80) Error("Invalid UTF-8 sequence"); Cat(((code - 0xC0) << 6) + c0 - 0x80); } else if(code <= 0xEF) { int c0 = (byte)*term++; int c1 = (byte)*term++; if(c0 < 0x80 || c1 < 0x80) Error("Invalid UTF-8 sequence"); Cat(((code - 0xE0) << 12) + ((c0 - 0x80) << 6) + c1 - 0x80); } else Error("Invalid UTF-8 sequence"); } else Cat(ToUnicode((byte)*term++, format.charset)); } while((byte)*term >= 128 || s_nodeqtf[(byte)*term]); } else if(*term) term++; } } // if(paragraph.GetCount() == 0) // TRC 11/02/15: kills formatting of last paragraph in text // SetFormat(); if(oldtab) FinishOldTable(); else while(table.GetCount()) FinishTable(); EndPart(); FlushStyles(); }
void RichPara::UnpackParts(Stream& in, const RichPara::CharFormat& chrstyle, Array<RichPara::Part>& part, const Array<RichObject>& obj, int& oi) { part.Add(); part.Top().format = format; int c; while((c = in.Term()) >= 0) if(c < 31 && c != 9 && c != FIELD) { do switch(in.Get()) { case BOLD0: format.NoBold(); break; case BOLD1: format.Bold(); break; case BOLDS: format.Bold(chrstyle.IsBold()); break; case ITALIC0: format.NoItalic(); break; case ITALIC1: format.Italic(); break; case ITALICS: format.Italic(chrstyle.IsItalic()); break; case UNDERLINE0: format.NoUnderline(); break; case UNDERLINE1: format.Underline(); break; case UNDERLINES: format.Underline(chrstyle.IsUnderline()); break; case STRIKEOUT0: format.NoStrikeout(); break; case STRIKEOUT1: format.Strikeout(); break; case STRIKEOUTS: format.Strikeout(chrstyle.IsStrikeout()); break; case CAPITALS0: format.capitals = false; break; case CAPITALS1: format.capitals = true; break; case CAPITALSS: format.capitals = chrstyle.capitals; break; case DASHED0: format.dashed = false; break; case DASHED1: format.dashed = true; break; case DASHEDS: format.dashed = chrstyle.dashed; break; case SSCRIPT: format.sscript = in.Get(); if(format.sscript == 3) format.sscript = chrstyle.sscript; break; case FACE: c = in.Get16(); format.Face(c == 0xffff ? chrstyle.GetFace() : c); break; case HEIGHT: c = in.Get16(); format.Height(c == 0xffff ? chrstyle.GetHeight() : c); break; case LINK: in % format.link; break; case INDEXENTRY: in % format.indexentry; break; case INK: in % format.ink; break; case PAPER: in % format.paper; break; case LANGUAGE: format.language = in.Get32(); break; case EXT: switch(in.Get()) { case NONAA0: format.NonAntiAliased(false); break; case NONAA1: format.NonAntiAliased(true); break; case NONAAS: format.NonAntiAliased(chrstyle.IsNonAntiAliased()); break; } } while((c = in.Term()) < 31 && c != 9 && c != FIELD && c >= 0); if(part.Top().text.GetLength()) part.Add(); part.Top().format = format; } else if(in.Term() == FIELD) { RichPara::Format pformat = format; if(part.Top().text.GetLength()) { part.Add(); part.Top().format = pformat; } in.Get(); Part& p = part.Top(); String id; in % id; p.field = id; in % p.fieldparam; String s; in % s; StringStream sn(s); UnpackParts(sn, chrstyle, p.fieldpart, obj, oi); part.Add(); part.Top().format = format = pformat; } else if(in.Term() == OBJECT) { if(part.Top().text.GetLength()) { part.Add(); part.Top().format = format; } part.Top().object = obj[oi++]; part.Top().format = format; part.Add(); part.Top().format = format; in.Get(); } else { StringBuffer b; b.Reserve(512); while(in.Term() >= 32 || in.Term() == 9) b.Cat(in.Get()); part.Top().text.Cat(FromUtf8(~b)); } if(part.Top().text.GetLength() == 0 && part.Top().IsText()) part.Drop(); }
void Ctrl::EventProc(XWindow& w, XEvent *event) { GuiLock __; eventid++; Ptr<Ctrl> _this = this; bool pressed = false; int count = 1; switch(event->type) { case NoExpose: LLOG("NoExpose serial " << event->xnoexpose.serial); break; case GraphicsExpose: LLOG("GraphicsExpose serial " << event->xgraphicsexpose.serial); case Expose: { XExposeEvent& e = event->xexpose; w.exposed = true; LLOG("Expose " << RectC(e.x, e.y, e.width, e.height)); Invalidate(w, RectC(e.x, e.y, e.width, e.height)); } return; case ConfigureNotify: { XConfigureEvent& e = event->xconfigure; int x, y; Window dummy; // 01/12/2007 - mdelfede // added support for windowed controls // if(top) // XTranslateCoordinates(Xdisplay, top->window, Xroot, 0, 0, &x, &y, &dummy); if(top) { Window DestW = (parent ? GetParentWindow() : Xroot); XTranslateCoordinates(Xdisplay, top->window, DestW, 0, 0, &x, &y, &dummy); Rect rect = RectC(x, y, e.width, e.height); LLOG("CongigureNotify " << rect); if(GetRect() != rect) SetWndRect(rect); // Synchronizes native windows (NOT the main one) } SyncNativeWindows(); // 01/12/2007 - END } return; default: if(!IsEnabled()) return; } LTIMING("XUserInput"); switch(event->type) { case FocusIn: if(w.xic) XSetICFocus(w.xic); break; case FocusOut: if(w.xic) XUnsetICFocus(w.xic); break; case KeyPress: pressed = true; LLOG("event type:" << event->type << " state:" << event->xkey.state << "keycode:" << event->xkey.keycode); for(;;) { XEvent ev1[1], ev2[1]; bool hasev2 = false; if(!IsWaitingEvent()) break; do XNextEvent(Xdisplay, ev1); while(ev1->type == NoExpose && IsWaitingEvent()); LLOG("ev1 type:" << ev1->type << " state:" << ev1->xkey.state << "keycode:" << ev1->xkey.keycode); if(ev1->type == KeyPress) *ev2 = *ev1; else { if(ev1->type != KeyRelease || ev1->xkey.state != event->xkey.state || ev1->xkey.keycode != event->xkey.keycode || !IsWaitingEvent()) { XPutBackEvent(Xdisplay, ev1); break; } do XNextEvent(Xdisplay, ev2); while(ev2->type == NoExpose && IsWaitingEvent()); LLOG("ev2 type:" << ev2->type << " state:" << ev2->xkey.state << "keycode:" << ev2->xkey.keycode); hasev2 = true; } if(ev2->type != KeyPress || ev2->xkey.state != event->xkey.state || ev2->xkey.keycode != event->xkey.keycode) { if(hasev2) XPutBackEvent(Xdisplay, ev2); XPutBackEvent(Xdisplay, ev1); break; } else { XFilterEvent(ev1, None); if(hasev2) XFilterEvent(ev2, None); } count++; } case KeyRelease: { mousePos = Point(event->xkey.x_root, event->xkey.y_root); char buff[128]; Xeventtime = event->xkey.time; LLOG("Key Xeventtime: " << Xeventtime << " count:" << count); KeySym keysym; int chr = 0; WString wtext; if(pressed && w.xic) { Status status; int len = Xutf8LookupString(w.xic, &event->xkey, buff, sizeof(buff), &keysym, &status); buff[len] = 0; if(status == XLookupChars || status == XLookupBoth) { chr = FromUtf8(buff, len)[0]; if(status == XLookupChars) wtext = FromUtf8(buff, len); } else if(status != XLookupKeySym && status != XLookupBoth) keysym = 0; } else { int len = XLookupString(&event->xkey, buff, sizeof(buff), &keysym, NULL); buff[len] = 0; chr = FromUtf8(buff, len)[0]; if(len > 1) wtext = FromUtf8(buff, len); } if(keysym == XK_Control_L || keysym == XK_Control_R) { keysym = XK_Control_L; if(pressed) sKbdState |= ControlMask; else sKbdState &= ~ControlMask; } if(keysym == XK_Shift_L || keysym == XK_Shift_R) { keysym = XK_Shift_L; if(pressed) sKbdState |= ShiftMask; else sKbdState &= ~ShiftMask; } if(keysym == XK_Meta_L || keysym == XK_Meta_R || keysym == XK_Alt_L || keysym == XK_Alt_R || keysym == XK_Super_L || keysym == XK_Super_R || keysym == XK_Hyper_L || keysym == XK_Hyper_R || keysym == XK_ISO_Prev_Group) { keysym = XK_Meta_L; if(pressed) sKbdState |= Mod1Mask; else sKbdState &= ~Mod1Mask; } LLOG("KeySym:" << FormatIntHex(keysym) << " " << (char)keysym << " " << count); dword up = pressed ? 0 : K_KEYUP; static struct { KeySym keysym; dword key; } tab[] = { { XK_ISO_Left_Tab, K_TAB|K_SHIFT }, { XK_BackSpace, K_BACKSPACE }, { XK_Tab, K_TAB }, { XK_Return, K_ENTER }, { XK_KP_Enter, K_ENTER }, { XK_Escape, K_ESCAPE }, { XK_space, K_SPACE }, { XK_KP_Space, K_SPACE }, { XK_KP_Tab, K_TAB }, { XK_KP_Enter, K_ENTER }, { XK_KP_F1, K_F1 }, { XK_KP_F2, K_F2 }, { XK_KP_F3, K_F3 }, { XK_KP_F4, K_F4 }, { XK_KP_Home, K_HOME }, { XK_KP_Left, K_LEFT }, { XK_KP_Up, K_UP }, { XK_KP_Right, K_RIGHT }, { XK_KP_Down, K_DOWN }, { XK_KP_Page_Up, K_PAGEUP }, { XK_KP_Page_Down, K_PAGEDOWN }, { XK_KP_End, K_END }, { XK_KP_Begin, K_HOME }, { XK_KP_Insert, K_INSERT }, { XK_KP_Delete, K_DELETE }, }; for(int i = 0; i < __countof(tab); i++) if(tab[i].keysym == keysym) { DispatchKey(KEYtoK(tab[i].key)|up, count); return; } if(GetShift() && chr == 0) { static dword k[] = { 41, 33, 64, 35, 36, 37, 94, 38, 42, 40 }; for(int i = 0; i < 10; i++) if(keysym == k[i]) { DispatchKey(KEYtoK(i + K_0)|up, count); return; } } if(keysym >= 48 && keysym <= 57 && chr == 0) { DispatchKey(KEYtoK(keysym - 48 + K_0)|up, count); return; } if(chr >= 1 && chr < 32) { DispatchKey(KEYtoK(chr - 1 + K_CTRL_A)|up, count); return; } if(keysym >= 0xff80 && keysym <= 0xffb9 && chr) { DispatchKey(KEYtoK(chr)|up, count); return; } if(keysym >= 0xff00 && chr < 128 || (GetCtrl() || GetAlt()) && keysym >= 0x20 && keysym < 0x7f) { if(keysym >= 'a' && keysym <= 'z') keysym = keysym - 'a' + 'A'; DispatchKey(KEYtoK(keysym|K_DELTA)|up, count); return; } if((chr == 32 || chr == 9 || chr == 13) && !pressed) DispatchKey(chr|K_KEYUP, count); if(chr && pressed) { DispatchKey(chr, count); for(int ii = 1; ii < wtext.GetLength(); ii++) DispatchKey(wtext[ii], count); } } break; case ButtonPress: { if(!HasWndFocus() && !popup) SetWndFocus(); ClickActivateWnd(); mousePos = Point(event->xbutton.x_root, event->xbutton.y_root); ReleaseGrab(); XButtonEvent& e = event->xbutton; sModState = e.state; Xeventtime = e.time; if(ignoreclick) break; Point p = Point(e.x, e.y); dword action = DOWN; if((dword)e.time - (dword)Xbuttontime < 800) { action = DOUBLE; Xbuttontime = Xeventtime - 0x80000000; } else { Xbuttontime = e.time; Xbuttonpos = mousePos; } switch(e.button) { case Button1: sModState |= Button1Mask; DispatchMouse(LEFT|action, p, 0); break; case Button2: sModState |= Button2Mask; if(Xbuttons < 3) DispatchMouse(RIGHT|action, p, 0); else DispatchMouse(MIDDLE|action, p, 0); break; case Button3: sModState |= Button3Mask; DispatchMouse(RIGHT|action, p, 0); break; } if(_this) PostInput(); } break; case ButtonRelease: { mousePos = Point(event->xbutton.x_root, event->xbutton.y_root); XButtonEvent& e = event->xbutton; sModState = e.state; Xeventtime = e.time; Point p = Point(e.x, e.y); switch(e.button) { case Button1: sModState &= ~Button1Mask; break; case Button2: sModState &= ~Button2Mask; break; case Button3: sModState &= ~Button3Mask; break; } if(ignoreclick) EndIgnore(); else switch(e.button) { case Button1: DispatchMouse(LEFTUP, p, 0); break; case Button2: if(Xbuttons < 3) DispatchMouse(RIGHTUP, p, 0); else DispatchMouse(MIDDLEUP, p, 0); break; case Button3: DispatchMouse(RIGHTUP, p, 0); break; case Button4: DispatchMouse(MOUSEWHEEL, p, 120); break; case Button5: DispatchMouse(MOUSEWHEEL, p, -120); break; } if(_this) PostInput(); } break; case MotionNotify: while(XCheckWindowEvent(Xdisplay, top->window, PointerMotionMask, event)); EndIgnore(); mousePos = Point(event->xmotion.x_root, event->xmotion.y_root); Xeventtime = event->xmotion.time; Point p = mousePos - Xbuttonpos; if(max(abs(p.x), abs(p.y)) > 4) Xbuttontime = Xeventtime - 0x80000000; sModState = event->xmotion.state; DispatchMouse(MOUSEMOVE, Point(event->xmotion.x, event->xmotion.y)); DoCursorShape(); break; } DropEvent(w, event); }
void Ctrl::IMCommit(GtkIMContext *context, gchar *str, gpointer user_data) { GuiLock __; AddEvent(user_data, EVENT_TEXT, FromUtf8(str), NULL); }
void XmlParser::Next() { nattr.Clear(); nattr1 = nattrval1 = Null; if(empty_tag) { empty_tag = false; type = XML_END; return; } type = Null; StringBuffer raw_text; for(;;) { if(*term == '\0') { type = XML_EOF; return; } if(*term == '<') { if(term[1] == '!' && term[2] == '[' && term[3] == 'C' && term[4] == 'D' && term[5] == 'A' && term[6] == 'T' && term[7] == 'A' && term[8] == '[') { // ![CDATA[ term += 9; for(;;) { if(*term == '\0') throw XmlError("Unterminated CDATA"); if(term[0] == ']' && term[1] == ']' && term[2] == '>') { // ]]> term += 3; break; } if(*term == '\n') line++; raw_text.Cat(*term++); } type = XML_TEXT; continue; } else break; } if(*term == '\n') line++; if(*term == '&') { Ent(raw_text); type = XML_TEXT; } else { if((byte)*term > ' ') type = XML_TEXT; raw_text.Cat(*term++); } } cdata = FromUtf8(String(raw_text)).ToString(); if(cdata.GetCount() && (npreserve || preserveall)) type = XML_TEXT; if(type == XML_TEXT) return; term++; if(*term == '!') { type = XML_DECL; term++; if(term[0] == '-' && term[1] == '-') { type = XML_COMMENT; term += 2; for(;;) { if(term[0] == '-' && term[1] == '-' && term[2] == '>') break; if(*term == '\0') throw XmlError("Unterminated comment"); if(*term == '\n') line++; tagtext.Cat(*term++); } term += 3; return; } bool intdt = false; for(;;) { if (*term == '[') intdt = true; if(*term == '>' && intdt == false) { term++; break; } if(intdt == true && term[0] == ']' && term[1] == '>') { tagtext.Cat(*term++); term++; break; } if(*term == '\0') throw XmlError("Unterminated declaration"); if(*term == '\n') line++; tagtext.Cat(*term++); } } else if(*term == '?') { type = XML_PI; term++; for(;;) { if(term[0] == '?' && term[1] == '>') { term += 2; return; } if(*term == '\0') throw XmlError("Unterminated processing info"); if(*term == '\n') line++; tagtext.Cat(*term++); } } else if(*term == '/') { type = XML_END; term++; const char *t = term; while(IsXmlNameChar(*term)) term++; tagtext = String(t, term); if(*term != '>') throw XmlError("Unterminated end-tag"); term++; } else { type = XML_TAG; const char *t = term; while(IsXmlNameChar(*term)) term++; tagtext = String(t, term); for(;;) { SkipWhites(); if(*term == '>') { term++; break; } if(term[0] == '/' && term[1] == '>') { cdata.Clear(); empty_tag = true; term += 2; break; } if(*term == '\0') throw XmlError("Unterminated tag"); const char *t = term++; while((byte)*term > ' ' && *term != '=' && *term != '>') term++; String attr(t, term); SkipWhites(); if(*term == '=') { term++; SkipWhites(); StringBuffer attrval; if(*term == '\"') ReadAttr(attrval, '\"'); else if(*term == '\'') ReadAttr(attrval, '\''); else while((byte)*term > ' ' && *term != '>' && *term != '/') if(*term == '&') Ent(attrval); else { const char *e = term; while((byte)*++e > ' ' && *e != '>' && *e != '&') ; attrval.Cat(term,(int) (e - term)); term = e; } if(attr == "xml:space" && attrval.GetLength() == 8 && !memcmp(~attrval, "preserve", 8)) npreserve = true; String aval = FromUtf8(~attrval, attrval.GetLength()).ToString(); if(IsNull(nattr1)) { nattr1 = attr; nattrval1 = aval; } else nattr.Add(attr, aval); } } } }