コード例 #1
0
ファイル: seldraw.cpp プロジェクト: cyclefusion/szarp
void SelectDrawWidget::InsertSomeDraws(size_t start, size_t count) {
	wxSizer *sizer = GetSizer();
	int width = GetCheckBoxWidth();
	ConfigNameHash& cnm = const_cast<ConfigNameHash&>(m_cfg->GetConfigTitles());

	for (size_t i = start; count; count--, i++) {
		if (i >= m_cb_l.size()) {
			i = m_cb_l.size();
			m_cb_l.push_back(new wxCheckBox());
			m_cb_l[i]->Create(this, drawID_SELDRAWCB,
				wxString::Format(_T("%d."), i + 1),
				wxDefaultPosition, wxSize(width, -1), 0,
				SelectDrawValidator(m_draws_wdg, i, m_cb_l[i]));
			m_cb_l[i]->Enable(FALSE);
			m_cb_l[i]->SetToolTip(wxEmptyString);
			m_cb_l[i]->SetBackgroundColour(DRAW3_BG_COLOR);

			sizer->Add(m_cb_l[i], 0, wxTOP | wxLEFT | wxRIGHT, 1);
		}

		Draw* draw = m_dc->GetDraw(i);
		DrawInfo* draw_info = draw->GetDrawInfo();
		wxString label;
		if (draw_info->IsValid()) {
			m_cb_l[i]->Enable(TRUE);
			m_cb_l[i]->SetValue(draw->GetEnable());
			m_cb_l[i]->SetToolTip(cnm[draw_info->GetBasePrefix()] + _T(":") + draw_info->GetParamName());

			label = wxString::Format(_T("%d."), draw->GetInitialDrawNo() + 1) + draw_info->GetName();
			if (draw_info->GetParam()->GetIPKParam()->GetPSC())
				label += _T("*");
			if (draw->GetBlocked())
				label.Replace(wxString::Format(_T("%d."), draw->GetInitialDrawNo() + 1), wxString::Format(_("%d.[B]"), i + 1), false);
		} else {
			label = _T("***");
		}
		m_cb_l[i]->SetLabel(label);

		wxValidator* validator = m_cb_l[i]->GetValidator();
		if (validator)
			dynamic_cast<SelectDrawValidator*>(validator)->Set(m_draws_wdg, i, m_cb_l[i]);
		else
			m_cb_l[i]->SetValidator(SelectDrawValidator(m_draws_wdg, i, m_cb_l[i]));

		m_cb_l[i]->SetBackgroundColour(draw_info->GetDrawColor());

#ifdef MINGW32
		m_cb_l[i]->Refresh();
#endif

	}

	if (m_cb_l.size() > MIN_DRAWS_COUNT)
		SetScrollRate(10, 10);
	else
		SetScrollRate(0, 0);

	sizer->Layout();
}
コード例 #2
0
ファイル: seldraw.cpp プロジェクト: cyclefusion/szarp
SelectDrawWidget::SelectDrawWidget(ConfigManager *cfg, DatabaseManager *dbmgr, DrawsWidget *drawswdg, RemarksHandler *remarks_handler, wxWindow* parent, wxWindowID id): wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS, _T("SelectDrawWidget")), m_remarks_handler(remarks_handler)
{
	assert (cfg != NULL);
	m_cfg = cfg;
	assert(drawswdg != NULL);
	m_draws_wdg = drawswdg;
	assert(dbmgr != NULL);
	m_dbmgr = dbmgr;

	SetHelpText(_T("draw3-base-hidegraphs"));

	wxBoxSizer * sizer1 = new wxBoxSizer(wxVERTICAL);

	int width = GetCheckBoxWidth();
	m_cb_l.resize(MIN_DRAWS_COUNT);

	for (size_t i = 0; i < MIN_DRAWS_COUNT; i++) {
		m_cb_l[i] = new wxCheckBox();
		m_cb_l[i]->Create(this, drawID_SELDRAWCB,
			wxString::Format(_T("%d."), i + 1),
			wxDefaultPosition, wxSize(width, -1), 0,
			SelectDrawValidator(m_draws_wdg, i, m_cb_l[i]));
		m_cb_l[i]->Enable(FALSE);

		m_cb_l[i]->SetToolTip(wxEmptyString);
		m_cb_l[i]->SetBackgroundColour(DRAW3_BG_COLOR);


		sizer1->Add(m_cb_l[i], 0, wxTOP | wxLEFT | wxRIGHT, 1);

#ifdef MINGW32
		m_cb_l[i]->Refresh();
#endif
	}

	SetSizer(sizer1);
	sizer1->SetSizeHints(this);
	sizer1->Layout();

	m_timer = new wxTimer(this, wxID_ANY);

}
コード例 #3
0
ファイル: clRowEntry.cpp プロジェクト: eranif/codelite
void clRowEntry::Render(wxWindow* win, wxDC& dc, const clColours& c, int row_index, clSearchText* searcher)
{
    wxUnusedVar(searcher);
    wxRect rowRect = GetItemRect();
    bool zebraColouring = (m_tree->HasStyle(wxTR_ROW_LINES) || m_tree->HasStyle(wxDV_ROW_LINES));
    bool even_row = ((row_index % 2) == 0);

    // Define the clipping region
    bool hasHeader = (m_tree->GetHeader() && !m_tree->GetHeader()->empty());

    // Not cell related
    clColours colours = c;
    if(zebraColouring) {
        // Set Zebra colouring, only if no user colour was provided for the given line
        colours.SetItemBgColour(even_row ? c.GetAlternateColour() : c.GetBgColour());
    }

    // Override default item bg colour with the user's one
    if(GetBgColour().IsOk()) { colours.SetItemBgColour(GetBgColour()); }
    wxRect selectionRect = rowRect;
    wxPoint deviceOrigin = dc.GetDeviceOrigin();
    selectionRect.SetX(-deviceOrigin.x);
    if(IsSelected()) {
        DrawSimpleSelection(win, dc, selectionRect, colours);
    } else if(IsHovered()) {
        dc.SetPen(colours.GetHoverBgColour());
        dc.SetBrush(colours.GetHoverBgColour());
        dc.DrawRectangle(selectionRect);
    } else if(colours.GetItemBgColour().IsOk()) {
        dc.SetBrush(colours.GetItemBgColour());
        dc.SetPen(colours.GetItemBgColour());
        dc.DrawRectangle(selectionRect);
    }

    // Per cell drawings
    for(size_t i = 0; i < m_cells.size(); ++i) {
        bool last_cell = (i == (m_cells.size() - 1));
        colours = c; // reset the colours
        wxFont f = clScrolledPanel::GetDefaultFont();
        clCellValue& cell = GetColumn(i);
        if(cell.GetFont().IsOk()) { f = cell.GetFont(); }
        if(cell.GetTextColour().IsOk()) { colours.SetItemTextColour(cell.GetTextColour()); }
        if(cell.GetBgColour().IsOk()) { colours.SetItemBgColour(cell.GetBgColour()); }
        dc.SetFont(f);
        wxColour buttonColour = IsSelected() ? colours.GetSelbuttonColour() : colours.GetButtonColour();
        wxRect cellRect = GetCellRect(i);

        // We use a helper class to clip the drawings this ensures that if we exit the scope
        // the clipping region is restored properly
        clClipperHelper clipper(dc);
        if(hasHeader) { clipper.Clip(cellRect); }

        int textXOffset = cellRect.GetX();
        if((i == 0) && !IsListItem()) {
            // The expand button is only make sense for the first cell
            if(HasChildren()) {
                wxRect buttonRect = GetButtonRect();
                buttonRect.Deflate(1);
                textXOffset += buttonRect.GetWidth();
                if(m_tree->IsNativeTheme() && !IS_OSX) {
                    int flags = wxCONTROL_CURRENT;
                    if(IsExpanded()) { flags |= wxCONTROL_EXPANDED; }
                    int button_width = wxSystemSettings::GetMetric(wxSYS_SMALLICON_X);
                    wxRect modButtonRect = buttonRect;
                    modButtonRect.SetWidth(button_width);
                    modButtonRect.SetHeight(button_width);
                    modButtonRect = modButtonRect.CenterIn(buttonRect);
                    wxRendererNative::Get().DrawTreeItemButton(win, dc, modButtonRect, flags);
                } else {
                    wxRect buttonRect = GetButtonRect();
                    if(textXOffset >= cellRect.GetWidth()) {
                        // if we cant draw the button (off screen etc)
                        SetRects(GetItemRect(), wxRect());
                        continue;
                    }
                    buttonRect.Deflate((buttonRect.GetWidth() / 3), (buttonRect.GetHeight() / 3));
                    wxRect tribtn = buttonRect;
                    dc.SetPen(wxPen(buttonColour, 2));
                    if(IsExpanded()) {
                        tribtn.SetHeight(tribtn.GetHeight() - tribtn.GetHeight() / 2);
                        tribtn = tribtn.CenterIn(buttonRect);
                        wxPoint middleLeft = wxPoint((tribtn.GetLeft() + tribtn.GetWidth() / 2), tribtn.GetBottom());
                        dc.DrawLine(tribtn.GetTopLeft(), middleLeft);
                        dc.DrawLine(tribtn.GetTopRight(), middleLeft);
                    } else {
                        tribtn.SetWidth(tribtn.GetWidth() - tribtn.GetWidth() / 2);
                        tribtn = tribtn.CenterIn(buttonRect);

                        wxPoint middleLeft = wxPoint(tribtn.GetRight(), (tribtn.GetY() + (tribtn.GetHeight() / 2)));
                        wxPoint p1 = tribtn.GetTopLeft();
                        wxPoint p2 = tribtn.GetBottomLeft();
                        dc.DrawLine(p1, middleLeft);
                        dc.DrawLine(middleLeft, p2);
                    }
                }

            } else {
                wxRect buttonRect(rowRect);
                buttonRect.SetWidth(rowRect.GetHeight());
                buttonRect.Deflate(1);
                textXOffset += buttonRect.GetWidth();
                if(textXOffset >= cellRect.GetWidth()) {
                    SetRects(GetItemRect(), wxRect());
                    continue;
                }
            }
        }
        int itemIndent = IsListItem() ? clHeaderItem::X_SPACER : (GetIndentsCount() * m_tree->GetIndent());
        int bitmapIndex = cell.GetBitmapIndex();
        if(IsExpanded() && HasChildren() && cell.GetBitmapSelectedIndex() != wxNOT_FOUND) {
            bitmapIndex = cell.GetBitmapSelectedIndex();
        }

        // Draw checkbox
        if(cell.IsBool()) {
            // Render the checkbox
            textXOffset += X_SPACER;
            int checkboxSize = GetCheckBoxWidth(win);
            wxRect checkboxRect = wxRect(textXOffset, rowRect.GetY(), checkboxSize, checkboxSize);
            checkboxRect = checkboxRect.CenterIn(rowRect, wxVERTICAL);
            dc.SetPen(colours.GetItemTextColour());
            RenderCheckBox(win, dc, colours, checkboxRect, cell.GetValueBool());
            cell.SetCheckboxRect(checkboxRect);
            textXOffset += checkboxRect.GetWidth();
            textXOffset += X_SPACER;
        } else {
            cell.SetCheckboxRect(wxRect()); // clear the checkbox rect
        }

        // Draw the bitmap
        if(bitmapIndex != wxNOT_FOUND) {
            const wxBitmap& bmp = m_tree->GetBitmap(bitmapIndex);
            if(bmp.IsOk()) {
                textXOffset += IsListItem() ? 0 : X_SPACER;
                int bitmapY = rowRect.GetY() + ((rowRect.GetHeight() - bmp.GetScaledHeight()) / 2);
                // if((textXOffset + bmp.GetScaledWidth()) >= cellRect.GetWidth()) { continue; }
                dc.DrawBitmap(bmp, itemIndent + textXOffset, bitmapY, true);
                textXOffset += bmp.GetScaledWidth();
                textXOffset += X_SPACER;
            }
        }

        // Draw the text
        wxRect textRect(dc.GetTextExtent(cell.GetValueString()));
        textRect = textRect.CenterIn(rowRect, wxVERTICAL);
        int textY = textRect.GetY();
        int textX = (i == 0 ? itemIndent : clHeaderItem::X_SPACER) + textXOffset;
        RenderText(win, dc, colours, cell.GetValueString(), textX, textY, i);
        textXOffset += textRect.GetWidth();
        textXOffset += X_SPACER;

        if(cell.IsChoice()) {
            // draw the drop down arrow. Make it aligned to the right
            wxRect dropDownRect(cellRect.GetTopRight().x - rowRect.GetHeight(), rowRect.GetY(), rowRect.GetHeight(),
                                rowRect.GetHeight());
            dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL);
            DrawingUtils::DrawDropDownArrow(win, dc, dropDownRect, wxNullColour);
            // Keep the rect to test clicks
            cell.SetDropDownRect(dropDownRect);
            textXOffset += dropDownRect.GetWidth();
            textXOffset += X_SPACER;
            
            // Draw a separator line between the drop down arrow and the rest of the cell content
            dropDownRect.Deflate(3);
            dropDownRect = dropDownRect.CenterIn(rowRect, wxVERTICAL);
            dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE));
            dc.DrawLine(dropDownRect.GetTopLeft(), dropDownRect.GetBottomLeft());
            
        } else {
            cell.SetDropDownRect(wxRect());
        }

        if(!last_cell) {
            cellRect.SetHeight(rowRect.GetHeight());
            dc.SetPen(wxPen(colours.GetHeaderVBorderColour(), 1, PEN_STYLE));
            dc.DrawLine(cellRect.GetTopRight(), cellRect.GetBottomRight());
        }
    }
}