wxRect wxRibbonPanel::GetExpandedPosition(wxRect panel, wxSize expanded_size, wxDirection direction) { // Strategy: // 1) Determine primary position based on requested direction // 2) Move the position so that it sits entirely within a display // (for single monitor systems, this moves it into the display region, // but for multiple monitors, it does so without splitting it over // more than one display) // 2.1) Move in the primary axis // 2.2) Move in the secondary axis wxPoint pos; bool primary_x = false; int secondary_x = 0; int secondary_y = 0; switch(direction) { case wxNORTH: pos.x = panel.GetX() + (panel.GetWidth() - expanded_size.GetWidth()) / 2; pos.y = panel.GetY() - expanded_size.GetHeight(); primary_x = true; secondary_y = 1; break; case wxEAST: pos.x = panel.GetRight(); pos.y = panel.GetY() + (panel.GetHeight() - expanded_size.GetHeight()) / 2; secondary_x = -1; break; case wxSOUTH: pos.x = panel.GetX() + (panel.GetWidth() - expanded_size.GetWidth()) / 2; pos.y = panel.GetBottom(); primary_x = true; secondary_y = -1; break; case wxWEST: default: pos.x = panel.GetX() - expanded_size.GetWidth(); pos.y = panel.GetY() + (panel.GetHeight() - expanded_size.GetHeight()) / 2; secondary_x = 1; break; } wxRect expanded(pos, expanded_size); wxRect best(expanded); int best_distance = INT_MAX; const unsigned display_n = wxDisplay::GetCount(); unsigned display_i; for(display_i = 0; display_i < display_n; ++display_i) { wxRect display = wxDisplay(display_i).GetGeometry(); if(display.Contains(expanded)) { return expanded; } else if(display.Intersects(expanded)) { wxRect new_rect(expanded); int distance = 0; if(primary_x) { if(expanded.GetRight() > display.GetRight()) { distance = expanded.GetRight() - display.GetRight(); new_rect.x -= distance; } else if(expanded.GetLeft() < display.GetLeft()) { distance = display.GetLeft() - expanded.GetLeft(); new_rect.x += distance; } } else { if(expanded.GetBottom() > display.GetBottom()) { distance = expanded.GetBottom() - display.GetBottom(); new_rect.y -= distance; } else if(expanded.GetTop() < display.GetTop()) { distance = display.GetTop() - expanded.GetTop(); new_rect.y += distance; } } if(!display.Contains(new_rect)) { // Tried moving in primary axis, but failed. // Hence try moving in the secondary axis. int dx = secondary_x * (panel.GetWidth() + expanded_size.GetWidth()); int dy = secondary_y * (panel.GetHeight() + expanded_size.GetHeight()); new_rect.x += dx; new_rect.y += dy; // Squaring makes secondary moves more expensive (and also // prevents a negative cost) distance += dx * dx + dy * dy; } if(display.Contains(new_rect) && distance < best_distance) { best = new_rect; best_distance = distance; } } } return best; }
TreeForTaxon::TreeForTaxon(wxString typeTaxon) { try { AppMenuBar &appMenuBar = AppMenuBar::Instance(); appMenuBar.disableAllMenus(); bool addId = true; wxString title = _("Arborescence des "); title += typeTaxon; title += "s"; Create(NULL, wxID_ANY, title, winRectGbl.GetPosition(), winRectGbl.GetSize(), (wxDEFAULT_FRAME_STYLE | wxMINIMIZE_BOX | wxCLOSE_BOX) & ~(wxMAXIMIZE_BOX | wxRESIZE_BORDER), wxEmptyString); this->SetBackgroundColour(Couleurs::backgColor); wxPanel *panel0 = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(largeurTreeForTaxon, winRectGbl.GetHeight())); ListesAuxMyTreeCtrl *tree = new ListesAuxMyTreeCtrl(panel0, ID_TreeCtrlTaxons, wxDefaultPosition, wxSize(largeurTreeForTaxon, winRectGbl.GetHeight()), wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT | wxBORDER_SIMPLE); // !!! resize tree->wxWindow::SetBackgroundColour(Couleurs::backgColor); Aux::logsStr("typeTaxon", typeTaxon, logNop); if (typeTaxon.IsSameAs(wxT("ordre"))) { wxArrayString *ordres = model->treeForTaxon(false, wxT("ordre")); wxTreeItemId root = tree->AddRoot(wxT("Ordres")); int count = 0; for (size_t ijk=0; ijk<ordres->GetCount(); ijk++) { wxString strOrdre = ordres->Item(ijk); int idOrdre = model->existTaxon(wxT("ordre"), strOrdre); wxTreeItemId niv1 = tree->AppendItem(root, strId(strOrdre, idOrdre, addId)); tree->SetItemTextColour(niv1, Couleurs::ordreColor); count = count + 1; wxArrayString *familles = model->listeDescTaxonsForTaxon(wxT("ordre"), ordres->Item(ijk)); for (size_t klm=0; klm<familles->GetCount(); klm++) { wxString strFamille = familles->Item(klm); int idFamille = model->existTaxon(wxT("famille"), strFamille); wxTreeItemId niv2 = tree->AppendItem(niv1, strId(strFamille, idFamille, addId)); tree->SetItemTextColour(niv2, Couleurs::familleColor); count = count + 1; wxArrayString *genres = model->listeDescTaxonsForTaxon(wxT("famille"), familles->Item(klm)); for (size_t qsd=0; qsd<genres->GetCount(); qsd++) { wxString strGenre = genres->Item(qsd); int idGenre = model->existTaxon(wxT("genre"), strGenre); wxTreeItemId niv3 = tree->AppendItem(niv2, strId(strGenre, idGenre, addId)); tree->SetItemTextColour(niv3, Couleurs::genreColor); count = count + 1; wxArrayString *plantes = model->listeDescTaxonsForTaxon(wxT("genre"), genres->Item(qsd)); for (size_t sde=0; sde<plantes->GetCount(); sde++) { wxString strPlante = plantes->Item(sde); int idPlante = model->existTaxon(wxT("plante"), strPlante); wxTreeItemId niv4 = tree->AppendItem(niv3, strId(strPlante, idPlante, addId)); tree->SetItemTextColour(niv4, Couleurs::planteColor); count = count + 1; } } } } } else if (typeTaxon.IsSameAs(wxT("famille"))) { wxArrayString *familles = model->treeForTaxon(false, wxT("famille")); wxTreeItemId root = tree->AddRoot(wxT("Familles")); int count = 0; for (size_t ijk=0; ijk<familles->GetCount(); ijk++) { wxString strFamille = familles->Item(ijk); int idFamille = model->existTaxon(wxT("famille"), strFamille); wxTreeItemId niv1 = tree->AppendItem(root, strId(strFamille, idFamille, addId)); tree->SetItemTextColour(niv1, Couleurs::familleColor); count = count + 1; wxArrayString *genres = model->listeDescTaxonsForTaxon(wxT("famille"), familles->Item(ijk)); for (size_t qsd=0; qsd<genres->GetCount(); qsd++) { wxString strGenre = genres->Item(qsd); int idGenre = model->existTaxon(wxT("genre"), strGenre); wxTreeItemId niv3 = tree->AppendItem(niv1, strId(strGenre, idGenre, addId)); tree->SetItemTextColour(niv3, Couleurs::genreColor); count = count + 1; wxArrayString *plantes = model->listeDescTaxonsForTaxon(wxT("genre"), genres->Item(qsd)); for (size_t sde=0; sde<plantes->GetCount(); sde++) { wxString strPlante = plantes->Item(sde); int idPlante = model->existTaxon(wxT("plante"), strPlante); wxTreeItemId niv4 = tree->AppendItem(niv3, strId(strPlante, idPlante, addId)); tree->SetItemTextColour(niv4, Couleurs::planteColor); count = count + 1; } } } } else if (typeTaxon.IsSameAs(wxT("genre"))) { wxArrayString *genres = model->treeForTaxon(false, wxT("genre")); wxTreeItemId root = tree->AddRoot(wxT("Genres")); int count = 0; for (size_t ijk=0; ijk<genres->GetCount(); ijk++) { wxString strGenre = genres->Item(ijk); int idGenre = model->existTaxon(wxT("genre"), strGenre); wxTreeItemId niv1 = tree->AppendItem(root, strId(strGenre, idGenre, addId)); tree->SetItemTextColour(niv1, Couleurs::genreColor); count = count + 1; wxArrayString *plantes = model->listeDescTaxonsForTaxon(wxT("genre"), strGenre); for (size_t sde=0; sde<plantes->GetCount(); sde++) { wxString strPlante = plantes->Item(sde); int idPlante = model->existTaxon(wxT("plante"), strPlante); wxTreeItemId niv4 = tree->AppendItem(niv1, strId(strPlante, idPlante, addId)); tree->SetItemTextColour(niv4, Couleurs::planteColor); count = count + 1; } } } tree->Show(true); this->Show(true); } catch (const exception &e) { Aux::logsStr("", e.what(), logPut); } }
void GotoFile::BuildContent(wxWindow* parent, IncrementalSelectIterator *iterator, const wxString &title, const wxString &message) { //(*Initialize(GotoFile) wxStaticText* labelCtrl; Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX, _T("wxID_ANY")); m_sizer = new wxBoxSizer(wxVERTICAL); labelCtrl = new wxStaticText(this, wxID_ANY, _("Some text"), wxDefaultPosition, wxDefaultSize, 0, _T("wxID_ANY")); m_sizer->Add(labelCtrl, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5); m_Text = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER, wxDefaultValidator, _T("ID_TEXTCTRL1")); m_Text->SetFocus(); m_sizer->Add(m_Text, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5); m_ResultList = new IncrementalListCtrl(this, ID_RESULT_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_NO_HEADER|wxLC_SINGLE_SEL|wxLC_VIRTUAL|wxVSCROLL|wxHSCROLL, wxDefaultValidator, _T("ID_RESULT_LIST")); m_ResultList->SetMinSize(wxSize(500,300)); m_sizer->Add(m_ResultList, 1, wxALL|wxEXPAND, 5); SetSizer(m_sizer); m_sizer->Fit(this); m_sizer->SetSizeHints(this); //*) SetTitle(title); labelCtrl->SetLabel(message); // Call this here to make sure the column widths are correctly calculated. m_ResultList->SetIterator(iterator); m_handler.Init(m_ResultList, m_Text); const int columnWidth = iterator->GetColumnWidth(0); // Add first column wxListItem column; column.SetId(0); column.SetText( _("Column") ); column.SetWidth(columnWidth); m_ResultList->InsertColumn(0, column); m_ResultList->SetIterator(iterator); // Call Fit to make sure all GetSize methods return correct values. m_sizer->Fit(this); { // Use GetItemRect to account for the spacing between rows. GetCharHeight is used just as // precaution if GetItemRect fails. wxRect itemRect; if (!m_ResultList->GetItemRect(0, itemRect)) itemRect = wxRect(); const int charHeight = std::max(m_ResultList->GetCharHeight(), itemRect.GetHeight()); const int totalHeight = charHeight * m_ResultList->GetItemCount() + charHeight / 2; const wxSize minSize = m_ResultList->GetMinSize(); int minYCorrected = minSize.y; // Make the list taller if there are many items in it. This should make it a bit easier to find // stuff. The height would be something like 50% of the display's client area height. if (totalHeight > minSize.y) { const wxRect monitorRect = cbGetMonitorRectForWindow(parent); const int monitorHeight = int(std::lround(monitorRect.GetHeight() * 0.5)); minYCorrected = std::max(minYCorrected, std::min(monitorHeight, totalHeight)); } // Resize the window to maximise visible items. Do this using SetSize instead of using // SetMinSize to allow the user to make the window smaller if he/she wishes to do so. const wxSize windowSize = GetSize(); // GetSize for the list control could return a window smaller than the minSize, but the // window size could be accounting for list control's min size. This means that sizeDiff // could be calculated larger than needed. Account for this using std::max. This seems to // happen in wx2.8 builds. const wxSize listSize(std::max(m_ResultList->GetSize().x, minSize.x), std::max(m_ResultList->GetSize().y, minSize.y)); // This accounts for non-list UI elements present in the window. const wxSize sizeDiff = windowSize - listSize; SetSize(wxSize(std::max(columnWidth + sizeDiff.x, windowSize.x), minYCorrected + sizeDiff.y)); } }
void wxSFGridShape::FitShapeToRect(wxSFShapeBase *shape, const wxRect& rct) { wxRect shapeBB = shape->GetBoundingBox(); wxRealPoint prevPos = shape->GetRelativePosition(); // do vertical alignment switch( shape->GetVAlign() ) { case valignTOP: shape->SetRelativePosition( prevPos.x, rct.GetTop() + shape->GetVBorder() ); break; case valignMIDDLE: shape->SetRelativePosition( prevPos.x, rct.GetTop() + (rct.GetHeight()/2 - shapeBB.GetHeight()/2) ); break; case valignBOTTOM: shape->SetRelativePosition( prevPos.x, rct.GetBottom() - shapeBB.GetHeight() - shape->GetVBorder() ); break; case valignEXPAND: if( shape->ContainsStyle( sfsSIZE_CHANGE ) ) { shape->SetRelativePosition( prevPos.x, rct.GetTop() + shape->GetVBorder() ); shape->Scale( 1.f, double(rct.GetHeight() - 2*shape->GetVBorder())/shapeBB.GetHeight() ); } break; default: shape->SetRelativePosition( prevPos.x, rct.GetTop() ); break; } prevPos = shape->GetRelativePosition(); // do horizontal alignment switch( shape->GetHAlign() ) { case halignLEFT: shape->SetRelativePosition( rct.GetLeft() + shape->GetHBorder(), prevPos.y ); break; case halignCENTER: shape->SetRelativePosition( rct.GetLeft() + (rct.GetWidth()/2 - shapeBB.GetWidth()/2), prevPos.y ); break; case halignRIGHT: shape->SetRelativePosition( rct.GetRight() - shapeBB.GetWidth() - shape->GetHBorder(), prevPos.y ); break; case halignEXPAND: if( shape->ContainsStyle( sfsSIZE_CHANGE ) ) { shape->SetRelativePosition( rct.GetLeft() + shape->GetHBorder(), prevPos.y ); shape->Scale( double(rct.GetWidth() - 2*shape->GetHBorder())/shapeBB.GetWidth(), 1.f ); } break; default: shape->SetRelativePosition( rct.GetLeft(), prevPos.y ); break; } }
void clAuiMainNotebookTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { if(in_rect.GetHeight() == 0) return; // Tabs are not visible int curx = 0; wxGCDC gdc; if(!DrawingUtils::GetGCDC(dc, gdc)) return; wxColour penColour = page.active ? m_activeTabPenColour : m_penColour; wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxRect rr(in_rect.GetTopLeft(), sz); rr.y += TAB_Y_OFFSET; rr.width += 1; #if 0 if(page.active) { rr.y -= 2; rr.height += 2; } #endif #ifndef __WXGTK__ rr.height += 4; #endif /// the tab start position (x) curx = rr.x + 7; // Set clipping region int clip_width = rr.width; if(rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.x; gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height); gdc.SetBrush(m_bgColour); gdc.SetPen(penColour); if(page.active) { gdc.SetBrush(m_activeTabBgColour); path.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, m_tabRadius); gdc.GetGraphicsContext()->FillPath(path); gdc.GetGraphicsContext()->StrokePath(path); } else { wxGraphicsPath outerPath = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); outerPath.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, m_tabRadius); gdc.GetGraphicsContext()->StrokePath(outerPath); gdc.SetPen(m_innerPenColour); path.AddRoundedRectangle(rr.x + 1, rr.y + 1, rr.width - 3, rr.height - 2, m_tabRadius); gdc.GetGraphicsContext()->StrokePath(path); gdc.SetBrush(m_tabBgColour); gdc.GetGraphicsContext()->StrokePath(path); gdc.GetGraphicsContext()->FillPath(path); gdc.SetPen(penColour); } if(!page.active) { // Draw 2 lines at the bottom rect // one with the background colour of the active tab and the second // with the active tab pen colour wxPoint p1, p2; p1 = in_rect.GetBottomLeft(); p1.x -= 1; p2 = in_rect.GetBottomRight(); gdc.SetPen(m_activeTabBgColour); gdc.DrawLine(p1, p2); p1.y -= 1; p2.y -= 1; gdc.SetPen(m_activeTabPenColour); gdc.DrawLine(p1, p2); } else { wxPoint p1, p2; p1 = in_rect.GetBottomLeft(); p2 = in_rect.GetBottomRight(); gdc.SetPen(m_activeTabBgColour); gdc.DrawLine(p1, p2); gdc.DrawPoint(p1); gdc.DrawPoint(p1); p1.x += 1; gdc.DrawPoint(p1); gdc.DrawPoint(p1); p1.x -= 1; gdc.DrawPoint(p1); gdc.DrawPoint(p1); } wxString caption = page.caption; if(caption.IsEmpty()) { caption = "Tp"; } wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); gdc.SetFont(fnt); wxSize ext = gdc.GetTextExtent(caption); if(caption == "Tp") caption.Clear(); /// Draw the bitmap if(page.bitmap.IsOk()) { int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight()) / 2) - TAB_Y_OFFSET + BMP_Y_SPACER; gdc.GetGraphicsContext()->DrawBitmap(page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight()); curx += page.bitmap.GetWidth(); curx += 3; } /// Draw the text wxColour textColour = page.active ? m_activeTabTextColour : m_tabTextColour; gdc.SetTextForeground(textColour); wxDouble textYOffCorrd = (rr.y + (rr.height - ext.y) / 2) - TAB_Y_OFFSET + TEXT_Y_SPACER; gdc.GetGraphicsContext()->DrawText(page.caption, curx, textYOffCorrd); // advance the X offset curx += ext.x; curx += 3; /// Draw the X button on the tab if(close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { curx += 1; wxBitmap xBmp = m_bmpClose; switch(close_button_state) { case wxAUI_BUTTON_STATE_HOVER: xBmp = m_bmpCloseHover; break; case wxAUI_BUTTON_STATE_PRESSED: xBmp = m_bmpClosePressed; break; } int btny = (rr.y + (rr.height - x_button_height) / 2) - TAB_Y_OFFSET + BMP_Y_SPACER; gdc.GetGraphicsContext()->DrawBitmap(xBmp, curx, btny, x_button_height, x_button_height); *out_button_rect = wxRect(curx, btny, x_button_height, x_button_height); curx += x_button_height; } *out_tab_rect = rr; gdc.DestroyClippingRegion(); }
wxSize DropDown::HandleDrawItemInternal(wxDC& dc, const wxRect& Rect, INT32 item, INT32 flags, BOOL Draw) { const INT32 border = 2; if (CCamApp::IsDisabled()) // Inside an error handler return(wxDefaultSize); wxOwnerDrawnComboBox * pGadget = GetBox(); // if ((INT32)pInfo->itemID == -1 || (INT32)pInfo->itemData == -1) // Draw item -1: just exit // return(FALSE); void * ItemData = GetItemData(item); // Determine if it is a divider item if (!ItemData) { // It's a divider, so draw it specially - it is a simple black line across the center of the rectangle wxCoord midpoint = Rect.GetTop()+Rect.GetHeight()/2; if (Draw) { wxPen OldPen=dc.GetPen(); dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT))); dc.DrawLine(Rect.GetLeft(), midpoint, Rect.GetRight()+1, midpoint); dc.SetPen(OldPen); } return(wxSize(-1,5)); } // If we aren't drawing, we should get the size of the text and return that appopriately modified if (!Draw) { // Call the derived class wxRect def(-1,-1,-1,-1); wxSize TextSize = DrawText(ItemData, dc, def, item, flags, FALSE); // Rect is unused here as Draw is FALSE TextSize.x+=2*border; TextSize.y+=2*border; // This gives us the bounding rect as we leave some space around it if (HasIcon(ItemData)) { // There is an icon. It's width is equal to the text height less 2 (deflated in both // directions. There is also a 6 pixel space TextSize.x += (TextSize.y-2)+6; } return TextSize; } wxRect rect=Rect; rect.Deflate(border); // Calculate where the colour splodge (if any) will go (also used to shift text to the right later) wxRect IconRect=rect; IconRect.Deflate(1); IconRect.SetWidth(IconRect.GetHeight()); wxRect TextRect=rect; wxPalette * OldPal = NULL; // If it's a special item with a colour splodge, or a normal colour item, draw the colour splodge if (HasIcon(ItemData)) { if (PaletteManager::UsePalette()) OldPal = PaletteManager::StartPaintPalette(&dc); // Call the derived class to draw the icon if (Draw) DrawIcon(ItemData, dc, IconRect, !pGadget->IsEnabled(), flags); // Shift the text to the right of the icon INT32 shift=IconRect.GetWidth()+6; TextRect.Offset(shift,0); INT32 NewWidth=TextRect.GetWidth()-shift; TextRect.SetWidth(NewWidth<1?1:NewWidth); } if (TextRect.GetWidth()>1) // if there's room to draw any text, draw it { // Call derived class to draw the text if (Draw) DrawText(ItemData, dc, TextRect, item, flags, TRUE); } // Restore the DC's previous palette if we selected our one in if (OldPal) PaletteManager::StopPaintPalette(&dc, OldPal); return(wxDefaultSize); }