17 #if defined(__WXMSW__) && wxUSE_UXTHEME 18 #include <wx/msw/uxtheme.h> 23 #define wxSWITCHER_TEXT_MARGIN_X 4 24 #define wxSWITCHER_TEXT_MARGIN_Y 2 25 #define wxSWITCHER_USE_BUFFERED_PAINTING 1 27 #include <wx/arrimpl.cpp> 41 m_breakColumn =
false;
91 if (m_items.GetCount() != items.m_items.GetCount())
94 if (m_selection != items.m_selection || m_rowCount != items.m_rowCount || m_columnCount != items.m_columnCount)
97 if (m_backgroundColour != items.m_backgroundColour ||
m_textColour != items.m_textColour ||
98 m_selectionColour != items.m_selectionColour || m_selectionOutlineColour != items.m_selectionOutlineColour ||
99 m_selectionTextColour != items.m_selectionTextColour || m_itemFont != items.m_itemFont)
103 for (i = 0; i < m_items.GetCount(); i++)
105 if (!(m_items[i] == items.m_items[i]))
118 #if defined(__WXMSW__) && wxUSE_UXTHEME &&!wxCHECK_VERSION(3, 1, 1) 121 if (wxUxThemeEngine::GetIfActive())
123 SetSelectionOutlineColour(
wxColour(49, 106, 197));
124 SetSelectionColour(
wxColour(193,210, 238));
135 for (i = 0; i < items.
m_items.GetCount(); i++)
160 return AddItem(item);
172 return AddItem(item);
178 return m_items[GetItemCount() - 1];
197 for (i = 0; i < m_items.GetCount(); i++)
199 if (m_items[i].
GetName() == name)
209 for (i = 0; i < m_items.GetCount(); i++)
211 if (m_items[i].
GetId() == id)
225 int idx = FindItemByName(name);
251 if (GetBackgroundColour().Ok())
252 backgroundColour = GetBackgroundColour();
257 if (GetSelectionColour().Ok())
258 selectionColour = GetSelectionColour();
260 if (GetSelectionOutlineColour().Ok())
261 selectionOutlineColour = GetSelectionOutlineColour();
263 if (GetSelectionTextColour().Ok())
264 selectionTextColour = GetSelectionTextColour();
266 if (GetItemFont().Ok())
268 standardFont = GetItemFont();
275 dc.SetLogicalFunction(
wxCOPY);
276 dc.SetBrush(
wxBrush(backgroundColour));
278 dc.DrawRectangle(win->GetClientRect());
279 dc.SetBackgroundMode(wxTRANSPARENT);
282 for (i = 0; i < m_items.GetCount(); i++)
285 bool selected = ((int) i == m_selection);
289 dc.SetPen(
wxPen(selectionOutlineColour));
290 dc.SetBrush(
wxBrush(selectionColour));
291 dc.DrawRectangle(item.
GetRect());
297 dc.SetClippingRegion(clippingRect);
300 dc.SetTextForeground(selectionTextColour);
304 dc.SetTextForeground(standardTextColour);
311 dc.SetFont(groupFont);
313 dc.SetFont(standardFont);
317 dc.GetTextExtent(item.
GetTitle(), & w, & h);
338 dc.DestroyClippingRegion();
355 if (GetItemFont().Ok())
356 standardFont = GetItemFont();
359 for (i = 0; i < m_items.GetCount(); i++)
368 dc.SetFont(groupFont);
370 dc.SetFont(standardFont);
374 dc.GetTextExtent(item.
GetTitle(), & w, & h);
376 w += 16 + 2*textMarginX;
379 sz.x = wxMin(w, maxWidth);
381 sz.y = wxMin(h, maxHeight);
388 sz.x += textMarginX*2;
389 sz.y += textMarginY*2;
398 for (
size_t i = 0; i < m_items.GetCount(); i++)
403 if (wxFindFocusDescendant(item.
GetWindow()))
414 for (
size_t i = 0; i < m_items.GetCount(); i++)
443 Create(parent,
id, pos, size, style);
448 wxControl::Create(parent,
id, pos, size, style);
450 SetInitialSize(size);
458 return m_overallSize;
464 while (topLevel && !topLevel->IsTopLevel())
465 topLevel = topLevel->GetParent();
470 closeEvent.SetEventObject(topLevel);
473 topLevel->GetEventHandler()->ProcessEvent(closeEvent);
485 #if wxSWITCHER_USE_BUFFERED_PAINTING 491 if (m_items.GetColumnCount() == 0)
494 if (m_items.GetColumnCount() == 0)
497 m_items.PaintItems(dc,
this);
504 int dir =
event.GetWheelRotation();
508 m_items.SetSelection(m_items.GetSelection() - 1);
509 if (m_items.GetSelection() < 0)
510 m_items.SetSelection(m_items.GetItemCount() - 1);
512 AdvanceToNextSelectableItem(-1);
516 m_items.SetSelection(m_items.GetSelection() + 1);
517 if (m_items.GetSelection() >= m_items.GetItemCount())
518 m_items.SetSelection(0);
520 AdvanceToNextSelectableItem(1);
523 GenerateSelectionEvent();
529 bool bCanSelectItem =
true;
530 if (m_ptMouse.x != -2 && m_ptMouse.y != -2)
532 if (m_ptMouse.x != -1 && m_ptMouse.y != -1)
535 if (abs(ptCurrent.
x - m_ptMouse.x) >= 3 || abs(ptCurrent.
y - m_ptMouse.y) >= 3)
537 m_ptMouse.
x = m_ptMouse.y = -1;
541 bCanSelectItem =
false;
549 m_items.SetSelection(idx);
550 GenerateSelectionEvent();
558 m_ptMouse.x = m_ptMouse.y = -1;
575 m_ptMouse.x = m_ptMouse.y = -2;
585 m_ptMouse.x = m_ptMouse.y = -2;
588 m_items.SetSelection(-1);
592 else if (event.
GetKeyCode() ==
WXK_TAB ||
event.GetKeyCode() == GetExtraNavigationKey())
596 m_items.SetSelection(m_items.GetSelection() - 1);
597 if (m_items.GetSelection() < 0)
598 m_items.SetSelection(m_items.GetItemCount() - 1);
600 AdvanceToNextSelectableItem(-1);
604 m_items.SetSelection(m_items.GetSelection() + 1);
605 if (m_items.GetSelection() >= m_items.GetItemCount())
606 m_items.SetSelection(0);
608 AdvanceToNextSelectableItem(1);
611 GenerateSelectionEvent();
617 m_items.SetSelection(m_items.GetSelection() + 1);
618 if (m_items.GetSelection() >= m_items.GetItemCount())
619 m_items.SetSelection(0);
621 AdvanceToNextSelectableItem(1);
623 GenerateSelectionEvent();
629 m_items.SetSelection(m_items.GetSelection() - 1);
630 if (m_items.GetSelection() < 0)
631 m_items.SetSelection(m_items.GetItemCount() - 1);
633 AdvanceToNextSelectableItem(-1);
635 GenerateSelectionEvent();
641 m_items.SetSelection(0);
643 AdvanceToNextSelectableItem(1);
645 GenerateSelectionEvent();
651 m_items.SetSelection(m_items.GetItemCount() - 1);
653 AdvanceToNextSelectableItem(-1);
655 GenerateSelectionEvent();
666 newCol = (m_items.GetColumnCount() - 1);
670 for (i = m_items.GetItemCount()-1; i >= 0; i--)
675 m_items.SetSelection(i);
680 AdvanceToNextSelectableItem(-1);
682 GenerateSelectionEvent();
692 if (newCol >= m_items.GetColumnCount())
697 for (i = m_items.GetItemCount()-1; i >= 0; i--)
702 m_items.SetSelection(i);
707 AdvanceToNextSelectableItem(1);
709 GenerateSelectionEvent();
720 if (m_items.GetItemCount() < 2)
723 if (m_items.GetSelection() == -1)
724 m_items.SetSelection(0);
726 int oldSel = m_items.GetSelection();
730 if (m_items.GetItem(m_items.GetSelection()).
GetIsGroup())
732 m_items.SetSelection(m_items.GetSelection() + direction);
733 if (m_items.GetSelection() == -1)
734 m_items.SetSelection(m_items.GetItemCount()-1);
735 else if (m_items.GetSelection() == m_items.GetItemCount())
736 m_items.SetSelection(0);
738 if (m_items.GetSelection() == oldSel)
750 event.SetEventObject(
this);
751 event.SetInt(m_items.GetSelection());
753 GetEventHandler()->ProcessEvent(event);
764 if (m_items.GetSelection() == -1)
765 m_items.SetSelection(0);
776 wxSize itemSize = m_items.CalculateItemSize(dc);
777 m_overallSize =
wxSize(350, 200);
784 bool breaking =
false;
786 for (i = 0; i < (size_t) m_items.GetItemCount(); i++)
788 wxSize oldOverallSize = m_overallSize;
790 m_items.GetItem(i).SetRect(
wxRect(x, y, itemSize.x, itemSize.y));
791 m_items.GetItem(i).SetColPos(columnCount-1);
792 m_items.GetItem(i).SetRowPos(currentRow);
794 if (m_items.GetItem(i).GetRect().GetBottom() > m_overallSize.y)
795 m_overallSize.y = m_items.GetItem(i).GetRect().GetBottom() + yMargin;
797 if (m_items.GetItem(i).GetRect().GetRight() > m_overallSize.x)
798 m_overallSize.x = m_items.GetItem(i).GetRect().GetRight() + xMargin;
802 y += (rowSpacing + itemSize.y);
804 bool stopBreaking = breaking;
806 if ((currentRow > m_items.GetRowCount()) || (m_items.GetItem(i).GetBreakColumn() && !breaking && (currentRow != 1)))
810 x += (xMargin + itemSize.x);
814 if (m_items.GetItem(i).GetIsGroup() || (m_items.GetItem(i).GetBreakColumn() && !breaking))
816 m_overallSize = oldOverallSize;
818 if (m_items.GetItem(i).GetBreakColumn())
830 m_items.SetColumnCount(columnCount);
832 InvalidateBestSize();
837 m_overallSize =
wxSize(200, 100);
839 m_extraNavigationKey = 0;
860 Create(items, parent,
id, title, position, size, style);
873 wxScrollingDialog::Create( parent,
id, title, position, size, style );
876 m_listCtrl->SetItems(items);
878 m_listCtrl->CalculateLayout();
880 if (m_extraNavigationKey != -1)
881 m_listCtrl->SetExtraNavigationKey(m_extraNavigationKey);
883 if (m_modifierKey != -1)
884 m_listCtrl->SetModifierKey(m_modifierKey);
890 m_descriptionCtrl->SetHTMLBackgroundColour(GetBackgroundColour());
894 m_descriptionCtrl->SetStandardFonts(fontSize);
903 sizer->SetSizeHints(
this);
905 m_listCtrl->SetFocus();
909 if (m_listCtrl->GetItems().GetSelection() == -1)
910 m_listCtrl->GetItems().SetSelection(0);
912 m_listCtrl->AdvanceToNextSelectableItem(1);
914 ShowDescription(m_listCtrl->GetItems().GetSelection());
922 m_descriptionCtrl =
NULL;
924 m_switcherBorderStyle = 0;
927 m_extraNavigationKey = -1;
929 #if defined(__WXMSW__) && wxUSE_UXTHEME &&!wxCHECK_VERSION(3, 1, 1) 930 if (wxUxThemeEngine::GetIfActive())
931 m_borderColour =
wxColour(49, 106, 197);
946 if (GetSelection() == -1)
956 return m_listCtrl->GetItems().GetSelection();
977 dc.SetPen(
wxPen(m_borderColour));
980 wxRect rect(GetClientRect());
981 dc.DrawRectangle(rect);
984 rect = m_descriptionCtrl->GetRect();
986 dc.DrawRectangle(rect);
992 ShowDescription(event.GetSelection());
1000 hex += wxDecToHex(col.
Red());
1001 hex += wxDecToHex(col.
Green());
1002 hex += wxDecToHex(col.
Blue());
1012 wxColour colour = m_listCtrl->GetItems().GetBackgroundColour();
1014 colour = GetBackgroundColour();
1026 html +=
wxT(
"</body>");
1028 m_descriptionCtrl->SetPage(html);
1033 m_extraNavigationKey = keyCode;
1035 m_listCtrl->SetExtraNavigationKey(keyCode);
1040 m_modifierKey = modifierKey;
1042 m_listCtrl->SetModifierKey(modifierKey);
const wxString & GetDescription() const
WX_DEFINE_OBJARRAY(wxSwitcherItemArray)
wxPoint wxGetMousePosition()
void EndModal(int retCode)
void AdvanceToNextSelectableItem(int direction)
wxBrush * wxTRANSPARENT_BRUSH
virtual bool GetUnderlined() const
const wxRect & GetRect() const
int HitTest(const wxPoint &pt) const
wxWindow * GetWindow() const
wxColour m_selectionOutlineColour
wxSwitcherItem & SetName(const wxString &name)
void Copy(const wxSwitcherItem &item)
const wxFont & GetFont() const
static wxFont GetFont(wxSystemFont index)
void OnEraseBackground(wxEraseEvent &event)
const wxBitmap & GetBitmap() const
wxSwitcherItem & SetTitle(const wxString &title)
virtual wxSize DoGetBestSize() const
wxColour m_selectionColour
#define wxSWITCHER_TEXT_MARGIN_X
virtual unsigned char Red() const
int GetIndexForFocus() const
const wxSwitcherItem & GetItem(int i) const
int FindItemByName(const wxString &name) const
virtual void SetWeight(wxFontWeight weight)
wxSwitcherItemArray m_items
wxSwitcherItem & AddGroup(const wxString &title, const wxString &name, int id=0, const wxBitmap &bitmap=wxNullBitmap)
const wxString & GetTitle() const
wxColour m_backgroundColour
wxEventType wxEVT_MOUSEWHEEL
wxSwitcherItem & SetDescription(const wxString &descr)
#define wxSWITCHER_TEXT_MARGIN_Y
wxPoint GetPosition() const
int FindItemById(int id) const
bool operator==(const wxSwitcherItem &item) const
void ShowDescription(int i)
virtual wxFontStyle GetStyle() const
bool Contains(int x, int y) const
void OnKey(wxKeyEvent &event)
void GenerateSelectionEvent()
wxColour m_selectionTextColour
void OnPaint(wxPaintEvent &event)
bool Create(const wxSwitcherItems &items, wxWindow *parent, wxWindowID id=-1, const wxString &title=_("Pane Switcher"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSTAY_ON_TOP|wxDIALOG_NO_PARENT|wxBORDER_SIMPLE)
virtual int GetWidth() const
wxSwitcherItem & SetBitmap(const wxBitmap &bitmap)
virtual unsigned char Green() const
const wxSize wxDefaultSize
wxSwitcherItem & AddItem(const wxString &title, const wxString &name, int id=0, const wxBitmap &bitmap=wxNullBitmap)
const wxPoint wxDefaultPosition
virtual wxFontFamily GetFamily() const
static wxColour GetColour(wxSystemColour index)
void OnActivate(wxActivateEvent &event)
virtual unsigned char Blue() const
bool Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void OnSelectItem(wxCommandEvent &event)
wxEventType wxEVT_CLOSE_WINDOW
static wxString ColourToHexString(const wxColour &col)
wxRect & Deflate(wxCoord dx, wxCoord dy)
wxSize CalculateItemSize(wxDC &dc)
wxSwitcherItem & SetId(int id)
void OnPaint(wxPaintEvent &event)
virtual int GetHeight() const
wxRect & Inflate(wxCoord dx, wxCoord dy)
virtual int GetPointSize() const
void OnCloseWindow(wxCloseEvent &event)
void SetCanVeto(bool canVeto)
const wxColour & GetTextColour() const
void SetModifierKey(int modifierKey)
virtual wxString GetFaceName() const
void Copy(const wxSwitcherItems &items)
wxPen * wxTRANSPARENT_PEN
void SetSelection(int sel)
const wxString & GetName() const
void OnChar(wxKeyEvent &event)
void OnMouseEvent(wxMouseEvent &event)
void PaintItems(wxDC &dc, wxWindow *win)
wxSwitcherItem & SetIsGroup(bool isGroup)