Пример #1
0
int main()
{
     square myrect(4, 5983);
     square mysecondrect(454, 8539); //defining the "variable"
     std::cout << myrect.area() << std::endl;
     std::cout << mysecondrect.area() << std::endl;
     return 0;
}
filter_result ClientAgentInputFilter::HandleKeys(BMessage* msg)
{
	filter_result result(B_DISPATCH_MESSAGE);
	const char* keyStroke;
	int32 keymodifiers;

	BMessenger msgr(fWindow);

	WindowList* winList(vision_app->pClientWin()->pWindowList());

	msg->FindString("bytes", &keyStroke);
	msg->FindInt32("modifiers", &keymodifiers);

	if (keyStroke == NULL) {
		return result;
	}

	switch (keyStroke[0]) {
	/////////////////
	/// catch all ///
	/////////////////

	case B_RETURN: {
		// we dont want Shift+B_RETURN to select all the text
		// treat keypress like we would a normal B_RETURN
		if (fWindow->fInput->TextView()->TextLength()) {
			BMessage msg(M_SUBMIT);
			msg.AddString("input", fWindow->fInput->TextView()->Text());
			msgr.SendMessage(&msg);
		}
		result = B_SKIP_MESSAGE;
	} break;

	case B_TAB: // tab key
	{
		if ((keymodifiers & B_OPTION_KEY) == 0 && (keymodifiers & B_COMMAND_KEY) == 0 &&
			(keymodifiers & B_CONTROL_KEY) == 0 && (keymodifiers & B_SHIFT_KEY) == 0) {
			// used for tabcompletion for nickname/channelname/etc
			fWindow->TabExpansion();
			BMessage logMessage(M_CLIENT_LOG);
			logMessage.AddString("name", fWindow->fId.String());
			logMessage.AddString("data", "DEBUG: Tab completion used\n");
			fWindow->fSMsgr.SendMessage(&logMessage);
		}
		if ((keymodifiers & B_SHIFT_KEY) || !(keymodifiers & B_CONTROL_KEY))
			result = B_SKIP_MESSAGE;
	} break;
	}

	if ((keymodifiers & B_OPTION_KEY) == 0 && (keymodifiers & B_COMMAND_KEY) != 0 &&
		(keymodifiers & B_CONTROL_KEY) == 0 && (keymodifiers & B_SHIFT_KEY) != 0) {
		switch (keyStroke[0]) {
		case '0':
		case B_INSERT:
			// switch to last active agent
			winList->SelectLast();
			result = B_SKIP_MESSAGE;
			break;

		case B_UP_ARROW:
		case B_LEFT_ARROW: // baxter muscle memory
		case ',':		   // bowser muscle memory
			winList->ContextSelectUp();
			result = B_SKIP_MESSAGE;
			break;

		case B_DOWN_ARROW:  //
		case B_RIGHT_ARROW: // baxter muscle memory
		case '.':			// bowser muscle memory
			winList->ContextSelectDown();
			result = B_SKIP_MESSAGE;
			break;

		case 'U':
			winList->MoveCurrentUp();
			result = B_SKIP_MESSAGE;
			break;

		case 'D':
			winList->MoveCurrentDown();
			result = B_SKIP_MESSAGE;
			break;
		}
	}

	else if ((keymodifiers & B_OPTION_KEY) == 0 && (keymodifiers & B_COMMAND_KEY) != 0 &&
			 (keymodifiers & B_CONTROL_KEY) == 0 && (keymodifiers & B_SHIFT_KEY) == 0) {
		///////////////
		/// Command ///
		///////////////
		switch (keyStroke[0]) {
		case B_UP_ARROW:
		case ',': // bowser muscle memory
		{
			// move up one agent
			winList->Select(winList->CurrentSelection() - 1);
			winList->ScrollToSelection();
			result = B_SKIP_MESSAGE;
		} break;

		case B_DOWN_ARROW:
		case '.': // bowser muscle memory
		{
			// move down one agent
			winList->Select(winList->CurrentSelection() + 1);
			winList->ScrollToSelection();
			result = B_SKIP_MESSAGE;
		} break;

		case B_LEFT_ARROW: // collapse current server (if expanded)
		{
			winList->CollapseCurrentServer();
			result = B_SKIP_MESSAGE;
		} break;

		case B_RIGHT_ARROW: // expand current server (if collapsed)
		{
			winList->ExpandCurrentServer();
			result = B_SKIP_MESSAGE;
		} break;

		case '/': // bowser muscle memory
			// move to the agents parent ServerAgent
			// XXX move to WindowList ?
			{
				winList->SelectServer();
				result = B_SKIP_MESSAGE;
			}
			break;
		}
	}

	if ((keymodifiers & B_OPTION_KEY) == 0 && (keymodifiers & B_COMMAND_KEY) == 0 &&
		(keymodifiers & B_CONTROL_KEY) == 0 && (keymodifiers & B_SHIFT_KEY) == 0) {
		////////////////////
		/// no modifiers ///
		////////////////////
		switch (keyStroke[0]) {
		case B_UP_ARROW: {
			// used for input history
			msgr.SendMessage(M_PREVIOUS_INPUT);
			result = B_SKIP_MESSAGE;
		} break;

		case B_DOWN_ARROW: {
			// used for input history
			msgr.SendMessage(M_NEXT_INPUT);
			result = B_SKIP_MESSAGE;
		} break;

		case B_PAGE_UP: {
			// scroll the IRCView
			BRect myrect(fWindow->fText->Bounds());
			float height(myrect.bottom - myrect.top - 10.0);

			if (fWindow->fTextScroll->ScrollBar(B_VERTICAL)->Value() > height)
				fWindow->fText->ScrollBy(0.0, -1 * height);
			else
				fWindow->fText->ScrollTo(0.0, 0.0);

			result = B_SKIP_MESSAGE;
		} break;

		case B_PAGE_DOWN: {
			// scroll the IRCView
			BRect myrect(fWindow->fText->Bounds());
			float height(myrect.bottom - myrect.top - 10.0);

			float min, max;
			fWindow->fTextScroll->ScrollBar(B_VERTICAL)->GetRange(&min, &max);
			if (fWindow->fTextScroll->ScrollBar(B_VERTICAL)->Value() != max)
				fWindow->fText->ScrollBy(0.0, height);
			result = B_SKIP_MESSAGE;
		} break;

		case B_ESCAPE: {
			fWindow->fCancelMLPaste = true;
			result = B_SKIP_MESSAGE;
		} break;
		}
	}

	else if ((keymodifiers & B_OPTION_KEY) == 0 && (keymodifiers & B_COMMAND_KEY) == 0 &&
			 (keymodifiers & B_CONTROL_KEY) != 0 && (keymodifiers & B_SHIFT_KEY) == 0) {
		////////////
		/// Ctrl ///
		////////////
		switch (keyStroke[0]) {
		case B_UP_ARROW: {
			// scroll the IRCView up by 1 line
			if (fWindow->fTextScroll->ScrollBar(B_VERTICAL)->Value() != 0) {
				fWindow->fText->ScrollBy(0.0, vision_app->GetClientFont(F_TEXT)->Size() * -1);
				result = B_SKIP_MESSAGE;
			}
		} break;

		case B_DOWN_ARROW: {
			// scroll the IRCView down by 1 line
			float min, max;
			fWindow->fTextScroll->ScrollBar(B_VERTICAL)->GetRange(&min, &max);
			if (fWindow->fTextScroll->ScrollBar(B_VERTICAL)->Value() != max) {
				fWindow->fText->ScrollBy(0.0, vision_app->GetClientFont(F_TEXT)->Size());
				result = B_SKIP_MESSAGE;
			}
		} break;

		case B_HOME: {
			// scroll to the beginning of the IRCView
			fWindow->fText->ScrollTo(0.0, 0.0);
			result = B_SKIP_MESSAGE;
		} break;

		case B_END: {
			// scroll to the end of the IRCView
			float min, max;
			fWindow->fTextScroll->ScrollBar(B_VERTICAL)->GetRange(&min, &max);
			fWindow->fText->ScrollTo(0.0, max);
			result = B_SKIP_MESSAGE;
		} break;

		case B_PAGE_UP:
		case B_PAGE_DOWN: {
			// scroll the IRCView
			BRect myrect(fWindow->fText->Bounds());
			float height(myrect.bottom - myrect.top);

			if (keyStroke[0] == B_PAGE_UP) {
				if (fWindow->fTextScroll->ScrollBar(B_VERTICAL)->Value() > height)
					fWindow->fText->ScrollBy(0.0, -1 * height);
				else
					fWindow->fText->ScrollTo(0.0, 0.0);
			} else // B_PAGE_DOWN
			{
				float min, max;
				fWindow->fTextScroll->ScrollBar(B_VERTICAL)->GetRange(&min, &max);
				if (fWindow->fTextScroll->ScrollBar(B_VERTICAL)->Value() != max)
					fWindow->fText->ScrollBy(0.0, height);
			}

			result = B_SKIP_MESSAGE;
		} break;

		// ctrl+u = special control char - ascii 21
		case 21: {
			if (fWindow->fInput->TextView()->TextLength()) {
				int32 selstart, selfinish;
				fWindow->fInput->TextView()->GetSelection(&selstart, &selfinish);
				fWindow->fInput->TextView()->Delete(0, selfinish);
			}
			result = B_SKIP_MESSAGE;
		} break;
		}
	}
	return result;
}