Пример #1
0
int EBuffer::BlockSelectLine() {
    int Y = VToR(CP.Row);
    if (BlockUnmark() == 0) return 0;
    BlockMode = bmStream;

    if (SetBB(EPoint(Y, 0)) == 0) return 0;
    if (Y == RCount - 1) {
        if (SetBE(EPoint(Y, LineLen(Y))) == 0) return 0;
    } else {
        if (SetBE(EPoint(Y + 1, 0)) == 0) return 0;
    }
    return 1;
}
Пример #2
0
// Icart's hash function
EPoint Icart::hash(ZZ_p u)
{
    // 0 maps to the point at infinity
    if (IsZero(u))
    {
        return EPoint(ZZ_p(0), ZZ_p(0), true);
    }

    // v = (3a - u^4) / 6u
    ZZ_p v = ((ZZ_p(3) * a) - power(u, 4)) * inv(ZZ_p(6) * u);
    // x = (v^2 - b - u^6/27)^(1/3) + u^2/3
    ZZ_p x = power( sqr(v) - b - (power(u, ZZ(6)) * ts), exp) + (sqr(u) * th);
    // y = ux + v
    ZZ_p y = (u * x) + v;

    return EPoint(x, y, false);
}
Пример #3
0
int EBuffer::BlockSelectWord() {
    int Y = VToR(CP.Row);
    PELine L = RLine(Y);
    int P;
    int C;

    if (BlockUnmark() == 0) return 0;
    BlockMode = bmStream;

    P = CharOffset(L, CP.Col);

    if (P >= L->Count) return 0;
    C = ChClassK(L->Chars[P]);

    while ((P > 0) && (C == ChClassK(L->Chars[P - 1]))) P--;
    if (SetBB(EPoint(Y, ScreenPos(L, P))) == 0) return 0;
    while ((P < L->Count) && (C == ChClassK(L->Chars[P]))) P++;
    if (SetBE(EPoint(Y, ScreenPos(L, P))) == 0) return 0;
    return 1;
}
Пример #4
0
// Selects the current function.
int EBuffer::BlockMarkFunction() {
    int by, ey;

    if (BlockUnmark() == 0)
        return 0;

    if ((by = FindFunction( 0, -1)) == -1)
        return 0;
    if ((ey = FindFunction(+1, +1)) == -1)
        return 0;

    //** Start and end are known. Set the block;
    BlockMode = bmStream;
    if (SetBB(EPoint(by, 0)) == 0)
        return 0;
    if (SetBE(EPoint(ey, 0)) == 0)
        return 0;

    return 1;
}
Пример #5
0
void
EBePrivateWin::FrameMoved(BPoint new_position)
{
	BWindow::FrameMoved(new_position);

	if(fContactor.IsValid())
	{
		EMessage message(E_WINDOW_MOVED);
		message.AddBool("etk:msg_from_gui", true);
		message.AddInt64("when", e_real_time_clock_usecs());
		message.AddPoint("where", EPoint(new_position.x, new_position.y));
		fContactor.SendMessage(&message);
	}
}
Пример #6
0
TView::TView(ERect frame, const char *name, euint32 resizingMode, euint32 flags)
	: EView(frame, name, resizingMode, flags)
{
	SetViewColor(216, 216, 216);

#if TEST_SCROLLBAR
	ERect cR = Bounds();
	ERect hR = Bounds();
	ERect vR = Bounds();

	cR.right -= 11;
	cR.bottom -= 11;

	hR.top = hR.bottom - 10;
	hR.right -= 10;
	vR.left = vR.right - 10;
	vR.bottom -= 10;

	EBox *box = new EBox(cR, NULL, E_FOLLOW_ALL);
	box->SetLabelAlignment(E_ALIGN_CENTER);
	box->SetLabel("装饰框框");
	AddChild(box);
#else
	EBox *box = new EBox(Bounds().InsetByCopy(-150, -150).OffsetToCopy(0, 0), NULL, E_FOLLOW_NONE);
	box->SetLabelAlignment(E_ALIGN_CENTER);
	box->SetLabel("装饰框框");
#endif

	ETextControl *edt = new ETextControl(ERect(10, 100, 250, 130), NULL,
					     "主题:", "这个世界日新月异", NULL,
					     E_FOLLOW_NONE, E_WILL_DRAW | E_FRAME_EVENTS | E_NAVIGABLE);
	edt->SetDivider(100);
	edt->SetAlignment(E_ALIGN_RIGHT, E_ALIGN_CENTER);
//	edt->HideTyping(true);
//	edt->HideTyping('*');
	edt->ResizeToPreferred();
	box->AddChild(edt);

	EButton *btn = new EButton(ERect(10, 280, 50, 300), NULL, "按钮", NULL);
	btn->SetFontSize(20);
	box->AddChild(btn);
	btn->ResizeToPreferred();

#if TEST_CHECKBOX
	ECheckBox *cbox = new ECheckBox(ERect(280, 60, 380, 90), NULL, "检查按钮", NULL);
	box->AddChild(cbox);
#endif

#if TEST_RADIOBUTTON
	EView *rbtns_group = new EView(ERect(430, 60, 530, 150), NULL, E_FOLLOW_NONE, 0);
	rbtns_group->AddChild(new ERadioButton(ERect(0, 0, 100, 30), NULL, "组合按钮1", NULL));
	rbtns_group->AddChild(new ERadioButton(ERect(0, 30, 100, 60), NULL, "组合按钮2", NULL));
	rbtns_group->AddChild(new ERadioButton(ERect(0, 60, 100, 90), NULL, "组合按钮3", NULL));
	box->AddChild(rbtns_group);
#endif

#if TEST_LISTVIEW
	EListView *listView = new EListView(ERect(0, 0, 200, 300), NULL, E_MULTIPLE_SELECTION_LIST, E_FOLLOW_NONE);
	listView->AddItem(new EStringItem("Item1"));
	listView->AddItem(new EStringItem("Item2", 1));
	listView->AddItem(new EStringItem("Item3"));
	listView->AddItem(new EStringItem("Item4", 2));
	listView->AddItem(new EStringItem("Item5"));
	listView->AddItem(new EStringItem("Item6"));
	listView->AddItem(new EStringItem("Item7"));
	listView->AddItem(new EStringItem("Item8"));
	listView->AddItem(new EStringItem("Item9"));
	listView->AddItem(new EStringItem("Item10"));
	listView->AddItem(new EStringItem("Item11"));
	listView->AddItem(new EStringItem("Item12"));
	listView->AddItem(new EStringItem("Item13"));
	box->AddChild(new EScrollView(ERect(100, 180, 250, 280), NULL, listView, E_FOLLOW_NONE));


	EOutlineListView *outline = new EOutlineListView(ERect(0, 0, 400, 300), NULL, E_SINGLE_SELECTION_LIST, E_FOLLOW_NONE);
	EListItem *region, *state, *locality;
	outline->AddItem(region = new EStringItem("United States of America"));
	outline->AddUnder(state = new EStringItem("California"), region);
	outline->AddUnder(new EStringItem("Menlo Park"), state);
	outline->AddUnder(new EStringItem("Los Angeles"), state);
	outline->AddUnder(locality = new EStringItem("New York"), region);
	outline->AddUnder(new EStringItem("Albany"), locality);
	outline->AddUnder(new EStringItem("Buffalo"), locality);
	outline->AddUnder(new EStringItem("New York City"), locality);
	outline->AddItem(region = new EStringItem("Europe"));
	outline->AddUnder(locality = new EStringItem("France"), region);
	outline->AddUnder(new EStringItem("Paris"), locality);
	outline->AddUnder(locality = new EStringItem("Germany"), region);
	outline->AddUnder(new EStringItem("Berlin"), locality);
	outline->AddUnder(new EStringItem("Hamburg"), locality);
	outline->AddUnder(locality = new EStringItem("Italy"), region);
	outline->AddUnder(new EStringItem("Milan"), locality);
	outline->AddUnder(new EStringItem("Rome"), locality);
	box->AddChild(new EScrollView(ERect(100, 300, 350, 450), NULL, outline, E_FOLLOW_NONE));
#endif


#if TEST_TEXTVIEW
	e_text_run_array array;
	array.count = 1;
	array.runs[0].font = *etk_plain_font;

	ETextView *textView = new ETextView(ERect(0, 0, 450, 200), NULL, ERect(0, 0, 450, 200));
//	textView->HideTyping(true);
//	textView->HideTyping('*');
	textView->SetAutoindent(true);

	array.runs[0].offset = 16;
	array.runs[0].font.SetSize(16);
	array.runs[0].color.set_to(0, 0, 200, 255);
	array.runs[0].background.set_to(255, 255, 0, 255);
	array.runs[0].underline = false;
	textView->Insert("This is a test, Be", &array);

	array.runs[0].offset = 0;
	array.runs[0].color.set_to(200, 0, 0, 255);
	textView->Insert(-1, "OS", -1, &array);

	array.runs[0].offset = 0;
	array.runs[0].font.SetSize(12);
	array.runs[0].color.set_to(200, 0, 200, 255);
	array.runs[0].background.alpha = 0;
	textView->Insert(-1, " style TextView, just enjoy it. :)\n", -1, &array);

	array.runs[0].offset = 0;
	array.runs[0].font = *etk_bold_font;
	array.runs[0].font.SetSize(20);
	array.runs[0].color.set_to(200, 0, 0, 255);
	array.runs[0].underline = true;
	textView->Insert(-1, "多行", -1, &array);

	array.runs[0].offset = 0;
	array.runs[0].font.SetSize(16);
	array.runs[0].color.set_to(0, 50, 0, 255);
	array.runs[0].underline = true;
	textView->Insert(-1, "文本", -1, &array);

	array.runs[0].offset = 0;
	array.runs[0].font.SetSize(30);
	array.runs[0].color.set_to(0, 0, 200, 255);
	array.runs[0].underline = false;
	textView->Insert(-1, "编辑", -1, &array);

	array.runs[0].offset = 0;
	array.runs[0].font = *etk_plain_font;
	array.runs[0].font.SetSize(10);
	array.runs[0].color.set_to(0, 0, 0, 255);
	textView->Insert(-1, "测试...", -1, &array);

	textView->Select(5, 20, true);

	box->AddChild(new EScrollView(ERect(100, 500, 350, 650), NULL, textView, E_FOLLOW_NONE));
#endif


#if TEST_TABVIEW
	ETabView *tabView = new ETabView(ERect(360, 300, 700, 500), NULL, E_WIDTH_FROM_LABEL, E_FOLLOW_NONE);
	ERect tabVR = tabView->ContainerView()->Bounds();

	ETab *tab = new ETab(new EStringView(tabVR, NULL, "Hello, This is the TAB 1.\nShow it...", E_FOLLOW_ALL));
	tab->SetLabel("Tab 1");
	tabView->AddTab(NULL, tab);

	tab = new ETab(new EColorControl(EPoint(5, 5), NULL, NULL, true));
	tab->SetLabel(">> ColorControl <<");
	tabView->AddTab(NULL, tab);

	tab = new ETab(new EStringView(tabVR, NULL, "Hello, This is the ** TAB 3 **.\nShow it...", E_FOLLOW_ALL));
	tab->SetLabel("  Tab 3  ");
	tabView->AddTab(NULL, tab);

	box->AddChild(tabView);
#endif

#if TEST_SCROLLBAR
	EScrollBar *hScrollBar = new EScrollBar(hR, NULL, 0, -100, 100, E_HORIZONTAL);
	EScrollBar *vScrollBar = new EScrollBar(vR, NULL, 0, -100, 100, E_VERTICAL);
	AddChild(hScrollBar);
	AddChild(vScrollBar);

	hScrollBar->SetTarget(box);
	vScrollBar->SetTarget(box);
#else
	EScrollView *scv = new EScrollView(Bounds(), NULL, box, E_FOLLOW_ALL);
	AddChild(scv);
#endif

#if TEST_STATUSBAR
	fStatusBar = new EStatusBar(ERect(280, 250, 500, 290), NULL, "进度条示例:", "/100");
	box->AddChild(fStatusBar);
	SetFlags(Flags() | E_PULSE_NEEDED);
#endif

#if TEST_MENUFIELD
	EMenu *menu = new EMenu("Options", E_ITEMS_IN_COLUMN);
	menu->SetLabelFromMarked(true);

	menu->AddItem(new EMenuItem("First Item", NULL));
	menu->AddSeparatorItem();
	menu->AddItem(new EMenuItem("Item", NULL));
	menu->AddItem(new EMenuItem("Item Item", NULL));
	menu->AddItem(new EMenuItem("Item Item Item", NULL));
	menu->AddItem(new EMenuItem("Item Item Item Item", NULL));
	menu->AddSeparatorItem();
	menu->AddItem(new EMenuItem("Last Item", NULL));
	menu->ItemAt(0)->SetMarked(true);

	EMenuField *menuField = new EMenuField(ERect(280, 150, 500, 200), NULL, "候选框:", menu, true);
	box->AddChild(menuField);
#endif
}
Пример #7
0
int main(int argc, char **argv)
{
	ETK_OUTPUT("message-test in ETK(%u.%u.%u)...\n",
		etk_major_version, etk_minor_version, etk_micro_version);

	EMessage *msg = new EMessage('TMSG');

	ETK_OUTPUT("=============== SET DATA 0 ===================\n");

	msg->AddString("String", "I am a test");
	if(msg->HasString("String")) ETK_OUTPUT("String <= \"I am a test\"\n");
	
	msg->AddInt8("Int8", (eint8)-0x3A);
	if(msg->HasInt8("Int8")) ETK_OUTPUT("Int8 <= %hhx -- %hhi\n", (eint8)-0x3A, (eint8)-0x3A);
	
	msg->AddInt16("Int16", (eint16)-0x3AFA);
	if(msg->HasInt16("Int16")) ETK_OUTPUT("Int16 <= %hx -- %hi\n", (eint16)-0x3AFA, (eint16)-0x3AFA);

	msg->AddInt32("Int32", (eint32)-0x3AFAFAFA);
	if(msg->HasInt32("Int32")) ETK_OUTPUT("Int32 <= %x --- %i\n", (eint32)-0x3AFAFAFA, (eint32)-0x3AFAFAFA);
	
	msg->AddInt64("Int64", E_INT64_CONSTANT(-0x3AFAFAFAFAFAFAFA));
	if(msg->HasInt64("Int64")) ETK_OUTPUT("Int64 <= %llx -- %lli\n", E_INT64_CONSTANT(-0x3AFAFAFAFAFAFAFA), E_INT64_CONSTANT(-0x3AFAFAFAFAFAFAFA));
	
	msg->AddBool("Bool", true);
	if(msg->HasBool("Bool")) ETK_OUTPUT("Bool <= %d\n", true);
	
	msg->AddFloat("Float", 0.5);
	if(msg->HasFloat("Float")) ETK_OUTPUT("Float <= %g\n", 0.5);
	
//	msg->AddDouble("Double", M_PI);
//	if(msg->HasDouble("Double")) ETK_OUTPUT("Double <= %lg\n", M_PI);
	
	msg->AddPoint("Point", EPoint(12, 15));
	if(msg->HasPoint("Point")) ETK_OUTPUT("Point <= X: %g\tY: %g\n", 12., 15.);

	msg->AddRect("Rect", ERect(0, 0, 800, 600));
	if(msg->HasRect("Rect")) ETK_OUTPUT("Rect <= LEFT: %g\tTOP: %g\tRIGHT: %g\tBOTTOM: %g\n", 0., 0., 800., 600.);

	ETK_OUTPUT("==============================================\n");


	ETK_OUTPUT("\n\n\n");
	ETK_OUTPUT("=============== SET DATA 1 ===================\n");

	msg->AddString("String", "Test again");
	if(msg->HasString("String")) ETK_OUTPUT("String <= \"Test again\"\n");
	
	msg->AddInt8("Int8", (eint8)0xFA);
	if(msg->HasInt8("Int8")) ETK_OUTPUT("Int8 <= %hhx -- %hhi\n", (eint8)0xFA, (eint8)0xFA);
	
	msg->AddInt16("Int16", (eint16)0xFAFA);
	if(msg->HasInt16("Int16")) ETK_OUTPUT("Int16 <= %hx -- %hi\n", (eint16)0xFAFA, (eint16)0xFAFA);

	msg->AddInt32("Int32", (eint32)0xFAFAFAFA);
	if(msg->HasInt32("Int32")) ETK_OUTPUT("Int32 <= %x --- %i\n", (eint32)0xFAFAFAFA, (eint32)0xFAFAFAFA);
	
	msg->AddInt64("Int64", E_INT64_CONSTANT(0xFAFAFAFAFAFAFAFA));
	if(msg->HasInt64("Int64")) ETK_OUTPUT("Int64 <= %llx -- %lli\n", E_INT64_CONSTANT(0xFAFAFAFAFAFAFAFA), E_INT64_CONSTANT(0xFAFAFAFAFAFAFAFA));
	
	msg->AddBool("Bool", false);
	if(msg->HasBool("Bool")) ETK_OUTPUT("Bool <= %d\n", false);
	
	msg->AddFloat("Float", 0.125);
	if(msg->HasFloat("Float")) ETK_OUTPUT("Float <= %g\n", 0.125);
	
//	msg->AddDouble("Double", M_PI_4);
//	if(msg->HasDouble("Double")) ETK_OUTPUT("Double <= %lg\n", M_PI_4);
	
	msg->AddPoint("Point", EPoint(34, 176));
	if(msg->HasPoint("Point")) ETK_OUTPUT("Point <= X: %g\tY: %g\n", 34., 176.);

	msg->AddRect("Rect", ERect(231, 121, 355, 595));
	if(msg->HasRect("Rect")) ETK_OUTPUT("Rect <= LEFT: %g\tTOP: %g\tRIGHT: %g\tBOTTOM: %g\n", 231., 121., 355., 595.);
	
	ETK_OUTPUT("==============================================\n");


	const char *gstr = NULL;
	eint8 gi8;
	eint16 gi16;
	eint32 gi32;
	eint64 gi64;
	bool gbool;
	float gfl;
	double gdl;
	EPoint gpt;
	ERect grt;

	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== GET DATA 0 ===================\n");

	if(msg->FindString("String", &gstr)) ETK_OUTPUT("String => \"%s\"\n", gstr);
	if(msg->FindInt8("Int8", &gi8)) ETK_OUTPUT("Int8 => %hhx --- %hhi\n", gi8, gi8);
	if(msg->FindInt16("Int16", &gi16)) ETK_OUTPUT("Int16 => %hx --- %hi\n", gi16, gi16);
	if(msg->FindInt32("Int32", &gi32)) ETK_OUTPUT("Int32 => %x --- %i\n", gi32, gi32);
	if(msg->FindInt64("Int64", &gi64)) ETK_OUTPUT("Int64 => %llx --- %lli\n", gi64, gi64);
	if(msg->FindBool("Bool", &gbool)) ETK_OUTPUT("Bool => %d\n", gbool);
	if(msg->FindFloat("Float", &gfl)) ETK_OUTPUT("Float => %g\n", gfl);
	if(msg->FindDouble("Double", &gdl)) ETK_OUTPUT("Double => %lg\n", gdl);

	if(msg->FindPoint("Point", &gpt)) ETK_OUTPUT("Point => X: %g\tY: %g\n", gpt.x, gpt.y);
	if(msg->FindRect("Rect", &grt)) ETK_OUTPUT("Rect => LEFT: %g\tTOP: %g\tRIGHT: %g\tBOTTOM: %g\n", grt.left, grt.top, grt.right, grt.bottom);

	ETK_OUTPUT("==============================================\n");

	
	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== GET DATA 1 ===================\n");

	if(msg->FindString("String", 1, &gstr)) ETK_OUTPUT("String => \"%s\"\n", gstr);
	if(msg->FindInt8("Int8", 1, &gi8)) ETK_OUTPUT("Int8 => %hhx --- %hhi\n", gi8, gi8);
	if(msg->FindInt16("Int16", 1, &gi16)) ETK_OUTPUT("Int16 => %hx --- %hi\n", gi16, gi16);
	if(msg->FindInt32("Int32", 1, &gi32)) ETK_OUTPUT("Int32 => %x --- %i\n", gi32, gi32);
	if(msg->FindInt64("Int64", 1, &gi64)) ETK_OUTPUT("Int64 => %llx --- %lli\n", gi64, gi64);
	if(msg->FindBool("Bool", 1, &gbool)) ETK_OUTPUT("Bool => %d\n", gbool);
	if(msg->FindFloat("Float", 1, &gfl)) ETK_OUTPUT("Float => %g\n", gfl);
	if(msg->FindDouble("Double", 1, &gdl)) ETK_OUTPUT("Double => %lg\n", gdl);

	if(msg->FindPoint("Point", 1, &gpt)) ETK_OUTPUT("Point => X: %g\tY: %g\n", gpt.x, gpt.y);
	if(msg->FindRect("Rect", 1, &grt)) ETK_OUTPUT("Rect => LEFT: %g\tTOP: %g\tRIGHT: %g\tBOTTOM: %g\n", grt.left, grt.top, grt.right, grt.bottom);

	ETK_OUTPUT("==============================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");
	ETK_OUTPUT("=============== PRINT TO STREAM ===================\n");
	msg->PrintToStream();
	ETK_OUTPUT("===================================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== FLATTEN ===================\n");
	size_t flattened_size = msg->FlattenedSize();
	ETK_OUTPUT("FlattenedSize = %lu\n", (unsigned long)flattened_size);
	char *flatten = (char*)malloc(flattened_size);
	if(flatten)
	{
		if(msg->Flatten(flatten, flattened_size))
		{
			msg->MakeEmpty();
			ETK_OUTPUT("Message have been flattened to the buffer and empty\n");
			if(msg->Unflatten(flatten, flattened_size))
			{
				ETK_OUTPUT("Message have been unflattened to the buffer\n");
				msg->PrintToStream();
			}
		}

		free(flatten);
	}
	ETK_OUTPUT("===========================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== REPLACE DATA ===================\n");
	msg->ReplaceString("String", 1, "Test again, Test again, do you right?");
	msg->ReplaceInt8("Int8", 1, (eint8)0xEE);
	msg->ReplaceInt16("Int16", 1, (eint16)0xEEEE);
	msg->ReplaceInt32("Int32", 1, (eint32)0xEEEEEEEE);
	msg->ReplaceInt64("Int64", 1, E_INT64_CONSTANT(0xEEEEEEEEEEEEEEEE));
	msg->ReplaceBool("Bool", 1, false);
	msg->ReplaceFloat("Float", 1, 0.00005);
//	msg->ReplaceDouble("Double", 1, M_PI_2);

	msg->PrintToStream();
	ETK_OUTPUT("================================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== REMOVE DATA ===================\n");
	msg->RemoveString("String");
	msg->RemoveInt8("Int8");
	msg->RemoveInt16("Int16", 1);
	msg->RemoveInt32("Int32", 1);
	msg->RemoveInt64("Int64");
	msg->RemoveBool("Bool", 1);
	msg->RemoveFloat("Float", 1);
	msg->RemoveDouble("Double", 1);

	msg->PrintToStream();
	ETK_OUTPUT("===============================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");
	ETK_OUTPUT("=============== aMsg = *msg ===================\n");
	EMessage aMsg = *msg;

	aMsg.PrintToStream();
	ETK_OUTPUT("===============================================\n");

	ETK_OUTPUT("\n\n\n");
	ETK_OUTPUT("=============== aMsg.MakeEmpty ===============\n");
	aMsg.MakeEmpty();

	aMsg.PrintToStream();
	ETK_OUTPUT("===============================================\n");

	ETK_OUTPUT("\n\n\n");
	ETK_OUTPUT("=============== aMsg.AddPointer ===============\n");
	aMsg.AddPointer("Pointer", msg);

	aMsg.PrintToStream();
	ETK_OUTPUT("===============================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");
	ETK_OUTPUT("=============== aMsg.FindPointer ===============\n");
	EMessage *kMsg = NULL;
	if(aMsg.FindPointer("Pointer", (void**)&kMsg) && kMsg)
	{
		ETK_OUTPUT("msg:address %p\n", kMsg);
		kMsg->PrintToStream();
	}
	ETK_OUTPUT("===============================================\n");

	getchar();

	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== aMsg.Flatten ===============\n");
	flattened_size = aMsg.FlattenedSize();
	ETK_OUTPUT("FlattenedSize = %lu\n", (unsigned long)flattened_size);
	flatten = (char*)malloc(flattened_size);
	if(flatten)
	{
		if(aMsg.Flatten(flatten, flattened_size))
		{
			aMsg.what = 0;
			aMsg.MakeEmpty();
			ETK_OUTPUT("Message have been flattened to the buffer and empty\n");
			if(aMsg.Unflatten(flatten, flattened_size))
			{
				ETK_OUTPUT("Message have been unflattened to the buffer\n");
				aMsg.PrintToStream();

				EMessage *pMsg = NULL;
				if(aMsg.FindPointer("Pointer", (void**)&pMsg) && pMsg)
				{
					pMsg->PrintToStream();
				}
				else
				{
					ETK_OUTPUT("********FAILED**********\n");
				}
			}
		}

		free(flatten);
	}
	ETK_OUTPUT("===========================================\n");

	ETK_OUTPUT("\n\n\n");	
	ETK_OUTPUT("=============== msg->BGetInfo ===============\n");
	char *name;
	euint32 type;
	eint32 count;
	for(eint32 i = 0; msg->BGetInfo(E_ANY_TYPE, i, &name, &type, &count) == E_OK; i++)
	{
		ETK_OUTPUT("[%I32i]: Name: \"%s\", type: \'%c%c%c%c\', count: %I32i\n",
			   i, name,
#ifdef ETK_LITTLE_ENDIAN
			   (euint8)(type >> 24), (euint8)((type >> 16) & 0xff), (euint8)((type >> 8) & 0xff), (euint8)(type & 0xff),
#else
			   (euint8)(type & 0xff), (euint8)((type >> 8) & 0xff), (euint8)((type >> 16) & 0xff), (euint8)(type >> 24),
#endif
			   count);
	}
	ETK_OUTPUT("===========================================\n");

	delete msg;

	return 0;
}
Пример #8
0
void
EBePrivateWin::DispatchMessage(BMessage *bMsg, BHandler *handler)
{
	bool handled = true;

	if(bMsg->what == 'etk_')
	{
		int32 what = 0;
		bMsg->FindInt32("etk:what", &what);

		switch(what)
		{
			case ETK_BEOS_QUIT:
				doQuit = true;
				PostMessage(B_QUIT_REQUESTED);
				break;

			case ETK_BEOS_CONTACT_TO:
				{
					fContactor = EMessenger();
					const char *buffer = NULL;
					ssize_t size = -1;
					if(bMsg->FindData("etk:messenger", B_ANY_TYPE, (const void**)&buffer, &size) != B_OK) break;
					if(buffer == NULL || size <= 0) break;
					fContactor.Unflatten(buffer, (size_t)size);
				}
				break;

			case ETK_BEOS_SET_BACKGROUND:
				{
					rgb_color bkColor;
					if(bMsg->FindInt32("background", (int32*)&bkColor) != B_OK) break;
					fTopView->SetViewColor(bkColor);
					fTopView->Invalidate();
				}
				break;

			case ETK_BEOS_SET_LOOK:
				{
					int8 look;
					if(bMsg->FindInt8("look", &look) != B_OK) break;
					switch((e_window_look)look)
					{
						case E_BORDERED_WINDOW_LOOK:
							SetLook(B_BORDERED_WINDOW_LOOK);
							break;

						case E_NO_BORDER_WINDOW_LOOK:
							SetLook(B_NO_BORDER_WINDOW_LOOK);
							break;

						case E_TITLED_WINDOW_LOOK:
							SetLook(B_TITLED_WINDOW_LOOK);
							break;

						case E_DOCUMENT_WINDOW_LOOK:
							SetLook(B_DOCUMENT_WINDOW_LOOK);
							break;

						case E_MODAL_WINDOW_LOOK:
							SetLook(B_MODAL_WINDOW_LOOK);
							break;

						case E_FLOATING_WINDOW_LOOK:
							SetLook(B_FLOATING_WINDOW_LOOK);
							break;

						default:
							break;
					}
				}
				break;

			case ETK_BEOS_SET_TITLE:
				{
					const char *title = NULL;
					if(bMsg->FindString("title", &title) != B_OK) break;
					SetTitle(title);
				}
				break;

			case ETK_BEOS_SET_WORKSPACES:
				{
					uint32 workspaces = 0;
					if(bMsg->FindInt32("workspaces", (int32*)&workspaces) != B_OK) break;
					if(workspaces == 0) workspaces = current_workspace() + 1;
					SetWorkspaces(workspaces);
				}
				break;

			case ETK_BEOS_GET_WORKSPACES:
				{
					uint32 workspaces = Workspaces();
					bMsg->AddInt32("workspaces", *((int32*)&workspaces));
				}
				break;

			case ETK_BEOS_ICONIFY:
				if(!IsMinimized()) Minimize(true);
				break;

			case ETK_BEOS_SHOW:
				if(IsHidden())
				{
					uint32 oldFlags = Flags();
					SetFlags(oldFlags | B_AVOID_FOCUS);
					Show();
					if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags);
				}
				break;

			case ETK_BEOS_HIDE:
				if(!IsHidden()) Hide();
				break;

			case ETK_BEOS_RAISE:
				if(!IsFront())
				{
					uint32 oldFlags = Flags();
					SetFlags(oldFlags | B_AVOID_FOCUS);
					Activate(true);
					if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags);
				}
				break;

			case ETK_BEOS_LOWER:
				{
					BHandler *_frontWin = NULL;
					if(bMsg->FindPointer("front", (void**)&_frontWin) != B_OK) break;
					BWindow *frontWin = e_cast_as(_frontWin, BWindow);
					if(frontWin == NULL) break;
					SendBehind(frontWin);
					bMsg->AddBool("done", true);
				}
				break;

			case ETK_BEOS_ACTIVATE:
				{
					bool state;
					if(bMsg->FindBool("state", &state) != B_OK || state == IsActive()) break;
					Activate(state);
				}
				break;

			case ETK_BEOS_GET_ACTIVATED_STATE:
				bMsg->AddBool("state", IsActive());
				break;

			case ETK_BEOS_MOVE_RESIZE:
				{
					if(bMsg->HasPoint("where"))
					{
						BPoint pt;
						if(bMsg->FindPoint("where", &pt) == B_OK) MoveTo(pt);
					}

					if(bMsg->HasFloat("width") && bMsg->HasFloat("height"))
					{
						float w = -1, h = -1;
						bMsg->FindFloat("width", &w);
						bMsg->FindFloat("height", &h);
						if(w < 0 || h < 0) break;
						ResizeTo(w, h);
					}
				}
				break;

			case ETK_BEOS_DRAW_BITMAP:
				{
					BBitmap *bitmap = NULL;
					BRect srcRect, destRect;
					const ERegion *clipping = NULL;

					if(bMsg->FindPointer("bitmap", (void**)&bitmap) != B_OK || bitmap == NULL) break;
					bMsg->FindRect("src", &srcRect);
					bMsg->FindRect("dest", &destRect);
					if(srcRect.IsValid() == false || destRect.IsValid() == false) break;
					bMsg->FindPointer("clipping", (void**)&clipping); 

					BRegion beRegion;
					__etk_convert_region(clipping, &beRegion, fTopView->Bounds());
					fTopView->ConstrainClippingRegion(&beRegion);
					fTopView->DrawBitmap(bitmap, srcRect, destRect);
				}
				break;

			case ETK_BEOS_GRAB_MOUSE:
			case ETK_BEOS_UNGRAB_MOUSE:
				{
					uint32 options = (what == ETK_BEOS_GRAB_MOUSE ? B_LOCK_WINDOW_FOCUS : 0);
					if(fTopView->SetEventMask(B_POINTER_EVENTS, options) != B_OK) break;
					bMsg->AddBool("state", what == ETK_BEOS_GRAB_MOUSE);
				}
				break;

			case ETK_BEOS_GRAB_KEYBOARD:
			case ETK_BEOS_UNGRAB_KEYBOARD:
				{
					uint32 options = (what == ETK_BEOS_GRAB_KEYBOARD ? B_LOCK_WINDOW_FOCUS : 0);
					if(fTopView->SetEventMask(B_KEYBOARD_EVENTS, options) != B_OK) break;
					bMsg->AddBool("state", what == ETK_BEOS_GRAB_KEYBOARD);
				}
				break;

			case ETK_BEOS_QUERY_MOUSE:
				{
					BPoint pt;
					uint32 btns = 0;
					fTopView->GetMouse(&pt, &btns, false);
					bMsg->AddInt32("x", (int32)pt.x);
					bMsg->AddInt32("y", (int32)pt.y);
					bMsg->AddInt32("buttons", (int32)btns);
				}
				break;

			case ETK_BEOS_SET_SIZE_LIMITS:
				{
					BRect r;
					if(bMsg->FindRect("limits", &r) != B_OK) break;
					SetSizeLimits(r.left, r.right, r.top, r.bottom);
					bMsg->AddBool("done", true);
				}
				break;

			case ETK_BEOS_GET_SIZE_LIMITS:
				{
					BRect r(-1, -1, -1, -1);
					GetSizeLimits(&(r.left), &(r.right), &(r.top), &(r.bottom));
					bMsg->AddRect("limits", r);
				}
				break;

			default:
				handled = false;
				break;
		}

		if(handled)
		{
			BMessage aMsg(*bMsg);
			bMsg->SendReply(&aMsg);
			return;
		}
	}

	switch(bMsg->what)
	{
		case B_WINDOW_ACTIVATED:
			{
				handled = false;

				if(fContactor.IsValid() == false) break;
				EMessage message(E_WINDOW_ACTIVATED);
				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				fContactor.SendMessage(&message);
			}
			break;

		case B_MOUSE_DOWN:
		case B_MOUSE_UP:
		case B_MOUSE_MOVED:
			{
				if(fContactor.IsValid() == false) break;

				BPoint where;
				int32 buttons = 0;

				bMsg->FindPoint("where", &where);
				if(bMsg->what != B_MOUSE_UP) bMsg->FindInt32("buttons", &buttons);

				int32 clicks = 1;
				if(bMsg->what == B_MOUSE_DOWN)
				{
#if 0
					bMsg->FindInt32("clicks", &clicks);
#else
					bigtime_t eventTime;
					if(bMsg->FindInt64("when", &eventTime) == B_OK)
					{
						if(eventTime - fPrevMouseDownTime <= CLICK_TIMEOUT)
							clicks = (fPrevMouseDownCount += 1);
						else
							clicks = fPrevMouseDownCount = 1;
						fPrevMouseDownTime = eventTime;
					}
#endif
				}

				EMessage message;
				if(bMsg->what == B_MOUSE_DOWN) message.what = E_MOUSE_DOWN;
				else if(bMsg->what == B_MOUSE_UP) message.what = E_MOUSE_UP;
				else message.what = E_MOUSE_MOVED;

				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				if(bMsg->what != B_MOUSE_UP) message.AddInt32("buttons", buttons);
				if(bMsg->what == B_MOUSE_DOWN) message.AddInt32("clicks", clicks);
				message.AddPoint("where", EPoint(where.x, where.y));
				ConvertToScreen(&where);
				message.AddPoint("screen_where", EPoint(where.x, where.y));

				// TODO: modifiers

				message.AddMessenger("etk:msg_for_target", fContactor);

				etk_app->PostMessage(&message);
			}
			break;

		case B_KEY_DOWN:
		case B_KEY_UP:
		case B_UNMAPPED_KEY_DOWN:
		case B_UNMAPPED_KEY_UP:
			{
				if(fContactor.IsValid() == false) break;

				int8 byte[4];
				const char *bytes = NULL;
				int32 numBytes = 0;
				int32 key = 0;
				int32 key_repeat = 0;
				int32 beModifiers = 0;
				eint32 modifiers = 0;

				bMsg->FindInt32("key", &key);
				bMsg->FindInt32("modifiers", &beModifiers);
				bzero(byte, sizeof(int8) * 4);

				if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP)
				{
					for(int32 i = 0; i < 3; i++) bMsg->FindInt8("byte", i, &byte[i]);
					if(bMsg->FindString("bytes", &bytes) == B_OK) numBytes = strlen(bytes);
//					if(bMsg->what == B_KEY_DOWN) bMsg->FindInt32("be:key_repeat", &key_repeat);
				}
				else
				{
					etk_beos_get_byte(beModifiers, key, (char*)byte);
				}

				if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY;
				if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY;
				if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY;

				EMessage message;
				if(bMsg->what == B_KEY_DOWN) message.what = E_KEY_DOWN;
				else if(bMsg->what == B_KEY_UP) message.what = E_KEY_UP;
				else if(bMsg->what == B_UNMAPPED_KEY_DOWN) message.what = E_UNMAPPED_KEY_DOWN;
				else message.what = E_UNMAPPED_KEY_UP;

				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				message.AddInt32("key", key);
				message.AddInt32("modifiers", modifiers);

				if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP)
				{
					if(bMsg->what == B_KEY_DOWN) message.AddInt32("etk:key_repeat", key_repeat);
					for(int32 i = 0; i < 3; i++) message.AddInt8("byte", byte[i]);
					if(!(numBytes != 1 || *bytes != byte[0]))
					{
						etk_beos_get_byte(beModifiers, key, (char*)byte);
						message.AddString("bytes", (char*)byte);
					}
					else if(numBytes > 0)
					{
						message.AddString("bytes", bytes);
					}
				}
				else if(byte[0] != 0)
				{
					message.AddInt8("byte", byte[0]);
					message.AddString("bytes", (char*)byte);
				}

				message.AddMessenger("etk:msg_for_target", fContactor);

				etk_app->PostMessage(&message);
			}
			break;

		case B_MODIFIERS_CHANGED:
			{
				if(fContactor.IsValid() == false) break;

				eint32 modifiers = 0;
				eint32 old_modifiers = 0;
				int32 beModifiers = 0;
				int32 old_beModifiers = 0;

				bMsg->FindInt32("modifiers", &beModifiers);
				bMsg->FindInt32("be:old_modifiers", &old_beModifiers);

				if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY;
				if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY;
				if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY;

				if(old_beModifiers & B_SHIFT_KEY) old_modifiers |= E_SHIFT_KEY;
				if(old_beModifiers & B_CONTROL_KEY) old_modifiers |= E_CONTROL_KEY;
				if(old_beModifiers & B_COMMAND_KEY) old_modifiers |= E_COMMAND_KEY;

				EMessage message(E_MODIFIERS_CHANGED);

				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				message.AddInt32("modifiers", modifiers);
				message.AddInt32("etk:old_modifiers", old_modifiers);

				message.AddMessenger("etk:msg_for_target", fContactor);

				etk_app->PostMessage(&message);
			}
			break;

		default:
			handled = false;
			break;
	}

	if(!handled) BWindow::DispatchMessage(bMsg, handler);
}
Пример #9
0
void
ETextEditable::Draw(ERect updateRect)
{
	if(!IsVisible()) return;

	ERect rect = Frame().OffsetToSelf(E_ORIGIN);
	rect.left += fMargins.left;
	rect.top += fMargins.top;
	rect.right -= fMargins.right;
	rect.bottom -= fMargins.bottom;

	if(!rect.IsValid()) return;

	ERegion clipping;
	GetClippingRegion(&clipping);
	if(clipping.CountRects() > 0) clipping &= (rect & updateRect);
	else clipping = (rect & updateRect);
	if(clipping.CountRects() <= 0) return;

	e_rgb_color bkColor = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR);
	e_rgb_color fgColor = e_ui_color(E_DOCUMENT_TEXT_COLOR);

	if(!IsEnabled())
	{
		bkColor.disable(ViewColor());
		fgColor.disable(ViewColor());
	}

	if(!IsFocusChanging())
	{
		PushState();
		ConstrainClippingRegion(&clipping);
		SetDrawingMode(E_OP_COPY);
		SetPenSize(0);
		SetHighColor(bkColor);
		FillRect(rect & updateRect, E_SOLID_HIGH);
		PopState();
	}

	EFont font;
	e_font_height fontHeight;
	GetFont(&font);
	font.GetHeight(&fontHeight);

	if(fCount > 0 && !IsFocusChanging())
	{
		PushState();

		ConstrainClippingRegion(&clipping);

		float x = 0, y = 0;
		if(GetCharLocation(0, &x, &y, &font))
		{
			SetDrawingMode(E_OP_COPY);
			SetPenSize(0);
			SetHighColor(fgColor);
			SetLowColor(bkColor);
			_DrawString(fText, EPoint(x, y));

			if(IsEnabled() && IsSelected())
			{
				char *selectedText = DuplicateText(fSelectStart, fSelectEnd);
				if(selectedText != NULL)
				{
					x = 0; y = 0;
					if(GetCharLocation(fSelectStart, &x, &y, &font))
					{
						DrawSelectedBackground(updateRect);
						SetLowColor(e_ui_color(E_DOCUMENT_HIGHLIGHT_COLOR));
						_DrawString(selectedText, EPoint(x, y));
					}
					free(selectedText);
				}
			}
		}

		PopState();
	}

	if(IsEnabled() && IsEditable() && (IsFocus() || IsFocusChanging()))
	{
		PushState();
		ConstrainClippingRegion(&clipping);
		DrawCursor();
		PopState();
	}

	if((IsFocus() || IsFocusChanging()) && Window()->IsActivate() && IsEnabled() && (Flags() & E_NAVIGABLE))
	{
		e_rgb_color color = e_ui_color(E_NAVIGATION_BASE_COLOR);
		if(IsFocusChanging() && !IsFocus()) color = e_ui_color(E_DOCUMENT_BACKGROUND_COLOR);

		PushState();
		ConstrainClippingRegion(&clipping);
		SetDrawingMode(E_OP_COPY);
		SetPenSize(0);
		SetHighColor(color);
		StrokeRect(rect, E_SOLID_HIGH);
		PopState();
	}
}