예제 #1
0
void sDialogWindow::Start()
{
    if(LeftLabel)
    {
        LeftButton = AddButton(LeftLabel,sMessage(this,&sDialogWindow::CmdLeft));
        LeftButton->Width = 75;
    }
    if(RightLabel)
    {
        RightButton = AddButton(RightLabel,sMessage(this,&sDialogWindow::CmdRight));
        RightButton->Width = 75;
    }
    if(EditString.Buffer)
    {
        EditControl = new sStringControl(EditString);
        AddChild(EditControl);
    }
    if(PoolString)
    {
        EditControl = new sStringControl(PoolString);
        AddChild(EditControl);
    }

    OnCalcSize();
    sGui->AddFloatingWindow(this,Header);
    if(EditControl)
    {
        sGui->SetFocus(EditControl);
        //  EditControl->DoneMsg = sMessage(this,&sDialogWindow::CmdRight);
    }
}
예제 #2
0
void CUploadTipCtrl::OnCalcSize(CDC* pDC)
{
	if ( m_pUploadFile && UploadFiles.Check( m_pUploadFile ) )
	{
		OnCalcSize( pDC, m_pUploadFile->GetActive() );
	}
	m_sz.cx = min( max( m_sz.cx, 400l ), (LONG)GetSystemMetrics( SM_CXSCREEN ) / 2 );
}
예제 #3
0
void sTextControl::SetText(sChar *t)
{
  sChar *d;

  Realloc(sGetStringLen(t)+1);

  d = Text;
  while(*t)
  {
    if(*t!='\r')
      *d++ = *t;
    t++;
  }
  *d++ = 0;
  Cursor = 0;
  SelPos = 0;
  SelMode = 0;
  OnCalcSize();
}
예제 #4
0
void sTextControl::OnPaint()
{
  sChar *p;
  sInt i,x,y,h,xs;
  sInt pos;
  sRect r;
  sInt font;
  sInt s0,s1;

  if(RecalcSize) // usefull for Logwindow
  {
    RecalcSize = 0;
    OnCalcSize();
  }

  x = Client.x0+2;
  y = Client.y0+2;
  font = sGui->FixedFont;
  h = sPainter->GetHeight(font);
  p = Text;
  pos = 0;

  s0 = s1 = 0;
  if(SelMode)
  {
    s0 = sMin(Cursor,SelPos);
    s1 = sMax(Cursor,SelPos);
  }

  r.y0 = y-2;
  r.y1 = y;
  r.x0 = Client.x0;
  r.x1 = Client.x1;
  sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_BACK]);

  for(;;)
  {
    i = 0;
    while(p[i]!=0 && p[i]!='\n')
      i++;

    r.y0 = y;
    r.y1 = y+h;
    r.x0 = Client.x0;
    r.x1 = Client.x1;
    if(sGui->CurrentClip.Hit(r))
    {
      sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_BACK]);
      if(Cursor>=pos && Cursor<=pos+i)
      {
        r.x0 = x+sPainter->GetWidth(font,p,Cursor-pos);
        if(Overwrite)
        {
          if(Cursor==pos+i)
            r.x1 = x+sPainter->GetWidth(font," ");
          else
            r.x1 = x+sPainter->GetWidth(font,p,Cursor-pos+1);
          sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_SELBACK]);
        }
        else
        {
          r.x1 = r.x0+1;
          r.x0--;
          sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_TEXT]);
        }
      }
      if(SelMode && s0<=pos+i && s1>=pos)
      {
        if(s0<=pos)
          r.x0 = x;
        else
          r.x0 = x+sPainter->GetWidth(font,p,s0-pos);
        if(s1>pos+i)
          r.x1 = x+sPainter->GetWidth(font,p,i)+sPainter->GetWidth(font," ");
        else
          r.x1 = x+sPainter->GetWidth(font,p,s1-pos);
          sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_SELBACK]);
      }
      sPainter->Print(font,x,y,p,sGui->Palette[sGC_TEXT],i);
    }
    xs = sPainter->GetWidth(font,p,i)+4+sPainter->GetWidth(font," ");
    y+=h;
    p+=i;
    pos+=i;
    if(*p==0)
      break;
    if(*p=='\n')
    {
      p++;
      pos++;
    }
  }
  r.y0 = y;
  r.y1 = Client.y1;
  r.x0 = Client.x0;
  r.x1 = Client.x1;
  if(r.y0<r.y1)
    sPainter->Paint(sGui->FlatMat,r,sGui->Palette[sGC_BACK]);
}
예제 #5
0
void sTextControl::OnKey(sU32 key)
{
  sInt len;
  sU32 ckey;
  sInt i,j;
  sChar buffer[2];

// prepare...

  if(key&sKEYQ_SHIFT) key|=sKEYQ_SHIFT;
  if(key&sKEYQ_CTRL ) key|=sKEYQ_CTRL ;

  len = sGetStringLen(Text);
  if(Cursor>len)
    Cursor = len;

// normal keys

  switch(key&(0x8001ffff|sKEYQ_SHIFT|sKEYQ_CTRL))
  {
  case sKEY_BACKSPACE:
    if(SelMode)
    {
      DelSel();
    }
    else
    {
      if(Cursor==0)
        break;
      Cursor--;
      Engine(Cursor,1,0);
      Post(DoneCmd);
      SelMode = 0;
      OnCalcSize();
      ScrollToCursor();
    }
    break;
  case sKEY_DELETE:
    if(SelMode)
    {
      DelSel();
    }
    else
    {
      Engine(Cursor,1,0);
      OnCalcSize();
      Post(DoneCmd);
    }
    ScrollToCursor();
    break;
  case sKEY_ENTER:
    if(SelMode)
      DelSel();
    i = Cursor-GetCursorX();
    for(j=0;i<Cursor && Text[i]==' ';i++)
      j++;
    if(Cursor>i && Text[Cursor-1]=='{')
      j+=2;
    Engine(Cursor,1,"\n");
    Cursor++;
    for(i=0;i<j;i++)
    {
      Engine(Cursor,1," ");
      Cursor++;
    }
    OnCalcSize();
    ScrollToCursor();
    break;
  case sKEY_PAGEUP:
    len = RealY/sPainter->GetHeight(sGui->FixedFont)-8;
    if(len<1) len = 1;
    for(i=0;i<len;i++)
      OnKey(sKEY_UP);
    break;
  case sKEY_PAGEDOWN:
    len = RealY/sPainter->GetHeight(sGui->FixedFont)-8;
    if(len<1) len = 1;
    for(i=0;i<len;i++)
      OnKey(sKEY_DOWN);
    break;
  case sKEY_INSERT:
    Overwrite = !Overwrite;
    ScrollToCursor();
    break;
  case 'x'|sKEYQ_CTRL:
    OnCommand(sTCC_CUT);
    OnCalcSize();
    ScrollToCursor();
    break;
  case 'c'|sKEYQ_CTRL:
    OnCommand(sTCC_COPY);
    ScrollToCursor();
    break;
  case 'v'|sKEYQ_CTRL:
    OnCommand(sTCC_PASTE);
    OnCalcSize();
    ScrollToCursor();
    break;
  case 'b'|sKEYQ_CTRL:
    OnCommand(sTCC_BLOCK);
    ScrollToCursor();
    break;
  }

//  sDPrintF("key %08x\n",key);
  ckey = key&~(sKEYQ_SHIFT|sKEYQ_ALTGR|sKEYQ_REPEAT);
  if((ckey>=0x20 && ckey<=0x7e) || (ckey>=0xa0 && ckey<=0xff))
  {
    DelSel();
    buffer[0] = ckey;
    buffer[1] = 0;
    if(Overwrite && Cursor<len)
    {
      Engine(Cursor,1,0);
      Engine(Cursor,1,buffer);
      Cursor++;
      Post(DoneCmd);
    }
    else
    {
      Engine(Cursor,1,buffer);
      Cursor++;
      Post(DoneCmd);
    } 
    OnCalcSize();
    ScrollToCursor();
  }
  else
  {
    Parent->OnKey(key);
  }

// cursor movement and shift-block-marking

  switch(key&0x8001ffff)
  {
  case sKEY_LEFT:
  case sKEY_RIGHT:
  case sKEY_UP:
  case sKEY_DOWN:
  case sKEY_HOME:
  case sKEY_END:
    if(SelMode==0 && (key&sKEYQ_SHIFT))
    {
      SelMode = 1;
      SelPos = Cursor;
    }
    if(SelMode==1 && !(key&sKEYQ_SHIFT))
    {
      SelMode = 0;
    }
    break;
  }

  switch(key&0x8001ffff)
  {
  case sKEY_LEFT:
    if(Cursor>0)
      Cursor--;
    ScrollToCursor();
    break;
  case sKEY_RIGHT:
    if(Cursor<len)
      Cursor++;
    ScrollToCursor();
    break;
  case sKEY_UP:
    j = i = CursorWish;
    if(Text[Cursor]=='\n' && Cursor>0)
      Cursor--;
    while(Text[Cursor]!='\n' && Cursor>0)
      Cursor--;
    while(Text[Cursor-1]!='\n' && Cursor>0)
      Cursor--;
    while(i>0 && Text[Cursor]!='\n' && Text[Cursor]!=0)
    {
      Cursor++;
      i--;
    }
    ScrollToCursor();
    CursorWish = j;
    break;
  case sKEY_DOWN:
    j = i = CursorWish;
    while(Text[Cursor]!='\n' && Text[Cursor]!=0)
      Cursor++;
    if(Text[Cursor]=='\n')
    {
      Cursor++;
      while(i>0 && Text[Cursor]!='\n' && Text[Cursor]!=0)
      {
        Cursor++;
        i--;
      }
    }
    ScrollToCursor();
    CursorWish = j;
    break;
  case sKEY_HOME:
    while(Cursor>0 && Text[Cursor-1]!='\n')
      Cursor--;
    ScrollToCursor();
    break;
  case sKEY_END:
    while(Text[Cursor]!='\n' && Text[Cursor]!=0)
      Cursor++;
    ScrollToCursor();
    break;
  }

}