Exemple #1
0
equation* mainWindow::createEqFromStr(Glib::ustring str)
{
	Gtk::MessageDialog tempDialog(*this, "Error!");
	unsigned int equalPos = commandLine->get_text().find("=");
	
	//check for = sign else give a error
	if(equalPos > 2000000000)
	{
		tempDialog.set_secondary_text("No \"=\" found");
		tempDialog.run();
		return 0;
	}else{
		//Now substring the str form equalPos
		Glib::ustring leftSide = str.substr(0, equalPos);
		
		//now find the function variable
		unsigned int firstBrace = leftSide.find("(");
		//if this is zero, no function name is given.
		if(firstBrace == 0)
		{
			tempDialog.set_secondary_text("No function name is given");
			tempDialog.run();
			return 0;
		}else{
			//if ( is not found error
			if(firstBrace > 2000000000)
			{
				tempDialog.set_secondary_text("Missing \"(\" in function name");
				tempDialog.run();
				return 0;
			}
			
			
			Glib::ustring afterBrace = leftSide.substr(firstBrace);
			if(afterBrace.length() != 3)
			{
				tempDialog.set_secondary_text("Syntax error in variable name");
				tempDialog.run();
				return 0;
			}
			
			Glib::ustring variableName = afterBrace.substr(1,1);
			Glib::ustring functionName = leftSide.substr(0, firstBrace);
			
			Glib::ustring rightSide = str.substr(equalPos+1);
			
			equation *tempEq = new equation();
			tempEq->setName(functionName);
			tempEq->setEquation(rightSide);
			tempEq->setVariable(variableName);
			return tempEq;
		}
	}
}
Exemple #2
0
int mainWindow::callFunc(Glib::ustring str)
{
	Gtk::MessageDialog tempDialog(*this, "Error!");
	unsigned int leftBrace = str.find("(");
	unsigned int rightBrace = str.find(")");
	
	if(leftBrace > 2000000000)
	{
		tempDialog.set_secondary_text("Missing \"(\"");
		tempDialog.run();
		return SYNTAX_ERROR;
	}else if(rightBrace > 2000000000){
		tempDialog.set_secondary_text("Missing \")\"");
		tempDialog.run();
		return SYNTAX_ERROR;
	}else if(leftBrace > rightBrace){
		tempDialog.set_secondary_text("Syntax error near )");
		tempDialog.run();
		return SYNTAX_ERROR;
	}else if(leftBrace == 0){
		tempDialog.set_secondary_text("No function name given");
		tempDialog.run();
		return SYNTAX_ERROR;
	}else{
		Glib::ustring funcName = str.substr(0, leftBrace);
		Glib::ustring rawArg = str.substr(leftBrace+1, rightBrace-leftBrace-1);
		
		if(funcName == "del")
		{
			if(this->eqView->removeByName(rawArg) == false)
			{
				tempDialog.set_secondary_text("No function by that name!");
				tempDialog.run();
			}
			return FUNC_HANDLED;
		}else{
			if(this->eqView->getEqByName(funcName))
			{
				equation *tmpEq = this->eqView->getEqByName(funcName);
				double number = strtod(rawArg.c_str(),NULL);
				number = tmpEq->getYFromX(number);
				char buffer[600];
				sprintf(buffer,"%f",number);
				tempDialog.set_secondary_text(buffer);
				tempDialog.run();
				
			}else{
				return FUNC_NOT_FOUND;
			}
		}
	}
}
Exemple #3
0
static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
{
  CWindow tempDialog(dialogHWND);
  if (message == WM_INITDIALOG)
    tempDialog.SetUserDataLongPtr(lParam);
  CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr());
  if (dialog == NULL)
    return FALSE;
  if (message == WM_INITDIALOG)
    dialog->Attach(dialogHWND);
  try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); }
  catch(...) { return TRUE; }
}
void MainWindow::connectHost()
{
    m_gobang->m_camp = Gobang::white;
    if(m_startMenu->currentIp.size() > 0)
    {
        m_server->connectHost(m_startMenu->currentIp);
    }
    else
    {
        enterDialog tempDialog(this);
        connect(&tempDialog, SIGNAL(setIP(QString)), m_server, SLOT(connectHost(QString)));
        tempDialog.exec();
    }
}