std::shared_ptr<void> Type::CopyConstruct(const void * r) const { assert(IsCopyConstructible()); if(IsTrivial()) { auto obj = DefConstruct(); CopyAssign(obj.get(), r); return obj; } else return nonTrivialOps->copyConstruct(r); }
bool MultiButton::Metrics(int& border, int& lx, int &rx, const Rect& r) { border = IsTrivial() ? style->trivialborder : style->border; lx = r.left; rx = r.right; if(ComplexFrame()) { border = 0; return false; } if(!IsNull(style->edge[0])) { lx += border; rx -= border; return true; } border = 0; return false; }
int Subgraph::CalcSize(const Node *n) const { if (n->GetType() != TREE || n->IsPreterminal()) { return 0; } if (IsTrivial()) { return 1; } int count = 1; const std::vector<Node*> &children = n->GetChildren(); for (std::vector<Node *>::const_iterator p = children.begin(); p != children.end(); ++p) { if (m_leaves.find(*p) == m_leaves.end()) { count += CalcSize(*p); } } return count; }
nsresult nsSVGClipPathFrame::ClipPaint(nsSVGRenderState* aContext, nsISVGChildFrame* aParent, nsIDOMSVGMatrix *aMatrix) { // If the flag is set when we get here, it means this clipPath frame // has already been used painting the current clip, and the document // has a clip reference loop. if (mInUse) { NS_WARNING("Clip loop detected!"); return NS_OK; } AutoClipPathReferencer clipRef(this); mClipParent = aParent, mClipParentMatrix = aMatrix; PRBool isTrivial = IsTrivial(); nsAutoSVGRenderMode mode(aContext, isTrivial ? nsSVGRenderState::CLIP : nsSVGRenderState::CLIP_MASK); for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) { nsISVGChildFrame* SVGFrame = nsnull; CallQueryInterface(kid, &SVGFrame); if (SVGFrame) { // The CTM of each frame referencing us can be different. SVGFrame->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION | nsISVGChildFrame::TRANSFORM_CHANGED); SVGFrame->PaintSVG(aContext, nsnull); } } if (isTrivial) { aContext->GetGfxContext()->Clip(); aContext->GetGfxContext()->NewPath(); } return NS_OK; }
int MultiButton::ChState(int i) { if(i == MAIN && Frame() && style->activeedge) { int q = 0; Ctrl *p = GetParent(); if(p) q = !p->IsEnabled() || !IsEnabled() || i >= 0 && !button[i].enabled ? CTRL_DISABLED : p->HasFocus() || push ? CTRL_PRESSED : p->HasMouse() || hl >= 0 ? CTRL_HOT : CTRL_NORMAL; return q; } if(IsTrivial() && !Frame()) i = 0; if(!IsShowEnabled() || i >= 0 && !button[i].enabled) return CTRL_DISABLED; return hl == i ? push ? CTRL_PRESSED : CTRL_HOT : CTRL_NORMAL; }
int Subgraph::CountNodes(const Node *n) const { if (n->GetType() != TREE) { return 0; } if (IsTrivial()) { return 1; } int count = 1; const std::vector<Node*> &children = n->GetChildren(); for (std::vector<Node *>::const_iterator p = children.begin(); p != children.end(); ++p) { const Node *child = *p; if (m_leaves.find(child) == m_leaves.end()) { count += CountNodes(child); } else if (child->GetType() == TREE) { ++count; } } return count; }
int MultiButton::FindButton(int px) { if(IsReadOnly()) return Null; if(IsTrivial() && !Frame()) return button[0].enabled ? 0 : Null; int border, lx, rx; Metrics(border, lx, rx); for(int i = 0; i < button.GetCount(); i++) { SubButton& b = button[i]; int x = 0, cx = 0; if(GetPos(b, lx, rx, x, cx, px)) return b.enabled ? i : Null; } if(WhenPush || WhenClick) return MAIN; if(display) for(int i = 0; i < button.GetCount(); i++) if(button[i].main) return i; return Null; }
void MultiButton::LeftDown(Point p, dword flags) { push = true; Refresh(); if(IsNull(hl)) pushrect = Null; else { if(hl == MAIN) pushrect = GetScreenRect(); else { int x, cx; int border = IsTrivial() ? style->trivialborder : style->border; GetPos(hl, x, cx); pushrect = RectC(x, border, cx, GetSize().cy - 2 * border) .Offseted(GetScreenView().TopLeft()); } Sync(); if(hl >= 0) button[hl].WhenPush(); else WhenPush(); } }
void MultiButton::Lay(Rect& r) { int border, lx, rx; bool frm = Metrics(border, lx, rx); bool left = false; bool right = false; for(int i = 0; i < button.GetCount(); i++) { SubButton& b = button[i]; int cx = 0; int x = 0; GetPos(b, lx, rx, x, cx); (b.left ? left : right) = true; } if(ComplexFrame()) { r.right = r.left + rx; r.left += lx; } else if(frm) { Rect m = GetMargin(); r = Rect(r.left + max(lx, m.left), r.top + m.top, min(rx, r.right - m.right), r.bottom - m.bottom); } else { Rect m = style->margin; r = Rect(r.left + max(lx, m.left), r.top + m.top, min(rx, r.right - m.right), r.bottom - m.bottom); if(!IsTrivial() || style->trivialsep) { if(left) r.left++; if(right) r.right--; } } if(!IsNull(valuecy)) { r.top += (r.GetHeight() - valuecy) / 2; r.bottom = r.top + valuecy; } }
void MultiButton::Paint(Draw& w) { Size sz = GetSize(); int border, lx, rx; bool frm = Metrics(border, lx, rx); int mst = ChState(MAIN); if(frm && !nobg) ChPaint(w, sz, style->edge[style->activeedge ? mst : 0]); bool left = false; bool right = false; for(int i = 0; i < button.GetCount(); i++) { SubButton& b = button[i]; int st = ChState(i); int x = 0, cx = 0; GetPos(b, lx, rx, x, cx); bool dopaint = true; Value v = b.left ? left ? style->lmiddle[st] : style->left[st] : right ? style->rmiddle[st] : style->right[st]; if(!nobg) { if(ComplexFrame()) ChPaint(w, x, border, cx, sz.cy - 2 * border, style->simple[st]); else if(frm) { if(IsTrivial() && style->usetrivial) dopaint = false; ChPaint(w, x, border, cx, sz.cy - 2 * border, dopaint ? v : style->trivial[st]); } else { w.Clip(x, 0, cx, sz.cy); ChPaint(w, sz, style->look[Frame() ? mst : st]); if(IsNull(v) || !Frame()) { if((!IsTrivial() || style->trivialsep) && IsEnabled()) { if(b.left) { if(left) ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); } else { ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); if(right) ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); } } } else ChPaint(w, x, 0, cx, sz.cy, v); w.End(); } } if(dopaint) { Size tsz = GetTextSize(b.label, StdFont()); Image m = tsz.cx > 0 ? b.img : (Image)Nvl(b.img, CtrlsImg::DA()); Size isz = m.GetSize(); Point p = (st == CTRL_PRESSED) * style->pressoffset; p.x += x + (cx - isz.cx - tsz.cx - (tsz.cx > 0 && isz.cx > 0 ? LB_IMAGE : 0)) / 2; p.y += (sz.cy - isz.cy) / 2; if(b.left) { if(!left) p.x += style->loff; } else if(!right) p.x += style->roff; if(b.monoimg || IsNull(b.img)) w.DrawImage(p.x, p.y, m, frm ? style->fmonocolor[st] : style->monocolor[st]); else w.DrawImage(p.x, p.y, m); if(tsz.cx > 0) { if(isz.cx > 0) p.x += isz.cx + LB_IMAGE; w.DrawText(p.x, (sz.cy - tsz.cy) / 2, b.label); } } (b.left ? left : right) = true; } Rect r, cr; cr = GetSize(); cr.left = lx; cr.right = rx; Color text = SColorLabel(); Color paper = Null; if(!nobg) { if(ComplexFrame()) { r = cr; paper = HasFocus() ? SColorHighlight() : SColorPaper(); if(HasFocus()) text = SColorHighlightText(); w.DrawRect(r, paper); } else if(frm) { Rect m = GetMargin(); r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom); Color paper; if(mst == CTRL_HOT && !IsTrivial()) paper = Blend(SColorHighlight, SColorPaper, 235); else if(mst == CTRL_PRESSED && !IsTrivial()) paper = Blend(SColorHighlight, SColorFace, 235); else if(HasFocus()) { paper = SColorHighlight(); text = SColorHighlightText(); } else paper = SColorPaper(); w.DrawRect(r, paper); cr = r; } else { w.Clip(lx, 0, rx - lx, sz.cy); ChPaint(w, sz, style->look[mst]); Rect m = style->margin; r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom); if(!IsTrivial() || style->trivialsep) { if(left) { r.left++; if(IsEnabled()) ChPaint(w, lx, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); } if(right) { if(IsEnabled()) ChPaint(w, rx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); r.right--; } } w.End(); cr = r; } } cr.left++; Rect clr = cr; if(!IsNull(valuecy)) { cr.top += (cr.GetHeight() - valuecy + 1) / 2; cr.bottom = cr.top + valuecy; } Value v = convert->Format(value); bool f = HasFocus() && !push && frm; if(cr.left < cr.right && display) { w.Clip(clr); display->Paint(w, cr, v, IsShowEnabled() ? text : SColorDisabled, paper, f ? Display::CURSOR : Display::FOCUS|Display::CURSOR); w.End(); } if(!frm && HasFocus()) DrawFocus(w, r); }
std::shared_ptr<void> Type::MoveConstruct(void * r) const { assert(IsMoveConstructible()); if(IsTrivial()) return CopyConstruct(r); else return nonTrivialOps->moveConstruct(r); }
nsresult nsSVGClipPathFrame::ClipPaint(nsSVGRenderState* aContext, nsIFrame* aParent, const gfxMatrix &aMatrix) { // If the flag is set when we get here, it means this clipPath frame // has already been used painting the current clip, and the document // has a clip reference loop. if (mInUse) { NS_WARNING("Clip loop detected!"); return NS_OK; } AutoClipPathReferencer clipRef(this); mClipParent = aParent; if (mClipParentMatrix) { *mClipParentMatrix = aMatrix; } else { mClipParentMatrix = new gfxMatrix(aMatrix); } bool isTrivial = IsTrivial(); nsAutoSVGRenderMode mode(aContext, isTrivial ? nsSVGRenderState::CLIP : nsSVGRenderState::CLIP_MASK); gfxContext *gfx = aContext->GetGfxContext(); nsSVGClipPathFrame *clipPathFrame = nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nsnull); bool referencedClipIsTrivial; if (clipPathFrame) { referencedClipIsTrivial = clipPathFrame->IsTrivial(); gfx->Save(); if (referencedClipIsTrivial) { clipPathFrame->ClipPaint(aContext, aParent, aMatrix); } else { gfx->PushGroup(gfxASurface::CONTENT_ALPHA); } } for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) { nsISVGChildFrame* SVGFrame = do_QueryFrame(kid); if (SVGFrame) { // The CTM of each frame referencing us can be different. SVGFrame->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION | nsISVGChildFrame::TRANSFORM_CHANGED); bool isOK = true; nsSVGClipPathFrame *clipPathFrame = nsSVGEffects::GetEffectProperties(kid).GetClipPathFrame(&isOK); if (!isOK) { continue; } bool isTrivial; if (clipPathFrame) { isTrivial = clipPathFrame->IsTrivial(); gfx->Save(); if (isTrivial) { clipPathFrame->ClipPaint(aContext, aParent, aMatrix); } else { gfx->PushGroup(gfxASurface::CONTENT_ALPHA); } } SVGFrame->PaintSVG(aContext, nsnull); if (clipPathFrame) { if (!isTrivial) { gfx->PopGroupToSource(); nsRefPtr<gfxPattern> clipMaskSurface; gfx->PushGroup(gfxASurface::CONTENT_ALPHA); clipPathFrame->ClipPaint(aContext, aParent, aMatrix); clipMaskSurface = gfx->PopGroup(); if (clipMaskSurface) { gfx->Mask(clipMaskSurface); } } gfx->Restore(); } } } if (clipPathFrame) { if (!referencedClipIsTrivial) { gfx->PopGroupToSource(); nsRefPtr<gfxPattern> clipMaskSurface; gfx->PushGroup(gfxASurface::CONTENT_ALPHA); clipPathFrame->ClipPaint(aContext, aParent, aMatrix); clipMaskSurface = gfx->PopGroup(); if (clipMaskSurface) { gfx->Mask(clipMaskSurface); } } gfx->Restore(); } if (isTrivial) { gfx->Clip(); gfx->NewPath(); } return NS_OK; }
nsresult nsSVGClipPathFrame::ClipPaint(nsRenderingContext* aContext, nsIFrame* aParent, const gfxMatrix &aMatrix) { // If the flag is set when we get here, it means this clipPath frame // has already been used painting the current clip, and the document // has a clip reference loop. if (mInUse) { NS_WARNING("Clip loop detected!"); return NS_OK; } AutoClipPathReferencer clipRef(this); mClipParent = aParent; if (mClipParentMatrix) { *mClipParentMatrix = aMatrix; } else { mClipParentMatrix = new gfxMatrix(aMatrix); } gfxContext *gfx = aContext->ThebesContext(); nsISVGChildFrame *singleClipPathChild = nsnull; if (IsTrivial(&singleClipPathChild)) { // Notify our child that it's painting as part of a clipPath, and that // we only require it to draw its path (it should skip filling, etc.): SVGAutoRenderState mode(aContext, SVGAutoRenderState::CLIP); if (!singleClipPathChild) { // We have no children - the spec says clip away everything: gfx->Rectangle(gfxRect()); } else { singleClipPathChild->NotifySVGChanged( nsISVGChildFrame::DO_NOT_NOTIFY_RENDERING_OBSERVERS | nsISVGChildFrame::TRANSFORM_CHANGED); singleClipPathChild->PaintSVG(aContext, nsnull); } gfx->Clip(); gfx->NewPath(); return NS_OK; } // Seems like this is a non-trivial clipPath, so we need to use a clip mask. // Notify our children that they're painting into a clip mask: SVGAutoRenderState mode(aContext, SVGAutoRenderState::CLIP_MASK); // Check if this clipPath is itself clipped by another clipPath: nsSVGClipPathFrame *clipPathFrame = nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nsnull); bool referencedClipIsTrivial; if (clipPathFrame) { referencedClipIsTrivial = clipPathFrame->IsTrivial(); gfx->Save(); if (referencedClipIsTrivial) { clipPathFrame->ClipPaint(aContext, aParent, aMatrix); } else { gfx->PushGroup(gfxASurface::CONTENT_ALPHA); } } for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) { nsISVGChildFrame* SVGFrame = do_QueryFrame(kid); if (SVGFrame) { // The CTM of each frame referencing us can be different. SVGFrame->NotifySVGChanged( nsISVGChildFrame::DO_NOT_NOTIFY_RENDERING_OBSERVERS | nsISVGChildFrame::TRANSFORM_CHANGED); bool isOK = true; nsSVGClipPathFrame *clipPathFrame = nsSVGEffects::GetEffectProperties(kid).GetClipPathFrame(&isOK); if (!isOK) { continue; } bool isTrivial; if (clipPathFrame) { isTrivial = clipPathFrame->IsTrivial(); gfx->Save(); if (isTrivial) { clipPathFrame->ClipPaint(aContext, aParent, aMatrix); } else { gfx->PushGroup(gfxASurface::CONTENT_ALPHA); } } SVGFrame->PaintSVG(aContext, nsnull); if (clipPathFrame) { if (!isTrivial) { gfx->PopGroupToSource(); nsRefPtr<gfxPattern> clipMaskSurface; gfx->PushGroup(gfxASurface::CONTENT_ALPHA); clipPathFrame->ClipPaint(aContext, aParent, aMatrix); clipMaskSurface = gfx->PopGroup(); if (clipMaskSurface) { gfx->Mask(clipMaskSurface); } } gfx->Restore(); } } } if (clipPathFrame) { if (!referencedClipIsTrivial) { gfx->PopGroupToSource(); nsRefPtr<gfxPattern> clipMaskSurface; gfx->PushGroup(gfxASurface::CONTENT_ALPHA); clipPathFrame->ClipPaint(aContext, aParent, aMatrix); clipMaskSurface = gfx->PopGroup(); if (clipMaskSurface) { gfx->Mask(clipMaskSurface); } } gfx->Restore(); } return NS_OK; }
void Type::MoveAssign(void * l, void * r) const { assert(IsMoveAssignable()); if(IsTrivial()) CopyAssign(l, r); else nonTrivialOps->moveAssign(l, r); }
void Type::CopyAssign(void * l, const void * r) const { assert(IsCopyAssignable()); if(IsTrivial()) memcpy(l, r, size); else nonTrivialOps->copyAssign(l, r); }
char* Preprocessor::ParseLexem( char* start, char* end, Lexem& out ) { if( start == end ) return start; char current_char = *start; if( IsTrivial( current_char ) ) { out.Value += current_char; out.Type = TrivialTypes[Trivials.find_first_of( current_char )]; return ++start; } if( IsIdentifierStart( current_char ) ) return ParseIdentifier( start, end, out ); if( current_char == '#' ) { out.Value = "#"; ++start; if( *start == '#' ) { out.Value = "##"; out.Type = Lexem::IGNORE; return ( ++start ); } while( start != end && ( *start == ' ' || *start == '\t' ) ) ++start; if( start != end && IsIdentifierStart( *start ) ) start = ParseIdentifier( start, end, out ); out.Type = Lexem::PREPROCESSOR; return start; } if( IsNumber( current_char ) ) return ParseNumber( start, end, out ); if( current_char == '\"' ) return ParseStringLiteral( start, end, '\"', out ); if( current_char == '\'' ) return ParseStringLiteral( start, end, '\'', out ); // Todo: set optional ParseCharacterLiteral? if( current_char == '/' ) { // Need to see if it's a comment. ++start; if( start == end ) return start; if( *start == '*' ) return ParseBlockComment( start, end, out ); if( *start == '/' ) return ParseLineComment( start, end, out ); // Not a comment - let default code catch it as MISC --start; } if( current_char == '\\' ) { out.Type = Lexem::BACKSLASH; return ++start; } out.Value = std::string( 1, current_char ); out.Type = Lexem::IGNORE; return ++start; }
std::shared_ptr<void> Type::DefConstruct() const { assert(IsDefConstructible()); if(IsTrivial()) return std::shared_ptr<void>(std::malloc(size), std::free); // Manage trivial types with malloc and free else return nonTrivialOps->defConstruct(); // If the type has a constructor, invoke it }