int LineEdit::PlaceCaretNoG(int newcursor, bool sel) { if(newcursor > total) newcursor = total; Point p = GetColumnLine(newcursor); if(sel) { if(anchor < 0) { anchor = cursor; } if(rectsel || rectsel != dorectsel) Refresh(); else RefreshLines(p.y, GetLine(cursor)); rectsel = dorectsel; } else { if(anchor >= 0) { if(rectsel || dorectsel) Refresh(); else RefreshLines(GetLine(cursor), GetLine(anchor)); anchor = -1; } rectsel = false; } RefreshLine(GetColumnLine(cursor).y); RefreshLine(p.y); cursor = newcursor; ScrollIntoCursor(); PlaceCaret0(p); SelectionChanged(); WhenSel(); if(IsAnySelection()) SetSelectionSource(ClipFmtsText()); return p.x; }
Rect LineEdit::GetRectSelection() const { if(IsRectSelection()) { int sell, selh; GetSelection(sell, selh); Rect r(GetColumnLine(sell), GetColumnLine(selh)); if(r.left > r.right) Swap(r.left, r.right); return r; } return Null; }
void LineEdit::ScrollIntoCursor() { Point p = GetColumnLine(GetCursor()); sb.ScrollInto(p); SetHBar(); sb.ScrollInto(p); }
void LineEdit::AlignChar() { int c = GetCursor(); if(c == 0) return; Point pos = GetColumnLine(c); if(pos.x == 0) return; for(int d = 1; d <= pos.y && d < 100; d++) { int lny = pos.y - d; WString above = GetWLine(lny); int offset = GetGPos(lny, pos.x) - GetPos(lny); int end = offset; char ch = GetChar(c - 1); if(ch == ' ') { offset++; while(end < above.GetLength() && above[end] != ' ') end++; while(end < above.GetLength() && above[end] == ' ') end++; } else while(end < above.GetLength() && above[end] != ch) end++; if(end < above.GetLength()) { int count = end - offset + 1; WString s(' ', count); Insert(c - 1, s, true); SetCursor(c + count); return; } } }
void LineEdit::DragAndDrop(Point p, PasteClip& d) { if(IsReadOnly()) return; int c = GetMousePos(p); if(AcceptText(d)) { NextUndo(); int a = sb.y; int sell, selh; WString text = GetWString(d); if(GetSelection(sell, selh)) { if(c >= sell && c < selh) { if(!IsReadOnly()) RemoveSelection(); if(IsDragAndDropSource()) d.SetAction(DND_COPY); c = sell; } else if(d.GetAction() == DND_MOVE && IsDragAndDropSource()) { if(c > sell) c -= selh - sell; if(!IsReadOnly()) RemoveSelection(); d.SetAction(DND_COPY); } } int count = Insert(c, text); sb.y = a; SetFocus(); SetSelection(c, c + count); Action(); return; } if(!d.IsAccepted()) return; if(!isdrag) { isdrag = true; ScrollIntoCursor(); } Point dc = Null; if(c >= 0) dc = GetColumnLine(c); if(dc != dropcaret) { RefreshDropCaret(); dropcaret = dc; RefreshDropCaret(); } }
void Console::Append(const String& s) { if(s.IsEmpty()) return; if(console) { String t = Filter(s, sCharFilterNoCr); if(*t.Last() == '\n') t.Trim(t.GetCount() - 1); Puts(t); return; } int l, h; GetSelection(l, h); if(GetCursor() == GetLength()) l = -1; EditPos p = GetEditPos(); SetEditable(); MoveTextEnd(); WString t = Filter(s, sAppf).ToWString(); int mg = sb.GetReducedViewSize().cx / GetFont().GetAveWidth(); if(wrap_text && mg > 4) { int x = GetColumnLine(GetCursor()).x; WStringBuffer tt; const wchar *q = t; while(*q) { if(x > mg - 1) { tt.Cat('\n'); tt.Cat(" "); x = 4; } x++; if(*q == '\n') x = 0; tt.Cat(*q++); } Paste(tt); } else Paste(t); SetReadOnly(); if(l >= 0) { SetEditPos(p); SetSelection(l, h); } }
void LineEdit::PasteColumn(const WString& text) { Vector<WString> cl = Split(text, '\n', false); if(cl.GetCount() && cl.Top().IsEmpty()) cl.Drop(); if(cl.GetCount() == 0) return; int pos; if(IsRectSelection()) { Rect t = GetRectSelection(); RemoveSelection(); Point p = t.TopLeft(); pos = cursor; for(int i = 0; i < t.bottom - t.top + 1; i++) { CacheLinePos(i + p.y); int l = GetGPos(i + p.y, p.x); pos = l + Insert(l, cl[i % cl.GetCount()]); } } else { RemoveSelection(); Point p = GetColumnLine(cursor); pos = cursor; for(int i = 0; i < cl.GetCount(); i++) { CacheLinePos(i + p.y); int li = p.y + i; if(li < line.GetCount()) { int l = GetGPos(i + p.y, p.x); pos = l + Insert(l, cl[i]); } else { Insert(GetLength(), cl[i] + "\n"); pos = GetLength(); } } } PlaceCaret(pos); }
int LineEdit::PlaceCaretNoG(int newcursor, bool sel) { if(newcursor > total) newcursor = total; Point p = GetColumnLine(newcursor); if(sel) { if(anchor < 0) { anchor = cursor; } RefreshLines(p.y, GetLine(cursor)); } else if(anchor >= 0) { RefreshLines(GetLine(cursor), GetLine(anchor)); anchor = -1; } cursor = newcursor; ScrollIntoCursor(); PlaceCaret0(p); SelectionChanged(); WhenSel(); if(IsSelection()) SetSelectionSource(ClipFmtsText()); return p.x; }
LineEdit& LineEdit::TabSize(int n) { tabsize = n; PlaceCaret0(GetColumnLine(cursor)); Refresh(); return *this; }
void LineEdit::Scroll() { PlaceCaret0(GetColumnLine(cursor)); scroller.Scroll(*this, GetSize(), sb.Get(), GetFontSize()); SetHBar(); NewScrollPos(); }
void AssistEditor::SyncParamInfo() { String qtf; Ctrl *p = GetTopCtrl(); int mpar = INT_MAX; int pos = 0; if(p && p->HasFocusDeep()) { for(int q = 0; q < PARAMN; q++) { ParamInfo& m = param[q]; int i = GetCursorLine(); if(m.line >= 0 && m.line < GetLineCount() && i >= m.line && i < m.line + 10 && m.editfile == theide->editfile && GetWLine(m.line).StartsWith(m.test)) { int c = GetCursor(); i = GetPos(m.line) + m.test.GetCount(); if(c >= i) { int par = 0; int pari = 0; for(;;) { int ch = Ch(i++); if(i > c) { if(par < mpar) { qtf = "[A1 " + DecoratedItem(m.item.name, m.item, m.item.natural, pari); mpar = par; pos = m.pos; } break; } if(ch == ')') { if(par <= 0) break; par--; } if(ch == '(') par++; if(ch == ',' && par == 0) pari++; } } } } } if(param_qtf != qtf) param_info.SetQTF(qtf); Rect r = GetLineScreenRect(GetCursorLine()); int cx = max(GetSize().cx - 30, 300); int h = param_info.GetHeight(cx); h = min(h, 550); int y = r.top - h - 6; if(y < GetWorkArea().top) y = r.bottom; r = RectC(r.left, y, min(param_info.GetWidth(), cx) + 8, h + 6); r.OffsetHorz(GetColumnLine(pos).x * GetFontSize().cx); r.OffsetHorz(min(GetWorkArea().right - r.right, 0)); if(param_qtf != qtf || r != param_info.GetRect()) { param_qtf = qtf; if(IsNull(qtf)) { if(param_info.IsOpen()) param_info.Close(); } else { param_info.SetRect(r); if(!param_info.IsOpen() && !IsSelection()) param_info.Ctrl::PopUp(this, false, false, false); } } }
//////////////////////////////////////////////////////////////////// // Public functions // void CDrawGrid::Draw( int page, CDC* dc ) /* ============================================================ Function : CDrawGrid::Draw Description : Draws this object. Access : Public Return : void Parameters : int page - Current page CDC* dc - CDC to draw to Usage : Called by the generator to draw the object. ============================================================*/ { ///////////////////////////////// // Get and convert grid position // int drawpage = page - GetPageOffset(); CDoubleRect rect = GetPosition(); CUnitConversion::InchesToPixels( rect ); CRect r( static_cast< int >( rect.left ), static_cast< int >( rect.top ), static_cast< int >( rect.right ), static_cast< int >( rect.bottom ) ); CUnitConversion::AdjustPixelsToPaper( dc, r ); ///////////////////////////////// // Create column widths and // fonts // int restWidth = 0; int sumWidth = 0; TContainer< CFont* > fonts; double lpi = static_cast< double >( GetLPI() ); double inch = static_cast< double >( dc->GetDeviceCaps( LOGPIXELSY ) ); int lineHeight = static_cast< int >( inch / lpi + .5 ); int max = m_columns.GetSize(); for( int t = 0 ; t < max ; t++ ) { CColumn* column = m_columns.GetAt( t ); if( column ) { sumWidth += CUnitConversion::InchesToPixels( column->GetWidth() ); fonts.Add( column->GetColumnFont() ); } } // restWidth will be used for // any 0-length field restWidth = r.Width() - sumWidth; ///////////////////////////////// // Find start and end of data // int start = m_pages.GetAt( drawpage )->m_startLine; int end = m_pages.GetAt( drawpage )->m_endLine; int mode = dc->SetBkMode( TRANSPARENT ); COLORREF color = dc->GetTextColor(); ///////////////////////////////// // Border // const CBorderLine* borderline = GetBorder(); CPen pen; CPen boldPen; if( borderline->GetVisible() ) { // Draw a border around the grid int thickness = CUnitConversion::InchesToPixels( borderline->GetThickness() ); pen.CreatePen( borderline->GetStyle(), thickness, borderline->GetColor() ); dc->SelectObject( &pen ); dc->SelectStockObject( NULL_BRUSH ); dc->Rectangle( r ); dc->SelectStockObject( NULL_PEN ); } ///////////////////////////////// // Line pens // const CBorderLine* columnline = GetColumnLine(); const CBorderLine* rowline = GetRowLine(); CPen* columnpen = NULL; CPen* rowpen = NULL; if( columnline->GetVisible() ) { columnpen = new CPen; int thickness = CUnitConversion::InchesToPixels( columnline->GetThickness() ); columnpen->CreatePen( columnline->GetStyle(), thickness, columnline->GetColor() ); } if( rowline->GetVisible() ) { rowpen = new CPen; int thickness = CUnitConversion::InchesToPixels( rowline->GetThickness() ); rowpen->CreatePen( rowline->GetStyle(), thickness, rowline->GetColor() ); } ///////////////////////////////// // Column lines // if( columnpen ) { dc->SelectObject( columnpen ); int left = r.left; // Loop columns for( int i = 0 ; i < max - 1; i++ ) { CColumn* column = m_columns.GetAt( i ); if( column ) { int pixelWidth = CUnitConversion::InchesToPixels( column->GetWidth() ); if( pixelWidth == 0 ) pixelWidth = restWidth; left += pixelWidth; dc->MoveTo( left, r.top ); dc->LineTo( left, r.bottom ); } } dc->SelectStockObject( NULL_PEN ); } ///////////////////////////////// // Loop and print column strings // int top = r.top; for(int t = start ; t < end ; t++ ) { // Tokenize a line of data CString line( m_data[ t ] ); int quarterHeight = lineHeight / 4; // Check if this is a separator if( IsSeparator( line ) ) { // Draw a line across the grid dc->SelectStockObject( BLACK_PEN ); dc->MoveTo( r.left, top + quarterHeight ); dc->LineTo( r.right, top + quarterHeight ); } else if( IsDoubleSeparator( line ) ) { // Draw a double line across the grid dc->SelectStockObject( BLACK_PEN ); dc->MoveTo( r.left, top + quarterHeight ); dc->LineTo( r.right, top + quarterHeight ); dc->MoveTo( r.left, top + quarterHeight * 2 ); dc->LineTo( r.right, top + quarterHeight * 2 ); } else if( IsBoldSeparator( line ) ) { // Draw a bold line across the grid boldPen.CreatePen( PS_SOLID, quarterHeight / 2, RGB( 0, 0, 0 ) ); dc->SelectObject( boldPen ); dc->MoveTo( r.left, top + quarterHeight ); dc->LineTo( r.right, top + quarterHeight ); dc->SelectStockObject( BLACK_PEN ); } else { CTokenizer tok( line, _T( "|" ) ); int left = r.left; // Loop columns for( int i = 0 ; i < max ; i++ ) { CColumn* column = m_columns.GetAt( i ); CRect drawRect( left, top, r.right, top + lineHeight ); if( column ) { // Get the data for this column CString data; tok.GetAt( i, data ); // Get the width of the column int pixelWidth = CUnitConversion::InchesToPixels( column->GetWidth() ); if( pixelWidth == 0 ) pixelWidth = restWidth; // Set font CFont* font = fonts.GetAt( i ); CFont* specialFont = NULL; if( font ) { if( IsBold( data ) ) { // Select a bold font // here instead specialFont = new CFont; LOGFONT lf; font->GetLogFont( &lf ); lf.lfWeight = FW_BOLD; specialFont->CreateFontIndirect( &lf ); } if( IsItalic( data )) { // Select an italic font // here instead specialFont = new CFont; LOGFONT lf; font->GetLogFont( &lf ); lf.lfItalic = TRUE; specialFont->CreateFontIndirect( &lf ); } } if( specialFont ) dc->SelectObject( specialFont ); else if( font ) dc->SelectObject( font ); // Create draw rect drawRect.SetRect( left, top, left + pixelWidth, top + lineHeight ); // Add offsets for columns int offset = CUnitConversion::PointsToPixels( column->GetFontSize() / 40.0 ); if( borderline->GetVisible() && i == 0 ) offset += max( 1, CUnitConversion::InchesToPixels( borderline->GetThickness() ) ); if( columnline->GetVisible() && i > 0 ) offset += max( 1, CUnitConversion::InchesToPixels( columnline->GetThickness() ) ); drawRect.left += offset; drawRect.right -= offset; // Draw data int justification = column->GetJustification(); dc->DrawText( data, drawRect, DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK | justification ); if( specialFont ) delete specialFont; // Increase x-coord left += pixelWidth; } ///////////////////////////////// // Row dividers // if( rowpen && t < end ) { dc->SelectObject( rowpen ); dc->MoveTo( r.left, drawRect.bottom ); dc->LineTo( r.right, drawRect.bottom ); } } } // Increase y-coord top += lineHeight; } ///////////////////////////////// // Restore everything // dc->SetBkMode( mode ); dc->SetTextColor( color ); dc->SelectStockObject( ANSI_VAR_FONT ); dc->SelectStockObject( NULL_PEN ); if( columnpen ) delete columnpen; if( rowpen ) delete rowpen; }