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

« back to all changes in this revision

Viewing changes to src/sdk/wxFlatNotebook/src/wxFlatNotebook/popup_dlg.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
 
#include <wx/wxFlatNotebook/popup_dlg.h>
2
 
#include <wx/listctrl.h>
3
 
#include <wx/wxFlatNotebook/wxFlatNotebook.h>
4
 
#include <wx/wxFlatNotebook/renderer.h>
5
 
#include <wx/listbox.h>
6
 
#include <wx/image.h>
7
 
//#include <wx/mstream.h>
8
 
#include <wx/wxFlatNotebook/fnb_resources.h>
9
 
 
10
 
wxBitmap wxTabNavigatorWindow::m_bmp;
11
 
 
12
 
wxTabNavigatorWindow::wxTabNavigatorWindow(wxWindow* parent)
13
 
: m_listBox(NULL)
14
 
, m_selectedItem(-1)
15
 
, m_panel(NULL)
16
 
{
17
 
        Create(parent);
18
 
        GetSizer()->Fit(this);
19
 
        GetSizer()->SetSizeHints(this);
20
 
        GetSizer()->Layout();
21
 
        Centre();
22
 
}
23
 
 
24
 
wxTabNavigatorWindow::wxTabNavigatorWindow()
25
 
: wxDialog()
26
 
, m_listBox(NULL)
27
 
, m_selectedItem(-1)
28
 
, m_panel(NULL)
29
 
{
30
 
}
31
 
 
32
 
wxTabNavigatorWindow::~wxTabNavigatorWindow()
33
 
{
34
 
}
35
 
 
36
 
void wxTabNavigatorWindow::Create(wxWindow* parent)
37
 
{
38
 
        long style = 0;
39
 
        if(  !wxDialog::Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, style) )
40
 
                return;
41
 
 
42
 
        wxBoxSizer *sz = new wxBoxSizer( wxVERTICAL );
43
 
        SetSizer( sz );
44
 
 
45
 
        long flags = wxLB_SINGLE | wxNO_BORDER ;
46
 
        m_listBox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(200, 150), 0, NULL, flags);
47
 
 
48
 
        static int panelHeight = 0;
49
 
        if( panelHeight == 0 )
50
 
        {
51
 
                wxMemoryDC mem_dc;
52
 
 
53
 
                // bitmap must be set before it can be used for anything
54
 
                wxBitmap bmp(10, 10);
55
 
                mem_dc.SelectObject(bmp);
56
 
 
57
 
                wxFont font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
58
 
                font.SetWeight( wxBOLD );
59
 
                mem_dc.SetFont(font);
60
 
                int w;
61
 
                mem_dc.GetTextExtent(wxT("Tp"), &w, &panelHeight);
62
 
                panelHeight += 4; // Place a spacer of 2 pixels
63
 
 
64
 
                // Out signpost bitmap is 24 pixels
65
 
                if( panelHeight < 24 )
66
 
                        panelHeight = 24;
67
 
        }
68
 
 
69
 
        m_panel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxSize(200, panelHeight));
70
 
 
71
 
        sz->Add( m_panel );
72
 
        sz->Add( m_listBox, 1, wxEXPAND );
73
 
 
74
 
        SetSizer( sz );
75
 
 
76
 
        // Connect events to the list box
77
 
        m_listBox->Connect(wxID_ANY, wxEVT_KEY_UP, wxKeyEventHandler(wxTabNavigatorWindow::OnKeyUp), NULL, this);
78
 
        //Connect(wxEVT_CHAR_HOOK, wxCharEventHandler(wxTabNavigatorWindow::OnKeyUp), NULL, this);
79
 
        m_listBox->Connect(wxID_ANY, wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(wxTabNavigatorWindow::OnNavigationKey), NULL, this);
80
 
        m_listBox->Connect(wxID_ANY, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler(wxTabNavigatorWindow::OnItemSelected), NULL, this);
81
 
 
82
 
        // Connect paint event to the panel
83
 
        m_panel->Connect(wxID_ANY, wxEVT_PAINT, wxPaintEventHandler(wxTabNavigatorWindow::OnPanelPaint), NULL, this);
84
 
        m_panel->Connect(wxID_ANY, wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(wxTabNavigatorWindow::OnPanelEraseBg), NULL, this);
85
 
 
86
 
        SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) );
87
 
        m_listBox->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
88
 
        PopulateListControl( static_cast<wxFlatNotebook*>( parent ) );
89
 
 
90
 
        // Create the bitmap, only once
91
 
        if( !m_bmp.Ok() )
92
 
        {
93
 
                wxImage img(signpost_xpm);
94
 
                img.SetAlpha((unsigned char*)signpost_alpha, true);
95
 
                m_bmp =  wxBitmap(img);
96
 
        }
97
 
        m_listBox->SetFocus();
98
 
}
99
 
 
100
 
void wxTabNavigatorWindow::OnKeyUp(wxKeyEvent &event)
101
 
{
102
 
        if( event.GetKeyCode() == WXK_CONTROL )
103
 
        {
104
 
                CloseDialog();
105
 
        }
106
 
}
107
 
 
108
 
void wxTabNavigatorWindow::OnNavigationKey(wxNavigationKeyEvent &event)
109
 
{
110
 
        long selected = m_listBox->GetSelection();
111
 
        wxFlatNotebook* bk = static_cast<wxFlatNotebook*>(GetParent());
112
 
        long maxItems = bk->GetPageCount();
113
 
        long itemToSelect;
114
 
 
115
 
        if( event.GetDirection() )
116
 
        {
117
 
                // Select next page
118
 
                if (selected == maxItems - 1)
119
 
                        itemToSelect = 0;
120
 
                else
121
 
                        itemToSelect = selected + 1;
122
 
        }
123
 
        else
124
 
        {
125
 
                // Previous page
126
 
                if( selected == 0 )
127
 
                        itemToSelect = maxItems - 1;
128
 
                else
129
 
                        itemToSelect = selected - 1;
130
 
        }
131
 
 
132
 
        m_listBox->SetSelection( itemToSelect );
133
 
}
134
 
 
135
 
void wxTabNavigatorWindow::PopulateListControl(wxFlatNotebook *book)
136
 
{
137
 
        int selection = book->GetSelection();
138
 
        //int count     = book->GetPageCount();
139
 
 
140
 
        std::map<int, bool> temp;
141
 
        m_listBox->Append( book->GetPageText(static_cast<int>(selection)) );
142
 
        m_indexMap[0] = selection;
143
 
        temp[selection] = true;
144
 
 
145
 
        const wxArrayInt &arr = book->GetBrowseHistory();
146
 
        for(size_t i=0; i<arr.GetCount(); i++)
147
 
        {
148
 
                if(temp.find(arr.Item(i)) == temp.end()){
149
 
                        m_listBox->Append( book->GetPageText(static_cast<int>(arr.Item(i))) );
150
 
                        m_indexMap[(int)m_listBox->GetCount()-1] = arr.Item(i);
151
 
                        temp[arr.Item(i)] = true;
152
 
                }
153
 
        }
154
 
 
155
 
        // Select the next entry after the current selection
156
 
        m_listBox->SetSelection( 0 );
157
 
        wxNavigationKeyEvent dummy;
158
 
        dummy.SetDirection(true);
159
 
        OnNavigationKey(dummy);
160
 
}
161
 
 
162
 
void wxTabNavigatorWindow::OnItemSelected(wxCommandEvent & event )
163
 
{
164
 
        wxUnusedVar( event );
165
 
        CloseDialog();
166
 
}
167
 
 
168
 
void wxTabNavigatorWindow::CloseDialog()
169
 
{
170
 
        wxFlatNotebook* bk = static_cast<wxFlatNotebook*>(GetParent());
171
 
        m_selectedItem = m_listBox->GetSelection();
172
 
        std::map<int, int>::iterator iter = m_indexMap.find(m_selectedItem);
173
 
        bk->SetSelection( iter->second );
174
 
        EndModal( wxID_OK );
175
 
}
176
 
 
177
 
void wxTabNavigatorWindow::OnPanelPaint(wxPaintEvent &event)
178
 
{
179
 
        wxUnusedVar(event);
180
 
        wxPaintDC dc(m_panel);
181
 
        wxRect rect = m_panel->GetClientRect();
182
 
 
183
 
        static bool first = true;
184
 
        static wxBitmap bmp( rect.width, rect.height );
185
 
 
186
 
        if( first )
187
 
        {
188
 
                first = false;
189
 
                wxMemoryDC mem_dc;
190
 
                mem_dc.SelectObject( bmp );
191
 
 
192
 
                wxColour endColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW) );
193
 
                wxColour startColour( wxFNBRenderer::LightColour(endColour, 50) );
194
 
                wxFNBRenderer::PaintStraightGradientBox(mem_dc, rect, startColour, endColour);
195
 
 
196
 
                // Draw the caption title and place the bitmap
197
 
                wxPoint bmpPt;
198
 
                wxPoint txtPt;
199
 
 
200
 
                // get the bitmap optimal position, and draw it
201
 
                bmpPt.y = (rect.height - m_bmp.GetHeight()) / 2;
202
 
                bmpPt.x = 3;
203
 
                mem_dc.DrawBitmap( m_bmp, bmpPt, true );
204
 
 
205
 
                // get the text position, and draw it
206
 
                int fontHeight(0), w(0);
207
 
                wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
208
 
                font.SetWeight( wxBOLD );
209
 
                mem_dc.SetFont( font );
210
 
                mem_dc.GetTextExtent( wxT("Tp"), &w, &fontHeight );
211
 
 
212
 
                txtPt.x = bmpPt.x + m_bmp.GetWidth() + 4;
213
 
                txtPt.y = (rect.height - fontHeight)/2;
214
 
                mem_dc.SetTextForeground( *wxWHITE );
215
 
                mem_dc.DrawText( wxT("Opened tabs:"), txtPt );
216
 
                mem_dc.SelectObject( wxNullBitmap );
217
 
        }
218
 
 
219
 
        dc.DrawBitmap( bmp, 0, 0 );
220
 
}
221
 
 
222
 
void wxTabNavigatorWindow::OnPanelEraseBg(wxEraseEvent &event)
223
 
{
224
 
        wxUnusedVar(event);
225
 
 
226
 
}