]>
Commit | Line | Data |
---|---|---|
1e6feb95 | 1 | /////////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/univ/window.cpp |
1e6feb95 VZ |
3 | // Purpose: implementation of extra wxWindow methods for wxUniv port |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 06.08.00 | |
7 | // RCS-ID: $Id$ | |
442b35b5 | 8 | // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
1e6feb95 VZ |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
e4db172a WS |
27 | #include "wx/window.h" |
28 | ||
1e6feb95 VZ |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/app.h" | |
1e6feb95 VZ |
31 | #include "wx/dcclient.h" |
32 | #include "wx/dcmemory.h" | |
33 | #include "wx/event.h" | |
34 | #include "wx/scrolbar.h" | |
35 | #include "wx/menu.h" | |
8cb172b4 | 36 | #include "wx/frame.h" |
e4db172a | 37 | #include "wx/log.h" |
1e6feb95 VZ |
38 | #endif // WX_PRECOMP |
39 | ||
40 | #include "wx/univ/colschem.h" | |
41 | #include "wx/univ/renderer.h" | |
42 | #include "wx/univ/theme.h" | |
43 | ||
44 | #if wxUSE_CARET | |
45 | #include "wx/caret.h" | |
46 | #endif // wxUSE_CARET | |
47 | ||
48 | // turn Refresh() debugging on/off | |
49 | #define WXDEBUG_REFRESH | |
50 | ||
51 | #ifndef __WXDEBUG__ | |
52 | #undef WXDEBUG_REFRESH | |
53 | #endif | |
54 | ||
cff7ef89 VS |
55 | #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__) |
56 | #include "wx/msw/private.h" | |
57 | #endif | |
58 | ||
1e6feb95 VZ |
59 | // ============================================================================ |
60 | // implementation | |
61 | // ============================================================================ | |
62 | ||
c04c7a3d VS |
63 | // ---------------------------------------------------------------------------- |
64 | // scrollbars class | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
67 | // This is scrollbar class used to implement wxWindow's "built-in" scrollbars; | |
68 | // unlike the standard wxScrollBar class, this one is positioned outside of its | |
69 | // parent's client area | |
70 | class wxWindowScrollBar : public wxScrollBar | |
71 | { | |
72 | public: | |
73 | wxWindowScrollBar(wxWindow *parent, | |
74 | wxWindowID id, | |
75 | const wxPoint& pos = wxDefaultPosition, | |
76 | const wxSize& size = wxDefaultSize, | |
77 | long style = wxSB_HORIZONTAL) | |
78 | : wxScrollBar(parent, id, pos, size, style) | |
79 | { | |
80 | } | |
81 | ||
82 | virtual bool CanBeOutsideClientArea() const { return true; } | |
83 | }; | |
84 | ||
85 | ||
1e6feb95 VZ |
86 | // ---------------------------------------------------------------------------- |
87 | // event tables | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
90 | // we can't use wxWindowNative here as it won't be expanded inside the macro | |
91 | #if defined(__WXMSW__) | |
92 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowMSW) | |
93 | #elif defined(__WXGTK__) | |
94 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowGTK) | |
95 | #elif defined(__WXMGL__) | |
96 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowMGL) | |
b3c86150 VS |
97 | #elif defined(__WXDFB__) |
98 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowDFB) | |
8354aa92 RR |
99 | #elif defined(__WXX11__) |
100 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowX11) | |
19193a2c KB |
101 | #elif defined(__WXPM__) |
102 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowOS2) | |
1e6feb95 VZ |
103 | #endif |
104 | ||
105 | BEGIN_EVENT_TABLE(wxWindow, wxWindowNative) | |
106 | EVT_SIZE(wxWindow::OnSize) | |
107 | ||
108 | #if wxUSE_ACCEL || wxUSE_MENUS | |
109 | EVT_KEY_DOWN(wxWindow::OnKeyDown) | |
110 | #endif // wxUSE_ACCEL | |
111 | ||
112 | #if wxUSE_MENUS | |
113 | EVT_CHAR(wxWindow::OnChar) | |
114 | EVT_KEY_UP(wxWindow::OnKeyUp) | |
115 | #endif // wxUSE_MENUS | |
116 | ||
117 | EVT_PAINT(wxWindow::OnPaint) | |
118 | EVT_NC_PAINT(wxWindow::OnNcPaint) | |
119 | EVT_ERASE_BACKGROUND(wxWindow::OnErase) | |
120 | END_EVENT_TABLE() | |
121 | ||
122 | // ---------------------------------------------------------------------------- | |
123 | // creation | |
124 | // ---------------------------------------------------------------------------- | |
125 | ||
126 | void wxWindow::Init() | |
127 | { | |
9a6384ca | 128 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
129 | m_scrollbarVert = |
130 | m_scrollbarHorz = (wxScrollBar *)NULL; | |
9a6384ca | 131 | #endif // wxUSE_SCROLLBAR |
1e6feb95 | 132 | |
a290fa5a | 133 | m_isCurrent = false; |
1e6feb95 VZ |
134 | |
135 | m_renderer = wxTheme::Get()->GetRenderer(); | |
2b5f62a0 | 136 | |
a290fa5a WS |
137 | m_oldSize.x = wxDefaultCoord; |
138 | m_oldSize.y = wxDefaultCoord; | |
1e6feb95 VZ |
139 | } |
140 | ||
141 | bool wxWindow::Create(wxWindow *parent, | |
142 | wxWindowID id, | |
143 | const wxPoint& pos, | |
144 | const wxSize& size, | |
145 | long style, | |
146 | const wxString& name) | |
147 | { | |
588cf92f | 148 | long actualStyle = style; |
8da1f9a9 | 149 | |
54e90b2a VS |
150 | // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW |
151 | // as under the other platforms | |
152 | actualStyle |= wxCLIP_CHILDREN; | |
153 | ||
588cf92f JS |
154 | actualStyle &= ~wxVSCROLL; |
155 | actualStyle &= ~wxHSCROLL; | |
54e90b2a | 156 | |
d743254a | 157 | #ifdef __WXMSW__ |
54e90b2a VS |
158 | // without this, borders (non-client areas in general) are not repainted |
159 | // correctly when resizing; apparently, native NC areas are fully repainted | |
160 | // even without this style by MSW, but wxUniv implements client area | |
161 | // itself, so it doesn't work correctly for us | |
162 | // | |
163 | // FIXME: this is very expensive, we need to fix the (commented-out) code | |
164 | // in OnSize() instead | |
165 | actualStyle |= wxFULL_REPAINT_ON_RESIZE; | |
8da1f9a9 VZ |
166 | #endif |
167 | ||
54e90b2a | 168 | if ( !wxWindowNative::Create(parent, id, pos, size, actualStyle, name) ) |
a290fa5a | 169 | return false; |
1e6feb95 | 170 | |
588cf92f JS |
171 | // Set full style again, including those we didn't want present |
172 | // when calling the base window Create(). | |
173 | wxWindowBase::SetWindowStyleFlag(style); | |
174 | ||
1cb853a8 JS |
175 | // if we allow or should always have a vertical scrollbar, make it |
176 | if ( style & wxVSCROLL || style & wxALWAYS_SHOW_SB ) | |
1e6feb95 | 177 | { |
ab6b6b15 | 178 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 179 | SetInsertIntoMain( true ); |
ab6b6b15 | 180 | #endif |
9a6384ca | 181 | #if wxUSE_SCROLLBAR |
c04c7a3d VS |
182 | m_scrollbarVert = new wxWindowScrollBar(this, wxID_ANY, |
183 | wxDefaultPosition, wxDefaultSize, | |
184 | wxSB_VERTICAL); | |
9a6384ca | 185 | #endif // wxUSE_SCROLLBAR |
ab6b6b15 | 186 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 187 | SetInsertIntoMain( false ); |
ab6b6b15 | 188 | #endif |
588cf92f | 189 | } |
1e6feb95 | 190 | |
1cb853a8 | 191 | // if we should allow a horizontal scrollbar, make it |
588cf92f JS |
192 | if ( style & wxHSCROLL ) |
193 | { | |
194 | #if wxUSE_TWO_WINDOWS | |
a290fa5a | 195 | SetInsertIntoMain( true ); |
588cf92f | 196 | #endif |
9a6384ca | 197 | #if wxUSE_SCROLLBAR |
c04c7a3d VS |
198 | m_scrollbarHorz = new wxWindowScrollBar(this, wxID_ANY, |
199 | wxDefaultPosition, wxDefaultSize, | |
200 | wxSB_HORIZONTAL); | |
9a6384ca | 201 | #endif // wxUSE_SCROLLBAR |
588cf92f | 202 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 203 | SetInsertIntoMain( false ); |
588cf92f JS |
204 | #endif |
205 | } | |
8da1f9a9 | 206 | |
9a6384ca | 207 | #if wxUSE_SCROLLBAR |
588cf92f JS |
208 | if (m_scrollbarHorz || m_scrollbarVert) |
209 | { | |
210 | // position it/them | |
1e6feb95 VZ |
211 | PositionScrollbars(); |
212 | } | |
9a6384ca | 213 | #endif // wxUSE_SCROLLBAR |
1e6feb95 | 214 | |
a290fa5a | 215 | return true; |
1e6feb95 VZ |
216 | } |
217 | ||
8da1f9a9 VZ |
218 | wxWindow::~wxWindow() |
219 | { | |
220 | m_isBeingDeleted = true; | |
221 | ||
478db4fc VS |
222 | #if wxUSE_SCROLLBAR |
223 | // clear pointers to scrollbar before deleting the children: they are | |
224 | // children and so will be deleted by DestroyChildren() call below and if | |
225 | // any code using the scrollbars would be called in the process or from | |
226 | // ~wxWindowBase, the app would crash: | |
227 | m_scrollbarVert = m_scrollbarHorz = NULL; | |
228 | #endif | |
229 | ||
8da1f9a9 VZ |
230 | // we have to destroy our children before we're destroyed because our |
231 | // children suppose that we're of type wxWindow, not just wxWindowNative, | |
232 | // and so bad things may happen if they're deleted from the base class dtor | |
233 | // as by then we're not a wxWindow any longer and wxUniv-specific virtual | |
234 | // functions can't be called | |
235 | DestroyChildren(); | |
236 | } | |
237 | ||
1e6feb95 VZ |
238 | // ---------------------------------------------------------------------------- |
239 | // background pixmap | |
240 | // ---------------------------------------------------------------------------- | |
241 | ||
242 | void wxWindow::SetBackground(const wxBitmap& bitmap, | |
243 | int alignment, | |
244 | wxStretch stretch) | |
245 | { | |
246 | m_bitmapBg = bitmap; | |
247 | m_alignBgBitmap = alignment; | |
248 | m_stretchBgBitmap = stretch; | |
249 | } | |
250 | ||
251 | const wxBitmap& wxWindow::GetBackgroundBitmap(int *alignment, | |
252 | wxStretch *stretch) const | |
253 | { | |
254 | if ( m_bitmapBg.Ok() ) | |
255 | { | |
256 | if ( alignment ) | |
257 | *alignment = m_alignBgBitmap; | |
258 | if ( stretch ) | |
259 | *stretch = m_stretchBgBitmap; | |
260 | } | |
261 | ||
262 | return m_bitmapBg; | |
263 | } | |
264 | ||
265 | // ---------------------------------------------------------------------------- | |
266 | // painting | |
267 | // ---------------------------------------------------------------------------- | |
268 | ||
1e6feb95 | 269 | // the event handlers executed when the window must be repainted |
3795cdba | 270 | void wxWindow::OnNcPaint(wxNcPaintEvent& WXUNUSED(event)) |
1e6feb95 VZ |
271 | { |
272 | if ( m_renderer ) | |
273 | { | |
274 | // get the window rect | |
9a6384ca | 275 | wxRect rect(GetSize()); |
1e6feb95 | 276 | |
9a6384ca | 277 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
278 | // if the scrollbars are outside the border, we must adjust the rect to |
279 | // exclude them | |
280 | if ( !m_renderer->AreScrollbarsInsideBorder() ) | |
281 | { | |
282 | wxScrollBar *scrollbar = GetScrollbar(wxVERTICAL); | |
283 | if ( scrollbar ) | |
284 | rect.width -= scrollbar->GetSize().x; | |
285 | ||
286 | scrollbar = GetScrollbar(wxHORIZONTAL); | |
287 | if ( scrollbar ) | |
288 | rect.height -= scrollbar->GetSize().y; | |
289 | } | |
9a6384ca | 290 | #endif // wxUSE_SCROLLBAR |
1e6feb95 VZ |
291 | |
292 | // get the DC and draw the border on it | |
293 | wxWindowDC dc(this); | |
294 | DoDrawBorder(dc, rect); | |
295 | } | |
296 | } | |
297 | ||
298 | void wxWindow::OnPaint(wxPaintEvent& event) | |
299 | { | |
300 | if ( !m_renderer ) | |
301 | { | |
302 | // it is a native control which paints itself | |
303 | event.Skip(); | |
304 | } | |
305 | else | |
306 | { | |
307 | // get the DC to use and create renderer on it | |
308 | wxPaintDC dc(this); | |
309 | wxControlRenderer renderer(this, dc, m_renderer); | |
310 | ||
311 | // draw the control | |
312 | DoDraw(&renderer); | |
313 | } | |
314 | } | |
315 | ||
5ebcf581 RR |
316 | // the event handler executed when the window background must be painted |
317 | void wxWindow::OnErase(wxEraseEvent& event) | |
318 | { | |
319 | if ( !m_renderer ) | |
320 | { | |
321 | event.Skip(); | |
322 | ||
323 | return; | |
324 | } | |
2b5f62a0 | 325 | |
5ebcf581 RR |
326 | DoDrawBackground(*event.GetDC()); |
327 | ||
9a6384ca | 328 | #if wxUSE_SCROLLBAR |
5ebcf581 RR |
329 | // if we have both scrollbars, we also have a square in the corner between |
330 | // them which we must paint | |
331 | if ( m_scrollbarVert && m_scrollbarHorz ) | |
332 | { | |
333 | wxSize size = GetSize(); | |
334 | wxRect rectClient = GetClientRect(), | |
335 | rectBorder = m_renderer->GetBorderDimensions(GetBorder()); | |
336 | ||
337 | wxRect rectCorner; | |
338 | rectCorner.x = rectClient.GetRight() + 1; | |
339 | rectCorner.y = rectClient.GetBottom() + 1; | |
340 | rectCorner.SetRight(size.x - rectBorder.width); | |
341 | rectCorner.SetBottom(size.y - rectBorder.height); | |
342 | ||
343 | if ( GetUpdateRegion().Contains(rectCorner) ) | |
344 | { | |
345 | m_renderer->DrawScrollCorner(*event.GetDC(), rectCorner); | |
346 | } | |
347 | } | |
9a6384ca | 348 | #endif // wxUSE_SCROLLBAR |
5ebcf581 RR |
349 | } |
350 | ||
1e6feb95 VZ |
351 | bool wxWindow::DoDrawBackground(wxDC& dc) |
352 | { | |
1e6feb95 | 353 | wxRect rect; |
2b5f62a0 | 354 | |
5ebcf581 RR |
355 | wxSize size = GetSize(); // Why not GetClientSize() ? |
356 | rect.x = 0; | |
357 | rect.y = 0; | |
358 | rect.width = size.x; | |
359 | rect.height = size.y; | |
2b5f62a0 VZ |
360 | |
361 | wxWindow * const parent = GetParent(); | |
3b6c95eb | 362 | if ( HasTransparentBackground() && !UseBgCol() && parent ) |
1e6feb95 | 363 | { |
5ebcf581 | 364 | wxASSERT( !IsTopLevel() ); |
2b5f62a0 | 365 | |
5ebcf581 | 366 | wxPoint pos = GetPosition(); |
2b5f62a0 | 367 | |
5ebcf581 | 368 | AdjustForParentClientOrigin( pos.x, pos.y, 0 ); |
2b5f62a0 | 369 | |
5ebcf581 | 370 | // Adjust DC logical origin |
635eb8bc JS |
371 | wxCoord org_x, org_y, x, y; |
372 | dc.GetLogicalOrigin( &org_x, &org_y ); | |
373 | x = org_x + pos.x; | |
374 | y = org_y + pos.y; | |
5ebcf581 | 375 | dc.SetLogicalOrigin( x, y ); |
2b5f62a0 | 376 | |
5ebcf581 RR |
377 | // Adjust draw rect |
378 | rect.x = pos.x; | |
379 | rect.y = pos.y; | |
2b5f62a0 | 380 | |
5ebcf581 | 381 | // Let parent draw the background |
2b5f62a0 | 382 | parent->EraseBackground( dc, rect ); |
635eb8bc JS |
383 | |
384 | // Restore DC logical origin | |
385 | dc.SetLogicalOrigin( org_x, org_y ); | |
1e6feb95 | 386 | } |
5ebcf581 RR |
387 | else |
388 | { | |
90e572f1 | 389 | // Draw background ourselves |
2b5f62a0 | 390 | EraseBackground( dc, rect ); |
5ebcf581 | 391 | } |
2b5f62a0 | 392 | |
a290fa5a | 393 | return true; |
5ebcf581 | 394 | } |
1e6feb95 | 395 | |
5ebcf581 RR |
396 | void wxWindow::EraseBackground(wxDC& dc, const wxRect& rect) |
397 | { | |
1e6feb95 VZ |
398 | if ( GetBackgroundBitmap().Ok() ) |
399 | { | |
5ebcf581 | 400 | // Get the bitmap and the flags |
1e6feb95 VZ |
401 | int alignment; |
402 | wxStretch stretch; | |
403 | wxBitmap bmp = GetBackgroundBitmap(&alignment, &stretch); | |
404 | wxControlRenderer::DrawBitmap(dc, bmp, rect, alignment, stretch); | |
405 | } | |
2b5f62a0 | 406 | else |
1e6feb95 | 407 | { |
5ebcf581 | 408 | // Just fill it with bg colour if no bitmap |
2b5f62a0 | 409 | |
1e6feb95 VZ |
410 | m_renderer->DrawBackground(dc, wxTHEME_BG_COLOUR(this), |
411 | rect, GetStateFlags()); | |
412 | } | |
1e6feb95 VZ |
413 | } |
414 | ||
415 | void wxWindow::DoDrawBorder(wxDC& dc, const wxRect& rect) | |
416 | { | |
417 | // draw outline unless the update region is enitrely inside it in which | |
418 | // case we don't need to do it | |
419 | #if 0 // doesn't seem to work, why? | |
420 | if ( wxRegion(rect).Contains(GetUpdateRegion().GetBox()) != wxInRegion ) | |
421 | #endif | |
422 | { | |
423 | m_renderer->DrawBorder(dc, GetBorder(), rect, GetStateFlags()); | |
424 | } | |
425 | } | |
426 | ||
61fef19b | 427 | void wxWindow::DoDraw(wxControlRenderer * WXUNUSED(renderer)) |
1e6feb95 VZ |
428 | { |
429 | } | |
430 | ||
6ef4b814 | 431 | void wxWindow::Refresh(bool eraseBackground, const wxRect *rect) |
1e6feb95 | 432 | { |
6ef4b814 VS |
433 | wxRect rectClient; // the same rectangle in client coordinates |
434 | wxPoint origin = GetClientAreaOrigin(); | |
1e6feb95 VZ |
435 | |
436 | wxSize size = GetClientSize(); | |
437 | ||
6ef4b814 | 438 | if ( rect ) |
1e6feb95 | 439 | { |
6ef4b814 VS |
440 | // the rectangle passed as argument is in client coordinates |
441 | rectClient = *rect; | |
1e6feb95 VZ |
442 | |
443 | // don't refresh anything beyond the client area (scrollbars for | |
444 | // example) | |
6ef4b814 VS |
445 | if ( rectClient.GetRight() > size.x ) |
446 | rectClient.SetRight(size.x); | |
447 | if ( rectClient.GetBottom() > size.y ) | |
448 | rectClient.SetBottom(size.y); | |
1e6feb95 | 449 | |
1e6feb95 VZ |
450 | } |
451 | else // refresh the entire client area | |
452 | { | |
6ef4b814 VS |
453 | // x,y is already set to 0 by default |
454 | rectClient.SetSize(size); | |
1e6feb95 VZ |
455 | } |
456 | ||
6ef4b814 VS |
457 | // convert refresh rectangle to window coordinates: |
458 | wxRect rectWin(rectClient); | |
459 | rectWin.Offset(origin); | |
460 | ||
1e6feb95 VZ |
461 | // debugging helper |
462 | #ifdef WXDEBUG_REFRESH | |
a290fa5a | 463 | static bool s_refreshDebug = false; |
1e6feb95 VZ |
464 | if ( s_refreshDebug ) |
465 | { | |
466 | wxWindowDC dc(this); | |
467 | dc.SetBrush(*wxCYAN_BRUSH); | |
468 | dc.SetPen(*wxTRANSPARENT_PEN); | |
469 | dc.DrawRectangle(rectWin); | |
470 | ||
471 | // under Unix we use "--sync" X option for this | |
8cb172b4 | 472 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
1e6feb95 VZ |
473 | ::GdiFlush(); |
474 | ::Sleep(200); | |
475 | #endif // __WXMSW__ | |
476 | } | |
477 | #endif // WXDEBUG_REFRESH | |
478 | ||
479 | wxWindowNative::Refresh(eraseBackground, &rectWin); | |
82e5f91b JS |
480 | |
481 | // Refresh all sub controls if any. | |
6ef4b814 VS |
482 | wxWindowList& children = GetChildren(); |
483 | for ( wxWindowList::iterator i = children.begin(); i != children.end(); ++i ) | |
82e5f91b | 484 | { |
6ef4b814 VS |
485 | wxWindow *child = *i; |
486 | // only refresh subcontrols if they are visible: | |
487 | if ( child->IsTopLevel() || !child->IsShown() || child->IsFrozen() ) | |
488 | continue; | |
489 | ||
490 | // ...and when the subcontrols are in the update region: | |
491 | wxRect childrect(child->GetRect()); | |
492 | childrect.Intersect(rectClient); | |
493 | if ( childrect.IsEmpty() ) | |
494 | continue; | |
495 | ||
496 | // refresh the subcontrol now: | |
497 | childrect.Offset(-child->GetPosition()); | |
498 | // NB: We must call wxWindowNative version because we need to refresh | |
499 | // the entire control, not just its client area, and this is why we | |
500 | // don't account for child client area origin here neither. Also | |
501 | // note that we don't pass eraseBackground to the child, but use | |
502 | // true instead: this is because we can't be sure that | |
503 | // eraseBackground=false is safe for children as well and not only | |
504 | // for the parent. | |
505 | child->wxWindowNative::Refresh(eraseBackground, &childrect); | |
82e5f91b | 506 | } |
1e6feb95 VZ |
507 | } |
508 | ||
509 | // ---------------------------------------------------------------------------- | |
510 | // state flags | |
511 | // ---------------------------------------------------------------------------- | |
512 | ||
513 | bool wxWindow::Enable(bool enable) | |
514 | { | |
515 | if ( !wxWindowNative::Enable(enable) ) | |
a290fa5a | 516 | return false; |
1e6feb95 VZ |
517 | |
518 | // disabled window can't keep focus | |
c4bcd8fc | 519 | if ( FindFocus() == this && GetParent() != NULL ) |
1e6feb95 VZ |
520 | { |
521 | GetParent()->SetFocus(); | |
522 | } | |
523 | ||
524 | if ( m_renderer ) | |
525 | { | |
526 | // a window with renderer is drawn by ourselves and it has to be | |
527 | // refreshed to reflect its new status | |
528 | Refresh(); | |
529 | } | |
530 | ||
a290fa5a | 531 | return true; |
1e6feb95 VZ |
532 | } |
533 | ||
534 | bool wxWindow::IsFocused() const | |
535 | { | |
5625d0d4 | 536 | return FindFocus() == this; |
1e6feb95 VZ |
537 | } |
538 | ||
539 | bool wxWindow::IsPressed() const | |
540 | { | |
a290fa5a | 541 | return false; |
1e6feb95 VZ |
542 | } |
543 | ||
544 | bool wxWindow::IsDefault() const | |
545 | { | |
a290fa5a | 546 | return false; |
1e6feb95 VZ |
547 | } |
548 | ||
549 | bool wxWindow::IsCurrent() const | |
550 | { | |
551 | return m_isCurrent; | |
552 | } | |
553 | ||
554 | bool wxWindow::SetCurrent(bool doit) | |
555 | { | |
556 | if ( doit == m_isCurrent ) | |
a290fa5a | 557 | return false; |
1e6feb95 VZ |
558 | |
559 | m_isCurrent = doit; | |
560 | ||
561 | if ( CanBeHighlighted() ) | |
562 | Refresh(); | |
563 | ||
a290fa5a | 564 | return true; |
1e6feb95 VZ |
565 | } |
566 | ||
567 | int wxWindow::GetStateFlags() const | |
568 | { | |
569 | int flags = 0; | |
570 | if ( !IsEnabled() ) | |
571 | flags |= wxCONTROL_DISABLED; | |
572 | ||
573 | // the following states are only possible if our application is active - if | |
574 | // it is not, even our default/focused controls shouldn't appear as such | |
575 | if ( wxTheApp->IsActive() ) | |
576 | { | |
577 | if ( IsCurrent() ) | |
578 | flags |= wxCONTROL_CURRENT; | |
579 | if ( IsFocused() ) | |
580 | flags |= wxCONTROL_FOCUSED; | |
581 | if ( IsPressed() ) | |
582 | flags |= wxCONTROL_PRESSED; | |
583 | if ( IsDefault() ) | |
584 | flags |= wxCONTROL_ISDEFAULT; | |
585 | } | |
586 | ||
587 | return flags; | |
588 | } | |
589 | ||
590 | // ---------------------------------------------------------------------------- | |
591 | // size | |
592 | // ---------------------------------------------------------------------------- | |
593 | ||
594 | void wxWindow::OnSize(wxSizeEvent& event) | |
595 | { | |
aae73669 | 596 | event.Skip(); |
2b5f62a0 | 597 | |
9a6384ca | 598 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
599 | if ( m_scrollbarVert || m_scrollbarHorz ) |
600 | { | |
601 | PositionScrollbars(); | |
602 | } | |
9a6384ca | 603 | #endif // wxUSE_SCROLLBAR |
2b5f62a0 | 604 | |
ab6b6b15 | 605 | #if 0 // ndef __WXMSW__ |
ec47a147 | 606 | // Refresh the area (strip) previously occupied by the border |
2b5f62a0 | 607 | |
e441e1f4 | 608 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) && IsShown() ) |
ec47a147 | 609 | { |
aae73669 RR |
610 | // This code assumes that wxSizeEvent.GetSize() returns |
611 | // the area of the entire window, not just the client | |
612 | // area. | |
ec47a147 | 613 | wxSize newSize = event.GetSize(); |
2b5f62a0 | 614 | |
a290fa5a | 615 | if (m_oldSize.x == wxDefaultCoord && m_oldSize.y == wxDefaultCoord) |
aae73669 RR |
616 | { |
617 | m_oldSize = newSize; | |
618 | return; | |
619 | } | |
2b5f62a0 | 620 | |
ec47a147 RR |
621 | if (HasFlag( wxSIMPLE_BORDER )) |
622 | { | |
623 | if (newSize.y > m_oldSize.y) | |
624 | { | |
625 | wxRect rect; | |
626 | rect.x = 0; | |
627 | rect.width = m_oldSize.x; | |
aae73669 | 628 | rect.y = m_oldSize.y-2; |
ec47a147 | 629 | rect.height = 1; |
a290fa5a | 630 | Refresh( true, &rect ); |
ec47a147 | 631 | } |
aae73669 RR |
632 | else if (newSize.y < m_oldSize.y) |
633 | { | |
634 | wxRect rect; | |
635 | rect.y = newSize.y; | |
636 | rect.x = 0; | |
637 | rect.height = 1; | |
638 | rect.width = newSize.x; | |
a290fa5a | 639 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 640 | } |
2b5f62a0 | 641 | |
ec47a147 RR |
642 | if (newSize.x > m_oldSize.x) |
643 | { | |
644 | wxRect rect; | |
645 | rect.y = 0; | |
646 | rect.height = m_oldSize.y; | |
aae73669 | 647 | rect.x = m_oldSize.x-2; |
ec47a147 | 648 | rect.width = 1; |
a290fa5a | 649 | Refresh( true, &rect ); |
ec47a147 | 650 | } |
aae73669 RR |
651 | else if (newSize.x < m_oldSize.x) |
652 | { | |
653 | wxRect rect; | |
654 | rect.x = newSize.x; | |
655 | rect.y = 0; | |
656 | rect.width = 1; | |
657 | rect.height = newSize.y; | |
a290fa5a | 658 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 659 | } |
ec47a147 RR |
660 | } |
661 | else | |
662 | if (HasFlag( wxSUNKEN_BORDER ) || HasFlag( wxRAISED_BORDER )) | |
663 | { | |
664 | if (newSize.y > m_oldSize.y) | |
665 | { | |
666 | wxRect rect; | |
667 | rect.x = 0; | |
668 | rect.width = m_oldSize.x; | |
aae73669 | 669 | rect.y = m_oldSize.y-4; |
ec47a147 | 670 | rect.height = 2; |
a290fa5a | 671 | Refresh( true, &rect ); |
ec47a147 | 672 | } |
aae73669 RR |
673 | else if (newSize.y < m_oldSize.y) |
674 | { | |
675 | wxRect rect; | |
676 | rect.y = newSize.y; | |
677 | rect.x = 0; | |
678 | rect.height = 2; | |
679 | rect.width = newSize.x; | |
a290fa5a | 680 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 681 | } |
2b5f62a0 | 682 | |
ec47a147 RR |
683 | if (newSize.x > m_oldSize.x) |
684 | { | |
685 | wxRect rect; | |
686 | rect.y = 0; | |
687 | rect.height = m_oldSize.y; | |
aae73669 | 688 | rect.x = m_oldSize.x-4; |
ec47a147 | 689 | rect.width = 2; |
a290fa5a | 690 | Refresh( true, &rect ); |
ec47a147 | 691 | } |
aae73669 RR |
692 | else if (newSize.x < m_oldSize.x) |
693 | { | |
694 | wxRect rect; | |
695 | rect.x = newSize.x; | |
696 | rect.y = 0; | |
697 | rect.width = 2; | |
698 | rect.height = newSize.y; | |
a290fa5a | 699 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 700 | } |
ec47a147 | 701 | } |
2b5f62a0 | 702 | |
ec47a147 RR |
703 | m_oldSize = newSize; |
704 | } | |
705 | #endif | |
1e6feb95 VZ |
706 | } |
707 | ||
708 | wxSize wxWindow::DoGetBestSize() const | |
709 | { | |
710 | return AdjustSize(DoGetBestClientSize()); | |
711 | } | |
712 | ||
713 | wxSize wxWindow::DoGetBestClientSize() const | |
714 | { | |
715 | return wxWindowNative::DoGetBestSize(); | |
716 | } | |
717 | ||
718 | wxSize wxWindow::AdjustSize(const wxSize& size) const | |
719 | { | |
720 | wxSize sz = size; | |
721 | if ( m_renderer ) | |
722 | m_renderer->AdjustSize(&sz, this); | |
723 | return sz; | |
724 | } | |
725 | ||
726 | wxPoint wxWindow::GetClientAreaOrigin() const | |
727 | { | |
728 | wxPoint pt = wxWindowBase::GetClientAreaOrigin(); | |
729 | ||
ab6b6b15 RR |
730 | #if wxUSE_TWO_WINDOWS |
731 | #else | |
1e6feb95 VZ |
732 | if ( m_renderer ) |
733 | pt += m_renderer->GetBorderDimensions(GetBorder()).GetPosition(); | |
ab6b6b15 | 734 | #endif |
1e6feb95 VZ |
735 | |
736 | return pt; | |
737 | } | |
738 | ||
739 | void wxWindow::DoGetClientSize(int *width, int *height) const | |
740 | { | |
3379ed37 VZ |
741 | // if it is a native window, we assume it handles the scrollbars itself |
742 | // too - and if it doesn't, there is not much we can do | |
743 | if ( !m_renderer ) | |
744 | { | |
745 | wxWindowNative::DoGetClientSize(width, height); | |
746 | ||
747 | return; | |
748 | } | |
749 | ||
1e6feb95 VZ |
750 | int w, h; |
751 | wxWindowNative::DoGetClientSize(&w, &h); | |
752 | ||
753 | // we assume that the scrollbars are positioned correctly (by a previous | |
754 | // call to PositionScrollbars()) here | |
755 | ||
756 | wxRect rectBorder; | |
757 | if ( m_renderer ) | |
758 | rectBorder = m_renderer->GetBorderDimensions(GetBorder()); | |
759 | ||
1e6feb95 VZ |
760 | if ( width ) |
761 | { | |
9a6384ca | 762 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
763 | // in any case, take account of the scrollbar |
764 | if ( m_scrollbarVert ) | |
765 | w -= m_scrollbarVert->GetSize().x; | |
9a6384ca | 766 | #endif // wxUSE_SCROLLBAR |
1e6feb95 | 767 | |
4eb124f5 VS |
768 | // account for the left and right borders |
769 | *width = w - rectBorder.x - rectBorder.width; | |
1e6feb95 VZ |
770 | |
771 | // we shouldn't return invalid width | |
772 | if ( *width < 0 ) | |
773 | *width = 0; | |
774 | } | |
775 | ||
776 | if ( height ) | |
777 | { | |
9a6384ca | 778 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
779 | if ( m_scrollbarHorz ) |
780 | h -= m_scrollbarHorz->GetSize().y; | |
9a6384ca | 781 | #endif // wxUSE_SCROLLBAR |
1e6feb95 | 782 | |
4eb124f5 | 783 | *height = h - rectBorder.y - rectBorder.height; |
1e6feb95 VZ |
784 | |
785 | // we shouldn't return invalid height | |
786 | if ( *height < 0 ) | |
787 | *height = 0; | |
788 | } | |
789 | } | |
790 | ||
791 | void wxWindow::DoSetClientSize(int width, int height) | |
792 | { | |
793 | // take into account the borders | |
794 | wxRect rectBorder = m_renderer->GetBorderDimensions(GetBorder()); | |
795 | width += rectBorder.x; | |
796 | height += rectBorder.y; | |
797 | ||
798 | // and the scrollbars (as they may be offset into the border, use the | |
799 | // scrollbar position, not size - this supposes that PositionScrollbars() | |
800 | // had been called before) | |
1e6feb95 | 801 | wxSize size = GetSize(); |
9a6384ca | 802 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
803 | if ( m_scrollbarVert ) |
804 | width += size.x - m_scrollbarVert->GetPosition().x; | |
9a6384ca | 805 | #endif // wxUSE_SCROLLBAR |
4eb124f5 | 806 | width += rectBorder.width; |
1e6feb95 | 807 | |
9a6384ca | 808 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
809 | if ( m_scrollbarHorz ) |
810 | height += size.y - m_scrollbarHorz->GetPosition().y; | |
9a6384ca | 811 | #endif // wxUSE_SCROLLBAR |
4eb124f5 | 812 | height += rectBorder.height; |
1e6feb95 VZ |
813 | |
814 | wxWindowNative::DoSetClientSize(width, height); | |
815 | } | |
816 | ||
817 | wxHitTest wxWindow::DoHitTest(wxCoord x, wxCoord y) const | |
818 | { | |
819 | wxHitTest ht = wxWindowNative::DoHitTest(x, y); | |
9a6384ca WS |
820 | |
821 | #if wxUSE_SCROLLBAR | |
1e6feb95 VZ |
822 | if ( ht == wxHT_WINDOW_INSIDE ) |
823 | { | |
824 | if ( m_scrollbarVert && x >= m_scrollbarVert->GetPosition().x ) | |
825 | { | |
826 | // it can still be changed below because it may also be the corner | |
827 | ht = wxHT_WINDOW_VERT_SCROLLBAR; | |
828 | } | |
829 | ||
830 | if ( m_scrollbarHorz && y >= m_scrollbarHorz->GetPosition().y ) | |
831 | { | |
832 | ht = ht == wxHT_WINDOW_VERT_SCROLLBAR ? wxHT_WINDOW_CORNER | |
833 | : wxHT_WINDOW_HORZ_SCROLLBAR; | |
834 | } | |
835 | } | |
9a6384ca | 836 | #endif // wxUSE_SCROLLBAR |
1e6feb95 VZ |
837 | |
838 | return ht; | |
839 | } | |
840 | ||
841 | // ---------------------------------------------------------------------------- | |
842 | // scrolling: we implement it entirely ourselves except for ScrollWindow() | |
843 | // function which is supposed to be (efficiently) implemented by the native | |
844 | // window class | |
845 | // ---------------------------------------------------------------------------- | |
846 | ||
847 | void wxWindow::RefreshScrollbars() | |
848 | { | |
9a6384ca | 849 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
850 | if ( m_scrollbarHorz ) |
851 | m_scrollbarHorz->Refresh(); | |
852 | ||
853 | if ( m_scrollbarVert ) | |
854 | m_scrollbarVert->Refresh(); | |
9a6384ca | 855 | #endif // wxUSE_SCROLLBAR |
1e6feb95 VZ |
856 | } |
857 | ||
858 | void wxWindow::PositionScrollbars() | |
859 | { | |
9a6384ca | 860 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
861 | // do not use GetClientSize/Rect as it relies on the scrollbars being |
862 | // correctly positioned | |
863 | ||
864 | wxSize size = GetSize(); | |
865 | wxBorder border = GetBorder(); | |
866 | wxRect rectBorder = m_renderer->GetBorderDimensions(border); | |
867 | bool inside = m_renderer->AreScrollbarsInsideBorder(); | |
868 | ||
869 | int height = m_scrollbarHorz ? m_scrollbarHorz->GetSize().y : 0; | |
870 | int width = m_scrollbarVert ? m_scrollbarVert->GetSize().x : 0; | |
871 | ||
872 | wxRect rectBar; | |
873 | if ( m_scrollbarVert ) | |
874 | { | |
875 | rectBar.x = size.x - width; | |
876 | if ( inside ) | |
877 | rectBar.x -= rectBorder.width; | |
878 | rectBar.width = width; | |
879 | rectBar.y = 0; | |
880 | if ( inside ) | |
881 | rectBar.y += rectBorder.y; | |
882 | rectBar.height = size.y - height; | |
883 | if ( inside ) | |
884 | rectBar.height -= rectBorder.y + rectBorder.height; | |
885 | ||
886 | m_scrollbarVert->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS); | |
887 | } | |
888 | ||
889 | if ( m_scrollbarHorz ) | |
890 | { | |
891 | rectBar.y = size.y - height; | |
892 | if ( inside ) | |
893 | rectBar.y -= rectBorder.height; | |
894 | rectBar.height = height; | |
895 | rectBar.x = 0; | |
896 | if ( inside ) | |
897 | rectBar.x += rectBorder.x; | |
898 | rectBar.width = size.x - width; | |
899 | if ( inside ) | |
900 | rectBar.width -= rectBorder.x + rectBorder.width; | |
901 | ||
902 | m_scrollbarHorz->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS); | |
903 | } | |
904 | ||
905 | RefreshScrollbars(); | |
9a6384ca | 906 | #endif // wxUSE_SCROLLBAR |
1e6feb95 VZ |
907 | } |
908 | ||
909 | void wxWindow::SetScrollbar(int orient, | |
910 | int pos, | |
911 | int pageSize, | |
912 | int range, | |
913 | bool refresh) | |
914 | { | |
9a6384ca | 915 | #if wxUSE_SCROLLBAR |
3f393e3d VZ |
916 | wxASSERT_MSG( pageSize <= range, |
917 | _T("page size can't be greater than range") ); | |
918 | ||
a290fa5a | 919 | bool hasClientSizeChanged = false; |
1e6feb95 | 920 | wxScrollBar *scrollbar = GetScrollbar(orient); |
3f393e3d | 921 | if ( range && (pageSize < range) ) |
1e6feb95 VZ |
922 | { |
923 | if ( !scrollbar ) | |
924 | { | |
925 | // create it | |
ab6b6b15 | 926 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 927 | SetInsertIntoMain( true ); |
ab6b6b15 | 928 | #endif |
c04c7a3d VS |
929 | scrollbar = new wxWindowScrollBar(this, wxID_ANY, |
930 | wxDefaultPosition, wxDefaultSize, | |
931 | orient & wxVERTICAL ? wxSB_VERTICAL | |
932 | : wxSB_HORIZONTAL); | |
ab6b6b15 | 933 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 934 | SetInsertIntoMain( false ); |
ab6b6b15 | 935 | #endif |
1e6feb95 VZ |
936 | if ( orient & wxVERTICAL ) |
937 | m_scrollbarVert = scrollbar; | |
938 | else | |
939 | m_scrollbarHorz = scrollbar; | |
940 | ||
941 | // the client area diminished as we created a scrollbar | |
a290fa5a | 942 | hasClientSizeChanged = true; |
1e6feb95 VZ |
943 | |
944 | PositionScrollbars(); | |
945 | } | |
946 | else if ( GetWindowStyle() & wxALWAYS_SHOW_SB ) | |
947 | { | |
948 | // we might have disabled it before | |
949 | scrollbar->Enable(); | |
950 | } | |
951 | ||
952 | scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh); | |
953 | } | |
954 | else // no range means no scrollbar | |
955 | { | |
956 | if ( scrollbar ) | |
957 | { | |
958 | // wxALWAYS_SHOW_SB only applies to the vertical scrollbar | |
959 | if ( (orient & wxVERTICAL) && (GetWindowStyle() & wxALWAYS_SHOW_SB) ) | |
960 | { | |
961 | // just disable the scrollbar | |
962 | scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh); | |
963 | scrollbar->Disable(); | |
964 | } | |
965 | else // really remove the scrollbar | |
966 | { | |
967 | delete scrollbar; | |
968 | ||
969 | if ( orient & wxVERTICAL ) | |
970 | m_scrollbarVert = NULL; | |
971 | else | |
972 | m_scrollbarHorz = NULL; | |
973 | ||
974 | // the client area increased as we removed a scrollbar | |
a290fa5a | 975 | hasClientSizeChanged = true; |
1e6feb95 VZ |
976 | |
977 | // the size of the remaining scrollbar must be adjusted | |
978 | if ( m_scrollbarHorz || m_scrollbarVert ) | |
979 | { | |
980 | PositionScrollbars(); | |
981 | } | |
982 | } | |
983 | } | |
984 | } | |
985 | ||
986 | // give the window a chance to relayout | |
987 | if ( hasClientSizeChanged ) | |
988 | { | |
a17a79ba RR |
989 | #if wxUSE_TWO_WINDOWS |
990 | wxWindowNative::SetSize( GetSize() ); | |
991 | #else | |
1e6feb95 VZ |
992 | wxSizeEvent event(GetSize()); |
993 | (void)GetEventHandler()->ProcessEvent(event); | |
a17a79ba | 994 | #endif |
1e6feb95 | 995 | } |
9a6384ca WS |
996 | #else |
997 | wxUnusedVar(orient); | |
998 | wxUnusedVar(pos); | |
999 | wxUnusedVar(pageSize); | |
1000 | wxUnusedVar(range); | |
1001 | wxUnusedVar(refresh); | |
1002 | #endif // wxUSE_SCROLLBAR | |
1e6feb95 VZ |
1003 | } |
1004 | ||
61fef19b | 1005 | void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
1e6feb95 | 1006 | { |
9a6384ca | 1007 | #if wxUSE_SCROLLBAR |
1e6feb95 | 1008 | wxScrollBar *scrollbar = GetScrollbar(orient); |
1e6feb95 | 1009 | |
45e13c7f JS |
1010 | if (scrollbar) |
1011 | scrollbar->SetThumbPosition(pos); | |
7d297414 VZ |
1012 | |
1013 | // VZ: I think we can safely ignore this as we always refresh it | |
1014 | // automatically whenever the value chanegs | |
1015 | #if 0 | |
1e6feb95 VZ |
1016 | if ( refresh ) |
1017 | Refresh(); | |
7d297414 | 1018 | #endif |
9a6384ca WS |
1019 | #else |
1020 | wxUnusedVar(orient); | |
1021 | wxUnusedVar(pos); | |
1022 | #endif // wxUSE_SCROLLBAR | |
1e6feb95 VZ |
1023 | } |
1024 | ||
1025 | int wxWindow::GetScrollPos(int orient) const | |
1026 | { | |
9a6384ca | 1027 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
1028 | wxScrollBar *scrollbar = GetScrollbar(orient); |
1029 | return scrollbar ? scrollbar->GetThumbPosition() : 0; | |
9a6384ca WS |
1030 | #else |
1031 | wxUnusedVar(orient); | |
1032 | return 0; | |
1033 | #endif // wxUSE_SCROLLBAR | |
1e6feb95 VZ |
1034 | } |
1035 | ||
1036 | int wxWindow::GetScrollThumb(int orient) const | |
1037 | { | |
9a6384ca | 1038 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
1039 | wxScrollBar *scrollbar = GetScrollbar(orient); |
1040 | return scrollbar ? scrollbar->GetThumbSize() : 0; | |
9a6384ca WS |
1041 | #else |
1042 | wxUnusedVar(orient); | |
1043 | return 0; | |
1044 | #endif // wxUSE_SCROLLBAR | |
1e6feb95 VZ |
1045 | } |
1046 | ||
1047 | int wxWindow::GetScrollRange(int orient) const | |
1048 | { | |
9a6384ca | 1049 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
1050 | wxScrollBar *scrollbar = GetScrollbar(orient); |
1051 | return scrollbar ? scrollbar->GetRange() : 0; | |
9a6384ca WS |
1052 | #else |
1053 | wxUnusedVar(orient); | |
1054 | return 0; | |
1055 | #endif // wxUSE_SCROLLBAR | |
1e6feb95 VZ |
1056 | } |
1057 | ||
1058 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) | |
1059 | { | |
66a58655 VS |
1060 | // use native scrolling when available and do it in generic way |
1061 | // otherwise: | |
4125131b RR |
1062 | #ifdef __WXX11__ |
1063 | ||
66a58655 | 1064 | wxWindowNative::ScrollWindow(dx, dy, rect); |
4125131b | 1065 | |
2b5f62a0 | 1066 | #else // !wxX11 |
4125131b | 1067 | |
1e6feb95 VZ |
1068 | // before scrolling it, ensure that we don't have any unpainted areas |
1069 | Update(); | |
1070 | ||
1071 | wxRect r; | |
1072 | ||
1073 | if ( dx ) | |
1074 | { | |
1075 | r = ScrollNoRefresh(dx, 0, rect); | |
a290fa5a | 1076 | Refresh(true /* erase bkgnd */, &r); |
1e6feb95 VZ |
1077 | } |
1078 | ||
1079 | if ( dy ) | |
1080 | { | |
1081 | r = ScrollNoRefresh(0, dy, rect); | |
a290fa5a | 1082 | Refresh(true /* erase bkgnd */, &r); |
1e6feb95 | 1083 | } |
2b5f62a0 VZ |
1084 | |
1085 | // scroll children accordingly: | |
66a58655 | 1086 | wxPoint offset(dx, dy); |
2b5f62a0 | 1087 | |
ac32ba44 | 1088 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
66a58655 VS |
1089 | node; node = node->GetNext()) |
1090 | { | |
1091 | wxWindow *child = node->GetData(); | |
9a6384ca | 1092 | #if wxUSE_SCROLLBAR |
1c9f1f4d VS |
1093 | if ( child == m_scrollbarVert || child == m_scrollbarHorz ) |
1094 | continue; | |
9a6384ca | 1095 | #endif // wxUSE_SCROLLBAR |
1c9f1f4d VS |
1096 | |
1097 | // VS: Scrolling children has non-trivial semantics. If rect=NULL then | |
2b5f62a0 | 1098 | // it is easy: we scroll all children. Otherwise it gets |
1c9f1f4d VS |
1099 | // complicated: |
1100 | // 1. if scrolling in one direction only, scroll only | |
1101 | // those children that intersect shaft defined by the rectangle | |
1102 | // and scrolling direction | |
1103 | // 2. if scrolling in both axes, scroll all children | |
2b5f62a0 | 1104 | |
6a6e2822 VS |
1105 | bool shouldMove = false; |
1106 | ||
1c9f1f4d VS |
1107 | if ( rect && (dx * dy == 0 /* moving in only one of x, y axis */) ) |
1108 | { | |
1109 | wxRect childRect = child->GetRect(); | |
1110 | if ( dx == 0 && (childRect.GetLeft() <= rect->GetRight() || | |
1111 | childRect.GetRight() >= rect->GetLeft()) ) | |
1112 | { | |
6a6e2822 | 1113 | shouldMove = true; |
1c9f1f4d VS |
1114 | } |
1115 | else if ( dy == 0 && (childRect.GetTop() <= rect->GetBottom() || | |
1116 | childRect.GetBottom() >= rect->GetTop()) ) | |
1117 | { | |
6a6e2822 | 1118 | shouldMove = true; |
1c9f1f4d | 1119 | } |
6a6e2822 | 1120 | // else: child outside of scrolling shaft, don't move |
1c9f1f4d | 1121 | } |
6a6e2822 | 1122 | else // scrolling in both axes or rect=NULL |
66a58655 | 1123 | { |
6a6e2822 | 1124 | shouldMove = true; |
66a58655 | 1125 | } |
6a6e2822 VS |
1126 | |
1127 | if ( shouldMove ) | |
1128 | child->Move(child->GetPosition() + offset, wxSIZE_ALLOW_MINUS_ONE); | |
2b5f62a0 VZ |
1129 | } |
1130 | #endif // wxX11/!wxX11 | |
1e6feb95 VZ |
1131 | } |
1132 | ||
1133 | wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal) | |
1134 | { | |
1135 | wxASSERT_MSG( !dx || !dy, _T("can't be used for diag scrolling") ); | |
1136 | ||
1137 | // the rect to refresh (which we will calculate) | |
1138 | wxRect rect; | |
1139 | ||
1140 | if ( !dx && !dy ) | |
1141 | { | |
1142 | // nothing to do | |
1143 | return rect; | |
1144 | } | |
1145 | ||
1146 | // calculate the part of the window which we can just redraw in the new | |
1147 | // location | |
1148 | wxSize sizeTotal = rectTotal ? rectTotal->GetSize() : GetClientSize(); | |
1149 | ||
1150 | wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"), | |
1151 | sizeTotal.x, sizeTotal.y, dx, dy); | |
1152 | ||
1153 | // the initial and end point of the region we move in client coords | |
1154 | wxPoint ptSource, ptDest; | |
1155 | if ( rectTotal ) | |
1156 | { | |
1157 | ptSource = rectTotal->GetPosition(); | |
1158 | ptDest = rectTotal->GetPosition(); | |
1159 | } | |
1160 | ||
1161 | // the size of this region | |
1162 | wxSize size; | |
1163 | size.x = sizeTotal.x - abs(dx); | |
1164 | size.y = sizeTotal.y - abs(dy); | |
1165 | if ( size.x <= 0 || size.y <= 0 ) | |
1166 | { | |
1167 | // just redraw everything as nothing of the displayed image will stay | |
1168 | wxLogTrace(_T("scroll"), _T("refreshing everything")); | |
1169 | ||
1170 | rect = rectTotal ? *rectTotal : wxRect(0, 0, sizeTotal.x, sizeTotal.y); | |
1171 | } | |
1172 | else // move the part which doesn't change to the new location | |
1173 | { | |
1174 | // note that when we scroll the canvas in some direction we move the | |
1175 | // block which doesn't need to be refreshed in the opposite direction | |
1176 | ||
1177 | if ( dx < 0 ) | |
1178 | { | |
1179 | // scroll to the right, move to the left | |
1180 | ptSource.x -= dx; | |
1181 | } | |
1182 | else | |
1183 | { | |
1184 | // scroll to the left, move to the right | |
1185 | ptDest.x += dx; | |
1186 | } | |
1187 | ||
1188 | if ( dy < 0 ) | |
1189 | { | |
1190 | // scroll down, move up | |
1191 | ptSource.y -= dy; | |
1192 | } | |
1193 | else | |
1194 | { | |
1195 | // scroll up, move down | |
1196 | ptDest.y += dy; | |
1197 | } | |
1198 | ||
1199 | #if wxUSE_CARET | |
1200 | // we need to hide the caret before moving or it will erase itself at | |
1201 | // the wrong (old) location | |
1202 | wxCaret *caret = GetCaret(); | |
1203 | if ( caret ) | |
1204 | caret->Hide(); | |
1205 | #endif // wxUSE_CARET | |
1206 | ||
1207 | // do move | |
1208 | wxClientDC dc(this); | |
1209 | wxBitmap bmp(size.x, size.y); | |
1210 | wxMemoryDC dcMem; | |
1211 | dcMem.SelectObject(bmp); | |
1212 | ||
c47addef | 1213 | dcMem.Blit(wxPoint(0,0), size, &dc, ptSource |
03147cd0 | 1214 | #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT) |
1e6feb95 VZ |
1215 | + GetClientAreaOrigin() |
1216 | #endif // broken wxGTK wxDC::Blit | |
1217 | ); | |
c47addef | 1218 | dc.Blit(ptDest, size, &dcMem, wxPoint(0,0)); |
1e6feb95 VZ |
1219 | |
1220 | wxLogTrace(_T("scroll"), | |
1221 | _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"), | |
1222 | ptSource.x, ptSource.y, | |
1223 | size.x, size.y, | |
1224 | ptDest.x, ptDest.y); | |
1225 | ||
1226 | // and now repaint the uncovered area | |
1227 | ||
1228 | // FIXME: We repaint the intersection of these rectangles twice - is | |
1229 | // it bad? I don't think so as it is rare to scroll the window | |
1230 | // diagonally anyhow and so adding extra logic to compute | |
1231 | // rectangle intersection is probably not worth the effort | |
1232 | ||
1233 | rect.x = ptSource.x; | |
1234 | rect.y = ptSource.y; | |
1235 | ||
1236 | if ( dx ) | |
1237 | { | |
1238 | if ( dx < 0 ) | |
1239 | { | |
1240 | // refresh the area along the right border | |
1241 | rect.x += size.x + dx; | |
1242 | rect.width = -dx; | |
1243 | } | |
1244 | else | |
1245 | { | |
1246 | // refresh the area along the left border | |
1247 | rect.width = dx; | |
1248 | } | |
1249 | ||
1250 | rect.height = sizeTotal.y; | |
1251 | ||
1252 | wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"), | |
1253 | rect.x, rect.y, | |
1254 | rect.GetRight() + 1, rect.GetBottom() + 1); | |
1255 | } | |
1256 | ||
1257 | if ( dy ) | |
1258 | { | |
1259 | if ( dy < 0 ) | |
1260 | { | |
1261 | // refresh the area along the bottom border | |
1262 | rect.y += size.y + dy; | |
1263 | rect.height = -dy; | |
1264 | } | |
1265 | else | |
1266 | { | |
1267 | // refresh the area along the top border | |
1268 | rect.height = dy; | |
1269 | } | |
1270 | ||
1271 | rect.width = sizeTotal.x; | |
1272 | ||
1273 | wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"), | |
1274 | rect.x, rect.y, | |
1275 | rect.GetRight() + 1, rect.GetBottom() + 1); | |
1276 | } | |
1277 | ||
1278 | #if wxUSE_CARET | |
1279 | if ( caret ) | |
1280 | caret->Show(); | |
1281 | #endif // wxUSE_CARET | |
1282 | } | |
1283 | ||
1284 | return rect; | |
1285 | } | |
1286 | ||
1e6feb95 VZ |
1287 | // ---------------------------------------------------------------------------- |
1288 | // accelerators and menu hot keys | |
1289 | // ---------------------------------------------------------------------------- | |
1290 | ||
1291 | #if wxUSE_MENUS | |
1292 | // the last window over which Alt was pressed (used by OnKeyUp) | |
1293 | wxWindow *wxWindow::ms_winLastAltPress = NULL; | |
1294 | #endif // wxUSE_MENUS | |
1295 | ||
1296 | #if wxUSE_ACCEL || wxUSE_MENUS | |
1297 | ||
1298 | void wxWindow::OnKeyDown(wxKeyEvent& event) | |
1299 | { | |
1300 | #if wxUSE_MENUS | |
1301 | int key = event.GetKeyCode(); | |
f52c3131 | 1302 | if ( !event.ControlDown() && (key == WXK_ALT || key == WXK_F10) ) |
1e6feb95 VZ |
1303 | { |
1304 | ms_winLastAltPress = this; | |
1305 | ||
1306 | // it can't be an accel anyhow | |
1307 | return; | |
1308 | } | |
1309 | ||
1310 | ms_winLastAltPress = NULL; | |
1311 | #endif // wxUSE_MENUS | |
1312 | ||
1313 | #if wxUSE_ACCEL | |
1314 | for ( wxWindow *win = this; win; win = win->GetParent() ) | |
1315 | { | |
1316 | int command = win->GetAcceleratorTable()->GetCommand(event); | |
1317 | if ( command != -1 ) | |
1318 | { | |
1319 | wxCommandEvent eventCmd(wxEVT_COMMAND_MENU_SELECTED, command); | |
1320 | if ( win->GetEventHandler()->ProcessEvent(eventCmd) ) | |
1321 | { | |
1322 | // skip "event.Skip()" below | |
1323 | return; | |
1324 | } | |
1325 | } | |
1326 | ||
1327 | if ( win->IsTopLevel() ) | |
1328 | { | |
1329 | // try the frame menu bar | |
1330 | #if wxUSE_MENUS | |
1331 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
1332 | if ( frame ) | |
1333 | { | |
1334 | wxMenuBar *menubar = frame->GetMenuBar(); | |
1335 | if ( menubar && menubar->ProcessAccelEvent(event) ) | |
1336 | { | |
1337 | // skip "event.Skip()" below | |
1338 | return; | |
1339 | } | |
1340 | } | |
1341 | #endif // wxUSE_MENUS | |
1342 | ||
2c4eefc0 | 1343 | #if wxUSE_BUTTON |
81762e79 VS |
1344 | // if it wasn't in a menu, try to find a button |
1345 | if ( command != -1 ) | |
1346 | { | |
1347 | wxWindow* child = win->FindWindow(command); | |
1348 | if ( child && wxDynamicCast(child, wxButton) ) | |
1349 | { | |
1350 | wxCommandEvent eventCmd(wxEVT_COMMAND_BUTTON_CLICKED, command); | |
1351 | eventCmd.SetEventObject(child); | |
1352 | if ( child->GetEventHandler()->ProcessEvent(eventCmd) ) | |
1353 | { | |
1354 | // skip "event.Skip()" below | |
1355 | return; | |
1356 | } | |
1357 | } | |
1358 | } | |
2c4eefc0 | 1359 | #endif // wxUSE_BUTTON |
81762e79 | 1360 | |
1e6feb95 VZ |
1361 | // don't propagate accels from the child frame to the parent one |
1362 | break; | |
1363 | } | |
1364 | } | |
1365 | #endif // wxUSE_ACCEL | |
1366 | ||
1367 | event.Skip(); | |
1368 | } | |
1369 | ||
1370 | #endif // wxUSE_ACCEL | |
1371 | ||
1372 | #if wxUSE_MENUS | |
1373 | ||
1374 | wxMenuBar *wxWindow::GetParentFrameMenuBar() const | |
1375 | { | |
1376 | for ( const wxWindow *win = this; win; win = win->GetParent() ) | |
1377 | { | |
1378 | if ( win->IsTopLevel() ) | |
1379 | { | |
1380 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
1381 | if ( frame ) | |
1382 | { | |
1383 | return frame->GetMenuBar(); | |
1384 | } | |
1385 | ||
1386 | // don't look further - we don't want to return the menubar of the | |
1387 | // parent frame | |
1388 | break; | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | return NULL; | |
1393 | } | |
1394 | ||
1395 | void wxWindow::OnChar(wxKeyEvent& event) | |
1396 | { | |
1397 | if ( event.AltDown() && !event.ControlDown() ) | |
1398 | { | |
1399 | int key = event.GetKeyCode(); | |
1400 | ||
1401 | wxMenuBar *menubar = GetParentFrameMenuBar(); | |
1402 | if ( menubar ) | |
1403 | { | |
1404 | int item = menubar->FindNextItemForAccel(-1, key); | |
1405 | if ( item != -1 ) | |
1406 | { | |
1407 | menubar->PopupMenu((size_t)item); | |
1408 | ||
1409 | // skip "event.Skip()" below | |
1410 | return; | |
1411 | } | |
1412 | } | |
1413 | } | |
1414 | ||
28117f24 VZ |
1415 | // if Return was pressed, see if there's a default button to activate |
1416 | if ( !event.HasModifiers() && event.GetKeyCode() == WXK_RETURN ) | |
1417 | { | |
1418 | wxTopLevelWindow * | |
346d8899 | 1419 | tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); |
28117f24 VZ |
1420 | if ( tlw ) |
1421 | { | |
346d8899 | 1422 | wxButton *btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton); |
28117f24 VZ |
1423 | if ( btn ) |
1424 | { | |
1425 | wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, btn->GetId()); | |
1426 | evt.SetEventObject(btn); | |
1427 | btn->Command(evt); | |
1428 | return; | |
1429 | } | |
1430 | } | |
1431 | } | |
1432 | ||
1433 | ||
1e6feb95 VZ |
1434 | event.Skip(); |
1435 | } | |
1436 | ||
1437 | void wxWindow::OnKeyUp(wxKeyEvent& event) | |
1438 | { | |
1439 | int key = event.GetKeyCode(); | |
f52c3131 | 1440 | if ( !event.HasModifiers() && (key == WXK_ALT || key == WXK_F10) ) |
1e6feb95 VZ |
1441 | { |
1442 | // only process Alt release specially if there were no other key | |
1443 | // presses since Alt had been pressed and if both events happened in | |
1444 | // the same window | |
1445 | if ( ms_winLastAltPress == this ) | |
1446 | { | |
1447 | wxMenuBar *menubar = GetParentFrameMenuBar(); | |
1448 | if ( menubar && this != menubar ) | |
1449 | { | |
1450 | menubar->SelectMenu(0); | |
1451 | } | |
1452 | } | |
1453 | } | |
1454 | else | |
1455 | { | |
1456 | event.Skip(); | |
1457 | } | |
1458 | ||
1459 | // in any case reset it | |
1460 | ms_winLastAltPress = NULL; | |
1461 | } | |
1462 | ||
1463 | #endif // wxUSE_MENUS | |
1464 | ||
30827629 VZ |
1465 | // ---------------------------------------------------------------------------- |
1466 | // MSW-specific section | |
1467 | // ---------------------------------------------------------------------------- | |
1468 | ||
1469 | #ifdef __WXMSW__ | |
1470 | ||
1471 | #include "wx/msw/private.h" | |
1472 | ||
c140b7e7 | 1473 | WXLRESULT wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
30827629 VZ |
1474 | { |
1475 | if ( message == WM_NCHITTEST ) | |
1476 | { | |
1477 | // the windows which contain the other windows should let the mouse | |
1478 | // events through, otherwise a window inside a static box would | |
1479 | // never get any events at all | |
1480 | if ( IsStaticBox() ) | |
1481 | { | |
1482 | return HTTRANSPARENT; | |
1483 | } | |
1484 | } | |
1485 | ||
1486 | return wxWindowNative::MSWWindowProc(message, wParam, lParam); | |
1487 | } | |
1488 | ||
1489 | #endif // __WXMSW__ |