1
1
#include " ColoursAndFontsManager.h"
2
2
#include " IWorkspace.h"
3
+ #include " bitmap_loader.h"
3
4
#include " clEditorBar.h"
4
5
#include " clTabRenderer.h"
5
6
#include " clWorkspaceManager.h"
24
25
25
26
clEditorBar::clEditorBar (wxWindow* parent)
26
27
: clEditorBarBase(parent)
28
+ , m_scopeButtonState(eButtonState::kNormal )
27
29
, m_state(eButtonState::kNormal )
30
+ , m_bookmarksButtonState(eButtonState::kNormal )
28
31
{
29
- wxBitmap bmp (1 , 1 );
30
- wxMemoryDC memDC (bmp);
31
- m_defaultColour = DrawingUtils::GetPanelTextColour ();
32
- m_functionColour = DrawingUtils::GetPanelTextColour ();
33
- m_classColour = DrawingUtils::GetPanelTextColour ();
34
- m_bgColour = DrawingUtils::GetPanelBgColour ();
35
- m_textFont = m_textFont = wxSystemSettings::GetFont (wxSYS_DEFAULT_GUI_FONT);
36
- LexerConf::Ptr_t defaultLexer = ColoursAndFontsManager::Get ().GetLexer (" default" );
37
- if (defaultLexer) { m_textFont = defaultLexer->GetFontForSyle (0 ); }
38
-
39
- EventNotifier::Get ()->Bind (wxEVT_ACTIVE_EDITOR_CHANGED, &clEditorBar::OnEditorChanged, this );
40
- EventNotifier::Get ()->Bind (wxEVT_CMD_PAGE_CHANGED, &clEditorBar::OnEditorChanged, this );
41
- EventNotifier::Get ()->Bind (wxEVT_ALL_EDITORS_CLOSED, &clEditorBar::OnEditorChanged, this );
42
- EventNotifier::Get ()->Bind (wxEVT_CL_THEME_CHANGED, &clEditorBar::OnThemeChanged, this );
43
- SetBackgroundStyle (wxBG_STYLE_PAINT);
44
-
45
- memDC.SetFont (m_textFont);
46
- wxSize sz = memDC.GetTextExtent (" Tp" );
47
- sz.y += 2 * Y_SPACER; // 2*3 pixels
48
- SetSizeHints (wxSize (-1 , sz.y ));
49
-
50
- Bind (wxEVT_ENTER_WINDOW, &clEditorBar::OnEnterWindow, this );
51
- Bind (wxEVT_LEAVE_WINDOW, &clEditorBar::OnLeaveWindow, this );
32
+ {
33
+ wxBitmap bmp (1 , 1 );
34
+ wxMemoryDC memDC (bmp);
35
+ m_defaultColour = DrawingUtils::GetPanelTextColour ();
36
+ m_functionColour = DrawingUtils::GetPanelTextColour ();
37
+ m_classColour = DrawingUtils::GetPanelTextColour ();
38
+ m_bgColour = DrawingUtils::GetPanelBgColour ();
39
+ m_textFont = m_textFont = wxSystemSettings::GetFont (wxSYS_DEFAULT_GUI_FONT);
40
+ LexerConf::Ptr_t defaultLexer = ColoursAndFontsManager::Get ().GetLexer (" default" );
41
+ if (defaultLexer) { m_textFont = defaultLexer->GetFontForSyle (0 ); }
42
+
43
+ EventNotifier::Get ()->Bind (wxEVT_ACTIVE_EDITOR_CHANGED, &clEditorBar::OnEditorChanged, this );
44
+ EventNotifier::Get ()->Bind (wxEVT_CMD_PAGE_CHANGED, &clEditorBar::OnEditorChanged, this );
45
+ EventNotifier::Get ()->Bind (wxEVT_ALL_EDITORS_CLOSED, &clEditorBar::OnEditorChanged, this );
46
+ EventNotifier::Get ()->Bind (wxEVT_CL_THEME_CHANGED, &clEditorBar::OnThemeChanged, this );
47
+ SetBackgroundStyle (wxBG_STYLE_PAINT);
48
+
49
+ memDC.SetFont (m_textFont);
50
+ wxSize sz = memDC.GetTextExtent (" Tp" );
51
+ sz.y += (2 * Y_SPACER); // 2*3 pixels
52
+ SetSizeHints (wxSize (-1 , sz.y ));
53
+ }
54
+
55
+ {
56
+ m_bookmarksBmp = wxBitmap (16 , 16 );
57
+ wxMemoryDC memDC (m_bookmarksBmp);
58
+ wxColour c (" rgb(255, 128, 64)" );
59
+ memDC.SetPen (wxSystemSettings::GetColour (wxSYS_COLOUR_3DSHADOW));
60
+ memDC.SetBrush (wxColour (c));
61
+ memDC.DrawRectangle (0 , 0 , 16 , 16 );
62
+ memDC.SelectObject (wxNullBitmap);
63
+ }
64
+
65
+ Bind (wxEVT_IDLE, &clEditorBar::OnIdle, this );
52
66
Bind (wxEVT_LEFT_UP, &clEditorBar::OnLeftUp, this );
53
67
}
54
68
@@ -58,8 +72,7 @@ clEditorBar::~clEditorBar()
58
72
EventNotifier::Get ()->Unbind (wxEVT_CMD_PAGE_CHANGED, &clEditorBar::OnEditorChanged, this );
59
73
EventNotifier::Get ()->Unbind (wxEVT_ALL_EDITORS_CLOSED, &clEditorBar::OnEditorChanged, this );
60
74
EventNotifier::Get ()->Unbind (wxEVT_CL_THEME_CHANGED, &clEditorBar::OnThemeChanged, this );
61
- Unbind (wxEVT_ENTER_WINDOW, &clEditorBar::OnEnterWindow, this );
62
- Unbind (wxEVT_LEAVE_WINDOW, &clEditorBar::OnLeaveWindow, this );
75
+ Unbind (wxEVT_IDLE, &clEditorBar::OnIdle, this );
63
76
Unbind (wxEVT_LEFT_UP, &clEditorBar::OnLeftUp, this );
64
77
}
65
78
@@ -70,62 +83,54 @@ void clEditorBar::OnPaint(wxPaintEvent& e)
70
83
PrepareDC (bdc);
71
84
wxGCDC gcdc (bdc);
72
85
PrepareDC (gcdc);
73
-
86
+
87
+ wxFont guiFont = clTabRenderer::GetTabFont ();
74
88
wxRect rect (GetClientRect ());
75
89
gcdc.SetPen (m_bgColour);
76
90
gcdc.SetBrush (m_bgColour);
77
91
gcdc.DrawRectangle (rect);
78
92
93
+ // Draw the text
94
+ wxCoord textX = X_SPACER;
95
+ gcdc.SetFont (guiFont);
96
+
79
97
wxString fulltext;
80
98
if (!m_classname.IsEmpty ()) { fulltext << m_classname << " ::" ; }
81
99
if (!m_function.IsEmpty ()) { fulltext << m_function; }
82
100
83
- gcdc.SetFont (m_textFont);
84
- fulltext << " wwww" ; // spacer
85
- // wxSize fulltextSize = gcdc.GetTextExtent(fulltext);
86
-
87
- // Draw the text
88
- wxCoord textX = X_SPACER;
89
- gcdc.SetFont (m_textFont);
90
- wxSize textSize;
91
- wxCoord textY = ((rect.GetHeight () - gcdc.GetTextExtent (" Tp" ).GetHeight ()) / 2 );
92
-
93
- const int filenameButtonWidth = 400 + (4 * X_SPACER);
94
-
95
- if (!m_classname.IsEmpty ()) {
96
- textSize = gcdc.GetTextExtent (m_classname);
97
- gcdc.SetTextForeground (m_classColour);
98
- gcdc.DrawText (m_classname, textX, textY);
99
- textX += textSize.x ;
100
-
101
- textSize = gcdc.GetTextExtent (" ::" );
102
- gcdc.SetTextForeground (m_defaultColour);
103
- gcdc.DrawText (" ::" , textX, textY);
104
- textX += textSize.x ;
105
- }
106
-
107
- if (!m_function.IsEmpty ()) {
108
- textSize = gcdc.GetTextExtent (m_function);
109
- gcdc.SetTextForeground (m_functionColour);
110
- gcdc.DrawText (m_function, textX, textY);
111
- textX += textSize.x ;
101
+ if (!fulltext.IsEmpty ()) {
102
+ int scopeButtonWidth = gcdc.GetTextExtent (" W" + fulltext + " W" ).GetWidth ();
103
+ m_scopeRect = wxRect (textX, 0 , scopeButtonWidth + 20 , rect.GetHeight () - 2 );
104
+ DrawingUtils::DrawButton (gcdc, this , m_scopeRect, fulltext, wxNullBitmap, eButtonKind::kDropDown ,
105
+ m_scopeButtonState);
106
+ textX += m_scopeRect.GetWidth ();
112
107
}
113
-
108
+
109
+ textX += X_SPACER;
114
110
if (!m_breadcrumbs.IsEmpty ()) {
115
111
wxString breadcumbsText;
116
112
for (size_t i = 0 ; i < m_breadcrumbs.size (); ++i) {
117
113
breadcumbsText << m_breadcrumbs.Item (i) << " / " ;
118
114
}
115
+
119
116
breadcumbsText.RemoveLast (3 );
120
- wxFont guiFont = clTabRenderer::GetTabFont ();
121
117
gcdc.SetFont (guiFont);
118
+ int filenameButtonWidth = gcdc.GetTextExtent (" W" + breadcumbsText + " W" ).GetWidth ();
119
+
122
120
// Geometry
123
- m_filenameRect = wxRect (GetClientRect ().GetWidth () - filenameButtonWidth - X_SPACER, 0 , filenameButtonWidth,
124
- rect.GetHeight () - 2 );
121
+ m_filenameRect = wxRect (textX, 0 , filenameButtonWidth, rect.GetHeight () - 2 );
125
122
DrawingUtils::DrawButton (gcdc, this , m_filenameRect, breadcumbsText, wxNullBitmap, eButtonKind::kDropDown ,
126
123
m_state);
127
124
textX += filenameButtonWidth;
128
- textX += (2 * X_SPACER);
125
+ textX += X_SPACER;
126
+
127
+ wxString bookmarksLabel = _ (" Bookmarks" );
128
+ wxSize bookmarksTextSize = gcdc.GetTextExtent (bookmarksLabel);
129
+
130
+ // Add 60 (about 40 for the image and 20 needed for the drop down button
131
+ m_bookmarksRect = wxRect (textX, 0 , bookmarksTextSize.GetWidth () + 60 , rect.GetHeight () - 2 );
132
+ DrawingUtils::DrawButton (gcdc, this , m_bookmarksRect, bookmarksLabel, m_bookmarksBmp, eButtonKind::kDropDown ,
133
+ m_bookmarksButtonState);
129
134
}
130
135
}
131
136
@@ -207,8 +212,11 @@ void clEditorBar::OnEditorSize(wxSizeEvent& event)
207
212
DoRefreshColoursAndFonts ();
208
213
}
209
214
210
- void clEditorBar::OnLeftDown (wxMouseEvent& e)
215
+ void clEditorBar::OnLeftDown (wxMouseEvent& e) { e.Skip (); }
216
+
217
+ void clEditorBar::OnLeftUp (wxMouseEvent& e)
211
218
{
219
+ e.Skip ();
212
220
if (m_filenameRect.Contains (e.GetPosition ())) {
213
221
wxMenu menu;
214
222
wxString text;
@@ -263,23 +271,28 @@ void clEditorBar::OnLeftDown(wxMouseEvent& e)
263
271
::CopyToClipboard (text);
264
272
clGetManager ()->SetStatusMessage ((wxString () << " '" << text << _ (" ' copied!" )), 2 );
265
273
}
274
+ } else if (m_bookmarksRect.Contains (e.GetPosition ())) {
275
+ // TODO: show bookmarks menu here
276
+ } else if (m_scopeRect.Contains (e.GetPosition ())) {
277
+ // TODO: show scope menu here
266
278
}
267
279
}
268
280
269
- void clEditorBar::OnLeftUp (wxMouseEvent& e)
270
- {
271
- m_state = eButtonState::kNormal ;
272
- Refresh ();
273
- }
281
+ void clEditorBar::DoRefresh () { Refresh (); }
274
282
275
- void clEditorBar::OnEnterWindow (wxMouseEvent & e)
283
+ void clEditorBar::OnIdle (wxIdleEvent & e)
276
284
{
277
- m_state = eButtonState::kHover ;
278
- Refresh ();
279
- }
280
-
281
- void clEditorBar::OnLeaveWindow (wxMouseEvent& e)
282
- {
283
- m_state = eButtonState::kNormal ;
284
- Refresh ();
285
+ e.Skip ();
286
+ wxPoint pos = ScreenToClient (::wxGetMousePosition ());
287
+ if (GetClientRect ().Contains (pos)) {
288
+ m_state = m_bookmarksButtonState = m_scopeButtonState = eButtonState::kNormal ;
289
+ if (m_filenameRect.Contains (pos)) {
290
+ m_state = eButtonState::kHover ;
291
+ } else if (m_bookmarksRect.Contains (pos)) {
292
+ m_bookmarksButtonState = eButtonState::kHover ;
293
+ } else if (m_scopeRect.Contains (pos)) {
294
+ m_scopeButtonState = eButtonState::kHover ;
295
+ }
296
+ CallAfter (&clEditorBar::DoRefresh);
297
+ }
285
298
}
0 commit comments