]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | // Name: univ/themes/win32.cpp |
2 | // Purpose: wxUniversal theme implementing Win32-like LNF | |
3 | // Author: Vadim Zeitlin | |
4 | // Modified by: | |
5 | // Created: 06.08.00 | |
6 | // RCS-ID: $Id$ | |
442b35b5 | 7 | // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) |
1e6feb95 VZ |
8 | // Licence: wxWindows license |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // =========================================================================== | |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | // For compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/timer.h" | |
28 | #include "wx/intl.h" | |
29 | #include "wx/dc.h" | |
30 | #include "wx/window.h" | |
31 | ||
32 | #include "wx/dcmemory.h" | |
33 | ||
34 | #include "wx/button.h" | |
35 | #include "wx/listbox.h" | |
36 | #include "wx/checklst.h" | |
8cb172b4 | 37 | #include "wx/combobox.h" |
1e6feb95 VZ |
38 | #include "wx/scrolbar.h" |
39 | #include "wx/slider.h" | |
40 | #include "wx/textctrl.h" | |
b72a54d1 MB |
41 | |
42 | #ifdef __WXMSW__ | |
43 | // for COLOR_* constants | |
44 | #include "wx/msw/private.h" | |
45 | #endif | |
1e6feb95 VZ |
46 | #endif // WX_PRECOMP |
47 | ||
48 | #include "wx/notebook.h" | |
49 | #include "wx/spinbutt.h" | |
8cb172b4 | 50 | #include "wx/settings.h" |
8a46f9b1 | 51 | #include "wx/menu.h" |
1e6feb95 VZ |
52 | |
53 | #include "wx/univ/scrtimer.h" | |
24a23c35 | 54 | #include "wx/toplevel.h" |
1e6feb95 VZ |
55 | #include "wx/univ/renderer.h" |
56 | #include "wx/univ/inphand.h" | |
57 | #include "wx/univ/colschem.h" | |
58 | #include "wx/univ/theme.h" | |
59 | ||
60 | // ---------------------------------------------------------------------------- | |
61 | // constants | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | static const int BORDER_THICKNESS = 2; | |
65 | ||
66 | // the offset between the label and focus rect around it | |
67 | static const int FOCUS_RECT_OFFSET_X = 1; | |
68 | static const int FOCUS_RECT_OFFSET_Y = 1; | |
69 | ||
24a23c35 VS |
70 | static const int FRAME_BORDER_THICKNESS = 3; |
71 | static const int RESIZEABLE_FRAME_BORDER_THICKNESS = 4; | |
72 | static const int FRAME_TITLEBAR_HEIGHT = 18; | |
73 | static const int FRAME_BUTTON_WIDTH = 16; | |
74 | static const int FRAME_BUTTON_HEIGHT = 14; | |
75 | ||
71e03035 VZ |
76 | static const size_t NUM_STATUSBAR_GRIP_BANDS = 3; |
77 | static const size_t WIDTH_STATUSBAR_GRIP_BAND = 4; | |
78 | static const size_t STATUSBAR_GRIP_SIZE = | |
79 | WIDTH_STATUSBAR_GRIP_BAND*NUM_STATUSBAR_GRIP_BANDS; | |
80 | ||
1e6feb95 VZ |
81 | enum IndicatorType |
82 | { | |
83 | IndicatorType_Check, | |
84 | IndicatorType_Radio, | |
85 | IndicatorType_Menu, | |
86 | IndicatorType_Max | |
87 | }; | |
88 | ||
89 | enum IndicatorState | |
90 | { | |
91 | IndicatorState_Normal, | |
92 | IndicatorState_Pressed, // this one is for check/radioboxes | |
93 | IndicatorState_Selected = IndicatorState_Pressed, // for menus | |
94 | IndicatorState_Disabled, | |
95 | IndicatorState_SelectedDisabled, // only for the menus | |
96 | IndicatorState_Max | |
97 | }; | |
98 | ||
99 | enum IndicatorStatus | |
100 | { | |
101 | IndicatorStatus_Checked, | |
102 | IndicatorStatus_Unchecked, | |
103 | IndicatorStatus_Max | |
104 | }; | |
105 | ||
1e6feb95 VZ |
106 | // wxWin32Renderer: draw the GUI elements in Win32 style |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
109 | class wxWin32Renderer : public wxRenderer | |
110 | { | |
111 | public: | |
112 | // constants | |
113 | enum wxArrowDirection | |
114 | { | |
115 | Arrow_Left, | |
116 | Arrow_Right, | |
117 | Arrow_Up, | |
118 | Arrow_Down, | |
119 | Arrow_Max | |
120 | }; | |
121 | ||
122 | enum wxArrowStyle | |
123 | { | |
124 | Arrow_Normal, | |
125 | Arrow_Disabled, | |
126 | Arrow_Pressed, | |
127 | Arrow_Inversed, | |
128 | Arrow_InversedDisabled, | |
129 | Arrow_StateMax | |
130 | }; | |
131 | ||
24a23c35 VS |
132 | enum wxFrameButtonType |
133 | { | |
134 | FrameButton_Close, | |
135 | FrameButton_Minimize, | |
136 | FrameButton_Maximize, | |
137 | FrameButton_Restore, | |
138 | FrameButton_Help, | |
139 | FrameButton_Max | |
140 | }; | |
141 | ||
1e6feb95 VZ |
142 | // ctor |
143 | wxWin32Renderer(const wxColourScheme *scheme); | |
144 | ||
145 | // implement the base class pure virtuals | |
146 | virtual void DrawBackground(wxDC& dc, | |
147 | const wxColour& col, | |
148 | const wxRect& rect, | |
149 | int flags = 0); | |
150 | virtual void DrawLabel(wxDC& dc, | |
151 | const wxString& label, | |
152 | const wxRect& rect, | |
153 | int flags = 0, | |
154 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
155 | int indexAccel = -1, | |
156 | wxRect *rectBounds = NULL); | |
157 | virtual void DrawButtonLabel(wxDC& dc, | |
158 | const wxString& label, | |
159 | const wxBitmap& image, | |
160 | const wxRect& rect, | |
161 | int flags = 0, | |
162 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
163 | int indexAccel = -1, | |
164 | wxRect *rectBounds = NULL); | |
165 | virtual void DrawBorder(wxDC& dc, | |
166 | wxBorder border, | |
167 | const wxRect& rect, | |
168 | int flags = 0, | |
169 | wxRect *rectIn = (wxRect *)NULL); | |
170 | virtual void DrawHorizontalLine(wxDC& dc, | |
171 | wxCoord y, wxCoord x1, wxCoord x2); | |
172 | virtual void DrawVerticalLine(wxDC& dc, | |
173 | wxCoord x, wxCoord y1, wxCoord y2); | |
174 | virtual void DrawFrame(wxDC& dc, | |
175 | const wxString& label, | |
176 | const wxRect& rect, | |
177 | int flags = 0, | |
178 | int alignment = wxALIGN_LEFT, | |
179 | int indexAccel = -1); | |
180 | virtual void DrawTextBorder(wxDC& dc, | |
181 | wxBorder border, | |
182 | const wxRect& rect, | |
183 | int flags = 0, | |
184 | wxRect *rectIn = (wxRect *)NULL); | |
185 | virtual void DrawButtonBorder(wxDC& dc, | |
186 | const wxRect& rect, | |
187 | int flags = 0, | |
188 | wxRect *rectIn = (wxRect *)NULL); | |
189 | virtual void DrawArrow(wxDC& dc, | |
190 | wxDirection dir, | |
191 | const wxRect& rect, | |
192 | int flags = 0); | |
193 | virtual void DrawScrollbarArrow(wxDC& dc, | |
194 | wxDirection dir, | |
195 | const wxRect& rect, | |
196 | int flags = 0) | |
197 | { DrawArrow(dc, dir, rect, flags); } | |
198 | virtual void DrawScrollbarThumb(wxDC& dc, | |
199 | wxOrientation orient, | |
200 | const wxRect& rect, | |
201 | int flags = 0); | |
202 | virtual void DrawScrollbarShaft(wxDC& dc, | |
203 | wxOrientation orient, | |
204 | const wxRect& rect, | |
205 | int flags = 0); | |
206 | virtual void DrawScrollCorner(wxDC& dc, | |
207 | const wxRect& rect); | |
208 | virtual void DrawItem(wxDC& dc, | |
209 | const wxString& label, | |
210 | const wxRect& rect, | |
211 | int flags = 0); | |
212 | virtual void DrawCheckItem(wxDC& dc, | |
213 | const wxString& label, | |
214 | const wxBitmap& bitmap, | |
215 | const wxRect& rect, | |
216 | int flags = 0); | |
217 | virtual void DrawCheckButton(wxDC& dc, | |
218 | const wxString& label, | |
219 | const wxBitmap& bitmap, | |
220 | const wxRect& rect, | |
221 | int flags = 0, | |
222 | wxAlignment align = wxALIGN_LEFT, | |
223 | int indexAccel = -1); | |
224 | virtual void DrawRadioButton(wxDC& dc, | |
225 | const wxString& label, | |
226 | const wxBitmap& bitmap, | |
227 | const wxRect& rect, | |
228 | int flags = 0, | |
229 | wxAlignment align = wxALIGN_LEFT, | |
230 | int indexAccel = -1); | |
231 | virtual void DrawTextLine(wxDC& dc, | |
232 | const wxString& text, | |
233 | const wxRect& rect, | |
234 | int selStart = -1, | |
235 | int selEnd = -1, | |
236 | int flags = 0); | |
237 | virtual void DrawLineWrapMark(wxDC& dc, const wxRect& rect); | |
238 | virtual void DrawTab(wxDC& dc, | |
239 | const wxRect& rect, | |
240 | wxDirection dir, | |
241 | const wxString& label, | |
242 | const wxBitmap& bitmap = wxNullBitmap, | |
243 | int flags = 0, | |
244 | int indexAccel = -1); | |
245 | ||
246 | virtual void DrawSliderShaft(wxDC& dc, | |
247 | const wxRect& rect, | |
248 | wxOrientation orient, | |
249 | int flags = 0, | |
250 | wxRect *rectShaft = NULL); | |
251 | virtual void DrawSliderThumb(wxDC& dc, | |
252 | const wxRect& rect, | |
253 | wxOrientation orient, | |
254 | int flags = 0); | |
255 | virtual void DrawSliderTicks(wxDC& dc, | |
256 | const wxRect& rect, | |
257 | const wxSize& sizeThumb, | |
258 | wxOrientation orient, | |
259 | int start, | |
260 | int end, | |
261 | int step = 1, | |
262 | int flags = 0); | |
263 | ||
264 | virtual void DrawMenuBarItem(wxDC& dc, | |
265 | const wxRect& rect, | |
266 | const wxString& label, | |
267 | int flags = 0, | |
268 | int indexAccel = -1); | |
269 | virtual void DrawMenuItem(wxDC& dc, | |
270 | wxCoord y, | |
271 | const wxMenuGeometryInfo& geometryInfo, | |
272 | const wxString& label, | |
273 | const wxString& accel, | |
274 | const wxBitmap& bitmap = wxNullBitmap, | |
275 | int flags = 0, | |
276 | int indexAccel = -1); | |
277 | virtual void DrawMenuSeparator(wxDC& dc, | |
278 | wxCoord y, | |
279 | const wxMenuGeometryInfo& geomInfo); | |
71e03035 VZ |
280 | |
281 | virtual void DrawStatusField(wxDC& dc, | |
282 | const wxRect& rect, | |
283 | const wxString& label, | |
284 | int flags = 0); | |
285 | ||
24a23c35 VS |
286 | // titlebars |
287 | virtual void DrawFrameTitleBar(wxDC& dc, | |
288 | const wxRect& rect, | |
289 | const wxString& title, | |
290 | const wxIcon& icon, | |
291 | int flags, | |
813edf09 VS |
292 | int specialButton = 0, |
293 | int specialButtonFlags = 0); | |
24a23c35 VS |
294 | virtual void DrawFrameBorder(wxDC& dc, |
295 | const wxRect& rect, | |
296 | int flags); | |
297 | virtual void DrawFrameBackground(wxDC& dc, | |
298 | const wxRect& rect, | |
299 | int flags); | |
300 | virtual void DrawFrameTitle(wxDC& dc, | |
301 | const wxRect& rect, | |
302 | const wxString& title, | |
303 | int flags); | |
304 | virtual void DrawFrameIcon(wxDC& dc, | |
305 | const wxRect& rect, | |
306 | const wxIcon& icon, | |
307 | int flags); | |
308 | virtual void DrawFrameButton(wxDC& dc, | |
309 | wxCoord x, wxCoord y, | |
310 | int button, | |
311 | int flags = 0); | |
312 | virtual wxRect GetFrameClientArea(const wxRect& rect, int flags) const; | |
313 | virtual wxSize GetFrameTotalSize(const wxSize& clientSize, int flags) const; | |
314 | virtual wxSize GetFrameIconSize() const; | |
813edf09 | 315 | virtual int HitTestFrame(const wxRect& rect, const wxPoint& pt, int flags) const; |
24a23c35 | 316 | |
63f06c22 VS |
317 | virtual wxIcon GetStdIcon(int which) const; |
318 | ||
1e6feb95 | 319 | virtual void GetComboBitmaps(wxBitmap *bmpNormal, |
1b465102 | 320 | wxBitmap *bmpFocus, |
1e6feb95 VZ |
321 | wxBitmap *bmpPressed, |
322 | wxBitmap *bmpDisabled); | |
323 | ||
324 | virtual void AdjustSize(wxSize *size, const wxWindow *window); | |
325 | virtual wxRect GetBorderDimensions(wxBorder border) const; | |
326 | virtual bool AreScrollbarsInsideBorder() const; | |
327 | ||
328 | virtual wxSize GetScrollbarArrowSize() const | |
329 | { return m_sizeScrollbarArrow; } | |
330 | virtual wxRect GetScrollbarRect(const wxScrollBar *scrollbar, | |
331 | wxScrollBar::Element elem, | |
332 | int thumbPos = -1) const; | |
333 | virtual wxCoord GetScrollbarSize(const wxScrollBar *scrollbar); | |
334 | virtual wxHitTest HitTestScrollbar(const wxScrollBar *scrollbar, | |
335 | const wxPoint& pt) const; | |
336 | virtual wxCoord ScrollbarToPixel(const wxScrollBar *scrollbar, | |
337 | int thumbPos = -1); | |
338 | virtual int PixelToScrollbar(const wxScrollBar *scrollbar, wxCoord coord); | |
339 | virtual wxCoord GetListboxItemHeight(wxCoord fontHeight) | |
340 | { return fontHeight + 2; } | |
341 | virtual wxSize GetCheckBitmapSize() const | |
342 | { return wxSize(13, 13); } | |
343 | virtual wxSize GetRadioBitmapSize() const | |
344 | { return wxSize(12, 12); } | |
345 | virtual wxCoord GetCheckItemMargin() const | |
346 | { return 0; } | |
347 | ||
348 | virtual wxRect GetTextTotalArea(const wxTextCtrl *text, | |
349 | const wxRect& rect); | |
350 | virtual wxRect GetTextClientArea(const wxTextCtrl *text, | |
351 | const wxRect& rect, | |
352 | wxCoord *extraSpaceBeyond); | |
353 | ||
354 | virtual wxSize GetTabIndent() const { return wxSize(2, 2); } | |
355 | virtual wxSize GetTabPadding() const { return wxSize(6, 5); } | |
356 | ||
357 | virtual wxCoord GetSliderDim() const { return 20; } | |
358 | virtual wxCoord GetSliderTickLen() const { return 4; } | |
359 | virtual wxRect GetSliderShaftRect(const wxRect& rect, | |
360 | wxOrientation orient) const; | |
361 | virtual wxSize GetSliderThumbSize(const wxRect& rect, | |
362 | wxOrientation orient) const; | |
363 | virtual wxSize GetProgressBarStep() const { return wxSize(16, 32); } | |
364 | ||
365 | virtual wxSize GetMenuBarItemSize(const wxSize& sizeText) const; | |
366 | virtual wxMenuGeometryInfo *GetMenuGeometry(wxWindow *win, | |
367 | const wxMenu& menu) const; | |
71e03035 VZ |
368 | |
369 | virtual wxSize GetStatusBarBorders(wxCoord *borderBetweenFields) const; | |
370 | ||
1e6feb95 VZ |
371 | protected: |
372 | // helper of DrawLabel() and DrawCheckOrRadioButton() | |
373 | void DoDrawLabel(wxDC& dc, | |
374 | const wxString& label, | |
375 | const wxRect& rect, | |
376 | int flags = 0, | |
377 | int alignment = wxALIGN_LEFT | wxALIGN_TOP, | |
378 | int indexAccel = -1, | |
379 | wxRect *rectBounds = NULL, | |
380 | const wxPoint& focusOffset | |
381 | = wxPoint(FOCUS_RECT_OFFSET_X, FOCUS_RECT_OFFSET_Y)); | |
382 | ||
383 | // common part of DrawLabel() and DrawItem() | |
384 | void DrawFocusRect(wxDC& dc, const wxRect& rect); | |
385 | ||
386 | // DrawLabel() and DrawButtonLabel() helper | |
387 | void DrawLabelShadow(wxDC& dc, | |
388 | const wxString& label, | |
389 | const wxRect& rect, | |
390 | int alignment, | |
391 | int indexAccel); | |
392 | ||
393 | // DrawButtonBorder() helper | |
394 | void DoDrawBackground(wxDC& dc, | |
395 | const wxColour& col, | |
396 | const wxRect& rect); | |
397 | ||
398 | // DrawBorder() helpers: all of them shift and clip the DC after drawing | |
399 | // the border | |
400 | ||
401 | // just draw a rectangle with the given pen | |
402 | void DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen); | |
403 | ||
404 | // draw the lower left part of rectangle | |
405 | void DrawHalfRect(wxDC& dc, wxRect *rect, const wxPen& pen); | |
406 | ||
407 | // draw the rectange using the first brush for the left and top sides and | |
408 | // the second one for the bottom and right ones | |
409 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
410 | const wxPen& pen1, const wxPen& pen2); | |
411 | ||
412 | // draw the normal 3D border | |
413 | void DrawRaisedBorder(wxDC& dc, wxRect *rect); | |
414 | ||
415 | // draw the sunken 3D border | |
416 | void DrawSunkenBorder(wxDC& dc, wxRect *rect); | |
417 | ||
418 | // draw the border used for scrollbar arrows | |
419 | void DrawArrowBorder(wxDC& dc, wxRect *rect, bool isPressed = FALSE); | |
420 | ||
421 | // public DrawArrow()s helper | |
422 | void DrawArrow(wxDC& dc, const wxRect& rect, | |
423 | wxArrowDirection arrowDir, wxArrowStyle arrowStyle); | |
424 | ||
425 | // DrawArrowButton is used by DrawScrollbar and DrawComboButton | |
426 | void DrawArrowButton(wxDC& dc, const wxRect& rect, | |
427 | wxArrowDirection arrowDir, | |
428 | wxArrowStyle arrowStyle); | |
429 | ||
430 | // DrawCheckButton/DrawRadioButton helper | |
431 | void DrawCheckOrRadioButton(wxDC& dc, | |
432 | const wxString& label, | |
433 | const wxBitmap& bitmap, | |
434 | const wxRect& rect, | |
435 | int flags, | |
436 | wxAlignment align, | |
437 | int indexAccel, | |
438 | wxCoord focusOffsetY); | |
439 | ||
440 | // draw a normal or transposed line (useful for using the same code fo both | |
441 | // horizontal and vertical widgets) | |
442 | void DrawLine(wxDC& dc, | |
443 | wxCoord x1, wxCoord y1, | |
444 | wxCoord x2, wxCoord y2, | |
445 | bool transpose = FALSE) | |
446 | { | |
447 | if ( transpose ) | |
448 | dc.DrawLine(y1, x1, y2, x2); | |
449 | else | |
450 | dc.DrawLine(x1, y1, x2, y2); | |
451 | } | |
452 | ||
453 | // get the standard check/radio button bitmap | |
454 | wxBitmap GetIndicator(IndicatorType indType, int flags); | |
455 | wxBitmap GetCheckBitmap(int flags) | |
456 | { return GetIndicator(IndicatorType_Check, flags); } | |
457 | wxBitmap GetRadioBitmap(int flags) | |
458 | { return GetIndicator(IndicatorType_Radio, flags); } | |
459 | ||
460 | private: | |
461 | const wxColourScheme *m_scheme; | |
462 | ||
463 | // the sizing parameters (TODO make them changeable) | |
464 | wxSize m_sizeScrollbarArrow; | |
465 | ||
466 | // GDI objects we use for drawing | |
467 | wxColour m_colDarkGrey, | |
468 | m_colHighlight; | |
469 | ||
470 | wxPen m_penBlack, | |
471 | m_penDarkGrey, | |
472 | m_penLightGrey, | |
473 | m_penHighlight; | |
71e03035 | 474 | |
24a23c35 | 475 | wxFont m_titlebarFont; |
71e03035 | 476 | |
24a23c35 VS |
477 | // titlebar icons: |
478 | wxBitmap m_bmpFrameButtons[FrameButton_Max]; | |
1e6feb95 VZ |
479 | |
480 | // first row is for the normal state, second - for the disabled | |
481 | wxBitmap m_bmpArrows[Arrow_StateMax][Arrow_Max]; | |
482 | }; | |
483 | ||
484 | // ---------------------------------------------------------------------------- | |
485 | // wxWin32InputHandler and derived classes: process the keyboard and mouse | |
486 | // messages according to Windows standards | |
487 | // ---------------------------------------------------------------------------- | |
488 | ||
489 | class wxWin32InputHandler : public wxInputHandler | |
490 | { | |
491 | public: | |
492 | wxWin32InputHandler(wxWin32Renderer *renderer); | |
493 | ||
67e49a98 | 494 | virtual bool HandleKey(wxInputConsumer *control, |
1e6feb95 VZ |
495 | const wxKeyEvent& event, |
496 | bool pressed); | |
67e49a98 | 497 | virtual bool HandleMouse(wxInputConsumer *control, |
1e6feb95 VZ |
498 | const wxMouseEvent& event); |
499 | ||
500 | protected: | |
501 | wxWin32Renderer *m_renderer; | |
502 | }; | |
503 | ||
504 | class wxWin32ScrollBarInputHandler : public wxStdScrollBarInputHandler | |
505 | { | |
506 | public: | |
507 | wxWin32ScrollBarInputHandler(wxWin32Renderer *renderer, | |
508 | wxInputHandler *handler); | |
509 | ||
67e49a98 VS |
510 | virtual bool HandleMouse(wxInputConsumer *control, const wxMouseEvent& event); |
511 | virtual bool HandleMouseMove(wxInputConsumer *control, const wxMouseEvent& event); | |
1e6feb95 VZ |
512 | |
513 | virtual bool OnScrollTimer(wxScrollBar *scrollbar, | |
514 | const wxControlAction& action); | |
515 | ||
516 | protected: | |
517 | virtual bool IsAllowedButton(int button) { return button == 1; } | |
518 | ||
519 | virtual void Highlight(wxScrollBar *scrollbar, bool doIt) | |
520 | { | |
521 | // we don't highlight anything | |
522 | } | |
523 | ||
524 | // the first and last event which caused the thumb to move | |
525 | wxMouseEvent m_eventStartDrag, | |
526 | m_eventLastDrag; | |
527 | ||
528 | // have we paused the scrolling because the mouse moved? | |
529 | bool m_scrollPaused; | |
530 | ||
531 | // we remember the interval of the timer to be able to restart it | |
532 | int m_interval; | |
533 | }; | |
534 | ||
535 | class wxWin32CheckboxInputHandler : public wxStdCheckboxInputHandler | |
536 | { | |
537 | public: | |
538 | wxWin32CheckboxInputHandler(wxInputHandler *handler) | |
539 | : wxStdCheckboxInputHandler(handler) { } | |
540 | ||
67e49a98 | 541 | virtual bool HandleKey(wxInputConsumer *control, |
1e6feb95 VZ |
542 | const wxKeyEvent& event, |
543 | bool pressed); | |
544 | }; | |
545 | ||
546 | class wxWin32TextCtrlInputHandler : public wxStdTextCtrlInputHandler | |
547 | { | |
548 | public: | |
549 | wxWin32TextCtrlInputHandler(wxInputHandler *handler) | |
550 | : wxStdTextCtrlInputHandler(handler) { } | |
551 | ||
67e49a98 | 552 | virtual bool HandleKey(wxInputConsumer *control, |
1e6feb95 VZ |
553 | const wxKeyEvent& event, |
554 | bool pressed); | |
555 | }; | |
556 | ||
71e03035 VZ |
557 | class wxWin32StatusBarInputHandler : public wxStdInputHandler |
558 | { | |
559 | public: | |
560 | wxWin32StatusBarInputHandler(wxInputHandler *handler); | |
561 | ||
562 | virtual bool HandleMouse(wxInputConsumer *consumer, | |
563 | const wxMouseEvent& event); | |
564 | ||
565 | virtual bool HandleMouseMove(wxInputConsumer *consumer, | |
566 | const wxMouseEvent& event); | |
567 | ||
568 | protected: | |
569 | // is the given point over the statusbar grip? | |
570 | bool IsOnGrip(wxWindow *statbar, const wxPoint& pt) const; | |
571 | ||
572 | private: | |
573 | // the cursor we had replaced with the resize one | |
574 | wxCursor m_cursorOld; | |
575 | ||
576 | // was the mouse over the grip last time we checked? | |
577 | bool m_isOnGrip; | |
578 | }; | |
579 | ||
1e6feb95 VZ |
580 | // ---------------------------------------------------------------------------- |
581 | // wxWin32ColourScheme: uses (default) Win32 colours | |
582 | // ---------------------------------------------------------------------------- | |
583 | ||
584 | class wxWin32ColourScheme : public wxColourScheme | |
585 | { | |
586 | public: | |
587 | virtual wxColour Get(StdColour col) const; | |
588 | virtual wxColour GetBackground(wxWindow *win) const; | |
589 | }; | |
590 | ||
591 | // ---------------------------------------------------------------------------- | |
592 | // wxWin32Theme | |
593 | // ---------------------------------------------------------------------------- | |
594 | ||
595 | WX_DEFINE_ARRAY(wxInputHandler *, wxArrayHandlers); | |
596 | ||
597 | class wxWin32Theme : public wxTheme | |
598 | { | |
599 | public: | |
600 | wxWin32Theme(); | |
601 | virtual ~wxWin32Theme(); | |
602 | ||
240889a1 | 603 | virtual wxRenderer *GetRenderer(); |
1e6feb95 VZ |
604 | virtual wxInputHandler *GetInputHandler(const wxString& control); |
605 | virtual wxColourScheme *GetColourScheme(); | |
606 | ||
607 | private: | |
608 | // get the default input handler | |
609 | wxInputHandler *GetDefaultInputHandler(); | |
610 | ||
611 | wxWin32Renderer *m_renderer; | |
612 | ||
613 | // the names of the already created handlers and the handlers themselves | |
614 | // (these arrays are synchronized) | |
615 | wxSortedArrayString m_handlerNames; | |
616 | wxArrayHandlers m_handlers; | |
617 | ||
618 | wxWin32InputHandler *m_handlerDefault; | |
619 | ||
620 | wxWin32ColourScheme *m_scheme; | |
621 | ||
622 | WX_DECLARE_THEME(win32) | |
623 | }; | |
624 | ||
625 | // ---------------------------------------------------------------------------- | |
626 | // standard bitmaps | |
627 | // ---------------------------------------------------------------------------- | |
628 | ||
24a23c35 VS |
629 | // frame buttons bitmaps |
630 | ||
631 | static const char *frame_button_close_xpm[] = { | |
632 | "12 10 2 1", | |
633 | " c None", | |
634 | ". c black", | |
635 | " ", | |
636 | " .. .. ", | |
637 | " .. .. ", | |
638 | " .... ", | |
639 | " .. ", | |
640 | " .... ", | |
641 | " .. .. ", | |
642 | " .. .. ", | |
643 | " ", | |
644 | " "}; | |
645 | ||
646 | static const char *frame_button_help_xpm[] = { | |
647 | "12 10 2 1", | |
648 | " c None", | |
649 | ". c #000000", | |
650 | " .... ", | |
651 | " .. .. ", | |
652 | " .. .. ", | |
653 | " .. ", | |
654 | " .. ", | |
655 | " .. ", | |
656 | " ", | |
657 | " .. ", | |
658 | " .. ", | |
659 | " "}; | |
660 | ||
661 | static const char *frame_button_maximize_xpm[] = { | |
662 | "12 10 2 1", | |
663 | " c None", | |
664 | ". c #000000", | |
665 | " ......... ", | |
666 | " ......... ", | |
667 | " . . ", | |
668 | " . . ", | |
669 | " . . ", | |
670 | " . . ", | |
671 | " . . ", | |
672 | " . . ", | |
673 | " ......... ", | |
674 | " "}; | |
675 | ||
676 | static const char *frame_button_minimize_xpm[] = { | |
677 | "12 10 2 1", | |
678 | " c None", | |
679 | ". c #000000", | |
680 | " ", | |
681 | " ", | |
682 | " ", | |
683 | " ", | |
684 | " ", | |
685 | " ", | |
686 | " ", | |
687 | " ...... ", | |
688 | " ...... ", | |
689 | " "}; | |
690 | ||
691 | static const char *frame_button_restore_xpm[] = { | |
692 | "12 10 2 1", | |
693 | " c None", | |
694 | ". c #000000", | |
695 | " ...... ", | |
696 | " ...... ", | |
697 | " . . ", | |
698 | " ...... . ", | |
699 | " ...... . ", | |
700 | " . ... ", | |
701 | " . . ", | |
702 | " . . ", | |
703 | " ...... ", | |
704 | " "}; | |
705 | ||
1e6feb95 VZ |
706 | // menu bitmaps |
707 | ||
708 | static const char *checked_menu_xpm[] = { | |
709 | /* columns rows colors chars-per-pixel */ | |
710 | "9 9 2 1", | |
711 | "w c None", | |
712 | "b c black", | |
713 | /* pixels */ | |
714 | "wwwwwwwww", | |
715 | "wwwwwwwbw", | |
716 | "wwwwwwbbw", | |
717 | "wbwwwbbbw", | |
718 | "wbbwbbbww", | |
719 | "wbbbbbwww", | |
720 | "wwbbbwwww", | |
721 | "wwwbwwwww", | |
722 | "wwwwwwwww" | |
723 | }; | |
724 | ||
725 | static const char *selected_checked_menu_xpm[] = { | |
726 | /* columns rows colors chars-per-pixel */ | |
727 | "9 9 2 1", | |
728 | "w c None", | |
729 | "b c white", | |
730 | /* pixels */ | |
731 | "wwwwwwwww", | |
732 | "wwwwwwwbw", | |
733 | "wwwwwwbbw", | |
734 | "wbwwwbbbw", | |
735 | "wbbwbbbww", | |
736 | "wbbbbbwww", | |
737 | "wwbbbwwww", | |
738 | "wwwbwwwww", | |
739 | "wwwwwwwww" | |
740 | }; | |
741 | ||
742 | static const char *disabled_checked_menu_xpm[] = { | |
743 | /* columns rows colors chars-per-pixel */ | |
744 | "9 9 3 1", | |
745 | "w c None", | |
746 | "b c #7f7f7f", | |
747 | "W c #e0e0e0", | |
748 | /* pixels */ | |
749 | "wwwwwwwww", | |
750 | "wwwwwwwbw", | |
751 | "wwwwwwbbW", | |
752 | "wbwwwbbbW", | |
753 | "wbbwbbbWW", | |
754 | "wbbbbbWWw", | |
755 | "wwbbbWWww", | |
756 | "wwwbWWwww", | |
757 | "wwwwWwwww" | |
758 | }; | |
759 | ||
760 | static const char *selected_disabled_checked_menu_xpm[] = { | |
761 | /* columns rows colors chars-per-pixel */ | |
762 | "9 9 2 1", | |
763 | "w c None", | |
764 | "b c #7f7f7f", | |
765 | /* pixels */ | |
766 | "wwwwwwwww", | |
767 | "wwwwwwwbw", | |
768 | "wwwwwwbbw", | |
769 | "wbwwwbbbw", | |
770 | "wbbwbbbww", | |
771 | "wbbbbbwww", | |
772 | "wwbbbwwww", | |
773 | "wwwbwwwww", | |
774 | "wwwwwwwww" | |
775 | }; | |
776 | ||
777 | // checkbox and radiobox bitmaps below | |
778 | ||
779 | static const char *checked_xpm[] = { | |
780 | /* columns rows colors chars-per-pixel */ | |
781 | "13 13 5 1", | |
782 | "w c white", | |
783 | "b c black", | |
784 | "d c #7f7f7f", | |
785 | "g c #c0c0c0", | |
786 | "h c #e0e0e0", | |
787 | /* pixels */ | |
788 | "ddddddddddddh", | |
789 | "dbbbbbbbbbbgh", | |
790 | "dbwwwwwwwwwgh", | |
791 | "dbwwwwwwwbwgh", | |
792 | "dbwwwwwwbbwgh", | |
793 | "dbwbwwwbbbwgh", | |
794 | "dbwbbwbbbwwgh", | |
795 | "dbwbbbbbwwwgh", | |
796 | "dbwwbbbwwwwgh", | |
797 | "dbwwwbwwwwwgh", | |
798 | "dbwwwwwwwwwgh", | |
799 | "dgggggggggggh", | |
800 | "hhhhhhhhhhhhh" | |
801 | }; | |
802 | ||
803 | static const char *pressed_checked_xpm[] = { | |
804 | /* columns rows colors chars-per-pixel */ | |
805 | "13 13 4 1", | |
806 | "b c black", | |
807 | "d c #7f7f7f", | |
808 | "g c #c0c0c0", | |
809 | "h c #e0e0e0", | |
810 | /* pixels */ | |
811 | "ddddddddddddh", | |
812 | "dbbbbbbbbbbgh", | |
813 | "dbggggggggggh", | |
814 | "dbgggggggbggh", | |
815 | "dbggggggbbggh", | |
816 | "dbgbgggbbbggh", | |
817 | "dbgbbgbbbgggh", | |
818 | "dbgbbbbbggggh", | |
819 | "dbggbbbgggggh", | |
820 | "dbgggbggggggh", | |
821 | "dbggggggggggh", | |
822 | "dgggggggggggh", | |
823 | "hhhhhhhhhhhhh" | |
824 | }; | |
825 | ||
826 | static const char *pressed_disabled_checked_xpm[] = { | |
827 | /* columns rows colors chars-per-pixel */ | |
828 | "13 13 4 1", | |
829 | "b c black", | |
830 | "d c #7f7f7f", | |
831 | "g c #c0c0c0", | |
832 | "h c #e0e0e0", | |
833 | /* pixels */ | |
834 | "ddddddddddddh", | |
835 | "dbbbbbbbbbbgh", | |
836 | "dbggggggggggh", | |
837 | "dbgggggggdggh", | |
838 | "dbggggggddggh", | |
839 | "dbgdgggdddggh", | |
840 | "dbgddgdddgggh", | |
841 | "dbgdddddggggh", | |
842 | "dbggdddgggggh", | |
843 | "dbgggdggggggh", | |
844 | "dbggggggggggh", | |
845 | "dgggggggggggh", | |
846 | "hhhhhhhhhhhhh" | |
847 | }; | |
848 | ||
849 | static const char *checked_item_xpm[] = { | |
850 | /* columns rows colors chars-per-pixel */ | |
851 | "13 13 3 1", | |
852 | "w c white", | |
853 | "b c black", | |
854 | "d c #808080", | |
855 | /* pixels */ | |
856 | "wwwwwwwwwwwww", | |
857 | "wdddddddddddw", | |
858 | "wdwwwwwwwwwdw", | |
859 | "wdwwwwwwwbwdw", | |
860 | "wdwwwwwwbbwdw", | |
861 | "wdwbwwwbbbwdw", | |
862 | "wdwbbwbbbwwdw", | |
863 | "wdwbbbbbwwwdw", | |
864 | "wdwwbbbwwwwdw", | |
865 | "wdwwwbwwwwwdw", | |
866 | "wdwwwwwwwwwdw", | |
867 | "wdddddddddddw", | |
868 | "wwwwwwwwwwwww" | |
869 | }; | |
870 | ||
871 | static const char *unchecked_xpm[] = { | |
872 | /* columns rows colors chars-per-pixel */ | |
873 | "13 13 5 1", | |
874 | "w c white", | |
875 | "b c black", | |
876 | "d c #7f7f7f", | |
877 | "g c #c0c0c0", | |
878 | "h c #e0e0e0", | |
879 | /* pixels */ | |
880 | "ddddddddddddh", | |
881 | "dbbbbbbbbbbgh", | |
882 | "dbwwwwwwwwwgh", | |
883 | "dbwwwwwwwwwgh", | |
884 | "dbwwwwwwwwwgh", | |
885 | "dbwwwwwwwwwgh", | |
886 | "dbwwwwwwwwwgh", | |
887 | "dbwwwwwwwwwgh", | |
888 | "dbwwwwwwwwwgh", | |
889 | "dbwwwwwwwwwgh", | |
890 | "dbwwwwwwwwwgh", | |
891 | "dgggggggggggh", | |
892 | "hhhhhhhhhhhhh" | |
893 | }; | |
894 | ||
895 | static const char *pressed_unchecked_xpm[] = { | |
896 | /* columns rows colors chars-per-pixel */ | |
897 | "13 13 4 1", | |
898 | "b c black", | |
899 | "d c #7f7f7f", | |
900 | "g c #c0c0c0", | |
901 | "h c #e0e0e0", | |
902 | /* pixels */ | |
903 | "ddddddddddddh", | |
904 | "dbbbbbbbbbbgh", | |
905 | "dbggggggggggh", | |
906 | "dbggggggggggh", | |
907 | "dbggggggggggh", | |
908 | "dbggggggggggh", | |
909 | "dbggggggggggh", | |
910 | "dbggggggggggh", | |
911 | "dbggggggggggh", | |
912 | "dbggggggggggh", | |
913 | "dbggggggggggh", | |
914 | "dbggggggggggh", | |
915 | "hhhhhhhhhhhhh" | |
916 | }; | |
917 | ||
918 | static const char *unchecked_item_xpm[] = { | |
919 | /* columns rows colors chars-per-pixel */ | |
920 | "13 13 2 1", | |
921 | "w c white", | |
922 | "d c #808080", | |
923 | /* pixels */ | |
924 | "wwwwwwwwwwwww", | |
925 | "wdddddddddddw", | |
926 | "wdwwwwwwwwwdw", | |
927 | "wdwwwwwwwwwdw", | |
928 | "wdwwwwwwwwwdw", | |
929 | "wdwwwwwwwwwdw", | |
930 | "wdwwwwwwwwwdw", | |
931 | "wdwwwwwwwwwdw", | |
932 | "wdwwwwwwwwwdw", | |
933 | "wdwwwwwwwwwdw", | |
934 | "wdwwwwwwwwwdw", | |
935 | "wdddddddddddw", | |
936 | "wwwwwwwwwwwww" | |
937 | }; | |
938 | ||
939 | static const char *checked_radio_xpm[] = { | |
940 | /* columns rows colors chars-per-pixel */ | |
941 | "12 12 6 1", | |
942 | " c None", | |
943 | "w c white", | |
944 | "b c black", | |
945 | "d c #7f7f7f", | |
946 | "g c #c0c0c0", | |
947 | "h c #e0e0e0", | |
948 | /* pixels */ | |
949 | " dddd ", | |
950 | " ddbbbbdd ", | |
951 | " dbbwwwwbbh ", | |
952 | " dbwwwwwwgh ", | |
953 | "dbwwwbbwwwgh", | |
954 | "dbwwbbbbwwgh", | |
955 | "dbwwbbbbwwgh", | |
956 | "dbwwwbbwwwgh", | |
957 | " dbwwwwwwgh ", | |
958 | " dggwwwwggh ", | |
959 | " hhgggghh ", | |
960 | " hhhh " | |
961 | }; | |
962 | ||
963 | static const char *pressed_checked_radio_xpm[] = { | |
964 | /* columns rows colors chars-per-pixel */ | |
965 | "12 12 6 1", | |
966 | " c None", | |
967 | "w c white", | |
968 | "b c black", | |
969 | "d c #7f7f7f", | |
970 | "g c #c0c0c0", | |
971 | "h c #e0e0e0", | |
972 | /* pixels */ | |
973 | " dddd ", | |
974 | " ddbbbbdd ", | |
975 | " dbbggggbbh ", | |
976 | " dbgggggggh ", | |
977 | "dbgggbbggggh", | |
978 | "dbggbbbbgggh", | |
979 | "dbggbbbbgggh", | |
980 | "dbgggbbggggh", | |
981 | " dbgggggggh ", | |
982 | " dggggggggh ", | |
983 | " hhgggghh ", | |
984 | " hhhh " | |
985 | }; | |
986 | ||
987 | static const char *pressed_disabled_checked_radio_xpm[] = { | |
988 | /* columns rows colors chars-per-pixel */ | |
989 | "12 12 6 1", | |
990 | " c None", | |
991 | "w c white", | |
992 | "b c black", | |
993 | "d c #7f7f7f", | |
994 | "g c #c0c0c0", | |
995 | "h c #e0e0e0", | |
996 | /* pixels */ | |
997 | " dddd ", | |
998 | " ddbbbbdd ", | |
999 | " dbbggggbbh ", | |
1000 | " dbgggggggh ", | |
1001 | "dbgggddggggh", | |
1002 | "dbggddddgggh", | |
1003 | "dbggddddgggh", | |
1004 | "dbgggddggggh", | |
1005 | " dbgggggggh ", | |
1006 | " dggggggggh ", | |
1007 | " hhgggghh ", | |
1008 | " hhhh ", | |
1009 | }; | |
1010 | ||
1011 | static const char *unchecked_radio_xpm[] = { | |
1012 | /* columns rows colors chars-per-pixel */ | |
1013 | "12 12 6 1", | |
1014 | " c None", | |
1015 | "w c white", | |
1016 | "b c black", | |
1017 | "d c #7f7f7f", | |
1018 | "g c #c0c0c0", | |
1019 | "h c #e0e0e0", | |
1020 | /* pixels */ | |
1021 | " dddd ", | |
1022 | " ddbbbbdd ", | |
1023 | " dbbwwwwbbh ", | |
1024 | " dbwwwwwwgh ", | |
1025 | "dbwwwwwwwwgh", | |
1026 | "dbwwwwwwwwgh", | |
1027 | "dbwwwwwwwwgh", | |
1028 | "dbwwwwwwwwgh", | |
1029 | " dbwwwwwwgh ", | |
1030 | " dggwwwwggh ", | |
1031 | " hhgggghh ", | |
1032 | " hhhh " | |
1033 | }; | |
1034 | ||
1035 | static const char *pressed_unchecked_radio_xpm[] = { | |
1036 | /* columns rows colors chars-per-pixel */ | |
1037 | "12 12 6 1", | |
1038 | " c None", | |
1039 | "w c white", | |
1040 | "b c black", | |
1041 | "d c #7f7f7f", | |
1042 | "g c #c0c0c0", | |
1043 | "h c #e0e0e0", | |
1044 | /* pixels */ | |
1045 | " dddd ", | |
1046 | " ddbbbbdd ", | |
1047 | " dbbggggbbh ", | |
1048 | " dbgggggggh ", | |
1049 | "dbgggggggggh", | |
1050 | "dbgggggggggh", | |
1051 | "dbgggggggggh", | |
1052 | "dbgggggggggh", | |
1053 | " dbgggggggh ", | |
1054 | " dggggggggh ", | |
1055 | " hhgggghh ", | |
1056 | " hhhh " | |
1057 | }; | |
1058 | ||
1059 | static const char ** | |
1060 | bmpIndicators[IndicatorType_Max][IndicatorState_Max][IndicatorStatus_Max] = | |
1061 | { | |
1062 | // checkboxes first | |
1063 | { | |
1064 | // normal state | |
1065 | { checked_xpm, unchecked_xpm }, | |
1066 | ||
1067 | // pressed state | |
1068 | { pressed_checked_xpm, pressed_unchecked_xpm }, | |
1069 | ||
1070 | // disabled state | |
1071 | { pressed_disabled_checked_xpm, pressed_unchecked_xpm }, | |
1072 | }, | |
1073 | ||
1074 | // radio | |
1075 | { | |
1076 | // normal state | |
1077 | { checked_radio_xpm, unchecked_radio_xpm }, | |
1078 | ||
1079 | // pressed state | |
1080 | { pressed_checked_radio_xpm, pressed_unchecked_radio_xpm }, | |
1081 | ||
1082 | // disabled state | |
1083 | { pressed_disabled_checked_radio_xpm, pressed_unchecked_radio_xpm }, | |
1084 | }, | |
1085 | ||
1086 | // menu | |
1087 | { | |
1088 | // normal state | |
1089 | { checked_menu_xpm, NULL }, | |
1090 | ||
1091 | // selected state | |
1092 | { selected_checked_menu_xpm, NULL }, | |
1093 | ||
1094 | // disabled state | |
1095 | { disabled_checked_menu_xpm, NULL }, | |
1096 | ||
1097 | // disabled selected state | |
1098 | { selected_disabled_checked_menu_xpm, NULL }, | |
1099 | } | |
1100 | }; | |
1101 | ||
1102 | // ============================================================================ | |
1103 | // implementation | |
1104 | // ============================================================================ | |
1105 | ||
1106 | WX_IMPLEMENT_THEME(wxWin32Theme, win32, wxTRANSLATE("Win32 theme")); | |
1107 | ||
1108 | // ---------------------------------------------------------------------------- | |
1109 | // wxWin32Theme | |
1110 | // ---------------------------------------------------------------------------- | |
1111 | ||
1112 | wxWin32Theme::wxWin32Theme() | |
1113 | { | |
240889a1 VS |
1114 | m_scheme = NULL; |
1115 | m_renderer = NULL; | |
1e6feb95 VZ |
1116 | m_handlerDefault = NULL; |
1117 | } | |
1118 | ||
1119 | wxWin32Theme::~wxWin32Theme() | |
1120 | { | |
1121 | size_t count = m_handlers.GetCount(); | |
1122 | for ( size_t n = 0; n < count; n++ ) | |
1123 | { | |
1124 | if ( m_handlers[n] != m_handlerDefault ) | |
1125 | delete m_handlers[n]; | |
1126 | } | |
1127 | ||
1128 | delete m_handlerDefault; | |
1129 | ||
1130 | delete m_renderer; | |
1131 | delete m_scheme; | |
1132 | } | |
1133 | ||
240889a1 VS |
1134 | wxRenderer *wxWin32Theme::GetRenderer() |
1135 | { | |
1136 | if ( !m_renderer ) | |
1137 | { | |
1138 | m_renderer = new wxWin32Renderer(GetColourScheme()); | |
1139 | } | |
1140 | ||
1141 | return m_renderer; | |
1142 | } | |
1143 | ||
1e6feb95 VZ |
1144 | wxInputHandler *wxWin32Theme::GetDefaultInputHandler() |
1145 | { | |
1146 | if ( !m_handlerDefault ) | |
1147 | { | |
1148 | m_handlerDefault = new wxWin32InputHandler(m_renderer); | |
1149 | } | |
1150 | ||
1151 | return m_handlerDefault; | |
1152 | } | |
1153 | ||
1154 | wxInputHandler *wxWin32Theme::GetInputHandler(const wxString& control) | |
1155 | { | |
1156 | wxInputHandler *handler; | |
1157 | int n = m_handlerNames.Index(control); | |
1158 | if ( n == wxNOT_FOUND ) | |
1159 | { | |
1160 | // create a new handler | |
1161 | if ( control == wxINP_HANDLER_SCROLLBAR ) | |
1162 | handler = new wxWin32ScrollBarInputHandler(m_renderer, | |
1163 | GetDefaultInputHandler()); | |
1164 | #if wxUSE_BUTTON | |
1165 | else if ( control == wxINP_HANDLER_BUTTON ) | |
1166 | handler = new wxStdButtonInputHandler(GetDefaultInputHandler()); | |
1167 | #endif // wxUSE_BUTTON | |
1168 | #if wxUSE_CHECKBOX | |
1169 | else if ( control == wxINP_HANDLER_CHECKBOX ) | |
1170 | handler = new wxWin32CheckboxInputHandler(GetDefaultInputHandler()); | |
1171 | #endif // wxUSE_CHECKBOX | |
1172 | #if wxUSE_COMBOBOX | |
1173 | else if ( control == wxINP_HANDLER_COMBOBOX ) | |
1174 | handler = new wxStdComboBoxInputHandler(GetDefaultInputHandler()); | |
1175 | #endif // wxUSE_COMBOBOX | |
1176 | #if wxUSE_LISTBOX | |
1177 | else if ( control == wxINP_HANDLER_LISTBOX ) | |
1178 | handler = new wxStdListboxInputHandler(GetDefaultInputHandler()); | |
1179 | #endif // wxUSE_LISTBOX | |
1180 | #if wxUSE_CHECKLISTBOX | |
1181 | else if ( control == wxINP_HANDLER_CHECKLISTBOX ) | |
1182 | handler = new wxStdCheckListboxInputHandler(GetDefaultInputHandler()); | |
1183 | #endif // wxUSE_CHECKLISTBOX | |
1184 | #if wxUSE_TEXTCTRL | |
1185 | else if ( control == wxINP_HANDLER_TEXTCTRL ) | |
1186 | handler = new wxWin32TextCtrlInputHandler(GetDefaultInputHandler()); | |
1187 | #endif // wxUSE_TEXTCTRL | |
1188 | #if wxUSE_SLIDER | |
1189 | else if ( control == wxINP_HANDLER_SLIDER ) | |
1190 | handler = new wxStdSliderButtonInputHandler(GetDefaultInputHandler()); | |
1191 | #endif // wxUSE_SLIDER | |
1192 | #if wxUSE_SPINBTN | |
1193 | else if ( control == wxINP_HANDLER_SPINBTN ) | |
1194 | handler = new wxStdSpinButtonInputHandler(GetDefaultInputHandler()); | |
1195 | #endif // wxUSE_SPINBTN | |
1196 | #if wxUSE_NOTEBOOK | |
1197 | else if ( control == wxINP_HANDLER_NOTEBOOK ) | |
1198 | handler = new wxStdNotebookInputHandler(GetDefaultInputHandler()); | |
1199 | #endif // wxUSE_NOTEBOOK | |
71e03035 VZ |
1200 | #if wxUSE_STATUSBAR |
1201 | else if ( control == wxINP_HANDLER_STATUSBAR ) | |
1202 | handler = new wxWin32StatusBarInputHandler(GetDefaultInputHandler()); | |
1203 | #endif // wxUSE_STATUSBAR | |
813edf09 VS |
1204 | else if ( control == wxINP_HANDLER_TOPLEVEL ) |
1205 | handler = new wxStdFrameInputHandler(GetDefaultInputHandler()); | |
1e6feb95 VZ |
1206 | else |
1207 | handler = GetDefaultInputHandler(); | |
1208 | ||
1209 | n = m_handlerNames.Add(control); | |
1210 | m_handlers.Insert(handler, n); | |
1211 | } | |
1212 | else // we already have it | |
1213 | { | |
1214 | handler = m_handlers[n]; | |
1215 | } | |
1216 | ||
1217 | return handler; | |
1218 | } | |
1219 | ||
1220 | wxColourScheme *wxWin32Theme::GetColourScheme() | |
1221 | { | |
240889a1 VS |
1222 | if ( !m_scheme ) |
1223 | { | |
1224 | m_scheme = new wxWin32ColourScheme; | |
1225 | } | |
1e6feb95 VZ |
1226 | return m_scheme; |
1227 | } | |
1228 | ||
1229 | // ============================================================================ | |
1230 | // wxWin32ColourScheme | |
1231 | // ============================================================================ | |
1232 | ||
1233 | wxColour wxWin32ColourScheme::GetBackground(wxWindow *win) const | |
1234 | { | |
1235 | wxColour col; | |
1236 | if ( win->UseBgCol() ) | |
1237 | { | |
1238 | // use the user specified colour | |
1239 | col = win->GetBackgroundColour(); | |
1240 | } | |
1241 | ||
1242 | if ( win->IsContainerWindow() ) | |
1243 | { | |
1244 | wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl); | |
1245 | if ( text ) | |
1246 | { | |
1247 | if ( !text->IsEnabled() ) // not IsEditable() | |
1248 | col = Get(CONTROL); | |
1249 | //else: execute code below | |
1250 | } | |
1251 | ||
1252 | if ( !col.Ok() ) | |
1253 | { | |
1254 | // doesn't depend on the state | |
1255 | col = Get(WINDOW); | |
1256 | } | |
1257 | } | |
1258 | else | |
1259 | { | |
1260 | int flags = win->GetStateFlags(); | |
1261 | ||
1262 | // the colour set by the user should be used for the normal state | |
1263 | // and for the states for which we don't have any specific colours | |
072a81ba | 1264 | if ( !col.Ok() || (flags & wxCONTROL_PRESSED) != 0 ) |
1e6feb95 VZ |
1265 | { |
1266 | if ( wxDynamicCast(win, wxScrollBar) ) | |
1267 | col = Get(flags & wxCONTROL_PRESSED ? SCROLLBAR_PRESSED | |
1268 | : SCROLLBAR); | |
1269 | else | |
1270 | col = Get(CONTROL); | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | return col; | |
1275 | } | |
1276 | ||
1277 | wxColour wxWin32ColourScheme::Get(wxWin32ColourScheme::StdColour col) const | |
1278 | { | |
1279 | switch ( col ) | |
1280 | { | |
16bdba2c VZ |
1281 | // use the system colours under Windows |
1282 | #if defined(__WXMSW__) | |
1283 | case WINDOW: return wxColour(GetSysColor(COLOR_WINDOW)); | |
1284 | ||
1285 | case CONTROL_PRESSED: | |
1286 | case CONTROL_CURRENT: | |
1287 | case CONTROL: return wxColour(GetSysColor(COLOR_BTNFACE)); | |
1288 | ||
1289 | case CONTROL_TEXT: return wxColour(GetSysColor(COLOR_BTNTEXT)); | |
1290 | ||
1291 | case SCROLLBAR: return wxColour(GetSysColor(COLOR_SCROLLBAR)); | |
1292 | case SCROLLBAR_PRESSED: return wxColour(GetSysColor(COLOR_HIGHLIGHT)); | |
1293 | ||
1294 | case HIGHLIGHT: return wxColour(GetSysColor(COLOR_HIGHLIGHT)); | |
1295 | case HIGHLIGHT_TEXT: return wxColour(GetSysColor(COLOR_HIGHLIGHTTEXT)); | |
1296 | ||
1297 | #if defined(COLOR_3DDKSHADOW) | |
1298 | case SHADOW_DARK: return wxColour(GetSysColor(COLOR_3DDKSHADOW)); | |
1299 | #else | |
1300 | case SHADOW_DARK: return *wxBLACK; | |
1301 | #endif | |
1302 | ||
1303 | case CONTROL_TEXT_DISABLED: | |
1304 | case SHADOW_HIGHLIGHT: return wxColour(GetSysColor(COLOR_BTNHIGHLIGHT)); | |
1305 | ||
1306 | case SHADOW_IN: return wxColour(GetSysColor(COLOR_BTNFACE)); | |
1307 | ||
1308 | case CONTROL_TEXT_DISABLED_SHADOW: | |
1309 | case SHADOW_OUT: return wxColour(GetSysColor(COLOR_BTNSHADOW)); | |
71e03035 | 1310 | |
24a23c35 VS |
1311 | case TITLEBAR: return wxColour(GetSysColor(COLOR_INACTIVECAPTION)); |
1312 | case TITLEBAR_ACTIVE: return wxColour(GetSysColor(COLOR_ACTIVECAPTION)); | |
6296744f VS |
1313 | case TITLEBAR_TEXT: return wxColour(GetSysColor(COLOR_INACTIVECAPTIONTEXT)); |
1314 | case TITLEBAR_ACTIVE_TEXT: return wxColour(GetSysColor(COLOR_CAPTIONTEXT)); | |
1315 | ||
1316 | case DESKTOP: return wxColour(0x808000); | |
16bdba2c VZ |
1317 | #else // !__WXMSW__ |
1318 | // use the standard Windows colours elsewhere | |
86313763 VZ |
1319 | case WINDOW: return *wxWHITE; |
1320 | ||
1e6feb95 VZ |
1321 | case CONTROL_PRESSED: |
1322 | case CONTROL_CURRENT: | |
1323 | case CONTROL: return wxColour(0xc0c0c0); | |
1324 | ||
1325 | case CONTROL_TEXT: return *wxBLACK; | |
1326 | ||
1327 | case SCROLLBAR: return wxColour(0xe0e0e0); | |
1328 | case SCROLLBAR_PRESSED: return *wxBLACK; | |
1329 | ||
1330 | case HIGHLIGHT: return wxColour(0x800000); | |
1331 | case HIGHLIGHT_TEXT: return wxColour(0xffffff); | |
1332 | ||
1333 | case SHADOW_DARK: return *wxBLACK; | |
1334 | ||
24a23c35 VS |
1335 | case CONTROL_TEXT_DISABLED:return wxColour(0xe0e0e0); |
1336 | case SHADOW_HIGHLIGHT: return wxColour(0xffffff); | |
1e6feb95 VZ |
1337 | |
1338 | case SHADOW_IN: return wxColour(0xc0c0c0); | |
1339 | ||
1340 | case CONTROL_TEXT_DISABLED_SHADOW: | |
1341 | case SHADOW_OUT: return wxColour(0x7f7f7f); | |
24a23c35 VS |
1342 | |
1343 | case TITLEBAR: return wxColour(0xaeaaae); | |
1344 | case TITLEBAR_ACTIVE: return wxColour(0x820300); | |
6296744f VS |
1345 | case TITLEBAR_TEXT: return wxColour(0xc0c0c0); |
1346 | case TITLEBAR_ACTIVE_TEXT:return *wxWHITE; | |
1347 | ||
1348 | case DESKTOP: return wxColour(0x808000); | |
16bdba2c | 1349 | #endif // __WXMSW__ |
1e6feb95 VZ |
1350 | |
1351 | case MAX: | |
1352 | default: | |
1353 | wxFAIL_MSG(_T("invalid standard colour")); | |
1354 | return *wxBLACK; | |
1355 | } | |
1356 | } | |
1357 | ||
1358 | // ============================================================================ | |
1359 | // wxWin32Renderer | |
1360 | // ============================================================================ | |
1361 | ||
1362 | // ---------------------------------------------------------------------------- | |
1363 | // construction | |
1364 | // ---------------------------------------------------------------------------- | |
1365 | ||
1366 | wxWin32Renderer::wxWin32Renderer(const wxColourScheme *scheme) | |
1367 | { | |
1368 | // init data | |
1369 | m_scheme = scheme; | |
1370 | m_sizeScrollbarArrow = wxSize(16, 16); | |
1371 | ||
1372 | // init colours and pens | |
1373 | m_penBlack = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_DARK), 0, wxSOLID); | |
1374 | ||
1375 | m_colDarkGrey = wxSCHEME_COLOUR(scheme, SHADOW_OUT); | |
1376 | m_penDarkGrey = wxPen(m_colDarkGrey, 0, wxSOLID); | |
1377 | ||
1378 | m_penLightGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_IN), 0, wxSOLID); | |
1379 | ||
1380 | m_colHighlight = wxSCHEME_COLOUR(scheme, SHADOW_HIGHLIGHT); | |
1381 | m_penHighlight = wxPen(m_colHighlight, 0, wxSOLID); | |
71e03035 | 1382 | |
a756f210 | 1383 | m_titlebarFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
24a23c35 | 1384 | m_titlebarFont.SetWeight(wxFONTWEIGHT_BOLD); |
1e6feb95 VZ |
1385 | |
1386 | // init the arrow bitmaps | |
1387 | static const size_t ARROW_WIDTH = 7; | |
1388 | static const size_t ARROW_LENGTH = 4; | |
1389 | ||
1390 | wxMask *mask; | |
1391 | wxMemoryDC dcNormal, | |
1392 | dcDisabled, | |
1393 | dcInverse; | |
1394 | for ( size_t n = 0; n < Arrow_Max; n++ ) | |
1395 | { | |
1396 | bool isVertical = n > Arrow_Right; | |
1397 | int w, h; | |
1398 | if ( isVertical ) | |
1399 | { | |
1400 | w = ARROW_WIDTH; | |
1401 | h = ARROW_LENGTH; | |
1402 | } | |
1403 | else | |
1404 | { | |
1405 | h = ARROW_WIDTH; | |
1406 | w = ARROW_LENGTH; | |
1407 | } | |
1408 | ||
1409 | // disabled arrow is larger because of the shadow | |
1410 | m_bmpArrows[Arrow_Normal][n].Create(w, h); | |
1411 | m_bmpArrows[Arrow_Disabled][n].Create(w + 1, h + 1); | |
1412 | ||
1413 | dcNormal.SelectObject(m_bmpArrows[Arrow_Normal][n]); | |
1414 | dcDisabled.SelectObject(m_bmpArrows[Arrow_Disabled][n]); | |
1415 | ||
1416 | dcNormal.SetBackground(*wxWHITE_BRUSH); | |
1417 | dcDisabled.SetBackground(*wxWHITE_BRUSH); | |
1418 | dcNormal.Clear(); | |
1419 | dcDisabled.Clear(); | |
1420 | ||
1421 | dcNormal.SetPen(m_penBlack); | |
1422 | dcDisabled.SetPen(m_penDarkGrey); | |
1423 | ||
1424 | // calculate the position of the point of the arrow | |
1425 | wxCoord x1, y1; | |
1426 | if ( isVertical ) | |
1427 | { | |
1428 | x1 = (ARROW_WIDTH - 1)/2; | |
1429 | y1 = n == Arrow_Up ? 0 : ARROW_LENGTH - 1; | |
1430 | } | |
1431 | else // horizontal | |
1432 | { | |
1433 | x1 = n == Arrow_Left ? 0 : ARROW_LENGTH - 1; | |
1434 | y1 = (ARROW_WIDTH - 1)/2; | |
1435 | } | |
1436 | ||
1437 | wxCoord x2 = x1, | |
1438 | y2 = y1; | |
1439 | ||
1440 | if ( isVertical ) | |
1441 | x2++; | |
1442 | else | |
1443 | y2++; | |
1444 | ||
1445 | for ( size_t i = 0; i < ARROW_LENGTH; i++ ) | |
1446 | { | |
1447 | dcNormal.DrawLine(x1, y1, x2, y2); | |
1448 | dcDisabled.DrawLine(x1, y1, x2, y2); | |
1449 | ||
1450 | if ( isVertical ) | |
1451 | { | |
1452 | x1--; | |
1453 | x2++; | |
1454 | ||
1455 | if ( n == Arrow_Up ) | |
1456 | { | |
1457 | y1++; | |
1458 | y2++; | |
1459 | } | |
1460 | else // down arrow | |
1461 | { | |
1462 | y1--; | |
1463 | y2--; | |
1464 | } | |
1465 | } | |
1466 | else // left or right arrow | |
1467 | { | |
1468 | y1--; | |
1469 | y2++; | |
1470 | ||
1471 | if ( n == Arrow_Left ) | |
1472 | { | |
1473 | x1++; | |
1474 | x2++; | |
1475 | } | |
1476 | else | |
1477 | { | |
1478 | x1--; | |
1479 | x2--; | |
1480 | } | |
1481 | } | |
1482 | } | |
1483 | ||
1484 | // draw the shadow for the disabled one | |
1485 | dcDisabled.SetPen(m_penHighlight); | |
1486 | switch ( n ) | |
1487 | { | |
1488 | case Arrow_Left: | |
1489 | y1 += 2; | |
1490 | dcDisabled.DrawLine(x1, y1, x2, y2); | |
1491 | break; | |
1492 | ||
1493 | case Arrow_Right: | |
1494 | x1 = ARROW_LENGTH - 1; | |
1495 | y1 = (ARROW_WIDTH - 1)/2 + 1; | |
1496 | x2 = 0; | |
1497 | y2 = ARROW_WIDTH; | |
1498 | dcDisabled.DrawLine(x1, y1, x2, y2); | |
1499 | dcDisabled.DrawLine(++x1, y1, x2, ++y2); | |
1500 | break; | |
1501 | ||
1502 | case Arrow_Up: | |
1503 | x1 += 2; | |
1504 | dcDisabled.DrawLine(x1, y1, x2, y2); | |
1505 | break; | |
1506 | ||
1507 | case Arrow_Down: | |
1508 | x1 = ARROW_WIDTH - 1; | |
1509 | y1 = 1; | |
1510 | x2 = (ARROW_WIDTH - 1)/2; | |
1511 | y2 = ARROW_LENGTH; | |
1512 | dcDisabled.DrawLine(x1, y1, x2, y2); | |
1513 | dcDisabled.DrawLine(++x1, y1, x2, ++y2); | |
1514 | break; | |
1515 | ||
1516 | } | |
1517 | ||
1518 | // create the inversed bitmap but only for the right arrow as we only | |
1519 | // use it for the menus | |
1520 | if ( n == Arrow_Right ) | |
1521 | { | |
1522 | m_bmpArrows[Arrow_Inversed][n].Create(w, h); | |
1523 | dcInverse.SelectObject(m_bmpArrows[Arrow_Inversed][n]); | |
1524 | dcInverse.Clear(); | |
1525 | dcInverse.Blit(0, 0, w, h, | |
1526 | &dcNormal, 0, 0, | |
1527 | wxXOR); | |
1528 | dcInverse.SelectObject(wxNullBitmap); | |
1529 | ||
1530 | mask = new wxMask(m_bmpArrows[Arrow_Inversed][n], *wxBLACK); | |
1531 | m_bmpArrows[Arrow_Inversed][n].SetMask(mask); | |
1532 | ||
1533 | m_bmpArrows[Arrow_InversedDisabled][n].Create(w, h); | |
1534 | dcInverse.SelectObject(m_bmpArrows[Arrow_InversedDisabled][n]); | |
1535 | dcInverse.Clear(); | |
1536 | dcInverse.Blit(0, 0, w, h, | |
1537 | &dcDisabled, 0, 0, | |
1538 | wxXOR); | |
1539 | dcInverse.SelectObject(wxNullBitmap); | |
1540 | ||
1541 | mask = new wxMask(m_bmpArrows[Arrow_InversedDisabled][n], *wxBLACK); | |
1542 | m_bmpArrows[Arrow_InversedDisabled][n].SetMask(mask); | |
1543 | } | |
1544 | ||
1545 | dcNormal.SelectObject(wxNullBitmap); | |
1546 | dcDisabled.SelectObject(wxNullBitmap); | |
1547 | ||
1548 | mask = new wxMask(m_bmpArrows[Arrow_Normal][n], *wxWHITE); | |
1549 | m_bmpArrows[Arrow_Normal][n].SetMask(mask); | |
1550 | mask = new wxMask(m_bmpArrows[Arrow_Disabled][n], *wxWHITE); | |
1551 | m_bmpArrows[Arrow_Disabled][n].SetMask(mask); | |
1552 | ||
1553 | m_bmpArrows[Arrow_Pressed][n] = m_bmpArrows[Arrow_Normal][n]; | |
1554 | } | |
71e03035 | 1555 | |
24a23c35 VS |
1556 | // init the frame buttons bitmaps |
1557 | m_bmpFrameButtons[FrameButton_Close] = wxBitmap(frame_button_close_xpm); | |
1558 | m_bmpFrameButtons[FrameButton_Minimize] = wxBitmap(frame_button_minimize_xpm); | |
1559 | m_bmpFrameButtons[FrameButton_Maximize] = wxBitmap(frame_button_maximize_xpm); | |
1560 | m_bmpFrameButtons[FrameButton_Restore] = wxBitmap(frame_button_restore_xpm); | |
1561 | m_bmpFrameButtons[FrameButton_Help] = wxBitmap(frame_button_help_xpm); | |
1e6feb95 VZ |
1562 | } |
1563 | ||
1564 | // ---------------------------------------------------------------------------- | |
1565 | // border stuff | |
1566 | // ---------------------------------------------------------------------------- | |
1567 | ||
1568 | /* | |
1569 | The raised border in Win32 looks like this: | |
1570 | ||
1571 | IIIIIIIIIIIIIIIIIIIIIIB | |
1572 | I GB | |
1573 | I GB I = white (HILIGHT) | |
1574 | I GB H = light grey (LIGHT) | |
1575 | I GB G = dark grey (SHADOI) | |
1576 | I GB B = black (DKSHADOI) | |
1577 | I GB I = hIghlight (COLOR_3DHILIGHT) | |
1578 | I GB | |
1579 | IGGGGGGGGGGGGGGGGGGGGGB | |
1580 | BBBBBBBBBBBBBBBBBBBBBBB | |
1581 | ||
1582 | The sunken border looks like this: | |
1583 | ||
1584 | GGGGGGGGGGGGGGGGGGGGGGI | |
1585 | GBBBBBBBBBBBBBBBBBBBBHI | |
1586 | GB HI | |
1587 | GB HI | |
1588 | GB HI | |
1589 | GB HI | |
1590 | GB HI | |
1591 | GB HI | |
1592 | GHHHHHHHHHHHHHHHHHHHHHI | |
1593 | IIIIIIIIIIIIIIIIIIIIIII | |
1594 | ||
1595 | The static border (used for the controls which don't get focus) is like | |
1596 | this: | |
1597 | ||
1598 | GGGGGGGGGGGGGGGGGGGGGGW | |
1599 | G W | |
1600 | G W | |
1601 | G W | |
1602 | G W | |
1603 | G W | |
1604 | G W | |
1605 | G W | |
1606 | WWWWWWWWWWWWWWWWWWWWWWW | |
1607 | ||
1608 | The most complicated is the double border: | |
1609 | ||
1610 | HHHHHHHHHHHHHHHHHHHHHHB | |
1611 | HWWWWWWWWWWWWWWWWWWWWGB | |
1612 | HWHHHHHHHHHHHHHHHHHHHGB | |
1613 | HWH HGB | |
1614 | HWH HGB | |
1615 | HWH HGB | |
1616 | HWH HGB | |
1617 | HWHHHHHHHHHHHHHHHHHHHGB | |
1618 | HGGGGGGGGGGGGGGGGGGGGGB | |
1619 | BBBBBBBBBBBBBBBBBBBBBBB | |
1620 | ||
1621 | And the simple border is, well, simple: | |
1622 | ||
1623 | BBBBBBBBBBBBBBBBBBBBBBB | |
1624 | B B | |
1625 | B B | |
1626 | B B | |
1627 | B B | |
1628 | B B | |
1629 | B B | |
1630 | B B | |
1631 | B B | |
1632 | BBBBBBBBBBBBBBBBBBBBBBB | |
1633 | */ | |
1634 | ||
1635 | void wxWin32Renderer::DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen) | |
1636 | { | |
1637 | // draw | |
1638 | dc.SetPen(pen); | |
1639 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
1640 | dc.DrawRectangle(*rect); | |
1641 | ||
1642 | // adjust the rect | |
1643 | rect->Inflate(-1); | |
1644 | } | |
1645 | ||
1646 | void wxWin32Renderer::DrawHalfRect(wxDC& dc, wxRect *rect, const wxPen& pen) | |
1647 | { | |
1648 | // draw the bottom and right sides | |
1649 | dc.SetPen(pen); | |
1650 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
1651 | rect->GetRight() + 1, rect->GetBottom()); | |
1652 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
1653 | rect->GetRight(), rect->GetBottom()); | |
1654 | ||
1655 | // adjust the rect | |
1656 | rect->width--; | |
1657 | rect->height--; | |
1658 | } | |
1659 | ||
1660 | void wxWin32Renderer::DrawShadedRect(wxDC& dc, wxRect *rect, | |
1661 | const wxPen& pen1, const wxPen& pen2) | |
1662 | { | |
1663 | // draw the rectangle | |
1664 | dc.SetPen(pen1); | |
1665 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
1666 | rect->GetLeft(), rect->GetBottom()); | |
1667 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
1668 | rect->GetRight(), rect->GetTop()); | |
1669 | dc.SetPen(pen2); | |
1670 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
1671 | rect->GetRight(), rect->GetBottom()); | |
1672 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
1673 | rect->GetRight() + 1, rect->GetBottom()); | |
1674 | ||
1675 | // adjust the rect | |
1676 | rect->Inflate(-1); | |
1677 | } | |
1678 | ||
1679 | void wxWin32Renderer::DrawRaisedBorder(wxDC& dc, wxRect *rect) | |
1680 | { | |
1681 | DrawShadedRect(dc, rect, m_penHighlight, m_penBlack); | |
1682 | DrawShadedRect(dc, rect, m_penLightGrey, m_penDarkGrey); | |
1683 | } | |
1684 | ||
1685 | void wxWin32Renderer::DrawSunkenBorder(wxDC& dc, wxRect *rect) | |
1686 | { | |
1687 | DrawShadedRect(dc, rect, m_penDarkGrey, m_penHighlight); | |
1688 | DrawShadedRect(dc, rect, m_penBlack, m_penLightGrey); | |
1689 | } | |
1690 | ||
1691 | void wxWin32Renderer::DrawArrowBorder(wxDC& dc, wxRect *rect, bool isPressed) | |
1692 | { | |
1693 | if ( isPressed ) | |
1694 | { | |
1695 | DrawRect(dc, rect, m_penDarkGrey); | |
1696 | ||
1697 | // the arrow is usually drawn inside border of width 2 and is offset by | |
1698 | // another pixel in both directions when it's pressed - as the border | |
1699 | // in this case is more narrow as well, we have to adjust rect like | |
1700 | // this: | |
1701 | rect->Inflate(-1); | |
1702 | rect->x++; | |
1703 | rect->y++; | |
1704 | } | |
1705 | else | |
1706 | { | |
1707 | DrawShadedRect(dc, rect, m_penLightGrey, m_penBlack); | |
1708 | DrawShadedRect(dc, rect, m_penHighlight, m_penDarkGrey); | |
1709 | } | |
1710 | } | |
1711 | ||
1712 | void wxWin32Renderer::DrawBorder(wxDC& dc, | |
1713 | wxBorder border, | |
1714 | const wxRect& rectTotal, | |
1715 | int WXUNUSED(flags), | |
1716 | wxRect *rectIn) | |
1717 | { | |
1718 | int i; | |
1719 | ||
1720 | wxRect rect = rectTotal; | |
1721 | ||
1722 | switch ( border ) | |
1723 | { | |
1724 | case wxBORDER_SUNKEN: | |
1725 | for ( i = 0; i < BORDER_THICKNESS / 2; i++ ) | |
1726 | { | |
1727 | DrawSunkenBorder(dc, &rect); | |
1728 | } | |
1729 | break; | |
1730 | ||
1731 | case wxBORDER_STATIC: | |
1732 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
1733 | break; | |
1734 | ||
1735 | case wxBORDER_RAISED: | |
1736 | for ( i = 0; i < BORDER_THICKNESS / 2; i++ ) | |
1737 | { | |
1738 | DrawRaisedBorder(dc, &rect); | |
1739 | } | |
1740 | break; | |
1741 | ||
1742 | case wxBORDER_DOUBLE: | |
1743 | DrawArrowBorder(dc, &rect); | |
1744 | DrawRect(dc, &rect, m_penLightGrey); | |
1745 | break; | |
1746 | ||
1747 | case wxBORDER_SIMPLE: | |
1748 | for ( i = 0; i < BORDER_THICKNESS / 2; i++ ) | |
1749 | { | |
1750 | DrawRect(dc, &rect, m_penBlack); | |
1751 | } | |
1752 | break; | |
1753 | ||
1754 | default: | |
1755 | wxFAIL_MSG(_T("unknown border type")); | |
1756 | // fall through | |
1757 | ||
1758 | case wxBORDER_DEFAULT: | |
1759 | case wxBORDER_NONE: | |
1760 | break; | |
1761 | } | |
1762 | ||
1763 | if ( rectIn ) | |
1764 | *rectIn = rect; | |
1765 | } | |
1766 | ||
1767 | wxRect wxWin32Renderer::GetBorderDimensions(wxBorder border) const | |
1768 | { | |
1769 | wxCoord width; | |
1770 | switch ( border ) | |
1771 | { | |
1772 | case wxBORDER_RAISED: | |
1773 | case wxBORDER_SUNKEN: | |
1774 | width = BORDER_THICKNESS; | |
1775 | break; | |
1776 | ||
1777 | case wxBORDER_SIMPLE: | |
1778 | case wxBORDER_STATIC: | |
1779 | width = 1; | |
1780 | break; | |
1781 | ||
1782 | case wxBORDER_DOUBLE: | |
1783 | width = 3; | |
1784 | break; | |
1785 | ||
1786 | default: | |
1787 | wxFAIL_MSG(_T("unknown border type")); | |
1788 | // fall through | |
1789 | ||
1790 | case wxBORDER_DEFAULT: | |
1791 | case wxBORDER_NONE: | |
1792 | width = 0; | |
1793 | break; | |
1794 | } | |
1795 | ||
1796 | wxRect rect; | |
1797 | rect.x = | |
1798 | rect.y = | |
1799 | rect.width = | |
1800 | rect.height = width; | |
1801 | ||
1802 | return rect; | |
1803 | } | |
1804 | ||
1805 | bool wxWin32Renderer::AreScrollbarsInsideBorder() const | |
1806 | { | |
1807 | return TRUE; | |
1808 | } | |
1809 | ||
1810 | // ---------------------------------------------------------------------------- | |
1811 | // borders | |
1812 | // ---------------------------------------------------------------------------- | |
1813 | ||
1814 | void wxWin32Renderer::DrawTextBorder(wxDC& dc, | |
1815 | wxBorder border, | |
1816 | const wxRect& rect, | |
1817 | int flags, | |
1818 | wxRect *rectIn) | |
1819 | { | |
1820 | // text controls are not special under windows | |
1821 | DrawBorder(dc, border, rect, flags, rectIn); | |
1822 | } | |
1823 | ||
1824 | void wxWin32Renderer::DrawButtonBorder(wxDC& dc, | |
1825 | const wxRect& rectTotal, | |
1826 | int flags, | |
1827 | wxRect *rectIn) | |
1828 | { | |
1829 | wxRect rect = rectTotal; | |
1830 | ||
1831 | if ( flags & wxCONTROL_PRESSED ) | |
1832 | { | |
1833 | // button pressed: draw a double border around it | |
1834 | DrawRect(dc, &rect, m_penBlack); | |
1835 | DrawRect(dc, &rect, m_penDarkGrey); | |
1836 | } | |
1837 | else | |
1838 | { | |
1839 | // button not pressed | |
1840 | ||
1841 | if ( flags & (wxCONTROL_FOCUSED | wxCONTROL_ISDEFAULT) ) | |
1842 | { | |
1843 | // button either default or focused (or both): add an extra border around it | |
1844 | DrawRect(dc, &rect, m_penBlack); | |
1845 | } | |
1846 | ||
1847 | // now draw a normal button | |
1848 | DrawShadedRect(dc, &rect, m_penHighlight, m_penBlack); | |
1849 | DrawHalfRect(dc, &rect, m_penDarkGrey); | |
1850 | } | |
1851 | ||
1852 | if ( rectIn ) | |
1853 | { | |
1854 | *rectIn = rect; | |
1855 | } | |
1856 | } | |
1857 | ||
1858 | // ---------------------------------------------------------------------------- | |
1859 | // lines and frame | |
1860 | // ---------------------------------------------------------------------------- | |
1861 | ||
1862 | void wxWin32Renderer::DrawHorizontalLine(wxDC& dc, | |
1863 | wxCoord y, wxCoord x1, wxCoord x2) | |
1864 | { | |
1865 | dc.SetPen(m_penDarkGrey); | |
1866 | dc.DrawLine(x1, y, x2 + 1, y); | |
1867 | dc.SetPen(m_penHighlight); | |
1868 | y++; | |
1869 | dc.DrawLine(x1, y, x2 + 1, y); | |
1870 | } | |
1871 | ||
1872 | void wxWin32Renderer::DrawVerticalLine(wxDC& dc, | |
1873 | wxCoord x, wxCoord y1, wxCoord y2) | |
1874 | { | |
1875 | dc.SetPen(m_penDarkGrey); | |
1876 | dc.DrawLine(x, y1, x, y2 + 1); | |
1877 | dc.SetPen(m_penHighlight); | |
1878 | x++; | |
1879 | dc.DrawLine(x, y1, x, y2 + 1); | |
1880 | } | |
1881 | ||
1882 | void wxWin32Renderer::DrawFrame(wxDC& dc, | |
1883 | const wxString& label, | |
1884 | const wxRect& rect, | |
1885 | int flags, | |
1886 | int alignment, | |
1887 | int indexAccel) | |
1888 | { | |
1889 | wxCoord height = 0; // of the label | |
1890 | wxRect rectFrame = rect; | |
1891 | if ( !label.empty() ) | |
1892 | { | |
1893 | // the text should touch the top border of the rect, so the frame | |
1894 | // itself should be lower | |
1895 | dc.GetTextExtent(label, NULL, &height); | |
1896 | rectFrame.y += height / 2; | |
1897 | rectFrame.height -= height / 2; | |
1898 | ||
1899 | // we have to draw each part of the frame individually as we can't | |
1900 | // erase the background beyond the label as it might contain some | |
1901 | // pixmap already, so drawing everything and then overwriting part of | |
1902 | // the frame with label doesn't work | |
1903 | ||
1904 | // TODO: the +5 and space insertion should be customizable | |
1905 | ||
1906 | wxRect rectText; | |
1907 | rectText.x = rectFrame.x + 5; | |
1908 | rectText.y = rect.y; | |
1909 | rectText.width = rectFrame.width - 7; // +2 border width | |
1910 | rectText.height = height; | |
1911 | ||
1912 | wxString label2; | |
1913 | label2 << _T(' ') << label << _T(' '); | |
1914 | if ( indexAccel != -1 ) | |
1915 | { | |
1916 | // adjust it as we prepended a space | |
1917 | indexAccel++; | |
1918 | } | |
1919 | ||
1920 | wxRect rectLabel; | |
1921 | DrawLabel(dc, label2, rectText, flags, alignment, indexAccel, &rectLabel); | |
1922 | ||
1923 | StandardDrawFrame(dc, rectFrame, rectLabel); | |
1924 | } | |
1925 | else | |
1926 | { | |
1927 | // just draw the complete frame | |
1928 | DrawShadedRect(dc, &rectFrame, m_penDarkGrey, m_penHighlight); | |
1929 | DrawShadedRect(dc, &rectFrame, m_penHighlight, m_penDarkGrey); | |
1930 | } | |
1931 | } | |
1932 | ||
1933 | // ---------------------------------------------------------------------------- | |
1934 | // label | |
1935 | // ---------------------------------------------------------------------------- | |
1936 | ||
1937 | void wxWin32Renderer::DrawFocusRect(wxDC& dc, const wxRect& rect) | |
1938 | { | |
1939 | // VZ: this doesn't work under Windows, the dotted pen has dots of 3 | |
1940 | // pixels each while we really need dots here... PS_ALTERNATE might | |
1941 | // work, but it is for NT 5 only | |
1942 | #if 0 | |
1943 | DrawRect(dc, &rect, wxPen(*wxBLACK, 0, wxDOT)); | |
1944 | #else | |
1945 | // draw the pixels manually: note that to behave in the same manner as | |
1946 | // DrawRect(), we must exclude the bottom and right borders from the | |
1947 | // rectangle | |
1948 | wxCoord x1 = rect.GetLeft(), | |
1949 | y1 = rect.GetTop(), | |
1950 | x2 = rect.GetRight(), | |
1951 | y2 = rect.GetBottom(); | |
1952 | ||
1953 | dc.SetPen(wxPen(*wxBLACK, 0, wxSOLID)); | |
1954 | ||
1955 | // this seems to be closer than what Windows does than wxINVERT although | |
1956 | // I'm still not sure if it's correct | |
1957 | dc.SetLogicalFunction(wxAND_REVERSE); | |
1958 | ||
1959 | wxCoord z; | |
1960 | for ( z = x1 + 1; z < x2; z += 2 ) | |
1961 | dc.DrawPoint(z, rect.GetTop()); | |
1962 | ||
1963 | wxCoord shift = z == x2 ? 0 : 1; | |
1964 | for ( z = y1 + shift; z < y2; z += 2 ) | |
1965 | dc.DrawPoint(x2, z); | |
1966 | ||
1967 | shift = z == y2 ? 0 : 1; | |
1968 | for ( z = x2 - shift; z > x1; z -= 2 ) | |
1969 | dc.DrawPoint(z, y2); | |
1970 | ||
1971 | shift = z == x1 ? 0 : 1; | |
1972 | for ( z = y2 - shift; z > y1; z -= 2 ) | |
1973 | dc.DrawPoint(x1, z); | |
1974 | ||
1975 | dc.SetLogicalFunction(wxCOPY); | |
1976 | #endif // 0/1 | |
1977 | } | |
1978 | ||
1979 | void wxWin32Renderer::DrawLabelShadow(wxDC& dc, | |
1980 | const wxString& label, | |
1981 | const wxRect& rect, | |
1982 | int alignment, | |
1983 | int indexAccel) | |
1984 | { | |
1985 | // draw shadow of the text | |
1986 | dc.SetTextForeground(m_colHighlight); | |
1987 | wxRect rectShadow = rect; | |
1988 | rectShadow.x++; | |
1989 | rectShadow.y++; | |
1990 | dc.DrawLabel(label, rectShadow, alignment, indexAccel); | |
1991 | ||
1992 | // make the text grey | |
1993 | dc.SetTextForeground(m_colDarkGrey); | |
1994 | } | |
1995 | ||
1996 | void wxWin32Renderer::DrawLabel(wxDC& dc, | |
1997 | const wxString& label, | |
1998 | const wxRect& rect, | |
1999 | int flags, | |
2000 | int alignment, | |
2001 | int indexAccel, | |
2002 | wxRect *rectBounds) | |
2003 | { | |
2004 | DoDrawLabel(dc, label, rect, flags, alignment, indexAccel, rectBounds); | |
2005 | } | |
2006 | ||
2007 | void wxWin32Renderer::DoDrawLabel(wxDC& dc, | |
2008 | const wxString& label, | |
2009 | const wxRect& rect, | |
2010 | int flags, | |
2011 | int alignment, | |
2012 | int indexAccel, | |
2013 | wxRect *rectBounds, | |
2014 | const wxPoint& focusOffset) | |
2015 | { | |
2016 | // the underscores are not drawn for focused controls in wxMSW | |
2017 | if ( flags & wxCONTROL_FOCUSED ) | |
2018 | { | |
2019 | indexAccel = -1; | |
2020 | } | |
2021 | ||
2022 | if ( flags & wxCONTROL_DISABLED ) | |
2023 | { | |
2024 | // the combination of wxCONTROL_SELECTED and wxCONTROL_DISABLED | |
2025 | // currently only can happen for a menu item and it seems that Windows | |
2026 | // doesn't draw the shadow in this case, so we don't do it neither | |
2027 | if ( flags & wxCONTROL_SELECTED ) | |
2028 | { | |
2029 | // just make the label text greyed out | |
2030 | dc.SetTextForeground(m_colDarkGrey); | |
2031 | } | |
2032 | else // draw normal disabled label | |
2033 | { | |
2034 | DrawLabelShadow(dc, label, rect, alignment, indexAccel); | |
2035 | } | |
2036 | } | |
2037 | ||
2038 | wxRect rectLabel; | |
2039 | dc.DrawLabel(label, wxNullBitmap, rect, alignment, indexAccel, &rectLabel); | |
2040 | ||
2041 | if ( flags & wxCONTROL_DISABLED ) | |
2042 | { | |
2043 | // restore the fg colour | |
2044 | dc.SetTextForeground(*wxBLACK); | |
2045 | } | |
2046 | ||
2047 | if ( flags & wxCONTROL_FOCUSED ) | |
2048 | { | |
2049 | if ( focusOffset.x || focusOffset.y ) | |
2050 | { | |
1e6feb95 VZ |
2051 | rectLabel.Inflate(focusOffset.x, focusOffset.y); |
2052 | } | |
2053 | ||
2054 | DrawFocusRect(dc, rectLabel); | |
2055 | } | |
2056 | ||
2057 | if ( rectBounds ) | |
2058 | *rectBounds = rectLabel; | |
2059 | } | |
2060 | ||
2061 | void wxWin32Renderer::DrawButtonLabel(wxDC& dc, | |
2062 | const wxString& label, | |
2063 | const wxBitmap& image, | |
2064 | const wxRect& rect, | |
2065 | int flags, | |
2066 | int alignment, | |
2067 | int indexAccel, | |
2068 | wxRect *rectBounds) | |
2069 | { | |
2070 | // the underscores are not drawn for focused controls in wxMSW | |
2071 | if ( flags & wxCONTROL_PRESSED ) | |
2072 | { | |
2073 | indexAccel = -1; | |
2074 | } | |
2075 | ||
2076 | wxRect rectLabel = rect; | |
2077 | if ( !label.empty() ) | |
2078 | { | |
2079 | // shift the label if a button is pressed | |
2080 | if ( flags & wxCONTROL_PRESSED ) | |
2081 | { | |
2082 | rectLabel.x++; | |
2083 | rectLabel.y++; | |
2084 | } | |
2085 | ||
2086 | if ( flags & wxCONTROL_DISABLED ) | |
2087 | { | |
2088 | DrawLabelShadow(dc, label, rectLabel, alignment, indexAccel); | |
2089 | } | |
2090 | ||
2091 | // leave enough space for the focus rectangle | |
2092 | if ( flags & wxCONTROL_FOCUSED ) | |
2093 | { | |
2094 | rectLabel.Inflate(-2); | |
2095 | } | |
2096 | } | |
2097 | ||
2098 | dc.DrawLabel(label, image, rectLabel, alignment, indexAccel, rectBounds); | |
2099 | ||
2100 | if ( !label.empty() && (flags & wxCONTROL_FOCUSED) ) | |
2101 | { | |
2102 | if ( flags & wxCONTROL_PRESSED ) | |
2103 | { | |
2104 | // the focus rectangle is never pressed, so undo the shift done | |
2105 | // above | |
2106 | rectLabel.x--; | |
2107 | rectLabel.y--; | |
2108 | rectLabel.width--; | |
2109 | rectLabel.height--; | |
2110 | } | |
2111 | ||
2112 | DrawFocusRect(dc, rectLabel); | |
2113 | } | |
2114 | } | |
2115 | ||
2116 | // ---------------------------------------------------------------------------- | |
2117 | // (check)listbox items | |
2118 | // ---------------------------------------------------------------------------- | |
2119 | ||
2120 | void wxWin32Renderer::DrawItem(wxDC& dc, | |
2121 | const wxString& label, | |
2122 | const wxRect& rect, | |
2123 | int flags) | |
2124 | { | |
2125 | wxDCTextColourChanger colChanger(dc); | |
2126 | ||
2127 | if ( flags & wxCONTROL_SELECTED ) | |
2128 | { | |
2129 | colChanger.Set(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT)); | |
2130 | ||
2131 | wxColour colBg = wxSCHEME_COLOUR(m_scheme, HIGHLIGHT); | |
2132 | dc.SetBrush(wxBrush(colBg, wxSOLID)); | |
2133 | dc.SetPen(wxPen(colBg, 0, wxSOLID)); | |
2134 | dc.DrawRectangle(rect); | |
2135 | } | |
2136 | ||
2137 | wxRect rectText = rect; | |
2138 | rectText.x += 2; | |
2139 | rectText.width -= 2; | |
2140 | dc.DrawLabel(label, wxNullBitmap, rectText); | |
2141 | ||
2142 | if ( flags & wxCONTROL_FOCUSED ) | |
2143 | { | |
2144 | DrawFocusRect(dc, rect); | |
2145 | } | |
2146 | } | |
2147 | ||
2148 | void wxWin32Renderer::DrawCheckItem(wxDC& dc, | |
2149 | const wxString& label, | |
2150 | const wxBitmap& bitmap, | |
2151 | const wxRect& rect, | |
2152 | int flags) | |
2153 | { | |
2154 | wxBitmap bmp; | |
2155 | if ( bitmap.Ok() ) | |
2156 | { | |
2157 | bmp = bitmap; | |
2158 | } | |
2159 | else // use default bitmap | |
2160 | { | |
2161 | bmp = wxBitmap(flags & wxCONTROL_CHECKED ? checked_item_xpm | |
2162 | : unchecked_item_xpm); | |
2163 | } | |
2164 | ||
2165 | dc.DrawBitmap(bmp, rect.x, rect.y + (rect.height - bmp.GetHeight()) / 2 - 1, | |
2166 | TRUE /* use mask */); | |
2167 | ||
2168 | wxRect rectLabel = rect; | |
2169 | int bmpWidth = bmp.GetWidth(); | |
2170 | rectLabel.x += bmpWidth; | |
2171 | rectLabel.width -= bmpWidth; | |
2172 | ||
2173 | DrawItem(dc, label, rectLabel, flags); | |
2174 | } | |
2175 | ||
2176 | // ---------------------------------------------------------------------------- | |
2177 | // check/radio buttons | |
2178 | // ---------------------------------------------------------------------------- | |
2179 | ||
2180 | wxBitmap wxWin32Renderer::GetIndicator(IndicatorType indType, int flags) | |
2181 | { | |
2182 | IndicatorState indState; | |
2183 | if ( flags & wxCONTROL_SELECTED ) | |
2184 | indState = flags & wxCONTROL_DISABLED ? IndicatorState_SelectedDisabled | |
2185 | : IndicatorState_Selected; | |
2186 | else if ( flags & wxCONTROL_DISABLED ) | |
2187 | indState = IndicatorState_Disabled; | |
2188 | else if ( flags & wxCONTROL_PRESSED ) | |
2189 | indState = IndicatorState_Pressed; | |
2190 | else | |
2191 | indState = IndicatorState_Normal; | |
2192 | ||
2193 | IndicatorStatus indStatus = flags & wxCONTROL_CHECKED | |
2194 | ? IndicatorStatus_Checked | |
2195 | : IndicatorStatus_Unchecked; | |
2196 | ||
2197 | const char **xpm = bmpIndicators[indType][indState][indStatus]; | |
54a96d02 JS |
2198 | if (xpm) |
2199 | { | |
2200 | wxBitmap bmp(xpm); | |
2201 | return bmp; | |
2202 | } | |
2203 | else | |
2204 | return wxNullBitmap; | |
1e6feb95 VZ |
2205 | } |
2206 | ||
2207 | void wxWin32Renderer::DrawCheckOrRadioButton(wxDC& dc, | |
2208 | const wxString& label, | |
2209 | const wxBitmap& bitmap, | |
2210 | const wxRect& rect, | |
2211 | int flags, | |
2212 | wxAlignment align, | |
2213 | int indexAccel, | |
2214 | wxCoord focusOffsetY) | |
2215 | { | |
2216 | // calculate the position of the bitmap and of the label | |
2217 | wxCoord heightBmp = bitmap.GetHeight(); | |
2218 | wxCoord xBmp, | |
2219 | yBmp = rect.y + (rect.height - heightBmp) / 2; | |
2220 | ||
2221 | wxRect rectLabel; | |
2222 | dc.GetMultiLineTextExtent(label, NULL, &rectLabel.height); | |
2223 | rectLabel.y = rect.y + (rect.height - rectLabel.height) / 2; | |
2224 | ||
2225 | // align label vertically with the bitmap - looks nicer like this | |
2226 | rectLabel.y -= (rectLabel.height - heightBmp) % 2; | |
2227 | ||
2228 | // calc horz position | |
2229 | if ( align == wxALIGN_RIGHT ) | |
2230 | { | |
2231 | xBmp = rect.GetRight() - bitmap.GetWidth(); | |
2232 | rectLabel.x = rect.x + 3; | |
2233 | rectLabel.SetRight(xBmp); | |
2234 | } | |
2235 | else // normal (checkbox to the left of the text) case | |
2236 | { | |
2237 | xBmp = rect.x; | |
2238 | rectLabel.x = xBmp + bitmap.GetWidth() + 5; | |
2239 | rectLabel.SetRight(rect.GetRight()); | |
2240 | } | |
2241 | ||
2242 | dc.DrawBitmap(bitmap, xBmp, yBmp, TRUE /* use mask */); | |
2243 | ||
2244 | DoDrawLabel( | |
2245 | dc, label, rectLabel, | |
2246 | flags, | |
2247 | wxALIGN_LEFT | wxALIGN_TOP, | |
2248 | indexAccel, | |
2249 | NULL, // we don't need bounding rect | |
2250 | // use custom vert focus rect offset | |
2251 | wxPoint(FOCUS_RECT_OFFSET_X, focusOffsetY) | |
2252 | ); | |
2253 | } | |
2254 | ||
2255 | void wxWin32Renderer::DrawRadioButton(wxDC& dc, | |
2256 | const wxString& label, | |
2257 | const wxBitmap& bitmap, | |
2258 | const wxRect& rect, | |
2259 | int flags, | |
2260 | wxAlignment align, | |
2261 | int indexAccel) | |
2262 | { | |
54a96d02 JS |
2263 | if (bitmap.Ok()) |
2264 | DrawCheckOrRadioButton(dc, label, | |
2265 | bitmap, | |
2266 | rect, flags, align, indexAccel, | |
2267 | FOCUS_RECT_OFFSET_Y); // default focus rect offset | |
2268 | else | |
2269 | { | |
2270 | wxBitmap rbitmap(GetRadioBitmap(flags)); | |
2271 | DrawCheckOrRadioButton(dc, label, | |
2272 | rbitmap, | |
1e6feb95 | 2273 | rect, flags, align, indexAccel, |
54a96d02 JS |
2274 | FOCUS_RECT_OFFSET_Y); // default focus rect offset |
2275 | } | |
1e6feb95 VZ |
2276 | } |
2277 | ||
2278 | void wxWin32Renderer::DrawCheckButton(wxDC& dc, | |
2279 | const wxString& label, | |
2280 | const wxBitmap& bitmap, | |
2281 | const wxRect& rect, | |
2282 | int flags, | |
2283 | wxAlignment align, | |
2284 | int indexAccel) | |
2285 | { | |
54a96d02 JS |
2286 | if (bitmap.Ok()) |
2287 | DrawCheckOrRadioButton(dc, label, | |
2288 | bitmap, | |
2289 | rect, flags, align, indexAccel, | |
2290 | 0); // no focus rect offset for checkboxes | |
2291 | else | |
2292 | { | |
d7552cab | 2293 | wxBitmap cbitmap(GetCheckBitmap(flags)); |
54a96d02 JS |
2294 | DrawCheckOrRadioButton(dc, label, |
2295 | cbitmap, | |
2296 | rect, flags, align, indexAccel, | |
2297 | 0); // no focus rect offset for checkboxes | |
2298 | } | |
1e6feb95 VZ |
2299 | } |
2300 | ||
2301 | // ---------------------------------------------------------------------------- | |
2302 | // text control | |
2303 | // ---------------------------------------------------------------------------- | |
2304 | ||
2305 | void wxWin32Renderer::DrawTextLine(wxDC& dc, | |
2306 | const wxString& text, | |
2307 | const wxRect& rect, | |
2308 | int selStart, | |
2309 | int selEnd, | |
2310 | int flags) | |
2311 | { | |
2312 | // nothing special to do here | |
2313 | StandardDrawTextLine(dc, text, rect, selStart, selEnd, flags); | |
2314 | } | |
2315 | ||
2316 | void wxWin32Renderer::DrawLineWrapMark(wxDC& dc, const wxRect& rect) | |
2317 | { | |
2318 | // we don't draw them | |
2319 | } | |
2320 | ||
2321 | // ---------------------------------------------------------------------------- | |
2322 | // notebook | |
2323 | // ---------------------------------------------------------------------------- | |
2324 | ||
2325 | void wxWin32Renderer::DrawTab(wxDC& dc, | |
2326 | const wxRect& rectOrig, | |
2327 | wxDirection dir, | |
2328 | const wxString& label, | |
2329 | const wxBitmap& bitmap, | |
2330 | int flags, | |
2331 | int indexAccel) | |
2332 | { | |
2333 | wxRect rect = rectOrig; | |
2334 | ||
2335 | // the current tab is drawn indented (to the top for default case) and | |
2336 | // bigger than the other ones | |
2337 | const wxSize indent = GetTabIndent(); | |
2338 | if ( flags & wxCONTROL_SELECTED ) | |
2339 | { | |
2340 | switch ( dir ) | |
2341 | { | |
2342 | default: | |
2343 | wxFAIL_MSG(_T("invaild notebook tab orientation")); | |
2344 | // fall through | |
2345 | ||
2346 | case wxTOP: | |
2347 | rect.Inflate(indent.x, 0); | |
2348 | rect.y -= indent.y; | |
2349 | rect.height += indent.y; | |
2350 | break; | |
2351 | ||
2352 | case wxBOTTOM: | |
2353 | rect.Inflate(indent.x, 0); | |
2354 | rect.height += indent.y; | |
2355 | break; | |
2356 | ||
2357 | case wxLEFT: | |
2358 | case wxRIGHT: | |
2359 | wxFAIL_MSG(_T("TODO")); | |
2360 | break; | |
2361 | } | |
2362 | } | |
2363 | ||
2364 | // draw the text, image and the focus around them (if necessary) | |
2365 | wxRect rectLabel = rect; | |
2366 | rectLabel.Deflate(1, 1); | |
2367 | DrawButtonLabel(dc, label, bitmap, rectLabel, | |
2368 | flags, wxALIGN_CENTRE, indexAccel); | |
2369 | ||
2370 | // now draw the tab border itself (maybe use DrawRoundedRectangle()?) | |
2371 | static const wxCoord CUTOFF = 2; // radius of the rounded corner | |
2372 | wxCoord x = rect.x, | |
2373 | y = rect.y, | |
2374 | x2 = rect.GetRight(), | |
2375 | y2 = rect.GetBottom(); | |
2376 | ||
2377 | // FIXME: all this code will break if the tab indent or the border width, | |
2378 | // it is tied to the fact that both of them are equal to 2 | |
2379 | switch ( dir ) | |
2380 | { | |
2381 | default: | |
2382 | case wxTOP: | |
2383 | dc.SetPen(m_penHighlight); | |
2384 | dc.DrawLine(x, y2, x, y + CUTOFF); | |
2385 | dc.DrawLine(x, y + CUTOFF, x + CUTOFF, y); | |
2386 | dc.DrawLine(x + CUTOFF, y, x2 - CUTOFF + 1, y); | |
2387 | ||
2388 | dc.SetPen(m_penBlack); | |
2389 | dc.DrawLine(x2, y2, x2, y + CUTOFF); | |
2390 | dc.DrawLine(x2, y + CUTOFF, x2 - CUTOFF, y); | |
2391 | ||
2392 | dc.SetPen(m_penDarkGrey); | |
2393 | dc.DrawLine(x2 - 1, y2, x2 - 1, y + CUTOFF - 1); | |
2394 | ||
2395 | if ( flags & wxCONTROL_SELECTED ) | |
2396 | { | |
2397 | dc.SetPen(m_penLightGrey); | |
2398 | ||
2399 | // overwrite the part of the border below this tab | |
2400 | dc.DrawLine(x + 1, y2 + 1, x2 - 1, y2 + 1); | |
2401 | ||
2402 | // and the shadow of the tab to the left of us | |
2403 | dc.DrawLine(x + 1, y + CUTOFF + 1, x + 1, y2 + 1); | |
2404 | } | |
2405 | break; | |
2406 | ||
2407 | case wxBOTTOM: | |
2408 | dc.SetPen(m_penHighlight); | |
2409 | // we need to continue one pixel further to overwrite the corner of | |
2410 | // the border for the selected tab | |
2411 | dc.DrawLine(x, y - (flags & wxCONTROL_SELECTED ? 1 : 0), | |
2412 | x, y2 - CUTOFF); | |
2413 | dc.DrawLine(x, y2 - CUTOFF, x + CUTOFF, y2); | |
2414 | ||
2415 | dc.SetPen(m_penBlack); | |
2416 | dc.DrawLine(x + CUTOFF, y2, x2 - CUTOFF + 1, y2); | |
2417 | dc.DrawLine(x2, y, x2, y2 - CUTOFF); | |
2418 | dc.DrawLine(x2, y2 - CUTOFF, x2 - CUTOFF, y2); | |
2419 | ||
2420 | dc.SetPen(m_penDarkGrey); | |
2421 | dc.DrawLine(x + CUTOFF, y2 - 1, x2 - CUTOFF + 1, y2 - 1); | |
2422 | dc.DrawLine(x2 - 1, y, x2 - 1, y2 - CUTOFF + 1); | |
2423 | ||
2424 | if ( flags & wxCONTROL_SELECTED ) | |
2425 | { | |
2426 | dc.SetPen(m_penLightGrey); | |
2427 | ||
2428 | // overwrite the part of the (double!) border above this tab | |
2429 | dc.DrawLine(x + 1, y - 1, x2 - 1, y - 1); | |
2430 | dc.DrawLine(x + 1, y - 2, x2 - 1, y - 2); | |
2431 | ||
2432 | // and the shadow of the tab to the left of us | |
2433 | dc.DrawLine(x + 1, y2 - CUTOFF, x + 1, y - 1); | |
2434 | } | |
2435 | break; | |
2436 | ||
2437 | case wxLEFT: | |
2438 | case wxRIGHT: | |
2439 | wxFAIL_MSG(_T("TODO")); | |
2440 | } | |
2441 | } | |
2442 | ||
2443 | // ---------------------------------------------------------------------------- | |
2444 | // slider | |
2445 | // ---------------------------------------------------------------------------- | |
2446 | ||
2447 | wxSize wxWin32Renderer::GetSliderThumbSize(const wxRect& rect, | |
2448 | wxOrientation orient) const | |
2449 | { | |
2450 | wxSize size; | |
2451 | ||
2452 | wxRect rectShaft = GetSliderShaftRect(rect, orient); | |
2453 | if ( orient == wxHORIZONTAL ) | |
2454 | { | |
2455 | size.y = rect.height - 6; | |
2456 | size.x = wxMin(size.y / 2, rectShaft.width); | |
2457 | } | |
2458 | else // vertical | |
2459 | { | |
2460 | size.x = rect.width - 6; | |
2461 | size.y = wxMin(size.x / 2, rectShaft.height); | |
2462 | } | |
2463 | ||
2464 | return size; | |
2465 | } | |
2466 | ||
2467 | wxRect wxWin32Renderer::GetSliderShaftRect(const wxRect& rectOrig, | |
2468 | wxOrientation orient) const | |
2469 | { | |
2470 | static const wxCoord SLIDER_MARGIN = 6; | |
2471 | ||
2472 | wxRect rect = rectOrig; | |
2473 | ||
2474 | if ( orient == wxHORIZONTAL ) | |
2475 | { | |
2476 | // make the rect of minimal width and centre it | |
2477 | rect.height = 2*BORDER_THICKNESS; | |
2478 | rect.y = rectOrig.y + (rectOrig.height - rect.height) / 2; | |
2479 | if ( rect.y < 0 ) | |
2480 | rect.y = 0; | |
2481 | ||
2482 | // leave margins on the sides | |
2483 | rect.Deflate(SLIDER_MARGIN, 0); | |
2484 | } | |
2485 | else // vertical | |
2486 | { | |
2487 | // same as above but in other direction | |
2488 | rect.width = 2*BORDER_THICKNESS; | |
2489 | rect.x = rectOrig.x + (rectOrig.width - rect.width) / 2; | |
2490 | if ( rect.x < 0 ) | |
2491 | rect.x = 0; | |
2492 | ||
2493 | rect.Deflate(0, SLIDER_MARGIN); | |
2494 | } | |
2495 | ||
2496 | return rect; | |
2497 | } | |
2498 | ||
2499 | void wxWin32Renderer::DrawSliderShaft(wxDC& dc, | |
2500 | const wxRect& rectOrig, | |
2501 | wxOrientation orient, | |
2502 | int flags, | |
2503 | wxRect *rectShaft) | |
2504 | { | |
2505 | if ( flags & wxCONTROL_FOCUSED ) | |
2506 | { | |
2507 | DrawFocusRect(dc, rectOrig); | |
2508 | } | |
2509 | ||
2510 | wxRect rect = GetSliderShaftRect(rectOrig, orient); | |
2511 | ||
2512 | if ( rectShaft ) | |
2513 | *rectShaft = rect; | |
2514 | ||
2515 | DrawSunkenBorder(dc, &rect); | |
2516 | } | |
2517 | ||
2518 | void wxWin32Renderer::DrawSliderThumb(wxDC& dc, | |
2519 | const wxRect& rect, | |
2520 | wxOrientation orient, | |
2521 | int flags) | |
2522 | { | |
2523 | /* | |
2524 | we are drawing a shape of this form | |
2525 | ||
2526 | HHHHHHB <--- y | |
2527 | H DB | |
2528 | H DB | |
2529 | H DB where H is hightlight colour | |
2530 | H DB D dark grey | |
2531 | H DB B black | |
2532 | H DB | |
2533 | H DB <--- y3 | |
2534 | H DB | |
2535 | HDB | |
2536 | B <--- y2 | |
2537 | ||
2538 | ^ ^ ^ | |
2539 | | | | | |
2540 | x x3 x2 | |
2541 | ||
2542 | The interior of this shape is filled with the hatched brush if the thumb | |
2543 | is pressed. | |
2544 | */ | |
2545 | ||
2546 | DrawBackground(dc, wxNullColour, rect, flags); | |
2547 | ||
2548 | bool transpose = orient == wxVERTICAL; | |
2549 | ||
2550 | wxCoord x, y, x2, y2; | |
2551 | if ( transpose ) | |
2552 | { | |
2553 | x = rect.y; | |
2554 | y = rect.x; | |
2555 | x2 = rect.GetBottom(); | |
2556 | y2 = rect.GetRight(); | |
2557 | } | |
2558 | else | |
2559 | { | |
2560 | x = rect.x; | |
2561 | y = rect.y; | |
2562 | x2 = rect.GetRight(); | |
2563 | y2 = rect.GetBottom(); | |
2564 | } | |
2565 | ||
2566 | // the size of the pointed part of the thumb | |
2567 | wxCoord sizeArrow = (transpose ? rect.height : rect.width) / 2; | |
2568 | ||
2569 | wxCoord x3 = x + sizeArrow, | |
2570 | y3 = y2 - sizeArrow; | |
2571 | ||
2572 | dc.SetPen(m_penHighlight); | |
2573 | DrawLine(dc, x, y, x2, y, transpose); | |
2574 | DrawLine(dc, x, y + 1, x, y2 - sizeArrow, transpose); | |
2575 | DrawLine(dc, x, y3, x3, y2, transpose); | |
2576 | ||
2577 | dc.SetPen(m_penBlack); | |
2578 | DrawLine(dc, x3, y2, x2, y3, transpose); | |
2579 | DrawLine(dc, x2, y3, x2, y - 1, transpose); | |
2580 | ||
2581 | dc.SetPen(m_penDarkGrey); | |
2582 | DrawLine(dc, x3, y2 - 1, x2 - 1, y3, transpose); | |
2583 | DrawLine(dc, x2 - 1, y3, x2 - 1, y, transpose); | |
2584 | ||
2585 | if ( flags & wxCONTROL_PRESSED ) | |
2586 | { | |
2587 | // TODO: MSW fills the entire area inside, not just the rect | |
2588 | wxRect rectInt = rect; | |
2589 | if ( transpose ) | |
2590 | rectInt.SetRight(y3); | |
2591 | else | |
2592 | rectInt.SetBottom(y3); | |
2593 | rectInt.Deflate(2); | |
2594 | ||
63f06c22 | 2595 | #if !defined(__WXMGL__) |
1e6feb95 VZ |
2596 | static const char *stipple_xpm[] = { |
2597 | /* columns rows colors chars-per-pixel */ | |
2598 | "2 2 2 1", | |
2599 | " c None", | |
2600 | "w c white", | |
2601 | /* pixels */ | |
2602 | "w ", | |
2603 | " w", | |
2604 | }; | |
63f06c22 VS |
2605 | #else |
2606 | // VS: MGL can only do 8x8 stipple brushes | |
2607 | static const char *stipple_xpm[] = { | |
2608 | /* columns rows colors chars-per-pixel */ | |
2609 | "8 8 2 1", | |
2610 | " c None", | |
2611 | "w c white", | |
2612 | /* pixels */ | |
2613 | "w w w w ", | |
2614 | " w w w w", | |
2615 | "w w w w ", | |
2616 | " w w w w", | |
2617 | "w w w w ", | |
2618 | " w w w w", | |
2619 | "w w w w ", | |
2620 | " w w w w", | |
2621 | }; | |
2622 | #endif | |
1e6feb95 VZ |
2623 | dc.SetBrush(wxBrush(stipple_xpm)); |
2624 | ||
2625 | dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, SHADOW_HIGHLIGHT)); | |
2626 | dc.SetTextBackground(wxSCHEME_COLOUR(m_scheme, CONTROL)); | |
2627 | dc.SetPen(*wxTRANSPARENT_PEN); | |
2628 | dc.DrawRectangle(rectInt); | |
2629 | } | |
2630 | } | |
2631 | ||
2632 | void wxWin32Renderer::DrawSliderTicks(wxDC& dc, | |
2633 | const wxRect& rect, | |
2634 | const wxSize& sizeThumb, | |
2635 | wxOrientation orient, | |
2636 | int start, | |
2637 | int end, | |
2638 | int step, | |
2639 | int flags) | |
2640 | { | |
2641 | if ( end == start ) | |
2642 | { | |
2643 | // empty slider? | |
2644 | return; | |
2645 | } | |
2646 | ||
2647 | // the variable names correspond to horizontal case, but they can be used | |
2648 | // for both orientations | |
2649 | wxCoord x1, x2, y1, y2, len, widthThumb; | |
2650 | if ( orient == wxHORIZONTAL ) | |
2651 | { | |
2652 | x1 = rect.GetLeft(); | |
2653 | x2 = rect.GetRight(); | |
2654 | ||
2655 | // draw from bottom to top to leave one pixel space between the ticks | |
2656 | // and the slider as Windows do | |
2657 | y1 = rect.GetBottom(); | |
2658 | y2 = rect.GetTop(); | |
2659 | ||
2660 | len = rect.width; | |
2661 | ||
2662 | widthThumb = sizeThumb.x; | |
2663 | } | |
2664 | else // vertical | |
2665 | { | |
2666 | x1 = rect.GetTop(); | |
2667 | x2 = rect.GetBottom(); | |
2668 | ||
2669 | y1 = rect.GetRight(); | |
2670 | y2 = rect.GetLeft(); | |
2671 | ||
2672 | len = rect.height; | |
2673 | ||
2674 | widthThumb = sizeThumb.y; | |
2675 | } | |
2676 | ||
2677 | // the first tick should be positioned in such way that a thumb drawn in | |
2678 | // the first position points down directly to it | |
2679 | x1 += widthThumb / 2; | |
2680 | x2 -= widthThumb / 2; | |
2681 | ||
2682 | // this also means that we have slightly less space for the ticks in | |
2683 | // between the first and the last | |
2684 | len -= widthThumb; | |
2685 | ||
2686 | dc.SetPen(m_penBlack); | |
2687 | ||
2688 | int range = end - start; | |
2689 | for ( int n = 0; n < range; n += step ) | |
2690 | { | |
2691 | wxCoord x = x1 + (len*n) / range; | |
2692 | ||
2693 | DrawLine(dc, x, y1, x, y2, orient == wxVERTICAL); | |
2694 | } | |
2695 | ||
2696 | // always draw the line at the end position | |
2697 | DrawLine(dc, x2, y1, x2, y2, orient == wxVERTICAL); | |
2698 | } | |
2699 | ||
2700 | // ---------------------------------------------------------------------------- | |
2701 | // menu and menubar | |
2702 | // ---------------------------------------------------------------------------- | |
2703 | ||
2704 | // wxWin32MenuGeometryInfo: the wxMenuGeometryInfo used by wxWin32Renderer | |
2705 | class WXDLLEXPORT wxWin32MenuGeometryInfo : public wxMenuGeometryInfo | |
2706 | { | |
2707 | public: | |
2708 | virtual wxSize GetSize() const { return m_size; } | |
2709 | ||
2710 | wxCoord GetLabelOffset() const { return m_ofsLabel; } | |
2711 | wxCoord GetAccelOffset() const { return m_ofsAccel; } | |
2712 | ||
2713 | wxCoord GetItemHeight() const { return m_heightItem; } | |
2714 | ||
2715 | private: | |
2716 | // the total size of the menu | |
2717 | wxSize m_size; | |
2718 | ||
2719 | // the offset of the start of the menu item label | |
2720 | wxCoord m_ofsLabel; | |
2721 | ||
2722 | // the offset of the start of the accel label | |
2723 | wxCoord m_ofsAccel; | |
2724 | ||
2725 | // the height of a normal (not separator) item | |
2726 | wxCoord m_heightItem; | |
2727 | ||
71e03035 VZ |
2728 | friend wxMenuGeometryInfo * |
2729 | wxWin32Renderer::GetMenuGeometry(wxWindow *, const wxMenu&) const; | |
1e6feb95 VZ |
2730 | }; |
2731 | ||
2732 | // FIXME: all constants are hardcoded but shouldn't be | |
2733 | static const wxCoord MENU_LEFT_MARGIN = 9; | |
2734 | static const wxCoord MENU_RIGHT_MARGIN = 18; | |
2735 | static const wxCoord MENU_VERT_MARGIN = 3; | |
2736 | ||
2737 | // the margin around bitmap/check marks (on each side) | |
2738 | static const wxCoord MENU_BMP_MARGIN = 2; | |
2739 | ||
2740 | // the margin between the labels and accel strings | |
2741 | static const wxCoord MENU_ACCEL_MARGIN = 8; | |
2742 | ||
2743 | // the separator height in pixels: in fact, strangely enough, the real height | |
2744 | // is 2 but Windows adds one extra pixel in the bottom margin, so take it into | |
2745 | // account here | |
2746 | static const wxCoord MENU_SEPARATOR_HEIGHT = 3; | |
2747 | ||
2748 | // the size of the standard checkmark bitmap | |
2749 | static const wxCoord MENU_CHECK_SIZE = 9; | |
2750 | ||
2751 | void wxWin32Renderer::DrawMenuBarItem(wxDC& dc, | |
2752 | const wxRect& rectOrig, | |
2753 | const wxString& label, | |
2754 | int flags, | |
2755 | int indexAccel) | |
2756 | { | |
2757 | wxRect rect = rectOrig; | |
2758 | rect.height--; | |
2759 | ||
2760 | wxDCTextColourChanger colChanger(dc); | |
2761 | ||
2762 | if ( flags & wxCONTROL_SELECTED ) | |
2763 | { | |
2764 | colChanger.Set(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT)); | |
2765 | ||
2766 | wxColour colBg = wxSCHEME_COLOUR(m_scheme, HIGHLIGHT); | |
2767 | dc.SetBrush(wxBrush(colBg, wxSOLID)); | |
2768 | dc.SetPen(wxPen(colBg, 0, wxSOLID)); | |
2769 | dc.DrawRectangle(rect); | |
2770 | } | |
2771 | ||
2772 | // don't draw the focus rect around menu bar items | |
2773 | DrawLabel(dc, label, rect, flags & ~wxCONTROL_FOCUSED, | |
2774 | wxALIGN_CENTRE, indexAccel); | |
2775 | } | |
2776 | ||
2777 | void wxWin32Renderer::DrawMenuItem(wxDC& dc, | |
2778 | wxCoord y, | |
2779 | const wxMenuGeometryInfo& gi, | |
2780 | const wxString& label, | |
2781 | const wxString& accel, | |
2782 | const wxBitmap& bitmap, | |
2783 | int flags, | |
2784 | int indexAccel) | |
2785 | { | |
2786 | const wxWin32MenuGeometryInfo& geometryInfo = | |
2787 | (const wxWin32MenuGeometryInfo&)gi; | |
2788 | ||
2789 | wxRect rect; | |
2790 | rect.x = 0; | |
2791 | rect.y = y; | |
2792 | rect.width = geometryInfo.GetSize().x; | |
2793 | rect.height = geometryInfo.GetItemHeight(); | |
2794 | ||
2795 | // draw the selected item specially | |
2796 | wxDCTextColourChanger colChanger(dc); | |
2797 | if ( flags & wxCONTROL_SELECTED ) | |
2798 | { | |
2799 | colChanger.Set(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT)); | |
2800 | ||
2801 | wxColour colBg = wxSCHEME_COLOUR(m_scheme, HIGHLIGHT); | |
2802 | dc.SetBrush(wxBrush(colBg, wxSOLID)); | |
2803 | dc.SetPen(wxPen(colBg, 0, wxSOLID)); | |
2804 | dc.DrawRectangle(rect); | |
2805 | } | |
2806 | ||
2807 | // draw the bitmap: use the bitmap provided or the standard checkmark for | |
2808 | // the checkable items | |
2809 | wxBitmap bmp = bitmap; | |
2810 | if ( !bmp.Ok() && (flags & wxCONTROL_CHECKED) ) | |
2811 | { | |
2812 | bmp = GetIndicator(IndicatorType_Menu, flags); | |
2813 | } | |
2814 | ||
2815 | if ( bmp.Ok() ) | |
2816 | { | |
2817 | rect.SetRight(geometryInfo.GetLabelOffset()); | |
2818 | wxControlRenderer::DrawBitmap(dc, bmp, rect); | |
2819 | } | |
2820 | ||
2821 | // draw the label | |
2822 | rect.x = geometryInfo.GetLabelOffset(); | |
2823 | rect.SetRight(geometryInfo.GetAccelOffset()); | |
2824 | ||
2825 | DrawLabel(dc, label, rect, flags, wxALIGN_CENTRE_VERTICAL, indexAccel); | |
2826 | ||
2827 | // draw the accel string | |
2828 | rect.x = geometryInfo.GetAccelOffset(); | |
2829 | rect.SetRight(geometryInfo.GetSize().x); | |
2830 | ||
2831 | // NB: no accel index here | |
2832 | DrawLabel(dc, accel, rect, flags, wxALIGN_CENTRE_VERTICAL); | |
2833 | ||
2834 | // draw the submenu indicator | |
2835 | if ( flags & wxCONTROL_ISSUBMENU ) | |
2836 | { | |
2837 | rect.x = geometryInfo.GetSize().x - MENU_RIGHT_MARGIN; | |
2838 | rect.width = MENU_RIGHT_MARGIN; | |
2839 | ||
2840 | wxArrowStyle arrowStyle; | |
2841 | if ( flags & wxCONTROL_DISABLED ) | |
2842 | arrowStyle = flags & wxCONTROL_SELECTED ? Arrow_InversedDisabled | |
2843 | : Arrow_Disabled; | |
2844 | else if ( flags & wxCONTROL_SELECTED ) | |
2845 | arrowStyle = Arrow_Inversed; | |
2846 | else | |
2847 | arrowStyle = Arrow_Normal; | |
2848 | ||
2849 | DrawArrow(dc, rect, Arrow_Right, arrowStyle); | |
2850 | } | |
2851 | } | |
2852 | ||
2853 | void wxWin32Renderer::DrawMenuSeparator(wxDC& dc, | |
2854 | wxCoord y, | |
2855 | const wxMenuGeometryInfo& geomInfo) | |
2856 | { | |
2857 | DrawHorizontalLine(dc, y + MENU_VERT_MARGIN, 0, geomInfo.GetSize().x); | |
2858 | } | |
2859 | ||
2860 | wxSize wxWin32Renderer::GetMenuBarItemSize(const wxSize& sizeText) const | |
2861 | { | |
2862 | wxSize size = sizeText; | |
2863 | ||
2864 | // FIXME: menubar height is configurable under Windows | |
2865 | size.x += 12; | |
2866 | size.y += 6; | |
2867 | ||
2868 | return size; | |
2869 | } | |
2870 | ||
2871 | wxMenuGeometryInfo *wxWin32Renderer::GetMenuGeometry(wxWindow *win, | |
2872 | const wxMenu& menu) const | |
2873 | { | |
2874 | // prepare the dc: for now we draw all the items with the system font | |
2875 | wxClientDC dc(win); | |
a756f210 | 2876 | dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
1e6feb95 VZ |
2877 | |
2878 | // the height of a normal item | |
2879 | wxCoord heightText = dc.GetCharHeight(); | |
2880 | ||
2881 | // the total height | |
2882 | wxCoord height = 0; | |
2883 | ||
2884 | // the max length of label and accel strings: the menu width is the sum of | |
2885 | // them, even if they're for different items (as the accels should be | |
2886 | // aligned) | |
2887 | // | |
2888 | // the max length of the bitmap is never 0 as Windows always leaves enough | |
2889 | // space for a check mark indicator | |
2890 | wxCoord widthLabelMax = 0, | |
2891 | widthAccelMax = 0, | |
2892 | widthBmpMax = MENU_LEFT_MARGIN; | |
2893 | ||
2894 | for ( wxMenuItemList::Node *node = menu.GetMenuItems().GetFirst(); | |
2895 | node; | |
2896 | node = node->GetNext() ) | |
2897 | { | |
2898 | // height of this item | |
2899 | wxCoord h; | |
2900 | ||
2901 | wxMenuItem *item = node->GetData(); | |
2902 | if ( item->IsSeparator() ) | |
2903 | { | |
2904 | h = MENU_SEPARATOR_HEIGHT; | |
2905 | } | |
2906 | else // not separator | |
2907 | { | |
2908 | h = heightText; | |
2909 | ||
2910 | wxCoord widthLabel; | |
2911 | dc.GetTextExtent(item->GetLabel(), &widthLabel, NULL); | |
2912 | if ( widthLabel > widthLabelMax ) | |
2913 | { | |
2914 | widthLabelMax = widthLabel; | |
2915 | } | |
2916 | ||
2917 | wxCoord widthAccel; | |
2918 | dc.GetTextExtent(item->GetAccelString(), &widthAccel, NULL); | |
2919 | if ( widthAccel > widthAccelMax ) | |
2920 | { | |
2921 | widthAccelMax = widthAccel; | |
2922 | } | |
2923 | ||
2924 | const wxBitmap& bmp = item->GetBitmap(); | |
2925 | if ( bmp.Ok() ) | |
2926 | { | |
2927 | wxCoord widthBmp = bmp.GetWidth(); | |
2928 | if ( widthBmp > widthBmpMax ) | |
2929 | widthBmpMax = widthBmp; | |
2930 | } | |
2931 | //else if ( item->IsCheckable() ): no need to check for this as | |
2932 | // MENU_LEFT_MARGIN is big enough to show the check mark | |
2933 | } | |
2934 | ||
2935 | h += 2*MENU_VERT_MARGIN; | |
2936 | ||
2937 | // remember the item position and height | |
2938 | item->SetGeometry(height, h); | |
2939 | ||
2940 | height += h; | |
2941 | } | |
2942 | ||
2943 | // bundle the metrics into a struct and return it | |
2944 | wxWin32MenuGeometryInfo *gi = new wxWin32MenuGeometryInfo; | |
2945 | ||
2946 | gi->m_ofsLabel = widthBmpMax + 2*MENU_BMP_MARGIN; | |
2947 | gi->m_ofsAccel = gi->m_ofsLabel + widthLabelMax; | |
2948 | if ( widthAccelMax > 0 ) | |
2949 | { | |
2950 | // if we actually have any accesl, add a margin | |
2951 | gi->m_ofsAccel += MENU_ACCEL_MARGIN; | |
2952 | } | |
2953 | ||
2954 | gi->m_heightItem = heightText + 2*MENU_VERT_MARGIN; | |
2955 | ||
2956 | gi->m_size.x = gi->m_ofsAccel + widthAccelMax + MENU_RIGHT_MARGIN; | |
2957 | gi->m_size.y = height; | |
2958 | ||
2959 | return gi; | |
2960 | } | |
2961 | ||
71e03035 VZ |
2962 | // ---------------------------------------------------------------------------- |
2963 | // status bar | |
2964 | // ---------------------------------------------------------------------------- | |
3379ed37 | 2965 | |
71e03035 VZ |
2966 | static const wxCoord STATBAR_BORDER_X = 2; |
2967 | static const wxCoord STATBAR_BORDER_Y = 2; | |
3379ed37 | 2968 | |
71e03035 | 2969 | wxSize wxWin32Renderer::GetStatusBarBorders(wxCoord *borderBetweenFields) const |
3379ed37 | 2970 | { |
71e03035 VZ |
2971 | if ( borderBetweenFields ) |
2972 | *borderBetweenFields = 2; | |
3379ed37 | 2973 | |
71e03035 | 2974 | return wxSize(STATBAR_BORDER_X, STATBAR_BORDER_Y); |
3379ed37 VZ |
2975 | } |
2976 | ||
71e03035 VZ |
2977 | void wxWin32Renderer::DrawStatusField(wxDC& dc, |
2978 | const wxRect& rect, | |
2979 | const wxString& label, | |
2980 | int flags) | |
3379ed37 | 2981 | { |
71e03035 | 2982 | wxRect rectIn; |
3379ed37 | 2983 | |
71e03035 VZ |
2984 | if ( flags & wxCONTROL_ISDEFAULT ) |
2985 | { | |
2986 | // draw the size grip: it is a normal rect except that in the lower | |
2987 | // right corner we have several bands which may be used for dragging | |
2988 | // the status bar corner | |
2989 | // | |
2990 | // each band consists of 4 stripes: m_penHighlight, double | |
2991 | // m_penDarkGrey and transparent one | |
2992 | wxCoord x2 = rect.GetRight(), | |
2993 | y2 = rect.GetBottom(); | |
3379ed37 | 2994 | |
71e03035 VZ |
2995 | // draw the upper left part of the rect normally |
2996 | dc.SetPen(m_penDarkGrey); | |
2997 | dc.DrawLine(rect.GetLeft(), rect.GetTop(), rect.GetLeft(), y2); | |
2998 | dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(), x2, rect.GetTop()); | |
2999 | ||
3000 | // draw the grey stripes of the grip | |
3001 | size_t n; | |
3002 | wxCoord ofs = WIDTH_STATUSBAR_GRIP_BAND - 1; | |
3003 | for ( n = 0; n < NUM_STATUSBAR_GRIP_BANDS; n++, ofs += WIDTH_STATUSBAR_GRIP_BAND ) | |
3004 | { | |
3005 | dc.DrawLine(x2 - ofs + 1, y2 - 1, x2, y2 - ofs); | |
3006 | dc.DrawLine(x2 - ofs, y2 - 1, x2, y2 - ofs - 1); | |
3007 | } | |
3008 | ||
3009 | // draw the white stripes | |
3010 | dc.SetPen(m_penHighlight); | |
3011 | ofs = WIDTH_STATUSBAR_GRIP_BAND + 1; | |
3012 | for ( n = 0; n < NUM_STATUSBAR_GRIP_BANDS; n++, ofs += WIDTH_STATUSBAR_GRIP_BAND ) | |
3013 | { | |
3014 | dc.DrawLine(x2 - ofs + 1, y2 - 1, x2, y2 - ofs); | |
3015 | } | |
3016 | ||
3017 | // draw the remaining rect boundaries | |
3018 | ofs -= WIDTH_STATUSBAR_GRIP_BAND; | |
3019 | dc.DrawLine(x2, rect.GetTop(), x2, y2 - ofs + 1); | |
3020 | dc.DrawLine(rect.GetLeft(), y2, x2 - ofs + 1, y2); | |
3021 | ||
3022 | rectIn = rect; | |
3023 | rectIn.Deflate(1); | |
3024 | ||
3025 | rectIn.width -= STATUSBAR_GRIP_SIZE; | |
3026 | } | |
3027 | else // normal pane | |
3028 | { | |
3029 | DrawBorder(dc, wxBORDER_STATIC, rect, flags, &rectIn); | |
3030 | } | |
3031 | ||
3032 | rectIn.Deflate(STATBAR_BORDER_X, STATBAR_BORDER_Y); | |
3033 | ||
3034 | wxDCClipper clipper(dc, rectIn); | |
3035 | DrawLabel(dc, label, rectIn, flags, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); | |
3036 | } | |
3379ed37 | 3037 | |
1e6feb95 VZ |
3038 | // ---------------------------------------------------------------------------- |
3039 | // combobox | |
3040 | // ---------------------------------------------------------------------------- | |
3041 | ||
3042 | void wxWin32Renderer::GetComboBitmaps(wxBitmap *bmpNormal, | |
1b465102 | 3043 | wxBitmap *bmpFocus, |
1e6feb95 VZ |
3044 | wxBitmap *bmpPressed, |
3045 | wxBitmap *bmpDisabled) | |
3046 | { | |
3047 | static const wxCoord widthCombo = 16; | |
3048 | static const wxCoord heightCombo = 17; | |
3049 | ||
3050 | wxMemoryDC dcMem; | |
3051 | ||
3052 | if ( bmpNormal ) | |
3053 | { | |
3054 | bmpNormal->Create(widthCombo, heightCombo); | |
3055 | dcMem.SelectObject(*bmpNormal); | |
3056 | DrawArrowButton(dcMem, wxRect(0, 0, widthCombo, heightCombo), | |
3057 | Arrow_Down, Arrow_Normal); | |
3058 | } | |
3059 | ||
3060 | if ( bmpPressed ) | |
3061 | { | |
3062 | bmpPressed->Create(widthCombo, heightCombo); | |
3063 | dcMem.SelectObject(*bmpPressed); | |
3064 | DrawArrowButton(dcMem, wxRect(0, 0, widthCombo, heightCombo), | |
3065 | Arrow_Down, Arrow_Pressed); | |
3066 | } | |
3067 | ||
3068 | if ( bmpDisabled ) | |
3069 | { | |
3070 | bmpDisabled->Create(widthCombo, heightCombo); | |
3071 | dcMem.SelectObject(*bmpDisabled); | |
3072 | DrawArrowButton(dcMem, wxRect(0, 0, widthCombo, heightCombo), | |
3073 | Arrow_Down, Arrow_Disabled); | |
3074 | } | |
3075 | } | |
3076 | ||
3077 | // ---------------------------------------------------------------------------- | |
3078 | // background | |
3079 | // ---------------------------------------------------------------------------- | |
3080 | ||
3081 | void wxWin32Renderer::DoDrawBackground(wxDC& dc, | |
3082 | const wxColour& col, | |
3083 | const wxRect& rect) | |
3084 | { | |
3085 | wxBrush brush(col, wxSOLID); | |
3086 | dc.SetBrush(brush); | |
3087 | dc.SetPen(*wxTRANSPARENT_PEN); | |
3088 | dc.DrawRectangle(rect); | |
3089 | } | |
3090 | ||
3091 | void wxWin32Renderer::DrawBackground(wxDC& dc, | |
3092 | const wxColour& col, | |
3093 | const wxRect& rect, | |
3094 | int flags) | |
3095 | { | |
3096 | // just fill it with the given or default bg colour | |
3097 | wxColour colBg = col.Ok() ? col : wxSCHEME_COLOUR(m_scheme, CONTROL); | |
3098 | DoDrawBackground(dc, colBg, rect); | |
3099 | } | |
3100 | ||
3101 | // ---------------------------------------------------------------------------- | |
3102 | // scrollbar | |
3103 | // ---------------------------------------------------------------------------- | |
3104 | ||
3105 | void wxWin32Renderer::DrawArrow(wxDC& dc, | |
3106 | wxDirection dir, | |
3107 | const wxRect& rect, | |
3108 | int flags) | |
3109 | { | |
3110 | // get the bitmap for this arrow | |
3111 | wxArrowDirection arrowDir; | |
3112 | switch ( dir ) | |
3113 | { | |
3114 | case wxLEFT: arrowDir = Arrow_Left; break; | |
3115 | case wxRIGHT: arrowDir = Arrow_Right; break; | |
3116 | case wxUP: arrowDir = Arrow_Up; break; | |
3117 | case wxDOWN: arrowDir = Arrow_Down; break; | |
3118 | ||
3119 | default: | |
3120 | wxFAIL_MSG(_T("unknown arrow direction")); | |
3121 | return; | |
3122 | } | |
3123 | ||
3124 | wxArrowStyle arrowStyle; | |
3125 | if ( flags & wxCONTROL_PRESSED ) | |
3126 | { | |
3127 | // can't be pressed and disabled | |
3128 | arrowStyle = Arrow_Pressed; | |
3129 | } | |
3130 | else | |
3131 | { | |
3132 | arrowStyle = flags & wxCONTROL_DISABLED ? Arrow_Disabled : Arrow_Normal; | |
3133 | } | |
3134 | ||
3135 | DrawArrowButton(dc, rect, arrowDir, arrowStyle); | |
3136 | } | |
3137 | ||
3138 | void wxWin32Renderer::DrawArrow(wxDC& dc, | |
3139 | const wxRect& rect, | |
3140 | wxArrowDirection arrowDir, | |
3141 | wxArrowStyle arrowStyle) | |
3142 | { | |
3143 | const wxBitmap& bmp = m_bmpArrows[arrowStyle][arrowDir]; | |
3144 | ||
3145 | // under Windows the arrows always have the same size so just centre it in | |
3146 | // the provided rectangle | |
3147 | wxCoord x = rect.x + (rect.width - bmp.GetWidth()) / 2, | |
3148 | y = rect.y + (rect.height - bmp.GetHeight()) / 2; | |
3149 | ||
3150 | // Windows does it like this... | |
3151 | if ( arrowDir == Arrow_Left ) | |
3152 | x--; | |
3153 | ||
3154 | // draw it | |
3155 | dc.DrawBitmap(bmp, x, y, TRUE /* use mask */); | |
3156 | } | |
3157 | ||
3158 | void wxWin32Renderer::DrawArrowButton(wxDC& dc, | |
3159 | const wxRect& rectAll, | |
3160 | wxArrowDirection arrowDir, | |
3161 | wxArrowStyle arrowStyle) | |
3162 | { | |
3163 | wxRect rect = rectAll; | |
3164 | DoDrawBackground(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), rect); | |
3165 | DrawArrowBorder(dc, &rect, arrowStyle == Arrow_Pressed); | |
3166 | DrawArrow(dc, rect, arrowDir, arrowStyle); | |
3167 | } | |
3168 | ||
3169 | void wxWin32Renderer::DrawScrollbarThumb(wxDC& dc, | |
3170 | wxOrientation orient, | |
3171 | const wxRect& rect, | |
3172 | int flags) | |
3173 | { | |
3174 | // we don't use the flags, the thumb never changes appearance | |
3175 | wxRect rectThumb = rect; | |
3176 | DrawArrowBorder(dc, &rectThumb); | |
3177 | DrawBackground(dc, wxNullColour, rectThumb); | |
3178 | } | |
3179 | ||
3180 | void wxWin32Renderer::DrawScrollbarShaft(wxDC& dc, | |
3181 | wxOrientation orient, | |
3182 | const wxRect& rectBar, | |
3183 | int flags) | |
3184 | { | |
3185 | wxColourScheme::StdColour col = flags & wxCONTROL_PRESSED | |
3186 | ? wxColourScheme::SCROLLBAR_PRESSED | |
3187 | : wxColourScheme::SCROLLBAR; | |
3188 | DoDrawBackground(dc, m_scheme->Get(col), rectBar); | |
3189 | } | |
3190 | ||
3191 | void wxWin32Renderer::DrawScrollCorner(wxDC& dc, const wxRect& rect) | |
3192 | { | |
3193 | DoDrawBackground(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), rect); | |
3194 | } | |
3195 | ||
3196 | wxRect wxWin32Renderer::GetScrollbarRect(const wxScrollBar *scrollbar, | |
3197 | wxScrollBar::Element elem, | |
3198 | int thumbPos) const | |
3199 | { | |
3200 | return StandardGetScrollbarRect(scrollbar, elem, | |
3201 | thumbPos, m_sizeScrollbarArrow); | |
3202 | } | |
3203 | ||
3204 | wxCoord wxWin32Renderer::GetScrollbarSize(const wxScrollBar *scrollbar) | |
3205 | { | |
3206 | return StandardScrollBarSize(scrollbar, m_sizeScrollbarArrow); | |
3207 | } | |
3208 | ||
3209 | wxHitTest wxWin32Renderer::HitTestScrollbar(const wxScrollBar *scrollbar, | |
3210 | const wxPoint& pt) const | |
3211 | { | |
3212 | return StandardHitTestScrollbar(scrollbar, pt, m_sizeScrollbarArrow); | |
3213 | } | |
3214 | ||
3215 | wxCoord wxWin32Renderer::ScrollbarToPixel(const wxScrollBar *scrollbar, | |
3216 | int thumbPos) | |
3217 | { | |
3218 | return StandardScrollbarToPixel(scrollbar, thumbPos, m_sizeScrollbarArrow); | |
3219 | } | |
3220 | ||
3221 | int wxWin32Renderer::PixelToScrollbar(const wxScrollBar *scrollbar, | |
3222 | wxCoord coord) | |
3223 | { | |
3224 | return StandardPixelToScrollbar(scrollbar, coord, m_sizeScrollbarArrow); | |
3225 | } | |
3226 | ||
24a23c35 VS |
3227 | // ---------------------------------------------------------------------------- |
3228 | // top level windows | |
3229 | // ---------------------------------------------------------------------------- | |
3230 | ||
813edf09 VS |
3231 | int wxWin32Renderer::HitTestFrame(const wxRect& rect, const wxPoint& pt, int flags) const |
3232 | { | |
3233 | wxRect client = GetFrameClientArea(rect, flags); | |
71e03035 | 3234 | |
813edf09 VS |
3235 | if ( client.Inside(pt) ) |
3236 | return wxHT_TOPLEVEL_CLIENT_AREA; | |
71e03035 | 3237 | |
813edf09 VS |
3238 | if ( flags & wxTOPLEVEL_TITLEBAR ) |
3239 | { | |
3240 | wxRect client = GetFrameClientArea(rect, flags & ~wxTOPLEVEL_TITLEBAR); | |
3241 | ||
3242 | if ( flags & wxTOPLEVEL_ICON ) | |
3243 | { | |
3244 | if ( wxRect(client.GetPosition(), GetFrameIconSize()).Inside(pt) ) | |
3245 | return wxHT_TOPLEVEL_ICON; | |
3246 | } | |
71e03035 | 3247 | |
813edf09 VS |
3248 | wxRect btnRect(client.GetRight() - 2 - FRAME_BUTTON_WIDTH, |
3249 | client.GetTop() + (FRAME_TITLEBAR_HEIGHT-FRAME_BUTTON_HEIGHT)/2, | |
3250 | FRAME_BUTTON_WIDTH, FRAME_BUTTON_HEIGHT); | |
71e03035 | 3251 | |
813edf09 VS |
3252 | if ( flags & wxTOPLEVEL_BUTTON_CLOSE ) |
3253 | { | |
3254 | if ( btnRect.Inside(pt) ) | |
3255 | return wxHT_TOPLEVEL_BUTTON_CLOSE; | |
3256 | btnRect.x -= FRAME_BUTTON_WIDTH + 2; | |
3257 | } | |
3258 | if ( flags & wxTOPLEVEL_BUTTON_MAXIMIZE ) | |
3259 | { | |
3260 | if ( btnRect.Inside(pt) ) | |
3261 | return wxHT_TOPLEVEL_BUTTON_MAXIMIZE; | |
3262 | btnRect.x -= FRAME_BUTTON_WIDTH; | |
3263 | } | |
3264 | if ( flags & wxTOPLEVEL_BUTTON_RESTORE ) | |
3265 | { | |
3266 | if ( btnRect.Inside(pt) ) | |
3267 | return wxHT_TOPLEVEL_BUTTON_RESTORE; | |
3268 | btnRect.x -= FRAME_BUTTON_WIDTH; | |
3269 | } | |
3270 | if ( flags & wxTOPLEVEL_BUTTON_ICONIZE ) | |
3271 | { | |
3272 | if ( btnRect.Inside(pt) ) | |
3273 | return wxHT_TOPLEVEL_BUTTON_ICONIZE; | |
3274 | btnRect.x -= FRAME_BUTTON_WIDTH; | |
3275 | } | |
3276 | if ( flags & wxTOPLEVEL_BUTTON_HELP ) | |
3277 | { | |
3278 | if ( btnRect.Inside(pt) ) | |
3279 | return wxHT_TOPLEVEL_BUTTON_HELP; | |
3280 | btnRect.x -= FRAME_BUTTON_WIDTH; | |
3281 | } | |
3282 | ||
b22d16ad | 3283 | if ( pt.y >= client.y && pt.y < client.y + FRAME_TITLEBAR_HEIGHT ) |
813edf09 VS |
3284 | return wxHT_TOPLEVEL_TITLEBAR; |
3285 | } | |
3286 | ||
3287 | if ( (flags & wxTOPLEVEL_BORDER) && !(flags & wxTOPLEVEL_MAXIMIZED) ) | |
3288 | { | |
3289 | // we are certainly at one of borders, lets decide which one: | |
71e03035 | 3290 | |
813edf09 VS |
3291 | int border = 0; |
3292 | // dirty trick, relies on the way wxHT_TOPLEVEL_XXX are defined! | |
b22d16ad | 3293 | if ( pt.x < client.x ) |
813edf09 | 3294 | border |= wxHT_TOPLEVEL_BORDER_W; |
b22d16ad | 3295 | else if ( pt.x >= client.width + client.x ) |
813edf09 | 3296 | border |= wxHT_TOPLEVEL_BORDER_E; |
b22d16ad | 3297 | if ( pt.y < client.y ) |
813edf09 | 3298 | border |= wxHT_TOPLEVEL_BORDER_N; |
b22d16ad | 3299 | else if ( pt.y >= client.height + client.y ) |
813edf09 VS |
3300 | border |= wxHT_TOPLEVEL_BORDER_S; |
3301 | return border; | |
3302 | } | |
71e03035 | 3303 | |
813edf09 VS |
3304 | return wxHT_NOWHERE; |
3305 | } | |
3306 | ||
24a23c35 VS |
3307 | void wxWin32Renderer::DrawFrameTitleBar(wxDC& dc, |
3308 | const wxRect& rect, | |
3309 | const wxString& title, | |
3310 | const wxIcon& icon, | |
3311 | int flags, | |
813edf09 VS |
3312 | int specialButton, |
3313 | int specialButtonFlags) | |
24a23c35 VS |
3314 | { |
3315 | if ( (flags & wxTOPLEVEL_BORDER) && !(flags & wxTOPLEVEL_MAXIMIZED) ) | |
3316 | { | |
3317 | DrawFrameBorder(dc, rect, flags); | |
3318 | } | |
3319 | if ( flags & wxTOPLEVEL_TITLEBAR ) | |
3320 | { | |
3321 | DrawFrameBackground(dc, rect, flags); | |
3322 | if ( flags & wxTOPLEVEL_ICON ) | |
3323 | DrawFrameIcon(dc, rect, icon, flags); | |
3324 | DrawFrameTitle(dc, rect, title, flags); | |
71e03035 | 3325 | |
24a23c35 VS |
3326 | wxRect client = GetFrameClientArea(rect, flags & ~wxTOPLEVEL_TITLEBAR); |
3327 | wxCoord x,y; | |
813edf09 | 3328 | x = client.GetRight() - 2 - FRAME_BUTTON_WIDTH; |
24a23c35 | 3329 | y = client.GetTop() + (FRAME_TITLEBAR_HEIGHT-FRAME_BUTTON_HEIGHT)/2; |
71e03035 | 3330 | |
813edf09 | 3331 | if ( flags & wxTOPLEVEL_BUTTON_CLOSE ) |
24a23c35 | 3332 | { |
813edf09 VS |
3333 | DrawFrameButton(dc, x, y, wxTOPLEVEL_BUTTON_CLOSE, |
3334 | (specialButton == wxTOPLEVEL_BUTTON_CLOSE) ? | |
3335 | specialButtonFlags : 0); | |
24a23c35 VS |
3336 | x -= FRAME_BUTTON_WIDTH + 2; |
3337 | } | |
813edf09 | 3338 | if ( flags & wxTOPLEVEL_BUTTON_MAXIMIZE ) |
24a23c35 | 3339 | { |
813edf09 VS |
3340 | DrawFrameButton(dc, x, y, wxTOPLEVEL_BUTTON_MAXIMIZE, |
3341 | (specialButton == wxTOPLEVEL_BUTTON_MAXIMIZE) ? | |
3342 | specialButtonFlags : 0); | |
24a23c35 VS |
3343 | x -= FRAME_BUTTON_WIDTH; |
3344 | } | |
813edf09 | 3345 | if ( flags & wxTOPLEVEL_BUTTON_RESTORE ) |
24a23c35 | 3346 | { |
813edf09 VS |
3347 | DrawFrameButton(dc, x, y, wxTOPLEVEL_BUTTON_RESTORE, |
3348 | (specialButton == wxTOPLEVEL_BUTTON_RESTORE) ? | |
3349 | specialButtonFlags : 0); | |
24a23c35 VS |
3350 | x -= FRAME_BUTTON_WIDTH; |
3351 | } | |
813edf09 | 3352 | if ( flags & wxTOPLEVEL_BUTTON_ICONIZE ) |
24a23c35 | 3353 | { |
813edf09 VS |
3354 | DrawFrameButton(dc, x, y, wxTOPLEVEL_BUTTON_ICONIZE, |
3355 | (specialButton == wxTOPLEVEL_BUTTON_ICONIZE) ? | |
3356 | specialButtonFlags : 0); | |
24a23c35 VS |
3357 | x -= FRAME_BUTTON_WIDTH; |
3358 | } | |
813edf09 | 3359 | if ( flags & wxTOPLEVEL_BUTTON_HELP ) |
24a23c35 | 3360 | { |
813edf09 VS |
3361 | DrawFrameButton(dc, x, y, wxTOPLEVEL_BUTTON_HELP, |
3362 | (specialButton == wxTOPLEVEL_BUTTON_HELP) ? | |
3363 | specialButtonFlags : 0); | |
24a23c35 VS |
3364 | x -= FRAME_BUTTON_WIDTH; |
3365 | } | |
3366 | } | |
3367 | } | |
3368 | ||
3369 | void wxWin32Renderer::DrawFrameBorder(wxDC& dc, | |
3370 | const wxRect& rect, | |
3371 | int flags) | |
3372 | { | |
3373 | if ( !(flags & wxTOPLEVEL_BORDER) ) return; | |
71e03035 | 3374 | |
24a23c35 | 3375 | wxRect r(rect); |
71e03035 | 3376 | |
24a23c35 VS |
3377 | DrawShadedRect(dc, &r, m_penLightGrey, m_penBlack); |
3378 | DrawShadedRect(dc, &r, m_penHighlight, m_penDarkGrey); | |
3379 | DrawShadedRect(dc, &r, m_penLightGrey, m_penLightGrey); | |
3380 | if ( flags & wxTOPLEVEL_RESIZEABLE ) | |
3381 | DrawShadedRect(dc, &r, m_penLightGrey, m_penLightGrey); | |
3382 | } | |
3383 | ||
3384 | void wxWin32Renderer::DrawFrameBackground(wxDC& dc, | |
3385 | const wxRect& rect, | |
3386 | int flags) | |
3387 | { | |
3388 | if ( !(flags & wxTOPLEVEL_TITLEBAR) ) return; | |
3389 | ||
71e03035 | 3390 | wxColour col = (flags & wxTOPLEVEL_ACTIVE) ? |
24a23c35 VS |
3391 | wxSCHEME_COLOUR(m_scheme, TITLEBAR_ACTIVE) : |
3392 | wxSCHEME_COLOUR(m_scheme, TITLEBAR); | |
3393 | ||
3394 | wxRect r = GetFrameClientArea(rect, flags & ~wxTOPLEVEL_TITLEBAR); | |
3395 | r.height = FRAME_TITLEBAR_HEIGHT; | |
71e03035 | 3396 | |
24a23c35 VS |
3397 | DrawBackground(dc, col, r); |
3398 | } | |
3399 | ||
3400 | void wxWin32Renderer::DrawFrameTitle(wxDC& dc, | |
3401 | const wxRect& rect, | |
3402 | const wxString& title, | |
3403 | int flags) | |
3404 | { | |
6296744f VS |
3405 | wxColour col = (flags & wxTOPLEVEL_ACTIVE) ? |
3406 | wxSCHEME_COLOUR(m_scheme, TITLEBAR_ACTIVE_TEXT) : | |
3407 | wxSCHEME_COLOUR(m_scheme, TITLEBAR_TEXT); | |
3408 | ||
24a23c35 VS |
3409 | wxRect r = GetFrameClientArea(rect, flags & ~wxTOPLEVEL_TITLEBAR); |
3410 | r.height = FRAME_TITLEBAR_HEIGHT; | |
3411 | if ( flags & wxTOPLEVEL_ICON ) | |
3412 | r.x += FRAME_TITLEBAR_HEIGHT; | |
3413 | else | |
3414 | r.x += 1; | |
71e03035 | 3415 | |
24a23c35 | 3416 | dc.SetFont(m_titlebarFont); |
6296744f | 3417 | dc.SetTextForeground(col); |
24a23c35 VS |
3418 | dc.DrawLabel(title, wxNullBitmap, r, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); |
3419 | } | |
3420 | ||
3421 | void wxWin32Renderer::DrawFrameIcon(wxDC& dc, | |
3422 | const wxRect& rect, | |
3423 | const wxIcon& icon, | |
3424 | int flags) | |
3425 | { | |
3deeefeb VS |
3426 | if ( icon.Ok() ) |
3427 | { | |
3428 | wxRect r = GetFrameClientArea(rect, flags & ~wxTOPLEVEL_TITLEBAR); | |
3429 | dc.DrawIcon(icon, r.x, r.y); | |
3430 | } | |
24a23c35 VS |
3431 | } |
3432 | ||
3433 | void wxWin32Renderer::DrawFrameButton(wxDC& dc, | |
3434 | wxCoord x, wxCoord y, | |
3435 | int button, | |
2e9f62da | 3436 | int flags) |
24a23c35 VS |
3437 | { |
3438 | wxRect r(x, y, FRAME_BUTTON_WIDTH, FRAME_BUTTON_HEIGHT); | |
813edf09 | 3439 | |
24a23c35 VS |
3440 | size_t idx = 0; |
3441 | switch (button) | |
3442 | { | |
813edf09 VS |
3443 | case wxTOPLEVEL_BUTTON_CLOSE: idx = FrameButton_Close; break; |
3444 | case wxTOPLEVEL_BUTTON_MAXIMIZE: idx = FrameButton_Maximize; break; | |
3445 | case wxTOPLEVEL_BUTTON_ICONIZE: idx = FrameButton_Minimize; break; | |
3446 | case wxTOPLEVEL_BUTTON_RESTORE: idx = FrameButton_Restore; break; | |
3447 | case wxTOPLEVEL_BUTTON_HELP: idx = FrameButton_Help; break; | |
24a23c35 VS |
3448 | default: |
3449 | wxFAIL_MSG(wxT("incorrect button specification")); | |
3450 | } | |
71e03035 VZ |
3451 | |
3452 | if ( flags & wxCONTROL_PRESSED ) | |
813edf09 VS |
3453 | { |
3454 | DrawShadedRect(dc, &r, m_penBlack, m_penHighlight); | |
3455 | DrawShadedRect(dc, &r, m_penDarkGrey, m_penLightGrey); | |
3456 | DrawBackground(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), r); | |
3457 | dc.DrawBitmap(m_bmpFrameButtons[idx], r.x+1, r.y+1, TRUE); | |
3458 | } | |
3459 | else | |
3460 | { | |
3461 | DrawShadedRect(dc, &r, m_penHighlight, m_penBlack); | |
3462 | DrawShadedRect(dc, &r, m_penLightGrey, m_penDarkGrey); | |
3463 | DrawBackground(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), r); | |
3464 | dc.DrawBitmap(m_bmpFrameButtons[idx], r.x, r.y, TRUE); | |
3465 | } | |
24a23c35 VS |
3466 | } |
3467 | ||
3468 | ||
3469 | wxRect wxWin32Renderer::GetFrameClientArea(const wxRect& rect, | |
3470 | int flags) const | |
3471 | { | |
3472 | wxRect r(rect); | |
3473 | ||
3474 | if ( (flags & wxTOPLEVEL_BORDER) && !(flags & wxTOPLEVEL_MAXIMIZED) ) | |
3475 | { | |
71e03035 | 3476 | int border = (flags & wxTOPLEVEL_RESIZEABLE) ? |
24a23c35 VS |
3477 | RESIZEABLE_FRAME_BORDER_THICKNESS : |
3478 | FRAME_BORDER_THICKNESS; | |
3479 | r.Inflate(-border); | |
3480 | } | |
3481 | if ( flags & wxTOPLEVEL_TITLEBAR ) | |
3482 | { | |
3483 | r.y += FRAME_TITLEBAR_HEIGHT; | |
3484 | r.height -= FRAME_TITLEBAR_HEIGHT; | |
3485 | } | |
3486 | ||
3487 | return r; | |
3488 | } | |
3489 | ||
3490 | wxSize wxWin32Renderer::GetFrameTotalSize(const wxSize& clientSize, | |
3491 | int flags) const | |
3492 | { | |
3493 | wxSize s(clientSize); | |
3494 | ||
3495 | if ( (flags & wxTOPLEVEL_BORDER) && !(flags & wxTOPLEVEL_MAXIMIZED) ) | |
3496 | { | |
71e03035 | 3497 | int border = (flags & wxTOPLEVEL_RESIZEABLE) ? |
24a23c35 VS |
3498 | RESIZEABLE_FRAME_BORDER_THICKNESS : |
3499 | FRAME_BORDER_THICKNESS; | |
3500 | s.x += 2*border; | |
3501 | s.y += 2*border; | |
3502 | } | |
3503 | if ( flags & wxTOPLEVEL_TITLEBAR ) | |
3504 | s.y += FRAME_TITLEBAR_HEIGHT; | |
3505 | ||
3506 | return s; | |
3507 | } | |
3508 | ||
3509 | wxSize wxWin32Renderer::GetFrameIconSize() const | |
3510 | { | |
3511 | return wxSize(16, 16); | |
3512 | } | |
3513 | ||
3514 | ||
63f06c22 VS |
3515 | // ---------------------------------------------------------------------------- |
3516 | // standard icons | |
3517 | // ---------------------------------------------------------------------------- | |
3518 | ||
3519 | static char *error_xpm[]={ | |
3520 | "32 32 5 1", | |
3521 | ". c None", | |
3522 | "# c #800000", | |
3523 | "b c #808080", | |
3524 | "a c #ff0000", | |
3525 | "c c #ffffff", | |
3526 | "...........########.............", | |
3527 | "........###aaaaaaaa###..........", | |
3528 | ".......#aaaaaaaaaaaaaa#.........", | |
3529 | ".....##aaaaaaaaaaaaaaaa##.......", | |
3530 | "....#aaaaaaaaaaaaaaaaaaaa#......", | |
3531 | "...#aaaaaaaaaaaaaaaaaaaaaa#.....", | |
3532 | "...#aaaaaaaaaaaaaaaaaaaaaa#b....", | |
3533 | "..#aaaaaacaaaaaaaaaacaaaaaa#b...", | |
3534 | ".#aaaaaacccaaaaaaaacccaaaaaa#...", | |
3535 | ".#aaaaacccccaaaaaacccccaaaaa#b..", | |
3536 | ".#aaaaaacccccaaaacccccaaaaaa#bb.", | |
3537 | "#aaaaaaaacccccaacccccaaaaaaaa#b.", | |
3538 | "#aaaaaaaaaccccccccccaaaaaaaaa#b.", | |
3539 | "#aaaaaaaaaaccccccccaaaaaaaaaa#bb", | |
3540 | "#aaaaaaaaaaaccccccaaaaaaaaaaa#bb", | |
3541 | "#aaaaaaaaaaaccccccaaaaaaaaaaa#bb", | |
3542 | "#aaaaaaaaaaccccccccaaaaaaaaaa#bb", | |
3543 | "#aaaaaaaaaccccccccccaaaaaaaaa#bb", | |
3544 | "#aaaaaaaacccccaacccccaaaaaaaa#bb", | |
3545 | ".#aaaaaacccccaaaacccccaaaaaa#bbb", | |
3546 | ".#aaaaacccccaaaaaacccccaaaaa#bbb", | |
3547 | ".#aaaaaacccaaaaaaaacccaaaaaa#bb.", | |
3548 | "..#aaaaaacaaaaaaaaaacaaaaaa#bbb.", | |
3549 | "...#aaaaaaaaaaaaaaaaaaaaaa#bbbb.", | |
3550 | "...#aaaaaaaaaaaaaaaaaaaaaa#bbb..", | |
3551 | "....#aaaaaaaaaaaaaaaaaaaa#bbb...", | |
3552 | ".....##aaaaaaaaaaaaaaaa##bbbb...", | |
3553 | "......b#aaaaaaaaaaaaaa#bbbbb....", | |
3554 | ".......b###aaaaaaaa###bbbbb.....", | |
3555 | ".........bb########bbbbbb.......", | |
3556 | "..........bbbbbbbbbbbbbb........", | |
3557 | ".............bbbbbbbb..........."}; | |
3558 | ||
3559 | static char *info_xpm[]={ | |
3560 | "32 32 6 1", | |
3561 | ". c None", | |
3562 | "d c #000000", | |
3563 | "c c #0000ff", | |
3564 | "# c #808080", | |
3565 | "a c #c0c0c0", | |
3566 | "b c #ffffff", | |
3567 | "...........########.............", | |
3568 | "........###abbbbbba###..........", | |
3569 | "......##abbbbbbbbbbbba##........", | |
3570 | ".....#abbbbbbbbbbbbbbbba#.......", | |
3571 | "....#bbbbbbbaccccabbbbbbbd......", | |
3572 | "...#bbbbbbbbccccccbbbbbbbbd.....", | |
3573 | "..#bbbbbbbbbccccccbbbbbbbbbd....", | |
3574 | ".#abbbbbbbbbaccccabbbbbbbbbad...", | |
3575 | ".#bbbbbbbbbbbbbbbbbbbbbbbbbbd#..", | |
3576 | "#abbbbbbbbbbbbbbbbbbbbbbbbbbad#.", | |
3577 | "#bbbbbbbbbbcccccccbbbbbbbbbbbd#.", | |
3578 | "#bbbbbbbbbbbbcccccbbbbbbbbbbbd##", | |
3579 | "#bbbbbbbbbbbbcccccbbbbbbbbbbbd##", | |
3580 | "#bbbbbbbbbbbbcccccbbbbbbbbbbbd##", | |
3581 | "#bbbbbbbbbbbbcccccbbbbbbbbbbbd##", | |
3582 | "#abbbbbbbbbbbcccccbbbbbbbbbbad##", | |
3583 | ".#bbbbbbbbbbbcccccbbbbbbbbbbd###", | |
3584 | ".#abbbbbbbbbbcccccbbbbbbbbbad###", | |
3585 | "..#bbbbbbbbcccccccccbbbbbbbd###.", | |
3586 | "...dbbbbbbbbbbbbbbbbbbbbbbd####.", | |
3587 | "....dbbbbbbbbbbbbbbbbbbbbd####..", | |
3588 | ".....dabbbbbbbbbbbbbbbbad####...", | |
3589 | "......ddabbbbbbbbbbbbadd####....", | |
3590 | ".......#dddabbbbbbaddd#####.....", | |
3591 | "........###dddabbbd#######......", | |
3592 | "..........####dbbbd#####........", | |
3593 | ".............#dbbbd##...........", | |
3594 | "...............dbbd##...........", | |
3595 | "................dbd##...........", | |
3596 | ".................dd##...........", | |
3597 | "..................###...........", | |
3598 | "...................##..........."}; | |
3599 | ||
3600 | static char *question_xpm[]={ | |
3601 | "32 32 6 1", | |
3602 | ". c None", | |
3603 | "c c #000000", | |
3604 | "d c #0000ff", | |
3605 | "# c #808080", | |
3606 | "a c #c0c0c0", | |
3607 | "b c #ffffff", | |
3608 | "...........########.............", | |
3609 | "........###abbbbbba###..........", | |
3610 | "......##abbbbbbbbbbbba##........", | |
3611 | ".....#abbbbbbbbbbbbbbbba#.......", | |
3612 | "....#bbbbbbbbbbbbbbbbbbbbc......", | |
3613 | "...#bbbbbbbaddddddabbbbbbbc.....", | |
3614 | "..#bbbbbbbadabbddddabbbbbbbc....", | |
3615 | ".#abbbbbbbddbbbbddddbbbbbbbac...", | |
3616 | ".#bbbbbbbbddddbbddddbbbbbbbbc#..", | |
3617 | "#abbbbbbbbddddbaddddbbbbbbbbac#.", | |
3618 | "#bbbbbbbbbaddabddddbbbbbbbbbbc#.", | |
3619 | "#bbbbbbbbbbbbbadddbbbbbbbbbbbc##", | |
3620 | "#bbbbbbbbbbbbbdddbbbbbbbbbbbbc##", | |
3621 | "#bbbbbbbbbbbbbddabbbbbbbbbbbbc##", | |
3622 | "#bbbbbbbbbbbbbddbbbbbbbbbbbbbc##", | |
3623 | "#abbbbbbbbbbbbbbbbbbbbbbbbbbac##", | |
3624 | ".#bbbbbbbbbbbaddabbbbbbbbbbbc###", | |
3625 | ".#abbbbbbbbbbddddbbbbbbbbbbac###", | |
3626 | "..#bbbbbbbbbbddddbbbbbbbbbbc###.", | |
3627 | "...cbbbbbbbbbaddabbbbbbbbbc####.", | |
3628 | "....cbbbbbbbbbbbbbbbbbbbbc####..", | |
3629 | ".....cabbbbbbbbbbbbbbbbac####...", | |
3630 | "......ccabbbbbbbbbbbbacc####....", | |
3631 | ".......#cccabbbbbbaccc#####.....", | |
3632 | "........###cccabbbc#######......", | |
3633 | "..........####cbbbc#####........", | |
3634 | ".............#cbbbc##...........", | |
3635 | "...............cbbc##...........", | |
3636 | "................cbc##...........", | |
3637 | ".................cc##...........", | |
3638 | "..................###...........", | |
3639 | "...................##..........."}; | |
3640 | ||
3641 | static char *warning_xpm[]={ | |
3642 | "32 32 6 1", | |
3643 | ". c None", | |
3644 | "c c #000000", | |
3645 | "# c #808000", | |
3646 | "d c #808080", | |
3647 | "b c #c0c0c0", | |
3648 | "a c #ffff00", | |
3649 | ".............###................", | |
3650 | "............#aabc...............", | |
3651 | "...........#aaaabcd.............", | |
3652 | "...........#aaaaacdd............", | |
3653 | "..........#aaaaaabcdd...........", | |
3654 | "..........#aaaaaaacdd...........", | |
3655 | ".........#aaaaaaaabcdd..........", | |
3656 | ".........#aaaaaaaaacdd..........", | |
3657 | "........#aaaaaaaaaabcdd.........", | |
3658 | "........#aaabcccbaaacdd.........", | |
3659 | ".......#aaaacccccaaabcdd........", | |
3660 | ".......#aaaacccccaaaacdd........", | |
3661 | "......#aaaaacccccaaaabcdd.......", | |
3662 | "......#aaaaacccccaaaaacdd.......", | |
3663 | ".....#aaaaaacccccaaaaabcdd......", | |
3664 | ".....#aaaaaa#ccc#aaaaaacdd......", | |
3665 | "....#aaaaaaabcccbaaaaaabcdd.....", | |
3666 | "....#aaaaaaaacccaaaaaaaacdd.....", | |
3667 | "...#aaaaaaaaa#c#aaaaaaaabcdd....", | |
3668 | "...#aaaaaaaaabcbaaaaaaaaacdd....", | |
3669 | "..#aaaaaaaaaaacaaaaaaaaaabcdd...", | |
3670 | "..#aaaaaaaaaaaaaaaaaaaaaaacdd...", | |
3671 | ".#aaaaaaaaaaabccbaaaaaaaaabcdd..", | |
3672 | ".#aaaaaaaaaaaccccaaaaaaaaaacdd..", | |
3673 | "#aaaaaaaaaaaaccccaaaaaaaaaabcdd.", | |
3674 | "#aaaaaaaaaaaabccbaaaaaaaaaaacdd.", | |
3675 | "#aaaaaaaaaaaaaaaaaaaaaaaaaaacddd", | |
3676 | "#aaaaaaaaaaaaaaaaaaaaaaaaaabcddd", | |
3677 | ".#aaaaaaaaaaaaaaaaaaaaaaaabcdddd", | |
3678 | "..#ccccccccccccccccccccccccddddd", | |
3679 | "....ddddddddddddddddddddddddddd.", | |
3680 | ".....ddddddddddddddddddddddddd.."}; | |
3681 | ||
3682 | wxIcon wxWin32Renderer::GetStdIcon(int which) const | |
3683 | { | |
3684 | switch(which) | |
3685 | { | |
3686 | case wxICON_INFORMATION: | |
3687 | return wxIcon(info_xpm); | |
3688 | ||
3689 | case wxICON_QUESTION: | |
3690 | return wxIcon(question_xpm); | |
3691 | ||
3692 | case wxICON_EXCLAMATION: | |
3693 | return wxIcon(warning_xpm); | |
3694 | ||
3695 | default: | |
3696 | wxFAIL_MSG(wxT("requested non existent standard icon")); | |
3697 | // still fall through | |
3698 | ||
3699 | case wxICON_HAND: | |
3700 | return wxIcon(error_xpm); | |
3701 | } | |
3702 | } | |
3703 | ||
24a23c35 | 3704 | |
1e6feb95 VZ |
3705 | // ---------------------------------------------------------------------------- |
3706 | // text control geometry | |
3707 | // ---------------------------------------------------------------------------- | |
3708 | ||
3709 | static inline int GetTextBorderWidth() | |
3710 | { | |
3711 | return 1; | |
3712 | } | |
3713 | ||
3714 | wxRect wxWin32Renderer::GetTextTotalArea(const wxTextCtrl *text, | |
3715 | const wxRect& rect) | |
3716 | { | |
3717 | wxRect rectTotal = rect; | |
3718 | ||
3719 | wxCoord widthBorder = GetTextBorderWidth(); | |
1e6feb95 VZ |
3720 | rectTotal.Inflate(widthBorder); |
3721 | ||
3722 | // this is what Windows does | |
3723 | rectTotal.height++; | |
3724 | ||
3725 | return rectTotal; | |
3726 | } | |
3727 | ||
3728 | wxRect wxWin32Renderer::GetTextClientArea(const wxTextCtrl *text, | |
3729 | const wxRect& rect, | |
3730 | wxCoord *extraSpaceBeyond) | |
3731 | { | |
3732 | wxRect rectText = rect; | |
3733 | ||
3734 | // undo GetTextTotalArea() | |
3735 | if ( rectText.height > 0 ) | |
3736 | rectText.height--; | |
3737 | ||
3738 | wxCoord widthBorder = GetTextBorderWidth(); | |
1e6feb95 VZ |
3739 | rectText.Inflate(-widthBorder); |
3740 | ||
3741 | if ( extraSpaceBeyond ) | |
3742 | *extraSpaceBeyond = 0; | |
3743 | ||
3744 | return rectText; | |
3745 | } | |
3746 | ||
3747 | // ---------------------------------------------------------------------------- | |
3748 | // size adjustments | |
3749 | // ---------------------------------------------------------------------------- | |
3750 | ||
3751 | void wxWin32Renderer::AdjustSize(wxSize *size, const wxWindow *window) | |
3752 | { | |
3753 | #if wxUSE_SCROLLBAR | |
3754 | if ( wxDynamicCast(window, wxScrollBar) ) | |
3755 | { | |
3756 | // we only set the width of vert scrollbars and height of the | |
3757 | // horizontal ones | |
3758 | if ( window->GetWindowStyle() & wxSB_HORIZONTAL ) | |
3759 | size->y = m_sizeScrollbarArrow.y; | |
3760 | else | |
3761 | size->x = m_sizeScrollbarArrow.x; | |
3762 | ||
3763 | // skip border width adjustments, they don't make sense for us | |
3764 | return; | |
3765 | } | |
3766 | #endif // wxUSE_SCROLLBAR/!wxUSE_SCROLLBAR | |
3767 | ||
3768 | #if wxUSE_BUTTON | |
3769 | if ( wxDynamicCast(window, wxButton) ) | |
3770 | { | |
1b465102 VZ |
3771 | if ( !(window->GetWindowStyle() & wxBU_EXACTFIT) ) |
3772 | { | |
3773 | // TODO: don't harcode all this | |
3774 | size->x += 3*window->GetCharWidth(); | |
3775 | ||
3776 | wxCoord heightBtn = (11*(window->GetCharHeight() + 8))/10; | |
3777 | if ( size->y < heightBtn - 8 ) | |
3778 | size->y = heightBtn; | |
3779 | else | |
3780 | size->y += 9; | |
3781 | } | |
1e6feb95 VZ |
3782 | |
3783 | // no border width adjustments for buttons | |
3784 | return; | |
3785 | } | |
3786 | #endif // wxUSE_BUTTON | |
3787 | ||
3788 | // take into account the border width | |
3789 | wxRect rectBorder = GetBorderDimensions(window->GetBorder()); | |
3790 | size->x += rectBorder.x + rectBorder.width; | |
3791 | size->y += rectBorder.y + rectBorder.height; | |
3792 | } | |
3793 | ||
3794 | // ============================================================================ | |
3795 | // wxInputHandler | |
3796 | // ============================================================================ | |
3797 | ||
3798 | // ---------------------------------------------------------------------------- | |
3799 | // wxWin32InputHandler | |
3800 | // ---------------------------------------------------------------------------- | |
3801 | ||
3802 | wxWin32InputHandler::wxWin32InputHandler(wxWin32Renderer *renderer) | |
3803 | { | |
3804 | m_renderer = renderer; | |
3805 | } | |
3806 | ||
67e49a98 | 3807 | bool wxWin32InputHandler::HandleKey(wxInputConsumer *control, |
1e6feb95 VZ |
3808 | const wxKeyEvent& event, |
3809 | bool pressed) | |
3810 | { | |
3811 | return FALSE; | |
3812 | } | |
3813 | ||
67e49a98 | 3814 | bool wxWin32InputHandler::HandleMouse(wxInputConsumer *control, |
1e6feb95 VZ |
3815 | const wxMouseEvent& event) |
3816 | { | |
211cc8dc | 3817 | // clicking on the control gives it focus |
71e03035 | 3818 | if ( event.ButtonDown() ) |
211cc8dc | 3819 | { |
71e03035 VZ |
3820 | wxWindow *win = control->GetInputWindow(); |
3821 | if ( wxWindow::FindFocus() != control->GetInputWindow() ) | |
3822 | { | |
3823 | win->SetFocus(); | |
211cc8dc | 3824 | |
71e03035 VZ |
3825 | return TRUE; |
3826 | } | |
211cc8dc VS |
3827 | } |
3828 | ||
1e6feb95 VZ |
3829 | return FALSE; |
3830 | } | |
3831 | ||
3832 | // ---------------------------------------------------------------------------- | |
3833 | // wxWin32ScrollBarInputHandler | |
3834 | // ---------------------------------------------------------------------------- | |
3835 | ||
3836 | wxWin32ScrollBarInputHandler:: | |
3837 | wxWin32ScrollBarInputHandler(wxWin32Renderer *renderer, | |
3838 | wxInputHandler *handler) | |
3839 | : wxStdScrollBarInputHandler(renderer, handler) | |
3840 | { | |
3841 | m_scrollPaused = FALSE; | |
3842 | m_interval = 0; | |
3843 | } | |
3844 | ||
3845 | bool wxWin32ScrollBarInputHandler::OnScrollTimer(wxScrollBar *scrollbar, | |
3846 | const wxControlAction& action) | |
3847 | { | |
3848 | // stop if went beyond the position of the original click (this can only | |
3849 | // happen when we scroll by pages) | |
3850 | bool stop = FALSE; | |
3851 | if ( action == wxACTION_SCROLL_PAGE_DOWN ) | |
3852 | { | |
3853 | stop = m_renderer->HitTestScrollbar(scrollbar, m_ptStartScrolling) | |
3854 | != wxHT_SCROLLBAR_BAR_2; | |
3855 | } | |
3856 | else if ( action == wxACTION_SCROLL_PAGE_UP ) | |
3857 | { | |
3858 | stop = m_renderer->HitTestScrollbar(scrollbar, m_ptStartScrolling) | |
3859 | != wxHT_SCROLLBAR_BAR_1; | |
3860 | } | |
3861 | ||
3862 | if ( stop ) | |
3863 | { | |
3864 | StopScrolling(scrollbar); | |
3865 | ||
3866 | scrollbar->Refresh(); | |
3867 | ||
3868 | return FALSE; | |
3869 | } | |
3870 | ||
3871 | return wxStdScrollBarInputHandler::OnScrollTimer(scrollbar, action); | |
3872 | } | |
3873 | ||
67e49a98 | 3874 | bool wxWin32ScrollBarInputHandler::HandleMouse(wxInputConsumer *control, |
1e6feb95 VZ |
3875 | const wxMouseEvent& event) |
3876 | { | |
3877 | // remember the current state | |
3878 | bool wasDraggingThumb = m_htLast == wxHT_SCROLLBAR_THUMB; | |
3879 | ||
3880 | // do process the message | |
3881 | bool rc = wxStdScrollBarInputHandler::HandleMouse(control, event); | |
3882 | ||
3883 | // analyse the changes | |
3884 | if ( !wasDraggingThumb && (m_htLast == wxHT_SCROLLBAR_THUMB) ) | |
3885 | { | |
3886 | // we just started dragging the thumb, remember its initial position to | |
3887 | // be able to restore it if the drag is cancelled later | |
affe4044 | 3888 | m_eventStartDrag = event; |
1e6feb95 VZ |
3889 | } |
3890 | ||
3891 | return rc; | |
3892 | } | |
3893 | ||
67e49a98 | 3894 | bool wxWin32ScrollBarInputHandler::HandleMouseMove(wxInputConsumer *control, |
1e6feb95 VZ |
3895 | const wxMouseEvent& event) |
3896 | { | |
3897 | // we don't highlight scrollbar elements, so there is no need to process | |
3898 | // mouse move events normally - only do it while mouse is captured (i.e. | |
3899 | // when we're dragging the thumb or pressing on something) | |
3900 | if ( !m_winCapture ) | |
3901 | return FALSE; | |
3902 | ||
3903 | if ( event.Entering() ) | |
3904 | { | |
3905 | // we're not interested in this at all | |
3906 | return FALSE; | |
3907 | } | |
3908 | ||
67e49a98 | 3909 | wxScrollBar *scrollbar = wxStaticCast(control->GetInputWindow(), wxScrollBar); |
1e6feb95 VZ |
3910 | wxHitTest ht; |
3911 | if ( m_scrollPaused ) | |
3912 | { | |
3913 | // check if the mouse returned to its original location | |
3914 | ||
3915 | if ( event.Leaving() ) | |
3916 | { | |
3917 | // it surely didn't | |
3918 | return FALSE; | |
3919 | } | |
3920 | ||
3921 | ht = m_renderer->HitTestScrollbar(scrollbar, event.GetPosition()); | |
3922 | if ( ht == m_htLast ) | |
3923 | { | |
3924 | // yes it did, resume scrolling | |
3925 | m_scrollPaused = FALSE; | |
3926 | if ( m_timerScroll ) | |
3927 | { | |
3928 | // we were scrolling by line/page, restart timer | |
3929 | m_timerScroll->Start(m_interval); | |
3930 | ||
3931 | Press(scrollbar, TRUE); | |
3932 | } | |
3933 | else // we were dragging the thumb | |
3934 | { | |
3935 | // restore its last location | |
3936 | HandleThumbMove(scrollbar, m_eventLastDrag); | |
3937 | } | |
3938 | ||
3939 | return TRUE; | |
3940 | } | |
3941 | } | |
3942 | else // normal case, scrolling hasn't been paused | |
3943 | { | |
3944 | // if we're scrolling the scrollbar because the arrow or the shaft was | |
3945 | // pressed, check that the mouse stays on the same scrollbar element | |
3946 | ||
3947 | if ( event.Moving() ) | |
3948 | { | |
3949 | ht = m_renderer->HitTestScrollbar(scrollbar, event.GetPosition()); | |
3950 | } | |
3951 | else // event.Leaving() | |
3952 | { | |
3953 | ht = wxHT_NOWHERE; | |
3954 | } | |
3955 | ||
3956 | // if we're dragging the thumb and the mouse stays in the scrollbar, it | |
3957 | // is still ok - we only want to catch the case when the mouse leaves | |
3958 | // the scrollbar here | |
3959 | if ( m_htLast == wxHT_SCROLLBAR_THUMB && ht != wxHT_NOWHERE ) | |
3960 | { | |
3961 | ht = wxHT_SCROLLBAR_THUMB; | |
3962 | } | |
3963 | ||
3964 | if ( ht != m_htLast ) | |
3965 | { | |
3966 | // what were we doing? 2 possibilities: either an arrow/shaft was | |
3967 | // pressed in which case we have a timer and so we just stop it or | |
3968 | // we were dragging the thumb | |
3969 | if ( m_timerScroll ) | |
3970 | { | |
3971 | // pause scrolling | |
3972 | m_interval = m_timerScroll->GetInterval(); | |
3973 | m_timerScroll->Stop(); | |
3974 | m_scrollPaused = TRUE; | |
3975 | ||
3976 | // unpress the arrow | |
3977 | Press(scrollbar, FALSE); | |
3978 | } | |
3979 | else // we were dragging the thumb | |
3980 | { | |
3981 | // remember the current thumb position to be able to restore it | |
3982 | // if the mouse returns to it later | |
affe4044 | 3983 | m_eventLastDrag = event; |
1e6feb95 VZ |
3984 | |
3985 | // and restore the original position (before dragging) of the | |
3986 | // thumb for now | |
3987 | HandleThumbMove(scrollbar, m_eventStartDrag); | |
3988 | } | |
3989 | ||
3990 | return TRUE; | |
3991 | } | |
3992 | } | |
3993 | ||
3994 | return wxStdScrollBarInputHandler::HandleMouseMove(control, event); | |
3995 | } | |
3996 | ||
3997 | // ---------------------------------------------------------------------------- | |
3998 | // wxWin32CheckboxInputHandler | |
3999 | // ---------------------------------------------------------------------------- | |
4000 | ||
67e49a98 | 4001 | bool wxWin32CheckboxInputHandler::HandleKey(wxInputConsumer *control, |
1e6feb95 VZ |
4002 | const wxKeyEvent& event, |
4003 | bool pressed) | |
4004 | { | |
4005 | if ( pressed ) | |
4006 | { | |
4007 | wxControlAction action; | |
4008 | int keycode = event.GetKeyCode(); | |
4009 | switch ( keycode ) | |
4010 | { | |
4011 | case WXK_SPACE: | |
4012 | action = wxACTION_CHECKBOX_TOGGLE; | |
4013 | break; | |
4014 | ||
4015 | case WXK_SUBTRACT: | |
4016 | case WXK_NUMPAD_SUBTRACT: | |
4017 | action = wxACTION_CHECKBOX_CHECK; | |
4018 | break; | |
4019 | ||
4020 | case WXK_ADD: | |
4021 | case WXK_NUMPAD_ADD: | |
4022 | case WXK_NUMPAD_EQUAL: | |
4023 | action = wxACTION_CHECKBOX_CLEAR; | |
4024 | break; | |
4025 | } | |
4026 | ||
4027 | if ( !!action ) | |
4028 | { | |
4029 | control->PerformAction(action); | |
4030 | ||
4031 | return TRUE; | |
4032 | } | |
4033 | } | |
4034 | ||
4035 | return FALSE; | |
4036 | } | |
4037 | ||
4038 | // ---------------------------------------------------------------------------- | |
4039 | // wxWin32TextCtrlInputHandler | |
4040 | // ---------------------------------------------------------------------------- | |
4041 | ||
67e49a98 | 4042 | bool wxWin32TextCtrlInputHandler::HandleKey(wxInputConsumer *control, |
1e6feb95 VZ |
4043 | const wxKeyEvent& event, |
4044 | bool pressed) | |
4045 | { | |
4046 | // handle only MSW-specific text bindings here, the others are handled in | |
4047 | // the base class | |
4048 | if ( pressed ) | |
4049 | { | |
4050 | int keycode = event.GetKeyCode(); | |
4051 | ||
4052 | wxControlAction action; | |
4053 | if ( keycode == WXK_DELETE && event.ShiftDown() ) | |
4054 | { | |
4055 | action = wxACTION_TEXT_CUT; | |
4056 | } | |
4057 | else if ( keycode == WXK_INSERT ) | |
4058 | { | |
4059 | if ( event.ControlDown() ) | |
4060 | action = wxACTION_TEXT_COPY; | |
4061 | else if ( event.ShiftDown() ) | |
4062 | action = wxACTION_TEXT_PASTE; | |
4063 | } | |
4064 | ||
4065 | if ( action != wxACTION_NONE ) | |
4066 | { | |
4067 | control->PerformAction(action); | |
4068 | ||
4069 | return TRUE; | |
4070 | } | |
4071 | } | |
4072 | ||
4073 | return wxStdTextCtrlInputHandler::HandleKey(control, event, pressed); | |
4074 | } | |
4075 | ||
71e03035 VZ |
4076 | // ---------------------------------------------------------------------------- |
4077 | // wxWin32StatusBarInputHandler | |
4078 | // ---------------------------------------------------------------------------- | |
4079 | ||
4080 | wxWin32StatusBarInputHandler:: | |
4081 | wxWin32StatusBarInputHandler(wxInputHandler *handler) | |
4082 | : wxStdInputHandler(handler) | |
4083 | { | |
4084 | m_isOnGrip = FALSE; | |
4085 | } | |
4086 | ||
4087 | bool wxWin32StatusBarInputHandler::IsOnGrip(wxWindow *statbar, | |
4088 | const wxPoint& pt) const | |
4089 | { | |
4090 | if ( statbar->HasFlag(wxST_SIZEGRIP) && | |
4091 | statbar->GetParent()->HasFlag(wxRESIZE_BORDER) ) | |
4092 | { | |
4093 | wxSize sizeSbar = statbar->GetSize(); | |
4094 | ||
8b9c5905 VZ |
4095 | return (sizeSbar.x - pt.x) < (wxCoord)STATUSBAR_GRIP_SIZE && |
4096 | (sizeSbar.y - pt.y) < (wxCoord)STATUSBAR_GRIP_SIZE; | |
71e03035 VZ |
4097 | } |
4098 | ||
4099 | return FALSE; | |
4100 | } | |
4101 | ||
4102 | bool wxWin32StatusBarInputHandler::HandleMouse(wxInputConsumer *consumer, | |
4103 | const wxMouseEvent& event) | |
4104 | { | |
4105 | if ( event.Button(1) ) | |
4106 | { | |
4107 | if ( event.ButtonDown(1) ) | |
4108 | { | |
4109 | wxWindow *statbar = consumer->GetInputWindow(); | |
4110 | ||
4111 | if ( IsOnGrip(statbar, event.GetPosition()) ) | |
4112 | { | |
4113 | wxTopLevelWindow *tlw = wxDynamicCast(statbar->GetParent(), | |
4114 | wxTopLevelWindow); | |
4115 | if ( tlw ) | |
4116 | { | |
4117 | tlw->PerformAction(wxACTION_TOPLEVEL_RESIZE, | |
4118 | wxHT_TOPLEVEL_BORDER_SE); | |
4119 | ||
4120 | statbar->SetCursor(m_cursorOld); | |
4121 | ||
4122 | return TRUE; | |
4123 | } | |
4124 | } | |
4125 | } | |
4126 | } | |
4127 | ||
4128 | return wxStdInputHandler::HandleMouse(consumer, event); | |
4129 | } | |
4130 | ||
4131 | bool wxWin32StatusBarInputHandler::HandleMouseMove(wxInputConsumer *consumer, | |
4132 | const wxMouseEvent& event) | |
4133 | { | |
4134 | wxWindow *statbar = consumer->GetInputWindow(); | |
4135 | ||
4136 | bool isOnGrip = IsOnGrip(statbar, event.GetPosition()); | |
4137 | if ( isOnGrip != m_isOnGrip ) | |
4138 | { | |
4139 | m_isOnGrip = isOnGrip; | |
4140 | if ( isOnGrip ) | |
4141 | { | |
4142 | m_cursorOld = statbar->GetCursor(); | |
4143 | statbar->SetCursor(wxCURSOR_SIZENWSE); | |
4144 | } | |
4145 | else | |
4146 | { | |
4147 | statbar->SetCursor(m_cursorOld); | |
4148 | } | |
4149 | } | |
4150 | ||
4151 | return wxStdInputHandler::HandleMouseMove(consumer, event); | |
4152 | } | |
4153 |