File: theme_handler.cpp

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (185 lines) | stat: -rw-r--r-- 6,989 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 The CodeLite Team
// file name            : theme_handler.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "theme_handler.h"
#include "editor_config.h"
#include "frame.h"
#include "workspace_pane.h"
#include "event_notifier.h"
#include "drawingutils.h"
#include <wx/listbox.h>
#include "wxcl_log_text_ctrl.h"
#include <wx/listctrl.h>
#include <wx/aui/framemanager.h>
#include "cl_aui_tb_are.h"

#ifdef __WXMAC__
#include <wx/srchctrl.h>
#endif

#define CHECK_POINTER(p) if ( !p ) return;

ThemeHandler::ThemeHandler()
{
    EventNotifier::Get()->Connect(wxEVT_CL_THEME_CHANGED, wxCommandEventHandler(ThemeHandler::OnEditorThemeChanged), NULL, this);
    EventNotifier::Get()->Connect(wxEVT_INIT_DONE, wxCommandEventHandler(ThemeHandler::OnInitDone), NULL, this);
}

ThemeHandler::~ThemeHandler()
{
    EventNotifier::Get()->Disconnect(wxEVT_CL_THEME_CHANGED, wxCommandEventHandler(ThemeHandler::OnEditorThemeChanged), NULL, this);
    EventNotifier::Get()->Disconnect(wxEVT_INIT_DONE, wxCommandEventHandler(ThemeHandler::OnInitDone), NULL, this);
}

void ThemeHandler::OnEditorThemeChanged(wxCommandEvent& e)
{
    e.Skip();
    wxColour bgColour = EditorConfigST::Get()->GetCurrentOutputviewBgColour();
    wxColour fgColour = EditorConfigST::Get()->GetCurrentOutputviewFgColour();
    
    if ( !bgColour.IsOk() || !fgColour.IsOk() ) {
        return;
    }
    
    size_t pageCount = clMainFrame::Get()->GetWorkspacePane()->GetNotebook()->GetPageCount();
    for(size_t i=0; i<pageCount; ++i) {
        
        wxWindow * page = clMainFrame::Get()->GetWorkspacePane()->GetNotebook()->GetPage(i);
        if ( page ) {
            DoUpdateColours(page, bgColour, fgColour);
        }
    }
    
    pageCount = clMainFrame::Get()->GetOutputPane()->GetNotebook()->GetPageCount();
    for(size_t i=0; i<pageCount; ++i) {
        
        wxWindow * page = clMainFrame::Get()->GetOutputPane()->GetNotebook()->GetPage(i);
        if ( page ) {
            DoUpdateColours(page, bgColour, fgColour);
        }
    }
    
    pageCount = clMainFrame::Get()->GetDebuggerPane()->GetNotebook()->GetPageCount();
    for(size_t i=0; i<pageCount; ++i) {
        
        wxWindow * page = clMainFrame::Get()->GetDebuggerPane()->GetNotebook()->GetPage(i);
        if ( page ) {
            DoUpdateColours(page, bgColour, fgColour);
        }
    }
    
    wxclTextCtrl *log = dynamic_cast<wxclTextCtrl*>( wxLog::GetActiveTarget() );
    if ( log ) {
        log->Reset();
    }
    
    /// go over all the aui-toolbars and make sure they all have
    /// our custom aui artproivder
    DoUpdateAuiToolBars(clMainFrame::Get());
}

void ThemeHandler::DoUpdateColours(wxWindow* win, const wxColour& bg, const wxColour& fg)
{
#ifdef __WXMAC__
    if ( dynamic_cast<wxSearchCtrl*>(win) ) {
        // On OSX, this looks bad...
        // so dont alter its colours, so we simply do nothing here
    } else 
#endif
    if ( dynamic_cast<wxTreeCtrl*>(win) || dynamic_cast<wxListBox*>(win) || dynamic_cast<wxDataViewCtrl*>(win) || dynamic_cast<wxTextCtrl*>(win) || dynamic_cast<wxListCtrl*>(win)) {
        win->SetBackgroundColour( bg );
        win->SetForegroundColour( fg );
        win->Refresh();
    }
    
    wxWindowList::compatibility_iterator pclNode = win->GetChildren().GetFirst();
    while(pclNode) {
        wxWindow* pclChild = pclNode->GetData();
        this->DoUpdateColours(pclChild, bg, fg);
        pclNode = pclNode->GetNext();
    }
}

void ThemeHandler::DoUpdateSTCBgColour(wxStyledTextCtrl* stc)
{
    CHECK_POINTER(stc);
    for (int i=0; i<=wxSTC_STYLE_DEFAULT; ++i) {
        stc->StyleSetBackground(i, DrawingUtils::GetOutputPaneBgColour());
    }
    stc->Refresh();
}

void ThemeHandler::OnInitDone(wxCommandEvent& e)
{
    e.Skip();
    // Load all wxAuiToolBars and make sure they all have our custom wxAuiTabArt (which supports dark theme)
    wxAuiManager &aui = clMainFrame::Get()->GetDockingManager();
    wxAuiPaneInfoArray& allPanes = aui.GetAllPanes();
    for(size_t i=0; i<allPanes.GetCount(); ++i) {
        if ( allPanes.Item(i).IsToolbar() ) {
            wxAuiPaneInfo &pane = allPanes.Item(i);
            wxAuiToolBar *auibar = dynamic_cast<wxAuiToolBar*>(pane.window);
            if( auibar ) {
                CLMainAuiTBArt *clArtProvider = dynamic_cast<CLMainAuiTBArt*>(auibar->GetArtProvider());
                if ( !clArtProvider ) {
                    /// not codelite's custom art provider
                    /// replace it
                    auibar->SetArtProvider( new CLMainAuiTBArt() );
                }
            }
        }
    }
    aui.Update();
}

void ThemeHandler::DoUpdateAuiToolBars(wxWindow* win)
{
    // bool bDarkBG = DrawingUtils::IsDark(EditorConfigST::Get()->GetCurrentOutputviewBgColour());
    // 
    // wxAuiToolBar *auibar = dynamic_cast<wxAuiToolBar*>( win );
    // if( auibar ) {
    //     CLMainAuiTBArt *clArtProvider = dynamic_cast<CLMainAuiTBArt*>(auibar->GetArtProvider());
    //     if ( !clArtProvider ) {
    //         /// not codelite's custom art provider
    //         /// replace it
    //         auibar->SetArtProvider( new CLMainAuiTBArt() );
    //     }
    //     size_t toolCount = auibar->GetToolCount();
    //     for(size_t i=0; i<toolCount; i++) {
    //         wxAuiToolBarItem* tool = auibar->FindToolByIndex(i);
    //         if ( tool->GetKind() == wxITEM_NORMAL || tool->GetKind() == wxITEM_CHECK || tool->GetKind() == wxITEM_DROPDOWN || tool->GetKind() == wxITEM_RADIO ) {
    //             tool->SetDisabledBitmap( tool->GetBitmap().ConvertToDisabled(bDarkBG ? 50 : 255) );
    //         }
    //     }
    //     auibar->Refresh();
    // }
    // 
    // wxWindowList::compatibility_iterator pclNode = win->GetChildren().GetFirst();
    // while(pclNode) {
    //     wxWindow* pclChild = pclNode->GetData();
    //     this->DoUpdateAuiToolBars(pclChild);
    //     pclNode = pclNode->GetNext();
    // }
}