// drawCondFmtCellIs provides a function to create conditional formatting rule
// for cell value (include between, not between, equal, not equal, greater
// than and less than) by given priority, criteria type and format settings.
174
func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule {
	c := &xlsxCfRule{
		Priority: p + 1,
		Type:     validType[format.Type],
		Operator: ct,
		DxfID:    &format.Format,
	}
	// "between" and "not between" criteria require 2 values.
	_, ok := map[string]bool{"between": true, "notBetween": true}[ct]
	if ok {
		c.Formula = append(c.Formula, format.Minimum)
		c.Formula = append(c.Formula, format.Maximum)
	}
	_, ok = map[string]bool{"equal": true, "notEqual": true, "greaterThan": true, "lessThan": true}[ct]
	if ok {
		c.Formula = append(c.Formula, format.Value)
	}
	return c
}
897744
func (c *Checkbox) Draw(screen tcell.Screen) {
	c.Box.Draw(screen)

	// Prepare
	x, y, width, height := c.GetInnerRect()
	rightLimit := x + width
	if height < 1 || rightLimit <= x {
		return
	}

	// Draw label.
	if c.labelWidth > 0 {
		labelWidth := c.labelWidth
		if labelWidth > rightLimit-x {
			labelWidth = rightLimit - x
		}
		Print(screen, c.label, x, y, labelWidth, AlignLeft, c.labelColor)
		x += labelWidth
	} else {
		_, drawnWidth := Print(screen, c.label, x, y, rightLimit-x, AlignLeft, c.labelColor)
		x += drawnWidth
	}

	// Draw checkbox.
	fieldStyle := tcell.StyleDefault.Background(c.fieldBackgroundColor).Foreground(c.fieldTextColor)
	if c.focus.HasFocus() {
		fieldStyle = fieldStyle.Background(c.fieldTextColor).Foreground(c.fieldBackgroundColor)
	}
	checkedRune := 'X'
	if !c.checked {
		checkedRune = ' '
	}
	screen.SetContent(x, y, checkedRune, nil, fieldStyle)
}
1022813
func fillCellData(rawCell xlsxC, refTable *RefTable, sharedFormulas map[int]sharedFormula, cell *Cell) {
	val := strings.Trim(rawCell.V, " \t\n\r")
	cell.formula = formulaForCell(rawCell, sharedFormulas)
	switch rawCell.T {
	case "s": // Shared String
		cell.cellType = CellTypeString
		if val != "" {
			ref, err := strconv.Atoi(val)
			if err != nil {
				panic(err)
			}
			cell.Value = refTable.ResolveSharedString(ref)
		}
	case "inlineStr":
		cell.cellType = CellTypeInline
		fillCellDataFromInlineString(rawCell, cell)
	case "b": // Boolean
		cell.Value = val
		cell.cellType = CellTypeBool
	case "e": // Error
		cell.Value = val
		cell.cellType = CellTypeError
	case "str":
		// String Formula (special type for cells with formulas that return a string value)
		// Unlike the other string cell types, the string is stored directly in the value.
		cell.Value = val
		cell.cellType = CellTypeStringFormula
	case "d": // Date: Cell contains a date in the ISO 8601 format.
		cell.Value = val
		cell.cellType = CellTypeDate
	case "": // Numeric is the default
		fallthrough
	case "n": // Numeric
		cell.Value = val
		cell.cellType = CellTypeNumeric
	default:
		panic(errors.New("invalid cell type"))
	}
}
1347795
func (c *ScrollFrame) DrawControl(t termboxControl) {
	if c.IsVisible(t) {
		ctlX, ctlY := t.GetX(), t.GetY()
		t.SetX((c.GetX() + ctlX))
		t.SetY((c.GetY() + ctlY))
		t.Draw()
		t.SetX(ctlX)
		t.SetY(ctlY)
	}
}
398328
func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
	min := &attrValFloat{Val: formatSet.YAxis.Minimum}
	max := &attrValFloat{Val: formatSet.YAxis.Maximum}
	if formatSet.YAxis.Minimum == 0 {
		min = nil
	}
	if formatSet.YAxis.Maximum == 0 {
		max = nil
	}
	return []*cAxs{
		{
			AxID: &attrValInt{Val: 753999904},
			Scaling: &cScaling{
				Orientation: &attrValString{Val: orientation[formatSet.YAxis.ReverseOrder]},
				Max:         max,
				Min:         min,
			},
			Delete: &attrValBool{Val: false},
			AxPos:  &attrValString{Val: valAxPos[formatSet.YAxis.ReverseOrder]},
			NumFmt: &cNumFmt{
				FormatCode:   chartValAxNumFmtFormatCode[formatSet.Type],
				SourceLinked: true,
			},
			MajorTickMark: &attrValString{Val: "none"},
			MinorTickMark: &attrValString{Val: "none"},
			TickLblPos:    &attrValString{Val: "nextTo"},
			SpPr:          f.drawPlotAreaSpPr(),
			TxPr:          f.drawPlotAreaTxPr(),
			CrossAx:       &attrValInt{Val: 754001152},
			Crosses:       &attrValString{Val: "autoZero"},
			CrossBetween:  &attrValString{Val: chartValAxCrossBetween[formatSet.Type]},
		},
	}
}
216926
func LOSetCellFormulaLocal(cell *ole.IDispatch, formula string) {
	oleutil.MustPutProperty(cell, "FormulaLocal", formula)
}
267277
func (a *Application) draw() *Application {
	a.Lock()
	defer a.Unlock()

	screen := a.screen
	root := a.root
	fullscreen := a.rootFullscreen
	before := a.beforeDraw
	after := a.afterDraw

	// Maybe we're not ready yet or not anymore.
	if screen == nil || root == nil {
		return a
	}

	// Resize if requested.
	if fullscreen && root != nil {
		width, height := screen.Size()
		root.SetRect(0, 0, width, height)
	}

	// Call before handler if there is one.
	if before != nil {
		if before(screen) {
			screen.Show()
			return a
		}
	}

	// Draw all primitives.
	root.Draw(screen)

	// Call after handler if there is one.
	if after != nil {
		after(screen)
	}

	// Sync screen.
	screen.Show()

	return a
}
278602
func fillCellData(rawcell xlsxC, reftable *RefTable, sharedFormulas map[int]sharedFormula, cell *Cell) {
	var data string = rawcell.V
	if len(data) > 0 {
		vval := strings.Trim(data, " \t\n\r")
		switch rawcell.T {
		case "s": // Shared String
			ref, error := strconv.Atoi(vval)
			if error != nil {
				panic(error)
			}
			cell.Value = reftable.ResolveSharedString(ref)
			cell.cellType = CellTypeString
		case "b": // Boolean
			cell.Value = vval
			cell.cellType = CellTypeBool
		case "e": // Error
			cell.Value = vval
			cell.formula = formulaForCell(rawcell, sharedFormulas)
			cell.cellType = CellTypeError
		default:
			if rawcell.F == nil {
				// Numeric
				cell.Value = vval
				cell.cellType = CellTypeNumeric
			} else {
				// Formula
				cell.Value = vval
				cell.formula = formulaForCell(rawcell, sharedFormulas)
				cell.cellType = CellTypeFormula
			}
		}
	}
}
41218
func (t *TextTable) Draw() string {
	drawedRows := make([]string, len(t.header)+len(t.rows)+3)
	index := 0

	border := t.borderString()

	// top line
	drawedRows[index] = border
	index++

	for _, row := range t.header {
		drawedRows[index] = t.generateRowString(row)
		index++
	}

	drawedRows[index] = border
	index++

	for _, row := range t.rows {
		var rowStr string
		if row.kind == ROW_CELLS {
			rowStr = t.generateRowString(row)
		} else {
			rowStr = border
		}
		drawedRows[index] = rowStr
		index++
	}

	// bottom line
	if len(t.rows) != 0 {
		drawedRows[index] = border
		index++
	}

	return strings.Join(drawedRows[:index], "\n")
}
815267
func (rgc *RasterGraphicContext) DrawImage(img image.Image) {
	DrawImage(img, rgc.img, rgc.current.Tr, draw.Over, BilinearFilter)
}
632098
func (i *ASCIIArt) Draw() {
	drawX, drawY := i.x, i.y
	for _, line := range i.contents {
		DrawStringAtPoint(line, drawX, drawY, i.fg, i.bg)
		drawY++
	}
}
836820
func (t *Table) printLineOptionalCellSeparators(nl bool, displayCellSeparator []bool) {
	fmt.Fprint(t.out, t.pCenter)
	for i := 0; i < len(t.cs); i++ {
		v := t.cs[i]
		if i > len(displayCellSeparator) || displayCellSeparator[i] {
			// Display the cell separator
			fmt.Fprintf(t.out, "%s%s%s%s",
				t.pRow,
				strings.Repeat(string(t.pRow), v),
				t.pRow,
				t.pCenter)
		} else {
			// Don't display the cell separator for this cell
			fmt.Fprintf(t.out, "%s%s",
				strings.Repeat(" ", v+2),
				t.pCenter)
		}
	}
	if nl {
		fmt.Fprint(t.out, t.newLine)
	}
}
817681
func drawConfFmtExp(p int, ct string, format *formatConditional) *xlsxCfRule {
	return &xlsxCfRule{
		Priority: p + 1,
		Type:     validType[format.Type],
		Formula:  []string{format.Criteria},
		DxfID:    &format.Format,
	}
}
611461
func (f *File) drawChartSeriesXVal(v formatChartSeries, formatSet *formatChart) *cCat {
	cat := &cCat{
		StrRef: &cStrRef{
			F: v.Categories,
		},
	}
	chartSeriesXVal := map[string]*cCat{Area: nil, AreaStacked: nil, AreaPercentStacked: nil, Area3D: nil, Area3DStacked: nil, Area3DPercentStacked: nil, Bar: nil, BarStacked: nil, BarPercentStacked: nil, Bar3DClustered: nil, Bar3DStacked: nil, Bar3DPercentStacked: nil, Col: nil, ColStacked: nil, ColPercentStacked: nil, Col3DClustered: nil, Col3D: nil, Col3DStacked: nil, Col3DPercentStacked: nil, Doughnut: nil, Line: nil, Pie: nil, Pie3D: nil, Radar: nil, Scatter: cat}
	return chartSeriesXVal[formatSet.Type]
}
495622
func (eb *EditBox) Draw(x, y, w, h int) {
	eb.AdjustVOffset(w)

	const coldef = termbox.ColorDefault
	fill(x, y, w, h, termbox.Cell{Ch: ' '})

	t := eb.text
	lx := 0
	tabstop := 0
	for {
		rx := lx - eb.line_voffset
		if len(t) == 0 {
			break
		}

		if lx == tabstop {
			tabstop += tabstop_length
		}

		if rx >= w {
			termbox.SetCell(x+w-1, y, '→',
				coldef, coldef)
			break
		}

		r, size := utf8.DecodeRune(t)
		if r == '\t' {
			for ; lx < tabstop; lx++ {
				rx = lx - eb.line_voffset
				if rx >= w {
					goto next
				}

				if rx >= 0 {
					termbox.SetCell(x+rx, y, ' ', coldef, coldef)
				}
			}
		} else {
			if rx >= 0 {
				termbox.SetCell(x+rx, y, r, coldef, coldef)
			}
			lx += runewidth.RuneWidth(r)
		}
	next:
		t = t[size:]
	}

	if eb.line_voffset != 0 {
		termbox.SetCell(x, y, '←', coldef, coldef)
	}
}
1291335
func (f *File) drawChartDLbls(formatSet *formatChart) *cDLbls {
	return &cDLbls{
		ShowLegendKey:   &attrValBool{Val: formatSet.Legend.ShowLegendKey},
		ShowVal:         &attrValBool{Val: formatSet.Plotarea.ShowVal},
		ShowCatName:     &attrValBool{Val: formatSet.Plotarea.ShowCatName},
		ShowSerName:     &attrValBool{Val: formatSet.Plotarea.ShowSerName},
		ShowBubbleSize:  &attrValBool{Val: formatSet.Plotarea.ShowBubbleSize},
		ShowPercent:     &attrValBool{Val: formatSet.Plotarea.ShowPercent},
		ShowLeaderLines: &attrValBool{Val: formatSet.Plotarea.ShowLeaderLines},
	}
}
1151329
func (f *File) drawDoughnutChart(formatSet *formatChart) *cPlotArea {
	return &cPlotArea{
		DoughnutChart: &cCharts{
			VaryColors: &attrValBool{
				Val: true,
			},
			Ser:      f.drawChartSeries(formatSet),
			HoleSize: &attrValInt{Val: 75},
		},
	}
}