diff --git a/include/wx/listbox.h b/include/wx/listbox.h index 52b846b93f..f96cdb95ec 100644 --- a/include/wx/listbox.h +++ b/include/wx/listbox.h @@ -66,6 +66,7 @@ public: virtual void SetSelection(int n, bool select = TRUE) = 0; virtual void Select(int n) { SetSelection(n, TRUE); } void Deselect(int n) { SetSelection(n, FALSE); } + void DeselectAll(int itemToLeaveSelected = -1); virtual bool SetStringSelection(const wxString& s, bool select = TRUE); diff --git a/include/wx/univ/colschem.h b/include/wx/univ/colschem.h index b172a5a5bc..916a28b5e6 100644 --- a/include/wx/univ/colschem.h +++ b/include/wx/univ/colschem.h @@ -16,6 +16,8 @@ #pragma interface "colschem.h" #endif +class WXDLLEXPORT wxWindow; + #include "wx/colour.h" // ---------------------------------------------------------------------------- @@ -28,17 +30,28 @@ public: // the standard colours enum StdColour { - // the background and text colour for the control + // the background colour for a window + WINDOW, + + // the different background and text colours for the control CONTROL, + CONTROL_PRESSED, + CONTROL_CURRENT, + + // the label text for the normal and the disabled state CONTROL_TEXT, + CONTROL_TEXT_DISABLED, + CONTROL_TEXT_DISABLED_SHADOW, + + // the scrollbar background colour for the normal and pressed states SCROLLBAR, + SCROLLBAR_PRESSED, // the background and text colour for the highlighted item HIGHLIGHT, HIGHLIGHT_TEXT, - // these colours are used for drawing the shadows of 3D objects, use - // only NORMAL in the renderers which don't use 3D shading + // these colours are used for drawing the shadows of 3D objects SHADOW_DARK, SHADOW_HIGHLIGHT, SHADOW_IN, @@ -47,9 +60,11 @@ public: MAX }; - // get the colour for the control in the state (combination of - // wxCONTROL_XXX values) - virtual wxColour Get(StdColour col, int flags = 0) const = 0; + // get a standard colour + virtual wxColour Get(StdColour col) const = 0; + + // get the background colour for the given window + virtual wxColour GetBackground(wxWindow *win) const = 0; // virtual dtor for any base class virtual ~wxColourScheme(); @@ -58,4 +73,16 @@ public: // some people just can't spell it correctly :-) typedef wxColourScheme wxColorScheme; +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + +// retrieve the default colour from the theme or the given scheme +#define wxSCHEME_COLOUR(scheme, what) scheme->Get(wxColorScheme::what) +#define wxTHEME_COLOUR(what) wxSCHEME_COLOUR(wxTheme::Get(), what) + +// get the background colour for the window in the current theme +#define wxTHEME_BG_COLOUR(win) \ + wxTheme::Get()->GetColourScheme()->GetBackground(win) + #endif // _WX_UNIV_COLSCHEM_H_ diff --git a/include/wx/univ/control.h b/include/wx/univ/control.h index e62a21f041..fc8e2298db 100644 --- a/include/wx/univ/control.h +++ b/include/wx/univ/control.h @@ -86,7 +86,7 @@ public: // several overloaded versions but this will expose the problem of // virtual function hiding we don't have here. virtual bool PerformAction(const wxControlAction& action, - long numArg = 0l, + long numArg = -1l, const wxString& strArg = wxEmptyString); protected: diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index 7b09009697..42cea9ea0a 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -37,6 +37,12 @@ #define wxACTION_LISTBOX_SELECT _T("select") // select/focus #define wxACTION_LISTBOX_UNSELECT _T("unselect") // unselect/unfocus +// do something with the selection globally (not for single selection ones) +#define wxACTION_LISTBOX_SELECTALL _T("selectall") // select all items +#define wxACTION_LISTBOX_UNSELECTALL _T("unselectall") // unselect all items +#define wxACTION_LISTBOX_SELTOGGLE _T("togglesel") // invert the selection +#define wxACTION_LISTBOX_EXTENDSEL _T("extend") // extend to item + // ---------------------------------------------------------------------------- // wxListBox: a list of selectable items // ---------------------------------------------------------------------------- @@ -118,10 +124,13 @@ public: void ChangeCurrent(int diff); // actions - void Activate(); - void Select(bool sel = TRUE); + void Activate(int item); + void Select(bool sel = TRUE, int item = -1); void EnsureVisible(); + void ExtendSelection(int itemTo); + void AnchorSelection(int itemFrom) { m_selAnchor = itemFrom; } + // get, calculating it if necessary, the number of items per page, the // height of each line and the max width of an item int GetItemsPerPage() const; @@ -133,6 +142,9 @@ public: long numArg = 0l, const wxString& strArg = wxEmptyString); + // let wxColourScheme choose the right colours for us + virtual bool IsContainerWindow() const { return TRUE; } + protected: virtual wxSize DoGetBestClientSize() const; virtual void DoDraw(wxControlRenderer *renderer); @@ -203,6 +215,11 @@ private: // of the window bool m_currentChanged; + // the anchor from which the selection is extended for the listboxes with + // wxLB_EXTENDED style - this is set to the last item which was selected + // by not extending the selection but by choosing it directly + int m_selAnchor; + DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(wxListBox) }; diff --git a/include/wx/univ/theme.h b/include/wx/univ/theme.h index 39b7c83c4c..b0a0ea2709 100644 --- a/include/wx/univ/theme.h +++ b/include/wx/univ/theme.h @@ -56,7 +56,7 @@ public: virtual wxInputHandler *GetInputHandler(const wxString& control) = 0; // get the colour scheme for the control with this name - virtual wxColourScheme *GetColourScheme(const wxString& control) = 0; + virtual wxColourScheme *GetColourScheme() = 0; // implementation only from now on // ------------------------------- diff --git a/include/wx/univ/window.h b/include/wx/univ/window.h index 6b5fae4402..22ec654856 100644 --- a/include/wx/univ/window.h +++ b/include/wx/univ/window.h @@ -118,6 +118,36 @@ public: // operations virtual void SetCurrent(bool doit = TRUE); + // methods used by wxColourScheme to choose the colours for this window + // -------------------------------------------------------------------- + + // return TRUE if this is a panel/canvas window which contains other + // controls only + virtual bool IsCanvasWindow() const { return FALSE; } + + // return TRUE if this a container window which contains the other items: + // e.g, a listbox, listctrl, treectrl, ... and FALSE if it is a monolithic + // control (e.g. a button, checkbox, ...) + virtual bool IsContainerWindow() const { return FALSE; } + + // return TRUE if this control can be highlighted when the mouse is over + // it (the theme decides itself whether it is really highlighted or not) + virtual bool CanBeHighlighted() const { return FALSE; } + + // return TRUE if we should use the colours/fonts returned by the + // corresponding GetXXX() methods instead of the default ones + bool UseBgCol() const { return m_hasBgCol; } + bool UseFgCol() const { return m_hasFgCol; } + bool UseFont() const { return m_hasFont; } + + // overridden base class methods + // ----------------------------- + + // remember that the font/colour was changed + virtual bool SetBackgroundColour(const wxColour& colour); + virtual bool SetForegroundColour(const wxColour& colour); + virtual bool SetFont(const wxFont& font); + protected: // common part of all ctors void Init(); @@ -172,8 +202,11 @@ protected: int m_alignBgBitmap; wxStretch m_stretchBgBitmap; - // is the mouse currently inside the window? - bool m_isCurrent; + // more flags + bool m_isCurrent:1; // is the mouse currently inside the window? + bool m_hasBgCol:1; // was the bg colour explicitly changed by user? + bool m_hasFgCol:1; // fg + bool m_hasFont:1; // font private: // the window scrollbars diff --git a/samples/univ/univ.cpp b/samples/univ/univ.cpp index c29cc74a88..4b5fb96da0 100644 --- a/samples/univ/univ.cpp +++ b/samples/univ/univ.cpp @@ -49,7 +49,7 @@ #include "wx/univ/theme.h" //#define DEBUG_SCROLL -#define DEBUG_LISTBOX +//#define DEBUG_LISTBOX // ---------------------------------------------------------------------------- // resources @@ -319,7 +319,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title) WXSIZEOF(choices), choices, wxLB_MULTIPLE | wxLB_ALWAYS_SB); lbox = new wxListBox(this, -1, wxPoint(550, 300), wxDefaultSize, - 0, NULL, wxLB_HSCROLL); + 0, NULL, wxLB_HSCROLL | wxLB_EXTENDED); for ( int i = 1; i <= 20; i++ ) { lbox->Append(wxString::Format(_T("%sentry %d"), diff --git a/src/common/lboxcmn.cpp b/src/common/lboxcmn.cpp index 7031381bf3..2258bc4f67 100644 --- a/src/common/lboxcmn.cpp +++ b/src/common/lboxcmn.cpp @@ -80,6 +80,31 @@ bool wxListBoxBase::SetStringSelection(const wxString& s, bool select) return TRUE; } +void wxListBoxBase::DeselectAll(int itemToLeaveSelected) +{ + if ( HasMultipleSelection() ) + { + wxArrayInt selections; + GetSelections(selections); + + size_t count = selections.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + int item = selections[n]; + if ( item != itemToLeaveSelected ) + Deselect(item); + } + } + else // single selection + { + int sel = GetSelection(); + if ( sel != -1 && sel != itemToLeaveSelected ) + { + Deselect(sel); + } + } +} + // ---------------------------------------------------------------------------- // misc // ---------------------------------------------------------------------------- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index fc0baf9bd1..21329d2d8c 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -118,15 +118,11 @@ void wxWindowBase::InitBase() m_windowValidator = (wxValidator *) NULL; #endif // wxUSE_VALIDATORS - // use the system default colours - wxSystemSettings settings; - - m_backgroundColour = settings.GetSystemColour(wxSYS_COLOUR_BTNFACE); - // m_foregroundColour = *wxBLACK; // TODO take this from sys settings too? + // use the system default colours and font + m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE); m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); + m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); - // GRG, changed Mar/2000 - m_font = settings.GetSystemFont(wxSYS_DEFAULT_GUI_FONT); // no style bits m_exStyle = m_windowStyle = 0; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 1c52f515d3..c1bdf28185 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -697,6 +697,7 @@ static int gtk_window_expose_callback( GtkWidget *widget, if (gdk_event->count == 0) { wxClientDC dc(win); + dc.SetClippingRegion(win->GetUpdateRegion()); wxEraseEvent eevent( win->GetId(), &dc ); eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); @@ -804,6 +805,7 @@ static void gtk_window_draw_callback( GtkWidget *widget, win->m_clipPaintRegion = TRUE; wxClientDC dc(win); + dc.SetClippingRegion(win->GetUpdateRegion()); wxEraseEvent eevent( win->GetId(), &dc ); eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 1c52f515d3..c1bdf28185 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -697,6 +697,7 @@ static int gtk_window_expose_callback( GtkWidget *widget, if (gdk_event->count == 0) { wxClientDC dc(win); + dc.SetClippingRegion(win->GetUpdateRegion()); wxEraseEvent eevent( win->GetId(), &dc ); eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); @@ -804,6 +805,7 @@ static void gtk_window_draw_callback( GtkWidget *widget, win->m_clipPaintRegion = TRUE; wxClientDC dc(win); + dc.SetClippingRegion(win->GetUpdateRegion()); wxEraseEvent eevent( win->GetId(), &dc ); eevent.SetEventObject( win ); win->GetEventHandler()->ProcessEvent(eevent); diff --git a/src/univ/control.cpp b/src/univ/control.cpp index 79797b78a9..039cbefa3c 100644 --- a/src/univ/control.cpp +++ b/src/univ/control.cpp @@ -79,8 +79,6 @@ bool wxControl::Create(wxWindow *parent, m_handler = CreateInputHandler(); - //SetBackgroundColour(parent->GetBackgroundColour()); - return TRUE; } diff --git a/src/univ/files.lst b/src/univ/files.lst index e6ef39f1a4..ea66d510fc 100644 --- a/src/univ/files.lst +++ b/src/univ/files.lst @@ -13,7 +13,6 @@ UNIVOBJS = \ stattext.o \ theme.o \ gtk.o \ - win32.o \ winuniv.o UNIVDEPS = \ diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index 0cefab0287..8e9b912ac9 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -66,6 +66,7 @@ void wxListBox::Init() // no items hence no current item m_current = -1; + m_selAnchor = -1; m_currentChanged = FALSE; // no need to update anything initially @@ -98,8 +99,6 @@ bool wxListBox::Create(wxWindow *parent, SetWindow(this); - SetBackgroundColour(*wxWHITE); - if ( style & wxLB_SORT ) m_strings = wxArrayString(TRUE /* auto sort */); @@ -683,23 +682,17 @@ bool wxListBox::SendEvent(int item, wxEventType type) wxCommandEvent event(type, m_windowId); event.SetEventObject(this); - int n; - if ( m_selections.GetCount() > 0 ) + if ( item != -1 ) { - n = m_selections[0]; if ( HasClientObjectData() ) - event.SetClientObject(GetClientObject(n)); + event.SetClientObject(GetClientObject(item)); else if ( HasClientUntypedData() ) - event.SetClientData(GetClientData(n)); + event.SetClientData(GetClientData(item)); - event.SetString(GetString(n)); - } - else // no selection - { - n = -1; + event.SetString(GetString(item)); } - event.m_commandInt = n; + event.m_commandInt = item; return GetEventHandler()->ProcessEvent(event); } @@ -715,7 +708,15 @@ void wxListBox::SetCurrentItem(int n) if ( m_current != -1 ) { - if ( !HasMultipleSelection() ) + if ( GetWindowStyle() & wxLB_EXTENDED ) + { + // if we hadn't had any selection before, make the freshly + // selected item the new selection anchor + if ( m_selections.IsEmpty() ) + m_selAnchor = m_current; + } + + if ( !(GetWindowStyle() & wxLB_MULTIPLE) ) { // for a single selection listbox, the current item is always // the one selected @@ -773,18 +774,56 @@ void wxListBox::ChangeCurrent(int diff) SetCurrentItem(current); } -void wxListBox::Select(bool sel) +void wxListBox::ExtendSelection(int itemTo) { - if ( sel && !HasMultipleSelection() ) + // if we don't have the explicit values for selection start/end, make them + // up + if ( m_selAnchor == -1 ) + m_selAnchor = m_current; + + if ( itemTo == -1 ) + itemTo = m_current; + + // swap the start/end of selection range if necessary + int itemFrom = m_selAnchor; + if ( itemFrom > itemTo ) { - // deselect the old item first - int selOld = GetSelection(); - if ( selOld != -1 ) - { - SetSelection(selOld, FALSE); - } + int itemTmp = itemFrom; + itemFrom = itemTo; + itemTo = itemTmp; } + // the selection should now include all items in the range between the + // anchor and the specified item and only them + + int n; + for ( n = 0; n < itemFrom; n++ ) + { + Deselect(n); + } + + for ( ; n <= itemTo; n++ ) + { + SetSelection(n); + } + + int count = GetCount(); + for ( ; n < count; n++ ) + { + Deselect(n); + } +} + +void wxListBox::Select(bool sel, int item) +{ + if ( sel && !(GetWindowStyle() & wxLB_MULTIPLE) ) + { + DeselectAll(item); + } + + if ( item != -1 ) + SetCurrentItem(item); + if ( m_current != -1 ) { // [de]select the new one @@ -797,8 +836,11 @@ void wxListBox::Select(bool sel) } } -void wxListBox::Activate() +void wxListBox::Activate(int item) { + if ( item != -1 ) + SetCurrentItem(item); + if ( m_current != -1 ) { Select(); @@ -811,16 +853,20 @@ bool wxListBox::PerformAction(const wxControlAction& action, long numArg, const wxString& strArg) { + int item = (int)numArg; + if ( item == -1 ) + item = m_current; + if ( action == wxACTION_LISTBOX_SETFOCUS ) - SetCurrentItem(numArg); + SetCurrentItem(item); else if ( action == wxACTION_LISTBOX_ACTIVATE ) - Activate(); + Activate(item); else if ( action == wxACTION_LISTBOX_TOGGLE ) - Select(!IsSelected(m_current)); + Select(!IsSelected(item), item); else if ( action == wxACTION_LISTBOX_SELECT ) - Select(TRUE); + Select(TRUE, item); else if ( action == wxACTION_LISTBOX_UNSELECT ) - Select(FALSE); + Select(FALSE, item); else if ( action == wxACTION_LISTBOX_MOVEDOWN ) ChangeCurrent(1); else if ( action == wxACTION_LISTBOX_MOVEUP ) @@ -833,6 +879,13 @@ bool wxListBox::PerformAction(const wxControlAction& action, SetCurrentItem(0); else if ( action == wxACTION_LISTBOX_END ) SetCurrentItem(GetCount() - 1); + else if ( action == wxACTION_LISTBOX_UNSELECTALL ) + DeselectAll(item); + else if ( action == wxACTION_LISTBOX_EXTENDSEL ) + ExtendSelection(item); + else if ( action == wxACTION_LISTBOX_SELECTALL || + action == wxACTION_LISTBOX_SELTOGGLE ) + wxFAIL_MSG(_T("unimplemented yet")); else return wxControl::PerformAction(action, numArg, strArg); @@ -864,7 +917,7 @@ bool wxStdListboxInputHandler::HandleKey(wxControl *control, const wxKeyEvent& event, bool pressed) { - // we're only interested in the (normal) key presses + // we're only interested in the key press events if ( pressed && !event.AltDown() ) { wxControlAction action; @@ -887,6 +940,12 @@ bool wxStdListboxInputHandler::HandleKey(wxControl *control, { control->PerformAction(action); + if ( event.ShiftDown() && + (control->GetWindowStyle() & wxLB_EXTENDED) ) + { + control->PerformAction(wxACTION_LISTBOX_EXTENDSEL); + } + return TRUE; } } @@ -945,9 +1004,29 @@ bool wxStdListboxInputHandler::HandleMouse(wxControl *control, ? 3 : 2; } - else + else // wxLB_EXTENDED listbox { - action = wxACTION_LISTBOX_TOGGLE; + // simple click in an extended listbox clears the + // selection, ctrl-click toggles an item to it and + // shift-click adds a range + if ( event.ControlDown() ) + { + lbox->AnchorSelection(item); + + action = wxACTION_LISTBOX_TOGGLE; + } + else if ( event.ShiftDown() ) + { + action = wxACTION_LISTBOX_EXTENDSEL; + } + else // simple click + { + lbox->AnchorSelection(item); + lbox->PerformAction(wxACTION_LISTBOX_UNSELECTALL, + item); + + action = wxACTION_LISTBOX_SELECT; + } } } else // single selection diff --git a/src/univ/renderer.cpp b/src/univ/renderer.cpp index d1e55c82fe..056e21a8d3 100644 --- a/src/univ/renderer.cpp +++ b/src/univ/renderer.cpp @@ -38,7 +38,9 @@ #include "wx/image.h" +#include "wx/univ/theme.h" #include "wx/univ/renderer.h" +#include "wx/univ/colschem.h" // ============================================================================ // implementation @@ -376,13 +378,7 @@ void wxControlRenderer::DrawButtonBorder() m_renderer->DrawButtonBorder(m_dc, m_rect, flags, &m_rect); - wxColour colBg; - if ( !(flags & wxCONTROL_CURRENT) ) - { - colBg = m_window->GetBackgroundColour(); - } - - m_renderer->DrawBackground(m_dc, colBg, m_rect, flags); + m_renderer->DrawBackground(m_dc, wxTHEME_BG_COLOUR(m_window), m_rect, flags); } void wxControlRenderer::DrawBitmap(const wxBitmap& bitmap) @@ -405,7 +401,7 @@ void wxControlRenderer::DrawBackgroundBitmap() } else // just fill it with bg colour if no bitmap { - m_renderer->DrawBackground(m_dc, m_window->GetBackgroundColour(), + m_renderer->DrawBackground(m_dc, wxTHEME_BG_COLOUR(m_window), m_rect, m_window->GetStateFlags()); } } diff --git a/src/univ/themes/gtk.cpp b/src/univ/themes/gtk.cpp index e8c813b8e6..fb93e54625 100644 --- a/src/univ/themes/gtk.cpp +++ b/src/univ/themes/gtk.cpp @@ -123,7 +123,14 @@ protected: // get the colour to use for background wxColour GetBackgroundColour(int flags) const - { return m_scheme->Get(wxColourScheme::CONTROL, flags); } + { + if ( flags & wxCONTROL_PRESSED ) + return wxSCHEME_COLOUR(m_scheme, CONTROL_PRESSED); + else if ( flags & wxCONTROL_CURRENT ) + return wxSCHEME_COLOUR(m_scheme, CONTROL_CURRENT); + else + return wxSCHEME_COLOUR(m_scheme, CONTROL); + } // draw the background with any colour, not only the default one(s) void DoDrawBackground(wxDC& dc, @@ -264,7 +271,8 @@ protected: class wxGTKColourScheme : public wxColourScheme { public: - virtual wxColour Get(StdColour col, int flags = 0) const; + virtual wxColour Get(StdColour col) const; + virtual wxColour GetBackground(wxWindow *win) const; }; // ---------------------------------------------------------------------------- @@ -281,8 +289,7 @@ public: virtual wxRenderer *GetRenderer() { return m_renderer; } virtual wxInputHandler *GetInputHandler(const wxString& control); - virtual wxColourScheme *GetColourScheme(const wxString& control) - { return m_scheme; } + virtual wxColourScheme *GetColourScheme() { return m_scheme; } private: wxGTKRenderer *m_renderer; @@ -350,40 +357,68 @@ wxInputHandler *wxGTKTheme::GetInputHandler(const wxString& control) // wxGTKColourScheme // ============================================================================ -wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col, - int flags) const +wxColour wxGTKColourScheme::GetBackground(wxWindow *win) const +{ + wxColour col; + if ( win->UseBgCol() ) + { + // use the user specified colour + col = win->GetBackgroundColour(); + } + + if ( win->IsContainerWindow() ) + { + // doesn't depend on the state + if ( !col.Ok() ) + { + col = Get(WINDOW); + } + } + else + { + int flags = win->GetStateFlags(); + + // the colour set by the user should be used for the normal state + // and for the states for which we don't have any specific colours + if ( !col.Ok() || (flags != 0) ) + { + if ( wxDynamicCast(win, wxScrollBar) ) + col = Get(SCROLLBAR); + else if ( (flags & wxCONTROL_CURRENT) && win->CanBeHighlighted() ) + col = Get(CONTROL_CURRENT); + else if ( flags & wxCONTROL_PRESSED ) + col = Get(CONTROL_PRESSED); + else + col = Get(CONTROL); + } + } + + return col; +} + +wxColour wxGTKColourScheme::Get(wxGTKColourScheme::StdColour col) const { switch ( col ) { + case WINDOW: return *wxWHITE; + case SHADOW_DARK: return *wxBLACK; case SHADOW_HIGHLIGHT: return *wxWHITE; case SHADOW_IN: return wxColour(0xd6d6d6); case SHADOW_OUT: return wxColour(0x969696); - case CONTROL: - if ( flags & wxCONTROL_PRESSED ) - { - return wxColour(0xc3c3c3); - } - else if ( flags & wxCONTROL_CURRENT ) - { - return wxColour(0xeaeaea); - } - else - { - return wxColour(0xd6d6d6); - } + case CONTROL: return wxColour(0xd6d6d6); + case CONTROL_PRESSED: return wxColour(0xc3c3c3); + case CONTROL_CURRENT: return wxColour(0xeaeaea); - case CONTROL_TEXT: if ( flags & wxCONTROL_DISABLED ) - { - return wxColour(0x757575); - } - else - { - return *wxBLACK; - } + case CONTROL_TEXT: return *wxBLACK; + case CONTROL_TEXT_DISABLED: + return wxColour(0x757575); + case CONTROL_TEXT_DISABLED_SHADOW: + return *wxWHITE; - case SCROLLBAR: return wxColour(0xc3c3c3); + case SCROLLBAR: + case SCROLLBAR_PRESSED: return wxColour(0xc3c3c3); case HIGHLIGHT: return wxColour(0x9c0000); case HIGHLIGHT_TEXT: return wxColour(0xffffff); @@ -410,11 +445,11 @@ wxGTKRenderer::wxGTKRenderer(const wxColourScheme *scheme) m_sizeScrollbarArrow = wxSize(15, 14); // init pens - m_penBlack = wxPen(scheme->Get(wxColourScheme::SHADOW_DARK), 0, wxSOLID); - m_penDarkGrey = wxPen(scheme->Get(wxColourScheme::SHADOW_OUT), 0, wxSOLID); - m_penGrey = wxPen(scheme->Get(wxColourScheme::SCROLLBAR), 0, wxSOLID); - m_penLightGrey = wxPen(scheme->Get(wxColourScheme::SHADOW_IN), 0, wxSOLID); - m_penHighlight = wxPen(scheme->Get(wxColourScheme::SHADOW_HIGHLIGHT), 0, wxSOLID); + m_penBlack = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_DARK), 0, wxSOLID); + m_penDarkGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_OUT), 0, wxSOLID); + m_penGrey = wxPen(wxSCHEME_COLOUR(scheme, SCROLLBAR), 0, wxSOLID); + m_penLightGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_IN), 0, wxSOLID); + m_penHighlight = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_HIGHLIGHT), 0, wxSOLID); } // ---------------------------------------------------------------------------- @@ -746,7 +781,7 @@ void wxGTKRenderer::DrawLabel(wxDC& dc, rectShadow.x++; rectShadow.y++; dc.DrawLabel(label, rectShadow, alignment, indexAccel); - dc.SetTextForeground(m_scheme->Get(wxColourScheme::CONTROL_TEXT, flags)); + dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, CONTROL_TEXT_DISABLED)); } dc.DrawLabel(label, image, rect, alignment, indexAccel, rectBounds); @@ -765,12 +800,12 @@ void wxGTKRenderer::DrawItem(wxDC& dc, wxColour colFg; if ( flags & wxCONTROL_SELECTED ) { - dc.SetBrush(wxBrush(m_scheme->Get(wxColourScheme::HIGHLIGHT), wxSOLID)); + dc.SetBrush(wxBrush(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT), wxSOLID)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(rect); colFg = dc.GetTextForeground(); - dc.SetTextForeground(m_scheme->Get(wxColourScheme::HIGHLIGHT_TEXT)); + dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT)); } if ( flags & wxCONTROL_FOCUSED ) @@ -816,16 +851,7 @@ void wxGTKRenderer::DrawBackground(wxDC& dc, const wxRect& rect, int flags) { - wxColour colBg; - if ( !col.Ok() ) - { - colBg = m_scheme->Get(wxColourScheme::CONTROL, flags); - } - else - { - colBg = col; - } - + wxColour colBg = col.Ok() ? col : GetBackgroundColour(flags); DoDrawBackground(dc, colBg, rect); } @@ -850,7 +876,7 @@ void wxGTKRenderer::DrawArrowBorder(wxDC& dc, rect2.Inflate(-1); rectInner.Inflate(-2); - DoDrawBackground(dc, m_scheme->Get(wxColourScheme::SCROLLBAR), *rect); + DoDrawBackground(dc, wxSCHEME_COLOUR(m_scheme, SCROLLBAR), *rect); // find the side not to draw and also adjust the rectangles to compensate // for it @@ -936,7 +962,7 @@ void wxGTKRenderer::DrawArrow(wxDC& dc, wxPoint ptArrow[Point_Max]; - wxColour colInside = m_scheme->Get(wxColourScheme::CONTROL, flags); + wxColour colInside = GetBackgroundColour(flags); wxPen penShadow[4]; if ( flags & wxCONTROL_PRESSED ) { @@ -1145,12 +1171,12 @@ void wxGTKRenderer::DrawScrollbarShaft(wxDC& dc, { wxRect rectBar = rect; DrawThumbBorder(dc, &rectBar, orient); - DoDrawBackground(dc, m_scheme->Get(wxColourScheme::SCROLLBAR), rectBar); + DoDrawBackground(dc, wxSCHEME_COLOUR(m_scheme, SCROLLBAR), rectBar); } void wxGTKRenderer::DrawScrollCorner(wxDC& dc, const wxRect& rect) { - DoDrawBackground(dc, m_scheme->Get(wxColourScheme::CONTROL), rect); + DoDrawBackground(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), rect); } wxRect wxGTKRenderer::GetScrollbarRect(const wxScrollBar *scrollbar, diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 76d94f049f..ed5e7ad331 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -251,6 +251,7 @@ class wxWin32ColourScheme : public wxColourScheme { public: virtual wxColour Get(StdColour col, int flags = 0) const; + virtual wxColour GetBackground(wxWindow *win); }; // ---------------------------------------------------------------------------- @@ -344,11 +345,18 @@ wxColourScheme *wxWin32Theme::GetColourScheme(const wxString& control) // wxWin32ColourScheme // ============================================================================ +wxColour wxWin32ColourScheme::GetBackground(wxWindow *win) +{ + return win->GetBackgroundColour(); +} + wxColour wxWin32ColourScheme::Get(wxWin32ColourScheme::StdColour col, int flags) const { switch ( col ) { + case WINDOW: return *wxWHITE; + case CONTROL: return wxColour(0xc0c0c0); case CONTROL_TEXT: return *wxBLACK; case SCROLLBAR: if ( flags & wxCONTROL_PRESSED ) diff --git a/src/univ/winuniv.cpp b/src/univ/winuniv.cpp index e2350597dd..2d67e4d688 100644 --- a/src/univ/winuniv.cpp +++ b/src/univ/winuniv.cpp @@ -97,6 +97,11 @@ bool wxWindow::Create(wxWindow *parent, wxSB_VERTICAL); } + // the colours/fonts are default + m_hasBgCol = + m_hasFgCol = + m_hasFont = FALSE; + return TRUE; } @@ -570,3 +575,36 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) } } +// ---------------------------------------------------------------------------- +// colours/fonts +// ---------------------------------------------------------------------------- + +bool wxWindow::SetBackgroundColour(const wxColour& colour) +{ + if ( !wxWindowNative::SetBackgroundColour(colour) ) + return FALSE; + + m_hasBgCol = TRUE; + + return TRUE; +} + +bool wxWindow::SetForegroundColour(const wxColour& colour) +{ + if ( !wxWindowNative::SetForegroundColour(colour) ) + return FALSE; + + m_hasFgCol = TRUE; + + return TRUE; +} + +bool wxWindow::SetFont(const wxFont& font) +{ + if ( !wxWindowNative::SetFont(font) ) + return FALSE; + + m_hasFont = TRUE; + + return TRUE; +}