~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/src/notebookstyles.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 
3
 * http://www.gnu.org/licenses/gpl-3.0.html
 
4
 */
 
5
 
 
6
#include <wx/dc.h>
 
7
#include <wx/window.h>
 
8
#include <wx/gdicmn.h>
 
9
#include <wx/string.h>
 
10
#include <wx/settings.h>
 
11
#include <wx/dcclient.h>
 
12
#include "cbauibook.h"
 
13
#include "notebookstyles.h"
 
14
 
 
15
// Some general constants:
 
16
namespace
 
17
{
 
18
    const int c_vertical_border_padding = 4;
 
19
}
 
20
 
 
21
/******************************************************************************
 
22
* Renderer for Microsoft (tm) Visual Studio 7.1 like tabs                     *
 
23
******************************************************************************/
 
24
 
 
25
NbStyleVC71::NbStyleVC71() : wxAuiDefaultTabArt()
 
26
{
 
27
}
 
28
 
 
29
wxAuiTabArt* NbStyleVC71::Clone()
 
30
{
 
31
    NbStyleVC71* clone = new NbStyleVC71();
 
32
 
 
33
    clone->SetNormalFont(m_normal_font);
 
34
    clone->SetSelectedFont(m_selected_font);
 
35
    clone->SetMeasuringFont(m_measuring_font);
 
36
 
 
37
    return clone;
 
38
}
 
39
 
 
40
void NbStyleVC71::DrawTab(wxDC& dc, wxWindow* wnd,
 
41
                            const wxAuiNotebookPage& page,
 
42
                            const wxRect& in_rect, int close_button_state,
 
43
                            wxRect* out_tab_rect, wxRect* out_button_rect,
 
44
                            int* x_extent)
 
45
{
 
46
    // Visual studio 7.1 style
 
47
    // This code is based on the renderer included in wxFlatNotebook:
 
48
    // http://svn.berlios.de/wsvn/codeblocks/trunk/src/sdk/wxFlatNotebook/src/wxFlatNotebook/renderer.cpp?rev=5106
 
49
 
 
50
    // figure out the size of the tab
 
51
 
 
52
    wxSize tab_size = GetTabSize(dc,
 
53
                                 wnd,
 
54
                                 page.caption,
 
55
                                 page.bitmap,
 
56
                                 page.active,
 
57
                                 close_button_state,
 
58
                                 x_extent);
 
59
 
 
60
    wxCoord tab_height = m_tab_ctrl_height - 3;
 
61
    wxCoord tab_width = tab_size.x;
 
62
    wxCoord tab_x = in_rect.x;
 
63
    wxCoord tab_y = in_rect.y + in_rect.height - tab_height;
 
64
    int clip_width = tab_width;
 
65
    if (tab_x + clip_width > in_rect.x + in_rect.width - 4)
 
66
        clip_width = (in_rect.x + in_rect.width) - tab_x - 4;
 
67
    dc.SetClippingRegion(tab_x, tab_y, clip_width + 1, tab_height - 3);
 
68
    if(m_flags & wxAUI_NB_BOTTOM)
 
69
        tab_y--;
 
70
 
 
71
    dc.SetPen((page.active) ? wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) : wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
 
72
    dc.SetBrush((page.active) ? wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)) : wxBrush(*wxTRANSPARENT_BRUSH));
 
73
 
 
74
    if (page.active)
 
75
    {
 
76
//        int tabH = (m_flags & wxAUI_NB_BOTTOM) ? tab_height - 5 : tab_height - 2;
 
77
        int tabH = tab_height - 2;
 
78
 
 
79
        dc.DrawRectangle(tab_x, tab_y, tab_width, tabH);
 
80
 
 
81
        int rightLineY1 = (m_flags & wxAUI_NB_BOTTOM) ? c_vertical_border_padding - 2 : c_vertical_border_padding - 1;
 
82
        int rightLineY2 = tabH + 3;
 
83
        dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
 
84
        dc.DrawLine(tab_x + tab_width - 1, rightLineY1 + 1, tab_x + tab_width - 1, rightLineY2);
 
85
        if(m_flags & wxAUI_NB_BOTTOM)
 
86
            dc.DrawLine(tab_x + 1, rightLineY2 - 3 , tab_x + tab_width - 1, rightLineY2 - 3);
 
87
        dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)));
 
88
        dc.DrawLine(tab_x + tab_width , rightLineY1 , tab_x + tab_width, rightLineY2);
 
89
        if(m_flags & wxAUI_NB_BOTTOM)
 
90
            dc.DrawLine(tab_x , rightLineY2 - 2 , tab_x + tab_width, rightLineY2 - 2);
 
91
 
 
92
    }
 
93
    else
 
94
    {
 
95
        // We dont draw a rectangle for non selected tabs, but only
 
96
        // vertical line on the right
 
97
        int blackLineY1 = (m_flags & wxAUI_NB_BOTTOM) ? c_vertical_border_padding + 2 : c_vertical_border_padding + 1;
 
98
        int blackLineY2 = tab_height - 5;
 
99
        dc.DrawLine(tab_x + tab_width, blackLineY1, tab_x + tab_width, blackLineY2);
 
100
    }
 
101
 
 
102
    wxPoint border_points[2];
 
103
    if (m_flags & wxAUI_NB_BOTTOM)
 
104
    {
 
105
        border_points[0] = wxPoint(tab_x, tab_y);
 
106
        border_points[1] = wxPoint(tab_x, tab_y + tab_height - 6);
 
107
    }
 
108
    else // if (m_flags & wxAUI_NB_TOP)
 
109
    {
 
110
        border_points[0] = wxPoint(tab_x, tab_y + tab_height - 4);
 
111
        border_points[1] = wxPoint(tab_x, tab_y + 2);
 
112
    }
 
113
 
 
114
    int drawn_tab_yoff = border_points[1].y;
 
115
    int drawn_tab_height = border_points[0].y - border_points[1].y;
 
116
 
 
117
    int text_offset = tab_x + 8;
 
118
    int close_button_width = 0;
 
119
    if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
 
120
    {
 
121
        close_button_width = m_active_close_bmp.GetWidth();
 
122
    }
 
123
 
 
124
 
 
125
    int bitmap_offset = 0;
 
126
    if (page.bitmap.IsOk())
 
127
    {
 
128
        bitmap_offset = tab_x + 8;
 
129
 
 
130
        // draw bitmap
 
131
        dc.DrawBitmap(page.bitmap,
 
132
                      bitmap_offset,
 
133
                      drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2),
 
134
                      true);
 
135
 
 
136
        text_offset = bitmap_offset + page.bitmap.GetWidth();
 
137
        text_offset += 3; // bitmap padding
 
138
    }
 
139
     else
 
140
    {
 
141
        text_offset = tab_x + 8;
 
142
    }
 
143
 
 
144
 
 
145
    // if the caption is empty, measure some temporary text
 
146
    wxString caption = page.caption;
 
147
    if (caption.empty())
 
148
        caption = wxT("Xj");
 
149
 
 
150
    wxCoord textx;
 
151
    wxCoord texty;
 
152
    if (page.active)
 
153
        dc.SetFont(m_selected_font);
 
154
    else
 
155
        dc.SetFont(m_normal_font);
 
156
    dc.GetTextExtent(caption, &textx, &texty);
 
157
    // draw tab text
 
158
    dc.DrawText(page.caption, text_offset,
 
159
                drawn_tab_yoff + drawn_tab_height / 2 - texty / 2 - 1);
 
160
 
 
161
    // draw 'x' on tab (if enabled)
 
162
    if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
 
163
    {
 
164
        int close_button_width = m_active_close_bmp.GetWidth();
 
165
        wxBitmap bmp = m_disabled_close_bmp;
 
166
 
 
167
        if ((close_button_state == wxAUI_BUTTON_STATE_HOVER) ||
 
168
                    (close_button_state == wxAUI_BUTTON_STATE_PRESSED))
 
169
            bmp = m_active_close_bmp;
 
170
 
 
171
        wxRect rect(tab_x + tab_width - close_button_width - 3,
 
172
                    drawn_tab_yoff + (drawn_tab_height / 2) - (bmp.GetHeight() / 2),
 
173
                    close_button_width, tab_height);
 
174
 
 
175
        // Indent the button if it is pressed down:
 
176
        if (close_button_state == wxAUI_BUTTON_STATE_PRESSED)
 
177
        {
 
178
            rect.x++;
 
179
            rect.y++;
 
180
        }
 
181
        dc.DrawBitmap(bmp, rect.x, rect.y, true);
 
182
        *out_button_rect = rect;
 
183
    }
 
184
 
 
185
    *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height);
 
186
    dc.DestroyClippingRegion();
 
187
}
 
188
 
 
189
int NbStyleVC71::GetBestTabCtrlSize(wxWindow* wnd,
 
190
                                    const wxAuiNotebookPageArray& WXUNUSED(pages),
 
191
                                    const wxSize& WXUNUSED(required_bmp_size))
 
192
{
 
193
//    m_requested_tabctrl_height = -1;
 
194
//    m_tab_ctrl_height = -1;
 
195
    wxClientDC dc(wnd);
 
196
    dc.SetFont(m_measuring_font);
 
197
    int x_ext = 0;
 
198
    wxSize s = GetTabSize(dc, wnd, wxT("ABCDEFGHIj"), wxNullBitmap, true,
 
199
                            wxAUI_BUTTON_STATE_HIDDEN, &x_ext);
 
200
    return s.y + 4;
 
201
}
 
202
 
 
203
NbStyleFF2::NbStyleFF2() : wxAuiDefaultTabArt()
 
204
{
 
205
}
 
206
 
 
207
wxAuiTabArt* NbStyleFF2::Clone()
 
208
{
 
209
    NbStyleFF2* clone = new NbStyleFF2();
 
210
 
 
211
    clone->SetNormalFont(m_normal_font);
 
212
    clone->SetSelectedFont(m_selected_font);
 
213
    clone->SetMeasuringFont(m_measuring_font);
 
214
 
 
215
    return clone;
 
216
}
 
217
 
 
218
void NbStyleFF2::DrawTab(wxDC& dc, wxWindow* wnd,
 
219
                            const wxAuiNotebookPage& page,
 
220
                            const wxRect& in_rect, int close_button_state,
 
221
                            wxRect* out_tab_rect, wxRect* out_button_rect,
 
222
                            int* x_extent)
 
223
{
 
224
 
 
225
    // Firefox 2 style
 
226
 
 
227
    // figure out the size of the tab
 
228
    wxSize tab_size = GetTabSize(dc, wnd, page.caption, page.bitmap,
 
229
                                    page.active, close_button_state, x_extent);
 
230
 
 
231
    wxCoord tab_height = m_tab_ctrl_height - 2;
 
232
    wxCoord tab_width = tab_size.x;
 
233
    wxCoord tab_x = in_rect.x;
 
234
    wxCoord tab_y = in_rect.y + in_rect.height - tab_height;
 
235
 
 
236
    int clip_width = tab_width;
 
237
    if (tab_x + clip_width > in_rect.x + in_rect.width - 4)
 
238
        clip_width = (in_rect.x + in_rect.width) - tab_x - 4;
 
239
    dc.SetClippingRegion(tab_x, tab_y, clip_width + 1, tab_height - 3);
 
240
 
 
241
        wxPoint tabPoints[7];
 
242
        int adjust = 0;
 
243
    if (!page.active)
 
244
    {
 
245
        adjust = 1;
 
246
    }
 
247
 
 
248
    tabPoints[0].x = tab_x + 3;
 
249
    tabPoints[0].y = (m_flags & wxAUI_NB_BOTTOM) ? 3 : tab_height - 2;
 
250
 
 
251
    tabPoints[1].x = tabPoints[0].x;
 
252
    tabPoints[1].y = (m_flags & wxAUI_NB_BOTTOM) ? tab_height - (c_vertical_border_padding + 2) - adjust : (c_vertical_border_padding + 2) + adjust;
 
253
 
 
254
    tabPoints[2].x = tabPoints[1].x+2;
 
255
    tabPoints[2].y = (m_flags & wxAUI_NB_BOTTOM) ? tab_height - c_vertical_border_padding - adjust: c_vertical_border_padding + adjust;
 
256
 
 
257
    tabPoints[3].x = tab_x +tab_width - 2;
 
258
    tabPoints[3].y = tabPoints[2].y;
 
259
 
 
260
    tabPoints[4].x = tabPoints[3].x + 2;
 
261
    tabPoints[4].y = tabPoints[1].y;
 
262
 
 
263
    tabPoints[5].x = tabPoints[4].x;
 
264
    tabPoints[5].y = tabPoints[0].y;
 
265
 
 
266
    tabPoints[6].x = tabPoints[0].x;
 
267
    tabPoints[6].y = tabPoints[0].y;
 
268
 
 
269
//    dc.SetBrush((page.active) ? wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)) : wxBrush(wxAuiStepColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE),85)));
 
270
    dc.SetBrush((page.active) ? wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)) : wxBrush(*wxTRANSPARENT_BRUSH));
 
271
 
 
272
        dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)));
 
273
 
 
274
        dc.DrawPolygon(7, tabPoints);
 
275
 
 
276
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
 
277
    if (page.active)
 
278
    {
 
279
        dc.DrawLine(tabPoints[0].x + 1, tabPoints[0].y, tabPoints[5].x , tabPoints[0].y);
 
280
    }
 
281
 
 
282
    int drawn_tab_yoff = tabPoints[1].y;
 
283
    int drawn_tab_height = tabPoints[0].y - tabPoints[2].y;
 
284
 
 
285
    int text_offset = tab_x + 8;
 
286
    int close_button_width = 0;
 
287
    if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
 
288
    {
 
289
        close_button_width = m_active_close_bmp.GetWidth();
 
290
    }
 
291
 
 
292
 
 
293
    int bitmap_offset = 0;
 
294
    if (page.bitmap.IsOk())
 
295
    {
 
296
        bitmap_offset = tab_x + 8;
 
297
 
 
298
        // draw bitmap
 
299
        dc.DrawBitmap(page.bitmap,
 
300
                      bitmap_offset,
 
301
                      drawn_tab_yoff + (drawn_tab_height/2) - (page.bitmap.GetHeight()/2),
 
302
                      true);
 
303
 
 
304
        text_offset = bitmap_offset + page.bitmap.GetWidth();
 
305
        text_offset += 3; // bitmap padding
 
306
    }
 
307
     else
 
308
    {
 
309
        text_offset = tab_x + 8;
 
310
    }
 
311
 
 
312
 
 
313
    // if the caption is empty, measure some temporary text
 
314
    wxString caption = page.caption;
 
315
    if (caption.empty())
 
316
        caption = wxT("Xj");
 
317
 
 
318
    wxCoord textx;
 
319
    wxCoord texty;
 
320
    if (page.active)
 
321
        dc.SetFont(m_selected_font);
 
322
    else
 
323
        dc.SetFont(m_normal_font);
 
324
    dc.GetTextExtent(caption, &textx, &texty);
 
325
    // draw tab text
 
326
    dc.DrawText(page.caption, text_offset,
 
327
                drawn_tab_yoff + drawn_tab_height / 2 - texty / 2 - 1);
 
328
 
 
329
    // draw 'x' on tab (if enabled)
 
330
    if (close_button_state != wxAUI_BUTTON_STATE_HIDDEN)
 
331
    {
 
332
        int close_button_width = m_active_close_bmp.GetWidth();
 
333
        wxBitmap bmp = m_disabled_close_bmp;
 
334
 
 
335
        if ((close_button_state == wxAUI_BUTTON_STATE_HOVER) ||
 
336
                    (close_button_state == wxAUI_BUTTON_STATE_PRESSED))
 
337
            bmp = m_active_close_bmp;
 
338
 
 
339
        wxRect rect(tab_x + tab_width - close_button_width - 3,
 
340
                    drawn_tab_yoff + (drawn_tab_height / 2) - (bmp.GetHeight() / 2),
 
341
                    close_button_width, tab_height);
 
342
 
 
343
        // Indent the button if it is pressed down:
 
344
        if (close_button_state == wxAUI_BUTTON_STATE_PRESSED)
 
345
        {
 
346
            rect.x++;
 
347
            rect.y++;
 
348
        }
 
349
        dc.DrawBitmap(bmp, rect.x, rect.y, true);
 
350
        *out_button_rect = rect;
 
351
    }
 
352
 
 
353
    *out_tab_rect = wxRect(tab_x, tab_y, tab_width, tab_height);
 
354
    dc.DestroyClippingRegion();
 
355
}
 
356
 
 
357
int NbStyleFF2::GetBestTabCtrlSize(wxWindow* wnd,
 
358
                                    const wxAuiNotebookPageArray& WXUNUSED(pages),
 
359
                                    const wxSize& WXUNUSED(required_bmp_size))
 
360
{
 
361
//    m_requested_tabctrl_height = -1;
 
362
//    m_tab_ctrl_height = -1;
 
363
    wxClientDC dc(wnd);
 
364
    dc.SetFont(m_measuring_font);
 
365
    int x_ext = 0;
 
366
    wxSize s = GetTabSize(dc, wnd, wxT("ABCDEFGHIj"), wxNullBitmap, true,
 
367
                            wxAUI_BUTTON_STATE_HIDDEN, &x_ext);
 
368
    return s.y + 6;
 
369
}
 
370