Exemple #1
0
void HTMLView::AddStatement() {

	int32 number_of_runs = (int32)insertStyles.Count();
	int32 lineCount, lastOffset;
	bool doAutoScroll = true;
	
	// Get the scrollbar position... this is the part where we do autoscroll, but only 
	//   if the scrollbar is already at the bottom. That way it won't get annoying.
	if( scroll == NULL ) scroll = ScrollBar( B_VERTICAL );
	if( scroll ) {
		float scrMin, scrMax;
		scroll->GetRange( &scrMin, &scrMax );
		if( scroll->Value() != scrMax )
			doAutoScroll = false;
	}	

	// allocate some room for the text_run_array
	text_run_array* styles = (text_run_array*)malloc( sizeof(text_run_array) +
							(sizeof(text_run) * (number_of_runs - 1)));							

	// fill in the individual text_runs
	styles->count = number_of_runs;
	for( int32 i = 0; i < number_of_runs; ++i )
		styles->runs[i] = insertStyles[i];
		
	// Get the offset of the last line
	lineCount = CountLines();
	lastOffset = OffsetAt( lineCount );

	// Add the silly thing
	Insert( lastOffset, insertText, strlen(insertText), styles );
	
	// do the autoscroll, if needed
	if( doAutoScroll ) {
		lineCount = CountLines();
		lastOffset = OffsetAt( lineCount );
		ScrollToOffset( lastOffset );	
	}
		
	// Prepare to start over
	Empty = false;
	ClearFontStates();
	free( styles );
}
Exemple #2
0
void KouhoView::HighlightLine( int32 line )
{
//printf( "highlightLine set to :%d\n", line);
	int32 begin, end;
	BRegion region;

	if ( line != -1 )
	{
		begin = OffsetAt( line );
		if ( line == CountLines() - 1 )
			end = TextLength() + 1;
		else
			end = OffsetAt( line + 1 ) - 1;
//printf( "Highlight line:%d, offset %d-%d\n", line,begin,end);
		GetTextRegion( begin, end, &region );
		//as hightlight is just one line, 0 is enough.
		highlightRect = region.RectAt( 0 );
		//extend highlihght region to right end
		highlightRect.right = Bounds().right;
		Invalidate( highlightRect );

	}

}
Exemple #3
0
HyperTextAction*
HyperTextView::_ActionAt(const BPoint& where) const
{
	int32 offset = OffsetAt(where);

	ActionInfo pointer(offset, offset + 1, NULL);

	const ActionInfo* action = fActionInfos->BinarySearch(pointer,
			ActionInfo::CompareEqualIfIntersecting);
	if (action != NULL) {
		// verify that the text region was hit
		BRegion textRegion;
		GetTextRegion(action->startOffset, action->endOffset, &textRegion);
		if (textRegion.Contains(where))
			return action->action;
	}

	return NULL;
}
// ----------------------------------------------------------------------- RHTML_text_view - MessageReceived -
void RHTMLtextview::MessageReceived(BMessage *msg)
{
 switch (msg->what)
  {
   case 'PPOP':
   {
	Window()->Lock();
	if (pushmenu)
    {
     int32 c,d;
     GetSelection(&c,&d);
     pushmenu=false;
     if (mode==1) fTagMenu->Start(ConvertToScreen(PointAt(c)),c,R_TAG_MENU,tags);
     if (mode==2) fTagMenu->Start(ConvertToScreen(PointAt(c)),c,R_PARAM_MENU,tags,BString(buf1));
     if (mode==3) fTagMenu->Start(ConvertToScreen(PointAt(c)),c,R_VALUE_MENU,tags,BString(buf1),BString(buf2));

    }
	Window()->Unlock();
	fTimer->EndTimer();
   }
   break;
   case 'TIMR':
   {
	Window()->Lock();
	UpdateParamMenu();
    fTarget->fNumView->UpdateNum();
	Window()->Unlock();
	fUpdateTimer->EndTimer();
   }
   break;
   case 'PTFC':
   {
    int32 c,d;
    BString oldstring;
    msg->FindInt32("sel1",&c);
    msg->FindInt32("sel2",&d);
    msg->FindString("oldstring",&oldstring);
    BString *newtext = new BString(Text());
    fFileTypes->SetFontAndColor(&oldstring, newtext,0,c,d);
    delete newtext;
   }
   break;
   case 'CWFC':
   {
    int32 c,d;
    GetSelection(&c,&d);
    BString *newtext = new BString(Text());
    fFileTypes->SetFontAndColor(newtext, newtext, 0, c);
    delete newtext;
   }
   break;
   case 'VALE':
   {
    msg->FindString("tag",&buf1);
    msg->FindString("param",&buf2);
    pushmenu=true;
    mode=3;
    fTimer->StartTimer(fOptions->ReakcioIdoTM);
   }
   break;
   case 'UPPM':
   {
    if (fUpdateTimer->IsActive())
     fUpdateTimer->ResetTimer();
    else
     fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
   }
   break;
   default:
   {
    if (msg->WasDropped())
    {
     int32		num;
     uint32		type;
     char*		name;
     BPoint		aPoint;
     BPoint		point;
     entry_ref ref;
     status_t err;
     
     msg->FindPoint("_drop_point_", &aPoint);

     point = aPoint;
     this->ConvertFromScreen(&point);

     const int32 offset = OffsetAt(point);
    
     if (msg->GetInfo(B_REF_TYPE, 0, &name, &type, &num) == B_NO_ERROR && num >= 1)
     {
		// - File
      for(int32 i = 0; i < num; i++)
      {
       BEntry entry;
       BPath path;
       BFile fFile;
       BNodeInfo fNodeInfo;
       entry_ref ref;
       char fFileType[B_MIME_TYPE_LENGTH];
       if(msg->FindRef("refs", i, &ref) != B_NO_ERROR)
       {
        continue;
       }
       if ((err=entry.SetTo(&ref)) == B_OK)
       {
        entry.GetPath(&path);
       } 
       fFile.SetTo(&ref,B_READ_ONLY);
       fNodeInfo.SetTo(&fFile);
       fNodeInfo.GetType(fFileType);
       DropFile(path.Path(), fFileType, offset);
      }
     }
    } else
    {
     BTextView::MessageReceived(msg);
    }
   }
   break;
  }
}
// ------------------------------------------------------------------------------- RHTML_text_view - KeyDown -
void RHTMLtextview::KeyDown(const char *bytes, int32 numBytes)
{
	pushmenu = false;
	int32 c,d;
	GetSelection(&c, &d);
	BString *oldtext = new BString(Text());
	BString *newtext = 0;
	switch(bytes[0])
	{
		case B_ESCAPE:			// - ESC
		{
		}
		break;
		case B_ENTER:				// - ENTER
		{
			fTarget->SetModify(true);
			BString tmp = "";
			if (d - OffsetAt(CurrentLine()) > 0)
			{
				for (int i = OffsetAt(CurrentLine()); i < d; i++)
				{
					if (Text()[i] == B_SPACE || Text()[i] == B_TAB)
					{
						tmp << Text()[i];
					} else
						break;
				}
			}
			BTextView::KeyDown(bytes, numBytes);
			Insert(tmp.String());

			fFileTypes->SetFontAndColor(oldtext, newtext = new BString(Text()), 0, c);
   
			if (fUpdateTimer->IsActive())
				fUpdateTimer->ResetTimer();
			else
				fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
   
			if (PointAt(TextLength() - 1).y + 50 > fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right, PointAt(TextLength() - 1).y + 50);
		}
		break;
		case '>':					// - >
		{
			fTagMenu->Stop();
   fTarget->SetModify(true);
   BTextView::KeyDown(bytes,numBytes);
   fFileTypes->SetFontAndColor(oldtext, newtext = new BString(Text()),0,c);

   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);

   if (PointAt(TextLength()-1).y+50>fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right,PointAt(TextLength()-1).y+50);
  }
  break;
  case '<':					// - <
  {
   BTextView::KeyDown(bytes,numBytes);
   fTarget->SetModify(true);
   pushmenu=true;
   ScrollToSelection();
   fFileTypes->SetFontAndColor(oldtext, newtext = new BString(Text()),0,c);

   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);

   if (PointAt(TextLength()-1).y+50>fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right,PointAt(TextLength()-1).y+50);
   mode=1;
   fTimer->StartTimer(fOptions->ReakcioIdoTM);
  }
  break;
  case B_SPACE:				// - SPACE
  {
   fTarget->SetModify(true);
   BTextView::KeyDown(bytes,numBytes);
   fFileTypes->SetFontAndColor(oldtext, newtext = new BString(Text()),0,c);

   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);

   if (PointAt(TextLength()-1).y+50>fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right,PointAt(TextLength()-1).y+50);
   buf1 = "";
   int32 o;
   
   for (int i=c;i>=0;i--)
   {
    if (Text()[i]=='>') break;
    if (Text()[i]=='<')
    {
     for (o=i+1;o<=c+1;o++)
     {
      if (Text()[o]=='>') break;
      if (Text()[o]=='<') break;

      if (Text()[o]==' ')
      {
       pushmenu=true;
       mode=2;
       fTimer->StartTimer(fOptions->ReakcioIdoTM);
       break;
       i=-1;
      }
      buf1 << Text()[o];
     }
    }
   }
   
   BString str(Text());
   int32 a,b;
   tags.clear();

   a=str.FindLast('<',c);

   if (a>str.FindLast('>',c))
   {
    b=str.FindFirst('>',c);
    int32 e=str.FindFirst('<',c);
    if (b>=0 && ((b<e && e>=0) || (e<0)))
    {
     while (str[a]!=' ')
      a++;
     a++;
     int32 i=a;
     while (i<b)
     {
      if (str[i]==' ')
      {
       BString tmp;
       str.CopyInto(tmp,a,i-a);
       tmp.ToLower();
       if (tmp!=" " && tmp!="")
        tags.push_back(tmp);
       a=i+1;
      }

      if (str[i]=='=')
      {
       BString tmp;
       str.CopyInto(tmp,a,i-a);
       tmp.ToLower();
       tags.push_back(tmp);
       if (str[i+1]=='"')
       {
        a=str.FindFirst('"',i+2)+1;
        i=a-1;
       }
       else
        a=i=str.FindFirst(' ',i+1);
      }

      i++;
     }
    }   
   }
  }
  break;
  case B_UP_ARROW:			// - UP
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_DOWN_ARROW:		// - DOWN
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_LEFT_ARROW:		// - LEFT
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_RIGHT_ARROW:		// - RIGHT
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_PAGE_UP:			// - PUP
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_PAGE_DOWN:			// - PDOWN
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_HOME:				// - HOME
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_END:				// - END
  {
   BTextView::KeyDown(bytes,numBytes);
   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);
  }
  break;
  case B_BACKSPACE:			// - BackSpace
  {
   fTarget->SetModify(true);
   BTextView::KeyDown(bytes,numBytes);
   fFileTypes->SetFontAndColor(oldtext, newtext = new BString(Text()),0,c-1);

   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);

   if (PointAt(TextLength()-1).y+50>fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right,PointAt(TextLength()-1).y+50);
  }
  break;
  default:
  {
   fTarget->SetModify(true);
   BTextView::KeyDown(bytes,numBytes);
   fFileTypes->SetFontAndColor(oldtext, newtext = new BString(Text()),0,c);

   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);

   if (PointAt(TextLength()-1).y+50>fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right,PointAt(TextLength()-1).y+50);

   if (fUpdateTimer->IsActive())
    fUpdateTimer->ResetTimer();
   else
    fUpdateTimer->StartTimer(fOptions->ReakcioIdo);

   if (PointAt(TextLength()-1).y+50>fTarget->fNumView->Bounds().bottom) fTarget->fNumView->ResizeTo(fTarget->fNumView->Bounds().right,PointAt(TextLength()-1).y+50);
  }
 }
	if (oldtext)
 		delete oldtext;
	if (newtext)
 		delete newtext;
// ScrollToSelection();
}
Exemple #6
0
 T& operator() ( Indices... indices ) {
     return data_[ OffsetAt(indices...) ];
 }
Exemple #7
0
void ChatTextView::MouseDown(BPoint pt)
{
	fprintf(stderr, "ChatTextView::MouseDown.\n");
	
	const char *text = BString(Text()).String();
	std::string url;

	// base
	BTextView::MouseDown(pt);

	// Ugly link search
	int32 curr_offset = OffsetAt(pt);

	// no more looking at spaces
	while (curr_offset >= 0 && !isspace(text[curr_offset])) {
		if (curr_offset + 8 <= TextLength() && text[curr_offset] == 'h'
			&& text[curr_offset + 1] == 't' && text[curr_offset + 2] == 't'
			&& text[curr_offset + 3] == 'p' && text[curr_offset + 4] == ':'
			&& text[curr_offset + 5] == '/' && text[curr_offset + 6] == '/') {

			url = text[curr_offset++];
			while(curr_offset < TextLength() && !isspace(text[curr_offset])) {
				url += text[curr_offset++];
			}

			break;
		}

		if (curr_offset + 7 <= TextLength() && text[curr_offset] == 'f'
			&& text[curr_offset + 1] == 't' && text[curr_offset + 2] == 'p'
			&& text[curr_offset + 3] == ':' && text[curr_offset + 4] == '/'
			&& text[curr_offset + 5] == '/') {

			url = text[curr_offset++];
			while(curr_offset < TextLength() && !isspace(text[curr_offset])) {
				url += text[curr_offset++];
			}

			break;
		}

		--curr_offset;
	}

	// default to www.
	if (url.empty()) {
		// Ugly link search
		curr_offset = OffsetAt(pt);

		while (curr_offset >= 0 && !isspace(text[curr_offset])) {
			if (curr_offset + 5 <= TextLength() && text[curr_offset] == 'w'
				&& text[curr_offset + 1] == 'w' && text[curr_offset + 2] == 'w'
				&& text[curr_offset + 3] == '.') {
				// ignore if it's not at the beginning or has no whitespace
				if ((curr_offset - 1) >= 0 && isalnum(text[curr_offset - 1])) {
					--curr_offset;
					continue;
				}

				// is it part of a sentence
				if (isspace(text[curr_offset + 4]) || text[curr_offset + 4] == '.') {
					--curr_offset;
					continue;
				}

				url = text[curr_offset++];

				while(curr_offset < TextLength() && !isspace(text[curr_offset])) {
					url += text[curr_offset++];
				}

				// prepend http
				url = "http://" + url;

				break;
			}

			if (curr_offset + 5 <= TextLength() && text[curr_offset] == 'f'
				&& text[curr_offset + 1] == 't' && text[curr_offset + 2] == 'p'
				&& text[curr_offset + 3] == '.') {
				url = text[curr_offset++];

				while(curr_offset < TextLength() && !isspace(text[curr_offset])) {
					url += text[curr_offset++];
				}

				// prepend http
				url = "ftp://" + url;

				break;
			}

			--curr_offset;
		}
	}

	// prune punctuation
	if (!url.empty()) {
		while (url.size() > 0) {
			if (url[url.size() - 1] == ',' || url[url.size() - 1] == '!'
				|| url[url.size() - 1] == '.' || url[url.size() - 1] == ')'
				|| url[url.size() - 1] == ';' || url[url.size() - 1] == ']'
				|| url[url.size() - 1] == '>' || url[url.size() - 1] == '?'
				|| url[url.size() - 1] == '\'' || url[url.size() - 1] == '"') {
				url.erase(url.size() - 1);
			} else {
				break;
			}
		}
	}

	// load up browser!!
	if (!url.empty()) {
		char *argv[] = {const_cast<char *>(url.c_str()), NULL};
		if (!be_roster->IsRunning("text/html"))
			be_roster->Launch("text/html", 1, argv);
		else {
			BMessenger messenger("text/html");
			BMessage msg(B_NETPOSITIVE_OPEN_URL);
			msg.AddString("be:url", url.c_str());
			messenger.SendMessage(&msg);
		}
	}
}