Example #1
0
void EscDraw::DrawSmartText(EscEscape& e)
{
	if(e.GetCount() < 3 || e.GetCount() > 7)
		e.ThrowError("wrong number of arguments in call to 'DrawSmartText'");
	int x = e.Int(0);
	int y = e.Int(1);
	int ii = 2;
	String text;
	if(ii < e.GetCount() && e[ii].IsArray())
		text = ToUtf8((WString)e[ii++]);
	int accesskey = ExtractAccessKey(text, text);
	Font font = StdFont().Height(11);
	if(ii < e.GetCount())
		font = FontEsc(e[ii++]);
	if(font.GetHeight() == 0)
#ifdef GUI_X11
		font.Height(12);
#else
		font.Height(11);
#endif
	Color color = SColorText;
	if(ii < e.GetCount())
		color = ColorEsc(e[ii++]);
	int cx = INT_MAX;
	if(ii < e.GetCount())
		cx = e.Int(ii++);
	::DrawSmartText(w, x, y, cx, text, font, color, accesskey);
}
Example #2
0
void RichPara::PackParts(Stream& out, const RichPara::CharFormat& chrstyle,
                         const Array<RichPara::Part>& part, CharFormat& cf,
                         Array<RichObject>& obj) const
{
	for(int i = 0; i < part.GetCount(); i++) {
		const Part& p = part[i];
		Charformat(out, cf, p.format, chrstyle);
		cf = p.format;
		if(p.field) {
			out.Put(FIELD);
			String s = ~p.field;
			out % s;
			s = p.fieldparam;
			out % s;
			StringStream oout;
			CharFormat subf = cf;
			PackParts(oout, chrstyle, p.fieldpart, subf, obj);
			s = oout;
			out % s;
		}
		else
		if(p.object) {
			obj.Add(p.object);
			out.Put(OBJECT);
		}
		else
			out.Put(ToUtf8(p.text));
	}
}
Example #3
0
void ChmDoc::FixPathCodepage(AutoFree& path, UINT& fileCP) {
    if (!path || HasData(path))
        return;

    AutoFree utf8Path(ToUtf8((unsigned char*)path.Get()));
    if (HasData(utf8Path)) {
        path.Set(utf8Path.StealData());
        fileCP = codepage;
    } else if (fileCP != codepage) {
        utf8Path.Set(ToUtf8((unsigned char*)path.Get(), fileCP));
        if (HasData(utf8Path)) {
            path.Set(utf8Path.StealData());
            codepage = fileCP;
        }
    }
}
Example #4
0
void XmlParser::Ent(StringBuffer& out)
{
	int outconst = 0;
	const char *t = ++term;
	if(*t == '#') {
		if(*++t == 'X' || *t == 'x') {
			for(byte c; (c = ctoi(*++t)) < 16; outconst = 16 * outconst + c)
				;
		}
		else {
			while(IsDigit(*t))
				outconst = 10 * outconst + *t++ - '0';
		}
		out.Cat(ToUtf8(outconst));
		if(*t == ';')
			t++;
		term = t;
		return;
	}
	const char *b = t;
	while(*t && *t != ';')
		t++;
	if(*t == ';') {
		int q = entity.Find(String(b, t));
		if(q >= 0) {
			out.Cat(entity[q]);
			term = t + 1;
			return;
		}
	}
	out.Cat('&');
}
Example #5
0
bool SpellWordRaw(const WString& wrd, int lang, Vector<String> *withdia)
{
	Speller *f = sGetSpeller(lang);
	if(!f)
		return true;
	if(f->data.GetCount())
		return f->CheckOld(wrd);
	String awrd = ToUpper(ToAscii(wrd).ToString());
	String t1 = ToUtf8(wrd);
	String t2 = ToUtf8(ToLower(wrd));
	for(int i = 0;; i++) {
		if(i + 1 >= f->block.GetCount() || awrd <= f->block[i + 1].first) {
			for(;;) {
				if(i >= f->block.GetCount())
					return f->user.Find(wrd) >= 0;;
				LLOG("Spell block " << i << ": " << f->block[i].first);
				const SpellBlock& b = f->block[i++];
				if(b.first > awrd) {
					LLOG("  --- end");
					return f->user.Find(wrd) >= 0;;
				}
				FileIn in(f->path);
				String ctrl = sZet(in, b.offset, b.ctrl_len);
				String text = sZet(in, b.offset + b.ctrl_len, b.text_len);
				in.Close();
				String w;
				const char *s = ctrl;
				const char *e = ctrl.End();
				const char *t = text;
				const char *te = text.End();
				while(s < e && t < te) {
					w.Trim(*s++);
					while(*t)
						w.Cat(*t++);
					if(w == t1 || w == t2)
						return true;
					if(withdia && t2 == ToLower(ToAscii(w.ToWString()).ToString()))
						withdia->Add(w);
					t++;
				}
			}
		}
	}
	return f->user.Find(wrd) >= 0;;
}
Example #6
0
String GetKeyDesc(dword key)
{
	String desc;
//	key &= 0xFFFF;

	if(key == 0)
		return desc;

	if(key & K_CTRL)  desc << t_("key\vCtrl+");
	if(key & K_ALT)   desc << t_("key\vAlt+");
	if(key & K_SHIFT) desc << t_("key\vShift+");
	if(key & K_KEYUP) desc << t_("key\vUP ");


	key &= ~(K_CTRL | K_ALT | K_SHIFT | K_KEYUP);
	if(key < K_DELTA && key > 32 && key != K_DELETE)
		return desc + ToUtf8((wchar)key);
	if(key >= K_NUMPAD0 && key <= K_NUMPAD9)
		desc << "Num " << (char)(key - K_NUMPAD0 + '0');
	else if(key >= K_0 && key <= K_9)
		desc << (char)('0' + key - K_0);
	else if(key >= K_A && key <= K_Z)
		desc << (char)('A' + key - K_A);
	else if(key >= K_F1 && key <= K_F12)
		desc << Format("F%d", (int)key - K_F1 + 1);
	else {
		static struct {
			dword key;
			const char *name;
		} nkey[] = {
			{ K_TAB, tt_("key\vTab") }, { K_SPACE, tt_("key\vSpace") },
			{ K_RETURN, tt_("key\vEnter") }, { K_BACKSPACE, tt_("key\vBackspace") },
			{ K_CAPSLOCK, tt_("key\vCaps Lock") }, { K_ESCAPE, tt_("key\vEsc") },
			{ K_PAGEUP, tt_("key\vPage Up") }, { K_PAGEDOWN, tt_("key\vPage Down") },
			{ K_END, tt_("key\vEnd") }, { K_HOME, tt_("key\vHome") },
			{ K_LEFT, tt_("key\vLeft") }, { K_UP, tt_("key\vUp") },
			{ K_RIGHT, tt_("key\vRight") }, { K_DOWN, tt_("key\vDown") },
			{ K_INSERT, tt_("key\vInsert") }, { K_DELETE, tt_("key\vDelete") },{ K_BREAK, tt_("key\vBreak") },
			{ K_MULTIPLY, tt_("key\vNum[*]") }, { K_ADD, tt_("key\vNum[+]") }, { K_SUBTRACT, tt_("key\vNum[-]") }, { K_DIVIDE, tt_("key\vNum[/]") },
			{ K_ALT_KEY, tt_("key\vAlt") }, { K_SHIFT_KEY, tt_("key\vShift") }, { K_CTRL_KEY, tt_("key\vCtrl") },
			{ K_PLUS, tt_("key\v[+]") }, { K_MINUS, tt_("key\v[-]") }, { K_COMMA, tt_("key\v[,]") }, { K_PERIOD, tt_("key\v[.]") },
			{ K_SEMICOLON, tt_("key\v[;]") }, { K_SLASH, tt_("key\v[/]") }, { K_GRAVE, tt_("key\v[`]") }, { K_LBRACKET, tt_("key\v[[]") },
			{ K_BACKSLASH, tt_("key\v[\\]") }, { K_RBRACKET, tt_("key\v[]]") }, { K_QUOTEDBL, tt_("key\v[']") },
			{ 0, NULL }
		};
		for(int i = 0; nkey[i].key; i++)
			if(nkey[i].key == key) {
				desc << GetLngString(nkey[i].name);
				return desc;
			}
		desc << Format("%04x", (int)key);
	}
	return desc;
}
Example #7
0
void SIC_GetSmartTextSize(EscEscape& e)
{
	if(e.GetCount() < 1 || e.GetCount() > 2)
		e.ThrowError("wrong number of arguments in call to 'GetTextSize'");
	e.CheckArray(0);
	String text = ToUtf8((WString)(e[0]));
	ExtractAccessKey(text, text);
	Font font = StdFont();
	if(e.GetCount() > 1)
		font = FontEsc(e[1]);
	e = EscSize(GetSmartTextSize(text, font));
}
Example #8
0
void RichEdit::SpellerAdd(const WString& w, int lang)
{
	if(!SpellWord(w, w.GetCount(), lang)) {
		Speller *f = sGetSpeller(lang);
		if(f) {
			FileAppend fa(sUserFile(lang));
			fa.PutLine(ToUtf8(w));
			f->user.Add(w);
			speller_cache.Clear();
		}
	}
}
Example #9
0
void EscDraw::DrawQtf(EscEscape& e)
{
	if(e.GetCount() < 5 || e.GetCount() > 6)
		e.ThrowError("wrong number of arguments in call to 'DrawQtf'");
//	int zoom = e.Int(0);
	int x = e.Int(1);
	int y = e.Int(2);
	e.CheckArray(3);
	WString text = e[3];
	int cx = e.Int(4);
	String txt = '\1' + ToUtf8(text);
	::DrawSmartText(w, x, y, cx, txt, StdFont(), SColorText, 0);
}
Example #10
0
/**
 * Initializes Scrobblify. Collects paths to meta-data, sets the scrobble
 * directory and initializes the connection to the Last.fm client.
 */
void Scrobblify::Init() {
    // Collect meta-data files
    Scrobblify::GetSpotifyUserDirectories(metadata_paths_);

    for (std::vector<std::wstring>::iterator it = metadata_paths_.begin();
            it != metadata_paths_.end();
            ++it) {
        *it += _T("/metadata"); // Here we could check if the file exists
    }

    scrobble_directory_ = ToUtf8(Scrobblify::GetSpotifyDirectory());

    // Initialize Last.fm
    scrob_submitter_.Init(kPluginId, &Scrobblify::StatusCallback, (void *) this);
}
Example #11
0
NAMESPACE_UPP

#define LLOG(x) // LOG(x);

static inline void sDeXmlChar(StringBuffer& result, char chr, byte charset, bool escapelf)
{
	/**/ if(chr == '<')  result.Cat("&lt;");
	else if(chr == '>')  result.Cat("&gt;");
	else if(chr == '&')  result.Cat("&amp;");
	else if(chr == '\'') result.Cat("&apos;");
	else if(chr == '\"') result.Cat("&quot;");
	else if((byte)chr < ' ' && (escapelf || chr != '\n' && chr != '\t' && chr != '\r'))
		result.Cat(NFormat("&#x%02x;", (byte)chr));
	else if(!(chr & 0x80) || charset == CHARSET_UTF8) result.Cat(chr);
	else result.Cat(ToUtf8(ToUnicode(chr, charset)));
}
Example #12
0
void VisGenDlg::Refresh()
{
	String s;
	int q = ~type;
	bool b = q >= 3 && q <= 4;
	pars.Enable(b);
	brackets.Enable(b);
	label1.Enable(b);
	toupper1.Enable(b);
	tolower1.Enable(b);
	initcaps1.Enable(b);
	name1.Enable(b);
	dname1.Enable(b);
	quotes1.Enable(b && !label1);
	b = q == 4;
	label2.Enable(b);
	toupper2.Enable(b);
	tolower2.Enable(b);
	initcaps2.Enable(b);
	name2.Enable(b);
	dname2.Enable(b);
	quotes2.Enable(b && !label2);
	String oce = "\tCtrlLayout";
	bool ok = false;
	if(HasItem("ok")) {
		ok = true;
		oce << "OK";
	}
	if(HasItem("cancel"))
		oce << "Cancel";
	if(HasItem("exit"))
		oce << "Exit";
	String n = ~name;
	if(IsNull(n))
		n = GetName();
	
	String b1, b2, b3;
	if(buttons) {
		for(int i = 0; i < layout.item.GetCount(); i++) {
			String bn = layout.item[i].variable;
			if(layout.item[i].type == "Button" && findarg(bn, "cancel", "ok", "exit") < 0) {
				String mn = IdInitCaps(bn);
				mn.Replace("_", "");
				if(b1.GetCount() == 0)
					b1 = b2 = "\n";
				b1 << '\t' << "void " << mn << "();\n";
				b2 << '\t' << bn << " << [=] { " << mn << "};\n";
				b3 << '\n' << "void " << n << "::" << mn << "()\n{\n}\n";
			}
		}
	}

	if(q == 0) {
		s << "class " << n << " : public With" << layout.name << "<TopWindow> {\n"
		  << "\ttypedef " << n << " CLASSNAME;\n"
		  << b1
		  << "\n"
		  << "public:\n"
		  << "\t" << n << "();\n"
		  << "};\n"
		  << "\n"
		  << n << "::" << n << "()\n"
		  << "{\n"
		  << oce << "(*this, \"\");\n"
		  << b2
		  << "}\n"
		  << b3;
	}
	else
	if(q == 1) {
		s << "struct " << n << " : With" << layout.name << "<TopWindow> {\n"
		  << "\ttypedef " << n << " CLASSNAME;\n"
		  << b1
		  << "\t" << n << "();\n"
		  << "};\n"
		  << "\n"
		  << n << "::" << n << "()\n"
		  << "{\n"
		  << oce << "(*this, \"\");\n"
		  << b2
		  << "}\n"
		  << b3;
	}
	else
	if(q == 2) {
		String n = ~name;
		if(IsNull(n))
			n = "dlg";
		s << "\tWith" << layout.name << "<TopWindow> " << n << ";\n"
		  << oce << '(' << n << ", \"\");\n";
		if(ok)
			s << "\tif(" << n << ".Execute() != IDOK)\n\t\treturn;\n";
		else
			s << '\t' << n << ".Execute();\n";
	}
	else
		for(int i = 0; i < sel.GetCount(); i++) {
			String id1 = layout.item[sel[i]].variable;
			String id2 = id1;
			int w = layout.item[sel[i]].FindProperty("SetLabel");
			String lbl;
			if(w >= 0 && IsString(~layout.item[sel[i]].property[w]))
				lbl = AsCString(ToUtf8((WString)~layout.item[sel[i]].property[w]));
			if(q <= 4) {
				if(label1)
					id1 = lbl;
				if(label2)
					id2 = lbl;
			}
			if(IsNull(id1) && (q != 4 || IsNull(id2)))
				continue;
			if(q == 5)
				s << "\t" << id1 << " << [=] { };\n";
			else
			if(q == 6)
				s << "\t" << IdInitCaps(id1) << "();\n";
			else
			if(q == 7)
				s << "\t" << id1 << " << [=] { " << IdInitCaps(id1) << "(); };\n";
			else {
				if((pars || brackets) && !(name1 || name2 || dname1 || dname2))
					s << ~name;
				if(pars)
					s << '(';
				String ss;
				if(name1 && !IsNull(~name))
					s << ~name << '.';
				if(toupper1)
					ss << ToUpper(id1);
				else
				if(tolower1)
					ss << ToLower(id1);
				else
				if(initcaps1)
					ss << IdInitCaps(id1);
				else
					ss << id1;
				if(quotes1 && !label1)
					ss = AsCString(ss);
				if(dname1 && !IsNull(~name))
					ss << '.' << ~name;
				if(brackets)
					s << '[';
				s << ss;
				if(brackets)
					s << ']';
				if(q == 4) {
					s << ", ";
					String ss;
					if(name2 && !IsNull(~name))
						ss << ~name << '.';
					if(toupper2)
						ss << ToUpper(id2);
					if(tolower2)
						ss << ToLower(id2);
					else
					if(initcaps2)
						ss << IdInitCaps(id2);
					else
						ss << id2;
					if(quotes2 && !label2)
						ss = AsCString(ss);
					if(dname2 && !IsNull(~name))
						ss << '.' << ~name;
					if(brackets)
						s << '[';
					s << ss;
					if(brackets)
						s << ']';
				}
				if(pars)
					s << ')';
				s << '\n';
			}
		}
	view <<= s;
}
Example #13
0
void
PDFWriter::DrawString(char *string, float escapementNoSpace,
	float escapementSpace)
{
	REPORT(kDebug, fPage, "DrawString string=\"%s\", escapementNoSpace=%f, "
		"escapementSpace=%f, at %f, %f", string, escapementNoSpace,
		escapementSpace, fState->penX, fState->penY);

	if (IsDrawing()) {
		// text color is always the high color and not the pattern!
		SetColor(fState->foregroundColor);
	}
	// convert string to UTF8
	BString utf8;
	if (fState->beFont.Encoding() == B_UNICODE_UTF8) {
		utf8 = string;
	} else {
		ToUtf8(fState->beFont.Encoding()-1, string, utf8);
	}

	// convert string in UTF8 to unicode UCS2
	BString unicode;
	ToUnicode(utf8.String(), unicode);
	// need font object to calculate width of utf8 code point
	BFont font = fState->beFont;
	font.SetEncoding(B_UNICODE_UTF8);
	// constants to calculate position of next character
	const double rotation = DEGREE2RAD(fState->beFont.Rotation());
	const bool rotate = rotation != 0.0;
	const double cos1 = rotate ? cos(rotation) : 1;
	const double sin1 = rotate ? -sin(rotation) : 0;

	BPoint start(fState->penX, fState->penY);

	BeginTransparency();
	// If !MakesPDF() all the effort below just for the bounding box!
	// draw each character
	const char *c = utf8.String();
	const unsigned char *u = (unsigned char*)unicode.String();
	for (int i = 0; i < unicode.Length(); i += 2) {
		int s = CodePointSize((char*)c);

		float w = font.StringWidth(c, s);

		if (MakesPDF() && IsClipping()) {
			ClipChar(&font, (char*)u, c, s, w);
		} else {
			DrawChar(u[0]*256+u[1], c, s);
		}

		// position of next character
		if (*(unsigned char*)c <= 0x20) { // should test if c is a white-space!
			w += escapementSpace;
		} else {
			w += escapementNoSpace;
		}

		fState->penX += w * cos1;
		fState->penY += w * sin1;

		// next character
		c += s; u += 2;
	}
	EndTransparency();

	// text line processing (for non rotated text only!)
	BPoint end(fState->penX, fState->penY);
	BRect bounds;
	font_height height;

	font.GetHeight(&height);

	bounds.left = start.x;
	bounds.right = end.x;
	bounds.top = start.y - height.ascent;
	bounds.bottom = end.y   + height.descent;

	TextSegment* segment = new TextSegment(utf8.String(), start, escapementSpace,
		escapementNoSpace, &bounds, &font, pdfSystem());

	fTextLine.Add(segment);
}
Example #14
0
inline string DebugPrint(UniString const & s)
{
  return ToUtf8(s);
}
Example #15
0
			QStringList operator() (const std::string& str) const
			{
				return QStringList (ToUtf8 (str));
			}
Example #16
0
/**
 * Scrobbles a track. Also finds meta data, length and (possibly) album, for
 * the current track.
 */
int Scrobblify::Start(const std::wstring& artist,
                      const std::wstring& track) {
    // Handle currently playing track
    if (current_request_id_ > 0) {
        Stop();
    }

    // Lines are divided into fields terminated by 0x1
    const wchar_t kDelimiterChar = 0x1;
    const wchar_t kDelimiter[] = {kDelimiterChar, _T('\0')};
    const size_t kDelimiterLength = 1;
    const size_t kHashLength = 32;
    const size_t kLongHashLength = 40;

    // Search all the meta-data files available
    for (std::vector<std::wstring>::const_iterator it = metadata_paths_.begin();
            it != metadata_paths_.end();
            ++it) {
        // Go get some meta data
        FILE *metadata_file;

        if (_wfopen_s(&metadata_file, (*it).c_str(), _T("r")) != 0) {
            continue;
        }

        std::wifstream in(metadata_file);
        const size_t kMaxLineLength = 2048;
        wchar_t line[kMaxLineLength];

        // Skip first line (contains "21" for no apparent reason)
        in.getline(line, kMaxLineLength);

        // Skip if file is empty
        if (wcsnlen(line, 1) == 0) {
            in.close();
            continue;
        }

        // Find hash for artist
        wchar_t artist_hash[kHashLength];
        bool artist_hash_found = false;

        for (;
                wcsnlen(line, kMaxLineLength) > 0;
                in.getline(line, kMaxLineLength)) {
            if (wcsncmp(artist.c_str(),
                        &line[kHashLength + kDelimiterLength],
                        artist.size()) == 0) {
                artist_hash_found = true;
                wcsncpy(artist_hash, line, kHashLength);
                break;
            }
        }

        if (!artist_hash_found) {
            in.close();
            continue; // Try next file
        }

        // Skip rest of artist section
        for (in.getline(line, kMaxLineLength);
                wcsnlen(line, kMaxLineLength) > 0;
                in.getline(line, kMaxLineLength)) {}

        in.getline(line, kMaxLineLength); // Skip section separator
        std::wifstream::pos_type album_section_position = in.tellg();

        // Skip albums section -- move to next empty line
        for (;
                wcsnlen(line, kMaxLineLength) > 0;
                in.getline(line, kMaxLineLength)) { }

        // Parse songs section. Each song is formatted like
        //   hash        32 bytes
        //   track
        //   artists     ; split with 0x2
        //   long hash
        //   length
        //   ...
        int length = 0;
        bool track_found = false;
        wchar_t album_hash[kHashLength];

        for (in.getline(line, kMaxLineLength);
                wcsnlen(line, kMaxLineLength) > 0;
                in.getline(line, kMaxLineLength)) {
            if (wcsncmp(track.c_str(),
                        &line[kHashLength + kDelimiterLength],
                        track.size()) == 0) {
                // Skip hash, separator, track, separator.
                wchar_t *p = &line[kHashLength + kDelimiterLength + track.size() +
                                   kDelimiterLength];

                // Match any of the artists
                bool artist_match_found = wcsncmp(artist_hash, p, kHashLength) == 0;

                for (p += kHashLength;
                        *p == 0x2;
                        p += kHashLength + kDelimiterLength) {
                    if (!artist_match_found && // Don't compare if artist has been found
                            wcsncmp(artist_hash, &p[1], kHashLength) == 0) {
                        artist_match_found = true;
                    }
                }

                if (!artist_match_found) {
                    continue;
                }

                p += kDelimiterLength + kLongHashLength + kDelimiterLength;

                // Read track length
                length = _wtoi(p);
                track_found = true;

                // Skip length
                p = wcschr(p, kDelimiterChar);
                p += kDelimiterLength;

                // Skip track number
                p = wcschr(p, kDelimiterChar);
                p += kDelimiterLength;

                // Get album hash
                wcsncpy(album_hash, p, kHashLength);
                break;
            }
        }

        if (!track_found || length <= 0) {
            in.close();
            continue;
        }

        // Get album
        in.seekg(album_section_position); // Seek back to the album section
        std::wstring album;

        for (in.getline(line, kMaxLineLength);
                wcsnlen(line, kMaxLineLength) > 0;
                in.getline(line, kMaxLineLength)) {
            if (wcsncmp(album_hash, line, kHashLength) == 0) {
                size_t album_length = wcscspn(&line[kHashLength + kDelimiterLength],
                                              kDelimiter);
                album.assign(line, kHashLength + kDelimiterLength, album_length);
                break;
            }
        }

        in.close();
        return current_request_id_ = scrob_submitter_.Start(
                                         ToUtf8(artist),
                                         ToUtf8(track),
                                         ToUtf8(album),
                                         "",
                                         length,
                                         scrobble_directory_);
    }

    // No meta-data found; fall back on a five minute track length
    // TODO(liesen): does this violate any AudioScrobbler rules?
    return current_request_id_ = scrob_submitter_.Start(
                                     ToUtf8(artist),
                                     ToUtf8(track),
                                     "",
                                     "",
                                     5 * 60, // five minutes -- more than most songs
                                     scrobble_directory_);
}
Example #17
0
bool Ctrl::DispatchKey(dword keycode, int count)
{
	GuiLock __;
	if(GUI_AltAccessKeys()) {
		bool alt = GetAlt();
		Ctrl *c = GetActiveCtrl();
		if(c)
			c->RefreshAccessKeysDo(alt);
	}
//	RLOGBLOCK("Ctrl::DispatchKey");
//	RLOG("DispatchKey: focusCtrl = " << FormatIntHex((int)~focusCtrl) << ", wnd = " << FormatIntHex((int)~focusCtrlWnd) << ")");
	LLOG("DispatchKey " << keycode << " (0x" << Sprintf("%08x", keycode)
		<< ", " << GetKeyDesc(keycode) << "), count:" << count
		<< " focusCtrl:" << UPP::Name(focusCtrl) << " focusCtrlWnd:" << UPP::Name(focusCtrlWnd));
	if((keycode & K_KEYUP) && ignorekeyup)
	{
		ignorekeyup = false;
		return true;
	}
	for(int i = 0; i < keyhook().GetCount(); i++)
		if((*keyhook()[i])(focusCtrl, keycode, count))
			return true;
	dword k = keycode;
	word l = LOWORD(keycode);
	if(!(k & K_DELTA) && l >= 32 && l != 127 && GetDefaultCharset() != CHARSET_UNICODE)
		k = MAKELONG((word)FromUnicode(l, CHARSET_DEFAULT), HIWORD(keycode));
	if(!focusCtrl)
		return false;
	Ptr<Ctrl> p = focusCtrl;
	if(Ini::user_log) {
		String kl;
		dword k = keycode;
		const char *l = "";
		if(k < 65536) {
			kl << "CHAR \'" << ToUtf8((wchar)keycode) << "\' (" << keycode << ')';
			l = "  ";
		}
		else {
			kl << "KEY";
			if(k & K_KEYUP) {
				kl << "UP";
				k &= ~K_KEYUP;
				l = "  ";
			}
			kl << " " << GetKeyDesc(k);
		}
		USRLOG(l << kl);
	}
	for(;;) {
		LLOG("Trying to DispatchKey: p = " << Desc(p));
		if(p->IsEnabled() && p->Key(p->unicode ? keycode : k, count))
		{
			LLOG("Ctrl::DispatchKey(" << FormatIntHex(keycode) << ", " << GetKeyDesc(keycode)
				<< "): eaten in " << Desc(p));
			if(Ini::user_log)
				USRLOG("  -> " << Desc(p));
			eventCtrl = focusCtrl;
			return true;
		}
		s_hotkey = true;
		if(!p->GetParent()) {
			if(p->HotKey(keycode)) {
				eventCtrl = focusCtrl;
				return true;
			}
			return false;
		}
		p = p->GetParent();
	}

	USRLOG("  key was ignored");

	return false;
}
Example #18
0
void logg(WString txt){
	String utf8=ToUtf8(txt);
	fprintf(plogfile,"%s",utf8.Begin());
	sprintf(linebuffer,"%s%s",linebuffer,utf8.Begin());
}
Example #19
0
// draw current page
void 
BF_GUI_Text::DrawPage()
{
	BRect	oRect;
	BPoint	oPoint(3,poSysSetup->oFontNode.fHeight);
	int32	iCurLine;
	BString	*psLine;
	char	cBuffer[256];
	
	oRect = Bounds();
	
	SetHighColor(SYS_COLOR(BF_COLOR_NODE));
	SetLowColor(SYS_COLOR(BF_COLOR_BACK));
	for(iCurLine = 0;oPoint.y < oRect.bottom + poSysSetup->oFontNode.fHeight && iCurLine < ploString->CountItems();iCurLine++)
	{
		psLine = (BString *) ploString->ItemAt(iCurLine);

		ToUtf8(psLine->String(),cBuffer);

		BString oCurStr(cBuffer);
		oCurStr.ReplaceAll("\r","\x0");
		oCurStr.ReplaceAll("\n","\x0");
		oCurStr.ReplaceAll("\t","        ");
		if (bDrawSel && iMatchLine == iCurLine)
		{
			BString oBuffer;
			// draw first part of the string
			iStartSel = oCurStr.FindFirst(poMatch->String(),iStartSel);
			iStopSel = poMatch->CountChars();
			oCurStr.MoveInto(oBuffer,0,iStartSel);
			DrawString(oBuffer.String(),oPoint);
			// draw selected part of the string
			SetHighColor(SYS_COLOR(BF_COLOR_CURSOR_BACK));
			float fStartPoint = StringWidth(oBuffer.String());
			float fWidth = StringWidth(poMatch->String());
			BRect oRect(oPoint.x + fStartPoint,oPoint.y - poSysSetup->oFontNode.fHeight,oPoint.x + fStartPoint + fWidth,oPoint.y);
			FillRect(oRect);
			SetHighColor(0,0,0);
			SetLowColor(SYS_COLOR(BF_COLOR_CURSOR_BACK));
			oCurStr.MoveInto(oBuffer,0,iStopSel);
			DrawString(oBuffer.String());
			// draw rest part of the string
			SetHighColor(SYS_COLOR(BF_COLOR_NODE));
			SetLowColor(SYS_COLOR(BF_COLOR_BACK));
			DrawString(oCurStr.String());
		}
		else
		{
			// draw string without selection
			DrawString(oCurStr.String(),oPoint);
		};
		oPoint.y += poSysSetup->oFontNode.fHeight;
	};
//-------------------------------- change display position ----------------------------
/*
	BMessage *poMSG = new BMessage(BF_MSG_VIEWER_MOVE);
	float fPOS = oPoint.y / (poSysSetup->oFontNode.fHeight * ploString->CountItems());
	poMSG->AddFloat("Position",fPOS);
	BMessenger oMessenger(poStatus);
	oMessenger.SendMessage(poMSG);
*/
//------------------------------ TRUE if page is full ---------------------------------
	bFullPage = (oPoint.y < oRect.bottom + poSysSetup->oFontNode.fHeight) ? false : true;
};